00001
00002
00003
00004
00005
00006 #include "cddefines.h"
00007 #include "taulines.h"
00008 #include "iso.h"
00009 #include "struc.h"
00010 #include "mole.h"
00011 #include "rfield.h"
00012 #include "iterations.h"
00013 #include "h2.h"
00014 #include "dense.h"
00015 #include "opacity.h"
00016 #include "atomfeii.h"
00017 #include "state.h"
00018
00019 static bool lgGet;
00020 static FILE *ioSTATE;
00021
00022
00023
00024 STATIC void state_do( void *pnt , size_t sizeof_pnt )
00025 {
00026 size_t n;
00027 double sanity = 1.,
00028 chk_sanity;
00029 size_t sizeof_sanity =sizeof( sanity );
00030
00031 DEBUG_ENTRY( "state_do()" );
00032
00033
00034 if( sizeof_pnt == 0 )
00035 return;
00036
00037 if( lgGet )
00038 {
00039
00040 if( (n=fread( pnt , 1 , sizeof_pnt , ioSTATE )) - sizeof_pnt )
00041 {
00042 fprintf( ioQQQ, " state_do failed reading state file, wanted %lu got %lu\n",
00043 (unsigned long)sizeof_pnt ,
00044 (unsigned long)n);
00045 cdEXIT(EXIT_FAILURE);
00046 }
00047
00048 if( (n=fread( &chk_sanity , 1 , sizeof_sanity , ioSTATE )) - sizeof_sanity )
00049 {
00050 fprintf( ioQQQ, " state_do failed reading sanity par of state file, wanted %lu got %lu\n",
00051 (unsigned long)sizeof_sanity ,
00052 (unsigned long)n);
00053 cdEXIT(EXIT_FAILURE);
00054 }
00055 if( ! fp_equal( sanity, chk_sanity ) )
00056 {
00057 fprintf( ioQQQ, " state_do sanity fails in state file, wanted %g got %g\n",
00058 sanity ,
00059 chk_sanity);
00060 cdEXIT(EXIT_FAILURE);
00061 }
00062 }
00063 else
00064 {
00065
00066 fwrite( pnt , 1 , sizeof_pnt , ioSTATE );
00067
00068 fwrite( &sanity , 1 , sizeof_sanity , ioSTATE );
00069 }
00070
00071 return;
00072 }
00073
00074
00075 void state_get_put( const char chJob[] )
00076 {
00077 long int ipISO , nelem , ipHi, i ,
00078 n , ion;
00079
00080 DEBUG_ENTRY( "state_get_put()" );
00081
00082 if( (strcmp( chJob , "get" ) == 0) )
00083 {
00084 lgGet = true;
00085 ioSTATE = open_data( state.chGetFilename, "rb", AS_LOCAL_ONLY );
00086 }
00087 else if( (strcmp( chJob , "put" ) == 0) )
00088 {
00089 lgGet = false;
00090 char chFilename[INPUT_LINE_LENGTH];
00091 if( !state.lgPutAll && iteration <= iterations.itermx )
00092 {
00093
00094 return;
00095 }
00096
00097
00098 strcpy( chFilename , state.chPutFilename );
00099
00100 if( state.lgPutAll )
00101 {
00102 char chIteration[INPUT_LINE_LENGTH];
00103 sprintf( chIteration , "_%li", iteration );
00104 strcat( chFilename , chIteration );
00105 }
00106 ioSTATE = open_data( chFilename, "wb", AS_LOCAL_ONLY );
00107 }
00108 else
00109 TotalInsanity();
00110
00111 if( state.lgState_print )
00112 fprintf(ioQQQ," Print state quantities, start iso seq \n");
00113
00114
00115 Transitions.state_do( ioSTATE, lgGet );
00116 ExtraLymanLines.state_do( ioSTATE, lgGet );
00117
00118 for( ipISO=ipH_LIKE; ipISO<NISO; ++ipISO )
00119 {
00120
00121 for( nelem=ipISO; nelem<LIMELM; ++nelem )
00122 {
00123 if( nelem < 2 || dense.lgElmtOn[nelem] )
00124 {
00125
00126 for( ipHi=1; ipHi < iso.numLevels_max[ipISO][nelem]; ++ipHi )
00127 {
00128 if( state.lgState_print )
00129 {
00130 fprintf(ioQQQ," start ISO ipISO= %li, nelem= %li, ipHi %li \n",
00131 ipISO ,
00132 nelem ,
00133 ipHi);
00134 for( n=0; n< ipHi; ++n )
00135 {
00136 fprintf(ioQQQ," ISO %li %li %li %li %.4e %.4e \n",
00137 ipISO , nelem , ipHi , n ,
00138 Transitions[ipISO][nelem][ipHi][n].Emis->TauIn ,
00139 Transitions[ipISO][nelem][ipHi][n].Emis->TauTot );
00140 }
00141 fprintf(ioQQQ," end ISO ipISO\n");
00142 }
00143 }
00144
00145 if( state.lgState_print )
00146 {
00147 fprintf(ioQQQ," start Ext ipISO= %li, nelem= %li, got %li \n",
00148 ipISO ,
00149 nelem ,
00150 iso.nLyman_malloc[ipISO] );
00151 }
00152 if( state.lgState_print )
00153 {
00154 for( n=2; n< iso.nLyman_malloc[ipISO]; ++n )
00155 {
00156 fprintf(ioQQQ," Ext %li %li %li %.4e %.4e \n",
00157 ipISO , nelem , n ,
00158 ExtraLymanLines[ipISO][nelem][n].Emis->TauIn ,
00159 ExtraLymanLines[ipISO][nelem][n].Emis->TauTot );
00160 }
00161 fprintf(ioQQQ," end Ext ipISO\n");
00162 }
00163 }
00164 }
00165 }
00166
00167 state_do( TauLines , (size_t)(nLevel1+1)*sizeof(transition ) );
00168 if( state.lgState_print )
00169 {
00170 for( n=0; n< (nLevel1+1); ++n )
00171 {
00172 fprintf(ioQQQ," Taulines %li %.4e %.4e \n",
00173 n ,
00174 TauLines[n].Emis->TauIn ,
00175 TauLines[n].Emis->TauTot );
00176 }
00177 }
00178
00179 state_do( TauLine2 , (size_t)nWindLine *sizeof(transition ) );
00180 if( state.lgState_print )
00181 {
00182 for( n=0; n< nWindLine; ++n )
00183 {
00184 fprintf(ioQQQ," TauLine2 %li %.4e %.4e \n",
00185 n ,
00186 TauLine2[n].Emis->TauIn ,
00187 TauLine2[n].Emis->TauTot );
00188 }
00189 }
00190
00191
00192 state_do( &UTALines[0], (size_t)nUTA *sizeof(transition ) );
00193 if( state.lgState_print )
00194 {
00195 for( n=0; n< nUTA; ++n )
00196 {
00197 fprintf(ioQQQ," UTALines %li %.4e %.4e \n",
00198 n ,
00199 UTALines[n].Emis->TauIn ,
00200 UTALines[n].Emis->TauTot );
00201 }
00202 }
00203
00204 state_do( HFLines , (size_t)nHFLines *sizeof(transition ) );
00205 if( state.lgState_print )
00206 {
00207 for( n=0; n< nHFLines; ++n )
00208 {
00209 fprintf(ioQQQ," HFLines %li %.4e %.4e \n",
00210 n ,
00211 HFLines[n].Emis->TauIn ,
00212 HFLines[n].Emis->TauTot );
00213 }
00214 }
00215
00216 for( ipHi=1; ipHi < FeII.nFeIILevel_malloc; ++ipHi )
00217 {
00218 state_do( Fe2LevN[ipHi] , (size_t)ipHi*sizeof(transition) );
00219 if( state.lgState_print )
00220 {
00221 for( n=0; n< ipHi; ++n )
00222 {
00223 fprintf(ioQQQ," Fe2LevN %li %li %.4e %.4e \n",
00224 ipHi , n ,
00225 Fe2LevN[ipHi][n].Emis->TauIn ,
00226 Fe2LevN[ipHi][n].Emis->TauTot );
00227 }
00228 }
00229 }
00230 for( i=0; i<2; ++i )
00231 {
00232 state_do( opac.TauAbsGeo[i] , (size_t)rfield.nupper*sizeof(realnum) );
00233 if( state.lgState_print )
00234 {
00235 for( n=0; n< rfield.nupper; ++n )
00236 {
00237 fprintf(ioQQQ," TauAbsGeo %li %li %.4e \n",
00238 i , n ,
00239 opac.TauAbsGeo[i][n] );
00240 }
00241 }
00242
00243 state_do( opac.TauScatGeo[i] , (size_t)rfield.nupper*sizeof(realnum) );
00244 if( state.lgState_print )
00245 {
00246 for( n=0; n< rfield.nupper; ++n )
00247 {
00248 fprintf(ioQQQ," TauScatGeo %li %li %.4e \n",
00249 i , n ,
00250 opac.TauAbsGeo[i][n] );
00251 }
00252 }
00253
00254 state_do( opac.TauTotalGeo[i], (size_t)rfield.nupper*sizeof(realnum) );
00255 if( state.lgState_print )
00256 {
00257 for( n=0; n< rfield.nupper; ++n )
00258 {
00259 fprintf(ioQQQ," TauTotalGeo %li %li %.4e \n",
00260 i , n ,
00261 opac.TauAbsGeo[i][n] );
00262 }
00263 }
00264
00265 }
00266
00267
00268 if( h2.lgH2ON )
00269 H2Lines.state_do( ioSTATE, lgGet );
00270
00271
00272 state_do( &struc.nzlim, sizeof(struc.nzlim ) );
00273 state_do( &struc.dr_ionfrac_limit, sizeof(struc.dr_ionfrac_limit ) );
00274
00275 state_do( struc.testr, (size_t)(struc.nzlim)*sizeof(realnum ) );
00276 state_do( struc.volstr, (size_t)(struc.nzlim)*sizeof(realnum ) );
00277 state_do( struc.drad_x_fillfac, (size_t)(struc.nzlim)*sizeof(realnum ) );
00278 state_do( struc.drad, (size_t)(struc.nzlim)*sizeof(realnum ) );
00279 state_do( struc.histr, (size_t)(struc.nzlim)*sizeof(realnum ) );
00280 state_do( struc.hiistr, (size_t)(struc.nzlim)*sizeof(realnum ) );
00281 state_do( struc.ednstr, (size_t)(struc.nzlim)*sizeof(realnum ) );
00282 state_do( struc.o3str, (size_t)(struc.nzlim)*sizeof(realnum ) );
00283 state_do( struc.pressure,(size_t)(struc.nzlim)*sizeof(realnum ) );
00284 state_do( struc.GasPressure ,(size_t)(struc.nzlim)*sizeof(realnum ) );
00285 state_do( struc.pres_radiation_lines_curr ,(size_t)(struc.nzlim)*sizeof(realnum ) );
00286 state_do( struc.hden ,(size_t)(struc.nzlim)*sizeof(realnum ) );
00287 state_do( struc.DenParticles ,(size_t)(struc.nzlim)*sizeof(realnum ) );
00288 state_do( struc.DenMass,(size_t)(struc.nzlim)*sizeof(realnum ) );
00289 state_do( struc.depth,(size_t)(struc.nzlim)*sizeof(realnum ) );
00290 state_do( struc.xLyman_depth , (size_t)(struc.nzlim)*sizeof(realnum ) );
00291
00292 state_do( struc.coolstr,(size_t)(struc.nzlim)*sizeof(double ) );
00293 state_do( struc.heatstr , (size_t)(struc.nzlim)*sizeof(double ) );
00294
00295 for( nelem=ipHYDROGEN; nelem<(LIMELM+3); ++nelem )
00296 {
00297 for( ion=0; ion<(LIMELM+1); ++ion )
00298 {
00299 state_do( struc.xIonDense[nelem][ion] , (size_t)(struc.nzlim)*sizeof(realnum ) );
00300 }
00301 }
00302 for( long ipISO=ipH_LIKE; ipISO<NISO; ++ipISO )
00303 {
00304 for( nelem=ipISO; nelem<LIMELM; ++nelem)
00305 {
00306 if( dense.lgElmtOn[nelem] )
00307 {
00308 for( long level=0; level < iso.numLevels_local[ipISO][nelem]; ++level )
00309 {
00310 state_do( struc.StatesElemNEW[nelem][nelem-ipISO][level] , (size_t)(struc.nzlim)*sizeof(realnum ) );
00311 }
00312 }
00313 }
00314 }
00315
00316
00317
00318 for( n=0; n<N_H_MOLEC; ++n )
00319 {
00320 state_do( struc.H2_molec[n] , (size_t)(struc.nzlim)*sizeof(realnum ) );
00321 }
00322 for( n=0; n<mole.num_comole_calc; ++n )
00323 {
00324 state_do( struc.CO_molec[n] , (size_t)(struc.nzlim)*sizeof(realnum ) );
00325 }
00326
00327 for( nelem=ipHYDROGEN; nelem<LIMELM; ++nelem )
00328 {
00329 state_do( struc.gas_phase[nelem] , (size_t)(struc.nzlim)*sizeof(realnum ) );
00330 }
00331
00332
00333
00334
00335 fclose( ioSTATE );
00336 return;
00337 }