爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 5481|回复: 1

[程序设计] MATLAB批量读取nc文件遇到的问题,求解答

[复制链接]

新浪微博达人勋

发表于 2017-1-22 12:46:25 | 显示全部楼层 |阅读模式

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

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

x
想提取nc文件中的 FinalAerosolAbsOpticalDepth500这一变量,但报错时显示nc文件中并无此变量,奇怪。
程序如下:
clc;  %清屏
clear; %清空
datadir='G:\AODdata\2005\'; %指定批量数据所在的文件夹
filelist=dir([datadir,'*.nc']); %指定批量数据的类型
a=filelist(1).name; %查看你要读取的文件的编号。filelist(1).name在window下为第一个标号数据
b=filelist(2).name; %查看你要读取的文件的编号。filelist(2).name在window下为第二个标号数据
k=length(filelist);
for s=1:k
  filename=[datadir,filelist(s).name];
  ncid=netcdf.open(filename,'NC_NOWRITE');
  ncdisp('G:\AODdata\2005\OMI-Aura_L3-OMAERUVd_2005m0930_v003-2012m0325t110429.he5.nc'); %在命令窗中显示nc文件的变量
  AODData  = ncread(filename,' FinalAerosolAbsOpticalDepth500'); %读入变量
  TimeData  = ncread(filename,'time'); %读入变量time
  LonData  = ncread(filename,'lon'); %读入变量lon
  LatData  = ncread(filename,'lat'); %读入变量lat
  netcdf.close(ncid);   % 关闭文件
end;
运行后显示:
Source:
           G:\AODdata\2005\OMI-Aura_L3-OMAERUVd_2005m0930_v003-2012m0325t110429.he5.nc
Format:
           classic
Global Attributes:
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.OrbitNumber             = [6418  6419  6420  6421  6422  6423  6424  6425  6426  6427  6428  6429  6430  6431  6432  6433  6434  6435  6436  6437  6438  6439  6440  6441  6442  6443  6444  6445  6446  6447  6448  6449  6450  6451  6452  6453  6454  6455  6456  6457  6458  6459  6460  6461]
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.OrbitPeriod             = [5933  5932  5933  5932  5933  5932  5933  5932  5933  5932  5933  5932  5933  5932  5933  5932  5933  5932  5933  5932  5933  5933  5932  5932  5933  5932  5933  5932  5933  5933  5932  5932  5933  5933  5932  5933  5932  5933  5932  5933  5932  5933  5932  5933]
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.InstrumentName          = 'OMI'
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.ProcessLevel            = '3'
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.GranuleMonth            = 9
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.GranuleDay              = 30
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.GranuleYear             = 2005
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.GranuleDayOfYear        = 273
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.TAI93At0zOfGranule      = 402192005
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.PGEVersion              = '\"1.2.0.1\"'
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.StartUTC                = '2005-09-29T12:15:00.000000Z'
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.EndUTC                  = '2005-10-01T11:45:00.000000Z'
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.Period                  = 'Daily'
           HDFEOS_ADDITIONAL_FILE_ATTRIBUTES.fullnamepath            = '/HDFEOS/ADDITIONAL/FILE_ATTRIBUTES'
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.GCTPProjectionCode       = 0
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.Projection               = 'Geographic'
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.GridOrigin               = 'Center'
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.GridSpacing              = '(1.0,1.0)'
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.GridSpacingUnit          = 'deg'
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.GridSpan                 = '(-180,180,-90,90)'
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.GridSpanUnit             = 'deg'
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.NumberOfLongitudesInGrid = 360
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.NumberOfLatitudesInGrid  = 180
           HDFEOS_GRIDS_Aerosol_NearUV_Grid.fullnamepath             = '/HDFEOS/GRIDS/Aerosol NearUV Grid'
           HDFEOS_INFORMATION.HDFEOSVersion                          = 'HDFEOS_5.1.11'
           HDFEOS_INFORMATION.fullnamepath                           = '/HDFEOS INFORMATION'
Dimensions:
           lat                  = 180
           lon                  = 360
           StructMetadata_0_len = 2491
