Skip to content

Commit

Permalink
Feature 1894 pb2nc var all (#1917)
Browse files Browse the repository at this point in the history
* #1894 Added station ID 14008 to pb2nc_NDAS_var_all unit test

* #1894 Check the existance of the valid data up to 16 levels

Co-authored-by: Howard Soh <[email protected]>
  • Loading branch information
hsoh-u and Howard Soh authored Sep 16, 2021
1 parent 9998f49 commit 054fe2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions met/src/tools/other/pb2nc/pb2nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ static const int mxr8vt = 6;
static const int mxr8nm = 8;
// Maximum number of BUFR variable types

// Length of the "YYYYMMDD_HHMMSS" string
static const int COUNT_THRESHOLD = 5;
static const int COUNT_THRESHOLD = 16;

// File unit number for opening the PrepBufr file
static const int file_unit = 11;
Expand Down Expand Up @@ -2004,7 +2003,7 @@ void process_pbfile_metadata(int i_pb) {
int lv, var_index;
int debug_threshold = 10;

int tmp_nlev_max_req = mxr8lv_small;
int nlev_max_req;
bool check_all = do_all_vars || collect_metadata;
char hdr_typ[max_str_len];
StringArray tmp_bufr_obs_name_arr;
Expand Down Expand Up @@ -2110,6 +2109,8 @@ void process_pbfile_metadata(int i_pb) {
int length;
bool is_prepbufr_hdr = false;
bool showed_progress = false;

nlev_max_req = (mxr8lv_small > COUNT_THRESHOLD) ? COUNT_THRESHOLD : mxr8lv_small;
// Loop through the PrepBufr messages from the input file
for(i_read=0; i_read<npbmsg && i_ret == 0; i_read++) {

Expand Down Expand Up @@ -2296,24 +2297,29 @@ void process_pbfile_metadata(int i_pb) {

int var_count = unchecked_var_list.n_elements();
for (int vIdx=var_count-1; vIdx>=0; vIdx--) {
int nlev2, buf_nlev;
int nlev2, count;
bool has_valid_data;
ConcatString var_name = unchecked_var_list[vIdx];
int var_name_len = var_name.length();

readpbint_(&unit, &i_ret, &nlev2, bufr_obs, (char*)var_name.c_str(), &var_name_len, &tmp_nlev_max_req);
readpbint_(&unit, &i_ret, &nlev2, bufr_obs, (char*)var_name.c_str(), &var_name_len, &nlev_max_req);
if (0 >= nlev2) continue;

// Checks the first level intread of searching through the vertical levels
lv = 0;
has_valid_data = (bufr_obs[lv][0] < r8bfms);
// Search through the vertical levels
has_valid_data = false;
for(lv=0; lv<nlev2; lv++) {
if (bufr_obs[lv][0] < r8bfms) {
has_valid_data = true;
break;
}
} //end for lv

if (has_valid_data) {
if (do_all_vars) {
mlog << Debug(5) << " found valid data: " << var_name
<< " (" << bufr_obs[lv][0] << ") at level index "
<< lv << " from message " << i_read << "-th message (levels="
<< buf_nlev << ")\n";
<< nlev2 << ")\n";
}
if (!tmp_bufr_obs_name_arr.has(var_name, false)
&& !bufr_hdr_name_arr.has(var_name, false)) {
Expand Down
2 changes: 1 addition & 1 deletion test/xml/unit_pb2nc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<test name="pb2nc_NDAS_var_all">
<exec>&MET_BIN;/pb2nc</exec>
<env>
<pair><name>STATION_ID</name> <value>"72364","72265","72274","72426","72489"</value></pair>
<pair><name>STATION_ID</name> <value>"72364","72265","72274","72426","72489","14008"</value></pair>
<pair><name>MASK_GRID</name> <value></value></pair>
<pair><name>MASK_POLY</name> <value></value></pair>
<pair><name>QUALITY_MARK_THRESH</name> <value>2</value></pair>
Expand Down

0 comments on commit 054fe2c

Please sign in to comment.