netcdf.copyAtt
将属性复制到新位置
语法
netcdf.copyAtt(ncid_in,varid_in,attname,ncid_out,varid_out)
说明
netcdf.copyAtt(ncid_in,varid_in,attname,ncid_out,varid_out)
将某属性从一个变量复制到另一个变量,可能涉及跨文件操作。ncid_in
和 ncid_out
是 netcdf.create
或 netcdf.open
返回的 netCDF 文件标识符。varid_in
标识您要从中复制属性的变量。varid_out
标识您要将属性复制到其中的变量。
此函数对应于 netCDF 库 C API 中的 nc_copy_att
函数。要使用此函数,应该熟悉 netCDF 编程范式。
示例
本例将 netCDF 示例文件 example.nc
中第一个变量的关联属性复制到一个新文件中。要运行本例,必须对当前目录拥有写入权限。
% Open example file. ncid = netcdf.open('example.nc','NC_NOWRITE'); % Get identifier for a variable in the file. varid = netcdf.inqVarID(ncid,'avagadros_number'); % Create new netCDF file. ncid2 = netcdf.create('foo.nc','NC_NOCLOBBER'); % Define a dimension in the new file. dimid2 = netcdf.defDim(ncid2,'x',50); % Define a variable in the new file. varid2 = netcdf.defVar(ncid2,'myvar','double',dimid2); % Copy the attribute named 'description' into the new file, % associating the attribute with the new variable. netcdf.copyAtt(ncid,varid,'description',ncid2,varid2); % % Check the name of the attribute in new file. attname = netcdf.inqAttName(ncid2,varid2,0) attname = description