Source Modification Example#
As an example of a source code modification, we will add a new CAM diagnostic variable:
Adding a new diagnostic variable typically consists of four steps:
Compute the variable.
Register the field with the CAM history system using
addfld.Supply the field values using
outfld.(Optional) Add the field to the default history output using
add_default.
Example: We will illustrate the step by adding atmospheric temperature at 750 hPa, called T750 to CAM. Although CAM outputs temperature at several standard pressure levels (for example, T500), it does not provide T750 by default. We will add T750 below.
Registering a field with addfld#
Before a field can be written to a history file, it must be registered with the CAM history system using:
call addfld(fname, type, avgflag, units, long_name)
where:
fname— field nametype— field dimensions (for example,horiz_onlyfor a 2D field or(/'lev'/)for a 3D field)avgflag— averaging flag ('A'= averaged,'I'= instantaneous)units— field unitslong_name— descriptive name
For T750, the registration is:
call addfld('T750', horiz_only, 'A', 'K', &
'Temperature at 750 hPa pressure surface')
This registers T750 as a two-dimensional, time-averaged field with units of Kelvin.
Writing values with outfld#
Once the field is registered, the computed values are passed to the history system using:
call outfld(fname, field, idim, c)
where:
fname— field namefield— array containing the field valuesidim— horizontal dimension of the fieldc— chunk (physics) or latitude (dynamics) index
For example:
call outfld('T750', t750, pcols, lchnk)
where t750 contains the temperature interpolated to 750 hPa. The CAM history system then performs any requested time averaging and writes the field to the appropriate history file.
Adding the field to the default history stream#
Registering a field does not automatically include it in the default history output. To do so, call:
call add_default(fname, tindex, flag)
where:
fname— field nametindex— history stream indexflag— averaging flag ('A'or'I')
For example:
call add_default('T750', 1, ' ')
This adds T750 to the default CAM history stream (h0).
Summary#
Adding a new diagnostic variable to CAM consists of:
Computing the diagnostic quantity.
Registering it with
addfld.Writing the values with
outfld.Optionally adding it to the default history stream using
add_default.
In the following exercise, we will add T750, rebuild CESM, and verify that the new variable appears in the CAM history files.