This document provides an example to incorporate the netCDF library in a source code of a land surface model. The model executable treats the number of grid boxes as a map, allowing a clean separation between I/O, model calculations and writing of results.
In the code listings below, only the netCDF reading/writing routines are included. A series of dots represents code that is model specific and taken out here for clarity. A series of dots followed by (etc) represents a repetition of a similar sequence of netCDF code found somewhere earlier in the example. A standard routine cdf_encode has been designed (but not tested) that defines a new 3D variable in a netCDF output field. Similar routines could be made for 4D fields (for instance, soil temperatures), but that has not been included in this example.
The code in the examples below is Fortran90 fixed format. Implicit type is used throughout, which implies that, in order to have a clean description of the code you should add, at the top of each routine, the declaration statements of logical and character array/scalars. Compilation on double precision is assumed. Output precision can be specified (either NCFLOAT or NCDOUBLE).
The code uses some Fortran90 intrinsic procedures, e.g. those that pack/unpack an array ((UN)PACK). The command
A1 = PACK (A2, LMASK)
creates a new array A1 containing only the results of A2 for cells where the corresponding elements of logical array LMASK are true. Thus, the size of A1 is smaller or equal to the size of A2, depending on the number of elements in LMASK that are true. The UNPACK command does the reverse.
For questions or remarks please refer to Bart van den Hurk (KNMI), hurkvd@knmi.nl.
main | main routine | |||
setup | setting of constants, timing etc | |||
setup_pout | setup of netCDF output files with prognostic quantities | |||
setup_dout | setup of netCDF output files with diagnostic quantities | |||
setup_phys | setup of physical parameters etc. | |||
initialize | initialization of variables | |||
rd_coor | read input coordinates | |||
rd_clim | read climate fields (vegetation, soil etc.) | |||
rd_prog | read initial prognostic quantities | |||
rd_forc | read forcings | |||
time_control | timing routine | |||
intp_forc | interpolation of forcings | |||
wr_prog | writing of prognostic quantities | |||
call_phys | call to physics | |||
filter | time filtering of diagnostic output | |||
wr_diag | writing of diagnostic quantities | |||
end | end routine | |||
f_close | close output files |