%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%
%.IDENTIFICATION $Id: common.sty,v 68.0 2001/03/02 12:19:38 cboarott Exp $
%.LANGUAGE       TeX, LaTeX
%.AUTHOR         Carlo Boarotto [ESO]
%.ENVIRONMENT    ESOFORM
%.PURPOSE        TeX and LaTeX common macro definition for ESOFORM.
%                
%.VERSION 66.0   09-Apr-1998 Creation (period 63)
%                27-Jan-1999 Revision (period 64)
%                16-Aug-1999 Revision (period 65) 
%                25-Feb-2000 Revision (period 66) 
%
%.REMARKS        Copyright 1998 by the European Southern Observatory
%------------------------------------------------------------------------
%
        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Source psfig to import PostScript pictures
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input{psfig}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Font definition: loading new fonts      
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% (Check if the NFSS is used)

\@ifundefined{selectfont}{
        % case 1: NFSS is not installed at this site
        \newfont{\@fon}{cmbx8}
        \newfont{\@ftw}{cmssbx10 \@halfmag}  % bold sans serif
        \newfont{\@fth}{cmss8}               % small sans serif
        \newfont{\@ffo}{cmssbx10 \@magscale1}% bold sans serif
        \newfont{\sevenrm}{cmr7}
        \newfont{\ninerm}{cmr9}
        \newfont{\svtnsf}{cmss17}
}{
        % case 2: NFSS installed at this site
        \def\@fon {
                \fontfamily{cmr}\fontseries{bx}\fontshape{n}
                \fontsize{8}{9.5pt} \selectfont
        } % small roman bold (cmbx8)

         \def\@ftw {
                \fontfamily{cmss}\fontseries{bx}\fontshape{n}
                \fontsize{11}{13.6pt} \selectfont
        } % bold sans serif (cmssbx10 \@halfmag)

        \def\@fth {
                \fontfamily{cmss}\fontseries{m}\fontshape{n}
                \fontsize{8}{9.5pt} \selectfont
        } % small sans serif (cmss8)
        
        \def\@ffo {
                \fontfamily{cmss}\fontseries{bx}\fontshape{n}
                \fontsize{12}{14pt} \selectfont
        } % bold sans serif (cmssbx10 \@magscale1)

        \def\sixrm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{6}{7pt}\selectfont
        }

        \def\sevenrm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{7}{8.2pt}\selectfont
        }

        \def\svtnrm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{17}{22pt}\selectfont
        }

        \def\egtrm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{8}{9.5pt}\selectfont
        }

        \def\tensf {
                \fontfamily{cmss}\fontseries{m}\fontshape{n}
                \fontsize{10}{12pt}\selectfont
        }
        
        \def\ninerm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{9}{11pt}\selectfont
        }

        \def\tenrm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{10}{12pt}\selectfont
        }

        \def\elvrm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{11}{13.6pt}\selectfont
        }

        \def\elvsf {
                \fontfamily{cmss}\fontseries{m}\fontshape{n}
                \fontsize{11}{13.6pt}\selectfont
        }

        \def\twlrm {
                \fontfamily{cmr}\fontseries{m}\fontshape{n}
                \fontsize{12}{14pt}\selectfont
        }

        \def\twlsf {
                \fontfamily{cmss}\fontseries{m}\fontshape{n}
                \fontsize{12}{14pt}\selectfont
        }

        \def\svtnsf {
                \fontfamily{cmss}\fontseries{m}\fontshape{n}
                \fontsize{17}{22pt}\selectfont
        }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Old ESOart.sty stuff (a simplified version of article.sty)
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\@options
\lineskip 1pt 
\normallineskip 1pt
\def\baselinestretch{1}

\def\@ads{\abovedisplayskip}
\def\@adss{\abovedisplayshortskip}
\def\@bds{\belowdisplayskip}
\def\@bdss{\belowdisplayshortskip}

\def\@normalsize{
        \@setsize\normalsize{12pt}\xpt\@xpt
        \@ads 10pt plus2pt minus5pt\@bds \@ads
        \@adss \z@ plus3pt\@bdss 6pt plus3pt minus3pt
        \let\@listi\@listI
}
 
\def\small{\@setsize\small{11pt}\ixpt\@ixpt
\@ads 8.5pt plus 3pt minus 4pt\@bds \@ads
\@adss \z@ plus2pt\@bdss 4pt plus2pt minus 2pt
\def\@listi{\leftmargin\leftmargini \topsep 4pt plus 2pt minus 2pt\parsep 2pt
plus 1pt minus 1pt
\itemsep \parsep}}

\def\footnotesize{\@setsize\footnotesize{9.5pt}\viiipt\@viiipt
\@ads 6pt plus 2pt minus 4pt\@bds \@ads 
\@adss \z@ plus 1pt\@bdss 3pt plus 1pt minus
2pt
\def\@listi{\leftmargin\leftmargini \topsep 3pt plus 1pt minus 1pt\parsep 2pt
plus 1pt minus 1pt
\itemsep \parsep}}

\def\scriptsize{\@setsize\scriptsize{8pt}\viipt\@viipt}
\def\tiny{\@setsize\tiny{6pt}\vpt\@vpt}
\def\large{\@setsize\large{14pt}\xiipt\@xiipt}
\def\Large{\@setsize\Large{18pt}\xivpt\@xivpt}
\def\LARGE{\@setsize\LARGE{22pt}\xviipt\@xviipt}
\def\huge{\@setsize\huge{25pt}\xxpt\@xxpt}
\def\Huge{\@setsize\Huge{30pt}\xxvpt\@xxvpt}

\normalsize 
\if@twoside \oddsidemargin 44pt \evensidemargin 82pt \marginparwidth 107pt
\else \oddsidemargin 63pt \evensidemargin 63pt
 \marginparwidth 90pt 
\fi
\marginparsep 11pt 
 \topmargin 27pt \headheight 12pt \headsep 25pt \footskip 30pt 

\textheight = 43\baselineskip
\advance\textheight by \topskip
\textwidth 345pt \columnsep 10pt \columnseprule 0pt 

\footnotesep 6.65pt 
\skip\footins 9pt plus 4pt minus 2pt 
\floatsep 12pt plus 2pt minus 2pt \textfloatsep 20pt plus 2pt minus 4pt
\intextsep 12pt plus 2pt minus 2pt \@maxsep 20pt \dblfloatsep 12pt plus 2pt
minus 2pt \dbltextfloatsep 20pt plus 2pt minus 4pt \@dblmaxsep 20pt 
\@fptop 0pt plus 1fil \@fpsep 8pt plus 2fil \@fpbot 0pt plus 1fil 
\@dblfptop 0pt plus 1fil \@dblfpsep 8pt plus 2fil \@dblfpbot 0pt plus 1fil
\marginparpush 5pt 

\parskip 0pt plus 1pt \parindent 15pt \partopsep 2pt plus 1pt minus 1pt 
\@lowpenalty 51 \@medpenalty 151 \@highpenalty 301 
\@beginparpenalty -\@lowpenalty \@endparpenalty -\@lowpenalty \@itempenalty
-\@lowpenalty 


\setcounter{secnumdepth}{3}

%% Lists definitions
\def\labelitemi{$\bullet$}
\def\labelitemii{\bf --}
\def\labelitemiii{$\ast$}
\def\labelitemiv{$\cdot$}

\leftmargini 25pt
\leftmarginii 22pt 
\leftmarginiii 18.7pt 
\leftmarginiv 17pt 
\leftmarginv 10pt
\leftmarginvi 10pt
\leftmargin\leftmargini
\labelsep 5pt
\labelwidth\leftmargini\advance\labelwidth-\labelsep

\def\@rightListMargin{20mm}

\def\@listI{
        \leftmargin\leftmargini 
        \parsep 4pt plus 2pt minus 1pt
        \topsep 8pt plus 2pt minus 4pt
        \itemsep 4pt plus 2pt minus 1pt 
        \rightmargin \@rightListMargin
}

\let\@listi\@listI
\@listi 

\def\@listii{
        \leftmargin\leftmarginii
        \labelwidth\leftmarginii\advance\labelwidth-\labelsep
        \topsep 4pt plus 2pt minus 1pt
        \parsep 2pt plus 1pt minus 1pt
        \itemsep \parsep 
        \rightmargin \@rightListMargin
}

\def\@listiii{
        \leftmargin\leftmarginiii
        \labelwidth\leftmarginiii\advance\labelwidth-\labelsep
        \topsep 2pt plus 1pt minus 1pt 
        \parsep \z@ \partopsep 1pt plus 0pt minus 1pt
        \itemsep \topsep 
        \rightmargin \@rightListMargin
}

\def\@listiv{
        \leftmargin\leftmarginiv
        \labelwidth\leftmarginiv\advance\labelwidth-\labelsep 
        \rightmargin \@rightListMargin
}

\def\@listv{
        \leftmargin\leftmarginv
        \labelwidth\leftmarginv\advance\labelwidth-\labelsep 
        \rightmargin \@rightListMargin
}

\def\@listvi{
        \leftmargin\leftmarginvi
        \labelwidth\leftmarginvi\advance\labelwidth-\labelsep 
        \rightmargin \@rightListMargin
}

\def\labelenumi{\theenumi.} 
\def\theenumi{\arabic{enumi}} 
\def\labelenumii{(\theenumii)}
\def\theenumii{\alph{enumii}}
\def\p@enumii{\theenumi}
\def\labelenumiii{\theenumiii.}
\def\theenumiii{\roman{enumiii}}
\def\p@enumiii{\theenumi(\theenumii)}
\def\labelenumiv{\theenumiv.}
\def\theenumiv{\Alph{enumiv}} 
\def\p@enumiv{\p@enumiii\theenumiii}

\def\quotation{\list{}{\listparindent 1.5em
 \itemindent\listparindent
 \rightmargin\leftmargin \parsep 0pt plus 1pt}\item[]}
\let\endquotation=\endlist
\def\quote{\list{}{\rightmargin\leftmargin}\item[]}
\let\endquote=\endlist

\def\descriptionlabel#1{\hspace\labelsep \bf #1}
\def\description{\list{}{\labelwidth\z@ \itemindent-\leftmargin
 \let\makelabel\descriptionlabel}}
\let\enddescription\endlist

\def\theequation{\arabic{equation}}

% \arraycolsep 5pt \tabcolsep 6pt \arrayrulewidth .4pt \doublerulesep 2pt 
\tabbingsep \labelsep 

\skip\@mpfootins = \skip\footins
\fboxsep = 3pt \fboxrule = .4pt 

\def\@pnumwidth{1.55em}
\def\@tocrmarg {2.55em}
\def\@dotsep{4.5}
\setcounter{tocdepth}{3}

\setcounter{topnumber}{2}
\def\topfraction{.7}
\setcounter{bottomnumber}{1}
\def\bottomfraction{.3}
\setcounter{totalnumber}{3}
\def\textfraction{.2}
\def\floatpagefraction{.5}
\setcounter{dbltopnumber}{2}
\def\dbltopfraction{.7}
\def\dblfloatpagefraction{.5}

\newif\if@restonecol

\def\footnoterule{\kern-3\p@ 
 \hrule width .4\columnwidth 
 \kern 2.6\p@} 

\long\def\@makefntext#1{\parindent 1em\noindent 
 \hbox to 1.8em{\hss$^{\@thefnmark}$}#1}

\mark{{}{}} 

\def\today{\ifcase\month\or
 January\or February\or March\or April\or May\or June\or
 July\or August\or September\or October\or November\or December\fi
 \space\number\day, \number\year}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      New Esoform general layout feature
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\if@twoside 
        \oddsidemargin -23pt \evensidemargin -23pt 
        \marginparwidth 0pt
\else 
        \oddsidemargin -23pt \evensidemargin -23pt
        \marginparwidth 0pt
\fi

\flushbottom
\marginparsep 0pt

\topmargin -53pt \topskip 0pt

\headheight 0pt \headsep -1pt \footheight 0pt \footskip 0pt
\textheight 830pt \textwidth 530pt \columnsep 10pt \columnseprule 0pt
\parindent 0pt

\setcounter{page}{1}
\pagestyle{empty}

% Set tabular horizontal ruler style parameters
% Bug fix: 06-Aug-98 C.Boarotto
\setlength\arrayrulewidth{.4\p@}
\setlength\doublerulesep{2\p@}

%% Macro: @setArticleSettings
%%
%% Setup tabular and array column separators like article.sty
%%
\def\@setArticleSettings{
        \setlength\arraycolsep{5\p@}
        \setlength\tabcolsep{6\p@}
        \setlength\tabbingsep{\labelsep}
}

