00001 /* This file is part of Cloudy and is copyright (C)1978-2010 by Gary J. Ferland and 00002 * others. For conditions of distribution and use see copyright notice in license.txt */ 00003 /*cdInit routine to initialize variables, called at start of calculation */ 00004 /*cdPrepareExit prepare termination of the code, but do not terminate yet */ 00005 /* unset EXTERN so that everything is defined here */ 00006 #define EXTERN 00007 #include "cddefines.h" 00008 00009 /* used for saving map*/ 00010 FILE *ioMAP = NULL; 00011 00012 /* external ZeroNum used to div by zero 00013 * ok here since never changed*/ 00014 const double ZeroNum = 0.; 00015 00016 /* this must go here since it defines NTA needed for other lines*/ 00017 #include "taulines.h" 00018 00019 /* following is true extern in taulines.h */ 00020 long nWindLine = NWINDDIM; 00021 00022 #include "abund.h" 00023 #include "atmdat.h" 00024 #include "atoms.h" 00025 #include "atomfeii.h" 00026 #include "monitor_results.h" 00027 #include "broke.h" 00028 #include "ca.h" 00029 #include "called.h" 00030 #include "carb.h" 00031 #include "cddrive.h" 00032 /* this will be set true when cdInit is called. The definition is in cdInit. 00033 * Other routines will check that this is true when they are called, 00034 * to verify that cdInit was called first */ 00035 bool lgcdInitCalled=false; 00036 #include "colden.h" 00037 #include "conv.h" 00038 #include "continuum.h" 00039 #include "coolheavy.h" 00040 #include "cosmology.h" 00041 #include "dark_matter.h" 00042 #include "dense.h" 00043 #include "doppvel.h" 00044 #include "dynamics.h" 00045 #include "elementnames.h" 00046 #include "embesq.h" 00047 #include "fe.h" 00048 #include "fudgec.h" 00049 #include "geometry.h" 00050 #include "grainvar.h" 00051 #include "grid.h" 00052 #include "h2.h" 00053 #include "h2_priv.h" 00054 bool lgH2_READ_DATA = false; 00055 #include "he.h" 00056 #include "heavy.h" 00057 #include "hextra.h" 00058 #include "hmi.h" 00059 #include "hydrogenic.h" 00060 /* this is set true once space malloced, then never change 00061 * number of levels again with hydrogenic command, 00062 * also to make sure MALLOC only happens one time */ 00063 bool lgHydroMalloc = false; 00064 /* */ 00065 #include "hyperfine.h" 00066 #include "input.h" 00067 #include "ionbal.h" 00068 #include "iso.h" 00069 #include "iterations.h" 00070 #include "lines.h" 00071 /* these are the definitions of the line save arrays in lines.h */ 00072 LinSv *LineSv=NULL; 00073 LinSv *LineSvSortWL=NULL; 00074 #include "magnetic.h" 00075 #include "hcmap.h" 00076 #include "mean.h" 00077 #include "mewecoef.h" 00078 #include "mpi_utilities.h" 00079 #include "mole.h" 00080 #include "nitro.h" 00081 #include "noexec.h" 00082 #include "numderiv.h" 00083 #include "oxy.h" 00084 #include "parse.h" 00085 #include "peimbt.h" 00086 #include "phycon.h" 00087 #include "plot.h" 00088 #include "sil.h" 00089 #include "version.h" 00090 /* this is set true when space is allocated for the FeII arrays, 00091 * once this happens the total number of levels cannot be changed with the atom feii levels command */ 00092 bool lgFeIIMalloc=false; 00093 /* */ 00094 #include "pressure.h" 00095 #include "prt.h" 00096 #include "save.h" 00097 #include "radius.h" 00098 #include "rfield.h" 00099 /* set true when malloced, init to false */ 00100 bool lgRfieldMalloced=false; 00101 #include "opacity.h" 00102 bool lgOpacMalloced=false; 00103 #include "rt.h" 00104 #include "secondaries.h" 00105 #include "state.h" 00106 #include "stopcalc.h" 00107 #include "struc.h" 00108 #include "thermal.h" 00109 #include "timesc.h" 00110 #include "trace.h" 00111 #include "warnings.h" 00112 #include "wind.h" 00113 #include "init.h" 00114 00115 00116 /* =================================================================== */ 00117 void cdInit(void) 00118 { 00119 long i; 00120 double vtest; 00121 00122 DEBUG_ENTRY( "cdInit()" ); 00123 00124 /* set flag saying that cdInit has been called */ 00125 lgcdInitCalled = true; 00126 00127 /*test if the following integer types have the correct width*/ 00128 if( sizeof(int16) != 2 || sizeof(uint16) != 2 || sizeof(int32) != 4 || sizeof(uint32) != 4 ) 00129 TotalInsanity(); 00130 00131 /********************************************************* 00132 * on a VAX compile with /G_FLOATING option on FORTRAN; * 00133 * following makes sure this happened. * 00134 *********************************************************/ 00135 vtest = 1e-35; 00136 vtest /= 1e35; 00137 if( vtest == 0. ) 00138 { 00139 fprintf( ioQQQ, " Something is wrong with the double precision. Use /g_floating on a VAX\n" ); 00140 } 00141 00142 /* initialize some variables dealing with cloudy's interaction with machine environment */ 00143 /* if TALK is true then do standard printout 00144 * if false then never say anything */ 00145 /* only the master rank produces output */ 00146 called.lgTalk = cpu.lgMPI_talk(); 00147 /* this flag is needed to turn print on to have effect */ 00148 called.lgTalkIsOK = cpu.lgMPI_talk(); 00149 /* means talk not forced off by call to cdTalk*/ 00150 called.lgTalkForcedOff = false; 00151 00152 optimize.lgNoVary = false; 00153 optimize.lgVaryOn = false; 00154 optimize.lgOptimr = false; 00155 grid.lgGrid = false; 00156 grid.nGridCommands = 0; 00157 00158 for( i=0; i<NUM_OUTPUT_TYPES; i++ ) 00159 { 00160 grid.lgOutputTypeOn[i] = false; 00161 } 00162 00163 /* this is a global variable in monitor_results.h, and can be checked by 00164 * other routines to see if asserts are ok - (most calculations will not use asserts, 00165 * and this will be the only place values are set, although they will be checked in maincl) */ 00166 lgMonitorsOK = true; 00167 lgBigBotch = false; 00168 lgPrtSciNot = false; 00169 00170 /* number of lines entered with cdLine 00171 * both check that number less than NKRD, the limit 00172 * the line save array is defined from 0 through input.nSave */ 00173 input.nSave = -1; 00174 00175 /* nRead is the number of the command in the input stream - many optimize options 00176 * point to it to refer to the original command. it is incremented before 00177 * it is used, so will become 0. it is the array element within the stack 00178 * of emission lines */ 00179 input.nRead = -1; 00180 00181 /* this is number of init lines read in */ 00182 input.nSaveIni = 0; 00183 input.lgUnderscoreFound = false; 00184 input.lgBracketFound = false; 00185 00186 /* this is sanity check that lines are read in ok */ 00187 for( i=0; i < NKRD; i++ ) 00188 { 00189 strcpy( input.chCardSav[i], "error! - no line image input" ); 00190 } 00191 00192 /* start the timer to log execution time */ 00193 cdSetExecTime(); 00194 00195 /* zero out lots of variables */ 00196 zero(); 00197 return; 00198 } 00199 00200 00201 /* =================================================================== */ 00202 /* cdPrepareExit prepare termination of the code, but do not terminate yet 00203 * this routine should only be called by exception handlers, never from the main code */ 00204 void cdPrepareExit() 00205 { 00206 enum {DEBUG_LOC=false}; 00207 if( DEBUG_LOC ) 00208 fprintf(ioQQQ," cdExit called\n"); 00209 00210 // make sure file descriptors are closed in case they were redirected 00211 cdInput( "", "" ); 00212 cdOutput( "", "" ); 00213 00214 /* close any open units */ 00215 CloseSaveFiles( true ); 00216 } 00217