00001 /* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and 00002 * others. For conditions of distribution and use see copyright notice in license.txt */ 00003 /*ParseMetal parse parameters on metal command */ 00004 #include "cddefines.h" 00005 #include "input.h" 00006 #include "optimize.h" 00007 #include "grainvar.h" 00008 #include "called.h" 00009 #include "abund.h" 00010 #include "parser.h" 00011 00012 void ParseMetal(Parser &p ) 00013 { 00014 bool 00015 lgGrains, 00016 lgLogOn; 00017 double dmlog; 00018 00019 DEBUG_ENTRY( "ParseMetal()" ); 00020 00021 /* parse the metals command */ 00022 00023 /* metal depletion factor, if negative then it is the log */ 00024 abund.lgAbnSolar = false; 00025 abund.ScaleMetals = (realnum)p.FFmtRead(); 00026 if( p.lgEOL() ) 00027 { 00028 if( p.nMatch("DEPL") ) 00029 { 00030 /* this option - no numbers on line but keyword depletion is 00031 * deplete by set of scale factors */ 00032 abund.lgDepln = true; 00033 for( long int i=0; i < LIMELM; i++ ) 00034 { 00035 abund.depset[i] = abund.Depletion[i]; 00036 } 00037 abund.ScaleMetals = 1.; 00038 return; 00039 } 00040 else 00041 { 00042 /* no number, so keyword, punch out */ 00043 if( !called.lgTalk ) 00044 { 00045 p.PrintLine( ioQQQ ); 00046 } 00047 fprintf( ioQQQ, " There must be a number on this line. Sorry.\n" ); 00048 cdEXIT(EXIT_FAILURE); 00049 } 00050 } 00051 00052 /* sort out whether log */ 00053 lgLogOn = false; 00054 if( p.nMatch(" LOG") ) 00055 { 00056 lgLogOn = true; 00057 } 00058 else if( p.nMatch("LINE") ) 00059 { 00060 lgLogOn = false; 00061 } 00062 00063 if( abund.ScaleMetals <= 0. || lgLogOn ) 00064 { 00065 dmlog = abund.ScaleMetals; 00066 abund.ScaleMetals = (realnum)pow((realnum)10.f,abund.ScaleMetals); 00067 } 00068 else 00069 { 00070 dmlog = log10(abund.ScaleMetals); 00071 } 00072 00073 /* option to vary grain abundance as well */ 00074 if( p.nMatch("GRAI") ) 00075 { 00076 lgGrains = true; 00077 gv.GrainMetal = abund.ScaleMetals; 00078 } 00079 else 00080 { 00081 lgGrains = false; 00082 gv.GrainMetal = 1.; 00083 } 00084 00085 /* vary option */ 00086 if( optimize.lgVarOn ) 00087 { 00088 strcpy( optimize.chVarFmt[optimize.nparm], "METALS= %f LOG" ); 00089 if( lgGrains ) 00090 strcat( optimize.chVarFmt[optimize.nparm], " GRAINS" ); 00091 /* pointer to where to write */ 00092 optimize.nvfpnt[optimize.nparm] = input.nRead; 00093 optimize.vparm[0][optimize.nparm] = (realnum)dmlog; 00094 optimize.vincr[optimize.nparm] = 0.5; 00095 optimize.nvarxt[optimize.nparm] = 1; 00096 ++optimize.nparm; 00097 } 00098 return; 00099 }