请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4406|回复: 4

[混合编程] 如何用matlab生成ncl可读的nc文件?

[复制链接]

新浪微博达人勋

发表于 2022-6-7 11:13:13 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
各位大神,有谁知道如何用matlab生成的mat文件,转换成ncl可以读取的nc文件么?以下是代码,但是生成出来的nc文件只能matlab读取,ncl和grads好像都没有办法读取。


ncid = netcdf.create(‘uwnd_all_1km_era5_d_mon_anomaly_win_1950_2019.nc','CLOBBER');
dimidx = netcdf.defDim(ncid,'lon',360);
dimidy = netcdf.defDim(ncid,'lat',181);
dimidz = netcdf.defDim(ncid,'level',37);
dimtime= netcdf.defDim(ncid,'time',70);
varid = netcdf.defVar(ncid,'u','double',[dimidx dimidy dimidz dimtime]);
varid2 = netcdf.defVar(ncid,'longitude','double',[dimidx]);
varid3 = netcdf.defVar(ncid,'latitude','double',[dimidy]);
varid4 = netcdf.defVar(ncid,'level','double',[dimidz]);
varid5 = netcdf.defVar(ncid,'time','double',[dimtime]);
netcdf.putAtt(ncid,varid,'units','m s**-1');                     
netcdf.putAtt(ncid,varid2,'units','degress_east');                 
netcdf.putAtt(ncid,varid3,'units','degrees_north');
netcdf.putAtt(ncid,varid4,'units','millibars');
netcdf.putAtt(ncid,varid5,'units','year');
netcdf.putAtt(ncid,varid,'long_name','U_component_of_wind');
netcdf.putAtt(ncid,varid2,'long_name','Lontitude');
netcdf.putAtt(ncid,varid3,'long_name','Latitude');
netcdf.putAtt(ncid,varid4,'long_name','pressure_level');
netcdf.putAtt(ncid,varid5,'long_name','1950:2019');
netcdf.endDef(ncid);
file1='uwnd_all_1km_era5_d_mon_anomaly_win_1950_2019.nc';
u1=ncread(file1,'u');
lat=ncread(file1,'latitude');
lon=ncread(file1,'longitude');
time=ncread(file1,'time');
level=ncread(file1,'level');
netcdf.putVar(ncid,varid,anomaly_var_monthly); %这里anomaly_var_monthly是已经准备好的360*181*37*70的矩阵
netcdf.putVar(ncid,varid2,lon);
netcdf.putVar(ncid,varid3,lat);
netcdf.putVar(ncid,varid4,level);
netcdf.putVar(ncid,varid5,time);
netcdf.close(ncid);



密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2022-6-7 15:09:41 | 显示全部楼层
% 保存为nc文件格式
file=['D:\example.nc'];
if exist(file,'file')
    eval(['delete ', file ])
end
start_date = datenum(1980,01,01);
end_date = datenum(1980,12,31);
T = start_date:end_date;
T(60) = [];
[t,m,n]=size(ssst);

nccreate(file,'time','dimensions',{'time' t },'Datatype','single','format','netcdf4');
nccreate(file,'longitude','dimensions',{ 'lon' m },'Datatype','single','format','netcdf4') ;
nccreate(file,'latitude','dimensions',{'lat' n },'Datatype','single','format','netcdf4') ;
nccreate(file,'hsb','dimensions',{ 'time' t 'lon' m 'lat' n },'Datatype','single','format','netcdf4') ;

ncwrite(file,'sst',sst);
ncwrite(file,'time',T);
ncwrite(file,'longitude',lon);
ncwrite(file,'latitude',lat);


用这个
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-6-8 12:40:01 | 显示全部楼层
就是一个netCDFd 版本问题
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2022-6-9 10:57:16 | 显示全部楼层
lt5201314 发表于 2022-6-7 15:09
% 保存为nc文件格式
file=['D:\example.nc'];
if exist(file,'file')

好的,我试试看,非常感谢啊。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2022-6-9 11:01:15 | 显示全部楼层
陈小昌 发表于 2022-6-8 12:40
就是一个netCDFd 版本问题

好的,我再看看
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表