% File: magbragg.w [CWEB source code] % Created: October 28, 2002 [v.1.0] % Last change: December 18, 2011 [v.1.44] % Author: Fredrik Jonsson % Description: The CWEB source code for the MAGBRAGG simulator of nonlinear % magneto-optical Bragg gratings. For information on the CWEB % programming language, see http://www.literateprogramming.com. % Compilation: Compile this program by using the enclosed Makefile, or use % the blocks of the Makefile as listed in section five of the % documentation (file magbragg.ps or magbragg.pdf). The C source % code (as generated from this CWEB code) conforms to the ANSI % standard for the C programming language (which is equivalent % to the ISO C90/C99 standard for C). % % Copyright (C) 2002--2011, Fredrik Jonsson % \input epsf \def\version{1.44} \def\lastrevdate{January 10, 2007} \font\eightcmr=cmr8 \font\tensc=cmcsc10 \font\eightcmssq=cmssq8 \font\eightcmssqi=cmssqi8 \font\twentycmcsc=cmcsc10 at 20 truept \def\magbragg{{\eightcmr MAGBRAGG\spacefactor1000}} \def\poincare{{\eightcmr POINCARE\spacefactor1000}} \def\ANSI{{\eightcmr ANSI\spacefactor1000}} % The language standard we stick to \def\SI{{\eightcmr SI\spacefactor1000}} % Another standard for physical units \def\GNU{{\eightcmr GNU\spacefactor1000}} % GNU is Not Unix \def\GCC{{\eightcmr GCC\spacefactor1000}} % The GNU C-compiler \def\CEE{{\eightcmr C\spacefactor1000}} % The C programming language \def\ANSICEE{{\eightcmr ANSI~C\spacefactor1000}}% The ANSI-C standard language \def\CWEB{{\eightcmr CWEB\spacefactor1000}} % The CWEB programming language \def\MATLAB{{\eightcmr MATLAB\spacefactor1000}} % The MATLAB ditto \def\UNIX{{\eightcmr UNIX\spacefactor1000}} \def\CYGWIN{{\eightcmr CYGWIN\spacefactor1000}} \def\CTANGLE{{\eightcmr CTANGLE\spacefactor1000}} \def\CWEAVE{{\eightcmr CWEAVE\spacefactor1000}} \def\OSX{{OS\,X}} \def\re{\mathop{\rm Re}\nolimits} % The real part of a complex number \def\im{\mathop{\rm Im}\nolimits} % The imaginary part of a complex number \def\dollar{\char'044} % The `$' character \def\tothepower{\char'136} % The `^' character \def\onehalf{{\textstyle{{1}\over{2}}}} \def\threefourth{{\textstyle{{3}\over{4}}}} \def\endalg{\vrule height 1.4ex width .6ex depth .4ex} % Rectangular bullet \def\ie{i.\thinspace{e.}~\ignorespaces} \def\eg{e.\thinspace{g.}~\ignorespaces} \let\,\thinspace %% \def\subsection[#1]{\goodbreak\noindent{\it #1}\par\nobreak\noindent} % % Define a handy macro for listing the steps of an algorithm. % \newdimen\aitemindent \aitemindent=26pt \newdimen\aitemleftskip \aitemleftskip=36pt \def\aitem[#1]{\smallbreak\noindent\hbox to 10pt{}% \hbox to\aitemindent{\bf #1\hfill}% \hangindent\aitemleftskip\ignorespaces} % % Define a handy macro for bibliographic references. % \newdimen\refitemindent \refitemindent=18pt \def\refitem[#1]{\smallbreak\noindent% \hbox to\refitemindent{[#1]\hfill}% \hangindent\refitemindent\ignorespaces} % % Define a handy macro for nicely typeset variable descriptions. % \newdimen\varitemindent \varitemindent=100pt \def\varitem[#1]#2{\smallbreak\noindent\hbox to 20pt{}% \hbox to\varitemindent{#1\hfill}% \hangindent 120pt\ignorespaces#2\par} % % Define a handy macro for the list of program revisions. % \newdimen\citemindent \citemindent=80pt \newdimen\citemleftskip \citemleftskip=90pt \def\citem[#1]{\smallbreak\noindent\hbox to 10pt{}% \hbox to\citemindent{\bf #1\hfill}% \hangindent\citemleftskip\ignorespaces} \def\citindent{\smallbreak\noindent\hbox to 10pt{}% \hbox to\citemindent{\hfil}% \hangindent\citemleftskip\ignorespaces} % % Define the \beginvrulealign and \endvrulealign macros as described in % Donald Knuth's The TeXbook, Appendix D: Dirty Tricks. These macros are % used in typesetting nicely looking tables. % \def\beginvrulealign{\setbox0=\vbox\bgroup} \def\endvrulealign{\egroup % now \box0 holds the entire alignment \setbox0=\vbox{\setbox2=\hbox{\vrule height\ht0 depth\dp0 width0pt} \unvbox0 \setbox0=\lastbox % now \box0 is the bottom row \nointerlineskip \copy0 % put it back \global\setbox1=\hbox{} % initialize box that will contain rules \setbox4=\hbox{\unhbox0 % now open up the bottom row \loop \skip0=\lastskip \unskip % remove tabskip glue \advance\skip0 by-.4pt % rules are .4 pt wide \divide\skip0 by 2 \global\setbox1=\hbox{\hskip\skip0\vrule\hskip\skip0 \unhbox2\unhbox1}% \setbox2=\lastbox % remove alignment entry \ifhbox2 \setbox2=\hbox{\kern\wd2}\repeat}}% \hbox{\rlap{\box0}\box1}} % superimpose the alignment on the rules \datethis @*Introduction. \vskip 120pt \centerline{\twentycmcsc MagBragg} \vskip 20pt \centerline{A simulator of nonlinear magneto-optical Bragg gratings} \vskip 2pt \centerline{(Version \version\ of \lastrevdate)} \vskip 10pt \centerline{Written by Fredrik Jonsson} \vskip 80pt \noindent This \CWEB\footnote{${}^\dagger$}{For information on the \CWEB\ programming language by Donald E.~Knuth, as well as samples of \CWEB\ programs, see \.{http://www-cs-faculty.stanford.edu/\~\ \kern -5pt knuth/cweb.html}. For general information on literate programming, see \.{http://www.literateprogramming.com}.} computer program calculates reflection and transmission spectra of nonlinear magneto-optical Bragg gratings, in a stratified geometry where the material parameters vary only in one Cartesian coordinate. The \magbragg\ program also simulates the propagation of the electromagnetic field of an optical wave as it traverses a magneto-optical Bragg grating, in linear as well as nonlinear optical regimes. Strictly speaking, in a linear-optical domain a forward algorithm would just as fine as a backward one; however, for nonlinear optical problems, it often (as in this particular case) turns out that it is easier to compute the inverse problem, that is to say, to compute the input that corresponds to a certain given output. This is the case for, for example, optical bistability, where a given input intensity and ellipticity of the input optical wave for certain configurations correspond to a multiple-valued optical output. This means that we are not always on safe ground when it comes to the evaluation of output as function of input; meantime it makes perfectly sense to calculate the single-valued input as function of optical output. This program, in particular, is formulated in terms of the inverse problem, and hence the input parameters to the program are partly given in terms of the optical output of the magneto-optical Bragg grating. The algorithm behind the program was published as F.~Jonsson and C.~Flytzanis, Physical Review Letters {\bf 96}, 063902 (2006). \bigskip \noindent Copyright \copyright\ Fredrik Jonsson, 2002--2007. All rights reserved. \vfill @*The CWEB programming language. For the reader who might not be familiar with the concept of the \CWEB\ programming language, the following citations hopefully will be useful. For further information, as well as freeware compilers for compiling \CWEB\ source code, see \.{http://www.literateprogramming.com}. \bigskip {\narrower\narrower\narrower\narrower\eightcmssqi\noindent I believe that the time is ripe for significantly better documentation of programs, and that we can best achieve this by considering programs to be works of literature. Hence, my title: `Literate Programming.' Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do. The practitioner of literate programming can be regarded as an essayist, whose main concern is with exposition and excellence of style. Such an author, with thesaurus in hand, chooses the names of variables carefully and explains what each variable means. He or she strives for a program that is comprehensible because its concepts have been introduced in an order that is best for human understanding, using a mixture of formal and informal methods that reinforce each other. \smallskip {\eightcmssq --\,Donald Knuth,} {\eightcmssqi The CWEB System of Structured Documentation} {\eightcmssq (Addison-Wesley, Massachusetts, 1994)} } \bigskip {\narrower\narrower\narrower\narrower\eightcmssqi\noindent The philosophy behind CWEB is that an experienced system programmer, who wants to provide the best possible documentation of his or her software products, needs two things simultaneously: a language like \TeX\ for formatting, and a language like C for programming. Neither type of language can provide the best documentation by itself; but when both are appropriately combined, we obtain a system that is much more useful than either language separately. The structure of a software program may be thought of as a `WEB' that is made up of many interconnected pieces. To document such a program we want to explain each individual part of the web and how it relates to its neighbors. The typographic tools provided by \TeX\ give us an opportunity to explain the local structure of each part by making that structure visible, and the programming tools provided by languages like C make it possible for us to specify the algorithms formally and unambiguously. By combining the two, we can develop a style of programming that maximizes our ability to perceive the structure of a complex piece of software, and at the same time the documented programs can be mechanically translated into a working software system that matches the documentation. Besides providing a documentation tool, CWEB enhances the C language by providing the ability to permute pieces of the program text, so that a large system can be understood entirely in terms of small sections and their local interrelationships. The CTANGLE program is so named because it takes a given web and moves the sections from their web structure into the order required by C; the advantage of programming in CWEB is that the algorithms can be expressed in ``untangled'' form, with each section explained separately. The CWEAVE program is so named because it takes a given web and intertwines the \TeX\ and C portions contained in each section, then it knits the whole fabric into a structured document. \smallskip {\eightcmssq --\,Donald Knuth, ``Literate Programming'', in} {\eightcmssqi Literate Programming} {\eightcmssq (CSLI Lecture Notes, Stanford, 1992)} } @*Theory of nonlinear magneto-optical Bragg gratings. The algorithm used for the simulation is based on the inverse problem of nonlinear optical gratings, where the transmitted optical field is used as input to the algorithm, which successively calculates the intra-grating optical fields backwards through the structure, finally ending up with the corresponding incident field. The analysis is here for the sake of simplicity restricted to infinite plane waves under assumption of the slowly varying envelope approximation. The conventions of notation for the discrete layers in the structure of analysis are shown in Fig.~1, in which $N-1$ layers of nonlinear magneto-optical media are separated by their boundaries at $z=z_1,\ldots,z_N$. \bigskip \centerline{\epsfxsize=86mm\epsfbox{figures/geom/geom.1}}\smallskip {\narrower\narrower\noindent{\bf Figure 1.} The geometry of the discretized model of the magneto-optical Bragg grating, in the Faraday configuration with the static magnetic ${\bf B}_0=B^z_0{\bf e}_z$ applied in the direction of wave propagation. The grating consists of $N$ optically homogeneous layers with $N+1$ discrete interfaces located at spatial coordinates $z_k$, for $k=1,2,\ldots,N$, with the optical properties of each layer described by the optical susceptibility tensors $\chi^{\rm ee}_{ij}$ and $\chi^{\rm eeee}_{ijkl}$ and their magneto-optical counter-parts $\chi^{\rm eem}_{ijk}$ and $\chi^{\rm eeeem}_{ijklm}$.\par} \bigskip @ Discretization of the problem. In each homogeneous layer $z_k}\hfill\break First properly working version of the \magbragg\ program, written in plain (\ANSI-conformant) \CEE. \citem[2002-11-15]{[v.1.1]} \.{}\hfill\break Minor changes to the blocks of the program for the generation of reflection spectra, providing data for a talk at the MRS 2002 Fall Meeting [F.~Jonsson and C.~Flytzanis, {\sl Theoretical model for magneto-optical Bragg gratings}, Talk O4.7 presented at the 2002 Materials Research Society (MRS) Fall Meeting, Boston, United States (December 2--6, 2002)]. \citem[2003-02-18]{[v.1.2]} \.{}\hfill\break Modified the part of the program that writes the spatial optical field distribution along the grating to file, so that both forward and backward left and right circularly polarized components of the propagating fields are written to file (using the \.{--fieldevolution} command line option). \citem[2003-02-25]{[v.1.3]} \.{}\hfill\break Transferred all source code of the \magbragg\ program from \CEE\ to \CWEB. For information on the \CWEB\ programming language, see \.{http://www.literateprogramming.com}. \citem[2003-04-18]{[v.1.4]} \.{}\hfill\break Added the \.{--modifylayer} option, enabling the user to manually modify an arbitrary layer of the grating structure in linear as well as nonlinear optical parameters, or modifying the layer thickness. \citem[2003-04-28]{[v.1.5]} \.{}\hfill\break Added the \.{--intensityevolution} option. \citem[2003-07-15]{[v.1.6]} \.{}\hfill\break Added some points in the documentation regarding the philosophy behind creating two-dimensional plots from topological graphs of Stokes-parameter hypersurfaces. \citem[2003-07-22]{[v.1.7]} \.{}\hfill\break Added the possibility of specifiying whether the electrical field displacement or Stokes parameters should be written to file, when saving the intra-grating field distribution via the \.{--fieldevolution} command line option. \citem[2003-07-23]{[v.1.8]} \.{}\hfill\break Changed the reference phase of the calculated, final intra-grating optical field, so that the main axis of the polarization ellipse always is directed along the $x$-axis (corresponding to $S_2=0$ in a Stokes parameter description) at the beginning of the grating, at $z=0$. (The naturally appearing reference phase is relative the output field, at the end of the grating, since $z=L$ is the spatial starting point in the inverse algorithm.) \citem[2003-08-04]{[v.1.9]} \.{}\hfill\break Added the \.{--normalize\_length\_to\_um} option, which causes the program to write spatial distances in micrometers instead of meters. Useful for pre-normalizing data prior to importing it into programs for making graphs of the spatial intra-grating distribution of intensity or polarization state. Also added the \.{--normalize\_intensity} option, which causes the program to write the intensity-related Stoke parameter $S_0(z)$ as the quote with the input intensity instead, as $S_0(z)/S_0(0)$. \citem[2003-08-07]{[v.1.10]} \.{}\hfill\break Added the \.{--intensityspectrumfile} option, to save a regular intensity spectrum as function of wavelength, and not only just the complex reflection and transmission spectra. Using this option, the character string following it will be used as the base filename for the generated intensity reflection spectrum, which will be named $\langle$basename$\rangle${\tt{.irsp.dat}}, and the intensity transmission spectrum, which will be named $\langle$basename$\rangle${\tt{.itsp.dat}}. The format of these files are simply that the first column is the vacuum wavelength in nanometers, and the second column the reflection or transmission coefficients. In addition to these two files, an additional file $\langle$basename$\rangle${\tt{.chec.dat}} will be generated, containing the sum of the respective reflection and transmission coefficients. Ideally, the second column of this file should be identically one; any deviation from this is an artefact of the limited numerical precision in the simulation, and can be taken as a measure on the correctness of the obtained data. \citem[2003-08-19]{[v.1.11]} \.{}\hfill\break Added the \.{--normalize\_ellipticity} option, which switch the program to writing the normalized ellipticity $S_3/S_0$ (with a numerical value between $-1$ and~$1$) instead of the third Stokes parameter, whenever it is to be written to disk. Also added the \.{--scale\_stokesparams} $\langle a\rangle$ option, which at the stage of saving the Stokes parameters to disk divides the sets $(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 scalefactor $\langle a\rangle$ prior to writing them to disk. This is typically a good thing to do if the program that is to post-analyze the generated data has a poor way of handling large numbers (typically larger than $\sim 10^{14}$ for the squared amplitudes of the components of the electric field). \citem[2003-08-20]{[v.1.12]} \.{}\hfill\break Modified the \.{Makefile} to provide a somewhat more intelligent check on which files that need to be updated on compilation. Also updated section five, {\it Compiling the source code}, of the documentation of the program. \citem[2003-08-23]{[v.1.13]} \.{}\hfill\break Added a check in the blocks that saves the full grating structure to file, so that the program now fully recognizes the \.{--normalize\_length\_to\_um} option. \citem[2003-10-06]{[v.1.14]} \.{}\hfill\break Added a few clarifying paragraphs on the conventions used for the magneto-optical material parameters and the exact conventions for the circularly polarized modes as here used. \citem[2003-12-10]{[v.1.15]} \.{}\hfill\break Added a few clarifying paragraphs on the scaling of the Stokes parameters that are written to file after the finished calculations. As a default, and as a matter of convention in electrodynamics in \SI\ units, all Stokes parameters are given in ${\rm V}^2/{\rm m}^2$, through their definition. For example, the incident field (which is calculated by the program in this inverse formulation of the problem) is expressed in terms of the Stokes parameters as $$ \eqalign{ S_0&=\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2,\qquad S_1=2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr S_3&=\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2,\qquad S_2=2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr } $$ However, the direct interpretation of these quantities in terms of squared Volts per square metres is sometimes somewhat inconvenient; therefore, those parameters can be scaled to give an interpretation of the intensity (in regular \SI\ units measured in Watts per square metres), as $S'_k=(\varepsilon_0 c/2)S_k$, or explicitly $$ \eqalign{ S'_0&=(\varepsilon_0 c/2) [\vert E^{\rm f}_{0_+}\vert^2+\vert E^{\rm f}_{0_-}\vert^2],\qquad S'_1=(\varepsilon_0 c/2) 2\re[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}],\cr S'_3&=(\varepsilon_0 c/2) [\vert E^{\rm f}_{0_+}\vert^2-\vert E^{\rm f}_{0_-}\vert^2],\qquad S'_2=(\varepsilon_0 c/2) 2\im[E^{{\rm f}*}_{0_+}E^{\rm f}_{0_-}].\cr } $$ In this representation, $S'_0$ is now identical to the incident intensity $I_{\rm in}$ [${\rm W}/{\rm m}^2$]. In order to have those scaled Stokes parameters $S'_k$ written to file, rather than the default ones, one convenient possibility is to use the previously added \.{--scale\_stokesparams} option, to include \.{--scale\_stokesparams 1.327209e-3} at the command line when invoking the program. This numerical value of the scaling is obtained from $$ \eqalign{ \varepsilon_0 c/2 &=(8.854187817\ldots\times 10^{-12}\ {\rm F}/{\rm m}) \times(2.99792458\times 10^8\ {\rm m}/{\rm s})/2\cr &\approx 1.327209\times 10^{-3}\ {\rm F}/{\rm s}.\cr } $$ In regular \SI\ units as here used, the physical dimension of the quantity $\varepsilon_0 c/2$ is $[({\rm A}\cdot{\rm s})/({\rm V}\cdot{\rm m})] \cdot[{\rm m}/{\rm s}]=[{\rm A}/{\rm V}]$, so the physical dimension of $(\varepsilon_0 c/2)S_k$ is hence $[{\rm A}/{\rm V}]\cdot[{\rm V}^2/{\rm m}^2] =[{\rm W}/{\rm m}^2]$, as expected for an intensity measure (power per unit area in the plane orthogonal to the direction of wave propagation). \citem[2003-12-10]{[v.1.16]} \.{}\hfill\break Added the \.{--intensityinfo} option, in order to track down the maximum optical intensity that is present inside (or outside) the magneto-optical grating structure. \citem[2003-12-17]{[v.1.17]} \.{}\hfill\break Added the \.{--trmtraject} option, in order to check the polarization state evolution of the transmitted light for a varying incident intensity, keeping the incident polarization state fixed. Typically, we use two-dimensional interpolation to get the trajectory of the transmitted polarization state as function of the incident light (the incident light typically being of a fixed polarization state, with a varying intensity). This trajectory can now be used as input to the \magbragg\ program in the invserse formulation of the problem, for the generation of Poincar\'e maps corresponding to cases with constant incident polarization states and varying input intensity. \citem[2004-03-10]{[v.1.18]} \.{}\hfill\break Last week in Stockholm I bought a new computer, a silvery Apple Macintosh Powerbook~G4 running Apple \OSX\ (10.3 Panther). As I recompiled the \CWEB\ source for the \magbragg\ program, still using the \GNU\ \CEE-compiler (\GCC) for the executable file, I got complaints about the definition of the \.{cabs} routine as shadowing a previously defined function. This is a complaint that I never previously had with \GCC\ under \CYGWIN\ and Windows 2000, and it is obvious that the \.{math.h} header file of \GCC\ has been slightly changed lately. However, after globally changing the routine name from \.{cabs} to \.{cdabs} (which anyway is better since the new name also indicates that it takes complex numbers in {\sl double}\/ precision as input), there were no more complaints, and the program now executes as expected in the \OSX\ environment. \citem[2004-04-23]{[v.1.19]} \.{}\hfill\break Fixed a bug in the initialization of chirped modulation of magneto-optical parameters, for which the last $z$-coordinate of the discretized grating, $z_N$, never was set. \citem[2004-04-24]{[v.1.20]} \.{}\hfill\break Added the \.{--gyroperturb} option in order to provide a way of locally manipulating and perturbing the gyration constant of the medium. This option was added since I got this idea that a perturbation introduced by external means, for example via a current carrying wire oriented orthogonally to the direction of propagation of light in the Faraday configuration, could be used for opening up a window in the transmission window of a chirped Bragg grating. The syntax of the \.{--gyroperturb} option is simply \.{--gyroperturb} $\langle z_{\rm p}\rangle$ $\langle a_{\rm p}\rangle$ $\langle w_{\rm p}\rangle$, where $\langle z_{\rm p}\rangle$ is the centre position, $\langle a_{\rm p}\rangle$ is the zero-to-peak amplitude of change of the gyration constant $g$, and $\langle w_{\rm p}\rangle$ is the corresponding full width half maximum of the perturbation. \citem[2004-04-26]{[v.1.21]} \.{}\hfill\break Added the \.{--stokesspectrum} option, so that it is possible to generate full Poincar\'e maps of the spectral properties of a magneto-optical Bragg grating. However, after having introduced this option, I get the following message from \CWEAVE: \citindent {\obeyspaces\obeylines\tt ~ cweave magbragg ~ This is CWEAVE, Version 3.64 (Web2C 7.5.2) ~ *1*3*4*5*6*7*36*37*38*55*60*67*68*70 ~ Writing the output file...*1*3*4*5*6*7*36*37*38*55*60 ~ ! Sorry, scrap/token/text capacity exceeded. (l. 2912) ~ sprintf(outfilename\_w1,"\%s\%s", ~ outfilename,".w1.dat"); ~ (That was a fatal error, my friend.) ~ make: *** [magbragg.tex] Error 1} \medskip \citindent The \CEE\ code generated by \CTANGLE\ compiles and executes perfectly, but obviously something is obstructing \CWEAVE\ to properly generating the \TeX\ code for the documentation. Most annoying. \citem[2004-05-07]{[v.1.22]} \.{}\hfill\break Added the \.{--displaysurrmedia}, which toggles if the program should write also the surrounding media to saved grating profiles or not. This is useful if one wish to just generate some part of a grating for a figure illustrating a particular refractive index distribution, cut exactly to the specified spatial interval of interest. As default, the \magbragg\ program writes also the surrounding media to the ends of the grating file, so by using this option only once at the command line forces the program to cut the grating file exactly to the specified spatial interval. The annoying compilation error from 2004-04-26 is still present, preventing me from generating the documentation. \citem[2004-07-03]{[v.1.23]} \.{}\hfill\break I am in Germany for laboratory work in Wuppertal during two weeks, and this free Saturday morning I decided to once and for all trace down and eliminate the annoying parsing error that \CWEAVE\ produces. (I am currently writing this entry at Starbucks in Cologne, being the only caf\'e in town with a non-smoking policy $\ldots$) Since this particular error seemed to stem from the block related to parsing of the command line options, and since this block anyway by now has grown over any reasonable size, I decided split it into several smaller blocks instead. Having done so, \CWEAVE\ immediately accepted the \CWEB\ source and extracted the \TeX\ source, which subsequently were compiled without any errors. It thus seems like I on April 26th must have passed some upper size limit on the source allowed in one single \CWEB\ block. Not that I really expected such a built-in constraint in \CWEB, but in some sense I can agree on that by putting some hard upper limit, one will at least force the programmer to structure the code into smaller blocks, probably increasing the readability. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 171418 bytes and 4138 lines of code. The size of the compiled executable is 70340 bytes, and the PostScript documentation is 808345 bytes (92 pages of A4 output in 10pt). \citem[2004-11-14]{[v.1.24]} \.{}\hfill\break Added the \.{--apodize} option, to be able to get rid of some unwanted Gibbs oscillations at the ends of the reflectance band of spectra generated for chirped gratings, aimed to generate nice spectra for a talk to be presented at the MRS 2004 Fall Meeting [F.~Jonsson and C.~Flytzanis, {\sl Artificially Induced Perturbations in Chirped Magneto-Optical {Bragg} Gratings}, in {\sl Magneto-Optical Materials for Photonics and Recording}, Eds.~{Koji Ando, W. Challener, R. Gambino and M. Levy}, Mater. Res. Soc. Symp. Proc. {\bf 834}, J1.8 ({Materials Research Society}, {Warrendale}, 2005)]. Also added the \.{--phasejump} option (short form \.{-j}) to allow specification of a discrete phase jump to appear in sinusoidal or chirped grating structures. In adding these options, the same error as of April 26th appeared again, in the block related to the parsing of command line options. Since this block has again grown over any reasonably readable size, I hence started to split this block into smaller \CWEB\ sub-blocks, after which there were no further complaints from \CWEAVE\ in extracting the \TeX\ documentation of the program. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 179296 bytes and 4312 lines of code. The size of the compiled executable is 74436 bytes, and the PostScript documentation is 835671 bytes (95 pages of A4 output in 10pt). \citem[2004-12-04]{[v.1.25]} \.{}\hfill\break Changed the way of output of Stokes parameters to file. Previously, the program always opened files with extensions \.{.s0.dat},$\ldots$, \.{.s3.dat} for output of the incident $S_k$ parameters (and similarly for the reflected and transmitted Stokes parameters $V_k$ and $W_k$), irregardless of the number of sampling points in intensity and ellipticity. However, for sampling of spectral characteristics we most often only encounter a simulation performed at one single intensity and ellipticity ($M_{\rm i}=1$ and $M_{\rm e}=1$), which means that, previously, twelve empty files were opened and closed for each simulation. This is now changed so that the program only opens those files for output in ``topological'' mode of operation, in which $M_{\rm i}\ge2$ and $M_{\rm e}\ge2$. Compiling the \CEE\ code with \GCC\ then caused some novel complaints using the \.{--pedantic} option, regarding the risk of using the associated file pointers uninitialized. That this complaint appear at all might be an indicator that \GCC\ is not that strict in checking the logical state of the program in which the file pointers were to be used, since I verified that there was no reason whatsoever for the warnings. The ``quick-and-dirty'' solution to get rid of the annoying and non-justified warnings was to simply initialize all file pointers to \.{NULL} at the beginning of the program. Also started to write a separate section on all command line options currently supported by \magbragg. The documentation has now for quite a while been in urgent need of such a section, since the number of options have grown quite a lot during the last year. As a start, the documentation for the \.{--grating}, \.{--phasejump}, and \.{--apodize} options was updated. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 192945 bytes and 4611 lines of code. The size of the compiled executable is 74436 bytes, and the PostScript documentation is 873757 bytes (102 pages of A4 output in 10pt). \citem[2004-12-05]{[v.1.26]} \.{}\hfill\break Added the feature that the program now uses \.{time.h} to extrapolate what the estimated time of arrival (ETA) of the simulation is. This is useful for predicting the total simulation time for large numbers of sampled layers, such in long sinusoidal or chirped gratings. The estimation is simply done via linear extrapolation as $$ t_{\rm ETA}=t_0+{{t-t_0}\over{\{\%\,{\rm finished}\}}}\times100, $$ to produce run-time messages of the form \medskip \leftskip=35mm {\obeyspaces\obeylines\tt Program execution started Sun Dec 5 20:55:27 2004 ---------------------------------------------------------------- ~...10 percent finished... ETA: Sun Dec 5 21:44:57 2004 ~...20 percent finished... ETA: Sun Dec 5 21:42:12 2004 ~...30 percent finished... ETA: Sun Dec 5 21:41:17 2004 ~...40 percent finished... ETA: Sun Dec 5 21:40:49 2004 ~...50 percent finished... ETA: Sun Dec 5 21:40:33 2004 ~...60 percent finished... ETA: Sun Dec 5 21:40:20 2004 ~...70 percent finished... ETA: Sun Dec 5 21:40:12 2004 ~...80 percent finished... ETA: Sun Dec 5 21:40:05 2004 ~...90 percent finished... ETA: Sun Dec 5 21:40:01 2004 ~...done. Elapsed execution time: 2644 s ---------------------------------------------------------------- Program execution closed Sun Dec 5 21:39:31 2004\par} \leftskip=0mm \medskip \citindent Also wrote documentation on command-line specifications of chirped gratings, and cleaned up the declarations of local variables somewhat. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 203691 bytes and 4830 lines of code. The size of the compiled executable is 74532 bytes, and the PostScript documentation is 898974 bytes (105 pages of A4 output in 10pt). \citem[2004-12-11]{[v.1.27]} \.{}\hfill\break Added two schematic figures to the documentation on the discretization of the grating. \citem[2005-04-22]{[v.1.28]} \.{}\hfill\break Removed an unused block in the code for saving spectra to file, after having thoroughly checked that it would have no affect on the backward compatibility of the program to earlier data generated. Also increased the numerical precision of the data written to file for the intensity reflection and transmission spectra, which now yields \.{\%-10.8f} in floating point conversion as conforming to \ANSICEE. \citem[2005-04-28]{[v.1.29]} \.{}\hfill\break Added four blocks of text in the documentation of command line options. \citem[2005-06-08]{[v.1.30]} \.{}\hfill\break In Stockholm for two months. Added the standard \CEE\ library function |fflush()| for enforcement in writing of all buffered calculated data to file. This in order to be able to follow the process of calculation more direct by file inspection. When executing \magbragg\ under the new distribution of \CYGWIN\ for Windows~XP, the block for the displaying of status of calculation suddenly behaves odd, showing estimated execution times well below any reasonable estimated time of arrival, and also going well beyond the maximum 100 percent in relative execution progress. This will have to be checked, and has never previously appeared when compiling with \GCC, neither under Apple \OSX (BSD), nor under \CYGWIN. \citem[2005-08-10]{[v.1.31]} \.{}\hfill\break Back in Southampton again with my family after a hot summer. Wrote the code for the |strip_away_path()| routine originally for the \poincare\ program and immediately decided to adopt the code also into the \magbragg\ program in order to finally solve the problem with long path strings that appear in the program name string whenever poincare is called with an explicit path specified at the command line. The call to the |strip_away_path()| routine is located in the beginning of the block for command line parsing. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 219666 bytes and 5172 lines of code. The size of the compiled (\CYGWIN) executable is 96647 bytes, and the PostScript documentation is 967813 bytes (112 pages of A4 output in 10pt). \citem[2005-08-11]{[v.1.32]} \.{}\hfill\break Cleaned up the blocks for displaying on-screen help messages. Wrote two routines |hl()| and |fhl()| to assist a coherent style in displaying help on command-line options. \citem[2005-08-19]{[v.1.33]} \.{}\hfill\break Fixed two remaining bugs in the |hl()| and |fhl()|, in which \GCC\ under \OSX\ this evening complained that long unsigned integers were sent to standard terminal output using the regular integer conversion of standard \CEE. This warning did not show as the code was compiled with \GCC\ under \CYGWIN, hence there seem to be some discrepancy between different ports of the otherwise reliable compilator. \citem[2005-09-15]{[v.1.34]} \.{}\hfill\break Corrected an error in the documentation of the options concerning specifications of chirped sinusoidal grating structures. The chirp parameter is now properly defined and described by example. \citem[2005-12-31]{[v.1.35]} \.{}\hfill\break The theoretical description of the algorithm behind the solving of the inverse problem in the \magbragg\ program is included in an article which today has been accepted for publication in Physical Review Letters. Added a section on the theoretical basis for the algorithm behind the program, deriving the algorithm from the electromagnetic wave equation in a manner similar to the description which soon will appear in the published article. \citem[2006-01-22]{[v.1.36]} \.{}\hfill\break Added a section on the Butcher and Cotter convention of degeneracy factors in nonlinear optics, picked from my {\sl Lecture Notes on Nonlinear Optics} from the course I gave at the Royal Institute of Technology in 2003. Also edited the section on the theoretical basis for the algorithm of calculation and added a figure describing the representation of the polarization state on the Poincar\'e sphere. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 252108 bytes and 5937 lines of code. The size of the compiled (\OSX) executable is 78808 bytes, and the PostScript documentation is 1651977 bytes (122 pages of A4 output in 10pt). \citem[2006-01-24]{[v.1.37]} \.{}\hfill\break Added a significant number of comments on the use of variables and their initialization. Also cleaned up and added more instructive text on the actual compilation of the \CWEB\ source code. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 261933 bytes and 6086 lines of code. The size of the compiled (\OSX) executable is 78828 bytes, and the PostScript documentation is 1673601 bytes (125 pages of A4 output in 10pt). \citem[2006-02-09]{[v.1.38]} \.{}\hfill\break As I now for a longer time of period have sketched on implementing the exact methodology of solution for the waves inside the homogeneous elements of the discretized medium, I today added the first sections on the theoretical part of a rigorous theory of wave propagation. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 305905 bytes and 7095 lines of code. The size of the compiled (\OSX) executable is 88002 bytes, and the PostScript documentation is 1778021 bytes (135 pages of A4 output in 10pt). \citem[2006-02-11]{[v.1.39]} \.{}\hfill\break Added two sections on how the amplitude evolution in the rigorous theory of wave propagation actually can be reduced to the evaluation of an elliptic function of the standard form $$ \int^{v(\zeta)}_{v(\zeta_0)}{{dv} \over{({a_4v^4+a_3v^3+a_2v^2+a_1v+a_0})^{1/2}}}, $$ with its solution $v(z)$ expressed in terms of the Weierstrass elliptic function $\wp(\zeta;g_2,g_3)$ with the invariants $g_2$ and $g_3$ explicitly expressed in terms of $a_0$, $a_1$, $a_2$, $a_3$, and $a_4$. \citem[2006-03-13]{[v.1.40]} \.{}\hfill\break After having spent some considerable time trying to verify that the integral equation $$ \int^{v(\zeta)}_{v(\zeta_0)}{{dv} \over{({a_4v^4+4a_3v^3+6a_2v^2+4a_1v+a_0})^{1/2}}}, $$ which naturally appear in the rigorous theory of cross-phase modulation in nonlinear magneto-optical media, really has the explicit solution $$ v(\zeta)=v_0+ {{\sqrt{f(v_0)}\wp'(\zeta)+{\textstyle{{1}\over{2}}}f'(v_0) [\wp(\zeta)-{\textstyle{{1}\over{24}}}f''(v_0)] +{\textstyle{{1}\over{24}}}f(v_0)f'''(v_0)} \over{2[\wp(\zeta)-{\textstyle{{1}\over{24}}}f''(v_0)]^2 -{\textstyle{{1}\over{48}}}f(v_0)f^{\rm (iv)}(v_0)}}. $$ with quartic invariants $$ g_2\equiv a_0a_4-4a_1a_3+3a^2_2,\qquad g_3\equiv \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 =a_0a_2a_4+2a_1a_2a_3-a^3_2-a_0a^2_3-a^2_1a_4, $$ I today realized that the first edition of E.~T. Whittaker's {\sl A Course of Modern Analysis} (Cambridge University Press, Cambridge, 1902) actually has a printing error in one of the terms in the denominator of the solution. This error has obviously been fixed in later editions of the book, for example in E.~T.~Whittaker and G.~N.~Watson, {\sl A Course of Modern Analysis}, 4th Reprinted Edn. (Cambridge University Press, Cambridge, 1996), ISBN 0-521-58807-3, but it caused be a considerable nuisance before I was able to track the error down. The verification of the solution was checked using the following blocks of MapleV code: \medskip \leftskip=30mm {\obeyspaces\obeylines\tt restart: f:=a[0]*v{\tothepower}4+4*a[1]*v{\tothepower}3+6*a[2]*v{\tothepower}2% +4*a[3]*v+a[4]; g[2]:=a[0]*a[4]-4*a[1]*a[3]+3*a[2]{\tothepower}2; g[3]:=a[0]*a[2]*a[4]+2*a[1]*a[2]*a[3]-a[2]{\tothepower}3-a[0]*a[3]% {\tothepower}2-a[1]{\tothepower}2*a[4]; df[0]:=eval(f,v=v0): df[1]:=eval(diff(f,v{\dollar}1),v=v0): df[2]:=eval(diff(f,v{\dollar}2),v=v0): df[3]:=eval(diff(f,v{\dollar}3),v=v0): df[4]:=eval(diff(f,v{\dollar}4),v=v0): tmp[1]:=sqrt(df[0])*WeierstrassPPrime(z,g[2],g[3]): tmp[2]:=(1/2)*df[1]*(WeierstrassP(z,g[2],g[3])-(1/24)*df[2]): tmp[3]:=(1/24)*df[0]*df[3]: tmp[4]:=2*(WeierstrassP(z,g[2],g[3])-(1/24)*df[2]){\tothepower}2: tmp[5]:=(1/48)*df[0]*df[4]: v:=v0+(tmp[1]+tmp[2]+tmp[3])/(tmp[4]-tmp[5]): p:=a[0]*v{\tothepower}4+4*a[1]*v{\tothepower}3+6*a[2]*v{\tothepower}2% +4*a[3]*v+a[4]: testfunc:=(diff(v,z)){\tothepower}2-p: testfunc:=simplify(testfunc);\par} \leftskip=0mm \medskip \citindent As this result was the only missing link in the formulation of an explicit solution to the wave propagation problem in nonlinear magneto-optical media, taking into account also weakly phase-mismatched nonlinear source terms, the only task remaining now is to formulate the algorithm for solving the inverse problem using this more stringent method. \citem[2006-03-20]{[v.1.41]} \.{}\hfill\break Added a few paragraphs on the rigorous theory of wave propagation, clarifying the role of the constant of integration $\Gamma$ and its calculation from the phase of the transmitted field and the amplitude-related invariants of propagation. This now interconnects more naturally to the formulation of the wave propagation as an inverse problem, being the natural mode of solving for reflectances as well as transmittances. I also took the opportunity to write an email to MathWorld, pointing out that their solution to the Weierstrass form of the integral equation, \.{http://mathworld.wolfram.com/EllipticIntegral.html}, Eqs. (51)--(56), actually contains errors; of course I could not resist the opportunity to provide the MapleV blocks I used for my own verification, rather than using Mathematica code! \citem[2006-05-01]{[v.1.42]} \.{}\hfill\break Added support for initialization of the grating structure as a fractal set, of the Cantor fractal type. This possibility is in the program now accessed via the command-line option \.{--grating fractal cantor [options]}. The initialization is done using recursion with the function |init_cantor_fractal_grating()|, which was finished today. As of today, the \CWEB\ source for the \magbragg\ program (source file \.{magbragg.w}) comprises 335649 bytes and 7753 lines of code. The size of the compiled (\CYGWIN) executable is 95217 bytes, and the PostScript documentation is 1874643 bytes (148 pages of A4 output in 10pt). \citem[2007-01-10]{[v.1.43]} \.{}\hfill\break Seefeld, Austria. Midnight. Cleaned up the theoretical part preceeding the algorithm of computation and merged all bibliographical references into one separate section at the end of the document. \citem[2011-12-18]{[v.1.44]} \.{}\hfill\break Updated \.{Makefile}:s for the generation of figures. Also corrected a rather stupid way of removing preceeding paths of file names. @*Compiling the source code. The program is written in \CWEB, generating \ANSICEE\ (ISO C90) conforming source code and documentation as plain \TeX-source, and is to be compiled using the sequences as outlined in the \.{Makefile} listed below. \bigskip {\obeylines\obeyspaces\tt \# \# Makefile designed for use with ctangle, cweave, gcc, and plain TeX. \# \# The CTANGLE program converts a CWEB source document into a C program which \# may be compiled in the usual way. The CWEAVE program converts the same CWEB \# file into a TeX file that may be formatted and printed in the usual way. \# \# Copyright (C) 2002-2006, Fredrik Jonsson \# CTANGLE = ctangle CWEAVE = cweave CC = gcc CCOPTS = -O2 -Wall -ansi -std=iso9899:1990 -pedantic LNOPTS = -lm TEX = tex DVIPS = dvips DVIPSOPTS = -ta4 -D1200 METAPOST = mp ~ ~ all: magbragg magbragg.ps ~ ~ magbragg: magbragg.o ~ \$(CC) \$(CCOPTS) -o magbragg magbragg.o \$(LNOPTS) ~ ~ magbragg.o: magbragg.w ~ \$(CTANGLE) magbragg ~ \$(CC) \$(CCOPTS) -c magbragg.c ~ ~ magbragg.ps: magbragg.dvi ~ \$(DVIPS) \$(DVIPSOPTS) magbragg.dvi -o magbragg.ps ~ ~ magbragg.dvi: magbragg.w ~ make -C figures/ ~ \$(CWEAVE) magbragg ~ \$(TEX) magbragg.tex ~ ~ clean: ~ make clean -ik -C figures/ ~ -rm -Rf magbragg *~ *.c *.o *.exe *.dat *.tgz *.pdf ~ -rm -Rf *.tex *.aux *.log *.toc *.idx *.scn *.dvi *.ps ~ ~ archive: ~ make -ik clean ~ tar --gzip --directory=../ -cf magbragg.tgz magbragg } \bigskip This \.{Makefile} essentially executes two major calls. First, the \CTANGLE\ program parses the \CWEB\ source document \.{magbragg.w} to extract a \CEE\ source file \.{magbragg.c} which may be compiled in the usual way using any \ANSICEE\ conformant compiler. The output source file includes \.{\#line} specifications so that any debugging can be done conveniently in terms of the original \CWEB\ source file. Second, the \CWEAVE\ program parses the same \CWEB\ source file to extract a plain \TeX\ source file \.{magbragg.tex} which may be compiled in the usual way. It takes appropriate care of typographic details like page layout and the use of indentation, italics, boldface, and so on, and it supplies extensive cross-index information that it gathers automatically. After having executed \.{make} in the same catalogue where the files \.{magbragg.w} and \.{Makefile} are located, one is left with an executable file \.{magbragg}, being the ready-to-use compiled program, and a PostScript file \.{magbragg.ps} which contains the full documentation of the program, that is to say the document you currently are reading. Notice that on platforms running Windows NT, Windows 2000, Windows ME, or any other operating system by Microsoft, the executable file will instead automatically be called \.{magbragg.exe}. This convention also applies to programs compiled under the \UNIX-like environment \CYGWIN. @*Running the program. The program is entirely controlled by the command line options supplied when invoking the program. Since the command line for some problems tend to be quite lengthy, since all material parameters and optical field inputs to the program must be specified, it is convenient to put blocks for the program calls into a Makefile, which makes it easy to maintain a structure in the simulations, as well as ensuring traceability of the steps in the generation of graphs. As an example of such a call, the following block is included as an example in the enclosed Makefile: \bigskip {\obeyspaces\obeylines\tt ~ testsimulation: ~ @@for g in 0.0 1.0 2.0; do {\char'134} ~ ./magbragg --verbose --outputfile fig1-\$\$g {\char'134} ~ --spectrumfile fig1-\$\$g.rsp.dat {\char'134} ~ --gratinglength 7.326376e-6 -N 1800 {\char'134} ~ --grating sinusoidal n 2.0550 0.1250 366.3188e-9 {\char'134} ~ g \$\$g'e-3' 0.0 1.0 {\char'134} ~ pe 0.0 0.0 1.0 {\char'134} ~ pm 0.0 0.0 1.0 {\char'134} ~ qe 0.0 0.0 1.0 {\char'134} ~ qm 0.0 0.0 1.0 {\char'134} ~ --refindsurr 2.0550 -M 2000 {\char'134} ~ --lambdastart 1300.0e-9 --lambdastop 1700.0e-9 {\char'134} ~ --trmintensity 7.0e8 7.0e8 1 {\char'134} ~ --trmellipticity 0.0 0.0 1 ;{\char'134} ~ done } In the following sections, a complete listing of all command line options accepted by the \magbragg\ program is presented. @*Specifying grating types. The \magbragg\ program currently accepts specifications of three different main types of gratings: stepwise gratings, sinusoidal gratings, and chirped sinusoidal gratings. The stepwise gratings are simply stacks of homogeneous layers, stacked to form a grating, and these gratings can be composed of two or more different materials. As an important subclass of the stepwise gratings, the binary gratings are probably the most important ones, being composed of alternating layers of only two types of media. Throughout the program, the following definitions of the material parameters apply, to the refractive index $n(z)$, gyration coefficient $g(z)$, nonlinear optical parameters $p^{({\rm e})}(z)$ and $q^{({\rm e})}(z)$, and nonlinear magneto-optical parameters $p^{({\rm m})}(z)$ and $q^{({\rm m})}(z)$, $$ \eqalign{ |n[k]|&=n_k=[1+\chi^{({\rm ee})}_{xx}]^{1/2},\cr |g[k]|&=g_k=i\chi^{({\rm eem})}_{xyz} B^z_0 /(2 n_k),\cr |pe[k]|&=p^{({\rm e})}_k =\chi^{\rm eeee}_{xxxx}-\chi^{\rm eeee}_{xyyx},\cr |qe[k]|&=q^{({\rm e})}_k =\chi^{\rm eeee}_{xxxx}+\chi^{\rm eeee}_{xyyx},\cr |pm[k]|&=p^{({\rm m})}_k =i(\chi^{\rm eeeem}_{xyyyz}-\chi^{\rm eeeem}_{xxxyz})B^z_0,\cr |qm[k]|&=q^{({\rm m})}_k =i(\chi^{\rm eeeem}_{xyyyz}+\chi^{\rm eeeem}_{xxxyz})B^z_0,\cr } $$ where |n[k]|, |g[k]|, |pe[k]|, |qe[k]|, |pm[k]|, |qm[k]| denote the variables as internally used in the \magbragg\ program to store the corresponding material data for the $N-1$ homogeneous segments $z_k\le z@; @@; @@; @@; @@; int main(int argc, char *argv[]) { @@; @@; @@; @@; @@; @@; @@; @@; @@; @@; @@; @@; @@; return(SUCCESS); } @ The standard \ANSICEE\ libraries included in this program are:\par \varitem[\.{math.h}]{For access to mathematical functions.} \varitem[\.{time.h}]{For time stamps and estimation of computation time.} \varitem[\.{stdio.h}]{For file access and any block involving |fprintf|.} \varitem[\.{stdlib.h}]{For memory allocation, |malloc|, |exit|, |free| etc.} \varitem[\.{string.h}]{For string manipulation, |strcpy|, |strcmp| etc.} \varitem[\.{ctype.h}]{For access to the |isalnum| routine.} @= #include #include #include #include #include #include @ Global definitions. There are just a few global definitions present in the \magbragg\ program:\par \varitem[\.{VERSION}]{The current program revision number.} \varitem[\.{COPYRIGHT}]{The copyright banner.} \varitem[\.{SUCCESS}]{The return code for successful program termination.} \varitem[\.{FAILURE}]{The return code for unsuccessful program termination.} \varitem[\.{NCHMAX}]{The maximum number of characters allowed in strings for storing file names, including path.} @= #define VERSION "1.43" #define COPYRIGHT "Copyright (C) 2002-2007, Fredrik Jonsson" #define SUCCESS (0) #define FAILURE (1) #define NCHMAX (256) @ Data structure definitions. The |dcomplex| data structure contains real and imaginary parts in double precision, and is also the basic data structure used for the allocation of complex valued vectors of double precision. @= typedef struct DCOMPLEX {double r,i;} dcomplex; @ Declaration of global variables. The only global variables allowed in my programs are |optarg|, which is a pointer to the the string of characters that specified the call from the command line, and |progname|, which simply is a pointer to the string containing the name of the program, as it was invoked from the command line. @= extern char *optarg; char *progname; @ Listing of subroutines called by the main program. @= @@; @@; @@; @@; @@; @@; @@; @*Declaration of local variables of the main program. In \CWEB\ one has the option of adding variables along the program, for example by locally adding temporary variables related to a given sub-block of code. However, my philosophy in the \magbragg\ program is to keep all variables of the |main| section collected together, so as to simplify tasks as, for example, tracking down a given variable type definition. [ADD A LIST OF VARIABLE DESCRIPTIONS WITH THE 'VARITEM' MACRO] \varitem[|somevariable|]{Some description of |somevariable|.} @= @@; @