Project

General

Profile

convert .dat file to .nc file

Added by kunal bali over 6 years ago

Dear CDO users,

How can I convert the attached .dat file to .nc file?

please let me know if you have any idea.

Thank You


Replies (3)

RE: convert .dat file to .nc file - Added by Karin Meier-Fleischer over 6 years ago

Hi Kunal,

the way to convert would be to create a gridfile

gridtype = lonlat
gridsize = 1036800
xname = lon
xlongname = longitude
xunits = degrees_east
yname = lat
ylongname = latitude
yunits = degrees_north
xsize = 1440
ysize = 720
xfirst = -179.88
xinc = 0.25
yfirst = -89.88
yinc = 0.25

then use CDOs input operator

cdo -f nc -settaxis,2016-04-01,00:00:00,1month -setname,OMIH2CO -input,gridfile.txt OM_outfile.nc < OMIH2CO_Grid_720x1440_201604.dat

BUT your ASCII data file do not contain the 1440x720 (=1036800) input elements!

-Karin

RE: convert .dat file to .nc file - Added by kunal bali over 6 years ago

Thanks for reply,

But the given code is not working. the processed as

Pushps-iMac:amit_kumar_sir Sagnik$ cdo -f nc -settaxis,2016-04-01,00:00:00,1month -setname,OMIH2CO -input,gridfile.txt OM_outfile.nc<OMIH2CO_Grida_720x1440_201604.dat
cdo settaxis: Started child process "setname,OMIH2CO -input,gridfile.txt (pipe1.1)".
cdo(2) setname: Started child process "input,gridfile.txt (pipe2.1)".
cdo(3) input: Enter all 1036800 elements of timestep 1!

cdo(3) input (Abort): Too few input elements (523080 of 1036800)!

Also, The data downloading link is given below
http://h2co.aeronomie.be/ch2o/ch2o.php?period=month&instr=omi&Month=04&Year=2016

RE: convert .dat file to .nc file - Added by Karin Meier-Fleischer over 6 years ago

Yup, the problem are the NaNs they have to be set to a missing value and then everything works fine.

  cat OMIH2CO_Grid_720x1440_201604.dat | sed -e 's|NaN|1e20|g' > OMIH2CO_Grid_720x1440_201604_changed.dat
  cdo -f nc -settaxis,2016-04-01,00:00:00,1month -setname,OMIH2CO -setmissval,1e20 -input,gridfile.txt OM_outfile.nc < OMIH2CO_Grid_720x1440_201604_changed.dat

-Karin

    (1-3/3)