cloudy
trunk
|
00001 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and 00002 * others. For conditions of distribution and use see copyright notice in license.txt */ 00003 /*ParseRatio derive continuum luminosity of this continuum relative to previous */ 00004 #include "cddefines.h" 00005 #include "optimize.h" 00006 #include "input.h" 00007 #include "rfield.h" 00008 #include "parse.h" 00009 /* HP cc cannot compile following except in -O1 mode */ 00010 #if defined(__HP_aCC) 00011 #pragma OPT_LEVEL 1 00012 #endif 00013 00014 void ParseRatio(char *chCard, 00015 long int *nqh) 00016 { 00017 bool lgAoxOn, 00018 lgEOL; 00019 long int i; 00020 double aox; 00021 00022 DEBUG_ENTRY( "ParseRatio()" ); 00023 00024 /* enter a continuum luminosity as a ratio of 00025 * nuFnu for this continuum relative to a previous continuum 00026 * format; first number is ratio of second to first continuum 00027 * second number is energy for this ratio 00028 * if third numbewr on line, then 2nd number is energy of 00029 * first continuum, while 3rd number is energy of second continuum */ 00030 00031 if( *nqh == 0 ) 00032 { 00033 fprintf( ioQQQ, " Can\'t form ratio since this is first continuum.\n" ); 00034 cdEXIT(EXIT_FAILURE); 00035 } 00036 00037 /* per sq cm or luminosity is really irrelevant */ 00038 strcpy( rfield.chRSpec[*nqh], "SQCM" ); 00039 strcpy( rfield.chSpNorm[*nqh], "RATI" ); 00040 00041 /* this option is to specify alpha ox */ 00042 if( nMatch("ALPH",chCard) ) 00043 { 00044 /* lgAoxOn is flag saying that we will spicify alpha ox */ 00045 lgAoxOn = true; 00046 /* only one parameter to be recognized, alpha ox */ 00047 i = 5; 00048 aox = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00049 00050 /* 403.3 is ratio of energies where alpha ox defined, 00051 * assumed to be 2500A and 2keV */ 00052 rfield.totpow[*nqh] = pow(403.3,aox); 00053 rfield.range[*nqh][0] = 0.3645; 00054 rfield.range[*nqh][1] = 147.; 00055 } 00056 00057 else 00058 { 00059 /* set flag saying that alpha ox will not be specified */ 00060 lgAoxOn = false; 00061 /* set this to impossible number since not used, but lint needs a value */ 00062 aox = -DBL_MAX; 00063 /* specify ratio, two energies */ 00064 i = 5; 00065 rfield.totpow[*nqh] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00066 00067 /* assumed to be a log if negative or zero */ 00068 if( rfield.totpow[*nqh] <= 0. || nMatch(" LOG",chCard ) ) 00069 { 00070 rfield.totpow[*nqh] = pow(10.,rfield.totpow[*nqh]); 00071 } 00072 00073 if( lgEOL ) 00074 { 00075 fprintf( ioQQQ, " There must be a number on this line.\n" ); 00076 cdEXIT(EXIT_FAILURE); 00077 } 00078 00079 rfield.range[*nqh][0] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00080 00081 if( lgEOL ) 00082 { 00083 fprintf( ioQQQ, " There must be at least 2 numbers on this line.\n" ); 00084 fprintf( ioQQQ, " The ratio, and two energies\n" ); 00085 cdEXIT(EXIT_FAILURE); 00086 } 00087 00088 rfield.range[*nqh][1] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00089 00090 /* if only one number then assume same for each */ 00091 if( lgEOL ) 00092 { 00093 rfield.range[*nqh][1] = rfield.range[*nqh][0]; 00094 } 00095 00096 if( rfield.range[*nqh][0] < rfield.emm || 00097 rfield.range[*nqh][1] < rfield.emm ) 00098 { 00099 fprintf( ioQQQ, " One of the energies is too low, outside the range of the code.\n" ); 00100 cdEXIT(EXIT_FAILURE); 00101 } 00102 else if( rfield.range[*nqh][0] > rfield.egamry || rfield.range[*nqh][1] > 00103 rfield.egamry ) 00104 { 00105 fprintf( ioQQQ, " One of the energies is too high, outside the range of the code.\n" ); 00106 cdEXIT(EXIT_FAILURE); 00107 } 00108 } 00109 00110 /* >>chng 06 mar 22, add time option to vary only some continua with time */ 00111 if( nMatch( "TIME" , chCard ) ) 00112 rfield.lgTimeVary[*nqh] = true; 00113 00114 /* vary option */ 00115 if( optimize.lgVarOn ) 00116 { 00117 /* pointer to where to write */ 00118 optimize.nvfpnt[optimize.nparm] = input.nRead; 00119 if( lgAoxOn ) 00120 { 00121 /* this is the number of parameters to feed onto the input line */ 00122 optimize.nvarxt[optimize.nparm] = 1; 00123 /* vary alpha ox */ 00124 strcpy( optimize.chVarFmt[optimize.nparm], "RATIO alphox %f" ); 00125 /* param is linear scale factor */ 00126 optimize.vparm[0][optimize.nparm] = (realnum)aox; 00127 optimize.vincr[optimize.nparm] = 0.2f; 00128 } 00129 else 00130 { 00131 /* this is the number of parameters to feed onto the input line */ 00132 optimize.nvarxt[optimize.nparm] = 3; 00133 strcpy( optimize.chVarFmt[optimize.nparm], "RATIO LOG %f %f %f" ); 00134 /* param is log of abundance by number relative to hydrogen */ 00135 optimize.vparm[0][optimize.nparm] = (realnum)log10(rfield.totpow[*nqh]); 00136 optimize.vparm[1][optimize.nparm] = (realnum)rfield.range[*nqh][0]; 00137 optimize.vparm[2][optimize.nparm] = (realnum)rfield.range[*nqh][1]; 00138 optimize.vincr[optimize.nparm] = 0.2f; 00139 } 00140 ++optimize.nparm; 00141 } 00142 00143 ++*nqh; 00144 if( *nqh >= LIMSPC ) 00145 { 00146 fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" ); 00147 cdEXIT(EXIT_FAILURE); 00148 } 00149 00150 return; 00151 } 00152 #if defined(__HP_aCC) 00153 #pragma OPTIMIZE OFF 00154 #pragma OPTIMIZE ON 00155 #endif