@@ -44,6 +44,11 @@ Euv::Euv() {
4444 }
4545 }
4646
47+ // Read in FISM data - does not need to be "slotted"
48+ if (input.get_euv_model () == " fism" )
49+ fismData = read_fism (input.get_euv_fismfile ());
50+ // Read in NEUVAC data - also does not need to be "slotted"
51+
4752 // Slot the EUVAC model coefficients:
4853 if (input.get_euv_model () == " euvac" ) {
4954 IsOk = slot_euv (" F74113" , " " , euvac_f74113);
@@ -167,6 +172,62 @@ bool Euv::read_file() {
167172 return DidWork;
168173}
169174
175+ // -------------------------------------------------------------------------------
176+ // Read in FISM data. FISM files are created with srcPython/fism.py,
177+ // and the data are read in to an index_file_output_struct.
178+ // Inside the struct, we have time & each of the "variables" correspond to a
179+ // FISM bin. This number of bins should match the number of bins in the EUV file
180+ // -------------------------------------------------------------------------------
181+
182+ index_file_output_struct Euv::read_fism (std::string fism_filename) {
183+
184+ std::ifstream fismfstream;
185+ fismfstream.open (fism_filename);
186+ std::vector<std::vector<std::string>> fism_file;
187+ fism_file = read_csv (fismfstream);
188+
189+ index_file_output_struct fism_contents;
190+
191+ // one row per time
192+ fism_contents.nTimes = fism_file.size ();
193+ // first six cols are the YYYY,MM,DD,HH,mm,ss (no ms)
194+ // the rest are the binned fism data
195+ fism_contents.nVars = fism_file[0 ].size () - 6 ;
196+
197+ // check that the user provided the correct EUV file
198+ // The number of bins in euv file should match the number of fism bins ("nVars")
199+ if (fism_contents.nVars != nWavelengths) {
200+ report.error (" Number of FISM wavelengths does not match the EUV file provided!" );
201+ report.error (" Either change EUV file or check your FISM file is correct." );
202+ IsOk = false ;
203+ }
204+
205+ std::vector<int > itime (7 , 0 );
206+ std::vector<std::vector<float >> values; // holds all values
207+ std::vector<float > values_tmp (fism_contents.nVars ); // holds values in each row
208+
209+ for (int iLine = 0 ; iLine < fism_file.size (); iLine ++) {
210+
211+ itime[0 ] = stoi (fism_file[iLine][0 ]);
212+ itime[1 ] = stoi (fism_file[iLine][1 ]);
213+ itime[2 ] = stoi (fism_file[iLine][2 ]);
214+ itime[3 ] = stoi (fism_file[iLine][3 ]);
215+ itime[4 ] = stoi (fism_file[iLine][4 ]);
216+ itime[5 ] = stoi (fism_file[iLine][5 ]);
217+ itime[6 ] = 0 ; // 0 ms
218+ fism_contents.times .push_back (time_int_to_real (itime));
219+
220+ for (int iVar = 0 ; iVar < fism_contents.nVars ; iVar++)
221+ values_tmp[iVar] = stof (fism_file[iLine][iVar + 6 ]);
222+
223+ values.push_back (values_tmp);
224+ }
225+
226+ fism_contents.values = values;
227+
228+ return fism_contents;
229+ }
230+
170231// ---------------------------------------------------------------------------
171232// Match rows in EUV file to different types of things, such as cross
172233// sections and spectra
@@ -371,6 +432,52 @@ bool Euv::euvac(Times time,
371432 return didWork;
372433}
373434
435+ // --------------------------------------------------------------------------
436+ // From the FISM file, interpolate the nearest 2 data to the current time
437+ // --------------------------------------------------------------------------
438+
439+ bool Euv::get_fism (Times time) {
440+ // This is functionally similar to get_indices, however we do not store FISM in
441+ // the Indices class since it has variable number of bins.
442+
443+ std::string function = " Euv::get_fism" ;
444+ static int iFunction = -1 ;
445+ report.enter (function, iFunction);
446+
447+ double time_now = time.get_current ();
448+ bool didWork = true ;
449+
450+ if (fism_prev_index == 0 ) {
451+ // This is probably the first time we're "running" fism.
452+ // Make sure the file covers the entire time range of the run.
453+ double end_time = time.get_end ();
454+
455+ if (time_now < fismData.times [0 ] && end_time > fismData.times [-1 ]) {
456+ report.error (" FISM data does not cover the entire time range!" );
457+ report.error (" Please check that your FISM file is correct." );
458+ didWork = false ;
459+ }
460+ }
461+
462+ // Get the index prior to the current time
463+ while (fismData.times [fism_prev_index + 1 ] <= time_now)
464+ fism_prev_index ++;
465+
466+ // Determine time-interpolation weighting factor
467+ precision_t dt_fism;
468+ dt_fism = fismData.times [fism_prev_index + 1 ] - fismData.times [fism_prev_index];
469+ precision_t x = (time_now - fismData.times [fism_prev_index]) / dt_fism;
470+
471+ // store the wavelength:
472+ for (int iWave = 0 ; iWave < nWavelengths; iWave ++)
473+ wavelengths_intensity_1au[iWave] =
474+ (1.0 - x) * fismData.values [fism_prev_index][iWave]
475+ + x * fismData.values [fism_prev_index + 1 ][iWave];
476+
477+ report.exit (function);
478+ return didWork;
479+ }
480+
374481// --------------------------------------------------------------------------
375482// Calculate EUVAC
376483// --------------------------------------------------------------------------
0 commit comments