H. 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: o An overbar indicates fluxes that are averaged over an outer loop synchronization in- terval, 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 synchro- nization 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. o Subscripts indicate the grid on which a field resides: atmosphere, ice, land, or ocean. o xa ; ya ; xi; yi, etc. are the component model grids. o 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. o 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). o 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. o 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 ( xa , ya , ncpla ) !_ recv spatial & temporal grid from atm _ msg-icei ( xi, yi, ncpli) !_ recv spatial & temporal grid from ice _ msg-lndi ( xl, yl, ncpll) !_ recv spatial & temporal grid from lnd _ msg-ocni ( xo , yo , ncplo ) !_ recv spatial & temporal grid from ocn _ msg-atmr ( Saa , F aiaa ,F alaa ,F aoaa ) !_ recv atm state & output fluxes _ msg-icer ( Sii, F ioii) !_ recv ice state & output fluxes _ msg-atmr ( Sla_, F alll)___ !_ recv lnd state & output fluxes _ msg-ocnr ( So o , 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 ( Saa , F aiaa ,F alaa ,F aoaa , Sii, F ioii, Sla , F alll, So o , F ioo o , F oxx o ) DO WHILE ( date < stop_date) tcheck ( ) !_ verify time coordination _ _________ msg-ocns ( FPoxx o ) !_ send daily avg fluxes to ocn _ tavg-zero ( F oxx o = 0) !_ initialize daily avg partial sum _ DO n = 1; ncpla = ncplo albd-ice ( Sii)_ !_ impose diurnal cycle on ice albedos _ albd-ocn ( So o ) !_ compute ocn albedos with diurnal cycle _ !_ redistribute solar radiation based on (1-albedo) _ map-i2a ( Sii,_Sia_)__ map-o2a ( So o , So a ) map-l2a ( Sll, Sla ) ____ solar-redistribution ( Sia , Sla , So a , F aiaa , F alaa , F aoaa ) !_ prepare lnd inputs & send to lnd _ map-a2l ( Saa , Sal) map-a2l ( F alaa , F alal) msg-lnds ( Sal, F alal) !_ compute & map all atm/ice fluxes _ map-a2i ( Saa , Sai) flux-ai ( Sai, Sii, F aici) map-i2a ( F aici, F aica ) map-a2i ( F aiaa , F aiai) !_ compute & map all atm/ocn fluxes _ map-a2o ( Saa , Sao_) flux-ao ( Sao , So o , F aoco ) map-o2a ( F aoco , F aoca ) map-a2o ( F aoaa , F aoao ) H-2 !_ recv lnd outputs & map to atm grid _ msg-lndr ( Sll, F alll) map-l2a ( Sll, Sla ) map-l2a ( F alll, F alla ) !_ merge atm inputs & send to atm _ mrg-atm ( F aica , F alla_, F aoca , F axxa ) mrg-atm ( Sia , Sla , So a , Sxa ) msg-atms ( F axxa , Sxa ) !_ compute & map all ice/ocn fluxes _ map-o2i ( F iooo , F iooi) map-i2o ( F_ioii,_F_ioio_) map-o2i ( So o_,_So_ i) flux-io ( Sii, So i, F ioci) map-i2o ( F ioci, F ioco ) !_ merge ice inputs & send_to_ice_model _ mrg-ice ( F aiai, F aici, F ioo i, F ioci, F ixxi) msg-ices ( F ixxi) !_ merge ocn inputs, form time-avg partial sum _ mrg-ocn ( F aoao , FPaoco , F ioio , F ioco , F oxxo ) tavg-sum ( F oxxo , F oxx o ) diagnos ( ) !_ do diagnostic calculations _ history ( ) !_ write a history file _ msg-icer ( Sii, F ioii) !_ recv ice outputs _ msg-atmr ( Saa , F aiaa , F alaa , F aoaa ) !_ recv atm outputs _ advance-date( date) !_ advanced the simulation date _ END DO P _________ tavg-done (____ F oxx___o_,_F oxx o ) !_ form time-avg ocn fluxes _ msg-ocnr ( So o , F ioo o ) !_ recv ocn outputs _ !_ make cpl restart data _ ____ ________ _________ restart-write ( Saa , F aiaa ,F alaa ,F aoaa , Sii, F ioii, Sla , F alll, So o , F ioo o , 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