Changes between Initial Version and Version 1 of ImplementAnalysislestkf


Ignore:
Timestamp:
Jan 22, 2012, 10:54:59 AM (7 years ago)
Author:
lnerger
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ImplementAnalysislestkf

    v1 v1  
     1= Implementation of the analysis step for the LESTKF =
     2
     3{{{
     4#!html
     5<div class="wiki-toc">
     6<h4>Implementation Guide</h4>
     7<ol><li><a href="ImplementationGuide">Main page</a></li>
     8<li><a href="AdaptParallelization">Adaptation of the parallelization</a></li>
     9<li><a href="InitPdaf">Initialization of PDAF</a></li>
     10<li><a href="ModifyModelforEnsembleIntegration">Modifications for ensemble integration</a></li>
     11<li><a href="ImplementationofAnalysisStep">Implementation of the analysis step</a></li>
     12<ol>
     13<li><a href="ImplementAnalysisseik">Implementation for SEIK</a></li>
     14<li><a href="ImplementAnalysislseik">Implementation for LSEIK</a></li>
     15<li><a href="ImplementAnalysisetkf">Implementation for ETKF</a></li>
     16<li><a href="ImplementAnalysisletkf">Implementation for LETKF</a></li>
     17<li><a href="ImplementAnalysisseek">Implementation for SEEK</a></li>
     18<li><a href="ImplementAnalysisenkf">Implementation for EnKF</a></li>
     19<li><a href="ImplementAnalysisestkf">Implementation for ESTKF</a></li>
     20<li>Implementation for LESTKF</li>
     21</ol>
     22<li><a href="AddingMemoryandTimingInformation">Memory and timing information</a></li>
     23</ol>
     24</div>
     25}}}
     26
     27
     28[[PageOutline(2-3,Contents of this page)]]
     29
     30== Overview ==
     31
     32With Version 1.8 of PDAF, the LESTKF [Local Error Subspace Transform Kalman Filter] algorithm has been introduced. The user-supplied routines required for the LESTKF are identical to those required for the LSEIK filter.
     33
     34For the analysis step of the LESTKF, several operations related to the observations are needed. These operations are requested by PDAF by calling user-supplied routines. Intentionally, the operations are split into separate routines in order to keep the operations rather elementary as this procedure should simplify the implementation. The names of the required routines are specified in the call to the routine `PDAF_put_state_lestkf` described below. With regard to the parallelization, all these routines (except `U_collect_state`) are executed by the filter processes (`filterpe=.true.`) only.
     35
     36For completeness we discuss here all user-supplied routines that are specified in the interface to `PDAF_put_state_lestkf`. Many of the routines are localized versions of those that are needed for the global ESTKF method. Hence, if the user-supplied routines for the global ESTKF have been already implemented, one can base on these routines to speed up the implementation. Due to this, it can also be reasonable to first fully implement a global filter version and subsequently implement the corresponding localized filter by modifying and extending the global routines.
     37
     38The LESTKF and the LETKF (Local Ensemble Transform Kalman Filter) are very similar. For this reason, the interface to the user-supplied routines is almost identical. Depending on the implementation it can be possible to use identical routines for the LESTKF and the LETKF. Differences are marked in the text below.
     39
     40
     41== `PDAF_put_state_lestkf` ==
     42
     43The general espects of the filter-specific routines `PDAF_put_state_*` have been described on the page [ModifyModelforEnsembleIntegration Modification of the model code for the ensemble integration].
     44The interface for the routine `PDAF_put_state_lestkf` contains several routine names for routines that operate on the local analysis domains (marked by `_l` at the end of the routine name). In addition, there are names for routines that consider all available observations required to perform local analyses with LESTKF within some sub-domain of a domain-decomposed model (marked by `_f` at the end of the routine name). In case of a serial execution of the assimilation program, these will be all globally available observations. However, if the program is executed with parallelization, this might be a smaller set of observations.
     45
     46To explain the  difference, it is assumed, for simplicity, that a local analysis domain consists of a single vertical column of the model grid. In addition, we assume that the domain decomposition splits the global model domain by vertical boundaries as is typical for ocean models and that the observations are spatially distributed observations of model fields that are part of the state vector.  Under these assumptions, the situation is the following: When a model uses domain decomposition, the LESTKF is executed such that for each model sub-domain a loop over all local analysis domains (e.g. vertical columns) that belong to the model sub-domain is performed. As each model sub-domain is treated by a different process, all loops are executed parallel to each other.
     47
     48For the update of each single vertical column, observations from some larger domain surrounding the vertical column are required. If the influence radius for the observations is sufficiently small there will be vertical columns for which the relevant observations reside completely inside the model sub-domain of the process. However, if a vertical column is considered that is located close to the boundary of the model sub-domain, there will be some observations that don't belong spatially to the local model sub-domain, but to a neighboring model sub-domain. Nonetheless, these observations are required on the local model sub-domain. A simple way to handle this situation is to initialize for each process all globally available observations, together with their coordinates. While this method is simple, it can also become inefficient if the assimilation program is executed using a large number of processes. As for an initial implementation it is usually not the concern to obtain the highest parallel efficiency, the description below assumes that 'full' refers to the global model domain.
     49
     50The interface when using the LESTKF algorithm is the following:
     51{{{
     52  SUBROUTINE PDAF_put_state_lestkf(U_collect_state, U_init_dim_obs_f, U_obs_op_f, U_init_obs_f, &
     53                                  U_init_obs_l, U_prepoststep, U_prodRinvA_l, U_init_n_domains, &
     54                                  U_init_dim_l, U_init_dim_obs_l, &
     55                                  U_g2l_state, U_l2g_state, U_g2l_obs, &
     56                                  U_init_obsvar, U_init_obsvar_l, status)
     57}}}
     58with the following arguments:
     59 * [#U_collect_statecollect_state_pdaf.F90 U_collect_state]: The name of the user-supplied routine that initializes a state vector from the array holding the ensemble of model states from the model fields. This is basically the inverse operation to `U_distribute_state` used in [ModifyModelforEnsembleIntegration#PDAF_get_state PDAF_get_state]
     60 * [#U_init_dim_obs_finit_dim_obs_f_pdaf.F90 U_init_dim_obs_f]: The name of the user-supplied routine that provides the size of the full observation vector
     61 * [#U_obs_op_fobs_op_f_pdaf.F90 U_obs_op_f]: The name of the user-supplied routine that acts as the full observation operator on some state vector
     62 * [#U_init_obs_finit_obs_f_pdaf.F90 U_init_obs_f]: The name of the user-supplied routine that initializes the full vector of observations
     63 * [#U_init_obs_linit_obs_l_pdaf.F90 U_init_obs_l]: The name of the user-supplied routine that initializes the vector of observations for a local analysis domain
     64 * [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep]: The name of the pre/poststep routine as in `PDAF_get_state`
     65 * [#U_prodRinvA_lprodrinva_l_pdaf.F90 U_prodRinvA_l]: The name of the user-supplied routine that computes the product of the inverse of the observation error covariance matrix with some matrix provided to the routine by PDAF.
     66 * [#U_init_n_domainsinit_n_domains_pdaf.F90 U_init_n_domains]: The name of the routine that provides the number of local analysis domains
     67 * [#U_init_dim_linit_dim_l_pdaf.F90 U_init_dim_l]: The name of the routine that provides the state dimension for a local analysis domain
     68 * [#U_init_dim_obs_linit_dim_obs_l_pdaf.F90 U_init_dim_obs_l]: The name of the routine that initializes the size of the observation vector for a local analysis domain
     69 * [#U_g2l_stateg2l_state_pdaf.F90 U_g2l_state]: The name of the routine that initializes a local state vector from the global state vector
     70 * [#U_l2g_statel2g_state_pdaf.F90 U_l2g_state]: The name of the routine that initializes the corresponding part of the global state vector from the the provided local state vector
     71 * [#U_g2l_obsg2l_obs_pdaf.F90 U_g2l_obs]: The name of the routine that initializes a local observation vector from a full observation vector
     72 * [#U_init_obsvarinit_obsvar_pdaf.F90 U_init_obsvar]: The name of the user-supplied routine that provides a global mean observation error variance (This routine will only be executed, if an adaptive forgetting factor is used)
     73 * [#U_init_obsvar_linit_obsvar_l_pdaf.F90 U_init_obsvar_l]: The name of the user-supplied routine that provides a mean observation error variance for the local analysis domain (This routine will only be executed, if a local adaptive forgetting factor is used)
     74 * `status`: The integer status flag. It is zero, if `PDAF_put_state_lestkf` is exited without errors.
     75
     76Note:
     77 * The order of the routine names does not show the order in which these routines are executed. See the [#Executionorderofuser-suppliedroutines section on the order of the execution] at the bottom of this page.
     78
     79== User-supplied routines ==
     80
     81Here, all user-supplied routines are described that are required in the call to `PDAF_put_state_lestkf`. For some of the generic routines, we link to the page on [ModifyModelforEnsembleIntegration modifying the model code for the ensemble integration].
     82
     83To indicate user-supplied routines we use the prefix `U_`. In the template directory `templates/` as well as in the example implementation in `testsuite/src/dummymodel_1D` these routines exist without the prefix, but with the extension `_pdaf.F90`. In the section titles below we provide the name of the template file in parentheses.
     84
     85In the subroutine interfaces some variables appear with the suffix `_p` (short for 'process'). This suffix indicates that the variable is particular to a model sub-domain, if a domain decomposed model is used. Thus, the value(s) in the variable will be different for different model sub-domains. In addition, there will be variables with the suffix `_f` (for 'full') and with the suffix `_l` (for 'local').
     86
     87=== `U_collect_state` (collect_state_pdaf.F90) ===
     88
     89This routine is independent from the filter algorithm used.
     90See the mape on [ModifyModelforEnsembleIntegration#U_collect_statecollect_state_pdaf.F90 modifying the model code for the ensemble integration] for the description of this routine.
     91
     92
     93=== `U_init_dim_obs_f` (init_dim_obs_f_pdaf.F90) ===
     94
     95This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     96
     97The interface for this routine is:
     98{{{
     99SUBROUTINE init_dim_obs_f(step, dim_obs_f)
     100
     101  INTEGER, INTENT(in)  :: step       ! Current time step
     102  INTEGER, INTENT(out) :: dim_obs_f  ! Dimension of full observation vector
     103}}}
     104
     105The routine is called at the beginning of each analysis step, before the loop over all local analysis domains is entered.  It has to initialize the size `dim_obs_f` of the full observation vector according to the current time step. For simplicity, `dim_obs_f` can be the size for the global model domain.
     106
     107Some hints:
     108 * It can be useful to not only determine the size of the observation vector at this point. One can also already gather information about the location of the observations, which can be used later, e.g. to implement the observation operator. In addition, one can already prepare an array that holds the full observation vector. This can be used later by `U_init_obs_l` to initialize a local vector of observations by selecting the relevant parts of the full observation vector. The required arrays can be defined in a module like `mod_assimilation`.
     109 * The routine is similar to `init_dim_obs` used in the global filters. However, if the global filter is used with a domain-decomposed model, it only initializes the size of the observation vector for the local model sub-domain. This is different for the local filters, as the local analysis also requires observational data from neighboring model sub-domains. Nonetheless, one can base on an implemented routine `init_dim_obs` to implement `init_dim_obs_f`.
     110
     111=== `U_obs_op_f` (obs_op_f_pdaf.F90) ===
     112
     113This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     114
     115The interface for this routine is:
     116{{{
     117SUBROUTINE obs_op_f(step, dim_p, dim_obs_f, state_p, m_state_f)
     118
     119  INTEGER, INTENT(in) :: step               ! Currrent time step
     120  INTEGER, INTENT(in) :: dim_p              ! PE-local dimension of state
     121  INTEGER, INTENT(in) :: dim_obs_f          ! Dimension of the full observed state
     122  REAL, INTENT(in)    :: state_p(dim_p)     ! PE-local model state
     123  REAL, INTENT(out) :: m_state_f(dim_obs_f) ! Full observed state
     124}}}
     125
     126The routine is called during the analysis step, before the loop over the local analysis domain is entered. It has to perform the operation of the observation operator acting on a state vector, which is provided as `state_p`. The observed state has to be returned in `m_state_f`. It is the observed state corresponding to the 'full' observation vector.
     127
     128Hint:
     129 * The routine is similar to `init_dim_obs` used for the global filters. However, with a domain-decomposed model `m_state_f` will contain parts of the state vector from neighboring model sub-domains. To make these parts accessible, some parallel communication will be necessary (The state information for a neighboring model sub-domain, will be in the memory of the process that handles that sub-domain). The example implementation in `testsuite/dummymodel_1d` uses the function `MPI_AllGatherV` for this communication.
     130
     131=== `U_init_obs_f` (init_obs_f_pdaf.F90) ===
     132
     133This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     134The routine is only called if the globally adaptive forgetting factor is used (`type_forget=1` in the example implementation). For the local filters there is also the alternative to use locally adaptive forgetting factors (`type_forget=2` in the example implementation)
     135
     136The interface for this routine is:
     137{{{
     138SUBROUTINE init_obs_f(step, dim_obs_f, observation_f)
     139
     140  INTEGER, INTENT(in) :: step                     ! Current time step
     141  INTEGER, INTENT(in) :: dim_obs_f                ! Dimension of full observation vector
     142  REAL, INTENT(out)   :: observation_f(dim_obs_f) ! Full observation vector
     143}}}
     144
     145The routine is called during the analysis step before the loop over the local analysis domains is entered. It has to provide the full vector of observations in `observation_f` for the current time step. The caller is the routine that computes an adaptive forgetting factor (PDAF_set_forget).
     146
     147Hints:
     148 * As for the other 'full' routines: While the global counterpart of this routine (`init_obs`) has to initialize the observation vector only for the local model sub-domain, the 'full' routine has to include observations that spatially belong to neighboring model sub-domains. As an easy choice one can simply initialize a vector of all globally available observations.
     149 * If the adaptive forgetting factor is not used, this routine only has to exist. However, no functionality is required.
     150
     151
     152=== `U_init_obs_l` (init_obs_l_pdaf.F90) ===
     153
     154This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     155
     156The interface for this routine is:
     157{{{
     158SUBROUTINE init_obs_l(domain_p, step, dim_obs_l, observation_l)
     159
     160  INTEGER, INTENT(in) :: domain_p                 ! Current local analysis domain
     161  INTEGER, INTENT(in) :: step                     ! Current time step
     162  INTEGER, INTENT(in) :: dim_obs_l                ! Local dimension of observation vector
     163  REAL, INTENT(out)   :: observation_l(dim_obs_l) ! Local observation vector
     164}}}
     165
     166The routine is called during the analysis step during the loop over the local analysis domain.
     167It has to provide the vector of observations for the analysis in the local analysis domain with index `domain_p` in `observation_l` for the current time step.
     168
     169Hints:
     170 * For parallel efficiency, the LESTKF algorithm is implemented in a way that first the full vectors are initialized. These are then restricted to the local analysis domain during the loop over all local analysis domains. Thus, if the full vector of observations has been initialized before `U_init_obs_l` is executed (e.g. by `U_init_dim_obs_f`), the operations performed in this routine will be to select the part of the full observation vector that is relevant for the current local analysis domain.
     171 * The routine `U_init_dim_obs_l` is executed before this routine. Thus, if that routine already prepares the information which elements of `observation_f` are needed for `observation_l`, this information can be used efficiently here.
     172
     173
     174=== `U_prepoststep` (prepoststep_ens_pdaf.F90) ===
     175
     176This routine can be identical to that used for the global ESTKF algorithm, which has already been described on the [ModifyModelforEnsembleIntegration#U_prepoststepprepoststep_ens.F90 page on modifying the model code for the ensemble integration]. For completeness, the description is repeated:
     177
     178The interface of the routine is identical for all filters. However, the particular operations that are performed in the routine can be specific for each filter algorithm.
     179
     180The interface for this routine is
     181{{{
     182SUBROUTINE prepoststep(step, dim_p, dim_ens, dim_ens_p, dim_obs_p, &
     183                       state_p, Uinv, ens_p, flag)
     184
     185  INTEGER, INTENT(in) :: step        ! Current time step
     186                         ! (When the routine is called before the analysis -step is provided.)
     187  INTEGER, INTENT(in) :: dim_p       ! PE-local state dimension
     188  INTEGER, INTENT(in) :: dim_ens     ! Size of state ensemble
     189  INTEGER, INTENT(in) :: dim_ens_p   ! PE-local size of ensemble
     190  INTEGER, INTENT(in) :: dim_obs_p   ! PE-local dimension of observation vector
     191  REAL, INTENT(inout) :: state_p(dim_p) ! PE-local forecast/analysis state
     192                                     ! The array 'state_p' is not generally not initialized in the case of SEIK/EnKF/ETKF/ESTKF.
     193                                     ! It can be used freely in this routine.
     194  REAL, INTENT(inout) :: Uinv(dim_ens-1, dim_ens-1) ! Inverse of matrix U
     195  REAL, INTENT(inout) :: ens_p(dim_p, dim_ens)      ! PE-local state ensemble
     196  INTEGER, INTENT(in) :: flag        ! PDAF status flag
     197}}}
     198
     199The routine `U_prepoststep` is called once at the beginning of the assimilation process. In addition, it is called during the assimilation cycles before the analysis step and after the ensemble transformation. The routine is called by all filter processes (that is `filterpe=1`).
     200
     201The routine provides for the user the full access to the ensemble of model states. Thus, user-controlled pre- and post-step operations can be performed.  For example the forecast and the analysis states and ensemble covariance matrix can be analyzed, e.g. by computing the estimated variances. In addition, the estimates can be written to disk.
     202
     203Hint:
     204 * If a user considers to perform adjustments to the estimates (e.g. for balances), this routine is the right place for it.
     205 * Only for the SEEK filter the state vector (`state_p`) is initialized. For all other filters, the array is allocated, but it can be used freely during the execution of `U_prepoststep`.
     206 * The interface has a difference for LETKF and LESTKF: For the LETKF, the array `Uinv` has size `dim_ens` x `dim_ens`. In contrast it has size `dim_ens-1` x `dim_ens-1` for the LESTKF.
     207
     208
     209
     210=== `U_prodRinvA_l` (prodrinva_l_pdaf.F90) ===
     211
     212This routine is used by the local filters (LSEIK, LETKF, LESTKF). There is a slight difference between LESTKF and LETKF for this routine, which is described below.
     213
     214The interface for this routine is:
     215{{{
     216SUBROUTINE prodRinvA_l(domain_p, step, dim_obs_l, rank, obs_l, A_l, C_l)
     217
     218  INTEGER, INTENT(in) :: domain_p             ! Current local analysis domain
     219  INTEGER, INTENT(in) :: step                 ! Current time step
     220  INTEGER, INTENT(in) :: dim_obs_l            ! Dimension of local observation vector
     221  INTEGER, INTENT(in) :: rank                 ! Rank of initial covariance matrix
     222  REAL, INTENT(in)    :: obs_l(dim_obs_l)     ! Local vector of observations
     223  REAL, INTENT(inout) :: A_l(dim_obs_l, rank) ! Input matrix from analysis routine
     224  REAL, INTENT(out)   :: C_l(dim_obs_l, rank) ! Output matrix
     225}}}
     226
     227The routine is called during the loop over the local analysis domains. In the algorithm, the product of the inverse of the observation error covariance matrix with some matrix has to be computed. For the SEIK filter this matrix holds the observed part of the ensemble perturbations for the local analysis domain of index `domain_p`. The matrix is provided as `A_l`. The product has to be given as `C_l`.
     228
     229This routine is also the place to perform observation localization. To initialize a vector of weights, the routine `PDAF_local_weights` can be called. The procedure is used in the example implementation and also demonstrated in the template routine.
     230
     231Hints:
     232 * The routine is a local variant of the routine `U_prodRinvA`. Thus if that routine has been implemented before, it can be adapted here for the local filter.
     233 * The routine does not require that the product is implemented as a real matrix-matrix product. Rather, the product can be implemented in its most efficient form. For example, if the observation error covariance matrix is diagonal, only the multiplication of the diagonal with matrix `A_l` has to be implemented.
     234 * The observation vector `obs_l` is provided through the interface for cases where the observation error variance is relative to the actual value of the observations.
     235 * The interface has a difference for LESTKF and LETKF: For LETKF the third argument is the ensemble size (`dim_ens`), while for LESTKF it is the rank (`rank`) of the covariance matrix (usually ensemble size minus one). In addition, the second dimension of `A_l` and `C_l` has size `dim_ens` for LETKF, while it is `rank` for LESTKF.  (Practically, one can usually ignore this difference as the fourth argument of the interface can be named arbitrarily in the routine.)
     236
     237
     238=== `U_init_n_domains` (init_n_domains_pdaf.F90) ===
     239
     240This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     241
     242The interface for this routine is:
     243{{{
     244SUBROUTINE init_n_domains(step, n_domains_p)
     245
     246  INTEGER, INTENT(in)  :: step        ! Current time step
     247  INTEGER, INTENT(out) :: n_domains_p ! Number of analysis domains for local model sub-domain
     248}}}
     249
     250The routine is called during the analysis step before the loop over the local analysis domains is entered.
     251It has to provide the number of local analysis domains. In case of a domain-decomposed model the number of local analysis domain for the model sub-domain of the calling process has to be initialized.
     252
     253Hints:
     254 * As a simple case, if the localization is only performed horizontally, the local analysis domains can be single vertical columns of the model grid. In this case, `n_domains_p` is simply the number of vertical columns in the local model sub-domain.
     255
     256
     257=== `U_init_dim_l` (init_dim_l_pdaf.F90) ===
     258
     259This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     260
     261The interface for this routine is:
     262{{{
     263SUBROUTINE init_dim_l(step, domain_p, dim_l)
     264
     265  INTEGER, INTENT(in)  :: step        ! Current time step
     266  INTEGER, INTENT(in)  :: domain_p    ! Current local analysis domain
     267  INTEGER, INTENT(out) :: dim_l       ! Local state dimension
     268}}}
     269
     270The routine is called during the loop over the local analysis domains in the analysis step.
     271It has to provide in `dim_l` the dimension of the state vector for the local analysis domain with index `domain_p`.
     272
     273Hints:
     274 * If a local analysis domain is a single vertical column of the model grid, the size of the state in the local analysis domain will be just the number of vertical grid points at this location.
     275
     276
     277=== `U_init_dim_obs_l` (init_dim_obs_l_pdaf.F90) ===
     278
     279This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     280
     281The interface for this routine is:
     282{{{
     283SUBROUTINE init_dim_obs_l(domain_p, step, dim_obs_f, dim_obs_l)
     284
     285  INTEGER, INTENT(in)  :: domain_p   ! Current local analysis domain
     286  INTEGER, INTENT(in)  :: step       ! Current time step
     287  INTEGER, INTENT(in)  :: dim_obs_f  ! Full dimension of observation vector
     288  INTEGER, INTENT(out) :: dim_obs_l  ! Local dimension of observation vector
     289}}}
     290
     291The routine is called during the loop over the local analysis domains in the analysis step.
     292It has to initialize in `dim_obs_l` the size of the observation vector used for the local analysis domain with index `domain_p`.
     293
     294Some hints:
     295 * Usually, the observations to be considered for a local analysis are those which reside within some distance from the local analysis domain. Thus, if the local analysis domain is a single vertical column of the model grid and if the model grid is a regular ij-grid, then one could use some range of i/j indices to select the observations and determine the local number of them. More generally, one can compute the physical distance of an observation from the local analysis domain and decide on this basis, if the observation has to be considered.
     296 * In the loop over the local analysis domains, the routine is always called before `U_init_obs_l` is executed. Thus, as `U_init_dim_obs_l` has to check which observations should be used for the local analysis domain, one can already initialize an integer array that stores the index of observations to be considered. This index should be the position of the observation in the array `observation_f`. With this, the initialization of the local observation vector in `U_init_obs_l` can be sped up.
     297 * For PDAF, we could not join the routines `U_init_dim_obs_l` and `U_init_obs_l`, because the array for the local observations is allocated internally to PDAF after its size has been determined in `U_init_dim_obs_l`.
     298
     299
     300=== `U_g2l_state` (g2l_state_pdaf.F90) ===
     301
     302This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     303
     304The interface for this routine is:
     305{{{
     306SUBROUTINE g2l_state(step, domain_p, dim_p, state_p, dim_l, state_l)
     307
     308  INTEGER, INTENT(in) :: step           ! Current time step
     309  INTEGER, INTENT(in) :: domain_p       ! Current local analysis domain
     310  INTEGER, INTENT(in) :: dim_p          ! State dimension for model sub-domain
     311  INTEGER, INTENT(in) :: dim_l          ! Local state dimension
     312  REAL, INTENT(in)    :: state_p(dim_p) ! State vector for model sub-domain
     313  REAL, INTENT(out)   :: state_l(dim_l) ! State vector on local analysis domain
     314}}}
     315
     316The routine is called during the loop over the local analysis domains in the analysis step. It has to provide the local state vector `state_l` that corresponds to the local analysis domain with index `domain_p`. Provided to the routine is the state vector `state_p`. With a domain decomposed model, this is the state for the local model sub-domain.
     317
     318Hints:
     319 * In the simple case that a local analysis domain is a single vertical column of the model grid, the operation in this routine would be to take out of `state_p` the data for the vertical column indexed by `domain_p`.
     320
     321
     322=== `U_l2g_state` (l2g_state_pdaf.F90) ===
     323
     324This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     325
     326The interface for this routine is:
     327{{{
     328SUBROUTINE l2g_state(step, domain_p, dim_l, state_l, dim_p, state_p)
     329
     330  INTEGER, INTENT(in) :: step           ! Current time step
     331  INTEGER, INTENT(in) :: domain_p       ! Current local analysis domain
     332  INTEGER, INTENT(in) :: dim_p          ! State dimension for model sub-domain
     333  INTEGER, INTENT(in) :: dim_l          ! Local state dimension
     334  REAL, INTENT(in)    :: state_p(dim_p) ! State vector for model sub-domain
     335  REAL, INTENT(out)   :: state_l(dim_l) ! State vector on local analysis domain
     336}}}
     337
     338The routine is called during the loop over the local analysis domains in the analysis step. It has to initialize the part of the global state vector `state_p` that corresponds to the local analysis domain with index `domain_p`. Provided to the routine is the state vector `state_l` for the local analysis domain.
     339
     340Hints:
     341 * In the simple case that a local analysis domain is a single vertical column of the model grid, the operation in this routine would be to write into `state_p` the data for the vertical column indexed by `domain_p`.
     342
     343
     344=== `U_g2l_obs` (g2l_obs_pdaf.F90) ===
     345
     346This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm.
     347
     348The interface for this routine is:
     349{{{
     350SUBROUTINE g2l_obs(domain_p, step, dim_obs_f, dim_obs_l, mstate_f, mstate_l)
     351
     352  INTEGER, INTENT(in) :: domain_p              ! Current local analysis domain
     353  INTEGER, INTENT(in) :: step                  ! Current time step
     354  INTEGER, INTENT(in) :: dim_obs_f             ! Dimension of full observation vector for model sub-domain
     355  INTEGER, INTENT(in) :: dim_obs_l             ! Dimension of observation vector for local analysis domain
     356  REAL, INTENT(in)    :: mstate_f(dim_obs_f)   ! Full observation vector for model sub-domain
     357  REAL, INTENT(out)   :: mstate_l(dim_obs_l)   ! Observation vector for local analysis domain
     358}}}
     359
     360The routine is called during the loop over the local analysis domains in the analysis step. It has to provide a local observation vector `mstate_l` for the observation domain that corresponds to the local analysis domain with index `domain_p`. Provided to the routine is the full observation vector `mstate_f` from which the local part has to be extracted.
     361
     362Hints:
     363 * The  vector `mstate_f` that is provided to the routine is one of the observed state vectors that are produced by `U_obs_op_f`.
     364 * Some operations performed here are analogous to those required to initialize a local vector of observations in `U_init_obs_l`. If that routine reads first a full vector of observations (e.g. in `U_init_dim_obs_f`), this vector has to be restricted to the relevant observations for the current local analysis domain. For this operation, one can for example initialize an index array when `U_init_dim_obs_l` is executed. (Which happens before `U_g2l_obs`)
     365
     366
     367=== `U_init_obsvar` (init_obsvar_pdaf.F90) ===
     368
     369This routine is used by the global filter algorithms SEIK, ETKF, and ESTKF as well as the local filters LSEIK, LETKF, ad LESTKF. The routine is only called if the adaptive forgetting factor is used (`type_forget=1` in the example implementation). The difference in this routine between global and local filters is that the global filters use 'global' while the local filters use 'full' quantities.
     370
     371The interface for this routine is:
     372{{{
     373SUBROUTINE init_obsvar(step, dim_obs_f, obs_f, meanvar_f)
     374
     375  INTEGER, INTENT(in) :: step             ! Current time step
     376  INTEGER, INTENT(in) :: dim_obs_f        ! Full dimension of observation vector
     377  REAL, INTENT(in)    :: obs_f(dim_obs_f) ! Full observation vector
     378  REAL, INTENT(out)   :: meanvar_f        ! Mean observation error variance
     379}}}
     380
     381The routine is called in the local filters before the loop over all local analysis domains is entered. The call is by the routine that computes an adaptive forgetting factor (`PDAF_set_forget`).
     382The routine has to initialize an average full observation error variance, which should be consistent with the observation vector initialized in `U_init_ob_full`.
     383
     384
     385Hints:
     386 * For a model with domain-decomposition one might use the mean variance for the model sub-domain of the calling process. Alternatively one can compute a mean variance for the full model domain using MPI communication (e.g. the function `MPI_allreduce`).
     387 * The observation vector `obs_p` is provided to the routine for the case that the observation error variance is relative to the value of the observations.
     388 * If the adaptive forgetting factor is not used, this routine has only to exist for the compilation, but it does not need functionality.
     389
     390
     391=== `U_init_obsvar_l` (init_obsvar_l_pdaf.F90) ===
     392
     393This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF, LESTKF) and is independent of the particular algorithm. The routine is only called if the local adaptive forgetting factor is used (`type_forget=2` in the example implementation).
     394
     395The interface for this routine is:
     396{{{
     397SUBROUTINE init_obsvar_l(domain_p, step, dim_obs_l, obs_l, meanvar_l)
     398
     399  INTEGER, INTENT(in) :: domain_p         ! Current local analysis domain
     400  INTEGER, INTENT(in) :: step             ! Current time step
     401  INTEGER, INTENT(in) :: dim_obs_l        ! Local dimension of observation vector
     402  REAL, INTENT(in)    :: obs_l(dim_obs_l) ! Local observation vector
     403  REAL, INTENT(out)   :: meanvar_l        ! Mean local observation error variance
     404}}}
     405
     406The routine is called in the local filters during the loop over all local analysis domains by the routine that computes a local adaptive forgetting factor (`PDAF_set_forget_l`). The routine has to initialize a local mean observation error variance for all observations used for the analysis in the current local analysis domain.
     407
     408Hints:
     409 * If the local adaptive forgetting factor is not used, this routine has only to exist for the compilation, but it does not need functionality.
     410
     411== Execution order of user-supplied routines ==
     412
     413The user-supplied routines are executed in the order listed below. The order can be important as some routines can perform preparatory work for routines executed later on during the analysis. For example, `U_init_dim_obs_local` can prepare an index array that provides the information how to localize a 'full' vector of observations. Some hints one the efficient implementation strategy are given with the descriptions of the routine interfaces above.
     414
     415Before the analysis step is called the following is executed:
     416 1. [#U_collect_statecollect_state_pdaf.F90 U_collect_state] (called once for each ensemble member)
     417
     418When the ensemble integration of the forecast is completed, the analysis step is executed. Before the loop over all local analysis domains, the following routines are executed:
     419 1. [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep] (Call to act on the forecast ensemble, called with negative value of the time step)
     420 1. [#U_init_n_domainsinit_n_domains_pdaf.F90 U_init_n_domains]
     421 1. [#U_init_dim_obs_finit_dim_obs_f_pdaf.F90 U_init_dim_obs_f]
     422 1. [#U_obs_op_fobs_op_f_pdaf.F90 U_obs_op_f] (Called `dim_ens` times; once for each ensemble member)
     423 1. [#U_init_obs_finit_obs_f_pdaf.F90 U_init_obs_f] (Only executed, if the global adaptive forgetting factor is used (`type_forget=1` in the example implemention))
     424 1. [#U_init_obsvarinit_obsvar_pdaf.F90 U_init_obsvar] (Only executed, if the global adaptive forgetting factor is used (`type_forget=1` in the example implemention))
     425
     426In the loop over all local analysis domains, it is executed for each local analysis domain:
     427 1. [#U_init_dim_linit_dim_l_pdaf.F90 U_init_dim_l]
     428 1. [#U_init_dim_obs_linit_dim_obs_l_pdaf.F90 U_init_dim_obs_l]
     429 1. [#U_g2l_stateg2l_state_pdaf.F90 U_g2l_state] (Called `dim_ens+1` times: Once for each ensemble member and once for the mean state estimate)
     430 1. [#U_g2l_obsg2l_obs_pdaf.F90 U_g2l_obs] (A single call to localize the mean observed state)
     431 1. [#U_init_obs_linit_obs_l_pdaf.F90 U_init_obs_l]
     432 1. [#U_g2l_obsg2l_obs_pdaf.F90 U_g2l_obs] (`dim_ens` calls: one call to localize the observed part of each ensemble member)
     433 1. [#U_init_obsvar_linit_obsvar_l_pdaf.F90 U_init_obsvar_l] (Only called, if the local adaptive forgetting factor is used (`type_forget=2` in the example implementation))
     434 1. [#U_prodRinvA_lprodrinva_l_pdaf.F90 U_prodRinvA_l]
     435 1. [#U_l2g_statel2g_state_pdaf.F90 U_l2g_state] (Called `dim_ens+1` times: Once for each ensemble member and once for the mean state estimate)
     436
     437After the loop over all local analysis domains, it is executed:
     438 1. [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep] (Call to act on the analysis ensemble, called with (positive) value of the time step)
     439
     440
     441