%%
%% This is file `fits-astro.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fits-astro-en.dtx  (with options: `package-tex')
%% 
%% ┌─────────────────────────────────────────────────────────────┐
%% │                                                             │
%% │                  The “fits-astro” package                   │
%% │       Retrieving FITS file header information in LuaTeX     │
%% │                                                             │
%% │  Copyright (C) 2026 Valentin Dao                            │
%% │                                                             │
%% │  This file may be distributed and/or modified under the     │
%% │  conditions of the LaTeX Project Public License, either     │
%% │  version 1.3c of this license or (at your option) any       │
%% │  later version.                                             │
%% │                                                             │
%% │  The latest version of this license is in:                  │
%% │                                                             │
%% │    > http://www.latex-project.org/lppl.txt                  │
%% │                                                             │
%% │  This work has the LPPL maintenance status 'maintained'     │
%% │  and the current maintainer is Valentin Dao                 │
%% │  (vdao.texdev@gmail.com).                                   │
%% │                                                             │
%% │  This work consists of the files listed in the              │
%% │  'MANIFEST.md' file.                                        │
%% │                                                             │
%% │  The repository of this work can be found here:             │
%% │                                                             │
%% │    > https://github.com/TeXackers/fits-astro                │
%% │                                                             │
%% └─────────────────────────────────────────────────────────────┘
%% 
\ifdefined\loadheader\expandafter\endinput\fi

\def\FITSerr#1{\errmessage{Package fits Error: #1}}
\def\FITSwar#1{\message{Package fits Warning: #1}}

\unless\ifdefined\directlua\FITSerr{LuaTeX required}\fi

\directlua{dofile('fits-astro.lua')}

\def\loadheader#1#2{
  \directlua{
    local file = '\csstring#1'
    if FITS_data[file] then
      tex.print('\luaescapestring{\FITSerr{FITS file '#2' already loaded}}')
    else
      FITS_data[file] = load_FITS_header('#2')
    end
  }
}

\def\showheader#1{
  \directlua{
    show_fits(FITS_data['\csstring#1'])
  }
}

\def\headerkey#1#2{
  \directlua{
    if FITS_data['\csstring#1']['#2'] then
      get_header_key(FITS_data['\csstring#1'], '#2')
    else
      tex.print('\luaescapestring{\FITSwar{Header key '#2' not found}}')
    end
  }
}

\def\setheaderkey#1#2#3{
  \directlua{
    if FITS_data['\csstring#1']['#2'] then
      token.set_macro('\csstring#3', FITS_data['\csstring#1']['#2'])
    end
  }
}

\def\gsetheaderkey#1#2#3{
  \directlua{
    if FITS_data['\csstring#1']['#2'] then
      token.set_macro('\csstring#3', FITS_data['\csstring#1']['#2'], 'global')
    end
  }
}

\endinput
%%
%% End of file `fits-astro.tex'.
