/*ParseAbundances parse and read in composition as set by abundances command */ #include #include "cddefines.h" #include "grainvar.h" #include "ipsolar.h" #include "solar.h" #include "solars.h" #include "called.h" #include "elmton.h" #include "elementnames.h" #include "caps.h" #include "ffmtread.h" #include "lgmatch.h" #include "readar.h" #include "strbst.h" #include "parse.h" void ParseAbundances(char *chCard, int lgDSet) { int lgEOF, lgEOL, lgLog; long int i, k , j, nd; double absav[LIMELM], chk; # ifdef DEBUG_FUN fputs( "<+>ParseAbundances()\n", debug_fp ); # endif j = 5; absav[0] = FFmtRead(chCard,&j,76,&lgEOL); /* check whether it scanned off end of line on first try * >>chng 97 june 8, get rid of go to * if( lgEOL ) go to10 */ if( !lgEOL ) { absav[1] = FFmtRead(chCard,&j,76,&lgEOL); if( lgEOL && lgMatch(" ALL",chCard) ) { /* special option, all abundances will be this number */ if( absav[0] <= 0. ) { absav[0] = pow(10.,absav[0]); } for( i=1; i < LIMELM; i++ ) { solarCom.solar[i] = (float)absav[0]; } # ifdef DEBUG_FUN fputs( " <->ParseAbundances()\n", debug_fp ); # endif return; } /* >>chng 95 july 14, get rid of go to's */ if( !lgEOL ) { /* do this is there was a second number */ for( i=2; i < ipSolarCom.npSolar; i++ ) { absav[i] = FFmtRead(chCard,&j,76,&lgEOL); if( lgEOL ) { /* read CONTINUE line if J scanned off end before reading all abund */ readar(chCard,&lgEOF); if( lgEOF ) { fprintf( ioQQQ, " There MUST be%3ld abundances entered, there were only%3ld. Sorry.\n", ipSolarCom.npSolar, i ); puts( "[Stop in ParseAbundances]" ); exit(1); } /* option to ignore all lines starting with #, *, or %. */ while( (chCard[0] == '#' || chCard[0] == '*') || chCard[0] == '%' ) { if( lgEOF ) { fprintf( ioQQQ, " There MUST be%3ld abundances entered, there were only%3ld. Sorry.\n", ipSolarCom.npSolar, i ); puts( "[Stop in ParseAbundances]" ); exit(1); } /* read in another line */ readar(chCard,&lgEOF); } /* we have the line image, print it */ if( called.lgTalk ) { fprintf( ioQQQ, " * "); k=0; while( chCard[k]!='\0' ) { fprintf(ioQQQ,"%c",chCard[k]); ++k; } while( k<80 ) { fprintf(ioQQQ,"%c",' '); ++k; } fprintf( ioQQQ,"*\n"); } /* now convert to caps */ caps(chCard); if( strncmp(chCard,"CONT",4) != 0 ) { fprintf( ioQQQ, " There MUST be%3ld abundances entered, there were only%3ld. Sorry.\n", ipSolarCom.npSolar, i ); puts( "[Stop in ParseAbundances]" ); exit(1); } else { j = 1; absav[i] = FFmtRead(chCard,&j,76,&lgEOL); if( lgEOF ) { fprintf( ioQQQ, " There MUST be%3ld abundances entered, there were only%3ld. Sorry.\n", ipSolarCom.npSolar, i); puts( "[Stop in ParseAbundances]" ); exit(1); } } } } /* fell through to here after reading in abundances * check that there are no more - could mean typo further upstream */ chk = FFmtRead(chCard,&j,76,&lgEOL); if( !lgEOL || (chk!=0.) ) { /* got another number, not lgEOL, so too many numbers */ fprintf( ioQQQ, " There were more than %3ld abundances entered\n", ipSolarCom.npSolar ); fprintf( ioQQQ, " Could there have been a typo somewhere?\n" ); } /* are numbers scale factors, or log of abund rel to H?? */ lgLog = FALSE; for( i=0; i < ipSolarCom.npSolar; i++ ) { if( absav[i] < 0. ) lgLog = TRUE; } if( lgLog ) { /* entered as log of number rel to hydrogen */ for( i=0; i < ipSolarCom.npSolar; i++ ) { solarCom.solar[ipSolarCom.ipSolar[i]-1] = (float)pow(10.,absav[i]); } } else { /* scale factors relative to solar */ for( i=0; i < ipSolarCom.npSolar; i++ ) { solarCom.solar[ipSolarCom.ipSolar[i]-1] *= (float)absav[i]; } } /* check whether the abundances are reasonable */ if( solarCom.solar[1] > 0.2 ) { fprintf( ioQQQ, " Is an abundance of%10.3e for %2.2s reasonable?\n", solarCom.solar[1], elementnames.chElementSym[1] ); } for( i=2; i < LIMELM; i++ ) { if( solarCom.solar[i] > 0.1 ) { fprintf( ioQQQ, " Is an abundance of%10.3e for %2.2s reasonable?\n", solarCom.solar[i], elementnames.chElementSym[i] ); } } # ifdef DEBUG_FUN fputs( " <->ParseAbundances()\n", debug_fp ); # endif return; } } /* no numbers on line if it got this far */ /* enter std abundances for various objects */ if( lgMatch("PLAN",chCard) ) { /* planetary nebular abundances */ if( !lgMatch("O GR",chCard) ) { /* turn on grains if not already done */ if( !lgDSet ) { GrainVar.lgDustOn = TRUE; for( nd=0; nd < NDUST; nd++ ) { GrainVar.dstfactor[nd] = 1.; /* >>chng 96 nov 29, loop setting false, followed by two set true */ GrainVar.lgDustOn1[nd] = FALSE; } GrainVar.lgDustOn1[0] = TRUE; GrainVar.lgDustOn1[6] = TRUE; } } for( i=0; i < LIMELM; i++ ) { solarCom.solar[i] = solars.apn[i]; } } else if( (lgMatch("HII ",chCard) || lgMatch("H II",chCard)) || lgMatch("ORIO",chCard) ) { /* H II region abundances */ if( !lgMatch("O GR",chCard) ) { /* option to turn on grains */ if( !lgDSet ) { GrainVar.lgDustOn = TRUE; for( nd=0; nd < NDUST; nd++ ) { GrainVar.dstfactor[nd] = 1.; /* >>chng 96 nov 29, loop setting false, followed by two set true */ GrainVar.lgDustOn1[nd] = FALSE; } /* orion grains */ GrainVar.lgDustOn1[2] = TRUE; GrainVar.lgDustOn1[3] = TRUE; } } for( i=0; i < LIMELM; i++ ) { solarCom.solar[i] = solars.ahii[i]; } } else if( lgMatch("ISM ",chCard) || lgMatch(" ISM",chCard) ) { /* ISM abundances from Cowie and Songaila Ann Rev '86 */ if( !lgMatch("O GR",chCard) ) { if( !lgDSet ) { GrainVar.lgDustOn = TRUE; for( nd=0; nd < NDUST; nd++ ) { GrainVar.dstfactor[nd] = 1.; GrainVar.lgDustOn1[nd] = FALSE; /* >>chng 96 nov 29, loop setting false, followed by two set true */ } /* ism grains */ GrainVar.lgDustOn1[0] = TRUE; GrainVar.lgDustOn1[1] = TRUE; } } for( i=0; i < LIMELM; i++ ) { solarCom.solar[i] = solars.aism[i]; } } else if( lgMatch("NOVA",chCard) ) { /* Nova Cyg abundances */ for( i=0; i < LIMELM; i++ ) { solarCom.solar[i] = solars.anova[i]; } } else if( lgMatch("STAR",chCard) ) { /* Fred Hamonn's starburst galaxy mixture */ strbst(chCard); } else if( lgMatch("PRIM",chCard) ) { /* roughly primordial abundances: He/H=.072 */ for( i=0; i < LIMELM; i++ ) { solarCom.solar[i] = solars.aprim[i]; } /* now turn off the heavy elements */ for( i=4; i < LIMELM; i++ ) { elmton.lgElmtOn[i] = FALSE; } } else if( lgMatch("CAME",chCard) ) { /* mix from Cameron 1982, "Essays on Nuclear Astrophysics" */ for( i=0; i < LIMELM; i++ ) { solarCom.solar[i] = solars.camern[i]; } } else { fprintf( ioQQQ, " ABUND must have PLAN, H II, CAMERON, NOVA, NLR, ALL, STARBURST or PRIMORDIAL. Sorry.\n" ); puts( "[Stop in ParseAbundances]" ); exit(1); } # ifdef DEBUG_FUN fputs( " <->ParseAbundances()\n", debug_fp ); # endif return; }