Difference between revisions of "Matlab Processing Scripts"

From WikiROMS
Jump to navigationJump to search
Line 9: Line 9:


{{note}} '''Notice:''' Starting Matlab version '''2012a''', released on Feb 9, 2012, the '''native''' interface to NetCDF is the preferred method for processing NetCDF data in the scripts distributed in the ROMS repository '''matlab''': <span class="red"><nowiki>https://www.myroms.org/svn/src/matlab</nowiki></span>. The '''native''' interface was introduced in Matlab version '''2008b''' for NetCDF-3 type files.  The NetCDF-4 support started in version '''2010b'''.  The support for HDF5 files was completed in version '''2011a'''.  The OpenDAP support began in version '''2012a'''.  If your Matlab version is older than 2008b, we highly recommend to update to the newest version.  However, in the basic generic scripts we have switches for older versions to activate either the '''MEXNC''' interface for standard NetCDF files and the '''SNCTOOLS''' interface to process NetCDF files on an OpenDAP server.
{{note}} '''Notice:''' Starting Matlab version '''2012a''', released on Feb 9, 2012, the '''native''' interface to NetCDF is the preferred method for processing NetCDF data in the scripts distributed in the ROMS repository '''matlab''': <span class="red"><nowiki>https://www.myroms.org/svn/src/matlab</nowiki></span>. The '''native''' interface was introduced in Matlab version '''2008b''' for NetCDF-3 type files.  The NetCDF-4 support started in version '''2010b'''.  The support for HDF5 files was completed in version '''2011a'''.  The OpenDAP support began in version '''2012a'''.  If your Matlab version is older than 2008b, we highly recommend to update to the newest version.  However, in the basic generic scripts we have switches for older versions to activate either the '''MEXNC''' interface for standard NetCDF files and the '''SNCTOOLS''' interface to process NetCDF files on an OpenDAP server.
{{warning}} '''Caution:''' The ROMS Grid structure used in all the scripts described here is the one returned from by the script <span class="blue">get_roms_grid.m</span>.