Variables:
    FinalAerosolAbsOpticalDepth388
           Size:       360x180
           Dimensions: lon,lat
           Datatype:   single
           Attributes:
                       _FillValue            = -1.267650600228229e+30
                       units                 = 'NoUnits'
                       title                 = 'Final Aerosol Absorption Optical Depth at 388 nm'
                       UniqueFieldDefinition = 'OMI-Specific'
                       scale_factor          = 1
                       add_offset            = 0
                       missing_value         = -1.267650600228229e+30
                       origname              = 'FinalAerosolAbsOpticalDepth388'
                       fullnamepath          = '/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolAbsOpticalDepth388'
                       orig_dimname_list     = 'YDim XDim'
    FinalAerosolAbsOpticalDepth500
           Size:       360x180
           Dimensions: lon,lat
           Datatype:   single
           Attributes:
                       _FillValue            = -1.267650600228229e+30
                       units                 = 'deg'
                       title                 = 'Final Aerosol Absorption Optical Depth at 500 nm'
                       UniqueFieldDefinition = 'Aura-Shared'
                       scale_factor          = 1
                       add_offset            = 0
                       missing_value         = -1.267650600228229e+30
                       origname              = 'FinalAerosolAbsOpticalDepth500'
                       fullnamepath          = '/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolAbsOpticalDepth500'
                       orig_dimname_list     = 'YDim XDim'
    FinalAerosolExtOpticalDepth388
           Size:       360x180
           Dimensions: lon,lat
           Datatype:   single
           Attributes:
                       _FillValue            = -1.267650600228229e+30
                       units                 = 'NoUnits'
                       title                 = 'Final Aerosol Extinction Optical Depth at 388 nm'
                       UniqueFieldDefinition = 'OMI-Specific'
                       scale_factor          = 1
                       add_offset            = 0
                       missing_value         = -1.267650600228229e+30
                       origname              = 'FinalAerosolExtOpticalDepth388'
                       fullnamepath          = '/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolExtOpticalDepth388'
                       orig_dimname_list     = 'YDim XDim'
    FinalAerosolExtOpticalDepth500
           Size:       360x180
           Dimensions: lon,lat
           Datatype:   single
           Attributes:
                       _FillValue            = -1.267650600228229e+30
                       units                 = 'NoUnits'
                       title                 = 'Final Aerosol Extinction Optical Depth at 500 nm'
                       UniqueFieldDefinition = 'OMI-Specific'
                       scale_factor          = 1
                       add_offset            = 0
                       missing_value         = -1.267650600228229e+30
                       origname              = 'FinalAerosolExtOpticalDepth500'
                       fullnamepath          = '/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolExtOpticalDepth500'
                       orig_dimname_list     = 'YDim XDim'
    FinalAerosolSingleScattAlb388
           Size:       360x180
           Dimensions: lon,lat
           Datatype:   single
           Attributes:
                       _FillValue            = -1.267650600228229e+30
                       units                 = 'NoUnits'
                       title                 = 'Final Aerosol Single Scattering Albedo at 388 nm'
                       UniqueFieldDefinition = 'OMI-Specific'
                       scale_factor          = 1
                       add_offset            = 0
                       missing_value         = -1.267650600228229e+30
                       origname              = 'FinalAerosolSingleScattAlb388'
                       fullnamepath          = '/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolSingleScattAlb388'
                       orig_dimname_list     = 'YDim XDim'
    FinalAerosolSingleScattAlb500
           Size:       360x180
           Dimensions: lon,lat
           Datatype:   single
           Attributes:
                       _FillValue            = -1.267650600228229e+30
                       units                 = 'NoUnits'
                       title                 = 'Final Aerosol Single Scattering Albedo at 500 nm'
                       UniqueFieldDefinition = 'OMI-Specific'
                       scale_factor          = 1
                       add_offset            = 0
                       missing_value         = -1.267650600228229e+30
                       origname              = 'FinalAerosolSingleScattAlb500'
                       fullnamepath          = '/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/FinalAerosolSingleScattAlb500'
                       orig_dimname_list     = 'YDim XDim'
    UVAerosolIndex               
           Size:       360x180
           Dimensions: lon,lat
           Datatype:   single
           Attributes:
                       _FillValue            = -1.267650600228229e+30
                       units                 = 'NoUnits'
                       title                 = 'UV Aerosol Index'
                       UniqueFieldDefinition = 'OMI-Specific'
                       scale_factor          = 1
                       add_offset            = 0
                       missing_value         = -1.267650600228229e+30
                       origname              = 'UVAerosolIndex'
                       fullnamepath          = '/HDFEOS/GRIDS/Aerosol NearUV Grid/Data Fields/UVAerosolIndex'
                       orig_dimname_list     = 'YDim XDim'
    StructMetadata_0              
           Size:       2491x1
           Dimensions: StructMetadata_0_len
           Datatype:   char
           Attributes:
                       origname     = 'StructMetadata.0'
                       fullnamepath = '/HDFEOS INFORMATION/StructMetadata.0'
    lon                           
           Size:       360x1
           Dimensions: lon
           Datatype:   single
           Attributes:
                       units = 'degrees_east'
    lat                           
           Size:       180x1
           Dimensions: lat
           Datatype:   single
           Attributes:
                       units = 'degrees_north'
Error using internal.matlab.imagesci.nc/getGroupAndVarid (line 2083)
Could not find variable or group ' FinalAerosolAbsOpticalDepth500' in file.

Error in internal.matlab.imagesci.nc/read (line 593)
            [gid, varid] = getGroupAndVarid(this, location);

Error in ncread (line 58)
vardata = ncObj.read(varName, varargin{:});

Error in dunc (line 12)
  AODData  = ncread(filename,' FinalAerosolAbsOpticalDepth500'); %读入变量


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

新浪微博达人勋

发表于 2017-1-23 09:03:40 | 显示全部楼层
咦题主不是已经知道前两个文件系统前两个文件是空的,for s= 1,k还从1开始循环呀?不是应该从3开始嘛?

这样的问题好像大部分是文件打开有问题,可能没有打开那个文件,但是netcdf.open好像并不会报错,题主试试看直接ncdisp(filename),可能就可以发现文件打开有问题了,现在是直接用路迳的
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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