00001
00002
00003
00004 #include "cddefines.h"
00005 #include "opacity.h"
00006 #include "taulines.h"
00007 #include "radius.h"
00008 #include "phycon.h"
00009 #include "save.h"
00010 #include "mole.h"
00011
00012
00013 STATIC void SaveSpeciesOne( const size_t species_index, const char chKey[],
00014 FILE *ioPUN, long int ipPun, size_t maxLevels );
00015
00016
00017 void SaveSpecies(
00018 FILE* ioPUN,
00019 long int ipPun)
00020 {
00021 DEBUG_ENTRY( "SaveSpecies()" );
00022
00023 if( strcmp( save.chSaveArgs[ipPun], "LABE" )==0 )
00024 {
00025 if( save.lgPunHeader[ipPun] )
00026 {
00027
00028 fprintf( ioPUN, "#Species labels\n" );
00029 save.lgPunHeader[ipPun] = false;
00030 for( size_t i=1; i<mole_global.list.size(); ++i )
00031 {
00032 molecule *spg = &(*mole_global.list[i]);
00033 fprintf( ioPUN, "%s\n", spg->label.c_str() );
00034 }
00035 }
00036 return;
00037 }
00038
00039 else if( strcmp(save.chSaveArgs[ipPun],"LEVL") == 0 )
00040 {
00041
00042 if( save.lgPunHeader[ipPun] )
00043 {
00044
00045 fprintf( ioPUN, "#Species\tnumber of levels\n" );
00046 save.lgPunHeader[ipPun] = false;
00047 }
00048 for( size_t i=1; i<mole_global.list.size(); ++i )
00049 {
00050 molecule *spg = &(*mole_global.list[i]);
00051 molezone *sp = &mole.species[i];
00052 fprintf( ioPUN, "%s", spg->label.c_str() );
00053 if( sp->levels == NULL )
00054 fprintf( ioPUN, "\t%4lu\n", 0UL );
00055 else
00056 fprintf( ioPUN, "\t%4lu\n", (unsigned long)sp->levels->size() );
00057 }
00058 return;
00059 }
00060
00061
00062
00063 if( strcmp( save.chSaveSpecies[ipPun], "" ) == 0 )
00064 {
00065
00066 size_t mostLevels = 0;
00067 for( size_t i=1; i<mole_global.list.size(); ++i )
00068 {
00069 molezone *sp = &mole.species[i];
00070 if( sp->levels != NULL )
00071 mostLevels = MAX2(mostLevels, sp->levels->size() );
00072 }
00073 ASSERT( mostLevels > 1 );
00074 ASSERT( mostLevels < 10000 );
00075
00076
00077 for( size_t i=1; i<mole_global.list.size(); ++i )
00078 SaveSpeciesOne( i, save.chSaveArgs[ipPun], ioPUN, ipPun, mostLevels );
00079 }
00080 else
00081 {
00082 const molecule *saveSpeciesGlobal = findspecies(save.chSaveSpecies[save.ipConPun]);
00083 const molezone *saveSpecies = findspecieslocal(save.chSaveSpecies[save.ipConPun]);
00084
00085 if( saveSpecies == null_molezone )
00086 {
00087 fprintf( ioQQQ,"Could not find species %s, so SAVE SPECIES LABELS to get a list of all species."
00088 "\nSorry.\n", save.chSaveSpecies[save.ipConPun] );
00089 cdEXIT(EXIT_FAILURE);
00090 }
00091
00092 size_t numLevels = 0;
00093 if( saveSpecies->levels != NULL )
00094 numLevels = saveSpecies->levels->size();
00095 SaveSpeciesOne( saveSpeciesGlobal->index, save.chSaveArgs[ipPun], ioPUN, ipPun, numLevels );
00096 }
00097
00098 return;
00099 }
00100
00101
00102 STATIC void PrintShortZero( FILE *ioPUN , double arg )
00103 {
00104 DEBUG_ENTRY( "PrintShortZero()" );
00105 if( arg==0. )
00106 fprintf(ioPUN,"\t0");
00107 else
00108 fprintf(ioPUN,"\t%.3e", arg);
00109
00110 }
00111
00112
00113 STATIC void SaveSpeciesOne( const size_t species_index, const char chKey[],
00114 FILE *ioPUN, long int ipPun, size_t maxLevels )
00115 {
00116 DEBUG_ENTRY( "SaveSpeciesOne()" );
00117
00118 molecule *spg = &(*mole_global.list[species_index]);
00119 molezone *sp = &mole.species[species_index];
00120
00121 if( spg == null_mole || sp == null_molezone )
00122 return;
00123
00124
00125 if( strcmp( chKey, "ENER" )==0 )
00126 {
00127 if( save.lgPunHeader[ipPun] )
00128 {
00129 save.lgPunHeader[ipPun] = false;
00130
00131 fprintf( ioPUN, "#species energies");
00132 for( size_t i = 0; i < maxLevels; ++i )
00133 {
00134 fprintf( ioPUN, "\t%lu", (unsigned long)i );
00135 }
00136 fprintf( ioPUN, "\n");
00137 }
00138
00139 fprintf( ioPUN, "%s", spg->label.c_str() );
00140 if( sp->levels == NULL || sp->levels->size() == 0 )
00141 {
00142 fprintf( ioPUN, "\t%.6e", 0. );
00143 }
00144 else
00145 {
00146 for( qList::const_iterator st = sp->levels->begin(); st != sp->levels->end(); ++st )
00147 {
00148 ASSERT( (*st).g() > 0.f );
00149 fprintf( ioPUN, "\t%.6e", AnuUnit( (*st).energy().Ryd() ) );
00150 }
00151 }
00152 fprintf( ioPUN, "\n");
00153 return;
00154 }
00155
00156 if( strcmp( chKey, "POPU" )==0 )
00157 {
00158 if( save.lgPunHeader[ipPun] )
00159 {
00160 fprintf( ioPUN, "#depth [cm] species populations [cm-3]");
00161
00162 for( size_t i = 0; i < maxLevels; ++i )
00163 {
00164 fprintf( ioPUN, "\t%lu", (unsigned long)i );
00165 }
00166 fprintf( ioPUN, "\n");
00167 save.lgPunHeader[ipPun] = false;
00168 }
00169
00170 fprintf( ioPUN, "%.5e", radius.depth_mid_zone );
00171 fprintf( ioPUN, "\t%s", spg->label.c_str() );
00172
00173 if( sp->levels == NULL || sp->levels->size() == 0 )
00174 {
00175 PrintShortZero( ioPUN, sp->den );
00176 }
00177 else
00178 {
00179 bool lgZeroHit = false;
00180
00181 for( qList::const_iterator st = sp->levels->begin(); st != sp->levels->end(); ++st )
00182 {
00183
00184 if( !lgZeroHit )
00185 PrintShortZero( ioPUN, (*st).Pop() );
00186 if( (*st).Pop() == 0.)
00187 lgZeroHit = true;
00188 }
00189 }
00190 fprintf( ioPUN, "\n");
00191 }
00192 else if( strcmp( chKey, "COLU" )==0 )
00193 {
00194
00195 if( save.lgPunHeader[ipPun] )
00196 {
00197 fprintf( ioPUN, "#species column density [cm-2]");
00198
00199 for( size_t i = 0; i < maxLevels; ++i )
00200 {
00201 fprintf( ioPUN, "\t%lu", (unsigned long)i );
00202 }
00203 fprintf( ioPUN, "\n");
00204 save.lgPunHeader[ipPun] = false;
00205 }
00206
00207 fprintf( ioPUN, "%s", spg->label.c_str() );
00208
00209 if( sp->levels == NULL || sp->levels->size() == 0 )
00210 {
00211 PrintShortZero( ioPUN, sp->column );
00212 }
00213 else
00214 {
00215
00216 bool lgZeroHit = false;
00217 for( qList::const_iterator st = sp->levels->begin(); st != sp->levels->end(); ++st )
00218 {
00219
00220 if( !lgZeroHit )
00221 PrintShortZero( ioPUN, (*st).ColDen() );
00222 if( (*st).ColDen() == 0.)
00223 lgZeroHit = true;
00224 }
00225 }
00226 fprintf( ioPUN, "\n");
00227 }
00228
00229 return;
00230 }