How do I write a netcdf file that ncdump and cdo/GrADS will understand?

9 次查看(过去 30 天)
I am experimenting with writing netcdf files using nccreate and ncwrite. everything appears to work fine and I can read the resulting netcdf file back into Matlab no problem. But when I try using unix/DOS utilities like ncdump, I'm told "Not a netCDF file". I am trying to import the data into GrADS using cdo (Climate data operators) but strike essentially the same problem. Is there something I'm missing?
My data are sea ice concentrations on a 161x161 grid over the southern oceans and Antarctica. I created the data set using
nccreate('ice_monthly_ps161x161_3d.nc','x','dimensions',{'x',nx},'format','netcdf4')
ncwrite('ice_monthly_ps161x161_3d.nc','x',x)
nccreate('ice_monthly_ps161x161_3d.nc','y','dimensions',{'y',ny})
ncwrite('ice_monthly_ps161x161_3d.nc','y',y)
nccreate('ice_monthly_ps161x161_3d.nc','lat','dimensions',{'x','y'})
ncwrite('ice_monthly_ps161x161_3d.nc','lat',lat)
nccreate('ice_monthly_ps161x161_3d.nc','lon','dimensions',{'x','y'})
ncwrite('ice_monthly_ps161x161_3d.nc','lon',lon)
nccreate('ice_monthly_ps161x161_3d.nc','time','dimensions',{'time',ice.nt})
ncwrite('ice_monthly_ps161x161_3d.nc','time',timenum)
nccreate('ice_monthly_ps161x161_3d.nc','projection','dimensions',{'projection',length(ice.specs)})
ncwrite('ice_monthly_ps161x161_3d.nc','projection',ice.specs)
nccreate('ice_monthly_ps161x161_3d.nc','ice_concentration','dimensions',{'x','y','time'})
ncwrite('ice_monthly_ps161x161_3d.nc','ice_concentration',icef)
where 'icef' is a 3d array of the sea ice data. I can look at the netCDF file with ncinfo and can read it OK with the ncread routine or with the nctoolbox library. But when I use ncdump from the DOS command line I am told this is not a netCDF file.
Am I missing something simple here? Any suggestions appreciated.
[Edit: Formatted code. -AU]

采纳的回答

Ashish Uthama
Ashish Uthama 2014-9-5
编辑:Ashish Uthama 2014-9-5
James - my guess is that the other utilities you are using are based on an older version of the NetCDF library - they do not recognize netcdf4 files. netcdf4 is not backwards compatible, hence @Geoff's suggestion to try a different format. Though, I would recommend also trying 'classic'.
More information on the formats is here
  1 个评论
James Renwick
James Renwick 2014-9-6
Dear Ashish, Geoff -
Thank you both so much! I was skeptical at first when I read your answers, as netcdf4_classic is the default format and I had already established that this didn't work either (forgot to mention this, sorry).
But - setting the format to 'classic' gave me a netCDF file that ncdump can read! This is great, and should solve my problems.
Cheers, James

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by