Search:

Return to previous page

Contents of file 'magbragg/magbragg.tex':




Deprecated: Function split() is deprecated in /storage/content/45/2011745/jonsson.eu/public_html/php/htmlicise.php on line 46
    1   \input cwebmac
    2   % File:        magbragg.w [CWEB source code]
    3   % Created:     October 28, 2002 [v.1.0]
    4   % Last change: December 18, 2011 [v.1.44]
    5   % Author:      Fredrik Jonsson
    6   % Description: The CWEB source code for the MAGBRAGG simulator of nonlinear
    7   %              magneto-optical Bragg gratings. For information on the CWEB
    8   %              programming language, see http://www.literateprogramming.com.
    9   % Compilation: Compile this program by using the enclosed Makefile, or use
   10   %              the blocks of the Makefile as listed in section five of the
   11   %              documentation (file magbragg.ps or magbragg.pdf). The C source
   12   %              code (as generated from this CWEB code) conforms to the ANSI
   13   %              standard for the C programming language (which is equivalent
   14   %              to the ISO C90/C99 standard for C).
   15   %
   16   % Copyright (C) 2002--2011, Fredrik Jonsson
   17   %
   18   \input epsf
   19   \def\version{1.44}
   20   \def\lastrevdate{January 10, 2007}
   21   \font\eightcmr=cmr8
   22   \font\tensc=cmcsc10
   23   \font\eightcmssq=cmssq8
   24   \font\eightcmssqi=cmssqi8
   25   \font\twentycmcsc=cmcsc10 at 20 truept
   26   \def\magbragg{{\eightcmr MAGBRAGG\spacefactor1000}}
   27   \def\poincare{{\eightcmr POINCARE\spacefactor1000}}
   28   \def\ANSI{{\eightcmr ANSI\spacefactor1000}} % The language standard we stick to
   29   \def\SI{{\eightcmr SI\spacefactor1000}}   % Another standard for physical units
   30   \def\GNU{{\eightcmr GNU\spacefactor1000}}       % GNU is Not Unix
   31   \def\GCC{{\eightcmr GCC\spacefactor1000}}       % The GNU C-compiler
   32   \def\CEE{{\eightcmr C\spacefactor1000}}         % The C programming language
   33   \def\ANSICEE{{\eightcmr ANSI~C\spacefactor1000}}% The ANSI-C standard language
   34   \def\CWEB{{\eightcmr CWEB\spacefactor1000}}     % The CWEB programming language
   35   \def\MATLAB{{\eightcmr MATLAB\spacefactor1000}} % The MATLAB ditto
   36   \def\UNIX{{\eightcmr UNIX\spacefactor1000}}
   37   \def\CYGWIN{{\eightcmr CYGWIN\spacefactor1000}}
   38   \def\CTANGLE{{\eightcmr CTANGLE\spacefactor1000}}
   39   \def\CWEAVE{{\eightcmr CWEAVE\spacefactor1000}}
   40   \def\OSX{{OS\,X}}
   41   \def\re{\mathop{\rm Re}\nolimits} % The real part of a complex number
   42   \def\im{\mathop{\rm Im}\nolimits} % The imaginary part of a complex number
   43   \def\dollar{\char'044}             % The `$' character
   44   \def\tothepower{\char'136}         % The `^' character
   45   \def\onehalf{{\textstyle{{1}\over{2}}}}
   46   \def\threefourth{{\textstyle{{3}\over{4}}}}
   47   \def\endalg{\vrule height 1.4ex width .6ex depth .4ex} % Rectangular bullet
   48   \def\ie{i.\thinspace{e.}~\ignorespaces}
   49   \def\eg{e.\thinspace{g.}~\ignorespaces}
   50   \let\,\thinspace
   51   %% \def\subsection[#1]{\goodbreak\noindent{\it #1}\par\nobreak\noindent}
   52   %
   53   % Define a handy macro for listing the steps of an algorithm.
   54   %
   55   \newdimen\aitemindent \aitemindent=26pt
   56   \newdimen\aitemleftskip \aitemleftskip=36pt
   57   \def\aitem[#1]{\smallbreak\noindent\hbox to 10pt{}%
   58     \hbox to\aitemindent{\bf #1\hfill}%
   59     \hangindent\aitemleftskip\ignorespaces}
   60   %
   61   % Define a handy macro for bibliographic references.
   62   %
   63   \newdimen\refitemindent \refitemindent=18pt
   64   \def\refitem[#1]{\smallbreak\noindent%
   65     \hbox to\refitemindent{[#1]\hfill}%
   66     \hangindent\refitemindent\ignorespaces}
   67   %
   68   % Define a handy macro for nicely typeset variable descriptions.
   69   %
   70   \newdimen\varitemindent \varitemindent=100pt
   71   \def\varitem[#1]#2{\smallbreak\noindent\hbox to 20pt{}%
   72     \hbox to\varitemindent{#1\hfill}%
   73     \hangindent 120pt\ignorespaces#2\par}
   74   %
   75   % Define a handy macro for the list of program revisions.
   76   %
   77   \newdimen\citemindent \citemindent=80pt
   78   \newdimen\citemleftskip \citemleftskip=90pt
   79   \def\citem[#1]{\smallbreak\noindent\hbox to 10pt{}%
   80     \hbox to\citemindent{\bf #1\hfill}%
   81     \hangindent\citemleftskip\ignorespaces}
   82   \def\citindent{\smallbreak\noindent\hbox to 10pt{}%
   83     \hbox to\citemindent{\hfil}%
   84     \hangindent\citemleftskip\ignorespaces}
   85   %
   86   % Define the \beginvrulealign and \endvrulealign macros as described in
   87   % Donald Knuth's The TeXbook, Appendix D: Dirty Tricks. These macros are
   88   % used in typesetting nicely looking tables.
   89   %
   90   \def\beginvrulealign{\setbox0=\vbox\bgroup}
   91   \def\endvrulealign{\egroup % now \box0 holds the entire alignment
   92     \setbox0=\vbox{\setbox2=\hbox{\vrule height\ht0 depth\dp0 width0pt}
   93       \unvbox0 \setbox0=\lastbox % now \box0 is the bottom row
   94       \nointerlineskip \copy0 % put it back
   95       \global\setbox1=\hbox{} % initialize box that will contain rules
   96       \setbox4=\hbox{\unhbox0 % now open up the bottom row
   97         \loop \skip0=\lastskip \unskip % remove tabskip glue
   98         \advance\skip0 by-.4pt % rules are .4 pt wide
   99         \divide\skip0 by 2
  100         \global\setbox1=\hbox{\hskip\skip0\vrule\hskip\skip0
  101           \unhbox2\unhbox1}%
  102         \setbox2=\lastbox % remove alignment entry
  103         \ifhbox2 \setbox2=\hbox{\kern\wd2}\repeat}}%
  104     \hbox{\rlap{\box0}\box1}} % superimpose the alignment on the rules
  105   
  106   \datethis
  107   
  108   
  109   \N{1}{1}Introduction.
  110   \vskip 120pt
  111   \centerline{\twentycmcsc MagBragg}
  112   \vskip 20pt
  113   \centerline{A simulator of nonlinear magneto-optical Bragg gratings}
  114   \vskip 2pt
  115   \centerline{(Version \version\ of \lastrevdate)}
  116   \vskip 10pt
  117   \centerline{Written by Fredrik Jonsson}
  118   \vskip 80pt
  119   \noindent
  120   This \CWEB\footnote{${}^\dagger$}{For information on the \CWEB\ programming
  121   language by Donald E.~Knuth, as well as samples of \CWEB\ programs, see
  122   \.{http://www-cs-faculty.stanford.edu/\~\ \kern -5pt knuth/cweb.html}.
  123   For general information on literate programming, see
  124   \.{http://www.literateprogramming.com}.} computer program calculates
  125   reflection and transmission spectra of nonlinear magneto-optical Bragg
  126   gratings, in a stratified geometry where the material parameters vary only
  127   in one Cartesian coordinate.
  128   The \magbragg\ program also simulates the propagation of the electromagnetic
  129   field of an optical wave as it traverses a magneto-optical Bragg grating, in
  130   linear as well as nonlinear optical regimes.
  131   
  132   Strictly speaking, in a linear-optical domain a forward algorithm would just as
  133   fine as a backward one; however, for nonlinear optical problems, it often (as
  134   in this particular case) turns out that it is easier to compute the inverse
  135   problem, that is to say, to compute the input that corresponds to a certain
  136   given output. This is the case for, for example, optical bistability, where a
  137   given input intensity and ellipticity of the input optical wave for certain
  138   configurations correspond to a multiple-valued optical output. This means that
  139   we are not always on safe ground when it comes to the evaluation of output as
  140   function of input; meantime it makes perfectly sense to calculate the
  141   single-valued input as function of optical output.
  142   This program, in particular, is formulated in terms of the inverse problem, and
  143   hence the input parameters to the program are partly given in terms of the
  144   optical output of the magneto-optical Bragg grating.
  145   The algorithm behind the program was published as F.~Jonsson and C.~Flytzanis,
  146   Physical Review Letters {\bf 96}, 063902 (2006).
  147   \bigskip
  148   \noindent Copyright \copyright\ Fredrik Jonsson, 2002--2007.
  149   All rights reserved.
  150   \vfill
  151   
  152   \fi
  153   
  154   \N{1}{2}The CWEB programming language.
  155   For the reader who might not be familiar with the concept of the
  156   \CWEB\ programming language, the following citations hopefully will
  157   be useful. For further information, as well as freeware compilers for
  158   compiling \CWEB\ source code, see \.{http://www.literateprogramming.com}.
  159   \bigskip
  160   
  161   {\narrower\narrower\narrower\narrower\eightcmssqi\noindent
  162   I believe that the time is ripe for significantly better documentation of
  163   programs, and that we can best achieve this by considering programs to be
  164   works of literature. Hence, my title: `Literate Programming.'
  165   
  166   Let us change our traditional attitude to the construction of programs:
  167   Instead of imagining that our main task is to instruct a computer what to
  168   do, let us concentrate rather on explaining to human beings what we want
  169   a computer to do.
  170   
  171   The practitioner of literate programming can be regarded as an essayist,
  172   whose main concern is with exposition and excellence of style. Such an
  173   author, with thesaurus in hand, chooses the names of variables carefully
  174   and explains what each variable means. He or she strives for a program
  175   that is comprehensible because its concepts have been introduced in an
  176   order that is best for human understanding, using a mixture of formal and
  177   informal methods that reinforce each other.
  178   \smallskip
  179   {\eightcmssq --\,Donald Knuth,}
  180   {\eightcmssqi The CWEB System of Structured Documentation}
  181   {\eightcmssq (Addison-Wesley, Massachusetts, 1994)}
  182   }
  183   \bigskip
  184   
  185   {\narrower\narrower\narrower\narrower\eightcmssqi\noindent
  186   The philosophy behind CWEB is that an experienced system programmer, who
  187   wants to provide the best possible documentation of his or her software
  188   products, needs two things simultaneously: a language like \TeX\ for
  189   formatting, and a language like C for programming. Neither type of language
  190   can provide the best documentation by itself; but when both are appropriately
  191   combined, we obtain a system that is much more useful than either language
  192   separately.
  193   
  194   The structure of a software program may be thought of as a `WEB' that is
  195   made up of many interconnected pieces. To document such a program we want to
  196   explain each individual part of the web and how it relates to its neighbors.
  197   The typographic tools provided by \TeX\ give us an opportunity to explain the
  198   local structure of each part by making that structure visible, and the
  199   programming tools provided by languages like C make it possible for us to
  200   specify the algorithms formally and unambiguously. By combining the two,
  201   we can develop a style of programming that maximizes our ability to perceive
  202   the structure of a complex piece of software, and at the same time the
  203   documented programs can be mechanically translated into a working software
  204   system that matches the documentation.
  205   
  206   Besides providing a documentation tool, CWEB enhances the C language by
  207   providing the ability to permute pieces of the program text, so that a
  208   large system can be understood entirely in terms of small sections and
  209   their local interrelationships. The CTANGLE program is so named because
  210   it takes a given web and moves the sections from their web structure into
  211   the order required by C; the advantage of programming in CWEB is that the
  212   algorithms can be expressed in ``untangled'' form, with each section
  213   explained separately. The CWEAVE program is so named because it takes a
  214   given web and intertwines the \TeX\ and C portions contained in each
  215   section, then it knits the whole fabric into a structured document.
  216   \smallskip
  217   {\eightcmssq --\,Donald Knuth, ``Literate Programming'', in}
  218   {\eightcmssqi Literate Programming}
  219   {\eightcmssq (CSLI Lecture Notes, Stanford, 1992)}
  220   }
  221   
  222   \fi
  223   
  224   \N{1}{3}Theory of nonlinear magneto-optical Bragg gratings.
  225   The algorithm used for the simulation is based on the inverse problem of
  226   nonlinear optical gratings,
  227   where the transmitted optical field is used as input to the algorithm,
  228   which successively calculates the intra-grating optical fields backwards
  229   through the structure, finally ending up with the corresponding incident field.
  230   The analysis is here for the sake of simplicity restricted to infinite
  231   plane waves under assumption of the slowly varying envelope approximation.
  232   The conventions of notation for the discrete layers in the structure of
  233   analysis are shown in Fig.~1, in which $N-1$ layers of nonlinear
  234   magneto-optical media are separated by their boundaries at $z=z_1,\ldots,z_N$.
  235   
  236   \bigskip
  237   \centerline{\epsfxsize=86mm\epsfbox{figures/geom/geom.1}}\smallskip
  238   {\narrower\narrower\noindent{\bf Figure 1.} The geometry of the discretized
  239   model of the magneto-optical Bragg grating, in the Faraday configuration with
  240   the static magnetic ${\bf B}_0=B^z_0{\bf e}_z$ applied in the direction of
  241   wave propagation. The grating consists of $N$ optically homogeneous layers
  242   with $N+1$ discrete interfaces located at spatial coordinates $z_k$, for
  243   $k=1,2,\ldots,N$, with the optical properties of each layer described by the
  244   optical susceptibility tensors $\chi^{\rm ee}_{ij}$ and
  245   $\chi^{\rm eeee}_{ijkl}$ and their magneto-optical counter-parts
  246   $\chi^{\rm eem}_{ijk}$ and $\chi^{\rm eeeem}_{ijklm}$.\par}
  247   \bigskip
  248   
  249   \fi
  250   
  251   \M{4}Discretization of the problem. In each homogeneous layer $z_k<z<z_{k+1}$,
  252   $k=1,2,\ldots,N-1$, the components of the plane-parallel electromagnetic field
  253   ${\bf E}(z,t)=\re[{\bf E}_{\omega}\exp(-i\omega t)]$ propagate collinearly
  254   with an externally applied static magnetic field ${\bf B}_0=B^z_0{\bf e}_z$,
  255   and the local constitutive relation for the electric polarization density
  256   ${\bf P}(z,t)=\re[{\bf P}_{\omega}\exp(-i\omega t)]$ of the medium
  257   is~[1]
  258   $$
  259   \eqalign{
  260   {\bf P}_{\omega}=\varepsilon_0[&\chi^{{\rm ee}}_{xx} {\bf E}_{\omega}
  261   +\chi^{{\rm eem}}_{xyz} {\bf E}_{\omega}\times{\bf B}_0\cr
  262   &+(\chi^{{\rm eeee}}_{xxxx}-\chi^{{\rm eeee}}_{xyyx})
  263   ({\bf E}_{\omega}\cdot{\bf E}^*_{\omega}){\bf E}_{\omega}
  264   +\chi^{{\rm eeee}}_{xyyx}
  265   ({\bf E}_{\omega}\cdot{\bf E}_{\omega}){\bf E}^*_{\omega}\cr
  266   &+\chi^{{\rm eeeem}}_{xyyyz}
  267   ({\bf E}_{\omega}\cdot{\bf E}^*_{\omega}){\bf E}_{\omega}\times{\bf B}_0
  268   +\chi^{{\rm eeeem}}_{xxxyz}{\bf E}_{\omega}
  269   ({\bf E}_{\omega}\cdot({\bf E}^*_{\omega}\times{\bf B}_0))].\cr
  270   }
  271   \eqno{(1)}
  272   $$
  273   In this expression, the spatial dependence of the fields and susceptibilities
  274   is omitted in notation, as is also any slow temporal variation of the fields;
  275   from now on each appearance of a field or susceptibility implicitly implies
  276   evaluation in respective layer of context. In each layer, the envelope of the
  277   electromagnetic field satisfies the autonomous nonlinear wave equation
  278   $$
  279   {{\partial^2{\bf E}_{\omega}}\over{\partial z^2}}
  280   +(\omega/c)^2{\bf E}_{\omega}
  281   =-\mu_0\omega^2{\bf P}_{\omega}.
  282   \eqno{(2)}
  283   $$
  284   The field is in each layer expressed in a circularly polarized basis
  285   ${\bf e}_{\pm}=({\bf e}_x \pm i{\bf e}_y)/\sqrt{2}$, with forward and
  286   backward traveling modes as a superposition
  287   $$
  288   \eqalign{
  289   {\bf E}_{\omega}&=
  290   [{\bf e}_+ E^{\rm f}_{k_+}(z) + {\bf e}_- E^{\rm f}_{k_-}(z)]
  291   \exp[i\omega n_k (z-z_k)/c]\cr
  292   &\qquad+[{\bf e}^*_+ E^{\rm b}_{k_+}(z) + {\bf e}^*_- E^{\rm b}_{k_-}(z)]
  293   \exp[-i\omega n_k (z-z_k)/c],\cr
  294   }
  295   \eqno{(3)}
  296   $$
  297   where $n_k=(1+\chi^{{\rm ee}}_{xx})^{1/2}$ are the linear refractive indices
  298   of the layers.
  299   We here adopt to the convention of circularly polarized field components
  300   that when looking into the oncoming wave, a left circularly polarized wave
  301   will have its vector of the electric field rotating with counterclockwise
  302   motion, while the corresponding vector of a right circularly polarized field
  303   will describe clockwise motion.
  304   This convention applies irregardless of whether we are looking into a forward
  305   propagating wave, that is to say looking in the negative $z$-direction, or
  306   looking into a backward propagating wave, in which case we instead look in the
  307   positive $z$-direction, along the $z$-axis. This convention conforms to the
  308   classical one as commonly used in optics~[5].
  309   Throughout this program, the notation $E^{\rm f}_{k_{\pm}}(z)$ is used to
  310   denote the left/right circularly polarized components of the forward traveling
  311   component of the electric field in the $k$th homogeneous layer, while
  312   $E^{\rm b}_{k_{\pm}}(z)$ in an analogous manner is used to denote the
  313   left/right circularly polarized components of the backward traveling component
  314   of the electric field, taking into account the previously described convention
  315   for circular polarization states.
  316   
  317   \fi
  318   
  319   \M{5}General solutions in the homogeneous layers.
  320   By inserting the form of the electric field as given by Eq.~(3) into the wave
  321   equation as given by Eq.~(1) under the constitutive relation given by Eq.~(1)
  322   and furthermore applying the slowly varying envelope approximation, the general
  323   solutions for the field components in loss-less media become~[1]
  324   $$
  325   \eqalignno{
  326   E^{\rm f}_{k_{\pm}}&=A^{\rm f}_{k_{\pm}}\exp[i(\omega/c)
  327   (\eta^{\rm f}_{k_{\pm}}\pm g_k)(z-z_k)+i\psi^{\rm f}_{k_{\pm}}],
  328   &(4{\rm a})\cr
  329   E^{\rm b}_{k_{\pm}}&=A^{\rm b}_{k_{\pm}}\exp[-i(\omega/c)
  330   (\eta^{\rm b}_{k_{\pm}}\mp g_k)(z-z_k)+i\psi^{\rm b}_{k_{\pm}}].
  331   &(4{\rm b})\cr
  332   }
  333   $$
  334   In these expressions $A^{\rm f,b}_{k_{\pm}}$ and $\psi^{\rm f,b}_{k_{\pm}}$
  335   are real constants of integration, determined by the boundary conditions of
  336   the $k$th layer, and $g_k=i\chi^{{\rm eem}}_{xyz}B^z_0/(2n_k)$ are the real
  337   linear magneto-optical gyration coefficients.
  338   In Eqs.~(4) the nonlinear optical and magneto-optical light-matter
  339   interactions are described by the field-dependent parameters
  340   $$
  341   \eqalignno{
  342   \eta^{\rm f}_{k_{\pm}}&=
  343   p_{k_{\pm}}(A^{{\rm f}\,2}_{k_{\pm}}+2A^{{\rm b}\,2}_{k_{\mp}})
  344   +q_{k_{\pm}}(A^{{\rm f}\,2}_{k_{\mp}}+A^{{\rm b}\,2}_{k_{\pm}}),
  345   &(5{\rm b})\cr
  346   \eta^{\rm b}_{k_{\pm}}&=
  347   p_{k_{\mp}}(A^{{\rm b}\,2}_{k_{\pm}}+2A^{{\rm f}\,2}_{k_{\mp}})
  348   +q_{k_{\mp}}(A^{{\rm b}\,2}_{k_{\mp}}+A^{{\rm f}\,2}_{k_{\pm}}),
  349   &(5{\rm b})\cr
  350   }
  351   $$
  352   where the coefficients $p_{k_{\pm}}$ and $q_{k_{\pm}}$ in the nonlinear
  353   susceptibility formalism~[3] are expressed as
  354   $$
  355   \eqalignno{
  356   p_{k_{\pm}}&=
  357   {{3}\over{8n_k}}[\chi^{{\rm eeee}}_{xxxx}-\chi^{{\rm eeee}}_{xyyx}
  358   \pm i(\chi^{{\rm eeeem}}_{xyyyz}-\chi^{{\rm eeeem}}_{xxxyz})B^z_0],
  359   &(6{\rm b})\cr
  360   q_{k_{\pm}}&=
  361   {{3}\over{8n_k}}[\chi^{{\rm eeee}}_{xxxx}+\chi^{{\rm eeee}}_{xyyx}
  362   \pm i(\chi^{{\rm eeeem}}_{xyyyz}+\chi^{{\rm eeeem}}_{xxxyz})B^z_0].
  363   &(6{\rm b})\cr
  364   }
  365   $$
  366   
  367   %\centerline{\epsfxsize=86mm\epsfbox{figures/geom/geom.2}}\smallskip
  368   %{\narrower\narrower\noindent{\bf Figure 2.} Closeup of the geometry of the
  369   %discretized model of the magneto-optical Bragg grating, illustrating the
  370   %convention of notation for the electric field of the optical wave taken
  371   %immediately to the left and right of the layer interfaces $z_k$.\par}
  372   
  373   \fi
  374   
  375   \M{6}Rotation of the polarization state across the homogeneous layers.
  376   The angle of rotation $\vartheta_k$ of the polarization ellipse of the
  377   forward traveling components around the $z$-axis in each layer is then
  378   $$
  379   \eqalign{
  380   \vartheta_k&={{\omega (z-z_k)}\over{2 n_k c}}[-i\chi^{{\rm eem}}_{xyz} B^z_0
  381   +(3/4)\chi^{{\rm eeee}}_{xyyx}(A^{{\rm f}\,2}_{k_+}-A^{{\rm f}\,2}_{k_-})
  382   %\cr&\quad
  383   +(3/8)(\chi^{{\rm eeee}}_{xxxx}-3\chi^{{\rm eeee}}_{xyyx})
  384   (A^{{\rm b}\,2}_{k_+}-A^{{\rm b}\,2}_{k_-})
  385   \cr&\quad
  386   %\cr&\quad
  387   -(3/4)i\chi^{{\rm eeeem}}_{xyyyz}
  388   (A^{{\rm f}\,2}_{k_+}+A^{{\rm f}\,2}_{k_-}) B^z_0
  389   +(3/8)i(\chi^{{\rm eeeem}}_{xxxyz}-3\chi^{{\rm eeeem}}_{xyyyz})
  390   (A^{{\rm b}\,2}_{k_+}+A^{{\rm b}\,2}_{k_-}) B^z_0].
  391   }
  392   \eqno{(7)}
  393   $$ % (Equation counterchecked to be OK July 29, 2004.)
  394   The first term in this expression describes linear Faraday rotation~[4] and
  395   leads to an effective Zeeman-like polarization state splitting of the doubly
  396   degenerate Bragg resonances. The second and third terms arise from optical
  397   Kerr-effect and lead to photo-induced modification of the ellipse rotation for
  398   forward and backward propagating waves respectively. Referring to the wave
  399   equation given by Eqs.~(1)--(2) these terms effectively act as to give
  400   photo-induced Stark-like shifts of the split Bragg resonances.
  401   Finally the fourth and fifth terms describe photo-induced magneto-optic
  402   Faraday rotation or equivalently photoinduced modification of the effective
  403   Zeeman-like splitting of the Bragg resonances. We note by passing that the
  404   third and fifth terms vanish whenever Kleinman symmetry~[3] holds.
  405   Moreover, from Eq.~(7) one obtains the Verdet coefficient~$V$ of the medium as
  406   $$
  407   V={{\omega\im[\chi^{{\rm eem}}_{xyz}]}\over{2 n_k c}},
  408   \eqno{(8)}
  409   $$
  410   describing the Faraday rotation angle per propagation length and static
  411   magnetic field intensity.
  412   
  413   \fi
  414   
  415   \M{7}Boundary conditions at the discrete interfaces. By neglecting any
  416   nonlinear
  417   effects at the discrete interfaces between the homogeneous layers, the
  418   continuity requirement of the transverse electromagnetic field across each
  419   interface is formulated by the boundary conditions
  420   $$
  421   \eqalignno{
  422   &E^{\rm f}_{k_{\pm}}(z_k)=
  423   \tau_{k_{\pm}} E^{\rm f}_{{k-1}_{\pm}}(z_k)
  424   \exp(i \omega n_{k-1} d_{k-1}/c)
  425   +\rho'_{k_{\mp}} E^{\rm b}_{k_{\mp}}(z_k),&(9{\rm a})\cr
  426   &E^{\rm b}_{k_{\mp}}(z_{k+1}) \exp(-i \omega n_k d_k/c)
  427   =\tau'_{{k+1}_{\mp}} E^{\rm b}_{{k+1}_{\mp}}(z_{k+1})
  428   +\rho_{{k+1}_{\pm}} E^{\rm f}_{k_{\pm}}(z_{k+1})
  429   \exp(i \omega n_k d_k/c),&(9{\rm b})\cr
  430   }
  431   $$
  432   for $k=1,2,\ldots,N-1$, where $d_k=z_{k+1}-z_k$ are the layer thicknesses,
  433   and where
  434   $$
  435   \eqalignno{
  436   \rho_{k_{\pm}}
  437   &={{n_{k-1}-n_k\pm(g_{k-1}-g_k)}\over{n_{k-1}+n_k\pm(g_{k-1}+g_k)}}
  438   =-\rho'_{k_{\mp}},
  439   &(10{\rm a})\cr
  440   \tau_{k_{\pm}}
  441   &={{2(n_{k-1}\pm g_{k-1})}\over{n_{k-1}+n_k\pm (g_{k-1}+g_k)}},
  442   &(10{\rm b})\cr
  443   \tau'_{k_{\mp}}
  444   &={{2(n_{k}\pm g_{k})}\over{n_{k-1}+n_k\pm (g_{k-1}+g_k)}},
  445   &(10{\rm c})\cr
  446   }
  447   $$
  448   are the reflection and transmission coefficients at the interfaces, with primed
  449   coefficients relating to the backward travelling field components, and with all
  450   coefficients including linear magneto-optical effects.
  451   The reflection and transmission coefficients obey the Stokes relation
  452   $$
  453   \tau_{k_{\pm}}=(1-\rho^2_{k_{\pm}})/\tau'_{k_{\mp}},
  454   $$
  455   reflecting the polarization state dependence of the boundary conditions at the
  456   layer interfaces.
  457   This linear approximation of the boundary conditions can be assumed to hold
  458   whenever processes such as the optical Kerr-effect gives a contribution to the
  459   electric polarization density which is small compared to the one given by the
  460   linear polarizability of the medium, or equivalently whenever the nonlinear
  461   index of refraction is small compared to the linear one, which for a linearly
  462   polarized optical wave can be formulated as the condition
  463   $$
  464   (3/4)\chi^{\rm eeee}_{xxxx}\vert E^x_{\omega}\vert^2
  465   \ll 1+\chi^{\rm ee}_{xx}.
  466   $$
  467   
  468   \fi
  469   
  470   \M{8}Solving the equations of motion for the inverse problem of transmission.
  471   In order to solve Eqs.~(4) and~(9) for the relation between incident ($k=0$)
  472   and transmitted ($k=N$) fields, we impose the additional boundary condition
  473   that the backward propagating field is zero at the exit end of the grating.
  474   By iteratively using Eqs.~(9) and~(4) in the order $k=N-1,N-2,\ldots,1$,
  475   consecutively solving for lower-indexed electric fields, we obtain an
  476   algorithm for solving the inverse problem, calculating the incident and
  477   reflected optical fields corresponding to a transmitted optical field.
  478   This algorithm is explicitly described in Section~10, {\sl The algorithm of
  479   computation}.
  480   
  481   \fi
  482   
  483   \M{9}Interpretation of the solution in terms of the Stokes parameters.
  484   The evolution of the optical field is conveniently expressed in terms of the
  485   Stokes parameters~[5], which for the input light are taken as
  486   $$
  487   \eqalignno{
  488   S_0&=\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2,\qquad
  489   S_1=2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],&(11{\rm a,b})\cr
  490   S_3&=\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2,\qquad
  491   S_2=2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].&(11{\rm c,d})\cr
  492   }
  493   $$
  494   The parameter $S_0$ is a measure of the intensity of the wave, and $S_3$ a
  495   measure of the ellipticity of the polarization state, while the parameters
  496   $S_1$ and $S_2$ indicate the amount of power contained in the $x$- and
  497   $y$-directions, serving as to determine the orientation of the polarization
  498   ellipse. Similarly, the Stokes parameters for the transmitted light are taken
  499   as
  500   $$
  501   \eqalignno{
  502   W_0&=\vert E^{\rm f}_{N_+}\vert^2+\vert E^{\rm f}_{N_-}\vert^2,\qquad
  503   W_1=2\re[E^{{\rm f}*}_{N_+}E^{\rm f}_{N_-}],&(12{\rm a,b})\cr
  504   W_3&=\vert E^{\rm f}_{N_+}\vert^2-\vert E^{\rm f}_{N_-}\vert^2,\qquad
  505   W_2=2\im[E^{{\rm f}*}_{N_+}E^{\rm f}_{N_-}],&(12{\rm c,d})\cr
  506   }
  507   $$
  508   and for the reflected light
  509   $$
  510   \eqalignno{
  511   V_0&=\vert E^{\rm b}_{0_+}\vert^2+\vert E^{\rm b}_{0_-}\vert^2,\qquad
  512   V_1=2\re[E^{{\rm b}*}_{0_+}E^{\rm b}_{0_-}],&(13{\rm a,b})\cr
  513   V_3&=\vert E^{\rm b}_{0_+}\vert^2-\vert E^{\rm b}_{0_-}\vert^2,\qquad
  514   V_2=2\im[E^{{\rm b}*}_{0_+}E^{\rm b}_{0_-}].&(13{\rm c,d})\cr
  515   }
  516   $$
  517   In terms of $S_0$ and $W_0$, the incident, transmitted, and reflected
  518   intensities in \SI\ units are $I_{\rm in}=\varepsilon_0 c S_0/2$,
  519   $I_{\rm tr}=\varepsilon_0 c W_0/2$, and $I_{\rm re}=\varepsilon_0 c V_0/2$,
  520   respectively.
  521   These respective sets of Stokes parameters can be combined to form the reduced
  522   Stokes vectors
  523   $$
  524   {\bf s}=(S_1,S_2,S_3)/S_0,\qquad
  525   {\bf w}=(W_1,W_2,W_3)/W_0,\qquad
  526   {\bf v}=(V_1,V_2,V_3)/V_0,
  527   $$
  528   which map the polarization states of the respective incident, transmitted, and
  529   reflected light onto the unitary Poincar\'e sphere, with
  530   $\vert{\bf s}\vert=\vert{\bf w}\vert=\vert{\bf v}\vert=1$,
  531   as schematically illustrated in Fig.~2.
  532   \bigskip
  533   \centerline{\epsfxsize=122mm\epsfbox{figures/stoke/stoke.1}}\smallskip
  534   {\narrower\narrower\noindent{\bf Figure 2.} The unitary Poincar\'e sphere, on
  535   which the normalized Stokes vectors ${\bf s}=(S_1,S_2,S_3)/S_0$,
  536   ${\bf w}=(W_1,W_2,W_3)/W_0$, or ${\bf v}=(V_1,V_2,V_3)/V_0$ provide
  537   representations of the polarization state of the light. The auxiliary figures
  538   show the paths traversed by the end point of the electric field vector as the
  539   observer looks into an oncoming wave propagating in the positive $z$-direction.
  540   At the upper pole of the sphere the light is left circularly polarized (LCP),
  541   while it at the lower pole is right circularly polarized (RCP), with the
  542   latitude there in between determining the ellipticity of the polarization
  543   state.
  544   At the equator, linearly polarized states of the light are represented, and
  545   their orientations are determined by the meridian. The figure was adopted from
  546   Ref.~[9].\par}
  547   \bigskip
  548   \noindent
  549   The described algorithm of calculation as described by iteratively using
  550   Eqs.~(4)--(9) can be applied to a wide range of magneto-optical gratings,
  551   singly or multiply periodic, chirped, or even random without appreciable
  552   complication, by employing a spatial oversampling of the continuous grating
  553   profiles in terms of thin layers, so as to provide an efficient finite
  554   difference scheme of computation.
  555   Examples of computations performed on magneto-optical structures of continuous
  556   spatial distribution of the optical and magneto-optical parameters can be found
  557   in Refs.[6--8]
  558   
  559   \fi
  560   
  561   \N{1}{10}The algorithm of computation. With the theory outlined we are now in
  562   position
  563   to explicitly describe the algorithm of computation of the transmission and
  564   reflection properties of the grating, as obtained by
  565   iteratively using Eqs.~(9) and~(4) in the order $k=N-1,N-2,\ldots,1$,
  566   consecutively solving for lower-indexed electric fields.
  567   This algorithm follows the one as described in Ref.~[2].
  568   
  569   \medskip
  570   \noindent{\bf Algorithm A}
  571   ({\it Calculation of amplitude reflection and transmission spectra}).
  572   The notation of geometry as used in the algorithm as here described refers to
  573   Fig.~1.
  574   Let ${E^{\rm f}_{N_{\pm}}(z_N)}$ be the complex-valued output optical
  575   field from the grating structure, as taken a coordinate $z=z^+_N$ immediately
  576   to the positive of the last interface $z_N$.
  577   The magneto-optical grating structure is described by the material
  578   parameters $n_k$, $g_k$, $p^{(k)}_{\pm}$, and
  579   $q^{(k)}_{\pm}$, which all are constant within each homogeneous
  580   layer $z_k\le z\le z_{k+1}$, $k=1,2,\ldots,N-1$.
  581   The optical fields in the respective homogeneous layers are denoted as
  582   ${E^{\rm f}_{k_{\pm}}(z)}$, for $z_k\le z\le z_{k+1}$, $k=1,2,\ldots,N-1$.
  583   
  584   \aitem[{\bf A1.}][Set boundary condition.]
  585   Apply the boundary condition $E^{\rm b}_{N_{\mp}}(z_N)=0$, that is to say,
  586   that the backward propagating field is zero after the end of the grating.
  587   
  588   \aitem[{\bf A2.}]{[Initialize forward field in layer $N-1$.]
  589   Using Eq.~(9a) for $k=N$ and furthermore applying the boundary condition in
  590   step A1 of the algorithm, set
  591   $$
  592   E^{\rm f}_{{N-1}_{\pm}}(z_N)\leftarrow
  593   [E^{\rm f}_{N_{\pm}}(z_N)/\tau_{{N}_{\pm}}]
  594   \exp[-i\omega n_{N-1}(z_N-z_{N-1})/c],
  595   $$
  596   where $\tau_{{N}_{\pm}}$ is the transmission coefficient as obtained from
  597   Eq.~(10b).
  598   }
  599   
  600   \aitem[{\bf A3.}]{[Initialize backward field in layer $N-1$.]
  601   Using Eq.~(9b) for $k=N-1$ and furthermore applying the boundary condition
  602   from A1 and the field calculated in A2, set
  603   $$
  604   E^{\rm b}_{{N-1}_{\mp}}(z_N)\leftarrow
  605   \rho_{{(N)}_{\pm}} E^{\rm f}_{{N-1}_{\pm}}(z_N)
  606   \exp[2i\omega n_{N-1}(z_N-z_{N-1})/c],
  607   $$
  608   where $\rho_{{(N)}_{\pm}}$ is the reflection coefficient as obtained from
  609   Eq.~(10a).
  610   }
  611   
  612   \aitem[{\bf A4.}]{[Initialize layer counter $k$.]
  613   Set $k\leftarrow N-1$. This is the counter which we use to keep track of
  614   the layers of the grating structure as this is traversed backwards, from the
  615   last layer $(k=N-1)$ towards the first one $(k=1)$.
  616   }
  617   
  618   \aitem[{\bf A5.}]{[Calculate propagation constants in the $k$th layer.]
  619   For a lossless medium the magnitudes of the circularly polarized field
  620   components are left invariant under propagation over a homogeneous layer,
  621   $$
  622   \vert E^{\rm f,b}_{k_{\pm}}(z_k)\vert
  623   =\vert E^{\rm f,b}_{k_{\pm}}(z_{k+1})\vert;
  624   $$
  625   and hence the field-dependent propagation constants $\eta^{\rm f}_{k_{\pm}}$
  626   and $\eta^{\rm b}_{k_{\pm}}$ of the layer $z^+_k\le z \le z^-_{k+1}$ are
  627   calculated using Eqs.~(5) as
  628   $$
  629   \eqalign{
  630   \eta^{\rm f}_{k_{\pm}}&\leftarrow
  631   p^{(k)}_{\pm}[\vert E^{\rm f}_{k_{\pm}}(z_{k+1})\vert^2
  632   +2\vert E^{\rm b}_{k_{\mp}}(z_{k+1})\vert^2]
  633   +q^{(k)}_{\pm}[\vert E^{\rm f}_{k_{\mp}}(z_{k+1})\vert^2
  634   +\vert E^{\rm b}_{k_{\pm}}(z_{k+1})\vert^2],\cr
  635   \eta^{\rm b}_{k_{\pm}}&\leftarrow
  636   p^{(k)}_{\mp}[\vert E^{\rm b}_{k_{\pm}}(z_{k+1})\vert^2
  637   +2\vert E^{\rm f}_{k_{\mp}}(z_{k+1})\vert^2]
  638   +q^{(k)}_{\mp}[\vert E^{\rm b}_{k_{\mp}}(z_{k+1})\vert^2
  639   +\vert E^{\rm f}_{k_{\pm}}(z_{k+1})\vert^2].\cr
  640   }
  641   $$
  642   }
  643   
  644   \aitem[{\bf A6.}]{[Propagate fields over the $k$th layer.]
  645   From the obtained complex-valued fields $E^{\rm f}_{k_{\pm}}(z_{k+1})$
  646   and $E^{\rm b}_{k_{\mp}}(z_{k+1})$, calculate the corresponding
  647   fields at the beginning $z=z^+_k$ of the $k$th layer by using Eqs.~(4),
  648   that is to say, set
  649   $$
  650   \eqalign{
  651   A^{\rm f}_{k_{\pm}}&\leftarrow
  652   \vert E^{\rm f}_{k_{\pm}}(z_{k+1})\vert,\cr
  653   A^{\rm b}_{k_{\pm}}&\leftarrow
  654   \vert E^{\rm b}_{k_{\pm}}(z_{k+1})\vert,\cr
  655   \psi^{\rm f}_{k_{\pm}}&\leftarrow
  656   \arg[E^{\rm f}_{k_{\pm}}(z_{k+1})]
  657   -\omega (\eta^{\rm f}_{k_{\pm}}\pm g_k)(z_{k+1}-z_k)/c,\cr
  658   \psi^{\rm b}_{k_{\pm}}&\leftarrow
  659   \arg[E^{\rm b}_{k_{\pm}}(z_{k+1})]
  660   +\omega (\eta^{\rm b}_{k_{\pm}}\mp g_k)(z_{k+1}-z_k)/c,\cr
  661   }
  662   $$
  663   and construct the fields $E^{\rm f}_{k_{\pm}}(z_k)$ and
  664   $E^{\rm b}_{k_{\pm}}(z_k)$ (taken immediately to the positive of $z_k$ in
  665   the $k$th layer) as
  666   $$
  667   \eqalign{
  668   E^{\rm f}_{k_{\pm}}(z_k)&\leftarrow
  669   A^{\rm f}_{k_{\pm}}\exp(i\psi^{\rm f}_{k_{\pm}}),\cr
  670   E^{\rm b}_{k_{\pm}}(z_k)&\leftarrow
  671   A^{\rm b}_{k_{\pm}}\exp(i\psi^{\rm b}_{k_{\pm}}).
  672   }
  673   $$
  674   }
  675   
  676   \aitem[{\bf A7.}]{[Check if the whole grating structure is traversed.]
  677   If the whole grating is traversed, that is to say if the layer counter has
  678   reached $k=1$, then proceed to A11; otherwise continue with A8.
  679   }
  680   
  681   \aitem[{\bf A8.}]{[Propagate forward traveling field components over interface
  682   located at $z=z_k$.]
  683   From the obtained complex-valued optical fields $E^{\rm f}_{k_{\pm}}(z_k)$
  684   and $E^{\rm b}_{k_{\mp}}(z_k)$, use Eq.~(9a) to calculate the corresponding
  685   forward propagating field at the negative side of the interface, at
  686   $z=z^-_k$, that is to say, set
  687   $$
  688   \eqalign{
  689   E^{\rm f}_{{k-1}_{\pm}}(z_k)&\leftarrow[E^{\rm f}_{k_{\pm}}(z_k)
  690   -\rho'_{{k}_{\mp}} E^{\rm b}_{k_{\mp}}(z_k)]
  691   \exp[-i \omega n_{k-1}(z_k-z_{k-1})/c]/\tau^{(k)}_{\pm}.
  692   }
  693   $$
  694   }
  695   
  696   \aitem[{\bf A9.}]{[Propagate backward traveling field components over interface
  697   located at $z=z_k$.]
  698   From the obtained complex-valued optical fields $E^{\rm f}_{k_{\pm}}(z_k)$
  699   and $E^{\rm b}_{k_{\mp}}(z_k)$, use Eq.~(9b) to calculate the corresponding
  700   backward propagating field at the negative side of the interface, at
  701   $z=z^-_k$, that is to say, set
  702   $$
  703   \eqalign{
  704   &E^{\rm b}_{{k-1}_{\mp}}(z_k)\leftarrow
  705   \tau^{(k)}_{\mp}{}' E^{\rm b}_{k_{\mp}}(z_k)
  706   \exp[i \omega n_{k-1}(z_k-z_{k-1})/c]
  707   +\rho^{(k)}_{\pm} E^{\rm f}_{{k-1}_{\pm}}(z_k)
  708   \exp[2i \omega n_{k-1}(z_k-z_{k-1})/c].
  709   }
  710   $$
  711   }
  712   
  713   \aitem[{\bf A10.}]{[Decrease layer counter.]
  714   Set $k\leftarrow k-1$ and return to A5.
  715   }
  716   
  717   \aitem[{\bf A11.}]{[Calculate input optical field.]
  718   From the obtained forward and backward propagating optical fields in the
  719   first ($k=1$) layer of the grating, calculate the corresponding input
  720   (forward propagating) field, that is to say, set
  721   $$
  722   E^{\rm f}_{0_{\pm}}(z_1)\leftarrow
  723   [E^{\rm f}_{1_{\pm}}(z_1)-\rho^{(1)}_{\mp}{}'E^{\rm b}_{1_{\mp}}(z_1)]
  724   /\tau^{(1)}_{\pm}.
  725   $$
  726   }
  727   
  728   \aitem[{\bf A12.}]{[Calculate reflected optical field.]
  729   From the obtained forward and backward propagating optical fields in the
  730   first ($k=1$) layer of the grating, and by using the calculated input optical
  731   field of A11, calculate the reflected optical field at the beginning of the
  732   grating, that is to say, set
  733   $$
  734   E^{\rm b}_{0_{\mp}}(z_1)\leftarrow
  735   \tau^{(1)}_{\mp}{}' E^{\rm b}_{1_{\mp}}(z_1)
  736   +\rho^{(1)}_{\pm} E^{\rm f}_{0_{\pm}}(z_1).
  737   $$
  738   }
  739   
  740   \aitem[{\bf A13.}]{[Calculate reflection and transmission coefficients.]
  741   Calculate any overall properties of the grating, such as the (intensity
  742   and polarization-state dependent) reflection and transmission
  743   $$
  744   \eqalign{
  745   R(\omega)&\leftarrow
  746   {{\vert E^{\rm b}_{0_+}(z_1)\vert^2+\vert E^{\rm b}_{0_-}(z_1)\vert^2}
  747   \over
  748   {\vert E^{\rm f}_{0_+}(z_1)\vert^2+\vert E^{\rm f}_{0_-}(z_1)\vert^2}},
  749   %\cr
  750   \qquad
  751   T(\omega)\leftarrow
  752   {{\vert E^{\rm f}_{N_+}(z_N)\vert^2+\vert E^{\rm f}_{N_-}(z_N)\vert^2}
  753   \over
  754   {\vert E^{\rm f}_{0_+}(z_1)\vert^2+\vert E^{\rm f}_{0_-}(z_1)\vert^2}},\cr
  755   }
  756   $$
  757   and terminate the algorithm.\quad\endalg}
  758   
  759   \fi
  760   
  761   \N{1}{11}The Butcher and Cotter convention.
  762   As a ``recipe'' for the degeneracy factors in theoretical nonlinear optics,
  763   Butcher and Cotter~[10] provide a very useful convention which is well worth
  764   holding on to.
  765   For a superposition of monochromatic waves, and by invoking the general
  766   property of the intrinsic permutation symmetry, the monochromatic
  767   form of the $n$th order polarization density can be written as
  768   $$
  769   (P^{(n)}_{\omega_{\sigma}})_{\mu}
  770   =\varepsilon_0\sum_{\alpha_1}\cdots\sum_{\alpha_n}\sum_{\omega}
  771   K(-\omega_{\sigma};\omega_1,\ldots,\omega_n)
  772   \chi^{(n)}_{\mu\alpha_1\cdots\alpha_n}
  773   (-\omega_{\sigma};\omega_1,\ldots,\omega_n)
  774   (E_{\omega_1})_{\alpha_1}\cdots(E_{\omega_n})_{\alpha_n}.
  775   \eqno{(14)}
  776   $$
  777   The first summations in Eq.~(14), over $\alpha_1,\ldots,\alpha_n$,
  778   is simply an explicit way of stating that the Einstein convention
  779   of summation over repeated indices holds.
  780   The summation sign $\sum_{\omega}$, however, serves as a reminder
  781   that the expression that follows is to be summed over
  782   {\sl all distinct sets of $\omega_1,\ldots,\omega_n$}.
  783   Because of the intrinsic permutation symmetry, the frequency arguments
  784   appearing in Eq.~(14) may be written in arbitrary order.
  785   
  786   By ``all distinct sets of $\omega_1,\ldots,\omega_n$'', we here mean
  787   that the summation is to be performed, as for example in the case of
  788   optical Kerr-effect, over the single set of nonlinear susceptibilities
  789   that contribute to a certain angular frequency as
  790   $(-\omega;\omega,\omega,-\omega)$ {\sl or} $(-\omega;\omega,-\omega,\omega)$
  791   {\sl or} $(-\omega;-\omega,\omega,\omega)$.
  792   In this example, each of the combinations are considered as {\sl distinct},
  793   and it is left as an arbitary choice which one of these sets that are
  794   most convenient to use (this is simply a matter of choosing notation,
  795   and does not by any means change the description of the interaction).
  796   
  797   In Eq.~(14), the degeneracy factor $K$ is formally described as
  798   $$K(-\omega_{\sigma};\omega_1,\ldots,\omega_n)=2^{l+m-n}p$$
  799   where
  800   $$
  801   \eqalign{
  802   p&={\rm the\ number\ of\ {\sl distinct}\ permutations\ of}
  803   \ \omega_1,\omega_2,\ldots,\omega_1,\cr
  804   n&={\rm the\ order\ of\ the\ nonlinearity},\cr
  805   m&={\rm the\ number\ of\ angular\ frequencies}\ \omega_k
  806   \ {\rm that\ are\ zero,\ and}\cr
  807   l&=\bigg\lbrace\matrix{1,\qquad{\rm if}\ \omega_{\sigma}\ne 0,\cr
  808   0,\qquad{\rm otherwise}.}\cr
  809   }
  810   $$
  811   In other words, $m$ is the number of DC electric fields present, and $l=0$ if
  812   the nonlinearity we are analyzing gives a static, or DC, polarization density,
  813   such as in the previously (in the spring model) described case of optical
  814   rectification in the presence of second harmonic fields (SHG).
  815   
  816   A list of frequently encountered nonlinear phenomena in nonlinear optics,
  817   including the degeneracy factors as conforming to the above convention, is
  818   given by Butcher and Cotter~[10], Table 2.1.
  819   
  820   \fi
  821   
  822   \M{12}Note on the complex representation of the optical field.
  823   Since the observable electric field of the light, in Butcher and
  824   Cotters notation taken as
  825   $$
  826   {\bf E}({\bf r},t)={{1}\over{2}}\sum_{\omega_k\ge 0}
  827   [{\bf E}_{\omega_k}\exp(-i\omega_k t)+{\bf E}^*_{\omega_k}\exp(i\omega_k t)],
  828   $$
  829   is a real-valued quantity, it follows that negative frequencies in the
  830   complex notation should be interpreted as the complex conjugate of the
  831   respective field component, or
  832   $$
  833   {\bf E}_{-\omega_k}={\bf E}^*_{\omega_k}.
  834   $$
  835   
  836   \fi
  837   
  838   \M{13}Example of degeneracy factor: The Optical Kerr-effect.
  839   Assume a monochromatic optical wave (containing forward and/or backward
  840   propagating components) polarized in the $xy$-plane,
  841   $$
  842   {\bf E}(z,t)=\re[{\bf E}_{\omega}(z)\exp(-i\omega t)]\in{\bf R}^3,
  843   $$
  844   with all spatial variation of the field contained in
  845   $$
  846   {\bf E}_{\omega}(z)={\bf e}_x E^x_{\omega}(z)
  847   +{\bf e}_y E^y_{\omega}(z)\in{\bf C}^3.
  848   $$
  849   Optical Kerr-effect is in isotropic media described by the third order
  850   susceptibility
  851   $$
  852   \chi^{(3)}_{\mu\alpha\beta\gamma}(-\omega;\omega,\omega,-\omega),
  853   $$
  854   with nonzero components of interest for the $xy$-polarized beam given in
  855   Appendix 3.3 of Butcher and Cotters book as
  856   $$
  857   \chi^{(3)}_{xxxx}=\chi^{(3)}_{yyyy},\quad
  858   \chi^{(3)}_{xxyy}=\chi^{(3)}_{yyxx}
  859   =\bigg\{\matrix{{\rm intr.\ perm.\ symm.}\cr
  860   (\alpha,\omega)\rightleftharpoons(\beta,\omega)\cr}\bigg\}=
  861   \chi^{(3)}_{xyxy}=\chi^{(3)}_{yxyx},\quad
  862   \chi^{(3)}_{xyyx}=\chi^{(3)}_{yxxy},
  863   $$
  864   with
  865   $$
  866   \chi^{(3)}_{xxxx}=\chi^{(3)}_{xxyy}+\chi^{(3)}_{xyxy}+\chi^{(3)}_{xyyx}.
  867   $$
  868   The degeneracy factor $K(-\omega;\omega,\omega,-\omega)$ is calculated as
  869   $$
  870   K(-\omega;\omega,\omega,-\omega)=2^{l+m-n}p=2^{1+0-3}3=3/4.
  871   $$
  872   From this set of nonzero susceptibilities, and using the calculated
  873   value of the degeneracy factor in the convention of Butcher and Cotter,
  874   we hence have the third order electric polarization density at
  875   $\omega_{\sigma}=\omega$ given as ${\bf P}^{(n)}({\bf r},t)=
  876   \re[{\bf P}^{(n)}_{\omega}\exp(-i\omega t)]$, with
  877   $$
  878   \eqalign{
  879   {\bf P}^{(3)}_{\omega}
  880   &=\sum_{\mu}{\bf e}_{\mu}(P^{(3)}_{\omega})_{\mu}\cr
  881   &=\{{\rm Using\ the\ convention\ of\ Butcher\ and\ Cotter}\}\cr
  882   &=\sum_{\mu}{\bf e}_{\mu}
  883   \bigg[\varepsilon_0{{3}\over{4}}\sum_{\alpha}\sum_{\beta}\sum_{\gamma}
  884   \chi^{(3)}_{\mu\alpha\beta\gamma}(-\omega;\omega,\omega,-\omega)
  885   (E_{\omega})_{\alpha}(E_{\omega})_{\beta}(E_{-\omega})_{\gamma}\bigg]\cr
  886   &=\{{\rm Evaluate\ the\ sums\ over\ } (x,y,z)
  887   {\rm\ for\ field\ polarized\ in\ the\ }xy{\rm\ plane}\}\cr
  888   &=\varepsilon_0{{3}\over{4}}\{
  889   {\bf e}_x[
  890   \chi^{(3)}_{xxxx} E^x_{\omega} E^x_{\omega} E^x_{-\omega}
  891   +\chi^{(3)}_{xyyx} E^y_{\omega} E^y_{\omega} E^x_{-\omega}
  892   +\chi^{(3)}_{xyxy} E^y_{\omega} E^x_{\omega} E^y_{-\omega}
  893   +\chi^{(3)}_{xxyy} E^x_{\omega} E^y_{\omega} E^y_{-\omega}]\cr
  894   &\qquad\quad
  895   +{\bf e}_y[
  896   \chi^{(3)}_{yyyy} E^y_{\omega} E^y_{\omega} E^y_{-\omega}
  897   +\chi^{(3)}_{yxxy} E^x_{\omega} E^x_{\omega} E^y_{-\omega}
  898   +\chi^{(3)}_{yxyx} E^x_{\omega} E^y_{\omega} E^x_{-\omega}
  899   +\chi^{(3)}_{yyxx} E^y_{\omega} E^x_{\omega} E^x_{-\omega}]\}\cr
  900   &=\{{\rm Make\ use\ of\ }{\bf E}_{-\omega}={\bf E}^*_{\omega}
  901   {\rm\ and\ relations\ }\chi^{(3)}_{xxyy}=\chi^{(3)}_{yyxx},
  902   {\rm\ etc.}\}\cr
  903   &=\varepsilon_0{{3}\over{4}}\{
  904   {\bf e}_x[
  905   \chi^{(3)}_{xxxx} E^x_{\omega} \vert E^x_{\omega}\vert^2
  906   +\chi^{(3)}_{xyyx} E^{y\,2}_{\omega} E^{x*}_{\omega}
  907   +\chi^{(3)}_{xyxy} \vert E^y_{\omega}\vert^2 E^x_{\omega}
  908   +\chi^{(3)}_{xxyy} E^x_{\omega} \vert E^y_{\omega}\vert^2]\cr
  909   &\qquad\quad
  910   +{\bf e}_y[
  911   \chi^{(3)}_{xxxx} E^y_{\omega} \vert E^y_{\omega}\vert^2
  912   +\chi^{(3)}_{xyyx} E^{x\,2}_{\omega} E^{y*}_{\omega}
  913   +\chi^{(3)}_{xyxy} \vert E^x_{\omega}\vert^2 E^y_{\omega}
  914   +\chi^{(3)}_{xxyy} E^y_{\omega} \vert E^x_{\omega}\vert^2]\}\cr
  915   &=\{{\rm Make\ use\ of\ intrinsic\ permutation\ symmetry}\}\cr
  916   &=\varepsilon_0{{3}\over{4}}\{
  917   {\bf e}_x[
  918   (\chi^{(3)}_{xxxx} \vert E^x_{\omega}\vert^2
  919   +2\chi^{(3)}_{xxyy} \vert E^y_{\omega}\vert^2) E^x_{\omega}
  920   +(\chi^{(3)}_{xxxx}-2\chi^{(3)}_{xxyy})
  921   E^{y\,2}_{\omega} E^{x*}_{\omega}\cr
  922   &\qquad\quad
  923   {\bf e}_y[
  924   (\chi^{(3)}_{xxxx} \vert E^y_{\omega}\vert^2
  925   +2\chi^{(3)}_{xxyy} \vert E^x_{\omega}\vert^2) E^y_{\omega}
  926   +(\chi^{(3)}_{xxxx}-2\chi^{(3)}_{xxyy})
  927   E^{x\,2}_{\omega} E^{y*}_{\omega}.\cr
  928   }
  929   $$
  930   For the optical field being linearly polarized, say in the $x$-direction,
  931   the expression for the polarization density is significantly simplified,
  932   to yield
  933   $$
  934   {\bf P}^{(3)}_{\omega}=\varepsilon_0(3/4){\bf e}_x
  935   \chi^{(3)}_{xxxx} \vert E^x_{\omega}\vert^2 E^x_{\omega},
  936   $$
  937   i.~e.~taking a form that can be interpreted as an intensity-dependent
  938   ($\sim\vert E^x_{\omega}\vert^2$) contribution to the refractive index
  939   (cf.~Butcher and Cotter \S 6.3.1).
  940   
  941   \fi
  942   
  943   \N{1}{14}Rigorous theory of wave propagation in isotropic media.
  944   
  945   \fi
  946   
  947   \M{15}The tensor form of the electric polarizability.
  948   In the nonlinear susceptibility formalism, with the real-valued electric field
  949   and polarization density of the medium taken according to
  950   $$
  951   {\bf E}(z,t)=\re[{\bf E}_{\omega}\exp(-i\omega t)],\qquad
  952   {\bf P}(z,t)=\re[{\bf P}_{\omega}\exp(-i\omega t)]
  953   $$
  954   respectively, the complex-valued envelope for the polarization density is here
  955   given by the expression
  956   $$
  957   \eqalign{
  958   {\bf P}_{\omega}=&\varepsilon_0[
  959   {\bf e}_{\mu}\chi^{{\rm ee}}_{\mu\alpha}E^{\alpha}_{\omega}
  960   +{\bf e}_{\mu}\chi^{{\rm eem}}_{\mu\alpha\beta}
  961   E^{\alpha}_{\omega}B^{\beta}_0
  962   +{\bf e}_{\mu}K\chi^{{\rm eeee}}_{\mu\alpha\beta\gamma}
  963   E^{\alpha}_{\omega}E^{\beta}_{\omega}E^{\gamma*}_{\omega}
  964   +{\bf e}_{\mu}K\chi^{{\rm eeeem}}_{\mu\alpha\beta\gamma\delta}
  965   E^{\alpha}_{\omega}E^{\beta}_{\omega}E^{\gamma*}_{\omega}B^{\delta}_0],
  966   \cr
  967   }
  968   \eqno{(15)}
  969   $$
  970   in which the complex conjugated field components are to be associated with
  971   negative angular frequencies, as following from the reality condition
  972   ${\bf E}_{-\omega}={\bf E}^*_{\omega}$, and where $K=3/4$ is the degeneracy
  973   factor as explicitly included in the Butcher and Cotter convention of nonlinear
  974   optical susceptibilities~[10], as described in the previous section.
  975   For isotropic media, in particular then homogeneous layers of stacked gratings
  976   or elements of a discretized continuous-profile grating, the tensor elements
  977   involved in this expression are for arbitrary frequencies of the electric
  978   and magnetic fields listed in Table 1.
  979   \medskip
  980   \noindent{\bf Table 1.} Optical and magneto-optical susceptibilities of
  981   isotropic nonlinear magneto-optical media, for arbitrary angular frequency
  982   arguments of the tensors
  983   $\chi^{\rm ee}_{\alpha\beta}(-\omega_{\sigma};\omega_{\sigma})$,
  984   $\chi^{\rm eem}_{\alpha\beta\gamma}(-\omega_{\sigma};\omega_1,\omega_2)$,
  985   $\chi^{\rm eeee}_{\alpha\beta\gamma\delta}
  986   (-\omega_{\sigma};\omega_1,\omega_2,\omega_3)$, and
  987   $\chi^{\rm eeeem}_{\alpha\beta\gamma\delta\epsilon}
  988   (-\omega_{\sigma};\omega_1,\omega_2,\omega_3,\omega_4)$.
  989   In the table, $M$ denotes the number of nonzero elements while $N$ denotes
  990   the number of nonzero and independent elements.
  991   \smallskip
  992   \noindent{\hrule width 467pt}\vskip1pt
  993   \beginvrulealign
  994   \tabskip=0pt
  995   \halign{
  996   \hbox to 34pt{\hfil\vphantom{gP}#\hfil}% first column is centered
  997   &\hbox to 34pt{\hfil#\hfil}% second column is centered
  998   &\hbox to 28pt{\hfil#\hfil}% third column is centered
  999   &\hbox to 28pt{\hfil#\hfil}% fourth column is centered
 1000   &\hbox to 343pt{\ \ #\hfil}\cr% fifth column is left aligned
 1001   \noalign{{\hrule width 467pt}\vskip 2pt}
 1002   Order&Source&$M$ & $N$ & Nonzero tensor elements\cr
 1003   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1004   1st &[1]&3&1&
 1005   $\chi^{\rm ee}_{xx}=\chi^{\rm ee}_{yy}=\chi^{\rm ee}_{zz}$\cr
 1006   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1007   2nd &[1]&6&1&
 1008   $\chi^{\rm eem}_{xyz}=\chi^{\rm eem}_{zxy}=\chi^{\rm eem}_{yzx}
 1009   =-\chi^{\rm eem}_{xzy}=-\chi^{\rm eem}_{zyx}=-\chi^{\rm eem}_{yxz}$\cr
 1010   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1011   3rd &[2]&21&3&
 1012   $\chi^{\rm eeee}_{xxxx}=\chi^{\rm eeee}_{yyyy}=\chi^{\rm eeee}_{zzzz}
 1013   =\chi^{\rm eeee}_{xxyy}+\chi^{\rm eeee}_{xyxy}+\chi^{\rm eeee}_{xyyx}$,\cr
 1014   &&&&
 1015   $\chi^{\rm eeee}_{yyzz}=\chi^{\rm eeee}_{zzyy}=\chi^{\rm eeee}_{zzxx}
 1016   =\chi^{\rm eeee}_{xxzz}=\chi^{\rm eeee}_{xxyy}=\chi^{\rm eeee}_{yyxx}$,\cr
 1017   &&&&
 1018   $\chi^{\rm eeee}_{yzyz}=\chi^{\rm eeee}_{zyzy}=\chi^{\rm eeee}_{zxzx}
 1019   =\chi^{\rm eeee}_{xzxz}=\chi^{\rm eeee}_{xyxy}=\chi^{\rm eeee}_{yxyx}$,\cr
 1020   &&&&
 1021   $\chi^{\rm eeee}_{yzzy}=\chi^{\rm eeee}_{zyyz}=\chi^{\rm eeee}_{zxxz}
 1022   =\chi^{\rm eeee}_{xzzx}=\chi^{\rm eeee}_{xyyx}=\chi^{\rm eeee}_{yxxy}$\cr
 1023   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1024   4th&[3]&60&6&
 1025   $\chi^{\rm eeeem}_{xxxyz}
 1026   =\chi^{\rm eeeem}_{yyyzx}
 1027   =\chi^{\rm eeeem}_{zzzxy}
 1028   = -\chi^{\rm eeeem}_{xxxzy}
 1029   = -\chi^{\rm eeeem}_{yyyxz}
 1030   = -\chi^{\rm eeeem}_{zzzyx}$\cr
 1031   &&&&\qquad\quad\,\,\,\,\,
 1032   $= \chi^{\rm eeeem}_{xxyzx}
 1033   +\chi^{\rm eeeem}_{xyxzx}
 1034   +\chi^{\rm eeeem}_{yxxzx}$\cr
 1035   &&&&
 1036   $\chi^{\rm eeeem}_{xxyxz}
 1037   =\chi^{\rm eeeem}_{yyzyx}
 1038   =\chi^{\rm eeeem}_{zzxzy}
 1039   = -\chi^{\rm eeeem}_{xxzxy}
 1040   = -\chi^{\rm eeeem}_{yyxyz}
 1041   = -\chi^{\rm eeeem}_{zzyzx}$\cr
 1042   &&&&\qquad\quad\,\,\,\,\,
 1043   $= -\chi^{\rm eeeem}_{xxyzx}
 1044   +\chi^{\rm eeeem}_{xyzxx}
 1045   +\chi^{\rm eeeem}_{yxzxx}$\cr
 1046   &&&&
 1047   $\chi^{\rm eeeem}_{xyxxz}
 1048   =\chi^{\rm eeeem}_{yzyyx}
 1049   =\chi^{\rm eeeem}_{zxzzy}
 1050   = -\chi^{\rm eeeem}_{xzxxy}
 1051   = -\chi^{\rm eeeem}_{yxyyz}
 1052   = -\chi^{\rm eeeem}_{zyzzx}$\cr
 1053   &&&&\qquad\quad\,\,\,\,\,
 1054   $= -\chi^{\rm eeeem}_{xyxzx}
 1055   -\chi^{\rm eeeem}_{xyzxx}
 1056   +\chi^{\rm eeeem}_{yzxxx}$\cr
 1057   &&&&
 1058   $\chi^{\rm eeeem}_{yxxxz}
 1059   =\chi^{\rm eeeem}_{zyyyx}
 1060   =\chi^{\rm eeeem}_{xzzzy}
 1061   = -\chi^{\rm eeeem}_{zxxxy}
 1062   = -\chi^{\rm eeeem}_{xyyyz}
 1063   = -\chi^{\rm eeeem}_{yzzzx}$\cr
 1064   &&&&\qquad\quad\,\,\,\,\,
 1065   $= -\chi^{\rm eeeem}_{yxxzx}
 1066   -\chi^{\rm eeeem}_{yxzxx}
 1067   -\chi^{\rm eeeem}_{yzxxx}$\cr
 1068   &&&&
 1069   $\chi^{\rm eeeem}_{xxyzx}
 1070   =\chi^{\rm eeeem}_{yyzxy}
 1071   =\chi^{\rm eeeem}_{zzxyz}
 1072   = -\chi^{\rm eeeem}_{yyxzy}
 1073   = -\chi^{\rm eeeem}_{zzyxz}
 1074   = -\chi^{\rm eeeem}_{xxzyx}$\cr
 1075   &&&&
 1076   $\chi^{\rm eeeem}_{xyxzx}
 1077   =\chi^{\rm eeeem}_{yzyxy}
 1078   =\chi^{\rm eeeem}_{zxzyz}
 1079   = -\chi^{\rm eeeem}_{xzxyx}
 1080   = -\chi^{\rm eeeem}_{yxyzy}
 1081   = -\chi^{\rm eeeem}_{zyzxz}$\cr
 1082   &&&&
 1083   $\chi^{\rm eeeem}_{yxxzx}
 1084   =\chi^{\rm eeeem}_{zyyxy}
 1085   =\chi^{\rm eeeem}_{xzzyz}
 1086   = -\chi^{\rm eeeem}_{zxxyx}
 1087   = -\chi^{\rm eeeem}_{xyyzy}
 1088   = -\chi^{\rm eeeem}_{yzzxz}$\cr
 1089   &&&&
 1090   $\chi^{\rm eeeem}_{xyzxx}
 1091   =\chi^{\rm eeeem}_{yzxyy}
 1092   =\chi^{\rm eeeem}_{zxyzz}
 1093   = -\chi^{\rm eeeem}_{xzyxx}
 1094   = -\chi^{\rm eeeem}_{yxzyy}
 1095   = -\chi^{\rm eeeem}_{zyxzz}$\cr
 1096   &&&&
 1097   $\chi^{\rm eeeem}_{yxzxx}
 1098   =\chi^{\rm eeeem}_{zyxyy}
 1099   =\chi^{\rm eeeem}_{xzyzz}
 1100   = -\chi^{\rm eeeem}_{zxyxx}
 1101   = -\chi^{\rm eeeem}_{xyzyy}
 1102   = -\chi^{\rm eeeem}_{yzxzz}$\cr
 1103   &&&&
 1104   $\chi^{\rm eeeem}_{yzxxx}
 1105   =\chi^{\rm eeeem}_{zxyyy}
 1106   =\chi^{\rm eeeem}_{xyzzz}
 1107   = -\chi^{\rm eeeem}_{zyxxx}
 1108   = -\chi^{\rm eeeem}_{xzyyy}
 1109   = -\chi^{\rm eeeem}_{yxzzz}$\cr
 1110   }\endvrulealign
 1111   \vskip-9.55pt
 1112   {\hskip-.4pt\hrule width 467pt}\vskip 1pt
 1113   \noindent{\hskip-.2pt\hrule width 467pt}
 1114   \medskip
 1115   
 1116   \vfill\eject
 1117   
 1118   \medskip
 1119   \noindent{\bf Table 2.} Optical and magneto-optical susceptibilities of
 1120   isotropic nonlinear magneto-optical media, corresponding to those as listed
 1121   in Table~1, but for angular frequency arguments corresponding to the
 1122   particular choice of optical Kerr-effect and photo-induced Faraday rotation
 1123   in presence of a static magnetic field, % ${\bf B}_0$, with
 1124   $\chi^{\rm ee}_{\alpha\beta}(-\omega;\omega)$,
 1125   $\chi^{\rm eem}_{\alpha\beta\gamma}(-\omega;\omega,0)$,
 1126   $\chi^{\rm eeee}_{\alpha\beta\gamma\delta}
 1127   (-\omega;\omega,\omega,-\omega)$, and
 1128   $\chi^{\rm eeeem}_{\alpha\beta\gamma\delta\epsilon}
 1129   (-\omega;\omega,\omega,-\omega,0)$.
 1130   As in Table~1, $M$ denotes the number of nonzero elements while $N$ denotes
 1131   the number of nonzero and independent elements.
 1132   \smallskip
 1133   \noindent{\hrule width 467pt}\vskip1pt
 1134   \beginvrulealign
 1135   \tabskip=0pt
 1136   \halign{
 1137   \hbox to 34pt{\hfil\vphantom{gP}#\hfil}% first column is centered
 1138   &\hbox to 34pt{\hfil#\hfil}% second column is centered
 1139   &\hbox to 28pt{\hfil#\hfil}% third column is centered
 1140   &\hbox to 28pt{\hfil#\hfil}% fourth column is centered
 1141   &\hbox to 343pt{\ \ #\hfil}\cr% fifth column is left aligned
 1142   \noalign{{\hrule width 467pt}\vskip 2pt}
 1143   Order&Source&$M$ & $N$ & Nonzero tensor elements\cr
 1144   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1145   1st &[1]&3&1&
 1146   $\chi^{\rm ee}_{xx}=\chi^{\rm ee}_{yy}=\chi^{\rm ee}_{zz}$\cr
 1147   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1148   2nd &[1]&6&1&
 1149   $\chi^{\rm eem}_{xyz}=\chi^{\rm eem}_{zxy}=\chi^{\rm eem}_{yzx}
 1150   =-\chi^{\rm eem}_{xzy}=-\chi^{\rm eem}_{zyx}=-\chi^{\rm eem}_{yxz}$\cr
 1151   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1152   3rd &[2]&21&3&
 1153   $\chi^{\rm eeee}_{xxxx}=\chi^{\rm eeee}_{yyyy}=\chi^{\rm eeee}_{zzzz}
 1154   =\chi^{\rm eeee}_{xxyy}+\chi^{\rm eeee}_{xyxy}+\chi^{\rm eeee}_{xyyx}$,\cr
 1155   &&&&
 1156   $\chi^{\rm eeee}_{yyzz}=\chi^{\rm eeee}_{zzyy}=\chi^{\rm eeee}_{zzxx}
 1157   =\chi^{\rm eeee}_{xxzz}=\chi^{\rm eeee}_{xxyy}=\chi^{\rm eeee}_{yyxx}$,\cr
 1158   &&&&
 1159   $\chi^{\rm eeee}_{yzyz}=\chi^{\rm eeee}_{zyzy}=\chi^{\rm eeee}_{zxzx}
 1160   =\chi^{\rm eeee}_{xzxz}=\chi^{\rm eeee}_{xyxy}=\chi^{\rm eeee}_{yxyx}$,\cr
 1161   &&&&
 1162   $\chi^{\rm eeee}_{yzzy}=\chi^{\rm eeee}_{zyyz}=\chi^{\rm eeee}_{zxxz}
 1163   =\chi^{\rm eeee}_{xzzx}=\chi^{\rm eeee}_{xyyx}=\chi^{\rm eeee}_{yxxy}$\cr
 1164   \noalign{\vskip .4pt{\hrule width 467pt}\vskip 1pt}
 1165   4th&[3]&60&6&
 1166   $\chi^{\rm eeeem}_{xxxyz}
 1167   =\chi^{\rm eeeem}_{yyyzx}
 1168   =\chi^{\rm eeeem}_{zzzxy}
 1169   = -\chi^{\rm eeeem}_{xxxzy}
 1170   = -\chi^{\rm eeeem}_{yyyxz}
 1171   = -\chi^{\rm eeeem}_{zzzyx}$\cr
 1172   &&&&\qquad\quad\,\,\,\,\,
 1173   $= \chi^{\rm eeeem}_{xxyzx}
 1174   +\chi^{\rm eeeem}_{xyxzx}
 1175   +\chi^{\rm eeeem}_{yxxzx}$\cr
 1176   &&&&
 1177   $\chi^{\rm eeeem}_{xxyxz}
 1178   =\chi^{\rm eeeem}_{yyzyx}
 1179   =\chi^{\rm eeeem}_{zzxzy}
 1180   = -\chi^{\rm eeeem}_{xxzxy}
 1181   = -\chi^{\rm eeeem}_{yyxyz}
 1182   = -\chi^{\rm eeeem}_{zzyzx}$\cr
 1183   &&&&\qquad\quad\,\,\,\,\,
 1184   $= -\chi^{\rm eeeem}_{xxyzx}
 1185   +\chi^{\rm eeeem}_{xyzxx}
 1186   +\chi^{\rm eeeem}_{yxzxx}$\cr
 1187   &&&&
 1188   $\chi^{\rm eeeem}_{xyxxz}
 1189   =\chi^{\rm eeeem}_{yzyyx}
 1190   =\chi^{\rm eeeem}_{zxzzy}
 1191   = -\chi^{\rm eeeem}_{xzxxy}
 1192   = -\chi^{\rm eeeem}_{yxyyz}
 1193   = -\chi^{\rm eeeem}_{zyzzx}$\cr
 1194   &&&&\qquad\quad\,\,\,\,\,
 1195   $= -\chi^{\rm eeeem}_{xyxzx}
 1196   -\chi^{\rm eeeem}_{xyzxx}
 1197   +\chi^{\rm eeeem}_{yzxxx}$\cr
 1198   &&&&
 1199   $\chi^{\rm eeeem}_{yxxxz}
 1200   =\chi^{\rm eeeem}_{zyyyx}
 1201   =\chi^{\rm eeeem}_{xzzzy}
 1202   = -\chi^{\rm eeeem}_{zxxxy}
 1203   = -\chi^{\rm eeeem}_{xyyyz}
 1204   = -\chi^{\rm eeeem}_{yzzzx}$\cr
 1205   &&&&\qquad\quad\,\,\,\,\,
 1206   $= -\chi^{\rm eeeem}_{yxxzx}
 1207   -\chi^{\rm eeeem}_{yxzxx}
 1208   -\chi^{\rm eeeem}_{yzxxx}$\cr
 1209   &&&&
 1210   $\chi^{\rm eeeem}_{xxyzx}
 1211   =\chi^{\rm eeeem}_{yyzxy}
 1212   =\chi^{\rm eeeem}_{zzxyz}
 1213   = -\chi^{\rm eeeem}_{yyxzy}
 1214   = -\chi^{\rm eeeem}_{zzyxz}
 1215   = -\chi^{\rm eeeem}_{xxzyx}$\cr
 1216   &&&&
 1217   $\chi^{\rm eeeem}_{xyxzx}
 1218   =\chi^{\rm eeeem}_{yzyxy}
 1219   =\chi^{\rm eeeem}_{zxzyz}
 1220   = -\chi^{\rm eeeem}_{xzxyx}
 1221   = -\chi^{\rm eeeem}_{yxyzy}
 1222   = -\chi^{\rm eeeem}_{zyzxz}$\cr
 1223   &&&&
 1224   $\chi^{\rm eeeem}_{yxxzx}
 1225   =\chi^{\rm eeeem}_{zyyxy}
 1226   =\chi^{\rm eeeem}_{xzzyz}
 1227   = -\chi^{\rm eeeem}_{zxxyx}
 1228   = -\chi^{\rm eeeem}_{xyyzy}
 1229   = -\chi^{\rm eeeem}_{yzzxz}$\cr
 1230   &&&&
 1231   $\chi^{\rm eeeem}_{xyzxx}
 1232   =\chi^{\rm eeeem}_{yzxyy}
 1233   =\chi^{\rm eeeem}_{zxyzz}
 1234   = -\chi^{\rm eeeem}_{xzyxx}
 1235   = -\chi^{\rm eeeem}_{yxzyy}
 1236   = -\chi^{\rm eeeem}_{zyxzz}$\cr
 1237   &&&&
 1238   $\chi^{\rm eeeem}_{yxzxx}
 1239   =\chi^{\rm eeeem}_{zyxyy}
 1240   =\chi^{\rm eeeem}_{xzyzz}
 1241   = -\chi^{\rm eeeem}_{zxyxx}
 1242   = -\chi^{\rm eeeem}_{xyzyy}
 1243   = -\chi^{\rm eeeem}_{yzxzz}$\cr
 1244   &&&&
 1245   $\chi^{\rm eeeem}_{yzxxx}
 1246   =\chi^{\rm eeeem}_{zxyyy}
 1247   =\chi^{\rm eeeem}_{xyzzz}
 1248   = -\chi^{\rm eeeem}_{zyxxx}
 1249   = -\chi^{\rm eeeem}_{xzyyy}
 1250   = -\chi^{\rm eeeem}_{yxzzz}$\cr
 1251   }\endvrulealign
 1252   \vskip-9.55pt
 1253   {\hskip-.4pt\hrule width 467pt}\vskip 1pt
 1254   \noindent{\hskip-.2pt\hrule width 467pt}
 1255   \medskip
 1256   
 1257   \fi
 1258   
 1259   \M{16}The vectorial form of the polarization density.
 1260   By expanding the tensorial form of the polarization denisty as given by
 1261   Eq.~(15) and using the nonzero elements of the susceptibility tensors as
 1262   given in Table~2, one after some straightforward algebra obtains the
 1263   polarization density of the medium in a vectorial form as
 1264   $$
 1265   \eqalign{
 1266   {\bf P}_{\omega}=&\varepsilon_0[\chi^{{\rm ee}}_{xx} {\bf E}_{\omega}
 1267   +\chi^{{\rm eem}}_{xyz} {\bf E}_{\omega}\times{\bf B}_0
 1268   +\threefourth
 1269   (\chi^{{\rm eeee}}_{xxxx}-\chi^{{\rm eeee}}_{xyyx})
 1270   ({\bf E}_{\omega}\cdot{\bf E}^*_{\omega}){\bf E}_{\omega}
 1271   +\threefourth\chi^{{\rm eeee}}_{xyyx}
 1272   ({\bf E}_{\omega}\cdot{\bf E}_{\omega}){\bf E}^*_{\omega}\cr
 1273   &+\threefourth\chi^{{\rm eeeem}}_{xyyyz}
 1274   ({\bf E}_{\omega}\cdot{\bf E}^*_{\omega}){\bf E}_{\omega}\times{\bf B}_0
 1275   +\threefourth\chi^{{\rm eeeem}}_{xxxyz}{\bf E}_{\omega}
 1276   ({\bf E}_{\omega}\cdot({\bf E}^*_{\omega}\times{\bf B}_0))],\cr
 1277   }
 1278   \eqno{(16)}
 1279   $$
 1280   where the degeneracy factor $K=3/4$ was explicitly stated with its numerical
 1281   value.
 1282   
 1283   \fi
 1284   
 1285   \M{17}The Polarization density in the Faraday configuration.
 1286   In the Faraday configuration~[1], the optical field propagates collinearly
 1287   with an externally applied static magnetic field ${\bf B}_0$.
 1288   Taking the direction of propagation as the $z$-axis in a Cartesian coordinate
 1289   system $({\bf e}_x,{\bf e}_y,{\bf e}_z)$ and furthermore assuming the infinite
 1290   plane wave approximation to hold for the transverse profile of the waves,
 1291   the probem of wave propagation becomes a one-dimensional nonlinear system.
 1292   
 1293   As a convention for circular polarization states, we employ the circularly
 1294   polarized basis vectors
 1295   $$
 1296   {\bf e}_{\pm}=({\bf e}_x\pm i{\bf e}_y)/\sqrt{2},
 1297   $$
 1298   which possesses the properties
 1299   $$
 1300   {\bf e}_{\pm}\times{\bf e}_z=\pm i{\bf e}_{\pm},\qquad
 1301   {\bf e}^*_{\pm}\cdot{\bf e}_{\pm}=1,\qquad
 1302   {\bf e}^*_{\pm}\cdot{\bf e}_{\mp}=0.
 1303   $$
 1304   In the circularly polarized basis, the fields are hence taken as ${\bf B}_0=
 1305   {\bf e}_z B^z_0$ and ${\bf E}_{\omega}={\bf e}_+ E^+_{\omega}+{\bf e}_-
 1306   E^-_{\omega}$, in which the electric field is the total one, including any
 1307   forward or backward traveling components. As this is inserted into Eq.~(2),
 1308   the electric polarization density of the medium hence becomes
 1309   $$
 1310   \eqalign{
 1311   {\bf e}^*_{\pm}\cdot{\bf P}_{\omega}&=
 1312   \varepsilon_0\{
 1313   (\chi^{\rm ee}_{xx}\pm i\chi^{\rm eem}_{xyz}B^z_0)E^{\pm}_{\omega}
 1314   +\threefourth[
 1315   (\chi^{\rm eeee}_{xxxx}-\chi^{\rm eeee}_{xyyx})
 1316   \vert E^{\pm}_{\omega}\vert^2+
 1317   (\chi^{\rm eeee}_{xxxx}+\chi^{\rm eeee}_{xyyx})
 1318   \vert E^{\mp}_{\omega}\vert^2]
 1319   E^{\pm}_{\omega}
 1320   \cr&\qquad
 1321   \pm\threefourth[
 1322   i(\chi^{\rm eeeem}_{xyyyz}-\chi^{\rm eeeem}_{xxxyz})B^z_0
 1323   \vert E^{\pm}_{\omega}\vert^2+
 1324   i(\chi^{\rm eeeem}_{xyyyz}+\chi^{\rm eeeem}_{xxxyz})B^z_0
 1325   \vert E^{\mp}_{\omega}\vert^2]
 1326   E^{\pm}_{\omega}
 1327   \}\cr
 1328   }
 1329   $$
 1330   From now on, the susceptibility tensor elements will for the sake of simplicity
 1331   in notation be incorporated into the index of refraction
 1332   $n=(1+\chi^{\rm ee}_{xx})^{1/2}$, the gyration coefficient
 1333   $\gamma=\chi^{\rm eem}_{xyz}B^z_0$, and the nonlinear optical and
 1334   magneto-optical parameters $p_{\pm}$ and $q_{\pm}$, defined as
 1335   $$
 1336   \eqalignno{
 1337   p_{\pm}&={{3}\over{8 n_{\pm}}}
 1338   [(\chi^{\rm eeee}_{xxxx}-\chi^{\rm eeee}_{xyyx})
 1339   \pm i(\chi^{\rm eeeem}_{xyyyz}-\chi^{\rm eeeem}_{xxxyz})B^z_0],
 1340   &(2{\rm a})\cr
 1341   q_{\pm}&={{3}\over{8 n_{\pm}}}
 1342   [(\chi^{\rm eeee}_{xxxx}+\chi^{\rm eeee}_{xyyx})
 1343   \pm i(\chi^{\rm eeeem}_{xyyyz}+\chi^{\rm eeeem}_{xxxyz})B^z_0],
 1344   &(2{\rm b})\cr
 1345   }
 1346   $$
 1347   where $n_{\pm}=(n^2\pm\gamma)^{1/2}$ are the effective refractive indices
 1348   for the circularly polarized components of the light,
 1349   to give the polarization density in Eq.~(1) in the simpler form
 1350   $$
 1351   {\bf e}^*_{\pm}\cdot{\bf P}_{\omega}=\varepsilon_0[n^2_{\pm}-1
 1352   +2n_{\pm}(p_{\pm}\vert E^{\pm}_{\omega}\vert^2
 1353   +q_{\pm}\vert E^{\mp}_{\omega}\vert^2)]E^{\pm}_{\omega}.
 1354   \eqno{(5)}
 1355   $$
 1356   The reason for includingthe refractive index in the particular scaling of the
 1357   nonlinear coefficients as apparing in $p_{\pm}$ and $q_{\pm}$ will become
 1358   obvious as the analysis proceeds with the wave equation.
 1359   As the polarization density given by Eq.~(5) is inserted into the wave
 1360   equation for the electric field inside the medium, one obtains the equation
 1361   of motion
 1362   $$
 1363   {{\partial^2 E^{\pm}_{\omega}}\over{\partial z^2}}
 1364   +{{\omega^2 n^2_{\pm}}\over{c^2}} E^{\pm}_{\omega}
 1365   +2n_{\pm}{{\omega^2}\over{c^2}}(p_{\pm}\vert E^{\pm}_{\omega}\vert^2
 1366   +q_{\pm}\vert E^{\mp}_{\omega}\vert^2)E^{\pm}_{\omega}=0.
 1367   \eqno{(5)}
 1368   $$
 1369   This equation determines the spatial evolution of the total electromagnetic
 1370   field, which may be composed of forward as well as backward traveling
 1371   components of arbitrary polarization state.
 1372   The task that now lies ahead is the separation of these components so as
 1373   to form a system which provides the basis for further analytical investigation.
 1374   
 1375   \fi
 1376   
 1377   \M{18}Separation into forward and traveling components.
 1378   It may from Eq.~(5) be noticed that in the absence of the nonlinear source
 1379   terms, the general solutions for the left and right circularly polarized
 1380   components of a forward traveling wave become
 1381   $$
 1382   E^+_{\omega}=E^{\rm f}_+\exp(in_+\omega z/c),\qquad
 1383   E^-_{\omega}=E^{\rm f}_-\exp(in_-\omega z/c),
 1384   $$
 1385   respectively,
 1386   where $E^{\rm f}_+$ and $E^{\rm f}_-$ are constants determined by the initial
 1387   conditions at some arbitrary point along the direction of propagation.
 1388   Meanwhile, the solution for the left/right circularly polarized components
 1389   of a backward traveling wave becomes
 1390   $$
 1391   E^+_{\omega}=E^{\rm b}_+\exp(in_-\omega z/c),\qquad
 1392   E^-_{\omega}=E^{\rm b}_-\exp(in_+\omega z/c),
 1393   $$
 1394   in which we here emphasize the change of effective refractive indices as
 1395   experienced compared to the forward traveling component.
 1396   This change is due to the fact that a backward traveling wave will experience
 1397   the applied static magnetic field as pointing in the opposite direction as
 1398   compared to the forward traveling wave, and hence the birefringence experienced
 1399   from the Faraday effect will be different in sign.
 1400   For a linearly polarized wave, this is manifested in that the polarization
 1401   state of the backward traveling wave will rotate in opposite direction around
 1402   the axis pointing in the direction of propagation, as compared to the forward
 1403   traveling wave.
 1404   Hence, by employing a separation according to
 1405   $$
 1406   \eqalign{
 1407   {\bf E}_{\omega}=
 1408   {\bf e}_+ &E^{\rm f}_+\exp(in_+\omega z/c)
 1409   +{\bf e}_- E^{\rm f}_-\exp(in_-\omega z/c)\cr
 1410   &+{\bf e}^*_+ E^{\rm b}_+\exp(-in_-\omega z/c)
 1411   +{\bf e}^*_- E^{\rm b}_-\exp(-in_+\omega z/c),\cr
 1412   }
 1413   \eqno{(6)}
 1414   $$
 1415   or equivalently in the scalar form
 1416   $$
 1417   E^{\pm}_{\omega}=E^{\rm f}_{\pm}\exp(i n_{\pm}\omega z/c)+
 1418   E^{\rm b}_{\mp}\exp(-in_{\pm}\omega z/c),
 1419   \eqno{(6)}
 1420   $$
 1421   the wave equation for the envelopes $E^{\rm f}_{\pm}$ and $E^{\rm b}_{\pm}$,
 1422   which generally are dependent on the coordinate $z$, naturally relaxes towards
 1423   the solution to the linear wave propagation problem, with $E^{\rm f}_{\pm}$
 1424   and $E^{\rm b}_{\pm}$ becoming constants whenever the nonlinear terms may be
 1425   neglected.
 1426   In addition, due to the separation of the linear phase evolution in this one
 1427   may also expect the field envelopes to be slowly varying functions of the
 1428   spatial coordinate $z$ under any reasonable nonlinear effects.
 1429   
 1430   By inserting Eq.~(6) into The polarization density given in Eq.~(5), the wave
 1431   equation (0) takes the form
 1432   $$
 1433   \eqalign{
 1434   \Big\{&{{\partial^2 E^{\rm f}_{\pm}}\over{\partial z^2}}
 1435   +2ik_{\pm}{{\partial E^{\rm f}_{\pm}}\over{\partial z}}
 1436   +2{{\omega^2 n_{\pm}}\over{c^2}}
 1437   [p_{\pm}(\vert E^{\rm f}_{\pm}\vert^2+2\vert E^{\rm b}_{\mp}\vert^2)
 1438   +q_{\pm}(\vert E^{\rm f}_{\mp}\vert^2+\vert E^{\rm b}_{\pm}\vert^2)]
 1439   E^{\rm f}_{\pm}
 1440   \Big\}\exp(ik_{\pm}z)\cr
 1441   &+\Big\{{{\partial^2 E^{\rm b}_{\mp}}\over{\partial z^2}}
 1442   -2ik_{\pm}{{\partial E^{\rm b}_{\mp}}\over{\partial z}}
 1443   +2{{\omega^2 n_{\pm}}\over{c^2}}
 1444   [p_{\pm}(\vert E^{\rm b}_{\mp}\vert^2+2\vert E^{\rm f}_{\pm}\vert^2)
 1445   +q_{\pm}(\vert E^{\rm b}_{\pm}\vert^2+\vert E^{\rm f}_{\mp}\vert^2)]
 1446   E^{\rm b}_{\mp}
 1447   \Big\}\exp(-ik_{\pm}z)\cr
 1448   &+2{{\omega^2 n_{\pm}}\over{c^2}}p_{\pm}
 1449   [E^{\rm f\,2}_{\pm}E^{\rm b*}_{\mp}\exp(3ik_{\pm}z)
 1450   +E^{\rm b\,2}_{\mp}E^{\rm f*}_{\pm}\exp(-3ik_{\pm}z)]\cr
 1451   &+2{{\omega^2 n_{\pm}}\over{c^2}}q_{\pm}
 1452   [E^{\rm f}_{\pm}E^{\rm f}_{\mp}E^{\rm b*}_{\pm}
 1453   \exp(i(k_{\pm}+2k_{\mp})z)
 1454   +E^{\rm b}_{\mp}E^{\rm b}_{\pm}E^{\rm f*}_{\mp}
 1455   \exp(-i(k_{\pm}+2k_{\mp})z)]\cr
 1456   &+2{{\omega^2 n_{\pm}}\over{c^2}}q_{\pm}
 1457   [E^{\rm f}_{\mp}E^{\rm b}_{\mp}E^{\rm b*}_{\pm}
 1458   \exp(i(2k_{\mp}-k_{\pm})z)
 1459   +E^{\rm b}_{\pm}E^{\rm f}_{\pm}E^{\rm f*}_{\mp}
 1460   \exp(-i(2k_{\mp}-k_{\pm})z)]=0,\cr
 1461   }
 1462   \eqno{(7)}
 1463   $$
 1464   where the notation $k_{\pm}\equiv\omega n_{\pm}/c$ was introduced for the
 1465   sake of algebraic simplicity.
 1466   In this equation, it may me noticed that the linear terms of the polarization
 1467   density have been eliminated, due to the particular choice of separation of
 1468   variables according to Eq.~(6).
 1469   However, in this form the wave propagation problem is extremely complex in its
 1470   analysis, and in order to proceed, two general approximations may be employed
 1471   without loosing much of generality. These are the slowly varying envelope
 1472   approximation and the method of projecting out spatially phase mismatched
 1473   terms.
 1474   The slowly varying envelope approximation simply assumes that the second-order
 1475   spatial derivative of the field envelope is much smaller in magnitude than
 1476   the first-order derivative multiplied by the wavevector, or in terms of the
 1477   here employed variables,
 1478   $$
 1479   \Big\vert{{\partial^2 E^{\rm f}_{\pm}}\over{\partial z^2}}\Big\vert\ll
 1480   2k_{\pm}\Big\vert{{\partial E^{\rm f}_{\pm}}\over{\partial z}}\Big\vert,
 1481   \qquad
 1482   \Big\vert{{\partial^2 E^{\rm b}_{\mp}}\over{\partial z^2}}\Big\vert\ll
 1483   2k_{\pm}\Big\vert{{\partial E^{\rm b}_{\mp}}\over{\partial z}}\Big\vert.
 1484   $$
 1485   By applying this approximation to Eq.~(7), one obtains the slightly simpler
 1486   system of equations
 1487   $$
 1488   \eqalign{
 1489   \Big\{&{{\partial E^{\rm f}_{\pm}}\over{\partial z}}
 1490   -i{{\omega}\over{c}}
 1491   [p_{\pm}(\vert E^{\rm f}_{\pm}\vert^2+2\vert E^{\rm b}_{\mp}\vert^2)
 1492   +q_{\pm}(\vert E^{\rm f}_{\mp}\vert^2+\vert E^{\rm b}_{\pm}\vert^2)]
 1493   E^{\rm f}_{\pm}
 1494   \Big\}\exp(ik_{\pm}z)\cr
 1495   &-\Big\{
 1496   {{\partial E^{\rm b}_{\mp}}\over{\partial z}}
 1497   +i{{\omega}\over{c}}
 1498   [p_{\pm}(\vert E^{\rm b}_{\mp}\vert^2+2\vert E^{\rm f}_{\pm}\vert^2)
 1499   +q_{\pm}(\vert E^{\rm b}_{\pm}\vert^2+\vert E^{\rm f}_{\mp}\vert^2)]
 1500   E^{\rm b}_{\mp}
 1501   \Big\}\exp(-ik_{\pm}z)\cr
 1502   &-i{{\omega}\over{c}}p_{\pm}
 1503   [E^{\rm f\,2}_{\pm}E^{\rm b*}_{\mp}\exp(3ik_{\pm}z)
 1504   +E^{\rm b\,2}_{\mp}E^{\rm f*}_{\pm}\exp(-3ik_{\pm}z)]\cr
 1505   &-i{{\omega}\over{c}}q_{\pm}
 1506   [E^{\rm f}_{\pm}E^{\rm f}_{\mp}E^{\rm b*}_{\pm}
 1507   \exp(i(k_{\pm}+2k_{\mp})z)
 1508   +E^{\rm b}_{\mp}E^{\rm b}_{\pm}E^{\rm f*}_{\mp}
 1509   \exp(-i(k_{\pm}+2k_{\mp})z)]\cr
 1510   &-i{{\omega}\over{c}}q_{\pm}
 1511   [E^{\rm f}_{\mp}E^{\rm b}_{\mp}E^{\rm b*}_{\pm}
 1512   \exp(i(2k_{\mp}-k_{\pm})z)
 1513   +E^{\rm b}_{\pm}E^{\rm f}_{\pm}E^{\rm f*}_{\mp}
 1514   \exp(-i(2k_{\mp}-k_{\pm})z)]=0.\cr
 1515   }
 1516   \eqno{(8)}
 1517   $$
 1518   Next step is now to project out terms which are closely phase matched, and in
 1519   particular then the terms related to the envelopes of the forward and backward
 1520   traveling components.
 1521   This is for the forward traveling parts done by multiplying Eq.~(8) by
 1522   $\exp(-ik_{\pm}z)$ and average the resulting equation over a few spatial
 1523   periods, assuming slowly varying field envelopes.
 1524   In performing this averaging, essentially two levels of approximation may be
 1525   applied: Either we keep also terms which are closely phase matched, that is
 1526   to say the term involving the exponent $\exp(i(2k_{\mp}-k_{\pm})z)$, or we
 1527   may assume that also this terms is averaged out for a sufficiently strong
 1528   Faraday effect.
 1529   This is in many cases a fully adequate approximation, in particular since
 1530   the main contribution to effects such as the ellipse rotation, optcal
 1531   Kerr-effect and photo-induced Faraday effect anyway are dominated by the
 1532   terms involving the absolute magnitude of the fields.
 1533   In the rigorous theory as here developed, however, these terms are kept for
 1534   the time being, so as to fully encounter for any effects introduced by these.
 1535   This method of projecting out the forward components is analogously applied
 1536   to the backward traveling ones, but for this case by instead multiplying the
 1537   equation by $\exp(ik_{\pm}z)$ prior to the averaging.
 1538   The resulting system of coupled equations for the envelopes of the forward
 1539   and backward traveling components of the field envelopes yield
 1540   $$
 1541   \eqalignno{
 1542   {{\partial E^{\rm f}_{\pm}}\over{\partial z}}
 1543   &=i{{\omega}\over{c}}\{
 1544   [p_{\pm}(\vert E^{\rm f}_{\pm}\vert^2+2\vert E^{\rm b}_{\mp}\vert^2)
 1545   +q_{\pm}(\vert E^{\rm f}_{\mp}\vert^2+\vert E^{\rm b}_{\pm}\vert^2)]
 1546   E^{\rm f}_{\pm}
 1547   +q_{\pm}E^{\rm f}_{\mp}E^{\rm b}_{\mp}E^{\rm b*}_{\pm}
 1548   \exp(\mp i\eta z)\}=0,&(9{\rm a})\cr
 1549   {{\partial E^{\rm b}_{\mp}}\over{\partial z}}
 1550   &=-i{{\omega}\over{c}}\{
 1551   [p_{\pm}(\vert E^{\rm b}_{\mp}\vert^2+2\vert E^{\rm f}_{\pm}\vert^2)
 1552   +q_{\pm}(\vert E^{\rm b}_{\pm}\vert^2+\vert E^{\rm f}_{\mp}\vert^2)]
 1553   E^{\rm b}_{\mp}
 1554   +q_{\pm}E^{\rm b}_{\pm}E^{\rm f}_{\pm}E^{\rm f*}_{\mp}
 1555   \exp(\pm i\eta z)\}=0,&(9{\rm b})\cr
 1556   }
 1557   $$
 1558   where the notation $\eta\equiv2(k_+-k_-)$ was introduced.
 1559   
 1560   
 1561   \fi
 1562   
 1563   \M{19}Separation of amplitude and phase of the field envelopes.
 1564   In order to proceed with Eqs.~(7), it is convenient to separate the wave
 1565   propagation into parts affecting the phase and amplitude of the forward and
 1566   backward traveling field envelopes.
 1567   In order to do so, the amplitude and phase of the field envelopes are taken
 1568   according to
 1569   $$
 1570   E^{\rm f,b}_{\pm}(z)=A^{\rm f,b}_{\pm}(z)\exp(i\psi^{\rm f,b}_{\pm}(z)),
 1571   $$
 1572   where $A^{\rm f,b}_{\pm}(z)\equiv\vert E^{\rm f,b}_{\pm}(z)\vert$ are the
 1573   amplitudes and $\psi^{\rm f,b}_{\pm}(z)$ the corresponding phases of
 1574   $E^{\rm f,b}_{\pm}(z)$.
 1575   This ansatz leads to Eqs.~(7) assuming the form
 1576   $$
 1577   \eqalignno{
 1578   \Big({{\partial A^{\rm f}_{\pm}}\over{\partial z}}
 1579   +iA^{\rm f}_{\pm}{{\partial\psi^{\rm f}_{\pm}}\over{\partial z}}\Big)
 1580   \exp(i\psi^{\rm f}_{\pm})
 1581   &=i{{\omega}\over{c}}\{
 1582   [p_{\pm}(A^{\rm f\,2}_{\pm}+2A^{\rm b\,2}_{\mp})
 1583   +q_{\pm}(A^{\rm f\,2}_{\mp}+A^{\rm b\,2}_{\pm})]
 1584   A^{\rm f}_{\pm}\exp(i\psi^{\rm f}_{\pm})
 1585   \cr&\hskip 50pt
 1586   +q_{\pm}A^{\rm f}_{\mp}A^{\rm b}_{\mp}A^{\rm b}_{\pm}
 1587   \exp(\mp i\eta z+i\psi^{\rm f}_{\mp}+i\psi^{\rm b}_{\mp}
 1588   -i\psi^{\rm b}_{\pm})\},&(11{\rm a})\cr
 1589   \Big({{\partial A^{\rm b}_{\mp}}\over{\partial z}}
 1590   +iA^{\rm b}_{\mp}{{\partial\psi^{\rm b}_{\mp}}\over{\partial z}}\Big)
 1591   \exp(i\psi^{\rm b}_{\mp})
 1592   &=-i{{\omega}\over{c}}\{
 1593   [p_{\pm}(A^{\rm b\,2}_{\mp}+2A^{\rm f\,2}_{\pm})
 1594   +q_{\pm}(A^{\rm b\,2}_{\pm}+A^{\rm f\,2}_{\mp})]
 1595   A^{\rm b}_{\mp}\exp(i\psi^{\rm b}_{\mp})
 1596   \cr&\hskip 50pt
 1597   +q_{\pm}A^{\rm b}_{\pm}A^{\rm f}_{\pm}A^{\rm f}_{\mp}
 1598   \exp(\pm i\eta z+i\psi^{\rm b}_{\pm}+i\psi^{\rm f}_{\pm}
 1599   -i\psi^{\rm f}_{\mp})\},&(11{\rm b})\cr
 1600   }
 1601   $$
 1602   or equivalently
 1603   $$
 1604   \eqalignno{
 1605   {{\partial A^{\rm f}_{\pm}}\over{\partial z}}
 1606   +iA^{\rm f}_{\pm}{{\partial\psi^{\rm f}_{\pm}}\over{\partial z}}
 1607   &=i{{\omega}\over{c}}\{
 1608   [p_{\pm}(A^{\rm f\,2}_{\pm}+2A^{\rm b\,2}_{\mp})
 1609   +q_{\pm}(A^{\rm f\,2}_{\mp}+A^{\rm b\,2}_{\pm})]A^{\rm f}_{\pm}
 1610   +q_{\pm}A^{\rm f}_{\mp}A^{\rm b}_{\mp}A^{\rm b}_{\pm}
 1611   \exp(\mp i\psi)\},&(12{\rm a})\cr
 1612   {{\partial A^{\rm b}_{\mp}}\over{\partial z}}
 1613   +iA^{\rm b}_{\mp}{{\partial\psi^{\rm b}_{\mp}}\over{\partial z}}
 1614   &=-i{{\omega}\over{c}}\{
 1615   [p_{\pm}(A^{\rm b\,2}_{\mp}+2A^{\rm f\,2}_{\pm})
 1616   +q_{\pm}(A^{\rm b\,2}_{\pm}+A^{\rm f\,2}_{\mp})]A^{\rm b}_{\mp}
 1617   +q_{\pm}A^{\rm b}_{\pm}A^{\rm f}_{\pm}A^{\rm f}_{\mp}
 1618   \exp(\pm i\psi)\},&(12{\rm b})\cr
 1619   }
 1620   $$
 1621   where the phase differences between the fields were incorporated into the
 1622   single variable $\psi=\psi(z)$, defined as
 1623   $$
 1624   \psi(z)\equiv\eta z+\psi^{\rm f}_+(z)-\psi^{\rm f}_-(z)
 1625   +\psi^{\rm b}_+(z)-\psi^{\rm b}_-(z).
 1626   \eqno{(13)}
 1627   $$
 1628   By multiplying Eqs.~(12) by respective amplitudes $A^{\rm f}_{\pm}$ and
 1629   $A^{\rm b}_{\mp}$, extracting the real parts of the left and right hand
 1630   sides of Eqs.~(12), and assumin a nonresonant medium in which $p_{\pm}$
 1631   and $q_{\pm}$ are real-valued quantities, one obtains the amplitude equations
 1632   $$
 1633   \eqalignno{
 1634   {{\partial A^{\rm f\,2}_{\pm}}\over{\partial z}}
 1635   =&\pm2({{\omega}/{c}})q_{\pm} A^{\rm f}_+ A^{\rm f}_-
 1636   A^{\rm b}_+ A^{\rm b}_- \sin(\psi),&(14{\rm a})\cr
 1637   {{\partial A^{\rm b\,2}_{\mp}}\over{\partial z}}
 1638   =&\pm2({{\omega}/{c}})q_{\pm} A^{\rm f}_+ A^{\rm f}_-
 1639   A^{\rm b}_+ A^{\rm b}_- \sin(\psi),&(14{\rm b})\cr
 1640   }
 1641   $$
 1642   while the analogous extraction of the imaginary parts instead provides the
 1643   phase equations
 1644   $$
 1645   \eqalignno{
 1646   A^{\rm f\,2}_{\pm}{{\partial\psi^{\rm f}_{\pm}}\over{\partial z}}
 1647   =&{{\omega}\over{c}}
 1648   [p_{\pm}(A^{\rm f\,2}_{\pm}+2A^{\rm b\,2}_{\mp})
 1649   +q_{\pm}(A^{\rm f\,2}_{\mp}+A^{\rm b\,2}_{\pm})]A^{\rm f\,2}_{\pm}
 1650   +{{\omega}\over{c}}q_{\pm}A^{\rm f}_+ A^{\rm f}_-
 1651   A^{\rm b}_+ A^{\rm b}_- \cos(\psi(z)),&(15{\rm a})\cr
 1652   A^{\rm b\,2}_{\mp}{{\partial\psi^{\rm b}_{\mp}}\over{\partial z}}
 1653   =&-{{\omega}\over{c}}
 1654   [p_{\pm}(A^{\rm b\,2}_{\mp}+2A^{\rm f\,2}_{\pm})
 1655   +q_{\pm}(A^{\rm b\,2}_{\pm}+A^{\rm f\,2}_{\mp})]A^{\rm b\,2}_{\mp}
 1656   -{{\omega}\over{c}}q_{\pm} A^{\rm f}_+ A^{\rm f}_-
 1657   A^{\rm b}_+ A^{\rm b}_- \cos(\psi(z)).&(15{\rm b})\cr
 1658   }
 1659   $$
 1660   The inclusion of the phases as differences into the single variable $\psi(z)$
 1661   is not, as one at a first glance might think, only just a matter of convenient
 1662   and compact notation.
 1663   In fact, by differentiating $\psi(z)$ with respect to $z$ and using the
 1664   phase evolution according to Eqs.~(10), it actually turns out that the
 1665   individual phases of the components of the optical wave can be eliminated
 1666   in favour of the single variable $\psi(z)$, hence providing an effective
 1667   reduction of the dimensionality of the problem, as will be shown in the
 1668   following sections.
 1669   
 1670   \fi
 1671   
 1672   \M{20}Invariants of motion.
 1673   As a short side track to the analysis, before proceeding with actually solving
 1674   the derived equations of motion for the amplitudes and phases of the field
 1675   components, we will now consider a few important points regarding conserved
 1676   quantities. These are important in the final stage when we separate out one
 1677   single differentail equation for one single field variable from the so far
 1678   complex and coupled system.
 1679   From the spatial evolution of the amplitudes as given in Eqs.~(14), one finds
 1680   that the magnitudes of the envelopes obey the invariants of motion
 1681   $$
 1682   {{\partial}\over{\partial z}}(A^{\rm f\,2}_+ - A^{\rm b\,2}_-)=0,\qquad
 1683   {{\partial}\over{\partial z}}(A^{\rm f\,2}_- - A^{\rm b\,2}_+)=0.
 1684   \eqno{(16)}
 1685   $$
 1686   Similarly, one also finds that the respective forward and backward traveling
 1687   circularly polarized components obey the invariants of motion
 1688   $$
 1689   {{\partial}\over{\partial z}}
 1690   (q_- A^{\rm f\,2}_+ + q_+ A^{\rm f\,2}_-)=0,\qquad
 1691   {{\partial}\over{\partial z}}
 1692   (q_+ A^{\rm b\,2}_+ + q_- A^{\rm b\,2}_-)=0.
 1693   \eqno{(17)}
 1694   $$
 1695   The invariants of motion given by Eqs.~(16) and~(17) can hence be summarized as
 1696   $$
 1697   \eqalignno{
 1698   A^{\rm f\,2}_+ - A^{\rm b\,2}_-&={\ \rm const.\ }
 1699   \equiv C_+/q_-,&(18{\rm a})\cr
 1700   A^{\rm f\,2}_- - A^{\rm b\,2}_+&={\ \rm const.\ }
 1701   \equiv C_-/q_+,&(18{\rm b})\cr
 1702   q_- A^{\rm f\,2}_+ + q_+ A^{\rm f\,2}_-&={\ \rm const.\ }\equiv
 1703   I_{\rm f},&(18{\rm c})\cr
 1704   q_+ A^{\rm b\,2}_+ + q_- A^{\rm b\,2}_-&={\ \rm const.\ }\equiv
 1705   I_{\rm b}.&(18{\rm d})\cr
 1706   }
 1707   $$
 1708   The reason for this particular choice of the form of the constants of motion,
 1709   with $C_+$ and $C_-$ scaled to be in units of $q_-$ and $q_+$, respectively,
 1710   is motivated later on by simplifying the notation when it comes to choosing
 1711   a normalized form for the equations of motion in the final stage of their
 1712   solving.
 1713   As Eqs.~(18) imply that the invariants of motion for the general, $z$-dependent
 1714   envelopes can be formulated as the linear algebraic system
 1715   $$
 1716   \pmatrix{
 1717   q_-&0&0&-q_-\cr
 1718   0&q_+&-q_+&0\cr
 1719   q_-&q_+&0&0\cr
 1720   0&0&q_+&q_-\cr
 1721   }
 1722   \pmatrix{A^{\rm f\,2}_+(z)\cr A^{\rm f\,2}_-(z)\cr
 1723   A^{\rm b\,2}_+(z)\cr A^{\rm b\,2}_-(z)\cr}
 1724   =\pmatrix{C_+\cr C_-\cr I_{\rm f}\cr I_{\rm b}\cr},
 1725   \eqno{(19)}
 1726   $$
 1727   one may be tempted to draw the conclusion that all envelopes
 1728   are constant with respect to the spatial coordinate~$z$.
 1729   However, this is a wrong conclusion, as one easily can verify that the
 1730   system~(18) is underdetermined, with a zero determinant of the system matrix,
 1731   as appearing in Eq.~(19).
 1732   
 1733   
 1734   \fi
 1735   
 1736   \M{21}Elimination of absolute phase dependence.
 1737   In order to reduce the algebraic complexity of Eqs.~(14) and~(15), which is
 1738   necessary in order proceed with the analytical theory of their evolution, we
 1739   will now eliminate the absolute phases of the fields in favour of the single
 1740   variable $\psi=\psi(z)$, which describes  the phase difference between the
 1741   four field components $E^{\rm f}_+$, $E^{\rm f}_-$, $E^{\rm b}_+$ and
 1742   $E^{\rm b}_-$.
 1743   This will reduce the dimension of of the problem from the original eight
 1744   variables present in Eqs.~(14) and~(15), down to a total of five coupled
 1745   variables and equations.
 1746   By differentiating the variable $\psi(z)$ with respect to $z$ and using
 1747   Eqs.~(10) one finds
 1748   $$
 1749   \eqalign{
 1750   {{\partial\psi}\over{\partial z}}
 1751   &=\eta
 1752   +{{\partial\psi^{\rm f}_+}\over{\partial z}}
 1753   -{{\partial\psi^{\rm f}_-}\over{\partial z}}
 1754   +{{\partial\psi^{\rm b}_+}\over{\partial z}}
 1755   -{{\partial\psi^{\rm b}_-}\over{\partial z}}\cr
 1756   &=\eta
 1757   +{{\omega}\over{c}}[p_+(A^{\rm f\,2}_++2A^{\rm b\,2}_-)
 1758   +q_+(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]
 1759   +{{\omega}\over{c}}q_+
 1760   {{A^{\rm f}_- A^{\rm b}_- A^{\rm b}_+}\over{A^{\rm f}_+}}
 1761   \cos(\psi)
 1762   \cr&\qquad\qquad
 1763   -{{\omega}\over{c}}[p_-(A^{\rm f\,2}_-+2A^{\rm b\,2}_+)
 1764   +q_-(A^{\rm f\,2}_++A^{\rm b\,2}_-)]
 1765   -{{\omega}\over{c}}q_-
 1766   {{A^{\rm f}_+ A^{\rm b}_+ A^{\rm b}_-}\over{A^{\rm f}_-}}
 1767   \cos(\psi)
 1768   \cr&\qquad\qquad
 1769   -{{\omega}\over{c}}[p_-(A^{\rm b\,2}_++2A^{\rm f\,2}_-)
 1770   +q_-(A^{\rm b\,2}_-+A^{\rm f\,2}_+)]
 1771   -{{\omega}\over{c}}q_-
 1772   {{A^{\rm b}_- A^{\rm f}_- A^{\rm f}_+}\over{A^{\rm b}_+}}
 1773   \cos(\psi)
 1774   \cr&\qquad\qquad
 1775   +{{\omega}\over{c}}[p_+(A^{\rm b\,2}_-+2A^{\rm f\,2}_+)
 1776   +q_+(A^{\rm b\,2}_++A^{\rm f\,2}_-)]
 1777   +{{\omega}\over{c}}q_+
 1778   {{A^{\rm b}_+ A^{\rm f}_+ A^{\rm f}_-}\over{A^{\rm b}_-}}
 1779   \cos(\psi)\cr
 1780   &=\eta
 1781   +{{\omega}\over{c}}[3p_+(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1782   +2q_+(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]
 1783   -{{\omega}\over{c}}[3p_-(A^{\rm f\,2}_-+A^{\rm b\,2}_+)
 1784   +2q_-(A^{\rm f\,2}_++A^{\rm b\,2}_-)]
 1785   \cr&\qquad\qquad
 1786   +{{\omega}\over{c}}\Big(
 1787   q_+ {{A^{\rm f}_- A^{\rm b}_- A^{\rm b}_+}\over{A^{\rm f}_+}}
 1788   -q_- {{A^{\rm f}_+ A^{\rm b}_+ A^{\rm b}_-}\over{A^{\rm f}_-}}
 1789   -q_- {{A^{\rm b}_- A^{\rm f}_- A^{\rm f}_+}\over{A^{\rm b}_+}}
 1790   +q_+ {{A^{\rm b}_+ A^{\rm f}_+ A^{\rm f}_-}\over{A^{\rm b}_-}}\Big)
 1791   \cos(\psi)\cr
 1792   &=\big\{{\rm\ Use\ Eqs.~(14)\ in\ substituting\ for\ terms\ in\ the\
 1793   second\ line\ }\big\}\cr
 1794   &=\eta
 1795   +{{\omega}\over{c}}[(3p_+-2q_-)(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1796   -(3p_--2q_+)(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]
 1797   \cr&\qquad\qquad
 1798   +\Big(
 1799   {{1}\over{A^{\rm f}_+}}{{\partial A^{\rm f}_+}\over{\partial z}}
 1800   +{{1}\over{A^{\rm f}_-}}{{\partial A^{\rm f}_-}\over{\partial z}}
 1801   +{{1}\over{A^{\rm b}_+}}{{\partial A^{\rm b}_+}\over{\partial z}}
 1802   +{{1}\over{A^{\rm b}_-}}{{\partial A^{\rm b}_-}\over{\partial z}}
 1803   \Big){{\cos(\psi)}\over{\sin(\psi)}}\cr
 1804   &=\bigg\{{\rm\ Use\ }{{1}\over{A^{\rm f\,b}_{\pm}}}
 1805   {{\partial A^{\rm f,b}_{\pm}}\over{\partial z}}
 1806   ={{\partial}\over{\partial z}}\ln A^{\rm f,b}_{\pm}{\rm\ and\ }
 1807   \cos(\psi)/\sin(\psi)\equiv\cot(\psi)\bigg\}\cr
 1808   &=\eta
 1809   +{{\omega}\over{c}}[(3p_+-2q_-)(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1810   -(3p_--2q_+)(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]
 1811   \cr&\qquad\qquad
 1812   +\Big(
 1813   {{\partial}\over{\partial z}}\ln A^{\rm f}_+
 1814   +{{\partial}\over{\partial z}}\ln A^{\rm f}_-
 1815   +{{\partial}\over{\partial z}}\ln A^{\rm b}_+
 1816   +{{\partial}\over{\partial z}}\ln A^{\rm b}_-
 1817   \Big)\cot(\psi)\cr
 1818   &=\eta
 1819   +{{\omega}\over{c}}[(3p_+-2q_-)(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1820   -(3p_--2q_+)(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]
 1821   +\cot(\psi){{\partial}\over{\partial z}}
 1822   \ln(A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-).\cr
 1823   }
 1824   $$
 1825   Thus, by returning to the amplitude evolution described by Eqs.~(14) and by
 1826   defining the short-hand notation
 1827   $$
 1828   r_{\pm}\equiv(3p_{\pm}-2q_{\mp})
 1829   $$
 1830   for the coefficients of the nonlinear terms, the evolution of the optical
 1831   field can be summarized with the considerably simplified system of coupled
 1832   and nonlinear differential equations
 1833   $$
 1834   \eqalignno{
 1835   &{{\partial A^{\rm f\,2}_{\pm}}\over{\partial z}}
 1836   =\pm2({{\omega}/{c}})q_{\pm} A^{\rm f}_+ A^{\rm f}_-
 1837   A^{\rm b}_+ A^{\rm b}_- \sin(\psi),&(19{\rm a})\cr
 1838   &{{\partial A^{\rm b\,2}_{\mp}}\over{\partial z}}
 1839   =\pm2({{\omega}/{c}})q_{\pm} A^{\rm f}_+ A^{\rm f}_-
 1840   A^{\rm b}_+ A^{\rm b}_- \sin(\psi),&(19{\rm b})\cr
 1841   &{{\partial\psi}\over{\partial z}}
 1842   =\eta+({{\omega}/{c}})[r_+(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1843   -r_-(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]
 1844   +\cot(\psi){{\partial}\over{\partial z}}
 1845   \ln(A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-).&(19{\rm c})\cr
 1846   }
 1847   $$
 1848   Notice that the absolute phases of the field components now have been entirely
 1849   eliminated in favour of $\psi=\psi(z)$, as was the goal outset in the beginning
 1850   of this section.
 1851   The next step in the analysis is to eliminate also the relative phase from the
 1852   equations of motion, so as to provide an autonomous system only involving the
 1853   field amplitudes $A^{\rm f}_{\pm}$ and $A^{\rm b}_{\pm}$.
 1854   
 1855   \fi
 1856   
 1857   \M{22}Elimination of the relative phase.
 1858   The equations of motion given by Eqs.~(19) are considerably reduced in their
 1859   algebraic complexity as compared to the original ones, as given by Eqs.~(1).
 1860   However, there are still some simplifications which can be applied to further
 1861   reduce the complexity, in particular then the elimination of the phase
 1862   altogether, as will now be shown.
 1863   
 1864   The trick to apply is to first multiply the left and right hand sides of
 1865   Eq.~(19{\rm c}) with
 1866   $A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-\sin(\psi)$, expanding the
 1867   spatial derivative on the right hand side, and rearrange the terms to obtain
 1868   $$
 1869   \eqalign{
 1870   &\cos(\psi){{\partial}\over{\partial z}}
 1871   (A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-)
 1872   -A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-
 1873   \sin(\psi){{\partial\psi}\over{\partial z}}
 1874   \cr&\qquad\qquad
 1875   =-\{\eta
 1876   +({{\omega}/{c}})[r_+(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1877   -r_-(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]\}
 1878   A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-\sin(\psi).\cr
 1879   }
 1880   \eqno{(20)}
 1881   $$
 1882   In this equation, we immediately find that the left hand side is the
 1883   spatial derivative of
 1884   $A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-\cos(\psi)$, so we may start
 1885   looking for rewriting the right hand side as a spatial derivative as well,
 1886   in which case we would end up with an integrable equation.
 1887   In this search for a form of the right hand side which could be integrated,
 1888   the appearance of the factor $A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-
 1889   \sin(\psi)$ leads to using either of Eqs.~(19{\rm a}) or~(19{\rm b}) to
 1890   express this term as a derivative of the amplitudes instead, hopefully leading
 1891   to the right hand side as a polynomial form which is easily integrated.
 1892   Thus, Eq.~(20) can be rewritten as
 1893   $$
 1894   \eqalign{
 1895   {{\partial}\over{\partial z}}
 1896   (A^{\rm f}_+ &A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-\cos(\psi))\cr
 1897   &=-\{\eta+({{\omega}/{c}})[r_+(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1898   -r_-(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]\}
 1899   A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-\sin(\psi).\cr
 1900   &=\big\{{\rm\ Use\ Eq.~(19a)\ in\ substituting\ for\ the\ factor\ }
 1901   A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-\sin(\psi)\ \big\}\cr
 1902   &=-\{\eta+({{\omega}/{c}})[r_+(A^{\rm f\,2}_++A^{\rm b\,2}_-)
 1903   -r_-(A^{\rm f\,2}_-+A^{\rm b\,2}_+)]\}
 1904   {{1}\over{2({{\omega}/{c}})q_+}}
 1905   {{\partial A^{\rm f\,2}_+}\over{\partial z}}\cr
 1906   &=\big\{{\rm\ Eliminate\ backward\ traveling\ components\ using\
 1907   Eqs.~(18a)\ and ~(18b)}\ \big\}\cr
 1908   &=-{{1}\over{q_+}}\Big\{{{\eta}\over{2({{\omega}/{c}})}}
 1909   +\onehalf
 1910   [r_+(2A^{\rm f\,2}_+-C_+/q_-)-r_-(2A^{\rm f\,2}_--C_-/q_+)]\Big\}
 1911   {{\partial A^{\rm f\,2}_+}\over{\partial z}}\cr
 1912   &=\big\{{\rm\ Eliminate\ }A^{\rm f\,2}_-{\rm\ using\ Eq.~(18c)}\ \big\}\cr
 1913   &=-{{1}\over{q_+}}\Big\{{{\eta}\over{2({{\omega}/{c}})}}
 1914   +\onehalf
 1915   [r_+(2q_-A^{\rm f\,2}_+-C_+)/q_--r_-(2(I_{\rm f}-q_-A^{\rm f\,2}_+)
 1916   -C_-)/q_+]\Big\}
 1917   {{\partial A^{\rm f\,2}_+}\over{\partial z}}\cr
 1918   &=\big\{{\rm\ Collect\ terms\ in\ powers\ of\ }A^{\rm f\,2}_+\ \big\}\cr
 1919   &=-{{1}\over{q_+}}\Big\{\Big(
 1920   {{\eta}\over{2({{\omega}/{c}})}}
 1921   -{{(q_+r_+C_+-q_-r_-C_-)}\over{2q_+q_-}}
 1922   -{{r_-I_{\rm f}}\over{q_+}}\Big)
 1923   +{{(q_+r_++q_-r_-)}\over{q_+q_-}}q_-A^{\rm f\,2}_+
 1924   \Big\} {{\partial A^{\rm f\,2}_+}\over{\partial z}}\cr
 1925   &=\big\{{\rm\ Identify\ as\ differential\ of\ polynomial\ of\ form\ }
 1926   p(A^{\rm f\,2}_+)\ \big\}\cr
 1927   &=-{{1}\over{q_+}}{{\partial}\over{\partial z}}\Big\{\Big(
 1928   {{\eta}\over{2({{\omega}/{c}})}}
 1929   -{{(q_+r_+C_+-q_-r_-C_-)}\over{2q_+q_-}}
 1930   -{{r_-I_{\rm f}}\over{q_+}}\Big)A^{\rm f\,2}_+
 1931   +{{(q_+r_++q_-r_-)}\over{2q_+q_-}}q_-A^{\rm f\,4}_+
 1932   \Big\}\cr
 1933   }
 1934   \eqno{(21)}
 1935   $$
 1936   which directly integrates to yield
 1937   $$
 1938   \eqalign{
 1939   q_+ A^{\rm f}_+ A^{\rm f}_- A^{\rm b}_+ A^{\rm b}_-\cos(\psi)
 1940   &=\Gamma/q_--\Big[\Big(
 1941   {{\eta}\over{2({{\omega}/{c}})}}
 1942   -{{(q_+r_+C_+-q_-r_-C_-)}\over{2q_+q_-}}
 1943   -{{r_-I_{\rm f}}\over{q_+}}\Big)A^{\rm f\,2}_+
 1944   +{{(q_+r_++q_-r_-)}\over{2q_+q_-}}q_-A^{\rm f\,4}_+
 1945   \Big]\cr
 1946   &=\Gamma/q_- -aA^{\rm f\,2}_+ - bq_-A^{\rm f\,4}_+,\cr
 1947   }
 1948   \eqno{(22)}
 1949   $$
 1950   where $\Gamma$ is a yet undetermined constant of integration, to be determined
 1951   later on by the boundary conditions of the homogeneous domain, and where the
 1952   short-hand notations
 1953   $$
 1954   a\equiv{{\eta}\over{2({{\omega}/{c}})}}
 1955   -{{(q_+r_+C_+-q_-r_-C_-)}\over{2q_+q_-}}
 1956   -{{r_-I_{\rm f}}\over{q_+}},\qquad
 1957   b\equiv{{(q_+r_++q_-r_-)}\over{2q_+q_-}},
 1958   \eqno{(24)}
 1959   $$
 1960   were introduced.
 1961   The relative phase $\psi$ is now from Eq.~(22) determined in terms of the
 1962   field amplitudes, and in order to get an expression for the factor $\sin(\psi)$
 1963   which appears in the amplitude equations, for example in Eq.~(19a), we may
 1964   employ the trigonometric identity $\sin^2(\psi)+\cos^2(\psi)=1$, from which
 1965   we obtain Eq.~(19a) as
 1966   $$
 1967   \eqalign{
 1968   &{{\partial A^{\rm f\,2}_+}\over{\partial z}}=(-1)^k 2({{\omega}/{c}})
 1969   [q^2_+ A^{\rm f\,2}_+ A^{\rm f\,2}_- A^{\rm b\,2}_+ A^{\rm b\,2}_-
 1970   -(\Gamma/q_- -aA^{\rm f\,2}_+ - bq_-A^{\rm f\,4}_+)^2]^{1/2},\cr
 1971   }
 1972   \eqno{(23)}
 1973   $$
 1974   where the undeterminacy of the sign of $\sin(\psi)=\pm(1-\cos^2(\psi))^{1/2}$
 1975   is included in the factor $(-1)^k$, with~$k$ being a yet undetermined integer.
 1976   In this nonlinear differential equation, also the relative phase~$\psi$ is
 1977   eliminated, and the mathematical dimension of the problem at hand has been
 1978   reduced from in total eight variables to the present four ones given by the
 1979   linearly independent field amplitudes.
 1980   It may be observed that in deriving Eq.~(23), the invariants of motion given
 1981   by Eqs.~~(18) had to be employed, in order to be able to write the right-hand
 1982   side as a total derivative.
 1983   As the invariants of motion equally well still can be employed to further
 1984   reduce the dimensionality of the problem by eliminating $A^{\rm f\,2}_-$,
 1985   $A^{\rm b\,2}_+$ and $A^{\rm b\,2}_-$, we can at this stage easily see the
 1986   outline to finally formulate the problem of wave propagation as one single
 1987   differential equation involving only the single variable $A^{\rm f\,2}_+$.
 1988   
 1989   \fi
 1990   
 1991   \M{23}Elimination of redundant field amplitudes.
 1992   In this section, the dimensionality of the wave propagation problem is
 1993   finally reduced to yield a one-dimensional problem in one single variable
 1994   $A^{\rm f\,2}_+$.
 1995   By  eliminating the field amplitudes $A^{\rm f\,2}_-$,
 1996   $A^{\rm b\,2}_+$ and $A^{\rm b\,2}_-$ with the use of the
 1997   invariants of motion as given by Eqs.~(18), one obtains Eq.~(23) as
 1998   $$
 1999   \eqalign{
 2000   {{\partial A^{\rm f\,2}_+}\over{\partial z}}
 2001   &=(-1)^k 2({{\omega}/{c}})[q^2_+ A^{\rm f\,2}_+
 2002   \underbrace{{q^{-1}_+}(I_{\rm f}-q_- A^{\rm f\,2}_+)
 2003   }_{=A^{\rm f\,2}_-(z)}
 2004   \underbrace{{q^{-1}_+}(I_{\rm f}-q_- A^{\rm f\,2}_+ - C_-)
 2005   }_{=A^{\rm b\,2}_+(z)}
 2006   \underbrace{{q^{-1}_-}(q_-A^{\rm f\,2}_+ - C_+)
 2007   }_{=A^{\rm b\,2}_-(z)}
 2008   \cr&\hskip270pt
 2009   -{q^{-2}_-}(\Gamma -aq_-A^{\rm f\,2}_+ - bq^2_-A^{\rm f\,4}_+)^2]^{1/2}\cr
 2010   &=(-1)^k 2{{({{\omega}/{c}})}\over{q_-}}[q_-A^{\rm f\,2}_+
 2011   (I_{\rm f}-q_- A^{\rm f\,2}_+)
 2012   (I_{\rm f}-q_- A^{\rm f\,2}_+ - C_-)
 2013   (q_-A^{\rm f\,2}_+ - C_+)
 2014   -(\Gamma -aq_-A^{\rm f\,2}_+ - bq^2_-A^{\rm f\,4}_+)^2]^{1/2}.\cr
 2015   }
 2016   \eqno{(24)}
 2017   $$
 2018   Hence, by taking the normalized and dimensionless field amplitude variable
 2019   $v$ and the normalized and dimensionless coordinate $\zeta$ according to
 2020   $$
 2021   v\equiv q_-A^{\rm f\,2}_+,\qquad\zeta\equiv 2\omega z/c,\eqno{(25)}
 2022   $$
 2023   we obtain the normalized equation for the amplitude of the left circularly
 2024   polarized forward traveling field component as
 2025   $$
 2026   {{\partial v}\over{\partial\zeta}}=(-1)^k
 2027   [v(I_{\rm f}-v)(I_{\rm f}-v-C_-)(v-C_+)-(\Gamma-av-bv^2)^2]^{1/2}.
 2028   \eqno{(26)}
 2029   $$
 2030   This nonlinear ordinary differential equation is now well suited for numerical
 2031   evaluation, or even analytical as will be shown next. It should however be
 2032   noticed that the field amplitudes $A^{\rm f}_+$, $A^{\rm f}_-$, $A^{\rm b}_+$,
 2033   and $A^{\rm b}_-$ are all involved implicitly through the invariants of motion
 2034   $I_{\rm f}$, $C_+$, and $C_-$, as given by Eqs.~(18), and also via the
 2035   introduced short-hand notations $a$ and $b$ as introduced in Eq.~(24); also
 2036   the relative phase $\psi$ of the fields evaluated at some coordinate $\zeta_0$
 2037   enters as one parameter to encounter for, via the integration constant $\Gamma$
 2038   and Eq.~(22).
 2039   
 2040   
 2041   \fi
 2042   
 2043   \M{24}Formulation in terms of an elliptic integral.
 2044   The nonlinear ordinary differential equation~(26) for $v=v(\zeta)$ can be
 2045   formulated as
 2046   $$
 2047   {{\partial v}\over{\partial\zeta}}=(-1)^k[f(v)]^{1/2},\eqno{(27)}
 2048   $$
 2049   where
 2050   $$
 2051   f(v)\equiv a_4v^4+4a_3v^3+6a_2v^2+4a_1v+a_0
 2052   $$
 2053   is a quartic polynomial in the normalized field amplitudes $v$, and in which
 2054   the coefficients $a_j$, for $j=1,\ldots,4$, are explicitly given in terms of
 2055   the previously used algebraic symbols as
 2056   $$
 2057   \eqalignno{
 2058   a_0&=-\Gamma^2,&(28{\rm a})\cr
 2059   a_1&=(2\Gamma a-I^2_{\rm f}C_+ +I_{\rm f}C_+C_-)/4,&(28{\rm b})\cr
 2060   a_2&=(I^2_{\rm f}+2\Gamma b+2I_{\rm f}C_+-I_{\rm f}C_-
 2061   -a^2-C_+C_-)/6,&(28{\rm c})\cr
 2062   a_3&=(-2I_{\rm f}+C_- -C_--2ab)/4,&(28{\rm d})\cr
 2063   a_4&=1-b^2.&(28{\rm e})\cr
 2064   }
 2065   $$
 2066   The solution $v(\zeta)$ is then from Eq.~(27) given by the integral equation
 2067   $$
 2068   \int^{v(\zeta)}_{v(\zeta_0)}
 2069   {{dx}\over{(a_4x^4+4a_3x^3+6a_2x^2+4a_1x+a_0)^{1/2}}}
 2070   =(-1)^k\int^{\zeta}_{\zeta_0}\,d\zeta=(-1)^k(\zeta-\zeta_0),
 2071   \eqno{(29)}
 2072   $$
 2073   where $v_0\equiv v(\zeta_0)$ with $\zeta_0$ being an arbitrarily chosen
 2074   reference coordinate $\zeta_0$ along the axis of wave propagation.
 2075   
 2076   The left-hand side of Eq.~(29) constitutes an elliptic integral which
 2077   principally can be reduced to the Legendre-Jacobi normal form by means
 2078   of suitable homographic substitutions and the use of Jacobian elliptic
 2079   functions.
 2080   This implies the solving for the roots of the characteristic polynomial
 2081   equation $f(v)=0$ which, however perfectly well analytically solvable,
 2082   though is an algebraically very cumbersome task.
 2083   
 2084   A more convenient method is to instead employ notation and method of solution
 2085   by Weierstrass, which turns out to considerably simplify the algebra, and which
 2086   provides an analytic solution which can be computed analytically in terms of
 2087   the Weierstrass elliptic function~[11--13] $\wp(\zeta)=\wp(\zeta;g_2,g_3)$ with
 2088   the quartic invariants $g_2$ and $g_3$ as
 2089   $$
 2090   \eqalign{
 2091   g_2&\equiv a_0a_4-4a_1a_3+3a^2_2,
 2092   \qquad % &\cr
 2093   g_3\equiv
 2094   \left\vert\matrix{a_0&a_1&a_2\cr a_1&a_2&a_3\cr a_2&a_3&a_4\cr}\right\vert
 2095   =a_0a_2a_4+2a_1a_2a_3-a^3_2-a_0a^2_3-a^2_1a_4.\cr
 2096   }
 2097   $$
 2098   The solution $v(\zeta)$ of Eq.~(29) is then explicitly given as
 2099   $$
 2100   v(\zeta)=v_0+
 2101   {{\sqrt{f(v_0)}\wp'(\zeta)+{\textstyle{{1}\over{2}}}f'(v_0)
 2102   [\wp(\zeta)-{\textstyle{{1}\over{24}}}f''(v_0)]
 2103   +{\textstyle{{1}\over{24}}}f(v_0)f'''(v_0)}
 2104   \over{2[\wp(\zeta)-{\textstyle{{1}\over{24}}}f''(v_0)]^2
 2105   -{\textstyle{{1}\over{48}}}f(v_0)f^{\rm (iv)}(v_0)}}.
 2106   \eqno{(30)}
 2107   $$
 2108   That the solution given by Eq.~(30) actually {\sl is} a solution to the
 2109   differential equation~(27) can easily be verified using the MapleV code
 2110   \medskip
 2111   \leftskip=15mm
 2112   {\obeyspaces\obeylines\tt
 2113   restart:
 2114   f:=a[0]*v{\tothepower}4+4*a[1]*v{\tothepower}3+6*a[2]*v{\tothepower}2%
 2115   +4*a[3]*v+a[4];
 2116   g[2]:=a[0]*a[4]-4*a[1]*a[3]+3*a[2]{\tothepower}2;
 2117   g[3]:=a[0]*a[2]*a[4]+2*a[1]*a[2]*a[3]-a[2]{\tothepower}3-a[0]*a[3]%
 2118   {\tothepower}2-a[1]{\tothepower}2*a[4];
 2119   df[0]:=eval(f,v=v0):
 2120   df[1]:=eval(diff(f,v{\dollar}1),v=v0):
 2121   df[2]:=eval(diff(f,v{\dollar}2),v=v0):
 2122   df[3]:=eval(diff(f,v{\dollar}3),v=v0):
 2123   df[4]:=eval(diff(f,v{\dollar}4),v=v0):
 2124   tmp[1]:=sqrt(df[0])*WeierstrassPPrime(z,g[2],g[3]):
 2125   tmp[2]:=(1/2)*df[1]*(WeierstrassP(z,g[2],g[3])-(1/24)*df[2]):
 2126   tmp[3]:=(1/24)*df[0]*df[3]:
 2127   tmp[4]:=2*(WeierstrassP(z,g[2],g[3])-(1/24)*df[2]){\tothepower}2:
 2128   tmp[5]:=(1/48)*df[0]*df[4]:
 2129   v:=v0+(tmp[1]+tmp[2]+tmp[3])/(tmp[4]-tmp[5]):
 2130   p:=a[0]*v{\tothepower}4+4*a[1]*v{\tothepower}3+6*a[2]*v{\tothepower}2%
 2131   +4*a[3]*v+a[4]:
 2132   testfunc:=(diff(v,z)){\tothepower}2-p:
 2133   testfunc:=simplify(testfunc);\par}
 2134   \leftskip=0mm
 2135   \medskip
 2136   
 2137   \fi
 2138   
 2139   \M{25}Boundary conditions.
 2140   
 2141   \fi
 2142   
 2143   \N{1}{26}Revision history of the program.
 2144   \medskip
 2145   
 2146   \citem[2002-10-28]{[v.1.0]} \.{<fredrik.jonsson@proximion.com>}\hfill\break
 2147   First properly working version of the \magbragg\ program, written in plain
 2148   (\ANSI-conformant) \CEE.
 2149   
 2150   \citem[2002-11-15]{[v.1.1]} \.{<fredrik.jonsson@proximion.com>}\hfill\break
 2151   Minor changes to the blocks of the program for the generation of reflection
 2152   spectra, providing data for a talk at the MRS 2002 Fall Meeting
 2153   [F.~Jonsson and C.~Flytzanis, {\sl Theoretical model for magneto-optical Bragg
 2154   gratings}, Talk O4.7 presented at the 2002 Materials Research
 2155   Society (MRS) Fall Meeting, Boston, United States (December 2--6, 2002)].
 2156   
 2157   \citem[2003-02-18]{[v.1.2]} \.{<fredrik.jonsson@proximion.com>}\hfill\break
 2158   Modified the part of the program that writes the spatial optical field
 2159   distribution along the grating to file, so that both forward and backward
 2160   left and right circularly polarized components of the propagating fields are
 2161   written to file (using the \.{--fieldevolution} command line option).
 2162   
 2163   \citem[2003-02-25]{[v.1.3]} \.{<fredrik.jonsson@proximion.com>}\hfill\break
 2164   Transferred all source code of the \magbragg\ program from \CEE\ to \CWEB.
 2165   For information on the \CWEB\ programming language, see
 2166   \.{http://www.literateprogramming.com}.
 2167   
 2168   \citem[2003-04-18]{[v.1.4]} \.{<fredrik.jonsson@proximion.com>}\hfill\break
 2169   Added the \.{--modifylayer} option, enabling the user to manually modify
 2170   an arbitrary layer of the grating structure in linear as well as nonlinear
 2171   optical parameters, or modifying the layer thickness.
 2172   
 2173   \citem[2003-04-28]{[v.1.5]} \.{<fredrik.jonsson@proximion.com>}\hfill\break
 2174   Added the \.{--intensityevolution} option.
 2175   
 2176   \citem[2003-07-15]{[v.1.6]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2177   Added some points in the documentation regarding the philosophy behind
 2178   creating two-dimensional plots from topological graphs of Stokes-parameter
 2179   hypersurfaces.
 2180   
 2181   \citem[2003-07-22]{[v.1.7]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2182   Added the possibility of specifiying whether the electrical field displacement
 2183   or Stokes parameters should be written to file, when saving the intra-grating
 2184   field distribution via the \.{--fieldevolution} command line option.
 2185   
 2186   \citem[2003-07-23]{[v.1.8]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2187   Changed the reference phase of the calculated, final intra-grating optical
 2188   field, so that the main axis of the polarization ellipse always is directed
 2189   along the $x$-axis (corresponding to $S_2=0$ in a Stokes parameter
 2190   description) at the beginning of the grating, at $z=0$.
 2191   (The naturally appearing reference phase is relative the output field, at the
 2192   end of the grating, since $z=L$ is the spatial starting point in the inverse
 2193   algorithm.)
 2194   
 2195   \citem[2003-08-04]{[v.1.9]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2196   Added the \.{--normalize\_length\_to\_um} option, which causes the program
 2197   to write spatial distances in micrometers instead of meters.
 2198   Useful for pre-normalizing data prior to importing it into programs
 2199   for making graphs of the spatial intra-grating distribution of intensity
 2200   or polarization state.
 2201   Also added the \.{--normalize\_intensity} option, which causes the program
 2202   to write the intensity-related Stoke parameter $S_0(z)$ as the quote
 2203   with the input intensity instead, as $S_0(z)/S_0(0)$.
 2204   
 2205   \citem[2003-08-07]{[v.1.10]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2206   Added the \.{--intensityspectrumfile} option, to save a regular intensity
 2207   spectrum as function of wavelength, and not only just the complex reflection
 2208   and transmission spectra.
 2209   Using this option, the character string following it will be used as the base
 2210   filename for the generated intensity reflection spectrum, which will be named
 2211   $\langle$basename$\rangle${\tt{.irsp.dat}}, and the intensity transmission
 2212   spectrum, which will be named $\langle$basename$\rangle${\tt{.itsp.dat}}.
 2213   The format of these files are simply that the first column is the vacuum
 2214   wavelength in nanometers, and the second column the reflection or transmission
 2215   coefficients.
 2216   In addition to these two files, an additional file
 2217   $\langle$basename$\rangle${\tt{.chec.dat}} will be generated, containing
 2218   the sum of the respective reflection and transmission coefficients.
 2219   Ideally, the second column of this file should be identically one;
 2220   any deviation from this is an artefact of the limited numerical precision
 2221   in the simulation, and can be taken as a measure on the correctness
 2222   of the obtained data.
 2223   
 2224   \citem[2003-08-19]{[v.1.11]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2225   Added the \.{--normalize\_ellipticity} option, which switch the program
 2226   to writing the normalized ellipticity $S_3/S_0$ (with a numerical value
 2227   between $-1$ and~$1$) instead of the third Stokes parameter, whenever it
 2228   is to be written to disk.
 2229   Also added the \.{--scale\_stokesparams} $\langle a\rangle$ option, which
 2230   at the stage of saving the Stokes parameters to disk divides the sets
 2231   $(S_0,S_1,S_2,S_3)$, $(W_0,W_1,W_2,W_3)$, and $(V_0,V_1,V_2,V_3)$ by the
 2232   scalefactor $\langle a\rangle$ prior to writing them to disk.
 2233   This is typically a good thing to do if the program that is to post-analyze
 2234   the generated data has a poor way of handling large numbers (typically larger
 2235   than $\sim 10^{14}$ for the squared amplitudes of the components of the
 2236   electric field).
 2237   
 2238   \citem[2003-08-20]{[v.1.12]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2239   Modified the \.{Makefile} to provide a somewhat more intelligent check on
 2240   which files that need to be updated on compilation. Also updated section five,
 2241   {\it Compiling the source code}, of the documentation of the program.
 2242   
 2243   \citem[2003-08-23]{[v.1.13]} \.{<hakkasberra@hotmail.com>}\hfill\break
 2244   Added a check in the blocks that saves the full grating structure to file,
 2245   so that the program now fully recognizes the \.{--normalize\_length\_to\_um}
 2246   option.
 2247   
 2248   \citem[2003-10-06]{[v.1.14]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2249   Added a few clarifying paragraphs on the conventions used for the
 2250   magneto-optical material parameters and the exact conventions for the
 2251   circularly polarized modes as here used.
 2252   
 2253   \citem[2003-12-10]{[v.1.15]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2254   Added a few clarifying paragraphs on the scaling of the Stokes parameters
 2255   that are written to file after the finished calculations.
 2256   As a default, and as a matter of convention in electrodynamics in \SI\ units,
 2257   all Stokes parameters are given in ${\rm V}^2/{\rm m}^2$, through their
 2258   definition.
 2259   For example, the incident field (which is calculated by the program in
 2260   this inverse formulation of the problem) is expressed in terms of the Stokes
 2261   parameters as
 2262   $$
 2263   \eqalign{
 2264   S_0&=\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2,\qquad
 2265   S_1=2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr
 2266   S_3&=\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2,\qquad
 2267   S_2=2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr
 2268   }
 2269   $$
 2270   However, the direct interpretation of these quantities in terms of squared
 2271   Volts per square metres is sometimes somewhat inconvenient; therefore, those
 2272   parameters can be scaled to give an interpretation of the intensity (in regular
 2273   \SI\ units measured in Watts per square metres),
 2274   as $S'_k=(\varepsilon_0 c/2)S_k$, or explicitly
 2275   $$
 2276   \eqalign{
 2277   S'_0&=(\varepsilon_0 c/2)
 2278   [\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2],\qquad
 2279   S'_1=(\varepsilon_0 c/2)
 2280   2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr
 2281   S'_3&=(\varepsilon_0 c/2)
 2282   [\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2],\qquad
 2283   S'_2=(\varepsilon_0 c/2)
 2284   2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr
 2285   }
 2286   $$
 2287   In this representation, $S'_0$ is now identical to the incident intensity
 2288   $I_{\rm in}$ [${\rm W}/{\rm m}^2$].
 2289   In order to have those scaled Stokes parameters $S'_k$ written to file,
 2290   rather than the default ones, one convenient possibility is to use the
 2291   previously added \.{--scale\_stokesparams} option, to include
 2292   \.{--scale\_stokesparams 1.327209e-3} at the command line when invoking
 2293   the program. This numerical value of the scaling is obtained from
 2294   $$
 2295   \eqalign{
 2296   \varepsilon_0 c/2
 2297   &=(8.854187817\ldots\times 10^{-12}\ {\rm F}/{\rm m})
 2298   \times(2.99792458\times 10^8\ {\rm m}/{\rm s})/2\cr
 2299   &\approx 1.327209\times 10^{-3}\ {\rm F}/{\rm s}.\cr
 2300   }
 2301   $$
 2302   In regular \SI\ units as here used, the physical dimension of the
 2303   quantity $\varepsilon_0 c/2$ is $[({\rm A}\cdot{\rm s})/({\rm V}\cdot{\rm m})]
 2304   \cdot[{\rm m}/{\rm s}]=[{\rm A}/{\rm V}]$, so the physical dimension of
 2305   $(\varepsilon_0 c/2)S_k$ is hence $[{\rm A}/{\rm V}]\cdot[{\rm V}^2/{\rm m}^2]
 2306   =[{\rm W}/{\rm m}^2]$, as expected for an intensity measure (power per unit
 2307   area in the plane orthogonal to the direction of wave propagation).
 2308   
 2309   \citem[2003-12-10]{[v.1.16]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2310   Added the \.{--intensityinfo} option, in order to track down the maximum
 2311   optical intensity that is present inside (or outside) the magneto-optical
 2312   grating structure.
 2313   
 2314   \citem[2003-12-17]{[v.1.17]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2315   Added the \.{--trmtraject} option, in order to check the polarization
 2316   state evolution of the transmitted light for a varying incident intensity,
 2317   keeping the incident polarization state fixed.
 2318   Typically, we use two-dimensional interpolation to get the trajectory
 2319   of the transmitted polarization state as function of the incident light
 2320   (the incident light typically being of a fixed polarization state, with
 2321   a varying intensity). This trajectory can now be used as input to the
 2322   \magbragg\ program in the invserse formulation of the problem, for the
 2323   generation of Poincar\'e maps corresponding to cases with constant incident
 2324   polarization states and varying input intensity.
 2325   
 2326   \citem[2004-03-10]{[v.1.18]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2327   Last week in Stockholm I bought a new computer, a silvery Apple Macintosh
 2328   Powerbook~G4 running Apple \OSX\ (10.3 Panther). As I recompiled the
 2329   \CWEB\ source for the \magbragg\ program, still using the \GNU\ \CEE-compiler
 2330   (\GCC) for the executable file, I got complaints about the definition of the
 2331   \.{cabs} routine as shadowing a previously defined function.
 2332   This is a complaint that I never previously had with \GCC\ under \CYGWIN\ and
 2333   Windows 2000, and it is obvious that the \.{math.h} header file of \GCC\ has
 2334   been slightly changed lately.
 2335   However, after globally changing the routine name from \.{cabs} to
 2336   \.{cdabs} (which anyway is better since the new name also indicates that
 2337   it takes complex numbers in  {\sl double}\/ precision as input), there
 2338   were no more complaints, and the program now executes as expected in the
 2339   \OSX\ environment.
 2340   
 2341   \citem[2004-04-23]{[v.1.19]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2342   Fixed a bug in the initialization of chirped modulation of magneto-optical
 2343   parameters, for which the last $z$-coordinate of the discretized grating,
 2344   $z_N$, never was set.
 2345   
 2346   \citem[2004-04-24]{[v.1.20]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2347   Added the \.{--gyroperturb} option in order to provide a way of locally
 2348   manipulating and perturbing the gyration constant of the medium. This option
 2349   was added since I got this idea that a perturbation introduced by external
 2350   means, for example via a current carrying wire oriented orthogonally to the
 2351   direction of propagation of light in the Faraday configuration, could be used
 2352   for opening up a window in the transmission window of a chirped Bragg grating.
 2353   The syntax of the \.{--gyroperturb} option is simply \.{--gyroperturb}
 2354   $\langle z_{\rm p}\rangle$ $\langle a_{\rm p}\rangle$
 2355   $\langle w_{\rm p}\rangle$, where $\langle z_{\rm p}\rangle$ is the centre
 2356   position, $\langle a_{\rm p}\rangle$ is the zero-to-peak amplitude of change of
 2357   the gyration constant $g$, and $\langle w_{\rm p}\rangle$ is the corresponding
 2358   full width half maximum of the perturbation.
 2359   
 2360   \citem[2004-04-26]{[v.1.21]} \.{<jonsson@uni-wuppertal.de>}\hfill\break
 2361   Added the \.{--stokesspectrum} option, so that it is possible to generate
 2362   full Poincar\'e maps of the spectral properties of a magneto-optical Bragg
 2363   grating. However, after having introduced this option, I get the following
 2364   message from \CWEAVE:
 2365   \citindent
 2366   {\obeyspaces\obeylines\tt
 2367   ~                   cweave magbragg
 2368   ~                   This is CWEAVE, Version 3.64 (Web2C 7.5.2)
 2369   ~                   *1*3*4*5*6*7*36*37*38*55*60*67*68*70
 2370   ~                   Writing the output file...*1*3*4*5*6*7*36*37*38*55*60
 2371   ~                   ! Sorry, scrap/token/text capacity exceeded. (l. 2912)
 2372   ~                      sprintf(outfilename\_w1,"\%s\%s",
 2373   ~                                                    outfilename,".w1.dat");
 2374   ~                   (That was a fatal error, my friend.)
 2375   ~                   make: *** [magbragg.tex] Error 1}
 2376   \medskip
 2377   \citindent
 2378   The \CEE\ code generated by \CTANGLE\ compiles and executes perfectly, but
 2379   obviously something is obstructing \CWEAVE\ to properly generating the
 2380   \TeX\ code for the documentation. Most annoying.
 2381   
 2382   \citem[2004-05-07]{[v.1.22]} \.{<fredrik.jonsson@nmrc.ie>}\hfill\break
 2383   Added the \.{--displaysurrmedia}, which toggles if the program should write
 2384   also the surrounding media to saved grating profiles or not.
 2385   This is useful if one wish to just generate some part of a grating for a figure
 2386   illustrating a particular refractive index distribution, cut exactly to the
 2387   specified spatial interval of interest.
 2388   As default, the \magbragg\ program writes also the surrounding media to the
 2389   ends of the grating file, so by using this option only once at the command
 2390   line forces the program to cut the grating file exactly to the specified
 2391   spatial interval.
 2392   The annoying compilation error from 2004-04-26 is still present, preventing
 2393   me from generating the documentation.
 2394   
 2395   \citem[2004-07-03]{[v.1.23]} \.{<fredrik.jonsson@nmrc.ie>}\hfill\break
 2396   I am in Germany for laboratory work in Wuppertal during two weeks, and this
 2397   free Saturday morning I decided to once and for all trace down and eliminate
 2398   the annoying parsing error that \CWEAVE\ produces.
 2399   (I am currently writing this entry at Starbucks in Cologne, being the only
 2400   caf\'e in town with a non-smoking policy $\ldots$)
 2401   Since this particular error seemed to stem from the block related to parsing
 2402   of the command line options, and since this block anyway by now has grown
 2403   over any reasonable size, I decided split it into several smaller blocks
 2404   instead. Having done so, \CWEAVE\ immediately accepted the \CWEB\ source
 2405   and extracted the \TeX\ source, which subsequently were compiled without
 2406   any errors. It thus seems like I on April 26th must have passed some upper
 2407   size limit on the source allowed in one single \CWEB\ block.
 2408   Not that I really expected such a built-in constraint in \CWEB, but in some
 2409   sense I can agree on that by putting some hard upper limit, one will at least
 2410   force the programmer to structure the code into smaller blocks, probably
 2411   increasing the readability.
 2412   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2413   \.{magbragg.w}) comprises 171418 bytes and 4138 lines of code.
 2414   The size of the compiled executable is 70340 bytes, and the PostScript
 2415   documentation is 808345 bytes (92 pages of A4 output in 10pt).
 2416   
 2417   \citem[2004-11-14]{[v.1.24]} \.{<fredrik.jonsson@nmrc.ie>}\hfill\break
 2418   Added the \.{--apodize} option, to be able to get rid of some unwanted Gibbs
 2419   oscillations at the ends of the reflectance band of spectra generated for
 2420   chirped gratings, aimed to generate nice spectra for a talk to be presented at
 2421   the MRS 2004 Fall Meeting [F.~Jonsson and C.~Flytzanis, {\sl Artificially
 2422   Induced Perturbations in Chirped Magneto-Optical {Bragg} Gratings}, in
 2423   {\sl Magneto-Optical Materials for Photonics and Recording}, Eds.~{Koji Ando,
 2424   W. Challener, R. Gambino and M. Levy}, Mater. Res. Soc. Symp. Proc. {\bf 834},
 2425   J1.8 ({Materials Research Society}, {Warrendale}, 2005)].
 2426   Also added the \.{--phasejump} option (short form \.{-j}) to allow
 2427   specification of a discrete phase jump to appear in sinusoidal or chirped
 2428   grating structures.
 2429   In adding these options, the same error as of April 26th appeared again,
 2430   in the block related to the parsing of command line options.
 2431   Since this block has again grown over any reasonably readable size, I hence
 2432   started to split this block into smaller \CWEB\ sub-blocks, after which there
 2433   were no further complaints from \CWEAVE\ in extracting the \TeX\ documentation
 2434   of the program.
 2435   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2436   \.{magbragg.w}) comprises 179296 bytes and 4312 lines of code.
 2437   The size of the compiled executable is 74436 bytes, and the PostScript
 2438   documentation is 835671 bytes (95 pages of A4 output in 10pt).
 2439   
 2440   \citem[2004-12-04]{[v.1.25]} \.{<fredrik.jonsson@nmrc.ie>}\hfill\break
 2441   Changed the way of output of Stokes parameters to file. Previously, the
 2442   program always opened files with extensions \.{.s0.dat},$\ldots$,
 2443   \.{.s3.dat} for output of the incident $S_k$ parameters (and similarly
 2444   for the reflected and transmitted Stokes parameters $V_k$ and $W_k$),
 2445   irregardless of the number of sampling points in intensity and ellipticity.
 2446   However, for sampling of spectral characteristics we most often only encounter
 2447   a simulation performed at one single intensity and ellipticity ($M_{\rm i}=1$
 2448   and $M_{\rm e}=1$), which means that, previously, twelve empty files were
 2449   opened and closed for each simulation. This is now changed so that the
 2450   program only opens those files for output in ``topological'' mode of
 2451   operation, in which $M_{\rm i}\ge2$ and $M_{\rm e}\ge2$. Compiling the
 2452   \CEE\ code with \GCC\ then caused some novel complaints using the
 2453   \.{--pedantic} option, regarding the risk of using the associated file
 2454   pointers uninitialized. That this complaint appear at all might be an
 2455   indicator that \GCC\ is not that strict in checking the logical state of
 2456   the program in which the file pointers were to be used, since I verified
 2457   that there was no reason whatsoever for the warnings.
 2458   The ``quick-and-dirty'' solution to get rid of the annoying and non-justified
 2459   warnings was to simply initialize all file pointers to \.{NULL} at the
 2460   beginning of the program.
 2461   Also started to write a separate section on all command line options currently
 2462   supported by \magbragg. The documentation has now for quite a while been in
 2463   urgent need of such a section, since the number of options have grown quite
 2464   a lot during the last year. As a start, the documentation for the
 2465   \.{--grating}, \.{--phasejump}, and \.{--apodize} options was updated.
 2466   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2467   \.{magbragg.w}) comprises 192945 bytes and 4611 lines of code.
 2468   The size of the compiled executable is 74436 bytes, and the PostScript
 2469   documentation is 873757 bytes (102 pages of A4 output in 10pt).
 2470   
 2471   \citem[2004-12-05]{[v.1.26]} \.{<fredrik.jonsson@nmrc.ie>}\hfill\break
 2472   Added the feature that the program now uses \.{time.h} to extrapolate
 2473   what the estimated time of arrival (ETA) of the simulation is.
 2474   This is useful for predicting the total simulation time for large numbers of
 2475   sampled layers, such in long sinusoidal or chirped gratings. The estimation
 2476   is simply done via linear extrapolation as
 2477   $$
 2478   t_{\rm ETA}=t_0+{{t-t_0}\over{\{\%\,{\rm finished}\}}}\times100,
 2479   $$
 2480   to produce run-time messages of the form
 2481   \medskip
 2482   \leftskip=35mm
 2483   {\obeyspaces\obeylines\tt
 2484   Program execution started Sun Dec  5 20:55:27 2004
 2485   ----------------------------------------------------------------
 2486   ~...10 percent finished...    ETA: Sun Dec  5 21:44:57 2004
 2487   ~...20 percent finished...    ETA: Sun Dec  5 21:42:12 2004
 2488   ~...30 percent finished...    ETA: Sun Dec  5 21:41:17 2004
 2489   ~...40 percent finished...    ETA: Sun Dec  5 21:40:49 2004
 2490   ~...50 percent finished...    ETA: Sun Dec  5 21:40:33 2004
 2491   ~...60 percent finished...    ETA: Sun Dec  5 21:40:20 2004
 2492   ~...70 percent finished...    ETA: Sun Dec  5 21:40:12 2004
 2493   ~...80 percent finished...    ETA: Sun Dec  5 21:40:05 2004
 2494   ~...90 percent finished...    ETA: Sun Dec  5 21:40:01 2004
 2495   ~...done.           Elapsed execution time: 2644 s
 2496   ----------------------------------------------------------------
 2497   Program execution closed Sun Dec  5 21:39:31 2004\par}
 2498   \leftskip=0mm
 2499   \medskip
 2500   \citindent
 2501   Also wrote documentation on command-line specifications of chirped gratings,
 2502   and cleaned up the declarations of local variables somewhat.
 2503   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2504   \.{magbragg.w}) comprises 203691 bytes and 4830 lines of code.
 2505   The size of the compiled executable is 74532 bytes, and the PostScript
 2506   documentation is 898974 bytes (105 pages of A4 output in 10pt).
 2507   
 2508   \citem[2004-12-11]{[v.1.27]} \.{<fredrik.jonsson@nmrc.ie>}\hfill\break
 2509   Added two schematic figures to the documentation on the discretization
 2510   of the grating.
 2511   
 2512   \citem[2005-04-22]{[v.1.28]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2513   Removed an unused block in the code for saving spectra to file, after having
 2514   thoroughly checked that it would have no affect on the backward compatibility
 2515   of the program to earlier data generated. Also increased the numerical
 2516   precision of the data written to file for the intensity reflection and
 2517   transmission spectra, which now yields \.{\%-10.8f} in floating point
 2518   conversion as conforming to \ANSICEE.
 2519   
 2520   \citem[2005-04-28]{[v.1.29]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2521   Added four blocks of text in the documentation of command line options.
 2522   
 2523   \citem[2005-06-08]{[v.1.30]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2524   In Stockholm for two months. Added the standard \CEE\ library function
 2525   \PB{\\{fflush}(\,)} for enforcement in writing of all buffered calculated data
 2526   to file.
 2527   This in order to be able to follow the process of calculation more direct by
 2528   file inspection. When executing \magbragg\ under the new distribution of
 2529   \CYGWIN\ for Windows~XP, the block for the displaying of status of calculation
 2530   suddenly behaves odd, showing estimated execution times well below any
 2531   reasonable estimated time of arrival, and also going well beyond the maximum
 2532   100 percent in relative execution progress. This will have to be checked, and
 2533   has never previously appeared when compiling with \GCC, neither under Apple
 2534   \OSX (BSD), nor under \CYGWIN.
 2535   
 2536   \citem[2005-08-10]{[v.1.31]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2537   Back in Southampton again with my family after a hot summer. Wrote the code
 2538   for the \PB{\\{strip\_away\_path}(\,)} routine originally for the \poincare\
 2539   program and
 2540   immediately decided to adopt the code also into the \magbragg\ program in
 2541   order to finally solve the problem with long path strings that appear in
 2542   the program name string whenever poincare is called with an explicit path
 2543   specified at the command line. The call to the \PB{\\{strip\_away\_path}(\,)}
 2544   routine
 2545   is located in the beginning of the block for command line parsing.
 2546   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2547   \.{magbragg.w}) comprises 219666 bytes and 5172 lines of code.
 2548   The size of the compiled (\CYGWIN) executable is 96647 bytes, and the
 2549   PostScript documentation is 967813 bytes (112 pages of A4 output in 10pt).
 2550   
 2551   \citem[2005-08-11]{[v.1.32]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2552   Cleaned up the blocks for displaying on-screen help messages. Wrote two
 2553   routines \PB{\\{hl}(\,)} and \PB{\\{fhl}(\,)} to assist a coherent style in
 2554   displaying help on
 2555   command-line options.
 2556   
 2557   \citem[2005-08-19]{[v.1.33]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2558   Fixed two remaining bugs in the \PB{\\{hl}(\,)} and \PB{\\{fhl}(\,)}, in which %
 2559   \GCC\ under \OSX\
 2560   this evening complained that long unsigned integers were sent to standard
 2561   terminal output using the regular integer conversion of standard \CEE.
 2562   This warning did not show as the code was compiled with \GCC\ under \CYGWIN,
 2563   hence there seem to be some discrepancy between different ports of the
 2564   otherwise reliable compilator.
 2565   
 2566   \citem[2005-09-15]{[v.1.34]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2567   Corrected an error in the documentation of the options concerning
 2568   specifications of chirped sinusoidal grating structures. The chirp parameter
 2569   is now properly defined and described by example.
 2570   
 2571   \citem[2005-12-31]{[v.1.35]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2572   The theoretical description of the algorithm behind the solving of the inverse
 2573   problem in the \magbragg\ program is included in an article which today has
 2574   been accepted for publication in Physical Review Letters.
 2575   Added a section on the theoretical basis for the algorithm behind the program,
 2576   deriving the algorithm from the electromagnetic wave equation in a manner
 2577   similar to the description which soon will appear in the published article.
 2578   
 2579   \citem[2006-01-22]{[v.1.36]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2580   Added a section on the Butcher and Cotter convention of degeneracy factors in
 2581   nonlinear optics, picked from my {\sl Lecture Notes on Nonlinear Optics} from
 2582   the course I gave at the Royal Institute of Technology in 2003. Also edited the
 2583   section on the theoretical basis for the algorithm of calculation and added a
 2584   figure describing the representation of the polarization state on the
 2585   Poincar\'e sphere.
 2586   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2587   \.{magbragg.w}) comprises 252108 bytes and 5937 lines of code.
 2588   The size of the compiled (\OSX) executable is 78808 bytes, and the
 2589   PostScript documentation is 1651977 bytes (122 pages of A4 output in 10pt).
 2590   
 2591   \citem[2006-01-24]{[v.1.37]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2592   Added a significant number of comments on the use of variables and their
 2593   initialization. Also cleaned up and added more instructive text on the actual
 2594   compilation of the \CWEB\ source code.
 2595   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2596   \.{magbragg.w}) comprises 261933 bytes and 6086 lines of code.
 2597   The size of the compiled (\OSX) executable is 78828 bytes, and the
 2598   PostScript documentation is 1673601 bytes (125 pages of A4 output in 10pt).
 2599   
 2600   \citem[2006-02-09]{[v.1.38]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2601   As I now for a longer time of period have sketched on implementing the exact
 2602   methodology of solution for the waves inside the homogeneous elements of the
 2603   discretized medium, I today added the first sections on the theoretical part
 2604   of a rigorous theory of wave propagation.
 2605   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2606   \.{magbragg.w}) comprises 305905 bytes and 7095 lines of code.
 2607   The size of the compiled (\OSX) executable is 88002 bytes, and the
 2608   PostScript documentation is 1778021 bytes (135 pages of A4 output in 10pt).
 2609   
 2610   \citem[2006-02-11]{[v.1.39]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2611   Added two sections on how the amplitude evolution in the rigorous theory
 2612   of wave propagation actually can be reduced to the evaluation of an elliptic
 2613   function of the standard form
 2614   $$
 2615   \int^{v(\zeta)}_{v(\zeta_0)}{{dv}
 2616   \over{({a_4v^4+a_3v^3+a_2v^2+a_1v+a_0})^{1/2}}},
 2617   $$
 2618   with its solution $v(z)$ expressed in terms of the Weierstrass elliptic
 2619   function $\wp(\zeta;g_2,g_3)$ with the invariants $g_2$ and $g_3$
 2620   explicitly expressed in terms of $a_0$, $a_1$, $a_2$, $a_3$, and $a_4$.
 2621   
 2622   \citem[2006-03-13]{[v.1.40]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2623   After having spent some considerable time trying to verify that the integral
 2624   equation
 2625   $$
 2626   \int^{v(\zeta)}_{v(\zeta_0)}{{dv}
 2627   \over{({a_4v^4+4a_3v^3+6a_2v^2+4a_1v+a_0})^{1/2}}},
 2628   $$
 2629   which naturally appear in the rigorous theory of cross-phase modulation in
 2630   nonlinear magneto-optical media, really has the explicit solution
 2631   $$
 2632   v(\zeta)=v_0+
 2633   {{\sqrt{f(v_0)}\wp'(\zeta)+{\textstyle{{1}\over{2}}}f'(v_0)
 2634   [\wp(\zeta)-{\textstyle{{1}\over{24}}}f''(v_0)]
 2635   +{\textstyle{{1}\over{24}}}f(v_0)f'''(v_0)}
 2636   \over{2[\wp(\zeta)-{\textstyle{{1}\over{24}}}f''(v_0)]^2
 2637   -{\textstyle{{1}\over{48}}}f(v_0)f^{\rm (iv)}(v_0)}}.
 2638   $$
 2639   with quartic invariants
 2640   $$
 2641   g_2\equiv a_0a_4-4a_1a_3+3a^2_2,\qquad
 2642   g_3\equiv
 2643   \left\vert\matrix{a_0&a_1&a_2\cr a_1&a_2&a_3\cr a_2&a_3&a_4\cr}\right\vert
 2644   =a_0a_2a_4+2a_1a_2a_3-a^3_2-a_0a^2_3-a^2_1a_4,
 2645   $$
 2646   I today realized that the first edition of E.~T. Whittaker's {\sl A Course of
 2647   Modern Analysis} (Cambridge University Press, Cambridge, 1902) actually has
 2648   a printing error in one of the terms in the denominator of the solution.
 2649   This error has obviously been fixed in later editions of the book, for example
 2650   in E.~T.~Whittaker and G.~N.~Watson, {\sl A Course of Modern Analysis}, 4th
 2651   Reprinted Edn. (Cambridge University Press, Cambridge, 1996), ISBN
 2652   0-521-58807-3, but it caused be a considerable nuisance before I was able to
 2653   track the error down. The verification of the solution was checked using the
 2654   following blocks of MapleV code:
 2655   \medskip
 2656   \leftskip=30mm
 2657   {\obeyspaces\obeylines\tt
 2658   restart:
 2659   f:=a[0]*v{\tothepower}4+4*a[1]*v{\tothepower}3+6*a[2]*v{\tothepower}2%
 2660   +4*a[3]*v+a[4];
 2661   g[2]:=a[0]*a[4]-4*a[1]*a[3]+3*a[2]{\tothepower}2;
 2662   g[3]:=a[0]*a[2]*a[4]+2*a[1]*a[2]*a[3]-a[2]{\tothepower}3-a[0]*a[3]%
 2663   {\tothepower}2-a[1]{\tothepower}2*a[4];
 2664   df[0]:=eval(f,v=v0):
 2665   df[1]:=eval(diff(f,v{\dollar}1),v=v0):
 2666   df[2]:=eval(diff(f,v{\dollar}2),v=v0):
 2667   df[3]:=eval(diff(f,v{\dollar}3),v=v0):
 2668   df[4]:=eval(diff(f,v{\dollar}4),v=v0):
 2669   tmp[1]:=sqrt(df[0])*WeierstrassPPrime(z,g[2],g[3]):
 2670   tmp[2]:=(1/2)*df[1]*(WeierstrassP(z,g[2],g[3])-(1/24)*df[2]):
 2671   tmp[3]:=(1/24)*df[0]*df[3]:
 2672   tmp[4]:=2*(WeierstrassP(z,g[2],g[3])-(1/24)*df[2]){\tothepower}2:
 2673   tmp[5]:=(1/48)*df[0]*df[4]:
 2674   v:=v0+(tmp[1]+tmp[2]+tmp[3])/(tmp[4]-tmp[5]):
 2675   p:=a[0]*v{\tothepower}4+4*a[1]*v{\tothepower}3+6*a[2]*v{\tothepower}2%
 2676   +4*a[3]*v+a[4]:
 2677   testfunc:=(diff(v,z)){\tothepower}2-p:
 2678   testfunc:=simplify(testfunc);\par}
 2679   \leftskip=0mm
 2680   \medskip
 2681   \citindent
 2682   As this result was the only missing link in the formulation of an explicit
 2683   solution to the wave propagation problem in nonlinear magneto-optical media,
 2684   taking into account also weakly phase-mismatched nonlinear source terms, the
 2685   only task remaining now is to formulate the algorithm for solving the inverse
 2686   problem using this more stringent method.
 2687   
 2688   \citem[2006-03-20]{[v.1.41]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2689   Added a few paragraphs on the rigorous theory of wave propagation, clarifying
 2690   the role of the constant of integration $\Gamma$ and its calculation from the
 2691   phase of the transmitted field and the amplitude-related invariants of
 2692   propagation. This now interconnects more naturally to the formulation of the
 2693   wave propagation as an inverse problem, being the natural mode of solving
 2694   for reflectances as well as transmittances.
 2695   I also took the opportunity to write an email to MathWorld, pointing out that
 2696   their solution to the Weierstrass form of the integral equation,
 2697   \.{http://mathworld.wolfram.com/EllipticIntegral.html}, Eqs. (51)--(56),
 2698   actually contains errors; of course I could not resist the opportunity to
 2699   provide the MapleV blocks I used for my own verification, rather than using
 2700   Mathematica code!
 2701   
 2702   \citem[2006-05-01]{[v.1.42]} \.{<fj@phys.soton.ac.uk>}\hfill\break
 2703   Added support for initialization of the grating structure as a fractal set,
 2704   of the Cantor fractal type. This possibility is in the program now accessed
 2705   via the command-line option \.{--grating fractal cantor [options]}.
 2706   The initialization is done using recursion with the function
 2707   \PB{\\{init\_cantor\_fractal\_grating}(\,)}, which was finished today.
 2708   As of today, the \CWEB\ source for the \magbragg\ program (source file
 2709   \.{magbragg.w}) comprises 335649 bytes and 7753 lines of code.
 2710   The size of the compiled (\CYGWIN) executable is 95217 bytes, and the
 2711   PostScript documentation is 1874643 bytes (148 pages of A4 output in 10pt).
 2712   
 2713   \citem[2007-01-10]{[v.1.43]} \.{<http://jonsson.eu>}\hfill\break
 2714   Seefeld, Austria. Midnight. Cleaned up the theoretical part preceeding the
 2715   algorithm of computation and merged all bibliographical references into one
 2716   separate section at the end of the document.
 2717   
 2718   \citem[2011-12-18]{[v.1.44]} \.{<http://jonsson.eu>}\hfill\break
 2719   Updated \.{Makefile}:s for the generation of figures. Also corrected a rather
 2720   stupid way of removing preceeding paths of file names.
 2721   
 2722   \fi
 2723   
 2724   \N{1}{27}Compiling the source code. The program is written in \CWEB, generating
 2725   \ANSICEE\ (ISO C90) conforming source code and documentation as plain
 2726   \TeX-source, and is to be compiled using the sequences as outlined in the
 2727   \.{Makefile} listed below.
 2728   \bigskip
 2729   {\obeylines\obeyspaces\tt
 2730   \#
 2731   \# Makefile designed for use with ctangle, cweave, gcc, and plain TeX.
 2732   \#
 2733   \# The CTANGLE program converts a CWEB source document into a C program which
 2734   \# may be compiled in the usual way. The CWEAVE program converts the same CWEB
 2735   \# file into a TeX file that may be formatted and printed in the usual way.
 2736   \#
 2737   \# Copyright (C) 2002-2006, Fredrik Jonsson <fj@phys.soton.ac.uk>
 2738   \#
 2739   CTANGLE   = ctangle
 2740   CWEAVE    = cweave
 2741   CC        = gcc
 2742   CCOPTS    = -O2 -Wall -ansi -std=iso9899:1990 -pedantic
 2743   LNOPTS    = -lm
 2744   TEX       = tex
 2745   DVIPS     = dvips
 2746   DVIPSOPTS = -ta4 -D1200
 2747   METAPOST  = mp
 2748   ~   ~
 2749   all: magbragg magbragg.ps
 2750   ~   ~
 2751   magbragg: magbragg.o
 2752   ~        \$(CC) \$(CCOPTS) -o magbragg magbragg.o \$(LNOPTS)
 2753   ~   ~
 2754   magbragg.o: magbragg.w
 2755   ~        \$(CTANGLE) magbragg
 2756   ~        \$(CC) \$(CCOPTS) -c magbragg.c
 2757   ~   ~
 2758   magbragg.ps: magbragg.dvi
 2759   ~        \$(DVIPS) \$(DVIPSOPTS) magbragg.dvi -o magbragg.ps
 2760   ~   ~
 2761   magbragg.dvi: magbragg.w
 2762   ~        make -C figures/
 2763   ~        \$(CWEAVE) magbragg
 2764   ~        \$(TEX) magbragg.tex
 2765   ~   ~
 2766   clean:
 2767   ~        make clean -ik -C figures/
 2768   ~        -rm -Rf magbragg *~ *.c *.o *.exe *.dat *.tgz *.pdf
 2769   ~        -rm -Rf *.tex *.aux *.log *.toc *.idx *.scn *.dvi *.ps
 2770   ~   ~
 2771   archive:
 2772   ~        make -ik clean
 2773   ~        tar --gzip --directory=../ -cf magbragg.tgz magbragg
 2774   }
 2775   \bigskip
 2776   This \.{Makefile} essentially executes two major calls. First, the \CTANGLE\
 2777   program parses the \CWEB\ source document \.{magbragg.w} to extract a \CEE\
 2778   source file \.{magbragg.c} which may be compiled in the usual way using any
 2779   \ANSICEE\ conformant compiler. The output source file includes \.{\#line}
 2780   specifications so that any debugging can be done conveniently in terms of
 2781   the original \CWEB\ source file.
 2782   Second, the \CWEAVE\ program parses the same \CWEB\ source file to extract a
 2783   plain \TeX\ source file \.{magbragg.tex} which may be compiled in the usual
 2784   way.
 2785   It takes appropriate care of typographic details like page layout and the use
 2786   of indentation, italics, boldface, and so on, and it supplies extensive
 2787   cross-index information that it gathers automatically.
 2788   
 2789   After having executed \.{make} in the same catalogue where the files
 2790   \.{magbragg.w} and \.{Makefile} are located, one is left with an
 2791   executable file \.{magbragg}, being the ready-to-use compiled program,
 2792   and a PostScript file \.{magbragg.ps}
 2793   which contains the full documentation of the program, that is to say the
 2794   document you currently are reading.
 2795   Notice that on platforms running Windows NT, Windows 2000, Windows ME, or any
 2796   other operating system by Microsoft, the executable file will instead
 2797   automatically be called \.{magbragg.exe}.
 2798   This convention also applies to programs compiled under the \UNIX-like
 2799   environment \CYGWIN.
 2800   
 2801   \fi
 2802   
 2803   \N{1}{28}Running the program. The program is entirely controlled by the command
 2804   line options supplied when invoking the program. Since the command line
 2805   for some problems tend to be quite lengthy, since all material parameters
 2806   and optical field inputs to the program must be specified, it is convenient
 2807   to put blocks for the program calls into a Makefile, which makes it easy to
 2808   maintain a structure in the simulations, as well as ensuring traceability
 2809   of the steps in the generation of graphs.
 2810   
 2811   As an example of such a call, the following block is included as an example
 2812   in the enclosed Makefile:
 2813   \bigskip
 2814   {\obeyspaces\obeylines\tt
 2815   ~    testsimulation:
 2816   ~         @for g in 0.0 1.0 2.0; do {\char'134}
 2817   ~              ./magbragg --verbose --outputfile fig1-\$\$g {\char'134}
 2818   ~                   --spectrumfile fig1-\$\$g.rsp.dat {\char'134}
 2819   ~                   --gratinglength 7.326376e-6 -N 1800 {\char'134}
 2820   ~                   --grating sinusoidal n 2.0550 0.1250 366.3188e-9 {%
 2821   \char'134}
 2822   ~                           g \$\$g'e-3' 0.0 1.0 {\char'134}
 2823   ~                           pe 0.0 0.0 1.0 {\char'134}
 2824   ~                           pm 0.0 0.0 1.0 {\char'134}
 2825   ~                           qe 0.0 0.0 1.0 {\char'134}
 2826   ~                           qm 0.0 0.0 1.0 {\char'134}
 2827   ~                   --refindsurr 2.0550 -M 2000 {\char'134}
 2828   ~                   --lambdastart 1300.0e-9 --lambdastop 1700.0e-9 {\char'134}
 2829   ~                   --trmintensity 7.0e8 7.0e8 1 {\char'134}
 2830   ~                   --trmellipticity 0.0 0.0 1 ;{\char'134}
 2831   ~          done
 2832   }
 2833   
 2834   In the following sections, a complete listing of all command line options
 2835   accepted by the \magbragg\ program is presented.
 2836   
 2837   \fi
 2838   
 2839   \N{1}{29}Specifying grating types.
 2840   The \magbragg\ program currently accepts specifications of three different
 2841   main types of gratings:
 2842   stepwise gratings, sinusoidal gratings, and chirped sinusoidal gratings.
 2843   The stepwise gratings are simply stacks of homogeneous layers, stacked to
 2844   form a grating, and these gratings can be composed of two or more different
 2845   materials. As an important subclass of the stepwise gratings, the binary
 2846   gratings are probably the most important ones, being composed of alternating
 2847   layers of only two types of media.
 2848   
 2849   Throughout the program, the following definitions of the material parameters
 2850   apply, to the refractive index $n(z)$, gyration coefficient $g(z)$,
 2851   nonlinear optical parameters $p^{({\rm e})}(z)$ and $q^{({\rm e})}(z)$,
 2852   and nonlinear magneto-optical parameters $p^{({\rm m})}(z)$ and
 2853   $q^{({\rm m})}(z)$,
 2854   $$
 2855   \eqalign{
 2856   \PB{\|n[\|k]}&=n_k=[1+\chi^{({\rm ee})}_{xx}]^{1/2},\cr
 2857   \PB{\|g[\|k]}&=g_k=i\chi^{({\rm eem})}_{xyz} B^z_0 /(2 n_k),\cr
 2858   \PB{\\{pe}[\|k]}&=p^{({\rm e})}_k
 2859   =\chi^{\rm eeee}_{xxxx}-\chi^{\rm eeee}_{xyyx},\cr
 2860   \PB{\\{qe}[\|k]}&=q^{({\rm e})}_k
 2861   =\chi^{\rm eeee}_{xxxx}+\chi^{\rm eeee}_{xyyx},\cr
 2862   \PB{\\{pm}[\|k]}&=p^{({\rm m})}_k
 2863   =i(\chi^{\rm eeeem}_{xyyyz}-\chi^{\rm eeeem}_{xxxyz})B^z_0,\cr
 2864   \PB{\\{qm}[\|k]}&=q^{({\rm m})}_k
 2865   =i(\chi^{\rm eeeem}_{xyyyz}+\chi^{\rm eeeem}_{xxxyz})B^z_0,\cr
 2866   }
 2867   $$
 2868   where \PB{\|n[\|k]}, \PB{\|g[\|k]}, \PB{\\{pe}[\|k]}, \PB{\\{qe}[\|k]}, \PB{%
 2869   \\{pm}[\|k]}, \PB{\\{qm}[\|k]} denote the variables
 2870   as internally used in the \magbragg\ program to store the corresponding
 2871   material data for the $N-1$ homogeneous segments $z_k\le z<z_{k+1}$,
 2872   $k=1,2,\ldots,N-1$.
 2873   
 2874   In terms of the Verdet constant $V_k$ of a homogeneous layer, as being the
 2875   commonly used measure of the linear magneto-optical rotational strength of
 2876   the material, the $g$-parameter of the \magbragg\ program is expressed as
 2877   $$
 2878   g_k=V_k B^z_0 c/\omega,
 2879   $$
 2880   which simply follows from the general relation
 2881   $$
 2882   i\chi^{({\rm eem})}_{xyz}=2 n c V/\omega.
 2883   $$
 2884   \medskip
 2885   
 2886   \fi
 2887   
 2888   \M{30}Stepwise grating structures.
 2889   The stepwise grating structures are specified using the command line option
 2890   \smallskip
 2891   \centerline{\hbox to 40pt{}%
 2892   \.{--grating stepwise} [\.{twolevel}$\langle\ldots\rangle$%
 2893   $\vert$\.{threelevel}$\langle\ldots\rangle$]\hfill}
 2894   \smallskip\noindent
 2895   where \.{twolevel}, \.{threelevel} etc., states the number of materials
 2896   used in the stacking of the layers.
 2897   For the \.{twolevel} (binary) type of gratings, the syntax is
 2898   \smallskip
 2899   \centerline{\hbox to 40pt{}%
 2900   \.{--grating stepwise twolevel t1} $\langle{t_1}\rangle$
 2901   \.{t2} $\langle{t_2}\rangle$
 2902   \.{n1} $\langle{n_1}\rangle$ \.{n2} $\langle{n_2}\rangle$
 2903   \.{g1} $\langle{g_1}\rangle$ \.{g2} $\langle{g_2}\rangle$
 2904   \hfill}
 2905   \centerline{\hbox to 80pt{}%
 2906   \.{pe1} $\langle{p^{({\rm e})}_1}\rangle$
 2907   \.{pe2} $\langle{p^{({\rm e})}_2}\rangle$
 2908   \.{pm1} $\langle{p^{({\rm m})}_1}\rangle$
 2909   \.{pm2} $\langle{p^{({\rm m})}_2}\rangle$
 2910   \hfill}
 2911   \centerline{\hbox to 80pt{}%
 2912   \.{qe1} $\langle{q^{({\rm e})}_1}\rangle$
 2913   \.{qe2} $\langle{q^{({\rm e})}_2}\rangle$
 2914   \.{qm1} $\langle{q^{({\rm m})}_1}\rangle$
 2915   \.{qm2} $\langle{q^{({\rm m})}_2}\rangle$
 2916   \hfill}
 2917   \smallskip\noindent
 2918   where $t_1$ and $t_2$ are the geometrical layer thicknesses of the
 2919   first two layers $0\le z\le t_1$ and $t_1\le z\le t_1+t_2$, and
 2920   $n_1$ and $n_2$ are the corresponding refractive indices of these
 2921   layers, respectively.
 2922   
 2923   The grating is then composed by repeating the basic pair of layers,
 2924   to give a grating composed of in total $N-1$ homogeneous layers, as
 2925   specified with the \.{-N} option.
 2926   Notice that if the total number of layers $N-1$ is an odd number
 2927   (\ie specifying an even number of interfaces $N$), the last
 2928   layer will possess the same material properties and geometrical
 2929   thickness as the first layer.
 2930   \medskip
 2931   
 2932   \fi
 2933   
 2934   \M{31}Sinusoidal structures.
 2935   The sinusoidal grating structures are specified using the command line option
 2936   \smallskip
 2937   \centerline{\hbox to 40pt{}%
 2938   \.{--grating sinusoidal}
 2939   \.{n} $\langle{n_0}\rangle$ $\langle{\Delta n}\rangle$
 2940   $\langle{\Lambda_{n}}\rangle$
 2941   \.{g} $\langle{g_0}\rangle$ $\langle{\Delta g}\rangle$
 2942   $\langle{\Lambda_{g}}\rangle$\hfill}
 2943   \centerline{\hbox to 80pt{}%
 2944   \.{pe} $\langle{p^{({\rm e})}_0}\rangle$
 2945   $\langle{\Delta p^{({\rm e})}_0}\rangle$
 2946   $\langle{\Lambda^{({\rm e})}_{\rm p}}\rangle$
 2947   \.{pm} $\langle{p^{({\rm m})}_0}\rangle$
 2948   $\langle{\Delta p^{({\rm m})}_0}\rangle$
 2949   $\langle{\Lambda^{({\rm m})}_{\rm p}}\rangle$\hfill}
 2950   \centerline{\hbox to 80pt{}%
 2951   \.{qe} $\langle{q^{({\rm e})}_0}\rangle$
 2952   $\langle{\Delta q^{({\rm e})}_0}\rangle$
 2953   $\langle{\Lambda^{({\rm e})}_{\rm q}}\rangle$
 2954   \.{qm} $\langle{q^{({\rm m})}_0}\rangle$
 2955   $\langle{\Delta q^{({\rm m})}_0}\rangle$
 2956   $\langle{\Lambda^{({\rm m})}_{\rm q}}\rangle$\hfill}
 2957   \smallskip\noindent
 2958   In terms of the supplied command line options, the resulting grating structure
 2959   is then described by the continuous distribution of refractive index,
 2960   gyration coefficient, and nonlinear optical and magneto-optical coefficients as
 2961   $$
 2962   \eqalign{
 2963   n(z)&=n_0+\Delta n\sin(2\pi z/\Lambda_{n}),\cr
 2964   g(z)&=g_0+\Delta g\sin(2\pi z/\Lambda_{g}),\cr
 2965   p^{({\rm e})}(z)&=p^{({\rm e})}_0+\Delta p^{({\rm e})}
 2966   \sin(2\pi z/\Lambda^{({\rm e})}_{\rm p}),\cr
 2967   q^{({\rm e})}(z)&=q^{({\rm e})}_0+\Delta q^{({\rm e})}
 2968   \sin(2\pi z/\Lambda^{({\rm e})}_{\rm q}),\cr
 2969   p^{({\rm m})}(z)&=p^{({\rm m})}_0+\Delta p^{({\rm m})}
 2970   \sin(2\pi z/\Lambda^{({\rm m})}_{\rm p}),\cr
 2971   q^{({\rm m})}(z)&=q^{({\rm m})}_0+\Delta q^{({\rm m})}
 2972   \sin(2\pi z/\Lambda^{({\rm m})}_{\rm q}),\cr
 2973   }
 2974   $$
 2975   which in the discretized and oversampled model as used in the internal
 2976   representration of the \magbragg\ program hence becomes
 2977   $$
 2978   \eqalign{
 2979   n_j&=n_0+\Delta n\sin(2\pi z_j/\Lambda_{n}),\cr
 2980   g_j&=g_0+\Delta g\sin(2\pi z_j/\Lambda_{g}),\cr
 2981   p^{({\rm e})}_j&=p^{({\rm e})}_0+\Delta p^{({\rm e})}
 2982   \sin(2\pi z_j/\Lambda^{({\rm e})}_{\rm p}),\cr
 2983   q^{({\rm e})}_j&=q^{({\rm e})}_0+\Delta q^{({\rm e})}
 2984   \sin(2\pi z_j/\Lambda^{({\rm e})}_{\rm q}),\cr
 2985   p^{({\rm m})}_j&=p^{({\rm m})}_0+\Delta p^{({\rm m})}
 2986   \sin(2\pi z_j/\Lambda^{({\rm m})}_{\rm p}),\cr
 2987   q^{({\rm m})}_j&=q^{({\rm m})}_0+\Delta q^{({\rm m})}
 2988   \sin(2\pi z_j/\Lambda^{({\rm m})}_{\rm q}),\cr
 2989   }
 2990   $$
 2991   for $j=1,2,\ldots,N-1$.
 2992   For sinusoidal gratings, discrete phase jumps of the refractive index
 2993   distribution can also be applied, by using the \.{--phasejump} command
 2994   line option. Subsequent apodization of the structure can also be applied,
 2995   using the {--apodize} option.
 2996   \medskip
 2997   
 2998   \fi
 2999   
 3000   \M{32}Sinusoidal chirped structures.
 3001   The chirped grating structures, being sinusoidal gratings with a spatially
 3002   varying grating period, are specified using the somewhat extensive command
 3003   line option
 3004   \smallskip
 3005   \centerline{\hbox to 40pt{}%
 3006   \.{--grating chirped}
 3007   \.{n} $\langle{n_0}\rangle$ $\langle{\Delta n}\rangle$
 3008   $\langle{\Lambda_{n}}\rangle$ $\langle{\eta_{n}}\rangle$
 3009   \.{g} $\langle{g_0}\rangle$ $\langle{\Delta g}\rangle$
 3010   $\langle{\Lambda_{g}}\rangle$ $\langle{\eta_{g}}\rangle$\hfill}
 3011   \centerline{\hbox to 80pt{}%
 3012   \.{pe} $\langle{p^{({\rm e})}_0}\rangle$
 3013   $\langle{\Delta p^{({\rm e})}_0}\rangle$
 3014   $\langle{\Lambda^{({\rm e})}_{\rm p}}\rangle$
 3015   $\langle{\eta^{({\rm e})}_{\rm p}}\rangle$
 3016   \.{pm} $\langle{p^{({\rm m})}_0}\rangle$
 3017   $\langle{\Delta p^{({\rm m})}_0}\rangle$
 3018   $\langle{\Lambda^{({\rm m})}_{\rm p}}\rangle$
 3019   $\langle{\eta^{({\rm m})}_{\rm p}}\rangle$\hfill}
 3020   \centerline{\hbox to 80pt{}%
 3021   \.{qe} $\langle{q^{({\rm e})}_0}\rangle$
 3022   $\langle{\Delta q^{({\rm e})}_0}\rangle$
 3023   $\langle{\Lambda^{({\rm e})}_{\rm q}}\rangle$
 3024   $\langle{\eta^{({\rm e})}_{\rm q}}\rangle$
 3025   \.{qm} $\langle{q^{({\rm m})}_0}\rangle$
 3026   $\langle{\Delta q^{({\rm m})}_0}\rangle$
 3027   $\langle{\Lambda^{({\rm m})}_{\rm q}}\rangle$
 3028   $\langle{\eta^{({\rm m})}_{\rm q}}\rangle$\hfill}
 3029   \smallskip\noindent
 3030   Here $\langle{n_0}\rangle$ is the bias refractive index across the grating,
 3031   $\langle{\Delta n}\rangle$ the modulation of the refractive index around the
 3032   bias value, that is to say half the bottom-to-peak value of the modulated
 3033   index of refraction, $\langle{\Lambda_{n}}\rangle$ is the initial geometrical
 3034   grating period at $z=0$,
 3035   and $\langle{\eta_{n}}\rangle$ the chirp of the grating, being the
 3036   relative change of the grating period over the length of the grating.
 3037   The other grating parameters are specified analogously, for gyration
 3038   coefficient and nonlinear optical and magneto-optical coefficients.
 3039   The chirp parameter is here defined as the change in geometrical grating period
 3040   per unit geometrical distance along the grating, or
 3041   $$
 3042   \eta_{n}={{\Lambda(L)-\Lambda(0)}\over{L}}
 3043   $$
 3044   where $\Lambda(z)$ denotes the geometrical grating period as function of
 3045   the spatial coordinate $z$ along the grating.
 3046   
 3047   To illustrate the meaning of the chirp parameter, consider a chirped refractive
 3048   index distribution over a geometrical distance $L$ and with a bias refractive
 3049   index $n_0$. To give a resonance in reflection ranging from vacuum wavelength
 3050   $\lambda_{\rm a}$ to $\lambda_{\rm b}$, say, the grating period could be either
 3051   increasing or decreasing with spatial coordinate $z$. By choosing the initial
 3052   part of the grating (at $z=0$) to be resonant in reflection for a vacuum
 3053   wavelength $\lambda_{\rm a}$, the initial grating period $\Lambda_{n}$ should
 3054   be chosen as half the optical period at resonance, or
 3055   $$
 3056   \Lambda_{n}={{\lambda_{\rm a}}\over{2 n_0}}.
 3057   $$
 3058   With this initial grating period the chirp parameter should, in order to give
 3059   a final resonance in reflection at vacuum wavelength $\lambda_{\rm b}$ at the
 3060   end of the grating (at $z=L$), then simply be chosen as
 3061   $$
 3062   \eta_{n}={{\lambda_{\rm b}-\lambda_{\rm a}}\over{2 n_0 L}}.
 3063   $$
 3064   Notice that whenever $\lambda_{\rm b}<\lambda_{\rm a}$, the chirp parameter
 3065   is negative, indicating a grating period which is decreasing with increasing
 3066   spatial coordinate $z$. This convention of sign for the chirp parameter is
 3067   consistently kept throughout the algorithms of the \magbragg\ program.
 3068   
 3069   In terms of the supplied command line options, the resulting chirped grating
 3070   structure is described by the continuous distribution of refractive index,
 3071   gyration coefficient, and nonlinear optical and magneto-optical coefficients as
 3072   $$
 3073   \eqalign{
 3074   n(z)&=n_0+\Delta n\sin((2\pi/\eta_{n})\ln(1+\eta_{n}z/\Lambda_{n})),\cr
 3075   g(z)&=g_0+\Delta g\sin((2\pi/\eta_{g})\ln(1+\eta_{g}z/\Lambda_{g})),\cr
 3076   p^{({\rm e})}(z)&=p^{({\rm e})}_0+\Delta p^{({\rm e})}
 3077   \sin((2\pi/\eta^{({\rm e})}_{\rm p})
 3078   \ln(1+\eta^{({\rm e})}_{\rm p}z/\Lambda^{({\rm e})}_{\rm p})),\cr
 3079   p^{({\rm m})}(z)&=p^{({\rm m})}_0+\Delta p^{({\rm m})}
 3080   \sin((2\pi/\eta^{({\rm m})}_{\rm p})
 3081   \ln(1+\eta^{({\rm m})}_{\rm p}z/\Lambda^{({\rm m})}_{\rm p})),\cr
 3082   q^{({\rm e})}(z)&=q^{({\rm e})}_0+\Delta q^{({\rm e})}
 3083   \sin((2\pi/\eta^{({\rm e})}_{\rm q})
 3084   \ln(1+\eta^{({\rm e})}_{\rm q}z/\Lambda^{({\rm e})}_{\rm q})),\cr
 3085   q^{({\rm m})}(z)&=q^{({\rm m})}_0+\Delta q^{({\rm m})}
 3086   \sin((2\pi/\eta^{({\rm m})}_{\rm q})
 3087   \ln(1+\eta^{({\rm m})}_{\rm q}z/\Lambda^{({\rm m})}_{\rm q})),\cr
 3088   }
 3089   $$
 3090   which in the discretized and oversampled model as used in the internal
 3091   representration of the \magbragg\ program hence becomes
 3092   $$
 3093   \eqalign{
 3094   n_j&=n_0+\Delta n\sin((2\pi/\eta_{n})\ln(1+\eta_{n}z_j/\Lambda_{n})),\cr
 3095   g_j&=g_0+\Delta g\sin((2\pi/\eta_{g})\ln(1+\eta_{g}z_j/\Lambda_{g})),\cr
 3096   p^{({\rm e})}_j&=p^{({\rm e})}_0+\Delta p^{({\rm e})}
 3097   \sin((2\pi/\eta^{({\rm e})}_{\rm p})
 3098   \ln(1+\eta^{({\rm e})}_{\rm p}z_j/\Lambda^{({\rm e})}_{\rm p})),\cr
 3099   p^{({\rm m})}_j&=p^{({\rm m})}_0+\Delta p^{({\rm m})}
 3100   \sin((2\pi/\eta^{({\rm m})}_{\rm p})
 3101   \ln(1+\eta^{({\rm m})}_{\rm p}z_j/\Lambda^{({\rm m})}_{\rm p})),\cr
 3102   q^{({\rm e})}_j&=q^{({\rm e})}_0+\Delta q^{({\rm e})}
 3103   \sin((2\pi/\eta^{({\rm e})}_{\rm q})
 3104   \ln(1+\eta^{({\rm e})}_{\rm q}z_j/\Lambda^{({\rm e})}_{\rm q})),\cr
 3105   q^{({\rm m})}_j&=q^{({\rm m})}_0+\Delta q^{({\rm m})}
 3106   \sin((2\pi/\eta^{({\rm m})}_{\rm q})
 3107   \ln(1+\eta^{({\rm m})}_{\rm q}z_j/\Lambda^{({\rm m})}_{\rm q})),\cr
 3108   }
 3109   $$
 3110   for $j=1,2,\ldots,N-1$.
 3111   
 3112   Notice that the geometrical period of any of the optical/physical properties
 3113   described by the above distributions is given by
 3114   $$
 3115   {{2\pi}\over{\{{\rm geometrical\ period}\}}}=
 3116   {{\partial}\over{\partial z}}\{{\rm argument\ of\ }\sin(\ldots)\}.
 3117   $$
 3118   For example, the refractive index distribution
 3119   $$
 3120   n(z)=n_0+\Delta n\sin((2\pi/\eta_{n})\ln(1+\eta_{n}z/\Lambda_{n}))
 3121   $$
 3122   has its spatially varying local grating period $\Lambda_{\rm loc}(z)$ given by
 3123   $$
 3124   \eqalign{
 3125   {{2\pi}\over{\Lambda_{\rm loc}(z)}}
 3126   &={{\partial}\over{\partial z}}
 3127   [({{2\pi}/{\eta_{n}}})\ln(1+{{\eta_{n}z}/{\Lambda_{n}}})]%\cr
 3128   =({{2\pi}/{\eta_{n}}})
 3129   {{{{\eta_{n}}/{\Lambda_{n}}}}\over{(1+{{\eta_{n}z}/{\Lambda_{n}}})}}%\cr
 3130   ={{2\pi}\over{(\Lambda_{n}+\eta_{n}z)}}%\cr
 3131   }
 3132   $$
 3133   that is to say, the geometrical local period is given as a linear function
 3134   which in terms of the vacuum resonance wavelengths $\lambda_{\rm a}$ and
 3135   $\lambda_{\rm b}$ becomes
 3136   $$
 3137   \eqalign{
 3138   \Lambda_{\rm loc}(z)&=\Lambda_n+\eta z
 3139   ={{\lambda_{\rm a}}\over{2n_0}}
 3140   +{{(\lambda_{\rm b}-\lambda_{\rm a})}\over{2n_0L}}z
 3141   ={{1}\over{2n_0}}(\lambda_{\rm a}+(\lambda_{\rm b}-\lambda_{\rm a})z/L).
 3142   }
 3143   $$
 3144   For the sake of consistency with the discussion earlier in this section,
 3145   $\lambda_{\rm a}$ is taken as the vacuum resonance wavelength at $z=0$,
 3146   while $\lambda_{\rm b}$ is the corresponding wavelength of resonance at $z=L$.
 3147   For chirped gratings, as well as for the sinusoidal gratings, discrete phase
 3148   jumps of the refractive index distribution can also be applied, by using the
 3149   \.{--phasejump} command line option. Subsequent apodization of the structure
 3150   can also be applied, using the {--apodize} option.
 3151   \medskip
 3152   
 3153   \fi
 3154   
 3155   \M{33}Fractal structures.
 3156   
 3157   [TEXT STILL TO BE WRITTEN]
 3158   
 3159   \fi
 3160   
 3161   \M{34}Discrete phase jumps.
 3162   Discrete phase jumps in sinusoidal type gratings (of sinusoidal of chirped
 3163   type as previously described)
 3164   can be specified using the \.{--phasejump} option, with syntax
 3165   \smallskip
 3166   \centerline{\hbox to 40pt{}%
 3167   \.{--phasejump} $\langle{\varphi_{\rm jump}}\rangle$
 3168   $\langle{z_{\rm jump}}\rangle$\hfill}
 3169   \smallskip\noindent
 3170   where $\varphi_{\rm jump}$ is the phase shift in radians to be applied for
 3171   the grating at all spatial coordinates $z\ge z_{\rm jump}$.
 3172   For sinusoidal type gratings, the effect is that the refractive index and
 3173   gyration coefficient distributions become
 3174   $$
 3175   \eqalign{
 3176   n(z)&=n_0+\Delta n\sin(2\pi z/\Lambda_{n}+\varphi(z)),\cr
 3177   g(z)&=g_0+\Delta g\sin(2\pi z/\Lambda_{g}+\varphi(z)),\cr
 3178   }
 3179   $$
 3180   where
 3181   $$
 3182   \varphi(z)=\cases{0,&$z<z_{\rm jump}$\cr
 3183   \varphi_{\rm jump},&$z\ge z_{\rm jump}$\cr},
 3184   $$
 3185   Notice that the parameters supplied with the \.{--phasejump} option
 3186   only affects the (linear) refractive index and gyration coefficient
 3187   distributions $n(z)$ and $g(z)$; all other (nonlinear) material parameters
 3188   are left unaffected, irregardless of potential spatial modulation schemes.
 3189   
 3190   \fi
 3191   
 3192   \M{35}The refractive index surrounding the grating.
 3193   The refractive index surrounding the grating is specified using the command
 3194   line option
 3195   \smallskip
 3196   \centerline{\hbox to 40pt{}\.{--refindsurr}
 3197   $\langle n_{\rm ext}\rangle$\hfill}
 3198   \smallskip\noindent
 3199   where $\langle n_{\rm ext}\rangle$ is the refractive index surrounding the
 3200   grating.
 3201   If the surrounding refractive index is not specified at the command line
 3202   at execution of the program, a default value of $n_{\rm ext}=1.0$ (vacuum)
 3203   is used in the simulation.
 3204   
 3205   \fi
 3206   
 3207   \M{36}Apodization of the grating.
 3208   Apodization of the grating structure is typically applied
 3209   in order to get rid of any occurring Gibbs oscillations due to a rapid
 3210   change of the index modulation at the ends of the grating.
 3211   For a more detailed description of Gibbs oscillations, see for example
 3212   Refs.~[14,15].
 3213   By applying apodization, the \magbragg\ program force a smoother
 3214   transition between modulated and non-modulated regions of the grating.
 3215   The apodization is invoked by the \.{--apodize}
 3216   option, with syntax
 3217   \smallskip
 3218   \centerline{\hbox to 40pt{}%
 3219   \.{--apodize} $\langle{L_{\rm apod}}\rangle$\hfill}
 3220   \smallskip\noindent
 3221   where $L_{\rm apod}$ is the apodization length at each end of the grating.
 3222   The apodization is performed at the ends of the grating according to a
 3223   multiplicative factor of the modulation amplitudes of the
 3224   refractive index and gyration coefficient, of the form
 3225   $$
 3226   f(z)=\cases{
 3227   [1-\cos(\pi z/L_{\rm apod})]/2,&$0\le z\le L_{\rm apod}$,\cr
 3228   1,&$L_{\rm apod}<z<L-L_{\rm apod}$,\cr
 3229   [1-\cos(\pi(z-L)/L_{\rm apod})]/2,&$L-L_{\rm apod}\le z\le L$,\cr
 3230   }
 3231   $$
 3232   and otherwise $f(z)=0$, for any $z$ outside the above domains of definition,
 3233   where $L_{\rm apod}$ is the effective apodization length, being the floating
 3234   point parameter specified after the \.{--apodize} option, and $L$ the
 3235   geometrical overall length of the grating, \eg as specified with the
 3236   \.{--gratinglength} option.
 3237   Notice that as in the previously described \.{--phasejump} option,
 3238   the parameter supplied with the \.{--apodize} option
 3239   only apodizes the (linear) refractive index and gyration coefficient
 3240   distributions $n(z)$ and $g(z)$; all other (nonlinear) material parameter
 3241   distributions are left unaffected.
 3242   
 3243   \fi
 3244   
 3245   \M{37}Specifying transmitted intensity.
 3246   The generated data relating a specified optical output to an optical input can
 3247   in the program automatically be iterated over a range of values of the
 3248   transmitted optical intensity, expressed in regular \SI\ units as Watts per
 3249   square meter (${\rm W}/{\rm m}^2$).
 3250   The command line syntax for specifying that the
 3251   program should generate the inverse relation for $M_{\rm i}$ discrete values of
 3252   the transmitted optical intensity in a range from $I_{\rm start}$ to
 3253   $I_{\rm stop}$ is
 3254   \smallskip
 3255   \centerline{\hbox to 40pt{}\.{--trmintensity}
 3256   $\langle I_{\rm start}\rangle$ $\langle I_{\rm stop}\rangle$
 3257   $\langle M_{\rm i}\rangle$\hfill}
 3258   \smallskip\noindent
 3259   Notice that parameters throughout the program are to be specified in terms
 3260   of regular \SI\ units. In case the in optical physics quite commonly used
 3261   quantity of gigawatts per square centimeter is preferred, just use the
 3262   conversion $1\,{\rm G}{\rm W}/{\rm cm}^2=10^{13}\,{\rm W}/{\rm m}^2$.
 3263   \smallskip\noindent
 3264   
 3265   \fi
 3266   
 3267   \M{38}Specifying transmitted ellipticity.
 3268   The command line syntax for specification of the range of ellipticity of the
 3269   transmitted polarization state is analogous to that of the transmitted
 3270   intensity, as
 3271   \smallskip
 3272   \centerline{\hbox to 40pt{}\.{--trmellipticity}
 3273   $\langle \epsilon_{\rm start}\rangle$ $\langle \epsilon_{\rm stop}\rangle$
 3274   $\langle M_{\rm e}\rangle$\hfill}
 3275   \smallskip\noindent
 3276   where $\langle \epsilon_{\rm start}\rangle$ and
 3277   $\langle \epsilon_{\rm stop}\rangle$ are the start and stop values for the
 3278   normalized transmitted ellipticity~$\epsilon$, which in terms of the
 3279   transmitted Stokes parameters is defined as $\epsilon\equiv W_3/W_0$.
 3280   (For the definitions of the Stokes parameters in terms of the electric
 3281   field of the light wave, see the corresponding separate section included
 3282   in this documentation.)
 3283   Here $\epsilon=-1$ corresponds to right circular polarization (RCP) while
 3284   $\epsilon=1$ corresponds to left circular polarization (LCP), with
 3285   $\epsilon=0$ corresponding to linear polarization.
 3286   Values intermediate of those give the various degrees of elliptic polarization
 3287   states. As in the case of specification of the transmitted intensity,
 3288   $\langle M_{\rm e}\rangle$ is the number of discrete steps of the ellipticity
 3289   that will be iterated over in the simulation.
 3290   
 3291   \fi
 3292   
 3293   \M{39}Specifying optical vacuum wavelength interval to be scanned.
 3294   For the sampling of optical spectra, with the reflectance and transmittance
 3295   sampled as function of optical vacuum wavelength, the interval of computation
 3296   is specified using the syntax
 3297   \smallskip
 3298   \centerline{\hbox to 40pt{}
 3299   \.{--lambdastart} $\langle \lambda_{\rm start}\rangle$
 3300   \.{--lambdastop} $\langle \lambda_{\rm stop}\rangle$\hfill}
 3301   \smallskip\noindent
 3302   where $\lambda_{\rm start}$ and $\lambda_{\rm stop}$ specifies the wavelength
 3303   domain. The number of samples $M$ to be calculated is specified using the
 3304   syntax
 3305   \smallskip
 3306   \centerline{\hbox to 40pt{}
 3307   \.{-M} $\langle M\rangle$\hfill}
 3308   \smallskip\noindent
 3309   The specific discrete vacuum wavelength $\lambda_k$ at which the computation
 3310   is performed are
 3311   $$
 3312   \lambda_k=\lambda_{\rm start}+{{(k-1)}\over{(M-1)}}
 3313   (\lambda_{\rm stop}-\lambda_{\rm start}),
 3314   $$
 3315   for $k=1,2,\ldots,M$.
 3316   
 3317   \fi
 3318   
 3319   \M{40}Scaling of Stokes parameters to yield optical intensity.
 3320   To force the output Stokes parameters to be expressed in terms of optical
 3321   intensity units of Watts per square meter, rather than the regular square
 3322   Volts per meter, use the command line option
 3323   \smallskip
 3324   \centerline{\hbox to 40pt{}\.{--scale\_stokesparams 1.327209e-3}\hfil}
 3325   \smallskip\noindent
 3326   forcing the program to save the scaled Stokes parameters
 3327   $S'_k=1.327209\times10^{-3}S_k$ to file instead of the original $S_k$,
 3328   $k=0,1,2,3$.
 3329   As a default, and as a matter of convention of electrodynamics in \SI\ units,
 3330   all Stokes parameters are given in ${\rm V}^2/{\rm m}^2$, through their
 3331   definition.
 3332   For example, the incident field (which is calculated by the program in
 3333   this inverse formulation of the problem) is expressed in terms of the Stokes
 3334   parameters as
 3335   $$
 3336   \eqalign{
 3337   S_0&=\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2,\qquad
 3338   S_1=2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr
 3339   S_3&=\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2,\qquad
 3340   S_2=2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr
 3341   }
 3342   $$
 3343   However, the direct interpretation of these quantities in terms of squared
 3344   Volts per square metres is sometimes somewhat inconvenient; therefore, those
 3345   parameters can be scaled to give an interpretation of the intensity (in regular
 3346   \SI\ units measured in Watts per square metres),
 3347   as $S'_k=(\varepsilon_0 c/2)S_k$, or explicitly
 3348   $$
 3349   \eqalign{
 3350   S'_0&=(\varepsilon_0 c/2)
 3351   [\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2],\qquad
 3352   S'_1=(\varepsilon_0 c/2)
 3353   2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr
 3354   S'_3&=(\varepsilon_0 c/2)
 3355   [\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2],\qquad
 3356   S'_2=(\varepsilon_0 c/2)
 3357   2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr
 3358   }
 3359   $$
 3360   In this representation, $S'_0$ is now identical to the incident intensity
 3361   $I_{\rm in}$ [${\rm W}/{\rm m}^2$].
 3362   In order to have those scaled Stokes parameters $S'_k$ written to file,
 3363   rather than the default ones, one convenient possibility is to use the
 3364   previously added \.{--scale\_stokesparams} option, to include
 3365   \.{--scale\_stokesparams 1.327209e-3} at the command line when invoking
 3366   the program.
 3367   The numerical value of this scaling was obtained
 3368   from
 3369   $$
 3370   \eqalign{
 3371   \varepsilon_0 c/2
 3372   &=(8.854187817\ldots\times 10^{-12}\ {\rm F}/{\rm m})
 3373   \times(2.99792458\times 10^8\ {\rm m}/{\rm s})/2\cr
 3374   &\approx 1.327209\times 10^{-3}\ {\rm F}/{\rm s}.\cr
 3375   }
 3376   $$
 3377   In regular \SI\ units as here used, the physical dimension of the
 3378   quantity $\varepsilon_0 c/2$ is $[({\rm A}\cdot{\rm s})/({\rm V}\cdot{\rm m})]
 3379   \cdot[{\rm m}/{\rm s}]=[{\rm A}/{\rm V}]$, so the physical dimension of
 3380   $(\varepsilon_0 c/2)S_k$ is hence $[{\rm A}/{\rm V}]\cdot[{\rm V}^2/{\rm m}^2]
 3381   =[{\rm W}/{\rm m}^2]$, as expected for an intensity measure (energy flow per
 3382   unit area in the plane orthogonal to the direction of wave propagation).
 3383   For any other scaling factor of the Stokes parameters, use the general syntax
 3384   \smallskip
 3385   \centerline{\hbox to 40pt{}\.{--scale\_stokesparams}
 3386   $\langle a\rangle$\hfill}
 3387   \smallskip\noindent
 3388   which forces the program to save the scaled Stokes parameters
 3389   $S'_k=a S_k$ to file instead of the original $S_k$, $k=0,1,2,3$.
 3390   
 3391   \fi
 3392   
 3393   \M{41}Saving intra-grating spatial evolution of optical field and intensity.
 3394   The optical intensity and/or general spatial evolution of the electromagnetic
 3395   field inside the grating can be saved to file using the command line option
 3396   of syntax
 3397   \smallskip
 3398   \centerline{\hbox to 40pt{}
 3399   \.{-M} $\langle M\rangle$\hfill}
 3400   \smallskip\noindent
 3401   
 3402   The data for the field evolution is written to file in the format
 3403   \smallskip
 3404   \centerline{\hbox to 20pt{}
 3405   $z_1$\quad
 3406   $\langle E^{\rm f}_+(z_1)\rangle$\quad
 3407   $\langle E^{\rm f}_-(z_1)\rangle$\quad
 3408   $\langle E^{\rm b}_+(z_1)\rangle$\quad
 3409   $\langle E^{\rm b}_-(z_1)\rangle$\quad
 3410   \hfill}
 3411   \centerline{\hbox to 20pt{}
 3412   $z_2$\quad
 3413   $\langle E^{\rm f}_+(z_2)\rangle$\quad
 3414   $\langle E^{\rm f}_-(z_2)\rangle$\quad
 3415   $\langle E^{\rm b}_+(z_2)\rangle$\quad
 3416   $\langle E^{\rm b}_-(z_2)\rangle$\quad
 3417   \hfill}
 3418   \centerline{\hbox to 20pt{}
 3419   $\vdots$\hskip 80pt$\vdots$\hskip 80pt$\vdots$
 3420   \hfill}
 3421   \centerline{\hbox to 20pt{}
 3422   $z_N$\quad
 3423   $\langle E^{\rm f}_+(z_N)\rangle$\quad
 3424   $\langle E^{\rm f}_-(z_N)\rangle$\quad
 3425   $\langle E^{\rm b}_+(z_N)\rangle$\quad
 3426   $\langle E^{\rm b}_-(z_N)\rangle$\quad
 3427   \hfill}
 3428   \smallskip\noindent
 3429   where each blank space-separated entry $\langle E^{\rm f}_+(z_k)\rangle$,
 3430   $\langle E^{\rm f}_-(z_k)\rangle$, $\langle E^{\rm b}_+(z_k)\rangle$, or
 3431   $\langle E^{\rm b}_-(z_k)\rangle$ for an electric field component constitutes
 3432   the pair of its real and imaginary parts,
 3433   $$
 3434   \langle E^{\rm f}_+(z_k)\rangle\equiv
 3435   \langle{\re}[E^{\rm f}_+(z_k)]\rangle\quad
 3436   \langle{\im}[E^{\rm f}_+(z_k)]\rangle,
 3437   $$
 3438   where each number $\langle{\re}[E^{\rm f}_+(z_k)]\rangle$ or
 3439   $\langle{\im}[E^{\rm f}_+(z_k)]\rangle$ in the pair in the saved file
 3440   is represented in plain ASCII by 16 significant digits.
 3441   
 3442   [TEXT STILL TO BE WRITTEN]
 3443   
 3444   \fi
 3445   
 3446   \M{42}Saving the spatial profile of grating structure.
 3447   The spatial distribution of the refractive index, gyration coefficient, and
 3448   nonlinear optical and magneto-optical parameters can in the progress of the
 3449   simulation be written to file using the command line option
 3450   \smallskip
 3451   \centerline{\hbox to 40pt{}\.{--writegratingfile}
 3452   $\langle {\rm filename}\rangle$\hfill}
 3453   \smallskip\noindent
 3454   [TEXT STILL TO BE WRITTEN]
 3455   
 3456   \fi
 3457   
 3458   \M{43}Intragrating intensity information.
 3459   In many cases the density distribution of optical intensity inside the medium
 3460   is of particular interest, since cavity-effects or other resonant phenomena
 3461   can considerably increase the intensity locally along the grating.
 3462   The program can automatically track down the maximum present intensity in the
 3463   grating and the corresponding location, presenting the information either at
 3464   the terminal window in which the program was started or written to file.
 3465   The syntax for getting this information calculated and displayed in the
 3466   terminal window is simply
 3467   \smallskip
 3468   \centerline{\hbox to 40pt{}\.{--intensityinfo}.\hfill}
 3469   \smallskip\noindent
 3470   To get the information instead written to file, use
 3471   \smallskip
 3472   \centerline{\hbox to 40pt{}\.{--intensityinfologfile}
 3473   $\langle{\rm filename}\rangle$,\hfill}
 3474   \smallskip\noindent
 3475   where $\langle{\rm filename}\rangle$ is the name of the destination file.
 3476   
 3477   \fi
 3478   
 3479   \N{1}{44}Postprocessing of the data to get the direct relation.
 3480   The data generated by the program naturally relate the inverse relation between
 3481   the incident and transmitted (or reflected) optical fields.
 3482   In other words, the input data are typically equidistantly spaced in the
 3483   transmitted intensity and/or ellipticity, while the spacing of the
 3484   calculated data (the incident optical field) is ....
 3485   
 3486   For topological mappings of the data, such as in Fig.~X [FIGURE TO BE
 3487   INSERTED], it is for most cases of no importance whether it is the
 3488   direct relation (transmitted or reflected field as function of incident field)
 3489   or its inverse (incident or reflected field as function of transmitted field)
 3490   that is described by the set of data.
 3491   However, in many cases we are interested in a maping that corresponds to
 3492   a direct experimental setup. For example, whenever we have a linearly
 3493   polarized incident light in the experimental setup of evaluation, the
 3494   transmitted polarization state generally differ from the input one, and
 3495   we must take into account that the input data will ....
 3496   
 3497   [TEXT STILL TO BE WRITTEN]
 3498   
 3499   \fi
 3500   
 3501   \N{1}{45}The main program. Here follows the general outline of the main
 3502   program.
 3503   
 3504   \Y\B\X46:Library inclusions\X\6
 3505   \X47:Global definitions\X\6
 3506   \X48:Data structure definitions\X\6
 3507   \X49:Global variables\X\6
 3508   \X50:Subroutines\X\7
 3509   \&{int} \\{main}(\&{int} \\{argc}${},\39{}$\&{char} ${}{*}\\{argv}[\,]){}$\1\1%
 3510   \2\2\6
 3511   ${}\{{}$\1\6
 3512   \X51:Declaration of local variables\X\6
 3513   \X61:Initialize variables\X\6
 3514   \X116:Parse command line for parameter values\X\6
 3515   \X134:Check for specified trajectory of transmitted Stokes parameters\X\6
 3516   \X135:Open files for output\X\6
 3517   \X62:Allocate optical field vectors\X\6
 3518   \X64:Initiate grating structure\X\6
 3519   \X70:Initiate surrounding medium\X\6
 3520   \X71:Calculate intragrating layer reflectances\X\6
 3521   \X72:Calculate incident optical field spectrum\X\6
 3522   \X87:Print information on maximum optical intensity in grating\X\6
 3523   \X63:Deallocate optical field vectors\X\6
 3524   \X136:Close output files\X\6
 3525   \&{return} (\.{SUCCESS});\6
 3526   \4${}\}{}$\2\par
 3527   \fi
 3528   
 3529   \M{46}The standard \ANSICEE\ libraries included in this program are:\par
 3530   \varitem[\.{math.h}]{For access to mathematical functions.}
 3531   \varitem[\.{time.h}]{For time stamps and estimation of computation time.}
 3532   \varitem[\.{stdio.h}]{For file access and any block involving \PB{%
 3533   \\{fprintf}}.}
 3534   \varitem[\.{stdlib.h}]{For memory allocation, \PB{\\{malloc}}, \PB{\\{exit}}, %
 3535   \PB{\\{free}} etc.}
 3536   \varitem[\.{string.h}]{For string manipulation, \PB{\\{strcpy}}, \PB{%
 3537   \\{strcmp}} etc.}
 3538   \varitem[\.{ctype.h}]{For access to the \PB{\\{isalnum}} routine.}
 3539   
 3540   \Y\B\4\X46:Library inclusions\X${}\E{}$\6
 3541   \8\#\&{include} \.{<math.h>}\6
 3542   \8\#\&{include} \.{<time.h>}\6
 3543   \8\#\&{include} \.{<stdio.h>}\6
 3544   \8\#\&{include} \.{<stdlib.h>}\6
 3545   \8\#\&{include} \.{<string.h>}\6
 3546   \8\#\&{include} \.{<ctype.h>}\par
 3547   \U45.\fi
 3548   
 3549   \M{47}Global definitions.
 3550   There are just a few global definitions present in the \magbragg\ program:\par
 3551   \varitem[\.{VERSION}]{The current program revision number.}
 3552   \varitem[\.{COPYRIGHT}]{The copyright banner.}
 3553   \varitem[\.{SUCCESS}]{The return code for successful program termination.}
 3554   \varitem[\.{FAILURE}]{The return code for unsuccessful program termination.}
 3555   \varitem[\.{NCHMAX}]{The maximum number of characters allowed in strings for
 3556   storing file names, including path.}
 3557   
 3558   \Y\B\4\X47:Global definitions\X${}\E{}$\6
 3559   \8\#\&{define} \.{VERSION} \5\.{"1.43"}\6
 3560   \8\#\&{define} \.{COPYRIGHT} \5\.{"Copyright\ (C)\ 2002-}\)\.{2007,\ Fredrik\
 3561   Jonsso}\)\.{n"}\6
 3562   \8\#\&{define} \.{SUCCESS} \5(\T{0})\6
 3563   \8\#\&{define} \.{FAILURE} \5(\T{1})\6
 3564   \8\#\&{define} \.{NCHMAX} \5(\T{256})\par
 3565   \U45.\fi
 3566   
 3567   \M{48}Data structure definitions.
 3568   The \PB{\\{dcomplex}} data structure contains real and imaginary parts in
 3569   double precision, and is also the basic data structure used for the
 3570   allocation of complex valued vectors of double precision.
 3571   
 3572   \Y\B\4\X48:Data structure definitions\X${}\E{}$\6
 3573   \&{typedef} \&{struct} \&{DCOMPLEX} ${}\{{}$\1\6
 3574   \&{double} \|r${},{}$ \|i;\2\6
 3575   ${}\}{}$ \&{dcomplex};\par
 3576   \U45.\fi
 3577   
 3578   \M{49}Declaration of global variables. The only global variables allowed in
 3579   my programs are \PB{\\{optarg}}, which is a pointer to the the string of
 3580   characters
 3581   that specified the call from the command line, and \PB{\\{progname}}, which
 3582   simply
 3583   is a pointer to the string containing the name of the program, as it was
 3584   invoked from the command line.
 3585   
 3586   \Y\B\4\X49:Global variables\X${}\E{}$\6
 3587   \&{extern} \&{char} ${}{*}\\{optarg};{}$\6
 3588   \&{char} ${}{*}\\{progname}{}$;\par
 3589   \U45.\fi
 3590   
 3591   \M{50}Listing of subroutines called by the main program.
 3592   
 3593   \Y\B\4\X50:Subroutines\X${}\E{}$\6
 3594   \X88:Routine for checking for numerical characters\X\6
 3595   \X89:Routine for initialization of Cantor type fractal gratings\X\6
 3596   \X90:Routines for removing preceding path of filenames\X\6
 3597   \X111:Routines for memory allocation of vectors\X\6
 3598   \X93:Routines for generation of random numbers\X\6
 3599   \X94:Routines for complex arithmetics\X\6
 3600   \X130:Routines for displaying help message\X\par
 3601   \U45.\fi
 3602   
 3603   \N{1}{51}Declaration of local variables of the main program.
 3604   In \CWEB\ one has the option of adding variables along the program, for example
 3605   by locally adding temporary variables related to a given sub-block of code.
 3606   However, my philosophy in the \magbragg\ program is to keep all variables of
 3607   the \PB{\\{main}} section collected together, so as to simplify tasks as, for
 3608   example,
 3609   tracking down a given variable type definition.
 3610   
 3611   [ADD A LIST OF VARIABLE DESCRIPTIONS WITH THE 'VARITEM' MACRO]
 3612   
 3613   \varitem[\PB{\\{somevariable}}]{Some description of \PB{\\{somevariable}}.}
 3614   
 3615   \Y\B\4\X51:Declaration of local variables\X${}\E{}$\6
 3616   \X52:Physical and mathematical constants\X\6
 3617   \X53:Time variables\X\6
 3618   \X54:Declaration of complex arrays storing the electrical field distribution\X\6
 3619   \X55:Declaration of Boolean variables for execution control\X\6
 3620   \X56:Discretization parameters\X\6
 3621   \X57:Grating parameters\X\6
 3622   \X58:Declaration of file pointers\X\6
 3623   \X59:Declaration of strings and file names\X\6
 3624   \X60:Declaration of local dummy variables\X\7
 3625   \&{long} \\{nne}${},{}$ \\{jje}${},{}$ \\{mmtraject};\6
 3626   \&{long} \\{ranseed};\C{ seed for random number generator }\6
 3627   \&{long} \\{maxintens\_layer}${}\K\T{0};{}$\6
 3628   \&{int} \\{fractal\_level}${}\K\T{0}{}$;\C{ The recursion level in construction
 3629   of Cantor-type fractal gratings }\6
 3630   \&{int} \\{maximum\_fractal\_level}${}\K\T{0}{}$;\C{ The maximum allowed
 3631   recursion level in                                construction of Cantor-type
 3632   fractal gratings }\6
 3633   \&{double} ${}{*}\\{w0traj}\K\NULL,{}$ ${}{*}\\{w3traj}\K\NULL;{}$\6
 3634   \&{double} \\{lambdastart};\C{ The start vacuum wavelength $\lambda_{\rm
 3635   start}$       of the spectrum to be sampled }\6
 3636   \&{double} \\{lambdastop};\C{ The stop vacuum wavelength $\lambda_{\rm stop}$
 3637       of the spectrum to be sampled }\6
 3638   \&{double} \\{lambda};\C{ Dummy variable to hold the vacuum wavelength at a
 3639     discrete spectral sample }\6
 3640   \&{double} \\{omega};\C{ Ditto for the angular frequency       $\omega\equiv 2%
 3641   \pi/\lambda$ }\6
 3642   \&{double} \\{ievolambda};\6
 3643   \&{double} \\{apolength};\C{ Length $L_{\rm apod}$ over which each end of the
 3644       grating should be apodized }\6
 3645   \&{double} \\{phasejumpangle};\C{ The magnitude of the phase discontinuity
 3646    $\varphi_{\rm jump}$ measured in radians }\6
 3647   \&{double} \\{phasejumpposition};\C{ The position $z_{\rm jump}$ in metres of
 3648   the        phase discontinuity $\varphi_{\rm jump}$ }\6
 3649   \&{double} \\{phi};\C{ Dummy variable to hold the reference phase over the
 3650   spatial        extent of the grating }\6
 3651   \&{double} \\{gyroperturb\_position};\C{ The position $z_{\rm p}$ in metres of
 3652   the        peak of the added Lorentzian perturbation $\Delta g(z)$ of the
 3653   gyration        coefficient $g(z)$ }\6
 3654   \&{double} \\{gyroperturb\_amplitude};\C{ The zero-to-peak amplitude $a_{\rm
 3655   p}$ of        the added Lorentzian perturbation $\Delta g(z)$ of the gyration
 3656        coefficient $g(z)$ }\6
 3657   \&{double} \\{gyroperturb\_width};\C{ The full width at half maximum $w_{\rm
 3658   p}$ of        the added Lorentzian perturbation $\Delta g(z)$ of the gyration
 3659        coefficient $g(z)$ }\6
 3660   \&{double} \\{nsurr};\C{ The linear index of refraction of the medium
 3661   surrounding        the grating }\6
 3662   \&{double} \\{n1}${},{}$ \\{n2}${},{}$ \\{t1}${},{}$ \\{t2}${},{}$ %
 3663   \\{nper}${},{}$ \\{ncrp}${},{}$ \\{g1}${},{}$ \\{g2}${},{}$ \\{gper}${},{}$ %
 3664   \\{gcrp}${},{}$ \\{pe1}${},{}$ \\{pe2}${},{}$ \\{peper}${},{}$ \\{pecrp}${},{}$
 3665   \\{pm1}${},{}$ \\{pm2}${},{}$ \\{pmper}${},{}$ \\{pmcrp}${},{}$ \\{qe1}${},{}$ %
 3666   \\{qe2}${},{}$ \\{qeper}${},{}$ \\{qecrp}${},{}$ \\{qm1}${},{}$ \\{qm2}${},{}$ %
 3667   \\{qmper}${},{}$ \\{qmcrp};\6
 3668   \&{double} \\{modn1}${},{}$ \\{modt1}${},{}$ \\{modg1}${},{}$ \\{modpe1}${},{}$
 3669   \\{modpm1}${},{}$ \\{modqe1}${},{}$ \\{modqm1}${},{}$ \\{aafp2}${},{}$ %
 3670   \\{aafm2}${},{}$ \\{aabp2}${},{}$ \\{aabm2};\6
 3671   \&{double} \\{trmintensity}${},{}$ \\{trmintenstart}${},{}$ %
 3672   \\{trmintenstop}${},{}$ \\{trmellipticity}${},{}$ \\{trmellipstart}${},{}$ %
 3673   \\{trmellipstop}${},{}$ \\{stoke\_scalefactor};\6
 3674   \&{static} \&{double} \\{nndef}${}\K\T{600}{}$;\C{ Number of samples in
 3675   spectrum    }\6
 3676   \&{static} \&{double} \\{mmdef}${}\K\T{1000}{}$;\C{ Number of samples in
 3677   grating     }\6
 3678   \&{static} \&{double} \\{mmedef}${}\K\T{1}{}$;\C{ Number of samples in
 3679   ellipticity }\6
 3680   \&{static} \&{double} \\{mmidef}${}\K\T{1}{}$;\C{ Number of samples in
 3681   intensity   }\6
 3682   \&{static} \&{double} \\{lldef}${}\K\T{0.050}{}$;\C{ Length of grating in
 3683   metres      }\6
 3684   \&{static} \&{double} \\{nsurrdef}${}\K\T{1.0}{}$;\C{ Default surrounding
 3685   refractive index }\6
 3686   \&{static} \&{double} \\{lambdastartdef}${}\K\T{1536.0\_-9},{}$ %
 3687   \\{lambdastopdef}${}\K\T{1546.0\_-9}{}$;\par
 3688   \U45.\fi
 3689   
 3690   \M{52}Declaration of numerical values of physical constants. All calculations
 3691   performed by this program are done in \SI\ units, in which the fundamental
 3692   physical constants take the values below.
 3693   
 3694   \Y\B\4\X52:Physical and mathematical constants\X${}\E{}$\6
 3695   \&{static} \&{double} \\{pi}${}\K\T{3.1415926535897932384626433832795}{}$;\C{ $%
 3696   \pi$ }\6
 3697   \&{static} \&{double} \\{twopi}${}\K\T{2.0}*%
 3698   \T{3.1415926535897932384626433832795}{}$;\C{ $2\pi$ }\6
 3699   \&{static} \&{double} \|c${}\K\T{2.997925\_8}{}$;\C{ Speed of light in vacuum,
 3700   $c$ [m/s] }\6
 3701   \&{static} \&{double} \\{epsilon0}${}\K\T{8.854\_-12}{}$;\C{ Permittivity of
 3702   vacuum, $\varepsilon_0$ [As/Vm] }\par
 3703   \U51.\fi
 3704   
 3705   \M{53}Declaration of time variables. Here any variables related to timing and
 3706   estimation of computing performance are declared. The significance of the
 3707   variables are as follows:
 3708   \varitem[\PB{\\{initime}}]{The time at which the \magbragg\ program is
 3709   initialized.
 3710   This variable is initialized already in its declaration.}
 3711   \varitem[\PB{\\{now}}]{Dummy variable for extraction of current time from the
 3712   system.}
 3713   \varitem[\PB{\\{eta}}]{Estimated time of arrival (ETA, not to be confused with
 3714   the
 3715   Greek letter $\eta$) of successful termination of the \magbragg\ program.}
 3716   
 3717   \Y\B\4\X53:Time variables\X${}\E{}$\6
 3718   \&{time\_t} \\{initime}${}\K\\{time}(\NULL),{}$ \\{now}${}\K\\{time}(\NULL),{}$
 3719   \\{eta}${}\K\\{time}(\NULL){}$;\par
 3720   \U51.\fi
 3721   
 3722   \M{54}Declaration of pointers to arrays of fields of \PB{\&{dcomplex}} class,
 3723   holding the
 3724   intra-grating electrical field distribution.
 3725   These pointers will after the memory allocation for complex-valued vectors
 3726   hold the spatial distribution of the electric field inside the grating.
 3727   The significance of the variables are as follows:\par
 3728   \varitem[{$\PB{\\{efp}}[k]\equiv E^{\rm f}_+(z^+_k),$}]{The left circularly
 3729   polarized
 3730   forward traveling field component at $z=z_k$ taken in the $k$th homogeneous
 3731   layer of the discretized grating.}
 3732   \varitem[{$\PB{\\{efm}}[k]\equiv E^{\rm f}_-(z^+_k),$}]{The right circularly
 3733   polarized
 3734   forward traveling field component at $z=z_k$ taken in the $k$th homogeneous
 3735   layer of the discretized grating.}
 3736   \varitem[{$\PB{\\{ebp}}[k]\equiv E^{\rm b}_+(z^+_k),$}]{The left circularly
 3737   polarized
 3738   backward traveling field component at $z=z_k$ taken in the $k$th homogeneous
 3739   layer of the discretized grating.}
 3740   \varitem[{$\PB{\\{ebm}}[k]\equiv E^{\rm b}_-(z^+_k),$}]{The right circularly
 3741   polarized
 3742   backward traveling field component at $z=z_k$ taken in the $k$th homogeneous
 3743   layer of the discretized grating.}
 3744   \medskip
 3745   \noindent
 3746   that is to say, in a loss-less medium in which the nonlinear correction to the
 3747   linear refractive index is determined by the magnitude of the circularly
 3748   polarized components of the field envelopes, these arrays hold the full complex
 3749   spatial evolution of the electric field.
 3750   
 3751   \Y\B\4\X54:Declaration of complex arrays storing the electrical field
 3752   distribution\X${}\E{}$\6
 3753   \&{dcomplex} ${}{*}\\{efp},{}$ ${}{*}\\{efm},{}$ ${}{*}\\{ebp},{}$ ${}{*}%
 3754   \\{ebm}{}$;\par
 3755   \U51.\fi
 3756   
 3757   \M{55}Declaration of Boolean variables. The Boolean variables are used as flags
 3758   that internally are set and recognized by the \magbragg\ program, for example
 3759   to determine states or modes of operation as specified by the user via command
 3760   line options.
 3761   In the \magbragg\ program, we use integer variables of \PB{\&{short}} precision
 3762   for
 3763   storing Boolean values, with the value~0 corresponding to the ``false'' state
 3764   and~1 corresponding to the ``true'' state.
 3765   
 3766   \Y\B\4\X55:Declaration of Boolean variables for execution control\X${}\E{}$\6
 3767   \&{short} \\{verbose};\C{ If nonzero, display information at terminal output
 3768   during  program execution }\6
 3769   \&{short} \\{randomdistribution};\C{ If nonzero, use random layer thicknesses
 3770   of  a binary-type grating }\6
 3771   \&{short} \\{writegratingtofile};\C{ If nonzero, save the grating structure to
 3772       file }\6
 3773   \&{short} \\{scale\_stokesparams};\C{ If nonzero, then scale Stokes parameters
 3774   by      \PB{\\{stoke\_scalefactor}} }\6
 3775   \&{short} \\{normalize\_length\_to\_micrometer};\C{ If nonzero,  }\6
 3776   \&{short} \\{normalize\_intensity};\C{ If nonzero,  }\6
 3777   \&{short} \\{normalize\_ellipticity};\C{ If nonzero,  }\6
 3778   \&{short} \\{normalize\_internally};\C{ If nonzero,  }\6
 3779   \&{short} \\{odd\_layer};\C{ Keeps track of odd and even grating layers in
 3780   initialization }\6
 3781   \&{short} \\{chirpflag};\C{ If nonzero, then apply chirp to periodicity of
 3782     sinusoidal grating structures }\6
 3783   \&{short} \\{apodize};\C{ If nonzero, apply apodization to the ends of the
 3784   grating }\6
 3785   \&{short} \\{phasejump};\C{ If nonzero, apply at least one discrete phase
 3786   discontinuity of the grating profile }\6
 3787   \&{short} \\{fieldevoflag};\C{ If nonzero, then save spatial field distribution
 3788   to file }\6
 3789   \&{short} \\{fieldevoflag\_efield};\C{ If nonzero while \PB{\\{fieldevoflag}}
 3790   is nonzero,      then save the complex electric field as the spatial field
 3791   distribution }\6
 3792   \&{short} \\{intensityevoflag};\C{ If nonzero while \PB{\\{fieldevoflag}} is
 3793   nonzero, then      save the field intensity as the spatial field distribution }%
 3794   \6
 3795   \&{short} \\{fieldevoflag\_stoke};\C{ If nonzero while \PB{\\{fieldevoflag}} is
 3796   nonzero,      then save the Stokes parameters as the spatial field distribution
 3797   }\6
 3798   \&{short} \\{intensityinfo};\C{ If nonzero, then display the maximum and
 3799   minimum      field intensities found within the grating at terminal output
 3800   before      closing the program }\6
 3801   \&{short} \\{saveintensityinfologfile};\C{ If nonzero, then also save the
 3802   displayed      maximum and minimum intensities to a log file }\6
 3803   \&{short} \\{trmtraject\_specified};\C{ If nonzero,  }\6
 3804   \&{short} \\{save\_dbspectra};\C{ If nonzero, then save any transmission
 3805   spectrum in      logarithmic (dB) scale }\6
 3806   \&{short} \\{stokes\_parameter\_spectrum};\C{ If nonzero, then save any
 3807   transmission      spectrum in terms of the corresponding Stokes parameters }\6
 3808   \&{short} \\{display\_surrounding\_media};\C{ If nonzero, then append also the
 3809       surrounding medium when saving the spatial grating profile to file }\6
 3810   \&{short} \\{perturbed\_gyration\_constant};\C{ If nonzero,  }\par
 3811   \U51.\fi
 3812   
 3813   \M{56}Declaration of discretization parameters. These parameters determine the
 3814   discretization of the problem at hand, such as the number of points in
 3815   intensity, ellipticity or wavelength to be scanned.
 3816   The significance of the variables are as follows:\par
 3817   \varitem[\PB{\\{mm}}]{The number of points $M$ to be sampled in the spectrum
 3818   between
 3819   vacuum wavelengths $\lambda_{\rm start}$ and $\lambda_{\rm stop}$.}
 3820   \varitem[\PB{\\{mme}}]{The number $M_{\rm e}$ of ellipticities $\varepsilon_{%
 3821   \rm tr}$
 3822   of the transmitted light to be sampled in the interval
 3823   $\varepsilon_{\rm tr,start}\le\varepsilon\le\varepsilon_{\rm tr,stop}$.}
 3824   \varitem[\PB{\\{mmi}}]{The number $M_{\rm i}$ of intensities $I_{\rm tr}$ of
 3825   the
 3826   transmitted light to be sampled in the interval
 3827   $I_{\rm tr,start}\le I_{\rm tr}\le I_{\rm tr,stop}$.}
 3828   
 3829   \Y\B\4\X56:Discretization parameters\X${}\E{}$\6
 3830   \&{long} \\{mm}${},{}$ \\{mme}${},{}$ \\{mmi};\par
 3831   \U51.\fi
 3832   
 3833   \M{57}Declaration of grating parameters. These parameters fully describe the
 3834   geometry and material properties of the medium in which the wave propagation
 3835   is to be performed. The significance of the variables are as follows:\par
 3836   \varitem[\PB{\\{ll}}]{Geometrical length $L$ of the grating measured in
 3837   metres.}
 3838   \varitem[\PB{\\{nn}}]{The number $N$ of discrete interfaces separating the
 3839   $N-1$
 3840   homogeneous layers of the grating and the surrounding medium.}
 3841   \varitem[\PB{\\{modnum}}]{If positive, this is the number of a manually
 3842   modified
 3843   layer, for instance a defect or cavity layer possessing different geometrical
 3844   or optical properties than the rest of the structure described by any of the
 3845   standard grating options.}
 3846   \varitem[\PB{${*}\|z$}]{Pointer to an array of $N$ elements for storing the
 3847   coordinates
 3848   of the discrete interfaces $z_1,\ldots,z_N$ between homogeneous layers of
 3849   the grating.}
 3850   \varitem[\PB{${*}\\{dz}$}]{Pointer to an array of $N-1$ elements containing the
 3851   layer
 3852   thicknesses $\PB{\\{dz}}[k]\equiv z_{k+1}-z_k$, $k=1,\ldots,N-1$.}
 3853   \varitem[\PB{${*}\|n$}, \PB{${*}\|g$}]{Pointers to arrays of $N-1$ elements
 3854   containing the
 3855   refractive indices $\PB{\|n[\|k]}=n_k$ and magneto-optical gyration
 3856   coefficients
 3857   $\PB{\|g[\|k]}=g_k=i\chi^{({\rm eem})}_{xyz}B^z_0 /(2 n_k)$ of the homogeneous
 3858   layers.}
 3859   \varitem[\PB{${*}\\{pe}$}, \PB{${*}\\{qe}$}]{Pointers to arrays of $N-1$
 3860   elements containing the
 3861   nonlinear optical coefficients
 3862   $\PB{\\{pe}[\|k]}=\chi^{\rm eeee}_{xxxx}-\chi^{\rm eeee}_{xyyx}$ and
 3863   $\PB{\\{qe}[\|k]}=\chi^{\rm eeee}_{xxxx}+\chi^{\rm eeee}_{xyyx}$ of the
 3864   homogeneous
 3865   layers.}
 3866   \varitem[\PB{${*}\\{pm}$}, \PB{${*}\\{qm}$}]{Pointers to arrays of $N-1$
 3867   elements containing the
 3868   nonlinear magneto-optical coefficients
 3869   $\PB{\\{pm}[\|k]}=i(\chi^{\rm eeeem}_{xyyyz}-\chi^{\rm eeeem}_{xxxyz})B^z_0$
 3870   and
 3871   $\PB{\\{qm}[\|k]}=i(\chi^{\rm eeeem}_{xyyyz}+\chi^{\rm eeeem}_{xxxyz})B^z_0$ of
 3872   the
 3873   layers.}
 3874   \varitem[\PB{${*}\\{etafp}$}, \PB{${*}\\{etafm}$}]{Pointers to arrays of $N-1$
 3875   elements for storing
 3876   the nonlinear coefficients of propagation $\eta^{\rm f}_+$ related to the
 3877   phase evolution of forward (f) traveling left ($+$) and right ($-$)
 3878   circularly polarized components of in respective layer $z_j<z<z_{j+1}$, with
 3879   $\PB{\\{etafp}}[j]=\eta^{\rm f}_+(z^+_j)$ and $\PB{\\{etafm}}[j]=\eta^{\rm
 3880   f}_-(z^+_j)$.}
 3881   \varitem[\PB{${*}\\{etabp}$}, \PB{${*}\\{etabm}$}]{Analogous to \PB{${*}%
 3882   \\{etafp}$} and \PB{${*}\\{etafm}$} but instead for
 3883   the nonlinear phase contributions $\PB{\\{etabp}}[j]=\eta^{\rm b}_+(z^+_j)$ and
 3884   $\PB{\\{etabm}}[j]=\eta^{\rm b}_-(z^+_j)$ for backward traveling field
 3885   components.}
 3886   \varitem[\PB{${*}\\{taup}$}, \PB{${*}\\{taum}$}]{Pointers to arrays of $N$
 3887   elements for storing the
 3888   forward intra-grating layer transmittances $\tau_{k_+}$ and $\tau_{k_-}$.}
 3889   \varitem[\PB{${*}\\{taupp}$}, \PB{${*}\\{taupm}$}]{Pointers to arrays of $N$
 3890   elements for storing
 3891   the backward intra-grating layer transmittances $\tau'_{k_+}$ and
 3892   $\tau'_{k_-}$.}
 3893   \varitem[\PB{${*}\\{rhop}$}, \PB{${*}\\{rhom}$}]{Pointers to arrays of $N$
 3894   elements for storing the
 3895   forward intra-grating layer reflectances $\rho_{k_+}$ and $\rho_{k_-}$.}
 3896   \varitem[\PB{${*}\\{rhopp}$}, \PB{${*}\\{rhopm}$}]{Pointers to arrays of $N$
 3897   elements for storing the
 3898   backward intra-grating layer reflectances $\rho'_{k_+}$ and $\rho'_{k_-}$.}
 3899   \medskip
 3900   For the definitions of the intra-grating layer reflectances and transmittances,
 3901   see the separate section {\it Calculation of intra-grating layer reflectances}.
 3902   
 3903   \Y\B\4\X57:Grating parameters\X${}\E{}$\6
 3904   \&{long} \\{nn}${},{}$ \\{modnum};\6
 3905   \&{double} \\{ll}${},{}$ ${}{*}\|z,{}$ ${}{*}\\{dz},{}$ ${}{*}\|n,{}$ ${}{*}%
 3906   \|g,{}$ ${}{*}\\{pe},{}$ ${}{*}\\{pm},{}$ ${}{*}\\{qe},{}$ ${}{*}\\{qm},{}$
 3907   ${}{*}\\{etafp},{}$ ${}{*}\\{etafm},{}$ ${}{*}\\{etabp},{}$ ${}{*}\\{etabm};{}$%
 3908   \6
 3909   \&{double} ${}{*}\\{taup},{}$ ${}{*}\\{taum},{}$ ${}{*}\\{taupp},{}$ ${}{*}%
 3910   \\{taupm},{}$ ${}{*}\\{rhop},{}$ ${}{*}\\{rhom},{}$ ${}{*}\\{rhopp},{}$ ${}{*}%
 3911   \\{rhopm}{}$;\par
 3912   \U51.\fi
 3913   
 3914   \M{58}Declaration of file pointers.
 3915   
 3916   \Y\B\4\X58:Declaration of file pointers\X${}\E{}$\6
 3917   \&{FILE} ${}{*}\\{fp\_s0},{}$ ${}{*}\\{fp\_s1},{}$ ${}{*}\\{fp\_s2},{}$ ${}{*}%
 3918   \\{fp\_s3}{}$;\C{ Stokes parameters of incident wave  }\6
 3919   \&{FILE} ${}{*}\\{fp\_v0},{}$ ${}{*}\\{fp\_v1},{}$ ${}{*}\\{fp\_v2},{}$ ${}{*}%
 3920   \\{fp\_v3}{}$;\C{ Stokes parameters of reflected wave }\6
 3921   \&{FILE} ${}{*}\\{fp\_w0},{}$ ${}{*}\\{fp\_w1},{}$ ${}{*}\\{fp\_w2},{}$ ${}{*}%
 3922   \\{fp\_w3}{}$;\C{ Stokes params. of transmitted wave  }\6
 3923   \&{FILE} ${}{*}\\{fp\_evo}\K\NULL,{}$ ${}{*}\\{fp\_ievo}\K\NULL,{}$ ${}{*}\\{fp%
 3924   \_spec}\K\NULL,{}$ ${}{*}\\{fp\_traject}\K\NULL;{}$\6
 3925   \&{FILE} ${}{*}\\{fp\_irspec}\K\NULL,{}$ ${}{*}\\{fp\_itspec}\K\NULL,{}$ ${}{*}%
 3926   \\{fp\_icspec}\K\NULL,{}$ ${}{*}\\{fp\_gr}\K\NULL;{}$\6
 3927   \&{FILE} ${}{*}\\{fp\_evo\_s0}\K\NULL,{}$ ${}{*}\\{fp\_evo\_s1}\K\NULL,{}$
 3928   ${}{*}\\{fp\_evo\_s2}\K\NULL,{}$ ${}{*}\\{fp\_evo\_s3}\K\NULL;{}$\6
 3929   \&{FILE} ${}{*}\\{intensinfologfile}\K\NULL{}$;\par
 3930   \U51.\fi
 3931   
 3932   \M{59}Declaration of character strings holding file names.
 3933   Generally in this program, the maximum number of characters a file name
 3934   string can contain is \PB{\.{NCHMAX}}, as defined in the definitions section
 3935   of the program.
 3936   
 3937   \Y\B\4\X59:Declaration of strings and file names\X${}\E{}$\6
 3938   \&{char} \\{gratingtype}[\.{NCHMAX}]${},{}$ \\{gratingsubtype}[\.{NCHMAX}];\6
 3939   \&{char} \\{fieldevofilename}[\.{NCHMAX}]${},{}$ \\{intensityevofilename}[%
 3940   \.{NCHMAX}];\6
 3941   \&{char} \\{spectrumfilename}[\.{NCHMAX}]${},{}$ \\{trmtraject\_filename}[%
 3942   \.{NCHMAX}];\6
 3943   \&{char} \\{intensity\_reflection\_spectrumfilename}[\.{NCHMAX}]${},{}$ %
 3944   \\{intensity\_transmission\_spectrumfilename}[\.{NCHMAX}]${},{}$ \\{intensity%
 3945   \_check\_spectrumfilename}[\.{NCHMAX}];\6
 3946   \&{char} \\{fieldevofilename\_s0}[\.{NCHMAX}]${},{}$ \\{fieldevofilename\_s1}[%
 3947   \.{NCHMAX}]${},{}$ \\{fieldevofilename\_s2}[\.{NCHMAX}]${},{}$ %
 3948   \\{fieldevofilename\_s3}[\.{NCHMAX}];\6
 3949   \&{char} \\{intensinfologfilename}[\.{NCHMAX}];\6
 3950   \&{char} \\{outfilename}[\.{NCHMAX}]${},{}$ \\{gratingfilename}[\.{NCHMAX}];\6
 3951   \&{char} \\{outfilename\_s0}[\.{NCHMAX}]${},{}$ \\{outfilename\_s1}[%
 3952   \.{NCHMAX}]${},{}$ \\{outfilename\_s2}[\.{NCHMAX}]${},{}$ \\{outfilename\_s3}[%
 3953   \.{NCHMAX}];\6
 3954   \&{char} \\{outfilename\_v0}[\.{NCHMAX}]${},{}$ \\{outfilename\_v1}[%
 3955   \.{NCHMAX}]${},{}$ \\{outfilename\_v2}[\.{NCHMAX}]${},{}$ \\{outfilename\_v3}[%
 3956   \.{NCHMAX}];\6
 3957   \&{char} \\{outfilename\_w0}[\.{NCHMAX}]${},{}$ \\{outfilename\_w1}[%
 3958   \.{NCHMAX}]${},{}$ \\{outfilename\_w2}[\.{NCHMAX}]${},{}$ \\{outfilename\_w3}[%
 3959   \.{NCHMAX}];\par
 3960   \U51.\fi
 3961   
 3962   \M{60}Declaration of dummy variables. Here dummy and temporary variables are
 3963   declared, where the ``dummy'' variables typically are integer counters
 3964   for iteration over wavelength, ellipticity, intensity and so on, while the
 3965   temporary variables are internally used for in some cases saving computational
 3966   time, and also for the sake of increasing the readability of the program
 3967   somewhat.
 3968   
 3969   \Y\B\4\X60:Declaration of local dummy variables\X${}\E{}$\6
 3970   \&{dcomplex} \\{tmpfp}${},{}$ \\{tmpfm}${},{}$ \\{tmpbp}${},{}$ \\{tmpbm};\6
 3971   \&{double} \\{tmp}${},{}$ \\{zt}${},{}$ \\{s0}${},{}$ \\{s1}${},{}$ %
 3972   \\{s2}${},{}$ \\{s3}${},{}$ \\{v0}${},{}$ \\{v1}${},{}$ \\{v2}${},{}$ %
 3973   \\{v3}${},{}$ \\{w0}${},{}$ \\{w1}${},{}$ \\{w2}${},{}$ \\{w3}${},{}$ %
 3974   \\{stn}${},{}$ \\{maxintens}${}\K\T{0.0},{}$ \\{maxintens\_inintens}${}\K%
 3975   \T{0.0},{}$ \\{maxintens\_inellip}${}\K\T{0.0},{}$ \\{maxintens\_trintens}${}\K%
 3976   \T{0.0},{}$ \\{maxintens\_trellip}${}\K\T{0.0};{}$\6
 3977   \&{int} \\{no\_arg}${},{}$ \\{status}${}\K\T{0},{}$ \\{tmpch};\6
 3978   \&{long} \|j${},{}$ \|k${},{}$ \\{ke}${},{}$ \\{ki};\par
 3979   \U51.\fi
 3980   
 3981   \N{1}{61}Initialization of variables.
 3982   
 3983   \Y\B\4\X61:Initialize variables\X${}\E{}$\6
 3984   $\\{trmtraject\_specified}\K\T{0}{}$;\C{ Is a trajectory of $(W_0,W_3)$
 3985   specified? }\6
 3986   ${}\\{intensityinfo}\K\T{0}{}$;\C{ Printing basic intensity info to stdout;
 3987   default: off }\6
 3988   ${}\\{saveintensityinfologfile}\K\T{0}{}$;\C{ Printing basic intensity info to
 3989   file }\6
 3990   ${}\\{randomdistribution}\K\T{0}{}$;\C{ Random shuffling of layers; default:
 3991   off }\6
 3992   ${}\\{writegratingtofile}\K\T{0}{}$;\C{ Save spatial grating structure;
 3993   default: off }\6
 3994   ${}\\{scale\_stokesparams}\K\T{0}{}$;\C{ Scale Stokes parameters by \PB{%
 3995   \\{stoke\_scalefactor}}; default: off }\6
 3996   ${}\\{stoke\_scalefactor}\K\T{1.0}{}$;\C{ Scale factor to be used for Stokes
 3997   parameters }\6
 3998   ${}\\{normalize\_length\_to\_micrometer}\K\T{0};{}$\6
 3999   ${}\\{normalize\_intensity}\K\T{0}{}$;\C{ Write normalized intensity to file;
 4000   default: off }\6
 4001   ${}\\{normalize\_ellipticity}\K\T{0}{}$;\C{ Ditto for the ellipticity }\6
 4002   ${}\\{ranseed}\K\T{1097}{}$;\C{ Seed for random number generator }\6
 4003   ${}\\{modnum}\K{-}\T{1}{}$;\C{ If positive, the manually modified layer number
 4004   }\6
 4005   ${}\\{verbose}\K\T{0}{}$;\C{ Verbose mode is off by default }\6
 4006   ${}\\{apodize}\K\T{0}{}$;\C{ Apodization is off by default }\6
 4007   ${}\\{phasejump}\K\T{0}{}$;\C{ Discrete phase jump is off by default }\6
 4008   ${}\\{normalize\_internally}\K\T{0}{}$;\C{ Default state of internal
 4009   normalization is off }\6
 4010   ${}\\{odd\_layer}\K\T{0}{}$;\C{ Counter flag for odd and even grating layers }\6
 4011   ${}\\{chirpflag}\K\T{1};{}$\6
 4012   ${}\\{save\_dbspectra}\K\T{0};{}$\6
 4013   ${}\\{stokes\_parameter\_spectrum}\K\T{0};{}$\6
 4014   ${}\\{display\_surrounding\_media}\K\T{1}{}$;\C{ Append also the
 4015   surrounding medium when saving the spatial grating profile to file;
 4016   default: on }\6
 4017   ${}\\{perturbed\_gyration\_constant}\K\T{0};{}$\6
 4018   ${}\\{fieldevoflag}\K\T{0}{}$;\C{ Save spatial field distribution to file;
 4019   default: off }\6
 4020   ${}\\{fieldevoflag\_efield}\K\T{0}{}$;\C{ Save as complex electric field;
 4021   default: off }\6
 4022   ${}\\{fieldevoflag\_stoke}\K\T{0}{}$;\C{ Save as Stokes parameters; default:
 4023   off }\6
 4024   ${}\\{intensityevoflag}\K\T{0}{}$;\C{ Save spatial intensity distribution;
 4025   default: off }\6
 4026   ${}\\{mm}\K\\{mmdef}{}$;\C{ Number of sampling points in optical spectrum }\6
 4027   ${}\\{nn}\K\\{nndef}{}$;\C{ Number of layer interfaces of grating; num of
 4028   layers is nn-1 }\6
 4029   ${}\\{mme}\K\\{mmedef}{}$;\C{ Number of sampling points in transmitted
 4030   ellipticity }\6
 4031   ${}\\{mmi}\K\\{mmidef}{}$;\C{ Number of sampling points in transmitted
 4032   intensity }\6
 4033   ${}\\{nne}\K\T{1}{}$;\C{ Default number extra, intra-layer sampling points }\6
 4034   ${}\\{ll}\K\\{lldef}{}$;\C{ Default physical length of the grating structure }\6
 4035   ${}\\{lambdastart}\K\\{lambdastartdef};{}$\6
 4036   ${}\\{lambdastop}\K\\{lambdastopdef};{}$\6
 4037   ${}\\{phasejumpangle}\K\T{0.0}{}$;\C{ Discrete phase jump is off by default }\6
 4038   ${}\\{phasejumpposition}\K\T{0.0}{}$;\C{ Discrete phase jump is off by default
 4039   }\6
 4040   ${}\\{phi}\K\T{0.0}{}$;\C{ Discrete phase jump is off by default }\6
 4041   ${}\\{nsurr}\K\\{nsurrdef}{}$;\C{ Default index of refraction of the
 4042   surrounding medium }\6
 4043   ${}\\{strcpy}(\\{outfilename},\39\.{"out.stok"}){}$;\C{ Default output file
 4044   basename }\6
 4045   ${}\\{strcpy}(\\{fieldevofilename},\39\.{"out.fevo.dat"}){}$;\C{ Default output
 4046   file basename }\6
 4047   ${}\\{strcpy}(\\{fieldevofilename\_s0},\39\.{"out.fevo.s0.dat"});{}$\6
 4048   ${}\\{strcpy}(\\{fieldevofilename\_s1},\39\.{"out.fevo.s1.dat"});{}$\6
 4049   ${}\\{strcpy}(\\{fieldevofilename\_s2},\39\.{"out.fevo.s2.dat"});{}$\6
 4050   ${}\\{strcpy}(\\{fieldevofilename\_s3},\39\.{"out.fevo.s3.dat"});{}$\6
 4051   ${}\\{strcpy}(\\{spectrumfilename},\39\.{"out.rsp.dat"}){}$;\C{ Default output
 4052   file name }\6
 4053   ${}\\{strcpy}(\\{intensity\_reflection\_spectrumfilename},\39%
 4054   \.{"out.irsp.dat"});{}$\6
 4055   ${}\\{strcpy}(\\{intensity\_transmission\_spectrumfilename},\39%
 4056   \.{"out.trsp.dat"});{}$\6
 4057   ${}\\{strcpy}(\\{intensity\_check\_spectrumfilename},\39\.{"out.chec.dat"});{}$%
 4058   \6
 4059   ${}\\{fp\_s0}\K\NULL;{}$\6
 4060   ${}\\{fp\_s1}\K\NULL;{}$\6
 4061   ${}\\{fp\_s2}\K\NULL;{}$\6
 4062   ${}\\{fp\_s3}\K\NULL;{}$\6
 4063   ${}\\{fp\_v0}\K\NULL;{}$\6
 4064   ${}\\{fp\_v1}\K\NULL;{}$\6
 4065   ${}\\{fp\_v2}\K\NULL;{}$\6
 4066   ${}\\{fp\_v3}\K\NULL;{}$\6
 4067   ${}\\{fp\_w0}\K\NULL;{}$\6
 4068   ${}\\{fp\_w1}\K\NULL;{}$\6
 4069   ${}\\{fp\_w2}\K\NULL;{}$\6
 4070   ${}\\{fp\_w3}\K\NULL{}$;\par
 4071   \U45.\fi
 4072   
 4073   \N{1}{62}Memory allocation.
 4074   Allocate memory for the temporary storage of the spatial distribution of
 4075   material parameters of the grating structure and internal, complex-valued
 4076   electromagnetic fields.
 4077   In \TeX-style notation, the parameters are interpreted in terms
 4078   of the optical and magneto-optical susceptibilities [Fredrik Jonsson,
 4079   {\it The Nonlinear Optics of Magneto-Optic Media}, PhD thesis
 4080   (The Royal Institute of Technology, Stockholm, 2000)] as follows,
 4081   starting with the all-optical (electric-dipolar related) parameters
 4082   $$
 4083   \eqalign{
 4084   \PB{\|n[\|k]}&=n_k=[1+\chi^{({\rm ee})}_{xx}]^{1/2},\cr
 4085   \PB{\\{pe}[\|k]}
 4086   &=\chi^{\rm eeee}_{xxxx}-\chi^{\rm eeee}_{xyyx},\cr
 4087   \PB{\\{qe}[\|k]}
 4088   &=\chi^{\rm eeee}_{xxxx}+\chi^{\rm eeee}_{xyyx},\cr
 4089   }
 4090   $$
 4091   where all susceptibilities of the right-hand sides are to be evaluated in the
 4092   domains $z_k<z<z_{k+1}$, $k=1,2,\ldots N-1$. In addition to the all-optical
 4093   parameters, the magneto-optical (magnetic-dipolar related) parameters are
 4094   defined as
 4095   $$
 4096   \eqalign{
 4097   \PB{\|g[\|k]}&=g_k=i\chi^{({\rm eem})}_{xyz} B^z_0 /(2 n_k),\cr
 4098   \PB{\\{pm}[\|k]}
 4099   &=i(\chi^{\rm eeeem}_{xyyyz}-\chi^{\rm eeeem}_{xxxyz})B^z_0,\cr
 4100   \PB{\\{qm}[\|k]}
 4101   &=i(\chi^{\rm eeeem}_{xyyyz}+\chi^{\rm eeeem}_{xxxyz})B^z_0,\cr
 4102   }
 4103   $$
 4104   using the same conventions of evaluation for the involved susceptibilities in
 4105   the righ-hand sides.
 4106   With these definitions, the left circularly polarized (LCP) and right
 4107   circularly polarized (RCP) modes that propagate in the forward direction in
 4108   the $k$th layer will experience the linear, field-independent refractive
 4109   indices $n_{k_+}$ and $n_{k_-}$, respectively, with
 4110   $$
 4111   \eqalignno{
 4112   n_{k_+}&=n_k[1+i\chi^{({\rm eem})}_{xyz} B^z_0 /(2 n^2_k)]
 4113   =n_k+g_k,&{\rm(LCP)}\cr
 4114   n_{k_-}&=n_k[1-i\chi^{({\rm eem})}_{xyz} B^z_0 /(2 n^2_k)]
 4115   =n_k-g_k.&{\rm(RCP)}\cr
 4116   }
 4117   $$
 4118   For backward propagating light, the experienced indices of refraction are
 4119   reversed, that is to say, backward propagating left circularly polarized
 4120   light experience $n_-$ as the refractive index, while the right circularly
 4121   polarized experience $n_+$.
 4122   
 4123   We here throughout adopt to common standard definition of circularly polarized
 4124   light, that when looking into an oncoming wave propagating in the positive
 4125   $z$-direction, the vector of the LCP electric field component $E^{\rm f}_+$
 4126   of the wave describes counterclockwise motion, while it for the RCP field
 4127   component $E^{\rm f}_-$ instead describes clockwise motion.
 4128   This convention conforms to the classical one as used in
 4129   optics~[J.~D.~Jackson, {Classical Electrodynamics} (Wiley, New York, 1975);
 4130   M.~Born and E.~Wolf, {Principles of Optics} (Cambridge University Press,
 4131   Cambridge, 1980)].
 4132   Similarly, by looking into an oncoming wave propagating in the negative
 4133   $z$-direction, the vector of the LCP electric field component $E^{\rm b}_+$
 4134   describes counterclockwise motion, while it for the RCP field component
 4135   $E^{\rm b}_-$ describes clockwise motion.
 4136   
 4137   In the following allocation of memory, the $k$th element of respective vector
 4138   contains the numerical value for the respective material parameter evaluated
 4139   in the domain $z_k < z < z_{k+1}$, for $k=1,2,\ldots,N-1$, while the vectors
 4140   containing the electrical field components contain the respective component
 4141   evaluated at the ``beginning'' of respective layer, at $z=z^+_k$.
 4142   From material parameters such as the linear refractive indices $n_k$ and
 4143   the magneto-optical gyration constants $g_k$ of the compound structure,
 4144   derived numerical quantities, such as the transmission coefficients
 4145   $\tau_{k_{\pm}}$ and $\tau'_{k_{\pm}}$ and the reflection coefficients
 4146   $\rho_{k_{\pm}}$ and $\rho'_{k_{\pm}}$ across the interfaces at $z_k$,
 4147   are later on calculated and stored in vectors that here are allocated.
 4148   
 4149   \Y\B\4\X62:Allocate optical field vectors\X${}\E{}$\6
 4150   ${}\{{}$\1\6
 4151   ${}\|z\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Spatial coordinate $z_k$ along the
 4152   Bragg grating }\6
 4153   ${}\\{dz}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{$\PB{\\{dz}}[k]\equiv\PB{%
 4154   \|z}[k+1]-\PB{\|z}[k]$, $k=1,2,...,\PB{\\{nn}}-1$}\6
 4155   ${}\\{efp}\K\\{dcvector}(\T{0},\39\\{nn}){}$;\C{ Equals $E^f_{k_+}$ in %
 4156   \TeX-style notation    }\6
 4157   ${}\\{efm}\K\\{dcvector}(\T{0},\39\\{nn}){}$;\C{ Equals $E^f_{k_-}$ in %
 4158   \TeX-style notation    }\6
 4159   ${}\\{ebp}\K\\{dcvector}(\T{0},\39\\{nn}){}$;\C{ Equals $E^b_{k_+}$ in %
 4160   \TeX-style notation    }\6
 4161   ${}\\{ebm}\K\\{dcvector}(\T{0},\39\\{nn}){}$;\C{ Equals $E^b_{k_-}$ in %
 4162   \TeX-style notation    }\6
 4163   ${}\\{taup}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Forward LCP transmission
 4164   coefficient $\tau_{k_+}$ }\6
 4165   ${}\\{taum}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Forward RCP transmission
 4166   coefficient $\tau_{k_+}$ }\6
 4167   ${}\\{taupp}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Backward LCP transmission
 4168   coeff.~ $\tau'_{k_+}$ }\6
 4169   ${}\\{taupm}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Backward RCP transmission
 4170   coeff.~$\tau'_{k_-}$ }\6
 4171   ${}\\{rhop}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Forward LCP reflection
 4172   coeff.~$\rho_{k_+}$ }\6
 4173   ${}\\{rhom}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Forward RCP reflection
 4174   coeff.~$\rho_{k_-}$ }\6
 4175   ${}\\{rhopp}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Backward LCP reflection
 4176   coeff.~$\rho'_{k_+}$ }\6
 4177   ${}\\{rhopm}\K\\{dvector}(\T{1},\39\\{nn}){}$;\C{ Backward RCP reflection
 4178   coeff.~$\rho'_{k_-}$ }\6
 4179   ${}\|n\K\\{dvector}(\T{0},\39\\{nn}){}$;\C{ Linear electric-dipolar refractive
 4180   index $n(z)$ }\6
 4181   ${}\|g\K\\{dvector}(\T{0},\39\\{nn}){}$;\C{ Linear magneto-optical contribution
 4182   to $n(z)$ }\6
 4183   ${}\\{pe}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear all-optical
 4184   contribution to $n(z)$ }\6
 4185   ${}\\{pm}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear magneto-optical
 4186   contribution to $n(z)$ }\6
 4187   ${}\\{qe}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear all-optical
 4188   contribution to $n(z)$ }\6
 4189   ${}\\{qm}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear magneto-optical
 4190   contribution to $n(z)$ }\6
 4191   ${}\\{etafp}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear LCP forward
 4192   contribution to $n(z)$  }\6
 4193   ${}\\{etabp}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear LCP backward
 4194   contribution to $n(z)$ }\6
 4195   ${}\\{etafm}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear RCP forward
 4196   contribution to $n(z)$  }\6
 4197   ${}\\{etabm}\K\\{dvector}(\T{1},\39\\{nn}-\T{1}){}$;\C{ Nonlinear RCP backward
 4198   contribution to $n(z)$ }\6
 4199   \4${}\}{}$\2\par
 4200   \U45.\fi
 4201   
 4202   \M{63}At the end of the program, we would also like to properly deallocate
 4203   the memory occupied by the previously allocated real- and complex-valued
 4204   vectors that have been used in the simulation. This is done by executing
 4205   the following block.
 4206   
 4207   \Y\B\4\X63:Deallocate optical field vectors\X${}\E{}$\6
 4208   ${}\{{}$\1\6
 4209   ${}\\{free\_dcvector}(\\{efp},\39\T{0},\39\\{nn});{}$\6
 4210   ${}\\{free\_dcvector}(\\{efm},\39\T{0},\39\\{nn});{}$\6
 4211   ${}\\{free\_dcvector}(\\{ebp},\39\T{0},\39\\{nn});{}$\6
 4212   ${}\\{free\_dcvector}(\\{ebm},\39\T{0},\39\\{nn});{}$\6
 4213   ${}\\{free\_dvector}(\\{taup},\39\T{1},\39\\{nn});{}$\6
 4214   ${}\\{free\_dvector}(\\{taum},\39\T{1},\39\\{nn});{}$\6
 4215   ${}\\{free\_dvector}(\\{taupp},\39\T{1},\39\\{nn});{}$\6
 4216   ${}\\{free\_dvector}(\\{taupm},\39\T{1},\39\\{nn});{}$\6
 4217   ${}\\{free\_dvector}(\\{rhop},\39\T{1},\39\\{nn});{}$\6
 4218   ${}\\{free\_dvector}(\\{rhom},\39\T{1},\39\\{nn});{}$\6
 4219   ${}\\{free\_dvector}(\\{rhopp},\39\T{1},\39\\{nn});{}$\6
 4220   ${}\\{free\_dvector}(\\{rhopm},\39\T{1},\39\\{nn});{}$\6
 4221   ${}\\{free\_dvector}(\|n,\39\T{0},\39\\{nn});{}$\6
 4222   ${}\\{free\_dvector}(\|g,\39\T{0},\39\\{nn});{}$\6
 4223   ${}\\{free\_dvector}(\\{pe},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4224   ${}\\{free\_dvector}(\\{pm},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4225   ${}\\{free\_dvector}(\\{qe},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4226   ${}\\{free\_dvector}(\\{qm},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4227   ${}\\{free\_dvector}(\\{etafp},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4228   ${}\\{free\_dvector}(\\{etabp},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4229   ${}\\{free\_dvector}(\\{etafm},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4230   ${}\\{free\_dvector}(\\{etabm},\39\T{1},\39\\{nn}-\T{1});{}$\6
 4231   \&{if} (\\{trmtraject\_specified})\5
 4232   ${}\{{}$\1\6
 4233   ${}\\{free\_dvector}(\\{w0traj},\39\T{1},\39\\{mmtraject});{}$\6
 4234   ${}\\{free\_dvector}(\\{w3traj},\39\T{1},\39\\{mmtraject});{}$\6
 4235   \4${}\}{}$\2\6
 4236   \4${}\}{}$\2\par
 4237   \U45.\fi
 4238   
 4239   \N{1}{64}Initialization of the grating structure.
 4240   Using the previously allocated memory for the temporary storage of the
 4241   spatially distributed grating structure, initiate the material parameters
 4242   of the interior of the grating.
 4243   If the user via the command line options has specified that a perturbation
 4244   of the gyration constant should be present somewhere along the grating, then
 4245   add a perturbation in the functional form of a magneto-optical effect that
 4246   would arise due to a current carrying wire, placed orthogonal to the direction
 4247   of propagation, and in a close vicinity of the medium.
 4248   
 4249   \Y\B\4\X64:Initiate grating structure\X${}\E{}$\6
 4250   ${}\{{}$\1\6
 4251   \&{if} ${}(\R\\{strcmp}(\\{gratingtype},\39\.{"stepwise"})){}$\5
 4252   ${}\{{}$\1\6
 4253   \X65:Initiate binary grating structure\X;\6
 4254   \4${}\}{}$\2\6
 4255   \&{else} \&{if} ${}(\R\\{strcmp}(\\{gratingtype},\39\.{"sinusoidal"})){}$\5
 4256   ${}\{{}$\1\6
 4257   \X66:Initiate sinusoidal grating structure\X;\6
 4258   \4${}\}{}$\2\6
 4259   \&{else} \&{if} ${}(\R\\{strcmp}(\\{gratingtype},\39\.{"chirped"})){}$\5
 4260   ${}\{{}$\1\6
 4261   \X67:Initiate chirped grating structure\X;\6
 4262   \4${}\}{}$\2\6
 4263   \&{else} \&{if} ${}(\R\\{strcmp}(\\{gratingtype},\39\.{"fractal"})){}$\5
 4264   ${}\{{}$\1\6
 4265   \X68:Initiate fractal grating structure\X;\6
 4266   \4${}\}{}$\2\6
 4267   \&{else}\5
 4268   ${}\{{}$\1\6
 4269   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error:\ Specifie}\)\.{d\ grating\ type\
 4270   is\ in}\)\.{valid.\\n"},\39\\{progname});{}$\6
 4271   \\{showsomehelp}(\,);\6
 4272   \\{exit}(\.{FAILURE});\6
 4273   \4${}\}{}$\2\6
 4274   \&{if} (\\{perturbed\_gyration\_constant})\5
 4275   ${}\{{}$\1\6
 4276   \X69:Add perturbation of gyration constant along grating structure\X;\6
 4277   \4${}\}{}$\2\6
 4278   \4${}\}{}$\2\par
 4279   \U45.\fi
 4280   
 4281   \M{65}For the binary type of stepwise gratings, with the refractive index and
 4282   all other material parameters of the medium spatially alternating between
 4283   two distinct values, the odd layers (i.e. $z_k<z<z_{k+1}$, with $k$ being
 4284   an odd integer) have all the layer thickness given by the parameter \PB{%
 4285   \\{t1}},
 4286   while all even layers (i.e. $z_k<z<z_{k+1}$, with $k$ being an even integer)
 4287   have the layer thickness given by \PB{\\{t2}}.
 4288   This means that in this case the total length of the grating is given as
 4289   $$
 4290   L = \{{\rm the\ number\ of\ odd\ layers}\}\times\PB{\\{t1}}
 4291   + \{{\rm the\ number\ of\ even\ layers}\}\times\PB{\\{t2}},
 4292   $$
 4293   and hence the value of any specified grating length (by using the
 4294   \.{--gratinglength} option) will be neglected for the \.{twolevel}
 4295   stepwise type of grating.
 4296   
 4297   The material parameters \PB{\\{pe}}, \PB{\\{qe}}, \PB{\\{pm}}, and \PB{\\{qm}},
 4298   are (as previously)
 4299   defined as
 4300   $$
 4301   \eqalign{
 4302   \PB{\\{pe}[\|k]}&=\chi^{\rm eeee}_{xxxx}(-\omega;\omega,\omega,-\omega)
 4303   -\chi^{\rm eeee}_{xyyx}(-\omega;\omega,\omega,-\omega),\cr
 4304   \PB{\\{qe}[\|k]}&=\chi^{\rm eeee}_{xxxx}(-\omega;\omega,\omega,-\omega)
 4305   +\chi^{\rm eeee}_{xyyx}(-\omega;\omega,\omega,-\omega),\cr
 4306   \PB{\\{pm}[\|k]}&=i(\chi^{\rm eeeem}_{xyyyz}(-\omega;\omega,\omega,-\omega,0)
 4307   -\chi^{\rm eeeem}_{xxxyz}(-\omega;\omega,\omega,-\omega,0))B^z_0,\cr
 4308   \PB{\\{qm}[\|k]}&=i(\chi^{\rm eeeem}_{xyyyz}(-\omega;\omega,\omega,-\omega,0)
 4309   +\chi^{\rm eeeem}_{xxxyz}(-\omega;\omega,\omega,-\omega,0))B^z_0,\cr
 4310   }
 4311   $$
 4312   where $\chi^{\rm eeee}_{\mu\alpha\beta\gamma}
 4313   (-\omega;\omega,\omega,-\omega)$ and
 4314   $\chi^{\rm eeeem}_{\mu\alpha\beta\gamma\delta}
 4315   (-\omega;\omega,\omega,-\omega,0)$
 4316   are the nonlinear optical and magneto-optical susceptibility tensors
 4317   governing the intensity-dependent refractive index and Faraday effect,
 4318   respectively, taken in a notation conforming to P.~N.~Butcher and D.~Cotter
 4319   [P.~N.~Butcher and D.~Cotter, {\it The Elements of Nonlinear Optics}
 4320   (Cambridge University Press, New York, 1990)], and to be evaluated in
 4321   respective layer $z_k<z<z_{k+1}$, $k=1,2,\ldots,N-1$.
 4322   
 4323   When initializing the binary type of stepwise gratings, the program will check
 4324   if the \PB{\\{randomdistribution}} flag (a numerical integer) was set through
 4325   the
 4326   command line parameters. If so (i.~e.~if $\PB{\\{randomdistribution}}=1$), then
 4327   the
 4328   layers of different indices and material parameters will be randomly ordered.
 4329   
 4330   \Y\B\4\X65:Initiate binary grating structure\X${}\E{}$\6
 4331   ${}\{{}$\1\6
 4332   \&{if} ${}(\R\\{strcmp}(\\{gratingsubtype},\39\.{"twolevel"})){}$\5
 4333   ${}\{{}$\1\6
 4334   \&{if} (\\{randomdistribution})\5
 4335   ${}\{{}$\1\6
 4336   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 4337   ${}\{{}$\1\6
 4338   \&{if} ${}(\|j\E\\{modnum}){}$\5
 4339   ${}\{{}$\1\6
 4340   \&{if} ${}(\|j\E\T{1}){}$\1\5
 4341   ${}\|z[\|j]\K\T{0.0};{}$\2\6
 4342   ${}\|z[\|j+\T{1}]\K\|z[\|j]+\\{modt1};{}$\6
 4343   ${}\\{dz}[\|j]\K\\{modt1};{}$\6
 4344   ${}\|n[\|j]\K\\{modn1};{}$\6
 4345   ${}\|g[\|j]\K\\{modg1};{}$\6
 4346   ${}\\{pe}[\|j]\K\\{modpe1};{}$\6
 4347   ${}\\{pm}[\|j]\K\\{modpm1};{}$\6
 4348   ${}\\{qe}[\|j]\K\\{modqe1};{}$\6
 4349   ${}\\{qm}[\|j]\K\\{modqm1};{}$\6
 4350   \4${}\}{}$\2\6
 4351   \&{else}\5
 4352   ${}\{{}$\1\6
 4353   ${}\\{ranseed}\K\\{ranseed}+\|j;{}$\6
 4354   \&{if} ${}(\\{ran1}({\AND}\\{ranseed})>\T{0.5}){}$\5
 4355   ${}\{{}$\1\6
 4356   \&{if} (\\{verbose})\1\5
 4357   ${}\\{fprintf}(\\{stdout},\39\.{"Random\ number:\ 1\\n"});{}$\2\6
 4358   \&{if} ${}(\|j\E\T{1}){}$\1\5
 4359   ${}\|z[\|j]\K\T{0.0};{}$\2\6
 4360   ${}\|z[\|j+\T{1}]\K\|z[\|j]+\\{t1};{}$\6
 4361   ${}\\{dz}[\|j]\K\\{t1};{}$\6
 4362   ${}\|n[\|j]\K\\{n1};{}$\6
 4363   ${}\|g[\|j]\K\\{g1};{}$\6
 4364   ${}\\{pe}[\|j]\K\\{pe1};{}$\6
 4365   ${}\\{pm}[\|j]\K\\{pm1};{}$\6
 4366   ${}\\{qe}[\|j]\K\\{qe1};{}$\6
 4367   ${}\\{qm}[\|j]\K\\{qm1};{}$\6
 4368   \4${}\}{}$\2\6
 4369   \&{else}\5
 4370   ${}\{{}$\1\6
 4371   \&{if} (\\{verbose})\1\5
 4372   ${}\\{fprintf}(\\{stdout},\39\.{"Random\ number:\ 0\\n"});{}$\2\6
 4373   \&{if} ${}(\|j\E\T{1}){}$\1\5
 4374   ${}\|z[\|j]\K\T{0.0};{}$\2\6
 4375   ${}\|z[\|j+\T{1}]\K\|z[\|j]+\\{t2};{}$\6
 4376   ${}\\{dz}[\|j]\K\\{t2};{}$\6
 4377   ${}\|n[\|j]\K\\{n2};{}$\6
 4378   ${}\|g[\|j]\K\\{g2};{}$\6
 4379   ${}\\{pe}[\|j]\K\\{pe2};{}$\6
 4380   ${}\\{pm}[\|j]\K\\{pm2};{}$\6
 4381   ${}\\{qe}[\|j]\K\\{qe2};{}$\6
 4382   ${}\\{qm}[\|j]\K\\{qm2};{}$\6
 4383   \4${}\}{}$\2\6
 4384   \4${}\}{}$\2\6
 4385   \4${}\}{}$\2\6
 4386   \4${}\}{}$\2\6
 4387   \&{else}\5
 4388   ${}\{{}$\C{ else, if non-random distribution }\1\6
 4389   \&{if} ${}(\\{modnum}<\T{0}){}$\5
 4390   ${}\{{}$\C{ if no modified layer of the grating, ... }\1\6
 4391   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\K\|j+\T{2}){}$\5
 4392   ${}\{{}$\C{ all odd layers, $\PB{\|j}=1,3,5,\ldots$ }\1\6
 4393   ${}\|z[\|j]\K\T{0.5}*((\&{double})(\|j-\T{1}))*(\\{t1}+\\{t2});{}$\6
 4394   ${}\\{dz}[\|j]\K\\{t1};{}$\6
 4395   ${}\|n[\|j]\K\\{n1};{}$\6
 4396   ${}\|g[\|j]\K\\{g1};{}$\6
 4397   ${}\\{pe}[\|j]\K\\{pe1};{}$\6
 4398   ${}\\{pm}[\|j]\K\\{pm1};{}$\6
 4399   ${}\\{qe}[\|j]\K\\{qe1};{}$\6
 4400   ${}\\{qm}[\|j]\K\\{qm1};{}$\6
 4401   \&{if} ${}(\|j\E\\{nn}-\T{1}){}$\1\5
 4402   ${}\|z[\\{nn}]\K\|z[\\{nn}-\T{1}]+\\{t1};{}$\2\6
 4403   \4${}\}{}$\2\6
 4404   \&{for} ${}(\|j\K\T{2};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\K\|j+\T{2}){}$\5
 4405   ${}\{{}$\C{ all even layers, $\PB{\|j}=2,4,6,\ldots$ }\1\6
 4406   ${}\|z[\|j]\K\|z[\|j-\T{1}]+\\{t1};{}$\6
 4407   ${}\\{dz}[\|j]\K\\{t2};{}$\6
 4408   ${}\|n[\|j]\K\\{n2};{}$\6
 4409   ${}\|g[\|j]\K\\{g2};{}$\6
 4410   ${}\\{pe}[\|j]\K\\{pe2};{}$\6
 4411   ${}\\{pm}[\|j]\K\\{pm2};{}$\6
 4412   ${}\\{qe}[\|j]\K\\{qe2};{}$\6
 4413   ${}\\{qm}[\|j]\K\\{qm2};{}$\6
 4414   \&{if} ${}(\|j\E\\{nn}-\T{1}){}$\1\5
 4415   ${}\|z[\\{nn}]\K\|z[\\{nn}-\T{1}]+\\{t2};{}$\2\6
 4416   \4${}\}{}$\2\6
 4417   \4${}\}{}$\2\6
 4418   \&{else}\5
 4419   ${}\{{}$\C{ ... else, if at least one modified layer of the grating }\1\6
 4420   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 4421   ${}\{{}$\1\6
 4422   \&{if} ${}(\|j\E\T{1}){}$\1\5
 4423   ${}\|z[\|j]\K\T{0.0};{}$\2\6
 4424   \&{if} ${}(\|j\E\\{modnum}){}$\5
 4425   ${}\{{}$\C{ the modified layer }\1\6
 4426   ${}\|z[\|j+\T{1}]\K\|z[\|j]+\\{modt1};{}$\6
 4427   ${}\\{dz}[\|j]\K\\{modt1};{}$\6
 4428   ${}\|n[\|j]\K\\{modn1};{}$\6
 4429   ${}\|g[\|j]\K\\{modg1};{}$\6
 4430   ${}\\{pe}[\|j]\K\\{modpe1};{}$\6
 4431   ${}\\{pm}[\|j]\K\\{modpm1};{}$\6
 4432   ${}\\{qe}[\|j]\K\\{modqe1};{}$\6
 4433   ${}\\{qm}[\|j]\K\\{modqm1};{}$\6
 4434   \4${}\}{}$\2\6
 4435   \&{else}\5
 4436   ${}\{{}$\1\6
 4437   ${}\\{tmp}\K{}$((\&{double}) \|j)${}/{}$((\&{double}) \T{2});\6
 4438   \&{if} ${}(\\{tmp}-\\{floor}(\\{tmp})>\T{0.25}){}$\5
 4439   ${}\{{}$\C{ if \PB{\|j} odd }\1\6
 4440   ${}\|z[\|j+\T{1}]\K\|z[\|j]+\\{t1};{}$\6
 4441   ${}\\{dz}[\|j]\K\\{t1};{}$\6
 4442   ${}\|n[\|j]\K\\{n1};{}$\6
 4443   ${}\|g[\|j]\K\\{g1};{}$\6
 4444   ${}\\{pe}[\|j]\K\\{pe1};{}$\6
 4445   ${}\\{pm}[\|j]\K\\{pm1};{}$\6
 4446   ${}\\{qe}[\|j]\K\\{qe1};{}$\6
 4447   ${}\\{qm}[\|j]\K\\{qm1};{}$\6
 4448   \4${}\}{}$\2\6
 4449   \&{else}\5
 4450   ${}\{{}$\C{ if \PB{\|j} even }\1\6
 4451   ${}\|z[\|j+\T{1}]\K\|z[\|j]+\\{t2};{}$\6
 4452   ${}\\{dz}[\|j]\K\\{t2};{}$\6
 4453   ${}\|n[\|j]\K\\{n2};{}$\6
 4454   ${}\|g[\|j]\K\\{g2};{}$\6
 4455   ${}\\{pe}[\|j]\K\\{pe2};{}$\6
 4456   ${}\\{pm}[\|j]\K\\{pm2};{}$\6
 4457   ${}\\{qe}[\|j]\K\\{qe2};{}$\6
 4458   ${}\\{qm}[\|j]\K\\{qm2};{}$\6
 4459   \4${}\}{}$\2\6
 4460   \4${}\}{}$\2\6
 4461   \4${}\}{}$\2\6
 4462   \4${}\}{}$\2\6
 4463   \4${}\}{}$\2\6
 4464   \4${}\}{}$\2\6
 4465   \&{else}\5
 4466   ${}\{{}$\1\6
 4467   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error.\\n"},\39\\{progname});{}$\6
 4468   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (No\ valid\ grati}\)\.{ng\ subtype\
 4469   found).\\n}\)\.{"},\39\\{progname});{}$\6
 4470   \\{exit}(\.{FAILURE});\6
 4471   \4${}\}{}$\2\6
 4472   \4${}\}{}$\2\par
 4473   \U64.\fi
 4474   
 4475   \M{66}For the sinusoidal type gratings, the grating structure is spatially
 4476   oversampled and modelled as a large number of thin homogeneous slices,
 4477   as in the oversampling in some algorithms for calculation of
 4478   transmission properties of fiber Bragg gratings. In the oversampling,
 4479   the thickness of each of the layers is equal, using an equidistanly
 4480   spaced spatial increment in the beam propagation performed across each
 4481   of the layers.
 4482   Here, \PB{\\{nper}} is the physical, spatial period of the refractive index
 4483   distribution $n(z)$, while \PB{\\{gper}} is the spatial period of the linear
 4484   magneto-optical gyration constant $g(z)$, etc.
 4485   
 4486   For sinusoidal type gratings, any stated apodization profile will also
 4487   be applied,
 4488   in order to get rid of any occurring Gibbs oscillations due to a rapid
 4489   change of the index modulation at the ends of the grating.
 4490   From a user perspective, the \.{--apodize}
 4491   option is used at startup time of the program for specifying a smoother
 4492   transition between modulated and non-modulated regions of the grating.
 4493   The apodization is performed at the ends of the grating according to a
 4494   multiplicative factor of the \PB{\\{n2}} and \PB{\\{g2}} modulation amplitudes
 4495   of the
 4496   refractive index and gyration coefficient, of the form
 4497   $$
 4498   f(z)=\Bigg\lbrace
 4499   \matrix{[1-\cos(\pi z/a)]/2,&\ 0\le z\le a,\cr
 4500   1,&\ a<z<L-a,\cr
 4501   [1-\cos(\pi(z-L)/a)]/2,&\ L-a\le z\le L,}
 4502   $$
 4503   and otherwise $f(z)=0$, for any $z$ outside the above domains of definition,
 4504   where $a$ is the effective apodization length, being the floating point
 4505   parameter specified after the \.{--apodize} option, and $L$ as usual the
 4506   geometrical overall length of the grating.
 4507   
 4508   In the generation of the sinusoidal grating structure, we also include any
 4509   possible discrete spatial phase jump, as specified by the \.{--phasejump}
 4510   command line option.
 4511   
 4512   \Y\B\4\X66:Initiate sinusoidal grating structure\X${}\E{}$\6
 4513   ${}\{{}$\1\6
 4514   ${}\\{t1}\K\\{ll}/((\&{double})(\\{nn}-\T{1}));{}$\6
 4515   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 4516   ${}\{{}$\1\6
 4517   ${}\|z[\|j]\K((\&{double})(\|j-\T{1}))*\\{t1};{}$\6
 4518   ${}\\{dz}[\|j]\K\\{t1};{}$\6
 4519   \&{if} (\\{apodize})\5
 4520   ${}\{{}$\1\6
 4521   \&{if} ${}((\T{0.0}\Z\|z[\|j])\W(\|z[\|j]\Z\\{apolength})){}$\5
 4522   ${}\{{}$\1\6
 4523   ${}\\{tmp}\K(\T{1.0}-\\{cos}(\\{pi}*\|z[\|j]/\\{apolength}))/\T{2.0};{}$\6
 4524   \4${}\}{}$\2\6
 4525   \&{else} \&{if} ${}((\\{apolength}\Z\|z[\|j])\W(\|z[\|j]\Z\\{ll}-%
 4526   \\{apolength})){}$\5
 4527   ${}\{{}$\1\6
 4528   ${}\\{tmp}\K\T{1.0};{}$\6
 4529   \4${}\}{}$\2\6
 4530   \&{else} \&{if} ${}((\\{ll}-\\{apolength}\Z\|z[\|j])\W(\|z[\|j]\Z\\{ll})){}$\5
 4531   ${}\{{}$\1\6
 4532   ${}\\{tmp}\K(\T{1.0}-\\{cos}(\\{pi}*(\|z[\|j]-\\{ll})/\\{apolength}))/%
 4533   \T{2.0};{}$\6
 4534   \4${}\}{}$\2\6
 4535   \&{else}\5
 4536   ${}\{{}$\1\6
 4537   ${}\\{tmp}\K\T{0.0};{}$\6
 4538   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Impossible\ apod}\)\.{ization\ event\
 4539   occurr}\)\.{ed."},\39\\{progname});{}$\6
 4540   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Please\ check\ g}\)\.{rating\
 4541   initializatio}\)\.{n.)"},\39\\{progname});{}$\6
 4542   \4${}\}{}$\2\6
 4543   \4${}\}{}$\2\6
 4544   \&{if} (\\{phasejump})\5
 4545   ${}\{{}$\1\6
 4546   \&{if} ${}(\|z[\|j]\G\\{phasejumpposition}){}$\5
 4547   ${}\{{}$\1\6
 4548   ${}\\{phi}\K\\{phasejumpangle};{}$\6
 4549   \4${}\}{}$\2\6
 4550   \&{else}\5
 4551   ${}\{{}$\1\6
 4552   ${}\\{phi}\K\T{0.0};{}$\6
 4553   \4${}\}{}$\2\6
 4554   \4${}\}{}$\2\6
 4555   \&{if} (\\{apodize})\5
 4556   ${}\{{}$\1\6
 4557   ${}\|n[\|j]\K\\{n1}+\\{n2}*\\{tmp}*\\{sin}(\\{twopi}*\|z[\|j]/\\{nper}+%
 4558   \\{phi});{}$\6
 4559   ${}\|g[\|j]\K\\{g1}+\\{g2}*\\{tmp}*\\{sin}(\\{twopi}*\|z[\|j]/\\{gper}+%
 4560   \\{phi});{}$\6
 4561   \4${}\}{}$\2\6
 4562   \&{else}\5
 4563   ${}\{{}$\1\6
 4564   ${}\|n[\|j]\K\\{n1}+\\{n2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{nper}+\\{phi});{}$\6
 4565   ${}\|g[\|j]\K\\{g1}+\\{g2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{gper}+\\{phi});{}$\6
 4566   \4${}\}{}$\2\6
 4567   ${}\\{pe}[\|j]\K\\{pe1}+\\{pe2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{peper});{}$\6
 4568   ${}\\{pm}[\|j]\K\\{pm1}+\\{pm2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{pmper});{}$\6
 4569   ${}\\{qe}[\|j]\K\\{qe1}+\\{qe2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{qeper});{}$\6
 4570   ${}\\{qm}[\|j]\K\\{qm1}+\\{qm2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{qmper});{}$\6
 4571   \4${}\}{}$\2\6
 4572   ${}\|z[\\{nn}]\K\\{ll};{}$\6
 4573   \4${}\}{}$\2\par
 4574   \U64.\fi
 4575   
 4576   \M{67}Just as for the sinusoidal type gratings, the chirped grating structure
 4577   is spatially oversampled and modelled as a large number of thin homogeneous
 4578   slices of equal thickness.
 4579   As in the case of a pure sinusoidal grating, we here also check whether an
 4580   apodization should be applied to the grating profile, subsequently applying
 4581   the apodization.
 4582   In the generation of the chirped grating structure, we also include any
 4583   possible discrete spatial phase jump, as specified by the \.{--phasejump}
 4584   command line option.
 4585   
 4586   \Y\B\4\X67:Initiate chirped grating structure\X${}\E{}$\6
 4587   ${}\{{}$\1\6
 4588   ${}\\{t1}\K\\{ll}/((\&{double})(\\{nn}-\T{1}));{}$\6
 4589   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 4590   ${}\{{}$\1\6
 4591   ${}\|z[\|j]\K((\&{double})(\|j-\T{1}))*\\{t1};{}$\6
 4592   ${}\\{dz}[\|j]\K\\{t1};{}$\6
 4593   \&{if} (\\{apodize})\5
 4594   ${}\{{}$\1\6
 4595   \&{if} ${}((\T{0.0}\Z\|z[\|j])\W(\|z[\|j]\Z\\{apolength})){}$\5
 4596   ${}\{{}$\1\6
 4597   ${}\\{tmp}\K(\T{1.0}-\\{cos}(\\{pi}*\|z[\|j]/\\{apolength}))/\T{2.0};{}$\6
 4598   \4${}\}{}$\2\6
 4599   \&{else} \&{if} ${}((\\{apolength}\Z\|z[\|j])\W(\|z[\|j]\Z\\{ll}-%
 4600   \\{apolength})){}$\5
 4601   ${}\{{}$\1\6
 4602   ${}\\{tmp}\K\T{1.0};{}$\6
 4603   \4${}\}{}$\2\6
 4604   \&{else} \&{if} ${}((\\{ll}-\\{apolength}\Z\|z[\|j])\W(\|z[\|j]\Z\\{ll})){}$\5
 4605   ${}\{{}$\1\6
 4606   ${}\\{tmp}\K(\T{1.0}-\\{cos}(\\{pi}*(\|z[\|j]-\\{ll})/\\{apolength}))/%
 4607   \T{2.0};{}$\6
 4608   \4${}\}{}$\2\6
 4609   \&{else}\5
 4610   ${}\{{}$\1\6
 4611   ${}\\{tmp}\K\T{0.0};{}$\6
 4612   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Impossible\ apod}\)\.{ization\ event\
 4613   occurr}\)\.{ed."},\39\\{progname});{}$\6
 4614   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Please\ check\ g}\)\.{rating\
 4615   initializatio}\)\.{n.)"},\39\\{progname});{}$\6
 4616   \4${}\}{}$\2\6
 4617   \4${}\}{}$\2\6
 4618   \&{if} (\\{phasejump})\5
 4619   ${}\{{}$\1\6
 4620   \&{if} ${}(\|z[\|j]\G\\{phasejumpposition}){}$\5
 4621   ${}\{{}$\1\6
 4622   ${}\\{phi}\K\\{phasejumpangle};{}$\6
 4623   \4${}\}{}$\2\6
 4624   \&{else}\5
 4625   ${}\{{}$\1\6
 4626   ${}\\{phi}\K\T{0.0};{}$\6
 4627   \4${}\}{}$\2\6
 4628   \4${}\}{}$\2\6
 4629   \&{if} (\\{apodize})\5
 4630   ${}\{{}$\1\6
 4631   \&{if} ${}(\\{fabs}(\\{ncrp})>\T{0.0}{}$)\C{ if nonzero chirp of $n(z)$ }\1\6
 4632   ${}\|n[\|j]\K\\{n1}+\\{n2}*\\{tmp}*\\{sin}((\\{twopi}/\\{ncrp})*\\{log}(%
 4633   \T{1.0}+\\{ncrp}*\|z[\|j]/\\{nper})+\\{phi});{}$\2\6
 4634   \&{else}\1\5
 4635   ${}\|n[\|j]\K\\{n1}+\\{n2}*\\{tmp}*\\{sin}(\\{twopi}*\|z[\|j]/\\{nper}+%
 4636   \\{phi});{}$\2\6
 4637   \&{if} ${}(\\{fabs}(\\{gcrp})>\T{0.0}{}$)\C{ if nonzero chirp of $g(z)$ }\1\6
 4638   ${}\|g[\|j]\K\\{g1}+\\{g2}*\\{tmp}*\\{sin}((\\{twopi}/\\{gcrp})*\\{log}(%
 4639   \T{1.0}+\\{gcrp}*\|z[\|j]/\\{gper})+\\{phi});{}$\2\6
 4640   \&{else}\1\5
 4641   ${}\|g[\|j]\K\\{g1}+\\{g2}*\\{tmp}*\\{sin}(\\{twopi}*\|z[\|j]/\\{gper}+%
 4642   \\{phi});{}$\2\6
 4643   \4${}\}{}$\2\6
 4644   \&{else}\5
 4645   ${}\{{}$\1\6
 4646   \&{if} ${}(\\{fabs}(\\{ncrp})>\T{0.0}{}$)\C{ if nonzero chirp of $n(z)$ }\1\6
 4647   ${}\|n[\|j]\K\\{n1}+\\{n2}*\\{sin}((\\{twopi}/\\{ncrp})*\\{log}(\T{1.0}+%
 4648   \\{ncrp}*\|z[\|j]/\\{nper})+\\{phi});{}$\2\6
 4649   \&{else}\1\5
 4650   ${}\|n[\|j]\K\\{n1}+\\{n2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{nper}+\\{phi});{}$\2\6
 4651   \&{if} ${}(\\{fabs}(\\{gcrp})>\T{0.0}{}$)\C{ if nonzero chirp of $g(z)$ }\1\6
 4652   ${}\|g[\|j]\K\\{g1}+\\{g2}*\\{sin}((\\{twopi}/\\{gcrp})*\\{log}(\T{1.0}+%
 4653   \\{gcrp}*\|z[\|j]/\\{gper})+\\{phi});{}$\2\6
 4654   \&{else}\1\5
 4655   ${}\|g[\|j]\K\\{g1}+\\{g2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{gper}+\\{phi});{}$\2\6
 4656   \4${}\}{}$\2\6
 4657   \&{if} ${}(\\{fabs}(\\{pecrp})>\T{0.0}{}$)\C{ if nonzero chirp of $p_{\rm
 4658   e}(z)$ }\1\6
 4659   ${}\\{pe}[\|j]\K\\{pe1}+\\{pe2}*\\{sin}((\\{twopi}/\\{pecrp})*\\{log}(\T{1.0}+%
 4660   \\{pecrp}*\|z[\|j]/\\{peper}));{}$\2\6
 4661   \&{else}\1\5
 4662   ${}\\{pe}[\|j]\K\\{pe1}+\\{pe2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{peper});{}$\2\6
 4663   \&{if} ${}(\\{pmcrp}*\\{pmcrp}>\T{0.0}{}$)\C{ if nonzero chirp of $p_{\rm
 4664   m}(z)$ }\1\6
 4665   ${}\\{pm}[\|j]\K\\{pm1}+\\{pm2}*\\{sin}((\\{twopi}/\\{pmcrp})*\\{log}(\T{1.0}+%
 4666   \\{pmcrp}*\|z[\|j]/\\{pmper}));{}$\2\6
 4667   \&{else}\1\5
 4668   ${}\\{pm}[\|j]\K\\{pm1}+\\{pm2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{pmper});{}$\2\6
 4669   \&{if} ${}(\\{fabs}(\\{qecrp})>\T{0.0}{}$)\C{ if nonzero chirp of $q_{\rm
 4670   e}(z)$ }\1\6
 4671   ${}\\{qe}[\|j]\K\\{qe1}+\\{qe2}*\\{sin}((\\{twopi}/\\{qecrp})*\\{log}(\T{1.0}+%
 4672   \\{qecrp}*\|z[\|j]/\\{qeper}));{}$\2\6
 4673   \&{else}\1\5
 4674   ${}\\{qe}[\|j]\K\\{qe1}+\\{qe2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{qeper});{}$\2\6
 4675   \&{if} ${}(\\{fabs}(\\{qmcrp})>\T{0.0}{}$)\C{ if nonzero chirp of $q_{\rm
 4676   m}(z)$ }\1\6
 4677   ${}\\{qm}[\|j]\K\\{qm1}+\\{qm2}*\\{sin}((\\{twopi}/\\{qmcrp})*\\{log}(\T{1.0}+%
 4678   \\{qmcrp}*\|z[\|j]/\\{qmper}));{}$\2\6
 4679   \&{else}\1\5
 4680   ${}\\{qm}[\|j]\K\\{qm1}+\\{qm2}*\\{sin}(\\{twopi}*\|z[\|j]/\\{qmper});{}$\2\6
 4681   \4${}\}{}$\2\6
 4682   ${}\|z[\\{nn}]\K\\{ll};{}$\6
 4683   \4${}\}{}$\2\par
 4684   \U64.\fi
 4685   
 4686   \M{68}For the fractal type gratings, the grating structure is composed of a
 4687   self-similar structure with certain scaling properties.
 4688   Currently only the Cantor-type fractal is possible to apply to the grating
 4689   structure.
 4690   
 4691   The initialization of the Cantor-type grating is performed by one single call
 4692   to \PB{\\{init\_cantor\_fractal\_grating}(\,)}, which intiates the positions
 4693   $z_k$ at
 4694   which the interfaces between media of different properties are located.
 4695   The \PB{\\{init\_cantor\_fractal\_grating}(\,)} routine then makes recursive
 4696   calls to
 4697   itself, until the bottom level of the fractal initialization is reached.
 4698   After this, the material parameters of these regions are set sequentially
 4699   in the same way as for binary type gratings.
 4700   
 4701   In the initialization of the Cantor-type fractal grating, the program uses
 4702   the vector \PB{\|z[\T{1..}\|N]} with upper bound determined by the `level' $p$
 4703   of the
 4704   fractal as $N=2^p$. The value of $N$ is calculated and set immediately after
 4705   the program has parsed the level from the command line options, and hence
 4706   any additional specifications of $N$ are superfluous, as this is set by the
 4707   fractal level.
 4708   If the number of elements in \PB{\|z} is {\sl not} an integer power of two,
 4709   then
 4710   the call to \PB{\\{init\_cantor\_fractal\_grating}(\,)} will fail, leaving the
 4711   error
 4712   message of this routine on exit.
 4713   This will happen if, for example, a command line option specifying $N$ appears
 4714   after the specification of the fractal type grating, if the specified value
 4715   for $N$ does not conform with the convention that $N=2^p$.
 4716   
 4717   \Y\B\4\X68:Initiate fractal grating structure\X${}\E{}$\6
 4718   ${}\{{}$\1\6
 4719   ${}\\{tmp}\K\T{1.0};{}$\6
 4720   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{fractal\_level}-\T{1};{}$ ${}\|j\PP){}$\1%
 4721   \5
 4722   ${}\\{tmp}\K\T{2.0}*\\{tmp};{}$\2\6
 4723   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{maximum\_fractal\_level}-\\{fractal%
 4724   \_level};{}$ ${}\|j\PP){}$\1\5
 4725   ${}\\{tmp}\K\T{3.0}*\\{tmp}{}$;\C{ leaves $\PB{\\{tmp}}=2^(p-1)3^(p_{\rm
 4726   max}-p)$ }\2\6
 4727   ${}\\{ll}\K\\{tmp}*\\{t1}-\\{tmp}*\\{t2};{}$\6
 4728   ${}\\{tmp}\K\T{1.0};{}$\6
 4729   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{maximum\_fractal\_level}-\T{1};{}$ ${}\|j%
 4730   \PP){}$\1\5
 4731   ${}\\{tmp}\K\T{3.0}*\\{tmp};{}$\2\6
 4732   ${}\\{ll}\K\\{ll}+\\{tmp}*\\{t2};{}$\6
 4733   \&{if} (\\{verbose})\5
 4734   ${}\{{}$\1\6
 4735   ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Minimum\ layer\ t}\)\.{hickness\ at\
 4736   maximum\ }\)\.{recursion\ depth:\\n"},\39\\{progname});{}$\6
 4737   ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ \ \ \ \ t2=\%f\ [nm]\\}\)\.{n"},\39%
 4738   \\{progname},\39\\{t1}*\T{1.0\_9});{}$\6
 4739   ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ \ \ \ \ t2=\%f\ [nm]\\}\)\.{n"},\39%
 4740   \\{progname},\39\\{t2}*\T{1.0\_9});{}$\6
 4741   ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Fractal\ grating}\)\.{\ length\
 4742   calculated\ a}\)\.{s\ L=\%e\ [m]\\n"},\39\\{progname},\39\\{ll});{}$\6
 4743   ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Based\ on\ fracta}\)\.{l\ recursion\ of\
 4744   \%d\ ou}\)\.{t\ of\ a\ maximum\ of\ \%d}\)\.{\ levels.\\n"},\39\\{progname},\39%
 4745   \\{fractal\_level},\39\\{maximum\_fractal\_level});{}$\6
 4746   \4${}\}{}$\2\6
 4747   ${}\\{init\_cantor\_fractal\_grating}(\|z,\39\T{1},\39\\{nn},\39\T{0.0},\39%
 4748   \\{ll},\39\\{n1},\39\\{n2});{}$\6
 4749   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 4750   ${}\{{}$\1\6
 4751   ${}\\{dz}[\|j]\K\|z[\|j+\T{1}]-\|z[\|j];{}$\6
 4752   \&{if} ${}(\|j\E\T{1}){}$\5
 4753   ${}\{{}$\1\6
 4754   ${}\\{odd\_layer}\K\T{1};{}$\6
 4755   \4${}\}{}$\2\6
 4756   \&{else}\5
 4757   ${}\{{}$\1\6
 4758   ${}\\{odd\_layer}\K(\\{odd\_layer}\?\T{0}:\T{1});{}$\6
 4759   \4${}\}{}$\2\6
 4760   ${}\|n[\|j]\K(\\{odd\_layer}\?\\{n1}:\\{n2});{}$\6
 4761   ${}\|g[\|j]\K(\\{odd\_layer}\?\\{g1}:\\{g2});{}$\6
 4762   ${}\\{pe}[\|j]\K(\\{odd\_layer}\?\\{pe1}:\\{pe2});{}$\6
 4763   ${}\\{pm}[\|j]\K(\\{odd\_layer}\?\\{pm1}:\\{pm2});{}$\6
 4764   ${}\\{qe}[\|j]\K(\\{odd\_layer}\?\\{qe1}:\\{qe2});{}$\6
 4765   ${}\\{qm}[\|j]\K(\\{odd\_layer}\?\\{qm1}:\\{qm2});{}$\6
 4766   \4${}\}{}$\2\6
 4767   \4${}\}{}$\2\par
 4768   \U64.\fi
 4769   
 4770   \M{69}Adding any present perturbation of gyration constant.
 4771   If the user via the command line has specified that a perturbation of the
 4772   gyration constant should be added to the present spatial distribution,
 4773   then \PB{\\{perturbed\_gyration\_constant}} will be set to unity (true), and a
 4774   perturbation of the profile corresponding to the magnetic field strength
 4775   of a current carrying wire, orthogonal to the direction of propagation of
 4776   light, will be added.
 4777   The added perturbation $\Delta g(z)$ will be a ``bump'' of the Lorentzian
 4778   spatial shape
 4779   $$
 4780   \Delta g(z)={{a_{\rm p}}\over{1+4(z-z_{\rm p})^2/w^2_{\rm p}}},
 4781   $$
 4782   where $z_{\rm p}$ is the position, $a_{\rm p}$ is the zero-to-peak amplitude,
 4783   and $w_{\rm p}$ the full width half maximum of the perturbation.
 4784   This form of perturbation applied to chirped sinusoidal magneto-optical Bragg
 4785   gratings has in a linear optical regime been analyzed for spectral windowing
 4786   and filtering, in [F.~Jonsson and C.~Flytzanis, JOSAB (2005);
 4787   F.~Jonsson and C.~Flytzanis, Proc. MRS Fall meeting (2005)].
 4788   
 4789   
 4790   \Y\B\4\X69:Add perturbation of gyration constant along grating structure\X${}%
 4791   \E{}$\6
 4792   ${}\{{}$\1\6
 4793   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 4794   ${}\{{}$\1\6
 4795   ${}\\{tmp}\K\T{2.0}*(\|z[\|j]-\\{gyroperturb\_position})/\\{gyroperturb%
 4796   \_width};{}$\6
 4797   ${}\|g[\|j]\MRL{+{\K}}\\{gyroperturb\_amplitude}/(\T{1.0}+\\{tmp}*\\{tmp});{}$\6
 4798   \4${}\}{}$\2\6
 4799   \4${}\}{}$\2\par
 4800   \U64.\fi
 4801   
 4802   \M{70}Set the refractive index of the medium surrounding the magneto-optical
 4803   Bragg grating.
 4804   The first and last elements of the double vectors \PB{$\|n[\T{0},\\{nn}]$} and %
 4805   \PB{$\|g[\T{0},\\{nn}]$}
 4806   are defined according to the convention
 4807   $$
 4808   \eqalign{
 4809   \PB{\|n[\T{0}]}&\equiv n(z^-_0),\qquad
 4810   \PB{\|n[\\{nn}]}\equiv n(z^+_N),\cr
 4811   \PB{\|g[\T{0}]}&\equiv g(z^-_0),\qquad
 4812   \PB{\|g[\\{nn}]}\equiv g(z^+_N),\cr
 4813   }
 4814   $$
 4815   and the surrounding medium is here assumed to be linear,
 4816   $$
 4817   p_{\rm e,m}(z^-_0)=p_{\rm e,m}(z^+_N)
 4818   =q_{\rm e,m}(z^-_0)=q_{\rm e,m}(z^+_N)=0,
 4819   $$
 4820   and non-gyrotropic ($g_0=g_N=0$).
 4821   
 4822   \Y\B\4\X70:Initiate surrounding medium\X${}\E{}$\6
 4823   ${}\{{}$\1\6
 4824   ${}\|n[\T{0}]\K\\{nsurr}{}$;\C{ $n(z^-_0)$ }\6
 4825   ${}\|n[\\{nn}]\K\\{nsurr}{}$;\C{ $n(z^+_N)$ }\6
 4826   ${}\|g[\T{0}]\K\T{0.0}{}$;\C{ $g(z^-_0)$ }\6
 4827   ${}\|g[\\{nn}]\K\T{0.0}{}$;\C{ $g(z^+_N)$ }\6
 4828   \4${}\}{}$\2\par
 4829   \U45.\fi
 4830   
 4831   \N{1}{71}Calculation of intra-grating layer reflectances.
 4832   Calculate the intrinsic reflectances over the layer interfaces prior to
 4833   entering the algorithm of calculation of field distributions or reflection and
 4834   transmission coefficients.
 4835   The reflectance and transmission coefficients across the layers are calculated
 4836   in terms of their linear optical and magneto-optical material parameters as
 4837   $$
 4838   \eqalign{
 4839   taup[j]&=\tau_+(z_j)
 4840   ={{2(n_{j-1}+g_{j-1})}\over{(n_{j-1}+n_j+g_{j-1}+g_j)}},\qquad
 4841   taum[j]=\tau_-(z_j)
 4842   ={{2(n_{j-1}-g_{j-1})}\over{(n_{j-1}+n_j-g_{j-1}-g_j)}},\cr
 4843   taupp[j]&=\tau'_+(z_j)
 4844   ={{2(n_j-g_j)}\over{(n_{j-1}+n_j-g_{j-1}-g_j)}},\qquad
 4845   taupm[j]=\tau'_-(z_j)
 4846   ={{2(n_j+g_j)}\over{(n_{j-1}+n_j+g_{j-1}+g_j)}},\cr
 4847   rhop[j]&=\rho_+(z_j)
 4848   ={{(n_{j-1}-n_j+g_{j-1}-g_j)}\over{(n_{j-1}+n_j+g_{j-1}+g_j)}},\qquad
 4849   rhom[j]=\rho_-(z_j)
 4850   ={{(n_{j-1}-n_j-g_{j-1}+g_j)}\over{(n_{j-1}+n_j-g_{j-1}-g_j)}},\cr
 4851   rhopp[j]&=\rho'_+(z_j)=-\rho_-(z_j),\hskip 60pt
 4852   rhopm[j]=\rho'_-(z_j)=-\rho_+(z_j),\cr
 4853   }
 4854   $$
 4855   for interface $z=z_j$, $j=1,2,\ldots,\PB{\\{nn}}$, where $n_j$ and $g_j$ are
 4856   the
 4857   respective refractive indices and gyration constants of the layers
 4858   $z_j<z<z_{j+1}$.
 4859   Outside the grating a zero gyration coefficient is assumed while the refractive
 4860   indices are specified by $n_0=n_N=\PB{\\{nsurr}}$, as given through the command
 4861   line
 4862   options.
 4863   
 4864   In these expressions, $\tau_{\pm}(z_j)$ are the layer reflectances for
 4865   forward propagating left/right circularly polarized light
 4866   (i.~e.~for light coming from the negative $z$-direction), while
 4867   $\tau'_{\pm}(z_j)$ are the layer reflectances for backward propagating
 4868   left/right circularly polarized light
 4869   (i.~e.~for light coming from the positive $z$-direction).
 4870   
 4871   These polarization selective amplitude reflectances satisfy the Stokes
 4872   relations
 4873   $$
 4874   \rho_{\pm}(z_j)=-\rho'_{\mp}(z_j),\qquad
 4875   \tau_{\pm}(z_j)\tau'_{\mp}(z_j)=1-\rho^2_{\pm}(z_j),
 4876   $$
 4877   in this particular case generalized to interfaces between magneto-optic media.
 4878   Notice the reversed order of the subscripts of the reflectances in the Stokes
 4879   relations, reflecting the nonreciprocity of the magneto-optical contributions
 4880   to the refractive index.
 4881   
 4882   \Y\B\4\X71:Calculate intragrating layer reflectances\X${}\E{}$\6
 4883   ${}\{{}$\1\6
 4884   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn};{}$ ${}\|j\PP){}$\5
 4885   ${}\{{}$\1\6
 4886   ${}\\{taup}[\|j]\K\T{2.0}*(\|n[\|j-\T{1}]+\|g[\|j-\T{1}])/(\|n[\|j-\T{1}]+\|n[%
 4887   \|j]+\|g[\|j-\T{1}]+\|g[\|j]);{}$\6
 4888   ${}\\{taum}[\|j]\K\T{2.0}*(\|n[\|j-\T{1}]-\|g[\|j-\T{1}])/(\|n[\|j-\T{1}]+\|n[%
 4889   \|j]-\|g[\|j-\T{1}]-\|g[\|j]);{}$\6
 4890   ${}\\{taupp}[\|j]\K\T{2.0}*(\|n[\|j]-\|g[\|j])/(\|n[\|j-\T{1}]+\|n[\|j]-\|g[%
 4891   \|j-\T{1}]-\|g[\|j]);{}$\6
 4892   ${}\\{taupm}[\|j]\K\T{2.0}*(\|n[\|j]+\|g[\|j])/(\|n[\|j-\T{1}]+\|n[\|j]+\|g[%
 4893   \|j-\T{1}]+\|g[\|j]);{}$\6
 4894   ${}\\{rhop}[\|j]\K(\|n[\|j-\T{1}]-\|n[\|j]+\|g[\|j-\T{1}]-\|g[\|j])/(\|n[\|j-%
 4895   \T{1}]+\|n[\|j]+\|g[\|j-\T{1}]+\|g[\|j]);{}$\6
 4896   ${}\\{rhom}[\|j]\K(\|n[\|j-\T{1}]-\|n[\|j]-\|g[\|j-\T{1}]+\|g[\|j])/(\|n[\|j-%
 4897   \T{1}]+\|n[\|j]-\|g[\|j-\T{1}]-\|g[\|j]);{}$\6
 4898   ${}\\{rhopp}[\|j]\K{-}\\{rhom}[\|j];{}$\6
 4899   ${}\\{rhopm}[\|j]\K{-}\\{rhop}[\|j];{}$\6
 4900   \4${}\}{}$\2\6
 4901   \4${}\}{}$\2\par
 4902   \U45.\fi
 4903   
 4904   \N{1}{72}Calculating the electrical field distribution inside the grating.
 4905   Having constructed all data needed for the analysis of optical wave
 4906   propagation in the grating structure, in linear as well as nonlinear,
 4907   all-optically as well as magneto-optically, we are now in position of
 4908   entering the actual electromagnetic field calculations.
 4909   The field calculation is performed for a set of vacuum wavelengths within
 4910   the spectral range specified by \PB{\\{lambdastart}} and \PB{\\{lambdastop}}.
 4911   The spectrum is sampled using equidistantly spaced wavelength increments.
 4912   
 4913   If the user instead of stating equidistantly spaced transmitted intensities
 4914   and ellipticities has specified a file where to find the trajectory of
 4915   Stokes parameters $(W_0,W_3)$ for the transmitted light, by using the
 4916   \.{--trmtraject} option, then \PB{\\{mme}} is set to be equal to the number of
 4917   points \PB{\\{mmtraject}} on this trajectory, and \PB{\\{mmi}} set to one. For
 4918   this case,
 4919   for every value of $\PB{\\{ke}}=1,2,3,\ldots,\PB{\\{mme}}$, the \PB{%
 4920   \\{trmintensity}} and
 4921   \PB{\\{trmellipticity}} variables will be set according to the data supplied
 4922   in the specified trajectory file.
 4923   
 4924   \Y\B\4\X72:Calculate incident optical field spectrum\X${}\E{}$\6
 4925   ${}\{{}$\1\6
 4926   \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\\{mm};{}$ ${}\|k\PP){}$\5
 4927   ${}\{{}$\C{ for all wavelengths in the spectrum window }\1\6
 4928   \&{if} ${}(\\{mm}>\T{1}){}$\5
 4929   ${}\{{}$\C{ if more than one sampling point in the spectrum }\1\6
 4930   ${}\\{lambda}\K\\{lambdastart}+(((\&{double})(\|k-\T{1}))/((\&{double})(\\{mm}-%
 4931   \T{1})))*(\\{lambdastop}-\\{lambdastart});{}$\6
 4932   \4${}\}{}$\2\6
 4933   \&{else}\5
 4934   ${}\{{}$\1\6
 4935   ${}\\{lambda}\K\\{lambdastart};{}$\6
 4936   \4${}\}{}$\2\6
 4937   ${}\\{omega}\K\\{twopi}*\|c/\\{lambda}{}$;\C{angular frequency of the light }\6
 4938   \&{if} (\\{trmtraject\_specified})\5
 4939   ${}\{{}$\1\6
 4940   ${}\\{mme}\K\\{mmtraject};{}$\6
 4941   ${}\\{mmi}\K\T{1};{}$\6
 4942   \4${}\}{}$\2\6
 4943   \X74:Scan transmitted optical field in ellipticity and intensity\X;\6
 4944   \4${}\}{}$\2\6
 4945   \&{if} (\\{verbose})\1\5
 4946   \X73:Display elapsed execution time\X;\2\6
 4947   \4${}\}{}$\2\par
 4948   \U45.\fi
 4949   
 4950   \M{73}Display the total execution time consumed by the simulation. This is the
 4951   last
 4952   block to be executed by the program, and employs the \PB{\\{difftime}} routine
 4953   of the
 4954   standard \CEE\ library \.{time.h}.
 4955   
 4956   \Y\B\4\X73:Display elapsed execution time\X${}\E{}$\6
 4957   ${}\{{}$\1\6
 4958   ${}\\{fprintf}(\\{stdout},\39\.{"\ ...done.\ \ \ \ \ \ \ \ \ \ }\)\.{\ \ \ \ \ %
 4959   \ \ \ \ \ \ "});{}$\6
 4960   ${}\\{now}\K\\{time}(\NULL);{}$\6
 4961   ${}\\{fprintf}(\\{stdout},\39\.{"Elapsed\ execution\ t}\)\.{ime:\ \%d\ s\\n"},%
 4962   \39{}$((\&{int}) \\{difftime}${}(\\{now},\39\\{initime})));{}$\6
 4963   \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\T{64};{}$ ${}\|k\PP){}$\1\5
 4964   ${}\\{fprintf}(\\{stdout},\39(\|k<\T{64}\?\.{"-"}:\.{"\\n"}));{}$\2\6
 4965   ${}\\{fprintf}(\\{stdout},\39\.{"Program\ execution\ c}\)\.{losed\ \%s"},\39%
 4966   \\{ctime}({\AND}\\{now}));{}$\6
 4967   \4${}\}{}$\2\par
 4968   \U72.\fi
 4969   
 4970   \M{74}For a specified range of the intensity and ellipticity of polarization
 4971   state
 4972   of the transmitted optical field, calculate the corresponding incident fields
 4973   in this inverse formulation of the electromagnetic wave propagation problem.
 4974   The range of the ellipticity $\varepsilon_{\rm T}$ of the polarization state
 4975   of the transmitted optical field is given as
 4976   $$\varepsilon_{\rm T}\in[\PB{\\{trmellipstart}},\PB{\\{trmellipstop}}],$$
 4977   where \PB{\\{trmellipstart}} and \PB{\\{trmellipstop}} are the parameters
 4978   provided at
 4979   startup of the program through the command line option
 4980   \.{--trmellipticity} $\langle\PB{\\{trmellipstart}}\rangle$
 4981   $\langle\PB{\\{trmellipstop}}\rangle$ $\langle\PB{\\{mme}}\rangle$.
 4982   Via the definition of the normalized ellipticity $\varepsilon_{\rm T}$,
 4983   the \PB{\\{trmellipstart}} and \PB{\\{trmellipstop}} parameters are bound to
 4984   $$-1\le\PB{\\{trmellipstart}}\le\PB{\\{trmellipstop}}\le 1.$$
 4985   
 4986   \Y\B\4\X74:Scan transmitted optical field in ellipticity and intensity\X${}%
 4987   \E{}$\6
 4988   ${}\{{}$\1\6
 4989   \&{for} ${}(\\{ke}\K\T{1};{}$ ${}\\{ke}\Z\\{mme};{}$ ${}\\{ke}\PP){}$\5
 4990   ${}\{{}$\1\6
 4991   \&{if} (\\{trmtraject\_specified})\5
 4992   ${}\{{}$\1\6
 4993   ${}\\{trmellipticity}\K\\{w3traj}[\\{ke}]/\\{w0traj}[\\{ke}];{}$\6
 4994   \4${}\}{}$\2\6
 4995   \&{else}\5
 4996   ${}\{{}$\1\6
 4997   \&{if} ${}(\\{mme}>\T{1}){}$\5
 4998   ${}\{{}$\1\6
 4999   ${}\\{trmellipticity}\K\\{trmellipstart}+(((\&{double})(\\{ke}-\T{1}))/((%
 5000   \&{double})(\\{mme}-\T{1})))*(\\{trmellipstop}-\\{trmellipstart});{}$\6
 5001   \4${}\}{}$\2\6
 5002   \&{else}\5
 5003   ${}\{{}$\1\6
 5004   ${}\\{trmellipticity}\K\\{trmellipstart};{}$\6
 5005   \4${}\}{}$\2\6
 5006   \4${}\}{}$\2\6
 5007   \X75:Scan transmitted optical field in intensity\X;\6
 5008   \4${}\}{}$\2\6
 5009   \4${}\}{}$\2\par
 5010   \U72.\fi
 5011   
 5012   \M{75}For a specified range of the intensity of the transmitted optical field,
 5013   calculate the corresponding incident fields in this inverse formulation of
 5014   the electromagnetic wave propagation problem.
 5015   The range of the intensity $I_{\rm T}$ of the transmitted optical field is
 5016   given as $$I_{\rm T}\in[\PB{\\{trmintenstart}},\PB{\\{trmintenstop}}],$$
 5017   where \PB{\\{trmintenstart}} and \PB{\\{trmintenstop}} are the parameters
 5018   provided at
 5019   startup of the program through the command line option
 5020   \.{--trmintensity} $\langle\PB{\\{trmintenstart}}\rangle$
 5021   $\langle\PB{\\{trmintenstop}}\rangle$ $\langle\PB{\\{mmi}}\rangle$.
 5022   
 5023   \Y\B\4\X75:Scan transmitted optical field in intensity\X${}\E{}$\6
 5024   ${}\{{}$\1\6
 5025   \&{for} ${}(\\{ki}\K\T{1};{}$ ${}\\{ki}\Z\\{mmi};{}$ ${}\\{ki}\PP){}$\5
 5026   ${}\{{}$\1\6
 5027   \&{if} (\\{trmtraject\_specified})\5
 5028   ${}\{{}$\1\6
 5029   ${}\\{trmintensity}\K(\\{epsilon0}*\|c/\T{2.0})*\\{w0traj}[\\{ke}];{}$\6
 5030   \4${}\}{}$\2\6
 5031   \&{else}\5
 5032   ${}\{{}$\1\6
 5033   \&{if} ${}(\\{mmi}>\T{1}){}$\5
 5034   ${}\{{}$\1\6
 5035   ${}\\{trmintensity}\K\\{trmintenstart}+(((\&{double})(\\{ki}-\T{1}))/((%
 5036   \&{double})(\\{mmi}-\T{1})))*(\\{trmintenstop}-\\{trmintenstart});{}$\6
 5037   \4${}\}{}$\2\6
 5038   \&{else}\5
 5039   ${}\{{}$\1\6
 5040   ${}\\{trmintensity}\K\\{trmintenstart};{}$\6
 5041   \4${}\}{}$\2\6
 5042   \4${}\}{}$\2\6
 5043   \X76:Set boundary conditions at end of grating\X;\6
 5044   \X77:Calculate optical field in last layer of the grating\X;\6
 5045   \X78:Propagate optical fields from last to first layer of the grating\X;\6
 5046   \X83:Write Stokes parameters and reflection coefficients to file\X;\6
 5047   \X84:Write intragrating field evolution to file\X;\6
 5048   \X85:Write intragrating intensity evolution to file\X;\6
 5049   \X86:Write spatial grating structure to file\X;\6
 5050   \4${}\}{}$\2\6
 5051   \4${}\}{}$\2\par
 5052   \U74.\fi
 5053   
 5054   \M{76}In this inverse formulation of the algorithm, apply the boundary
 5055   condition
 5056   that the backward propagating wave at the end of the grating is zero,
 5057   $$
 5058   E^{\rm b}_{N_{\pm}}(z_N)\equiv E^{\rm b}_{\pm}(z^+_N)=0,
 5059   $$
 5060   and that the forward propagating field is a given quantity, specified
 5061   in terms of intensity and ellipticity of the polarization state, as
 5062   $$
 5063   \eqalign{
 5064   E^{\rm f}_{N_+}(z_N)\equiv E^{\rm f}_+(z^+_N)
 5065   &=\left[(1+\varepsilon_{\rm T})I_{\rm T}/(\varepsilon_0 c)\right]^{1/2},\cr
 5066   E^{\rm f}_{N_-}(z_N)\equiv E^{\rm f}_-(z^+_N)
 5067   &=\left[(1-\varepsilon_{\rm T})I_{\rm T}/(\varepsilon_0 c)\right]^{1/2},\cr
 5068   }
 5069   $$
 5070   with values of transmitted intensity and ellipticity in the range specified
 5071   by parameters parsed from the command line options, supplied during startup
 5072   of the program.
 5073   Here the transmitted intensity $I_{\rm T}$ (in the program described by the
 5074   variable \PB{\\{trmintensity}}) is expressed in regular \SI\ units,
 5075   in ${\rm W}/{\rm m}^2$ (Watts per square meter), as
 5076   $$
 5077   I_{\rm T}=(c\varepsilon_0/2)
 5078   (\vert E^{\rm f}_+(z^+_N)\vert^2+\vert E^{\rm f}_-(z^+_N)\vert^2),
 5079   $$
 5080   and the normalized transmitted ellipticity $\varepsilon_{\rm T}$ of the
 5081   transmitted polarization state (in the program described by the
 5082   variable \PB{\\{trmellipticity}})
 5083   $$
 5084   \varepsilon_{\rm T}
 5085   ={{\vert E^{\rm f}_+(z^+_N)\vert^2-\vert E^{\rm f}_-(z^+_N)\vert^2}
 5086   \over{\vert E^{\rm f}_+(z^+_N)\vert^2+\vert E^{\rm f}_-(z^+_N)\vert^2}},
 5087   $$
 5088   is a number in the range from $-1$ to $1$, with $-1$ corresponding to right
 5089   circularly polarized (RCP), $0$ to linearly polarized, and $1$ left circularly
 5090   polarized (LCP) light.
 5091   
 5092   \Y\B\4\X76:Set boundary conditions at end of grating\X${}\E{}$\6
 5093   ${}\{{}$\1\6
 5094   ${}\\{ebp}[\\{nn}]\K\\{complex}(\T{0.0},\39\T{0.0});{}$\6
 5095   ${}\\{ebm}[\\{nn}]\K\\{complex}(\T{0.0},\39\T{0.0});{}$\6
 5096   ${}\\{efp}[\\{nn}]\K\\{complex}(\\{sqrt}((\T{1.0}+\\{trmellipticity})*%
 5097   \\{trmintensity}/(\|c*\\{epsilon0})),\39\T{0.0});{}$\6
 5098   ${}\\{efm}[\\{nn}]\K\\{complex}(\\{sqrt}((\T{1.0}-\\{trmellipticity})*%
 5099   \\{trmintensity}/(\|c*\\{epsilon0})),\39\T{0.0});{}$\6
 5100   \4${}\}{}$\2\par
 5101   \U75.\fi
 5102   
 5103   \M{77}Having applied the boundary conditions at the end of the grating,
 5104   calculate
 5105   the optical fields in the last layer, for which $j=N-1$. These fields are
 5106   taken immediately next to the last interface, at $z=z^-_N$.
 5107   
 5108   \Y\B\4\X77:Calculate optical field in last layer of the grating\X${}\E{}$\6
 5109   ${}\{{}$\1\6
 5110   ${}\\{efp}[\\{nn}-\T{1}]\K\\{cmul}(\\{crdiv}(\\{efp}[\\{nn}],\39\\{taup}[%
 5111   \\{nn}]),\39\\{crexpi}({-}\\{omega}*\|n[\\{nn}-\T{1}]*\\{dz}[\\{nn}-\T{1}]/%
 5112   \|c));{}$\6
 5113   ${}\\{efm}[\\{nn}-\T{1}]\K\\{cmul}(\\{crdiv}(\\{efm}[\\{nn}],\39\\{taum}[%
 5114   \\{nn}]),\39\\{crexpi}({-}\\{omega}*\|n[\\{nn}-\T{1}]*\\{dz}[\\{nn}-\T{1}]/%
 5115   \|c));{}$\6
 5116   ${}\\{ebp}[\\{nn}-\T{1}]\K\\{cmul}(\\{rcmul}(\\{rhom}[\\{nn}],\39\\{efm}[%
 5117   \\{nn}-\T{1}]),\39\\{crexpi}(\T{2.0}*\\{omega}*\|n[\\{nn}-\T{1}]*\\{dz}[\\{nn}-%
 5118   \T{1}]/\|c));{}$\6
 5119   ${}\\{ebm}[\\{nn}-\T{1}]\K\\{cmul}(\\{rcmul}(\\{rhop}[\\{nn}],\39\\{efp}[%
 5120   \\{nn}-\T{1}]),\39\\{crexpi}(\T{2.0}*\\{omega}*\|n[\\{nn}-\T{1}]*\\{dz}[\\{nn}-%
 5121   \T{1}]/\|c));{}$\6
 5122   \4${}\}{}$\2\par
 5123   \U75.\fi
 5124   
 5125   \M{78}Given the right and left circularly polarized components of the forward
 5126   and backward propagating optical fields in the last layer, iterate the
 5127   propagation over the whole grating structure in order to find the
 5128   corresponding input optical fields. This is done in an iterative manner
 5129   over all the layers $z_j$, starting with the last layer (for which $j=N-1$)
 5130   and ending up at the first layer (for which $j=1$), successively propagating
 5131   the optical field over one layer at the time.
 5132   
 5133   As we enter the loop in the order $j=N-1,N-2,...,1$, the forward and backward
 5134   propagating optical field components immediately to the ``left'' of $z_{j+1}$
 5135   are contained in the complex vector elements \PB{\\{efp}[\|j]}, \PB{\\{efm}[%
 5136   \|j]}, \PB{\\{ebp}[\|j]}, and
 5137   \PB{\\{ebm}[\|j]}, with
 5138   $$
 5139   \eqalign{
 5140   \PB{\\{efp}[\|j]}&=E^f_{j_+}(z^-_{j+1}),\qquad
 5141   \PB{\\{efm}[\|j]}=E^f_{j_-}(z^-_{j+1}),\qquad
 5142   \PB{\\{ebp}[\|j]}=E^b_{j_+}(z^-_{j+1}),\qquad
 5143   \PB{\\{ebm}[\|j]}=E^b_{j_-}(z^-_{j+1}),\cr
 5144   }
 5145   $$
 5146   where $z=z^-_j$ denotes the position immediately to the ``left''
 5147   of $z=z_j$. We will now propagate the fields from $z_{j+1}$ to $z_j$,
 5148   for $j=N-1,N-2,...,1$ (in that order), by first calculating the
 5149   nonlinear (optical field-dependent) propagation constants of the current
 5150   layer $z_j < z < z_{j+1}$.
 5151   
 5152   This block of code also deals with displaying information on the progress of
 5153   calculation, using the standard \ANSICEE\ time library for the calculation
 5154   of ``estimated time of arrival'' (ETA) for the finishing of execution.
 5155   
 5156   \Y\B\4\X78:Propagate optical fields from last to first layer of the grating%
 5157   \X${}\E{}$\6
 5158   ${}\{{}$\1\6
 5159   \&{for} ${}(\|j\K\\{nn}-\T{1};{}$ ${}\|j\G\T{1};{}$ ${}\|j\MM){}$\5
 5160   ${}\{{}$\1\6
 5161   \X79:Calculate nonlinear propagation constants of layer\X;\6
 5162   \X80:Propagate fields over homogeneous layer\X;\6
 5163   \X81:Propagate fields over interface to next layer\X;\6
 5164   \&{if} (\\{verbose})\5
 5165   ${}\{{}$\1\6
 5166   \X82:Display simulation status and estimated time of arrival\X;\6
 5167   \4${}\}{}$\2\6
 5168   \4${}\}{}$\2\6
 5169   \4${}\}{}$\2\par
 5170   \U75.\fi
 5171   
 5172   \M{79}Calculate the nonlinear, optical field- and polarization-dependent
 5173   contributions to the refractive index, including electric dipolar
 5174   (all-optical) as well as magetic dipolar (magneto-optical) contributions.
 5175   
 5176   Here the local variables are defined as
 5177   $$
 5178   \eqalign{
 5179   \PB{\\{aafp2}}&=\vert E^f_{j_+}(z_j)\vert^2,
 5180   \qquad\PB{\\{etafp}[\|j]}=\eta^{\rm f}_+(z_j)\cr
 5181   \PB{\\{aafm2}}&=\vert E^f_{j_-}(z_j)\vert^2,
 5182   \qquad\PB{\\{etafm}[\|j]}=\eta^{\rm f}_-(z_j)\cr
 5183   \PB{\\{aabp2}}&=\vert E^b_{j_+}(z_j)\vert^2,
 5184   \qquad\PB{\\{etabp}[\|j]}=\eta^{\rm b}_+(z_j)\cr
 5185   \PB{\\{aabm2}}&=\vert E^b_{j_-}(z_j)\vert^2,
 5186   \qquad\PB{\\{etabm}[\|j]}=\eta^{\rm b}_-(z_j)\cr
 5187   }
 5188   $$
 5189   and the optical field-dependent propagation constants $\eta^{\rm f}_{\pm}$
 5190   and $\eta^{\rm b}_{\pm}$ are given in terms of the optical fields and
 5191   material parameters of the layer $z_j<z<z_{j+1}$ as
 5192   $$
 5193   \eqalign{
 5194   etafp[j]&={{3}\over{8 n_j}}
 5195   ((pe[j]+pm[j])
 5196   (\vert E^f_{j_+}(z_j)\vert^2+2\vert E^b_{j_-}(z_j)\vert^2)
 5197   +(qe[j]+qm[j])
 5198   (\vert E^f_{j_-}(z_j)\vert^2+\vert E^b_{j_+}(z_j)\vert^2)),\cr
 5199   etafm[j]&={{3}\over{8 n_j}}
 5200   ((pe[j]-pm[j])
 5201   (\vert E^f_{j_-}(z_j)\vert^2+2\vert E^b_{j_+}(z_j)\vert^2)
 5202   +(qe[j]-qm[j])
 5203   (\vert E^f_{j_+}(z_j)\vert^2+\vert E^b_{j_-}(z_j)\vert^2)),\cr
 5204   etabp[j]&={{3}\over{8 n_j}}
 5205   ((pe[j]-pm[j])
 5206   (\vert E^b_{j_+}(z_j)\vert^2+2\vert E^f_{j_-}(z_j)\vert^2)
 5207   +(qe[j]-qm[j])
 5208   (\vert E^b_{j_-}(z_j)\vert^2+\vert E^f_{j_+}(z_j)\vert^2)),\cr
 5209   etabm[j]&={{3}\over{8 n_j}}
 5210   ((pe[j]+pm[j])
 5211   (\vert E^b_{j_-}(z_j)\vert^2+2\vert E^f_{j_+}(z_j)\vert^2)
 5212   +(qe[j]+qm[j])
 5213   (\vert E^b_{j_+}(z_j)\vert^2+\vert E^f_{j_-}(z_j)\vert^2)).\cr
 5214   }
 5215   $$
 5216   For a more strict derivation of these parameters, as governing the phase
 5217   evolution of light in homogeneous nonlinear magneto-optical Kerr-media,
 5218   see F.~Jonsson and C.~Flytzanis, {\it Phys.~Rev.~Lett.}~{\bf 82}, 1426 (1999).
 5219   
 5220   \Y\B\4\X79:Calculate nonlinear propagation constants of layer\X${}\E{}$\6
 5221   ${}\{{}$\1\6
 5222   ${}\\{aafp2}\K\\{cdabs}(\\{efp}[\|j]);{}$\6
 5223   ${}\\{aafm2}\K\\{cdabs}(\\{efm}[\|j]);{}$\6
 5224   ${}\\{aabp2}\K\\{cdabs}(\\{ebp}[\|j]);{}$\6
 5225   ${}\\{aabm2}\K\\{cdabs}(\\{ebm}[\|j]);{}$\6
 5226   ${}\\{aafp2}\MRL{*{\K}}\\{aafp2}{}$;\C{ equals $\vert E^f_{j_+}(z_j)\vert^2$ }\6
 5227   ${}\\{aafm2}\MRL{*{\K}}\\{aafm2}{}$;\C{ equals $\vert E^f_{j_-}(z_j)\vert^2$ }\6
 5228   ${}\\{aabp2}\MRL{*{\K}}\\{aabp2}{}$;\C{ equals $\vert E^b_{j_+}(z_j)\vert^2$ }\6
 5229   ${}\\{aabm2}\MRL{*{\K}}\\{aabm2}{}$;\C{ equals $\vert E^b_{j_-}(z_j)\vert^2$ }\6
 5230   ${}\\{tmp}\K\T{3.0}/(\T{8.0}*\|n[\|j]);{}$\6
 5231   ${}\\{etafp}[\|j]\K\\{tmp}*((\\{pe}[\|j]+\\{pm}[\|j])*(\\{aafp2}+\T{2.0}*%
 5232   \\{aabm2})+(\\{qe}[\|j]+\\{qm}[\|j])*(\\{aafm2}+\\{aabp2}));{}$\6
 5233   ${}\\{etafm}[\|j]\K\\{tmp}*((\\{pe}[\|j]-\\{pm}[\|j])*(\\{aafm2}+\T{2.0}*%
 5234   \\{aabp2})+(\\{qe}[\|j]-\\{qm}[\|j])*(\\{aafp2}+\\{aabm2}));{}$\6
 5235   ${}\\{etabp}[\|j]\K\\{tmp}*((\\{pe}[\|j]-\\{pm}[\|j])*(\\{aabp2}+\T{2.0}*%
 5236   \\{aafm2})+(\\{qe}[\|j]-\\{qm}[\|j])*(\\{aabm2}+\\{aafp2}));{}$\6
 5237   ${}\\{etabm}[\|j]\K\\{tmp}*((\\{pe}[\|j]+\\{pm}[\|j])*(\\{aabm2}+\T{2.0}*%
 5238   \\{aafp2})+(\\{qe}[\|j]+\\{qm}[\|j])*(\\{aabp2}+\\{aafm2}));{}$\6
 5239   \4${}\}{}$\2\par
 5240   \U78.\fi
 5241   
 5242   \M{80}Having calculated the nonlinear propagation constants of the layer, now
 5243   propagate the optical fields to the next interface in the negative
 5244   $z$-direction. This wave propagation in homogeneous slices of the medium
 5245   is performed using the analytical solution for loss-less propagation as
 5246   published in F.~Jonsson and C.~Flytzanis, Phys.~Rev.~Lett.~{\bf 82},
 5247   1426 (1999).
 5248   
 5249   After this propagation over the homogeneous slice (layer), the temporary
 5250   variables \PB{\\{tmpfp}}, \PB{\\{tmpfm}}, \PB{\\{tmpbp}}, and \PB{\\{tmpbm}}
 5251   contain the forward and
 5252   backward travelling optical fields taken at the ``beginning'' of the current,
 5253   homogeneous segment.
 5254   
 5255   \Y\B\4\X80:Propagate fields over homogeneous layer\X${}\E{}$\6
 5256   ${}\{{}$\1\6
 5257   ${}\\{tmpfp}\K\\{cmul}(\\{efp}[\|j],\39\\{crexpi}({-}\\{omega}*(\\{etafp}[\|j]+%
 5258   \|g[\|j])*\\{dz}[\|j]/\|c));{}$\6
 5259   ${}\\{tmpfm}\K\\{cmul}(\\{efm}[\|j],\39\\{crexpi}({-}\\{omega}*(\\{etafm}[\|j]-%
 5260   \|g[\|j])*\\{dz}[\|j]/\|c));{}$\6
 5261   ${}\\{tmpbp}\K\\{cmul}(\\{ebp}[\|j],\39\\{crexpi}(\\{omega}*(\\{etabp}[\|j]-%
 5262   \|g[\|j])*\\{dz}[\|j]/\|c));{}$\6
 5263   ${}\\{tmpbm}\K\\{cmul}(\\{ebm}[\|j],\39\\{crexpi}(\\{omega}*(\\{etabm}[\|j]+%
 5264   \|g[\|j])*\\{dz}[\|j]/\|c));{}$\6
 5265   \4${}\}{}$\2\par
 5266   \U78.\fi
 5267   
 5268   \M{81}Make the passage over the interface to the next layer. The infinitesimal
 5269   propagation of the waves over the interfaces between homogeneous layers is
 5270   performed by using the previously calculated reflection and transmission
 5271   coefficients, taking the linear magneto-optical effect into account as well.
 5272   
 5273   \Y\B\4\X81:Propagate fields over interface to next layer\X${}\E{}$\6
 5274   ${}\{{}$\1\6
 5275   \&{if} ${}(\|j>\T{1}){}$\5
 5276   ${}\{{}$\1\6
 5277   ${}\\{efp}[\|j-\T{1}]\K\\{crdiv}(\\{cmul}(\\{csub}(\\{tmpfp},\39\\{rcmul}(%
 5278   \\{rhopm}[\|j],\39\\{tmpbm})),\39\\{crexpi}({-}\\{omega}*\|n[\|j-\T{1}]*\\{dz}[%
 5279   \|j-\T{1}]/\|c)),\39\\{taup}[\|j]);{}$\6
 5280   ${}\\{efm}[\|j-\T{1}]\K\\{crdiv}(\\{cmul}(\\{csub}(\\{tmpfm},\39\\{rcmul}(%
 5281   \\{rhopp}[\|j],\39\\{tmpbp})),\39\\{crexpi}({-}\\{omega}*\|n[\|j-\T{1}]*\\{dz}[%
 5282   \|j-\T{1}]/\|c)),\39\\{taum}[\|j]);{}$\6
 5283   ${}\\{ebp}[\|j-\T{1}]\K\\{cadd}(\\{rcmul}(\\{taupp}[\|j],\39\\{cmul}(\\{tmpbp},%
 5284   \39\\{crexpi}(\\{omega}*\|n[\|j-\T{1}]*\\{dz}[\|j-\T{1}]/\|c))),\39\\{rcmul}(%
 5285   \\{rhom}[\|j],\39\\{cmul}(\\{efm}[\|j-\T{1}],\39\\{crexpi}(\T{2.0}*\\{omega}*%
 5286   \|n[\|j-\T{1}]*\\{dz}[\|j-\T{1}]/\|c))));{}$\6
 5287   ${}\\{ebm}[\|j-\T{1}]\K\\{cadd}(\\{rcmul}(\\{taupm}[\|j],\39\\{cmul}(\\{tmpbm},%
 5288   \39\\{crexpi}(\\{omega}*\|n[\|j-\T{1}]*\\{dz}[\|j-\T{1}]/\|c))),\39\\{rcmul}(%
 5289   \\{rhop}[\|j],\39\\{cmul}(\\{efp}[\|j-\T{1}],\39\\{crexpi}(\T{2.0}*\\{omega}*%
 5290   \|n[\|j-\T{1}]*\\{dz}[\|j-\T{1}]/\|c))));{}$\6
 5291   \4${}\}{}$\2\6
 5292   \&{else}\5
 5293   ${}\{{}$\1\6
 5294   ${}\\{efp}[\T{0}]\K\\{crdiv}(\\{csub}(\\{tmpfp},\39\\{rcmul}(\\{rhopm}[\T{1}],%
 5295   \39\\{tmpbm})),\39\\{taup}[\T{1}]);{}$\6
 5296   ${}\\{efm}[\T{0}]\K\\{crdiv}(\\{csub}(\\{tmpfm},\39\\{rcmul}(\\{rhopp}[\T{1}],%
 5297   \39\\{tmpbp})),\39\\{taum}[\T{1}]);{}$\6
 5298   ${}\\{ebp}[\T{0}]\K\\{cadd}(\\{rcmul}(\\{taupp}[\T{1}],\39\\{tmpbp}),\39%
 5299   \\{rcmul}(\\{rhom}[\T{1}],\39\\{efm}[\T{0}]));{}$\6
 5300   ${}\\{ebm}[\T{0}]\K\\{cadd}(\\{rcmul}(\\{taupm}[\T{1}],\39\\{tmpbm}),\39%
 5301   \\{rcmul}(\\{rhop}[\T{1}],\39\\{efp}[\T{0}]));{}$\6
 5302   \4${}\}{}$\2\6
 5303   \4${}\}{}$\2\par
 5304   \U78.\fi
 5305   
 5306   \M{82}Display the real-time progress in the simulation and calculate the
 5307   estimated
 5308   time of arrival for finishing of the simulation. The completeness of the
 5309   simulation is displayed for every ten percent up to successful termination of
 5310   the program at one hundred percent.
 5311   
 5312   The formula for calculation of the progress is
 5313   $$
 5314   \Big\{\matrix{{\rm progress\ in}\cr{\rm percent}\cr}\Big\}=
 5315   100\times{{(N-j-1)+(k_{\rm i}-1)(N-1)+k_{\rm e}M_{\rm i}(N-1)+(k-1)M_{\rm e}
 5316   M_{\rm i}(N-1)}\over{M M_{\rm e} M_{\rm e}(N-1)}},
 5317   $$
 5318   where
 5319   $$
 5320   \eqalign{
 5321   1\le j\le N&\qquad{\rm [Layer\ counter\ index]}\cr
 5322   1\le k\le M&\qquad{\rm [Wavelength\ counter\ index]}\cr
 5323   1\le k_{\rm i}\le M_{\rm i}&\qquad{\rm [Intensity\ counter\ index]}\cr
 5324   1\le k_{\rm e}\le M_{\rm e}&\qquad{\rm [Ellipticity\ counter\ index]}\cr
 5325   }
 5326   $$
 5327   
 5328   \Y\B\4\X82:Display simulation status and estimated time of arrival\X${}\E{}$\6
 5329   ${}\{{}$\1\6
 5330   ${}\\{modf}(\T{100.0}*((\&{float})((\\{nn}-\|j-\T{1})+(\\{ki}-\T{1})*(\\{nn}-%
 5331   \T{1})+(\\{ke}-\T{1})*\\{mmi}*(\\{nn}-\T{1})+(\|k-\T{1})*\\{mme}*\\{mmi}*(%
 5332   \\{nn}-\T{1})))/((\&{float})(\\{mm}*\\{mme}*\\{mmi}*(\\{nn}-\T{1}))),\39{\AND}%
 5333   \\{stn});{}$\6
 5334   \&{if} ${}(\\{stn}>\\{status}+\T{10}){}$\5
 5335   ${}\{{}$\1\6
 5336   ${}\\{status}\K\\{status}+\T{10};{}$\6
 5337   ${}\\{now}\K\\{time}(\NULL);{}$\6
 5338   ${}\\{eta}\K\\{initime}+((\&{int})((\T{100.0}/{}$((\&{double}) \\{status}))${}*%
 5339   \\{difftime}(\\{now},\39\\{initime})));{}$\6
 5340   ${}\\{fprintf}(\\{stdout},\39\.{"\ ...\%2d\ percent\ fin}\)\.{ished...\ \ \ "},%
 5341   \39\\{status});{}$\6
 5342   ${}\\{fprintf}(\\{stdout},\39\.{"\ ETA:\ \%s"},\39\\{ctime}({\AND}\\{eta}));{}$%
 5343   \6
 5344   \4${}\}{}$\2\6
 5345   \4${}\}{}$\2\par
 5346   \U78.\fi
 5347   
 5348   \M{83}Having calculated the input electromagnetic field from the given output
 5349   field (as in this case, using the implicit way of calculating the
 5350   transmission characteristics of a nonlinear magneto-optical Bragg grating),
 5351   now calculate the corresponding incident $(S_0,S_1,S_2,S_3)$, transmitted
 5352   $(W_0,W_1,W_2,W_3)$, and reflected $(V_0,V_1,V_2,V_3)$ Stokes parameters
 5353   of the optical fields.
 5354   Notice that in this inverse formulation of the algorithm, the transmitted
 5355   Stokes parameters are not really calculated in a strict sense, since they
 5356   follow directly from the given input to the program -- the transmitted
 5357   optical field.
 5358   
 5359   The Stokes parameters are defined as conforming to the standard definition in
 5360   J.~D.~Jackson's {\it Classical Electrodynamics} (Wiley, New York, 1975), as
 5361   $$
 5362   \eqalign{
 5363   S_0&=\vert{E^f_+(z^-_0)}\vert^2+\vert{E^f_-(z^-_0)}\vert^2,\qquad\qquad
 5364   S_1=2\re[E^{f*}_+(z^-_0)E^f_-(z^-_0)],\cr
 5365   S_3&=\vert{E^f_+(z^-_0)}\vert^2-\vert{E^f_-(z^-_0)}\vert^2,\qquad\qquad
 5366   S_2=2\im[E^{f*}_+(z^-_0)E^f_-(z^-_0)],\cr
 5367   }
 5368   $$
 5369   for the incident wave,
 5370   $$
 5371   \eqalign{
 5372   W_0&=\vert{E^f_+(z^+_N)}\vert^2+\vert{E^f_-(z^+_N)}\vert^2,\qquad\qquad
 5373   W_1=2\re[E^{f*}_+(z^+_N)E^f_-(z^+_N)],\cr
 5374   W_3&=\vert{E^f_+(z^+_N)}\vert^2-\vert{E^f_-(z^+_N)}\vert^2,\qquad\qquad
 5375   W_2=2\im[E^{f*}_+(z^+_N)E^f_-(z^+_N)],\cr
 5376   }
 5377   $$
 5378   for the transmitted wave, and finally
 5379   $$
 5380   \eqalign{
 5381   V_0&=\vert{E^b_+(z^-_0)}\vert^2+\vert{E^b_-(z^-_0)}\vert^2,\qquad\qquad
 5382   V_1=2\re[E^{b*}_+(z^-_0)E^b_-(z^-_0)],\cr
 5383   V_3&=\vert{E^b_+(z^-_0)}\vert^2-\vert{E^b_-(z^-_0)}\vert^2,\qquad\qquad
 5384   V_2=2\im[E^{b*}_+(z^-_0)E^b_-(z^-_0)],\cr
 5385   }
 5386   $$
 5387   for the reflected wave of the grating structure. These parameters fully
 5388   specify the reflection and transmission characteristics for the nonlinear
 5389   magneto-optical grating structure, in a linear as well as nonlinear optical
 5390   domain. In particular, the intensity transmission and reflection coefficients
 5391   are expressed in as $T=W_0/S_0$ and $R=V_0/S_0$, respectively.
 5392   
 5393   In this calculation, a check is being performed regarding if the simulation
 5394   is being performed for a multiple set of intensities and ellipticities of the
 5395   transmitted light; if found to be so, then the set of Stokes parameters
 5396   are calculated in order to create topological graphs as in F.~Jonsson and
 5397   C.~Flytzanis, {\it Phys.~Rev.~Lett.}~{\bf 82}, 1426 (1999), in which case only
 5398   one particular wavelength should being considered for the simulation
 5399   (otherwise we would end up with too many topological graphs to keep track of);
 5400   otherwise the complex-valued amplitude reflection and transmission
 5401   coefficients,
 5402   $$
 5403   \rho_{\pm}(\omega)=E^{\rm b}_{0_{\mp}}(z_0)/E^{\rm f}_{0_{\pm}}(z_0),
 5404   \qquad\tau_{\pm}(\omega)=E^{\rm f}_{N_{\pm}}(z_N)/E^{\rm f}_{0_{\pm}}(z_0),
 5405   $$
 5406   are calculated, in order to create graphs of the spectral reflection and
 5407   transmission properties of the magneto-optical grating for circularly
 5408   polarized fields (in which case $k>1$ is implicitly assumed).
 5409   
 5410   If Stokes parameters are generated as data ouput,
 5411   the resulting output files (named according to the suffix convention
 5412   \PB{\\{outfilename}}{\tt.s0.dat}, \PB{\\{outfilename}}{\tt.s1.dat}, $\ldots$
 5413   \PB{\\{outfilename}}{\tt.v0.dat}, $\ldots$, etc.),
 5414   can after the simulation be used for creating topological graphs.
 5415   
 5416   For instance, by mapping the contents of Stokes parameter files
 5417   \PB{\\{outfilename}}{\tt.s0.dat}, \PB{\\{outfilename}}{\tt.s3.dat},
 5418   and \PB{\\{outfilename}}{\tt.w0.dat}
 5419   (using, for example, the \MATLAB\ command \.{mesh(s0,s3./s0,w0)},
 5420   assuming that the variables \.{s0}, \.{s3}, and \.{w0} were loaded
 5421   using the \MATLAB\ commands
 5422   \.{s0=load(\PB{\\{outfilename}}.s0.dat);} \.{s3=load(\PB{%
 5423   \\{outfilename}}.s3.dat);}
 5424   \.{w0=load(\PB{\\{outfilename}}.w0.dat);}),
 5425   one gets a topological graph showing (\PB{\\{s0}},\PB{\\{s3}},\PB{\\{w0}}) as
 5426   defining a surface
 5427   showing the transmitted intensity \PB{\\{w0}} as function of the input
 5428   intensity
 5429   \PB{\\{s0}} and input ellipticity \PB{\\{s3}}.
 5430   
 5431   Similarly, two-dimensional graphs can be generated by, as an example,
 5432   instead using the \MATLAB\ command \.{contour(s3./s0,w3./w0,s0)},
 5433   to get graphs of the transmitted ellipticity \.{w3./w0} ($\PB{\\{w3}}/\PB{%
 5434   \\{w0}}$,
 5435   the ``$y$-coordinate'') as function of the input ellipticity \.{s3./s0}
 5436   ($\PB{\\{s3}}/\PB{\\{s0}}$, the ``$x$-coordinate''), for various values of the
 5437   input
 5438   intensity \.{s0} ($\PB{\\{s0}}$, the ``$z$-coordinate'').
 5439   This way of creating two-dimensional graphs from a parametric hypersurface
 5440   of Stokes-parameters might seem to be a cumbersome
 5441   way of generating a visible output; however, it actually turns out to be
 5442   a very convenient method. Once one has adopted to this somewhat topologically
 5443   directed way of thinking, any element of the Stokes vector is easily
 5444   visualized as function of any of the other variables, and one avoids the
 5445   difficulty that arise whenever the parameter of interest is a multivalued
 5446   function of the other parameters (particularly appreciated when considering,
 5447   for example, optically bistable behaviour of the structure, since one for
 5448   those cases carefully must sort out data that belong to different state
 5449   branches).
 5450   
 5451   As a default, and as a matter of convention of electrodynamics, all Stokes
 5452   parameters are given in ${\rm V}^2/{\rm m}^2$, through their definition.
 5453   For example, the incident field (which is calculated by the program in
 5454   this inverse formulation of the problem) is expressed in terms of the Stokes
 5455   parameters as
 5456   $$
 5457   \eqalign{
 5458   S_0&=\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2,\qquad
 5459   S_1=2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr
 5460   S_3&=\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2,\qquad
 5461   S_2=2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr
 5462   }
 5463   $$
 5464   However, the direct interpretation of these quantities in terms of squared
 5465   Volts per square metres is sometimes somewhat inconvenient; therefore, those
 5466   parameters can be scaled to give an interpretation of the intensity (in regular
 5467   \SI\ units measured in Watts per square metres),
 5468   as $S'_k=(\varepsilon_0 c/2)S_k$, or explicitly
 5469   $$
 5470   \eqalign{
 5471   S'_0&=(\varepsilon_0 c/2)
 5472   [\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2],\qquad
 5473   S'_1=(\varepsilon_0 c/2)
 5474   2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr
 5475   S'_3&=(\varepsilon_0 c/2)
 5476   [\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2],\qquad
 5477   S'_2=(\varepsilon_0 c/2)
 5478   2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr
 5479   }
 5480   $$
 5481   In this representation, $S'_0$ is now identical to the incident intensity
 5482   $I_{\rm in}$ [${\rm W}/{\rm m}^2$].
 5483   In order to have those scaled Stokes parameters $S'_k$ written to file,
 5484   rather than the default ones, one convenient possibility is to use the
 5485   previously added \.{--scale\_stokesparams} option, to include
 5486   \.{--scale\_stokesparams 1.327209e-3} at the command line when invoking
 5487   the program.
 5488   The numerical value of this scaling was obtained from\footnote{$\dagger$}{In
 5489   regular \SI\ units, the physical dimension of the quantity $\varepsilon_0 c/2$
 5490   is $[{\rm F}/{\rm s}]=[{\rm C}/({\rm V}\cdot{\rm s})]$,
 5491   so the physical dimension of $(\varepsilon_0 c/2)S_k$ is easily verified as
 5492   $[{\rm C}/({\rm V}\cdot{\rm s})][{\rm V}^2/{\rm m}^2]
 5493   =[{\rm C}\cdot{\rm V}/({\rm m}^2\cdot{\rm s})]
 5494   =[{\rm J}/({\rm m}^2\cdot{\rm s})]
 5495   =[{\rm W}/{\rm m}^2]$, as expected for a physical quantity describing an
 5496   energy flow per unit area.
 5497   }
 5498   $$
 5499   \eqalign{
 5500   \varepsilon_0 c/2
 5501   &=(8.854187817\ldots\times 10^{-12}\ {\rm F}/{\rm m})
 5502   \times(2.99792458\times 10^8\ {\rm m}/{\rm s})/2\cr
 5503   &\approx 1.327209\times 10^{-3}\ {\rm F}/{\rm s}.\cr
 5504   }
 5505   $$
 5506   
 5507   \Y\B\4\X83:Write Stokes parameters and reflection coefficients to file\X${}%
 5508   \E{}$\6
 5509   ${}\{{}$\C{ Scan the grating spatially for the maximum intra-grating intensity.
 5510   }\C{ This is performed with the original, unscaled Stokes parameters. }\1\6
 5511   \&{if} (\\{intensityinfo})\5
 5512   ${}\{{}$\1\6
 5513   \&{for} ${}(\|j\K\T{0};{}$ ${}\|j\Z\\{nn};{}$ ${}\|j\PP){}$\5
 5514   ${}\{{}$\1\6
 5515   ${}\\{tmp}\K(\\{epsilon0}*\|n[\|j]*\|c/\T{2})*(\\{cabs2}(\\{efp}[\|j])+%
 5516   \\{cabs2}(\\{efm}[\|j]));{}$\6
 5517   \&{if} ${}(\\{maxintens}<\\{tmp}){}$\5
 5518   ${}\{{}$\1\6
 5519   ${}\\{maxintens}\K\\{tmp};{}$\6
 5520   ${}\\{maxintens\_layer}\K\|j;{}$\6
 5521   ${}\\{maxintens\_inintens}\K(\\{epsilon0}*\\{nsurr}*\|c/\T{2})*(\\{cabs2}(%
 5522   \\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}]));{}$\6
 5523   ${}\\{maxintens\_inellip}\K(\\{cabs2}(\\{efp}[\T{0}])-\\{cabs2}(\\{efm}[%
 5524   \T{0}]))/(\\{cabs2}(\\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}]));{}$\6
 5525   ${}\\{maxintens\_trintens}\K(\\{epsilon0}*\\{nsurr}*\|c/\T{2})*(\\{cabs2}(%
 5526   \\{efp}[\\{nn}])+\\{cabs2}(\\{efm}[\\{nn}]));{}$\6
 5527   ${}\\{maxintens\_trellip}\K(\\{cabs2}(\\{efp}[\\{nn}])-\\{cabs2}(\\{efm}[%
 5528   \\{nn}]))/(\\{cabs2}(\\{efp}[\\{nn}])+\\{cabs2}(\\{efm}[\\{nn}]));{}$\6
 5529   \4${}\}{}$\2\6
 5530   \4${}\}{}$\2\6
 5531   \4${}\}{}$\2\6
 5532   \&{if} ${}((\\{mme}>\T{1})\W(\\{mmi}>\T{1})){}$\5
 5533   ${}\{{}$\C{ ``topological'' mode }\C{ Stokes parameters of input optical wave }%
 5534   \1\6
 5535   ${}\\{s0}\K\\{cabs2}(\\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}]);{}$\6
 5536   ${}\\{s1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\T{0}]),\39\\{efm}[\T{0}]).%
 5537   \|r;{}$\6
 5538   ${}\\{s2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\T{0}]),\39\\{efm}[\T{0}]).%
 5539   \|i;{}$\6
 5540   ${}\\{s3}\K\\{cabs2}(\\{efp}[\T{0}])-\\{cabs2}(\\{efm}[\T{0}]);{}$\6
 5541   \&{if} (\\{scale\_stokesparams})\5
 5542   ${}\{{}$\1\6
 5543   ${}\\{s0}\K\\{s0}*\\{stoke\_scalefactor};{}$\6
 5544   ${}\\{s1}\K\\{s1}*\\{stoke\_scalefactor};{}$\6
 5545   ${}\\{s2}\K\\{s2}*\\{stoke\_scalefactor};{}$\6
 5546   ${}\\{s3}\K\\{s3}*\\{stoke\_scalefactor};{}$\6
 5547   \4${}\}{}$\2\6
 5548   \&{if} (\\{normalize\_ellipticity})\1\5
 5549   ${}\\{s3}\K\\{s3}/\\{s0};{}$\2\6
 5550   ${}\\{fprintf}(\\{fp\_s0},\39\.{"\%16.12e\ \ "},\39\\{s0});{}$\6
 5551   ${}\\{fprintf}(\\{fp\_s1},\39\.{"\%16.12e\ \ "},\39\\{s1});{}$\6
 5552   ${}\\{fprintf}(\\{fp\_s2},\39\.{"\%16.12e\ \ "},\39\\{s2});{}$\6
 5553   ${}\\{fprintf}(\\{fp\_s3},\39\.{"\%16.12e\ \ "},\39\\{s3});{}$\6
 5554   \\{fflush}(\\{fp\_s0});\6
 5555   \\{fflush}(\\{fp\_s1});\6
 5556   \\{fflush}(\\{fp\_s2});\6
 5557   \\{fflush}(\\{fp\_s3});\C{ Stokes parameters of reflected optical wave }\6
 5558   ${}\\{v0}\K\\{cabs2}(\\{ebp}[\T{0}])+\\{cabs2}(\\{ebm}[\T{0}]);{}$\6
 5559   ${}\\{v1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{ebp}[\T{0}]),\39\\{ebm}[\T{0}]).%
 5560   \|r;{}$\6
 5561   ${}\\{v2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{ebp}[\T{0}]),\39\\{ebm}[\T{0}]).%
 5562   \|i;{}$\6
 5563   ${}\\{v3}\K\\{cabs2}(\\{ebp}[\T{0}])-\\{cabs2}(\\{ebm}[\T{0}]);{}$\6
 5564   \&{if} (\\{scale\_stokesparams})\5
 5565   ${}\{{}$\1\6
 5566   ${}\\{v0}\K\\{v0}*\\{stoke\_scalefactor};{}$\6
 5567   ${}\\{v1}\K\\{v1}*\\{stoke\_scalefactor};{}$\6
 5568   ${}\\{v2}\K\\{v2}*\\{stoke\_scalefactor};{}$\6
 5569   ${}\\{v3}\K\\{v3}*\\{stoke\_scalefactor};{}$\6
 5570   \4${}\}{}$\2\6
 5571   \&{if} (\\{normalize\_ellipticity})\1\5
 5572   ${}\\{v3}\K\\{v3}/\\{v0};{}$\2\6
 5573   ${}\\{fprintf}(\\{fp\_v0},\39\.{"\%16.12e\ \ "},\39\\{v0});{}$\6
 5574   ${}\\{fprintf}(\\{fp\_v1},\39\.{"\%16.12e\ \ "},\39\\{v1});{}$\6
 5575   ${}\\{fprintf}(\\{fp\_v2},\39\.{"\%16.12e\ \ "},\39\\{v2});{}$\6
 5576   ${}\\{fprintf}(\\{fp\_v3},\39\.{"\%16.12e\ \ "},\39\\{v3});{}$\6
 5577   \\{fflush}(\\{fp\_v0});\6
 5578   \\{fflush}(\\{fp\_v1});\6
 5579   \\{fflush}(\\{fp\_v2});\6
 5580   \\{fflush}(\\{fp\_v3});\C{ Stokes parameters of transmitted optical wave }\6
 5581   ${}\\{w0}\K\\{cabs2}(\\{efp}[\\{nn}])+\\{cabs2}(\\{efm}[\\{nn}]);{}$\6
 5582   ${}\\{w1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\\{nn}]),\39\\{efm}[\\{nn}]).%
 5583   \|r;{}$\6
 5584   ${}\\{w2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\\{nn}]),\39\\{efm}[\\{nn}]).%
 5585   \|i;{}$\6
 5586   ${}\\{w3}\K\\{cabs2}(\\{efp}[\\{nn}])-\\{cabs2}(\\{efm}[\\{nn}]);{}$\6
 5587   \&{if} (\\{scale\_stokesparams})\5
 5588   ${}\{{}$\1\6
 5589   ${}\\{w0}\K\\{w0}*\\{stoke\_scalefactor};{}$\6
 5590   ${}\\{w1}\K\\{w1}*\\{stoke\_scalefactor};{}$\6
 5591   ${}\\{w2}\K\\{w2}*\\{stoke\_scalefactor};{}$\6
 5592   ${}\\{w3}\K\\{w3}*\\{stoke\_scalefactor};{}$\6
 5593   \4${}\}{}$\2\6
 5594   \&{if} (\\{normalize\_ellipticity})\1\5
 5595   ${}\\{w3}\K\\{w3}/\\{w0};{}$\2\6
 5596   ${}\\{fprintf}(\\{fp\_w0},\39\.{"\%16.12e\ \ "},\39\\{w0});{}$\6
 5597   ${}\\{fprintf}(\\{fp\_w1},\39\.{"\%16.12e\ \ "},\39\\{w1});{}$\6
 5598   ${}\\{fprintf}(\\{fp\_w2},\39\.{"\%16.12e\ \ "},\39\\{w2});{}$\6
 5599   ${}\\{fprintf}(\\{fp\_w3},\39\.{"\%16.12e\ \ "},\39\\{w3});{}$\6
 5600   \\{fflush}(\\{fp\_w0});\6
 5601   \\{fflush}(\\{fp\_w1});\6
 5602   \\{fflush}(\\{fp\_w2});\6
 5603   \\{fflush}(\\{fp\_w3});\6
 5604   \4${}\}{}$\2\6
 5605   \&{else}\5
 5606   ${}\{{}$\C{ ``spectrum'' mode }\1\6
 5607   \&{if} (\\{stokes\_parameter\_spectrum})\5
 5608   ${}\{{}$\C{ spectrum of Stokes parameters }\C{ Stokes parameters of input
 5609   optical wave }\1\6
 5610   ${}\\{s0}\K\\{cabs2}(\\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}]);{}$\6
 5611   ${}\\{s1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\T{0}]),\39\\{efm}[\T{0}]).%
 5612   \|r;{}$\6
 5613   ${}\\{s2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\T{0}]),\39\\{efm}[\T{0}]).%
 5614   \|i;{}$\6
 5615   ${}\\{s3}\K\\{cabs2}(\\{efp}[\T{0}])-\\{cabs2}(\\{efm}[\T{0}]);{}$\6
 5616   ${}\\{fprintf}(\\{fp\_spec},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e%
 5617   \ \%16.12e}\)\.{\\n"},\39\\{lambda},\39\\{omega},\39\\{s1}/\\{s0},\39\\{s2}/%
 5618   \\{s0},\39\\{s3}/\\{s0});{}$\6
 5619   \\{fflush}(\\{fp\_spec});\C{ Stokes parameters of reflected optical wave }\6
 5620   ${}\\{v0}\K\\{cabs2}(\\{ebp}[\T{0}])+\\{cabs2}(\\{ebm}[\T{0}]);{}$\6
 5621   ${}\\{v1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{ebp}[\T{0}]),\39\\{ebm}[\T{0}]).%
 5622   \|r;{}$\6
 5623   ${}\\{v2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{ebp}[\T{0}]),\39\\{ebm}[\T{0}]).%
 5624   \|i;{}$\6
 5625   ${}\\{v3}\K\\{cabs2}(\\{ebp}[\T{0}])-\\{cabs2}(\\{ebm}[\T{0}]){}$;\C{ CODE FOR
 5626   WRITING TO BE INSERTED HERE }\C{ Stokes parameters of transmitted optical wave
 5627   }\6
 5628   ${}\\{w0}\K\\{cabs2}(\\{efp}[\\{nn}])+\\{cabs2}(\\{efm}[\\{nn}]);{}$\6
 5629   ${}\\{w1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\\{nn}]),\39\\{efm}[\\{nn}]).%
 5630   \|r;{}$\6
 5631   ${}\\{w2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\\{nn}]),\39\\{efm}[\\{nn}]).%
 5632   \|i;{}$\6
 5633   ${}\\{w3}\K\\{cabs2}(\\{efp}[\\{nn}])-\\{cabs2}(\\{efm}[\\{nn}]){}$;\C{ CODE
 5634   FOR WRITING TO BE INSERTED HERE }\6
 5635   \4${}\}{}$\2\6
 5636   \&{if} (\\{save\_dbspectra})\5
 5637   ${}\{{}$\C{ spectrum in dB }\1\6
 5638   ${}\\{tmp}\K(\\{cabs2}(\\{ebp}[\T{0}])+\\{cabs2}(\\{ebm}[\T{0}]))/(\\{cabs2}(%
 5639   \\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}]));{}$\6
 5640   ${}\\{fprintf}(\\{fp\_irspec},\39\.{"\%-10.8f\ \%-10.8f\\n"},\39\\{lambda}*%
 5641   \T{1.0\_9},\39\T{10.0}*\\{log10}(\\{tmp}));{}$\6
 5642   ${}\\{fprintf}(\\{fp\_itspec},\39\.{"\%-10.8f\ \%-10.8f\\n"},\39\\{lambda}*%
 5643   \T{1.0\_9},\39\T{10.0}*\\{log10}(\T{1.0}-\\{tmp}));{}$\6
 5644   \\{fflush}(\\{fp\_irspec});\6
 5645   \\{fflush}(\\{fp\_itspec});\6
 5646   \4${}\}{}$\2\6
 5647   \&{else}\5
 5648   ${}\{{}$\C{ linear scale between zero and unity }\1\6
 5649   ${}\\{fprintf}(\\{fp\_irspec},\39\.{"\%-10.8f\ \%-10.8f\\n"},\39\\{lambda}*%
 5650   \T{1.0\_9},\39(\\{cabs2}(\\{ebp}[\T{0}])+\\{cabs2}(\\{ebm}[\T{0}]))/(\\{cabs2}(%
 5651   \\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}])));{}$\6
 5652   ${}\\{fprintf}(\\{fp\_itspec},\39\.{"\%-10.8f\ \%-10.8f\\n"},\39\\{lambda}*%
 5653   \T{1.0\_9},\39(\\{cabs2}(\\{efp}[\\{nn}])+\\{cabs2}(\\{efm}[\\{nn}]))/(%
 5654   \\{cabs2}(\\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}])));{}$\6
 5655   \\{fflush}(\\{fp\_irspec});\6
 5656   \\{fflush}(\\{fp\_itspec});\6
 5657   \4${}\}{}$\2\6
 5658   ${}\\{fprintf}(\\{fp\_icspec},\39\.{"\%-10.8f\ \%-10.8f\\n"},\39\\{lambda}*%
 5659   \T{1.0\_9},\39(\\{cabs2}(\\{ebp}[\T{0}])+\\{cabs2}(\\{ebm}[\T{0}]))/(\\{cabs2}(%
 5660   \\{efp}[\T{0}])+\\{cabs2}(\\{efm}[\T{0}]))+(\\{cabs2}(\\{efp}[\\{nn}])+%
 5661   \\{cabs2}(\\{efm}[\\{nn}]))/(\\{cabs2}(\\{efp}[\T{0}])+\\{cabs2}(\\{efm}[%
 5662   \T{0}])));{}$\6
 5663   \\{fflush}(\\{fp\_icspec});\6
 5664   \4${}\}{}$\2\6
 5665   \&{if} ${}(\\{ki}\G\\{mmi}){}$\5
 5666   ${}\{{}$\C{ Write linefeed at and of each scan of intensity }\1\6
 5667   \&{if} ${}((\\{mme}>\T{1})\W(\\{mmi}>\T{1})){}$\5
 5668   ${}\{{}$\1\6
 5669   ${}\\{fprintf}(\\{fp\_s0},\39\.{"\\n"});{}$\6
 5670   ${}\\{fprintf}(\\{fp\_s1},\39\.{"\\n"});{}$\6
 5671   ${}\\{fprintf}(\\{fp\_s2},\39\.{"\\n"});{}$\6
 5672   ${}\\{fprintf}(\\{fp\_s3},\39\.{"\\n"});{}$\6
 5673   ${}\\{fprintf}(\\{fp\_v0},\39\.{"\\n"});{}$\6
 5674   ${}\\{fprintf}(\\{fp\_v1},\39\.{"\\n"});{}$\6
 5675   ${}\\{fprintf}(\\{fp\_v2},\39\.{"\\n"});{}$\6
 5676   ${}\\{fprintf}(\\{fp\_v3},\39\.{"\\n"});{}$\6
 5677   ${}\\{fprintf}(\\{fp\_w0},\39\.{"\\n"});{}$\6
 5678   ${}\\{fprintf}(\\{fp\_w1},\39\.{"\\n"});{}$\6
 5679   ${}\\{fprintf}(\\{fp\_w2},\39\.{"\\n"});{}$\6
 5680   ${}\\{fprintf}(\\{fp\_w3},\39\.{"\\n"});{}$\6
 5681   \4${}\}{}$\2\6
 5682   \4${}\}{}$\2\6
 5683   \4${}\}{}$\2\par
 5684   \U75.\fi
 5685   
 5686   \M{84}Check if the user has specified a filename for saving the electromagnetic
 5687   field as it propagates through the grating structure, with \PB{\\{nne}} being
 5688   the
 5689   number of discrete sampling points within each homogeneous layer.
 5690   (This is quite useful since we otherwise just would get samples of the
 5691   intra grating electromagnetic field at the boundaries of the homogeneous
 5692   layers of the model; for twolevel grating types with comparatively thick
 5693   layers this would otherwise, for example, cause unwanted discrete jumps
 5694   in the plots of the polarization state evolution in the grating structure.)
 5695   If so, write the full information of the electromagnetic field to file, to
 5696   be used for later graphs (not necessarily just in terms of Stokes parameters).
 5697   
 5698   \Y\B\4\X84:Write intragrating field evolution to file\X${}\E{}$\6
 5699   ${}\{{}$\1\6
 5700   \&{if} (\\{fieldevoflag})\5
 5701   ${}\{{}$\1\6
 5702   \&{if} (\\{fieldevoflag\_efield})\5
 5703   ${}\{{}$\1\6
 5704   \&{if} (\\{verbose})\1\5
 5705   ${}\\{fprintf}(\\{stdout},\39\.{"Writing\ spatial\ fie}\)\.{ld\ evolution\ to\
 5706   file}\)\.{.\\n"});{}$\2\6
 5707   \&{if} ${}(\\{fp\_evo}\I\NULL){}$\5
 5708   ${}\{{}$\1\6
 5709   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 5710   ${}\{{}$\1\6
 5711   \&{for} ${}(\\{jje}\K\T{1};{}$ ${}\\{jje}\Z\\{nne};{}$ ${}\\{jje}\PP){}$\5
 5712   ${}\{{}$\1\6
 5713   \&{if} ${}(\\{nne}>\T{1}){}$\5
 5714   ${}\{{}$\1\6
 5715   ${}\\{zt}\K\|z[\|j]+((\&{double})(\\{jje}-\T{1}))*\\{dz}[\|j]/((\&{double})(%
 5716   \\{nne}));{}$\6
 5717   \4${}\}{}$\2\6
 5718   \&{else}\5
 5719   ${}\{{}$\1\6
 5720   ${}\\{zt}\K\|z[\|j];{}$\6
 5721   \4${}\}{}$\2\6
 5722   ${}\\{tmpfp}\K\\{cmul}(\\{efp}[\|j],\39\\{crexpi}(\\{omega}*(\\{etafp}[\|j]+%
 5723   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5724   ${}\\{tmpfm}\K\\{cmul}(\\{efm}[\|j],\39\\{crexpi}(\\{omega}*(\\{etafm}[\|j]-%
 5725   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5726   ${}\\{tmpbp}\K\\{cmul}(\\{ebp}[\|j],\39\\{crexpi}({-}\\{omega}*(\\{etabp}[\|j]-%
 5727   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5728   ${}\\{tmpbm}\K\\{cmul}(\\{ebm}[\|j],\39\\{crexpi}({-}\\{omega}*(\\{etabm}[\|j]+%
 5729   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5730   \&{if} (\\{normalize\_length\_to\_micrometer})\5
 5731   ${}\{{}$\1\6
 5732   ${}\\{fprintf}(\\{fp\_evo},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ %
 5733   \%16.12e"}\.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\ \%16.12e"}\.{"\ \%16.12e%
 5734   \\n"},\39\\{zt}*\T{1.0\_6},\39\\{tmpfp}.\|r,\39\\{tmpfp}.\|i,\39\\{tmpfm}.\|r,%
 5735   \39\\{tmpfm}.\|i,\39\\{tmpbp}.\|r,\39\\{tmpbp}.\|i,\39\\{tmpbm}.\|r,\39%
 5736   \\{tmpbm}.\|i);{}$\6
 5737   \4${}\}{}$\2\6
 5738   \&{else}\5
 5739   ${}\{{}$\1\6
 5740   ${}\\{fprintf}(\\{fp\_evo},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ %
 5741   \%16.12e"}\.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\ \%16.12e"}\.{"\ \%16.12e%
 5742   \\n"},\39\\{zt},\39\\{tmpfp}.\|r,\39\\{tmpfp}.\|i,\39\\{tmpfm}.\|r,\39%
 5743   \\{tmpfm}.\|i,\39\\{tmpbp}.\|r,\39\\{tmpbp}.\|i,\39\\{tmpbm}.\|r,\39\\{tmpbm}.%
 5744   \|i);{}$\6
 5745   \4${}\}{}$\2\6
 5746   \4${}\}{}$\2\6
 5747   \4${}\}{}$\2\6
 5748   \&{if} (\\{normalize\_length\_to\_micrometer})\5
 5749   ${}\{{}$\1\6
 5750   ${}\\{fprintf}(\\{fp\_evo},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e\
 5751   \%16.12e}\)\.{"}\.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\ \%16.12e\\n"},\39\|z[%
 5752   \\{nn}]*\T{1.0\_6},\39\\{efp}[\\{nn}].\|r,\39\\{efp}[\\{nn}].\|i,\39\\{efm}[%
 5753   \\{nn}].\|r,\39\\{efm}[\\{nn}].\|i,\39\\{ebp}[\\{nn}].\|r,\39\\{ebp}[\\{nn}].%
 5754   \|i,\39\\{ebm}[\\{nn}].\|r,\39\\{ebm}[\\{nn}].\|i);{}$\6
 5755   \4${}\}{}$\2\6
 5756   \&{else}\5
 5757   ${}\{{}$\1\6
 5758   ${}\\{fprintf}(\\{fp\_evo},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e\
 5759   \%16.12e}\)\.{"}\.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\ \%16.12e\\n"},\39\|z[%
 5760   \\{nn}],\39\\{efp}[\\{nn}].\|r,\39\\{efp}[\\{nn}].\|i,\39\\{efm}[\\{nn}].\|r,%
 5761   \39\\{efm}[\\{nn}].\|i,\39\\{ebp}[\\{nn}].\|r,\39\\{ebp}[\\{nn}].\|i,\39%
 5762   \\{ebm}[\\{nn}].\|r,\39\\{ebm}[\\{nn}].\|i);{}$\6
 5763   \4${}\}{}$\2\6
 5764   \4${}\}{}$\2\6
 5765   \&{else}\5
 5766   ${}\{{}$\1\6
 5767   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Could\ not\ write}\)\.{\ to\ file\ \%s!%
 5768   \\n"},\39\\{progname},\39\\{fieldevofilename});{}$\6
 5769   \\{exit}(\.{FAILURE});\6
 5770   \4${}\}{}$\2\6
 5771   \4${}\}{}$\2\6
 5772   \&{else} \&{if} (\\{fieldevoflag\_stoke})\5
 5773   ${}\{{}$\1\6
 5774   \&{if} (\\{verbose})\1\5
 5775   ${}\\{fprintf}(\\{stdout},\39\.{"Writing\ spatial\ evo}\)\.{lution\ of\ Stokes\
 5776   par}\)\.{ameters\ to\ file.\\n"});{}$\2\6
 5777   \&{if} ${}((\\{fp\_evo\_s0}\I\NULL)\W(\\{fp\_evo\_s1}\I\NULL)\W(\\{fp\_evo\_s2}%
 5778   \I\NULL)\W(\\{fp\_evo\_s3}\I\NULL)){}$\5
 5779   ${}\{{}$\1\6
 5780   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 5781   ${}\{{}$\1\6
 5782   \&{for} ${}(\\{jje}\K\T{1};{}$ ${}\\{jje}\Z\\{nne};{}$ ${}\\{jje}\PP){}$\5
 5783   ${}\{{}$\1\6
 5784   \&{if} ${}(\\{nne}>\T{1}){}$\5
 5785   ${}\{{}$\1\6
 5786   ${}\\{zt}\K\|z[\|j]+((\&{double})(\\{jje}-\T{1}))*\\{dz}[\|j]/((\&{double})(%
 5787   \\{nne}));{}$\6
 5788   \4${}\}{}$\2\6
 5789   \&{else}\5
 5790   ${}\{{}$\1\6
 5791   ${}\\{zt}\K\|z[\|j];{}$\6
 5792   \4${}\}{}$\2\6
 5793   ${}\\{tmpfp}\K\\{cmul}(\\{efp}[\|j],\39\\{crexpi}(\\{omega}*(\\{etafp}[\|j]+%
 5794   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5795   ${}\\{tmpfm}\K\\{cmul}(\\{efm}[\|j],\39\\{crexpi}(\\{omega}*(\\{etafm}[\|j]-%
 5796   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5797   ${}\\{tmpbp}\K\\{cmul}(\\{ebp}[\|j],\39\\{crexpi}({-}\\{omega}*(\\{etabp}[\|j]-%
 5798   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5799   ${}\\{tmpbm}\K\\{cmul}(\\{ebm}[\|j],\39\\{crexpi}({-}\\{omega}*(\\{etabm}[\|j]+%
 5800   \|g[\|j])*(\\{zt}-\|z[\|j])/\|c));{}$\6
 5801   ${}\\{s0}\K\\{cabs2}(\\{tmpfp})+\\{cabs2}(\\{tmpfm});{}$\6
 5802   ${}\\{s1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{tmpfp}),\39\\{tmpfm}).\|r;{}$\6
 5803   ${}\\{s2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{tmpfp}),\39\\{tmpfm}).\|i;{}$\6
 5804   ${}\\{s3}\K\\{cabs2}(\\{tmpfp})-\\{cabs2}(\\{tmpfm});{}$\6
 5805   \&{if} (\\{normalize\_intensity})\1\5
 5806   ${}\\{s0}\K\\{s0}/(\\{cabs2}(\\{efp}[\T{1}])+\\{cabs2}(\\{efm}[\T{1}]));{}$\2\6
 5807   \&{if} (\\{normalize\_length\_to\_micrometer})\5
 5808   ${}\{{}$\1\6
 5809   ${}\\{fprintf}(\\{fp\_evo\_s0},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt}*\T{1.0%
 5810   \_6},\39\\{s0});{}$\6
 5811   ${}\\{fprintf}(\\{fp\_evo\_s1},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt}*\T{1.0%
 5812   \_6},\39\\{s1});{}$\6
 5813   ${}\\{fprintf}(\\{fp\_evo\_s2},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt}*\T{1.0%
 5814   \_6},\39\\{s2});{}$\6
 5815   ${}\\{fprintf}(\\{fp\_evo\_s3},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt}*\T{1.0%
 5816   \_6},\39\\{s3});{}$\6
 5817   \4${}\}{}$\2\6
 5818   \&{else}\5
 5819   ${}\{{}$\1\6
 5820   ${}\\{fprintf}(\\{fp\_evo\_s0},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt},\39%
 5821   \\{s0});{}$\6
 5822   ${}\\{fprintf}(\\{fp\_evo\_s1},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt},\39%
 5823   \\{s1});{}$\6
 5824   ${}\\{fprintf}(\\{fp\_evo\_s2},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt},\39%
 5825   \\{s2});{}$\6
 5826   ${}\\{fprintf}(\\{fp\_evo\_s3},\39\.{"\%16.12e\ \%16.12e\\n"},\39\\{zt},\39%
 5827   \\{s3});{}$\6
 5828   \4${}\}{}$\2\6
 5829   \4${}\}{}$\2\6
 5830   \4${}\}{}$\2\6
 5831   ${}\\{s0}\K\\{cabs2}(\\{efp}[\\{nn}])+\\{cabs2}(\\{efm}[\\{nn}]);{}$\6
 5832   ${}\\{s1}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\\{nn}]),\39\\{efm}[\\{nn}]).%
 5833   \|r;{}$\6
 5834   ${}\\{s2}\K\T{2.0}*\\{cmul}(\\{conjg}(\\{efp}[\\{nn}]),\39\\{efm}[\\{nn}]).%
 5835   \|i;{}$\6
 5836   ${}\\{s3}\K\\{cabs2}(\\{efp}[\\{nn}])-\\{cabs2}(\\{efm}[\\{nn}]);{}$\6
 5837   \&{if} (\\{normalize\_intensity})\1\5
 5838   ${}\\{s0}\K\\{s0}/(\\{cabs2}(\\{efp}[\T{1}])+\\{cabs2}(\\{efm}[\T{1}]));{}$\2\6
 5839   \&{if} (\\{normalize\_length\_to\_micrometer})\5
 5840   ${}\{{}$\1\6
 5841   ${}\\{fprintf}(\\{fp\_evo\_s0},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}]*%
 5842   \T{1.0\_6},\39\\{s0});{}$\6
 5843   ${}\\{fprintf}(\\{fp\_evo\_s1},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}]*%
 5844   \T{1.0\_6},\39\\{s1});{}$\6
 5845   ${}\\{fprintf}(\\{fp\_evo\_s2},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}]*%
 5846   \T{1.0\_6},\39\\{s2});{}$\6
 5847   ${}\\{fprintf}(\\{fp\_evo\_s3},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}]*%
 5848   \T{1.0\_6},\39\\{s3});{}$\6
 5849   \4${}\}{}$\2\6
 5850   \&{else}\5
 5851   ${}\{{}$\1\6
 5852   ${}\\{fprintf}(\\{fp\_evo\_s0},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}],%
 5853   \39\\{s0});{}$\6
 5854   ${}\\{fprintf}(\\{fp\_evo\_s1},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}],%
 5855   \39\\{s1});{}$\6
 5856   ${}\\{fprintf}(\\{fp\_evo\_s2},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}],%
 5857   \39\\{s2});{}$\6
 5858   ${}\\{fprintf}(\\{fp\_evo\_s3},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\\{nn}],%
 5859   \39\\{s3});{}$\6
 5860   \4${}\}{}$\2\6
 5861   \4${}\}{}$\2\6
 5862   \&{else}\5
 5863   ${}\{{}$\1\6
 5864   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Could\ not\ write}\)\.{\ to\ file\ \%s,\
 5865   \%s,\ \%s,}\)\.{\ or\ \%s!\\n"},\39\\{progname},\39\\{fieldevofilename\_s0},\39%
 5866   \\{fieldevofilename\_s1},\39\\{fieldevofilename\_s2},\39\\{fieldevofilename%
 5867   \_s3});{}$\6
 5868   \\{exit}(\.{FAILURE});\6
 5869   \4${}\}{}$\2\6
 5870   \4${}\}{}$\2\6
 5871   \&{else}\5
 5872   ${}\{{}$\1\6
 5873   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Unknown\ field\ e}\)\.{volution\ flag.%
 5874   \\n"}\.{"\%s:\ (This\ cannot\ ha}\)\.{ppen)\\n"},\39\\{progname},\39%
 5875   \\{progname});{}$\6
 5876   \\{exit}(\.{FAILURE});\6
 5877   \4${}\}{}$\2\6
 5878   \4${}\}{}$\2\6
 5879   \4${}\}{}$\2\par
 5880   \U75.\fi
 5881   
 5882   \M{85}Check if the user has specified a filename for saving the electromagnetic
 5883   intensity distribution inside the grating structure, with \PB{\\{nne}} being
 5884   the
 5885   number of discrete sampling points within each homogeneous layer.
 5886   
 5887   \Y\B\4\X85:Write intragrating intensity evolution to file\X${}\E{}$\6
 5888   ${}\{{}$\1\6
 5889   \&{if} (\\{intensityevoflag})\5
 5890   ${}\{{}$\1\6
 5891   \&{if} ${}(\\{fabs}(\\{ievolambda}-\\{lambda})<\\{fabs}(\\{lambdastop}-%
 5892   \\{lambdastart})/((\&{double})(\\{mm}))){}$\5
 5893   ${}\{{}$\1\6
 5894   \&{if} (\\{verbose})\1\5
 5895   ${}\\{fprintf}(\\{stdout},\39\.{"\%s:\ Saving\ intensit}\)\.{y\ evolution\ at\
 5896   lambd}\)\.{a=\%8.4e\\n"},\39\\{progname},\39\\{lambda});{}$\2\6
 5897   \&{if} ${}(\\{strcmp}(\\{intensityevofilename},\39\.{""})){}$\5
 5898   ${}\{{}$\1\6
 5899   \&{if} ${}(\\{fp\_ievo}\I\NULL){}$\5
 5900   ${}\{{}$\1\6
 5901   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 5902   ${}\{{}$\1\6
 5903   \&{if} (\\{normalize\_length\_to\_micrometer})\5
 5904   ${}\{{}$\1\6
 5905   ${}\\{fprintf}(\\{fp\_ievo},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\|j]*\T{1.0%
 5906   \_6},\39(\\{cdabs}(\\{efp}[\|j])*\\{cdabs}(\\{efp}[\|j])+\\{cdabs}(\\{efm}[%
 5907   \|j])*\\{cdabs}(\\{efm}[\|j]))/(\\{cdabs}(\\{efp}[\T{1}])*\\{cdabs}(\\{efp}[%
 5908   \T{1}])+\\{cdabs}(\\{efm}[\T{1}])*\\{cdabs}(\\{efm}[\T{1}])));{}$\6
 5909   ${}\\{fprintf}(\\{fp\_ievo},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\|j+\T{1}]*%
 5910   \T{1.0\_6},\39(\\{cdabs}(\\{efp}[\|j])*\\{cdabs}(\\{efp}[\|j])+\\{cdabs}(%
 5911   \\{efm}[\|j])*\\{cdabs}(\\{efm}[\|j]))/(\\{cdabs}(\\{efp}[\T{1}])*\\{cdabs}(%
 5912   \\{efp}[\T{1}])+\\{cdabs}(\\{efm}[\T{1}])*\\{cdabs}(\\{efm}[\T{1}])));{}$\6
 5913   \4${}\}{}$\2\6
 5914   \&{else}\5
 5915   ${}\{{}$\1\6
 5916   ${}\\{fprintf}(\\{fp\_ievo},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\|j],\39(%
 5917   \\{cdabs}(\\{efp}[\|j])*\\{cdabs}(\\{efp}[\|j])+\\{cdabs}(\\{efm}[\|j])*%
 5918   \\{cdabs}(\\{efm}[\|j]))/(\\{cdabs}(\\{efp}[\T{1}])*\\{cdabs}(\\{efp}[\T{1}])+%
 5919   \\{cdabs}(\\{efm}[\T{1}])*\\{cdabs}(\\{efm}[\T{1}])));{}$\6
 5920   ${}\\{fprintf}(\\{fp\_ievo},\39\.{"\%16.12e\ \%16.12e\\n"},\39\|z[\|j+\T{1}],%
 5921   \39(\\{cdabs}(\\{efp}[\|j])*\\{cdabs}(\\{efp}[\|j])+\\{cdabs}(\\{efm}[\|j])*%
 5922   \\{cdabs}(\\{efm}[\|j]))/(\\{cdabs}(\\{efp}[\T{1}])*\\{cdabs}(\\{efp}[\T{1}])+%
 5923   \\{cdabs}(\\{efm}[\T{1}])*\\{cdabs}(\\{efm}[\T{1}])));{}$\6
 5924   \4${}\}{}$\2\6
 5925   \4${}\}{}$\2\6
 5926   \4${}\}{}$\2\6
 5927   \&{else}\5
 5928   ${}\{{}$\1\6
 5929   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Could\ not\ write}\)\.{\ to\ file\ \%s!%
 5930   \\n"},\39\\{progname},\39\\{intensityevofilename});{}$\6
 5931   \\{exit}(\.{FAILURE});\6
 5932   \4${}\}{}$\2\6
 5933   \4${}\}{}$\2\6
 5934   \4${}\}{}$\2\6
 5935   \4${}\}{}$\2\6
 5936   \4${}\}{}$\2\par
 5937   \U75.\fi
 5938   
 5939   \M{86}Check if the user has specified a filename for saving the spatial grating
 5940   structure to. If so, save the whole grating structure to disk; this is
 5941   useful as reference in graphs of the intragrating intensity and polarization
 5942   state evolution.
 5943   
 5944   \Y\B\4\X86:Write spatial grating structure to file\X${}\E{}$\6
 5945   ${}\{{}$\1\6
 5946   \&{if} (\\{writegratingtofile})\5
 5947   ${}\{{}$\1\6
 5948   \&{if} ${}((\\{fp\_gr}\K\\{fopen}(\\{gratingfilename},\39\.{"w"}))\E\NULL){}$\5
 5949   ${}\{{}$\1\6
 5950   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Could\ not\ open\ }\)\.{file\ \%s\ for\
 5951   output!\\}\)\.{n"},\39\\{progname},\39\\{gratingfilename});{}$\6
 5952   \\{exit}(\.{FAILURE});\6
 5953   \4${}\}{}$\2\6
 5954   \&{if} (\\{normalize\_length\_to\_micrometer})\5
 5955   ${}\{{}$\C{ length $z$ in micrometer }\1\6
 5956   \&{if} (\\{display\_surrounding\_media})\5
 5957   ${}\{{}$\1\6
 5958   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5959   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39(\|z[\T{1}]-\T{0.1}*(\|z[%
 5960   \\{nn}]-\|z[\T{1}]))*\T{1.0\_6},\39\\{nsurr},\39\T{0.0},\39\T{0.0},\39\T{0.0},%
 5961   \39\T{0.0},\39\T{0.0});{}$\6
 5962   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5963   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\T{1}]*\T{1.0\_6},\39%
 5964   \\{nsurr},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0});{}$\6
 5965   \4${}\}{}$\2\6
 5966   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 5967   ${}\{{}$\1\6
 5968   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5969   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\|j]*\T{1.0\_6},\39\|n[%
 5970   \|j],\39\|g[\|j],\39\\{pe}[\|j],\39\\{pm}[\|j],\39\\{qe}[\|j],\39\\{qm}[%
 5971   \|j]);{}$\6
 5972   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5973   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\|j+\T{1}]*\T{1.0\_6},\39%
 5974   \|n[\|j],\39\|g[\|j],\39\\{pe}[\|j],\39\\{pm}[\|j],\39\\{qe}[\|j],\39\\{qm}[%
 5975   \|j]);{}$\6
 5976   \4${}\}{}$\2\6
 5977   \&{if} (\\{display\_surrounding\_media})\5
 5978   ${}\{{}$\1\6
 5979   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5980   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\\{nn}]*\T{1.0\_6},\39%
 5981   \\{nsurr},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0});{}$\6
 5982   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5983   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39(\|z[\\{nn}]+\T{0.1}*(\|z[%
 5984   \\{nn}]-\|z[\T{1}]))*\T{1.0\_6},\39\\{nsurr},\39\T{0.0},\39\T{0.0},\39\T{0.0},%
 5985   \39\T{0.0},\39\T{0.0});{}$\6
 5986   \4${}\}{}$\2\6
 5987   \4${}\}{}$\2\6
 5988   \&{else}\5
 5989   ${}\{{}$\C{ length $z$ in meter }\1\6
 5990   \&{if} (\\{display\_surrounding\_media})\5
 5991   ${}\{{}$\1\6
 5992   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5993   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\T{1}]-\T{0.1}*(\|z[%
 5994   \\{nn}]-\|z[\T{1}]),\39\\{nsurr},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0},%
 5995   \39\T{0.0});{}$\6
 5996   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 5997   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\T{1}],\39\\{nsurr},\39%
 5998   \T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0});{}$\6
 5999   \4${}\}{}$\2\6
 6000   \&{for} ${}(\|j\K\T{1};{}$ ${}\|j\Z\\{nn}-\T{1};{}$ ${}\|j\PP){}$\5
 6001   ${}\{{}$\1\6
 6002   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 6003   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\|j],\39\|n[\|j],\39\|g[%
 6004   \|j],\39\\{pe}[\|j],\39\\{pm}[\|j],\39\\{qe}[\|j],\39\\{qm}[\|j]);{}$\6
 6005   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 6006   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\|j+\T{1}],\39\|n[\|j],\39%
 6007   \|g[\|j],\39\\{pe}[\|j],\39\\{pm}[\|j],\39\\{qe}[\|j],\39\\{qm}[\|j]);{}$\6
 6008   \4${}\}{}$\2\6
 6009   \&{if} (\\{display\_surrounding\_media})\5
 6010   ${}\{{}$\1\6
 6011   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 6012   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\\{nn}],\39\\{nsurr},\39%
 6013   \T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0});{}$\6
 6014   ${}\\{fprintf}(\\{fp\_gr},\39\.{"\%16.12e\ \%16.12e\ \%16}\)\.{.12e\ \%16.12e"}%
 6015   \.{"\ \%16.12e\ \%16.12e\ \%1}\)\.{6.12e\\n"},\39\|z[\\{nn}]+\T{0.1}*(\|z[%
 6016   \\{nn}]-\|z[\T{1}]),\39\\{nsurr},\39\T{0.0},\39\T{0.0},\39\T{0.0},\39\T{0.0},%
 6017   \39\T{0.0});{}$\6
 6018   \4${}\}{}$\2\6
 6019   \4${}\}{}$\2\6
 6020   \\{fclose}(\\{fp\_gr});\6
 6021   \4${}\}{}$\2\6
 6022   \4${}\}{}$\2\par
 6023   \U75.\fi
 6024   
 6025   \M{87}Display the maximum optical intensity detected in the grating.
 6026   
 6027   \Y\B\4\X87:Print information on maximum optical intensity in grating\X${}\E{}$\6
 6028   ${}\{{}$\1\6
 6029   \&{if} (\\{intensityinfo})\5
 6030   ${}\{{}$\1\6
 6031   \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\T{64};{}$ ${}\|k\PP){}$\1\5
 6032   ${}\\{fprintf}(\\{stdout},\39(\|k<\T{64}\?\.{"-"}:\.{"\\n"}));{}$\2\6
 6033   ${}\\{fprintf}(\\{stdout},\39\.{"Summary\ of\ intra-gr}\)\.{ating\ intensities:%
 6034   \\n}\)\.{"});{}$\6
 6035   ${}\\{fprintf}(\\{stdout},\39\.{"The\ maximum\ intensi}\)\.{ty\ \%1.4e\ [W/m%
 6036   \^2]\ (\%1}\)\.{.4f\ GW/cm\^2)\ was\ det}\)\.{ected\\n"},\39\\{maxintens},\39%
 6037   \\{maxintens}*\T{1.0\_-13});{}$\6
 6038   ${}\\{fprintf}(\\{stdout},\39\.{"in\ layer\ \%ld.\ The\ m}\)\.{aximum\
 6039   intensity\ was}\)\.{\ detected\ at\ a\ trans}\)\.{mitted\\n"},\39\\{maxintens%
 6040   \_layer});{}$\6
 6041   ${}\\{fprintf}(\\{stdout},\39\.{"intensity\ of\ \%1.4e\ }\)\.{[W/m\^2]\ (\%1.4f%
 6042   \ GW/cm}\)\.{\^2),\ and\ at\ a\ transm}\)\.{itted\\n"},\39\\{maxintens%
 6043   \_trintens},\39\\{maxintens\_trintens}*\T{1.0\_-13});{}$\6
 6044   ${}\\{fprintf}(\\{stdout},\39\.{"normalized\ elliptic}\)\.{ity\ of\ S3/S0=%
 6045   \%1.4f.\ }\)\.{"},\39\\{maxintens\_trellip});{}$\6
 6046   ${}\\{fprintf}(\\{stdout},\39\.{"(where\ S3/S0=1\ for\ }\)\.{LCP,\ and\ -1\\n"}%
 6047   \.{"for\ RCP)."});{}$\6
 6048   ${}\\{fprintf}(\\{stdout},\39\.{"At\ this\ state,\ the\ }\)\.{calculated\
 6049   optical\ i}\)\.{ntensity\ incident\ to}\)\.{\ the\\n"});{}$\6
 6050   ${}\\{fprintf}(\\{stdout},\39\.{"crystal\ was\ \%1.4e\ [}\)\.{W/m\^2]\ (\%1.4f\
 6051   GW/cm\^}\)\.{2),\ or\ \%1.1f\ percent}\)\.{\\n"},\39\\{maxintens\_inintens},\39%
 6052   \\{maxintens\_inintens}*\T{1.0\_-13},\39\T{100.0}*\\{maxintens\_inintens}/%
 6053   \\{maxintens});{}$\6
 6054   ${}\\{fprintf}(\\{stdout},\39\.{"of\ the\ maximum\ intr}\)\.{a-grating\ optical%
 6055   \ in}\)\.{tensity.\\n"});{}$\6
 6056   ${}\\{fprintf}(\\{stdout},\39\.{"The\ calculated\ norm}\)\.{alized\ incident\
 6057   elli}\)\.{pticity\ was\ \%1.4f.\\n}\)\.{"},\39\\{maxintens\_inellip});{}$\6
 6058   ${}\\{fprintf}(\\{stdout},\39\.{"The\ intensity\ trans}\)\.{mission\ was\ for\
 6059   this}\)\.{\ state\ \%1.1f\ percent}\)\.{.\\n"},\39\T{100.0}*\\{maxintens%
 6060   \_trintens}/\\{maxintens\_inintens});{}$\6
 6061   \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\T{64};{}$ ${}\|k\PP){}$\1\5
 6062   ${}\\{fprintf}(\\{stdout},\39(\|k<\T{64}\?\.{"-"}:\.{"\\n"}));{}$\2\6
 6063   \&{if} (\\{saveintensityinfologfile})\5
 6064   ${}\{{}$\C{ also save log to file }\1\6
 6065   \&{if} ${}((\\{intensinfologfile}\K\\{fopen}(\\{intensinfologfilename},\39%
 6066   \.{"w"}))\E\NULL){}$\5
 6067   ${}\{{}$\1\6
 6068   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Could\ not\ open\ }\)\.{\%s\ for\
 6069   intensity\ log}\)\.{!\\n"},\39\\{progname},\39\\{intensinfologfilename});{}$\6
 6070   \\{exit}(\.{FAILURE});\6
 6071   \4${}\}{}$\2\6
 6072   \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\T{32};{}$ ${}\|k\PP){}$\1\5
 6073   ${}\\{fprintf}(\\{intensinfologfile},\39(\|k<\T{32}\?\.{"-"}:\.{"\\n"}));{}$\2\6
 6074   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"Summary\ of\ intra-gr}\)\.{ating\
 6075   intensities:\\n}\)\.{"});{}$\6
 6076   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"Maximum\ intensity\ \%}\)\.{1.4e\
 6077   [W/sq.m]\ (\%1.4f}\)\.{\ GW/sq.cm)\ was\ detec}\)\.{ted\\n"},\39\\{maxintens},%
 6078   \39\\{maxintens}*\T{1.0\_-13});{}$\6
 6079   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"in\ layer\ \%ld.\ Maxim}\)\.{um\
 6080   intensity\ was\ det}\)\.{ected\ at\ a\ transmitt}\)\.{ed\\n"},\39\\{maxintens%
 6081   \_layer});{}$\6
 6082   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"intensity\ of\ \%1.4e\ }\)%
 6083   \.{[W/sq.m]\ (\%1.4f\ GW/s}\)\.{q.cm),\ and\ at\ transm}\)\.{itted\\n"},\39%
 6084   \\{maxintens\_trintens},\39\\{maxintens\_trintens}*\T{1.0\_-13});{}$\6
 6085   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"normalized\ elliptic}\)\.{ity\ of\
 6086   S3/S0=\%1.4f.\ }\)\.{"},\39\\{maxintens\_trellip});{}$\6
 6087   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"(where\ S3/S0=1\ for\ }\)\.{LCP,\
 6088   and\ -1\\n"}\.{"for\ RCP).\ "});{}$\6
 6089   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"At\ this\ state,\ the\ }\)%
 6090   \.{calculated\ optical\ i}\)\.{ntensity\ incident\ to}\)\.{\ the\\n"});{}$\6
 6091   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"crystal\ was\ \%1.4e\ [}\)%
 6092   \.{W/sq.m]\ (\%1.4f\ GW/sq}\)\.{.cm),\ or\ \%1.1f\ perce}\)\.{nt\\n"},\39%
 6093   \\{maxintens\_inintens},\39\\{maxintens\_inintens}*\T{1.0\_-13},\39\T{100.0}*%
 6094   \\{maxintens\_inintens}/\\{maxintens});{}$\6
 6095   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"of\ the\ maximum\ intr}\)%
 6096   \.{a-grating\ optical\ in}\)\.{tensity.\\n"});{}$\6
 6097   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"The\ calculated\ norm}\)\.{alized\
 6098   incident\ elli}\)\.{pticity\ was\ \%1.4f.\\n}\)\.{"},\39\\{maxintens%
 6099   \_inellip});{}$\6
 6100   ${}\\{fprintf}(\\{intensinfologfile},\39\.{"The\ intensity\ trans}\)\.{mission\
 6101   was\ for\ this}\)\.{\ state\ \%1.1f\ percent}\)\.{.\\n"},\39\T{100.0}*%
 6102   \\{maxintens\_trintens}/\\{maxintens\_inintens});{}$\6
 6103   \\{fclose}(\\{intensinfologfile});\6
 6104   \&{for} ${}(\|k\K\T{1};{}$ ${}\|k\Z\T{32};{}$ ${}\|k\PP){}$\1\5
 6105   ${}\\{fprintf}(\\{intensinfologfile},\39(\|k<\T{32}\?\.{"-"}:\.{"\\n"}));{}$\2\6
 6106   \4${}\}{}$\2\6
 6107   \4${}\}{}$\2\6
 6108   \4${}\}{}$\2\par
 6109   \U45.\fi
 6110   
 6111   \N{1}{88}Routine for checking for numerical characters.
 6112   The \PB{\\{numeric}(\,)} routine takes one character \PB{\\{ch}} as argument,
 6113   and
 6114   returns 1 (``true'') if the character is a sign or numeric,
 6115   otherwise 0 (``false'') is returned. Notice that numerical fields
 6116   of the form ``.314159'' are not allowed or recognized here.
 6117   
 6118   \Y\B\4\X88:Routine for checking for numerical characters\X${}\E{}$\6
 6119   \&{int} \\{numeric}(\&{char} \\{ch})\1\1\2\2\6
 6120   ${}\{{}$\1\6
 6121   \&{if} ${}((\\{ch}\E\.{'0'})\V(\\{ch}\E\.{'1'})\V(\\{ch}\E\.{'2'})\V(\\{ch}\E%
 6122   \.{'3'})\V(\\{ch}\E\.{'4'})\V(\\{ch}\E\.{'5'})\V(\\{ch}\E\.{'6'})\V(\\{ch}\E%
 6123   \.{'7'})\V(\\{ch}\E\.{'8'})\V(\\{ch}\E\.{'9'})\V(\\{ch}\E\.{'+'})\V(\\{ch}\E%
 6124   \.{'-'})){}$\5
 6125   ${}\{{}$\1\6
 6126   \&{return} (\T{1});\C{ yes, this is a sign or numeric character }\6
 6127   \4${}\}{}$\2\6
 6128   \&{else}\5
 6129   ${}\{{}$\1\6
 6130   \&{return} (\T{0});\C{ no, this is not a sign or numeric character }\6
 6131   \4${}\}{}$\2\6
 6132   \4${}\}{}$\2\par
 6133   \U50.\fi
 6134   
 6135   \N{1}{89}Routine for initialization of Cantor type fractal gratings.
 6136   
 6137   \Y\B\4\X89:Routine for initialization of Cantor type fractal gratings\X${}\E{}$%
 6138   \6
 6139   \&{void} \\{init\_cantor\_fractal\_grating}(\&{double} ${}{*}\|z,\39{}$\&{int} %
 6140   \\{indxmin}${},\39{}$\&{int} \\{indxmax}${},\39{}$\&{double} \\{llmin}${},%
 6141   \39{}$\&{double} \\{llmax}${},\39{}$\&{double} \\{n1}${},\39{}$\&{double} %
 6142   \\{n2})\1\1\2\2\6
 6143   ${}\{{}$\1\6
 6144   \&{int} \\{indxmid};\6
 6145   \&{double} \\{dll};\7
 6146   \&{if} ${}(\\{indxmax}-\\{indxmin}\E\T{1}){}$\5
 6147   ${}\{{}$\1\6
 6148   ${}\|z[\\{indxmin}]\K\\{llmin};{}$\6
 6149   ${}\|z[\\{indxmax}]\K\\{llmax};{}$\6
 6150   \4${}\}{}$\2\6
 6151   \&{else} \&{if} ${}(\\{indxmax}-\\{indxmin}\G\T{3}){}$\5
 6152   ${}\{{}$\1\6
 6153   ${}\\{indxmid}\K(\\{indxmin}+\\{indxmax})/\T{2};{}$\6
 6154   ${}\\{dll}\K(\\{n2}/(\\{n1}+\T{2}*\\{n2}))*(\\{llmax}-\\{llmin});{}$\6
 6155   ${}\\{init\_cantor\_fractal\_grating}(\|z,\39\\{indxmin},\39\\{indxmid},\39%
 6156   \\{llmin},\39\\{llmin}+\\{dll},\39\\{n1},\39\\{n2});{}$\6
 6157   ${}\\{init\_cantor\_fractal\_grating}(\|z,\39\\{indxmid}+\T{1},\39\\{indxmax},%
 6158   \39\\{llmax}-\\{dll},\39\\{llmax},\39\\{n1},\39\\{n2});{}$\6
 6159   \4${}\}{}$\2\6
 6160   \&{else}\5
 6161   ${}\{{}$\1\6
 6162   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ indexe}\)\.{s\ detected\ in\
 6163   routin}\)\.{e\ \%s"},\39\\{progname},\39\.{"init\_cantor\_fractal}\)\.{%
 6164   \_grating()!\\n"});{}$\6
 6165   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Please\ verify\ t}\)\.{hat\ the\ number\
 6166   of\ di}\)\.{screte\ layers\\n"},\39\\{progname});{}$\6
 6167   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ in\ the\ grating\ }\)\.{is\ N-1,\ where\
 6168   N\ is\ a}\)\.{n\ integer"}\.{"\ power\ of\ 2.\\n"},\39\\{progname});{}$\6
 6169   \\{exit}(\.{FAILURE});\6
 6170   \4${}\}{}$\2\6
 6171   \4${}\}{}$\2\par
 6172   \U50.\fi
 6173   
 6174   \N{1}{90}Routines for removing preceding path of filenames.
 6175   In this block all routines related to removing preceding path strings go.
 6176   Not really fancy programming, and no contribution to any increase of numerical
 6177   efficiency or precision; just for the sake of keeping a tidy terminal output
 6178   of the program. The \PB{\\{strip\_away\_path}(\,)} routine is typically called
 6179   when
 6180   initializing the program name string \PB{\\{progname}} from the command line
 6181   string
 6182   \PB{\\{argv}[\T{0}]}, and is typically located in the blocks related to parsing
 6183   of the
 6184   command line options.
 6185   
 6186   \Y\B\4\X90:Routines for removing preceding path of filenames\X${}\E{}$\6
 6187   \X91:Routine for checking valid path characters\X\6
 6188   \X92:Routine for stripping away path string\X\par
 6189   \U50.\fi
 6190   
 6191   \M{91}Checking for a valid path character.
 6192   The \PB{\\{pathcharacter}} routine takes one character \PB{\\{ch}} as argument,
 6193   and returns
 6194   1 (``true'') if the character is valid character of a path string, otherwise 0
 6195   (``false'') is returned. The \PB{\\{isalnum}} requires \.{ctype.h}.
 6196   
 6197   \Y\B\4\X91:Routine for checking valid path characters\X${}\E{}$\6
 6198   \&{short} \\{pathcharacter}(\&{int} \\{ch})\1\1\2\2\6
 6199   ${}\{{}$\1\6
 6200   \&{return} ${}(\\{isalnum}(\\{ch})\V(\\{ch}\E\.{'.'})\V(\\{ch}\E\.{'/'})\V(%
 6201   \\{ch}\E\.{'\\\\'})\V(\\{ch}\E\.{'\_'})\V(\\{ch}\E\.{'-'})\V(\\{ch}\E%
 6202   \.{'+'}));{}$\6
 6203   \4${}\}{}$\2\par
 6204   \U90.\fi
 6205   
 6206   \M{92}Stripping path string from a file name.
 6207   The \PB{\\{strip\_away\_path}} routine takes a character string \PB{%
 6208   \\{filename}} as
 6209   argument, and returns a pointer to the same string but without any
 6210   preceding path segments. This routine is, for example, useful for
 6211   removing paths from program names as parsed from the command line.
 6212   
 6213   \Y\B\4\X92:Routine for stripping away path string\X${}\E{}$\6
 6214   \&{char} ${}{*}{}$\\{strip\_away\_path}(\&{char} \\{filename}[\,])\1\1\2\2\6
 6215   ${}\{{}$\1\6
 6216   \&{int} \|j${},{}$ \|k${}\K\T{0};{}$\7
 6217   \&{while} (\\{pathcharacter}(\\{filename}[\|k]))\1\5
 6218   ${}\|k\PP;{}$\2\6
 6219   ${}\|j\K(\MM\|k){}$;\C{ this is the uppermost index of the full path+file
 6220   string }\6
 6221   \&{while} (\\{isalnum}((\&{int})(\\{filename}[\|j])))\1\5
 6222   ${}\|j\MM;{}$\2\6
 6223   ${}\|j\PP{}$;\C{ this is the lowermost index of the stripped file name }\6
 6224   \&{return} ${}({\AND}\\{filename}[\|j]);{}$\6
 6225   \4${}\}{}$\2\par
 6226   \U90.\fi
 6227   
 6228   \N{1}{93}Routines for generation of random numbers. The \PB{\\{ran1}(\,)}
 6229   routine is
 6230   taken from Numerical Recipes in C, 2nd ed.~(Cambridge University Press,
 6231   New York, 1994).
 6232   
 6233   \Y\B\4\X93:Routines for generation of random numbers\X${}\E{}$\6
 6234   \8\#\&{define} \.{IA} \5\T{16807}\6
 6235   \8\#\&{define} \.{IM} \5\T{2147483647}\6
 6236   \8\#\&{define} \.{AM} \5${}(\T{1.0}/\.{IM}){}$\6
 6237   \8\#\&{define} \.{IQ} \5\T{127773}\6
 6238   \8\#\&{define} \.{IR} \5\T{2836}\6
 6239   \8\#\&{define} \.{NTAB} \5\T{32}\6
 6240   \8\#\&{define} \.{NDIV} \5${}(\T{1}+(\.{IM}-\T{1})/\.{NTAB}){}$\6
 6241   \8\#\&{define} \.{EPS} \5\T{1.2\_-7}\6
 6242   \8\#\&{define} \.{RNMX} \5${}(\T{1.0}-\.{EPS}){}$\6
 6243   \&{float} \\{ran1}(\&{long} ${}{*}\\{idum}){}$\1\1\2\2\6
 6244   ${}\{{}$\1\6
 6245   \&{int} \|j;\6
 6246   \&{long} \|k;\6
 6247   \&{static} \&{long} \\{iy}${}\K\T{0};{}$\6
 6248   \&{static} \&{long} \\{iv}[\.{NTAB}];\6
 6249   \&{float} \\{temp};\7
 6250   \&{if} ${}({*}\\{idum}\Z\T{0}\V\R\\{iy}){}$\5
 6251   ${}\{{}$\1\6
 6252   \&{if} ${}({-}({*}\\{idum})<\T{1}){}$\1\5
 6253   ${}{*}\\{idum}\K\T{1};{}$\2\6
 6254   \&{else}\1\5
 6255   ${}{*}\\{idum}\K{-}({*}\\{idum});{}$\2\6
 6256   \&{for} ${}(\|j\K\.{NTAB}+\T{7};{}$ ${}\|j\G\T{0};{}$ ${}\|j\MM){}$\5
 6257   ${}\{{}$\1\6
 6258   ${}\|k\K({*}\\{idum})/\.{IQ};{}$\6
 6259   ${}{*}\\{idum}\K\.{IA}*({*}\\{idum}-\|k*\.{IQ})-\.{IR}*\|k;{}$\6
 6260   \&{if} ${}({*}\\{idum}<\T{0}){}$\1\5
 6261   ${}{*}\\{idum}\MRL{+{\K}}\.{IM};{}$\2\6
 6262   \&{if} ${}(\|j<\.{NTAB}){}$\1\5
 6263   ${}\\{iv}[\|j]\K{*}\\{idum};{}$\2\6
 6264   \4${}\}{}$\2\6
 6265   ${}\\{iy}\K\\{iv}[\T{0}];{}$\6
 6266   \4${}\}{}$\2\6
 6267   ${}\|k\K({*}\\{idum})/\.{IQ};{}$\6
 6268   ${}{*}\\{idum}\K\.{IA}*({*}\\{idum}-\|k*\.{IQ})-\.{IR}*\|k;{}$\6
 6269   \&{if} ${}({*}\\{idum}<\T{0}){}$\1\5
 6270   ${}{*}\\{idum}\MRL{+{\K}}\.{IM};{}$\2\6
 6271   ${}\|j\K\\{iy}/\.{NDIV};{}$\6
 6272   ${}\\{iy}\K\\{iv}[\|j];{}$\6
 6273   ${}\\{iv}[\|j]\K{*}\\{idum};{}$\6
 6274   \&{if} ${}((\\{temp}\K\.{AM}*\\{iy})>\.{RNMX}){}$\1\5
 6275   \&{return} \.{RNMX};\2\6
 6276   \&{else}\1\5
 6277   \&{return} \\{temp};\2\6
 6278   \4${}\}{}$\2\6
 6279   \8\#\&{undef} \.{IA}\6
 6280   \8\#\&{undef} \.{IM}\6
 6281   \8\#\&{undef} \.{AM}\6
 6282   \8\#\&{undef} \.{IQ}\6
 6283   \8\#\&{undef} \.{IR}\6
 6284   \8\#\&{undef} \.{NTAB}\6
 6285   \8\#\&{undef} \.{NDIV}\6
 6286   \8\#\&{undef} \.{EPS}\6
 6287   \8\#\&{undef} \.{RNMX}\par
 6288   \U50.\fi
 6289   
 6290   \N{1}{94}Routines for doing complex arithmetics. By using the data structure
 6291   \PB{\&{dcomplex}}, which here is the basic construct for complex numbers,
 6292   containing real and imaginary parts in double precision, several
 6293   routines for doing arithmetics with this representation have been
 6294   implemented.
 6295   
 6296   \Y\B\4\X94:Routines for complex arithmetics\X${}\E{}$\6
 6297   \X95:Complex number\X\6
 6298   \X96:Complex conjugation\X\6
 6299   \X97:Absolute value of complex number\X\6
 6300   \X98:Squared absolute value of complex number\X\6
 6301   \X99:Complex addition\X\6
 6302   \X100:Complex subtraction\X\6
 6303   \X101:Complex multiplication\X\6
 6304   \X104:Complex division\X\6
 6305   \X107:Complex square root\X\6
 6306   \X108:Complex exponentiation\X\par
 6307   \U50.\fi
 6308   
 6309   \M{95}The function \PB{$\\{complex}(\|a,\|b)$} takes two real valued arguments %
 6310   \PB{\|a} and \PB{\|b}
 6311   as input, and returns the complex number $\PB{\|c}=\PB{\|a}+i\PB{\|b}$.
 6312   This basic construct is useful for storing temporary results, and
 6313   for internal use in routines dealing with complex arithmetics.
 6314   
 6315   \Y\B\4\X95:Complex number\X${}\E{}$\6
 6316   \&{dcomplex} \\{complex}(\&{double} \\{re}${},\39{}$\&{double} \\{im})\1\1\2\2\6
 6317   ${}\{{}$\1\6
 6318   \&{dcomplex} \|c;\7
 6319   ${}\|c.\|r\K\\{re};{}$\6
 6320   ${}\|c.\|i\K\\{im};{}$\6
 6321   \&{return} \|c;\6
 6322   \4${}\}{}$\2\par
 6323   \U94.\fi
 6324   
 6325   \M{96}The function \PB{\\{conjg}(\|z)} takes a complex valued argument \PB{\|z}
 6326   of
 6327   type \PB{\&{dcomplex}} as input, and returns the complex conjugate
 6328   $\bar{\PB{\|z}}=\re(\PB{\|z})-i\im(\PB{\|z})$.
 6329   
 6330   \Y\B\4\X96:Complex conjugation\X${}\E{}$\6
 6331   \&{dcomplex} \\{conjg}(\&{dcomplex} \|z)\1\1\2\2\6
 6332   ${}\{{}$\1\6
 6333   \&{dcomplex} \|c;\7
 6334   ${}\|c.\|r\K\|z.\|r;{}$\6
 6335   ${}\|c.\|i\K{-}\|z.\|i;{}$\6
 6336   \&{return} \|c;\6
 6337   \4${}\}{}$\2\par
 6338   \U94.\fi
 6339   
 6340   \M{97}The function \PB{\\{cdabs}(\|z)} takes a complex valued argument \PB{\|z}
 6341   as input,
 6342   and returns the absolute value
 6343   $\vert\PB{\|z}\vert=[\re(\PB{\|z})^2+\im(\PB{\|z})^2]^{1/2}$.
 6344   
 6345   \Y\B\4\X97:Absolute value of complex number\X${}\E{}$\6
 6346   \&{double} \\{cdabs}(\&{dcomplex} \|z)\1\1\2\2\6
 6347   ${}\{{}$\1\6
 6348   \&{double} \|x${},{}$ \|y${},{}$ \|c${},{}$ \\{tmp};\7
 6349   ${}\|x\K\\{fabs}(\|z.\|r);{}$\6
 6350   ${}\|y\K\\{fabs}(\|z.\|i);{}$\6
 6351   \&{if} ${}(\|x\E\T{0.0}){}$\1\5
 6352   ${}\|c\K\|y;{}$\2\6
 6353   \&{else} \&{if} ${}(\|y\E\T{0.0}){}$\1\5
 6354   ${}\|c\K\|x;{}$\2\6
 6355   \&{else} \&{if} ${}(\|x>\|y){}$\5
 6356   ${}\{{}$\1\6
 6357   ${}\\{tmp}\K\|y/\|x;{}$\6
 6358   ${}\|c\K\|x*\\{sqrt}(\T{1.0}+\\{tmp}*\\{tmp});{}$\6
 6359   \4${}\}{}$\2\6
 6360   \&{else}\5
 6361   ${}\{{}$\1\6
 6362   ${}\\{tmp}\K\|x/\|y;{}$\6
 6363   ${}\|c\K\|y*\\{sqrt}(\T{1.0}+\\{tmp}*\\{tmp});{}$\6
 6364   \4${}\}{}$\2\6
 6365   \&{return} \|c;\6
 6366   \4${}\}{}$\2\par
 6367   \U94.\fi
 6368   
 6369   \M{98}The function \PB{\\{cabs2}(\|z)} takes a complex valued argument \PB{\|z}
 6370   as input, and
 6371   returns the squared absolute value $\vert\PB{\|z}\vert^2=\re(\PB{\|z})^2+\im(%
 6372   \PB{\|z})^2$.
 6373   This function is identical to the \PB{\\{cdabs}(\|z)} function, with the
 6374   exception that
 6375   the squared result is returned.
 6376   
 6377   \Y\B\4\X98:Squared absolute value of complex number\X${}\E{}$\6
 6378   \&{double} \\{cabs2}(\&{dcomplex} \|z)\1\1\2\2\6
 6379   ${}\{{}$\1\6
 6380   \&{double} \|x${},{}$ \|y${},{}$ \|c${},{}$ \\{tmp};\7
 6381   ${}\|x\K\\{fabs}(\|z.\|r);{}$\6
 6382   ${}\|y\K\\{fabs}(\|z.\|i);{}$\6
 6383   \&{if} ${}(\|x\E\T{0.0}){}$\1\5
 6384   ${}\|c\K\|y*\|y;{}$\2\6
 6385   \&{else} \&{if} ${}(\|y\E\T{0.0}){}$\1\5
 6386   ${}\|c\K\|x*\|x;{}$\2\6
 6387   \&{else} \&{if} ${}(\|x>\|y){}$\5
 6388   ${}\{{}$\1\6
 6389   ${}\\{tmp}\K\|y/\|x;{}$\6
 6390   ${}\|c\K\|x*\|x*(\T{1.0}+\\{tmp}*\\{tmp});{}$\6
 6391   \4${}\}{}$\2\6
 6392   \&{else}\5
 6393   ${}\{{}$\1\6
 6394   ${}\\{tmp}\K\|x/\|y;{}$\6
 6395   ${}\|c\K\|y*\|y*(\T{1.0}+\\{tmp}*\\{tmp});{}$\6
 6396   \4${}\}{}$\2\6
 6397   \&{return} \|c;\6
 6398   \4${}\}{}$\2\par
 6399   \U94.\fi
 6400   
 6401   \M{99}The function \PB{$\\{cadd}(\|a,\|b)$} takes complex valued arguments \PB{%
 6402   \|a} and \PB{\|b}
 6403   as inputs, and returns the complex valued sum $\PB{\|a}+\PB{\|b}$.
 6404   
 6405   \Y\B\4\X99:Complex addition\X${}\E{}$\6
 6406   \&{dcomplex} \\{cadd}(\&{dcomplex} \|a${},\39{}$\&{dcomplex} \|b)\1\1\2\2\6
 6407   ${}\{{}$\1\6
 6408   \&{dcomplex} \|c;\7
 6409   ${}\|c.\|r\K\|a.\|r+\|b.\|r;{}$\6
 6410   ${}\|c.\|i\K\|a.\|i+\|b.\|i;{}$\6
 6411   \&{return} \|c;\6
 6412   \4${}\}{}$\2\par
 6413   \U94.\fi
 6414   
 6415   \M{100}The function \PB{$\\{csub}(\|a,\|b)$} takes complex valued arguments %
 6416   \PB{\|a} and \PB{\|b} as
 6417   inputs, and returns the complex valued difference $\PB{\|a}-\PB{\|b}$.
 6418   
 6419   \Y\B\4\X100:Complex subtraction\X${}\E{}$\6
 6420   \&{dcomplex} \\{csub}(\&{dcomplex} \|a${},\39{}$\&{dcomplex} \|b)\1\1\2\2\6
 6421   ${}\{{}$\1\6
 6422   \&{dcomplex} \|c;\7
 6423   ${}\|c.\|r\K\|a.\|r-\|b.\|r;{}$\6
 6424   ${}\|c.\|i\K\|a.\|i-\|b.\|i;{}$\6
 6425   \&{return} \|c;\6
 6426   \4${}\}{}$\2\par
 6427   \U94.\fi
 6428   
 6429   \M{101}When dealing with multiplication involving complex numbers, the case
 6430   where one of the numbers is entirely real is distinguished from the
 6431   general multiplication by two complex valued numbers, in order to speed
 6432   up the multiplication somewhat.
 6433   
 6434   \Y\B\4\X101:Complex multiplication\X${}\E{}$\6
 6435   \X102:Multiplication by two complex numbers\X\6
 6436   \X103:Multiplication by real and complex numbers\X\par
 6437   \U94.\fi
 6438   
 6439   \M{102}The function \PB{$\\{cmul}(\|a,\|b)$} takes complex valued arguments %
 6440   \PB{\|a} and \PB{\|b}
 6441   as inputs, and returns the complex valued product \PB{\\{ab}}.
 6442   
 6443   \Y\B\4\X102:Multiplication by two complex numbers\X${}\E{}$\6
 6444   \&{dcomplex} \\{cmul}(\&{dcomplex} \|a${},\39{}$\&{dcomplex} \|b)\1\1\2\2\6
 6445   ${}\{{}$\1\6
 6446   \&{dcomplex} \|c;\7
 6447   ${}\|c.\|r\K\|a.\|r*\|b.\|r-\|a.\|i*\|b.\|i;{}$\6
 6448   ${}\|c.\|i\K\|a.\|i*\|b.\|r+\|a.\|r*\|b.\|i;{}$\6
 6449   \&{return} \|c;\6
 6450   \4${}\}{}$\2\par
 6451   \U101.\fi
 6452   
 6453   \M{103}The function \PB{$\\{rcmul}(\|a,\|b)$} takes a real valued argument \PB{%
 6454   \|a} and
 6455   a complex valued arguments \PB{\|b} as inputs, and returns the
 6456   complex valued product $\PB{\\{ab}} = \PB{\|a}\re(\PB{\|b}) + i\PB{\|a}\im(\PB{%
 6457   \|b})$.
 6458   
 6459   \Y\B\4\X103:Multiplication by real and complex numbers\X${}\E{}$\6
 6460   \&{dcomplex} \\{rcmul}(\&{double} \|a${},\39{}$\&{dcomplex} \|b)\1\1\2\2\6
 6461   ${}\{{}$\1\6
 6462   \&{dcomplex} \|c;\7
 6463   ${}\|c.\|r\K\|a*\|b.\|r;{}$\6
 6464   ${}\|c.\|i\K\|a*\|b.\|i;{}$\6
 6465   \&{return} \|c;\6
 6466   \4${}\}{}$\2\par
 6467   \U101.\fi
 6468   
 6469   \M{104}When dealing with division involving complex numbers, the case
 6470   where the denominator is entirely real is distinguished from the
 6471   general division by two complex valued numbers, in order to speed
 6472   up the division somewhat.
 6473   
 6474   \Y\B\4\X104:Complex division\X${}\E{}$\6
 6475   \X105:Division by complex numbers\X\6
 6476   \X106:Division by complex and real number\X\par
 6477   \U94.\fi
 6478   
 6479   \M{105}The function \PB{$\\{cdiv}(\|a,\|b)$} takes complex valued arguments %
 6480   \PB{\|a} and \PB{\|b}
 6481   as inputs, and returns the complex valued quote $\PB{\|a}/\PB{\|b}$.
 6482   If the denominator is found to be real, this routine speed up the
 6483   division in similar to the \PB{\\{crdiv}} routine, by instead applying the
 6484   rules
 6485   of real-valued division.
 6486   
 6487   \Y\B\4\X105:Division by complex numbers\X${}\E{}$\6
 6488   \&{dcomplex} \\{cdiv}(\&{dcomplex} \|a${},\39{}$\&{dcomplex} \|b)\1\1\2\2\6
 6489   ${}\{{}$\1\6
 6490   \&{dcomplex} \|c;\6
 6491   \&{double} \|r${},{}$ \\{den};\7
 6492   \&{if} ${}(\\{cdabs}(\|b)>\T{0.0}){}$\5
 6493   ${}\{{}$\1\6
 6494   \&{if} ${}(\\{fabs}(\|b.\|i)\E\T{0.0}){}$\5
 6495   ${}\{{}$\1\6
 6496   ${}\|c.\|r\K\|a.\|r/\|b.\|r;{}$\6
 6497   ${}\|c.\|i\K\|a.\|i/\|b.\|r;{}$\6
 6498   \4${}\}{}$\2\6
 6499   \&{else}\5
 6500   ${}\{{}$\1\6
 6501   \&{if} ${}(\\{fabs}(\|b.\|r)\G\\{fabs}(\|b.\|i)){}$\5
 6502   ${}\{{}$\1\6
 6503   ${}\|r\K\|b.\|i/\|b.\|r;{}$\6
 6504   ${}\\{den}\K\|b.\|r+\|r*\|b.\|i;{}$\6
 6505   ${}\|c.\|r\K(\|a.\|r+\|r*\|a.\|i)/\\{den};{}$\6
 6506   ${}\|c.\|i\K(\|a.\|i-\|r*\|a.\|r)/\\{den};{}$\6
 6507   \4${}\}{}$\2\6
 6508   \&{else}\5
 6509   ${}\{{}$\1\6
 6510   ${}\|r\K\|b.\|r/\|b.\|i;{}$\6
 6511   ${}\\{den}\K\|b.\|i+\|r*\|b.\|r;{}$\6
 6512   ${}\|c.\|r\K(\|a.\|r*\|r+\|a.\|i)/\\{den};{}$\6
 6513   ${}\|c.\|i\K(\|a.\|i*\|r-\|a.\|r)/\\{den};{}$\6
 6514   \4${}\}{}$\2\6
 6515   \4${}\}{}$\2\6
 6516   \4${}\}{}$\2\6
 6517   \&{else}\5
 6518   ${}\{{}$\1\6
 6519   ${}\\{fprintf}(\\{stderr},\39\.{"Error\ in\ cdiv():\ Di}\)\.{vision\ by\ zero!%
 6520   \\n"});{}$\6
 6521   \\{exit}(\.{FAILURE});\6
 6522   \4${}\}{}$\2\6
 6523   \&{return} \|c;\6
 6524   \4${}\}{}$\2\par
 6525   \U104.\fi
 6526   
 6527   \M{106}The function \PB{$\\{crdiv}(\|a,\|b)$} takes a complex valued argument %
 6528   \PB{\|a} of
 6529   and a real valued argument \PB{\|b} as inputs, and returns the complex
 6530   valued quote $\PB{\|a}/\PB{\|b} = \re(\PB{\|a})/\PB{\|b} + i\im(\PB{\|a})/\PB{%
 6531   \|b}$.
 6532   
 6533   \Y\B\4\X106:Division by complex and real number\X${}\E{}$\6
 6534   \&{dcomplex} \\{crdiv}(\&{dcomplex} \|a${},\39{}$\&{double} \|b)\1\1\2\2\6
 6535   ${}\{{}$\1\6
 6536   \&{dcomplex} \|c;\7
 6537   \&{if} ${}(\\{fabs}(\|b)>\T{0.0}){}$\5
 6538   ${}\{{}$\1\6
 6539   ${}\|c.\|r\K\|a.\|r/\|b;{}$\6
 6540   ${}\|c.\|i\K\|a.\|i/\|b;{}$\6
 6541   \4${}\}{}$\2\6
 6542   \&{else}\5
 6543   ${}\{{}$\1\6
 6544   ${}\\{fprintf}(\\{stderr},\39\.{"Error\ in\ crdiv():\ D}\)\.{ivision\ by\ zero!%
 6545   \\n"});{}$\6
 6546   \\{exit}(\.{FAILURE});\6
 6547   \4${}\}{}$\2\6
 6548   \&{return} \|c;\6
 6549   \4${}\}{}$\2\par
 6550   \U104.\fi
 6551   
 6552   \M{107}The function \PB{\\{csqrt}(\|z)} takes a complex valued argument \PB{%
 6553   \|z} as input
 6554   and returns the complex valued square root $\PB{\|z}{}^{1/2}$.
 6555   
 6556   \Y\B\4\X107:Complex square root\X${}\E{}$\6
 6557   \&{dcomplex} \\{csqrt}(\&{dcomplex} \|z)\1\1\2\2\6
 6558   ${}\{{}$\1\6
 6559   \&{dcomplex} \|c;\6
 6560   \&{double} \|x${},{}$ \|y${},{}$ \|w${},{}$ \|r;\7
 6561   \&{if} ${}((\|z.\|r\E\T{0.0})\W(\|z.\|i\E\T{0.0})){}$\5
 6562   ${}\{{}$\1\6
 6563   ${}\|c.\|r\K\T{0.0};{}$\6
 6564   ${}\|c.\|i\K\T{0.0};{}$\6
 6565   \&{return} \|c;\6
 6566   \4${}\}{}$\2\6
 6567   \&{else}\5
 6568   ${}\{{}$\1\6
 6569   ${}\|x\K\\{fabs}(\|z.\|r);{}$\6
 6570   ${}\|y\K\\{fabs}(\|z.\|i);{}$\6
 6571   \&{if} ${}(\|x\G\|y){}$\5
 6572   ${}\{{}$\1\6
 6573   ${}\|r\K\|y/\|x;{}$\6
 6574   ${}\|w\K\\{sqrt}(\|x)*\\{sqrt}(\T{0.5}*(\T{1.0}+\\{sqrt}(\T{1.0}+\|r*\|r)));{}$%
 6575   \6
 6576   \4${}\}{}$\2\6
 6577   \&{else}\5
 6578   ${}\{{}$\1\6
 6579   ${}\|r\K\|x/\|y;{}$\6
 6580   ${}\|w\K\\{sqrt}(\|y)*\\{sqrt}(\T{0.5}*(\|r+\\{sqrt}(\T{1.0}+\|r*\|r)));{}$\6
 6581   \4${}\}{}$\2\6
 6582   \&{if} ${}(\|z.\|r\G\T{0.0}){}$\5
 6583   ${}\{{}$\1\6
 6584   ${}\|c.\|r\K\|w;{}$\6
 6585   ${}\|c.\|i\K\T{0.5}*\|z.\|i/\|w;{}$\6
 6586   \4${}\}{}$\2\6
 6587   \&{else}\5
 6588   ${}\{{}$\1\6
 6589   ${}\|c.\|i\K((\|z.\|i\G\T{0})\?\|w:{-}\|w);{}$\6
 6590   ${}\|c.\|r\K\T{0.5}*\|z.\|i/\|c.\|i;{}$\6
 6591   \4${}\}{}$\2\6
 6592   \&{return} \|c;\6
 6593   \4${}\}{}$\2\6
 6594   \4${}\}{}$\2\par
 6595   \U94.\fi
 6596   
 6597   \M{108}For complex exponentiation, we distinguish between the case when
 6598   the argument is complex valued, with nonzero real and imaginary parts,
 6599   and the case where the argument is entirely imaginary.
 6600   In the former case, the \PB{\\{cexp}} routine should be used, while in
 6601   the latter case, the \PB{\\{crexpi}} routine is more appropriate.
 6602   
 6603   \Y\B\4\X108:Complex exponentiation\X${}\E{}$\6
 6604   \X109:Exponentiation by complex number\X\6
 6605   \X110:Exponentiation by imaginary number\X\par
 6606   \U94.\fi
 6607   
 6608   \M{109}The function \PB{\\{cexp}(\|a)} takes a complex valued argument \PB{\|a}
 6609   as input
 6610   and returns the complex valued ex\-po\-nen\-tial
 6611   $\exp(a)=\exp(\re(a))[\cos(\im(\PB{\|a}))+i\sin(\im(\PB{\|a}))]$.
 6612   
 6613   \Y\B\4\X109:Exponentiation by complex number\X${}\E{}$\6
 6614   \&{dcomplex} \\{cexp}(\&{dcomplex} \|a)\1\1\2\2\6
 6615   ${}\{{}$\1\6
 6616   \&{dcomplex} \|c;\6
 6617   \&{double} \\{tmp}${}\K\\{exp}(\|a.\|r);{}$\7
 6618   ${}\|c.\|r\K\\{tmp}*\\{cos}(\|a.\|i);{}$\6
 6619   ${}\|c.\|i\K\\{tmp}*\\{sin}(\|a.\|i);{}$\6
 6620   \&{return} \|c;\6
 6621   \4${}\}{}$\2\par
 6622   \U108.\fi
 6623   
 6624   \M{110}The function \PB{\\{crexpi}(\|a)} takes a real valued argument \PB{\|a}
 6625   as input and
 6626   returns the complex valued expo\-nen\-tial $\exp(i\PB{\|a})=\cos(\PB{\|a})+i%
 6627   \sin(\PB{\|a})$.
 6628   
 6629   \Y\B\4\X110:Exponentiation by imaginary number\X${}\E{}$\6
 6630   \&{dcomplex} \\{crexpi}(\&{double} \|a)\1\1\2\2\6
 6631   ${}\{{}$\1\6
 6632   \&{dcomplex} \|c;\7
 6633   ${}\|c.\|r\K\\{cos}(\|a);{}$\6
 6634   ${}\|c.\|i\K\\{sin}(\|a);{}$\6
 6635   \&{return} \|c;\6
 6636   \4${}\}{}$\2\par
 6637   \U108.\fi
 6638   
 6639   \N{1}{111}Subroutines for memory allocation. Here follows the routines for
 6640   memory
 6641   allocation and deallocation of double precision real and complex valued
 6642   vectors, as used for storing the optical field distribution in the grating,
 6643   the refractive index distribution of the grating, etc.
 6644   
 6645   \Y\B\4\X111:Routines for memory allocation of vectors\X${}\E{}$\6
 6646   \X112:Allocation of real-valued vectors\X\6
 6647   \X113:Allocation of complex-valued vectors\X\6
 6648   \X114:Deallocation of real-valued vectors\X\6
 6649   \X115:Deallocation of complex-valued vectors\X\par
 6650   \U50.\fi
 6651   
 6652   \M{112}The \PB{\\{dvector}} routine allocate a real-valued vector of double
 6653   precision,
 6654   with vector index ranging from \PB{\\{nl}} to \PB{\\{nh}}, while the \PB{%
 6655   \\{dcvector}}
 6656   routine allocate a complex-valued vector of double precision, with
 6657   vector index ranging from \PB{\\{nl}} to \PB{\\{nh}}.
 6658   
 6659   \Y\B\4\X112:Allocation of real-valued vectors\X${}\E{}$\6
 6660   \&{double} ${}{*}{}$\\{dvector}(\&{long} \\{nl}${},\39{}$\&{long} \\{nh})\1\1\2%
 6661   \2\6
 6662   ${}\{{}$\1\6
 6663   \&{double} ${}{*}\|v;{}$\7
 6664   ${}\|v\K{}$(\&{double} ${}{*}){}$ \\{malloc}${}((\&{size\_t})((\\{nh}-\\{nl}+%
 6665   \T{2})*\&{sizeof}(\&{double})));{}$\6
 6666   \&{if} ${}(\R\|v){}$\5
 6667   ${}\{{}$\1\6
 6668   ${}\\{fprintf}(\\{stderr},\39\.{"Error:\ Allocation\ f}\)\.{ailure\ in\
 6669   dvector()\\}\)\.{n"});{}$\6
 6670   \\{exit}(\.{FAILURE});\6
 6671   \4${}\}{}$\2\6
 6672   \&{return} \|v${}-\\{nl}+\T{1};{}$\6
 6673   \4${}\}{}$\2\par
 6674   \U111.\fi
 6675   
 6676   \M{113}The \PB{\\{dcvector}} routine allocate a complex-valued vector of double
 6677   precision, with vector index ranging from \PB{\\{nl}} to \PB{\\{nh}}. The basic
 6678   building type of the obtained complex valued vector is the globally
 6679   declarated \PB{\&{dcomplex}} data structure.
 6680   
 6681   \Y\B\4\X113:Allocation of complex-valued vectors\X${}\E{}$\6
 6682   \&{dcomplex} ${}{*}{}$\\{dcvector}(\&{long} \\{nl}${},\39{}$\&{long} \\{nh})\1%
 6683   \1\2\2\6
 6684   ${}\{{}$\1\6
 6685   \&{dcomplex} ${}{*}\|v;{}$\7
 6686   ${}\|v\K{}$(\&{dcomplex} ${}{*}){}$ \\{malloc}${}((\&{size\_t})((\\{nh}-\\{nl}+%
 6687   \T{2})*\&{sizeof}(\&{dcomplex})));{}$\6
 6688   \&{if} ${}(\R\|v){}$\5
 6689   ${}\{{}$\1\6
 6690   ${}\\{fprintf}(\\{stderr},\39\.{"Error:\ Allocation\ f}\)\.{ailure\ in\
 6691   dcvector()}\)\.{\\n"});{}$\6
 6692   \\{exit}(\.{FAILURE});\6
 6693   \4${}\}{}$\2\6
 6694   \&{return} \|v${}-\\{nl}+\T{1};{}$\6
 6695   \4${}\}{}$\2\par
 6696   \U111.\fi
 6697   
 6698   \M{114}The \PB{\\{free\_dvector}} routine release the memory occupied by the
 6699   real-valued vector \PB{$\|v[\\{nl}\MRL{{.}{.}}\\{nh}]$}.
 6700   
 6701   \Y\B\4\X114:Deallocation of real-valued vectors\X${}\E{}$\6
 6702   \&{void} \\{free\_dvector}(\&{double} ${}{*}\|v,\39{}$\&{long} \\{nl}${},\39{}$%
 6703   \&{long} \\{nh})\1\1\2\2\6
 6704   ${}\{{}$\1\6
 6705   \\{free}((\&{char} ${}{*})(\|v+\\{nl}-\T{1}));{}$\6
 6706   \4${}\}{}$\2\par
 6707   \U111.\fi
 6708   
 6709   \M{115}The \PB{\\{free\_dcvector}} routine release the memory occupied by the
 6710   complex-valued vector \PB{$\|v[\\{nl}\MRL{{.}{.}}\\{nh}]$}.
 6711   
 6712   \Y\B\4\X115:Deallocation of complex-valued vectors\X${}\E{}$\6
 6713   \&{void} \\{free\_dcvector}(\&{dcomplex} ${}{*}\|v,\39{}$\&{long} \\{nl}${},%
 6714   \39{}$\&{long} \\{nh})\1\1\2\2\6
 6715   ${}\{{}$\1\6
 6716   \\{free}((\&{char} ${}{*})(\|v+\\{nl}-\T{1}));{}$\6
 6717   \4${}\}{}$\2\par
 6718   \U111.\fi
 6719   
 6720   \N{1}{116}Parsing command line options. All input parameters are passed to the
 6721   program through command line options and arguments to the program.
 6722   The syntax of command line options is listed
 6723   whenever the program is invoked without any options, or whenever any of the
 6724   \.{--help} or \.{-h} options are specified at startup.
 6725   
 6726   \Y\B\4\X116:Parse command line for parameter values\X${}\E{}$\6
 6727   ${}\{{}$\1\6
 6728   ${}\\{progname}\K\\{strip\_away\_path}(\\{argv}[\T{0}]);{}$\6
 6729   ${}\\{fprintf}(\\{stdout},\39\.{"This\ is\ \%s\ v.\%s.\ \%s}\)\.{\\n"},\39%
 6730   \\{progname},\39\.{VERSION},\39\.{COPYRIGHT});{}$\6
 6731   ${}\\{no\_arg}\K\\{argc};{}$\6
 6732   \&{while} ${}(\MM\\{argc}){}$\5
 6733   ${}\{{}$\1\6
 6734   \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-o"})\V\R%
 6735   \\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--outputfile"})){}$\5
 6736   ${}\{{}$\1\6
 6737   ${}\MM\\{argc};{}$\6
 6738   ${}\\{strcpy}(\\{outfilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 6739   \4${}\}{}$\2\6
 6740   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-w"})\V%
 6741   \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--writegratingfile"})){}$\5
 6742   ${}\{{}$\1\6
 6743   ${}\MM\\{argc};{}$\6
 6744   ${}\\{strcpy}(\\{gratingfilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 6745   ${}\\{writegratingtofile}\K\T{1};{}$\6
 6746   \4${}\}{}$\2\6
 6747   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6748   \.{"--displaysurrmedia"})){}$\5
 6749   ${}\{{}$\1\6
 6750   ${}\\{display\_surrounding\_media}\K(\\{display\_surrounding\_media}\?\T{0}:%
 6751   \T{1});{}$\6
 6752   \4${}\}{}$\2\6
 6753   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-a"})\V%
 6754   \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--apodize"})){}$\5
 6755   ${}\{{}$\1\6
 6756   \X118:Parse apodization options\X;\6
 6757   \4${}\}{}$\2\6
 6758   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6759   \.{"--phasejump"})){}$\5
 6760   ${}\{{}$\1\6
 6761   \X119:Parse phase jump options\X;\6
 6762   \4${}\}{}$\2\6
 6763   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6764   \.{"--fieldevolution"})){}$\5
 6765   ${}\{{}$\1\6
 6766   \X121:Parse field evolution saving options\X;\6
 6767   \4${}\}{}$\2\6
 6768   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6769   \.{"--intensityevolutio}\)\.{n"})){}$\5
 6770   ${}\{{}$\1\6
 6771   ${}\MM\\{argc};{}$\6
 6772   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 6773   \\{ievolambda})){}$\5
 6774   ${}\{{}$\1\6
 6775   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--int}\)\.{ensityevolution'\
 6776   opt}\)\.{ion.\\n"},\39\\{progname});{}$\6
 6777   \\{exit}(\.{FAILURE});\6
 6778   \4${}\}{}$\2\6
 6779   ${}\MM\\{argc};{}$\6
 6780   ${}\\{strcpy}(\\{intensityevofilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 6781   ${}\\{intensityevoflag}\K\T{1};{}$\6
 6782   \4${}\}{}$\2\6
 6783   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6784   \.{"--spectrumfile"})){}$\5
 6785   ${}\{{}$\1\6
 6786   ${}\MM\\{argc};{}$\6
 6787   ${}\\{strcpy}(\\{spectrumfilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 6788   \4${}\}{}$\2\6
 6789   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6790   \.{"--stokesspectrum"})){}$\5
 6791   ${}\{{}$\1\6
 6792   ${}\\{stokes\_parameter\_spectrum}\K\T{1};{}$\6
 6793   \4${}\}{}$\2\6
 6794   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6795   \.{"--trmtraject"})){}$\5
 6796   ${}\{{}$\1\6
 6797   ${}\MM\\{argc};{}$\6
 6798   ${}\\{strcpy}(\\{trmtraject\_filename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 6799   ${}\\{trmtraject\_specified}\K\T{1};{}$\6
 6800   \4${}\}{}$\2\6
 6801   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6802   \.{"--intensityspectrum}\)\.{file"})){}$\5
 6803   ${}\{{}$\1\6
 6804   ${}\MM\\{argc};{}$\6
 6805   ${}\\{strcpy}(\\{intensity\_reflection\_spectrumfilename},\39\\{argv}[\\{no%
 6806   \_arg}-\\{argc}]);{}$\6
 6807   ${}\\{strcpy}(\\{intensity\_transmission\_spectrumfilename},\39\\{argv}[\\{no%
 6808   \_arg}-\\{argc}]);{}$\6
 6809   ${}\\{strcpy}(\\{intensity\_check\_spectrumfilename},\39\\{argv}[\\{no\_arg}-%
 6810   \\{argc}]);{}$\6
 6811   ${}\\{sprintf}(\\{intensity\_reflection\_spectrumfilename},\39\.{"%
 6812   \%s.irsp.dat"},\39\\{intensity\_reflection\_spectrumfilename});{}$\6
 6813   ${}\\{sprintf}(\\{intensity\_transmission\_spectrumfilename},\39\.{"%
 6814   \%s.itsp.dat"},\39\\{intensity\_transmission\_spectrumfilename});{}$\6
 6815   ${}\\{sprintf}(\\{intensity\_check\_spectrumfilename},\39\.{"\%s.chec.dat"},\39%
 6816   \\{intensity\_check\_spectrumfilename});{}$\6
 6817   \4${}\}{}$\2\6
 6818   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6819   \.{"--logarithmicspectr}\)\.{um"})){}$\5
 6820   ${}\{{}$\1\6
 6821   ${}\\{save\_dbspectra}\K\T{1};{}$\6
 6822   \4${}\}{}$\2\6
 6823   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-v"})\V%
 6824   \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--verbose"})){}$\5
 6825   ${}\{{}$\1\6
 6826   ${}\\{verbose}\K(\\{verbose}\?\T{0}:\T{1});{}$\6
 6827   \4${}\}{}$\2\6
 6828   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--scale%
 6829   \_stokesparam}\)\.{s"})){}$\5
 6830   ${}\{{}$\1\6
 6831   ${}\\{scale\_stokesparams}\K\T{1};{}$\6
 6832   ${}\MM\\{argc};{}$\6
 6833   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 6834   \\{stoke\_scalefactor})){}$\5
 6835   ${}\{{}$\1\6
 6836   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--sca}\)\.{le\_stokesparams'%
 6837   \ opt}\)\.{ion.\\n"},\\39\\{progname});{}$\6
 6838   \\{exit}(\.{FAILURE});\6
 6839   \4${}\}{}$\2\6
 6840   \4${}\}{}$\2\6
 6841   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6842   \.{"--intensityinfo"})){}$\5
 6843   ${}\{{}$\1\6
 6844   ${}\\{intensityinfo}\K(\\{intensityinfo}\?\T{0}:\T{1});{}$\6
 6845   \4${}\}{}$\2\6
 6846   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6847   \.{"--intensityinfologf}\)\.{ile"})){}$\5
 6848   ${}\{{}$\1\6
 6849   ${}\\{intensityinfo}\K\T{1};{}$\6
 6850   ${}\\{saveintensityinfologfile}\K\T{1};{}$\6
 6851   ${}\MM\\{argc};{}$\6
 6852   ${}\\{strcpy}(\\{intensinfologfilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 6853   \4${}\}{}$\2\6
 6854   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6855   \.{"--gyroperturb"})){}$\5
 6856   ${}\{{}$\1\6
 6857   \X120:Parse gyration constant perturbation options\X;\6
 6858   \4${}\}{}$\2\6
 6859   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6860   \.{"--normalize\_length\_}\)\.{to\_um"})){}$\5
 6861   ${}\{{}$\1\6
 6862   ${}\\{normalize\_length\_to\_micrometer}\K(\\{normalize\_length\_to%
 6863   \_micrometer}\?\T{0}:\T{1});{}$\6
 6864   \4${}\}{}$\2\6
 6865   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6866   \.{"--normalize\_intensi}\)\.{ty"})){}$\5
 6867   ${}\{{}$\1\6
 6868   ${}\\{normalize\_intensity}\K(\\{normalize\_intensity}\?\T{0}:\T{1});{}$\6
 6869   \4${}\}{}$\2\6
 6870   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6871   \.{"--normalize\_ellipti}\)\.{city"})){}$\5
 6872   ${}\{{}$\1\6
 6873   ${}\\{normalize\_ellipticity}\K(\\{normalize\_ellipticity}\?\T{0}:\T{1});{}$\6
 6874   \4${}\}{}$\2\6
 6875   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6876   \.{"--normalizedreprese}\)\.{ntation"})){}$\5
 6877   ${}\{{}$\1\6
 6878   ${}\\{normalize\_internally}\K(\\{normalize\_internally}\?\T{0}:\T{1});{}$\6
 6879   \4${}\}{}$\2\6
 6880   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-r"})\V%
 6881   \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--random"})){}$\5
 6882   ${}\{{}$\1\6
 6883   ${}\\{randomdistribution}\K(\\{randomdistribution}\?\T{0}:\T{1});{}$\6
 6884   \4${}\}{}$\2\6
 6885   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-h"})\V%
 6886   \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--help"})){}$\5
 6887   ${}\{{}$\1\6
 6888   \\{showsomehelp}(\,);\6
 6889   \4${}\}{}$\2\6
 6890   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-g"})\V%
 6891   \R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--grating"})){}$\5
 6892   ${}\{{}$\1\6
 6893   ${}\MM\\{argc};{}$\6
 6894   \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"stepwise"})){}$\5
 6895   ${}\{{}$\1\6
 6896   \X122:Parse for stepwise grating options\X\6
 6897   \4${}\}{}$\2\6
 6898   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6899   \.{"sinusoidal"})){}$\5
 6900   ${}\{{}$\1\6
 6901   \X123:Parse for sinusoidal grating options\X\6
 6902   \4${}\}{}$\2\6
 6903   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6904   \.{"chirped"})){}$\5
 6905   ${}\{{}$\1\6
 6906   \X124:Parse for chirped grating options\X\6
 6907   \4${}\}{}$\2\6
 6908   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6909   \.{"fractal"})){}$\5
 6910   ${}\{{}$\1\6
 6911   \X125:Parse for fractal grating options\X\6
 6912   \4${}\}{}$\2\6
 6913   \&{else}\5
 6914   ${}\{{}$\1\6
 6915   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '-g'\ o}\)\.{r\ '--grating'\
 6916   option}\)\.{.\\n"},\39\\{progname});{}$\6
 6917   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (No\ valid\ grati}\)\.{ng\ type\ found!)%
 6918   \\n"},\39\\{progname});{}$\6
 6919   \\{exit}(\.{FAILURE});\6
 6920   \4${}\}{}$\2\6
 6921   \4${}\}{}$\2\6
 6922   \&{else} \&{if} ${}((\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"-L"}))%
 6923   \V(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"--gratinglength"}))){}$\5
 6924   ${}\{{}$\1\6
 6925   ${}\MM\\{argc};{}$\6
 6926   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 6927   \\{ll})){}$\5
 6928   ${}\{{}$\1\6
 6929   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '-L'\ o}\)\.{ption.\\n"},\39%
 6930   \\{progname});{}$\6
 6931   \\{exit}(\.{FAILURE});\6
 6932   \4${}\}{}$\2\6
 6933   \4${}\}{}$\2\6
 6934   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6935   \.{"--modifylayer"})){}$\5
 6936   ${}\{{}$\1\6
 6937   \X126:Parse for options for modified layer of grating structure\X\6
 6938   \4${}\}{}$\2\6
 6939   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6940   \.{"--refindsurr"})){}$\5
 6941   ${}\{{}$\1\6
 6942   ${}\MM\\{argc};{}$\6
 6943   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 6944   \\{nsurr})){}$\5
 6945   ${}\{{}$\1\6
 6946   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--ref}\)\.{indsurr'\ option.%
 6947   \\n"},\39\\{progname});{}$\6
 6948   \\{exit}(\.{FAILURE});\6
 6949   \4${}\}{}$\2\6
 6950   \4${}\}{}$\2\6
 6951   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6952   \.{"--trmintensity"})){}$\5
 6953   ${}\{{}$\1\6
 6954   \X127:Parse the command line for transmitted intensity range\X\6
 6955   \4${}\}{}$\2\6
 6956   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6957   \.{"--trmellipticity"})){}$\5
 6958   ${}\{{}$\1\6
 6959   \X128:Parse the command line for transmitted ellipticity range\X\6
 6960   \4${}\}{}$\2\6
 6961   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6962   \.{"--lambdastart"})){}$\5
 6963   ${}\{{}$\1\6
 6964   ${}\MM\\{argc};{}$\6
 6965   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 6966   \\{lambdastart})){}$\5
 6967   ${}\{{}$\1\6
 6968   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--lam}\)\.{bdastart'\
 6969   option.\\n"},\39\\{progname});{}$\6
 6970   \\{exit}(\.{FAILURE});\6
 6971   \4${}\}{}$\2\6
 6972   \4${}\}{}$\2\6
 6973   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6974   \.{"--lambdastop"})){}$\5
 6975   ${}\{{}$\1\6
 6976   ${}\MM\\{argc};{}$\6
 6977   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 6978   \\{lambdastop})){}$\5
 6979   ${}\{{}$\1\6
 6980   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--lam}\)\.{bdastop'\ option.%
 6981   \\n"},\39\\{progname});{}$\6
 6982   \\{exit}(\.{FAILURE});\6
 6983   \4${}\}{}$\2\6
 6984   \4${}\}{}$\2\6
 6985   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6986   \.{"--wlenlinz"})){}$\5
 6987   ${}\{{}$\1\6
 6988   ${}\\{chirpflag}\K\T{1};{}$\6
 6989   \4${}\}{}$\2\6
 6990   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6991   \.{"--freqlinz"})){}$\5
 6992   ${}\{{}$\1\6
 6993   ${}\\{chirpflag}\K\T{0};{}$\6
 6994   \4${}\}{}$\2\6
 6995   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 6996   \.{"-N"})){}$\5
 6997   ${}\{{}$\1\6
 6998   ${}\MM\\{argc};{}$\6
 6999   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%ld"},\39{\AND}%
 7000   \\{nn})){}$\5
 7001   ${}\{{}$\1\6
 7002   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '-N'\ o}\)\.{ption.\\n"},\39%
 7003   \\{progname});{}$\6
 7004   \\{exit}(\.{FAILURE});\6
 7005   \4${}\}{}$\2\6
 7006   \4${}\}{}$\2\6
 7007   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 7008   \.{"-M"})){}$\5
 7009   ${}\{{}$\1\6
 7010   ${}\MM\\{argc};{}$\6
 7011   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%ld"},\39{\AND}%
 7012   \\{mm})){}$\5
 7013   ${}\{{}$\1\6
 7014   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '-M'\ o}\)\.{ption.\\n"},\39%
 7015   \\{progname});{}$\6
 7016   \\{exit}(\.{FAILURE});\6
 7017   \4${}\}{}$\2\6
 7018   \4${}\}{}$\2\6
 7019   \&{else}\5
 7020   ${}\{{}$\1\6
 7021   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Specified\ optio}\)\.{n\ invalid!\\n"},%
 7022   \39\\{progname});{}$\6
 7023   \\{showsomehelp}(\,);\6
 7024   \\{exit}(\.{FAILURE});\6
 7025   \4${}\}{}$\2\6
 7026   \4${}\}{}$\2\6
 7027   \X117:Create outfile suffixes\X\6
 7028   \X129:Display parameters parsed from the command line\X\6
 7029   \4${}\}{}$\2\par
 7030   \U45.\fi
 7031   
 7032   \M{117}Create suffixes for output filenames. The output files for the Stokes
 7033   parameters are named according to the convention that....
 7034   
 7035   \Y\B\4\X117:Create outfile suffixes\X${}\E{}$\6
 7036   ${}\{{}$\1\6
 7037   ${}\\{sprintf}(\\{outfilename\_s0},\39\.{"\%s.s0.dat"},\39\\{outfilename});{}$\6
 7038   ${}\\{sprintf}(\\{outfilename\_s1},\39\.{"\%s.s1.dat"},\39\\{outfilename});{}$\6
 7039   ${}\\{sprintf}(\\{outfilename\_s2},\39\.{"\%s.s2.dat"},\39\\{outfilename});{}$\6
 7040   ${}\\{sprintf}(\\{outfilename\_s3},\39\.{"\%s.s3.dat"},\39\\{outfilename});{}$\6
 7041   ${}\\{sprintf}(\\{outfilename\_v0},\39\.{"\%s.v0.dat"},\39\\{outfilename});{}$\6
 7042   ${}\\{sprintf}(\\{outfilename\_v1},\39\.{"\%s.v1.dat"},\39\\{outfilename});{}$\6
 7043   ${}\\{sprintf}(\\{outfilename\_v2},\39\.{"\%s.v2.dat"},\39\\{outfilename});{}$\6
 7044   ${}\\{sprintf}(\\{outfilename\_v3},\39\.{"\%s.v3.dat"},\39\\{outfilename});{}$\6
 7045   ${}\\{sprintf}(\\{outfilename\_w0},\39\.{"\%s.w0.dat"},\39\\{outfilename});{}$\6
 7046   ${}\\{sprintf}(\\{outfilename\_w1},\39\.{"\%s.w1.dat"},\39\\{outfilename});{}$\6
 7047   ${}\\{sprintf}(\\{outfilename\_w2},\39\.{"\%s.w2.dat"},\39\\{outfilename});{}$\6
 7048   ${}\\{sprintf}(\\{outfilename\_w3},\39\.{"\%s.w3.dat"},\39\\{outfilename});{}$\6
 7049   \4${}\}{}$\2\par
 7050   \U116.\fi
 7051   
 7052   \M{118}Parse the command line for options related to apodization~[15] of the
 7053   spatial
 7054   modulation of the refractive index and gyration coefficient.
 7055   
 7056   \Y\B\4\X118:Parse apodization options\X${}\E{}$\6
 7057   ${}\{{}$\1\6
 7058   ${}\\{apodize}\K\T{1};{}$\6
 7059   ${}\MM\\{argc};{}$\6
 7060   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7061   \\{apolength})){}$\5
 7062   ${}\{{}$\1\6
 7063   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--apo}\)\.{dize'\ option.%
 7064   \\n"},\39\\{progname});{}$\6
 7065   \\{exit}(\.{FAILURE});\6
 7066   \4${}\}{}$\2\6
 7067   \4${}\}{}$\2\par
 7068   \U116.\fi
 7069   
 7070   \M{119}Parse the command line for options related to discrete phase jump in
 7071   the spatial modulation of the refractive index and gyration coefficient.
 7072   
 7073   \Y\B\4\X119:Parse phase jump options\X${}\E{}$\6
 7074   ${}\{{}$\1\6
 7075   ${}\\{phasejump}\K\T{1};{}$\6
 7076   ${}\MM\\{argc};{}$\6
 7077   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7078   \\{phasejumpangle})){}$\5
 7079   ${}\{{}$\1\6
 7080   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 1st\ ar}\)\.{g\ of\
 7081   '--phasejump'\ o}\)\.{ption.\\n"},\39\\{progname});{}$\6
 7082   \\{exit}(\.{FAILURE});\6
 7083   \4${}\}{}$\2\6
 7084   ${}\MM\\{argc};{}$\6
 7085   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7086   \\{phasejumpposition})){}$\5
 7087   ${}\{{}$\1\6
 7088   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 2nd\ ar}\)\.{g\ of\
 7089   '--phasejump'\ o}\)\.{ption.\\n"},\39\\{progname});{}$\6
 7090   \\{exit}(\.{FAILURE});\6
 7091   \4${}\}{}$\2\6
 7092   \4${}\}{}$\2\par
 7093   \U116.\fi
 7094   
 7095   \M{120}Parse the command line for options related to a Lorentzian perturbation
 7096   of the magneto-optical gyration coefficient of the grating.
 7097   
 7098   \Y\B\4\X120:Parse gyration constant perturbation options\X${}\E{}$\6
 7099   ${}\{{}$\1\6
 7100   ${}\\{perturbed\_gyration\_constant}\K\T{1};{}$\6
 7101   ${}\MM\\{argc};{}$\6
 7102   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7103   \\{gyroperturb\_position})){}$\5
 7104   ${}\{{}$\1\6
 7105   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--gyr}\)\.{operturb'\
 7106   option.\\n"},\39\\{progname});{}$\6
 7107   \\{exit}(\.{FAILURE});\6
 7108   \4${}\}{}$\2\6
 7109   ${}\MM\\{argc};{}$\6
 7110   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7111   \\{gyroperturb\_amplitude})){}$\5
 7112   ${}\{{}$\1\6
 7113   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--gyr}\)\.{operturb'\
 7114   option.\\n"},\39\\{progname});{}$\6
 7115   \\{exit}(\.{FAILURE});\6
 7116   \4${}\}{}$\2\6
 7117   ${}\MM\\{argc};{}$\6
 7118   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7119   \\{gyroperturb\_width})){}$\5
 7120   ${}\{{}$\1\6
 7121   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--gyr}\)\.{operturb'\
 7122   option.\\n"},\39\\{progname});{}$\6
 7123   \\{exit}(\.{FAILURE});\6
 7124   \4${}\}{}$\2\6
 7125   \4${}\}{}$\2\par
 7126   \U116.\fi
 7127   
 7128   \M{121}Parse the command line for options related to saving the intra grating
 7129   optical field spatial evolution to file.
 7130   If Stokes parameters are preferred for the output of the spatial
 7131   intra-grating field evolution, the specified filename will be
 7132   used as the base name for the output file; the suffixes
 7133   \.{.s0.dat}, \.{.s1.dat}, \.{.s2.dat}, and \.{.s3.dat} will then be
 7134   appended to the base name in order to keep track of them.
 7135   
 7136   \Y\B\4\X121:Parse field evolution saving options\X${}\E{}$\6
 7137   ${}\{{}$\1\6
 7138   ${}\MM\\{argc};{}$\6
 7139   \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"efield"})){}$\5
 7140   ${}\{{}$\1\6
 7141   ${}\\{fieldevoflag\_efield}\K\T{1};{}$\6
 7142   \4${}\}{}$\2\6
 7143   \&{else} \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39%
 7144   \.{"stoke"})){}$\5
 7145   ${}\{{}$\1\6
 7146   ${}\\{fieldevoflag\_stoke}\K\T{1};{}$\6
 7147   \4${}\}{}$\2\6
 7148   \&{else}\5
 7149   ${}\{{}$\1\6
 7150   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Unknown\ field\ e}\)\.{volution\ flag\ '%
 7151   \%s'\ i}\)\.{n\ second\ argument\ of}\)\.{\\n"}\.{"\ --fieldevolution\ o}\)%
 7152   \.{ption.\\n"},\39\\{progname},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 7153   \\{exit}(\.{FAILURE});\6
 7154   \4${}\}{}$\2\6
 7155   ${}\MM\\{argc};{}$\6
 7156   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%ld"},\39{\AND}%
 7157   \\{nne})){}$\5
 7158   ${}\{{}$\1\6
 7159   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '--fie}\)\.{ldevolution'\
 7160   option.}\)\.{\\n"},\39\\{progname});{}$\6
 7161   \\{exit}(\.{FAILURE});\6
 7162   \4${}\}{}$\2\6
 7163   ${}\MM\\{argc};{}$\6
 7164   ${}\\{strcpy}(\\{fieldevofilename},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 7165   ${}\\{fieldevoflag}\K\T{1}{}$;\C{ Indicate that the field evolution shold be
 7166   saved }\6
 7167   \&{if} (\\{fieldevoflag\_stoke})\5
 7168   ${}\{{}$\C{ Stokes parameter output preferred }\1\6
 7169   ${}\\{sprintf}(\\{fieldevofilename\_s0},\39\.{"\%s.s0.dat"},\39%
 7170   \\{fieldevofilename});{}$\6
 7171   ${}\\{sprintf}(\\{fieldevofilename\_s1},\39\.{"\%s.s1.dat"},\39%
 7172   \\{fieldevofilename});{}$\6
 7173   ${}\\{sprintf}(\\{fieldevofilename\_s2},\39\.{"\%s.s2.dat"},\39%
 7174   \\{fieldevofilename});{}$\6
 7175   ${}\\{sprintf}(\\{fieldevofilename\_s3},\39\.{"\%s.s3.dat"},\39%
 7176   \\{fieldevofilename});{}$\6
 7177   \4${}\}{}$\2\6
 7178   \4${}\}{}$\2\par
 7179   \U116.\fi
 7180   
 7181   \M{122}Parse the command line for options related to the initiation of a
 7182   stepwise
 7183   grating, consisting of a set of stacked layers.
 7184   
 7185   \Y\B\4\X122:Parse for stepwise grating options\X${}\E{}$\6
 7186   ${}\{{}$\1\6
 7187   ${}\\{strcpy}(\\{gratingtype},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 7188   ${}\MM\\{argc};{}$\6
 7189   \&{if} ${}(\R\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"twolevel"})){}$\5
 7190   ${}\{{}$\1\6
 7191   ${}\\{strcpy}(\\{gratingsubtype},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 7192   ${}\MM\\{argc};{}$\6
 7193   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"t1"})){}$\5
 7194   ${}\{{}$\1\6
 7195   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7196   \\n"},\39\\{progname});{}$\6
 7197   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 't1').\\n"},%
 7198   \39\\{progname});{}$\6
 7199   \\{exit}(\.{FAILURE});\6
 7200   \4${}\}{}$\2\6
 7201   ${}\MM\\{argc};{}$\6
 7202   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7203   \\{t1})){}$\5
 7204   ${}\{{}$\1\6
 7205   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7206   \\n"},\39\\{progname});{}$\6
 7207   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ t1).%
 7208   \\n"},\39\\{progname});{}$\6
 7209   \\{exit}(\.{FAILURE});\6
 7210   \4${}\}{}$\2\6
 7211   ${}\MM\\{argc};{}$\6
 7212   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"t2"})){}$\5
 7213   ${}\{{}$\1\6
 7214   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7215   \\n"},\39\\{progname});{}$\6
 7216   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 't2').\\n"},%
 7217   \39\\{progname});{}$\6
 7218   \\{exit}(\.{FAILURE});\6
 7219   \4${}\}{}$\2\6
 7220   ${}\MM\\{argc};{}$\6
 7221   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7222   \\{t2})){}$\5
 7223   ${}\{{}$\1\6
 7224   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7225   \\n"},\39\\{progname});{}$\6
 7226   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ t2).%
 7227   \\n"},\39\\{progname});{}$\6
 7228   \\{exit}(\.{FAILURE});\6
 7229   \4${}\}{}$\2\6
 7230   ${}\MM\\{argc};{}$\6
 7231   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"n1"})){}$\5
 7232   ${}\{{}$\1\6
 7233   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7234   \\n"},\39\\{progname});{}$\6
 7235   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'n1').\\n"},%
 7236   \39\\{progname});{}$\6
 7237   \\{exit}(\.{FAILURE});\6
 7238   \4${}\}{}$\2\6
 7239   ${}\MM\\{argc};{}$\6
 7240   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7241   \\{n1})){}$\5
 7242   ${}\{{}$\1\6
 7243   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7244   \\n"},\39\\{progname});{}$\6
 7245   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n1).%
 7246   \\n"},\39\\{progname});{}$\6
 7247   \\{exit}(\.{FAILURE});\6
 7248   \4${}\}{}$\2\6
 7249   ${}\MM\\{argc};{}$\6
 7250   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"n2"})){}$\5
 7251   ${}\{{}$\1\6
 7252   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7253   \\n"},\39\\{progname});{}$\6
 7254   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'n2').\\n"},%
 7255   \39\\{progname});{}$\6
 7256   \\{exit}(\.{FAILURE});\6
 7257   \4${}\}{}$\2\6
 7258   ${}\MM\\{argc};{}$\6
 7259   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7260   \\{n2})){}$\5
 7261   ${}\{{}$\1\6
 7262   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7263   \\n"},\39\\{progname});{}$\6
 7264   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n2).%
 7265   \\n"},\39\\{progname});{}$\6
 7266   \\{exit}(\.{FAILURE});\6
 7267   \4${}\}{}$\2\6
 7268   ${}\MM\\{argc};{}$\6
 7269   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"g1"})){}$\5
 7270   ${}\{{}$\1\6
 7271   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7272   \\n"},\39\\{progname});{}$\6
 7273   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'g1').\\n"},%
 7274   \39\\{progname});{}$\6
 7275   \\{exit}(\.{FAILURE});\6
 7276   \4${}\}{}$\2\6
 7277   ${}\MM\\{argc};{}$\6
 7278   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7279   \\{g1})){}$\5
 7280   ${}\{{}$\1\6
 7281   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7282   \\n"},\39\\{progname});{}$\6
 7283   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g1).%
 7284   \\n"},\39\\{progname});{}$\6
 7285   \\{exit}(\.{FAILURE});\6
 7286   \4${}\}{}$\2\6
 7287   ${}\MM\\{argc};{}$\6
 7288   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"g2"})){}$\5
 7289   ${}\{{}$\1\6
 7290   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7291   \\n"},\39\\{progname});{}$\6
 7292   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'g2').\\n"},%
 7293   \39\\{progname});{}$\6
 7294   \\{exit}(\.{FAILURE});\6
 7295   \4${}\}{}$\2\6
 7296   ${}\MM\\{argc};{}$\6
 7297   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7298   \\{g2})){}$\5
 7299   ${}\{{}$\1\6
 7300   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7301   \\n"},\39\\{progname});{}$\6
 7302   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g2).%
 7303   \\n"},\39\\{progname});{}$\6
 7304   \\{exit}(\.{FAILURE});\6
 7305   \4${}\}{}$\2\6
 7306   ${}\MM\\{argc};{}$\6
 7307   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pe1"})){}$\5
 7308   ${}\{{}$\1\6
 7309   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7310   \\n"},\39\\{progname});{}$\6
 7311   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pe1').\\n"},%
 7312   \39\\{progname});{}$\6
 7313   \\{exit}(\.{FAILURE});\6
 7314   \4${}\}{}$\2\6
 7315   ${}\MM\\{argc};{}$\6
 7316   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7317   \\{pe1})){}$\5
 7318   ${}\{{}$\1\6
 7319   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7320   \\n"},\39\\{progname});{}$\6
 7321   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7322   pe1).\\n"},\39\\{progname});{}$\6
 7323   \\{exit}(\.{FAILURE});\6
 7324   \4${}\}{}$\2\6
 7325   ${}\MM\\{argc};{}$\6
 7326   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pe2"})){}$\5
 7327   ${}\{{}$\1\6
 7328   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7329   \\n"},\39\\{progname});{}$\6
 7330   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pe2').\\n"},%
 7331   \39\\{progname});{}$\6
 7332   \\{exit}(\.{FAILURE});\6
 7333   \4${}\}{}$\2\6
 7334   ${}\MM\\{argc};{}$\6
 7335   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7336   \\{pe2})){}$\5
 7337   ${}\{{}$\1\6
 7338   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7339   \\n"},\39\\{progname});{}$\6
 7340   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7341   pe2).\\n"},\39\\{progname});{}$\6
 7342   \\{exit}(\.{FAILURE});\6
 7343   \4${}\}{}$\2\6
 7344   ${}\MM\\{argc};{}$\6
 7345   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pm1"})){}$\5
 7346   ${}\{{}$\1\6
 7347   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7348   \\n"},\39\\{progname});{}$\6
 7349   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pm1').\\n"},%
 7350   \39\\{progname});{}$\6
 7351   \\{exit}(\.{FAILURE});\6
 7352   \4${}\}{}$\2\6
 7353   ${}\MM\\{argc};{}$\6
 7354   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7355   \\{pm1})){}$\5
 7356   ${}\{{}$\1\6
 7357   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7358   \\n"},\39\\{progname});{}$\6
 7359   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7360   pm1).\\n"},\\39\\{progname});{}$\6
 7361   \\{exit}(\.{FAILURE});\6
 7362   \4${}\}{}$\2\6
 7363   ${}\MM\\{argc};{}$\6
 7364   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pm2"})){}$\5
 7365   ${}\{{}$\1\6
 7366   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7367   \\n"},\39\\{progname});{}$\6
 7368   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pm2').\\n"},%
 7369   \39\\{progname});{}$\6
 7370   \\{exit}(\.{FAILURE});\6
 7371   \4${}\}{}$\2\6
 7372   ${}\MM\\{argc};{}$\6
 7373   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7374   \\{pm2})){}$\5
 7375   ${}\{{}$\1\6
 7376   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7377   \\n"},\39\\{progname});{}$\6
 7378   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7379   pm2).\\n"},\\39\\{progname});{}$\6
 7380   \\{exit}(\.{FAILURE});\6
 7381   \4${}\}{}$\2\6
 7382   ${}\MM\\{argc};{}$\6
 7383   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"qe1"})){}$\5
 7384   ${}\{{}$\1\6
 7385   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7386   \\n"},\39\\{progname});{}$\6
 7387   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'qe1').\\n"},%
 7388   \39\\{progname});{}$\6
 7389   \\{exit}(\.{FAILURE});\6
 7390   \4${}\}{}$\2\6
 7391   ${}\MM\\{argc};{}$\6
 7392   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7393   \\{qe1})){}$\5
 7394   ${}\{{}$\1\6
 7395   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7396   \\n"},\39\\{progname});{}$\6
 7397   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7398   qe1).\\n"},\\39\\{progname});{}$\6
 7399   \\{exit}(\.{FAILURE});\6
 7400   \4${}\}{}$\2\6
 7401   ${}\MM\\{argc};{}$\6
 7402   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"qe2"})){}$\5
 7403   ${}\{{}$\1\6
 7404   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7405   \\n"},\39\\{progname});{}$\6
 7406   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'qe2').\\n"},%
 7407   \39\\{progname});{}$\6
 7408   \\{exit}(\.{FAILURE});\6
 7409   \4${}\}{}$\2\6
 7410   ${}\MM\\{argc};{}$\6
 7411   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7412   \\{qe2})){}$\5
 7413   ${}\{{}$\1\6
 7414   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7415   \\n"},\39\\{progname});{}$\6
 7416   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7417   qe2).\\n"},\39\\{progname});{}$\6
 7418   \\{exit}(\.{FAILURE});\6
 7419   \4${}\}{}$\2\6
 7420   ${}\MM\\{argc};{}$\6
 7421   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"qm1"})){}$\5
 7422   ${}\{{}$\1\6
 7423   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7424   \\n"},\39\\{progname});{}$\6
 7425   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'qm1').\\n"},%
 7426   \39\\{progname});{}$\6
 7427   \\{exit}(\.{FAILURE});\6
 7428   \4${}\}{}$\2\6
 7429   ${}\MM\\{argc};{}$\6
 7430   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7431   \\{qm1})){}$\5
 7432   ${}\{{}$\1\6
 7433   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7434   \\n"},\39\\{progname});{}$\6
 7435   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7436   qm1).\\n"},\39\\{progname});{}$\6
 7437   \\{exit}(\.{FAILURE});\6
 7438   \4${}\}{}$\2\6
 7439   ${}\MM\\{argc};{}$\6
 7440   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"qm2"})){}$\5
 7441   ${}\{{}$\1\6
 7442   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7443   \\n"},\39\\{progname});{}$\6
 7444   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'qm2').\\n"},%
 7445   \39\\{progname});{}$\6
 7446   \\{exit}(\.{FAILURE});\6
 7447   \4${}\}{}$\2\6
 7448   ${}\MM\\{argc};{}$\6
 7449   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7450   \\{qm2})){}$\5
 7451   ${}\{{}$\1\6
 7452   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'twole}\)\.{vel'\ option.%
 7453   \\n"},\39\\{progname});{}$\6
 7454   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\
 7455   qm2).\\n"},\39\\{progname});{}$\6
 7456   \\{exit}(\.{FAILURE});\6
 7457   \4${}\}{}$\2\6
 7458   \4${}\}{}$\2\6
 7459   \&{else}\5
 7460   ${}\{{}$\1\6
 7461   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ '-g'\ o}\)\.{r\ '--grating'\
 7462   option}\)\.{.\\n"},\39\\{progname});{}$\6
 7463   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (No\ valid\ stepw}\)\.{ise\ grating\
 7464   type\ fou}\)\.{nd!)\\n"},\39\\{progname});{}$\6
 7465   \\{exit}(\.{FAILURE});\6
 7466   \4${}\}{}$\2\6
 7467   \4${}\}{}$\2\par
 7468   \U116.\fi
 7469   
 7470   \M{123}Parse the command line for options related to the initiation of a
 7471   sinusoidal
 7472   grating, consisting of a set of stacked layers.
 7473   
 7474   \Y\B\4\X123:Parse for sinusoidal grating options\X${}\E{}$\6
 7475   ${}\{{}$\1\6
 7476   ${}\\{strcpy}(\\{gratingtype},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 7477   ${}\MM\\{argc};{}$\6
 7478   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"n"})){}$\5
 7479   ${}\{{}$\1\6
 7480   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7481   \\n"},\39\\{progname});{}$\6
 7482   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'n').\\n"},\39%
 7483   \\{progname});{}$\6
 7484   \\{exit}(\.{FAILURE});\6
 7485   \4${}\}{}$\2\6
 7486   ${}\MM\\{argc};{}$\6
 7487   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7488   \\{n1})){}$\5
 7489   ${}\{{}$\1\6
 7490   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7491   \\n"},\39\\{progname});{}$\6
 7492   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n\
 7493   [1st\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7494   \\{exit}(\.{FAILURE});\6
 7495   \4${}\}{}$\2\6
 7496   ${}\MM\\{argc};{}$\6
 7497   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7498   \\{n2})){}$\5
 7499   ${}\{{}$\1\6
 7500   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7501   \\n"},\39\\{progname});{}$\6
 7502   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n\
 7503   [2nd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7504   \\{exit}(\.{FAILURE});\6
 7505   \4${}\}{}$\2\6
 7506   ${}\MM\\{argc};{}$\6
 7507   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7508   \\{nper})){}$\5
 7509   ${}\{{}$\1\6
 7510   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7511   \\n"},\39\\{progname});{}$\6
 7512   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n\
 7513   [3rd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7514   \\{exit}(\.{FAILURE});\6
 7515   \4${}\}{}$\2\6
 7516   ${}\MM\\{argc};{}$\6
 7517   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"g"})){}$\5
 7518   ${}\{{}$\1\6
 7519   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7520   \\n"},\39\\{progname});{}$\6
 7521   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'g').\\n"},\39%
 7522   \\{progname});{}$\6
 7523   \\{exit}(\.{FAILURE});\6
 7524   \4${}\}{}$\2\6
 7525   ${}\MM\\{argc};{}$\6
 7526   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7527   \\{g1})){}$\5
 7528   ${}\{{}$\1\6
 7529   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7530   \\n"},\39\\{progname});{}$\6
 7531   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g\
 7532   [1st\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7533   \\{exit}(\.{FAILURE});\6
 7534   \4${}\}{}$\2\6
 7535   ${}\MM\\{argc};{}$\6
 7536   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7537   \\{g2})){}$\5
 7538   ${}\{{}$\1\6
 7539   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7540   \\n"},\39\\{progname});{}$\6
 7541   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g\
 7542   [2nd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7543   \\{exit}(\.{FAILURE});\6
 7544   \4${}\}{}$\2\6
 7545   ${}\MM\\{argc};{}$\6
 7546   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7547   \\{gper})){}$\5
 7548   ${}\{{}$\1\6
 7549   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7550   \\n"},\39\\{progname});{}$\6
 7551   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g\
 7552   [3rd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7553   \\{exit}(\.{FAILURE});\6
 7554   \4${}\}{}$\2\6
 7555   ${}\MM\\{argc};{}$\6
 7556   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pe"})){}$\5
 7557   ${}\{{}$\1\6
 7558   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7559   \\n"},\39\\{progname});{}$\6
 7560   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pe').\\n"},%
 7561   \39\\{progname});{}$\6
 7562   \\{exit}(\.{FAILURE});\6
 7563   \4${}\}{}$\2\6
 7564   ${}\MM\\{argc};{}$\6
 7565   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7566   \\{pe1})){}$\5
 7567   ${}\{{}$\1\6
 7568   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7569   \\n"},\39\\{progname});{}$\6
 7570   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pe\
 7571   [1st\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7572   \\{exit}(\.{FAILURE});\6
 7573   \4${}\}{}$\2\6
 7574   ${}\MM\\{argc};{}$\6
 7575   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7576   \\{pe2})){}$\5
 7577   ${}\{{}$\1\6
 7578   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7579   \\n"},\39\\{progname});{}$\6
 7580   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pe\
 7581   [2nd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7582   \\{exit}(\.{FAILURE});\6
 7583   \4${}\}{}$\2\6
 7584   ${}\MM\\{argc};{}$\6
 7585   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7586   \\{peper})){}$\5
 7587   ${}\{{}$\1\6
 7588   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7589   \\n"},\39\\{progname});{}$\6
 7590   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pe\
 7591   [3rd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7592   \\{exit}(\.{FAILURE});\6
 7593   \4${}\}{}$\2\6
 7594   ${}\MM\\{argc};{}$\6
 7595   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pm"})){}$\5
 7596   ${}\{{}$\1\6
 7597   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7598   \\n"},\39\\{progname});{}$\6
 7599   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pm').\\n"},%
 7600   \39\\{progname});{}$\6
 7601   \\{exit}(\.{FAILURE});\6
 7602   \4${}\}{}$\2\6
 7603   ${}\MM\\{argc};{}$\6
 7604   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7605   \\{pm1})){}$\5
 7606   ${}\{{}$\1\6
 7607   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7608   \\n"},\39\\{progname});{}$\6
 7609   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pm\
 7610   [1st\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7611   \\{exit}(\.{FAILURE});\6
 7612   \4${}\}{}$\2\6
 7613   ${}\MM\\{argc};{}$\6
 7614   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7615   \\{pm2})){}$\5
 7616   ${}\{{}$\1\6
 7617   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7618   \\n"},\39\\{progname});{}$\6
 7619   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pm\
 7620   [2nd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7621   \\{exit}(\.{FAILURE});\6
 7622   \4${}\}{}$\2\6
 7623   ${}\MM\\{argc};{}$\6
 7624   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7625   \\{pmper})){}$\5
 7626   ${}\{{}$\1\6
 7627   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7628   \\n"},\39\\{progname});{}$\6
 7629   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pm\
 7630   [3rd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7631   \\{exit}(\.{FAILURE});\6
 7632   \4${}\}{}$\2\6
 7633   ${}\MM\\{argc};{}$\6
 7634   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"qe"})){}$\5
 7635   ${}\{{}$\1\6
 7636   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7637   \\n"},\39\\{progname});{}$\6
 7638   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'qe').\\n"},%
 7639   \39\\{progname});{}$\6
 7640   \\{exit}(\.{FAILURE});\6
 7641   \4${}\}{}$\2\6
 7642   ${}\MM\\{argc};{}$\6
 7643   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7644   \\{qe1})){}$\5
 7645   ${}\{{}$\1\6
 7646   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7647   \\n"},\39\\{progname});{}$\6
 7648   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qe\
 7649   [1st\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7650   \\{exit}(\.{FAILURE});\6
 7651   \4${}\}{}$\2\6
 7652   ${}\MM\\{argc};{}$\6
 7653   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7654   \\{qe2})){}$\5
 7655   ${}\{{}$\1\6
 7656   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7657   \\n"},\39\\{progname});{}$\6
 7658   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qe\
 7659   [2nd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7660   \\{exit}(\.{FAILURE});\6
 7661   \4${}\}{}$\2\6
 7662   ${}\MM\\{argc};{}$\6
 7663   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7664   \\{qeper})){}$\5
 7665   ${}\{{}$\1\6
 7666   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7667   \\n"},\39\\{progname});{}$\6
 7668   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qe\
 7669   [3rd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7670   \\{exit}(\.{FAILURE});\6
 7671   \4${}\}{}$\2\6
 7672   ${}\MM\\{argc};{}$\6
 7673   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"qm"})){}$\5
 7674   ${}\{{}$\1\6
 7675   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7676   \\n"},\39\\{progname});{}$\6
 7677   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'qm').\\n"},%
 7678   \39\\{progname});{}$\6
 7679   \\{exit}(\.{FAILURE});\6
 7680   \4${}\}{}$\2\6
 7681   ${}\MM\\{argc};{}$\6
 7682   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7683   \\{qm1})){}$\5
 7684   ${}\{{}$\1\6
 7685   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7686   \\n"},\39\\{progname});{}$\6
 7687   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qm\
 7688   [1st\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7689   \\{exit}(\.{FAILURE});\6
 7690   \4${}\}{}$\2\6
 7691   ${}\MM\\{argc};{}$\6
 7692   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7693   \\{qm2})){}$\5
 7694   ${}\{{}$\1\6
 7695   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7696   \\n"},\39\\{progname});{}$\6
 7697   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qm\
 7698   [2nd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7699   \\{exit}(\.{FAILURE});\6
 7700   \4${}\}{}$\2\6
 7701   ${}\MM\\{argc};{}$\6
 7702   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7703   \\{qmper})){}$\5
 7704   ${}\{{}$\1\6
 7705   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'sinus}\)\.{oidal'\ option.%
 7706   \\n"},\39\\{progname});{}$\6
 7707   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qm\
 7708   [3rd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7709   \\{exit}(\.{FAILURE});\6
 7710   \4${}\}{}$\2\6
 7711   \4${}\}{}$\2\par
 7712   \U116.\fi
 7713   
 7714   \M{124}Parse the command line for options related to the initiation of a
 7715   sinusoidal
 7716   grating, consisting of a set of stacked layers.
 7717   
 7718   \Y\B\4\X124:Parse for chirped grating options\X${}\E{}$\6
 7719   ${}\{{}$\1\6
 7720   ${}\\{strcpy}(\\{gratingtype},\39\\{argv}[\\{no\_arg}-\\{argc}]);{}$\6
 7721   ${}\MM\\{argc};{}$\6
 7722   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"n"})){}$\5
 7723   ${}\{{}$\1\6
 7724   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7725   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7726   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'n').\\n"},\39%
 7727   \\{progname});{}$\6
 7728   \\{exit}(\.{FAILURE});\6
 7729   \4${}\}{}$\2\6
 7730   ${}\MM\\{argc};{}$\6
 7731   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7732   \\{n1})){}$\5
 7733   ${}\{{}$\1\6
 7734   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7735   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7736   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n\
 7737   [1st\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7738   \\{exit}(\.{FAILURE});\6
 7739   \4${}\}{}$\2\6
 7740   ${}\MM\\{argc};{}$\6
 7741   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7742   \\{n2})){}$\5
 7743   ${}\{{}$\1\6
 7744   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7745   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7746   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n\
 7747   [2nd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7748   \\{exit}(\.{FAILURE});\6
 7749   \4${}\}{}$\2\6
 7750   ${}\MM\\{argc};{}$\6
 7751   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7752   \\{nper})){}$\5
 7753   ${}\{{}$\1\6
 7754   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7755   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7756   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n\
 7757   [3rd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7758   \\{exit}(\.{FAILURE});\6
 7759   \4${}\}{}$\2\6
 7760   ${}\MM\\{argc};{}$\6
 7761   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7762   \\{ncrp})){}$\5
 7763   ${}\{{}$\1\6
 7764   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7765   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7766   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ n\
 7767   [4th\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7768   \\{exit}(\.{FAILURE});\6
 7769   \4${}\}{}$\2\6
 7770   ${}\MM\\{argc};{}$\6
 7771   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"g"})){}$\5
 7772   ${}\{{}$\1\6
 7773   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7774   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7775   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'g').\\n"},\39%
 7776   \\{progname});{}$\6
 7777   \\{exit}(\.{FAILURE});\6
 7778   \4${}\}{}$\2\6
 7779   ${}\MM\\{argc};{}$\6
 7780   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7781   \\{g1})){}$\5
 7782   ${}\{{}$\1\6
 7783   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7784   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7785   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g\
 7786   [1st\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7787   \\{exit}(\.{FAILURE});\6
 7788   \4${}\}{}$\2\6
 7789   ${}\MM\\{argc};{}$\6
 7790   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7791   \\{g2})){}$\5
 7792   ${}\{{}$\1\6
 7793   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7794   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7795   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g\
 7796   [2nd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7797   \\{exit}(\.{FAILURE});\6
 7798   \4${}\}{}$\2\6
 7799   ${}\MM\\{argc};{}$\6
 7800   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7801   \\{gper})){}$\5
 7802   ${}\{{}$\1\6
 7803   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7804   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7805   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g\
 7806   [3rd\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7807   \\{exit}(\.{FAILURE});\6
 7808   \4${}\}{}$\2\6
 7809   ${}\MM\\{argc};{}$\6
 7810   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7811   \\{gcrp})){}$\5
 7812   ${}\{{}$\1\6
 7813   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7814   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7815   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ g\
 7816   [4th\ arg}\)\.{]).\\n"},\39\\{progname});{}$\6
 7817   \\{exit}(\.{FAILURE});\6
 7818   \4${}\}{}$\2\6
 7819   ${}\MM\\{argc};{}$\6
 7820   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pe"})){}$\5
 7821   ${}\{{}$\1\6
 7822   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7823   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7824   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pe').\\n"},%
 7825   \39\\{progname});{}$\6
 7826   \\{exit}(\.{FAILURE});\6
 7827   \4${}\}{}$\2\6
 7828   ${}\MM\\{argc};{}$\6
 7829   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7830   \\{pe1})){}$\5
 7831   ${}\{{}$\1\6
 7832   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7833   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7834   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pe\
 7835   [1st\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7836   \\{exit}(\.{FAILURE});\6
 7837   \4${}\}{}$\2\6
 7838   ${}\MM\\{argc};{}$\6
 7839   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7840   \\{pe2})){}$\5
 7841   ${}\{{}$\1\6
 7842   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7843   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7844   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pe\
 7845   [2nd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7846   \\{exit}(\.{FAILURE});\6
 7847   \4${}\}{}$\2\6
 7848   ${}\MM\\{argc};{}$\6
 7849   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7850   \\{peper})){}$\5
 7851   ${}\{{}$\1\6
 7852   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7853   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7854   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pe\
 7855   [3rd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7856   \\{exit}(\.{FAILURE});\6
 7857   \4${}\}{}$\2\6
 7858   ${}\MM\\{argc};{}$\6
 7859   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7860   \\{pecrp})){}$\5
 7861   ${}\{{}$\1\6
 7862   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7863   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7864   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pe\
 7865   [4th\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7866   \\{exit}(\.{FAILURE});\6
 7867   \4${}\}{}$\2\6
 7868   ${}\MM\\{argc};{}$\6
 7869   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"pm"})){}$\5
 7870   ${}\{{}$\1\6
 7871   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7872   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7873   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'pm').\\n"},%
 7874   \39\\{progname});{}$\6
 7875   \\{exit}(\.{FAILURE});\6
 7876   \4${}\}{}$\2\6
 7877   ${}\MM\\{argc};{}$\6
 7878   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7879   \\{pm1})){}$\5
 7880   ${}\{{}$\1\6
 7881   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7882   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7883   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pm\
 7884   [1st\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7885   \\{exit}(\.{FAILURE});\6
 7886   \4${}\}{}$\2\6
 7887   ${}\MM\\{argc};{}$\6
 7888   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7889   \\{pm2})){}$\5
 7890   ${}\{{}$\1\6
 7891   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7892   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7893   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pm\
 7894   [2nd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7895   \\{exit}(\.{FAILURE});\6
 7896   \4${}\}{}$\2\6
 7897   ${}\MM\\{argc};{}$\6
 7898   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7899   \\{pmper})){}$\5
 7900   ${}\{{}$\1\6
 7901   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7902   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7903   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pm\
 7904   [3rd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7905   \\{exit}(\.{FAILURE});\6
 7906   \4${}\}{}$\2\6
 7907   ${}\MM\\{argc};{}$\6
 7908   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7909   \\{pmcrp})){}$\5
 7910   ${}\{{}$\1\6
 7911   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7912   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7913   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ pm\
 7914   [4th\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7915   \\{exit}(\.{FAILURE});\6
 7916   \4${}\}{}$\2\6
 7917   ${}\MM\\{argc};{}$\6
 7918   \&{if} ${}(\\{strcmp}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"qe"})){}$\5
 7919   ${}\{{}$\1\6
 7920   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7921   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7922   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Expecting\ stri}\)\.{ng\ 'qe').\\n"},%
 7923   \39\\{progname});{}$\6
 7924   \\{exit}(\.{FAILURE});\6
 7925   \4${}\}{}$\2\6
 7926   ${}\MM\\{argc};{}$\6
 7927   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7928   \\{qe1})){}$\5
 7929   ${}\{{}$\1\6
 7930   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7931   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7932   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qe\
 7933   [1st\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7934   \\{exit}(\.{FAILURE});\6
 7935   \4${}\}{}$\2\6
 7936   ${}\MM\\{argc};{}$\6
 7937   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7938   \\{qe2})){}$\5
 7939   ${}\{{}$\1\6
 7940   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7941   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7942   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qe\
 7943   [2nd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7944   \\{exit}(\.{FAILURE});\6
 7945   \4${}\}{}$\2\6
 7946   ${}\MM\\{argc};{}$\6
 7947   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7948   \\{qeper})){}$\5
 7949   ${}\{{}$\1\6
 7950   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7951   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7952   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qe\
 7953   [3rd\ ar}\)\.{g]).\\n"},\39\\{progname});{}$\6
 7954   \\{exit}(\.{FAILURE});\6
 7955   \4${}\}{}$\2\6
 7956   ${}\MM\\{argc};{}$\6
 7957   \&{if} ${}(\R\\{sscanf}(\\{argv}[\\{no\_arg}-\\{argc}],\39\.{"\%lf"},\39{\AND}%
 7958   \\{qecrp})){}$\5
 7959   ${}\{{}$\1\6
 7960   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ Error\ in\ 'chirp}\)\.{ed'\ grating\
 7961   option.\\}\)\.{n"},\39\\{progname});{}$\6
 7962   ${}\\{fprintf}(\\{stderr},\39\.{"\%s:\ (Could\ not\ read}\)\.{\ data\ for\ qe\
 7963   [4th\ ar}\)\.{g]).\\n"},\39