Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
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]
  1 commentaire
Geoff Hayes
Geoff Hayes le 5 Sep 2014
James - what happens if you use change the format from netcdf4 to netcdf4_classic?

Connectez-vous pour commenter.

Réponse acceptée

Ashish Uthama
Ashish Uthama le 5 Sep 2014
Modifié(e) : Ashish Uthama le 5 Sep 2014
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 commentaire
James Renwick
James Renwick le 6 Sep 2014
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

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by