Problem

After using grib_to_netcdf to convert GRIB data to netCDF there are some fields in the output that are filled with missing values.

For example, the following file contains seven GRIB messages:  temperature at six constant pressure levels: 1000 hPa, 850 hPa, 700 hPa, 500 hPa,400 hPa and 300 hPa and geopotential at 1000 hPa only.  An inventory of the contents of the files using the cdo info  command shows:

% cdo info pl_data.grib
    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter ID
     1 : 2021-05-24 12:00:00  100000    16380       0 :      234.35      282.68      318.25 : 130.128       
     2 : 2021-05-24 12:00:00   85000    16380       0 :      227.39      275.67      306.60 : 130.128       
     3 : 2021-05-24 12:00:00   70000    16380       0 :      217.33      268.32      290.35 : 130.128       
     4 : 2021-05-24 12:00:00   50000    16380       0 :      225.52      253.62      277.05 : 130.128       
     5 : 2021-05-24 12:00:00   40000    16380       0 :      216.96      242.89      264.89 : 130.128       
     6 : 2021-05-24 12:00:00   30000    16380       0 :      206.11      229.50      250.12 : 130.128       
     7 : 2021-05-24 12:00:00  100000    16380       0 :     -2633.3      770.08      2708.6 : 129.128       
cdo    info: Processed 114660 values from 2 variables over 1 timestep [0.00s 15MB].

These GRIB messages are converted to netCDF with the grib_to_netcdf tool:

% grib_to_netcdf -o pl_data.nc pl_data.grib
grib_to_netcdf: Version 2.21.0
grib_to_netcdf: Processing input file 'pl_data.grib'.
grib_to_netcdf: Found 7 GRIB fields in 1 file.
grib_to_netcdf: Ignoring key(s): method, type, stream, refdate, hdate
grib_to_netcdf: Creating netCDF file 'pl_data.nc'
grib_to_netcdf: NetCDF library version: 4.7.4 of Apr 13 2020 12:16:51 $
grib_to_netcdf: Creating large (64 bit) file format.
grib_to_netcdf: Defining variable 't'.
grib_to_netcdf: Defining variable 'z'.
grib_to_netcdf: Done.

The seven GRIB fields are found and the netCDF file created.

However, when the inventory of the contents of the netCDF file is inspected using the cdo info  command,  12 fields are shown:

% cdo info pl_data.nc
    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter ID
     1 : 2021-05-24 12:00:00    1000    16380       0 :      234.35      282.68      318.25 : -1            
     2 : 2021-05-24 12:00:00     850    16380       0 :      227.39      275.67      306.60 : -1            
     3 : 2021-05-24 12:00:00     700    16380       0 :      217.33      268.32      290.35 : -1            
     4 : 2021-05-24 12:00:00     500    16380       0 :      225.52      253.62      277.05 : -1            
     5 : 2021-05-24 12:00:00     400    16380       0 :      216.96      242.89      264.89 : -1            
     6 : 2021-05-24 12:00:00     300    16380       0 :      206.11      229.50      250.13 : -1            
     7 : 2021-05-24 12:00:00    1000    16380       0 :     -2633.3      770.08      2708.6 : -2            
     8 : 2021-05-24 12:00:00     850    16380   16380 :                     nan             : -2            
     9 : 2021-05-24 12:00:00     700    16380   16380 :                     nan             : -2            
    10 : 2021-05-24 12:00:00     500    16380   16380 :                     nan             : -2            
    11 : 2021-05-24 12:00:00     400    16380   16380 :                     nan             : -2            
    12 : 2021-05-24 12:00:00     300    16380   16380 :                     nan             : -2            
cdo    info: Processed 196560 values from 2 variables over 1 timestep [0.00s 19MB].

It appears that grib_to_netcdf has 'invented' five additional geopotential fields at 850 hPa, 700 hPa, 500 hPa,400 hPa and 300 hPa and has filled these with missing values.

Explanation

The netCDF file really does contain the additional five fields filled with missing values. 

This happens because netCDF needs each data dimension to be of the same size for each variable so there cannot be only 1 level for one variable but 6 for the other. 

There has to be 6 levels for both variables in the netCDF file and so the conversion to netCDF creates the missing 5 levels for geopotential and fills all the data points with missing values.