Project

General

Profile

How can I convert .dat file to .nc file? How to create gridfile.txt for converting ?

Added by jyoti lodha about 6 years ago

Hi
I want to convert my .dat file of CRU data to .nc format. How to create a gridfile for it, as I am not able to see the parameters through cdo sinfon? How i can process it.

cdo -f nc -settaxis,2001-01-01,00:00:00,1month -setname,rain -input,gridfile.txt cru_outfile.nc < cru_ts4.01.2001.2010.pre.dat

cdo settaxis: Started child process "setname,rain -input,gridfile.txt (pipe1.1)".
cdo(2) setname: Started child process "input,gridfile.txt (pipe2.1)".
cdo(3) input: Enter all 1036800 elements of record 1!
cdo(3) input: Enter all 1036800 elements of record 2!
cdo(3) input: Enter all 1036800 elements of record 3!
cdo(3) input: Enter all 1036800 elements of record 4!
cdo(3) input: Enter all 1036800 elements of record 5!
cdo(3) input: Enter all 1036800 elements of record 6!
cdo(3) input: Enter all 1036800 elements of record 7!
cdo(3) input: Enter all 1036800 elements of record 8!
cdo(3) input: Enter all 1036800 elements of record 9!
cdo(3) input: Enter all 1036800 elements of record 10!
cdo(3) input: Enter all 1036800 elements of record 11!
cdo(3) input: Enter all 1036800 elements of record 12!
cdo(3) input: Enter all 1036800 elements of record 13!
cdo(3) input: Enter all 1036800 elements of record 14!
cdo(3) input: Enter all 1036800 elements of record 15!
cdo(3) input: Enter all 1036800 elements of record 16!
cdo(3) input: Enter all 1036800 elements of record 17!
cdo(3) input: Enter all 1036800 elements of record 18!
cdo(3) input: Enter all 1036800 elements of record 19!
cdo(3) input: Enter all 1036800 elements of record 20!
cdo(3) input: Enter all 1036800 elements of record 21!
cdo(3) input: Enter all 1036800 elements of record 22!
cdo(3) input: Enter all 1036800 elements of record 23!
cdo(3) input: Enter all 1036800 elements of record 24!
cdo(3) input: Enter all 1036800 elements of record 25!
cdo(3) input: Enter all 1036800 elements of record 26!
cdo(3) input: Enter all 1036800 elements of record 27!
cdo(3) input: Enter all 1036800 elements of record 28!
cdo(3) input: Enter all 1036800 elements of record 29!
cdo(3) input: Enter all 1036800 elements of record 30!
cdo(3) input: Enter all 1036800 elements of record 31!
cdo(3) input: ( 30.13s )
cdo(2) setname: Processed 31104000 values from 1 variable over 30 timesteps ( 30.14s )
cdo settaxis: Processed 31104000 values from 1 variable over 30 timesteps ( 30.14s )

Thanks .


Replies (5)

RE: How can I convert .dat file to .nc file? How to create gridfile.txt for converting ? - Added by Karin Meier-Fleischer about 6 years ago

Hi Jyoti,

you can use the import_binary operator and a GrADS descriptor file to read and convert a binary file. Without the gridfile.txt I can only give you an example what it could look like.

grid_descriptor.ctl

DSET ^cru_ts4.01.2001.2010.pre.dat
OPTIONS sequential
UNDEF -999
XDEF 360 LINEAR -179.5 1
YDEF 180 LINEAR  -89.5 1
ZDEF   1 LINEAR    1   1
TDEF 120 LINEAR 00:00:00Z01jan2001 1mo
VARS 1 
rain 1 99 description of the variable
ENDVARS
cdo -f nc import_binary grid_description.ctl cru.nc

-Karin

RE: How can I convert .dat file to .nc file? How to create gridfile.txt for converting ? - Added by jyoti lodha about 6 years ago

Hi
Thanks a lot. I will try in Grads and read my input file. Thanks a lot. :)

RE: How can I convert .dat file to .nc file? How to create gridfile.txt for converting ? - Added by Karin Meier-Fleischer about 6 years ago

No, not in GrADS. You have to save the descriptor file in your working directory and run the CDO command from above.

-Karin

RE: How can I convert .dat file to .nc file? How to create gridfile.txt for converting ? - Added by jyoti lodha about 6 years ago

Hi
Yes, I understood what u said, but If I am having different year .dat files I want to create descriptor file like u created and gave me like :grid_descriptor.ctl. So how I will create it at my end?Does I have to use GrADS software for it. Thanks a Lot.:)

RE: How can I convert .dat file to .nc file? How to create gridfile.txt for converting ? - Added by jyoti lodha about 6 years ago

Hi
When I ran the above command I got the following error: As I just copy the the command in my txt file and save it as .ctl. Is it correct.
DSET ^cru_ts4.01.2001.2010.pre.dat
OPTIONS sequential
UNDEF -999
XDEF 360 LINEAR -179.5 1
YDEF 180 LINEAR -89.5 1
ZDEF 1 LINEAR 1 1
TDEF 120 LINEAR 00:00:00Z01jan2001 1mo
VARS 1
rain 1 99 description of the variable
ENDVARS

me@64cca86184b5:~$ cdo -f nc import_binary grid_description.ctl cru.nc
fopen failed on grid_description.ctl
cdo import_binary (Abort): Open failed!

Help me where I am wrong.

    (1-5/5)