00001
00002
00003
00004 #include "cddefines.h"
00005 #include "grainvar.h"
00006 #include "phycon.h"
00007 #include "input.h"
00008 #include "optimize.h"
00009 #include "parse.h"
00010 #include "grains.h"
00011
00012 void ParseGrain(char *chCard,
00013 bool *lgDSet)
00014 {
00015 bool lgC15 = false,
00016 lgC120 = false,
00017 lgEOL,
00018 lgLinSet,
00019 lgLogLinSet,
00020 lgQuoteFound,
00021 lgSizeDistribution;
00022 char *ptr;
00023 GrainPar gp;
00024
00025
00026 char chFile[FILENAME_PATH_LENGTH_2];
00027 const char *chOption;
00028 long int i;
00029
00030 DEBUG_ENTRY( "ParseGrain()" );
00031
00032 *lgDSet = true;
00033
00034
00035 chFile[0] = '\0';
00036 chOption = "";
00037
00038
00039 lgQuoteFound = strchr( input.chOrgCard,'\"' ) != NULL;
00040 if( lgQuoteFound )
00041 {
00042
00043
00044
00045 GetQuote( chFile , chCard , true );
00046 }
00047
00048 if( nMatch("GREY",chCard) || nMatch("GRAY",chCard) || nMatch("grey_",chFile) )
00049 gp.lgGreyGrain = true;
00050 else
00051 gp.lgGreyGrain = false;
00052
00053
00054
00055
00056 if( nMatch("FUNC",chCard) )
00057 gp.lgAbunVsDepth = true;
00058 else
00059 gp.lgAbunVsDepth = false;
00060
00061
00062
00063
00064 if( !nMatch("SING",chCard) )
00065 lgSizeDistribution = true;
00066 else
00067 lgSizeDistribution = false;
00068
00069
00070
00071 gp.lgForbidQHeating = false;
00072
00073 if( nMatch("QHEA",chCard) )
00074 gp.lgRequestQHeating = true;
00075 else
00076 gp.lgRequestQHeating = false;
00077
00078
00079 if( nMatch("O QH",chCard) )
00080 {
00081 gp.lgForbidQHeating = true;
00082 gp.lgRequestQHeating = false;
00083 phycon.lgPhysOK = false;
00084 }
00085
00086
00087
00088
00089 gv.lgReevaluate = !nMatch(" NO REEV",chCard);
00090
00091
00092 if( nMatch("O HE",chCard) )
00093 {
00094 phycon.lgPhysOK = false;
00095 gv.lgDHetOn = false;
00096 }
00097
00098
00099 if( nMatch("O CO",chCard) )
00100 {
00101 phycon.lgPhysOK = false;
00102 gv.lgDColOn = false;
00103 }
00104
00105
00106 if( (ptr = strstr(chCard,"C120 ")) != NULL )
00107 {
00108 lgC120 = true;
00109
00110 strncpy(ptr," ",5);
00111 }
00112 else if( (ptr = strstr(chCard,"C15 ")) != NULL )
00113 {
00114 lgC15 = true;
00115
00116 strncpy(ptr," ",4);
00117 }
00118
00119
00120 lgLogLinSet = false;
00121 lgLinSet = false;
00122 if( nMatch(" LOG",chCard) )
00123 {
00124 lgLogLinSet = true;
00125 lgLinSet = false;
00126 }
00127 else if( nMatch("LINE",chCard) )
00128 {
00129 lgLogLinSet = true;
00130 lgLinSet = true;
00131 }
00132
00133
00134
00135 i = 5;
00136 gp.dep = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
00137
00138
00139 if( lgLogLinSet )
00140 {
00141
00142 if( lgLinSet )
00143 {
00144
00145 if( gp.dep <= 0. )
00146 {
00147 fprintf( ioQQQ, " Impossible value for linear abundance.\n" );
00148 fprintf( ioQQQ, " Abundance entered was%10.2e\n", gp.dep );
00149 fprintf( ioQQQ, " Sorry.\n" );
00150 puts( "[Stop in ParseGrain]" );
00151 cdEXIT(EXIT_FAILURE);
00152 }
00153 }
00154 else
00155 {
00156 gp.dep = pow(10.,gp.dep);
00157 }
00158 }
00159 else
00160 {
00161
00162
00163 if( gp.dep <= 0. )
00164 {
00165 gp.dep = pow(10.,gp.dep);
00166 }
00167 }
00168
00169 if( gp.dep < FLT_MIN )
00170 {
00171 fprintf( ioQQQ, " Grain abundance entered here (%f) is impossible.\n", gp.dep );
00172 puts( "[Stop in ParseGrain]" );
00173 cdEXIT(EXIT_FAILURE);
00174 }
00175
00176
00177
00178
00179 if( lgQuoteFound )
00180 {
00181
00182 mie_read_opc(chFile,gp);
00183 }
00184 else
00185 {
00186 if( nMatch("ORIO",chCard) )
00187 {
00188
00189
00190
00191
00192
00193 gp.dep *= 0.85;
00194
00195
00196
00197 if( nMatch("GRAP",chCard) )
00198 {
00199
00200 chOption = "ORION GRAPHITE ";
00201 if( lgSizeDistribution )
00202 {
00203 mie_read_opc("graphite_orion_10.opc",gp);
00204 }
00205 else
00206 {
00207 mie_read_opc("graphite_orion_01.opc",gp);
00208 }
00209 }
00210 else if( nMatch("SILI",chCard) )
00211 {
00212
00213 chOption = "ORION SILICATE ";
00214 if( lgSizeDistribution )
00215 {
00216 mie_read_opc("silicate_orion_10.opc",gp);
00217 }
00218 else
00219 {
00220 mie_read_opc("silicate_orion_01.opc",gp);
00221 }
00222 }
00223 else
00224 {
00225
00226 chOption = "ORION ";
00227 if( lgSizeDistribution )
00228 {
00229 mie_read_opc("graphite_orion_10.opc",gp);
00230 mie_read_opc("silicate_orion_10.opc",gp);
00231 }
00232 else
00233 {
00234 mie_read_opc("graphite_orion_01.opc",gp);
00235 mie_read_opc("silicate_orion_01.opc",gp);
00236 }
00237 }
00238 }
00239
00240 else if( nMatch(" PAH",chCard) )
00241 {
00242
00243 if( lgC120 )
00244 {
00245 chOption = "PAH C120 ";
00246 mie_read_opc("pah1_0n682.opc",gp);
00247 }
00248
00249 else if( lgC15 )
00250 {
00251 chOption = "PAH C15 ";
00252 mie_read_opc("pah1_0n341.opc",gp);
00253 }
00254
00255 else
00256 {
00257 chOption = "PAH ";
00258 if( lgSizeDistribution )
00259 {
00260 mie_read_opc("pah1_bt94_10.opc",gp);
00261 }
00262 else
00263 {
00264 mie_read_opc("pah1_bt94_01.opc",gp);
00265 }
00266 }
00267 }
00268
00269 else if( nMatch("GREY",chCard) || nMatch("GRAY",chCard) )
00270 {
00271
00272 chOption = "GREY ";
00273 if( lgSizeDistribution )
00274 {
00275 mie_read_opc("grey_ism_10.opc",gp);
00276 }
00277 else
00278 {
00279 mie_read_opc("grey_ism_01.opc",gp);
00280 }
00281 }
00282
00283 else if( nMatch(" ISM",chCard) )
00284 {
00285 if( nMatch("GRAP",chCard) )
00286 {
00287
00288 chOption = "ISM GRAPHITE ";
00289 if( lgSizeDistribution )
00290 {
00291 mie_read_opc("graphite_ism_10.opc",gp);
00292 }
00293 else
00294 {
00295 mie_read_opc("graphite_ism_01.opc",gp);
00296 }
00297 }
00298 else if( nMatch("SILI",chCard) )
00299 {
00300
00301 chOption = "ISM SILICATE ";
00302 if( lgSizeDistribution )
00303 {
00304 mie_read_opc("silicate_ism_10.opc",gp);
00305 }
00306 else
00307 {
00308 mie_read_opc("silicate_ism_01.opc",gp);
00309 }
00310 }
00311 else
00312 {
00313
00314 chOption = "ISM ";
00315 if( lgSizeDistribution )
00316 {
00317 mie_read_opc("graphite_ism_10.opc",gp);
00318 mie_read_opc("silicate_ism_10.opc",gp);
00319 }
00320 else
00321 {
00322 mie_read_opc("graphite_ism_01.opc",gp);
00323 mie_read_opc("silicate_ism_01.opc",gp);
00324 }
00325 }
00326 }
00327
00328
00329 else
00330 {
00331
00332 if( lgSizeDistribution )
00333 {
00334 mie_read_opc("graphite_ism_10.opc",gp);
00335 mie_read_opc("silicate_ism_10.opc",gp);
00336 }
00337 else
00338 {
00339 mie_read_opc("graphite_ism_01.opc",gp);
00340 mie_read_opc("silicate_ism_01.opc",gp);
00341 }
00342 }
00343 }
00344
00345
00346 if( optimize.lgVarOn )
00347 {
00348 char chHold[INPUT_LINE_LENGTH];
00349 size_t length;
00350
00351 optimize.nvfpnt[optimize.nparm] = input.nRead;
00352 optimize.vparm[0][optimize.nparm] = (float)log10(gp.dep);
00353 optimize.vincr[optimize.nparm] = 1.;
00354
00355
00356
00357 strcpy( optimize.chVarFmt[optimize.nparm] , "GRAIN ABUND=%f LOG ");
00358
00359 if( chFile[0] != '\0' )
00360 {
00361 sprintf(chHold , "\"%s\" ", chFile );
00362 strcat( optimize.chVarFmt[optimize.nparm] , chHold );
00363 }
00364
00365
00366 length = strlen( chOption );
00367
00368
00369
00370
00371 if( length > static_cast<size_t>(FILENAME_PATH_LENGTH_2) )
00372 {
00373 fprintf(ioQQQ," type of grain string length is too long. This is parse_grain\n");
00374 TotalInsanity();
00375 }
00376
00377 strcat( optimize.chVarFmt[optimize.nparm] , chOption );
00378
00379 if( gp.lgAbunVsDepth )
00380 strcat( optimize.chVarFmt[optimize.nparm] , "FUNCTION " );
00381 if( !lgSizeDistribution )
00382 strcat( optimize.chVarFmt[optimize.nparm] , "SINGLE " );
00383 if( gp.lgForbidQHeating )
00384 strcat( optimize.chVarFmt[optimize.nparm] , "NO QHEAT " );
00385 else if( gp.lgRequestQHeating )
00386 strcat( optimize.chVarFmt[optimize.nparm] , "QHEAT " );
00387 if( !gv.lgReevaluate )
00388 strcat( optimize.chVarFmt[optimize.nparm] , "NO REEVALUATE " );
00389 if( !gv.lgDHetOn )
00390 strcat( optimize.chVarFmt[optimize.nparm] , "NO HEATING " );
00391 if( !gv.lgDColOn )
00392 strcat( optimize.chVarFmt[optimize.nparm] , "NO COOLING " );
00393
00394 optimize.nvarxt[optimize.nparm] = 1;
00395 ++optimize.nparm;
00396 }
00397
00398 DEBUG_EXIT( "ParseGrain()" );
00399 return;
00400 }
00401