Skip to content

Commit

Permalink
#1922 Removed trailing spaces based on the string lenth than buffer l…
Browse files Browse the repository at this point in the history
…ength
  • Loading branch information
Howard Soh committed Sep 17, 2021
1 parent c6a51c3 commit e8f42d5
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions met/src/tools/other/ioda2nc/ioda2nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

////////////////////////////////////////////////////////////////////////

//
Expand Down Expand Up @@ -662,7 +664,6 @@ 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);

Expand Down Expand Up @@ -692,7 +693,6 @@ 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);
hdr_sid = tmp_sid;
}
Expand Down Expand Up @@ -990,7 +990,9 @@ 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--) {
int str_len = m_strlen(hdr_buf);
if (buf_len <= str_len) str_len = buf_len;
for(i=str_len-1; i>=0; i--) {
if(' ' == hdr_buf[i]) {
hdr_buf[i] = '\0';
if(i > 0 && ' ' != hdr_buf[i-1]) break;
Expand All @@ -1001,10 +1003,12 @@ static void cleanup_hdr_buf(char *hdr_buf, int buf_len) {
////////////////////////////////////////////////////////////////////////

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);
}
Expand All @@ -1013,8 +1017,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);
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -1036,6 +1046,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);
}

Expand Down

0 comments on commit e8f42d5

Please sign in to comment.