root/branches/newmole/source/cdinit.cpp

Revision 1800, 7.3 kB (checked in by rjrw, 11 months ago)

Merged from trunk r1779:1799.

  • Property svn:eol-style set to native
Line 
1/* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2 * others.  For conditions of distribution and use see copyright notice in license.txt */
3/*cdInit routine to initialize variables, called at start of calculation */
4/*cdExit exit handler to terminate calculation, called at end of calculation */
5/* unset EXTERN so that everything is defined here */
6#define EXTERN 
7#include "cddefines.h"
8
9/* used for punching map*/
10FILE *ioMAP = NULL;
11
12/* external ZeroNum used to div by zero
13 * ok here since never changed*/
14const double ZeroNum = 0.;
15
16/* this must go here since it defines NTA needed for other lines*/
17#include "taulines.h"
18
19/* following is true extern in taulines.h */
20long nWindLine = NWINDDIM;
21
22/* set number of CO rotation levels to default, 20 as set in taulines.h */
23long int nCORotate = NCOROTATE;
24
25/* say that space not allocated yet */
26bool lgCORotateMalloc = false;
27
28#include "abund.h"
29#include "atmdat.h"
30#include "atoms.h"
31#include "atomfeii.h"
32#include "assertresults.h"
33#include "broke.h"
34#include "ca.h"
35#include "called.h"
36#include "carb.h"
37#include "cddrive.h"
38/* this will be set true when cdInit is called.  The definition is in cdInit.
39* Other routines will check that this is true when they are called,
40* to verify that cdInit was called first */
41bool lgcdInitCalled=false;
42#include "co.h"
43#include "colden.h"
44#include "conv.h"
45#include "continuum.h"
46#include "coolheavy.h"
47#include "dense.h"
48#include "doppvel.h"
49#include "dynamics.h"
50#include "elementnames.h"
51#include "embesq.h"
52#include "extinc.h"
53#include "fe.h"
54#include "fudgec.h"
55#include "geometry.h"
56#include "grainvar.h"
57#include "grid.h"
58#include "h2.h"
59#include "h2_priv.h"
60bool lgH2_READ_DATA = false;
61#include "he.h"
62#include "heavy.h"
63#include "hextra.h"
64#include "hmi.h"
65#include "hydrogenic.h"
66/* this is set true once space malloced, then never change
67* number of levels again with hydrogenic command,
68* also to make sure MALLOC only happens one time  */
69bool lgHydroMalloc = false;
70/*  */
71#include "hyperfine.h"
72#include "input.h"
73#include "ionbal.h"
74#include "iso.h"
75#include "iterations.h"
76#include "lines.h"
77/* these are the definitions of the line save arrays in lines.h */
78LinSv *LineSv=NULL;
79#include "magnetic.h"
80#include "hcmap.h"
81#include "mean.h"
82#include "mewecoef.h"
83#include "mole.h" 
84#include "nitro.h"
85#include "noexec.h"
86#include "numderiv.h"
87#include "oxy.h"
88#include "parse.h"
89#include "peimbt.h"
90#include "phycon.h"
91#include "plot.h"
92#include "sil.h"
93#include "version.h"
94/* this is set true when space is allocated for the FeII arrays,
95* once this happens FeII.nFeIILevel cannot be changed with the atom feii levels command */
96bool lgFeIIMalloc=false;
97/* */
98#include "pressure.h"
99#include "prt.h"
100#include "punch.h"
101#include "radius.h"
102#include "rfield.h"
103/* set true when malloced, init to false */
104bool lgRfieldMalloced=false;
105#include "opacity.h"
106bool lgOpacMalloced=false;
107#include "rt.h"
108#include "secondaries.h"
109#include "state.h"
110#include "stopcalc.h"
111#include "struc.h"
112#include "thermal.h"
113#include "timesc.h"
114#include "trace.h"
115#include "warnings.h"
116#include "wind.h"
117#include "init.h"
118/* include MPI header if MPI_ENABLED true
119 * This flag indicates whether we are multi-processing.
120 * if this is true then all output happens at the end,
121 * if false then each set of results is printed and flushed when it happens.
122 * must be set true on parallel machines, false on serial */
123#ifdef MPI_ENABLED
124#       include <mpi.h>
125#endif
126
127/* flag set true when cdMPI called, tells exit handler to clean up MPI */
128/* lint error saying never used for anything is fine --
129 * only is used if MPI flags are set, this is so that we do not call
130 * MPI_Finalize when on serial queue on parallel machine */
131static bool lgMPI=false;
132
133/*cdMPI sets flag telling exit handler to call MPI_Finalize, must
134 * call after cdInit when MPI is used */
135void cdMPI(void) /* set flag so that exit handler will clean up MPI */
136{
137        lgMPI = true;
138        return;
139}
140
141/* =================================================================== */
142void cdInit(void)
143{
144        long i;
145        double vtest;
146
147        DEBUG_ENTRY( "cdInit()" );
148
149        /* set ioQQQ to standard output */
150        ioQQQ = stdout;
151
152        /* set ioStdin to standard input, will get line images from here */
153        ioStdin = stdin;
154
155        /* set ioPrnErr to stderr */
156        ioPrnErr = stderr;
157
158        /* but don't want to usually print to stderr */
159        lgPrnErr = false;
160
161        /* set flag saying that cdInit has been called */
162        lgcdInitCalled = true;
163
164        /*test if the following integer types have the correct width*/
165        if( sizeof(int16) != 2 || sizeof(uint16) != 2 || sizeof(int32) != 4 || sizeof(uint32) != 4 )
166                TotalInsanity();
167
168        /*********************************************************
169         *  on a VAX compile with /G_FLOATING option on FORTRAN; *
170         *  following makes sure this happened.                  *
171         *********************************************************/
172        vtest = 1e-35;
173        vtest /= 1e35;
174        if( vtest == 0. )
175        {
176                fprintf( ioQQQ, " Something is wrong with the double precision.  Use /g_floating on a VAX\n" );
177        }
178
179        /* initialize some variables dealing with cloudy's interaction with machine environment */
180        /* if TALK is true then do standard printout
181         * if false then never say anything */
182        called.lgTalk = true;
183        /* this flag is needed to turn print on to have effect */
184        called.lgTalkIsOK = true;
185        /* means talk not forced off by call to cdTalk*/
186        called.lgTalkForcedOff = false;
187
188        optimize.lgNoVary = false;
189        optimize.lgVaryOn = false;
190        optimize.lgOptimr = false;
191        grid.lgGrid = false;
192        grid.nGridCommands = 0;
193
194        for( i=0; i<NUM_OUTPUT_TYPES; i++ )
195        {
196                grid.lgOutputTypeOn[i] = false;
197        }
198
199        for( i=0; i<LIMPAR; i++ )
200        {
201                grid.numParamValues[i] = 0;
202        }
203
204        /* this is a global variable in assertresults.h, and can be checked by
205         * other routines to see if asserts are ok - (most calculations will not use asserts,
206         * and this will be the only place values are set, although they will be checked in maincl) */
207        lgAssertsOK = true;
208        lgBigBotch = false;
209        lgPrtSciNot = false;
210
211        /* number of lines entered with cdLine
212         * both check that number less than NKRD, the limit
213         * the line save array is defined from 0 through input.nSave */
214        input.nSave = -1;
215
216        /* nRead is the number of the command in the input stream - many optimize options
217         * point to it to refer to the original command.  it is incremented before
218         * it is used, so will become 0.  it is the array element within the stack
219         * of emission lines */
220        input.nRead = -1;
221
222        /* this is number of init lines read in */
223        input.nSaveIni = 0;
224        input.lgUnderscoreFound = false;
225        input.lgBracketFound = false;
226
227        /* this is sanity check that lines are read in ok */
228        for( i=0; i < NKRD; i++ )
229        {
230                strcpy( input.chCardSav[i], "error! - no line image input" );
231        }
232
233        /* start the timer to log execution time */
234        cdSetExecTime();
235
236        /* zero out lots of variables */
237        zero();
238        return;
239}
240
241
242/* =================================================================== */
243/*cdExit the routine that should be called to exit cloudy */
244NORETURN void cdExit(
245        /* EXIT_FAILURE for failure, EXIT_SUCCESS for success */
246        int iexit)
247{
248        enum {DEBUG_LOC=false};
249        if( DEBUG_LOC )
250                fprintf(ioQQQ," cdExit called\n");
251
252        /* if doing an MPI run, just throw an exception
253         * so that cddrive can report the problem and continue
254         * computing other grid points */
255        if( lgMPI )
256        {
257                throw bad_mpi(-1);
258        }
259        else
260        {
261                /* close any open units */
262                ClosePunchFiles( true );
263                exit( iexit );
264        }
265}
Note: See TracBrowser for help on using the browser.