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