==Nested Grid Generation Scripts==
==Nested Grid Generation Scripts==
Line 14: Line 16:
Currently, it is not our intention to develop a fancy GUI tool to prepare ROMS nested grids.  The capability of ROMS nesting is unique and requires special tools since we support mosaics, composite, and refinement grids in a variety of [[Nested_Grids#Nested_Grids_Classes|nested classes]]. Perhaps in the future an expert user will help us develop this GUI. However, the scripts described here are basic and fundamental. They can be used in the future to build a fancier interface.
Currently, it is not our intention to develop a fancy GUI tool to prepare ROMS nested grids.  The capability of ROMS nesting is unique and requires special tools since we support mosaics, composite, and refinement grids in a variety of [[Nested_Grids#Nested_Grids_Classes|nested classes]]. Perhaps in the future an expert user will help us develop this GUI. However, the scripts described here are basic and fundamental. They can be used in the future to build a fancier interface.


Two strategies are possible when configuring nested grids for a particular application:
#Build an intermediate large coarse resolution grid and extract the composite and/or refinement grids from it using the functions dicussed below. The disadvantage of this approach is that we need work independently each grid for adjustments in the land/sea masking, target bathymetry, and matching domain volumes.  Additionally, the finer resolution grids bathymetry can be under- or over-estimated due to the original coarser bathymetry.  There is a linear definition of topographic features that are unresolved in the finer grids.
#Build an intermediate large very fine resolution grid, work on the desired land/sea masking, and target smooth bathymetry. The intermediate grid must resolve that smaller resolution desired for a particular application. Then, use the scripts described below to extract the composite and/or refinement grids.  We think that this strategy is advantageous in all aspects.  However, it is cumbersome dealing with large grid and working the details of the land/sea making.  The function [[landsea.m]] can be used to automatize the land/sea masking , but it still needs some hand editing.
The main scripts to carry this tasks are located in the '''matlab/grid''' sub-directory:


;<span id="c_grid"></span><span class="blue">c_grid.m</span>
;<span id="c_grid"></span><span class="blue">c_grid.m</span>
:Creates a new ROMS grid NetCDF file or modifies a existing ROMS grid NetCDF file.<br />
:Creates a new ROMS grid NetCDF file or modifies a existing ROMS grid NetCDF file.<br />
:<span class="green">status</span> = <span class="red">c_grid</span> &nbsp;(<span class="green">Lp</span>,<span class="green">Mp</span>, <span class="green">Gname</span>, <span class="green">NewFile</span>, <span class="green">spherical</span>)
::<span class="green">status</span> = <span class="red">c_grid</span> &nbsp;(<span class="green">Lp</span>,<span class="green">Mp</span>, <span class="green">Gname</span>, <span class="green">NewFile</span>, <span class="green">spherical</span>)
:'''On Input:'''
:'''On Input:'''
::<span class="green">Lp</span>: &nbsp; Number of &rho;-point in the &xi;-direction
::<span class="green">Lp</span>: &nbsp; Number of &rho;-point in the &xi;-direction
Line 26: Line 33:
:'''On Ouput:'''
:'''On Ouput:'''
::<span class="green">status</span>: &nbsp; Error flag
::<span class="green">status</span>: &nbsp; Error flag
;<span id="coarse2fine"></span><span class="blue">coarse2fine</span>
:Given a coarse resolution ROMS Grid NetCDF file (<span class="green">Ginp</span>), this function creates a finer resolution grid in the region specified by the coarser grid coordinates (<span class="green">Imin</span>, <span class="green">Jmin</span>) and (<span class="green">Imax</span>, <span class="green">Jmax</span>). Notice that (<span class="green">Imin</span>, <span class="green">Jmin</span>), and (<span class="green">Imax</span>, <span class="green">Jmax</span>) indices are in terms of the &psi;-points because it actually define the physical boundaries of the refined grid. The grid refinement coefficient is specified with <span class="green">Gfactor</span>. <br />
::<span class="green">F</span> = <span class="red">coarse2fine</span> &nbsp;(<span class="green">Ginp</span>,<span class="green">Gout</span>, <span class="green">Gfactor</span>, <span class="green">Imin</span>, <span class="green">Imax</span>, <span class="green">Jmin</span>, <span class="green">Jmax</span>)
:'''On Input:'''
::<span class="green">Ginp</span>: &nbsp; Input coarser Grid NetCDF file name (string)
::<span class="green">Gout</span>: &nbsp; Output finer Grid NetCDF file name (string)
::<span class="green">Gfactor</span>: &nbsp; Grid refinement factor (3,5,7,9,11,13,15,...)
::<span class="green">Imin</span>: &nbsp; Coarse grid lower-left  I-coordinate (&psi;-point)
::<span class="green">Imax</span>: &nbsp; Coarse grid upper-right I-coordinate (&psi;-point)
::<span class="green">Jmin</span>: &nbsp; Coarse grid lower-left  J-coordinate (&psi;-point)
::<span class="green">Jmax</span>: &nbsp; Coarse grid upper-right J-coordinate (&psi;-point)
:'''On Ouput:'''
::<span class="green">F</span>: &nbsp; Fine resolution grid structure (struct array)
;<span id="fine2coarse"></span><span class="blue">fine2coarse</span>
:Given a finer resolution ROMS Grid NetCDF file (<span class="green">Ginp</span>), this function creates a coarser resolution grid in the region specified by the finer grid coordinates (<span class="green">Imin</span>, <span class="green">Jmin</span>) and (<span class="green">Imax</span>, <span class="green">Jmax</span>). Notice that (<span class="green">Imin</span>, <span class="green">Jmin</span>), and (<span class="green">Imax</span>, <span class="green">Jmax</span>) indices are in terms of the &psi;-points because it actually define the physical boundaries of the coarser grid. The grid coarseness coefficient is specified with <span class="green">Gfactor</span>. <br />
::<span class="green">C</span> = <span class="red">fine2coarse</span> &nbsp;(<span class="green">Ginp</span>,<span class="green">Gout</span>, <span class="green">Gfactor</span>, <span class="green">Imin</span>, <span class="green">Imax</span>, <span class="green">Jmin</span>, <span class="green">Jmax</span>)
:'''On Input:'''
::<span class="green">Ginp</span>: &nbsp; Input finer Grid NetCDF file name (string)
::<span class="green">Gout</span>: &nbsp; Output coarser Grid NetCDF file name (string)
::<span class="green">Gfactor</span>: &nbsp; Grid coarseness factor (3,5,7,9,11,13,15,...)
::<span class="green">Imin</span>: &nbsp; Finer grid lower-left  I-coordinate (&psi;-point)
::<span class="green">Imax</span>: &nbsp; Finer grid upper-right I-coordinate (&psi;-point)
::<span class="green">Jmin</span>: &nbsp; Finer grid lower-left  J-coordinate (&psi;-point)
::<span class="green">Jmax</span>: &nbsp; Finer grid upper-right J-coordinate (&psi;-point)
:'''On Ouput:'''
::<span class="green">C</span>: &nbsp; Coarser resolution grid structure (struct array)
;<span id="grid_extract"></span><span class="blue">grid_extract</span>
:Given a larger ROMS Grid NetCDF file (<span class="green">Ginp</span>), this function extracts and creates a sub-domain Grid NetCDF file (<span class="green">Gout</span>) for the sampled region in terms of the larger grid coordinates (<span class="green">Imin</span>, <span class="green">Jmin</span>) and (<span class="green">Imax</span>, <span class="green">Jmax</span>). Notice that the (<span class="green">Imin</span>, <span class="green">Jmin</span>), and (<span class="green">Imax</span>, <span class="green">Jmax</span>) indices are located at &psi;-points. They actually define the physical boundaries of the smaller sub-domain grid.<br />
::<span class="green">S</span> = <span class="red">grid_extract</span> &nbsp;(<span class="green">Ginp</span>,<span class="green">Gout</span>,  <span class="green">Imin</span>, <span class="green">Imax</span>, <span class="green">Jmin</span>, <span class="green">Jmax</span>)
:'''On Input:'''
::<span class="green">Ginp</span>: &nbsp; Input coaser Grid NetCDF file name (string) or an existing grid structure (struct array)
::<span class="green">Gout</span>: &nbsp; Output smaller Grid NetCDF file name (string)
::<span class="green">Gfactor</span>: &nbsp; Grid refinement factor (3,5,7,9,11,13,15,...)
::<span class="green">Imin</span>: &nbsp; Larger grid lower-left  I-coordinate (&psi;-point)
::<span class="green">Imax</span>: &nbsp; Larger grid upper-right I-coordinate (&psi;-point)
::<span class="green">Jmin</span>: &nbsp; Larger grid lower-left  J-coordinate (&psi;-point)
::<span class="green">Jmax</span>: &nbsp; Larger grid upper-right J-coordinate (&psi;-point)
:'''On Ouput:'''
::<span class="green">S</span>: &nbsp; Smaller grid structure (struct array)


==Contact Regions and Contact Points Scripts==
==Contact Regions and Contact Points Scripts==

Revision as of 21:57, 20 April 2012

Matlab Processing Scripts for Nesting

The Matlab processing scripts for nesting applications are divided in four categories:

  • Scripts to aid in the building of nested grids and associated NetCDF files,
  • Scripts to process contact regions and contact points and build its associated NetCDF file,
  • Scripts to process initial conditions data and NetCDF files, and
  • Generic support scripts.

Note Notice: Starting Matlab version 2012a, released on Feb 9, 2012, the native interface to NetCDF is the preferred method for processing NetCDF data in the scripts distributed in the ROMS repository matlab: https://www.myroms.org/svn/src/matlab. The native interface was introduced in Matlab version 2008b for NetCDF-3 type files. The NetCDF-4 support started in version 2010b. The support for HDF5 files was completed in version 2011a. The OpenDAP support began in version 2012a. If your Matlab version is older than 2008b, we highly recommend to update to the newest version. However, in the basic generic scripts we have switches for older versions to activate either the MEXNC interface for standard NetCDF files and the SNCTOOLS interface to process NetCDF files on an OpenDAP server.

Warning Caution: The ROMS Grid structure used in all the scripts described here is the one returned from by the script get_roms_grid.m.

Nested Grid Generation Scripts

Currently, it is not our intention to develop a fancy GUI tool to prepare ROMS nested grids. The capability of ROMS nesting is unique and requires special tools since we support mosaics, composite, and refinement grids in a variety of nested classes. Perhaps in the future an expert user will help us develop this GUI. However, the scripts described here are basic and fundamental. They can be used in the future to build a fancier interface.

Two strategies are possible when configuring nested grids for a particular application:

  1. Build an intermediate large coarse resolution grid and extract the composite and/or refinement grids from it using the functions dicussed below. The disadvantage of this approach is that we need work independently each grid for adjustments in the land/sea masking, target bathymetry, and matching domain volumes. Additionally, the finer resolution grids bathymetry can be under- or over-estimated due to the original coarser bathymetry. There is a linear definition of topographic features that are unresolved in the finer grids.
  2. Build an intermediate large very fine resolution grid, work on the desired land/sea masking, and target smooth bathymetry. The intermediate grid must resolve that smaller resolution desired for a particular application. Then, use the scripts described below to extract the composite and/or refinement grids. We think that this strategy is advantageous in all aspects. However, it is cumbersome dealing with large grid and working the details of the land/sea making. The function landsea.m can be used to automatize the land/sea masking , but it still needs some hand editing.

The main scripts to carry this tasks are located in the matlab/grid sub-directory:

c_grid.m
Creates a new ROMS grid NetCDF file or modifies a existing ROMS grid NetCDF file.
status = c_grid  (Lp,Mp, Gname, NewFile, spherical)
On Input:
Lp:   Number of ρ-point in the ξ-direction
Mp:   Number of ρ-point in the η-direction
Gname:   Grid NetCDF file name (string)
NewFile:   Switch to create a new file (logical, optional, default false)
spherical:   Spherical grid switch (logical, optional, default true)
On Ouput:
status:   Error flag
coarse2fine
Given a coarse resolution ROMS Grid NetCDF file (Ginp), this function creates a finer resolution grid in the region specified by the coarser grid coordinates (Imin, Jmin) and (Imax, Jmax). Notice that (Imin, Jmin), and (Imax, Jmax) indices are in terms of the ψ-points because it actually define the physical boundaries of the refined grid. The grid refinement coefficient is specified with Gfactor.
F = coarse2fine  (Ginp,Gout, Gfactor, Imin, Imax, Jmin, Jmax)
On Input:
Ginp:   Input coarser Grid NetCDF file name (string)
Gout:   Output finer Grid NetCDF file name (string)
Gfactor:   Grid refinement factor (3,5,7,9,11,13,15,...)
Imin:   Coarse grid lower-left I-coordinate (ψ-point)
Imax:   Coarse grid upper-right I-coordinate (ψ-point)
Jmin:   Coarse grid lower-left J-coordinate (ψ-point)
Jmax:   Coarse grid upper-right J-coordinate (ψ-point)
On Ouput:
F:   Fine resolution grid structure (struct array)
fine2coarse
Given a finer resolution ROMS Grid NetCDF file (Ginp), this function creates a coarser resolution grid in the region specified by the finer grid coordinates (Imin, Jmin) and (Imax, Jmax). Notice that (Imin, Jmin), and (Imax, Jmax) indices are in terms of the ψ-points because it actually define the physical boundaries of the coarser grid. The grid coarseness coefficient is specified with Gfactor.
C = fine2coarse  (Ginp,Gout, Gfactor, Imin, Imax, Jmin, Jmax)
On Input:
Ginp:   Input finer Grid NetCDF file name (string)
Gout:   Output coarser Grid NetCDF file name (string)
Gfactor:   Grid coarseness factor (3,5,7,9,11,13,15,...)
Imin:   Finer grid lower-left I-coordinate (ψ-point)
Imax:   Finer grid upper-right I-coordinate (ψ-point)
Jmin:   Finer grid lower-left J-coordinate (ψ-point)
Jmax:   Finer grid upper-right J-coordinate (ψ-point)
On Ouput:
C:   Coarser resolution grid structure (struct array)
grid_extract
Given a larger ROMS Grid NetCDF file (Ginp), this function extracts and creates a sub-domain Grid NetCDF file (Gout) for the sampled region in terms of the larger grid coordinates (Imin, Jmin) and (Imax, Jmax). Notice that the (Imin, Jmin), and (Imax, Jmax) indices are located at ψ-points. They actually define the physical boundaries of the smaller sub-domain grid.
S = grid_extract  (Ginp,Gout, Imin, Imax, Jmin, Jmax)
On Input:
Ginp:   Input coaser Grid NetCDF file name (string) or an existing grid structure (struct array)
Gout:   Output smaller Grid NetCDF file name (string)
Gfactor:   Grid refinement factor (3,5,7,9,11,13,15,...)
Imin:   Larger grid lower-left I-coordinate (ψ-point)
Imax:   Larger grid upper-right I-coordinate (ψ-point)
Jmin:   Larger grid lower-left J-coordinate (ψ-point)
Jmax:   Larger grid upper-right J-coordinate (ψ-point)
On Ouput:
S:   Smaller grid structure (struct array)

Contact Regions and Contact Points Scripts

Initial Condition Scripts

Support Scripts