- 积分
- 1656
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-7-18
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
在matlab中读netCDF格式文件的一些函数
A.文件IO操作函数:
1.打开netCDF数据文件
ncid = netcdf.open(filename, mode) mode:'NC_WRITE','NC_SHARE','NC_NOWRITE'
2.还原最近的netCDF文件定义
netcdf.abort(ncid)
3.关闭netCDF文件
netcdf.close(ncid)
4.创建新netCDF数据文件
ncid = netcdf.create(filename, mode)
mode:
'NC_NOCLOBBER': Prevent overwriting of existing file with the same name.
'NC_SHARE': Allow synchronous file updates.
'NC_64BIT_OFFSET': Allow easier creation of files and variables which are larger than two gigabytes.
5.完成netCDF文件定义模式
netcdf.endDef(ncid)
netcdf.endDef(ncid,h_minfree,v_align,v_minfree,r_align)
6.返回已知netCDF库常数的列表
val = netcdf.getConstantNames
如:
nc_constants = netcdf.getConstantNames
nc_constants =
'NC2_ERR'
'NC_64BIT_OFFSET'
'NC_BYTE'
'NC_CHAR'
'NC_CLOBBER'
'NC_DOUBLE'
'NC_EBADDIM'
'NC_EBADID'
'NC_EBADNAME'
'NC_EBADTYPE'
...
7.返回数值的命名常数
val = netcdf.getConstant(param_name)
param_name为netcdf.getConstantNames中的string类型的值。
如:
>> netcdf.getConstant('NC_MAX_VARS')
ans =
8192
>> netcdf.getConstant('NC_SHORT')
ans =
3
8.返回有关netCDF文件的信息
[ndims,nvars,ngatts,unlimdimid] = netcdf.inq(ncid)
9.返回netCDF的库版本信息
libvers = netcdf.inqLibVers
10.把打开netCDF文件换成定义模式
netcdf.reDef(ncid)
注:打开的文件可以通过此函数进入重新定义状态
11.更改默认netCDF的文件格式
oldFormat = netcdf.setDefaultFormat(newFormat)
newFormat可以取:
'NC_FORMAT_CLASSIC':Original netCDF file format'NC_FORMAT_64BIT'
64-bit offset format; relaxes limitations on creating very large files
12.填充模式设置netCDF
old_mode = netcdf.setFill(ncid,new_mode)
13.Synchronize netCDF file to disk 同步netCDF文件
netcdf.sync(ncid)
*******************************************************************************************
B.操作:
1.Create Dimensions函数:
dimid = netcdf.defDim(ncid,dimname,dimlen)
2.用ID返回Dimensions的名和长度的函数:
[dimname, dimlen] = netcdf.inqDim(ncid,dimid)
3.用名字返回Dimensions的ID号:
dimid = netcdf.inqDimID(ncid,dimname)
4.重命名Dimensions:
netcdf.renameDim(ncid,dimid,newName)
*******************************************************************************************
C.Variables变量操作:
1.Create 变量函数:
varid = netcdf.defVar(ncid,varname,xtype,dimids)
2.从netdcf变量中返回数据,其函数形式有
data = netcdf.getVar(ncid,varid)
data = netcdf.getVar(ncid,varid,start)
data = netcdf.getVar(ncid,varid,start,count)
data = netcdf.getVar(ncid,varid,start,count,stride)
data = netcdf.getVar(...,output_type)
output_type可以取值:'int','double','int16','short','single','int8','float','int32','uint8'
3.取得变量的信息
[varname,xtype,dimids,natts] = netcdf.inqVar(ncid,varid)
4.从变量名知道变量的ID号
varid = netcdf.inqVarID(ncid,varname)
5.把数据写到netcdf的文件中
netcdf.putVar(ncid,varid,data)
netcdf.putVar(ncid,varid,start,data)
netcdf.putVar(ncid,varid,start,count,data)
netcdf.putVar(ncid,varid,start,count,stride,data)
6.重命名变量名
netcdf.renameVar(ncid,varid,newName)
*******************************************************************************************
D.Attributes操作:
1.把Attributes拷贝到新的位置
netcdf.copyAtt(ncid_in,varid_in,attname,ncid_out,varid_out)
2.删除一个Attributes:
netcdf.delAtt(ncid,varid,attName)
3.获得一个Attributes:
attrvalue = netcdf.getAtt(ncid,varid,attname)
attrvalue = netcdf.getAtt(ncid,varid,attname,output_datatype)
4.返回Attributes的信息(类型和长度)
[xtype,attlen] = netcdf.inqAtt(ncid,varid,attname)
5.返回Attributes的ID:
attnum = netcdf.inqAttID(ncid,varid,attname)
6.返回Attributes的名字
attname = netcdf.inqAttName(ncid,varid,attnum)
7.向netcdf文件中写入Attributes
netcdf.putAtt(ncid,varid,attrname,attrvalue)
8.重命名Attributes的名
netcdf.renameAtt(ncid,varid,oldName,newName)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
评分
-
查看全部评分
|