/*cdInit routine to initialize variables, called at start of calculation */ #include #include "cddefines.h" /* NB - following must appear after cddefines.h since code there * ensures that __unix is defined on any unix box */ #ifdef __unix # include # include #endif #include "cddrive.h" #include "vary.h" #include "optimr.h" #include "blockdata.h" #include "setfpenv.h" #include "dustop.h" #include "called.h" #include "input.h" #include "phfit.h" #include "zero.h" #include "varypar.h" void exithandler(void) { /* close any open units */ CloseUnits(); } void cdInit() { long i; double vtest; static int lgFIRST=TRUE; float cs; # ifdef __unix char *ptr; # endif /* if this is very first call then set up handler */ if( lgFIRST ) { /* register the exit handler */ atexit( exithandler ); lgFIRST = FALSE; } /* set ioQQQ to standard output */ ioQQQ = stdout; /* set flag saying that we have been called */ lgcdInitCalled = TRUE; /* set ioPrnErr to stderr */ ioPrnErr = stderr; /* but don't what to usually do this */ lgPrnErr = FALSE; blkdata2(); /* fe2data */ blkdata4(); /* hpdata */ /* initialize some grains data before grains read in */ GrainsInit(); /*need a fake call to phfit so that ionization potentials are stored in * proper structures */ phfit(1,1,1,13.7,&cs,0); /*set FP environment to crash on div by zero*/ SetFPEnv(); /********************************************************* * on a VAX compile with /G_FLOATING option on FORTRAN; * * following makes sure this happened. * *********************************************************/ vtest = 1e-35; vtest /= 1e35; if( vtest == 0. ) { fprintf( ioQQQ, " Something is wrong with the double precision. Use /g_floating on a VAX\n" ); } /********************************************************* * check that we are being compiled with ANSI C or C++ * *********************************************************/ # if !defined(__STDC__) && !defined(__cplusplus) fprintf(ioQQQ," I must be compiled using ANSI C options. This was not enabled.\n"); fprintf(ioQQQ," Visual Studio use the /Za flag.\n"); fprintf(ioQQQ," GNU gcc use the -ansi flag.\n"); fprintf(ioQQQ," Dec alpha use the -std1 flag.\n"); fprintf(ioQQQ," Sparc use the -Xc flag.\n"); puts( "[Stop in cdInit]" ); exit(1); # endif /* initialize some variables dealing with cloudy's interaction with machine environment */ /* if TALK is TRUE then do standard printout * if FALSE then never say anything */ called.lgTalk = TRUE; called.lgBusted = FALSE; /* this flag is needed to turn print on to ahave effect */ called.lgTalkIsOK = TRUE; /* means talk not forced off by call to cdTalk*/ called.lgTalkForce = FALSE; vary.lgNoVary = FALSE; vary.lgVaryOn = FALSE; optimr.lgOptimr = FALSE; # ifdef __unix /* determine hostname; used by PHYMIR */ if( (ptr = getenv("HOST")) != NULL ) strcpy(VaryPar.HostName,ptr); else strcpy(VaryPar.HostName,"unknown"); /* determine the no. of CPUs on this machine; used by PHYMIR */ # if defined(_SC_NPROCESSORS_ONLN) /* Sun Sparc, DEC Alpha */ VaryPar.maxCPU = sysconf(_SC_NPROCESSORS_ONLN); # elif defined(_SC_NPROC_ONLN) /* SGI Iris */ VaryPar.maxCPU = sysconf(_SC_NPROC_ONLN); # elif defined(_SC_CRAY_NCPU) /* Cray */ VaryPar.maxCPU = sysconf(_SC_CRAY_NCPU); # else /* Other systems, supply no. of CPUs on OPTIMIZE PHYMIR command line */ VaryPar.maxCPU = 1; # endif # else strcpy(VaryPar.HostName,"unknown"); VaryPar.maxCPU = 1; # endif /* number of lines entered with cdLine * both check that number less than NKRD, the limit * the line save array is devined from 0 through input.nSave */ input.nSave = -1; /* nRead is the number of the command in the input stream - many vary options * point to it to refer to the original command. it is incremented before * it is used, so will become 0. it is the array element within the stack * of emission lines */ input.nRead = -1; /* this is number of init lines read in */ input.nSaveIni = 0; /* flag identifying whether any line images were too long, tested in cdRead */ lgCardSavTooLong = FALSE; /* this is sanity check that lines are read in ok */ for( i=0; i < NKRD; i++ ) { strcpy( input.chCardSav[i], "error! - no line image input" ); } /* start the timer to log execution time */ cdSetExecTime(); /* zero out lots of variables */ zero(); # ifdef DEBUG_FUN fputs( " <->cdInit()\n", debug_fp ); # endif return; }