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

14 ビュー (過去 30 日間)
James Renwick
James Renwick 2014 年 9 月 5 日
コメント済み: James Renwick 2014 年 9 月 6 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 9 月 5 日
James - what happens if you use change the format from netcdf4 to netcdf4_classic?

サインインしてコメントする。

採用された回答

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 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by