Project

General

Profile

CDO NetCDF to Grib files

Added by Eric Baysee over 11 years ago

I am trying to convert a ocean current map into a grib file. Unfortunately I know nothing about netCDF or grib formats.

The NC file I'm trying to convert can be found here:
ftp://podaac-ftp.jpl.nasa.gov/allData/oscar/preview/L4/oscar_third_deg/
it is the oscar_vel7403.nc.gz file.

When I try:
cdo -f grb copy oscar_vel7403.nc oscar.grb
cgribexDefLevel : Changed zaxis type from generic to pressure
encodeBMS : Missing value = NaN is unsupported!
encodeBDS : Problem calculating binary scale value for encode code 1!
encodeBDS : < range nan rangec nan fmin -nan fmax -nan

Error (cgribexEncode) : Problem during GRIB encode (errno = 707)!

When I try:
cdo -f grb2 copy oscar_vel7403.nc oscar.grb2
gribapiDefLevel : Changed zaxis type from generic to pressure
GRIB_API ERROR : concept: no match for shortName=um
Warning (gribapiDefParam) : grib_api: No match for shortName=um
GRIB_API ERROR : concept: no match for shortName=vm
Warning (gribapiDefParam) : grib_api: No match for shortName=vm
cdo copy: Processed 2310724 values from 4 variables over 1 timestep ( 2.68s )

But the output file (oscar.grb2) is unreadable by zyGrib.

I would really appreciate any help anyone is willing to provide because I'm quite stuck.

Thanks,
Eric


Replies (6)

RE: CDO NetCDF to Grib files - Added by Eric Baysee over 11 years ago

After looking at this some more I found a valid list of grib2 shortnames:
http://ecmwf.int/publications/manuals/d/gribapi/param/order=paramId/order_type=asc/p=9/

I think the um and vm parameters need to be remapped into a valid grib2 name like:
Current direction dirc Degree true
Current speed spc m s**-1

I don't know anything about netcdf, so is there a tool that can modify the fields? Can CDO redefine them?

RE: CDO NetCDF to Grib files - Added by Eric Baysee over 11 years ago

I found from the CDO course how to compute magnitude (spc) and direction (dirc) using the u & v parameters.

The speed example is:
cdo sqrt -add -sqr u1000.grb -sqr v1000.grb SPEED1000.grb

But I don't know how to separate u & m from the original NetCDF file. I also don't know how to map the results to the spc parameter when building a grib file. Is this where I use an external parameter table to rename them when building a grib?

Likewise when the example creates the direction file through the following steps:
cdo mulc,57.3 -atan2 -mulc,-1, U1000.grb -mulc, -1 v1000.grb uv.grb
(performs the 180/pi * atan2(-u,-v) calculation)
cdo ltc,0 uv.zw2.grb mask
(makes mask file)
cdo ifthen mask -addc,360 uv.zw2.grb unter0.grb
cdo ifnotthen mask uv.zw2.grb ueber0.grb
cdo ifthenelse unter0.grb ueber0.grb uvcorrect.grb

How would I merge uvcorrect back with speed with the proper grib parameters? And the example commands I found are for working with grib files and I'm working with nc trying to get them to grib. So it's not working quite the same way.

RE: CDO NetCDF to Grib files - Added by Ralf Mueller over 11 years ago

Eric Baysee wrote:

I am trying to convert a ocean current map into a grib file. Unfortunately I know nothing about netCDF or grib formats.

The NC file I'm trying to convert can be found here:
ftp://podaac-ftp.jpl.nasa.gov/allData/oscar/preview/L4/oscar_third_deg/
it is the oscar_vel7403.nc.gz file.

When I try:
cdo -f grb copy oscar_vel7403.nc oscar.grb
cgribexDefLevel : Changed zaxis type from generic to pressure
encodeBMS : Missing value = NaN is unsupported!
encodeBDS : Problem calculating binary scale value for encode code 1!
encodeBDS : < range nan rangec nan fmin -nan fmax -nan

Error (cgribexEncode) : Problem during GRIB encode (errno = 707)!

