...
Before converting to netCDF separate the different vertical axes:
Code Block |
---|
title | Separate multiple z axes into individual files |
---|
|
cdo splitzaxis <input grib> <output grib> |
Then finally convert the resulting output files to netcdf:. 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.
Code Block |
---|
title | Convert GRIB file to netCDF file |
---|
|
cdo -t ecmwf |
Code Block |
---|
cdo -f nc copy <input grib> <output netcdf> |
Example 1
The following script shows how to loop over several output files using the steps above to convert to netCDF:
Code Block |
---|
title | Sample script to convert OpenIFS GRIB output to netCDF |
---|
|
for i in 000 024 048 072
do
grib_set -s editionNumber=1 ICMGGfpp4+000${i} ICMGGfpp4+000${i}.grb
cdo -R copy ICMGGfpp4+000${i}.grb ICMGGfpp4+000${i}_R.grb
cdo splitzaxis ICMGGfpp4+000${i}_R.grb ICMGGfpp4+000${i}
cdo -t ecmwf -f nc copy ICMGGfpp4+000${i}01.grb ICMGGfpp4+000${i}_PLGG.nc
cdo -t ecmwf -f nc copy ICMGGfpp4+000${i}02.grb ICMGGfpp4+000${i}_MLGG.nc
grib_set -s editionNumber=1 ICMSHfpp4+000${i} ICMSHfpp4+000${i}.grb
cdo splitzaxis ICMSHfpp4+000${i}.grb ICMSHfpp4+000${i}
cdo sp2gpl ICMSHfpp4+000${i}01.grb ICMSHfpp4+000${i}01_GP.grb
cdo sp2gpl ICMSHfpp4+000${i}03.grb ICMSHfpp4+000${i}03_GP.grb
cdo sp2gpl ICMSHfpp4+000${i}04.grb ICMSHfpp4+000${i}04_GP.grb
cdo -t ecmwf -f nc copy ICMSHfpp4+000${i}03_GP.grb ICMSHfpp4+000${i}_ML.nc
cdo -t ecmwf -f nc copy ICMSHfpp4+000${i}01_GP.grb ICMSHfpp4+000${i}_PL.nc
cdo -t ecmwf -f nc copy ICMSHfpp4+000${i}04_GP.grb ICMSHfpp4+000${i}_surf.nc
done |
Note the spherical harmonic files are also converted but the extra command using the sp2gpl operator is first used to convert the variables from spherical harmonics to gridpoint.
There are various commands for inspecting the contents of a GRIB file. The GRIB_API installation as part of OpenIFS has useful commands like grib_ls
and grib_dump
. Here is another example using the cdo command:
Code Block |
---|
title | Example cdo command for inspecting GRIB file |
---|
|
$ 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. |
...
Example 2
Code Block |
---|
grib_set -s editionNumber=1 file file.grb #set grib2 -> grib1
cdo -t ecmwf -f nc copy file.grb file.nc #copy to netcdf
cdo -t ecmwf dv2uvl file.nc file_uv.nc #div/vort -> u/v
cdo -t ecmwf sp2gpl file_uv.nc file_uv_gg.nc #sh -> gp
cdo -t ecmwf ml2pl,92500,85000,50000,20000 file_uv_gg.nc file_uv_gg_pl.nc #ml -> pl |
...