...
Section | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
NCAR command language (NCL)
|
NCAR command language (NCL)
NCL provides a tool to convert both GRIB-1 & GRIB-2 NCL provides a tool to convert both GRIB1 & GRIB2 to netCDF called ncl_convert2nc.
...
These instructions assume the use of a recent version of Climate Data Operators (CDO) (available from Max-Planck-Institut, Germany).
CDO supports GRIB2 GRIB-2 but needs either the GRIB_API or ecCodes library from ECMWF to be included. This is necessary in order to work correctly with OpenIFS model output.
...
In this example, the different files might contain: '01' - fields on pressure levels, '02' - fields on model levels, '03' - hybrid levels, '04' - surface and so on. The number of files created depends on the number of different types of levels. Use the command 'grib_ls' to inspect the contents of each split file.
Note that the filename 'ICMSH
' in this example, indicates it contains spectral and not gridpoint fields.
Another way to split the file would be using the grib_copy command from the grib-api (or ecCodes) library as shown above:
Code Block |
---|
grib_copy ICMSHg4a4+000000.grb ICMSHg4a4+000000_[typeOfLevel].grb |
...
To interpolate to pressure levels instead of from model levels, use this cdo command, for example:
Code Block | ||
---|---|---|
| ||
cdo ml2pl,92500,85000,50000,20000 <input file> <output file> |
...
Code Block | ||
---|---|---|
| ||
grib_ls ICMSHfrq2+000000.grb
grib_dump ICMSHfrq2+000000.grb |
Here is another example using the cdo command:
Code Block | ||
---|---|---|
| ||
$ cdo sinfo ICMSHfrq2+000000.grb File format: GRIB -1 : Institut Source Param Time Typ Grid Size Num Levels Num 1 : ECMWF unknown 11.3 var P16 65792 1 60 1 2 : ECMWF unknown 39.3 var P16 65792 1 60 1 3 : ECMWF unknown 43.3 var P16 65792 1 60 1 4 : ECMWF unknown 44.3 var P16 65792 1 60 1 5 : ECMWF unknown 152.128 var P16 65792 1 1 2 6 : ECMWF unknown 6.3 var P16 65792 1 1 2 Horizontal grids : 1 : spectral > size : dim = 65792 truncation = 255 spc = 32896 complexPacking = 1 Vertical grids : 1 : hybrid level : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 2 : hybrid level : 1 Time axis : 1 step RefTime = 1999-12-24 12:00:00 Units = hours Calendar = PROLEPTIC YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss 1999-12-24 12:00:00 cdo sinfo: Processed 6 variables over 1 timestep. ( 0.04s ) |
Examples
...
Converting a single file
In this example a single GRIB file with model level data, on a regular Gaussian grid is converted to netCDF with vorticity & divergence replaced by u & v and model level data interpolated to pressure levels.
Code Block |
---|
cdo -f nc copy file.grb file.nc cdo dv2uvl file.nc file_uv.nc cdo sp2gpl file_uv.nc file_uv_gg.nc cdo ml2pl,92500,85000,50000,20000 file_uv_gg.nc file_uv_gg_pl.nc |
...
Converting series of files
The following script shows how to loop over several output files using the steps above to convert to netCDF. Note the spectral parameter files are also converted but the extra command using the sp2gpl operator is first used to convert the variables from spectral to gridpoint on a regular, linear, Gaussian grid.
In this example, we use the pipelining feature of CDO to do both the 'copy' and 'sp2gpl' steps in one command, keeping the entire operations in memory for efficiency.
Code Block | ||
---|---|---|
| ||
for i in 000 024 048 072 do cdo -R copy ICMGGfpp4+000${i}.grb ICMGGfpp4+000${i}_R.grb cdo splitzaxis ICMGGfpp4+000${i}_R.grb ICMGGfpp4+000${i} cdo -f nc copy ICMGGfpp4+000${i}01.grb ICMGGfpp4+000${i}_PL_PLGGGP.nc # pressure level gridpoint fields cdo -f nc copy ICMGGfpp4+000${i}02.grb ICMGGfpp4+000${i}_ML_MLGGGP.nc cdo splitzaxis ICMSHfpp4+ # model level gridpoint fields cdo splitzaxis ICMSHfpp4+000${i}.grb ICMSHfpp4+000${i} cdo -f nc copy -sp2gpl ICMSHfpp4+000${i}01.grb ICMSHfpp4+000${i}01_PL_GP_PL.grb # spectral fields on press levels transformed to gridpoint cdo -f nc copy -sp2gpl ICMSHfpp4+000${i}03.grb ICMSHfpp4+000${i}03_ML_GP_ML.grb cdo -f nc copy - # spectral fields on model levels transformed to gridpoint cdo -f nc copy -sp2gpl ICMSHfpp4+000${i}04.grb ICMSHfpp4+000${i}04_surf_GP_surf.grb # spectral fields on surface levels transformed to gridpoint done |
Possible problems and solutions
Workaround if CDO does not understand
...
GRIB-2 messages
If you are using an old version of CDO, it may not understand GRIB-2 messages. CDO must be compiled with either grib-api or ecCodes library in order to handle GRIB-2.
A workaround is to use or one that does not use the grib-api or ecCodes libraries, Use the grib_set
command (from the grib_api/ecCodes installation) to change the GRIB edition number for all messages.
...
Note |
---|
Note this will only work if you are using less than 128 model levels as it does not actually convert the message to GRIB1 GRIB-1 if there are any GRIB2 GRIB-2 specific elements in the messages. |
Parameter names are lost
...
for GRIB-1 fields
ECMWF GRIB-1 use keys which may not be recognised by CDO because they are locally defined (e.g. the shortName
key) and not defined in the WMO GRIB tables that CDO uses. This can cause parameter names to be lost or not recognised when using the CDO commands.
A workaround is to use the -t ecmwf
option. The -t option
tells CDO to use the predefined The -t option tells CDO to use the predefined ECMWF parameter tables (see CDO documentation for more details). Without this option parameter names are not preserved. If the - t option doesn't work this is usually because CDO is using an old version of the ECMWF GRIB_API software.
.
Code Block |
---|
cdo -t ecmwf -f nc copy mygrib1.grb mygrib1.nc |
Warning |
---|
Do not use this option for GRIB-2 fields. It sets the GRIB table default to be specific to the GRIB-1 ECMWF tables. |
Acknowledgements
Thanks to Paul Dando of User Support for help with the contents of this page.
...
HTML |
---|
<script type="text/javascript" src="https://software.ecmwf.int/issues/s/en_UKet2vtj/787/12/1.2.5/_/download/batch/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector.js?collectorId=5fd84ec6"></script> |
...