Difference between revisions of "NetCDF Data Processing Scripts"

From WikiROMS
Jump to navigationJump to search
 
Line 14: Line 14:
::<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>)
::<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">ncfile</span>: &nbsp;  NetCDF file name (string)
::{| class="matlab"
::<span class="green">Aname</span>: &nbsp; Attribute name (string)
|-
::<span class="green">Avalue</span>: &nbsp; Attribute value (numeric or string)
|<span class="green">ncfile</span>:
::<span class="green">Vname</span>: &nbsp; Variable name (string; optional)
|NetCDF file name (string)
|-
|<span class="green">Aname</span>:
|Attribute name (string)
|-
|<span class="green">Avalue</span>:
|Attribute value (numeric or string)
|-
|<span class="green">Vname</span>:
|Variable name (string; optional)
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_attadd.m />
::{| class="matlab"
|-
|<span class="green">status</span>:
|Error flag
|-
|}<section end=nc_attadd.m />




Line 26: Line 42:
::<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>)
::<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:'''
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp;  NetCDF file name (string)
::{| class="matlab"
::<span class="green">Aname</span>: &nbsp; Attribute name (string)
|-
::<span class="green">Vname</span>: &nbsp; Variable name (string; optional)
|<span class="green">ncfile</span>:
|NetCDF file name (string)
|-
|<span class="green">Aname</span>:
|Attribute name (string)
|-
|<span class="green">Vname</span>:
|Variable name (string; optional)
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_attdel.m />
::{| class="matlab"
|-
|<span class="green">status</span>:
|Error flag
|-
|}<section end=nc_attdel.m />




Line 37: Line 67:
::<span class="green">I</span> = <span class="red">nc_check</span> &nbsp;(<span class="green">Info</span>)
::<span class="green">I</span> = <span class="red">nc_check</span> &nbsp;(<span class="green">Info</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">Info</span>: &nbsp; NetCDF file information structure (struct array)
::{| class="matlab"
|-
|<span class="green">Info</span>:
|NetCDF file information structure (struct array)
|-
|}
:'''On Ouput:'''
:'''On Ouput:'''
::<span class="green">I</span>: &nbsp;  Updated NetCDF file information structure (struct array)<section end=nc_check.m />
::{| class="matlab"
|-
|<span class="green">I</span>:
|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>
: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:
: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>
::    <span class="green">S</span> = <span class="red">nc_inq</span> ('roms_his.nc')
: or
: or
::    <span class="red">S = ncinfo('roms_his.nc')</span> &nbsp; &nbsp;    '''native''' Matlab function
::    <span class="green">S</span> = <span class="red">ncinfo</span> ('roms_his.nc')  &nbsp; &nbsp;    '''native''' Matlab function
:If the user wants different dimension values than those returned by [[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 />
:If the user wants different dimension values than those returned by [[NetCDF_Data_Processing_Scripts#nc_inq|nc_inq]] or <span class="blue">ncinfo</span>, see <span class="green">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_create</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">mode</span>, <span class="green">S</span>)
::<span class="green">ncid</span> = <span class="red">nc_create</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">mode</span>, <span class="green">S</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp; NetCDF file name to create (string)
::{| class="matlab"
::<span class="green">mode</span>: NetCDF file creation mode (string):
|-
:::<span class="red">'clobber'</span>, &nbsp; overwrite existing files
|<span class="green">ncfile</span>:
:::<span class="red">'noclobber'</span>, &nbsp; do not overwrite existing files
|NetCDF file name to create (string)
:::<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="green">mode</span>:
:::<span class="red">'netcdf4'</span>, &nbsp; creates a netCDF-4/HDF-5 file
|NetCDF file creation mode (string):
:::<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)
|}
:::{| class="matlab"
|-
|<span class="twilightBlue">'clobber'</span>
|overwrite existing files
|-
|<span class="twilightBlue">'noclobber'</span>
|do not overwrite existing files
|-
|<span class="twilightBlue">'shared'</span>
|allow for synchronous file updates
|-
|<span class="twilightBlue">'64bit_offset'</span>
|allow the creation of 64-bit files instead of the classic format
|-
|<span class="twilightBlue">'netcdf4'</span>
|creates a netCDF-4/HDF-5 file
|-
|<span class="twilightBlue">'classic_model'</span>
|enforce classic model, has no effect unless used in a bitwise-or with <span class="twilightBlue">'netcdf4'</span>
|-
|}
::{| class="matlab"
|-
|<span class="green">S</span>:
|NetCDF file Schema Structure (struct array)
|-
|}
:'''On Ouput:'''
:'''On Ouput:'''
::<span class="green">ncid</span>: &nbsp;  NetCDF file ID. If no function output arguments are given, the file is closed after it is created.<section end=nc_create.m />
::{| class="matlab"
|-
|<span class="green">ncid</span>:
|NetCDF file ID. If no function output arguments are given, the file is closed after it is created.
|-
|}<section end=nc_create.m />




Line 67: Line 139:
::<span class="green">D</span> = <span class="red">nc_dinfo</span> &nbsp;(<span class="green">ncfile</span>)
::<span class="green">D</span> = <span class="red">nc_dinfo</span> &nbsp;(<span class="green">ncfile</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp; NetCDF file name or URL file name (string)
::{| class="matlab"
|-
|<span class="green">ncfile</span>:
|NetCDF file name or URL file name (string)
|-
|}
:'''On Ouput:'''
:'''On Ouput:'''
::<span class="green">D</span>: &nbsp;  Dimensions information (Struct array):
::{| class="matlab"
:::<span class="green">D(:).Name     </span>: &nbsp; dimension name (string)
|-
:::<span class="green">D(:).Length   </span>: &nbsp; dimension length (double)
|<span class="green">D</span>:
:::<span class="green">D(:).Unlimited</span>: &nbsp; unlimited dimension (logical)
|Dimensions information (Struct array):
:::<span class="green">D(:).dimid   </span>: &nbsp; NetCDF dimension id (double)<section end=nc_dinfo.m />
|-
|}
:::{| class="matlab"
|-
|<span class="green">D(:).Name</span>:
|dimension name (string)
|-
|<span class="green">D(:).Length</span>:
|dimension length (double)
|-
|<span class="green">D(:).Unlimited</span>:
|unlimited dimension (logical)
|-
|<span class="green">D(:).dimid</span>:
|NetCDF dimension id (double)
|-
|}<section end=nc_dinfo.m />




Line 80: Line 173:
::<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>)
::<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:'''
:'''On Input:'''
::<span class="green">ncfile   </span>: &nbsp;  NetCDF file name (string)
::{| class="matlab"
::<span class="green">Dname_old</span>: &nbsp;  Old dimension name (string)
|-
::<span class="green">Dname_new</span>: &nbsp;  New dimension name (string)
|<span class="green">ncfile</span>:
|NetCDF file name (string)
|-
|<span class="green">Dname_old</span>:
|Old dimension name (string)
|-
|<span class="green">Dname_new</span>:
|New dimension name (string)
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_drename.m />
::{| class="matlab"
|-
|<span class="green">status</span>:
|Error flag
|-
|}<section end=nc_drename.m />




Line 91: Line 198:
::<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>)
::<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:'''
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp;  NetCDF file name or URL file name (string)
::{| class="matlab"
::<span class="green">Aname </span>: &nbsp;  Attribute name (string; optional)
|-
::<span class="green">Vname </span>: &nbsp;  Variable name  (string; optional)
|<span class="green">ncfile</span>:
|NetCDF file name or URL file name (string)
|-
|<span class="green">Aname </span>:
|Attribute name (string; optional)
|-
|<span class="green">Vname </span>:
|Variable name  (string; optional)
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">A</span>: &nbsp;  Attribute value (numeric, string, or struct array)
::{| class="matlab"
|-
|<span class="green">A</span>:
|Attribute value (numeric, string, or struct array)
|-
|}
:'''Usage:'''
:'''Usage:'''
::<span class="mediumOrchid">A = nc_getatt ('ocean_his.nc')</span>
::<span class="mediumOrchid">A = nc_getatt ('ocean_his.nc')</span>
Line 111: Line 232:
::<span class="green">I</span> = <span class="red">nc_inq</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Lprint</span>)
::<span class="green">I</span> = <span class="red">nc_inq</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Lprint</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp;  NetCDF file name or URL file name (string)
::{| class="matlab"
::<span class="green">Lprint</span>: &nbsp;  Switch to print information (optional; default false)
|-
|<span class="green">ncfile</span>:
|NetCDF file name or URL file name (string)
|-
|<span class="green">Lprint</span>:
|Switch to print information (optional; default false)
|-
|}
:'''On Output:'''
:'''On Output:'''
:: <span class="green">I</span>: &nbsp;  NetCDF information (struct array):
::{| class="matlab"
::: <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</span>:
::::<span class="green">I.Attributes(:).Name</span>
|NetCDF information (struct array):
::::<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>
:::{| class="matlab"
::::<span class="green">I.Dimensions(:).Length</span>
|-
::::<span class="green">I.Dimensions(:).Unlimited</span>
|<span class="green">I.Filename</span>
:
|NetCDF file name (string)
::: <span class="green">I.Variables(:).Dimensions</span>, &nbsp; variable dimensions (struct array):  
|-
::::<span class="green">I.Variables(:).Dimensions(:).Name</span>  
|<span class="green">I.Attributes</span>
::::<span class="green">I.Variables(:).Dimensions(:).Length</span>
|NetCDF global attributes (struct array):
::::<span class="green">I.Variables(:).Dimensions(:).Unlimited</span>
|-
:
|style="padding-left: 3em" colspan="2" | <span class="green">I.Attributes(:).Name</span><br /><span class="green">I.Attributes(:).Value</span>
::: <span class="green">I.Variables(:).Size</span>, &nbsp; variable size (double array)
|-
:
|<span class="green">I.Dimensions</span>
::: <span class="green">I.Variables(:).Attributes</span>, &nbsp; variable attributes (struct array):
|NetCDF file dimensions (struct array):
::::<span class="green">I.Variables(:).Attributes(:).Name</span>
|-
::::<span class="green">I.Variables(:).Attributes(:).Value</span>
|style="padding-left: 3em" colspan="2" | <span class="green">I.Dimensions(:).Name</span><br /><span class="green">I.Dimensions(:).Length</span><br /><span class="green">I.Dimensions(:).Unlimited</span>
:
|-
::: <span class="green">I.Variables(:).Cgridtype</span>, &nbsp; stagged C-grid type (struct array):
|<span class="green">I.Variables(:).Dimensions</span>
::::<span class="green">I.Variables(:).Cgridtype.Name</span>
|variable dimensions (struct array):
::::<span class="green">I.Variables(:).Cgridtype.Value</span>
|-
:
|style="padding-left: 3em" colspan="2" | <span class="green">I.Variables(:).Dimensions(:).Name</span><br /><span class="green">I.Variables(:).Dimensions(:).Length</span><br /><span class="green">I.Variables(:).Dimensions(:).Unlimited</span>
::: <span class="green">I.Variables(:).Datatype</span>, &nbsp; original variable data type (string)
|-
:
|<span class="green">I.Variables(:).Size</span>
::: <span class="green">I.Variables(:).ncType</span>, &nbsp; NetCDF data type (numeric)<section end=nc_inq.m />
|variable size (double array)
 
|-
|<span class="green">I.Variables(:).Attributes</span>
|variable attributes (struct array):
|-
|style="padding-left:3em" colspan="2" | <span class="green">I.Variables(:).Attributes(:).Name</span><br /><span class="green">I.Variables(:).Attributes(:).Value</span>
|-
|<span class="green">I.Variables(:).Cgridtype</span>
|stagged C-grid type (struct array):
|-
|style="padding-left:3em" colspan="2" | <span class="green">I.Variables(:).Cgridtype.Name</span><br /><span class="green">I.Variables(:).Cgridtype.Value</span>
|-
|<span class="green">I.Variables(:).Datatype</span>
|original variable data type (string)
|-
|<span class="green">I.Variables(:).ncType</span>
|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>
<section begin=nc_interface.m />;<span id="nc_interface"></span><span class="blue">nc_interface.m</span>
: Determines the interface to use when processing a NetCDF file. The strategy is to always use 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 />
: Determines the interface to use when processing a NetCDF file. The strategy is to always use 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>)
::[<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:'''
:'''On Input:'''
::<span class="green">ncfile  </span>: &nbsp;  NetCDF file name or URL name (string)
::{| class="matlab"
|-
|<span class="green">ncfile  </span>:
|NetCDF file name or URL name (string)
|-
|}
:'''On Output:'''
:'''On Output:'''
:: <span class="green">method  </span>: &nbsp; NetCDF interface for Matlab (string):
::{| class="matlab"
:::<span class="red">'native' </span>, &nbsp; '''Native''' Matlab interface
|-
:::<span class="red">'mexnc'   </span>, &nbsp; '''MEXNC''' interface
|<span class="green">method  </span>:
:::<span class="red">'java'   </span>, &nbsp; '''SNCTOOLS''' Java interface
|NetCDF interface for Matlab (string):
:: <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
:::{| class="matlab"
:::<span class="red">'NetCDF4' </span>, &nbsp; '''NetCDF-4'''/'''HDF5''' file
|-
:::<span class="red">'OpenDAP' </span>, &nbsp; '''OpenDAP''' file <section end=nc_interface.m />
|<span class="twilightBlue">'native'</span>
|'''Native''' Matlab interface
|-
|<span class="twilightBlue">'mexnc'</span>
|'''MEXNC''' interface
|-
|<span class="twilightBlue">'java'</span>
|'''SNCTOOLS''' Java interface
|-
|}
::{| class="matlab"
|-
|<span class="green">url</span>:
|Switch indicating an OpenDAP file (logical)
|-
|<span class="green">ftype</span>:
|File type (string)
|-
|}
:::{| class="matlab"
|-
|<span class="twilightBlue">'NetCDF'</span>
|Classic '''NetCDF-3''' file
|-
|<span class="twilightBlue">'NetCDF4'</span>
|'''NetCDF-4'''/'''HDF5''' file
|-
|<span class="twilightBlue">'OpenDAP'</span>
|'''OpenDAP''' file
|-
|}<section end=nc_interface.m />




Line 166: Line 346:
::<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>)
::<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:'''
:'''On Input:'''
::<span class="green">ncfile     </span>: &nbsp;  NetCDF file name or URL name (string)
::{| class="matlab"
::<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 the unlimited dimension or the word <span class="red">time</span> in any of its dimension names. Otherwise, provide an empty [ ] argument.
|<span class="green">ncfile</span>:
::<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 better visualize the land masking or the missing data.
|NetCDF file name or URL name (string)
::<span class="green">PreserveType</span>: &nbsp;  Switch to preserve numerical data type (logical). If false, convert numerical data to double precision. It has no effect on data that is already in double precision.
|-
|<span class="green">Vname</span>:
|NetCDF variable name to read (string)
|-
|<span class="green">Tindex</span>:
|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 the unlimited dimension or the word '''time''' in any of its dimension names. Otherwise, provide an empty [&nbsp;] argument.
|-
|<span class="green">ReplaceValue</span>:
|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 better visualize the land masking or the missing data.
|-
|<span class="green">PreserveType</span>:
|Switch to preserve numerical data type (logical). If false, convert numerical data to double precision. It has no effect on data that is already in double precision.
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">f</span>: &nbsp;  Field (scalar or array) <section end=nc_read.m />
::{| class="matlab"
|-
|<span class="green">f</span>:
|Field (scalar or array)
|-
|}<section end=nc_read.m />




Line 179: Line 377:
::[<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>)
::[<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:'''
:'''On Input:'''
::<span class="green">Gfile </span>: &nbsp;  ROMS Grid NetCDF file name (string). If no grid file, use field file name instead.
::{| class="matlab"
::<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">Gfile</span>:
::<span class="green">depth </span>: &nbsp;  Slice depth (scalar; meters, negative)
|ROMS Grid NetCDF file name (string). If no grid file, use field file name instead.
::<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.
|<span class="green">Hfile</span>:
|Field history NetCDF file name (string)
|-
|<span class="green">Vname</span>:
|NetCDF variable name to process (string)
|-
|<span class="green">depth</span>:
|Slice depth (scalar; meters, negative)
|-
|<span class="green">Tindex</span>:
|Time index to read (integer). If <span class="green">Tindex&nbsp;=&nbsp;0</span>, all time records are processed. Otherwise if <span class="green">Tindex&nbsp;>&nbsp;0</span>, only the specified record is processed.
|-
|<span class="green">zflag</span>:
|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:'''
:'''On Output:'''
::<span class="green">x</span>: &nbsp;  Slice X-positions (2D array)
::{| class="matlab"
::<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 />
|<span class="green">x</span>:
|Slice X-positions (2D array)
|-
|<span class="green">y</span>:
|Slice Y-positions (2D array)
|-
|<span class="green">f</span>:
|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>
<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 into 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 />
:Creates a NetCDF file 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 into 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>)
::<span class="red">nc_test</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Interface</span>, <span class="green">Lplot</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile  </span>: &nbsp;  NetCDF file name to create (string)
::<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="green">Interface</span>: &nbsp;  NetCDF interface for Matlab (string):
:::<span class="red">'native' </span>, &nbsp;  '''Native''' Matlab interface
:::{| class="matlab"
:::<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="twilightBlue">'native'</span>
:::<span class="red">'snctools'</span>, &nbsp;  '''SNCTOOLS''' inteface
|'''Native''' Matlab interface
::<span class="green">Lplot   </span>: &nbsp;  Switch to plot the data (Optional, default false) <section end=nc_test.m />
|-
|<span class="twilightBlue">'mexnc'</span>
|'''MEXNC''' interface
|-
|<span class="twilightBlue">'roms'</span>
|'''ROMS''' [[NetCDF_Data_Processing_Scripts#nc_write|nc_write.m]] and [[NetCDF_Data_Processing_Scripts#nc_read|nc_read.m]] functions
|-
|<span class="twilightBlue">'snctools'</span>
|'''SNCTOOLS''' interface
|-
|}
::{| class="matlab"
|-
|<span class="green">Lplot</span>:
|Switch to plot the data (Optional, default false)
|-
|}<section end=nc_test.m />




Line 208: Line 446:
::[<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>)
::[<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:'''
:'''On Input:'''
::<span class="green">ncid   </span>: &nbsp; NetCDF file ID (scalar)
::{| class="matlab"
:: <span class="green">Var   </span>: &nbsp; NetCDF interface for Matlab (string):
|-
:::<span class="red">Var.name </span>, &nbsp; variable name (string)
|<span class="green">ncid</span>:
:::<span class="red">Var.type </span>, &nbsp; external data type (string or numeric)
|NetCDF file ID (scalar)
:::<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; Values, if any, for '<span class="red">field</span>' in the structure are processed as variable attributes. The values of the attribute can be numeric (scalar or vector) or strings (character array or cell array). For example,
|<span class="green">Var</span>:
::::<span class="red">Var.long_name</span> = 'temp',  &nbsp; 'long_name' attribute (string)
|NetCDF interface for Matlab (string):
::::<span class="red">Var.FillValue</span> = 1.0E+37, &nbsp; '_FillValue' attribute (numeric)
|-
|}
:::{| class="matlab"
|-
|<span class="green">Var.name</span>
|variable name (string)
|-
|<span class="green">Var.type</span>
|external data type (string or numeric)
|-
|<span class="green">Var.dimid</span>
|dimension IDs (numeric). If not present or empty [&nbsp;], the variable is a scalar
|-
|<span class="green">Var.field</span>
|Values, if any, for ''''field'''' in the structure are processed as variable attributes. The values of the attribute can be numeric (scalar or vector) or strings (character array or cell array). For&nbsp;example:<br /><div style="padding-left: 3em"><span class="green">Var.long_name</span> = 'temp',  &nbsp; &nbsp; &nbsp;'long_name' attribute (string)<br /><span class="green">Var.FillValue</span> &nbsp; &nbsp; = 1.0E+37, &nbsp; '_FillValue' attribute (numeric)</div>
|-
|}
:'''On Output:'''
:'''On Output:'''
:: <span class="green">varid   </span>: &nbsp; Variable ID (scalar)
::{| class="matlab"
:: <span class="green">status   </span>: &nbsp; Error flag <section end=nc_vdef.m />
|-
|<span class="green">varid</span>:
|Variable ID (scalar)
|-
|<span class="green">status</span>:
|Error flag
|-
|}<section end=nc_vdef.m />




Line 225: Line 486:
::<span class="green">V</span> = <span class="red">nc_vinfo</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname</span>)
::<span class="green">V</span> = <span class="red">nc_vinfo</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile   </span>: &nbsp; NetCDF file name or URL name (string)
::{| class="matlab"
::<span class="green">Dname_old</span>: &nbsp; Variable name (string)
|-
|<span class="green">ncfile</span>:
|NetCDF file name or URL name (string)
|-
|<span class="green">Vname</span>:
|Variable name (string)
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">V</span>: &nbsp;  Requested variable information (struct array):
::{| class="matlab"
:::<span class="green">V.Filename</span>, &nbsp;  NetCDF file name (string)
|-
:
|<span class="green">V</span>:
::: <span class="green">V.Dimensions</span>, &nbsp; variable dimensions (struct array):  
|Requested variable information (struct array):
::::<span class="green">V.Dimensions(:).Name</span>  
|-
::::<span class="green">V.Dimensions(:).Length</span>
|}
::::<span class="green">V.Dimensions(:).Unlimited</span>
:::{| class="matlab"
:
|-
::: <span class="green">V.Size</span>, &nbsp; variable size (double array)
|<span class="green">V.Filename</span>
:
|NetCDF file name (string)
::: <span class="green">V.Attributes</span>, &nbsp; variable attributes (struct array):
|-
::::<span class="green">V.Attributes(:).Name</span>
|<span class="green">V.Dimensions</span>
::::<span class="green">V.Attributes(:).Value</span>
|variable dimensions (struct array):
:
|-
::: <span class="green">V.Cgridtype</span>, &nbsp; stagged C-grid type (struct array):
|style="padding-left: 3em" | <span class="green">V.Dimensions(:).Name</span>  
::::<span class="green">V.Cgridtype.Name</span>
|-
::::<span class="green">V.Cgridtype.Value</span>
|style="padding-left: 3em" | <span class="green">V.Dimensions(:).Length</span>
:
|-
::: <span class="green">V.Datatype</span>, &nbsp; original variable data type (string)
|style="padding-left: 3em" | <span class="green">V.Dimensions(:).Unlimited</span>
:
|-
::: <span class="green">V.ncType</span>, &nbsp; NetCDF data type (numeric)<section end=nc_vinfo.m />
|<span class="green">V.Size</span>
|variable size (double array)
|-
|<span class="green">V.Attributes</span>
|variable attributes (struct array):
|-
|style="padding-left: 3em" | <span class="green">V.Attributes(:).Name</span>
|-
|style="padding-left: 3em" | <span class="green">V.Attributes(:).Value</span>
|-
|<span class="green">V.Cgridtype</span>
|stagged C-grid type (struct array):
|-
|style="padding-left: 3em" | <span class="green">V.Cgridtype.Name</span>
|-
|style="padding-left: 3em" | <span class="green">V.Cgridtype.Value</span>
|-
|<span class="green">V.Datatype</span>
|original variable data type (string)
|-
|<span class="green">V.ncType</span>
|NetCDF data type (numeric)
|-
|}<section end=nc_vinfo.m />




Line 255: Line 546:
::<span class="green">S</span> = <span class="red">nc_vnames</span> &nbsp;(<span class="green">ncfile</span>)
::<span class="green">S</span> = <span class="red">nc_vnames</span> &nbsp;(<span class="green">ncfile</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile   </span>: &nbsp; NetCDF file name or URL name (string)
::{| class="matlab"
|-
|<span class="green">ncfile</span>:
|NetCDF file name or URL name (string)
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">S</span>: &nbsp;  NetCDF file variables information (struct array):
::{| class="matlab"
:::<span class="green">S.Filename</span>, &nbsp;  NetCDF file name (string)
|-
:
|<span class="green">S</span>:
::: <span class="green">S.Variables(:).Dimensions</span>, &nbsp; variable dimensions (struct array):  
|NetCDF file variables information (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>
:::{| class="matlab"
:
|-
::: <span class="green">S.Variables(:).Size</span>, &nbsp; variable size (double array)
|<span class="green">S.Filename</span>
:
|NetCDF file name (string)
::: <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(:).Dimensions</span>
::::<span class="green">S.Variables(:).Attributes(:).Value</span>
|variable dimensions (struct array):  
:
|-
::: <span class="green">S.Variables(:).Cgridtype</span>, &nbsp; stagged C-grid type (struct array):
|style="padding-left: 3em" | <span class="green">S.Variables(:).Dimensions(:).Name</span>
::::<span class="green">S.Variables(:).Cgridtype.Name</span>
|-
::::<span class="green">S.Variables(:).Cgridtype.Value</span>
|style="padding-left: 3em" | <span class="green">S.Variables(:).Dimensions(:).Length</span>
:
|-
::: <span class="green">S.Variables(:).Datatype</span>, &nbsp; original variable data type (string)
|style="padding-left: 3em" | <span class="green">S.Variables(:).Dimensions(:).Unlimited</span>
:
|-
::: <span class="green">S.Variables(:).ncType</span>, &nbsp; NetCDF data type (numeric)<section end=nc_vnames.m />
|<span class="green">S.Variables(:).Size</span>
|variable size (double array)
|-
|<span class="green">S.Variables(:).Attributes</span>
|variable attributes (struct array):
|-
|style="padding-left: 3em" | <span class="green">S.Variables(:).Attributes(:).Name</span>
|-
|style="padding-left: 3em" | <span class="green">S.Variables(:).Attributes(:).Value</span>
|-
|<span class="green">S.Variables(:).Cgridtype</span>
|stagged C-grid type (struct array):
|-
|style="padding-left: 3em" | <span class="green">S.Variables(:).Cgridtype.Name</span>
|-
|style="padding-left: 3em" | <span class="green">S.Variables(:).Cgridtype.Value</span>
|-
|<span class="green">S.Variables(:).Datatype</span>
|original variable data type (string)
|-
|<span class="green">S.Variables(:).ncType</span>
|NetCDF data type (numeric)
|-
|}<section end=nc_vnames.m />




Line 284: Line 603:
::<span class="green">status</span> = <span class="red">nc_vrename</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname_old</span>, <span class="green">Vname_new</span>)
::<span class="green">status</span> = <span class="red">nc_vrename</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname_old</span>, <span class="green">Vname_new</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile   </span>: &nbsp;  NetCDF file name (string)
::{| class="matlab"
::<span class="green">Vname_old</span>: &nbsp;  Old variable name (string)
|-
::<span class="green">Vname_new</span>: &nbsp;  New variable name (string)
|<span class="green">ncfile</span>:
|NetCDF file name (string)
|-
|<span class="green">Vname_old</span>:
|Old variable name (string)
|-
|<span class="green">Vname_new</span>:
|New variable name (string)
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_vrename.m />
::{| class="matlab"
|-
|<span class="green">status</span>:
|Error flag
|-
|}<section end=nc_vrename.m />
 


<section begin=nc_write.m />;<span id="nc_write"></span><span class="blue">nc_write.m</span>
<section begin=nc_write.m />;<span id="nc_write"></span><span class="blue">nc_write.m</span>
Line 294: Line 628:
::<span class="green">status</span> = <span class="red">nc_read</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname</span>, <span class="green">f</span>, <span class="green">Tindex</span>)
::<span class="green">status</span> = <span class="red">nc_read</span> &nbsp;(<span class="green">ncfile</span>, <span class="green">Vname</span>, <span class="green">f</span>, <span class="green">Tindex</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">ncfile</span>: &nbsp;  NetCDF file name or URL name (string)
::{| class="matlab"
::<span class="green">Vname </span>: &nbsp;  NetCDF variable name to read (string)
|-
::<span class="green">f     </span>: &nbsp;  variable values (scalar or array)
|<span class="green">ncfile</span>:
::<span class="green">Tindex</span>: &nbsp;  If <span class="green">Tindex</span> is not provided as an argument during function call, it is assumed that the entire variable is to be written. If  the variable has an unlimited record dimension, <span class="green">Tindex</span> can be used to increase that dimension or replace an existing record. If the variable has the word <span class="red">time</span> in its dimension name, <span class="green">Tindex</span> can be used to write at the specified the time record.
|NetCDF file name or URL name (string)
|-
|<span class="green">Vname</span>:
|NetCDF variable name to read (string)
|-
|<span class="green">f</span>:
|variable values (scalar or array)
|-
|<span class="green">Tindex</span>:
|If <span class="green">Tindex</span> is not provided as an argument during function call, it is assumed that the entire variable is to be written. If  the variable has an unlimited record dimension, <span class="green">Tindex</span> can be used to increase that dimension or replace an existing record. If the variable has the word '''time''' in its dimension name, <span class="green">Tindex</span> can be used to write at the specified the time record.
|-
|}
:'''On Output:'''
:'''On Output:'''
::<span class="green">status</span>: &nbsp;  Error flag <section end=nc_write.m />
::{| class="matlab"
|-
|<span class="green">status</span>:
|Error flag
|-
|}<section end=nc_write.m />

Latest revision as of 16:57, 4 May 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 the native NetCDF interface if using Matlab Version 2008b or newer for local NetCDF files and Matlab Version 2012a or newer for OpenDAP files. For older Matlab versions, the MEXNC interface is 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 variable types and attributes. For example, it updates the spherical switch to integer and fixes 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 than those returned by 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_create  (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 no function output arguments are given, the file is closed after it is created.


nc_dinfo.m
Gets all the dimension information about the requested NetCDF file.
D = nc_dinfo  (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 length (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_getatt.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 a NetCDF file. The strategy is to always use 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 the 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 better visualize 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 no effect on data that 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 file using data from the peaks(40) function. Several data type variables are created from the original double precision data and packed into 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)
Interface:   NetCDF interface for Matlab (string):
'native' Native Matlab interface
'mexnc' MEXNC interface
'roms' ROMS nc_write.m and nc_read.m functions
'snctools' SNCTOOLS interface
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 Values, if any, for 'field' in the structure are processed as variable attributes. 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)
Vname: 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)


nc_vrename.m
Renames requested variable in a NetCDF file.
status = nc_vrename  (ncfile, Vname_old, Vname_new)
On Input:
ncfile: NetCDF file name (string)
Vname_old: Old variable name (string)
Vname_new: New variable name (string)
On Output:
status: Error flag


nc_write.m
Writes a generic variable into a NetCDF file.
status = nc_read  (ncfile, Vname, f, Tindex)
On Input:
ncfile: NetCDF file name or URL name (string)
Vname: NetCDF variable name to read (string)
f: variable values (scalar or array)
Tindex: If Tindex is not provided as an argument during function call, it is assumed that the entire variable is to be written. If the variable has an unlimited record dimension, Tindex can be used to increase that dimension or replace an existing record. If the variable has the word time in its dimension name, Tindex can be used to write at the specified the time record.
On Output:
status: Error flag