NaN is not allowed in the grib standard, but you can change it with cdo:

[ram@thingol:~/tar/downloads]cdo setmissval,-9.e38 oscar_vel7403.nc t.nc
cdo setmissval: Processed 2310724 values from 4 variables over 1 timestep ( 0.12s )

and then convert it to grib
[ram@thingol:~/tar/downloads]cdo -f grb copy t.nc oscar_vel7403.grb            
cgribexDefLevel    : Changed zaxis type from generic to pressure
cdo copy: Processed 2310724 values from 4 variables over 1 timestep ( 0.09s )

Some lines on grib and netcdf:
GRIB1/GRIB2 are international standards for climate data sets defined by the WMO. Every data set has to have some identifiers (mostly integers), which describe what the data is (physical variable,unit,...). See here for a docu on the definitions. For example, NaN is not allowed for a missing value in the GRIB1 standard. In contrast to this Netcdf is self-explanatory: The user can defined, which name, unit or other (freely definable) attributes a certain variable should have. That's why it's not always possible to convert netcdf to grib.

hth
ralf

RE: CDO NetCDF to Grib files - Added by Eric Baysee over 11 years ago

Thanks Ralf. That's definitely a step in the right direction. I've made more progress. Your link will help me sort out why the grib format is still not working in grib viewers. There must be some problems with the Level/Parameter Names still.

I have small sample_current.grb off the internet that works (it also has sea temperature in it):

sample_current.grb 
    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter name
     1 : 2013-01-16 12:00:00       0       66      15 :    -0.26000    0.072745     0.46000 : var49      
     2 : 2013-01-16 12:00:00       0       66      14 :    -0.38000    0.040000     0.58000 : var50      
     3 : 2013-01-16 12:00:00       0       66      14 :      296.07      299.27      300.83 : var80      
cdo infon: Processed 198 values from 3 variables over 1 timestep ( 0.01s )

vs mine:
    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter name
     1 : 2013-01-11 00:00:00      15   577681  251085 :  0.00066114      182.13      360.00 : var1       
     2 : 2013-01-11 00:00:00      15   577681  251085 :  0.00018081     0.16572      3.0767 : var2       
cdo infon: Processed 1155362 values from 2 variables over 1 timestep ( 0.16s )


So if I can get the level and parameter name to match it might be closer.

RE: CDO NetCDF to Grib files - Added by Eric Baysee over 11 years ago

I've tried to find all the proper parameter settings but my grib viewers are still not displaying the data.

Example file that works (using grid_dump to extract info):

