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