how to write attribute in netcdf file when creating it

31 ビュー (過去 30 日間)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2017 年 8 月 29 日
コメント済み: GS Louw 2021 年 3 月 11 日
I have extracted information from one netcdf file and writting it to another netcdf file.I have created the netcdf file by
ncdisp('H:\era\ERA_Q.nc');
lev=ncread('H:\era\ERA_Q.nc','level');
lev1=lev*100;
lat=ncread('H:\era\ERA_Q.nc','latitude');
lon=ncread('H:\era\ERA_Q.nc','longitude');
q=ncread('H:\era\ERA_Q.nc','q');
Q1=single(q);
nccreate('test_files.nc','lat','Dimensions',{'lat' 3});
nccreate('test_files.nc','lon','Dimensions',{'lon' 4});
nccreate('test_files.nc','time','Dimensions',{'time' 9862});
nccreate('test_files.nc','lev','Dimensions',{'lev' 4});
nccreate('test_files.nc','q','datatype','single','Dimensions',{'lon' 4 'lat' 3 'lev' 4 'time' 9862});
% ncdisp('test_files.nc');
ncwrite('test_files.nc','lat',31.5000:.5:32.5000);
ncwrite('test_files.nc','lon',76.5000:.5:78);
ncwrite('test_files.nc','q',Q1);
ncdisp('test_files.nc');
I have to add attributes like
time
Size: 18262x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time variable'
units = 'days since 1950-01-01 00:00:00'
_CoordinateAxisType = 'Time'
lat
Size: 6x1
Dimensions: rlat
Datatype: double
Attributes:
standard_name = 'latitude'
long_name = 'latitude'
units = 'degrees north'
_CoordinateAxisType = 'Lat'
lon
Size: 9x1
Dimensions: rlon
Datatype: double
Attributes:
standard_name = 'longitude'
long_name = 'longitude'
units = 'degrees east'
_CoordinateAxisType = 'Lon'
lev
Size: 4x1
Dimensions: lev
Datatype: double
Attributes:
standard_name = 'pressure'
long_name = 'pressure'
units = 'Pa'
_CoordinateAxisType = 'Z'
Q
Size: 6x9x4x18262
Dimensions: rlat,rlon,lev,time
Datatype: single
Attributes:
standard_name = 'specific humidity'
long_name = 'Specific humidity'
units = 'kg kg**-1'
missing_value = -1e+04
How can I do it?

採用された回答

KSSV
KSSV 2017 年 8 月 29 日
  4 件のコメント
UTKARSH VERMA
UTKARSH VERMA 2021 年 1 月 8 日
編集済み: UTKARSH VERMA 2021 年 1 月 8 日
Please guide me how to write global attributes to the same file?
Also, I want to know how to create nc file in Matlab so that it can be read by grads without using descriptor file.
GS Louw
GS Louw 2021 年 3 月 11 日
When using the function ncwriteatt(filename,location,attname,attvalue)For global attributes you use '/' at location, so an example would look like the below:
ncwriteatt('test_files.nc', '/', 'geospatial_lat_units','degrees_north');

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by