***** FILE: sample_current.grb 
#==============   MESSAGE 1 ( length=143 )                 ==============
GRIB {
  editionNumber = 1;
  table2Version = 2;
  # US National Weather Service - NCEP  (WMC)  (grib1/0.table)  
  centre = 7;
  generatingProcessIdentifier = 45;
  # None U-component of current m s**-1 (grib1/2.0.2.table)  
  indicatorOfParameter = 49;
  # Surface  (of the Earth, which includes sea surface)  (grib1/3.table)  
  indicatorOfTypeOfLevel = 1;
  level = 0;
  # P1 occupies octets 19 and 20; product valid at reference time + P1 (grib1/5.table)  
  timeRangeIndicator = 10;
  # Unknown code table entry ()  
  subCentre = 0;
  paramId = 3049;
  #-READ ONLY- units = m s**-1;
  #-READ ONLY- nameECMF = U-component of current ;
  #-READ ONLY- name = U-component of current ;
  decimalScaleFactor = 2;
  dataDate = 20130116;
  dataTime = 0;
  # Hour (stepUnits.table)  
  stepUnits = 1;
  stepRange = 12;
  startStep = 12;
  endStep = 12;
  #-READ ONLY- marsParam = 49.2;
  shortName = ucurr;
  GDSPresent = 1;
  bitmapPresent = 1;
  numberOfVerticalCoordinateValues = 0;
  Ni = 11;
  Nj = 6;
  latitudeOfFirstGridPointInDegrees = 20.165;
  longitudeOfFirstGridPointInDegrees = -89.985;
  earthIsOblate = 0;
  uvRelativeToGrid = 0;
  latitudeOfLastGridPointInDegrees = 24.755;
  longitudeOfLastGridPointInDegrees = -80.04;
  iScansNegatively = 0;
  jScansPositively = 1;
  jPointsAreConsecutive = 0;
  #-READ ONLY- alternativeRowScanning = 0;
  jDirectionIncrementInDegrees = 1.02;
  iDirectionIncrementInDegrees = 1.02;
  #-READ ONLY- numberOfDataPoints = 66;
  #-READ ONLY- numberOfValues = 51;
  missingValue = 9999;
  tableReference = 0;
  #-READ ONLY- binaryScaleFactor = 0;
  #-READ ONLY- referenceValue = -26;
  sphericalHarmonics = 0;
  complexPacking = 0;
  integerPointValues = 0;
  additionalFlagPresent = 0;
  packingType = grid_simple;
  bitsPerValue = 7;
  values(66) =  {
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, -3.0000152588e-02, 
  2.5999984741e-01, 1.4999984741e-01, 6.9999847412e-02, -1.2000015259e-01, -2.6000015259e-01, 
  1.2999984741e-01, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  3.9999847412e-02, -4.0000152588e-02, -8.0000152588e-02, 9.9990000000e+03, -1.0000015259e-01, 
  -1.8000015259e-01, 7.9999847412e-02, -1.5258789063e-07, -1.5258789063e-07, -1.5258789063e-07, 
  -2.0000152588e-02, 2.4999984741e-01, -3.0000152588e-02, 9.9990000000e+03, -1.5258789063e-07, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 6.9999847412e-02, -1.0000152588e-02, 
  -1.5258789063e-07, -1.5000015259e-01, -9.0000152588e-02, 1.4999984741e-01, 4.0999984741e-01, 
  3.0999984741e-01, 9.9990000000e+03, -1.5258789063e-07, -1.7000015259e-01, -8.0000152588e-02, 
  -5.0000152588e-02, 1.5999984741e-01, 1.7999984741e-01, 2.3999984741e-01, 5.9999847412e-02, 
  -6.0000152588e-02, 2.1999984741e-01, 3.8999984741e-01, 4.1999984741e-01, -3.0000152588e-02, 
  1.1999984741e-01, 2.5999984741e-01, 2.2999984741e-01, 2.0999984741e-01, 4.5999984741e-01, 
  2.5999984741e-01, -1.5258789063e-07, -1.5258789063e-07, -1.0000152588e-02, 9.9990000000e+03, 
  8.9999847412e-02
  } 
  #-READ ONLY- numberOfCodedValues = 51;
  #-READ ONLY- maximum = 0.46;
  #-READ ONLY- minimum = -0.26;
  #-READ ONLY- average = 0.0727449;
  #-READ ONLY- numberOfMissing = 15;
  #-READ ONLY- standardDeviation = 0.164151;
  #-READ ONLY- skewness = -0.11031;
  #-READ ONLY- kurtosis = 0.0981997;
  #-READ ONLY- isConstant = 0;
  gridType = regular_ll;
  #-READ ONLY- getNumberOfValues = 66;
}
#==============   MESSAGE 2 ( length=145 )                 ==============
GRIB {
  editionNumber = 1;
  table2Version = 2;
  # US National Weather Service - NCEP  (WMC)  (grib1/0.table)  
  centre = 7;
  generatingProcessIdentifier = 45;
  # None V-component of current m s**-1 (grib1/2.0.2.table)  
  indicatorOfParameter = 50;
  # Surface  (of the Earth, which includes sea surface)  (grib1/3.table)  
  indicatorOfTypeOfLevel = 1;
  level = 0;
  # P1 occupies octets 19 and 20; product valid at reference time + P1 (grib1/5.table)  
  timeRangeIndicator = 10;
  # Unknown code table entry ()  
  subCentre = 0;
  paramId = 3050;
  #-READ ONLY- units = m s**-1;
  #-READ ONLY- nameECMF = V-component of current ;
  #-READ ONLY- name = V-component of current ;
  decimalScaleFactor = 2;
  dataDate = 20130116;
  dataTime = 0;
  # Hour (stepUnits.table)  
  stepUnits = 1;
  stepRange = 12;
  startStep = 12;
  endStep = 12;
  #-READ ONLY- marsParam = 50.2;
  shortName = vcurr;
  GDSPresent = 1;
  bitmapPresent = 1;
  numberOfVerticalCoordinateValues = 0;
  Ni = 11;
  Nj = 6;
  latitudeOfFirstGridPointInDegrees = 20.165;
  longitudeOfFirstGridPointInDegrees = -89.985;
  earthIsOblate = 0;
  uvRelativeToGrid = 0;
  latitudeOfLastGridPointInDegrees = 24.755;
  longitudeOfLastGridPointInDegrees = -80.04;
  iScansNegatively = 0;
  jScansPositively = 1;
  jPointsAreConsecutive = 0;
  #-READ ONLY- alternativeRowScanning = 0;
  jDirectionIncrementInDegrees = 1.02;
  iDirectionIncrementInDegrees = 1.02;
  #-READ ONLY- numberOfDataPoints = 66;
  #-READ ONLY- numberOfValues = 52;
  missingValue = 9999;
  tableReference = 0;
  #-READ ONLY- binaryScaleFactor = 0;
  #-READ ONLY- referenceValue = -38;
  sphericalHarmonics = 0;
  complexPacking = 0;
  integerPointValues = 0;
  additionalFlagPresent = 0;
  packingType = grid_simple;
  bitsPerValue = 7;
  values(66) =  {
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 5.0000000000e-02, 
  -1.1000000000e-01, 6.0000000000e-02, -2.6000000000e-01, -1.6000000000e-01, 1.1000000000e-01, 
  1.4000000000e-01, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  4.3000000000e-01, -2.6000000000e-01, 1.9000000000e-01, 9.9990000000e+03, 1.5000000000e-01, 
  1.5000000000e-01, -8.0000000000e-02, 1.0000000000e-02, 0.0000000000e+00, 1.0000000000e-02, 
  4.0000000000e-02, 5.8000000000e-01, -3.0000000000e-02, 9.9990000000e+03, 0.0000000000e+00, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 1.3000000000e-01, 0.0000000000e+00, 
  0.0000000000e+00, 1.3000000000e-01, -6.0000000000e-02, -1.2000000000e-01, -2.1000000000e-01, 
  1.2000000000e-01, 0.0000000000e+00, 0.0000000000e+00, 1.0000000000e-02, 1.7000000000e-01, 
  -7.0000000000e-02, 7.0000000000e-02, 3.2000000000e-01, 3.3000000000e-01, -3.8000000000e-01, 
  -6.0000000000e-02, 4.0000000000e-02, 7.0000000000e-02, 2.5000000000e-01, 6.0000000000e-02, 
  -7.0000000000e-02, 1.7000000000e-01, -1.7000000000e-01, 1.0000000000e-01, 2.1000000000e-01, 
  -3.6000000000e-01, 1.0000000000e-02, 1.0000000000e-02, 1.0000000000e-02, 9.9990000000e+03, 
  3.5000000000e-01
  } 
  #-READ ONLY- numberOfCodedValues = 52;
  #-READ ONLY- maximum = 0.58;
  #-READ ONLY- minimum = -0.38;
  #-READ ONLY- average = 0.04;
  #-READ ONLY- numberOfMissing = 14;
  #-READ ONLY- standardDeviation = 0.180235;
  #-READ ONLY- skewness = -0.081396;
  #-READ ONLY- kurtosis = 0.217355;
  #-READ ONLY- isConstant = 0;
  gridType = regular_ll;
  #-READ ONLY- getNumberOfValues = 66;
}
#==============   MESSAGE 3 ( length=157 )                 ==============
GRIB {
  editionNumber = 1;
  table2Version = 2;
  # US National Weather Service - NCEP  (WMC)  (grib1/0.table)  
  centre = 7;
  generatingProcessIdentifier = 45;
  # None Water temperature K (grib1/2.0.2.table)  
  indicatorOfParameter = 80;
  # Surface  (of the Earth, which includes sea surface)  (grib1/3.table)  
  indicatorOfTypeOfLevel = 1;
  level = 0;
  # P1 occupies octets 19 and 20; product valid at reference time + P1 (grib1/5.table)  
  timeRangeIndicator = 10;
  # Unknown code table entry ()  
  subCentre = 0;
  paramId = 3080;
  #-READ ONLY- units = K;
  #-READ ONLY- nameECMF = Water temperature;
  #-READ ONLY- name = Water temperature;
  decimalScaleFactor = 2;
  dataDate = 20130116;
  dataTime = 0;
  # Hour (stepUnits.table)  
  stepUnits = 1;
  stepRange = 12;
  startStep = 12;
  endStep = 12;
  #-READ ONLY- marsParam = 80.2;
  shortName = wtmp;
  GDSPresent = 1;
  bitmapPresent = 1;
  numberOfVerticalCoordinateValues = 0;
  Ni = 11;
  Nj = 6;
  latitudeOfFirstGridPointInDegrees = 20.165;
  longitudeOfFirstGridPointInDegrees = -89.985;
  earthIsOblate = 0;
  uvRelativeToGrid = 0;
  latitudeOfLastGridPointInDegrees = 24.755;
  longitudeOfLastGridPointInDegrees = -80.04;
  iScansNegatively = 0;
  jScansPositively = 1;
  jPointsAreConsecutive = 0;
  #-READ ONLY- alternativeRowScanning = 0;
  jDirectionIncrementInDegrees = 1.02;
  iDirectionIncrementInDegrees = 1.02;
  #-READ ONLY- numberOfDataPoints = 66;
  #-READ ONLY- numberOfValues = 52;
  missingValue = 9999;
  tableReference = 0;
  #-READ ONLY- binaryScaleFactor = 0;
  #-READ ONLY- referenceValue = 29607;
  sphericalHarmonics = 0;
  complexPacking = 0;
  integerPointValues = 0;
  additionalFlagPresent = 0;
  packingType = grid_simple;
  bitsPerValue = 9;
  values(66) =  {
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 3.0046000000e+02, 
  3.0030000000e+02, 3.0063000000e+02, 3.0034000000e+02, 3.0051000000e+02, 3.0074000000e+02, 
  3.0083000000e+02, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  3.0057000000e+02, 3.0028000000e+02, 3.0035000000e+02, 9.9990000000e+03, 3.0030000000e+02, 
  3.0000000000e+02, 2.9989000000e+02, 2.9862000000e+02, 2.9888000000e+02, 2.9883000000e+02, 
  2.9958000000e+02, 3.0057000000e+02, 3.0008000000e+02, 9.9990000000e+03, 2.9822000000e+02, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 2.9823000000e+02, 2.9861000000e+02, 
  2.9869000000e+02, 3.0061000000e+02, 3.0018000000e+02, 2.9983000000e+02, 2.9948000000e+02, 
  2.9982000000e+02, 2.9828000000e+02, 2.9841000000e+02, 2.9865000000e+02, 2.9797000000e+02, 
  2.9853000000e+02, 2.9836000000e+02, 3.0000000000e+02, 2.9989000000e+02, 2.9983000000e+02, 
  2.9828000000e+02, 2.9849000000e+02, 2.9829000000e+02, 2.9977000000e+02, 2.9868000000e+02, 
  2.9759000000e+02, 2.9809000000e+02, 2.9816000000e+02, 2.9988000000e+02, 3.0013000000e+02, 
  2.9925000000e+02, 2.9730000000e+02, 2.9745000000e+02, 2.9607000000e+02, 9.9990000000e+03, 
  2.9941000000e+02
  } 
  #-READ ONLY- numberOfCodedValues = 52;
  #-READ ONLY- maximum = 300.83;
  #-READ ONLY- minimum = 296.07;
  #-READ ONLY- average = 299.273;
  #-READ ONLY- numberOfMissing = 14;
  #-READ ONLY- standardDeviation = 1.07835;
  #-READ ONLY- skewness = 36.0257;
  #-READ ONLY- kurtosis = 189.834;
  #-READ ONLY- isConstant = 0;
  gridType = regular_ll;
  #-READ ONLY- getNumberOfValues = 66;
}

