Grid Processing Scripts

From WikiROMS
Jump to: navigation, search
Matlab: Grid Processing Scripts

This page describes several Matlab scripts to process ROMS grid.



c_contact.m
Creates a new contact points NetCDF file for a ROMS nesting application. The contact point data is written elsewhere using write_contact.m. If the Ndatum argument is not provided, the datum dimension is unlimited.
c_contact  (ncname, spherical, Ngrids, Ndatum)
On Input:
ncname: Output contact points NetCDF file name (string)
spherical: Spherical grid switch (logical)
Ngrids: Number of nested grids
Ndatum: Total number of contact points (optional)
c_grid.m
Creates a new ROMS grid NetCDF file or modifies an existing ROMS grid NetCDF file.
status = c_grid  (Lp, Mp, Gname, NewFile, spherical)
On Input:
Lp: Number of ρ-points in the ξ-direction
Mp: Number of ρ-points 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 Output:
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 defines 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 Output:
F: Fine resolution grid structure (struct array)


contact.m
Sets ROMS nested grid contact points for each contact region. The order of the nested grid file names in the input cell array (Gnames) is important. Set the file names in the order of nesting layers and time-stepping in ROMS. The MaskInterp switch is only relevant when processing the contact region of a refinement grid. The setting of land/sea masking in the contact region is critical. Usually, it is better to linearly interpolate the finer grid ψ- u-, and v-masks from coarser grid than recomputing via uvp_masks. The recomputed masks may be one point smaller or larger. Use the MaskInterp switch to either interpolate (true) or use uvp_masks (false). Recall that we are not modifying the original refined grid mask, just computing the mask in the contact region adjacent to the finer grid from the coarser grid mask. This is only relevant when there are land/sea masking features in any of the refinement grid physical boundaries. If so, the user just needs to experiment with MaskInterp and edit such points during post-processing.
[S, G] = contact  (Gnames, Cname, Lmask, MaskInterp, Lplot)
On Input:
Gnames: Input Grid NetCDF full path file names (cell array)
Cname: Output contact points NetCDF file name (string)
Lmask: Switch to remove contact points over land (logical, optional, default false)
MaskInterp: Switch to interpolate ψ-, u- and v-masks (true) or compute from interpolated ρ-mask (false). The default is false (logical, optional).
Lplot: Switch to plot various contact points figures (logical, optional, default false)
On Output:
S: Nested grids contact points structure (struct array)
G: Nested grids structure (1 x Ngrids struct array)


disp_contact.m
Prints the nested grids contact points unique values for each Contact Region. The contact points structure is rich and this simple function facilitates summarizing the contact points values.
disp_contact  (S)
On Input:
ncname: Contact points 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 defines 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 Output:
C: Coarser resolution grid structure (struct array)


flip_grid.m
Given a ROMS Grid NetCDF file (Ginp), this function creates a new Grid NetCDF file (Gout) with the flipped dimensions, coordinates, and variables.
G = flip_grid  (Ginp, Gout)
On Input:
Ginp: Input ROMS grid NetCDF file name (string)
Gout: Output flipped ROMS grid NetCDF file name (string)
On Output:
Sinp: Flipped Grid structure (struct array)


get_roms_grid.m
Builds or updates a ROMS Grid structure (Gout) containing all the variables associated with the application's horizontal and vertical grids.
Gout = get_roms_grid  (Ginp)
Gout = get_roms_grid  (Ginp, Sinp)
Gout = get_roms_grid  (Ginp, Sinp, Tindex)
Gout = get_roms_grid  (Ginp, Tindex)
On Input:
Ginp: Input ROMS Grid/History NetCDF file/URL name containing all grid variables (string) or an existing grid structure to which the vertical coordinates are added or updated (struct array)
Sinp: ROMS output NetCDF file/URL name from which the vertical coordinates can be determined (string) or a structure containing vertical coordinates stretching parameters (struct array):
Sinp.N number of vertical levels
Sinp.Vtransform vertical transformation equation
Sinp.Vstretching vertical stretching function
Sinp.theta_s surface control parameter
Sinp.theta_b bottom control parameter
Sinp.Tcline surface/bottom stretching width
Sinp.hc stretching width used in ROMS
Tindex Time record index used to process free-surface in the vertical coordinates (scalar; optional):
If Tindex is omitted, zero or empty, it assumes that zeta = 0 yielding unperturbed depths.
Otherwise, the free-surface record in input NetCDF is processed. The free-surface is read from either Ginp (if history file) or Sinp (if provided and history file).
On Output:
Gout: ROMS grid variables structure (struct array)


