20 namespace fs = std::filesystem;
28 #define OBSATTRS_NAME "OBSATTRS"
29 #define SPAX_NAME "SPAXEL"
30 #define NSPAX_NAME "num_spax"
31 #define FREQS_NAME "frequencies"
32 #define ETA_AP_NAME "eta_ap"
33 #define TIME_NAME "times"
36 #define PWV_NAME "pwv"
38 #define AZ_SPAX_NAME "az_spax"
39 #define EL_SPAX_NAME "el_spax"
40 #define OUT_NAME "data"
46 void readAtmMeta(
int **meta, std::string path);
48 template <
typename T,
typename U>
55 template <
typename T,
typename U>
76 hid_t dspace_id, dspace_pwv_id, dspace_slab_id, dspace_pwv_slab_id, dset_id, dset_pwv_id;
79 hsize_t dims_1D[RANK1D],
81 dims_2D_chunk[RANK2D],
82 dims_2D_stride[RANK2D];
84 hsize_t dims_2D_null[2] = {0,0};
87 hsize_t start[2], count[2], start_pink[2], count_pink[2], start_pwv[1], count_pwv[1];
92 int offset_times_pwv = 0;
94 void check_API_call_status(
99 if(status < 0) {printf(
"HDF5 API error occured on line %d\n", loc);}
104 const char *filename,
115 this->filename = filename;
116 this->ntimes = ntimes;
117 this->nfreqs = nfreqs;
126 count_pink[1] = ntimes;
136 obsattrs_id = H5Gcreate(
145 dspace_id = H5Screate(H5S_SCALAR);
157 check_API_call_status(
169 check_API_call_status(H5Dclose(dset_id), __LINE__);
174 dspace_id = H5Screate_simple(
190 check_API_call_status(
201 check_API_call_status(H5Dclose(dset_id), __LINE__);
214 check_API_call_status(
225 check_API_call_status(H5Dclose(dset_id), __LINE__);
226 check_API_call_status(H5Sclose(dspace_id), __LINE__);
231 dspace_id = H5Screate_simple(
247 check_API_call_status(
258 check_API_call_status(H5Dclose(dset_id), __LINE__);
270 check_API_call_status(
281 check_API_call_status(H5Dclose(dset_id), __LINE__);
293 check_API_call_status(
304 check_API_call_status(H5Dclose(dset_id), __LINE__);
305 check_API_call_status(H5Sclose(dspace_id), __LINE__);
308 dspace_pwv_id = H5Screate_simple(
314 dset_pwv_id = H5Dcreate(
324 void write_chunk_to_pwv(
329 start_pwv[0] = offset_times_pwv;
330 count_pwv[0] = ntimes_chunk;
332 dims_1D[0] = ntimes_chunk;
334 check_API_call_status(
346 dspace_pwv_slab_id = H5Screate_simple(
352 check_API_call_status(
364 offset_times_pwv += ntimes_chunk;
365 check_API_call_status(H5Sclose(dspace_pwv_slab_id), __LINE__);
367 void close_obsattrs() {
368 check_API_call_status(H5Dclose(dset_pwv_id), __LINE__);
369 check_API_call_status(H5Sclose(dspace_pwv_id), __LINE__);
370 check_API_call_status(H5Gclose(obsattrs_id), __LINE__);
382 char spax_name[CHBUFF] = SPAX_NAME;
385 sprintf(buffer,
"%d", spax_index);
386 strcat(spax_name, buffer);
396 dspace_id = H5Screate(H5S_SCALAR);
408 check_API_call_status(
419 check_API_call_status(H5Dclose(dset_id), __LINE__);
431 check_API_call_status(
442 check_API_call_status(H5Dclose(dset_id), __LINE__);
443 check_API_call_status(H5Sclose(dspace_id), __LINE__);
446 dspace_id = H5Screate_simple(
463 void write_pink_chunk_to_spaxel(
468 start_pink[0] = k_ch;
473 check_API_call_status(
485 dspace_slab_id = H5Screate_simple(
491 check_API_call_status(
503 check_API_call_status(H5Sclose(dspace_slab_id), __LINE__);
506 void write_chunk_to_spaxel(
511 start[1] = offset_times;
512 count[1] = ntimes_chunk;
514 dims_1D[0] = ntimes_chunk * nfreqs;
516 check_API_call_status(
528 dspace_slab_id = H5Screate_simple(
534 float *buffer =
new float[dims_1D[0]];
535 check_API_call_status(
547 for(
int ii=0; ii < dims_1D[0]; ii++)
549 buffer[ii] += data[ii];
552 check_API_call_status(
566 offset_times += ntimes_chunk;
567 check_API_call_status(H5Sclose(dspace_slab_id), __LINE__);
572 check_API_call_status(H5Dclose(dset_id), __LINE__);
573 check_API_call_status(H5Sclose(dspace_id), __LINE__);
574 check_API_call_status(H5Gclose(spax_id), __LINE__);
578 check_API_call_status(H5Fclose(file_id), __LINE__);
589 fs::path file(
"atm_meta.datp");
590 fs::path abs_loc = dir / file;
592 *meta =
new int[NATMGRID];
596 std::ifstream myfile(abs_loc);
604 <<
"Could not open the file at "
611 while(std::getline(myfile, line))
613 std::istringstream iss(line);
614 while(std::getline(iss, store,
' '))
616 if (store==
"") {
continue;}
617 (*meta)[idx] = std::stoi(store);
625 template <
typename T,
typename U>
634 pwv_atm->start = 0.1;
636 pwv_atm->num = NPWVATM;
638 freq_atm->start = 70.e9;
639 freq_atm->step = 0.1e9;
640 freq_atm->num = NFREQ;
642 *eta_array =
new T[NPWVATM * NFREQ];
647 std::ifstream myfile(filepath);
656 <<
"Could not open the resource file at "
663 while(std::getline(myfile, line))
665 std::istringstream iss(line);
672 while(std::getline(iss, store,
' '))
684 (*eta_array)[NFREQ * (idx-1) + (line_nr - 1)] = std::stof(store);
693 template <
typename T,
typename U>
703 fs::path abs_loc = dir / file;
705 *PWV_screen =
new T[x_spec->num * y_spec->num];
709 std::ifstream myfile(abs_loc);
718 <<
"Could not open the file!"
723 while(std::getline(myfile, line))
725 std::istringstream iss(line);
726 while(std::getline(iss, store,
' '))
733 (*PWV_screen)[y_spec->num * line_nr + idx] = std::stof(store);