Skip to content

Commit

Permalink
Per #2883, update the pcp_combine logic for the sum command to allow …
Browse files Browse the repository at this point in the history
…missing data files based on the -input_thresh threshold. Add a test in unit_pcp_combine.xml to demonstrate.
  • Loading branch information
JohnHalleyGotway committed May 11, 2024
1 parent a4f99a0 commit d81447a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
13 changes: 13 additions & 0 deletions internal/test_unit/xml/unit_pcp_combine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
</output>
</test>

<test name="pcp_combine_sum_GRIB1_MISSING">
<exec>&MET_BIN;/pcp_combine</exec>
<param> \
20120409_00 3 20120412_15 12 \
&OUTPUT_DIR;/pcp_combine/nam_2012040900_F087_APCP12.nc \
-pcpdir &DATA_DIR_MODEL;/grib1/nam \
-input_thresh 0.75
</param>
<output>
<grid_nc>&OUTPUT_DIR;/pcp_combine/nam_2012040900_F087_APCP12.nc</grid_nc>
</output>
</test>

<test name="pcp_combine_sum_GRIB1_MULTIPLE_FIELDS">
<exec>&MET_BIN;/pcp_combine</exec>
<param> \
Expand Down
39 changes: 27 additions & 12 deletions src/tools/core/pcp_combine/pcp_combine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void do_sum_command() {
mlog << Error << "\ndo_sum_command() -> "
<< "the output accumulation time ("
<< sec_to_hhmmss(out_accum)
<< ") cannot be greater than the lead time ("
<< ") can't be greater than the lead time ("
<< sec_to_hhmmss(lead_time) << ").\n\n";
exit(1);
}
Expand Down Expand Up @@ -568,7 +568,7 @@ void do_sum_command() {
////////////////////////////////////////////////////////////////////////

void sum_data_files(Grid & grid, DataPlane & plane) {
int i, j, x, y;
int i, j, x, y, n_vld;
DataPlane part;
double v_sum, v_part;
Grid cur_grid;
Expand Down Expand Up @@ -604,7 +604,7 @@ void sum_data_files(Grid & grid, DataPlane & plane) {
//
// Search for each file time.
//
for(i=0; i<n_files; i++) {
for(i=0, n_vld=0; i<n_files; i++) {

//
// Search in each directory for the current file time.
Expand All @@ -620,30 +620,46 @@ void sum_data_files(Grid & grid, DataPlane & plane) {
<< " matches valid time of "
<< unix_to_yyyymmdd_hhmmss(pcp_times[i]) << "\n";
break;
} // if
} // end if

} // end for j

//
// Check for no matching file found.
//
if(pcp_recs[i] == -1) {
mlog << Error << "\nsum_data_files() -> "
<< "cannot find a file with a valid time of "
if(pcp_recs[i] != -1) {
n_vld++;
}
else {
mlog << Warning << "\nsum_data_files() -> "
<< "can't find a file with a valid time of "
<< unix_to_yyyymmdd_hhmmss(pcp_times[i])
<< " and accumulation time of "
<< sec_to_hhmmss(in_accum) << " matching the regular "
<< "expression \"" << pcp_reg_exp << "\"\n\n";
exit(1);
}

} // end for i

// Check for enough valid input files.
if((double) n_vld/n_files < input_thresh) {
mlog << Error << "\nsum_data_files() -> "
<< n_vld << " of " << n_files << " (" << (double) n_vld/n_files
<< ") valid inputs does not meet the required input threshold ("
<< input_thresh << ").\n\n";
exit(1);
}

//
// Open each of the files found and parse the data.
//
for(i=0; i<n_files; i++) {

//
// Skip missing inputs.
//
if(pcp_recs[i] == -1) continue;

mlog << Debug(1)
<< "[" << (i+1) << "] Reading input file: " << pcp_files[i]
<< "\n";
Expand All @@ -663,10 +679,9 @@ void sum_data_files(Grid & grid, DataPlane & plane) {
cur_grid, part, true);

//
// For the first file processed store the grid, allocate memory
// to store the precipitation sums, and initialize the sums.
// Initialize the grid and data after the first successful read.
//
if(i == 0) {
if(grid.nxy() == 0) {
grid = cur_grid;
plane = part;
}
Expand Down Expand Up @@ -732,7 +747,7 @@ int search_pcp_dir(const char *cur_dir, const unixtime cur_ut,
dp = met_opendir(cur_dir);
if(!dp) {
mlog << Error << "\nsearch_pcp_dir() -> "
<< "cannot open search directory: " << cur_dir << "\n\n";
<< "can't open search directory: " << cur_dir << "\n\n";
exit(1);
}

Expand Down

0 comments on commit d81447a

Please sign in to comment.