Converting netcdf file to grads .grd binary file

Dear All,

Hope you are well. I have been using Linear Baroclinic Model (Watanabe 2000) for a study and I prepared a forcing file of latent heating using xarray. The file is in of course netcdf format. However, I need to transform it to a .grd file (and corresponding .ctl file) to incorporate it into the model. Scouring the internet, I have not been able to solve this issue. I have tried ncl, cdo etc. CDO for example changes the vertical levels to pressure from sigma. I need the file to be in sigma coordinates.

I would really appreciate if someone could help me on this. Thank you.

Nazimur
International Centre for Theoretical Physics

1 Like

Welcome @nrchow!

If you want someone to help you, you’ll need to provide a lot more detail. For example.

  • Share the file in question
  • Share the code you have tried so far
  • Share the documentation about the file format you want to transform it to (I’ve never heard of .grd or .ctl files)

Hello Nazimur,
I would like to know if you were able to figure conversion form netcdf to GRD file. Regards

Hi @nrchow

My understanding is that the .grd file is just a binary file, and the .ctl describes the dimensions and coordinates … see this link for a simple example of converting from netcdf using the air temperature tutorial dataset shipped with xarray:

netcdf_to_grads/netcdf_to_grads.ipynb at main · nicolasfauchereau/netcdf_to_grads

1 Like

Thank you nicolasf,

This is of very great help.

The code works perfectly for a 3-d data but i tend to run to issues converting a 4d dataset (time, level, lat, lon). The first time step displays perfectly in Grads but other time steps have a distorted longitude while the whole data have the same longitude axis. Also i’m trying to combine multiple variables into the grid file. my sample code is as below;

with open(output_grd, ‘wb’) as f:
for vr in [‘t’,‘u’]:#[‘u’,‘v’,‘t’,‘z’,‘q’,‘slp’]:
dd=data[vr].values.byteswap().astype(‘float32’)
f.write(dd)