diff --git a/met/src/basic/vx_log/str_wrappers.cc b/met/src/basic/vx_log/str_wrappers.cc index 81d707c5a7..7862c1e525 100644 --- a/met/src/basic/vx_log/str_wrappers.cc +++ b/met/src/basic/vx_log/str_wrappers.cc @@ -86,6 +86,14 @@ void m_strncpy(char *to_str, const char *from_str, const int buf_len, if (str_len > buf_len) str_len = buf_len; memset(to_str, 0, str_len); + // Kludge: there were cases that sizeof returns 8 instead of the real size. + // Use sizeof only if it's not 8. + int to_buf_size = sizeof(to_str); + if (to_buf_size != 8) { + if (str_len < to_buf_size) memset(to_str, str_len, to_buf_size); + if (str_len > to_buf_size) str_len = to_buf_size; // truncate + } + string temp_str = from_str; temp_str.copy(to_str, str_len); to_str[str_len] = 0; @@ -99,4 +107,25 @@ void m_strncpy(char *to_str, const char *from_str, const int buf_len, } +//////////////////////////////////////////////////////////////////////// + +void m_rstrip(char *str_buf, int buf_len) { + // Make sure it's NULL terminated + if (buf_len >= 0) str_buf[buf_len] = '\0'; + // Change the trailing blank space to a null + int str_len = m_strlen(str_buf); + for(int idx=str_len-1; idx>=0; idx--) { + if(is_whitespaces(str_buf[idx])) { + str_buf[idx] = '\0'; + if((idx > 0) && !is_whitespaces(str_buf[idx-1])) break; + } + } +} + +//////////////////////////////////////////////////////////////////////// + +bool is_whitespaces(char cur_char) { + return (' ' == cur_char || '\t' == cur_char || '\n' == cur_char || '\r' == cur_char); +} +//////////////////////////////////////////////////////////////////////// diff --git a/met/src/basic/vx_log/str_wrappers.h b/met/src/basic/vx_log/str_wrappers.h index 5d74eef860..9a2e72a09d 100644 --- a/met/src/basic/vx_log/str_wrappers.h +++ b/met/src/basic/vx_log/str_wrappers.h @@ -27,6 +27,10 @@ extern void m_strncpy(char *to_str, const char *from_str, const int buf_len, const char *method_name, const char *extra_msg=(char *)0, bool truncate=false); +extern void m_rstrip(char *str_buf, const int buf_len=-1); + +extern bool is_whitespaces(char cur_char); + //////////////////////////////////////////////////////////////////////// diff --git a/met/src/tools/other/ioda2nc/ioda2nc.cc b/met/src/tools/other/ioda2nc/ioda2nc.cc index 04c58c0909..2c8f67d8ba 100644 --- a/met/src/tools/other/ioda2nc/ioda2nc.cc +++ b/met/src/tools/other/ioda2nc/ioda2nc.cc @@ -59,6 +59,8 @@ static const char * DEF_CONFIG_NAME = "MET_BASE/config/IODA2NCConfig_default"; static const char *program_name = "ioda2nc"; +static const int REJECT_DEBUG_LEVEL = 9; + //////////////////////////////////////////////////////////////////////// // @@ -150,7 +152,6 @@ static void set_valid_beg_time(const StringArray &); static void set_valid_end_time(const StringArray &); static void set_verbosity(const StringArray &); -static void cleanup_hdr_buf(char *hdr_buf, int buf_len); static bool check_core_data(const bool, const bool, StringArray &, StringArray &); static bool check_missing_thresh(float value); static ConcatString find_meta_name(StringArray, StringArray); @@ -662,9 +663,7 @@ void process_ioda_file(int i_pb) { if(has_msg_type) { int buf_len = sizeof(modified_hdr_typ); m_strncpy(hdr_typ, hdr_msg_types+(i_read*nstring), nstring, method_name, "hdr_typ"); - hdr_typ[nstring] = 0; - // Null terminate the message type string - cleanup_hdr_buf(hdr_typ, nstring); + m_rstrip(hdr_typ, nstring); // If the message type is not listed in the configuration // file and it is not the case that all message types should be @@ -692,8 +691,7 @@ void process_ioda_file(int i_pb) { if(has_station_id) { char tmp_sid[nstring+1]; m_strncpy(tmp_sid, hdr_station_ids+(i_read*nstring), nstring, method_name, "tmp_sid"); - tmp_sid[nstring] = 0; - cleanup_hdr_buf(tmp_sid, nstring); + m_rstrip(tmp_sid, nstring); hdr_sid = tmp_sid; } else hdr_sid.clear(); @@ -986,25 +984,13 @@ void clean_up() { //////////////////////////////////////////////////////////////////////// -static void cleanup_hdr_buf(char *hdr_buf, int buf_len) { - int i; - hdr_buf[buf_len] = '\0'; - // Change the trailing blank space to a null - for(i=buf_len-1; i>=0; i--) { - if(' ' == hdr_buf[i]) { - hdr_buf[i] = '\0'; - if(i > 0 && ' ' != hdr_buf[i-1]) break; - } - } -} - -//////////////////////////////////////////////////////////////////////// - bool keep_message_type(const char *mt_str) { - bool keep = false; + bool keep = conf_info.message_type.n_elements() == 0 || + conf_info.message_type.has(mt_str, false); - keep = conf_info.message_type.n_elements() == 0 || - conf_info.message_type.has(mt_str, false); + if(!keep && mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) { + mlog << Debug(REJECT_DEBUG_LEVEL) << "The message type [" << mt_str << "] is rejected\n"; + } return(keep); } @@ -1013,8 +999,14 @@ bool keep_message_type(const char *mt_str) { bool keep_station_id(const char *sid_str) { - return(conf_info.station_id.n_elements() == 0 || - conf_info.station_id.has(sid_str, false)); + bool keep = (conf_info.station_id.n_elements() == 0 || + conf_info.station_id.has(sid_str, false)); + + if(!keep && mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) { + mlog << Debug(REJECT_DEBUG_LEVEL) << "The station ID [" << sid_str << "] is rejected\n"; + } + + return(keep); } //////////////////////////////////////////////////////////////////////// @@ -1036,6 +1028,11 @@ bool keep_valid_time(const unixtime ut, if(ut > max_ut) keep = false; } + if(!keep && mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) { + mlog << Debug(REJECT_DEBUG_LEVEL) << "The valid_time [" << ut << ", " + << unix_to_yyyymmdd_hhmmss(ut) << "] is rejected\n"; + } + return(keep); }