how to write attribute in netcdf file when creating it
조회 수: 27 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
KSSV
2017년 8월 29일
doc ncwrite and ncwriteatt
댓글 수: 4
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
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 Exchange에서 NetCDF에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!