grid_connections.m
Appends the nested grid connectivity fields between donor and receiver grids for each contact region to the nested grids structure, Sinp.
S = grid_connections  (G, Sinp)
On Input:
G: Nested grids information structure (1 x Ngrids struct array)
Sinp: Nested grids contact points structure (struct array)
On Output:
S: Updated nested grids contact points structure (struct array)


grid_extract.m
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)
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 Output:
S: Smaller grid structure (struct array)


grid_metrics.m
Computes horizontal grid spacing metrics from Grid NetCDF file or Grid structure G.
[pm, pn, dndx, dmde] = grid_metrics  (G, GreatCircle)
On Input:
G: Either a ROMS grid NetCDF file name (string) or ROMS grid structure (struct array)
GreatCircle: Switch indicating how to compute the grid distance (logical): true Great-circle distance or false Cartesian distance
On Output:
pm: Curvilinear coordinate metric in the ξ-direction (1/meters; dx = 1/pm)
pn: Curvilinear coordinate metric in the η-direction (1/meters; dy = 1/pn)
dndx: ξ-derivative of inverse metric factor pn, d(1/pn)/d(ξ) (meter)
dmde: η-derivative of inverse metric factor pm, d(1/pm)/d(η) (meter)


grid_perimeter.m
Creates a structure containing information about nested grids perimeters, boundary edges, and other information parameters.
S = grid_perimeter  (Gnames)
On Input:
Gnames: Input Grid NetCDF full path file names (cell array)
On Output:
Sinp: Beginning of contact points structure (struct array)


plot_contact.m
Plots various figures of contact points for each contact region.
plot_contact  (G, S)
On Input:
G: Nested grids structure (1 x Ngrids struct array)
S: Nested grids contact points structure (struct array)


read_contact.m
Reads in the nested grids contact points NetCDF file and loads data into a structure.
[S, G] = read_contact  (ncname)
On Input:
ncname: Nested grids contact points NetCDF file name (string)
On Output:
S: Nested grids contact points structure (struct array)
G: Nested grids structure (1 x Ngrids struct array)


uniform_grid.m
Given the grid spacing (dx, dy) and number of ψ-points (L, M) in the X- and Y-direction, this function sets the ROMS grid Cartesian coordinates and metrics.
G = uniform_grid  (dx, dy, L, M)
On Input:
dx: Grid spacing in the X-direction (meters; scalar)
dy: Grid spacing in the Y-direction (meters; scalar)
L: Number of ψ-points in the X-direction
M: Number of ψ-points in the Y-direction
On Output:
G: Uniform grid coordinates and metrics (struct array):
G.x_psi X-coordinates at ψ-points (meters)
G.y_psi Y-coordinates at ψ-points (meters)
G.x_rho X-coordinates at ρ-points (meters)
G.y_rho Y-coordinates at ρ-points (meters)
G.x_u X-coordinates at u-points (meters)
G.y_u Y-coordinates at u-points (meters)
G.x_v X-coordinates at v-points (meters)
G.y_v Y-coordinates at v-points (meters)
G.pm X-coordinates metric m (1/meters, 1/dx)
G.pn Y-coordinates metric n (1/meters, 1/dy)
G.dndx Inverse metric, d(1/pn)/d(ξ) (meter)
G.dmde Inverse metric, d(1/pm)/d(η) (meter)


write_contact.m
Writes out the nested grids contact points data generated by contact.m or read_contact.m into a NetCDF.
write_contact   (ncname, S, Lcreate)
On Input:
ncname: Nested grids contact points NetCDF file name (string)
S: Nested grids contact points structure (struct array)
Lcreate: Switch to create a new NetCDF file (logical, optional, default true)