nccreatewrite

Creates the NetCDF file directly, and these NetCDF files are readbale in GrADS. Get rid of writing the long commands everytime to create
264 Downloads
Updated Mon, 12 Jul 2021 19:33:54 +0000

View License

Function:
One can create a NetCDF file with the predefined MATLAB
function using nccreate and ncwrite. This function is a
combination of these two predefined functions. One can use this
to save the time and get rid of writing the same commands for
storing multi variables in a nc file.
Syntax:
nccreatewrite('sample_file.nc','variable',{'lon','lat','lev'},randi(20,20,30,5))
Inputs:
First input should be the name of the nc file in which you want
to store the data.
Second input should be the name of the variable in which you
want to store the specific variable.
Third argument should be in braces (not structure) which must
contains the number of variables as that of the size of the
data you want to store.
ex: If you want to store 'lat' whose dimensions is 5*1, then
third argument should be {'lat'}
The above is becasue of MATLAB also stores the variable
dimensions seprately, not in the variable list.
You can see this when you use ncdisp to see the listed
variables in nc file.
Fourth argument should be the data you want to write in nc
file.
Fifth argument is an optional argument, and if provided, it should
be the attributes of the variable.
Example:
random_data = normrnd(3,10,[20,30,5])+273;
filename='sample.nc';
delete(filename)
lon_att.standard_name='longitude';
lon_att.long_name='longitude';
lon_att.units='degrees_east';
lon_att.axis='X';
nccreatewrite(filename,'lon',{'lon'},[65:84],lon_att)
lat_att.standard_name='latitude';
lat_att.long_name='latitude';
lat_att.units='degrees_north';
lat_att.axis='Y';
nccreatewrite(filename,'lat',{'lat'},[1:30],lat_att)
lev_att.long_name='generic';
lev_att.units='level';
lev_att.axis='Z';
nccreatewrite(filename,'lev',{'lev'},[1:5],lev_att)
nccreatewrite(filename,'TC',{'lon','lat','lev'},random_data)
ncdisp(filename)
Please send your suggestions to the email id: ankurk017@gmail.com or
ankur.kumar@nsstc.uah.edu

Cite As

ANKUR KUMAR (2024). nccreatewrite (https://www.mathworks.com/matlabcentral/fileexchange/65636-nccreatewrite), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on MATLAB Compiler SDK in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
2.0.0.1

Readable in GrDAS.

2.0

Updaetd the codes to that the output files are readable in GrADS.

1.0.0.0