| 185 | | |
| 186 | | int IntegerMod ,lgAbort; |
| 187 | | int myrank ; |
| 188 | | double hden , absolute , relative , flux; |
| 189 | | char chVer[10] , chPath[1000] , chFilename[1000] , chFile[2000] ; |
| 190 | | |
| 191 | | double *xpar , *ypar, *par1, *par2; |
| 192 | | |
| 193 | | /* following will become array of line wavelengths and the number of lines |
| 194 | | * in this array */ |
| 195 | | long int mod, nLines, LimModels, nModels; |
| 196 | | |
| 197 | | /* these will be passed to cdGetLineList and will become arrays of |
| 198 | | * labels and wavelengths */ |
| 199 | | char **chLabel ; |
| 200 | | float *wl; |
| 201 | | |
| 202 | | long int |
| 203 | | NumberWarnings1, NumberCautions1, NumberNotes1, NumberSurprises1, NumberTempFailures1, |
| 204 | | NumberPresFailures1, NumberIonFailures1, NumberNeFailures1 ; |
| 205 | | /* number of time Cloudy returned with error condition */ |
| 206 | | int nErrorExits; |
| 207 | | |
| 208 | | FILE *ioOUT , *ioDATA ; |
| 209 | | char chLine[100]; |
| 210 | | |
| 211 | | long int n; |
| 212 | | /* number of processors, =1 for single non-MPI */ |
| 213 | | int numprocs = 1; |
| 214 | | |
| 215 | | /* this will hold a single grid point */ |
| 216 | | GRIDTAG grid; |
| 217 | | |
| 218 | | /* start MPI if -DMPI on command line */ |
| 219 | | # ifdef MPI |
| | 186 | DEBUG_ENTRY( "main()" ); |
| | 187 | |
| | 188 | try { |
| | 189 | bool lgAbort; |
| | 190 | int IntegerMod; |
| | 191 | int myrank ; |
| | 192 | double hden , absolute , relative , flux; |
| | 193 | char chVer[10] , chPath[1000] , chFilename[1000] , chFile[2000] ; |
| | 194 | |
| | 195 | double *xpar , *ypar, *par1, *par2; |
| | 196 | |
| | 197 | /* following will become array of line wavelengths and the number of lines |
| | 198 | * in this array */ |
| | 199 | long int mod, nLines, LimModels, nModels; |
| | 200 | |
| | 201 | /* these will be passed to cdGetLineList and will become arrays of |
| | 202 | * labels and wavelengths */ |
| | 203 | char **chLabel ; |
| | 204 | realnum *wl; |
| | 205 | |
| | 206 | long int |
| | 207 | NumberWarnings1, NumberCautions1, NumberNotes1, NumberSurprises1, NumberTempFailures1, |
| | 208 | NumberPresFailures1, NumberIonFailures1, NumberNeFailures1 ; |
| | 209 | /* number of time Cloudy returned with error condition */ |
| | 210 | int nErrorExits; |
| | 211 | |
| | 212 | FILE *ioOUT , *ioDATA ; |
| | 213 | char chLine[100]; |
| | 214 | |
| | 215 | long int n; |
| | 216 | /* number of processors, =1 for single non-MPI */ |
| | 217 | int numprocs = 1; |
| | 218 | |
| | 219 | /* this will hold a single grid point */ |
| | 220 | GRIDTAG grid; |
| | 221 | |
| | 222 | /* start MPI if -DMPI on command line */ |
| | 223 | # ifdef MPI |
| 232 | | # endif |
| 233 | | |
| 234 | | /* the following is the path for the directory where the output should appear, |
| 235 | | * it needs to end with the OS standard directory delimiter, a "/" on unix */ |
| 236 | | strcpy( chPath , PATHNAME ); |
| 237 | | |
| 238 | | /* this is the first part of the name of the resulting data file. The final |
| 239 | | * file will have this name with a ".lin" after it. */ |
| 240 | | strcpy( chFilename , FILENAME ); |
| 241 | | |
| 242 | | /* ====================================================================== */ |
| 243 | | /* |
| 244 | | * make arrays of parameters for this grid */ |
| 245 | | |
| 246 | | /* total number of models */ |
| 247 | | LimModels = (long)((FLUXLIMIT - FLUXINIT)/INCREMENT + 1.1); |
| 248 | | LimModels *= (long)((HDENLIMIT - HDENINIT)/INCREMENT+1.1); |
| 249 | | /* add number of processors since this is most we would possibly have to |
| 250 | | * add on to make integer number of mpi calls */ |
| 251 | | LimModels += numprocs; |
| 252 | | |
| 253 | | xpar = (double*)malloc(LimModels*sizeof(double) ); |
| 254 | | ypar = (double*)malloc(LimModels*sizeof(double) ); |
| 255 | | par1 = (double*)malloc(LimModels*sizeof(double) ); |
| 256 | | par2 = (double*)malloc(LimModels*sizeof(double) ); |
| 257 | | |
| 258 | | if( xpar==NULL || ypar==NULL || par1==NULL || par2==NULL ) |
| 259 | | { |
| 260 | | fprintf(stderr,"malloc failed\n"); |
| 261 | | # ifdef MPI |
| 262 | | MPI_Finalize(); |
| 264 | | exit(1); |
| 265 | | } |
| 266 | | /* now define set of parameters */ |
| 267 | | hden = HDENINIT; |
| 268 | | flux = FLUXINIT; |
| 269 | | nModels = 0; |
| 270 | | nErrorExits = 0; |
| 271 | | # ifdef MPI |
| 272 | | /* loop along constant U diagonals, starting from |
| 273 | | * bottom right of loc plane, increasing density, |
| 274 | | * and ending on the major diagonal. |
| 275 | | * this is for load leveling on parallel machines */ |
| 276 | | for( hden = HDENLIMIT; hden>= HDENINIT; hden-=INCREMENT ) |
| 277 | | { |
| 278 | | for( flux=FLUXINIT; flux<=FLUXLIMIT; flux+= INCREMENT ) |
| 279 | | { |
| 280 | | if( hden + (flux-FLUXINIT) > HDENLIMIT ) break; |
| 281 | | assert( nModels < LimModels ); |
| 282 | | xpar[nModels] = hden + (flux-FLUXINIT); |
| 283 | | ypar[nModels] = flux; |
| 284 | | par1[nModels] = COLDEN; |
| 285 | | par2[nModels] = 0.; |
| 286 | | ++nModels; |
| 287 | | } |
| 288 | | } |
| 289 | | /* loop increasing flux, starting at lower left plus increment */ |
| 290 | | for( flux=FLUXINIT+INCREMENT; flux<=FLUXLIMIT; flux+= INCREMENT ) |
| 291 | | { |
| 292 | | for( hden = HDENINIT; hden<= HDENLIMIT; hden+=INCREMENT ) |
| 293 | | { |
| 294 | | if( flux + (hden-HDENINIT) > FLUXLIMIT ) break; |
| 295 | | assert( nModels < LimModels ); |
| 296 | | xpar[nModels] = hden ; |
| 297 | | ypar[nModels] = flux + (hden-HDENINIT); |
| 298 | | par1[nModels] = COLDEN; |
| 299 | | par2[nModels] = 0.; |
| 300 | | ++nModels; |
| 301 | | } |
| 302 | | } |
| 303 | | # else |
| 304 | | /* on scalar machines do models in xy order */ |
| 305 | | while( hden < 1.00001 * HDENLIMIT ) |
| 306 | | { |
| 307 | | while( flux < 1.00001*FLUXLIMIT ) |
| 308 | | { |
| 309 | | xpar[nModels] = hden; |
| 310 | | ypar[nModels] = flux; |
| 311 | | par1[nModels] = COLDEN; |
| 312 | | par2[nModels] = 0.; |
| 313 | | ++nModels; |
| 314 | | flux += INCREMENT; |
| 315 | | } |
| 316 | | flux = FLUXINIT; |
| 317 | | hden += INCREMENT; |
| 318 | | } |
| 319 | | # endif |
| 320 | | /* increase total number to an integer multiple of number of processors */ |
| 321 | | if( nModels%numprocs) |
| 322 | | { |
| 323 | | /* add extra bit */ |
| 324 | | IntegerMod = nModels + (numprocs - nModels%numprocs); |
| 325 | | } |
| 326 | | else |
| 327 | | { |
| 328 | | IntegerMod = nModels; |
| 329 | | } |
| 330 | | |
| 331 | | /* make up data for the "extra" models */ |
| 332 | | for( mod=nModels; mod<IntegerMod; ++mod) |
| 333 | | { |
| 334 | | xpar[mod] = xpar[0]; |
| 335 | | ypar[mod] = ypar[0]; |
| 336 | | par1[mod] = par1[0]; |
| 337 | | par2[mod] = par2[0]; |
| 338 | | } |
| 339 | | |
| 340 | | /* ====================================================================== */ |
| 341 | | |
| 342 | | # ifdef MPI |
| 343 | | /* allocate memory for grids */ |
| 344 | | if( (grids = ((GRIDTAG *)malloc( (size_t)(numprocs)*sizeof(GRIDTAG )))) == NULL ) |
| 345 | | { |
| 346 | | fprintf(stderr," main could not malloc grid\n"); |
| 347 | | puts( "[Stop in main]" ); |
| 348 | | # ifdef MPI |
| 349 | | MPI_Finalize(); |
| 350 | | # endif |
| 351 | | exit(1); |
| 352 | | } |
| 353 | | # endif |
| 354 | | |
| 355 | | /* initialize the code so that cdGetLineList can be called */ |
| 356 | | cdInit(); |
| 357 | | /* get list of lines from standard data file. With no arguments this reads |
| 358 | | * the file BLRLineList, part of the standard data distribution. There could |
| 359 | | * have been another file name within the quotes - that file would have been |
| 360 | | * used instead */ |
| 361 | | nLines = cdGetLineList("" , &chLabel , &wl); |
| 362 | | /*nLines = cdGetLineList("NLRLineList.dat" , &chLabel , &wl);*/ |
| 363 | | |
| 364 | | /* now copy version into string to print */ |
| 365 | | cdVersion(chVer); |
| 366 | | |
| 367 | | /* open file for large output if this is desired */ |
| 368 | | if( DO_PRINT ) |
| 369 | | { |
| 370 | | /* now create final filename */ |
| 371 | | strcpy( chFile , chPath ); |
| 372 | | strcat( chFile , chFilename ); |
| 373 | | strcat( chFile , ".out" ); |
| 374 | | ioOUT = fopen(chFile,"w"); |
| 375 | | if( ioOUT == NULL ) |
| 376 | | { |
| 377 | | printf(" main could not open %s for writing.\n", chFile); |
| | 237 | |
| | 238 | /* the following is the path for the directory where the output should appear, |
| | 239 | * it needs to end with the OS standard directory delimiter, a "/" on unix */ |
| | 240 | strcpy( chPath , PATHNAME ); |
| | 241 | |
| | 242 | /* this is the first part of the name of the resulting data file. The final |
| | 243 | * file will have this name with a ".lin" after it. */ |
| | 244 | strcpy( chFilename , FILENAME ); |
| | 245 | |
| | 246 | /* ====================================================================== */ |
| | 247 | /* |
| | 248 | * make arrays of parameters for this grid */ |
| | 249 | |
| | 250 | /* total number of models */ |
| | 251 | LimModels = (long)((FLUXLIMIT - FLUXINIT)/INCREMENT + 1.1); |
| | 252 | LimModels *= (long)((HDENLIMIT - HDENINIT)/INCREMENT+1.1); |
| | 253 | /* add number of processors since this is most we would possibly have to |
| | 254 | * add on to make integer number of mpi calls */ |
| | 255 | LimModels += numprocs; |
| | 256 | |
| | 257 | xpar = (double*)malloc(LimModels*sizeof(double) ); |
| | 258 | ypar = (double*)malloc(LimModels*sizeof(double) ); |
| | 259 | par1 = (double*)malloc(LimModels*sizeof(double) ); |
| | 260 | par2 = (double*)malloc(LimModels*sizeof(double) ); |
| | 261 | |
| | 262 | if( xpar==NULL || ypar==NULL || par1==NULL || par2==NULL ) |
| | 263 | { |
| | 264 | fprintf(stderr,"malloc failed\n"); |
| 399 | | MPI_Finalize(); |
| | 276 | /* loop along constant U diagonals, starting from |
| | 277 | * bottom right of loc plane, increasing density, |
| | 278 | * and ending on the major diagonal. |
| | 279 | * this is for load leveling on parallel machines */ |
| | 280 | for( hden = HDENLIMIT; hden>= HDENINIT; hden-=INCREMENT ) |
| | 281 | { |
| | 282 | for( flux=FLUXINIT; flux<=FLUXLIMIT; flux+= INCREMENT ) |
| | 283 | { |
| | 284 | if( hden + (flux-FLUXINIT) > HDENLIMIT ) break; |
| | 285 | assert( nModels < LimModels ); |
| | 286 | xpar[nModels] = hden + (flux-FLUXINIT); |
| | 287 | ypar[nModels] = flux; |
| | 288 | par1[nModels] = COLDEN; |
| | 289 | par2[nModels] = 0.; |
| | 290 | ++nModels; |
| | 291 | } |
| | 292 | } |
| | 293 | /* loop increasing flux, starting at lower left plus increment */ |
| | 294 | for( flux=FLUXINIT+INCREMENT; flux<=FLUXLIMIT; flux+= INCREMENT ) |
| | 295 | { |
| | 296 | for( hden = HDENINIT; hden<= HDENLIMIT; hden+=INCREMENT ) |
| | 297 | { |
| | 298 | if( flux + (hden-HDENINIT) > FLUXLIMIT ) break; |
| | 299 | assert( nModels < LimModels ); |
| | 300 | xpar[nModels] = hden ; |
| | 301 | ypar[nModels] = flux + (hden-HDENINIT); |
| | 302 | par1[nModels] = COLDEN; |
| | 303 | par2[nModels] = 0.; |
| | 304 | ++nModels; |
| | 305 | } |
| | 306 | } |
| | 307 | # else |
| | 308 | /* on scalar machines do models in xy order */ |
| | 309 | while( hden < 1.00001 * HDENLIMIT ) |
| | 310 | { |
| | 311 | while( flux < 1.00001*FLUXLIMIT ) |
| | 312 | { |
| | 313 | xpar[nModels] = hden; |
| | 314 | ypar[nModels] = flux; |
| | 315 | par1[nModels] = COLDEN; |
| | 316 | par2[nModels] = 0.; |
| | 317 | ++nModels; |
| | 318 | flux += INCREMENT; |
| | 319 | } |
| | 320 | flux = FLUXINIT; |
| | 321 | hden += INCREMENT; |
| | 322 | } |
| 401 | | exit(1); |
| 402 | | } |
| 403 | | |
| 404 | | /* print the header information before we begin the calculation */ |
| 405 | | /* print version number on both headers */ |
| 406 | | fprintf(ioDATA,"Cloudy version %s, %s\n",chVer,TITLE); |
| 407 | | |
| 408 | | for( mod=myrank; mod<IntegerMod; mod+=numprocs ) |
| 409 | | { |
| 410 | | hden = xpar[mod]; |
| 411 | | flux = ypar[mod]; |
| 412 | | /* zero out grid, which will hold all info for a single grid point */ |
| 413 | | memset(&grid, 0, sizeof(GRIDTAG)); |
| 414 | | |
| 415 | | /* initialize the code for this run */ |
| | 324 | /* increase total number to an integer multiple of number of processors */ |
| | 325 | if( nModels%numprocs) |
| | 326 | { |
| | 327 | /* add extra bit */ |
| | 328 | IntegerMod = nModels + (numprocs - nModels%numprocs); |
| | 329 | } |
| | 330 | else |
| | 331 | { |
| | 332 | IntegerMod = nModels; |
| | 333 | } |
| | 334 | |
| | 335 | /* make up data for the "extra" models */ |
| | 336 | for( mod=nModels; mod<IntegerMod; ++mod) |
| | 337 | { |
| | 338 | xpar[mod] = xpar[0]; |
| | 339 | ypar[mod] = ypar[0]; |
| | 340 | par1[mod] = par1[0]; |
| | 341 | par2[mod] = par2[0]; |
| | 342 | } |
| | 343 | |
| | 344 | /* ====================================================================== */ |
| | 345 | |
| | 346 | # ifdef MPI |
| | 347 | /* allocate memory for grids */ |
| | 348 | if( (grids = ((GRIDTAG *)malloc( (size_t)(numprocs)*sizeof(GRIDTAG )))) == NULL ) |
| | 349 | { |
| | 350 | fprintf(stderr," main could not malloc grid\n"); |
| | 351 | # ifdef MPI |
| | 352 | MPI_Finalize(); |
| | 353 | # endif |
| | 354 | cdEXIT(EXIT_FAILURE); |
| | 355 | } |
| | 356 | # endif |
| | 357 | |
| | 358 | /* initialize the code so that cdGetLineList can be called */ |
| 417 | | |
| 418 | | /* direct the standard output to this file */ |
| 419 | | cdOutp(ioOUT); |
| 420 | | |
| 421 | | /* send flag saying whether to create large output */ |
| 422 | | cdTalk( DO_PRINT ); |
| 423 | | |
| 424 | | /* title for grid */ |
| 425 | | sprintf(chLine,"title %s", TITLE); |
| 426 | | n = cdRead( chLine ); |
| 427 | | |
| 428 | | /* print only last iteration? */ |
| 429 | | # if PRINT_LAST |
| 430 | | n = cdRead("print last iteration "); |
| 431 | | # endif |
| 432 | | |
| 433 | | /* option for fast model, or only header */ |
| 434 | | # if QUICK_MODEL |
| 435 | | n = cdRead( "stop zone 3 " );/**/ |
| 436 | | n = cdRead( "constant temper 4 " );/**/ |
| 437 | | # endif |
| 438 | | # if VERY_QUICK_MODEL |
| 439 | | cdNoExec(); |
| 440 | | # endif |
| 441 | | |
| 442 | | /* iterate if not fast model */ |
| 443 | | # if ( (!QUICK_MODEL) && (!VERY_QUICK_MODEL) &&(ITERATIONS!=0) ) |
| 444 | | # if ITERATIONS < 0 |
| 445 | | n = cdRead( "iterate convergence " );/**/ |
| 446 | | # else |
| 447 | | sprintf(chLine,"iterate %i", ITERATIONS); |
| 448 | | n = cdRead( chLine ); |
| 449 | | # endif |
| 450 | | # endif |
| 451 | | |
| 452 | | # ifdef MPI |
| 453 | | /* set flag so that exit handler will call MPI_Finalize */ |
| 454 | | cdMPI(); |
| 455 | | # endif |
| 456 | | |
| 457 | | /* option to turn off file buffering if code might crash */ |
| 458 | | # ifdef NO_BUFFERING |
| 459 | | n = cdRead("no buffering "); |
| 460 | | # endif |
| 461 | | |
| 462 | | /* if we have run off end of array of models say not to execute, |
| 463 | | * still must do something on this processor so that the gather can occur |
| 464 | | * at the bottom of the loop */ |
| 465 | | if( mod >= nModels ) |
| 466 | | cdNoExec(); |
| 467 | | |
| 468 | | /* flux and density */ |
| 469 | | sprintf(chLine,"phi(h) %f", flux); |
| 470 | | n = cdRead( chLine ); |
| 471 | | |
| 472 | | sprintf(chLine,"hden %f", hden); |
| 473 | | n = cdRead( chLine ); |
| 474 | | |
| 475 | | /* turn on large FeII atom, VERY slow */ |
| 476 | | # if FEII |
| 477 | | n = cdRead( "atom feii " ); |
| 478 | | # endif |
| 479 | | |
| 480 | | /* this is the continuum we used in the large apjs paper */ |
| 481 | | n = cdRead( "agn 6.00 -1.40 -0.50 -1.0 " );/**/ |
| 482 | | |
| 483 | | /* a bare powerlaw with a break at 1 microns */ |
| 484 | | /*n = cdRead( "table powerlaw -1.0 1 micron break " );*/ |
| 485 | | |
| 486 | | /* the much maligned Mathews&Ferland continuum */ |
| 487 | | /*n = cdRead( "table agn " );*/ |
| 488 | | |
| 489 | | /*n = cdRead( "blackbody 142,000 " );*/ |
| 490 | | |
| 491 | | /* broken power law used in Fred's paper */ |
| 492 | | /*n = cdRead( "interpolate (0.00000001, -14.899), (0.0091126732, 0.000) " ); |
| 493 | | n = cdRead( "continue (1.00, -1.2242), (73.54, -4.2106) " ); |
| 494 | | n = cdRead( "continue (3675, -5.7395), (7354000, -11.2526) " );*/ |
| 495 | | |
| 496 | | /* broken power law used in Mark's paper */ |
| 497 | | /*n = cdRead( "interpolate (10.517, -30.850) (13.383, -23.684) " ); |
| 498 | | n = cdRead( "continue (16.684, -26.986) (17.383, -27.9996) " ); |
| 499 | | n = cdRead( "continue (18.383, -28.8899) (19.124, -29.268) " ); |
| 500 | | n = cdRead( "continue (22.383, -35.788) " );*/ |
| 501 | | |
| 502 | | /* add cosmic IR background as well */ |
| 503 | | n = cdRead( "background z=0 " ); |
| 504 | | |
| 505 | | sprintf(chLine,"stop column density %f ", par1[mod]); |
| 506 | | n = cdRead( chLine );/**/ |
| 507 | | |
| 508 | | n = cdRead( "failures 3 " ); |
| 509 | | |
| 510 | | /* options to change abundances */ |
| 511 | | # if 0 |
| 512 | | n = cdRead( "metals 10 " );/**/ |
| 513 | | n = cdRead( "element nitrogen scale 10 " );/**/ |
| 514 | | n = cdRead( "element helium scale 1.66 " );/**/ |
| 515 | | n = cdRead( "metals 20 " );/**/ |
| 516 | | n = cdRead( "element nitrogen scale 20 " );/**/ |
| 517 | | n = cdRead( "element helium scale 2.41 " );/**/ |
| 518 | | # endif |
| 519 | | |
| 520 | | /*sprintf(chLine,"turbulence %f km/sec", vturb); |
| 521 | | n = cdRead( chLine );*/ |
| 522 | | |
| 523 | | /* all line intensities will be relative to incident continuum near Lya */ |
| 524 | | n = cdRead( "normalize to label \"inci\" 1215 " ); |
| 525 | | |
| 526 | | /* actually call the code, 1 indicates error exit |
| 527 | | * but this could be warning or abort */ |
| 528 | | grid.lgBadEnd = cdDrive(); |
| 529 | | nErrorExits += grid.lgBadEnd; |
| 530 | | |
| 531 | | /* print header information for very first model only */ |
| 532 | | if( mod==0 ) |
| 533 | | { |
| 534 | | if( (nLines+nFeIIBands+nFeIIConBins) > NLINTOT ) |
| 535 | | { |
| 536 | | fprintf( stderr , "there are too many lines - increase NLINTOT "); |
| 537 | | printf( "there are too many lines - increase NLINTOT "); |
| | 360 | /* get list of lines from standard data file. With no arguments this reads |
| | 361 | * the file BLRLineList, part of the standard data distribution. There could |
| | 362 | * have been another file name within the quotes - that file would have been |
| | 363 | * used instead */ |
| | 364 | nLines = cdGetLineList("" , &chLabel , &wl); |
| | 365 | /*nLines = cdGetLineList("NLRLineList.dat" , &chLabel , &wl);*/ |
| | 366 | |
| | 367 | /* now copy version into string to print */ |
| | 368 | version.chVersion = "c00.00"; |
| | 369 | cdVersion(chVer); |
| | 370 | |
| | 371 | /* open file for large output if this is desired */ |
| | 372 | if( DO_PRINT ) |
| | 373 | { |
| | 374 | /* now create final filename */ |
| | 375 | strcpy( chFile , chPath ); |
| | 376 | strcat( chFile , chFilename ); |
| | 377 | strcat( chFile , ".out" ); |
| | 378 | ioOUT = fopen(chFile,"w"); |
| | 379 | if( ioOUT == NULL ) |
| | 380 | { |
| | 381 | printf(" main could not open %s for writing.\n", chFile); |
| 541 | | exit(1); |
| 542 | | } |
| 543 | | |
| 544 | | /* for very first model (mod==0) send input stream to data file, followed |
| 545 | | * by keyword showing end and finally set of tables */ |
| 546 | | cdPrintCommands( ioDATA ); |
| 547 | | |
| 548 | | /* all the printout happens here */ |
| 549 | | /* print header for the data file */ |
| 550 | | fprintf(ioDATA,"abort\twarn\tExecT\tdensity\tflux\tcolden\tpar2\t"); |
| | 385 | cdEXIT(EXIT_FAILURE); |
| | 386 | } |
| | 387 | } |
| | 388 | else |
| | 389 | { |
| | 390 | /* there should be nothing coming here, but something might */ |
| | 391 | ioOUT = stderr; |
| | 392 | } |
| | 393 | |
| | 394 | /* calculation's results, all the lines in file ending .lin */ |
| | 395 | strcpy( chFile , chPath ); |
| | 396 | strcat( chFile , chFilename ); |
| | 397 | strcat( chFile , ".lin" ); |
| | 398 | ioDATA = fopen(chFile,"w"); |
| | 399 | if( ioDATA == NULL ) |
| | 400 | { |
| | 401 | printf(" could not open %s for writing.\n" , chFile ); |
| | 402 | # ifdef MPI |
| | 403 | MPI_Finalize(); |
| | 404 | # endif |
| | 405 | cdEXIT(EXIT_FAILURE); |
| | 406 | } |
| | 407 | |
| | 408 | /* print the header information before we begin the calculation */ |
| | 409 | /* print version number on both headers */ |
| | 410 | fprintf(ioDATA,"Cloudy version %s, %s\n",chVer,TITLE); |
| | 411 | |
| | 412 | for( mod=myrank; mod<IntegerMod; mod+=numprocs ) |
| | 413 | { |
| | 414 | hden = xpar[mod]; |
| | 415 | flux = ypar[mod]; |
| | 416 | /* zero out grid, which will hold all info for a single grid point */ |
| | 417 | memset(&grid, 0, sizeof(GRIDTAG)); |
| | 418 | |
| | 419 | /* initialize the code for this run */ |
| | 420 | cdInit(); |
| | 421 | |
| | 422 | /* direct the standard output to this file */ |
| | 423 | cdOutp(ioOUT); |
| | 424 | |
| | 425 | /* send flag saying whether to create large output */ |
| | 426 | cdTalk( DO_PRINT ); |
| | 427 | |
| | 428 | /* title for grid */ |
| | 429 | sprintf(chLine,"title %s", TITLE); |
| | 430 | n = cdRead( chLine ); |
| | 431 | |
| | 432 | /* print only last iteration? */ |
| | 433 | # if PRINT_LAST |
| | 434 | n = cdRead("print last iteration "); |
| | 435 | # endif |
| | 436 | |
| | 437 | /* option for fast model, or only header */ |
| | 438 | # if QUICK_MODEL |
| | 439 | n = cdRead( "stop zone 3 " );/**/ |
| | 440 | n = cdRead( "constant temper 4 " );/**/ |
| | 441 | # endif |
| | 442 | # if VERY_QUICK_MODEL |
| | 443 | cdNoExec(); |
| | 444 | # endif |
| | 445 | |
| | 446 | /* iterate if not fast model */ |
| | 447 | # if ( (!QUICK_MODEL) && (!VERY_QUICK_MODEL) &&(ITERATIONS!=0) ) |
| | 448 | # if ITERATIONS < 0 |
| | 449 | n = cdRead( "iterate convergence " );/**/ |
| | 450 | # else |
| | 451 | sprintf(chLine,"iterate %i", ITERATIONS); |
| | 452 | n = cdRead( chLine ); |
| | 453 | # endif |
| | 454 | # endif |
| | 455 | |
| | 456 | # ifdef MPI |
| | 457 | /* set flag so that exit handler will call MPI_Finalize */ |
| | 458 | cdMPI(); |
| | 459 | # endif |
| | 460 | |
| | 461 | /* option to turn off file buffering if code might crash */ |
| | 462 | # ifdef NO_BUFFERING |
| | 463 | n = cdRead("no buffering "); |
| | 464 | # endif |
| | 465 | |
| | 466 | /* if we have run off end of array of models say not to execute, |
| | 467 | * still must do something on this processor so that the gather can occur |
| | 468 | * at the bottom of the loop */ |
| | 469 | |