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-2017 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 "monitor_results.h"
22 #include "called.h"
23 #include "cddrive.h"
24 /* this will be set true when cdInit is called. The definition is in cdInit.
25 * Other routines will check that this is true when they are called,
26 * to verify that cdInit was called first */
27 bool lgcdInitCalled=false;
28 #include "grid.h"
29 /* this is set true once space malloced, then never change
30 * number of levels again with hydrogenic command,
31 * also to make sure MALLOC only happens one time */
32 bool lgHydroMalloc = false;
33 /* */
34 #include "input.h"
35 #include "parse.h"
36 /* */
37 #include "save.h"
38 /* set true when malloced, init to false */
39 bool lgRfieldMalloced=false;
40 bool lgOpacMalloced=false;
41 #include "init.h"
42 
43 
44 /* =================================================================== */
45 void cdInit(void)
46 {
47  long i;
48  double vtest;
49 
50  DEBUG_ENTRY( "cdInit()" );
51 
52  /* set flag saying that cdInit has been called */
53  lgcdInitCalled = true;
54 
55  /*test if the following integer types have the correct width*/
56  if( sizeof(int16) != 2 || sizeof(uint16) != 2 || sizeof(int32) != 4 || sizeof(uint32) != 4 )
57  TotalInsanity();
58 
59  /*********************************************************
60  * on a VAX compile with /G_FLOATING option on FORTRAN; *
61  * following makes sure this happened. *
62  *********************************************************/
63  vtest = 1e-35;
64  vtest /= 1e35;
65  if( vtest == 0. )
66  {
67  fprintf( ioQQQ, " Something is wrong with the double precision. Use /g_floating on a VAX\n" );
68  }
69 
70  /* initialize some variables dealing with cloudy's interaction with machine environment */
71  /* if TALK is true then do standard printout
72  * if false then never say anything */
73  /* only the master rank produces output */
75  /* this flag is needed to turn print on to have effect */
77  /* means talk not forced off by call to cdTalk*/
78  called.lgTalkForcedOff = false;
79 
80  optimize.lgNoVary = false;
81  optimize.lgVaryOn = false;
82  optimize.lgOptimr = false;
83  grid.lgGrid = false;
84  grid.nGridCommands = 0;
85 
86  for( i=0; i<NUM_OUTPUT_TYPES; i++ )
87  {
88  grid.lgOutputTypeOn[i] = false;
89  }
90 
91  /* this is a global variable in monitor_results.h, and can be checked by
92  * other routines to see if asserts are ok - (most calculations will not use asserts,
93  * and this will be the only place values are set, although they will be checked in maincl) */
94  lgMonitorsOK = true;
95  lgBigBotch = false;
96  lgPrtSciNot = false;
97 
98  /* number of lines entered with cdLine
99  * both check that number less than NKRD, the limit
100  * the line save array is defined from 0 through input.nSave */
101  input.nSave = -1;
102 
103  /* nRead is the number of the command in the input stream - many optimize options
104  * point to it to refer to the original command. it is incremented before
105  * it is used, so will become 0. it is the array element within the stack
106  * of emission lines */
107  input.nRead = -1;
108 
109  /* this is number of init lines read in */
110  input.nSaveIni = 0;
111  input.lgUnderscoreFound = false;
112  input.lgBracketFound = false;
113 
114  /* this is sanity check that lines are read in ok */
115  for( i=0; i < NKRD; i++ )
116  {
117  strcpy( input.chCardSav[i], "error! - no line image input" );
118  }
119 
120  /* start the timer to log execution time */
121  cdSetExecTime();
122 
123  /* zero out lots of variables */
124  zero();
125  return;
126 }
127 
128 
129 /* =================================================================== */
130 /* cdPrepareExit prepare termination of the code, but do not terminate yet
131  * this routine should only be called by exception handlers, never from the main code */
132 void cdPrepareExit(exit_type exit_status)
133 {
134  enum {DEBUG_LOC=false};
135  if( DEBUG_LOC )
136  fprintf(ioQQQ," cdExit called\n");
137 
138  // make sure file descriptors are closed in case they were redirected
139  cdInput( "", "" );
140  cdOutput( "", "" );
141 
142  // make sure the error condition is logged in the SAVE GRID output
143  // we do this here (and not SaveDo) to make sure that the output is complete
144  if( grid.lgGrid && cpu.i().lgMPISingleRankMode() )
145  SaveGrid( grid.pnunit, exit_status );
146 
147  /* close any open units */
148  CloseSaveFiles( true );
149 }
150 
long int nSave
Definition: input.h:62
FILE * ioMAP
Definition: cdinit.cpp:9
void cdInit()
Definition: cdinit.cpp:45
FILE * pnunit
Definition: grid.h:71
const int NKRD
Definition: input.h:12
NORETURN void TotalInsanity(void)
Definition: service.cpp:1067
bool lgOpacMalloced
Definition: cdinit.cpp:40
t_input input
Definition: input.cpp:12
bool lgGrid
Definition: grid.h:42
long int nSaveIni
Definition: input.h:62
bool lgHydroMalloc
Definition: cdinit.cpp:32
t_cpu_i & i()
Definition: cpu.h:415
void cdInput(const char *filename, const char *mode)
Definition: cddrive.cpp:1224
const int NWINDDIM
Definition: taulines.h:96
long int nRead
Definition: input.h:62
void CloseSaveFiles(bool lgFinal)
bool lgVaryOn
Definition: optimize.h:173
bool lgcdInitCalled
Definition: cdinit.cpp:27
FILE * ioQQQ
Definition: cddefines.cpp:7
bool lgTalk
Definition: called.h:12
void zero(void)
Definition: zero.cpp:43
exit_type
Definition: cddefines.h:142
bool lgOptimr
Definition: optimize.h:178
bool lgMonitorsOK
void cdOutput(const char *filename, const char *mode)
Definition: cddrive.cpp:1211
void SaveGrid(FILE *pnunit, exit_type status)
Definition: save_do.cpp:4694
void cdSetExecTime()
Definition: cddrive.cpp:476
const double ZeroNum
Definition: cdinit.cpp:13
const int NUM_OUTPUT_TYPES
Definition: grid.h:22
bool lgMPI_talk() const
Definition: cpu.h:394
long nWindLine
Definition: cdinit.cpp:19
t_optimize optimize
Definition: optimize.cpp:6
t_grid grid
Definition: grid.cpp:5
bool lgUnderscoreFound
Definition: input.h:79
bool lgBracketFound
Definition: input.h:83
bool lgPrtSciNot
bool lgRfieldMalloced
Definition: cdinit.cpp:39
bool lgBigBotch
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:729
bool lgTalkForcedOff
Definition: called.h:19
bool lgOutputTypeOn[NUM_OUTPUT_TYPES]
Definition: grid.h:66
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1217
char chCardSav[NKRD][INPUT_LINE_LENGTH]
Definition: input.h:48
static t_cpu cpu
Definition: cpu.h:423
bool lgNoVary
Definition: optimize.h:175
long int nGridCommands
Definition: grid.h:55
void cdPrepareExit(exit_type)
Definition: cdinit.cpp:132
bool lgMPISingleRankMode() const
Definition: cpu.h:390
t_called called
Definition: called.cpp:4
bool lgTalkIsOK
Definition: called.h:23