cloudy  trunk
cdinit.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2013 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 /*cdPrepareExit prepare termination of the code, but do not terminate yet */
5 /* unset EXTERN so that everything is defined here */
6 #include "cddefines.h"
7 
8 /* used for saving map*/
9 FILE *ioMAP = NULL;
10 
11 /* external ZeroNum used to div by zero
12  * ok here since never changed*/
13 const double ZeroNum = 0.;
14 
15 /* this must go here since it defines NTA needed for other lines*/
16 #include "taulines.h"
17 
18 /* following is true extern in taulines.h */
20 
21 #include "abund.h"
22 #include "atmdat.h"
23 #include "atoms.h"
24 #include "atomfeii.h"
25 #include "monitor_results.h"
26 #include "broke.h"
27 #include "ca.h"
28 #include "called.h"
29 #include "carb.h"
30 #include "cddrive.h"
31 /* this will be set true when cdInit is called. The definition is in cdInit.
32 * Other routines will check that this is true when they are called,
33 * to verify that cdInit was called first */
34 bool lgcdInitCalled=false;
35 #include "co.h"
36 #include "colden.h"
37 #include "conv.h"
38 #include "continuum.h"
39 #include "coolheavy.h"
40 #include "cosmology.h"
41 #include "dark_matter.h"
42 #include "dense.h"
43 #include "doppvel.h"
44 #include "dynamics.h"
45 #include "elementnames.h"
46 #include "embesq.h"
47 #include "fe.h"
48 #include "fudgec.h"
49 #include "geometry.h"
50 #include "grainvar.h"
51 #include "grid.h"
52 //#include "h2.h"
53 #include "he.h"
54 #include "heavy.h"
55 #include "hextra.h"
56 #include "hmi.h"
57 #include "hydrogenic.h"
58 /* this is set true once space malloced, then never change
59 * number of levels again with hydrogenic command,
60 * also to make sure MALLOC only happens one time */
61 bool lgHydroMalloc = false;
62 /* */
63 #include "hyperfine.h"
64 #include "input.h"
65 #include "ionbal.h"
66 #include "iso.h"
67 #include "iterations.h"
68 #include "lines.h"
69 /* these are the definitions of the line save arrays in lines.h */
70 LinSv *LineSv=NULL;
72 #include "magnetic.h"
73 #include "hcmap.h"
74 #include "mean.h"
75 #include "mewecoef.h"
76 #include "mpi_utilities.h"
77 #include "mole.h"
78 #include "nitro.h"
79 #include "noexec.h"
80 #include "numderiv.h"
81 #include "oxy.h"
82 #include "parse.h"
83 #include "peimbt.h"
84 #include "phycon.h"
85 #include "plot.h"
86 #include "sil.h"
87 #include "version.h"
88 /* this is set true when space is allocated for the FeII arrays,
89 * once this happens the total number of levels cannot be changed with the atom feii levels command */
90 bool lgFeIIMalloc=false;
91 /* */
92 #include "pressure.h"
93 #include "prt.h"
94 #include "save.h"
95 #include "radius.h"
96 #include "rfield.h"
97 /* set true when malloced, init to false */
98 bool lgRfieldMalloced=false;
99 #include "opacity.h"
100 bool lgOpacMalloced=false;
101 #include "rt.h"
102 #include "secondaries.h"
103 #include "state.h"
104 #include "stopcalc.h"
105 #include "struc.h"
106 #include "thermal.h"
107 #include "timesc.h"
108 #include "trace.h"
109 #include "warnings.h"
110 #include "wind.h"
111 #include "init.h"
112 
113 
114 /* =================================================================== */
115 void cdInit(void)
116 {
117  long i;
118  double vtest;
119 
120  DEBUG_ENTRY( "cdInit()" );
121 
122  /* set flag saying that cdInit has been called */
123  lgcdInitCalled = true;
124 
125  /*test if the following integer types have the correct width*/
126  if( sizeof(int16) != 2 || sizeof(uint16) != 2 || sizeof(int32) != 4 || sizeof(uint32) != 4 )
127  TotalInsanity();
128 
129  /*********************************************************
130  * on a VAX compile with /G_FLOATING option on FORTRAN; *
131  * following makes sure this happened. *
132  *********************************************************/
133  vtest = 1e-35;
134  vtest /= 1e35;
135  if( vtest == 0. )
136  {
137  fprintf( ioQQQ, " Something is wrong with the double precision. Use /g_floating on a VAX\n" );
138  }
139 
140  /* initialize some variables dealing with cloudy's interaction with machine environment */
141  /* if TALK is true then do standard printout
142  * if false then never say anything */
143  /* only the master rank produces output */
144  called.lgTalk = cpu.i().lgMPI_talk();
145  /* this flag is needed to turn print on to have effect */
147  /* means talk not forced off by call to cdTalk*/
148  called.lgTalkForcedOff = false;
149 
150  optimize.lgNoVary = false;
151  optimize.lgVaryOn = false;
152  optimize.lgOptimr = false;
153  grid.lgGrid = false;
154  grid.nGridCommands = 0;
155 
156  for( i=0; i<NUM_OUTPUT_TYPES; i++ )
157  {
158  grid.lgOutputTypeOn[i] = false;
159  }
160 
161  /* this is a global variable in monitor_results.h, and can be checked by
162  * other routines to see if asserts are ok - (most calculations will not use asserts,
163  * and this will be the only place values are set, although they will be checked in maincl) */
164  lgMonitorsOK = true;
165  lgBigBotch = false;
166  lgPrtSciNot = false;
167 
168  /* number of lines entered with cdLine
169  * both check that number less than NKRD, the limit
170  * the line save array is defined from 0 through input.nSave */
171  input.nSave = -1;
172 
173  /* nRead is the number of the command in the input stream - many optimize options
174  * point to it to refer to the original command. it is incremented before
175  * it is used, so will become 0. it is the array element within the stack
176  * of emission lines */
177  input.nRead = -1;
178 
179  /* this is number of init lines read in */
180  input.nSaveIni = 0;
181  input.lgUnderscoreFound = false;
182  input.lgBracketFound = false;
183 
184  /* this is sanity check that lines are read in ok */
185  for( i=0; i < NKRD; i++ )
186  {
187  strcpy( input.chCardSav[i], "error! - no line image input" );
188  }
189 
190  /* start the timer to log execution time */
191  cdSetExecTime();
192 
193  /* zero out lots of variables */
194  zero();
195  return;
196 }
197 
198 
199 /* =================================================================== */
200 /* cdPrepareExit prepare termination of the code, but do not terminate yet
201  * this routine should only be called by exception handlers, never from the main code */
202 void cdPrepareExit(exit_type exit_status)
203 {
204  enum {DEBUG_LOC=false};
205  if( DEBUG_LOC )
206  fprintf(ioQQQ," cdExit called\n");
207 
208  // make sure file descriptors are closed in case they were redirected
209  cdInput( "", "" );
210  cdOutput( "", "" );
211 
212  // make sure the error condition is logged in the SAVE GRID output
213  // we do this here (and not SaveDo) to make sure that the output is complete
214  if( grid.lgGrid && cpu.i().lgMPISingleRankMode() )
215  SaveGrid( grid.pnunit, exit_status );
216 
217  /* close any open units */
218  CloseSaveFiles( true );
219 }
220 
colden.h
thermal.h
t_input::nSaveIni
long int nSaveIni
Definition: input.h:52
t_called::lgTalkForcedOff
bool lgTalkForcedOff
Definition: called.h:19
lines.h
t_optimize::lgOptimr
bool lgOptimr
Definition: optimize.h:178
struc.h
elementnames.h
secondaries.h
atoms.h
cdInput
void cdInput(const char *filename, const char *mode)
Definition: cddrive.cpp:1530
t_input::nRead
long int nRead
Definition: input.h:49
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
geometry.h
fudgec.h
conv.h
rfield.h
nWindLine
long nWindLine
Definition: cdinit.cpp:19
SaveGrid
void SaveGrid(FILE *pnunit, exit_type status)
Definition: save_do.cpp:4846
cdOutput
void cdOutput(const char *filename, const char *mode)
Definition: cddrive.cpp:1517
mole.h
grid
t_grid grid
Definition: grid.cpp:5
t_optimize::lgNoVary
bool lgNoVary
Definition: optimize.h:175
t_cpu_i::lgMPISingleRankMode
bool lgMPISingleRankMode() const
Definition: cpu.h:324
abund.h
t_input::chCardSav
char chCardSav[NKRD][INPUT_LINE_LENGTH]
Definition: input.h:32
lgRfieldMalloced
bool lgRfieldMalloced
Definition: cdinit.cpp:98
cpu
static t_cpu cpu
Definition: cpu.h:355
trace.h
lgcdInitCalled
bool lgcdInitCalled
Definition: cdinit.cpp:34
grid.h
cdPrepareExit
void cdPrepareExit(exit_type exit_status)
Definition: cdinit.cpp:202
embesq.h
dynamics.h
input
t_input input
Definition: input.cpp:12
iso.h
version.h
atmdat.h
ioMAP
FILE * ioMAP
Definition: cdinit.cpp:9
dark_matter.h
cdInit
void cdInit(void)
Definition: cdinit.cpp:115
lgOpacMalloced
bool lgOpacMalloced
Definition: cdinit.cpp:100
cddrive.h
broke.h
parse.h
t_input::lgBracketFound
bool lgBracketFound
Definition: input.h:67
cdSetExecTime
void cdSetExecTime()
Definition: cddrive.cpp:474
optimize
t_optimize optimize
Definition: optimize.cpp:5
t_cpu::i
t_cpu_i & i()
Definition: cpu.h:347
nitro.h
mewecoef.h
dense.h
lgPrtSciNot
bool lgPrtSciNot
Definition: monitor_results.cpp:37
init.h
coolheavy.h
cddefines.h
fe.h
t_grid::nGridCommands
long int nGridCommands
Definition: grid.h:45
TotalInsanity
NORETURN void TotalInsanity(void)
Definition: service.cpp:886
CloseSaveFiles
void CloseSaveFiles(bool lgFinal)
Definition: parse_save.cpp:2765
t_called::lgTalk
bool lgTalk
Definition: called.h:12
hyperfine.h
radius.h
lgFeIIMalloc
bool lgFeIIMalloc
Definition: cdinit.cpp:90
heavy.h
lgBigBotch
bool lgBigBotch
Definition: monitor_results.cpp:37
hmi.h
ZeroNum
const double ZeroNum
Definition: cdinit.cpp:13
lgMonitorsOK
bool lgMonitorsOK
Definition: monitor_results.cpp:37
pressure.h
mpi_utilities.h
peimbt.h
NWINDDIM
const int NWINDDIM
Definition: taulines.h:145
save.h
co.h
he.h
t_cpu_i::lgMPI_talk
bool lgMPI_talk() const
Definition: cpu.h:328
cosmology.h
prt.h
hydrogenic.h
doppvel.h
t_optimize::lgVaryOn
bool lgVaryOn
Definition: optimize.h:173
zero
void zero(void)
Definition: zero.cpp:73
NUM_OUTPUT_TYPES
const int NUM_OUTPUT_TYPES
Definition: grid.h:21
t_input::nSave
long int nSave
Definition: input.h:46
grainvar.h
sil.h
timesc.h
rt.h
wind.h
ionbal.h
magnetic.h
called
t_called called
Definition: called.cpp:5
t_tag_LineSv
Definition: lines.h:111
noexec.h
t_input::lgUnderscoreFound
bool lgUnderscoreFound
Definition: input.h:63
t_grid::lgOutputTypeOn
bool lgOutputTypeOn[NUM_OUTPUT_TYPES]
Definition: grid.h:56
hextra.h
taulines.h
hcmap.h
phycon.h
numderiv.h
iterations.h
LineSvSortWL
LinSv * LineSvSortWL
Definition: cdinit.cpp:71
state.h
lgHydroMalloc
bool lgHydroMalloc
Definition: cdinit.cpp:61
opacity.h
called.h
continuum.h
oxy.h
LineSv
LinSv * LineSv
Definition: cdinit.cpp:70
NKRD
#define NKRD
Definition: input.h:10
stopcalc.h
monitor_results.h
warnings.h
plot.h
t_called::lgTalkIsOK
bool lgTalkIsOK
Definition: called.h:23
input.h
carb.h
t_grid::lgGrid
bool lgGrid
Definition: grid.h:40
atomfeii.h
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684
exit_type
exit_type
Definition: cddefines.h:115
t_grid::pnunit
FILE * pnunit
Definition: grid.h:61
ca.h
mean.h