|
|
|
Next: 7.3 Fortran Native I/O:
Up: 7.2 NetCDF I/O: MNC
Previous: 7.2.2 MNC Troubleshooting
Contents
Subsections
The mnc package is a two-level convenience library (or
``wrapper'') for most of the NetCDF Fortran API. Its purpose is to
streamline the user interface to NetCDF by maintaining internal
relations (look-up tables) keyed with strings (or names) and entities
such as NetCDF files, variables, and attributes.
The two levels of the mnc package are:
- Upper level
-
The upper level contains information about two kinds of
associations:
- grid type
- is lookup table indexed with a grid type name.
Each grid type name is associated with a number of dimensions, the
dimension sizes (one of which may be unlimited), and starting and
ending index arrays. The intent is to store all the necessary
size and shape information for the Fortran arrays containing
MITgcm-style ``tile'' variables (that is, a central region
surrounded by a variably-sized ``halo'' or exchange region as
shown in Figures 4.7 and
4.8).
- variable type
- is a lookup table indexed by a variable type
name. For each name, the table contains a reference to a grid
type for the variable and the names and values of various
attributes.
Within the upper level, these associations are not permanently tied
to any particular NetCDF file. This allows the information to be
re-used over multiple file reads and writes.
- Lower level
-
In the lower (or internal) level, associations are stored for NetCDF
files and many of the entities that they contain including
dimensions, variables, and global attributes. All associations are
on a per-file basis. Thus, each entity is tied to a unique NetCDF
file and will be created or destroyed when files are, respectively,
opened or closed.
As a convenience for users, the MNC package includes numerous routines
to aid in the writing of data to NetCDF format. Probably the biggest
convenience is the use of pre-defined ``grid types'' and ``variable
types''. These ``types'' are simply look-up tables that store
dimensions, indicies, attributes, and other information that can all
be retrieved using a single character string.
The ``grid types'' are a way of mapping variables within MITgcm to
NetCDF arrays. Within MITgcm, most spatial variables are defined
using two- or three-dimensional arrays with ``overlap'' regions (see
Figures 4.7, a possible vertical index,
and 4.8) and tile indicies such as the following
``U'' velocity:
_RL uVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
as defined in model/inc/DYNVARS.h
The grid type is a character string that encodes the presence and
types associated with the four possible dimensions. The character
string follows the format
H0_H1_H2__V__T
where the terms H0, H1, H2, V,
T can be almost any combination of the following:
Horizontal |
Vertical |
Time |
H0: location |
H1: dimensions |
H2: halo |
V: location |
T: level |
- |
xy |
Hn |
- |
- |
U |
x |
Hy |
i |
t |
V |
y |
|
c |
|
Cen |
|
|
|
|
Cor |
|
|
|
|
A example list of all pre-defined combinations is contained in the
file
pkg/mnc/pre-defined_grids.txt.
The variable type is an association between a variable type name and the
following items:
Item |
Purpose |
grid type |
defines the in-memory arrangement |
bi,bj dimensions |
tiling indices, if present |
and is used by the mnc_cw_*_[R|W] subroutines for reading
and writing variables.
Writing variables to NetCDF files can be accomplished in as few as two
function calls. The first function call defines a variable type,
associates it with a name (character string), and provides additional
information about the indicies for the tile (bi,bj)
dimensions. The second function call will write the data at, if
necessary, the current time level within the model.
Examples of the initialization calls can be found in the file
model/src/ini_mnc_io.F
where these function calls:
C Create MNC definitions for DYNVARS.h variables
CALL MNC_CW_ADD_VNAME('iter', '-_-_--__-__t', 0,0, myThid)
CALL MNC_CW_ADD_VATTR_TEXT('iter',1,
& 'long_name','iteration_count', myThid)
CALL MNC_CW_ADD_VNAME('model_time', '-_-_--__-__t', 0,0, myThid)
CALL MNC_CW_ADD_VATTR_TEXT('model_time',1,
& 'long_name','Model Time', myThid)
CALL MNC_CW_ADD_VATTR_TEXT('model_time',1,'units','s', myThid)
CALL MNC_CW_ADD_VNAME('U', 'U_xy_Hn__C__t', 4,5, myThid)
CALL MNC_CW_ADD_VATTR_TEXT('U',1,'units','m/s', myThid)
CALL MNC_CW_ADD_VATTR_TEXT('U',1,
& 'coordinates','XU YU RC iter', myThid)
CALL MNC_CW_ADD_VNAME('T', 'Cen_xy_Hn__C__t', 4,5, myThid)
CALL MNC_CW_ADD_VATTR_TEXT('T',1,'units','degC', myThid)
CALL MNC_CW_ADD_VATTR_TEXT('T',1,'long_name',
& 'potential_temperature', myThid)
CALL MNC_CW_ADD_VATTR_TEXT('T',1,
& 'coordinates','XC YC RC iter', myThid)
initialize four VNAMEs and add one or more NetCDF
attributes to each.
The four variables defined above are subsequently written at specific
time steps within
model/src/write_state.F
using the function calls:
C Write dynvars using the MNC package
CALL MNC_CW_SET_UDIM('state', -1, myThid)
CALL MNC_CW_I_W('I','state',0,0,'iter', myIter, myThid)
CALL MNC_CW_SET_UDIM('state', 0, myThid)
CALL MNC_CW_RL_W('D','state',0,0,'model_time',myTime, myThid)
CALL MNC_CW_RL_W('D','state',0,0,'U', uVel, myThid)
CALL MNC_CW_RL_W('D','state',0,0,'T', theta, myThid)
While it is easiest to write variables within typical 2D and 3D fields
where all data is known at a given time, it is also possible to write
fields where only a portion (eg. a ``slab'' or ``slice'') is
known at a given instant. An example is provided within
pkg/mom_vecinv/mom_vecinv.F
where an offset vector is used:
IF (useMNC .AND. snapshot_mnc) THEN
CALL MNC_CW_RL_W_OFFSET('D','mom_vi',bi,bj, 'fV', uCf,
& offsets, myThid)
CALL MNC_CW_RL_W_OFFSET('D','mom_vi',bi,bj, 'fU', vCf,
& offsets, myThid)
ENDIF
to write a 3D field one depth slice at a time.
Each element in the offset vector corresponds (in order) to the
dimensions of the ``full'' (or virtual) array and specifies which are
known at the time of the call. A zero within the offset array means
that all values along that dimension are available while a positive
integer means that only values along that index of the dimension are
available. In all cases, the matrix passed is assumed to start (that
is, have an in-memory structure) coinciding with the start of the
specified slice. Thus, using this offset array mechanism, a slice
can be written along any single dimension or combinations of
dimensions.
Next: 7.3 Fortran Native I/O:
Up: 7.2 NetCDF I/O: MNC
Previous: 7.2.2 MNC Troubleshooting
Contents
mitgcm-support@mitgcm.org
Copyright © 2006
Massachusetts Institute of Technology |
Last update 2011-01-09 |
|
|