| 78 | == User-supplied routines == |
| 79 | |
| 80 | To indicate user-supplied routines we use the prefix `U_`. In the template directory `templates/` these routines are provided in files with the routines name without this prefix. In the example implementation in `testsuite/src/dummymodel_1D` the routines exist without the prefix, but with the extension `_dummy_D.F90`. In the section titles below we provide the name of the template file in parentheses. |
| 81 | |
| 82 | === `U_next_observation` (next_observation.F90) === |
| 83 | |
| 84 | The interface for this routine is |
| 85 | {{{ |
| 86 | SUBROUTINE U_next_obs(stepnow, nsteps, doexit, timenow) |
| 87 | |
| 88 | INTEGER, INTENT(in) :: stepnow ! Number of the current time step |
| 89 | INTEGER, INTENT(out) :: nsteps ! Number of time steps until next obs |
| 90 | INTEGER, INTENT(out) :: doexit ! Whether to exit forecasting (1 for exit) |
| 91 | REAL, INTENT(out) :: timenow ! Current model (physical) time |
| 92 | }}} |
| 93 | |
| 94 | The routine is called once at the beginning of each forecast phase. It is executed by all processes that participate in the model integrations. |
| 95 | |
| 96 | Based on the information of the current time step, the routine has to define the number of time steps `nsteps` for the next forecast phase. In addition, the flag `doexit` has to be initialized to provide the information if the external ensemble loop can be exited. `timenow` is the current model time. This variable should also be initialized. It is particularly important, if an ensemble task integrates more than one model state. In this case `timenow` can be used to correctly jump back in time. |
| 97 | |
| 98 | Some hints: |
| 99 | * If the time interval between successive observations is known, `nsteps` can be simply initialized by dividing the time interval by the size of the time step |
| 100 | * `doexit` should be 0 to continue the assimilation process. In most cases `doexit` is set to 1, when `PDAF_get_state` is called after the last analysis for which observations are available. |
| 101 | * At the first call to `U_next_obs` the variable `timenow` should be initialized with the current model time. At the next call a forecast phase has been completed. Thus, the new value of `timenow` follows from the timer interval for the previous forecast phase. |
| 102 | |
| 103 | === `U_distribute_state` (distributed_state.F90) === |
| 104 | |
| 105 | The interface for this routine is |
| 106 | {{{ |
| 107 | SUBROUTINE distribute_state(dim_p, state_p) |
| 108 | |
| 109 | INTEGER, INTENT(in) :: dim_p ! State dimension for PE-local model sub-domain |
| 110 | REAL, INTENT(inout) :: state_p(dim_p) ! State vector for PE-local model sub-domain |
| 111 | }}} |
| 112 | |
| 113 | This routine is called during the forecast phase as many times as there are states to be integrated by a model task. Again, the routine is executed by all processes that belong to model tasks. |
| 114 | |
| 115 | When the routine is called a state vector `state_p` and its size `dim_p` are provided. As the user has defines how the model fields are stored in the state vector, one can initialize the model fields from this information. If the model is not parallelized, `state_p` will contain a full state vector. If the model is parallelized using domain decomposition, `state_p` will contain the part of the state vector that corresponds to the model sub-domain for the calling process. |
| 116 | |
| 117 | Some hints: |
| 118 | * If the state vector does not include all model fields, it can be useful to keep a separate array to store those additional fields. This array has to be kept separate from PDAF, but can be defined using a module like `mod_assimilation`. |
| 119 | |
| 120 | === U_prepoststep (prepoststep_seik.F90) === |
| 121 | |
| 122 | |