Project

General

Profile

Trouble converting a GRADS ctl GRIB file to a NetCDF!

Added by Layla Smith almost 2 years ago

Hello cdo users,

I am having problems converting a GrADs ctl GRIB data file to NetCDF format. From the Data Integration and Analysis System, I downloaded 6-hourly JRA-55 reanalysis data for an entire month. It downloads in the form of a DAT file and there is a supporting GrADs ctl file that says that the data type is in GRIB format.

The contents of the anl_surf.ctl file is as follows:

dset ^anl_surf.%y4%m2%d2%h2
index ^anl_surf.idx
undef 9.999E+20
title anl_surf
  • produced by grib2ctl v0.9.12.5p41
    dtype grib 255
    options template
    ydef 320 levels
    -89.570 -89.013 -88.453 -87.892 -87.331 -86.769 -86.208 -85.647 -85.085 -84.523
    -83.962 -83.400 -82.839 -82.277 -81.716 -81.154 -80.592 -80.031 -79.469 -78.908
    -78.346 -77.784 -77.223 -76.661 -76.100 -75.538 -74.976 -74.415 -73.853 -73.291
    -72.730 -72.168 -71.607 -71.045 -70.483 -69.922 -69.360 -68.799 -68.237 -67.675
    -67.114 -66.552 -65.990 -65.429 -64.867 -64.306 -63.744 -63.182 -62.621 -62.059
    -61.498 -60.936 -60.374 -59.813 -59.251 -58.689 -58.128 -57.566 -57.005 -56.443
    -55.881 -55.320 -54.758 -54.196 -53.635 -53.073 -52.512 -51.950 -51.388 -50.827
    -50.265 -49.704 -49.142 -48.580 -48.019 -47.457 -46.895 -46.334 -45.772 -45.211
    -44.649 -44.087 -43.526 -42.964 -42.402 -41.841 -41.279 -40.718 -40.156 -39.594
    -39.033 -38.471 -37.909 -37.348 -36.786 -36.225 -35.663 -35.101 -34.540 -33.978
    -33.416 -32.855 -32.293 -31.732 -31.170 -30.608 -30.047 -29.485 -28.924 -28.362
    -27.800 -27.239 -26.677 -26.115 -25.554 -24.992 -24.431 -23.869 -23.307 -22.746
    -22.184 -21.622 -21.061 -20.499 -19.938 -19.376 -18.814 -18.253 -17.691 -17.129
    -16.568 -16.006 -15.445 -14.883 -14.321 -13.760 -13.198 -12.636 -12.075 -11.513
    -10.952 -10.390 -9.828 -9.267 -8.705 -8.144 -7.582 -7.020 -6.459 -5.897
    -5.335 -4.774 -4.212 -3.651 -3.089 -2.527 -1.966 -1.404 -0.842 -0.281
    0.281 0.842 1.404 1.966 2.527 3.089 3.651 4.212 4.774 5.335
    5.897 6.459 7.020 7.582 8.144 8.705 9.267 9.828 10.390 10.952
    11.513 12.075 12.636 13.198 13.760 14.321 14.883 15.445 16.006 16.568
    17.129 17.691 18.253 18.814 19.376 19.938 20.499 21.061 21.622 22.184
    22.746 23.307 23.869 24.431 24.992 25.554 26.115 26.677 27.239 27.800
    28.362 28.924 29.485 30.047 30.608 31.170 31.732 32.293 32.855 33.416
    33.978 34.540 35.101 35.663 36.225 36.786 37.348 37.909 38.471 39.033
    39.594 40.156 40.718 41.279 41.841 42.402 42.964 43.526 44.087 44.649
    45.211 45.772 46.334 46.895 47.457 48.019 48.580 49.142 49.704 50.265
    50.827 51.388 51.950 52.512 53.073 53.635 54.196 54.758 55.320 55.881
    56.443 57.005 57.566 58.128 58.689 59.251 59.813 60.374 60.936 61.498
    62.059 62.621 63.182 63.744 64.306 64.867 65.429 65.990 66.552 67.114
    67.675 68.237 68.799 69.360 69.922 70.483 71.045 71.607 72.168 72.730
    73.291 73.853 74.415 74.976 75.538 76.100 76.661 77.223 77.784 78.346
    78.908 79.469 80.031 80.592 81.154 81.716 82.277 82.839 83.400 83.962
    84.523 85.085 85.647 86.208 86.769 87.331 87.892 88.453 89.013 89.570
    xdef 640 linear 0.000000 0.562500
    pdef 157792 1 file 1 stream binary-big ^TL319.pdef
    tdef 120 linear 00Z01Apr1958 6hr
    zdef 1 linear 1 1
    vars 7
    POTsfc 0 13,1,0 * surface Potential temperature [K]
    PRESsfc 0 1,1,0 *
    surface Pressure [Pa]
    RH2m 0 52,105,2 * 2 m above ground Relative humidity [%]
    SPFH2m 0 51,105,2 *
    2 m above ground Specific humidity [kg/kg]
    TMP2m 0 11,105,2 * 2 m above ground Temperature [K]
    UGRD10m 0 33,105,10 *
    10 m above ground u-component of wind [m/s]
    VGRD10m 0 34,105,10 ** 10 m above ground v-component of wind [m/s]
    ENDVARS

