爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 10318|回复: 13

[程序设计] matlab读取NC处理完后,写入NC的问题

[复制链接]

新浪微博达人勋

发表于 2015-3-31 09:09:04 | 显示全部楼层 |阅读模式

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

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

x
大家好,新手,轻拍。
代码如下:
**************************************************************
clear all
clc
ifile = 'clip_pr_Amon_bcc-csm1-1-m_historical_r1i1p1_185001-201212.nc';
ncdisp(ifile);
PrData = ncread(ifile,'pr');
TimeData = ncread(ifile,'time');
Lon = ncread(ifile,'lon');
Lat = ncread(ifile,'lat');

PrData = permute(PrData,[2 1 3]);
[xx,yy,zz] = meshgrid(Lon,Lat,TimeData);
[xi,yi,zi] = meshgrid(87:0.5:127,37:0.5:54,TimeData);
%---------------Interpolation-----------------------------------
vi = interp3(xx,yy,zz,PrData,xi,yi,zi);
%---------------Define the output file-----------------------
outfile = ['bil_',ifile];%定义输出的nc文件的文件名
outid = netcdf.create(outfile,'CLOBBER');%创建nc文件
%---------------Define dimension-----------------------------
latdimID = netcdf.defDim(outid,'lat',35);%创建维度及维数
londimID = netcdf.defDim(outid,'lon',181);%同理
timedimID = netcdf.defDim(outid,'time',1956);%同
% ----------------Define new variables-----------------------
lat_ = netcdf.defVar(outid,'lat','double',latdimID);%定义变量,变量名等。
lon_ = netcdf.defVar(outid,'lon','double',londimID);
time_ = netcdf.defVar(outid,'time','int',timedimID);
predata_ = netcdf.defVar(outid,'pr','double',[londimID,latdimID,timedimID]);                 
netcdf.endDef(outid);%定义结束
%----------------Assign value--------------------------------
xi_lat = xi(:,1,1);
yi_lon = permute(yi(1,:,1),[2 1]);

netcdf.putVar(outid,lat_,xi_lat);%将值赋给变量
netcdf.putVar(outid,lon_,yi_lon);
netcdf.putVar(outid,time_,TimeData);
netcdf.putVar(outid,predata_,vi);
netcdf.reDef(outid);%赋值结束
%---------------Add attribute--------------------------------
netcdf.putAtt(outid,lat_,'long_name','latitude');%对变量的说明
netcdf.putAtt(outid,lat_,'units','degrees_north');
netcdf.putAtt(outid,lat_,'standard_name','latitude');

netcdf.putAtt(outid,lon_,'long_name','longitude');
netcdf.putAtt(outid,lon_,'units','degrees_east');
netcdf.putAtt(outid,lon_,'standard_name','longitude');

netcdf.putAtt(outid,time_,'long_name','time');
netcdf.putAtt(outid,time_,'units','days since 1850-01-01 00:00:00');
netcdf.putAtt(outid,time_,'standard_name','time');

netcdf.putAtt(outid,predata_,'long_name','Precipitation');
netcdf.putAtt(outid,predata_,'units','kg m-2 s-1');
netcdf.putAtt(outid,predata_,'_FillValue','1e+20');
netcdf.putAtt(outid,predata_,'missing_value','1e+20');

netcdf.close(outid);

**************************************************************
写入数据不太明白怎么搞?请熟悉的人给予指导。谢谢。
来自群组: 国科大

评分

参与人数 1金钱 +2 收起 理由
谢丽凤凤 + 2 很给力!

查看全部评分

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

新浪微博达人勋

发表于 2015-3-31 10:27:48 | 显示全部楼层

回帖奖励 +2 金钱

看不懂你的问题。。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-3-31 10:45:59 | 显示全部楼层
又是那隻貓 发表于 2015-3-31 10:27
看不懂你的问题。。

就是我的数据经过了插值,想把处理过的数据写入新的nc文件,黄色部分提示错误。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-2 16:49:34 | 显示全部楼层

回帖奖励 +2 金钱

cool。。。。。。。。
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2015-4-3 09:21:39 | 显示全部楼层

回帖奖励 +2 金钱

感觉挺有用 赞楼主
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-3 09:40:38 | 显示全部楼层

回帖奖励 +2 金钱

最好也把错误提示贴出来  也方便解答的
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-4-11 19:41:59 | 显示全部楼层

回帖奖励 +2 金钱

看不出来。。。
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2015-4-13 17:51:16 | 显示全部楼层

回帖奖励 +2 金钱

写过一个二维的,grads可用。大致一样,不过是属性在前,赋值在后,没有这个命令:netcdf.reDef(outid);%赋值结束
写入属性——netcdf.endDef(outid);,赋值——netcdf.close(ncid);
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-10-10 10:54:36 | 显示全部楼层

回帖奖励 +2 金钱

不知楼主问题解决么?我想问下楼主变量为pr=128*60*240,时间为240*1怎么解决楼主
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-11-17 19:39:35 | 显示全部楼层

回帖奖励 +2 金钱

楼主问题解决了吗
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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