how to write attribute in netcdf file when creating it
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tanmoyee Bhattacharya
le 29 Août 2017
Commenté : GS Louw
le 11 Mar 2021
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 commentaires
Réponse acceptée
KSSV
le 29 Août 2017
doc ncwrite and ncwriteatt
4 commentaires
UTKARSH VERMA
le 8 Jan 2021
Modifié(e) : UTKARSH VERMA
le 8 Jan 2021
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
le 11 Mar 2021
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');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur NetCDF dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!