00001
00002
00003
00004 #include "cddefines.h"
00005 #include "cddrive.h"
00006 #include "input.h"
00007 #include "elementnames.h"
00008 #include "save.h"
00009 #include "parser.h"
00010
00011
00012 void parse_save_average(
00013 Parser &p,
00014
00015 long int ipPun,
00016 char *chHeader)
00017 {
00018 long int i;
00019 long int nLine;
00020
00021 DEBUG_ENTRY( "parse_save_average()" );
00022
00023 char chCap[INPUT_LINE_LENGTH];
00024 char chTemp[INPUT_LINE_LENGTH];
00025
00026
00027
00028 nLine = input.nRead;
00029
00030
00031
00032
00033
00034
00035 save.nAverageList[ipPun] = 0;
00036
00037
00038 p.getline();
00039 if( p.m_lgEOF )
00040 {
00041 fprintf( ioQQQ,
00042 " Punch average hit EOF while reading list; use END to end list.\n" );
00043 cdEXIT(EXIT_FAILURE);
00044 }
00045
00046
00047 while( p.strcmp( "END" ) != 0 )
00048 {
00049
00050 ++save.nAverageList[ipPun];
00051
00052
00053 p.getline();
00054 if( p.m_lgEOF )
00055 {
00056 fprintf( ioQQQ, " save averages hit EOF while reading species list; use END to end list.\n" );
00057 cdEXIT(EXIT_FAILURE);
00058 }
00059 }
00060
00061 # ifdef PADEBUG
00062 fprintf(ioQQQ , "DEBUG save_average %li species read in.\n",
00063 save.nAverageList[ipPun] );
00064 # endif
00065
00066
00067
00068 if( save.ipPnunit[ipPun] == NULL )
00069 {
00070
00071 save.SaveAverageFree(ipPun);
00072
00073
00074 save.nAverageIonList[ipPun].resize(save.nAverageList[ipPun]);
00075
00076
00077 save.nAverage2ndPar[ipPun].resize(save.nAverageList[ipPun]);
00078
00079
00080 save.chAverageType[ipPun].resize(save.nAverageList[ipPun]);
00081
00082
00083 save.chAverageSpeciesLabel[ipPun].resize(save.nAverageList[ipPun]);
00084
00085 for( i=0; i < save.nAverageList[ipPun]; ++i )
00086 {
00087
00088 save.chAverageType[ipPun][i] = new char[5];
00089
00090 save.chAverageSpeciesLabel[ipPun][i] = new char[5];
00091 }
00092 }
00093
00094
00095
00096 input.nRead = nLine;
00097
00098 # ifdef PADEBUG
00099 fprintf(ioQQQ , "DEBUG save_average %li species read in.\n",
00100 save.nAverageList[ipPun] );
00101 # endif
00102
00103
00104 p.getline();
00105 if( p.m_lgEOF )
00106 {
00107 fprintf( ioQQQ,
00108 " Punch average hit EOF while reading list; use END to end list.\n" );
00109 cdEXIT(EXIT_FAILURE);
00110 }
00111
00112
00113
00114 nLine = 0;
00115
00116 while( p.strcmp("END" ) != 0 )
00117 {
00118
00119 ++nLine;
00120 if( p.nMatch("TEMP" ))
00121 {
00122
00123 strcpy( save.chAverageType[ipPun][nLine-1] , "TEMP" );
00124 }
00125 else if( p.nMatch("COLU" ))
00126 {
00127
00128 strcpy( save.chAverageType[ipPun][nLine-1] , "COLU" );
00129 }
00130 else if( p.nMatch("IONI" ))
00131 {
00132
00133 strcpy( save.chAverageType[ipPun][nLine-1] , "IONI" );
00134 }
00135 else
00136 {
00137 fprintf(ioQQQ,"PROBLEM one of the jobs TEMPerature, COLUmn density, or IONIzation, must appear.\n");
00138 cdEXIT(EXIT_FAILURE);
00139 }
00140
00141
00142
00143 if( (i = p.GetElem( )) < 0 )
00144 {
00145
00146 fprintf(ioQQQ, "save average did not an element on this line, sorry %s\n",
00147 chCap );
00148 cdEXIT(EXIT_FAILURE);
00149 }
00150 strcpy( save.chAverageSpeciesLabel[ipPun][nLine-1] , elementnames.chElementNameShort[i]);
00151
00152
00153 save.nAverageIonList[ipPun][nLine-1] = (int) p.FFmtRead();
00154 if( p.lgEOL() )
00155 {
00156
00157 p.NoNumb("ionization stage" );
00158 }
00159
00160
00161
00162 if( p.nMatch( "VOLU" ) )
00163 {
00164
00165 save.nAverage2ndPar[ipPun][nLine-1] = 1;
00166 }
00167 else
00168 {
00169
00170 save.nAverage2ndPar[ipPun][nLine-1] = 0;
00171 }
00172
00173
00174 p.getline();
00175 if( p.m_lgEOF )
00176 {
00177 fprintf( ioQQQ, " save averages hit EOF while reading species list; use END to end list.\n" );
00178 cdEXIT(EXIT_FAILURE);
00179 }
00180 }
00181
00182
00183 ASSERT( nLine == save.nAverageList[ipPun]);
00184
00185 # ifdef PADEBUG
00186 for( i=0; i<nLine ; ++i )
00187 {
00188 fprintf(ioQQQ, "PDDEBUG %s %s %i %i\n",
00189 save.chAverageType[ipPun][i],
00190 save.chAverageSpeciesLabel[ipPun][i] ,
00191 save.nAverageIonList[ipPun][i] ,
00192 save.nAverage2ndPar[ipPun][i] );
00193 }
00194 # endif
00195
00196
00197 sprintf(chHeader, "#averages");
00198 for( i=0; i<nLine ; ++i )
00199 {
00200 sprintf(chTemp, "\t %s %s %i %i",
00201 save.chAverageType[ipPun][i],
00202 save.chAverageSpeciesLabel[ipPun][i] ,
00203 save.nAverageIonList[ipPun][i] ,
00204 save.nAverage2ndPar[ipPun][i] );
00205 strcat( chHeader, chTemp );
00206 }
00207 strcat( chHeader, "\n");
00208 }
00209
00210 void save_average(
00211
00212 long int ipPun)
00213 {
00214 long int i;
00215
00216 DEBUG_ENTRY( "save_average()" );
00217
00218
00219 for( i=0; i<save.nAverageList[ipPun] ; ++i )
00220 {
00221 double result;
00222 char chWeight[7];
00223 if( save.nAverage2ndPar[ipPun][i] == 0 )
00224 strcpy( chWeight , "RADIUS");
00225 else
00226 strcpy( chWeight , "VOLUME");
00227
00228 if( strncmp( save.chAverageType[ipPun][i] , "TEMP" , 4 ) == 0)
00229 {
00230
00231 if( cdTemp(
00232 save.chAverageSpeciesLabel[ipPun][i] ,
00233 save.nAverageIonList[ipPun][i] ,
00234 &result ,
00235 chWeight ) )
00236 {
00237 fprintf( ioQQQ, " save average temperature could not identify the species.\n" );
00238 cdEXIT(EXIT_FAILURE);
00239 }
00240
00241 result = log10( result );
00242 }
00243 else if( strncmp( save.chAverageType[ipPun][i] , "IONI" , 4 ) == 0)
00244 {
00245
00246
00247
00248 if( strncmp( "HYDR" ,
00249 save.chAverageSpeciesLabel[ipPun][i] , 4)==0 &&
00250 save.nAverageIonList[ipPun][i]== 0 )
00251 strncpy( save.chAverageSpeciesLabel[ipPun][i],
00252 "H2 " , 4 );
00253 if( cdIonFrac(
00254 save.chAverageSpeciesLabel[ipPun][i] ,
00255 save.nAverageIonList[ipPun][i] ,
00256 &result ,
00257 chWeight ,
00258 false
00259 ) )
00260 {
00261 fprintf( ioQQQ, " save average ionization fraction could not identify the species.\n" );
00262 cdEXIT(EXIT_FAILURE);
00263 }
00264
00265 result = log10( result );
00266 }
00267 else if( strncmp( save.chAverageType[ipPun][i] , "COLU" , 4 ) == 0)
00268 {
00269
00270 if( cdColm(
00271 save.chAverageSpeciesLabel[ipPun][i] ,
00272 save.nAverageIonList[ipPun][i] ,
00273 &result ) )
00274 {
00275 fprintf( ioQQQ, " save average column density fraction could not identify the species.\n" );
00276 cdEXIT(EXIT_FAILURE);
00277 }
00278
00279 result = log10( result );
00280 }
00281 else
00282 TotalInsanity();
00283
00284 fprintf(save.ipPnunit[ipPun], "\t %.3f", result );
00285 }
00286 fprintf(save.ipPnunit[ipPun], "\n");
00287 }