%% Macro: @unsetArticleSettings
%%
%% Unset tabular and array column separators
%%
\def\@unsetArticleSettings{
        \setlength\arraycolsep{0\p@}
        \setlength\tabcolsep{0\p@}
        \setlength\tabbingsep{0\p@}
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      List macros (see also D. Knuth - TEXbook pag. 378)
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Token list registers for temporary use
\toksdef\ta=0 
\toksdef\tb=2

%% Macro: concatenate
%%
%% This very useful macro allows to attach items to a list.
%%
%% Warning: \toksdef\ta=0\toksdef\tb=2 token list registers have to be
%% defined somewhere.
%%
%% parameters:  #1 Output list
%%              #2 Input list
%%              #3 Item to be added to the input list
%%
\def\concatenate#1=#2&#3{
        \ta=\expandafter{#2}
        \tb=\expandafter{#3}
        \edef#1{\the\ta\the\tb}
}

%% Boolean variable to check if an item is member of a list.
\newif\if@ismember\@ismembertrue

%% Register: it saves the position of the first found element when
%% ismember macro is invoked.
%%
\gdef\listposition{-1}

%% Macro: ismember
%%
%% Check if a given item is member of a given list and set the global
%% variable \listposition either to the found position or to -1.
%%
%% parameters:  #1 item to check
%%              #2 list
%%
\def\ismember#1\of#2{
        \count100=0
        \@ismemberfalse
        \def\given{#1}
        \def\\##1{
                \def\next{##1}
                \if@ismember \else \advance\count100 by 1 \fi
                % In the original was: \ifx\next\given ... and it was
                % not working
                %\typeout{Item: \given}
                \ifx\next#1 \edef\listposition{\the\count100} \@ismembertrue \fi
        }#2
}               

%% Macro: select
%%
%% Get an index and return the selected item in the list.
%%
%% parameters:  #1 count register, externally defined
%%                      Ex: \count0=2 to select position 2
%%              #2 list
%%              #3 returned item variable
%%
%% NOTE: the counter value is modified after the macro invocation !!
%%
\def\select#1\of#2\to#3{
        %\typeout{ item number \the#1}
        \def#3{}
        \long\def\\##1{
                \advance#1-1
                %\typeout{ counter \the#1}
                \ifnum#1=0 \def#3{##1} \fi
        }#2
}

%% Macro: cardinality
%%
%% Get the length of a list of items.
%%
%% parameters:  #1 List of items
%%              #2 Counter (set to the list length)
%%
\def\cardinality#1\to#2{#2=0 \long\def\\##1{\advance#2 by1}#1}

%% Counter to check single characters belonging to a
%% string.
%%
\newcount\strCount
\newcount\sepCount

%% End character (delimitator) to check single characters belonging to
%% a string.
%%
\def\@endchar{*}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Error Handling Macros
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Macro: @mg
%%
%% Dump a message to the screen.
%%
\def\@mg{
        \typeout{}
        \message
}

%% Macro: stm
%%
%% Abort and dump a fatal error to the screen.
%%
\def\@stm{
        \typeout{}
        \message{--------------------------------------------------------------------}
        \message{ESOFORM Abort}
        \typeout{}
        \batchmode\errmessage{ESOFORM abort}\stop
}

%% Macro: WarningMsg
%%
%% parameters:  #1 warning message
%%
\def\WarningMsg#1{
        \@mg{WARNING - Line \the\inputlineno: #1.}      
        \typeout{}
}

%% Macro: WeakValidation
%%
%% Check if the parameter is empty. In this case, dump the error and
%% exit.
%%
%% parameters:  #1 parameter to be validated
%%              #2 parameter name
%%              #3 macro name
%%
\def\WeakValidation#1#2#3{

        \def\@parameterVal{#1}

        \ifx \@emptyValue#1
                \@mg{ERROR - Line \the\inputlineno: Missing #2 in macro #3!}
                \@stm
        \fi
}

%% Macro: StrongValidation
%%
%% Check if the parameter value fits the parameter range.
%%
%% parameters:  #1 parameter to be validated
%%              #2 parameter range (a TeX list)
%%              #3 parameter name
%%              #4 macro name
%%
\def\StrongValidation#1#2#3#4{

        \WeakValidation{#1}{#3}{#4}

        % Is member explicitly defined here. Calling the ``ismember''
        % macro, it doesn't work
        %
        \count100=0
        \@ismemberfalse
        \def\\##1{
                \def\next{##1}
                \if@ismember \else \advance\count100 by 1 \fi
                \ifx\next#1 \@ismembertrue \fi
        }#2

        \if@ismember 
                % OK, the value is compatible with the range.
                % Do nothing.
        \else
                \def\@rangelist{}
                \def\@sep{ }

                % Build a list of the allowed values
                \count100=0
                \def\\##1{
                        \def\next{##1}
                        \advance\count100 by 1
                        \concatenate{\@rangelist}={\@rangelist}&{\next\@sep}
                }#2
                
                \@mg{ERROR - Line \the\inputlineno: Wrong #3 value {#1} in macro #4!}
                \message{It should be one of: \@rangelist.}
                \@stm
        \fi     
}


%% Macro: RangeValidation
%%
%% Check if the parameter value fits the parameter range or skip it if
%% it's empty.
%%
%% parameters:  #1 parameter to be validated
%%              #2 parameter range (a TeX list)
%%              #3 parameter name
%%              #4 macro name
%%
\def\RangeValidation#1#2#3#4{

        \ifx \@emptyValue#1
        \else
                \StrongValidation{#1}{#2}{#3}{#4}
        \fi     
}

%% Macro: NumericValidation
%%
%% Check if the parameter value is numeric.
%%
%% parameters:  #1 parameter to be validated
%%              #2 parameter name
%%              #3 macro name
%%
\def\NumericValidation#1#2#3{

        \def\@testChar{#1}
        \def\@numList{\\{0}\\{1}\\{2}\\{3}\\{4}\\{5}\\{6}\\{7}\\{8}\\{9}}
        % Check the category
        \ismember\@testChar\of\@numList

        \if@ismember
        \else
                \@mg{ERROR - Line \the\inputlineno: Wrong #2 value {#1}.}
                \message{It should be numeric.}
                \@stm
        \fi     
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Import Configuration Information for the Current Period
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input config.sty

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Esoform internal definitions and simple macros
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Frequently used alias (to fill hboxes)
\def\@h{\hfil}

%% Empty string
%%
\gdef\@emptyValue{}

%% Dump the whole macro stack when showing an error.
%% C.Boarotto 27-Jan-99
\errorcontextlines=20

\def\@pageonelength{267}
\def\@pagetwolength{276}

\def\@startpos{0mm}
\def\@endpos{180mm}

\def\@pageWidth{185}
\def\@boxLength{180mm}
\def\@boxLengthMm{180}

\def\@boxInLength{178mm}
\def\@tabInsideBoxLength{170mm}

%% Box number temporary counter (it is valid within a page)
%%
\newcount\@boxNoCount

%% Box number variable
%%
\def\@boxno{0}

%% Global boolean flag. If true it indicates that the next box is a
%% continuation of the previous one.
\newif\if@bNewBox\@bNewBoxtrue

%% Macro: @makeGenericBox
%%
%% Create a generic frame box (\@boxLengthMm x #2) housing a title and textual 
%% contents.
%%
%% parameters:  #1 Framebox y dimension.
%%              #2 Box title.
%%              #3 Box textual contents.
%%
\def\@makeGenericBox#1#2#3{

        % If it's a new box increment the box counter
        \if@bNewBox
                % A dirty trick ...
                \@boxNoCount=\@boxno
                \advance\@boxNoCount by1
                \xdef\@boxno{\the\@boxNoCount}
        \else
                % If it's an extension, reset the boolean value
                \@bNewBoxtrue   
        \fi

        
        \def\@thisBoxTitle{#2}
        \def\@thisBoxText{#3}

        \count250=#1

        % C.Boarotto 28-Jan-99
        % Changed: it was \advance\count250 by-10 
        %
        % Therefore it is possible to edit 2 lines in box 1, 9 lines
        % in box 3 and 3 lines in box 5 
        \advance\count250 by-8

        \def\@testBoxText{                      
                \vbox{
                        \hsize=170mm 
                        \@thisBoxText
                        \vfill
                }
        }

        % Necessary to avoid nasty Underfull or Overfull
        % error message
        \vbadness=100000000
        \hbadness=100000000
        \vfuzz=10000pt
        
        \def\@maxtestdim{\the\count250mm}

        % Check the box length
        \setbox250=\@testBoxText
        \setbox251=\vsplit250 to \@maxtestdim
        \setbox252=\vsplit250 to \@maxtestdim
        
        \ifvbox252
                \WarningMsg{Text field too long. 
                        Internally truncated in Box \@boxno}
        \fi

        \setlength{\unitlength}{1mm}

        \framebox(\@boxLengthMm,#1)[tl]{
                \vbox{
                        \ifx#2\@emptyValue
                                \vspace{1.5mm}
                                \hbox to \@boxInLength{
                                        \hspace{1mm} \box251 \@h
                                }
                        \else
                                \vspace{1.5mm}
                                \elvsf\hbox to \@boxInLength{
                                        \makebox[4mm][l]{\@boxno.}{
                                                \@thisBoxTitle
                                        } \@h
                                }
                                \vspace{1.5mm}
                                \hbox{\hspace{5mm} {\box251} \@h}
                                %\box251
                        \fi
                        \vfill
                }
        }

        \vspace{-0.5pt}
}

%% Macro: MakePageNumber
%%
%% Generate  and increment the page number.
%%
\def\MakePageNumber{

        \begin{center}
        {-\ \ \arabic{page}\ \ -}
        \end{center}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Proposal type definitions (updated: C.Boarotto 16-Aug-99)
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Define the proposal id before printing the proposal
\def\@proposalID{}
\def\ProposalID#1{\gdef\@proposalID{#1}}

%% Guaranteed Time Observation programme boolean flag.
%% 
\newif\if@gto\@gtofalse

%% Target of Opportunity programme boolean flag.
%% 
\newif\if@too\@toofalse

%% Director Discretionary Time programme boolean flag.
%% 
\newif\if@ddt\@ddtfalse

%% Large programme boolean flag.
%%
\newif\if@keyprg\@keyprgfalse

%% Macro: KeyProgramme
%%
%% Define a Large Programme.
%%
\def\KeyProgramme{\global\@keyprgtrue}

%% Internal variable set by GTO, ToO and DDT macros
%%
\def\@specialProposalType{}

%% String containing the send address (changed only if the proposal
%% type is DDT).
%%
\def\@submitStr{To be submitted only to: proposal@eso.org\@h}

%% Macro: @specialTypeError
%%
%% Dump a type error and abort: only one special type can be specified.
%%
%% parameters:  #1 First special type.
%%              #2 Second special type.
%%
\def\@specialTypeError#1#2{
        \@mg{ERROR - Line \the\inputlineno: #1 cannot be #2 at the
        same time!}  \@stm }

%% Macro: GuaranteedTimeObservation
%%
%% When invoked, this macro sets @specialProposalType internal
%% variable, to be displayed in the header.
%%
\def\GuaranteedTimeObservation{
        \if@too
                \@specialTypeError{GTO}{ToO}
        \fi 
        \if@ddt
                \@specialTypeError{GTO}{DDT}
        \fi 
        \gdef\@specialProposalType{GTO}
        \global\@gtotrue
}

%% Macro: TargetofOpportunity
%%
%% When invoked, this macro sets @specialProposalType internal
%% variable, to be displayed in the header.
%%
\def\TargetofOpportunity{
        \if@gto
                \@specialTypeError{ToO}{GTO}
        \fi 
        \if@ddt
                \@specialTypeError{ToO}{DDT}
        \fi 
        \gdef\@specialProposalType{ToO}
        \global\@tootrue
}

%% Macro: DirectorDiscretionaryTime
%%
%% When invoked, this macro sets @specialProposalType internal
%% variable, to be displayed in the header.
%%
\def\DirectorDiscretionaryTime{
        \if@gto
                \@specialTypeError{DDT}{GTO}
        \fi 
        \if@too
                \@specialTypeError{DDT}{ToO}
        \fi 
        \gdef\@specialProposalType{DDT}
        \global\@ddttrue

        % DDT proposals shall be submitted to a different address
        \gdef\@submitStr{To be submitted only to: ddt@eso.org\@h}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Astronomical symbols available for use in the proposal templates.
%%
%%      ( A&A and AASTeX stuff, from the STScI style files )
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\ang{\AA}                           %Angstrom unit
\def\degpoint{\mbox{$^\circ\mskip-7.0mu.\,$}}
\def\halpha{\mbox{H$\alpha$}}
\def\hbeta{\mbox{H$\beta$}}
\def\hgamma{\mbox{H$\gamma$}}
\def\kms{\,km~s$^{-1}$}      % note leading thinspace
\def\lya{\mbox{Ly$\alpha$}}
\def\lyb{\mbox{Ly$\beta$}}
\def\minpoint{\mbox{$'\mskip-4.7mu.\mskip0.8mu$}}
\def\mv{\mbox{$m_{_V}$}}
\def\Mv{\mbox{$M_{_V}$}}
\def\peryr{\mbox{$\>\rm yr^{-1}$}}
\def\secpoint{\mbox{$''\mskip-7.6mu.\,$}}
\def\sqdeg{\mbox{${\rm deg}^2$}}
\def\squig{\sim\!\!}
\def\subsun{\mbox{$_{\normalsize\odot}$}}
\def\deg{\hbox{$^\circ$}}
\def\sun{\hbox{$\odot$}}
\def\earth{\hbox{$\oplus$}}
\def\lesssim{\mathrel{\hbox{\rlap{\hbox{\lower4pt\hbox{$\sim$}}}\hbox{$<$}}}}
\def\gtrsim{\mathrel{\hbox{\rlap{\hbox{\lower4pt\hbox{$\sim$}}}\hbox{$>$}}}}
\def\la{\mathrel{\hbox{\rlap{\hbox{\lower4pt\hbox{$\sim$}}}\hbox{$<$}}}}
\def\ga{\mathrel{\hbox{\rlap{\hbox{\lower4pt\hbox{$\sim$}}}\hbox{$>$}}}}
\def\sq{\hbox{\rlap{$\sqcap$}$\sqcup$}}
\def\arcmin{\hbox{$^\prime$}}
\def\arcsec{\hbox{$^{\prime\prime}$}}
\def\fd{\hbox{$.\!\!^{\rm d}$}}
\def\fh{\hbox{$.\!\!^{\rm h}$}}
\def\fm{\hbox{$.\!\!^{\rm m}$}}
\def\fs{\hbox{$.\!\!^{\rm s}$}}
\def\fdg{\hbox{$.\!\!^\circ$}}
\def\farcm{\hbox{$.\mkern-4mu^\prime$}}
\def\farcs{\hbox{$.\!\!^{\prime\prime}$}}
\def\fp{\hbox{$.\!\!^{\scriptscriptstyle\rm p}$}}
\def\micron{\hbox{$\mu$m}}
\def\case#1#2{\hbox{$\frac{#1}{#2}$}}
\def\slantfrac#1#2{\hbox{$\,^#1\!/_#2$}}
\def\onehalf{\slantfrac{1}{2}}
\def\onethird{\slantfrac{1}{3}}
\def\twothirds{\slantfrac{2}{3}}
\def\onequarter{\slantfrac{1}{4}}
\def\threequarters{\slantfrac{3}{4}}
\def\ubvr{\hbox{$U\!BV\!R$}}            % UBVR system
\def\ub{\hbox{$U\!-\!B$}}               % U-B
\def\bv{\hbox{$B\!-\!V$}}               % B-V
\def\vr{\hbox{$V\!-\!R$}}               % V-R
\def\ur{\hbox{$U\!-\!R$}}               % U-R
\def\jhk{\hbox{$J\!H\!K$}}              % JHK system
\def\jh{\hbox{$J\!-\!H$}}               % J-H
\def\hk{\hbox{$H\!-\!K$}}               % H-K
\def\jk{\hbox{$J\!-\!K$}}               % J-K
\def\nodata{\multicolumn{1}{c}{$\cdots$}}
\def\ion#1#2{#1$\;${\small\rm\@Roman{#2}}\relax}

% End of stuff (53 short macros) from A&A and AASTeX

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Proposal Header
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Macro: @esologo
%%
%% Definition of ESO logo: print a ESO logo.
%%
\def\@esologo{

        \begin{picture}(24.2,32.1)

        \@ifundefined{psfig}{
                \put(-2,25){\framebox(24.1,32.1){\ }}
                \put(5,42){{\Huge E}}
                \put(11,43){{\Huge S}}
                \put(7.5,33){{\Huge O}}
                \put(8,26.5){{\LARGE $\ast$}}
                \put(-1,42.7){{\Large $\ast$}}
                \put(18,45.5){{\large $\ast$}}
                \put(10.5,54){{\normalsize $\ast$}}
        }{
                \put(-2,25){\psfig{figure=esologo.ps,silent=1,height=3.2cm}}
        }

        \end{picture}   
}

%% Macro: EsoEnglish
%%
%% Return the ESO English name.
%%
\def\EsoEnglish{
        E\@h U\@h R\@h O\@h P\@h E\@h A\@h N\@h\ 
        \@h S\@h O\@h U\@h T\@h H\@h E\@h R\@h N\@h\ 
        \@h O\@h B\@h S\@h E\@h R\@h V\@h A\@h T\@h O\@h R\@h Y
}

%% Macro: EsoFrench
%%
%% Return the ESO French name.
%%
\def\EsoFrench{
        Organisation\@h Europ\'eenne\@h
        pour\@h des\@h Recherches\@h Astronomiques\@h
        dans\@h l'H\'emisph\`ere\@h Austral
}

%% Macro: EsoGerman
%%
%% Return the ESO German name.
%%
\def\EsoGerman{
        Europ\"{a}ische\@h Organisation\@h
        f\"{u}r\@h astronomische\@h Forschung\@h 
        in\@h der\@h s\"{u}dlichen\@h Hemisph\"{a}re
}

%% Macro: VisasAddress
%%
%% Return Visas address, email and telephone.
%%
\def\VisasAddress{V\@ I\@ S\@ I\@ T\@ I\@ N\@ G\@\ \@ 
        A\@ S\@ T\@ R\@ O\@ N\@ O\@ M\@ E\@ R\@ S\@\ \@ 
        S\@ E\@ C\@ T\@ I\@ O\@ N\@\ $\bullet$
        K\@ a\@ r\@ l\@-\@ 
        S\@ c\@ h\@ w\@ a\@ r\@ z\@ s\@ c\@ h\@ i\@ l\@ d\@-\@ 
        S\@ t\@ r\@ a\@\ss\@ e\@\ \@2\@\ \@ $\bullet$
        D\@-\@8\@5\@7\@4\@8\@\ \@ 
        G\@ a\@ r\@ c\@ h\@ i\@ n\@ g\@\ \@ b\@ e\@ i\@\ \@ 
        M\@\"{u}\@ n\@ c\@ h\@ e\@ n\@\ \@ $\bullet$
        e\@-\@ m\@ a\@ i\@ l\@:\@\ \@
        v\@ i\@ s\@ a\@ s\@ @\@ e\@ s\@ o\@.\@ o\@ r\@ g\@\ \@ $\bullet$
        T\@ e\@ l\@.\@\,\@:\@\ \@
        \@+\@4\@9\@-\@8\@9\@-\@3\@2\@\ \@0\@0\@\ \@6\@2\@\ \@2\@3
}

%% Macro: EsoHeader
%%
%% Create a box displaying the Eso Header (logo + Eso name)
%%
\def\EsoHeader{

        \setlength{\unitlength}{1mm}

        \def\@esoendpos{152mm}

        % Need to specify box dimensions, otherwise it adds a large space 
        % below the eso-header
        \vbox{\hbox{
                % Display the ESO logo
                \@esologo
                % Fixed coordinates
                \put(0,32){
                \vbox{
                        \svtnrm\hbox to \@esoendpos{\bf\EsoEnglish}
                        \elvrm\hbox{ } % one blank line
                        \elvrm\hbox to \@esoendpos{\EsoFrench}
                        \elvrm\hbox to \@esoendpos{\EsoGerman}

                        % Print proposal ID if defined
                        %\batchmode
                        \@ffo\hbox to 148mm{\@h \@proposalID}
                        %\errorstopmode
                }
                }
                }
        }
}

%% Macro: MakeHeader
%%
%% This macro create a box to host Eso header, visas address and the header
%% notes.
%%
\def\MakeHeader{

        \setlength{\unitlength}{1mm}

        \vbox{

                \vspace{1mm}
                \EsoHeader

                \vspace{-20mm}

                \sixrm\hbox to \@endpos{\VisasAddress}
                \sevenrm\hbox { }
                \bf\twlsf{
                        \def\@applicationString{APPLICATION FOR OBSERVING TIME\@h}
                        \def\@largeString{LARGE PROGRAMME\@h}
                        \def\@periodBox{\hbox{PERIOD: \@ffo\thePeriod}}

                        \if@keyprg 
                                \hbox to \@endpos{
                                        \@applicationString \@largeString \@periodBox
                                }
                        \else
                                \hbox to \@endpos{\@applicationString \@periodBox}
                        \fi
                }

                \sevenrm\hbox { }

                \elvsf{
                        \def\@specialTypeBox{\hbox{\@ffo\@specialProposalType}}
                        \hbox to \@endpos{\@submitStr \@specialTypeBox}
                }

                \elvsf\hbox{Important Notice:}
                \vspace{2mm}

                % Generate the note
                \ninerm\vbox{
                        \hbox to \@endpos{By submitting this proposal, the PI takes
                                full responsibility for the content of the
                                proposal, in particular with regard to the}
                        \hbox to \@endpos{names of COIs and the agreement to act 
                                according to the ESO policy and regulations,
                                should observing time be granted}
                }
        }

        \vspace{3mm}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Title Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Boolean variable, if it is true skip all the checks and print an
%% empty form.
%% 
\newif\if@test\@testtrue

%% Boolean variable for panel definitions.
%% 
\newif\if@csf\@csftrue

%% Title handling
\def\@title{}
\long\def\Title#1{\gdef\@title{#1}}

%% @category, @subcategotycode and @panel global variable
%% 
\def\@category{}
\def\@subcategorycode{}
\def\@panel{}


%% Macro: SplitCategory
%% 
%% Bug fixed: C.Boarotto 24-Mar-99 (added one parameter to process
%%            subcategories like N10)
%% Split category definition into @panel and @subcategorycode.
%%
\def\SplitCategory#1#2#3{
        \gdef\@panel{#1}
        \gdef\@subcategorycode{#2#3}
}


%% Macro: SubCategoryCode
%%
%% Validate proposal subcategory. Set global variable @subcategorycode 
%% to the complete subcategory code and global variable @Panel to the 
%% belonging panel (category).
%% If the subcategory code is correct then set csf false (global boolean 
%% variable).
%% Ex: N7 -> csf = false, @subcategorycode = N7, @Panel = N
%%
\def\SubCategoryCode#1{

        \gdef\@category{#1}
        
        % Check the category only if the title is not empty,
        % otherwise it is considered an empty template
        \ifx\@title\@emptyValue
        \else
                \StrongValidation{\@category}{\Panels}
                        {subcategory}{SubCategoryCode (first parameter)}
                \global\@csffalse
                \SplitCategory#1\@emptyValue
        \fi
}


%% Macro: MakeTitle
%%
%% Generate the proposal title and print the proposal header with the
%% Eso logo
%%
\def\MakeTitle{

        % Check for an empty proposal (title+class empty), then suppress
        % checks to allow the printout of a blank form.
        \if@test 
                \ifx \@emptyValue\@title 
                        \if@csf
                                \@testfalse
                        \fi
                \fi
        \fi

        \if@test
                \WeakValidation{\@title}{title}{Title}
                \StrongValidation{\@category}{\Panels}
                        {category code}{SubCategoryCode}
        \fi
        
        \setlength{\unitlength}{1mm}

        \def\@titleHeader{Title\hfill}
        \def\@panelBox{\hbox{Panel: \@ffo{\@panel--\@subcategorycode} \@h}}
        \def\@titleboxTitle{\@titleHeader \@panelBox}

        \@makeGenericBox{18}{\@titleboxTitle}{\normalsize\@title}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Abstract Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Abstract  handling
\def\@abstract{}
\long\def\Abstract#1{\gdef\@abstract{#1}}

%% Total amount of time variable for Large Programmes (it
%% shouldn't be empty - weak validation)
%% 
\def\@amountOfTime{}
\def\TotalAmountOfTime#1{\gdef\@amountOfTime{#1}}

%% Total number of semesters variable for Large Programmes (it
%% shouldn't be empty - weak validation)
%% 
\def\@numberOfSemesters{}
\def\TotalNumberOfSemesters#1{\gdef\@numberOfSemesters{#1}}

%% Macro: MakeAbstract
%%
%% Generate the proposal title and print the proposal header with the
%% Eso logo
%%
\def\MakeAbstract{

        \setlength{\unitlength}{1mm}

        \if@test
                % Abstract weak validation: it shouldn't be empty \if@test
                \WeakValidation{\@abstract}{abstract}{Abstract}
        \fi                     

        % Create the frame box to house the abstract
        % Note that the box is smaller in case of Large Programme
        \if@keyprg

                \def\@abstractboxTitle{Abstract / Total Time Requested\@h}
                \def\@absBoxlen{70}

                % Total number of semesters and total amount of time
                % to be displayed in the Abstract box for Large
                % Programmes (Weak validation)
                \ifx\@emptyValue\@title
                \else
                        \WeakValidation{\@amountOfTime}
                                {total amount of time}
                                {TotalAmountOfTime (first parameter)}
                        \WeakValidation{\@numberOfSemesters}
                                {total number of semesters}
                                {TotalNumberOfSemesters (first parameter)}
                \fi                     

                \def\@absBoxText{

                        \parbox[tl]{\@tabInsideBoxLength}{
                                \elvsf{TotalAmountOfTime: }
                                \normalsize\@amountOfTime
                                \@h             
                                \elvsf{TotalNumberOfSemesters: }
                                \normalsize\@numberOfSemesters
                                \@h
                                \vspace{2mm}
                        }

                        \normalsize\@abstract
                }

        \else
                \def\@abstractboxTitle{Abstract\@h}
                \def\@absBoxlen{45}
                \def\@absBoxText{\normalsize\@abstract}
        \fi
        
        \@makeGenericBox{\@absBoxlen}{\@abstractboxTitle}{\@absBoxText}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Observing Run Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% List to store already defined observing runs' codes
%%
\def\@RunCodeList{}

%% List to store already defined alternative observing runs' codes
%%
\def\@RunAltCodeList{}

%% Boolean value alternative
%%
\newif\if@altRun\@altRunfalse


%% Boolean value to parse the run id
%%
\newif\if@validRunCode\@validRunCodetrue

%% Variable to store the run id (without alt)
%%
\def\@runcode{}

%% Macro: @setruncode
%%
%% Parse the given run code in the form and extract run id (without alt).
%% Tricky, it uses tail recursion to parse each single character
%% contained in the input string.
%%
%% parameter:   #1 run number (A, A/alt, B, B/alt)
%%
\def\@setruncode#1{

        %\typeout{checking character {#1}}
        \ifx#1\@endchar 
                \let\next=\relax
        \else
                \def\given{#1}
                % Skip everything after ``/'' because it should
                % be the alternative indication
                \if\given/
                        \@validRunCodefalse
                \fi

                \if@validRunCode
                        %\typeout{+++ setting run code: \given}
                        \gdef\@runcode{#1}
                \fi
                \let\next=\@setruncode           
        \fi

        % Tail recursion
        \next
}


%% Macro: @CheckRunNum
%%
%% Validate run entry
%%
%% parameter:   #1 run number (A, A/alt, B, B/alt)
%%
\def\@CheckRunNum#1{
        
        \def\@runPar{#1}
        \def\@runEntry{\\ {#1}}

        \ismember\@runPar\of\AltRunCodeValues
        \if@ismember
                \def\@altPar{alt}
        \else
                \def\@altPar{}
                % Run id validation
                \StrongValidation{\@runPar}{\RunCodeValues}
                {observing run code}{ObservingRun (first parameter)}
        \fi

        % Set the run code (A -> A, A/alt -> A)
        %\typeout{before checking run {#1}}
        \@setruncode#1\@endchar
        % Reset the boolean variable to parse the run code
        \@validRunCodetrue                
        %\typeout{after checking run {#1}}

        % Different check if it is an alternative run
        \ifx\@altPar\@emptyValue

                \@altRunfalse
                % It is not an alternative but a principal run  
                % Check if the run number (or code) is unique
                \ismember\@runPar\of\@RunCodeList
        
                \if@ismember 
                        \@mg{ERROR - Line \the\inputlineno: 
                                Wrong observing run code: 
                                code {#1} already defined for this programme 
                                (macro ObservingRun first parameter)!}
                        \@stm
                \fi     

                % Append to the already defined run codes list          
                \concatenate{\@RunCodeList}={\@RunCodeList}&{\@runEntry}
        \else

                \@altRuntrue

                % Alternative
                \ismember\@runcode\of\@RunCodeList

                % Check if the primary run is already defined   
                \if@ismember
                \else
                        \@mg{ERROR - Line \the\inputlineno: 
                                Wrong alternative observing run code: 
                                code -\@runcode - is not yet defined 
                                (macro ObservingRun first parameter)!}
                        \@stm
                \fi 

                % Check if the alternative run number (or code) is unique
                \ismember\@runPar\of\@RunAltCodeList
        
                \if@ismember 
                        \@mg{ERROR - Line \the\inputlineno: 
                                Wrong alternative observing run code: 
                                alternative code {#1} already defined for this
                                programme (macro ObservingRun first parameter)!}
                        \@stm
                \fi     

                % Append to the already defined alternative run codes list              
                \concatenate{\@RunAltCodeList}={\@RunAltCodeList}&{\@runEntry}
        \fi
}

%% SEST handling variable
%% Current run sest flag
\newif\if@isSEST\@isSESTfalse
%% At least one sest run defined
\newif\if@DefSEST\@DefSESTfalse
\def\@sestvar{SEST}

%% Macro: CheckSEST
%%
%% Check if the telescope defined is SEST.
%%
%% parameters:  #1 Telescope
%%
\def\CheckSEST#1{
        \@isSESTfalse
        \ifx #1\@sestvar \global\@isSESTtrue \global\@DefSESTtrue \fi
}

%% ADONIS handling variable
%%
\newif\if@DefAdonis\@DefAdonisfalse
\def\@adonisco{AdonisCO}
\def\@adonissh{AdonisSH}

%% Macro: CheckAdonis
%%
%% Check if the instrument defined is ADONIS to set a boolean variable
%% to force the user to write the adonis-page.
%%
%% parameters:  #1 Instrument
%%
\def\CheckAdonis#1{

        \def\@Adonis{\global\@DefAdonistrue}
        \ifx #1\@adonisco \@Adonis \fi
        \ifx #1\@adonissh \@Adonis \fi
}

%% Mapping one to one for the following lists
\def\usedTelescopeList{}
\def\usedInstrumentList{}

%% Observing modes: boolean variables.
%% When choosing a telescope, these three variables are set according
%% the VisitorModeTel, ServiceModeTel and RemoteModeTel lists that define
%% which telescopes can run in a specific mode
\newif\if@VisitorMode\@VisitorModefalse
\newif\if@ServiceMode\@ServiceModefalse
\newif\if@RemoteMode\@RemoteModefalse

%% Macro: @CheckTelObsMode
%% 
%% Check the allowed observing modes given a specific telescope.
%%
%% parameter:   #1 telescope code
%%
\def\@CheckTelObsMode#1{

        % Initialize booleans
        \global\@VisitorModefalse
        \global\@ServiceModefalse
        \global\@RemoteModefalse

        % Check visitor mode
        \ismember#1\of\VisitorTelescopes
        \if@ismember 
                % \typeout{telescope #1 visitor mode}
                \global\@VisitorModetrue 
        \fi

        % Check service mode
        \ismember#1\of\ServiceTelescopes
        \if@ismember 
                % \typeout{telescope #1 service mode}
                \global\@ServiceModetrue 
        \fi

        % Check remote mode
        \ismember#1\of\RemoteTelescopes
        \if@ismember 
                % \typeout{telescope #1 remote mode}
                \global\@RemoteModetrue 
        \fi
}

%%% Visitor instrument page internal flag (if empty no visitor
%% instrument page).
\def\@pageVisitorInstrument{}

% Macro: @CheckTelIns
%%
%% Validate entered telescope and instrument codes
%%
%% parameters:  #1 telescope code
%%              #2 instrument code
%%
\def\@CheckTelIns#1#2{

        \def\@anstel{#1}
        \def\@ansins{#2}

        % Telescope code validation
        \StrongValidation{\@anstel}{\Telescopes}
                {telescope code}{ObservingRun (second parameter)}

        % Get the telescope-instrument sublist
        \ismember\@anstel\of\Telescopes
        \count100=\listposition
        \select\count100\of\Instruments\to\telInstrList

        % Instrument code validation: don't check if it's equal to the
        % visitor instrument
        % C.Boarotto 25-Sep-98
        \ifx\@ansins\VisitorInstrument
                \gdef\@pageVisitorInstrument{yes}
        \else
                \StrongValidation{\@ansins}{\telInstrList}
                        {instrument code}{ObservingRun (third parameter)}
        \fi

        % Add to the defined instruments list
        \def\@tel{\\ {#1}}
        \def\@ins{\\ {#2}}

        % Check the observing modes allowed for the specified
        % telescope (set booleans flags)
        \@CheckTelObsMode{\@anstel}

        % Check if the telescope is SEST
        \CheckSEST{\@anstel}

        % Different behavior if alternative
        \if@altRun
        \else

                % Don't append visitor instruments and their
                % telescopes to the list of instruments to be configured
                \ifx\@ansins\VisitorInstrument
                \else
                \concatenate{\usedTelescopeList}={\usedTelescopeList}&{\@tel}
                \concatenate{\usedInstrumentList}={\usedInstrumentList}&{\@ins}
                \fi

                % Check if the instrument is Adonis
                \CheckAdonis{\@ansins}
        \fi
}

%% Variables to check the time indication (hours or nights)
%%
\newif\if@isnight\@isnightfalse
\newif\if@ishour\@ishourfalse
\def\@nightval{n}
\def\@hourval{h}

%% List of allowed symbols in the time algebra field
%% Bug fixed: C.Boarotto 21-Sep-98 allow fractional nights (ex: 2.5)
%%
\def\@TimeSymbolList{\\{.}\\{0}\\{1}\\{2}\\{3}\\{4}\\{5}\\{6}
        \\{7}\\{8}\\{9}\\{=}\\{x}\\{+}\\{h}\\{n}\\{H}}

%% Macro: @scanTimeSyntax
%%
%% Tricky, it uses tail recursion to parse each single character
%% contained in the input string.
%%
%% parameter:   #1 Input string (and then single char).
%%
\def\@scanTimeSyntax#1{

        \ifx#1\@endchar 
                \let\next=\relax
        \else
                % \typeout{checking character {#1}}
                
                \def\given{#1}
                \StrongValidation{\given}{\@TimeSymbolList}
                        {time syntax symbol}{ObservingRun (fourth parameter)}

                \ifx\given\@nightval \global\@isnighttrue \fi
                \ifx\given\@hourval \global\@ishourtrue \fi

                \advance\strCount by1 
                \let\next=\@scanTimeSyntax              
        \fi

        % Tail recursion
        \next
}

%% Macro: @CheckTime
%%
%% Validate entered time.
%%
%% parameter:   #1 time specification
%%
\def\@CheckTime#1{
                
        \@isnightfalse
        \@ishourfalse
        
        \def\@anstime{#1}

        % Time validation
        \WeakValidation{\@anstime}{time}{ObservingRun (fourth parameter)}

        % OK, not empty. Check single characters
        \strCount=0
        \@scanTimeSyntax#1\@endchar

        % One and only one time indication must exist
        \if@isnight

                % Hours and nights cannnot be specified at the same time
                \if@ishour
                        \StrongValidation{n AND h}{\\{n}\\{OR}\\{h}}
                                {time indication}{ObservingRun (fourth parameter)}
                \fi

                % Nights cannot be specified if the telescope is not
                % supporting visitor mode
                \if@VisitorMode
                        %\typeout{visitor mode + nights OK}
                \else
                        %\typeout{non visitor mode + nights WRONG}
                        \StrongValidation{n}{\\{h}}
                                {time indication (hours required in non visitor mode)}
                                {ObservingRun (fourth parameter)}
                \fi

                % Nights cannot be specified if SEST (only hours)
                \if@isSEST                      
                        %\typeout{SEST + nights WRONG}
                        \StrongValidation{n}{\\{h}}
                                {time indication (SEST requires hours)}
                                {ObservingRun (fourth parameter)}
                \fi

        \else
                \if@ishour

                        % Hour allowed only for SEST, for remote and
                        % service mode, otherwise error !
                        \def\@testRes{0}
                        \def\@bad{0}
                        \if@ServiceMode \def\@testRes{1} \fi
                        \if@RemoteMode \def\@testRes{1} \fi
                        \if@isSEST \def\@testRes{1} \fi

                        \ifnum\@testRes=\@bad
                                \StrongValidation{h}{\\{n}}
                                        {time indication}
                                        {ObservingRun (fourth parameter)}
                        \fi

                \else
                        \WeakValidation{\@emptyValue}
                                {time indication (should be n OR h)}
                                {ObservingRun (fourth parameter)}
                \fi
        \fi
}

%% Macro: SeeingReq
%%
%% Set the @seeing variable and performs strong validation check.
%%
%% parameter: #1 Seeing requirements (must be 0.4, 0.6, 0.8, 1.0, 1.2,
%%               1.4 or n)
%%
\def\@CheckSeeingReq#1{

        \def\@ansseeing{#1}
        \StrongValidation{\@ansseeing}{\SeeingValues}
                {seeing requirements}{ObservingRun (seventh parameter)}
}

%% Macro: MoonAge
%%
%% Set the @moonage variable and performs strong validation check.
%%
%% parameter:   #1 MoonAge requirements (must be d, g or n)
%%
\def\@CheckMoonAge#1{

        \def\@ansmoon{#1}
        \StrongValidation{\@ansmoon}{\MoonList}
                {moon age}{ObservingRun (sixth parameter)}
}

%% List of all acceptable months
%%
\def\@allMonthList{\\{jan}\\{feb}\\{mar}\\{apr}\\{may}\\{jun}
                        \\{jul}\\{aug}\\{sep}\\{oct}\\{nov}\\{dec}}

%% Macro: @CheckMonth
%%
%% Get a sub-list of the allowed month for a specific telescope and
%% check if the month preference fits with this list.
%%
%% parameters:  #1 telescope
%%              #2 month preference
%%
\def\@CheckMonth#1#2{

        \def\@anstel{#1}
        \def\@ansmonth{#2}

        % If the month is ``any'' skip all the checks.
        \def\@anymonth{any}     

        \ifx\@ansmonth\@anymonth
        \else

                % If ddt check the month with all months
                \if@ddt
                        \StrongValidation{\@ansmonth}{\@allMonthList}
                                {primary month}{ObservingRun (fifth parameter)}
                
                \else   
                        % Get the telescope-months sublist. 
                        % It's assumed that the telescope has a valid code
                        \ismember\@anstel\of\Telescopes
                        \count100=\listposition
                        \select\count100\of\Months\to\telMonthList

                        \StrongValidation{\@ansmonth}{\telMonthList}
                                {primary month}{ObservingRun (fifth parameter)}
                \fi
        \fi
}

%% Macro: @CheckObsMode
%%
%% Strong validation check for the observing mode. Check if the
%% expressed value is compatible with the observation modes allowed
%% for the specific telescope.
%%
%% parameter:   #1 Observing mode requirements (must be v, s, r)
%%
\def\@CheckObsMode#1{
        
        \def\@ansmode{#1}
        \def\@allowedModes{}

        \def\@serviceMode{\\ {s}}
        \def\@visitorMode{\\ {v}}
        \def\@remoteMode{\\ {r}}

        \StrongValidation{\@ansmode}{\ObsModeValues}
                {observing mode}{ObservingRun (eigth parameter)}

        % Determinate allowed observing modes (the choosen telescope
        % sets the boolean flags)
        \if@VisitorMode
                \concatenate{\@allowedModes}={\@allowedModes}&{\@visitorMode}
        \fi

        \if@ServiceMode
                \concatenate{\@allowedModes}={\@allowedModes}&{\@serviceMode}
        \fi

        \if@RemoteMode
                \concatenate{\@allowedModes}={\@allowedModes}&{\@remoteMode}
        \fi

        % Check given mode with allowed observing modes
        \StrongValidation{\@ansmode}{\@allowedModes}
                {observing mode}{ObservingRun (eigth parameter)}
}

%% Macro: CheckSkyTransparency
%%
%% Performs strong validation check.
%%
%% parameter: #1 Seeing requirements (must be PHO, CLR, THN)
%%
\def\@CheckSkyTransparency#1{

        \def\@anstrans{#1}
        \StrongValidation{\@anstrans}{\SkyTransparencyValues}
        {sky transparency requirements}
        {ObservingRun (nineth parameter)}
}

%% Macro: @formatSeeing
%%
%% Print a better seeing format
%%
%% parameter:   #1 Seeing value (numeric or n)
%% 
\def\@formatSeeing#1{
        \def\@anssee{#1}
        \def\@nval{n}
        \ifx\@anssee\@nval
                #1
        \else
                $\le #1''$
        \fi
}

%% Macro: @formatMoonAge
%%
%% Print a better moon age format
%%
%% parameter:   #1 Moon age  value (numeric or n)
%% 
\def\@formatMoonAge#1{
        \def\@ansmoon{#1}
        \def\@nval{n}
        \ifx\@ansmoon\@nval
                #1
        \else
                $\le #1$ days
        \fi
}

%% List of the Observing Run data to be displayed in the telescope box
%% table.
%% 
\def\ObservingRunList{}
\newcount\@obsRunCounter
\@obsRunCounter=0

%% Macro: ObservingRun
%%
%% Validate proposed ObservingRun(s)
%%
%% parameters:  #1 observing run code (single capital letter or letter/alt)
%%              #2 telescope code
%%              #3 instrument code
%%              #4 requested time 
%%              #5 primary month
%%              #6 moon requirements (a char letter code)
%%              #7 seeing requirements (a char letter code)
%%              #9 sky transparency
%%              #8 observing mode (a char letter code)
%%
\def\ObservingRun#1#2#3#4#5#6#7#8#9{

        \def\@monthPar{#5}
        \def\@moonPar{#6}
        \def\@seeingPar{#7}
        \def\@obsmodePar{#9}

        \if@keyprg
                \def\@runMaxNum{13}
        \else
                \def\@runMaxNum{10}
        \fi

        \ifx\@title\@emptyValue
        \else

                \@CheckRunNum{#1}
                \@CheckTelIns{#2}{#3}
                \@CheckTime{#4}         
                \@CheckMonth{#2}{#5}
                \@CheckMoonAge{#6}              
                \@CheckSeeingReq{#7}            
                \@CheckSkyTransparency{#8}
                \@CheckObsMode{#9}              

                \def\runentry{\ \ \ \ \ {#1} & {#2} & {#3} & 
                  {#4} & {#5} & {#6} & \@formatSeeing{#7} & {#8} & {#9} \\}

                % Truncate if there are more than 10 runs...
                \advance\@obsRunCounter by 1
                \ifnum\the\@obsRunCounter>\@runMaxNum
                        \WarningMsg{Observing Run number exceeds the maximum
                                number \@runMaxNum    (included alternatives).
                                Internally truncated in Box 3}
                \else
                        \concatenate{\ObservingRunList}={\ObservingRunList}&{\runentry}
                \fi
        \fi
}

%% Macro: MakeTelescopeBox
%%
%% Create a telescope box: it contains a 5 columns table displaying
%% requested telescopes, instruments, amount of time, observing mode and
%% alternative.
%%
\def\MakeTelescopeBox{

        \ifx\@title\@emptyValue
        \else
                \WeakValidation{\ObservingRunList}
                        {ObservingRun internal list}
                        {ObservingRun (macro never called)}
        \fi

        \setlength{\unitlength}{1mm}

        \def\@telescopeboxTitle{}

        %% 170/6=34mm
        \def\tableHead{\elvsf{\makebox[4mm][l]{3.} Run} & \elvsf{Telescope} & 
                        \elvsf{Instrument} & \elvsf{Time} & 
                        \elvsf{Month} & \elvsf{Moon} & 
                        \elvsf{Seeing} &
                        \elvsf{Sky Trans.} & 
                        \elvsf{Obs.Mode} \\}

        \def\@telescopeText{
                \begin{tabular*}{\@tabInsideBoxLength}[tl]
                {p{18.01mm}p{20mm}p{25mm}p{35mm}p{15mm}p{10mm}p{15mm}p{19mm}p{19mm}}
                \tableHead
                %\\
                \normalsize\ObservingRunList
                \end{tabular*}
        }

        % Create the frame box to house the abstract
        % Note that the box is smaller in case of Large Programme
        \if@keyprg
                \@makeGenericBox{64}{\@telescopeboxTitle}
                        {\normalsize\@telescopeText}
        \else
                \@makeGenericBox{53}{\@telescopeboxTitle}
                        {\normalsize\@telescopeText}
        \fi
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Requested Nights Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Box 4 variables: awarded and required nights
\def\@awardedNightsTelescopes{}
\def\@awardedNightsTime{}
\def\@requiredNightsTelescopes{}
\def\@requiredNightsTime{}

%% Nights macros
\def\AwardedNights#1#2{
        \gdef\@awardedNightsTelescopes{#1}
        \gdef\@awardedNightsTime{#2}
}
\def\FutureNights#1#2{
        \gdef\@requiredNightsTelescopes{#1}
        \gdef\@requiredNightsTime{#2}
}

%% Macro: MakeNightBox
%%
%% Not used for large programmes, it generates box 4 with the
%% indication of how many nights are required for the observing
%% projects (running over more than one period)
%%
\def\MakeNightBox{
        
        \setlength{\unitlength}{1mm}

        % Empty because the actual title is formatted within the table
        \def\@nightboxTitle{}

        \def\@nightboxtableHead{\elvsf{4.\ \ Number of nights/hours} & 
                        \elvsf{Telescope(s)} & 
                        \elvsf{Amount of time} \\}

        \def\@nightboxText{
                
                \begin{tabular*}{\@tabInsideBoxLength}[tl]
                {p{70mm}p{50mm}p{50mm}}

                \@nightboxtableHead
                \tensf{ a) already awarded to this project:} & 
                        \@awardedNightsTelescopes & \@awardedNightsTime \\
                \tensf{ b) still required to complete this project:} & 
                        \@requiredNightsTelescopes & \@requiredNightsTime
                
                \end{tabular*}
        }

        \@makeGenericBox{17}{\@nightboxTitle}{\normalsize\@nightboxText}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Special Remark Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Remarks handling
\def\@specialRemarks{}
\long\def\SpecialRemarks#1{\gdef\@specialRemarks{#1}}

%% Macro: MakeSpecialRemarks
%%
%% It generates box 5 for normal programmes, or box 8 for large
%% programmes, containing special remarks.
%%
\def\MakeSpecialRemarks{

        \if@keyprg
                \def\@remBoxLen{54}
        \else
                \def\@remBoxLen{19}
        \fi     

        \@makeGenericBox{\@remBoxLen}{Special remarks}{\normalsize\@specialRemarks}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Principal Investigator and CoI-Investigators Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% PI's variables
%%
\def\@PIInitials{}
\def\@PISurname{}
\def\@PIAffiliation{}
\def\@PICountry{}
\def\@PIemail{}

%% Macro: PI
%%
%% Check the PI's data performing strong an weak validation for each
%% field.
%%
%% parameters:  #1 PI's initials
%%              #2 PI's family name
%%              #3 PI's institution
%%              #4 PI's country code
%%              #5 PI's email address
%%
\def\PI#1#2#3#4#5{

        \def\piInit{#1}
        \def\piName{#2}
        \def\piInst{#3}
        \def\piCountry{#4}
        \def\piMail{#5}

        % PI parameter validation
        \ifx\@emptyValue\@title
        \else
                \WeakValidation{\piInit}{PI's initials}{PI (first parameter)}
                \WeakValidation{\piName}{PI's surname}{PI (second parameter)}
                \WeakValidation{\piInst}{PI's institution}{PI (third parameter)}
                \StrongValidation{\piCountry}{\Countries}
                        {PI's country code}{PI (fourth parameter)}
                \WeakValidation{\piMail}{PI's e-mail address}{PI (fifth parameter)}
        \fi

        % Set the PI variables
        \gdef\@PIInitials{#1}
        \gdef\@PISurname{#2}
        \gdef\@PIAffiliation{#3}
        \gdef\@PICountry{#4}
        \gdef\@PIemail{#5}
}

%% CoI list
%%
\def\@CoIList{}

%% CoI counter
%%
\newcounter{CoIcounter}

%% Macro: CoI
%%
%% Verify the CoI entry and append it to the CoI list.
%%
%% parameters:  #1 CoI's initials
%%              #2 CoI's family name
%%              #3 CoI's institution
%%              #4 CoI's country code
%%
\def\CoI#1#2#3#4{

        %% Max number of allowed CoIs per proposal
        \if@keyprg
                \def\@CoIMaxNum{25}
        \else
                \def\@CoIMaxNum{20}
        \fi

        % \@CoIMaxNum is the max number of CoIs in the list.
        \addtocounter{CoIcounter}{1}
        \def\coinumber{\theCoIcounter}

        \def\coiInit{#1}
        \def\coiName{#2}
        \def\coiInst{#3}
        \def\coiCountry{#4}

        % CoI parameter validation
        \ifx\@emptyValue\@title
        \else
                \WeakValidation{\coiInit}{CoI's initials}{CoI (first parameter)}
                \WeakValidation{\coiName}{CoI's surname}{CoI (second parameter)}
                \WeakValidation{\coiInst}{CoI's institution}{CoI (third parameter)}
                \StrongValidation{\coiCountry}{\Countries}
                        {CoI's country code}{CoI (fourth parameter)}
        \fi

        % Spacing for the first element is different
        \ifx \@CoIList\empty
                \def\@CoIName{{#1} \ {#2} ({#3}, {#4})}
        \else
                \def\@CoIName{,\ \ {#1} \ {#2} ({#3}, {#4})}
        \fi

        \ifnum\coinumber>\@CoIMaxNum
                \WarningMsg{CoI number exceeds the maximum
                        number \@CoIMaxNum. CoI list internally truncated}
                % \@mg{ERROR - Line \the\inputlineno:
                %        More than \@CoIMaxNum\ CoIs!}
                % \@stm
        \else
        
                % Append to the CoI list                
                \concatenate{\@CoIList}={\@CoIList}&{\@CoIName}
        \fi
}

%% Macro: MakeInvestigator
%%
%% Create the PI and CoI box.
%%
\def\MakeInvestigator{

        \ifx\@title\@emptyValue
        \else
                \WeakValidation{\@PISurname}
                        {Principal Investigator}
                        {PI (macro never called)}
        \fi

        \def\@investigator{
                \vbox{
                        % Line length
                        \hsize=130mm
                        \svtnsf{\@PIInitials \ \@PISurname\ } 
                        \normalsize{(\@PIAffiliation ,\ \@PICountry ,\ \@PIemail)}
                }
        }
 
        \def\@coinvestigatorsText{
                \vbox{
                        % Line length
                        \hsize=170mm
                        \elvsf{CoI(s): \ }
                        \normalsize\@CoIList
                }
        }

        \if@keyprg
                \def\@invBoxLen{52}
        \else
                \def\@invBoxLen{38}
        \fi     

        \@makeGenericBox{\@invBoxLen}{Principal Investigator: \@investigator}
               {\normalsize\@coinvestigatorsText}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      PhD Thesis Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Thesis variable
%%
\def\@PhDthesis{}

%% Thesis status allowed values (s, m, n).
%%
\def\@PhDthesisValue{\\{s}\\{m}\\{n}}

%% Macro: Thesis
%%
%% Check the thesis data.
%%
%% parameters:  #1 Student name
%%              #2 Thesis status (s, m, n)
%%
\def\Thesis#1#2{

        \def\thesisStatus{}
        \def\@studentName{#1}
        \def\@ansStatus{#2}

        \ifx\@title\@emptyValue
        \else
                % Student name weak validation: it shouldn't be empty
                \WeakValidation{\@studentName}
                        {student name}{Thesis (first parameter)}

                % Thesis status strong validation
                \StrongValidation{\@ansStatus}{\@PhDthesisValue}
                        {thesis status}{Thesis (second parameter)}

                \if s#2 {\gdef\thesisStatus{starting}}\fi
                \if m#2 {\gdef\thesisStatus{mid-course}}\fi
                \if n#2 {\gdef\thesisStatus{near completion}}\fi
        \fi

        \gdef\@PhDthesis{Yes \ \ / \ \ {#1} \ \ / \ \ {\thesisStatus}}
}

%% Macro: MakeThesis
%%
%% Generate the thesis box.
%%
\def\MakeThesis{

        \def\@thesisBoxTitle{Is this proposal linked to the PhD thesis 
                preparation of one of the applicants?}

        \@makeGenericBox{13}{\@thesisBoxTitle}{\normalsize\@PhDthesis}  
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Description Boxes
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Observation description fields.
%%
\def\@scientificRationale{}
\long\def\ScientificRationale#1{\gdef\@scientificRationale{#1}}

\def\@immediateObjective{}
\long\def\ImmediateObjective#1{\gdef\@immediateObjective{#1}}

\def\@telescopeJustification{}
\long\def\TelescopeJustification#1{\gdef\@telescopeJustification{#1}}

\def\@obsModeJustification{}
\long\def\ModeJustification#1{\gdef\@obsModeJustification{#1}}

\def\@strategy{}
\long\def\Strategy#1{\gdef\@strategy{#1}}

\def\@strategy{}
\long\def\Strategy#1{\gdef\@strategy{#1}}

%% List of contents to be written on the additional pages.
%%
\def\@additionalBoxList{}

%% Macro: MakeCaption
%%
%% Write the additional text on the additional description pages.
%%
%% parameter:   #1 Additional (latex) text
%%
\long\def\MakeCaption#1{

        \def\@attachedText{#1}

        \ifx\@emptyValue\@attachedText
        \else
                \def\@attachedTexTBox{
                        \vbox{
                                % Line length
                                \hsize=170mm
                                \normalsize{#1}
                                \vspace{1cm}
                                \vfill
                        }
                }

                \concatenate{\@additionalBoxList}={\@additionalBoxList}&{\@attachedTexTBox}             
        \fi
}

%% If a slash is written in the file name it is a absolute pathname
\def\@absPathNameChar{/}

%% If a comma is written in the file name it is a wrong filename
\def\@commaChar{,}

%% Macro: @scanFileName
%%
%% Tricky, it uses tail recursion to parse each single character
%% contained in the input string.
%%
%% parameter:   #1 Input string (and then single char).
%%
\def\@scanFileName#1{

        \ifx#1\@endchar 
                \let\next=\relax
        \else
                % \typeout{checking character {#1}}
                
                \def\given{#1}

                \ifx\given\@absPathNameChar
                        \@mg{ERROR - Line \the\inputlineno: 
                                Absolute file path name in macro MakePicture!}
                        \@stm
                \fi

                \ifx\given\@commaChar
                        \@mg{ERROR - Line \the\inputlineno: 
                                Wrong file name in macro MakePicture!}
                        \@stm
                \fi

                \advance\strCount by1 
                \let\next=\@scanFileName
        \fi

        % Tail recursion
        \next
}


%% Macro: MakePicture
%%
%% parameters:  #1 PostScript file
%%              #2 Picture label
%%              #3 width or length specified in the psfig format
%%                 Ex: width=10cm, height=15cm
%%
\def\MakePicture#1#2#3{

        \@ifundefined{psfig}{
                % \WarningMsg{Cannot attach pictures: 
                %       psfig utility not found}        
        }{
                \def\@psFile{#1}

                % Check the path (reject absolute paths)
                \strCount=0
                \@scanFileName#1\@endchar

                \def\@picLabel{#2}
                \def\@picFormat{#3}

                \ifx\@emptyValue\@psFile
                \else
                        % Create a vertical box to host the picture
                        \def\@pictureBox{
                                \vbox{
                                        \ifx\@emptyValue\@picFormat
                                                \centerline{
                                                        \psfig{figure=#1,silent=1}
                                                }
                                        \else
                                                \centerline{
                                                        \psfig{figure=#1,silent=1,#3}
                                                }
                                        \fi

                                        \centerline{#2}

                                        \vspace{1cm}
                                        \vfill
                                }
                        }

                        \concatenate{\@additionalBoxList}={\@additionalBoxList}&{\@pictureBox}
                \fi
        }
}

%% Macro: MakeAdditionalPages
%%
%% Generate the picture pages, splitting the pictures
%% into two (max) pages.
%%
\def\MakeAdditionalPages{

        \def\@verticalPictureBox{
                \vbox{
                        % Line length
                        \hsize=170mm
                        \normalsize\@additionalBoxList
                }
        }

        % Split the description into three parts (box111, box112,
        % box113) that should be written as two different pages.
        \setbox200=\@verticalPictureBox
        \setbox201=\vsplit200 to \@maxDescrLen
        \setbox202=\vsplit200 to \@maxDescrLen
        \setbox203=\vsplit200 to \@maxDescrLen

        % If the first box is not empty, generate a page to contain
        % the associated text.
        \ifvbox201

                \begin{picture}(\@pageWidth,\@pagetwolength)

                \makebox(\@pageWidth,\@pagetwolength)[tl]{
                        \vbox{
                                \@bNewBoxfalse
                                \@makeGenericBox{\@pagetwolength}
                                        {\@descriptionboxPicTitle \@h}
                                        {\box201 \@h}

                                \MakePageNumber
                        }
                }

                \end{picture}
                \vfill
                \pagebreak
        \fi

        % If the second box is not empty, generate a page to contain
        % the associated text.
        \ifvbox202

                \begin{picture}(\@pageWidth,\@pagetwolength)
                
                \makebox(\@pageWidth,\@pagetwolength)[tl]{
                        \vbox{
                                \@bNewBoxfalse
                                \@makeGenericBox{\@pagetwolength}
                                        {\@descriptionboxPicTitle \@h}
                                        {\box202 \@h}

                                \MakePageNumber
                        }
                }

                \end{picture}
                \vfill
                \pagebreak
        \fi

        % If the third box is not empty the description exceeds two
        % pages, truncate it and display a warning message
        \ifvbox203
                \WarningMsg{Attached pictures and text exceed 2 pages.
                        Internally truncated in macro MakeAdditionalPages}
        \fi
}

%% Backup programme (only normal programmes)
\def\@backUpProgramme{}

%% Macro: BackUpProgramme
%%
%% Generate a backup programmes description page.
%% parameter: #1 Backup programme
%%
\long\def\BackUpProgramme#1{

        \if@keyprg
                % Only normal programmes !!
        \else

                \gdef\@backUpProgramme{#1}      

                % % Backup programme weak validation: it shouldn't be
                % % empty
                % \WeakValidation{\@backUpProgramme}
                %       {backup programme}{BackUpProgramme}
        \fi
}

%% Macro: MakeBackUpProgrammePage
%%
%% Generate a backup programme page..
%%
\def\MakeBackUpProgrammePage{

        \def\@verticalBackUpBox{
                \vbox{
                        % Line length
                        \hsize=170mm
                        \normalsize\@backUpProgramme

                        % Needed in order to prevent text vertical stretching
                        % Bug fixed: C. Boarotto 09-Sep-98
                        \vfill
                }
        }

        % Split the description into two parts (box211,
        % box212). Truncate to one page
        \setbox210=\@verticalBackUpBox
        \setbox211=\vsplit210 to \@maxDescrLen
        \setbox212=\vsplit210 to \@maxDescrLen

        % If the first box is not empty, generate a page to contain
        % the associated text.
        \ifvbox211

                \begin{picture}(\@pageWidth,\@pagetwolength)

                \makebox(\@pageWidth,\@pagetwolength)[tl]{
                        \vbox{
                                \@bNewBoxfalse
                                \@makeGenericBox{\@pagetwolength}
                                        {\@descriptionboxBackUpTitle \@h}
                                        {\box211 \@h}

                                \MakePageNumber
                        }
                }

                \end{picture}
                \vfill
                \pagebreak
        \fi

        % If the second box is not empty the description exceeds two
        % pages, truncate it and display a warning message
        \ifvbox212
                \WarningMsg{Backup programme text exceed 2 pages.
                        Internally truncated in macro MakeBackUpProgramme}
        \fi
}

%% Macro: MakeDescriptionPages
%%
%% Generate the description pages, splitting the description fields
%% into two (max) pages.
%%
\def\MakeDescriptionPages{
        
        \@setArticleSettings
        
        \ifx\@emptyValue\@title
        \else
                % Scientific rationale weak validation: it shouldn't be empty
                \WeakValidation{\@scientificRationale}
                        {scientific rationale}{ScientificRationale}
                % Immediate objective weak validation: it shouldn't be empty
                \WeakValidation{\@immediateObjective}
                        {immediate objective}{ImmediateObjective}

                \WeakValidation{\@telescopeJustification}
                        {telescope justification}{TelescopeJustification}
                
                \WeakValidation{\@obsModeJustification}
                        {observation mode justification}{ModeJustification}
                
                \if@keyprg
                \else
                        \WeakValidation{\@strategy}
                                {strategy}{Strategy}
                \fi
        \fi

        \def\@descriptionboxTitle{Description of the proposed programme}
        \def\@descriptionboxTitleCont{Description of the proposed programme (continued)}
        \def\@descriptionboxPicTitle{Attachments (Figures)}
        \def\@descriptionboxBackUpTitle{Backup Programme}

        \rightmargin 30mm

        \def\@descriptionboxText{
                \vbox{
                        % Line length
                        \hsize=170mm

                        \vspace{3mm}
                        \elvsf{A) Scientific Rationale: \ }
                        \normalsize\@scientificRationale
                        \vfill
                
                        \vspace{3mm}
                        \elvsf{B) Immediate Objective: \ }
                        \normalsize\@immediateObjective
                        \vfill

                        \vspace{3mm}
                        \elvsf{C) Telescope Justification: \ }
                        \normalsize\@telescopeJustification
                        \vfill
                        
                        \vspace{3mm}
                        \elvsf{D) Observing Mode Justification 
                                (visitor or service): \ }
                        \normalsize\@obsModeJustification

                        % Strategy only for normal programmes
                        \if@keyprg
                        \else
                                \vfill
                                \vspace{3mm}
                                \elvsf{E) Strategy for Data Reduction and Analysis: \ }
                                \normalsize\@strategy
                        \fi

                        % Needed in order to prevent text vertical stretching
                        \vfill
                }
        }

        % Necessary to avoid nasty Underfull \vbox (badness 10000)
        % error message
        \vbadness=1000000
        \hbadness=1000000

        % Max text length within the page (and the frame)
        \def\@maxDescrLen{260mm}        

        % Split the description into three parts (box101, box102,
        % box103) that should be written as two different pages.
        \setbox100=\@descriptionboxText
        \setbox101=\vsplit100 to \@maxDescrLen
        \setbox102=\vsplit100 to \@maxDescrLen
        \setbox103=\vsplit100 to \@maxDescrLen
        \setbox104=\vsplit100 to \@maxDescrLen

        % If the first box is not empty, generate a page to contain
        % the associated text.
        \ifvbox101

                \begin{picture}(\@pageWidth,\@pagetwolength)
                
                \makebox(\@pageWidth,\@pagetwolength)[tl]{
                        \vbox{
                                \@makeGenericBox{\@pagetwolength}
                                        {\@descriptionboxTitle \@h}{\box101 \@h}

                                \MakePageNumber
                        }
                }

                \end{picture}
                \vfill
                \pagebreak
        \fi

        % If the second box is not empty, generate a page to contain
        % the associated text.
        % Split the description into three parts (box101, box102,
        % box103) that should be written as two different pages.
        \ifvbox102

                \begin{picture}(\@pageWidth,\@pagetwolength)
                
                \makebox(\@pageWidth,\@pagetwolength)[tl]{
                        \vbox{
                                \@bNewBoxfalse
                                \@makeGenericBox{\@pagetwolength}
                                        {\@descriptionboxTitleCont \@h}{\box102 \@h}

                                \MakePageNumber
                        }
                }

                \end{picture}
                \vfill
                \pagebreak
        \fi

        % Large Programmes provide three description pages. Normal
        % programmes just two pages.
        % Bug fixed: C.Boarotto 21-Sep-98
        \if@keyprg

                % If the third box is not empty, generate a page to
                % contain the associated text.
                % LARGE PROGRAMMES ONLY
                \ifvbox103

                        \begin{picture}(\@pageWidth,\@pagetwolength)
                        
                        \makebox(\@pageWidth,\@pagetwolength)[tl]{
                                \vbox{
                                        \@bNewBoxfalse
                                        \@makeGenericBox{\@pagetwolength}
                                                {\@descriptionboxTitleCont \@h}
                                                {\box103 \@h}

                                        \MakePageNumber
                                }
                        }

                        \end{picture}
                        \vfill
                        \pagebreak
                \fi

                % If the fourt box is not empty the description
                % exceeds three pages, truncate it and display a warning
                % message
                % LARGE PROGRAMMES ONLY
                \ifvbox104
        
                        \WarningMsg{Description exceeds 3 pages. 
                        Internally truncated in macro MakeDescriptionPages}
                \fi

        \else

                % If the third box is not empty the description
                % exceeds two pages, truncate it and display a warning
                % message.
                % NORMAL PROGRAMMES ONLY
                \ifvbox103

                        \WarningMsg{Description exceeds 2 pages. 
                        Internally truncated in macro MakeDescriptionPages}
                \fi
        \fi
        
        % Make additional pages if the additional boxes list is not empty
        \ifx\@emptyValue\@additionalBoxList
        \else
                \MakeAdditionalPages
        \fi

        % Make backup pages if the backup programme is not empty
        \ifx\@emptyValue\@backUpProgramme
        \else
                \MakeBackUpProgrammePage
        \fi

        \@unsetArticleSettings
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Applicant's Experience Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Applicant's experience handling
%%
\def\@experience{}
\long\def\Experience#1{\gdef\@experience{#1}}

%% Macro: MakeExperienceBox
%%
%% Generate a box to contain the @experience text.
%%
\def\MakeExperienceBox{

        % Weak validation
        \ifx\@emptyValue\@title
        \else
                \WeakValidation{\@experience}{experience}{Experience}
        \fi

        \def\@experienceboxTitle{Experience of the applicants with telescopes, 
                        instruments and data reduction}

        \@makeGenericBox{114}
                {\@experienceboxTitle}{\normalsize\@experience}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Resources Availability Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Resources handling
%%
\def\@resources{}
\long\def\Resources#1{\gdef\@resources{#1}}

%% Macro: MakeResourcesBox
%%
%% Generate a box to contain the @resources text.
%%
\def\MakeResourcesBox{

        % Weak validation
        \ifx\@emptyValue\@title
        \else
                \WeakValidation{\@resources}{resources}{Resources}
        \fi

        \def\@resourcesboxTitle{Resources available to the team, such as: 
                        computing facilities, research assistants, etc.}

        \@makeGenericBox{107}
                {\@resourcesboxTitle}{\normalsize\@resources}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Justification of requested observing time
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Why Nights and Lunar Phase text variables
%%
\def\@whyNights{}
\def\@whyLunarPhase{}
\long\def\WhyNights#1{\gdef\@whyNights{#1}}
\long\def\WhyLunarPhase#1{\gdef\@whyLunarPhase{#1}}

%% Exposure time calculator
\def\@expTCBox{}

%% Macro: ExposureTimeCalculator
%%
%% parameters:  #1 instrument
%%              #2 version
%%
\def\ExposureTimeCalculator#1#2{

        \gdef\@expTCBox {
                \parbox[tl]{\@tabInsideBoxLength}{
                        \elvsf{Exposure Time Calculator:}
                        \@h
                        \elvsf{Instrument: }\normalsize{#1}
                        \@h
                        \elvsf{Version: }\normalsize{#2}
                        \@h
                }
        }
}

\def\@stdCalibration{Standard Calibration}
\def\@isStdCalibrationSet{}
\def\@calibrationRequest{\@stdCalibration}

%% Macro: MakeNightLunarPhase
%%
%% Set the internal variable containing the special calibration
%% requested to the default value (standard calibration).
%%
\def\StandardCalibrations{
        \gdef\@calibrationRequest{\@stdCalibration}
        \gdef\@isStdCalibrationSet{set}
}

%% Macro: SpecialCalibration
%%
%% Set the internal variable containing the special calibration
%% requested. It shouldn't be empty.
%%
\def\SpecialCalibrations#1{

        \ifx\@emptyValue\@isStdCalibrationSet
        \else
                \WarningMsg{Standard calibration already requested}
        \fi

        \gdef\@calibrationRequest{#1}

        % Special calibration weak validation: it shouldn't be empty
        \ifx\@emptyValue\@title
        \else
                \WeakValidation{\@calibrationRequest}
                        {special calibration request}{SpecialCalibration}
        \fi
}

%% Large programme conversion internal variables
%%
\def\@convertToNormal{Yes}
\def\@dontConvertToNormal{No}
\def\@largeProgrammeConversion{\@dontConvertToNormal}

%% Macro: ConvertLargeToNormal
%%
%% Allow the user to specify that he wants the programme to be run as a
%% normal programme if no time has been granted as large programme.
%%
\def\ConvertLargeToNormal{
  \gdef\@largeProgrammeConversion{\@convertToNormal} 
}

%% Macro: DontConvertLargeToNormal
%%
%% Allow the user to specify that he doesn't want the programme to be run
%% as a normal programme if no time has been granted as large programme.
%%
\def\DoNotConvertLargeToNormal{
  \gdef\@largeProgrammeConversion{\@dontConvertToNormal} 
}

%% Macro: MakeNightLunarPhase
%%
%% Generate box 9 for both large and normal programmes, containing the
%% justification (text) of requested observing time and lunar phase.
%%
\def\MakeNightLunarPhase{

        \@setArticleSettings

        % Why Nights weak validation: it shouldn't be empty
        % Lunar Phase weak validation: it shouldn't be empty
        \ifx\@emptyValue\@title
        \else
                \WeakValidation{\@whyNights}
                        {nights justification}{WhyNights}
                \WeakValidation{\@whyLunarPhase}
                        {lunar phase justification}{WhyLunarPhase}
        \fi

        \def\@nightlunarphaseboxTitle{Justification of requested observing time and lunar phase}

        \if@keyprg
                \def\@nightlunarphaseboxLen{140}
                \def\@textLen{130mm}
        \else
                \def\@nightlunarphaseboxLen{112}
                \def\@textLen{102mm}
        \fi

        \def\@nightlunarbox{
                \vbox {
                        % Line length
                        \hsize=170mm

                        \ifx\@expTCBox\@emptyValue
                        \else
                                \@expTCBox
                                \vfill
                        \fi     

                        \vspace{3mm}
                        \elvsf{Lunar Phase Justification: \ } 
                        \normalsize\@whyLunarPhase
                        \vfill
                
                        \vspace{3mm}
                        \elvsf{Time Justification: \ } 
                        \normalsize\@whyNights
                        \vfill

                        \vspace{3mm}
                        \elvsf{Calibration Request: \ } 
                        \normalsize\@calibrationRequest

                        \if@keyprg 
                        \vspace{3mm}
                        \elvsf{Convert to a normal programme? \ } 
                        \normalsize\@largeProgrammeConversion
                        \fi
                }
        }

        \setbox110=\@nightlunarbox
        \setbox111=\vsplit110 to \@textLen
        \setbox112=\vsplit110 to \@textLen

        \ifvbox112
                \WarningMsg{Description exceeds the maximum text length. 
                        Internally truncated in macro MakeNightLunarPhase}
        \fi


        \@makeGenericBox{\@nightlunarphaseboxLen}
                {\@nightlunarphaseboxTitle}{\box111}

        \@unsetArticleSettings
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Report of Last Observation Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Variable to handle last programme data
%%
\def\@lastProgramme{}

%% Macro: LastProgramme
%%
%% If the first parameter is empty don't verify the others, otherwise
%% check if the second and the third parameters are empty.
%%
%% parameters:  #1 Last programme ID
%%              #2 Last programme PI
%%              #3 Last programme title
%%
\def\LastProgramme#1#2#3{

        \def\parA{#1}
        \def\parB{#2}
        \def\parC{#3}

        \ifx \parA\@emptyValue

                % Last programme not defined, OK, skip any further
                % verification

        \else
                \WeakValidation{\parB}
                        {last programme PI}{LastProgramme (second parameter)}
                \WeakValidation{\parC}{last programme title}
                        {LastProgramme (third parameter)}
                \gdef\@lastProgramme{{#1}\ /\ {#2}\ /\ {#3}}
        \fi
}

%% Variable to handle last observation data (it's a list)
%%
\def\@lastObservationList{}

%% Variable to store time lost reason values
%%
\def\@timelostReasonValues{\\{weather}\\{technical}\\{ToO}\\{none}}

%% Macro: LastObservation
%%
%% If the first parameter is empty don't verify the others, otherwise
%% check if the other parameters are empty.
%%
%% parameters:  #1 Last observation telescope
%%              #2 Last observation instrument
%%              #3 Last observation dates
%%              #4 Last observation completed fraction
%%              #5 Last observation time lost fraction
%%              #6 Last observation reason for time lost (weather 
%%                 or technical)
%%
\def\LastObservation#1#2#3#4#5#6{

        \def\parA{#1}
        \def\parB{#2}
        \def\parC{#3}
        \def\parD{#4}
        \def\parE{#5}
        \def\parF{#6}

        \ifx \parA\@emptyValue
                % Last observation not defined, OK, skip any further
                % verification
        \else
                \WeakValidation{\parB}
                        {instrument code}{LastObservation (second parameter)}
                \WeakValidation{\parC}
                        {dates}{LastObservation (third parameter)}
                \WeakValidation{\parD}
                        {completed fraction}{LastObservation (fourth parameter)}
                \WeakValidation{\parE}
                        {time lost fraction}{LastObservation (fifth parameter)}
                % \StrongValidation{\parF}{\@timelostReasonValues}
                %       {time lost reason}{LastObservation (sixth parameter)}

                % Spacing for the first element is different
                \def\tableEntry{{#1} & {#2} & {#3} & {#4\%} & {#5\%} & {#6} \\}

                % Append to the last observation list           
                \concatenate{\@lastObservationList}={\@lastObservationList}&{\tableEntry}
        \fi
}

%% Data reduction handling.
%%
\def\@dataReductionStatus{}
\def\@dataReductionStatusValues{\\{paper-submitted}\\{paper-in-press/published}}

%% Macro: Datareduction
%%
%% Verify the entered parameter
%%
\def\Datareduction#1{
        
        \def\param{#1}

        \ifx \@emptyValue\param
                % Skip, OK
        \else   
                \ifx\@emptyValue\@dataReductionStatus
                \else
                        \WarningMsg{Data reduction status already defined}
                \fi

                % If no empty it has to be one of the allowed values
                \StrongValidation{\param}{\@dataReductionStatusValues}
                                {data reduction status}{Datareduction}
                \gdef\@dataReductionStatus{#1}
        \fi
}

%% Last observation remark handling.
%%
\def\@lastObservationRemark{}
\long\def\LastObservationRemark#1{\gdef\@lastObservationRemark{#1}}

%% Macro: MakeLastProgramme
%%
%% Generate box 10 for normal programmes, containing the report of
%% the last use of the ESO facilities in Chile.
%%
\def\MakeLastProgramme{

        \if@test
                \ifx \@emptyValue\@lastProgramme
                        % Ignore the following fields
                \else
                        % If last programme has been specified, the
                        % last observation list shall not be empty
                        \ifx \@emptyValue\@lastObservationList
                                \@mg{ERROR - Line \the\inputlineno: 
                                        Missing last observation data 
                                        when last programme has been defined 
                                        (macro LastObservation empty)!}
                                \@stm
                        \fi
                \fi
        \fi

        \def\@lastProgrammeBoxTitle{Report on the last use of ESO facilities}
        
        %% 170/6=34mm
        \def\tableHead{\elvsf{Telescope} & \elvsf{Instrument} & 
                        \elvsf{Obs. Dates} & \elvsf{Completion (\%)} & 
                        \elvsf{Time lost (\%)} & 
                        \elvsf{Reason} \\}

        \def\@lastProgrammeBoxText{
                \vbox{
                        \hbox{\@lastProgramme}
                        \vspace{3mm}
                        \hbox{
                                \hspace{-2.5mm}
                                \begin{tabular*}{\@tabInsideBoxLength}[tl]
                                {p{28mm}p{28mm}p{30mm}p{28mm}p{28mm}p{28mm}}
                                \tableHead
                                \\
                                \normalsize\@lastObservationList
                                \end{tabular*}
                        }
                        \vspace{3mm}
                        \hbox{
                                \hspace{-5mm}
                                \elvsf{Current status of obtained data: \ }
                                \normalsize\@dataReductionStatus
                        }
                        % Line length
                        \hsize=170mm
                        \vspace{3mm}
                        \elvsf{Remarks:\ }
                        \normalsize\@lastObservationRemark
                }
        }                       

        \def\@textLen{55mm}     
        \setbox110=\@lastProgrammeBoxText
        \setbox111=\vsplit110 to \@textLen
        \setbox112=\vsplit110 to \@textLen

        \ifvbox112
                \WarningMsg{LastObservationRemark exceeds the maximum
                        text length. Internally truncated in macro 
                        MakeLastProgramme}
        \fi

        \@makeGenericBox{65}{\@lastProgrammeBoxTitle}
                {\normalsize\box111}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Publication Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Publication handling
%%
\def\@publications{}
\long\def\Publications#1{\gdef\@publications{#1}}

%% Macro: MakePubblications
%%
%% Generate box 11 for large programmes or box 11 for normal
%% programmes, containing the list of all related publications.
%%
\def\MakePublications{

        \def\@publicationsboxTitle{Applicant's publications related 
                to the subject of this application during the past two years}

        \if@keyprg
                \def\@publicationsboxLen{137}
        \else
                \def\@publicationsboxLen{98}
        \fi

        \def\@publicationsboxText{\parbox[t]{\@tabInsideBoxLength}{\@publications}}

        \@makeGenericBox{\@publicationsboxLen}
                {\@publicationsboxTitle}{\normalsize\@publicationsboxText}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Target Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\@runsHavingTargets{}

%% Macro: @scanRunID
%%
%% Tricky, it uses tail recursion to parse each single character
%% contained in the input string.
%%
%% parameter:   #1 Input string (and then single char).
%%
\def\@scanRunID#1{

        \ifx#1\@endchar 
                \let\next=\relax
        \else
                %\typeout{checking character {#1}}
                
                \def\given{#1}
                \StrongValidation{\given}{\@RunCodeList}
                {run ID}{Target (second parameter)}
                
                % Append the run code to the list of the runs having 
                % at least one target
                \ismember\given\of\@runsHavingTargets
                \if@ismember
                \else
                        \def\@runentry{\\ {#1}}
                        \concatenate{\@runsHavingTargets}={\@runsHavingTargets}&{\@runentry}
                \fi

                \advance\strCount by1 
                \let\next=\@scanRunID           
        \fi

        % Tail recursion
        \next
}

%% Macro: @checkTargetRun
%%
%% Used to invoke @scanchar.
%%
%% parameter:   #1 Input string (ex: ``ABCDE'').
%%
\def\@checkTargetRun#1{
        \strCount=0
        \@scanRunID#1\@endchar
}

%% Target list variable
%%
\def\@targetList{}

%% Macro: Target
%%
%% Add a target to the target list after validating its fields.
%%
%% parameters:  #1 observing run code
%%              #2 target name
%%              #3 target right ascension (alpha)
%%              #4 target declination (delta)
%%              #5 target epoch
%%              #6 target magnitude (optional)
%%              #7 target diameter (optional)
%%              #8 target additional information (optional)
\def\Target#1#2#3#4#5#6#7#8{

        \def\tRunIDs{#1}

        % Run checks only if it is not test mode (title not empty)
        \ifx\@emptyValue\@title
        \else

        \@checkTargetRun{#1}

        \def\tName{#2}
        \def\tRa{#3}
        \def\tDec{#4}
        \def\tEpoch{#5}
        \def\tMag{#6}
        \def\tDiam{#7}
        \def\tInfo{#8}

        % Run reference weak validation
        \WeakValidation{\tRunIDs}
        {observing run code}{Target (first parameter)}

        % Name weak validation
        \WeakValidation{\tName}
        {target name}{Target (second parameter)}

        % Ra weak validation
        \WeakValidation{\tRa}
        {target right ascension}{Target (third parameter)}

        % Dec weak validation
        \WeakValidation{\tDec}
        {target declination}{Target (fourth parameter)}

        % Epoch weak validation
        \WeakValidation{\tEpoch}
        {target epoch}{Target (fifth parameter)}

        % No validations for optional fields
        \def\tableEntry{\ninerm{#1} & \ninerm{#2} & \ninerm{#3} & \ninerm{#4} & 
                \ninerm{#5} & \ninerm{#6} & \ninerm{#7} & \ninerm{#8}\\}

        % Append to the target list             
        \concatenate{\@targetList}={\@targetList}&{\tableEntry}
        \fi
}

%% Target notes handling
%%
\def\@targetsNotes{}
\long\def\TargetNotes#1{\gdef\@targetsNotes{#1}}


%% Macro: checkRunsAndTargets
%%
%% Check that all the runs defined in the run box have at least one target. 
%% For each run defined in the \@RunCodeList list verify that a corresponding 
%% code is defined also in the \@runsHavingTargets list.
%%
\def\@checkRunsAndTargets{

        % Counters
        \newcount\runCount
        \newcount\tmprunCount
        \newcount\runLen
        \runCount=1

        \cardinality\@RunCodeList\to\runLen
        \advance\runLen by1

        \def\@runlength{\the\runLen}
        \def\@runerrorList{}

        % LOOP:
        % For each run defined in the \@RunCodeList list verify that a
        % corresponding  code is defined also in the \@runsHavingTargets 
        % list.
        %
        % BUG FIXED: extra emtpy lines REMOVED in the LOOP code
        % otherwise it fails on some systems (different latex 
        % installations).
        \loop\ifnum\runCount<\@runlength
                % A temporary counter is necessary because its value
                % is modified when used in the ``select'' macro
                \tmprunCount=\the\runCount
                \select\tmprunCount\of\@RunCodeList\to\@tmpRunCode
                % Check @tmpRunCode if is member of the list of runs 
                % having targets
                \ismember\@tmpRunCode\of\@runsHavingTargets
                \if@ismember
                \else
                        % Not a member: i.e. the run doesn't have targets
                        \@mg {ERROR - Run {\@tmpRunCode} has no targets.
                          Please define at least one target for the observing
                          run {\@tmpRunCode}.}
                        \def\@runerrorList{yes}
                \fi
                \advance\runCount by1
        \repeat

        % In case of errors exit...
        \ifx\@emptyValue\@runerrorList
        \else
                \@stm
        \fi
  
}


%% Macro: MakeTargets
%%
%% Generate box 11 for large programmes or box 12 for normal
%% programmes, containing the target list and the target notes.
%%
\def\MakeTargets{

        \@checkRunsAndTargets

        \def\@targetsboxTitle{List of targets proposed in this programme}

        \def\tableHead{\tensf{Run} & \tensf{Target/Field} & \tensf{$\alpha$} & 
                        \tensf{$\delta$} & \tensf{Equinox} & 
                        \tensf{Mag.} & \tensf{Diam.} & 
                        \tensf{Additional information}\\}

        \def\@targetsboxText{
                \vbox{
                        \hbox{
                                \begin{tabular*}{\@tabInsideBoxLength}[tl]
                                {p{17mm}p{30mm}p{20mm}p{20mm}p{15mm}p{15mm}p{15mm}p{38mm}}
                                \tableHead
                                % Don't delete the ``\\" at the end of the following line
                                \multicolumn{8}{l}{\rule{\@tabInsideBoxLength}{.3mm}} \\
                                \@targetList
                                \end{tabular*}
                        }
                        
                        \ifx \@emptyValue\@targetsNotes
                        \else
                                \vspace{10mm}
                                \parbox[t]{\@tabInsideBoxLength}{
                                        \elvsf{Target Notes:}
                                        \normalsize\@targetsNotes
                                }
                        \fi
                }
        }

        \@makeGenericBox{\@pagetwolength}
                {\@targetsboxTitle}{\normalsize\@targetsboxText}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Scheduling Information Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% List of allowed symbols in the split algebra field 
\def\@splitSymbolList{}
\def\@newsymbols{\\{,}\\{w}\\{s}}
\concatenate{\@splitSymbolList}={\@TimeSymbolList}&{\@newsymbols}

%% Macro: @scanSplitSyntax
%%
%% Tricky, it uses tail recursion to parse each single character
%% contained in the input string.
%%
%% parameter:   #1 Input string (and then single char).
%%
\def\@scanSplitSyntax#1{

        \ifx#1\@endchar 
                \let\next=\relax
        \else
                % \typeout{@scanSplitSyntax checking character {#1}}
                
                \def\given{#1}
                \StrongValidation{\given}{\@splitSymbolList}
                        {split syntax symbol}{Split (second parameter)}

                \advance\strCount by1 
                \let\next=\@scanSplitSyntax             
        \fi

        % Tail recursion
        \next
}

%% Split list
%%
\def\@splitList{}

%% Macro: RunSplitting
%%
%% Define subruns using the ``scheduling algebra'' and display within
%% a table.
%%
%% parameters:  #1 run code
%%              #2 subruns splitting
%%
\def\RunSplitting#1#2{

        \def\@rcode{#1}

        % Run checks only if it is not test mode (title not empty)
        \ifx\@emptyValue\@title
        \else

            \ifx\@rcode\@emptyValue
            \else

                \StrongValidation{\@rcode}{\@RunCodeList}
                        {run ID}{Split (first parameter)}

                \def\@splitting{#2}

                \WeakValidation{\@splitting}
                        {splitting}{Split (second parameter)}

                % OK, not empty. Check single characters
                \strCount=0
                \@scanSplitSyntax#2\@endchar
                
                \def\@tabEntry{{#1} & {#2} \\}

                % Append to the preferred time list             
                \concatenate{\@splitList}={\@splitList}&{\@tabEntry}            
            \fi
        \fi
}

%% Macro: @scanDate
%%
%% Tricky, it uses tail recursion to parse each single character
%% contained in the input string.
%%
%% parameter:   #1 Input string (and then single char).
%%
\def\@scanDate#1{

        \ifx#1\@endchar 
                \let\next=\relax
        \else
                % \typeout{ checking character {#1}}

                \def\given{#1}
                \ifx\given\@dateSeparator
                        \advance\sepCount by1 
                \else
                        \ifnum\sepCount=0 \NumericValidation#1{day}{} \concatenate{\@dateday}={\@dateday}&{#1} \fi              
                        \ifnum\sepCount=1 \concatenate{\@datemonth}={\@datemonth}&{#1} \fi
                        \ifnum\sepCount=2 \NumericValidation#1{year}{} \concatenate{\@dateyear}={\@dateyear}&{#1} \fi           
                \fi

                \advance\strCount by1 
                \let\next=\@scanDate            
        \fi

        % Tail recursion
        \next
}

%% Macro: @CheckDate
%%
%% Validate date entries in the format dd-mm-yy (e.g. 10-may-98).
%%
%% parameters:  #1 date
%%              #2 run code
%%              #3 invoking macro name
%%
\def\@CheckDate#1#2#3{

        \def\@dateday{}
        \def\@datemonth{}
        \def\@dateyear{}

        \def\@dateSeparator{-}
        \sepCount=0
        \strCount=0

        \@scanDate#1\@endchar

        % \typeout{Run: #2 \ day: \@dateday \  month: \@datemonth \ year: \@dateyear}

        \WeakValidation{\@dateday}{day}{#3 for run #2}
        \StrongValidation{\@datemonth}{\@allMonthList}
                {month for run #2}{#3}
        \WeakValidation{\@dateyear}{year}{#3 for run #2}
}

%% Preferred time list
%%
\def\@prefTimeList{}

%% Macro: TimeCritical
%%
%% Prepare entries for the TimeCritical table
%%
%% parameters:  #1 run code
%%              #2 start date
%%              #3 end date
%%              #4 reason.
%%
\def\TimeCritical#1#2#3#4{

        \def\@rcode{#1}

        % Run checks only if it is not test mode (title not empty)
        \ifx\@emptyValue\@title
        \else

            \ifx\@rcode\@emptyValue
            \else

                \StrongValidation{\@rcode}{\@RunCodeList}
                        {run ID}{TimeCritical (first parameter)}

                \def\@rstart{#2}
                \def\@rend{#3}

                \@CheckDate{#2}{#1}{TimeCritical (third parameter)}
                \@CheckDate{#3}{#1}{TimeCritical (second parameter)}
                
                \def\@tabEntry{{#1} & {#2} & {#3} & {#4} \\}

                % Append to the preferred time list             
                \concatenate{\@prefTimeList}={\@prefTimeList}&{\@tabEntry}
            \fi
        \fi
}

%% Unsuitable time list
%%
\def\@unsuitTimeList{}

%% Macro: UnsuitableTimes
%%
%% Prepare entries for the UnsuitableTimes table
%%
%% parameters:  #1 run code
%%              #2 start date
%%              #3 end date
%%              #4 reason.
%%
\def\UnsuitableTimes#1#2#3#4{

        \def\@rcode{#1}

        % Run checks only if it is not test mode (title not empty)
        \ifx\@emptyValue\@title
        \else

            \ifx\@rcode\@emptyValue
            \else

                \StrongValidation{\@rcode}{\@RunCodeList}
                        {run ID}{UnsuitableTimes (first parameter)}

                \def\@rstart{#2}
                \def\@rend{#3}

                \@CheckDate{#2}{#1}{UnsuitableTimes (third parameter)}
                \@CheckDate{#3}{#1}{UnsuitableTimes (second parameter)}

                \def\@tabEntry{\ \ {#1} & {#2} & {#3} & {#4} \\}

                % Append to the preferred time list             
                \concatenate{\@unsuitTimeList}={\@unsuitTimeList}&{\@tabEntry}          
            \fi
        \fi
}

%% Link type keywords
%%
\def\@linkTypes{\\{after}\\{simultaneous}}
\def\@linkAfter{after}

%% Observing run link list
%%
\def\@linkList{}

%% Macro: Link
%%
%% Prepare entries for the Link table
%%
%% parameters:  #1 first run code
%%              #2 type (can be follows or same-time)
%%              #3 second run code
%%              #4 delay (n. of days)
%%
\def\Link#1#2#3#4{

        \def\@rcodeA{#1}
        \def\@rcodeB{#3}
        \def\@lType{#2}
        \def\@lDel{#4}

        % Run checks only if it is not test mode (title not empty)
        \ifx\@emptyValue\@title
        \else

            \ifx\@rcodeA\@emptyValue
            \else
                \StrongValidation{\@rcodeA}{\@RunCodeList}
                        {first run ID}{Link (first parameter)}
                \StrongValidation{\@rcodeB}{\@RunCodeList}
                        {second run ID}{Link (third parameter)}
                \StrongValidation{\@lType}{\@linkTypes}
                        {link type}{Link (second parameter)}

                % C.Boarotto 27-Jan-99 weak validation if the link
                % type is after
                \ifx\@lType\@linkAfter
                        \WeakValidation{\@lDel}{delay}{Link (fourth parameter)}
                \fi

                \def\@tabEntry{\ \ {#1} & {#2} & {#3} & {#4} \\}

                % Append to the preferred time list             
                \concatenate{\@linkList}={\@linkList}&{\@tabEntry}
            \fi 
        \fi     
}

%% Observing run link list
%%
\def\@specialReqList{}

%% Macro: SpecialRequirements
%%
%% Prepare entries for the SpecialRequirements table
%%
%% parameters:  #1 run code
%%              #2 special requirements text
%%
\def\SpecialRequirements#1#2{

        \def\@rcode{#1}
        \def\@rtext{#2}

        % Run checks only if it is not test mode (title not empty)
        \ifx\@emptyValue\@title
        \else

            \ifx\@rcode\@emptyValue
            \else

                \StrongValidation{\@rcode}{\@RunCodeList}
                        {run ID}{SpecialRequirements (first parameter)}
                \WeakValidation{\@rtext}
                        {special requirements text}
                        {SpecialRequirements (second parameter)}

                \def\@tabEntry{\ \ {#1} & {#2} \\}

                % Append to the special requirements list               
                \concatenate{\@specialReqList}={\@specialReqList}&{\@tabEntry}
            \fi
        \fi
}

%% Moving targets scheduling requirements list
%%
\def\@movingTargetList{}

%% Macro: MovingTargets
%%
%% Prepare entries for the MovingTargets table
%%
%% parameters:  #1 run code
%%              #2 moving targets requirements text
%%
\def\MovingTargets#1#2{

        \def\@rcode{#1}
        \def\@rtext{#2}

        % Run checks only if it is not test mode (title not empty)
        \ifx\@emptyValue\@title
        \else

            \ifx\@rcode\@emptyValue
            \else

                \StrongValidation{\@rcode}{\@RunCodeList}
                        {run ID}{MovingTargets (first parameter)}
                \WeakValidation{\@rtext}
                        {upper limit of proper motions of moving target}
                        {MovingTargets (second parameter)}

                \def\@tabEntry{\ \ {#1} & {#2} \\}

                % Append to the moving target list              
                \concatenate{\@movingTargetList}={\@movingTargetList}&{\@tabEntry}              
            \fi
        \fi
}

%% Macro: @schedReqTables
%%
%% Display the scheduling requirements tables:
%% 1) preferred times table
%% 2) unsuitable times table
%% 3) link table
%% 4) special requirements table
%%
\def\@schedReqTables{

        \def\@splitTab{}        
        \def\@criticalTab{}
        \def\@unsuitTab{}
        \def\@linkTab{}
        \def\@specialTab{}
        \def\@motionTab{}

        \ifx\@emptyValue\@splitList
        \else
                \def\@splitHeader{\sevenrm\bf{Run} & 
                        \sevenrm\bf{splitting} \\}
                \def\@splitTab{
                        
                        \sixrm{
                                \begin{tabular*}{80mm}[tl]
                                {p{10mm}p{70mm}}
                                \multicolumn{2}{l}{\sevenrm\bf{1. Run Splitting}}\\
                                \multicolumn{2}{l}{\rule{80mm}{.1mm}} \\
                                \@splitHeader
                                \multicolumn{2}{l}{\rule{80mm}{.1mm}} \\
                                \@splitList
                                \end{tabular*}
                        }
                }
        \fi

        \ifx\@emptyValue\@prefTimeList
        \else
                \def\@criticalHeader{\sevenrm\bf{Run} & \sevenrm\bf{from} & 
                        \sevenrm\bf{to} & \sevenrm\bf{reason} \\}

                \def\@criticalTab{
                        
                        \sixrm{
                                \begin{tabular*}{80mm}[tl]
                                {p{10mm}p{20mm}p{20mm}p{30mm}}
                                \multicolumn{4}{l}{\sevenrm\bf{2. Specific date(s)
                                        for time critical observations:}}\\
                                \multicolumn{4}{l}{\rule{80mm}{.1mm}} \\
                                \@criticalHeader
                                \multicolumn{4}{l}{\rule{80mm}{.1mm}} \\
                                \@prefTimeList
                                \end{tabular*}
                        }
                }
        \fi

        \ifx\@emptyValue\@unsuitTimeList
        \else
                \def\@unsuitHeader{\sevenrm\bf{Run} & \sevenrm\bf{from} & 
                        \sevenrm\bf{to} & \sevenrm\bf{reason} \\}
                \def\@unsuitTab{
                        \sixrm{
                                \begin{tabular*}{80mm}[tl]
                                {p{10mm}p{20mm}p{20mm}p{30mm}}
                                \multicolumn{4}{l}{\sevenrm\bf{3. Unsuitable period(s)
                                        of time}}\\
                                \multicolumn{4}{l}{\rule{80mm}{.1mm}} \\
                                \@unsuitHeader
                                \multicolumn{4}{l}{\rule{80mm}{.1mm}} \\
                                \@unsuitTimeList
                                \end{tabular*}
                        }
                }
        \fi

        \ifx\@emptyValue\@linkList
        \else
                \def\@linkHeader{\sevenrm\bf{Run 1} & { } & 
                        \sevenrm\bf{Run 2} & \sevenrm\bf{delay} \\}
                \def\@linkTab{
                        \sixrm{
                                \begin{tabular*}{80mm}[tl]
                                {p{15mm}p{30mm}p{15mm}p{20mm}}
                                \multicolumn{4}{l}{\sevenrm\bf{4. Link for coordinated 
                                        observation}}\\
                                \multicolumn{4}{l}{\rule{80mm}{.1mm}} \\
                                \@linkHeader
                                \multicolumn{4}{l}{\rule{80mm}{.1mm}} \\
                                \@linkList
                                \end{tabular*}
                        }
                }
        \fi

        \ifx\@emptyValue\@specialReqList
        \else
                \def\@specialHeader{\sevenrm\bf{Run} & 
                        \sevenrm\bf{Special Requirements} \\}
                \def\@specialTab{
                        \sixrm{
                                \begin{tabular*}{80mm}[tl]
                                {p{10mm}p{70mm}}
                                \multicolumn{2}{l}{\sevenrm\bf{5. Run special 
                                        requirement(s)}}\\
                                \multicolumn{2}{l}{\rule{80mm}{.1mm}} \\
                                \@specialHeader
                                \multicolumn{2}{l}{\rule{80mm}{.1mm}} \\
                                \@specialReqList
                                \end{tabular*}
                        }
                }
        \fi

        \ifx\@emptyValue\@movingTargetList
        \else
                \def\@motionHeader{\sevenrm\bf{Run} & 
                        \sevenrm\bf{Upper Limit} \\}
                \def\@motionTab{
                        \sixrm{
                                \begin{tabular*}{80mm}[tl]
                                {p{10mm}p{70mm}}
                                \multicolumn{2}{l}{\sevenrm\bf{6. Upper limit of 
                                        proper motion of moving target}}\\
                                \multicolumn{2}{l}{\rule{80mm}{.1mm}} \\
                                \@motionHeader
                                \multicolumn{2}{l}{\rule{80mm}{.1mm}} \\
                                \@movingTargetList
                                \end{tabular*}
                        }
                }
        \fi

        \vbox{
                \vspace{5mm}
                \hbox{\@splitTab \@h \@linkTab \@h}
                \vspace{5mm}
                \hbox{\@criticalTab \@h \@specialTab \@h}
                \vspace{5mm}
                \hbox{\@unsuitTab \@h \@motionTab \@h}
                \vfill
        }
}

%% SEST scheduling requirements handling.
%%
\def\@sestlst{}
\def\@sestperiod{}
\def\SESTLST#1{\def\@sestlst{#1}}
\def\SESTperiod#1{\def\@sestperiod{#1}}

%% Macro: @SestInfo
%%
%% If SEST is defined, display SEST scheduling requirements.
%%
\def\@SestInfo{
        \if@DefSEST
                \vbox{
                        \vspace{5mm}
                        \hbox{
                                \sevenrm\bf\hbox to 17mm{7. SEST:\@h}
                                \hbox{\vbox{
                                        \sevenrm\bf{(i) \ preferred LST interval:} 
                                        \parbox[t]{105mm}{\sevenrm\@sestlst}
                                }\@h}\@h
                        }
                        \hbox{
                                \elvsf\hbox to 17mm{ }
                                \hbox{\vbox{
                                        \sevenrm\bf{(ii) observability period of the target:} 
                                        \parbox[t]{90mm}{\sevenrm\@sestperiod}
                                }\@h}\@h
                        }
                }
        \fi
}

%% Macro: MakeSchedulingReq
%%
%% Build up the scheduling requirements box, n. 12 for large
%% programmes or n. 13 for normal ones.
%% 
\def\MakeSchedulingReq{

        \def\@schedboxTitle{Scheduling requirements}

        \def\boxtext{
                \@schedReqTables
                \vfill
                \@SestInfo
        }

        \def\@boxLen{140}
        \def\@schedboxText{\boxtext\@h}

        % Create the frame box to house the scheduling requirements
        % Note that the box is smaller in case of Normal Programme
        \@makeGenericBox{\@boxLen}{\@schedboxTitle}
                {\@schedboxText}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Instrument Configuration Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% List to be displayed in the instrument configuration box.
%% 
\def\InstrumentConfigList{}

%% List of ``configured'' instruments, to be compared with the list of
%% ``used'' instruments in order to check that all the instruments defined 
%% have been properly configured.
%% 
\def\@InsConfiguredList{}

%% Macro: INSconfig
%%
%% Generate the entries for the instrument setup table
%%
%% parameters:  #1 Instrument code (e.g. EMMI)
%%              #2 Instrument parameter name (e.g. Spectroscopy)
%%              #3 Instrument parameter value (e.g. Grisms #1 and #2)
%%
\def\INSconfig#1#2#3{

    % Run checks only if it is not test mode (title not empty)
    \ifx\@emptyValue\@title
    \else

        \def\pIns{#1}
        \def\pPar{#2}
        \def\pVal{#3}

        % Check values
        \StrongValidation{\pIns}{\usedInstrumentList}{instrument code 
                (doesn't match the instrument list in Box 3)}
                {INSconfig (first parameter)}
        % \WeakValidation{\pPar}{parameter}{INSconfig (second parameter)}
        % \WeakValidation{\pVal}{value}{INSconfig (third parameter)}

        % Get the telescope for the instrument
        \ismember\pIns\of\usedInstrumentList

        \if@ismember

                % Find the telescope 
                \count100=\listposition
                \select\count100\of\usedTelescopeList\to\tmpTel

                % Substituted \\ with \cr otherwise it can't expand it
                \def\itemEntry{{\tmpTel} & {#1} & {#2} & {#3} \cr }
                \def\@ins{\\ {#1}}

                % It is necessary to expand the entry before concatenating
                \edef\expandedEntry{\itemEntry}
                \concatenate{\InstrumentConfigList}={\InstrumentConfigList}&{\expandedEntry}

                % Append the instrument to the list of ``configured'' instruments
                \concatenate{\@InsConfiguredList}={\@InsConfiguredList}&{\@ins}
        \fi
    \fi
}

%% Macro: CheckInsConfig
%%
%% Check that all the instruments defined have been properly
%% configured.
%% 
\def\CheckInsConfig{

    % Run checks only if it is not test mode (title not empty)
    \ifx\@emptyValue\@title
    \else

        % Counters
        \newcount\insCount
        \newcount\tmpCount
        \newcount\insLen
        \insCount=1

        \cardinality\usedInstrumentList\to\insLen
        \advance\insLen by1

        \def\@inslength{\the\insLen}
        \def\@errorList{}

        % LOOP:
        % Foreach instrument defined in box 3 (belonging to
        % \usedInstrumentList) check if it is contained in
        % \@InsConfiguredList too.
        %
        % BUG FIXED: extra emtpy lines REMOVED in the LOOP code
        % otherwise it fails on some systems (different latex 
        % installations).
        % C.Boarotto 09-Mar-99
        %
        \loop\ifnum\insCount<\@inslength
                % A temporary counter is necessary because its value
                % is modified when used in the ``select'' macro
                \tmpCount=\the\insCount
                \select\tmpCount\of\usedInstrumentList\to\@tmpIns
                % Check @tmpIns if is member of the configured instruments
                \ismember\@tmpIns\of\@InsConfiguredList
                \if@ismember
                \else
                        % It isn't member: i.e. the instrument has
                        % been defined in box 3 but its setup has not
                        % been defined.
                        \@mg {ERROR - Instrument {\@tmpIns} defined in box 3 not configured. 
                                Please uncomment the specific INSconfig macro for {\@tmpIns}.}
                        \def\@errorList{yes}
                \fi
                \advance\insCount by1
        \repeat

        % In case of errors exit...
        \ifx\@emptyValue\@errorList
        \else
                \@stm
        \fi
    \fi
}

%% Macro: MakeInstrumentConfBox
%%
%% Display the table containing the instrument set up
%%
\def\MakeInstrumentConfBox{

        \CheckInsConfig

        \def\@instrumentconfboxTitle{Instrument configuration}

        \def\tableHead{\elvsf{Telescope} & \elvsf{Instrument} & 
                        \elvsf{Parameter} & \elvsf{Value or list} \\}

        \def\@boxLen{136}

        \def\@instrumentconfboxText{
                %% 170/4=42.5mm
                \begin{tabular*}{\@tabInsideBoxLength}[tl]
                {p{35mm}p{35mm}p{50mm}p{50mm}}
                \tableHead
                \\
                \normalsize\InstrumentConfigList
                \end{tabular*}
        }

        % Create the frame box to house the instrument configuration table
        % Note that the box is smaller in case of Large Programme
        \@makeGenericBox{\@boxLen}{\@instrumentconfboxTitle}
                {\normalsize\@instrumentconfboxText}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Adonis Information Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Adonis info variable and macro
\def\@adonisInfo{}
\def\AdonisInfo#1{\gdef\@adonisInfo{#1}}

%% Macro: MakeAdonisBox
%%
%% Create the adonis description box
%%
\def\MakeAdonisBox{

        \def\@adonisboxTitle{Adonis information}

        \WeakValidation{\@adonisInfo}
                {ADONIS information mandatory when requesting ADONIS}
                {AdonisInfo empty}

        \@makeGenericBox{\@pagetwolength}{\@adonisboxTitle}
                {\normalsize\@adonisInfo}       
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%      Visitor Instrument Box
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Macro: MakePageVisitorInstrument (OBSOLETE)
%%
%% Set an internal flag to print the visitor instrument page
%%
\def\MakePageVisitorInstrument{\gdef\@pageVisitorInstrument{yes}}

%% Visitor instrument description variables and setup macros.
%%
\def\@desc{}
\def\@comm{}
\def\@wv{}
\def\@wfocus{}
\def\@interf{}
\def\@focal{}
\def\@acqu{}
\def\@softw{}
\def\@suppl{}
\def\Desc#1{\gdef\@desc{#1}}
\def\Comm#1{\gdef\@comm{#1}}
\def\WV#1{\gdef\@wv{#1}}
\def\Wfocus#1{\gdef\@wfocus{#1}}
\def\Interf#1{\gdef\@interf{#1}}
\def\Focal#1{\gdef\@focal{#1}}
\def\Acqu#1{\gdef\@acqu{#1}}
\def\Softw#1{\gdef\@softw{#1}}
\def\Suppl#1{\gdef\@suppl{#1}}

%% Macro: MakeVisitorInstrumentBox
%%
%% Visitor instrument description page
%%
\def\MakeVisitorInstrumentBox{

        % Fonts, to be changed only once (if necessary)
        \def\@visfonts{\ninerm}

        % Single paragraph length
        \def\parlen{29mm}

        \def\@visitorboxTitle{Visitor instrument}

        \def\@visitorboxText{
                \@visfonts{Description of the instrument and of its operation: \ }
                \normalsize\@desc
                \vfill
                \@visfonts{On which telescope(s) has your 
                        instrument been commissioned and/or 
                        used (scientific publications): \ }
                \normalsize\@comm
                \vfill
                
                \@visfonts{Total weight and value of equipment to be shipped: \ }
                \normalsize\@wv
                \vfill

                \@visfonts{Weight at the focus (including ancillary equipment): \ }
                \normalsize\@wfocus
                \vfill

                \@visfonts{Compatibility of attachment interface with 
                        required telescope focus: \ }
                \normalsize\@interf
                \vfill

                \@visfonts{Back focal distance value: \ }
                \normalsize\@focal
                \vfill

                \@visfonts{Acquisition, focusing, and guiding procedure: \ }
                \normalsize\@acqu
                \vfill

                \@visfonts{Compatibility with ESO software standards 
                        (data handling): \ }
                \normalsize\@softw
                \vfill

                \@visfonts{Estimate of supplies and services expected 
                        from ESO (in person days): \ }
                \normalsize\@suppl
                \smallskip
        }

        \@makeGenericBox{\@pagetwolength}
                {\@visitorboxTitle \@h}{\@visitorboxText \@h}
}


