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

Generated for cloudy by doxygen 1.8.4