cloudy  trunk
 All Data Structures Namespaces 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-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 
long int nSave
Definition: input.h:46
FILE * ioMAP
Definition: cdinit.cpp:9
#define NKRD
Definition: input.h:10
void cdInit()
Definition: cdinit.cpp:115
FILE * pnunit
Definition: grid.h:58
NORETURN void TotalInsanity(void)
Definition: service.cpp:886
bool lgOpacMalloced
Definition: cdinit.cpp:100
t_input input
Definition: input.cpp:12
bool lgGrid
Definition: grid.h:40
long int nSaveIni
Definition: input.h:46
bool lgHydroMalloc
Definition: cdinit.cpp:61
t_cpu_i & i()
Definition: cpu.h:334
void cdInput(const char *filename, const char *mode)
Definition: cddrive.cpp:1530
const int NWINDDIM
Definition: taulines.h:145
long int nRead
Definition: input.h:46
void CloseSaveFiles(bool lgFinal)
bool lgVaryOn
Definition: optimize.h:173
bool lgcdInitCalled
Definition: cdinit.cpp:34
FILE * ioQQQ
Definition: cddefines.cpp:7
bool lgTalk
Definition: called.h:12
void zero(void)
Definition: zero.cpp:73
exit_type
Definition: cddefines.h:119
bool lgOptimr
Definition: optimize.h:178
bool lgFeIIMalloc
Definition: cdinit.cpp:90
bool lgMonitorsOK
void cdOutput(const char *filename, const char *mode)
Definition: cddrive.cpp:1517
void SaveGrid(FILE *pnunit, exit_type status)
Definition: save_do.cpp:4846
LinSv * LineSv
Definition: cdinit.cpp:70
void cdSetExecTime()
Definition: cddrive.cpp:474
const double ZeroNum
Definition: cdinit.cpp:13
const int NUM_OUTPUT_TYPES
Definition: grid.h:21
bool lgMPI_talk() const
Definition: cpu.h:315
long nWindLine
Definition: cdinit.cpp:19
t_optimize optimize
Definition: optimize.cpp:5
t_grid grid
Definition: grid.cpp:5
bool lgUnderscoreFound
Definition: input.h:63
bool lgBracketFound
Definition: input.h:67
bool lgPrtSciNot
bool lgRfieldMalloced
Definition: cdinit.cpp:98
bool lgBigBotch
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:688
bool lgTalkForcedOff
Definition: called.h:19
bool lgOutputTypeOn[NUM_OUTPUT_TYPES]
Definition: grid.h:53
LinSv * LineSvSortWL
Definition: cdinit.cpp:71
char chCardSav[NKRD][INPUT_LINE_LENGTH]
Definition: input.h:32
static t_cpu cpu
Definition: cpu.h:342
bool lgNoVary
Definition: optimize.h:175
long int nGridCommands
Definition: grid.h:45
void cdPrepareExit(exit_type)
Definition: cdinit.cpp:202
bool lgMPISingleRankMode() const
Definition: cpu.h:311
t_called called
Definition: called.cpp:5
bool lgTalkIsOK
Definition: called.h:23