vs. my version with as many parameters as I could duplicate:

***** FILE: grib4.grb 
#==============   MESSAGE 1 ( length=1052089 )             ==============
GRIB {
  editionNumber = 1;
  table2Version = 2;
  # Absent (grib1/0.table)  
  centre = 0;
  generatingProcessIdentifier = 0;
  # None U-component of current m s**-1 (grib1/2.0.2.table)  
  indicatorOfParameter = 49;
  # Unknown code table entry (grib1/3.table)  
  indicatorOfTypeOfLevel = 99;
  level = 0;
  # P1 occupies octets 19 and 20; product valid at reference time + P1 (grib1/5.table)  
  timeRangeIndicator = 10;
  # Unknown code table entry ()  
  subCentre = 0;
  paramId = 3049;
  #-READ ONLY- units = m s**-1;
  #-READ ONLY- nameECMF = U-component of current ;
  #-READ ONLY- name = U-component of current ;
  decimalScaleFactor = 0;
  dataDate = 20130111;
  dataTime = 0;
  # Hour (stepUnits.table)  
  stepUnits = 1;
  stepRange = 0;
  startStep = 0;
  endStep = 0;
  #-READ ONLY- marsParam = 49.2;
  shortName = ucurr;
  GDSPresent = 1;
  bitmapPresent = 1;
  numberOfVerticalCoordinateValues = 0;
  Ni = 1201;
  Nj = 481;
  latitudeOfFirstGridPointInDegrees = 80;
  longitudeOfFirstGridPointInDegrees = 20;
  earthIsOblate = 0;
  uvRelativeToGrid = 0;
  latitudeOfLastGridPointInDegrees = -80;
  longitudeOfLastGridPointInDegrees = 420;
  iScansNegatively = 0;
  jScansPositively = 0;
  jPointsAreConsecutive = 0;
  #-READ ONLY- alternativeRowScanning = 0;
  jDirectionIncrementInDegrees = 0.333;
  iDirectionIncrementInDegrees = 0.333;
  #-READ ONLY- numberOfDataPoints = 577681;
  #-READ ONLY- numberOfValues = 326596;
  missingValue = 9999;
  tableReference = 0;
  #-READ ONLY- binaryScaleFactor = -21;
  #-READ ONLY- referenceValue = -2.974;
  sphericalHarmonics = 0;
  complexPacking = 0;
  integerPointValues = 0;
  additionalFlagPresent = 0;
  packingType = grid_simple;
  bitsPerValue = 24;
  values(577681) =  {
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 6.1985492706e-02, 6.8765640259e-02, 
  7.0969581604e-02, 6.7500591278e-02, 6.8272590637e-02, 7.1832180023e-02, 7.3102951050e-02, 
  7.2218894958e-02, 6.9448471069e-02, 6.4827442169e-02, 6.0001850128e-02, 5.6409835815e-02, 
  5.2356243134e-02, 4.6277999878e-02, 3.9613246918e-02, 3.2646656036e-02, 2.8143405914e-02, 
  2.4936199188e-02, 2.1338939667e-02, 1.6165256500e-02, 1.2553215027e-02, 1.1231422424e-02, 
  6.0567855835e-03, -2.8510093689e-03, -5.9452056885e-03, -4.2695999146e-03, -5.0683021545e-03, 
  -8.4004402161e-03, -1.0519981384e-02, -1.1647701263e-02, -1.2827396393e-02, -1.3732433319e-02, 
  -1.5794754028e-02, -1.8545627594e-02, -2.0952224731e-02, -2.3254871368e-02, -2.5729656219e-02, 
  -2.8085231781e-02, -2.9251575470e-02, -2.9203891754e-02, -2.9052734375e-02, -2.8546810150e-02, 
  -2.9724597931e-02, -3.3092498779e-02, -3.4337997437e-02, -3.3972263336e-02, -3.2477855682e-02, 
  -2.8063774109e-02, -2.5378704071e-02, -2.4604320526e-02, -2.0157337189e-02, -1.2188911438e-02, 
  -9.3183517456e-03, -1.0591030121e-02, -9.7460746765e-03, -6.9160461426e-03, -5.1298141479e-03, 
  -3.3512115479e-03, -7.2345733643e-03, -1.8085956573e-02, -2.2605895996e-02, -2.1058082581e-02, 
  -2.3513317108e-02, -1.2103080750e-02, -1.2700080872e-02, -1.2605667114e-02, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03
  ... 577581 more values
  } 
  #-READ ONLY- numberOfCodedValues = 326596;
  #-READ ONLY- maximum = 2.6378;
  #-READ ONLY- minimum = -2.974;
  #-READ ONLY- average = 0.00108477;
  #-READ ONLY- numberOfMissing = 251085;
  #-READ ONLY- standardDeviation = 0.180649;
  #-READ ONLY- skewness = 548.577;
  #-READ ONLY- kurtosis = 4455.66;
  #-READ ONLY- isConstant = 0;
  gridType = regular_ll;
  #-READ ONLY- getNumberOfValues = 577681;
}
#==============   MESSAGE 2 ( length=1052145 )             ==============
GRIB {
  editionNumber = 1;
  table2Version = 2;
  # Absent (grib1/0.table)  
  centre = 0;
  generatingProcessIdentifier = 0;
  # None V-component of current m s**-1 (grib1/2.0.2.table)  
  indicatorOfParameter = 50;
  # Unknown code table entry (grib1/3.table)  
  indicatorOfTypeOfLevel = 99;
  level = 0;
  # P1 occupies octets 19 and 20; product valid at reference time + P1 (grib1/5.table)  
  timeRangeIndicator = 10;
  # Unknown code table entry ()  
  subCentre = 0;
  paramId = 3050;
  #-READ ONLY- units = m s**-1;
  #-READ ONLY- nameECMF = V-component of current ;
  #-READ ONLY- name = V-component of current ;
  decimalScaleFactor = 0;
  dataDate = 20130111;
  dataTime = 0;
  # Hour (stepUnits.table)  
  stepUnits = 1;
  stepRange = 0;
  startStep = 0;
  endStep = 0;
  #-READ ONLY- marsParam = 50.2;
  shortName = vcurr;
  GDSPresent = 1;
  bitmapPresent = 1;
  numberOfVerticalCoordinateValues = 0;
  Ni = 1201;
  Nj = 481;
  latitudeOfFirstGridPointInDegrees = 80;
  longitudeOfFirstGridPointInDegrees = 20;
  earthIsOblate = 0;
  uvRelativeToGrid = 0;
  latitudeOfLastGridPointInDegrees = -80;
  longitudeOfLastGridPointInDegrees = 420;
  iScansNegatively = 0;
  jScansPositively = 0;
  jPointsAreConsecutive = 0;
  #-READ ONLY- alternativeRowScanning = 0;
  jDirectionIncrementInDegrees = 0.333;
  iDirectionIncrementInDegrees = 0.333;
  #-READ ONLY- numberOfDataPoints = 577681;
  #-READ ONLY- numberOfValues = 326615;
  missingValue = 9999;
  tableReference = 0;
  #-READ ONLY- binaryScaleFactor = -21;
  #-READ ONLY- referenceValue = -2.80945;
  sphericalHarmonics = 0;
  complexPacking = 0;
  integerPointValues = 0;
  additionalFlagPresent = 0;
  packingType = grid_simple;
  bitsPerValue = 24;
  values(577681) =  {
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 7.3223114014e-03, 1.3909816742e-02, 
  8.9507102966e-03, 2.0589351654e-02, 4.2535305023e-02, 2.5877952576e-02, 1.8608570099e-02, 
  1.4615058899e-02, -2.7960777283e-02, -4.1948795319e-02, -3.0321121216e-02, -5.4396152496e-02, 
  -5.5059432983e-02, -3.3967494965e-02, -5.3331375122e-02, -4.9716949463e-02, -2.7568817139e-02, 
  -4.6511650085e-02, -2.9290676117e-02, 2.9468536377e-04, -3.6760807037e-02, -2.4107456207e-02, 
  4.1730403900e-02, 1.5381813049e-02, -2.3376941681e-02, -1.5441894531e-02, -4.8038482666e-02, 
  -4.2623996735e-02, 1.5630722046e-03, -1.8455028534e-02, -1.6727924347e-02, 1.1217117310e-02, 
  -1.9688129425e-02, -2.6135921478e-02, -8.1539154053e-03, -4.6359539032e-02, -5.9507846832e-02, 
  -4.3700695038e-02, -7.3716163635e-02, -8.0008506775e-02, -5.6048870087e-02, -6.9665908813e-02, 
  -7.3253631592e-02, -4.7851085663e-02, -3.9845943451e-02, -1.9941806793e-02, 2.2924423218e-02, 
  3.0858993530e-02, 1.2455940247e-02, 2.5856494904e-02, 6.3945770264e-02, 6.1388492584e-02, 
  3.1032562256e-02, 3.9249897003e-02, 5.5818080902e-02, 5.3390026093e-02, 6.5127372742e-02, 
  5.3706169128e-02, 2.0084857941e-02, 3.8753986359e-02, 6.0284137726e-02, 4.1775703430e-02, 
  4.2128086090e-02, 4.2120933533e-02, 4.3317794800e-02, 7.8818321228e-02, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 
  9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03, 9.9990000000e+03
  ... 577581 more values
  } 
  #-READ ONLY- numberOfCodedValues = 326615;
  #-READ ONLY- maximum = 2.36568;
  #-READ ONLY- minimum = -2.80945;
  #-READ ONLY- average = 0.00595926;
  #-READ ONLY- numberOfMissing = 251066;
  #-READ ONLY- standardDeviation = 0.148112;
  #-READ ONLY- skewness = 256.623;
  #-READ ONLY- kurtosis = 2647.56;
  #-READ ONLY- isConstant = 0;
  gridType = regular_ll;
  #-READ ONLY- getNumberOfValues = 577681;
}

