%%
%% This is file `fits-astro.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fits-astro.dtx  (with options: `package-tex')
%% 
%% This is a generated file.
%% 
%% 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.3 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
%% 
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2008-05-04 or later.
%% 
%% 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 fits-astro.ins, fits-astro.dtx, along with the derived files fits-astro.tex, fits-astro.sty and fits-astro-en.pdf
%% 
%% The repository of this work can be found at:
%% 
%%   https://github.com/ankaa3908/fitsheader
%% 
\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 key = '\csstring#1'
    if FITS_data[key] then
      tex.print('\luaescapestring{\FITSerr{FITS file '#2' already loaded}}')
    else
      FITS_data[key] = load_fits('#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'.
