/*cdDrive main routine to call cloudy under all circumstances) */ /*cdReasonGeo wrte why the model stopped and type of geometry on io file */ /*cdWarnings write all warnings entered into comment stack */ /*cdCautions print out all cautions after calculation, on arbitrary io unit */ /*cdSurprises print out all surprises on arbitrary unit number */ /*cdNotes print stack of notes about current calculation */ /*cdGetCooling routine to query results and return cooling of last zone */ /*cdGetHeating routine to query results and return heating of last zone */ /*cdNoexec call this routine to tell code not to actually execute */ /*cdVersion produces string that gives version number of the code */ /*cdDrive main routine to call cloudy under all circumstances) */ #include #include "cddefines.h" #include "vary.h" #include "trace.h" #include "called.h" #include "input.h" #include "date.h" #include "optimr.h" #include "dooptimize.h" #include "timesc.h" #include "cloudy.h" #include "aaaa.h" #include "warnings.h" #include "cddrive.h" /************************************************************************* * * cdDrive - main routine to call cloudy - returns 0 if all ok, 1 if problems * ************************************************************************/ int cdDrive(void ) { int lgBAD; # ifdef DEBUG_FUN fputs( "<+>cdDrive()\n", debug_fp ); # endif /********************************* * main routine to call cloudy * *********************************/ /* this is set FALSE when code loaded, set TRUE when cdInit called, * this is check that cdInit was called first */ if( !lgcdInitCalled ) { printf(" cdInit was not called first - this must be the first call.\n"); puts( "[Stop in cdDrive]" ); exit(1); } if( trace.lgTraceInput ) { fprintf( ioQQQ, "cdDrive: lgOptimr=%1i lgVaryOn=%1i lgNoVary=%1i input.nSave:%li\n", optimr.lgOptimr , vary.lgVaryOn , vary.lgNoVary, input.nSave ); } /* should we call cloudy, or the optimization driver? */ /* possible to have VARY on line without OPTIMIZE being set */ if( optimr.lgOptimr && vary.lgVaryOn ) { vary.lgVaryOn = TRUE; } else { vary.lgVaryOn = FALSE; } /* this is option to have command line saying "no vary" * to turn off optimizer */ if( vary.lgNoVary ) vary.lgVaryOn = FALSE; if( vary.lgVaryOn ) { if( trace.lgTraceInput ) fprintf( ioQQQ, "cdDrive: calling DoOptimize\n"); /* option to drive optimizer set if OPTIMIZE was in input stream */ lgBAD = DoOptimize(); } else { if( trace.lgTraceInput ) fprintf( ioQQQ, "cdDrive: calling cloudy\n"); /* optimize did not occur, only compute one model, call cloudy */ lgBAD = cloudy(); } if( called.lgBusted || lgBAD ) { /* lgBusted set true if something wrong, so return lgBAD false. */ # ifdef DEBUG_FUN fputs( " <->cdDrive()\n", debug_fp ); # endif return(1); } else { /* everything is ok, return 0 */ # ifdef DEBUG_FUN fputs( " <->cdDrive()\n", debug_fp ); # endif return(0); } } /************************************************************************* * * cdReasonGeo wrte why the model stopped and type of geometry on io file * ************************************************************************/ /*cdReasonGeo wrte why the model stopped and type of geometry on io file */ void cdReasonGeo(FILE * ioOUT) { # ifdef DEBUG_FUN fputs( "<+>cdReasonGeo()\n", debug_fp ); # endif /*this is the reason the calculation stopped*/ fprintf( ioOUT, "%s", warnings.chRgcln[0] ); fprintf( ioOUT , "\n" ); /* this is the geometry */ fprintf( ioOUT, "%s", warnings.chRgcln[1] ); fprintf( ioOUT , "\n" ); # ifdef DEBUG_FUN fputs( " <->cdReasonGeo()\n", debug_fp ); # endif return; } /************************************************************************* * * cdWarnings write all warnings entered into comment stack * ************************************************************************/ /*cdWarnings write all warnings entered into comment stack */ void cdWarnings(FILE *ioPNT ) { long int i; # ifdef DEBUG_FUN fputs( "<+>cdWarnings()\n", debug_fp ); # endif if( warnings.nwarn > 0 ) { for( i=0; i < warnings.nwarn; i++ ) { /* these are all warnings that were entered in comment */ fprintf( ioPNT, "%s", warnings.chWarnln[i] ); fprintf( ioPNT, "\n" ); } } # ifdef DEBUG_FUN fputs( " <->cdWarnings()\n", debug_fp ); # endif return; } /************************************************************************* * * cdCautions print out all cautions after calculation, on arbitrary io unit * ************************************************************************/ /*cdCautions print out all cautions after calculation, on arbitrary io unit */ void cdCautions(FILE * ioOUT) { long int i; # ifdef DEBUG_FUN fputs( "<+>cdCautions()\n", debug_fp ); # endif if( warnings.ncaun > 0 ) { for( i=0; i < warnings.ncaun; i++ ) { fprintf( ioOUT, "%s", warnings.chCaunln[i] ); fprintf( ioOUT, "\n" ); } } # ifdef DEBUG_FUN fputs( " <->cdCautions()\n", debug_fp ); # endif return; } /************************************************************************* * * cdTimescales returns thermal, recombination, and H2 foramtion timescales * ************************************************************************/ void cdTimescales( /* the thermal cooling timescale */ double *TTherm , /* the hydrogen recombination timescale */ double *THRecom , /* the H2 formation timescale */ double *TH2 ) { # ifdef DEBUG_FUN fputs( "<+>cdTimescales()\n", debug_fp ); # endif /* these were all evaluated in AgeCheck, which was called by PrtComment */ /* thermal or cooling timescale */ *TTherm = timesc.ttherm; /* the hydrogen recombination timescale */ *THRecom = timesc.threc; /* the H2 formation timescale */ *TH2 = timesc.BigH2MoleForm; # ifdef DEBUG_FUN fputs( " <->cdTimescales()\n", debug_fp ); # endif return; } /************************************************************************* * * cdSurprises print out all surprises on arbitrary unit number * ************************************************************************/ /*cdSurprises print out all surprises on arbitrary unit number */ void cdSurprises(FILE * ioOUT) { long int i; # ifdef DEBUG_FUN fputs( "<+>cdSurprises()\n", debug_fp ); # endif if( warnings.nbang > 0 ) { for( i=0; i < warnings.nbang; i++ ) { fprintf( ioOUT, "%s", warnings.chBangln[i] ); fprintf( ioOUT, "\n" ); } } # ifdef DEBUG_FUN fputs( " <->cdSurprises()\n", debug_fp ); # endif return; } /************************************************************************* * * cdNotes print stack of notes about current calculation * ************************************************************************/ /*cdNotes print stack of notes about current calculation */ void cdNotes(FILE * ioOUT) { long int i; # ifdef DEBUG_FUN fputs( "<+>cdNotes()\n", debug_fp ); # endif if( warnings.nnote > 0 ) { for( i=0; i < warnings.nnote; i++ ) { fprintf( ioOUT, "%s", warnings.chNoteln[i] ); fprintf( ioOUT, "\n" ); } } # ifdef DEBUG_FUN fputs( " <->cdNotes()\n", debug_fp ); # endif return; } /************************************************************************* * * cdGetCooling routine to query results and return cooling of last zone * ************************************************************************/ /*cdGetCooling routine to query results and return cooling of last zone */ #include "heat.h" #include "tcool.h" double cdGetCooling(void) /* return cooling for last zone */ { return (tcool.ctot); } /************************************************************************* * * cdVersion - puts version number of code into string * incoming string must have at least 8 char and will become null * terminated string * ************************************************************************/ void cdVersion(char chString[] ) { /* first call routine that sets var to make sure we get valid numbers */ AAAA(); strcpy( chString , date.chVersion ); return ; } /************************************************************************* * * cdDate - puts date of code into string * incoming string must have at least 8 char and will become null * terminated string * ************************************************************************/ /* cdDate - puts date of code into string */ void cdDate(char chString[] ) { /* first call routine that sets var to make sure we get valid numbers */ AAAA(); strcpy( chString , date.chDate ); return ; } /************************************************************************* * * cdGetHeating routine to query results and return heating of last zone * ************************************************************************/ /*cdGetHeating routine to query results and return heating of last zone */ double cdGetHeating(void) /* return heating for last zone */ { return (heat.htot); } /************************************************************************* * * cdNoexec call this routine to tell code not to actually execute * ************************************************************************/ /*cdNoexec call this routine to tell code not to actually execute */ #include "noexec.h" void cdNoexec(void) { # ifdef DEBUG_FUN fputs( "<+>cdNoexec()\n", debug_fp ); # endif /* this is an option to have the code read in all input quanties * ot to NOT execute the actual model - to check on input parameters * */ noexec.lgNoExec = TRUE; # ifdef DEBUG_FUN fputs( " <->cdNoexec()\n", debug_fp ); # endif return; } /*cdSetExecTime routine to initialize variables keeping track of time at start of calculation */ /*cdExecTime any routine can call this, and find the time since cdInit was called */ #include /* will be used to save initial time */ static clock_t before; /* this must be true when cdExeTime is called, and is set true * when SetExecTime is called */ static int lgCalled=FALSE; /* this routine is called by cdinit when everything is initialized, * so that every time cdExecTime is called the elapsed time is returned */ void cdSetExecTime(void) { /* save startup time */ before = clock(); lgCalled = TRUE; } /*cdExecTime any routine can call this, and find the time since cdInit was called */ double cdExecTime(void) { /* check that we were properly initialized */ if( lgCalled ) { /* this is elapsed time in seconds */ return( (clock() - before) / CLOCKS_PER_SEC ) ; } else { /* this is a big problem, we were asked for the elapsed time but * the timer was not initialized by calling SetExecTime */ fprintf( ioQQQ, " cdExecTime was called before SetExecTime, impossible.\n" ); fprintf( ioQQQ, "Sorry.\n" ); puts( "[Stop in cdExecTime]" ); exit(1); } }