爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4789|回复: 2

[脚本编辑] matlab读取创建nc文件失败,有错误不知道怎么改?求助

[复制链接]

新浪微博达人勋

发表于 2018-4-21 16:31:33 | 显示全部楼层 |阅读模式

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

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

x
想把文件夹里的三个nc文件全部读入到一个新建的nc文件中,出现了错误,求指教!错误如下所示
错误使用 netcdflib
无法使用指定的文件名创建文件。文件名可能包含不受支持的字符。

出错 netcdf.create (line 53)
        ncid = netcdflib('create', filename, mode);

出错 humidity (line 11)
outid = netcdf.create(outdirfile,'NC_NOCLOBBER');%创建nc文件
代码如下

  1. clear all
  2. clc
  3. %定义输入目录
  4. inputdir = 'D:/matlabht/pdsi0505';
  5. %定义输出目录
  6. outputdir = 'D:/matlabht/pdsi';
  7. %获取目录下所有nc文件的信息
  8. inputfiles = dir([inputdir , '/', '*.nc']);
  9. outfile = (['pdsi199101_201412.nc']);%定义输出的nc文件的文件名
  10. outdirfile = [outputdir '/' outfile];%输出路径
  11. outid = netcdf.create(outdirfile,'NC_NOCLOBBER');%创建nc文件
  12. latdimID = netcdf.defDim(outid,'lat',360);%创建维度及维数
  13. londimID = netcdf.defDim(outid,'lon',720);%同理
  14. timedimID = netcdf.defDim(outid,'time',1380);%同

  15. latid = netcdf.defVar(outid,'lat','double',latdimID);%定义变量,变量名等。
  16. lonid = netcdf.defVar(outid,'lon','double',londimID);
  17. timeid = netcdf.defVar(outid,'time','int',timedimID);
  18. pdsiid = netcdf.defVar(outid,'pdsi','double',[londimID,latdimID,timedimID]);                 
  19. netcdf.endDef(outid);%定义结束
  20. for ifiles = 1:length(inputfiles) %length(inputfiles)是获取inputfiles的长度,就是nc文件的数目
  21.     infile = inputfiles(ifiles).name;%获取nc文件名
  22.     varName = infile(11:14);%把文件名的pdsi赋值给varname
  23.     indirfile = [inputdir '/' inputfiles(ifiles).name];%获取nc文件的完整路径
  24.     time = ncread(indirfile,'time');%读取时间变量
  25.     Ti=size(time);%获取时间变量的尺度
  26.     lon = ncread(indirfile,'lon');%读取经度
  27.     lat = ncread(indirfile,'lat');%读取纬度
  28.     pdsi = ncread(indirfile,'pdsi');
  29.     pdsi = double(pdsi);

  30.     netcdf.putVar(outid,latid,lat);%将值赋给变量
  31.     netcdf.putVar(outid,lonid,lon);
  32.     netcdf.putVar(outid,timeid,time);
  33.     netcdf.putVar(outid,pdsiid,pdsi);
  34.     netcdf.reDef(outid);%赋值结束

  35.     netcdf.putAtt(outid,latid,'long_name','latitude');%对变量的说明
  36.     netcdf.putAtt(outid,latid,'units','degrees_north');
  37.     netcdf.putAtt(outid,latid,'standard_name','latitude');

  38.     netcdf.putAtt(outid,lonid,'long_name','longitude');
  39.     netcdf.putAtt(outid,lonid,'units','degrees_east');
  40.     netcdf.putAtt(outid,lonid,'standard_name','longitude');

  41.     netcdf.putAtt(outid,timeid,'long_name','time');
  42.     netcdf.putAtt(outid,timeid,'units','hours since 1900-01-01 00:00:00');
  43.     netcdf.putAtt(outid,timeid,'standard_name','time');
  44.    
  45.     netcdf.putAtt(outid,pdsiid,'long_name','Palmer Drought Severity Index');
  46.     netcdf.putAtt(outid,pdsiid,'units','mm');
  47.     netcdf.putAtt(outid,pdsiid,'_FillValue','-9.99e+33');
  48.     netcdf.putAtt(outid,pdsiid,'missing_value','-9.99e+33');
  49.     netcdf.close(outid);
  50. end
复制代码



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

新浪微博达人勋

发表于 2018-11-14 19:33:41 | 显示全部楼层
请问您解决了吗?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-10-31 16:36:22 | 显示全部楼层
请问这问题怎么解决的呢
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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