00001
00002
00003 #include "cddefines.h"
00004 #include "lines_service.h"
00005 #include "taulines.h"
00006 #include "trace.h"
00007 #include "string.h"
00008 #include "input.h"
00009 #include "thirdparty.h"
00010 #include "dense.h"
00011 #include "atmdat.h"
00012 #include "mole.h"
00013 #include "elementnames.h"
00014 #include "version.h"
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 STATIC void states_popfill(void);
00034 STATIC void states_nelemfill(void);
00035 STATIC void database_prep(int);
00036 STATIC void set_fractionation( species *sp );
00037 STATIC void states_propprint(void);
00038
00039 STATIC void SpeciesJunk( species *sp );
00040
00041 #define DEBUGSTATE false
00042 void database_readin( void )
00043 {
00044 int i,intNoSp;
00045
00046 FILE *ioMASTERLIST, *ioVERSION;
00047
00048 char *chToken;
00049
00050 char chLine[FILENAME_PATH_LENGTH_2],
00051 chDLine[FILENAME_PATH_LENGTH_2],
00052 chPath[FILENAME_PATH_LENGTH_2] = "";
00053
00054 const int MAX_NUM_SPECIES = 1000;
00055
00056 char chLabels[MAX_NUM_SPECIES][CHARS_SPECIES];
00057 char chLabelsOrig[MAX_NUM_SPECIES][CHARS_SPECIES];
00058 char chPaths[MAX_NUM_SPECIES][FILENAME_PATH_LENGTH_2];
00059
00060 static int nCalled = 0;
00061 long nSpeciesLAMDA, nSpeciesSTOUT, nSpeciesCHIANTI;
00062
00063 DEBUG_ENTRY( "database_readin()" );
00064
00065
00066 if( nCalled > 0 )
00067 {
00068 return;
00069 }
00070
00071
00072 ++nCalled;
00073
00074
00075 nSpecies = 0;
00076
00078
00079
00080
00082
00083
00084
00085 nSpeciesLAMDA = 0;
00086
00087 if( atmdat.lgLamdaOn )
00088 {
00089 long numModelsNotUsed = 0;
00090 strcpy( chPath, "lamda" );
00091 strcat( chPath, input.chDelimiter );
00092 strcat( chPath, "masterlist" );
00093 ioMASTERLIST = open_data( chPath, "r" );
00094
00095 if( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) == NULL )
00096 {
00097 fprintf( ioQQQ, " database_readin could not read first line of LAMDA masterlist.\n");
00098 cdEXIT(EXIT_FAILURE);
00099 }
00100
00101 do
00102 {
00103 if ((chLine[0]!='#') && (chLine[0]!='\n')&&(chLine[0]!='\t')&&(chLine[0]!='\r'))
00104 {
00105 strcpy(chDLine, chLine);
00106 chToken = strtok(chDLine," \t\n");
00107 if( findspecies( chToken ) != null_mole ||
00108 ( chToken[1]=='-' && findspecies( chToken+2 ) != null_mole ) )
00109 {
00110 ASSERT( nSpecies + 1 <= MAX_NUM_SPECIES );
00111 ASSERT( nSpeciesLAMDA + 1 <= MAX_NUM_SPECIES );
00112 ASSERT( strlen(chToken) < CHARS_SPECIES );
00113 strcpy( chLabels[nSpecies], chToken );
00114 chLabels[nSpecies][CHARS_SPECIES-1] = '\0';
00115
00116
00117 strcpy( chPaths[nSpecies], "lamda" );
00118 strcat( chPaths[nSpecies], input.chDelimiter );
00119 chToken = strtok( NULL," \t\n" );
00120 strcat( chPaths[nSpecies], chToken );
00121 ++nSpecies;
00122 ++nSpeciesLAMDA;
00123 }
00124 else
00125 ++numModelsNotUsed;
00126 }
00127 }
00128 while( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) != NULL );
00129
00130
00131
00132
00133
00134 fclose(ioMASTERLIST);
00135 }
00136
00138
00139
00140
00141
00142
00144
00145 if( atmdat.lgCalpgmOn )
00146 {
00147 long numModelsNotUsed = 0;
00148 strcpy( chPath, "cdms+jpl" );
00149 strcat( chPath, input.chDelimiter );
00150 strcat( chPath, "masterlist" );
00151 ioMASTERLIST = open_data( chPath, "r" );
00152
00153 if( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) == NULL )
00154 {
00155 fprintf( ioQQQ, " database_readin could not read first line of CDMS/JPL masterlist.\n");
00156 cdEXIT(EXIT_FAILURE);
00157 }
00158
00159 do
00160 {
00161 if ((chLine[0]!='#') && (chLine[0]!='\n')&&(chLine[0]!='\t')&&(chLine[0]!='\r'))
00162 {
00163 strcpy(chDLine, chLine);
00164 chToken = strtok(chDLine," \t\n");
00165
00166 if( strcmp( chToken, "SH" ) == 0 )
00167 strcpy( chToken, "HS" );
00168 if( strcmp( chToken, "SH+" ) == 0 )
00169 strcpy( chToken, "HS+" );
00170 if( strcmp( chToken, "CCH" ) == 0 )
00171 strcpy( chToken, "C2H" );
00172 if( findspecies( chToken ) != null_mole ||
00173 ( chToken[1]=='-' && findspecies( chToken+2 ) != null_mole ) )
00174 {
00175 ASSERT( nSpecies + 1 <= MAX_NUM_SPECIES );
00176 ASSERT( nSpeciesLAMDA + 1 <= MAX_NUM_SPECIES );
00177 strcpy( chLabels[nSpecies], chToken );
00178 chLabels[nSpecies][CHARS_SPECIES-1] = '\0';
00179
00180 strcpy( chPaths[nSpecies], "cdms+jpl" );
00181 strcat( chPaths[nSpecies], input.chDelimiter );
00182 chToken = strtok( NULL," \t\n" );
00183 strcat( chPaths[nSpecies], chToken );
00184 ++nSpecies;
00185 ++nSpeciesLAMDA;
00186 }
00187 else
00188 ++numModelsNotUsed;
00189 }
00190 }
00191 while( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) != NULL );
00192
00193
00194
00195
00196
00197 fclose(ioMASTERLIST);
00198 }
00199
00201
00202
00203
00205 nSpeciesSTOUT = 0;
00206 if( atmdat.lgStoutOn )
00207 {
00208
00209 strcpy( chPath, "stout" );
00210 strcat( chPath, input.chDelimiter );
00211 strcat( chPath, "masterlist" );
00212 strcat( chPath, input.chDelimiter );
00213
00214 strcat( chPath, atmdat.chStoutFile );
00215
00216
00217 if( (ioMASTERLIST = fopen( atmdat.chStoutFile , "r" ) ) == NULL )
00218 {
00219 ioMASTERLIST = open_data( chPath, "r" );
00220 }
00221
00222
00223 if( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) == NULL )
00224 {
00225 fprintf( ioQQQ, " database_readin could not read first line of stout.ini.\n");
00226 cdEXIT(EXIT_FAILURE);
00227 }
00228
00229 bool lgEOLST;
00230 long int ipST = 1;
00231 long int nYrRdST = (long)FFmtRead(chLine,&ipST,sizeof(chLine),&lgEOLST);
00232 long int nMonRdST = (long)FFmtRead(chLine,&ipST,sizeof(chLine),&lgEOLST);
00233 long int nDayRdST = (long)FFmtRead(chLine,&ipST,sizeof(chLine),&lgEOLST);
00234
00235 static long int nYrST =11 , nMonST = 10, nDayST = 25;
00236 if( ( nYrRdST != nYrST ) || ( nMonRdST != nMonST ) || ( nDayRdST != nDayST ) )
00237 {
00238 fprintf( ioQQQ,
00239 " I expected to find the number %2.2li %2.2li %2.2li and got %2.2li %2.2li %2.2li instead.\n" ,
00240 nYrST , nMonST , nDayST , nYrRdST , nMonRdST , nDayRdST );
00241 fprintf( ioQQQ, "Here is the line image:\n==%s==\n", chLine );
00242 cdEXIT(EXIT_FAILURE);
00243 }
00244 if( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) == NULL )
00245 {
00246 fprintf( ioQQQ, " database_readin could not read first line of CHIANTI masterlist.\n");
00247 cdEXIT(EXIT_FAILURE);
00248 }
00249
00250 do
00251 {
00252 strcpy(chDLine, chLine);
00253 chToken = strtok(chDLine," \n");
00254 if ((chLine[0]!='#') && (chLine[0]!='\n')&&(chLine[0]!='\t')&&(chLine[0]!='\r'))
00255 {
00256 ASSERT( nSpecies + 1 <= MAX_NUM_SPECIES );
00257 ASSERT( nSpeciesSTOUT + 1 <= MAX_NUM_SPECIES );
00258 strcpy( chLabels[nSpecies], chToken );
00259 strcpy( chLabelsOrig[nSpecies], chLabels[nSpecies] );
00260
00261 char *chElement, chTokenTemp[7];
00262 strcpy( chTokenTemp, chToken );
00263 chElement = strtok(chTokenTemp," \n");
00264 chElement = strtok(chTokenTemp,"_");
00265 uncaps( chElement );
00266
00267
00268
00269
00270
00271 strcpy( chPaths[nSpecies], "stout" );
00272 strcat( chPaths[nSpecies], input.chDelimiter );
00273 strcat( chPaths[nSpecies], chElement );
00274 strcat( chPaths[nSpecies], input.chDelimiter );
00275 strcat( chPaths[nSpecies], chLabels[nSpecies] );
00276 strcat( chPaths[nSpecies], input.chDelimiter );
00277 strcat( chPaths[nSpecies], chLabels[nSpecies] );
00278
00279 ASSERT( isalpha(chToken[0]) );
00280 long cursor=0;
00281 chLabels[nSpecies][0] = chToken[0];
00282 if( isalpha(chToken[1]) )
00283 {
00284 chLabels[nSpecies][1] = chToken[1];
00285 cursor = 2;
00286 }
00287 else
00288 {
00289 chLabels[nSpecies][1] = ' ';
00290 cursor = 1;
00291 }
00292
00293 ASSERT( chToken[cursor++]=='_' );
00294 ASSERT( isdigit(chToken[cursor]) );
00295
00296 if( isdigit(chToken[cursor+1]) )
00297 {
00298 chLabels[nSpecies][2] = chToken[cursor++];
00299 chLabels[nSpecies][3] = chToken[cursor++];
00300 }
00301 else
00302 {
00303 chLabels[nSpecies][2] = ' ';
00304 chLabels[nSpecies][3] = chToken[cursor++];
00305 }
00306 chLabels[nSpecies][4] = '\0';
00307 ASSERT( chToken[cursor]=='\0' || chToken[cursor]=='d' );
00308
00309
00310 chLabels[nSpecies][0] = toupper( chLabels[nSpecies][0] );
00311 ++nSpecies;
00312 ++nSpeciesSTOUT;
00313 }
00314 }
00315 while( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) != NULL );
00316 fclose(ioMASTERLIST);
00317 }
00318
00319
00321
00322
00323
00325
00326 nSpeciesCHIANTI = 0;
00327
00328 if( atmdat.lgChiantiOn )
00329 {
00330 char chPathSave[FILENAME_PATH_LENGTH_2];
00331 strcpy( chPath, "chianti" );
00332 strcat( chPath, input.chDelimiter );
00333
00334
00335 strcpy( chPathSave , chPath );
00336 strcat(chPath,"VERSION");
00337 ioVERSION = open_data(chPath,"r");
00338 if( read_whole_line( chLine , (int)sizeof(chLine) , ioVERSION ) == NULL )
00339 {
00340 fprintf( ioQQQ, " database_readin could not read first line of the Chianti VERSION.\n");
00341 cdEXIT(EXIT_FAILURE);
00342 }
00343 fclose(ioVERSION);
00344
00345 strncpy(atmdat.chVersion,chLine,atmdat.iVersionLength);
00346
00347 long len = strlen(atmdat.chVersion);
00348 if( atmdat.chVersion[len-1] == '\n' )
00349 atmdat.chVersion[len-1] = '\0';
00350
00351 atmdat.chVersion[atmdat.iVersionLength-1] = '\0';
00352
00353 strcpy(chPath,chPathSave);
00354
00355 strcat( chPath, "masterlist" );
00356 strcat( chPath, input.chDelimiter );
00357
00358 strcpy( chPathSave , chPath );
00359
00360
00361 strcat( chPath, atmdat.chCloudyChiantiFile );
00362
00363
00364 if( (ioMASTERLIST = fopen( atmdat.chCloudyChiantiFile , "r" ) ) == NULL )
00365 {
00366 ioMASTERLIST = open_data( chPath, "r" );
00367 }
00368
00369
00370 if( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) == NULL )
00371 {
00372 fprintf( ioQQQ, " database_readin could not read first line of CloudyChianti.ini.\n");
00373 cdEXIT(EXIT_FAILURE);
00374 }
00375
00376 bool lgEOL;
00377 long int ip = 1;
00378 long int nYrRd = (long)FFmtRead(chLine,&ip,sizeof(chLine),&lgEOL);
00379 long int nMonRd = (long)FFmtRead(chLine,&ip,sizeof(chLine),&lgEOL);
00380 long int nDayRd = (long)FFmtRead(chLine,&ip,sizeof(chLine),&lgEOL);
00381
00382 static long int nYr=11 , nMon = 10, nDay = 3;
00383 if( ( nYrRd != nYr ) || ( nMonRd != nMon ) || ( nDayRd != nDay ) )
00384 {
00385 fprintf( ioQQQ,
00386 " database_readin: the version of CloudyChianti.ini is not the current version.\n" );
00387 fprintf( ioQQQ,
00388 " database_readin obtain the current version from the Cloudy web site.\n" );
00389 fprintf( ioQQQ,
00390 " I expected to find the number %2.2li %2.2li %2.2li and got %2.2li %2.2li %2.2li instead.\n" ,
00391 nYr , nMon , nDay , nYrRd , nMonRd , nDayRd );
00392 fprintf( ioQQQ, "Here is the line image:\n==%s==\n", chLine );
00393 cdEXIT(EXIT_FAILURE);
00394 }
00395
00396 if( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) == NULL )
00397 {
00398 fprintf( ioQQQ, " database_readin could not read first line of CHIANTI masterlist.\n");
00399 cdEXIT(EXIT_FAILURE);
00400 }
00401
00402 do
00403 {
00404
00405 if ((chLine[0]!='#') && (chLine[0]!='\n')&&(chLine[0]!='\t')&&(chLine[0]!='\r'))
00406 {
00407 strcpy(chDLine, chLine);
00408 chToken = strtok(chDLine," \n");
00409
00410 fixit();
00411
00412
00413 if( chToken[3]!='d' && chToken[4]!='d' && chToken[5]!='d' )
00414 {
00415 ASSERT( nSpecies + 1 <= MAX_NUM_SPECIES );
00416 ASSERT( nSpeciesCHIANTI + 1 <= MAX_NUM_SPECIES );
00417 strcpy( chLabels[nSpecies], chToken );
00418 strcpy( chLabelsOrig[nSpecies], chLabels[nSpecies]);
00419
00420 bool skipSpecies = false;
00421
00422
00423 for( int j = nSpeciesLAMDA; j < nSpecies; j++)
00424 {
00425 if( strcmp( chLabelsOrig[j], chLabelsOrig[nSpecies] ) == 0)
00426 {
00427 printf("Skipping the Chianti version of %s, using Stout version\n",chLabels[nSpecies]);
00428 skipSpecies = true;
00429 break;
00430 }
00431 }
00432 if( skipSpecies)
00433 continue;
00434
00435 char *chElement, chTokenTemp[7];
00436 strcpy( chTokenTemp, chToken );
00437 chElement = strtok(chTokenTemp," \n");
00438 chElement = strtok(chTokenTemp,"_");
00439 uncaps( chElement );
00440
00441
00442
00443 strcpy( chPaths[nSpecies], "chianti" );
00444 strcat( chPaths[nSpecies], input.chDelimiter );
00445 strcat( chPaths[nSpecies], chElement );
00446 strcat( chPaths[nSpecies], input.chDelimiter );
00447 strcat( chPaths[nSpecies], chLabels[nSpecies] );
00448 strcat( chPaths[nSpecies], input.chDelimiter );
00449 strcat( chPaths[nSpecies], chLabels[nSpecies] );
00450
00451 ASSERT( isalpha(chToken[0]) );
00452 long cursor=0;
00453 chLabels[nSpecies][0] = chToken[0];
00454 if( isalpha(chToken[1]) )
00455 {
00456 chLabels[nSpecies][1] = chToken[1];
00457 cursor = 2;
00458 }
00459 else
00460 {
00461 chLabels[nSpecies][1] = ' ';
00462 cursor = 1;
00463 }
00464
00465 ASSERT( chToken[cursor++]=='_' );
00466 ASSERT( isdigit(chToken[cursor]) );
00467
00468 if( isdigit(chToken[cursor+1]) )
00469 {
00470 chLabels[nSpecies][2] = chToken[cursor++];
00471 chLabels[nSpecies][3] = chToken[cursor++];
00472 }
00473 else
00474 {
00475 chLabels[nSpecies][2] = ' ';
00476 chLabels[nSpecies][3] = chToken[cursor++];
00477 }
00478 chLabels[nSpecies][4] = '\0';
00479 ASSERT( chToken[cursor]=='\0' || chToken[cursor]=='d' );
00480
00481
00482 chLabels[nSpecies][0] = toupper( chLabels[nSpecies][0] );
00483 ++nSpecies;
00484 ++nSpeciesCHIANTI;
00485 }
00486 }
00487 }
00488 while( read_whole_line( chLine , (int)sizeof(chLine) , ioMASTERLIST ) != NULL );
00489
00490 fclose(ioMASTERLIST);
00491 }
00492
00493
00494 if( nSpecies==0 )
00495 return;
00496
00497
00498 dBaseSpecies = (species *)MALLOC( (unsigned long)nSpecies*sizeof(species));
00499
00500
00501 AtmolCollRateCoeff.reserve( nSpecies );
00502 AtmolCollSplines = (CollSplinesArray****)MALLOC((unsigned long)nSpecies *sizeof(CollSplinesArray***));
00503 StoutCollData = (StoutColls****)MALLOC((unsigned long)nSpecies *sizeof(StoutColls***));
00504
00505
00506 for( i=0; i<nSpecies; i++ )
00507 {
00508 AtmolCollRateCoeff.reserve( i, ipNCOLLIDER );
00509 }
00510 AtmolCollRateCoeff.alloc();
00511
00512
00513 dBaseStates.resize(nSpecies);
00514 ipdBaseTrans.resize(nSpecies);
00515
00516 for( i = 0; i < nSpecies; i++ )
00517 {
00518 dBaseTrans.push_back(TransitionList("dBaseTrans",&dBaseStates[i]));
00519 SpeciesJunk( &dBaseSpecies[i] );
00520
00521 size_t los = max(4,strlen(chLabels[i]));
00522 ASSERT( los >= 4 && los <= 7 );
00523 dBaseSpecies[i].chLabel = new char[los+1];
00524 strcpy(dBaseSpecies[i].chLabel,chLabels[i]);
00525 dBaseSpecies[i].lgActive = true;
00526
00527
00528 set_fractionation( &dBaseSpecies[i] );
00529
00530
00531 los = (int)strlen( dBaseSpecies[i].chLabel );
00532 ASSERT( los < CHARS_SPECIES );
00533
00534
00535 if( dBaseSpecies[i].chLabel[2]=='\0' )
00536 {
00537 dBaseSpecies[i].chLabel[2]=' ';
00538 dBaseSpecies[i].chLabel[3]=' ';
00539 dBaseSpecies[i].chLabel[4]='\0';
00540 }
00541 else if( dBaseSpecies[i].chLabel[3]=='\0' )
00542 {
00543 dBaseSpecies[i].chLabel[3]=' ';
00544 dBaseSpecies[i].chLabel[4]='\0';
00545 }
00546
00547 if( i<nSpeciesLAMDA )
00548 {
00549
00550 atmdat_LAMDA_readin( i, chPaths[i] );
00551 }
00552 else if( i < nSpeciesLAMDA + nSpeciesSTOUT )
00553 {
00554 atmdat_STOUT_readin( i, chPaths[i] );
00555 }
00556 else if( i < nSpeciesLAMDA + nSpeciesSTOUT + nSpeciesCHIANTI )
00557 {
00558
00559 atmdat_CHIANTI_readin( i, chPaths[i] );
00560 }
00561 else
00562 TotalInsanity();
00563 }
00564
00565 states_popfill();
00566 states_nelemfill();
00567
00568
00569
00570 for( intNoSp=0; intNoSp<nSpecies; intNoSp++ )
00571 {
00572 database_prep(intNoSp);
00573 AllTransitions.push_back(dBaseTrans[intNoSp]);
00574 }
00575
00576
00577 if(DEBUGSTATE)
00578 states_propprint();
00579 return;
00580 }
00581
00582 STATIC void set_fractionation( species *sp )
00583 {
00584 DEBUG_ENTRY("set_fractionation()");
00585
00586 char chToken[3];
00587
00588 sp->fracIsotopologue = 1.f;
00589
00590 strncpy( chToken, sp->chLabel, 2 );
00591 chToken[2] = '\0';
00592 if( strcmp( "p-", chToken )==0 )
00593 sp->fracType = 0.25f;
00594 else if( strcmp( "o-", chToken )==0 )
00595 sp->fracType = 0.75f;
00596 else if( strcmp( "e-", chToken )==0 )
00597 sp->fracType = 0.5f;
00598 else if( strcmp( "a-", chToken )==0 )
00599 sp->fracType = 0.5f;
00600 else
00601 sp->fracType = 1.0f;
00602
00603 fixit();
00604
00605
00606 if( sp->chLabel[1]=='-')
00607 memmove(sp->chLabel,sp->chLabel+2,strlen(sp->chLabel+2)+1);
00608
00609 return;
00610 }
00611
00612
00613 STATIC void states_popfill( void)
00614 {
00615 DEBUG_ENTRY( "states_popfill()" );
00616
00617 for( long i=0; i<nSpecies; i++)
00618 {
00619 for( long j=0; j<dBaseSpecies[i].numLevels_max; j++)
00620 {
00621 dBaseStates[i][j].Pop() = 0.;
00622 }
00623 }
00624 return;
00625 }
00626
00627
00628 STATIC void states_nelemfill(void)
00629 {
00630 DEBUG_ENTRY( "states_nelemfill()" );
00631
00632 for( long i=0; i<nSpecies; i++ )
00633 {
00634 long nelem = 0, IonStg;
00635 char chLabelChemical[CHARS_SPECIES];
00636
00637 if( dBaseSpecies[i].lgMolecular )
00638 {
00639 fixit();
00640
00641
00642 nelem = -1;
00643 IonStg = -1;
00644 strcpy( chLabelChemical, dBaseSpecies[i].chLabel );
00645 }
00646 else
00647 {
00648 char chToken[3];
00649 strncpy( chToken, dBaseSpecies[i].chLabel, 2 );
00650 chToken[2] = '\0';
00651 strcpy( chLabelChemical, chToken );
00652 if( chLabelChemical[1]==' ' )
00653 chLabelChemical[1] = '\0';
00654 for( long ipElement=0; ipElement<LIMELM; ipElement++ )
00655 {
00656 if( strcmp( elementnames.chElementSym[ipElement], chToken )==0 )
00657 {
00658 nelem = ipElement + 1;
00659 break;
00660 }
00661 }
00662 ASSERT( nelem > 0 && nelem <= LIMELM );
00663 strncpy( chToken, dBaseSpecies[i].chLabel + 2, 2 );
00664 IonStg = atoi(chToken);
00665 char chStage[5] = {'\0'};
00666 if( IonStg==2 )
00667 sprintf( chStage, "+" );
00668 else if( IonStg>1 )
00669 sprintf( chStage, "+%li", IonStg-1 );
00670 strcat( chLabelChemical, chStage );
00671 ASSERT( IonStg >= 1 && IonStg <= nelem+1 );
00672
00673 if( nelem - IonStg < NISO )
00674 {
00675 fprintf(ioQQQ, " PROBLEM: Cannot use Chianti model for %s%li\n",elementnames.chElementSym[nelem-1],IonStg);
00676 fprintf(ioQQQ, " Iso-sequences are handled by our own model.\n");
00677 cdEXIT(EXIT_FAILURE);
00678 }
00679 dBaseSpecies[i].fmolweight = dense.AtomicWeight[nelem-1];
00680
00681
00682 if( dBaseTrans[i].chLabel() == "Chianti" )
00683 {
00684 dense.lgIonChiantiOn[nelem-1][IonStg-1] = true;
00685 }
00686 else if( dBaseTrans[i].chLabel() == "Stout" )
00687 {
00688 dense.lgIonStoutOn[nelem-1][IonStg-1] = true;
00689 }
00690 else
00691 {
00692 TotalInsanity();
00693 }
00694
00695 if( atmdat.lgChiantiHybrid || atmdat.lgStoutHybrid )
00696 {
00697
00698
00699 dense.maxWN[nelem-1][IonStg-1] = dBaseSpecies[i].maxWN;
00700 }
00701 else
00702 {
00703 dense.maxWN[nelem-1][IonStg-1] = 0.;
00704 }
00705 }
00706
00707 molecule *sp = findspecies(chLabelChemical);
00708 if( sp == null_mole )
00709 {
00710 dBaseSpecies[i].index = INT_MAX;
00711 if( nelem-1 >= ipHYDROGEN && dense.lgElmtOn[nelem-1] )
00712 fprintf(ioQQQ," PROBLEM: could not find species %li - %s\n",i,
00713 chLabelChemical );
00714 }
00715 else
00716 {
00717 dBaseSpecies[i].index = sp->index;
00718 mole.species[ sp->index ].levels = &dBaseStates[i];
00719 mole.species[ sp->index ].lines = &dBaseTrans[i];
00720 }
00721
00722 for( long j=0; j<dBaseSpecies[i].numLevels_max; j++ )
00723 {
00724 dBaseStates[i][j].nelem() = nelem;
00725 dBaseStates[i][j].IonStg() = IonStg;
00726 }
00727 }
00728 return;
00729 }
00730
00731
00732 STATIC void states_propprint(void)
00733 {
00734 DEBUG_ENTRY( "states_propprint()" );
00735
00736 for( long i=0; i<nSpecies; i++ )
00737 {
00738 printf("The species is %s \n",dBaseSpecies[i].chLabel);
00739 printf("The data output is in the following format \n");
00740 printf("Label Energy St.wt Pop Lifetime\n");
00741
00742 for( long j=0; j<dBaseSpecies[i].numLevels_max; j++ )
00743 {
00744 printf("This is the %ld state \n",j);
00745 printf("%s %f %f %f %e \n",dBaseStates[i][j].chLabel(),
00746 dBaseStates[i][j].energy().WN(),
00747 dBaseStates[i][j].g(),
00748 dBaseStates[i][j].Pop(),
00749 dBaseStates[i][j].lifetime());
00750 }
00751 }
00752 return;
00753 }
00754
00755
00756 STATIC void database_prep(int intSpIndex)
00757 {
00758 vector<realnum> fsumAs(dBaseSpecies[intSpIndex].numLevels_max,SMALLFLOAT);
00759
00760 DEBUG_ENTRY( "database_prep()" );
00761
00762
00763 for( EmissionList::iterator em = dBaseTrans[intSpIndex].Emis().begin();
00764 em != dBaseTrans[intSpIndex].Emis().end(); ++em)
00765 {
00766 fsumAs[(*em).Tran().ipHi()] += (*em).Aul();
00767 (*em).iRedisFun() = ipPRD;
00768 }
00769
00770 dBaseStates[intSpIndex][0].lifetime()= BIGFLOAT;
00771 for( int ipHi=1; ipHi < dBaseSpecies[intSpIndex].numLevels_max; ipHi++ )
00772 {
00773 dBaseStates[intSpIndex][ipHi].lifetime() = 1./fsumAs[ipHi];
00774 }
00775 return;
00776 }
00777
00778
00779 STATIC void SpeciesJunk( species *sp )
00780 {
00781 sp->chLabel = NULL;
00782 set_NaN(sp->fmolweight);
00783 set_NaN(sp->fracIsotopologue );
00784 set_NaN(sp->fracType);
00785 sp->lgMolecular = false;
00786 sp->numLevels_local = -INT_MAX;
00787 sp->numLevels_max = -INT_MAX;
00788
00789 return;
00790 }