/*ParseOptimize parse the optimize command line */ #include #include "cddefines.h" #ifdef DEFERR # undef DEFERR #endif #define DEFERR 0.05f #include "varypar.h" #include "lgmatch.h" #include "ffmtread.h" #include "getoptcolden.h" #include "getoptlineint.h" #include "getquote.h" #include "parse.h" void ParseOptimize(char *chCard) { int lgEOL; long int i; # ifdef __unix long int dum; # endif # ifdef DEBUG_FUN fputs( "<+>ParseOptimize()\n", debug_fp ); # endif if( lgMatch("AMOE",chCard) ) { /* use Amoeba to optimize parameters */ strcpy( chVaryPar.chOptRtn, "AMOE" ); } else if( lgMatch("COLU",chCard) ) { /* optimize column density */ VaryPar.lgOptCol = TRUE; /* read lcolumn densities to match */ GetOptColDen(chCard); } else if( lgMatch("CONT",chCard) ) { /* set flag saying that optimization should start from continue file */ VaryPar.lgOptCont = TRUE; } else if( lgMatch("INCR",chCard) ) { /* scan off increments for the previously selected paramter */ if( VaryPar.nparm > 0 ) { /* also called during optimization process, ignore then */ i = 5; VaryPar.OptIncrm[VaryPar.nparm-1] = (float)FFmtRead(chCard,&i,76,&lgEOL); } } else if( lgMatch("LUMI",chCard) || lgMatch("INTE",chCard) ) { /* scan off intensity or luminosity of normalization line */ i = 5; VaryPar.optint = (float)FFmtRead(chCard,&i,76,&lgEOL); VaryPar.optier = (float)FFmtRead(chCard,&i,76,&lgEOL); if( lgEOL ) { VaryPar.optier = DEFERR; } /* set flag to say that intentity or luminosity of line set */ VaryPar.lgOptLum = TRUE; } else if( lgMatch("ITER",chCard) ) { /* scan off number of iterations */ i = 5; VaryPar.nIterOptim = (long)FFmtRead(chCard,&i,76,&lgEOL); } else if( lgMatch("LINE",chCard) ) { /* read lines to match */ GetOptLineInt(chCard); /* set flag saying that something has been set */ VaryPar.lgOptLin = TRUE; } else if( lgMatch("PHYM",chCard) ) { /* use PHYMIR to optimize parameters */ strcpy( chVaryPar.chOptRtn, "PHYM" ); # ifdef __unix VaryPar.lgParallel = ! lgMatch("SEQU",chCard); if( VaryPar.lgParallel ) { i = 5; dum = (long)FFmtRead(chCard,&i,76,&lgEOL); /* default has already been set in cdinit ! */ if( ! lgEOL ) { VaryPar.maxCPU = dum; } } else { VaryPar.maxCPU = 1; } # else VaryPar.lgParallel = FALSE; VaryPar.maxCPU = 1; # endif } else if( lgMatch("POWE",chCard) ) { /* use Powell to optimize parameters */ strcpy( chVaryPar.chOptRtn, "POWE" ); } else if( lgMatch("FILE",chCard) ) { /* option to send final set of parameters to an input file * get name within double quotes, * and set to blanks in chCard and OrgCard */ GetQuote( chOptimFileName , chCard ); /* open the file */ VaryPar.ioOptim = fopen( chOptimFileName , "w" ) ; if( VaryPar.ioOptim == NULL ) { fprintf(ioQQQ," error opening file %s\n", chOptimFileName ); exit(1); } } else if( lgMatch("RANG",chCard) ) { /* scan off range for the previously selected variable */ if( VaryPar.nparm > 0 ) { i = 5; VaryPar.varang[VaryPar.nparm-1][0] = (float)FFmtRead(chCard,&i,76,&lgEOL); if( lgEOL ) { VaryPar.varang[VaryPar.nparm-1][0] = -1e38f; } VaryPar.varang[VaryPar.nparm-1][1] = (float)FFmtRead(chCard,&i,76,&lgEOL); if( lgEOL ) { VaryPar.varang[VaryPar.nparm-1][1] = 1e38f; } } } else if( lgMatch("SUBP",chCard) ) { /* use subplex to optimize parameters */ strcpy( chVaryPar.chOptRtn, "SUBP" ); } else if( lgMatch("TOLE",chCard) ) { /* scan off tolerance of fit, sum of residuals must be smaller than this * default is 0.10 */ i = 5; VaryPar.OptGlobalErr = (float)FFmtRead(chCard,&i,76,&lgEOL); } else if( lgMatch("TRAC",chCard) ) { if( lgMatch("STAR",chCard) ) { /* trace start iteration number * turn on trace printout starting on nth call to cloudy */ i = 5; VaryPar.nTrOpt = (long)FFmtRead(chCard,&i,76,&lgEOL); if( lgEOL ) { fprintf( ioQQQ, " optimize trace start command:\n" ); fprintf( ioQQQ, " The iteration number must appear.\n" ); puts( "[Stop in ParseOptimize]" ); exit(1); } VaryPar.lgTrOpt = TRUE; } else if( lgMatch("FLOW",chCard) ) { /* trace flow * follow logical flow within code */ VaryPar.lgOptimFlow = TRUE; } else { fprintf( ioQQQ, " optimize trace flow command:\n" ); fprintf( ioQQQ, " One of the sub keys START or FLOW must appear.\n" ); puts( "[Stop in ParseOptimize]" ); exit(1); } } else { fprintf( ioQQQ, " Unrecognized keyword, consult HAZY.\n" ); puts( "[Stop in ParseOptimize]" ); exit(1); } # ifdef DEBUG_FUN fputs( " <->ParseOptimize()\n", debug_fp ); # endif return; }