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.nAverageIonList[ipPun] = (int *)MALLOC(
00072 (size_t)(save.nAverageList[ipPun]*sizeof(int)) );
00073
00074
00075 save.nAverage2ndPar[ipPun] = (int *)MALLOC((size_t)
00076 (save.nAverageList[ipPun]*sizeof(int)) );
00077
00078
00079 save.chAverageType[ipPun] = (char **)MALLOC((size_t)
00080 (save.nAverageList[ipPun]*sizeof(char *)) );
00081
00082
00083 save.chAverageSpeciesLabel[ipPun] = (char **)MALLOC((size_t)
00084 (save.nAverageList[ipPun]*sizeof(char *)) );
00085 for( i=0; i<save.nAverageList[ipPun]; ++i )
00086 {
00087
00088 save.chAverageType[ipPun][i] = (char *)MALLOC((size_t)
00089 (5*sizeof(char)) );
00090
00091
00092 save.chAverageSpeciesLabel[ipPun][i] = (char *)MALLOC((size_t)
00093 (5*sizeof(char)) );
00094 }
00095 }
00096
00097
00098
00099 input.nRead = nLine;
00100
00101 # ifdef PADEBUG
00102 fprintf(ioQQQ , "DEBUG save_average %li species read in.\n",
00103 save.nAverageList[ipPun] );
00104 # endif
00105
00106
00107 p.getline();
00108 if( p.m_lgEOF )
00109 {
00110 fprintf( ioQQQ,
00111 " Punch average hit EOF while reading list; use END to end list.\n" );
00112 cdEXIT(EXIT_FAILURE);
00113 }
00114
00115
00116
00117 nLine = 0;
00118
00119 while( p.strcmp("END" ) != 0 )
00120 {
00121
00122 ++nLine;
00123 if( p.nMatch("TEMP" ))
00124 {
00125
00126 strcpy( save.chAverageType[ipPun][nLine-1] , "TEMP" );
00127 }
00128 else if( p.nMatch("COLU" ))
00129 {
00130
00131 strcpy( save.chAverageType[ipPun][nLine-1] , "COLU" );
00132 }
00133 else if( p.nMatch("IONI" ))
00134 {
00135
00136 strcpy( save.chAverageType[ipPun][nLine-1] , "IONI" );
00137 }
00138 else
00139 {
00140 fprintf(ioQQQ,"PROBLEM one of the jobs TEMPerature, COLUmn density, or IONIzation, must appear.\n");
00141 cdEXIT(EXIT_FAILURE);
00142 }
00143
00144
00145
00146 if( (i = p.GetElem( )) < 0 )
00147 {
00148
00149 fprintf(ioQQQ, "save average did not an element on this line, sorry %s\n",
00150 chCap );
00151 cdEXIT(EXIT_FAILURE);
00152 }
00153 strcpy( save.chAverageSpeciesLabel[ipPun][nLine-1] , elementnames.chElementNameShort[i]);
00154
00155
00156 save.nAverageIonList[ipPun][nLine-1] = (int) p.FFmtRead();
00157 if( p.lgEOL() )
00158 {
00159
00160 p.NoNumb("ionization stage" );
00161 }
00162
00163
00164
00165 if( p.nMatch( "VOLU" ) )
00166 {
00167
00168 save.nAverage2ndPar[ipPun][nLine-1] = 1;
00169 }
00170 else
00171 {
00172
00173 save.nAverage2ndPar[ipPun][nLine-1] = 0;
00174 }
00175
00176
00177 p.getline();
00178 if( p.m_lgEOF )
00179 {
00180 fprintf( ioQQQ, " save averages hit EOF while reading species list; use END to end list.\n" );
00181 cdEXIT(EXIT_FAILURE);
00182 }
00183 }
00184
00185
00186 ASSERT( nLine == save.nAverageList[ipPun]);
00187
00188 # ifdef PADEBUG
00189 for( i=0; i<nLine ; ++i )
00190 {
00191 fprintf(ioQQQ, "PDDEBUG %s %s %i %i\n",
00192 save.chAverageType[ipPun][i],
00193 save.chAverageSpeciesLabel[ipPun][i] ,
00194 save.nAverageIonList[ipPun][i] ,
00195 save.nAverage2ndPar[ipPun][i] );
00196 }
00197 # endif
00198
00199
00200 sprintf(chHeader, "#averages");
00201 for( i=0; i<nLine ; ++i )
00202 {
00203 sprintf(chTemp, "\t %s %s %i %i",
00204 save.chAverageType[ipPun][i],
00205 save.chAverageSpeciesLabel[ipPun][i] ,
00206 save.nAverageIonList[ipPun][i] ,
00207 save.nAverage2ndPar[ipPun][i] );
00208 strcat( chHeader, chTemp );
00209 }
00210 strcat( chHeader, "\n");
00211 }
00212
00213 void save_average(
00214
00215 long int ipPun)
00216 {
00217 long int i;
00218
00219 DEBUG_ENTRY( "save_average()" );
00220
00221
00222 for( i=0; i<save.nAverageList[ipPun] ; ++i )
00223 {
00224 double result;
00225 char chWeight[7];
00226 if( save.nAverage2ndPar[ipPun][i] == 0 )
00227 strcpy( chWeight , "RADIUS");
00228 else
00229 strcpy( chWeight , "VOLUME");
00230
00231 if( strncmp( save.chAverageType[ipPun][i] , "TEMP" , 4 ) == 0)
00232 {
00233
00234 if( cdTemp(
00235 save.chAverageSpeciesLabel[ipPun][i] ,
00236 save.nAverageIonList[ipPun][i] ,
00237 &result ,
00238 chWeight ) )
00239 {
00240 fprintf( ioQQQ, " save average temperature could not identify the species.\n" );
00241 cdEXIT(EXIT_FAILURE);
00242 }
00243
00244 result = log10( result );
00245 }
00246 else if( strncmp( save.chAverageType[ipPun][i] , "IONI" , 4 ) == 0)
00247 {
00248
00249
00250
00251 if( strncmp( "HYDR" ,
00252 save.chAverageSpeciesLabel[ipPun][i] , 4)==0 &&
00253 save.nAverageIonList[ipPun][i]== 0 )
00254 strncpy( save.chAverageSpeciesLabel[ipPun][i],
00255 "H2 " , 4 );
00256 if( cdIonFrac(
00257 save.chAverageSpeciesLabel[ipPun][i] ,
00258 save.nAverageIonList[ipPun][i] ,
00259 &result ,
00260 chWeight ,
00261 false
00262 ) )
00263 {
00264 fprintf( ioQQQ, " save average ionization fraction could not identify the species.\n" );
00265 cdEXIT(EXIT_FAILURE);
00266 }
00267
00268 result = log10( result );
00269 }
00270 else if( strncmp( save.chAverageType[ipPun][i] , "COLU" , 4 ) == 0)
00271 {
00272
00273 if( cdColm(
00274 save.chAverageSpeciesLabel[ipPun][i] ,
00275 save.nAverageIonList[ipPun][i] ,
00276 &result ) )
00277 {
00278 fprintf( ioQQQ, " save average column density fraction could not identify the species.\n" );
00279 cdEXIT(EXIT_FAILURE);
00280 }
00281
00282 result = log10( result );
00283 }
00284 else
00285 TotalInsanity();
00286
00287 fprintf(save.ipPnunit[ipPun], "\t %.3f", result );
00288 }
00289 fprintf(save.ipPnunit[ipPun], "\n");
00290 }