- 积分
- 266
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-12-14
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如题,使用的是Matlab2014a
尝试生成一个nc数据,经向和纬向各十个格点,时次为1,生成数据后,用matlab读取没有问题,但是用grads的sdfopen命令读取就会报错。
报错内容如下:
gadsdf: SDF file has no discernable X coordinate.
To open this file with GrADS, use a descriptor file with an XDEF entry.
Documentation is at http://iges.org/grads/gadoc/SDFdescriptorfile.html
生成nc的程序如下,可能有点长,请各位指教,万谢!
%% 1创建nc文件
ncid=netcdf.create('test8.nc','NC_NOCLOBBER');
%% 2定义Dimension
lon=1:10;
lat=1:10;
time=0;
dimidx = netcdf.defDim(ncid,'lon',10);
dimidy = netcdf.defDim(ncid,'lat',10);
dimidt = netcdf.defDim(ncid,'time',1);
%%3赋予属性
%lon
varid_lon=netcdf.defVar(ncid,'longitude','double',dimidx);
netcdf.putAtt(ncid,varid_lon,'long_name','Longitude');
netcdf.putAtt(ncid,varid_lon,'units','degrees_east');
netcdf.putAtt(ncid,varid_lon,'axis','X');
%lat
varid_lat = netcdf.defVar(ncid,'latitude','double',dimidy);
netcdf.putAtt(ncid,varid_lat,'long_name','Latitude');
netcdf.putAtt(ncid,varid_lat,'units','degrees_north');
netcdf.putAtt(ncid,varid_lat,'axis','Y');
%time
varid_time = netcdf.defVar(ncid,'time','int',dimidt);
netcdf.putAtt(ncid,varid_time,'long_name','Time');
netcdf.putAtt(ncid,varid_time,'calendar','standard');
netcdf.putAtt(ncid,varid_time,'units','hour since 1900-01-01 00:00');
%% 4.定义变量:
varid_chl = netcdf.defVar(ncid,'CHL','double',[dimidx dimidy dimidt]);
netcdf.putAtt(ncid,varid_chl,'long_name','CHLFEB');
netcdf.putAtt(ncid,varid_chl,'units','mg/m2/day');
% netcdf.putAtt(ncid,varid_chl,'missing_value',-32767);%fine the missing value
%% 5完成netCDF文件定义模式
netcdf.endDef(ncid)
%% 6 把数据写到netcdf的文件中
netcdf.putVar(ncid,varid_chl,rand(10))
netcdf.putVar(ncid,varid_lon,lon);
netcdf.putVar(ncid,varid_lat,lat);
netcdf.putVar(ncid,varid_time,time);
%% 7 关闭文件
netcdf.close(ncid);
|
|