Difference between revisions of "NetCDF Data Processing Scripts"

From WikiROMS
Jump to navigationJump to search
Line 12: Line 12:
<section begin=nc_attadd.m />;<span id="nc_attadd"></span><span class="blue">nc_attadd.m</span>
<section begin=nc_attadd.m />;<span id="nc_attadd"></span><span class="blue">nc_attadd.m</span>
:Adds or modifies a global or variable attribute in a NetCDF file. If the <span class="green">Vname</span> argument is missing, it is assumed that <span class="green">Aname</span> is a global attribute. <br />
:Adds or modifies a global or variable attribute in a NetCDF file. If the <span class="green">Vname</span> argument is missing, it is assumed that <span class="green">Aname</span> is a global attribute. <br />
::<span class="green">status</span> = <span class="red">nc_attadd</span> &nbsp;(<span class="green">ncname</span>, <span class="green">Aname</span>, <span class="green">Avalue</span>, <span class="green">Vname</span>)
::<span class="green">status</span> = <span class="red">nc_attadd</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Aname</span>, <span class="green">Avalue</span>, <span class="green">Vname</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncname</span>: &nbsp;  NetCDF file name (string)
::<span class="green">ncfile</span>: &nbsp;  NetCDF file name (string)
::<span class="green">Aname</span>: &nbsp; Attribute name (string)
::<span class="green">Aname</span>: &nbsp; Attribute name (string)
::<span class="green">Avalue</span>: &nbsp; Attribute value (numeric or string)
::<span class="green">Avalue</span>: &nbsp; Attribute value (numeric or string)
::<span class="green">Vname</span>: &nbsp; Variable name (string; optional)
::<span class="green">Vname</span>: &nbsp; Variable name (string; optional)
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_attadd.m />
<section begin=nc_attdel.m />;<span id="nc_attdel"></span><span class="blue">nc_attdel.m</span>
:Deletes requested global or variable attribute in a NetCDF file. If the <span class="green">Vname</span> argument is missing, it is assumed that "<span class="green">Aname</span> is a global attribute. <br />
::<span class="green">status</span> = <span class="red">nc_attdel</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Aname</span>, <span class="green">Vname</span>)
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp;  NetCDF file name (string)
::<span class="green">Aname</span>: &nbsp; Attribute name (string)
::<span class="green">Vname</span>: &nbsp; Variable name (string; optional)
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_attdel.m />
<section begin=nc_check.m />;<span id="nc_check"></span><span class="blue">nc_check.m</span>
:Checks the information structure returned from calls to [[NetCDF_Data_Processing_Scripts#nc_inq|nc_inq]] or '''native''' <span class="green">ncinfo</span> for compliance and changes new variables types and attributes. For example, it updates the <span class="red">spherical</span> switch to integer and fix the land/sea masking attributes for compliance. Notice that this information structure is very convenient to create new NetCDF files having the dimensions and variable schema of and old NetCDF file. <br />
::<span class="green">I</span> = <span class="red">nc_check</span> &nbsp;(<span class="green">Info</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_attadd.m />
::<span class="green">Info</span>: &nbsp; NetCDF file information structure (struct array)
:'''On Ouput:'''
::<span class="green">I</span>: &nbsp;  Updated NetCDF file information structure (struct array)<section end=nc_check.m />
 
<section begin=nc_create.m />;<span id="nc_create"></span><span class="blue">nc_create.m</span>
:creates a new NetCDF file according to the file creation <span class="green">mode</span>. If a structure <span class="green">S</span> is provided, it defines the dimensions, global attributes, variables and attributes stored in the structure.  This structure can be created using:
::    <span class="red">S = nc_inq('roms_his.nc')</span>
: or
::    <span class="red">S = ncinfo('roms_his.nc')</span> &nbsp; &nbsp;    '''native''' Matlab function
:If the user wants different dimension values to those returned by the [[NetCDF_Data_Processing_Scripts#nc_inq|nc_inq]] or <span class="blue">ncinfo</span>, see <span class="red">S.Dimensions(:).Length</span>, make sure that such values are overwritten before calling this function. Therefore, it is possible to replicate the schema of a particular NetCDF file with identical or different dimensions. This facilitates the extraction of smaller sub-domain data from a large (coarser) dataset. This function does not write the variable data. It just creates the NetCDF file. <br />
::<span class="green">ncid</span> = <span class="red">nc_check</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">mode</span>, <span class="green">S</span>)
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp; NetCDF file name to create (string)
::<span class="green">mode</span>: NetCDF file creation mode (string):
:::<span class="red">'clobber'</span>, &nbsp; overwrite existing files
:::<span class="red">'noclobber'</span>, &nbsp; do not overwrite existing files
:::<span class="red">'shared'</span>, &nbsp; allow for synchronous file updates
:::<span class="red">'64bit_offset'</span>, &nbsp; allow the creation of 64-bit files instead of the classic format
:::<span class="red">'netcdf4'</span>, &nbsp; creates a netCDF-4/HDF5 file
:::<span class="red">'classic_model'</span>, &nbsp; enforce classic model, has no effect unless used in a bitwise-or with <span class="red">'netcdf4'</span>
::<span class="green">S</span>: &nbsp; NetCDF file Schema Structure (struct array)
:'''On Ouput:'''
::<span class="green">I</span>: &nbsp;  NetCDF file ID. If not function output arguments, the file is closed after created.<section end=nc_create.m />

Revision as of 21:38, 23 April 2012

Matlab: NetCDF Data Processing Scripts

This page describes several Matlab scripts used to process NetCDF data. These scripts are located in the matlab/netcdf sub-directory in the repository. They are high level scripts on top of lower level functions that use the native interface if using Matlab Version 2008b or newer for local NetCDF files and Matlab Version 2012a or newer for OpenDAP files. Otherwise for older Matlab versions, the MEXNC interface are used for local files whereas the SNCTOOLS java interface is used for OpenDAP files. Notice that processing of OpenDAP files is only possible for reading.



nc_attadd.m
Adds or modifies a global or variable attribute in a NetCDF file. If the Vname argument is missing, it is assumed that Aname is a global attribute.
status = nc_attadd  (ncfile, Aname, Avalue, Vname)
On Input:
ncfile:   NetCDF file name (string)
Aname:   Attribute name (string)
Avalue:   Attribute value (numeric or string)
Vname:   Variable name (string; optional)
On Output:
status:   Error flag
nc_attdel.m
Deletes requested global or variable attribute in a NetCDF file. If the Vname argument is missing, it is assumed that "Aname is a global attribute.
status = nc_attdel  (ncfile, Aname, Vname)
On Input:
ncfile:   NetCDF file name (string)
Aname:   Attribute name (string)
Vname:   Variable name (string; optional)
On Output:
status:   Error flag
nc_check.m
Checks the information structure returned from calls to nc_inq or native ncinfo for compliance and changes new variables types and attributes. For example, it updates the spherical switch to integer and fix the land/sea masking attributes for compliance. Notice that this information structure is very convenient to create new NetCDF files having the dimensions and variable schema of and old NetCDF file.
I = nc_check  (Info)
On Input:
Info:   NetCDF file information structure (struct array)
On Ouput:
I:   Updated NetCDF file information structure (struct array)
nc_create.m
creates a new NetCDF file according to the file creation mode. If a structure S is provided, it defines the dimensions, global attributes, variables and attributes stored in the structure. This structure can be created using:
S = nc_inq('roms_his.nc')
or
S = ncinfo('roms_his.nc')     native Matlab function
If the user wants different dimension values to those returned by the nc_inq or ncinfo, see S.Dimensions(:).Length, make sure that such values are overwritten before calling this function. Therefore, it is possible to replicate the schema of a particular NetCDF file with identical or different dimensions. This facilitates the extraction of smaller sub-domain data from a large (coarser) dataset. This function does not write the variable data. It just creates the NetCDF file.
ncid = nc_check  (ncfile, mode, S)
On Input:
ncfile:   NetCDF file name to create (string)
mode: NetCDF file creation mode (string):
'clobber',   overwrite existing files
'noclobber',   do not overwrite existing files
'shared',   allow for synchronous file updates
'64bit_offset',   allow the creation of 64-bit files instead of the classic format
'netcdf4',   creates a netCDF-4/HDF5 file
'classic_model',   enforce classic model, has no effect unless used in a bitwise-or with 'netcdf4'
S:   NetCDF file Schema Structure (struct array)
On Ouput:
I:   NetCDF file ID. If not function output arguments, the file is closed after created.