cloudy trunk
Loading...
Searching...
No Matches
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*/
9FILE *ioMAP = NULL;
10
11/* external ZeroNum used to div by zero
12 * ok here since never changed*/
13const 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 */
34bool 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 */
61bool 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 */
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 */
90bool 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 */
99#include "opacity.h"
100bool 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/* =================================================================== */
115void 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 )
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 */
146 called.lgTalkIsOK = cpu.i().lgMPI_talk();
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 */
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 */
202void 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
bool lgFeIIMalloc
Definition cdinit.cpp:90
t_called called
Definition called.cpp:5
FILE * ioQQQ
Definition cddefines.cpp:7
exit_type
Definition cddefines.h:115
FILE * ioMAP
Definition cdinit.cpp:9
const double ZeroNum
Definition cdinit.cpp:13
NORETURN void TotalInsanity(void)
Definition service.cpp:886
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
void cdInput(const char *filename, const char *mode)
Definition cddrive.cpp:1530
void cdSetExecTime()
Definition cddrive.cpp:474
void cdOutput(const char *filename, const char *mode)
Definition cddrive.cpp:1517
bool lgcdInitCalled
Definition cdinit.cpp:34
bool lgRfieldMalloced
Definition cdinit.cpp:98
LinSv * LineSvSortWL
Definition cdinit.cpp:71
bool lgHydroMalloc
Definition cdinit.cpp:61
void cdInit(void)
Definition cdinit.cpp:115
void cdPrepareExit(exit_type exit_status)
Definition cdinit.cpp:202
long nWindLine
Definition cdinit.cpp:19
LinSv * LineSv
Definition cdinit.cpp:70
bool lgOpacMalloced
Definition cdinit.cpp:100
static t_cpu cpu
Definition cpu.h:355
t_grid grid
Definition grid.cpp:5
const int NUM_OUTPUT_TYPES
Definition grid.h:21
void zero(void)
Definition zero.cpp:73
t_input input
Definition input.cpp:12
#define NKRD
Definition input.h:10
struct t_tag_LineSv LinSv
bool lgPrtSciNot
bool lgBigBotch
bool lgMonitorsOK
t_optimize optimize
Definition optimize.cpp:5
void CloseSaveFiles(bool lgFinal)
void SaveGrid(FILE *pnunit, exit_type status)
Definition save_do.cpp:4846
const int NWINDDIM
Definition taulines.h:145