Difference between revisions of "NetCDF Data Processing Scripts"

From WikiROMS
Jump to navigationJump to search
Line 20: Line 20:
:'''On Output:'''
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_attadd.m />
::<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>
<section begin=nc_attdel.m />;<span id="nc_attdel"></span><span class="blue">nc_attdel.m</span>
Line 30: Line 31:
:'''On Output:'''
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_attdel.m />
::<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>
<section begin=nc_check.m />;<span id="nc_check"></span><span class="blue">nc_check.m</span>
Line 38: Line 40:
:'''On Ouput:'''
:'''On Ouput:'''
::<span class="green">I</span>: &nbsp;  Updated NetCDF file information structure (struct array)<section end=nc_check.m />
::<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>
<section begin=nc_create.m />;<span id="nc_create"></span><span class="blue">nc_create.m</span>
Line 53: Line 56:
:::<span class="red">'shared'</span>, &nbsp; allow for synchronous file updates
:::<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">'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">'netcdf4'</span>, &nbsp; creates a netCDF-4/HDF-5 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="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)
::<span class="green">S</span>: &nbsp; NetCDF file Schema Structure (struct array)
:'''On Ouput:'''
:'''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 />
::<span class="green">ncid</span>: &nbsp;  NetCDF file ID. If not function output arguments, the file is closed after created.<section end=nc_create.m />
 
 
<section begin=nc_dinfo.m />;<span id="nc_dinfo"></span><span class="blue">nc_dinfo.m</span>
:Gets all the dimensions information about requested NetCDF file. <br />
::<span class="green">D</span> = <span class="red">nc_check</span> &nbsp;(<span class="green">ncfile</span>)
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp; NetCDF file name or URL file name (string)
:'''On Ouput:'''
::<span class="green">D</span>: &nbsp;  Dimensions information (Struct array):
:::<span class="green">D(:).Name    </span>: &nbsp; dimension name (string)
:::<span class="green">D(:).Length  </span>: &nbsp; dimension lentgh (double)
:::<span class="green">D(:).Unlimited</span>: &nbsp; unlimited dimension (logical)
:::<span class="green">D(:).dimid    </span>: &nbsp; NetCDF dimension id (double)<section end=nc_dinfo.m />

Revision as of 21:47, 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/HDF-5 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:
ncid:   NetCDF file ID. If not function output arguments, the file is closed after created.


nc_dinfo.m
Gets all the dimensions information about requested NetCDF file.
D = nc_check  (ncfile)
On Input:
ncfile:   NetCDF file name or URL file name (string)
On Ouput:
D:   Dimensions information (Struct array):
D(:).Name :   dimension name (string)
D(:).Length :   dimension lentgh (double)
D(:).Unlimited:   unlimited dimension (logical)
D(:).dimid :   NetCDF dimension id (double)