Skip to content

NetCDF 4.10.0: compound type with enum: ncdump cannot read a file generated by ncgen. #3407

Description

@Alexander-Barth

I am try to implement NetCDF compound data types in the julia package NCDatasets.jl.

I came across a strange issue where ncdump does not accept the NetCDF file generated by ncgen.
ncgen is given the following CDL:

netcdf weather_data {
types:
  byte enum cloud_t {Clear = 0, Cumulonimbus = 1, Stratus = 2, Overcast = 3};

  compound obs_t {
    float temperature;
    int humidity;
    cloud_t sky_condition;  // Nested Enum
  };

dimensions:
  station = 3;

variables:
  obs_t weather_reports(station);

data:
  weather_reports =
    {22.5, 65, Clear},
    {18.0, 90, Cumulonimbus},
    {15.4, 82, Overcast};
}

Note the nested enum. ncgen seem to be work fine

ncgen -o compound_enum_issue.nc compound_enum_issue.cdl

but ncdump compound_enum_issue.nc fails with:

netcdf compound_enum_issue {                                                                                                                                                 
types:                                                                                                                                                                       
  byte enum cloud_t {Clear = 0, Cumulonimbus = 1, Stratus = 2, Overcast = 3} ;                                                                                               
  compound obs_t {                                                                                                                                                           
    float temperature ;                                                                                                                                                      
    int humidity ;                                                                                                                                                           
    cloud_t sky_condition ;                                                                                                                                                  
  }; // obs_t                                                                                                                                                                
dimensions:                                                                                                                                                                  
        station = 3 ;                                                                                                                                                        
variables:                                                                                                                                                                   
        obs_t weather_reports(station) ;                                                                                                                                     
data:                                                                                                                                                                        
                                                                                                                                                                             
NetCDF: Invalid argument
Location: file dumplib.c; fcn ncenum_typ_tostring line 959
weather_reports = {22.5, 65, Clear}, {0, 5915024, Clear},

Only the first value is correct.

I am using netcdf version 4.10.0 distributed by julia on Linux.
I have similar issue with other NetCDF version installed on my system.

Maybe ncgen did not create correctly data in the first place.
Or do you see a problem with my CDL?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions