H. \underline{Pseudo-Code for the Flux Coupler}

To understand the more subtle points of the coupler’s functionality, it is useful to have a basic understanding of the computer code that is the Flux Coupler. To that end, pseudo-code is shown below. If one wishes to modify the coupler source code, it is strongly recommended that one first study this section in conjunction with studying the source code file, main.F. This should provide a good overview of how the coupler works; a necessary pre-requisite for successful code modification. The actual source code is written almost entirely using standard Fortran 77.

Notice that the Flux Coupler code is configured for a particular time coordination scheme. Model time coordination occurs within a nested loop structure. The ocean model communicates with the coupler once per outer loop iteration, while the atmosphere, ice, and land models communicate once per inner loop iteration. Typically the outer loop corresponds to one day, while the inner loop corresponds to several hours or less. In this case, the ocean communicates with the coupler once per day, while the other component models communicate frequently enough to resolve a diurnal cycle. While this configuration is hard-coded within the coupler, it’s modular design facilitates code modifications to implement alternate configurations. A variety of time coordination schemes can be, and have been, implemented simply by rearranging subroutine calls at the highest level within the main program file, requiring a minimal amount of code modifications or new code.

An explanation of some pseudo-code notation:

• An overbar indicates fluxes that are averaged over an outer loop synchronization interval, typically one day. Output fluxes from a component model are assumed to be time averages that were formed by the component model over the preceeding synchronization interval. If that synchronization interval happens to coincide with one model time step, then we have a degenerate case wherein the time averaged flux is identical to the unaveraged flux.

• Subscripts indicate the grid on which a field resides: atmosphere, ice, land, or ocean.

• x_{a}, y_{a}, x_{i}, y_{i}, etc. are the component model grids.

• date is incremented on every inner-loop iteration. At the start of each outer-loop interation, the coupler and all component models must be synchronized in time – the coupler will verify this. The coupler stops when date = stop date.

• The routines map-o2i, map-a2i, etc., map state and flux fields between the various grids. Different mapping techniques can be used. For example, when mapping state variables one might want to use an interpolation routine that preserves higher order derivatives, whereas when mapping flux fields one might use a conservative mapping technique (e.g., area averaging).

• The routines mrg-atm, mrg-ocn, etc. merge the various component fluxes into complete sets of input fluxes. For example, evaporation over ice, land, and ocean surfaces is initially computed on three different grids. These three fields are subsequently merged into one global surface evaporation field which is then sent to the atmosphere model.

• The routines flux-io, flux-ai, etc. provide the fluxes computed in the coupler between component model pairs. All fluxes that are not model output fluxes are computed by the coupler in these routines.

H-1

PROGRAM main  ! Top-level Flux Coupler pseudo-code
msg-atmi ( x_{a}, y_{a}, ncpl_{a})  !— recv spatial & temporal grid from atm —
msg-icei ( x_{i}, y_{i}, ncpl_{i})  !— recv spatial & temporal grid from ice —
msg-lndi ( x_{l}, y_{l}, ncpl_{l})  !— recv spatial & temporal grid from lnd —
msg-ocni ( x_{o}, y_{o}, ncpl_{o})  !— recv spatial & temporal grid from ocn —
msg-atmr ( Sa_{a}, F aia_{a},F ala_{a},F aoa_{a}) !— recv atm state & output fluxes —
msg-icer ( Si_{i}, F ioi_{i})  !— recv ice state & output fluxes —
msg-atmr ( Sl_{a}, F all_{l})  !— recv lnd state & output fluxes —
msg-ocnr ( \overline{So}_{o}, \overline{F ioo}_{o})  !— recv ocn state & output fluxes —

!— acquire cpl restart data: the coupler can choose between this data and that just received —

restart-read ( Sa_{a}, F aia_{a},F ala_{a},F aoa_{a}, Si_{i}, F ioi_{i}, Sl_{a}, F all_{l}, \overline{So}_{o}, \overline{F ioo}_{o}, \overline{F oxx}_{o})

DO WHILE ( date < stop date)

tcheck ( )  !— verify time coordination —
msg-ocns ( \overline{F oxx}_{o})  !— send daily avg fluxes to ocn —
tavg-zero ( ∑ F oxx_{o}= 0)  !— initialize daily avg partial sum —

DO n = 1, ncpl_{a}/ ncpl_{o}

albd-ice ( Si_{i})  !— impose diurnal cycle on ice albedos —
albd-ocn ( \overline{So}_{o})  !— compute ocn albedos with diurnal cycle —

!— redistribute solar radiation based on (1-albedo) — map-i2a ( Si_{i}, Si_{a}) map-o2a ( \overline{So}_{o}, \overline{So}_{a}) map-l2a ( Sl_{l}, Sl_{a}) solar-redistribution ( Si_{a}, Sl_{a}, \overline{So}_{a}, F aia_{a}, F ala_{a}, F aoa_{a})

!— prepare lnd inputs & send to lnd — map-a2l ( Sa_{a}, Sa_{l}) map-a2l ( F ala_{a}, F ala_{l}) msg-lnds ( Sa_{l}, F ala_{l})

!— compute & map all atm/ice fluxes — map-a2i ( Sa_{a}, Sa_{i}) flux-ai ( Sa_{i}, Si_{i}, F aic_{i}) map-i2a ( F aic_{i}, F aic_{a}) map-a2i ( F aia_{a}, F aia_{i})

!— compute & map all atm/ocn fluxes — map-a2o ( Sa_{a}, Sa_{o}) flux-ao ( Sa_{o}, \overline{So}_{o}, F aoc_{o}) map-o2a ( F aoc_{o}, F aoc_{a}) map-a2o ( F aoa_{a}, F aoa_{o})

H-2

!— recv lnd outputs & map to atm grid — msg-lndr ( Sl_{l}, F all_{l}) map-l2a ( Sl_{l}, Sl_{a}) map-l2a ( F all_{l}, F all_{a})

!— merge atm inputs & send to atm —

mrg-atm ( F aic_{a}, F all_{a}, F aoc_{a}, F axx_{a})

mrg-atm ( Si_{a}, Sl_{a}, \overline{So}_{a}, Sx_{a}) msg-atms ( F axx_{a}, Sx_{a})

!— compute & map all ice/ocn fluxes — map-o2i ( F ioo_{o}, F ioo_{i}) map-i2o ( F ioi_{i}, F ioi_{o}) map-o2i ( \overline{So}_{o}, \overline{So}_{i}) flux-io ( Si_{i}, \overline{So}_{i}, F ioc_{i}) map-i2o ( F ioc_{i}, F ioc_{o})

!— merge ice inputs & send to ice model —

mrg-ice ( F aia_{i}, F aic_{i}, \overline{F ioo}_{i}, F ioc_{i}, F ixx_{i})

msg-ices ( F ixx_{i})

!— merge ocn inputs, form time-avg partial sum —

mrg-ocn ( F aoa_{o}, F aoc_{o}, F ioi_{o}, F ioc_{o}, F oxx_{o})

tavg-sum ( F oxx_{o}, ∑ F oxx_{o})

diagnos ( ) !— do diagnostic calculations —
history ( )  !— write a history file —
msg-icer ( Si_{i}, F ioi_{i})  !— recv ice outputs —
msg-atmr ( Sa_{a}, F aia_{a}, F ala_{a}, F aoa_{a})  !— recv atm outputs —
advance-date( date)  !— advanced the simulation date —

END DO

tavg-done ( ∑ F oxx_{o}, \overline{F oxx}_{o}) !— form time-avg ocn fluxes —
msg-ocnr ( \overline{So}_{o}, \overline{F ioo}_{o})  !— recv ocn outputs —

!— make cpl restart data —

restart-write ( Sa_{a}, F aia_{a},F ala_{a},F aoa_{a}, Si_{i}, F ioi_{i}, Sl_{a}, F all_{l}, \overline{So}_{o}, \overline{F ioo}_{o}, \overline{F oxx}_{o})

END DO

msg-atmf ( ) !— send final msg to atm —
msg-icef ( ) !— send final msg to ice —
msg-lndf ( ) !— send final msg to lnd —
msg-ocnf ( ) !— send final msg to ocn —

STOP

H-3