Difference between revisions of "NetCDF Data Processing Scripts"

From WikiROMS
Jump to navigationJump to search
Line 74: Line 74:
:::<span class="green">D(:).Unlimited</span>: &nbsp; unlimited dimension (logical)
:::<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 />
:::<span class="green">D(:).dimid    </span>: &nbsp; NetCDF dimension id (double)<section end=nc_dinfo.m />
<section begin=nc_drename.m />;<span id="nc_drename"></span><span class="blue">nc_drename.m</span>
:Renames requested dimension in a NetCDF file. <br />
::<span class="green">status</span> = <span class="red">nc_drename</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Dname_old</span>, <span class="green">Dname_new</span>)
:'''On Input:'''
::<span class="green">ncfile  </span>: &nbsp;  NetCDF file name (string)
::<span class="green">Dname_old</span>: &nbsp;  Old dimension name (string)
::<span class="green">Dname_new</span>: &nbsp;  New dimension name (string)
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_drename.m />
<section begin=nc_drename.m />;<span id="nc_drename"></span><span class="blue">nc_drename.m</span>
:Reads global or variable attributes from input 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. If both <span class="green">Aname</span> and <span class="green">Vname</span> arguments are missing, it returns all global attributes. <br />
::<span class="green">A</span> = <span class="red">nc_getatt</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 or URL file name (string)
::<span class="green">Aname </span>: &nbsp;  Attribute name (string; optional)
::<span class="green">Vname </span>: &nbsp;  Variable name  (string; optional)
:'''On Output:'''
::<span class="green">A</span>: &nbsp;  Attribute value (numeric, string, or struct array)
:'''Usage:'''
::<span class="mediumOrchid">A = nc_getatt ('ocean_his.nc')</span>
:will return a structure array with all the global attributes names and values: <span class="mediumOrchid">A.Name(:)</span>, <span class="mediumOrchid">A.Value(:)</span>
::<span class="mediumOrchid">A = nc_getatt ('ocean_his.nc', 'history')</span>
:will return a string with the value of the global <span class="mediumOrchid">'history'</span> attribute
::<span class="mediumOrchid">A = nc_getatt ('ocean_his.nc', [ ], 'temp')</span>
:will return a structure array with all the <span class="mediumOrchid">'temp'</span> variable attributes names and values: <span class="mediumOrchid">A.Name(:)</span>, <span class="mediumOrchid">A.Value(:)</span>
::<span class="mediumOrchid">A = nc_getatt ('ocean_his.nc', 'FillValue', 'temp')</span>
:will return a numeric value for the attribute <span class="mediumOrchid">'FillValue'</span> in variable <span class="mediumOrchid">'temp'</span><section end=nc_getatt.m />
<section begin=nc_inq.m />;<span id="nc_inq"></span><span class="blue">nc_inq.m</span>
:Inquires about the contents of a NetCDF file: dimensions, global attributes, and variables. <br />
::<span class="green">I</span> = <span class="red">nc_inq</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Lprint</span>)
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp;  NetCDF file name or URL file name (string)
::<span class="green">Lprint</span>: &nbsp;  Switch to print information (optional; default false)
:'''On Output:'''
::  <span class="green">I</span>: &nbsp;  NetCDF information (struct array):
::: <span class="green">I.Filename</span>, &nbsp;    NetCDF file name (string)
::: <span class="green">I.Attributes</span>, &nbsp;  NetCDF global attributes (struct array):
::::<span class="green">I.Attributes(:).Name</span>
::::<span class="green">I.Attributes(:).Value</span>
::: <span class="green">I.Dimensions</span>, &nbsp;  NetCDF file dimensions (struct array):
::::<span class="green">I.Dimensions(:).Name</span>
::::<span class="green">I.Dimensions(:).Length</span>
::::<span class="green">I.Dimensions(:).Unlimited</span>
:
::: <span class="green">I.Variables(:).Dimensions</span>, &nbsp; variable dimensions (struct array):
::::<span class="green">I.Variables(:).Dimensions(:).Name</span>
::::<span class="green">I.Variables(:).Dimensions(:).Length</span>
::::<span class="green">I.Variables(:).Dimensions(:).Unlimited</span>
:
::: <span class="green">I.Variables(:).Size</span>, &nbsp; variable size (double array)
:
::: <span class="green">I.Variables(:).Attributes</span>, &nbsp; variable attributes (struct array):
::::<span class="green">I.Variables(:).Attributes(:).Name</span>
::::<span class="green">I.Variables(:).Attributes(:).Value</span>
:
::: <span class="green">I.Variables(:).Cgridtype</span>, &nbsp; stagged C-grid type (struct array):
::::<span class="green">I.Variables(:).Cgridtype.Name</span>
::::<span class="green">I.Variables(:).Cgridtype.Value</span>
:
::: <span class="green">I.Variables(:).Datatype</span>, &nbsp; original variable data type (string)
:
::: <span class="green">I.Variables(:).ncType</span>, &nbsp; NetCDF data type (numeric)<section end=nc_inq.m />
<section begin=nc_interface.m />;<span id="nc_interface"></span><span class="blue">nc_interface.m</span>
: Determines the interface to use when processing NetCDF file. The strategy is to use always the 'native' method when possible. It was introduced in Matlab version '''2008b''' for '''NetCDF-3''' type files. The '''NetCDF-4''' support was introduced in version '''2010b'''. The support for '''HDF5''' files was completed in version '2011a'. The '''OpenDAP''' support started in version '2012a'. The '''MEXNC''' and '''SNCTOOLS''' interfaces are becoming obsolete.  The '''MEXNC''' is the oldest interface. It is no longer developed and only has support for '''NetCDF-3''' and''' NetCDF-4''' classic files. It does not have Java support for '''OpenDAP''' files.  The '''SNCTOOLS''' have support for '''NetCDF-3''', '''NetCDF-4''', '''HDF5''', and a Java interface for '''OpenDAP''' files. <br />
::[<span class="green">method</span>, <span class="green">url</span>, <span class="green">ftype</span>] = <span class="red">nc_interface</span> &nbsp;(<span class="green">ncfile</span>)
:'''On Input:'''
::<span class="green">ncfile  </span>: &nbsp;  NetCDF file name or URL name (string)
:'''On Output:'''
:: <span class="green">method  </span>: &nbsp; NetCDF interface for Matlab (string):
:::<span class="red">'native'  </span>, &nbsp; '''Native''' Matlab interface
:::<span class="red">'mexnc'  </span>, &nbsp; '''MEXNC''' interface
:::<span class="red">'java'    </span>, &nbsp; '''SNCTOOLS''' Java interface
:: <span class="green">url    </span>: &nbsp; Switch indicating an OpenDAP file (logical)
:: <span class="green">ftype  </span>: &nbsp; File type (string)
:::<span class="red">'NetCDF'  </span>, &nbsp; Classic '''NetCDF-3''' file
:::<span class="red">'NetCDF4' </span>, &nbsp; '''NetCDF-4'''/'''HDF5''' file
:::<span class="red">'OpenDAP' </span>, &nbsp; '''OpenDAP''' file <section end=nc_interface.m />
<section begin=nc_read.m />;<span id="nc_read"></span><span class="blue">nc_read.m</span>
:Reads in a generic variable from a NetCDF file.  If only the water points are available, this function fill the land areas with zero and returns the full field. <br />
::<span class="green">f</span> = <span class="red">nc_read</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname</span>, <span class="green">Tindex</span>, <span class="green">ReplaceValue</span>, <span class="green">PreserveType</span>)
:'''On Input:'''
::<span class="green">ncfile      </span>: &nbsp;  NetCDF file name or URL name (string)
::<span class="green">Vname      </span>: &nbsp;  NetCDF variable name to read (string)
::<span class="green">Tindex      </span>: &nbsp;  Time record index to read (scalar). If <span class="green">Tindex</span> is provided, only the requested time record is processed when the variable has unlimited dimension or the word <span class="red">time</span> in any of its dimension names. Otherwise, provide an empty [ ] argument.
::<span class="green">ReplaceValue</span>: &nbsp;  Value to use when <span class="red">_FillValue</span> or <span class="red">missing_value</span> attribute is found in variable. If not provided, a zero value will used. In some instances, like plotting, it is advantageous to use '''NaN''' to visualize better the land masking or the missing data.
::<span class="green">PreserveType</span>: &nbsp;  Switch to preserve numerical data type (logical). If false, convert numerical data to double precision. It has not effect data is already in double precision.
:'''On Output:'''
::<span class="green">f</span>: &nbsp;  Field (scalar or array) <section end=nc_read.m />
<section begin=nc_slice.m />;<span id="nc_slice"></span><span class="blue">nc_slice.m</span>
:Computes a horizontal variable slice from a NetCDF file generated by ROMS.  It should only be used when the grid has variable bathymetry.  The field slice is interpolated at the requested depth from the input terrain-following coordinate data.<br />
::[<span class="green">x</span>,  <span class="green">y</span>, <span class="green">f</span>] = <span class="red">nc_slice</span> &nbsp;(<span class="green">Gfile</span>, <span class="green">Hfile</span>, <span class="green">Vname</span>, <span class="green">depth</span>, <span class="green">Tindex</span>, <span class="green">zflag</span>)
:'''On Input:'''
::<span class="green">Gfile </span>: &nbsp;  ROMS Grid NetCDF file name (string). If no grid file, use field file name instead.
::<span class="green">Hfile </span>: &nbsp;  Field history NetCDF file name (string)
::<span class="green">Vname </span>: &nbsp;  NetCDF variable name to process (string)
::<span class="green">depth </span>: &nbsp;  Slice depth (scalar; meters, negative)
::<span class="green">Tindex</span>: &nbsp;  Time index to read (integer). If <span class="green">tindex = 0</span>, all time records are processed. Otherwise if <span class="green">tindex > 0</span>, only the specified record is processed.
::<span class="green">zflag </span>: &nbsp;  Variable depths computation switch (scalar). If <span class="green">zflag = 0</span>, use zero free-surface. Otherwise if <span class="green">zflag = 1</span>, use <span class="green">Tindex</span> record free-surface.
:'''On Output:'''
::<span class="green">x</span>: &nbsp;  Slice X-positions (2D array)
::<span class="green">y</span>: &nbsp;  Slice Y-positions (2D array)
::<span class="green">f</span>: &nbsp;  Field slice (array) <section end=nc_slice.m />
<section begin=nc_test.m />;<span id="nc_test"></span><span class="blue">nc_test.m</span>
:Creates a NetCDF using data from the <span class="blue">peaks(40)</span> function. Several data type variables are created from the original double precision data and packed a byte ('''int8'''), short ('''int16'''), integer ('''int32'''), and single precision.  It is used to test the writing and reading  of NetCDF data in Matlab using the various interfaces. It computes and reports the processing and truncation RMSE.<br />
::<span class="red">nc_test</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Interface</span>, <span class="green">Lplot</span>)
:'''On Input:'''
::<span class="green">ncfile  </span>: &nbsp;  NetCDF file name to create (string)
::<span class="green">Dname_old</span>: &nbsp;  NetCDF interface for Matlab (string):
:::<span class="red">'native'  </span>, &nbsp;  '''Native''' Matlab interface
:::<span class="red">'mexnc'  </span>, &nbsp;  '''MEXNC''' interface
:::<span class="red">'roms'    </span>, &nbsp;  '''ROMS''' [[NetCDF_Data_Processing_Scripts#nc_write|nc_write.m]] and [[NetCDF_Data_Processing_Scripts#nc_read|nc_read.m]] functions     
:::<span class="red">'snctools'</span>, &nbsp;  '''SNCTOOLS''' inteface
::<span class="green">Lplot    </span>: &nbsp;  Switch to plot the data (Optional, default false) <section end=nc_test.m />
<section begin=nc_vdef.m />;<span id="nc_vdef"></span><span class="blue">nc_vdef.m</span>
:Defines a variable in a NetCDF file. <br />
::[<span class="green">varid</span>, <span class="green">status</span>] = <span class="red">nc_vdef</span> &nbsp;(<span class="green">ncid</span>, <span class="green">Var</span>)
:'''On Input:'''
::<span class="green">ncid    </span>: &nbsp; NetCDF file ID (scalar)
:: <span class="green">Var    </span>: &nbsp; NetCDF interface for Matlab (string):
:::<span class="red">Var.name </span>, &nbsp; variable name (string)
:::<span class="red">Var.type </span>, &nbsp; external data type (string or numeric)
:::<span class="red">Var.dimid</span>, &nbsp; dimension IDs (numeric). If not present or empty [ ], the variable is a scalar
:::<span class="red">Var.field</span>, &nbsp; any other <span class="red">field</span> in the structure, if any, is processed as variable attribute. The values of the attribute can be numeric (scalar or vector) or strings (character array or cell array). For example,
::::<span class="red">Var.long_name</span> = 'temp',  &nbsp; 'long_name' attribute (string)
::::<span class="red">Var.FillValue</span> = 1.0E+37, &nbsp; '_FillValue' attribute (numeric)
:'''On Output:'''
:: <span class="green">varid    </span>: &nbsp; Variable ID (scalar)
:: <span class="green">status  </span>: &nbsp; Error flag <section end=nc_vdef.m />
<section begin=nc_vinfo.m />;<span id="nc_vinfo"></span><span class="blue">nc_vinfo.m</span>
:Gets information about requested NetCDF variable. <br />
::<span class="green">V</span> = <span class="red">nc_vinfo</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname</span>)
:'''On Input:'''
::<span class="green">ncfile  </span>: &nbsp; NetCDF file name or URL name (string)
::<span class="green">Dname_old</span>: &nbsp; Variable name (string)
:'''On Output:'''
::<span class="green">V</span>: &nbsp;  Requested variable information (struct array):
:::<span class="green">V.Filename</span>, &nbsp;  NetCDF file name (string)
:
::: <span class="green">V.Dimensions</span>, &nbsp; variable dimensions (struct array):
::::<span class="green">V.Dimensions(:).Name</span>
::::<span class="green">V.Dimensions(:).Length</span>
::::<span class="green">V.Dimensions(:).Unlimited</span>
:
::: <span class="green">V.Size</span>, &nbsp; variable size (double array)
:
::: <span class="green">V.Attributes</span>, &nbsp; variable attributes (struct array):
::::<span class="green">V.Attributes(:).Name</span>
::::<span class="green">V.Attributes(:).Value</span>
:
::: <span class="green">V.Cgridtype</span>, &nbsp; stagged C-grid type (struct array):
::::<span class="green">V.Cgridtype.Name</span>
::::<span class="green">V.Cgridtype.Value</span>
:
::: <span class="green">V.Datatype</span>, &nbsp; original variable data type (string)
:
::: <span class="green">V.ncType</span>, &nbsp; NetCDF data type (numeric)<section end=nc_vinfo.m />
<section begin=nc_vnames.m />;<span id="nc_vnames"></span><span class="blue">nc_vnames.m</span>
: gets the names and informaton of all variables available in a NetCDF file<br />
::<span class="green">S</span> = <span class="red">nc_vnames</span> &nbsp;(<span class="green">ncfile</span>)
:'''On Input:'''
::<span class="green">ncfile  </span>: &nbsp; NetCDF file name or URL name (string)
:'''On Output:'''
::<span class="green">S</span>: &nbsp;  NetCDF file variables information (struct array):
:::<span class="green">S.Filename</span>, &nbsp;  NetCDF file name (string)
:
::: <span class="green">S.Variables(:).Dimensions</span>, &nbsp; variable dimensions (struct array):
::::<span class="green">S.Variables(:).Dimensions(:).Name</span>
::::<span class="green">S.Variables(:).Dimensions(:).Length</span>
::::<span class="green">S.Variables(:).Dimensions(:).Unlimited</span>
:
::: <span class="green">S.Variables(:).Size</span>, &nbsp; variable size (double array)
:
::: <span class="green">S.Variables(:).Attributes</span>, &nbsp; variable attributes (struct array):
::::<span class="green">S.Variables(:).Attributes(:).Name</span>
::::<span class="green">S.Variables(:).Attributes(:).Value</span>
:
::: <span class="green">S.Variables(:).Cgridtype</span>, &nbsp; stagged C-grid type (struct array):
::::<span class="green">S.Variables(:).Cgridtype.Name</span>
::::<span class="green">S.Variables(:).Cgridtype.Value</span>
:
::: <span class="green">S.Variables(:).Datatype</span>, &nbsp; original variable data type (string)
:
::: <span class="green">S.Variables(:).ncType</span>, &nbsp; NetCDF data type (numeric)<section end=nc_vnames.m />

Revision as of 03:37, 24 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)


nc_drename.m
Renames requested dimension in a NetCDF file.
status = nc_drename  (ncfile, Dname_old, Dname_new)
On Input:
ncfile :   NetCDF file name (string)
Dname_old:   Old dimension name (string)
Dname_new:   New dimension name (string)
On Output:
status:   Error flag


nc_drename.m
Reads global or variable attributes from input NetCDF file. If the Vname argument is missing, it is assumed that Aname is a global attribute. If both Aname and Vname arguments are missing, it returns all global attributes.
A = nc_getatt  (ncfile, Aname, Vname)
On Input:
ncfile:   NetCDF file name or URL file name (string)
Aname :   Attribute name (string; optional)
Vname :   Variable name (string; optional)
On Output:
A:   Attribute value (numeric, string, or struct array)
Usage:
A = nc_getatt ('ocean_his.nc')
will return a structure array with all the global attributes names and values: A.Name(:), A.Value(:)
A = nc_getatt ('ocean_his.nc', 'history')
will return a string with the value of the global 'history' attribute
A = nc_getatt ('ocean_his.nc', [ ], 'temp')
will return a structure array with all the 'temp' variable attributes names and values: A.Name(:), A.Value(:)
A = nc_getatt ('ocean_his.nc', 'FillValue', 'temp')
will return a numeric value for the attribute 'FillValue' in variable 'temp'
nc_inq.m
Inquires about the contents of a NetCDF file: dimensions, global attributes, and variables.
I = nc_inq  (ncfile, Lprint)
On Input:
ncfile:   NetCDF file name or URL file name (string)
Lprint:   Switch to print information (optional; default false)
On Output:
I:   NetCDF information (struct array):
I.Filename,   NetCDF file name (string)
I.Attributes,   NetCDF global attributes (struct array):
I.Attributes(:).Name
I.Attributes(:).Value
I.Dimensions,   NetCDF file dimensions (struct array):
I.Dimensions(:).Name
I.Dimensions(:).Length
I.Dimensions(:).Unlimited
I.Variables(:).Dimensions,   variable dimensions (struct array):
I.Variables(:).Dimensions(:).Name
I.Variables(:).Dimensions(:).Length
I.Variables(:).Dimensions(:).Unlimited
I.Variables(:).Size,   variable size (double array)
I.Variables(:).Attributes,   variable attributes (struct array):
I.Variables(:).Attributes(:).Name
I.Variables(:).Attributes(:).Value
I.Variables(:).Cgridtype,   stagged C-grid type (struct array):
I.Variables(:).Cgridtype.Name
I.Variables(:).Cgridtype.Value
I.Variables(:).Datatype,   original variable data type (string)
I.Variables(:).ncType,   NetCDF data type (numeric)


nc_interface.m
Determines the interface to use when processing NetCDF file. The strategy is to use always the 'native' method when possible. It was introduced in Matlab version 2008b for NetCDF-3 type files. The NetCDF-4 support was introduced in version 2010b. The support for HDF5 files was completed in version '2011a'. The OpenDAP support started in version '2012a'. The MEXNC and SNCTOOLS interfaces are becoming obsolete. The MEXNC is the oldest interface. It is no longer developed and only has support for NetCDF-3 and NetCDF-4 classic files. It does not have Java support for OpenDAP files. The SNCTOOLS have support for NetCDF-3, NetCDF-4, HDF5, and a Java interface for OpenDAP files.
[method, url, ftype] = nc_interface  (ncfile)
On Input:
ncfile :   NetCDF file name or URL name (string)
On Output:
method :   NetCDF interface for Matlab (string):
'native' ,   Native Matlab interface
'mexnc' ,   MEXNC interface
'java' ,   SNCTOOLS Java interface
url :   Switch indicating an OpenDAP file (logical)
ftype :   File type (string)
'NetCDF' ,   Classic NetCDF-3 file
'NetCDF4' ,   NetCDF-4/HDF5 file
'OpenDAP' ,   OpenDAP file


nc_read.m
Reads in a generic variable from a NetCDF file. If only the water points are available, this function fill the land areas with zero and returns the full field.
f = nc_read  (ncfile, Vname, Tindex, ReplaceValue, PreserveType)
On Input:
ncfile :   NetCDF file name or URL name (string)
Vname :   NetCDF variable name to read (string)
Tindex :   Time record index to read (scalar). If Tindex is provided, only the requested time record is processed when the variable has unlimited dimension or the word time in any of its dimension names. Otherwise, provide an empty [ ] argument.
ReplaceValue:   Value to use when _FillValue or missing_value attribute is found in variable. If not provided, a zero value will used. In some instances, like plotting, it is advantageous to use NaN to visualize better the land masking or the missing data.
PreserveType:   Switch to preserve numerical data type (logical). If false, convert numerical data to double precision. It has not effect data is already in double precision.
On Output:
f:   Field (scalar or array)


nc_slice.m
Computes a horizontal variable slice from a NetCDF file generated by ROMS. It should only be used when the grid has variable bathymetry. The field slice is interpolated at the requested depth from the input terrain-following coordinate data.
[x, y, f] = nc_slice  (Gfile, Hfile, Vname, depth, Tindex, zflag)
On Input:
Gfile :   ROMS Grid NetCDF file name (string). If no grid file, use field file name instead.
Hfile :   Field history NetCDF file name (string)
Vname :   NetCDF variable name to process (string)
depth :   Slice depth (scalar; meters, negative)
Tindex:   Time index to read (integer). If tindex = 0, all time records are processed. Otherwise if tindex > 0, only the specified record is processed.
zflag :   Variable depths computation switch (scalar). If zflag = 0, use zero free-surface. Otherwise if zflag = 1, use Tindex record free-surface.
On Output:
x:   Slice X-positions (2D array)
y:   Slice Y-positions (2D array)
f:   Field slice (array)


nc_test.m
Creates a NetCDF using data from the peaks(40) function. Several data type variables are created from the original double precision data and packed a byte (int8), short (int16), integer (int32), and single precision. It is used to test the writing and reading of NetCDF data in Matlab using the various interfaces. It computes and reports the processing and truncation RMSE.
nc_test  (ncfile, Interface, Lplot)
On Input:
ncfile :   NetCDF file name to create (string)
Dname_old:   NetCDF interface for Matlab (string):
'native' ,   Native Matlab interface
'mexnc' ,   MEXNC interface
'roms' ,   ROMS nc_write.m and nc_read.m functions
'snctools',   SNCTOOLS inteface
Lplot :   Switch to plot the data (Optional, default false)


nc_vdef.m
Defines a variable in a NetCDF file.
[varid, status] = nc_vdef  (ncid, Var)
On Input:
ncid :   NetCDF file ID (scalar)
Var :   NetCDF interface for Matlab (string):
Var.name ,   variable name (string)
Var.type ,   external data type (string or numeric)
Var.dimid,   dimension IDs (numeric). If not present or empty [ ], the variable is a scalar
Var.field,   any other field in the structure, if any, is processed as variable attribute. The values of the attribute can be numeric (scalar or vector) or strings (character array or cell array). For example,
Var.long_name = 'temp',   'long_name' attribute (string)
Var.FillValue = 1.0E+37,   '_FillValue' attribute (numeric)
On Output:
varid :   Variable ID (scalar)
status :   Error flag


nc_vinfo.m
Gets information about requested NetCDF variable.
V = nc_vinfo  (ncfile, Vname)
On Input:
ncfile :   NetCDF file name or URL name (string)
Dname_old:   Variable name (string)
On Output:
V:   Requested variable information (struct array):
V.Filename,   NetCDF file name (string)
V.Dimensions,   variable dimensions (struct array):
V.Dimensions(:).Name
V.Dimensions(:).Length
V.Dimensions(:).Unlimited
V.Size,   variable size (double array)
V.Attributes,   variable attributes (struct array):
V.Attributes(:).Name
V.Attributes(:).Value
V.Cgridtype,   stagged C-grid type (struct array):
V.Cgridtype.Name
V.Cgridtype.Value
V.Datatype,   original variable data type (string)
V.ncType,   NetCDF data type (numeric)


nc_vnames.m
gets the names and informaton of all variables available in a NetCDF file
S = nc_vnames  (ncfile)
On Input:
ncfile :   NetCDF file name or URL name (string)
On Output:
S:   NetCDF file variables information (struct array):
S.Filename,   NetCDF file name (string)
S.Variables(:).Dimensions,   variable dimensions (struct array):
S.Variables(:).Dimensions(:).Name
S.Variables(:).Dimensions(:).Length
S.Variables(:).Dimensions(:).Unlimited
S.Variables(:).Size,   variable size (double array)
S.Variables(:).Attributes,   variable attributes (struct array):
S.Variables(:).Attributes(:).Name
S.Variables(:).Attributes(:).Value
S.Variables(:).Cgridtype,   stagged C-grid type (struct array):
S.Variables(:).Cgridtype.Name
S.Variables(:).Cgridtype.Value
S.Variables(:).Datatype,   original variable data type (string)
S.Variables(:).ncType,   NetCDF data type (numeric)