21 namespace fs = std::filesystem;
29 #define OBSATTRS_NAME "OBSATTRS"
30 #define SPAX_NAME "SPAXEL"
31 #define NSPAX_NAME "num_spax"
32 #define FREQS_NAME "frequencies"
33 #define ETA_AP_NAME "eta_ap"
34 #define TIME_NAME "times"
37 #define PWV_NAME "pwv"
39 #define AZ_SPAX_NAME "az_spax"
40 #define EL_SPAX_NAME "el_spax"
41 #define OUT_NAME "data"
47 void readAtmMeta(
int **meta, std::string path);
49 template <
typename T,
typename U>
64 template <
typename T,
typename U>
86 hid_t dspace_id, dspace_pwv_id, dspace_slab_id, dspace_pwv_slab_id, dset_id, dset_pwv_id;
89 hsize_t dims_1D[RANK1D],
91 dims_2D_chunk[RANK2D],
92 dims_2D_stride[RANK2D];
94 hsize_t dims_2D_null[2] = {0,0};
97 hsize_t start[2], count[2], start_pink[2], count_pink[2], start_pwv[1], count_pwv[1];
100 int offset_times = 0;
101 int offset_freqs = 0;
102 int offset_times_pwv = 0;
104 void check_API_call_status(
109 if(status < 0) {printf(
"HDF5 API error occured on line %d\n", loc);}
114 const char *filename,
126 this->filename = filename;
127 this->dry_run = dry_run;
128 this->ntimes = ntimes;
129 this->nfreqs = nfreqs;
130 printf(
"%d\n", this->dry_run);
132 if (this->dry_run) {
return;}
141 count_pink[1] = ntimes;
151 obsattrs_id = H5Gcreate(
160 dspace_id = H5Screate(H5S_SCALAR);
172 check_API_call_status(
184 check_API_call_status(H5Dclose(dset_id), __LINE__);
189 dspace_id = H5Screate_simple(
205 check_API_call_status(
216 check_API_call_status(H5Dclose(dset_id), __LINE__);
229 check_API_call_status(
240 check_API_call_status(H5Dclose(dset_id), __LINE__);
241 check_API_call_status(H5Sclose(dspace_id), __LINE__);
246 dspace_id = H5Screate_simple(
262 check_API_call_status(
273 check_API_call_status(H5Dclose(dset_id), __LINE__);
285 check_API_call_status(
296 check_API_call_status(H5Dclose(dset_id), __LINE__);
308 check_API_call_status(
319 check_API_call_status(H5Dclose(dset_id), __LINE__);
320 check_API_call_status(H5Sclose(dspace_id), __LINE__);
323 dspace_pwv_id = H5Screate_simple(
329 dset_pwv_id = H5Dcreate(
339 void write_chunk_to_pwv(
344 if (this->dry_run) {
return;}
345 start_pwv[0] = offset_times_pwv;
346 count_pwv[0] = ntimes_chunk;
348 dims_1D[0] = ntimes_chunk;
350 check_API_call_status(
362 dspace_pwv_slab_id = H5Screate_simple(
368 check_API_call_status(
380 offset_times_pwv += ntimes_chunk;
381 check_API_call_status(H5Sclose(dspace_pwv_slab_id), __LINE__);
383 void close_obsattrs() {
384 if (this->dry_run) {
return;}
385 check_API_call_status(H5Dclose(dset_pwv_id), __LINE__);
386 check_API_call_status(H5Sclose(dspace_pwv_id), __LINE__);
387 check_API_call_status(H5Gclose(obsattrs_id), __LINE__);
396 if (this->dry_run) {
return;}
400 char spax_name[CHBUFF] = SPAX_NAME;
403 sprintf(buffer,
"%d", spax_index);
404 strcat(spax_name, buffer);
414 dspace_id = H5Screate(H5S_SCALAR);
426 check_API_call_status(
437 check_API_call_status(H5Dclose(dset_id), __LINE__);
449 check_API_call_status(
460 check_API_call_status(H5Dclose(dset_id), __LINE__);
461 check_API_call_status(H5Sclose(dspace_id), __LINE__);
464 dspace_id = H5Screate_simple(
481 void write_pink_chunk_to_spaxel(
486 if (this->dry_run) {
return;}
487 start_pink[0] = k_ch;
492 check_API_call_status(
504 dspace_slab_id = H5Screate_simple(
510 check_API_call_status(
522 check_API_call_status(H5Sclose(dspace_slab_id), __LINE__);
525 void write_chunk_to_spaxel(
530 if (this->dry_run) {
return;}
531 start[1] = offset_times;
532 count[1] = ntimes_chunk;
534 dims_1D[0] = ntimes_chunk * nfreqs;
536 check_API_call_status(
548 dspace_slab_id = H5Screate_simple(
554 float *buffer =
new float[dims_1D[0]];
555 check_API_call_status(
567 for(
int ii=0; ii < dims_1D[0]; ii++)
569 buffer[ii] += data[ii];
572 check_API_call_status(
586 offset_times += ntimes_chunk;
587 check_API_call_status(H5Sclose(dspace_slab_id), __LINE__);
592 if (this->dry_run) {
return;}
593 check_API_call_status(H5Dclose(dset_id), __LINE__);
594 check_API_call_status(H5Sclose(dspace_id), __LINE__);
595 check_API_call_status(H5Gclose(spax_id), __LINE__);
599 if (this->dry_run) {
return;}
600 check_API_call_status(H5Fclose(file_id), __LINE__);
611 fs::path file(
"atm_meta.datp");
612 fs::path abs_loc = dir / file;
614 *meta =
new int[NATMGRID];
618 std::ifstream myfile(abs_loc);
626 <<
"Could not open the file at "
633 while(std::getline(myfile, line))
635 std::istringstream iss(line);
636 while(std::getline(iss, store,
' '))
638 if (store==
"") {
continue;}
639 (*meta)[idx] = std::stoi(store);
647 template <
typename T,
typename U>
656 pwv_atm->start = 0.1;
658 pwv_atm->num = NPWVATM;
660 freq_atm->start = 70.e9;
661 freq_atm->step = 0.1e9;
662 freq_atm->num = NFREQ;
664 *eta_array =
new T[NPWVATM * NFREQ];
669 std::ifstream myfile(filepath);
678 <<
"Could not open the resource file at "
685 while(std::getline(myfile, line))
687 std::istringstream iss(line);
694 while(std::getline(iss, store,
' '))
706 (*eta_array)[NFREQ * (idx-1) + (line_nr - 1)] = std::stof(store);
715 template <
typename T,
typename U>
724 *PWV_screen =
new T[x_spec->num * y_spec->num];
732 fs::path abs_loc = dir / file;
734 std::ifstream myfile(abs_loc);
741 <<
"Could not open the file!"
746 while(std::getline(myfile, line))
748 std::istringstream iss(line);
749 while(std::getline(iss, store,
' '))
751 if (store==
"") {
continue;}
752 (*PWV_screen)[y_spec->num * line_nr + idx] = std::stof(store);