00001
00002
00003
00004
00005
00006 #include "cddefines.h"
00007 #include "cddrive.h"
00008 #include "input.h"
00009 #include "prt.h"
00010 #include "punch.h"
00011 #include "assertresults.h"
00012 #include "grains.h"
00013
00014 int main( int argc, char *argv[] )
00015 {
00016
00017 long int NumberWarnings,
00018 NumberCautions,
00019 NumberNotes,
00020 NumberSurprises,
00021 NumberTempFailures,
00022 NumberPresFailures,
00023 NumberIonFailures,
00024 NumberNeFailures;
00025
00026 bool lgAbort_exit,
00027 lgFileIO ,
00028 lgBadExit;
00029
00030 int nread=0;
00031
00032 int i,
00033 lenp,
00034 leno,
00035 leni,
00036 lena;
00037 char *s,
00038 *prefix = NULL,
00039 *filename,
00040 outtag[] = ".out",
00041 intag[] = ".in";
00042
00043
00044
00045
00046
00047
00048 char chLine[10000];
00049
00050
00051 lgFileIO = false;
00052
00053
00054
00055
00056
00057
00058
00059 for(i=1; i<argc; i++)
00060 {
00061 s = argv[i];
00062 if(*s != '-')
00063 {
00064 fprintf(stderr,"%s: argument %d `%s' not understood\n",argv[0],i,s);
00065 exit(-1);
00066 }
00067 else
00068 {
00069 while (s != NULL && *(++s)) {
00070 switch (*s)
00071 {
00072 case 'p':
00073 if(s[1] != '\0')
00074 {
00075 prefix = s+1;
00076 }
00077 else
00078 {
00079 if(++i == argc || argv[i][0] == '-') {
00080 fprintf(stderr,"%s: no argument given for -p flag\n",argv[0]);
00081 exit(-1);
00082 }
00083 prefix = argv[i];
00084 }
00085 s = NULL;
00086 lgFileIO = true;
00087 break;
00088 default:
00089 fprintf(stderr,"%s: argument %d, `%s': flag -%c not understood\n",argv[0],i,argv[i],*s);
00090 exit(-1);
00091 }
00092 }
00093 }
00094 }
00095
00096
00097 cdInit();
00098
00099
00100 if( lgFileIO )
00101 {
00102 FILE *ioOut, *ioInp;
00103 if(prefix == NULL)
00104 {
00105
00106
00107 if( (ioOut = fopen("c:\\projects\\cloudy\\tests\\CallCloudy.txt", "w" ))==NULL)
00108 BadOpen();
00109 cdOutp(ioOut);
00110 }
00111 else
00112 {
00113 leno = (int)strlen(outtag);
00114 leni = (int)strlen(intag);
00115 lenp = (int)strlen(prefix);
00116 if(leno > leni)
00117 lena = lenp+leno+1;
00118 else
00119 lena = lenp+leni+1;
00120 filename = (char *)MALLOC((unsigned)lena*sizeof(char));
00121 if(filename == NULL)
00122 {
00123 fprintf(stderr,"%s: can't allocate memory\n",argv[0]);
00124 exit(-1);
00125 }
00126 strcpy(filename,prefix);
00127 strcpy(filename+lenp,outtag);
00128 if( (ioOut = fopen(filename, "w" ))==NULL)
00129 BadOpen();
00130 cdOutp(ioOut);
00131 strcpy(filename+lenp,intag);
00132 if( (ioInp = fopen(filename, "r" ))==NULL)
00133 BadOpen();
00134 cdInp(ioInp);
00135 strcpy( punch.chFilenamePrefix , prefix );
00136 free(filename);
00137 }
00138 }
00139
00140 nread = 1;
00141
00142 while( fgets(chLine, (int)sizeof(chLine), ioStdin)!= NULL )
00143 {
00144 char *chChar;
00145
00146
00147
00148
00149
00150 if( (chLine[0]=='\n') || (chLine[0]==13) ||
00151 ( (chLine[0]==' ')&& (chLine[23]!='*') )
00152 ) break;
00153
00154
00155
00156
00157 if( !lgInputComment(chLine) )
00158 {
00159 if( (chChar = strchr(chLine , '\"' ) ) ==NULL )
00160 {
00161
00162 while( (chChar = strchr(chLine , '_' ) ) !=NULL )
00163 {
00164 *chChar = ' ';
00165 input.lgUnderscoreFound = true;
00166 }
00167 }
00168
00169
00170 while( (chChar = strchr(chLine , '[' ) ) !=NULL )
00171 {
00172 *chChar = ' ';
00173 input.lgBracketFound = true;
00174 }
00175
00176 while( (chChar = strchr(chLine , ']' ) ) !=NULL )
00177 {
00178 *chChar = ' ';
00179 input.lgBracketFound = true;
00180 }
00181 }
00182
00183
00184
00185 if( strncmp(chLine," * ",25) == 0 )
00186 {
00187
00188 nread = cdRead( chLine+25 );
00189 }
00190 else
00191 {
00192
00193 nread = cdRead( chLine );
00194 }
00195 }
00196 if( nread <= 0 )
00197 {
00198 fprintf(ioQQQ," Warning: limit to number of lines exceeded, %i\n", nread);
00199 }
00200
00201
00202
00203
00204
00205
00206 if( cdDrive() )
00207 lgBadExit = true;
00208 else
00209 lgBadExit = false;
00210
00211
00212 cdNwcns(
00213
00214 &lgAbort_exit,
00215
00216 &NumberWarnings,
00217 &NumberCautions,
00218 &NumberNotes,
00219 &NumberSurprises,
00220
00221 &NumberTempFailures,
00222
00223 &NumberPresFailures,
00224
00225 &NumberIonFailures,
00226
00227 &NumberNeFailures );
00228
00229 fprintf( ioQQQ,
00230 " Cloudy ends:%4ld zone" ,
00231 nzone);
00232
00233
00234 if( nzone > 1 )
00235 {
00236 fprintf( ioQQQ,"s");
00237 }
00238
00239 fprintf( ioQQQ,
00240 ", %3ld iteration" ,
00241 iteration );
00242
00243
00244 if( iteration > 1 )
00245 {
00246 fprintf( ioQQQ,"s");
00247 }
00248
00249 if( lgAbort_exit )
00250 {
00251 fprintf( ioQQQ,
00252 ", ABORT ABORT" );
00253 }
00254
00255 if( NumberWarnings > 0 )
00256 {
00257 fprintf( ioQQQ,
00258 ",%3ld warning",
00259 NumberWarnings);
00260
00261
00262 if( NumberWarnings > 1 )
00263 {
00264 fprintf( ioQQQ,"s");
00265 }
00266
00267 lgBadExit = 1;
00268 }
00269
00270 if( NumberCautions > 0 )
00271 {
00272 fprintf( ioQQQ,
00273 ",%3ld caution",
00274 NumberCautions);
00275
00276
00277 if( NumberCautions > 1 )
00278 {
00279 fprintf( ioQQQ,"s");
00280 }
00281 }
00282
00283
00284 if( !lgAssertsOK )
00285 {
00286 fprintf(ioQQQ,", ");
00287
00288 if( lgBigBotch )
00289 fprintf(ioQQQ,"BIG ");
00290 fprintf(ioQQQ,"BOTCHED ASSERTS!!!");
00291
00292 lgBadExit = 1;
00293 }
00294
00295 if( NumberTempFailures+NumberPresFailures +NumberIonFailures+NumberNeFailures >0 )
00296 {
00297 fprintf( ioQQQ,
00298 ". Failures:%3ld thermal,%3ld pressure,%3ld ionization,%3ld electron density",
00299 NumberTempFailures,
00300 NumberPresFailures ,
00301 NumberIonFailures,
00302 NumberNeFailures);
00303 }
00304
00305
00306
00307 if( prt.lgPrintTime )
00308 {
00309
00310
00311
00312 fprintf( ioQQQ, ". ExecTime(s) %.2f", cdExecTime());
00313 }
00314
00315 fprintf( ioQQQ, "\n");
00316
00317 if( lgBadExit )
00318 {
00319 fprintf(ioQQQ, " [Stop in maincl, something went wrong]\n" );
00320 }
00321 else
00322 {
00323 fprintf(ioQQQ, " [Stop in maincl, Cloudy exited OK]\n" );
00324 }
00325
00326
00327 ReturnGrainBins();
00328
00329
00330
00331 return(lgBadExit);
00332 }