Skip to content

Bugfix: Fix the MET NetCDF library to support variables with more that 4 dimensions #3112

@maddenp-cu

Description

@maddenp-cu

Describe the Problem

Please see Discussion dtcenter/METplus#2935, which includes a reproducer.

The MET NetCDF library code currently segfaults with an unhelpful error message when reading data from a 5-dimensional variable.

The issues are:

  1. A 5D netCDF variable causes a segmentation fault.
  2. A 5D netCDF variable causes MET tools to emit an unhelpful, ungrammatical error message.
  3. The requirement for < 5D netCDF variables does not seem to be well documented.

An example exhibiting issues 1 and 2:

$ plot_data_plane 2t-heightAboveGround-0002.nc a.ps 'name="T2M"; level="(0,0,0,*,*)";'
DEBUG 1: Start plot_data_plane by maddenp(1000) at 2025-03-20 03:24:20Z  cmd: plot_data_plane 2t-heightAboveGround-0002.nc a.ps name="T2M"; level="(0,0,0,*,*)"; 
DEBUG 1: Opening data file: 2t-heightAboveGround-0002.nc
ERROR  : 
ERROR  : get_nc_att(NcVar) -> can't read attribute "grid_mapping" from because variable is invalid.
ERROR  : 
FATAL ERROR (SEGFAULT): Process 41632 got signal 11 @ local time = 2025-03-20 03:24:20Z
FATAL ERROR (SEGFAULT): Look for a core file in /home/maddenp/Desktop
FATAL ERROR (SEGFAULT): Process command line: plot_data_plane 2t-heightAboveGround-0002.nc a.ps name="T2M"; level="(0,0,0,*,*)"; 
Segmentation fault (core dumped)

Expected Behavior

Ideally, the 5D variable should be supported and processed. In weather applications, 5D data (dimensions: initialization time, forecast lead time, level, y/lat, x/lon) is common. A requirement to discard a dimension to work with MET could lead to information loss in otherwise self-describing netCDF.

If supporting >4D netCDF variables isn't feasible in the near term, I think a helpful improvement would be:

  1. Detect the issue and exit gracefully, avoiding a segmentation fault.
  2. Emit an precise message about the nature of the problem.
  3. State the requirements for netCDF variable dimensionality prominently in the MET User's Guide, ideally in section 4, MET Data I/O, in the subsections about netCDF. (It's possible that this is already documented and that I just missed it.)

Environment

I can reproduce the issue on NOAA's Hera, and on my own system running Ubuntu 22.04, and with my own build of MET V11.0.3, as well as the published V11.0.3 and latest V12 OCI container images.

To Reproduce

See plot_data_plane command and data file in the linked-to discussion.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

🏁 Done

Relationships

None yet

Development

No branches or pull requests

Issue actions