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