Demo: Code to read and write NetCDF in
a model driver
Zhichang Guo & Paul Dirmeyer
Due to the need to describe the complex nature of land surface processes,
land surface schemes have many input/output variables and parameters. Modelers
have to expend a lot of effort to work on data input/output. For example,
certain decisions have to be made to deal with various configurations of
input variables based on their availabilities. Here, I will introduce several
programs developed and publicly provided by our group, which might be helpful
for model I/O parts.
1. Two modules for NetCDF handling
2. A sample program and demo
Two modules for F90 NetCDF handling:
|The input model has several functions:
drv_readcon - This routine reads the run control
deck, which contains all of the run-specific parameters, file paths
(or URLs for DODS use), etc. that are controlled from outside the model.
All input data files (forcing, BCs) are listed here, as well as names for
drv_almaparse - This is the primary means of opening, checking and
cataloging contents of NetCDF input files for the LSS driver. The
standard table is read by this program. All required model inputs
are resolved and mapped to input files automatically - the user need not
worry about what files contain which variables.
drv_readnf_mod - generic reading of NetCDF data by arbitrary variable
name from any of multiple input files. Handles grids and gathered
(GDT) data sets.
|The output model has several functions:
drv_table_mod - This routine reads the ASCII output
tables to determine frequency, location and selection of output variables.
drv_almagen - Generates all of the ALMA-standard metadata for NetCDF
drv_almaout - Coordinates the data output, based on the output tables.
drv_writenf_mod - Module for generic writing of NetCDF output.
Advantages of using these two modules:
All information of ALMA variables found in input files are collected, and
certain quality checks can be done. Given various possible configurations
of available input variables, this information is very helpful for making
decisions to deal with those situations.
Generic NetCDF input/output subroutines.
Gridded data can be read in, and automatically gathered.
External table used to control model output
A sample program:
Tables to use for ALMA/NetCDF output generation:
||This is the table of ALMA output variables, with ranges, etc. specified
per ALMA standards. The table allows for specification of the frequency
of output (at the forcing interval, or at an averaging interval specified
in the control deck.
||This table specifies latitudes and longitudes where Grid Point Histories
(a.k.a. MOLTS) should be saved. The model grid box encompassing the
location is used in drv_table_mod
(i.e. no interpolation of model results to the exact grid point is performed)
Other useful routines:
drv_timestamp - Converts
between Y/M/D H:M:S and seconds from arbitrary origin time set at start
drv_postproc - fills
ALMA output registers with model results. This code is very SSiB
specific, but it is structured just like the ALMA output tables (V1.2 in
this case), and would make a very good template to follow to produce the
data for the drv_output_mod module described
drv_finterp - This
routine performs time interpolation of atmospheric forcing data (adtt
seconds period) to dtt seconds model time-step
for one forcing data interval. Interpolation is performed based on the
value of trp_flag:
"L" or "l" = value represents average over interval ending at current time
"N" or "n" = value represents average over interval beginning at current
"C" or "c" = value represents average over interval centered on current
"I" or "i" = instantaneous value at current time (linear interpolation)
"P" or "p" = PDF disaggregation applied in time (e.g. for precip)
"0" (zero) = no interpolation, centered on current time
Otherwise = no interpolation, applied beginning at current time
Global Soil Wetness Project
4041 Powder Mill Road, Suite 302
Calverton, MD 20705-3106
A portion of GSWP2 is supported by the National Aeronautics
and Space Administration (NAG5-11579).