1 |
% $Header: /u/gcmpack/manual/part6/mnc.tex,v 1.15 2005/07/18 14:00:00 edhill Exp $ |
2 |
% $Name: $ |
3 |
|
4 |
\section{NetCDF I/O Integration: MNC} |
5 |
\label{sec:pkg:mnc} |
6 |
\begin{rawhtml} |
7 |
<!-- CMIREDIR:package_mnc: --> |
8 |
\end{rawhtml} |
9 |
|
10 |
The \texttt{mnc} package is a set of convenience routines written to |
11 |
expedite the process of creating, appending, and reading NetCDF files. |
12 |
NetCDF is an increasingly popular self-describing file format |
13 |
\cite{rew:97} intended primarily for scientific data sets. An |
14 |
extensive collection of NetCDF reference papers, user guides, |
15 |
software, FAQs, and other information can be obtained from UCAR's web |
16 |
site at: |
17 |
\begin{rawhtml} <A href="http://www.unidata.ucar.edu/packages/netcdf/"> \end{rawhtml} |
18 |
\begin{verbatim} |
19 |
http://www.unidata.ucar.edu/packages/netcdf/ |
20 |
\end{verbatim} |
21 |
\begin{rawhtml} </A> \end{rawhtml} |
22 |
|
23 |
Since it is a ``wrapper'' for netCDF, MNC depends upon the Fortran-77 |
24 |
interface included with the standard netCDF v3.x library which is |
25 |
often called \texttt{libnetcdf.a}. Please contact your local systems |
26 |
administrators or the |
27 |
\begin{rawhtml} <A href="mailto:mitgcm-support@mitgcm.org"> \end{rawhtml} |
28 |
MITgcm-support |
29 |
\begin{rawhtml} </A> \end{rawhtml} |
30 |
list for help building and installing netCDF for your particular |
31 |
platform. |
32 |
|
33 |
|
34 |
\subsection{Using MNC} |
35 |
|
36 |
\subsubsection{MNC Configuration} |
37 |
|
38 |
As with all MITgcm packages, MNC can be turned on or off at compile time |
39 |
using the \texttt{packages.conf} file or the \texttt{genmake2} |
40 |
\texttt{-enable=mnc} or \texttt{-disable=mnc} switches. |
41 |
|
42 |
While MNC is likely to work ``as is'', there are a few compile--time |
43 |
constants that may need to be increased for simulations that employ |
44 |
large numbers of tiles within each process. Note that the important |
45 |
quantity is the maximum number of tiles \textbf{per process}. Since |
46 |
MPI configurations tend to distribute large numbers of tiles over |
47 |
relatively large numbers of MPI processes, these constants will rarely |
48 |
need to be increased. |
49 |
|
50 |
If MNC runs out of space within its ``lookup'' tables during a |
51 |
simulation, then it will provide an error message along with a |
52 |
recommendation of which parameter to increase. The parameters are all |
53 |
located within \filelink{pkg/mnc/mnc\_common.h}{pkg-mnc-mnc_common.h} |
54 |
and the ones that may need to be increased are: |
55 |
|
56 |
\begin{center} |
57 |
{\footnotesize |
58 |
\begin{tabular}[htb]{|l|r|l|}\hline |
59 |
\textbf{Name} & |
60 |
\textbf{Default} & \textbf{Description} \\\hline |
61 |
& & \\ |
62 |
\texttt{MNC\_MAX\_ID} & 1000 & |
63 |
\textbf{IDs for various low-level entities} \\ |
64 |
\texttt{MNC\_MAX\_INFO} & 400 & |
65 |
\textbf{IDs (mostly for object sizes)} \\ |
66 |
\texttt{MNC\_CW\_MAX\_I} & 150 & |
67 |
\textbf{IDs for the ``wrapper'' layer} \\\hline |
68 |
\end{tabular} |
69 |
} |
70 |
\end{center} |
71 |
|
72 |
In those rare cases where MNC ``out-of-memory'' error messages are |
73 |
encountered, it is a good idea to increase the too-small parameter by |
74 |
a factor of \textbf{2--10} in order to avoid wasting time on an |
75 |
iterative compile--test sequence. |
76 |
|
77 |
|
78 |
\subsubsection{MNC Inputs} |
79 |
|
80 |
Like most MITgcm packages, all of MNC can be turned on/off at runtime |
81 |
using a single flag in \texttt{data.pkg} |
82 |
\begin{center} |
83 |
{\footnotesize |
84 |
\begin{tabular}[htb]{|l|c|l|l|}\hline |
85 |
\textbf{Name} & \textbf{T} & |
86 |
\textbf{Default} & \textbf{Description} \\\hline |
87 |
& & & \\ |
88 |
\texttt{useMNC} & L & \texttt{.FALSE.} & |
89 |
overall MNC ON/OFF switch \\\hline |
90 |
\end{tabular} |
91 |
} |
92 |
\end{center} |
93 |
|
94 |
One important MNC--related flag is present in the main \texttt{data} |
95 |
namelist file in the \texttt{PARM03} section and it is: |
96 |
\begin{center} |
97 |
{\footnotesize |
98 |
\begin{tabular}[htb]{|l|c|l|l|}\hline |
99 |
\textbf{Name} & \textbf{T} & |
100 |
\textbf{Default} & \textbf{Description} \\\hline |
101 |
& & & \\ |
102 |
\texttt{outputTypesInclusive} & L & \texttt{.FALSE.} & |
103 |
use all available output ``types'' \\\hline |
104 |
\end{tabular} |
105 |
} |
106 |
\end{center} |
107 |
which specifies that turning on MNC for a particular type of output |
108 |
should not simultaneously turn off the default output method as it |
109 |
normally does. Usually, this option is only used for debugging |
110 |
purposes since it is inefficient to write output types using both MNC |
111 |
and MDSIO or ASCII output. This option can also be helpful when |
112 |
transitioning from MDSIO to MNC since the output can be readily |
113 |
compared. |
114 |
|
115 |
For run-time configuration, most of the MNC--related model parameters |
116 |
are contained within a Fortran namelist file called |
117 |
\texttt{data.mnc}. The availabe parameters currently include: |
118 |
\begin{center} |
119 |
{\footnotesize |
120 |
\begin{tabular}[htb]{|l|c|l|l|}\hline |
121 |
\textbf{Name} & \textbf{T} & |
122 |
\textbf{Default} & \textbf{Description} \\\hline |
123 |
& & & \\ |
124 |
\texttt{mnc\_use\_outdir} & L & \texttt{.FALSE.} & |
125 |
create a directory for output \\ |
126 |
\ \ \texttt{mnc\_outdir\_str} & S & \texttt{'mnc\_'} & |
127 |
output directory name \\ |
128 |
\ \ \texttt{mnc\_outdir\_date} & L & \texttt{.FALSE.} & |
129 |
embed date in the outdir name \\ |
130 |
\ \ \texttt{mnc\_outdir\_num} & L & \texttt{.FALSE.} & |
131 |
optional \\ |
132 |
\texttt{pickup\_write\_mnc} & L & \texttt{.FALSE.} & |
133 |
use MNC to write pickup files \\ |
134 |
\texttt{pickup\_read\_mnc} & L & \texttt{.FALSE.} & |
135 |
use MNC to read pickup files \\ |
136 |
\texttt{mnc\_use\_indir} & L & \texttt{.FALSE.} & |
137 |
use a directory (path) for input \\ |
138 |
\ \ \texttt{mnc\_indir\_str} & S & \texttt{''} & |
139 |
input directory (or path) name \\ |
140 |
\texttt{snapshot\_mnc} & L & \texttt{.FALSE.} & |
141 |
write \texttt{snapshot} output w/MNC \\ |
142 |
\texttt{monitor\_mnc} & L & \texttt{.FALSE.} & |
143 |
write \texttt{monitor} output w/MNC \\ |
144 |
\texttt{timeave\_mnc} & L & \texttt{.FALSE.} & |
145 |
write \texttt{timeave} output w/MNC \\ |
146 |
\texttt{autodiff\_mnc} & L & \texttt{.FALSE.} & |
147 |
write \texttt{autodiff} output w/MNC \\ |
148 |
\texttt{mnc\_max\_fsize} & R & 2.1e+09 & |
149 |
max allowable file size \\ |
150 |
\texttt{readgrid\_mnc} & L & \texttt{.FALSE.} & |
151 |
read grid quantities using MNC \\ |
152 |
\texttt{mnc\_echo\_gvtypes} & L & \texttt{.FALSE.} & |
153 |
list pre-defined ``types'' (debug) \\\hline |
154 |
\end{tabular} |
155 |
} |
156 |
\end{center} |
157 |
|
158 |
Unlike the older MDSIO method, MNC has the ability to create or use |
159 |
existing output directories. If either \texttt{mnc\_outdir\_date} or |
160 |
\texttt{mnc\_outdir\_num} is true, then MNC will try to create |
161 |
directories on a \textit{PER PROCESS} basis for its output. This |
162 |
means that a single directory will be created for a non-MPI run and |
163 |
multiple directories (one per MPI process) will be created for an MPI |
164 |
run. This approach was chosen since it works safely on both shared |
165 |
global file systems (such as NFS and AFS) and on local |
166 |
(per-compute-node) file systems. And if both |
167 |
\texttt{mnc\_outdir\_date} and \texttt{mnc\_outdir\_num} are false, |
168 |
then the MNC package will assume that the directory specified in |
169 |
\texttt{mnc\_outdir\_str} already exists and will use it. This allows |
170 |
the user to create and specify directories outside of the model. |
171 |
|
172 |
For input, MNC can use a single global input directory. This is a |
173 |
just convenience that allows MNC to gather all of its input files from a |
174 |
path other than the current working directory. As with MDSIO, the |
175 |
default is to use the current working directory. |
176 |
|
177 |
The flags \texttt{snapshot\_mnc}, \texttt{monitor\_mnc}, |
178 |
\texttt{timeave\_mnc}, and \texttt{autodiff\_mnc} allow the user to |
179 |
turn on MNC for particular ``types'' of output. If a type is |
180 |
selected, then MNC will be used for all output that matches that type. |
181 |
This applies to output from the main model and from all of the |
182 |
optional MITgcm packages. Mostly, the names used here correspond to |
183 |
the names used for the output frequencies in the main \texttt{data} |
184 |
namelist file. |
185 |
|
186 |
The \texttt{mnc\_max\_fsize} parameter is a convenience added to help |
187 |
users work around common file size limitations. On many computer |
188 |
systems, either the opterating system, the file system(s), and/or the |
189 |
netCDF libraries are unable to handle files greater than two or four |
190 |
gigabytes in size. The MNC package is able to work within this |
191 |
limitation by creating new files which grow along the netCDF |
192 |
``unlimited'' (usually, time) dimension. The default value for this |
193 |
parameter is just slightly less than 2GB which is safe on virtually |
194 |
all operating systems. Essentially, this feature is a way to |
195 |
intelligently and automatically split files output along the unlimited |
196 |
dimension. On systems that support large file sizes, these splits can |
197 |
be readily concatenated (that is, un-done) using tools such as the |
198 |
netCDF Operators (with \texttt{ncrcat}) which is available at: |
199 |
\begin{rawhtml} <A href="http://nco.sourceforge.net/"> \end{rawhtml} |
200 |
\begin{verbatim} |
201 |
http://nco.sourceforge.net/ |
202 |
\end{verbatim} |
203 |
\begin{rawhtml} </A> \end{rawhtml} |
204 |
|
205 |
Additional MNC--related parameters may be contained within each |
206 |
package. Please see the individual packages for descriptions of their |
207 |
use of MNC. |
208 |
|
209 |
|
210 |
\subsubsection{MNC Output} |
211 |
|
212 |
Depending upon the flags used, MNC will produce zero or more |
213 |
directories containing one or more netCDF files as output. These |
214 |
files are either mostly or entirely compliant with the netCDF ``CF'' |
215 |
convention (v1.0) and any conformance issues will be fixed over time. |
216 |
The patterns used for file names are: |
217 |
\begin{center} |
218 |
\texttt{BASENAME.nIter0.tileNum.seqNum.nc} |
219 |
\end{center} |
220 |
and an example is: |
221 |
\begin{center} |
222 |
\texttt{grid.0000000000.000001.0000.nc} |
223 |
\end{center} |
224 |
where \texttt{BASENAME} is the name selected to represent a set of |
225 |
variables written together, \texttt{nIter0} is the starting iteration |
226 |
number as specified in the main \texttt{data} namelist input file and |
227 |
written in a zero-filled 10-digit format, \texttt{tileNum} is the |
228 |
six-digit zero-filled tile number, \texttt{seqnum} is a four-digit |
229 |
zero-filled sequence number used when maximum allowable files sizes |
230 |
are too small to contain all of the output for a particular type |
231 |
within one run (new files are created with sequential numbers as files |
232 |
reach the maximum file size limit), and \texttt{.nc} is the file |
233 |
suffix specified by the current netCDF ``CF'' conventions. |
234 |
|
235 |
Some example \texttt{BASENAME} values are: |
236 |
\begin{description} |
237 |
\item[grid] contains the variables that describe the various grid |
238 |
constants related to locations, lengths, areas, etc. |
239 |
\item[state] contains the variables output at the snapshot or |
240 |
\texttt{dumpFreq} time frequency |
241 |
\item[pickup.ckptA, pickup.ckptB] are the ``rolling'' checkpoint files |
242 |
\item[tave] contains the time-averaged quantities from the main model |
243 |
\end{description} |
244 |
|
245 |
All MNC output is currently done in a ``file-per-tile'' fashion since |
246 |
most NetCDF v3.x implementions cannot write safely within MPI or |
247 |
multi-threaded environments. This tiling is done in a global fashion |
248 |
and the tile numbers are appended to the base names as described |
249 |
above. Some scripts to manipulate MNC output are available at |
250 |
\texttt{MITgcm/utils/matlab/} which includes a spatial ``assembly'' |
251 |
script called \texttt{MITgcm/utils/matlab/mnc\_assembly.m}. |
252 |
|
253 |
More general manipulations can be performed on netCDF files with |
254 |
\begin{rawhtml} <A href="http://nco.sourceforge.net"> \end{rawhtml} |
255 |
\begin{verbatim} |
256 |
the NetCDF Operators (``NCO'') |
257 |
at http://nco.sourceforge.net |
258 |
\end{verbatim} |
259 |
\begin{rawhtml} </A> \end{rawhtml} |
260 |
or with |
261 |
\begin{rawhtml} <A href=''http://www.mpimet.mpg.de/~cdo/"> \end{rawhtml} |
262 |
\begin{verbatim} |
263 |
the Climate Data Operators (``CDO'') |
264 |
at http://www.mpimet.mpg.de/~cdo/ |
265 |
\end{verbatim} |
266 |
\begin{rawhtml} </A> \end{rawhtml} |
267 |
|
268 |
Unlike the older MDSIO routines, MNC reads and writes variables on |
269 |
different ``grids'' depending upon their location on, for instance, an |
270 |
Arakawa C--grid. The following table provides examples: |
271 |
\begin{center} |
272 |
{\footnotesize |
273 |
\begin{tabular}[htb]{|l|c|c|c|}\hline |
274 |
\textbf{Name} & \textbf{C--grid location} & |
275 |
\textbf{\# in X} & \textbf{\# in Y} \\\hline |
276 |
Temperature & mass & \texttt{sNx} & \texttt{sNy} \\ |
277 |
Salinity & mass & \texttt{sNx} & \texttt{sNy} \\ |
278 |
U velocity & U & \texttt{sNx+1} & \texttt{sNy} \\ |
279 |
V velocity & V & \texttt{sNx} & \texttt{sNy+1} \\ |
280 |
Vorticity & vorticity & \texttt{sNx+1} & \texttt{sNy+1} \\\hline |
281 |
\end{tabular} |
282 |
} |
283 |
\end{center} |
284 |
and the intent is two--fold: |
285 |
\begin{enumerate} |
286 |
\item For some grid topologies it is impossible to output all |
287 |
quantities using only \texttt{sNx,sNy} arrays for every tile. Two |
288 |
examples of this failure are the missing corners problem for |
289 |
vorticity values on the cubesphere and the velocity edge values for |
290 |
some open--boundary domains. |
291 |
\item Writing quantities located on velocity or vorticity points with |
292 |
the above scheme introduces a very small data redundancy. However, |
293 |
any slight inconvenience is easily offset by the ease with which one |
294 |
can, on every individual tile, interpolate these values to mass |
295 |
points without having to perform an ``exchange'' (or |
296 |
``halo-filling'') operation to collect the values from neighboring |
297 |
tiles. This makes the most common post--processing operations much |
298 |
easier to implement. |
299 |
\end{enumerate} |
300 |
|
301 |
|
302 |
\subsection{MNC Troubleshooting} |
303 |
|
304 |
\subsubsection{Build Troubleshooting} |
305 |
|
306 |
In order to build MITgcm with MNC enabled, the netCDF v3.x Fortran-77 |
307 |
(not Fortran-90) library must be available. This library is compposed |
308 |
of a single header file (called \texttt{netcdf.inc}) and a single |
309 |
library file (usually called \texttt{libnetcdf.a}) and it must be |
310 |
built with the same compiler (or a binary-compatible compiler) with |
311 |
compatible compiler options as the one used to build MITgcm. |
312 |
|
313 |
For more details concerning the netCDF build and install process, |
314 |
please visit the netCDF home page at: |
315 |
\begin{rawhtml} <A href="http://www.unidata.ucar.edu/packages/netcdf/"> \end{rawhtml} |
316 |
\begin{verbatim} |
317 |
http://www.unidata.ucar.edu/packages/netcdf/ |
318 |
\end{verbatim} |
319 |
\begin{rawhtml} </A> \end{rawhtml} |
320 |
which includes an extensive list of known--good netCDF configurations |
321 |
for various platforms |
322 |
|
323 |
\subsubsection{Runtime Troubleshooting} |
324 |
|
325 |
Please be aware of the following: |
326 |
|
327 |
\begin{itemize} |
328 |
\item As a safety feature, the MNC package does not, by default, allow |
329 |
pre-existing files to be appended to or overwritten. This is in |
330 |
contrast to the older MDSIO package which will, without any warning, |
331 |
overwrite existing files. If MITgcm aborts with an error message |
332 |
about the inability to open or write to a netCDF file, please check |
333 |
\textbf{first} whether you are attempting to overwrite files from a |
334 |
previous run. |
335 |
|
336 |
\item The constraints placed upon the ``unlimited'' (or ``record'') |
337 |
dimension inherent with NetCDF v3.x make it very inefficient to put |
338 |
variables written at potentially different intervals within the same |
339 |
file. For this reason, MNC output is split into groups of files |
340 |
which attempt to reflect the nature of their content. |
341 |
|
342 |
\item On many systems, netCDF has practical file size limits on the |
343 |
order of 2--4GB (the maximium memory addressable with 32bit pointers |
344 |
or pointer differences) due to a lack of operating system, compiler, |
345 |
and/or library support. The latest revisions of netCDF v3.x have |
346 |
large file support and, on some operating systems, file sizes are |
347 |
only limited by available disk space. |
348 |
|
349 |
\item There is an 80 character limit to the total length of all file |
350 |
names. This limit includes the directory (or path) since paths and |
351 |
file names are internally appended. Generally, file names will not |
352 |
exceed the limit and paths can usually be shortened using, for |
353 |
example, soft links. |
354 |
|
355 |
\item MNC does not (yet) provide a mechanism for reading information |
356 |
from a single ``global'' file as can be done with the MDSIO |
357 |
package. This is in progress. |
358 |
\end{itemize} |
359 |
|
360 |
|
361 |
\subsection{MNC Internals} |
362 |
|
363 |
The \texttt{mnc} package is a two-level convenience library (or |
364 |
``wrapper'') for most of the NetCDF Fortran API. Its purpose is to |
365 |
streamline the user interface to NetCDF by maintaining internal |
366 |
relations (look-up tables) keyed with strings (or names) and entities |
367 |
such as NetCDF files, variables, and attributes. |
368 |
|
369 |
The two levels of the \texttt{mnc} package are: |
370 |
\begin{description} |
371 |
|
372 |
\item[Upper level] \ |
373 |
|
374 |
The upper level contains information about two kinds of |
375 |
associations: |
376 |
\begin{description} |
377 |
\item[grid type] is lookup table indexed with a grid type name. |
378 |
Each grid type name is associated with a number of dimensions, the |
379 |
dimension sizes (one of which may be unlimited), and starting and |
380 |
ending index arrays. The intent is to store all the necessary |
381 |
size and shape information for the Fortran arrays containing |
382 |
MITgcm--style ``tile'' variables (that is, a central region |
383 |
surrounded by a variably-sized ``halo'' or exchange region as |
384 |
shown in Figures \ref{fig:communication_primitives} and |
385 |
\ref{fig:tiling-strategy}). |
386 |
|
387 |
\item[variable type] is a lookup table indexed by a variable type |
388 |
name. For each name, the table contains a reference to a grid |
389 |
type for the variable and the names and values of various |
390 |
attributes. |
391 |
\end{description} |
392 |
|
393 |
Within the upper level, these associations are not permanently tied |
394 |
to any particular NetCDF file. This allows the information to be |
395 |
re-used over multiple file reads and writes. |
396 |
|
397 |
\item[Lower level] \ |
398 |
|
399 |
In the lower (or internal) level, associations are stored for NetCDF |
400 |
files and many of the entities that they contain including |
401 |
dimensions, variables, and global attributes. All associations are |
402 |
on a per-file basis. Thus, each entity is tied to a unique NetCDF |
403 |
file and will be created or destroyed when files are, respectively, |
404 |
opened or closed. |
405 |
|
406 |
\end{description} |
407 |
|
408 |
|
409 |
\subsubsection{MNC Grid--Types and Variable--Types} |
410 |
|
411 |
As a convenience for users, the MNC package includes numerous routines |
412 |
to aid in the writing of data to NetCDF format. Probably the biggest |
413 |
convenience is the use of pre-defined ``grid types'' and ``variable |
414 |
types''. These ``types'' are simply look-up tables that store |
415 |
dimensions, indicies, attributes, and other information that can all |
416 |
be retrieved using a single character string. |
417 |
|
418 |
The ``grid types'' are a way of mapping variables within MITgcm to |
419 |
NetCDF arrays. Within MITgcm, most spatial variables are defined |
420 |
using two-- or three--dimensional arrays with ``overlap'' regions (see |
421 |
Figures \ref{fig:communication_primitives}, a possible vertical index, |
422 |
and \ref{fig:tiling-strategy}) and tile indicies such as the following |
423 |
``U'' velocity: |
424 |
\begin{verbatim} |
425 |
_RL uVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
426 |
\end{verbatim} |
427 |
as defined in \filelink{model/inc/DYNVARS.h}{model-inc-DYNVARS.h} |
428 |
|
429 |
The grid type is a character string that encodes the presence and |
430 |
types associated with the four possible dimensions. The character |
431 |
string follows the format |
432 |
\begin{center} |
433 |
\texttt{H0\_H1\_H2\_\_V\_\_T} |
434 |
\end{center} |
435 |
where the terms \textit{H0}, \textit{H1}, \textit{H2}, \textit{V}, |
436 |
\textit{T} can be almost any combination of the following: |
437 |
\begin{center} |
438 |
\begin{tabular}[h]{|ccc|c|c|}\hline |
439 |
\multicolumn{3}{|c|}{Horizontal} & Vertical & Time \\ |
440 |
\textbf{H0}: location & \textbf{H1}: dimensions & \textbf{H2}: halo |
441 |
& \textbf{V}: location & \textbf{T}: level \\\hline |
442 |
\texttt{-} & xy & Hn & \texttt{-} & \texttt{-} \\ |
443 |
U & x & Hy & i & t \\ |
444 |
V & y & & c & \\ |
445 |
Cen & & & & \\ |
446 |
Cor & & & & \\\hline |
447 |
\end{tabular} |
448 |
\end{center} |
449 |
A example list of all pre-defined combinations is contained in the |
450 |
file |
451 |
\begin{center} |
452 |
\texttt{pkg/mnc/pre-defined\_grids.txt}. |
453 |
\end{center} |
454 |
|
455 |
The variable type is an association between a variable type name and the |
456 |
following items: |
457 |
\begin{center} |
458 |
\begin{tabular}[h]{|l|l|}\hline |
459 |
\textbf{Item} & \textbf{Purpose} \\\hline |
460 |
grid type & defines the in-memory arrangement \\ |
461 |
\texttt{bi,bj} dimensions & tiling indices, if present \\\hline |
462 |
\end{tabular} |
463 |
\end{center} |
464 |
and is used by the \texttt{mnc\_cw\_*\_[R|W]} subroutines for reading |
465 |
and writing variables. |
466 |
|
467 |
|
468 |
\subsubsection{Using MNC: Examples} |
469 |
|
470 |
Writing variables to NetCDF files can be accomplished in as few as two |
471 |
function calls. The first function call defines a variable type, |
472 |
associates it with a name (character string), and provides additional |
473 |
information about the indicies for the tile (\texttt{bi},\texttt{bj}) |
474 |
dimensions. The second function call will write the data at, if |
475 |
necessary, the current time level within the model. |
476 |
|
477 |
Examples of the initialization calls can be found in the file |
478 |
\filelink{model/src/ini\_mnc\_io.F}{model-src-ini_mnc_io.F} |
479 |
where these function calls: |
480 |
{\footnotesize |
481 |
\begin{verbatim} |
482 |
C Create MNC definitions for DYNVARS.h variables |
483 |
CALL MNC_CW_ADD_VNAME('iter', '-_-_--__-__t', 0,0, myThid) |
484 |
CALL MNC_CW_ADD_VATTR_TEXT('iter',1, |
485 |
& 'long_name','iteration_count', myThid) |
486 |
|
487 |
CALL MNC_CW_ADD_VNAME('model_time', '-_-_--__-__t', 0,0, myThid) |
488 |
CALL MNC_CW_ADD_VATTR_TEXT('model_time',1, |
489 |
& 'long_name','Model Time', myThid) |
490 |
CALL MNC_CW_ADD_VATTR_TEXT('model_time',1,'units','s', myThid) |
491 |
|
492 |
CALL MNC_CW_ADD_VNAME('U', 'U_xy_Hn__C__t', 4,5, myThid) |
493 |
CALL MNC_CW_ADD_VATTR_TEXT('U',1,'units','m/s', myThid) |
494 |
CALL MNC_CW_ADD_VATTR_TEXT('U',1, |
495 |
& 'coordinates','XU YU RC iter', myThid) |
496 |
|
497 |
CALL MNC_CW_ADD_VNAME('T', 'Cen_xy_Hn__C__t', 4,5, myThid) |
498 |
CALL MNC_CW_ADD_VATTR_TEXT('T',1,'units','degC', myThid) |
499 |
CALL MNC_CW_ADD_VATTR_TEXT('T',1,'long_name', |
500 |
& 'potential_temperature', myThid) |
501 |
CALL MNC_CW_ADD_VATTR_TEXT('T',1, |
502 |
& 'coordinates','XC YC RC iter', myThid) |
503 |
\end{verbatim} |
504 |
} |
505 |
{\noindent initialize four \texttt{VNAME}s and add one or more NetCDF |
506 |
attributes to each.} |
507 |
|
508 |
The four variables defined above are subsequently written at specific |
509 |
time steps within |
510 |
\filelink{model/src/write\_state.F}{model-src-write_state.F} |
511 |
using the function calls: |
512 |
{\footnotesize |
513 |
\begin{verbatim} |
514 |
C Write dynvars using the MNC package |
515 |
CALL MNC_CW_SET_UDIM('state', -1, myThid) |
516 |
CALL MNC_CW_I_W('I','state',0,0,'iter', myIter, myThid) |
517 |
CALL MNC_CW_SET_UDIM('state', 0, myThid) |
518 |
CALL MNC_CW_RL_W('D','state',0,0,'model_time',myTime, myThid) |
519 |
CALL MNC_CW_RL_W('D','state',0,0,'U', uVel, myThid) |
520 |
CALL MNC_CW_RL_W('D','state',0,0,'T', theta, myThid) |
521 |
\end{verbatim} |
522 |
} |
523 |
|
524 |
While it is easiest to write variables within typical 2D and 3D fields |
525 |
where all data is known at a given time, it is also possible to write |
526 |
fields where only a portion (\textit{eg.} a ``slab'' or ``slice'') is |
527 |
known at a given instant. An example is provided within |
528 |
\filelink{pkg/mom\_vecinv/mom\_vecinv.F}{pkg-mom_vecinv-mom_vecinv.F} |
529 |
where an offset vector is used: {\footnotesize |
530 |
\begin{verbatim} |
531 |
IF (useMNC .AND. snapshot_mnc) THEN |
532 |
CALL MNC_CW_RL_W_OFFSET('D','mom_vi',bi,bj, 'fV', uCf, |
533 |
& offsets, myThid) |
534 |
CALL MNC_CW_RL_W_OFFSET('D','mom_vi',bi,bj, 'fU', vCf, |
535 |
& offsets, myThid) |
536 |
ENDIF |
537 |
\end{verbatim} |
538 |
} |
539 |
to write a 3D field one depth slice at a time. |
540 |
|
541 |
Each element in the offset vector corresponds (in order) to the |
542 |
dimensions of the ``full'' (or virtual) array and specifies which are |
543 |
known at the time of the call. A zero within the offset array means |
544 |
that all values along that dimension are available while a positive |
545 |
integer means that only values along that index of the dimension are |
546 |
available. In all cases, the matrix passed is assumed to start (that |
547 |
is, have an in-memory structure) coinciding with the start of the |
548 |
specified slice. Thus, using this offset array mechanism, a slice |
549 |
can be written along any single dimension or combinations of |
550 |
dimensions. |
551 |
|