Skip to content

Commit

Permalink
Feature #2809 nc_laea (#2811)
Browse files Browse the repository at this point in the history
* Per #2809 work in progress parsing LAEA grids from MET NetCDF files.

* Per #2809, update the LaeaData struct to store the spheroid_name as a character array. I tried very hard to store this as a string instead but ran into lots of problems with segfaults when deleting the allocated structs. Using a fixed length character array while making calls to the m_strncpy() and m_strlen() utility functions enables the code to work properly while hopefully minimizing SonarQube findings.

* Per #2809, call m_strncpy() to set LaeaData::spheroid_name

* Per #2809, add tests to pcp_combine and plot_data_plane to demonstrate the reading the LAEA data from MET NetCDF files.

* Per #2809, correct the expected PostScript file output name in unit_plot_data_plane.xml
  • Loading branch information
JohnHalleyGotway authored Feb 6, 2024
1 parent 45274a1 commit 4abec0b
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 433 deletions.
12 changes: 12 additions & 0 deletions internal/test_unit/xml/unit_pcp_combine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,16 @@
</output>
</test>

<test name="pcp_combine_LAEA_GRIB2">
<exec>&MET_BIN;/pcp_combine</exec>
<param> \
-add &DATA_DIR_MODEL;/grib2/ukv/ukv_agl_temperature_1.5_12.grib2 \
'name="TMP"; level="Z1.5"; lead_time="24";' \
&OUTPUT_DIR;/pcp_combine/ukv_agl_temperature_1.5.nc
</param>
<output>
<grid_nc>&OUTPUT_DIR;/pcp_combine/ukv_agl_temperature_1.5.nc</grid_nc>
</output>
</test>

</met_test>
15 changes: 15 additions & 0 deletions internal/test_unit/xml/unit_plot_data_plane.xml
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,21 @@
</output>
</test>

<test name="plot_data_plane_LAEA_MET_NC">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
&OUTPUT_DIR;/pcp_combine/ukv_agl_temperature_1.5.nc \
&OUTPUT_DIR;/plot_data_plane/ukv_agl_temperature_laea_met_nc.ps \
'name="TMP_Z1.5"; level="(*,*)";' \
-title "MET NetCDF LAEA 1.5m Temperature" \
-v 1
</param>
<output>
<ps>&OUTPUT_DIR;/plot_data_plane/ukv_agl_temperature_laea_met_nc.ps</ps>
</output>
</test>


<test name="plot_data_plane_NCCF_POLAR_STEREO">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
Expand Down
10 changes: 6 additions & 4 deletions src/libcode/vx_data2d_grib2/data2d_grib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,8 @@ void MetGrib2DataFile::read_grib2_record_list() {

void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) {

const char * method_name = "MetGrib2DataFile::read_grib2_grid() -> ";

double d, r_km;
int ResCompFlag;
char hem = 0;
Expand Down Expand Up @@ -1040,7 +1042,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) {

// check for thinned lat/lon grid
if( data.Nlon == -1 ){
mlog << Error << "\nMetGrib2DataFile::read_grib2_grid() -> "
mlog << Error << "\n" << method_name
<< "Thinned Lat/Lon grids are not supported for GRIB version 2.\n\n";
exit(1);
}
Expand Down Expand Up @@ -1329,7 +1331,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) {
// build an LaeaData struct with the projection information
LaeaData laea;
laea.name = laea_proj_type;
laea.spheroid_name = "Grib template";
m_strncpy(laea.spheroid_name, "Grib template",m_strlen("Grib template"), method_name);

// earth shape
// Reference: https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table3-2.shtml
Expand Down Expand Up @@ -1385,7 +1387,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) {
break;

default:
mlog << Error << "\nMetGrib2DataFile::read_grib2_grid() -> "
mlog << Error << "\n" << method_name
<< "unsupported earth shape value of " << earth_shape_int << "!\n\n";
exit(1);
}
Expand Down Expand Up @@ -1433,7 +1435,7 @@ void MetGrib2DataFile::read_grib2_grid(gribfield *gfld) {
// unrecognized grid
else {

mlog << Error << "\nMetGrib2DataFile::read_grib2_grid() -> "
mlog << Error << "\n" << method_name
<< "found unrecognized grid definition (" << gfld->igdtnum << ")\n\n";
exit(1);

Expand Down
Loading

0 comments on commit 4abec0b

Please sign in to comment.