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