Any ideas of what I might be doing wrong or what I could try?

RE: CDO NetCDF to Grib files - Added by Eric Baysee over 11 years ago

As a follow up, I've found that viewing programs are not very consistent. Some can read the file I've generated and some can't.

zyGrib, uGrib - fail
airmail's viewfax - works
maxsea's viewer - works.
openCPN - no errors, but no data shown

However with the sample file only zyGrib (don't know about uGrib) fails.

Here is basically what I'm doing:

# changed -9.e38 to 0 because grib_dump was showing large array size mismatch errors
cdo setmissval,0 oscar_vel7403.nc temp.nc
cdo -selname,u temp.nc u.nc
cdo -selname,v temp.nc v.nc
cdo -setname,var49 u.nc u2.nc
cdo -setname,var50 v.nc v2.nc
cdo -merge u2.nc v2.nc temp.nc
cdo -setlevel,0 temp.nc final.nc
cdo -setlevel,0 final.nc final1.nc
cdo -f grb -t table.txt copy final1.nc grib.grb
grib_set -s paramId=3049 grib.grb -w indicatorOfParameter=49 grib2.grb
grib_set -s paramId=3050 grib2.grb -w indicatorOfParameter=50 grib3.grb
grib_set -s table2Version=2 grib3.grb grib4.grb

My table.txt file is (but it doesn't seem to be working, so I use setname and follow up with grib_set)

049    u-component of current [m s**-1]
050    v-component of current [m s**-1]

    (1-6/6)