Using someone's answer from a similarly asked question I used the command:
cdo -f nc import_binary anl_surf.ctl anl_surf.nc

But I receive the following error:

Open Error: Unknown keyword in description file
--> The invalid description file record is:
--> index ^anl_surf.idx
The data file was not opened.

cdo import_binary (Abort): Open failed!

I found out from another forum post that this error is a result of the fact that the INDEX component is not supported by CDO and the import_binary operator does not support the GRIB format.

Does anyone know if there is an operator that supports converting a GrADS ctl file with data in GRIB format to a NetCDF. Unfortunately, I cannot download this data directly in the GRIB format, only in DAT format. Any help is appreciated, thank you!


Replies (8)

RE: Trouble converting a GRADS ctl GRIB file to a NetCDF! - Added by Layla Smith almost 2 years ago

Here is the ctl file and index file I have, if anyone would like to try it themselves.

RE: Trouble converting a GRADS ctl GRIB file to a NetCDF! - Added by Estanislao Gavilan almost 2 years ago

Hi Grace,

I am not sure if this is the solution that you are looking for. I was able to run it after removing these lines.

index ^anl_surf.idx
dtype grib 255
pdef 157792 1 file 1 stream binary-big ^TL319.pdef

You will need to check if these lines are important or/and the information is not altered.Maybe cdo has a different keyword for those lines that is why it does not recognise them

RE: Trouble converting a GRADS ctl GRIB file to a NetCDF! - Added by Karin Meier-Fleischer almost 2 years ago

Hi Grace,

CDO don't accept all Parameters used in the GrADS .ctl file (https://code.mpimet.mpg.de/boards/1/topics/3220)

CDO supports only the following components of a GrADS control file:

BYTESWAPPED, CHSUB, DSET, ENDVARS, FILEHEADER, HEADERBYTES, OPTIONS, TDEF, TITLE,
TRAILERBYTES, UNDEF, VARS, XDEF, XYHEADER, YDEF, ZDEF

The INDEX component is not supported! As far as I know the INDEX component is needed for GRIB files. The GRIB format is also not supported by this operator! import_binary was >implemented only for binary data.

You can try to use NCL (https://www.ncl.ucar.edu/Applications/grads.shtml).

RE: Trouble converting a GRADS ctl GRIB file to a NetCDF! - Added by Layla Smith almost 2 years ago

Hi Estanislao,

I believe I need those lines in there because an index is needed inside a ctl file for a GRIB formatted data. I just need to figure out how to convert it with those lines in there.

RE: Trouble converting a GRADS ctl GRIB file to a NetCDF! - Added by Layla Smith almost 2 years ago

Hi Karin,

When I look at the NCL website it only talks about converting binary data using import_binary, which is what didn't work for me earlier. I don't know what supports converting a GRADs file with GRIB data to NetCDF.

RE: Trouble converting a GRADS ctl GRIB file to a NetCDF! - Added by Estanislao Gavilan almost 2 years ago

Hi Grace,
it seems quite tricky to use that extension. The only thing I can recommend you is to open your files in python (there are several kernels: xgrads, py3grads, pyGrads), and then you save them in a new netcdf file. I am not sure if you can open those files in Ferret. You colud ask their community, they are really active and helpful.

Kind regards,

PS: if you find a way post it. I was looking on internet and there are not many things about grads ctl with idx

RE: Trouble converting a GRADS ctl GRIB file to a NetCDF! - Added by Karin Meier-Fleischer almost 2 years ago

Hi Grace,

netCDF is a self-describing file format that makes work a lot easier and the NCL page describes how you can do it.

    (1-8/8)