/*ParseElement parse options on element command */ #include #include "cddefines.h" #include "varypar.h" #include "abuntabllg.h" #include "abuntablfac.h" #include "abnslr.h" #include "solar.h" #include "elmton.h" #include "scalem.h" #include "input.h" #include "ipsolar.h" #include "elementnames.h" #include "cap4.h" #include "ffmtread.h" #include "lgmatch.h" #include "readar.h" #include "caps.h" #include "parse.h" void ParseElement(char *chCard ) { char chCap[81]; int lgEOL, lgEnd, lgHIT; long int i, iel, j, k; double param; # ifdef DEBUG_FUN fputs( "<+>ParseElement()\n", debug_fp ); # endif /* say that abundances have been changed */ abnslr.lgAbnSolar = FALSE; /* read in list of elements for abundances command */ if( lgMatch("READ",chCard) ) { ipSolarCom.npSolar = 0; for( i=1; i < LIMELM; i++ ) { readar(chCard,&lgEnd); if( lgEnd ) { fprintf( ioQQQ, " Hit EOF while reading element list; use END to end list.\n" ); puts( "[Stop in ParseElement]" ); exit(1); } strcpy( chCap, chCard ); caps(chCap); /* this would be a line starting with END to say end on list */ if( strncmp(chCap,"END",3) == 0 ) { # ifdef DEBUG_FUN fputs( " <->ParseElement()\n", debug_fp ); # endif return; } j = 1; lgHIT = FALSE; while( j < LIMELM && !lgHIT ) { j += 1; if( strncmp( chCap,elementnames.chElementNameShort[j-1] , 4) == 0 ) { ipSolarCom.npSolar += 1; ipSolarCom.ipSolar[ipSolarCom.npSolar-1] = j; lgHIT = TRUE; } } if( !lgHIT ) { fprintf( ioQQQ, "%80.80s\n", chCard ); fprintf( ioQQQ, " Sorry, but I did not recognize element name on this line.\n" ); fprintf( ioQQQ, " Here is the list of names I recognize.\n" ); fprintf( ioQQQ, " " ); for( k=2; k <= LIMELM; k++ ) { fprintf( ioQQQ, "%4.4s", elementnames.chElementNameShort[k-1] ); } fprintf( ioQQQ, " \n" ); puts( "[Stop in ParseElement]" ); exit(1); } } /* fell through, make sure one more line, the end line */ readar(chCard,&lgEnd); strcpy( chCap, chCard ); caps(chCap); if( strncmp(chCap,"END",3) == 0 ) { # ifdef DEBUG_FUN fputs( " <->ParseElement()\n", debug_fp ); # endif return; } else { fprintf( ioQQQ, " Too many elements were entered.\n" ); fprintf( ioQQQ, " I only know about%3ld elements.\n", LIMELM ); fprintf( ioQQQ, " Sorry.\n" ); puts( "[Stop in ParseElement]" ); exit(1); } } /* find which element */ i = 0; /* will be used in remainder of routine to point to particular element */ iel = 0; /* used to signal discovery of element */ lgHIT = FALSE; while( i < LIMELM ) { if( lgMatch((char*)elementnames.chElementNameShort[i],chCard) ) { /* IEL is atomic number of element, is used below */ iel = i; lgHIT = TRUE; break; } ++i; } if( !lgHIT ) { fprintf( ioQQQ, " ParseElement did not find an element on the following line:\n" ); fprintf( ioQQQ, "%80.80s\n", chCard ); puts( "[Stop in ParseElement]" ); exit(1); } /* IEL is the atomic number of the element */ i = 4; param = FFmtRead(chCard,&i,76,&lgEOL); if( lgMatch("SCAL",chCard) ) { /* enter abundance as scale factor, relative to what is in now */ if( lgEOL ) { fprintf( ioQQQ, " There must be a number on this line.\n" ); fprintf( ioQQQ, " Sorry.\n" ); puts( "[Stop in ParseElement]" ); exit(1); } else { if( lgMatch(" LOG",chCard) || param <= 0. ) { /* option for log of scale factor */ param = pow(10.,param); } scalem.ScaleElement[iel] = (float)param; } } else if( lgMatch("ABUN",chCard) ) { /* log of actual abundance */ if( lgEOL ) { fprintf( ioQQQ, " There must be a number on this line.\n" ); fprintf( ioQQQ, " Sorry.\n" ); puts( "[Stop in ParseElement]" ); exit(1); } else { solarCom.solar[iel] = (float)pow(10.,param); if( solarCom.solar[iel]> 1. ) { fprintf( ioQQQ, " Please check the abundance of this element. It seems high to me.\n" ); } } } else if( lgMatch(" OFF",chCard) ) { /* option to turn off this element, set abundance to zero */ elmton.lgElmtOn[iel] = FALSE; if( iel == 0 ) { fprintf( ioQQQ, " It is not possible to turn hydrogen off.\n" ); fprintf( ioQQQ, " Sorry.\n" ); puts( "[Stop in ParseElement]" ); exit(1); } } else if( lgMatch("TABL",chCard) ) { /* >>chng 97 jun 2, add table option * when called, read in densities from input stream */ AbunTablLG.lgAbunTabl[iel] = TRUE; /* general flag saying this option turned on */ AbunTablLG.lgAbTaON = TRUE; if( lgMatch("DEPT",chCard) ) { AbunTablLG.lgAbTaDepth[iel] = TRUE; } else { AbunTablLG.lgAbTaDepth[iel] = FALSE; } /* make sure not trying to change hydrogen */ if( iel == 0 ) { fprintf( ioQQQ, " cannot change abundance of hydrogen.\n" ); fprintf( ioQQQ, " Sorry.\n" ); puts( "[Stop in ParseElement]" ); exit(1); } readar(chCard,&lgEnd); i = 1; AbunTablFac.AbTabRad[0][iel] = (float)FFmtRead(chCard,&i,76,&lgEOL); AbunTablFac.AbTabFac[0][iel] = (float)FFmtRead(chCard,&i,76,&lgEOL); if( lgEOL ) { fprintf( ioQQQ, " no pairs entered - cant interpolate\n" ); puts( "[Stop in ParseElement]" ); exit(1); } AbunTablFac.nAbunTabl = 2; lgEnd = FALSE; while( !lgEnd && AbunTablFac.nAbunTabl < LIMTABD ) { readar(chCard,&lgEnd); if( !lgEnd ) { /* convert first 4 char to caps, into chCap */ cap4(chCap , chCard); if( strncmp(chCap,"END",3) == 0 ) lgEnd = TRUE; } /* lgEnd may have been set within above if, if end line encountered*/ if( !lgEnd ) { i = 1; AbunTablFac.AbTabRad[AbunTablFac.nAbunTabl-1][iel] = (float)FFmtRead(chCard ,&i,76,&lgEOL); AbunTablFac.AbTabFac[AbunTablFac.nAbunTabl-1][iel] = (float)FFmtRead(chCard ,&i,76,&lgEOL); AbunTablFac.nAbunTabl += 1; } } AbunTablFac.nAbunTabl -= 1; /* now chec that abundances are in increasing order */ for( i=1; i < AbunTablFac.nAbunTabl; i++ ) { /* the radius values are assumed to be strictly increasing */ if( AbunTablFac.AbTabRad[i][iel] <= AbunTablFac.AbTabRad[i-1][iel] ) { fprintf( ioQQQ, " abun radii must be in increasing order\n" ); puts( "[Stop in ParseElement]" ); exit(1); } } } else { fprintf( ioQQQ, " There must be a keyword on this line.\n" ); fprintf( ioQQQ, " The keys I know about are TABLE, SCALE and ABUNDANCE.\n" ); fprintf( ioQQQ, " Sorry.\n" ); puts( "[Stop in ParseElement]" ); exit(1); } /* vary option */ if( VaryPar.lgVarOn ) { VaryPar.nvarxt[VaryPar.nparm] = 1; /* pointer to where to write */ VaryPar.nvfpnt[VaryPar.nparm] = input.nRead; if( lgMatch("SCAL",chCard) ) { /* vary scale factor */ sprintf( chVaryPar.chVarFmt[VaryPar.nparm], "ELEMENT %4.4s SCALE%%f LOG", elementnames.chElementNameShort[iel] ); /* param is linear scale factor */ VaryPar.vparm[0][VaryPar.nparm] = (float)log10(param); VaryPar.vincr[VaryPar.nparm] = 0.2f; } else if( lgMatch("ABUN",chCard) ) { /* vary absolute abundance */ sprintf( chVaryPar.chVarFmt[VaryPar.nparm], "ELEMENT %4.4s ABUND %%f LOG ", elementnames.chElementNameShort[iel] ); /* param is log of abundance by number relative to hydrogen */ VaryPar.vparm[0][VaryPar.nparm] = (float)param; VaryPar.vincr[VaryPar.nparm] = 0.2f; } ++VaryPar.nparm; } # ifdef DEBUG_FUN fputs( " <->ParseElement()\n", debug_fp ); # endif return; }