%%
%% This is file `pst-spectrum.tex',
%%
%% IMPORTANT NOTICE:
%%
%% Package `pst-spectrum.tex'
%%
%% Manuel Luque <Manuel.Luque27 _at_ gmail.com>
%% Herbert VoÃŸ <hvoss@tug.org>
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `pst-spectrum is a PSTricks package to draw sspectrum of light
%%
\csname PSTspectrumLoaded\endcsname
\let\PSTspectrumLoaded\endinput
\ifx\PSTricksLoaded\endinput\else \input pstricks.tex\fi
%\ifx\PSTplotLoaded \endinput\else \input pst-plot.tex\fi
%\ifx\PSTnodesLoaded\endinput\else \input pst-node.tex \fi
%\ifx\PSTnodesLoaded\endinput\else \input pst-cie.tex \fi
%
\def\fileversion{1.0}
\def\filedate{2026/04/13}
\message{`PST-spectrum' v\fileversion, \filedate\space (ml,hv)}
%
\RequirePackage{multido,expl3}
\ExplSyntaxOn
  \cs_new_eq:NN \ps@Calc \fp_eval:n
\ExplSyntaxOff

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
\pst@addfams{pst-spectrum}
\pstheader{pst-spectrum.pro}

\define@key[psset]{pst-spectrum}{gamma}[2.2]{\def\psk@psspectrum@GAM{#1 }}
\define@key[psset]{pst-spectrum}{begin}[360]{\def\psk@psspectrum@begin{#1 }}
\define@key[psset]{pst-spectrum}{end}[830]{\def\psk@psspectrum@end{#1 }}
\define@boolkey[psset]{pst-spectrum}[Pst@]{axe}[true]{}
\define@boolkey[psset]{pst-spectrum}[Pst@]{invers}[true]{}
\define@boolkey[psset]{pst-spectrum}[Pst@]{values}[true]{}
\psset[pst-spectrum]{gamma=2.2,begin=360,end=830,axe=true,invers,values}

% primary illuminants
\define@choicekey*+[psset]{pst-spectrum}{ColorSpace}{%
  Adobe,CIE,ColorMatch,NTSC,Pal-Secam,ProPhoto,SMPTE,sRGB}[sRGB]{% 
  \def\pst@spectrum@ColorSpace{#1}%
}{\PackageWarning{pst-spectrum}{erroneous input (#1) for ColorSpace ignored. 
  Using sRGB.}%
  \def\pst@spectrum@ColorSpace{#1}%
}
\psset[pst-spectrum]{ColorSpace=sRGB}
%
% datas
\define@choicekey*+[psset]{pst-spectrum}{datas}{CIE1964,CIE1931}[CIE1931]{% 
  \def\pst@spectrum@datas{#1}%
}{\PackageWarning{pst-spectrum}{erroneous input (#1) for datas ignored. Using CIE1931.}%
  \def\pst@spectrum@datas{#1}%
}
\psset[pst-spectrum]{datas=CIE1931}
%
\def\psDeltaX{1}
\def\psDeltaY{0.7}
%
\def\psCIEspectrum{\def\pst@par{}\pst@object{psCIEspectrum}}
\def\psCIEspectrum@i{%
  \@ifnextchar({\psCIEspectrum@ii}{\psCIEspectrum@iii(-6,-1)(6,1)}}
\def\psCIEspectrum@ii(#1){%
  \@ifnextchar({\psCIEspectrum@iii(#1)}{\psCIEspectrum@iii(-6,-1)(#1)}}
\def\psCIEspectrum@iii(#1,#2)(#3,#4){%
  \begingroup
  \use@par
  \pspicture(\ps@Calc{#1-\psDeltaX},\ps@Calc{#2-\psDeltaY})%
            (\ps@Calc{#3+\psDeltaX},\ps@Calc{#4+0.5*\psDeltaY})
  \ifPst@invers
    \psframe*(\ps@Calc{#1-\psDeltaX},\ps@Calc{#2-\psDeltaY})%
            (\ps@Calc{#3+\psDeltaX},\ps@Calc{#4+0.5*\psDeltaY})
    \ifPst@values
      \multido{\i=-6+2,\iL=400+50}{7}{%
        \psline[linecolor=white](\i,-1)(\i,-1.2)
        \uput[d](\i,-1.2){\textcolor{white}{\iL}}}%
    \fi
  \else%  white background and noframe
%    \psframe(\ps@Calc{#1-\psDeltaX},\ps@Calc{#2-\psDeltaY})%
%            (\ps@Calc{#3+\psDeltaX},\ps@Calc{#4+0.5*\psDeltaY})
    \ifPst@values
      \multido{\i=-6+2,\iL=400+50}{7}{%
        \psline(\i,-1)(\i,-1.2)
        \uput[d](\i,-1.2){\iL}}%
    \fi
  \fi
  \addto@pscode{
	/WLbegin \psk@psspectrum@begin def
	/WLend \psk@psspectrum@end def
 	WLbegin 360 lt {/WLbegin 360 def} if
 	WLend 830 gt {/WLend 830 def} if
	/L1 WLbegin 360 sub def
	/L2 WLend 360 sub def
	/GAM {1 \psk@psspectrum@GAM div} def
	/ColorSpace (\pst@spectrum@ColorSpace) def
	/datas (\pst@spectrum@datas) def
	/DW L2 L1 sub def
	/X1 #1 \pst@number\psxunit mul def 
	/X2 #3 \pst@number\psxunit mul def
	/Y1 #2 \pst@number\psyunit mul def 
	/Y2 #4 \pst@number\psyunit mul def
	/DX X2 X1 sub def
	/Coeff DX DW div def
	/Times-Roman findfont 7 scalefont setfont
 	/chaine 15 string def
 	/imprime {chaine cvs show } def
 	/SYTEM {ColorSpace cvx exec} def
 	/TAB {datas cvx exec} def
 	spectrumdict begin TAB spectre end
  }%
  \use@pscode
  \endpspicture
  \endgroup
}%


% spectre d'après Dan Bruton
\def\psCIEspectrumDB{\def\pst@par{}\pst@object{psCIEspectrumDB}}
\def\psCIEspectrumDB@i{%
  \@ifnextchar({\psCIEspectrumDB@ii}{\psCIEspectrumDB@iii(-6,-1)(6,1)}}
\def\psCIEspectrumDB@ii(#1){%
  \@ifnextchar({\psCIEspectrumDB@iii(#1)}{\psCIEspectrumDB@iii(-6,-1)(#1)}}
\def\psCIEspectrumDB@iii(#1,#2)(#3,#4){%
  \begingroup
  \use@par
  \pspicture(\ps@Calc{#1-\psDeltaX},\ps@Calc{#2-\psDeltaY})%
            (\ps@Calc{#3+\psDeltaX},\ps@Calc{#4+0.5*\psDeltaY})
  \ifPst@invers
    \psframe*(\ps@Calc{#1-\psDeltaX},\ps@Calc{#2-\psDeltaY})%
            (\ps@Calc{#3+\psDeltaX},\ps@Calc{#4+0.5*\psDeltaY})
    \ifPst@values
      \multido{\i=-6+2,\iL=400+50}{7}{%
        \psline[linecolor=white](\i,-1)(\i,-1.2)
        \uput[d](\i,-1.2){\textcolor{white}{\iL}}}%
    \fi
  \else%  white background and noframe
%    \psframe(\ps@Calc{#1-\psDeltaX},\ps@Calc{#2-\psDeltaY})%
%            (\ps@Calc{#3+\psDeltaX},\ps@Calc{#4+0.5*\psDeltaY})
    \ifPst@values
      \multido{\i=-6+2,\iL=400+50}{7}{%
        \psline(\i,-1)(\i,-1.2)
        \uput[d](\i,-1.2){\iL}}%
    \fi
  \fi
  \addto@pscode{
	/WLbegin \psk@psspectrum@begin def
	/WLend \psk@psspectrum@end def
	/L1 WLbegin def
	/L2 WLend  def
	/GAM \psk@psspectrum@GAM def
	/DW L2 L1 sub def
	/X1 #1 \pst@number\psxunit mul def /X2 #3 \pst@number\psxunit mul def
	/Y1 #2 \pst@number\psyunit mul def /Y2 #4 \pst@number\psyunit mul def
	/DX X2 X1 sub def
	/Coeff DX DW div def
	/Times-Roman findfont 7 scalefont setfont
	/chaine 15 string def
	/imprime { chaine cvs show } def
  	spectrumdict begin spectreDB end
  }%
  \use@pscode
  \endpspicture
  \endgroup
}
\catcode`\@=\PstAtCode\relax
\endinput
