From e2fd280f19a523791336bbb046c58051ffbe1f43 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Thu, 11 Jan 2024 09:46:06 -0700 Subject: [PATCH] Bugfix #2782 main_v11.1 MASSDEN (#2784) * Per #2782, update the multiple matching records warning message to include the table number for each record. * Per #2782, update read_grib2_record_list() to parse the level values and aerosol information correctly for table 4.48. * Per #2782 tweak variable naming convention. --- src/libcode/vx_data2d_grib2/data2d_grib2.cc | 36 +++++++++++++++++---- src/libcode/vx_data2d_grib2/data2d_grib2.h | 4 +++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/libcode/vx_data2d_grib2/data2d_grib2.cc b/src/libcode/vx_data2d_grib2/data2d_grib2.cc index 6a3f40574d..fa58324f73 100644 --- a/src/libcode/vx_data2d_grib2/data2d_grib2.cc +++ b/src/libcode/vx_data2d_grib2/data2d_grib2.cc @@ -198,8 +198,9 @@ bool MetGrib2DataFile::data_plane(VarInfo &vinfo, DataPlane &plane) { if( 1 < listMatch.size() ){ ConcatString msg; for(size_t i=0; i < listMatch.size(); i++) { - msg << "record " << listMatch[i]->RecNum + msg << " Record " << listMatch[i]->RecNum << " field " << listMatch[i]->FieldNum + << ", table 4." << listMatch[i]->PdsTmpl << ": ipdtmpl[" << listMatch[i]->IPDTmpl.n() << "] = "; for(int j=0; j < listMatch[i]->IPDTmpl.n(); j++) { @@ -259,8 +260,9 @@ int MetGrib2DataFile::data_plane_array( VarInfo &vinfo, if( 1 < listMatchExact.size() ){ ConcatString msg; for(size_t i=0; i < listMatchExact.size(); i++) { - msg << "record " << listMatchExact[i]->RecNum + msg << " Record " << listMatchExact[i]->RecNum << " field " << listMatchExact[i]->FieldNum + << ", table 4." << listMatchExact[i]->PdsTmpl << ": ipdtmpl[" << listMatchExact[i]->IPDTmpl.n() << "] = "; for(int j=0; j < listMatchExact[i]->IPDTmpl.n(); j++) { @@ -729,11 +731,17 @@ void MetGrib2DataFile::read_grib2_record_list() { rec->PdsTmpl = gfld->ipdtnum; rec->ParmCat = gfld->ipdtmpl[0]; rec->Parm = gfld->ipdtmpl[1]; - rec->Process = gfld->ipdtmpl[2]; + + // get the process id + if( gfld->ipdtnum != 46 && gfld->ipdtnum != 48 ) { + rec->Process = gfld->ipdtmpl[2]; + } // get the level type if( gfld->ipdtnum == 46 ) { rec->LvlTyp = gfld->ipdtmpl[15]; + } else if( gfld->ipdtnum == 48 ) { + rec->LvlTyp = gfld->ipdtmpl[20]; } else { rec->LvlTyp = gfld->ipdtmpl[9]; } @@ -746,10 +754,16 @@ void MetGrib2DataFile::read_grib2_record_list() { // check for template number 46 if( gfld->ipdtnum == 46 ) { rec->LvlVal1 = scaled2dbl(gfld->ipdtmpl[16], gfld->ipdtmpl[17]); - rec->LvlVal2 = rec->LvlVal1; - // check for special fixed level types (1 through 10 or 101) and set the level values to 0 - // Reference: https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table4-5.shtml - } else if( (rec->LvlTyp >= 1 && rec->LvlTyp <= 10) || rec->LvlTyp == 101 ) { + rec->LvlVal2 = rec->LvlVal1; + } + // check for template number 48 + else if( gfld->ipdtnum == 48 ) { + rec->LvlVal1 = scaled2dbl(gfld->ipdtmpl[21], gfld->ipdtmpl[22]); + rec->LvlVal2 = rec->LvlVal1; + } + // check for special fixed level types (1 through 10 or 101) and set the level values to 0 + // Reference: https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table4-5.shtml + else if( (rec->LvlTyp >= 1 && rec->LvlTyp <= 10) || rec->LvlTyp == 101 ) { rec->LvlVal1 = 0; rec->LvlVal2 = 0; } else { @@ -806,6 +820,14 @@ void MetGrib2DataFile::read_grib2_record_list() { rec->PercVal = gfld->ipdtmpl[15]; } + // aerosol type and size for templates 46 and 48 + if( 46 == gfld->ipdtnum || 48 == gfld->ipdtnum ){ + rec->AerosolType = gfld->ipdtmpl[2]; + rec->AerosolIntervalType = gfld->ipdtmpl[3]; + rec->AerosolSizeLower = scaled2dbl(gfld->ipdtmpl[4], gfld->ipdtmpl[5]); + rec->AerosolSizeUpper = scaled2dbl(gfld->ipdtmpl[6], gfld->ipdtmpl[7]); + } + // depending on the template number, determine the reference times if( 8 <= gfld->ipdtnum && 12 >= gfld->ipdtnum ){ diff --git a/src/libcode/vx_data2d_grib2/data2d_grib2.h b/src/libcode/vx_data2d_grib2/data2d_grib2.h index 4191e19728..abf334a837 100644 --- a/src/libcode/vx_data2d_grib2/data2d_grib2.h +++ b/src/libcode/vx_data2d_grib2/data2d_grib2.h @@ -62,6 +62,10 @@ typedef struct { int DerType; int StatType; int PercVal; + int AerosolType; + int AerosolIntervalType; + double AerosolSizeLower; + double AerosolSizeUpper; IntArray IPDTmpl; } Grib2Record;