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