Loading data-access/engine/src/vlkb-obscore/src/database/SqlSchema_INSERT.cpp +57 −3 Original line number Diff line number Diff line Loading @@ -186,6 +186,59 @@ string get_wavelen(int precision, fitsfiles::key_values_by_type key_values) } // trim from start (in place) inline void ltrim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); } // trim from end (in place) inline void rtrim(std::string &s) { s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); } // trim from both ends (in place) inline void trim(std::string &s) { rtrim(s); ltrim(s); } // returns band in wavelen [m] double parse_transition(string trans) { // Surveys::survTransition "num unit" <-- for images trim(trans); if(!trans.empty()) { string::size_type pos = trans.find(' '); std::string num = trans.substr(0, pos); std::string unit = trans.substr(pos+1); LOG_STREAM << "parse trans: " << num << " " << unit << endl; const double speed_of_light = 299792458.0; // [m/s] in vacuum double value = stod(num); if(unit.compare("um") == 0) return value * 1e-6; else if(unit.compare("mm") == 0) return value * 1e-3; else if(unit.compare("m") == 0) return value; else if(unit.compare("GHz") == 0) return (speed_of_light / (value * 1e9)); else if(unit.compare("MHz") == 0) return (speed_of_light / (value * 1e6)); else if(unit.compare("kHz") == 0) return (speed_of_light / (value * 1e3)); else if(unit.compare("Hz") == 0) return (speed_of_light / (value)); else return 0.0; // ignore } else return 0.0; } //---------------------------------------------------------------------- // public API Loading Loading @@ -374,10 +427,11 @@ void SqlSchema_INSERT::appendRow(/*const int hid, const int sid,*/ } else if(icrsBounds.size() == 2) // 2D images { //if(!strcmp(survey.survSpecies.c_str(), "Continuum")) // dem_min = dem_max = 0.0; // FIXME transtod(psurv->transition); // surv.restFrequency [Hz] <-- is empty for 2D images: take from survTransition ? // surv.survTransition "num unit" <-- for images obscoreRow[em_min] = get_wavelen(EM_PRECISION, hdu.key_values); double val = parse_transition(surv.survTransition); obscoreRow[em_min] = ((val==0.0) ? "NULL" : to_string(val)); //get_wavelen(EM_PRECISION, hdu.key_values); obscoreRow[em_max] = obscoreRow[em_min]; obscoreRow[em_res_power] = "NULL"; obscoreRow[em_xel] = "NULL"; Loading Loading
data-access/engine/src/vlkb-obscore/src/database/SqlSchema_INSERT.cpp +57 −3 Original line number Diff line number Diff line Loading @@ -186,6 +186,59 @@ string get_wavelen(int precision, fitsfiles::key_values_by_type key_values) } // trim from start (in place) inline void ltrim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); } // trim from end (in place) inline void rtrim(std::string &s) { s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); } // trim from both ends (in place) inline void trim(std::string &s) { rtrim(s); ltrim(s); } // returns band in wavelen [m] double parse_transition(string trans) { // Surveys::survTransition "num unit" <-- for images trim(trans); if(!trans.empty()) { string::size_type pos = trans.find(' '); std::string num = trans.substr(0, pos); std::string unit = trans.substr(pos+1); LOG_STREAM << "parse trans: " << num << " " << unit << endl; const double speed_of_light = 299792458.0; // [m/s] in vacuum double value = stod(num); if(unit.compare("um") == 0) return value * 1e-6; else if(unit.compare("mm") == 0) return value * 1e-3; else if(unit.compare("m") == 0) return value; else if(unit.compare("GHz") == 0) return (speed_of_light / (value * 1e9)); else if(unit.compare("MHz") == 0) return (speed_of_light / (value * 1e6)); else if(unit.compare("kHz") == 0) return (speed_of_light / (value * 1e3)); else if(unit.compare("Hz") == 0) return (speed_of_light / (value)); else return 0.0; // ignore } else return 0.0; } //---------------------------------------------------------------------- // public API Loading Loading @@ -374,10 +427,11 @@ void SqlSchema_INSERT::appendRow(/*const int hid, const int sid,*/ } else if(icrsBounds.size() == 2) // 2D images { //if(!strcmp(survey.survSpecies.c_str(), "Continuum")) // dem_min = dem_max = 0.0; // FIXME transtod(psurv->transition); // surv.restFrequency [Hz] <-- is empty for 2D images: take from survTransition ? // surv.survTransition "num unit" <-- for images obscoreRow[em_min] = get_wavelen(EM_PRECISION, hdu.key_values); double val = parse_transition(surv.survTransition); obscoreRow[em_min] = ((val==0.0) ? "NULL" : to_string(val)); //get_wavelen(EM_PRECISION, hdu.key_values); obscoreRow[em_max] = obscoreRow[em_min]; obscoreRow[em_res_power] = "NULL"; obscoreRow[em_xel] = "NULL"; Loading