Changes between Initial Version and Version 1 of ImplementAnalysis_Hyb3DVar_classical


Ignore:
Timestamp:
Dec 9, 2021, 12:55:43 PM (3 years ago)
Author:
lnerger
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ImplementAnalysis_Hyb3DVar_classical

    v1 v1  
     1= Implementation of the Analysis Step for Hybrid 3D-Var without using OMI =
     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="ImplementAnalysisestkf">Implementation for ESTKF</a></li>
     14<li><a href="ImplementAnalysislestkf">Implementation for LESTKF</a></li>
     15<li><a href="ImplementAnalysisetkf">Implementation for ETKF</a></li>
     16<li>Implementation for LETKF</li>
     17<li><a href="ImplementAnalysisseik">Implementation for SEIK</a></li>
     18<li><a href="ImplementAnalysislseik">Implementation for LSEIK</a></li>
     19<li><a href="ImplementAnalysisseek">Implementation for SEEK</a></li>
     20<li><a href="ImplementAnalysisenkf">Implementation for EnKF</a></li>
     21<li><a href="ImplementAnalysislenkf">Implementation for LEnKF</a></li>
     22<li><a href="ImplementAnalysisnetf">Implementation for NETF</a></li>
     23<li><a href="ImplementAnalysislnetf">Implementation for LNETF</a></li>
     24<li><a href="ImplementAnalysispf">Implementation for PF</a></li>
     25<li><a href="ImplementAnalysis_3dVar_classical">Implementation for 3D-Var</a></li>
     26<li><a href="ImplementAnalysis_3DEnVar_classical">Implementation for 3D Ensemble Var</a></li>
     27<li>Implementation for Hybrid 3D-Var</li>
     28</ol>
     29<li><a href="AddingMemoryandTimingInformation">Memory and timing information</a></li>
     30<li><a href="EnsembleGeneration">Ensemble Generation</a></li>
     31<li><a href="DataAssimilationDiagnostics">Diagnostics</a></li>
     32</ol>
     33</div>
     34}}}
     35[[PageOutline(2-3,Contents of this page)]]
     36
     37== Overview ==
     38
     39With Version 2.0 with introduced 3D variational assimilation methods to PDAF. There are genenerally three different variants: parameterized 3D-Var, 3D Ensemble Var, and hybrid (parameterized + ensemble) 3D-Var.
     40
     41This page describes the implementation of the analysis step for the hybrid 3D-Var in the classical way (without using PDAF-OMI).
     42
     43For the analysis step of 3D-Var we need different operations related to the observations. 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_assimilate_3dvar` in the fully-parallel implementation (or `PDAF_put_state_3dvar` for the 'flexible' implementation) described below. With regard to the parallelization, all these routines (except `U_collect_state`) are executed by the filter processes (`filterpe=.true.`) only.
     44
     45For Hybrid 3D-Var the background covariance matrix '''B''' is represented by a combination of a parameterized covariance matrix with a covariance matrix part represented by the ensemble. In practive this means that in the square root of '''B''' one concatenates parameterized and ensemble columns. The ensemble perturbations need to be transformed by means of an ensemble Kalman filter. PDAF uses for this the error-subspace transform filter ESTKF. There are two variants: The first uses the localized filter LESTKF, while the second uses the global filter ESTKF.
     46
     47For completeness we discuss here all user-supplied routines that are specified in the interface to `PDAF_assimilate_hyb3dvar_*` and `PDAF_put_state_hyb3dvar_*`. Thus, some of the user-supplied routines that are explained on the page describing the modification of the model code for the ensemble integration are repeated here.
     48
     49
     50== Analysis Routines ==
     51
     52The general aspects of the filter (or solver) specific routines `PDAF_assimilate_*` have been described on the page [ModifyModelforEnsembleIntegration Modification of the model code for the ensemble integration] and its sub-page on [InsertAnalysisStep inserting the analysis step]. The routine is used in the fully-parallel implementation variant of the data assimilation system. When the 'flexible' implementation variant is used, the routines `PDAF_put_state_*` is used as described further below. Here, we list the full interface of the routine. Subsequently, the user-supplied routines specified in the call is explained.
     53
     54There are two variants that either compute the transformataion of the ensemble transformation using the local LESTKF method, or the global ESTKF.
     55
     56=== `PDAF_assimilate_hyb3dvar_lestkf` ===
     57
     58This routine is called for the case of transforming the ensemble perturbations using the local LESTKF.
     59
     60The interface is:
     61{{{
     62SUBROUTINE PDAF_assimilate_hyb3dvar_lestkf(U_collect_state, U_distribute_state, &
     63                                 U_init_dim_obs, U_obs_op, U_init_obs, U_prodRinvA, &
     64                                 U_cvt_ens, U_cvt_adj_ens, U_cvt, U_cvt_adj, U_obs_op_lin, U_obs_op_adj, &
     65                                 U_init_dim_obs_f, U_obs_op_f, U_init_obs_f, U_init_obs_l, U_prodRinvA_l, &
     66                                 U_init_n_domains_p, U_init_dim_l, U_init_dim_obs_l, U_g2l_state, U_l2g_state, &
     67                                 U_g2l_obs, U_init_obsvar, U_init_obsvar_l, &
     68                                 U_prepoststep, U_next_observation, outflag)
     69}}}
     70with the following arguments:
     71 * [#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 `PDAF_get_state` as well as here.
     72 * [#U_distribute_statedistribute_state_pdaf.F90 U_distribute_state]:  The name of a user supplied routine that initializes the model fields from the array holding the ensemble of model state vectors.
     73 * [#U_init_dim_obsinit_dim_obs_pdaf.F90 U_init_dim_obs]: The name of the user-supplied routine that provides the size of observation vector
     74 * [#U_obs_opobs_op_pdaf.F90 U_obs_op]: The name of the user-supplied routine that acts as the observation operator on some state vector
     75 * [#U_init_obsinit_obs_pdaf.F90 U_init_obs]: The name of the user-supplied routine that initializes the vector of observations
     76 * [#U_prodRinvAprodrinva_pdaf.F90 U_prodRinvA]: 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. This operation occurs during the analysis step of the ETKF.
     77 * [#U_cvt_enscvt_ens_pdaf.F90 U_cvt_ens]: The name of the user-supplied routine that applies the ensemble control-vector transformation (square-root of the B-matrix) on some control vector to obtain a state vector.
     78 * [#U_cvt_adj_enscvt_adj_ens_pdaf.F90 U_cvt_adj_ens]: The name of the user-supplied routine that applies the adjoint ensemble control-vector transformation (with square-root of the B-matrix) on some state vector to obtain the control vector.
     79 * [#U_cvtcvt_pdaf.F90 U_cvt]: The name of the user-supplied routine that applies the control-vector transformation (square-root of the B-matrix) on some control vector to obtain a state vector.
     80 * [#U_cvt_adjcvt_adj_pdaf.F90 U_cvt_adj]: The name of the user-supplied routine that applies the adjoint control-vector transformation (with square-root of the B-matrix) on some state vector to obtain the control vector.
     81 * [#U_obs_op_linobs_op_lin_pdaf.F90 U_obs_op_lin]: The name of the user-supplied routine that acts as the linearized observation operator on some state vector
     82 * [#U_obs_op_adjobs_op_adj_pdaf.F90 U_obs_op_adj]: The name of the user-supplied routine that acts as the adjoint observation operator on some state vector
     83 * [#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
     84 * [#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
     85 * [#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
     86 * [#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
     87 * [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep]: The name of the pre/poststep routine as in `PDAF_get_state`
     88 * [#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.
     89 * [#U_init_n_domains_pinit_n_domains_pdaf.F90 U_init_n_domains]: The name of the routine that provides the number of local analysis domains
     90 * [#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
     91 * [#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
     92 * [#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
     93 * [#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
     94 * [#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
     95 * [#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)
     96 * [#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)
     97 * [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep]: The name of the pre/poststep routine as in `PDAF_get_state`
     98 * [#U_next_observationnext_observation.F90 U_next_observation]: The name of a user supplied routine that initializes the variables `nsteps`, `timenow`, and `doexit`. The same routine is also used in `PDAF_get_state`.
     99 * `status`: The integer status flag. It is zero, if the routine is exited without errors.
     100
     101
     102
     103=== `PDAF_assimilate_hyb3dvar_estkf` ===
     104
     105This routine is called for the case of transforming the ensemble perturbations using the global ESTKF. 
     106
     107The interface is:
     108{{{
     109SUBROUTINE PDAF_assimilate_hyb3dvar_estkf(U_collect_state, U_distribute_state, &
     110                                 U_init_dim_obs, U_obs_op, U_init_obs, U_prodRinvA, &
     111                                 U_cvt_ens, U_cvt_adj_ens, U_cvt, U_cvt_adj, U_obs_op_lin, U_obs_op_adj, &
     112                                 U_init_obsvar, U_prepoststep, U_next_observation, outflag)
     113}}}
     114with the following arguments:
     115 * [#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 `PDAF_get_state` as well as here.
     116 * [#U_distribute_statedistribute_state_pdaf.F90 U_distribute_state]:  The name of a user supplied routine that initializes the model fields from the array holding the ensemble of model state vectors.
     117 * [#U_init_dim_obsinit_dim_obs_pdaf.F90 U_init_dim_obs]: The name of the user-supplied routine that provides the size of observation vector
     118 * [#U_obs_opobs_op_pdaf.F90 U_obs_op]: The name of the user-supplied routine that acts as the observation operator on some state vector
     119 * [#U_init_obsinit_obs_pdaf.F90 U_init_obs]: The name of the user-supplied routine that initializes the vector of observations
     120 * [#U_prodRinvAprodrinva_pdaf.F90 U_prodRinvA]: 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. This operation occurs during the analysis step of the ETKF.
     121 * [#U_cvt_enscvt_ens_pdaf.F90 U_cvt_ens]: The name of the user-supplied routine that applies the ensemble control-vector transformation (square-root of the B-matrix) on some control vector to obtain a state vector.
     122 * [#U_cvt_adj_enscvt_adj_ens_pdaf.F90 U_cvt_adj_ens]: The name of the user-supplied routine that applies the adjoint ensemble control-vector transformation (with square-root of the B-matrix) on some state vector to obtain the control vector.
     123 * [#U_cvtcvt_pdaf.F90 U_cvt]: The name of the user-supplied routine that applies the control-vector transformation (square-root of the B-matrix) on some control vector to obtain a state vector.
     124 * [#U_cvt_adjcvt_adj_pdaf.F90 U_cvt_adj]: The name of the user-supplied routine that applies the adjoint control-vector transformation (with square-root of the B-matrix) on some state vector to obtain the control vector.
     125 * [#U_obs_op_linobs_op_lin_pdaf.F90 U_obs_op_lin]: The name of the user-supplied routine that acts as the linearized observation operator on some state vector
     126 * [#U_obs_op_adjobs_op_adj_pdaf.F90 U_obs_op_adj]: The name of the user-supplied routine that acts as the adjoint observation operator on some state vector
     127 * [#U_init_obsvarinit_obsvar_pdaf.F90 U_init_obsvar]: The name of the user-supplied routine that provides a mean observation error variance to PDAF (This routine will only be executed, if an adaptive forgetting factor is used)
     128 * [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep]: The name of the pre/poststep routine as in `PDAF_get_state`
     129 * [#U_next_observationnext_observation.F90 U_next_observation]: The name of a user supplied routine that initializes the variables `nsteps`, `timenow`, and `doexit`. The same routine is also used in `PDAF_get_state`.
     130 * `status`: The integer status flag. It is zero, if the routine is exited without errors.
     131
     132
     133=== `PDAF_put_state_hyb3dvar_lestkf` ===
     134
     135When the 'flexible' implementation variant is chosen for the assimilation system, the routine `PDAF_put_state_*` has to be used instead of `PDAF_assimilate_*`. The general aspects of the filter specific routines `PDAF_put_state_*` have been described on the page [ModifyModelforEnsembleIntegration Modification of the model code for the ensemble integration]. The interface of the routine is identical with that of `PDAF_assimilate_*` with the exception the specification of the user-supplied routines `U_distribute_state` and `U_next_observation` are missing.
     136
     137The interface when using one of the global filters is the following:
     138{{{
     139  SUBROUTINE PDAF_put_state_hyb3dvar_lestkf(U_collect_state, &
     140                                 U_init_dim_obs, U_obs_op, U_init_obs, U_prodRinvA, &
     141                                 U_cvt_ens, U_cvt_adj_ens, U_cvt, U_cvt_adj, U_obs_op_lin, U_obs_op_adj, &
     142                                 U_init_dim_obs_f, U_obs_op_f, U_init_obs_f, U_init_obs_l, U_prodRinvA_l, &
     143                                 U_init_n_domains_p, U_init_dim_l, U_init_dim_obs_l, U_g2l_state, U_l2g_state, &
     144                                 U_g2l_obs, U_init_obsvar, U_init_obsvar_l, &
     145                                 U_prepoststep, outflag)
     146}}}
     147
     148=== `PDAF_put_state_hyb3dvar_estkf` ===
     149
     150The interface of this routine is analogous to that of `PDAF_assimilate_en3dvar_estkf'. Thus it is identical to this routine with the exception the specification of the user-supplied routines `U_distribute_state` and `U_next_observation` are missing.
     151
     152The interface when using one of the global filters is the following:
     153{{{
     154  SUBROUTINE PDAF_put_state_hyb3dvar_estkf(U_collect_state, &
     155                                 U_init_dim_obs, U_obs_op, U_init_obs, U_prodRinvA, &
     156                                 U_cvt_ens, U_cvt_adj_ens, U_cvt, U_cvt_adj, U_obs_op_lin, U_obs_op_adj, &
     157                                 U_init_obsvar, U_prepoststep, outflag)
     158}}}
     159
     160== User-supplied routines ==
     161
     162Here all user-supplied routines are described that are required in the calls to `PDAF_assimilate_en3dvar_*` and `PDAF_put_state_en3dvar_*`. For some of the generic routines, we link to the page on [ModifyModelforEnsembleIntegration modifying the model code for the ensemble integration].
     163
     164To 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.
     165
     166In the subroutine interfaces some variables appear with the suffix `_p`. 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.
     167
     168
     169=== `U_collect_state` (collect_state_pdaf.F90) ===
     170
     171This routine is independent of the filter algorithm used.
     172
     173See the page on [InsertAnalysisStep#U_collect_statecollect_state_pdaf.F90 inserting the analysis step] for the description of this routine.
     174
     175
     176=== `U_distribute_state` (distribute_state_pdaf.F90) ===
     177
     178This routine is independent of the filter algorithm used.
     179
     180See the page on [InsertAnalysisStep#U_distribute_statedistribute_state_pdaf.F90 inserting the analysis step] for the description of this routine.
     181
     182
     183
     184=== `U_init_dim_obs` (init_dim_obs_pdaf.F90) ===
     185
     186This routine is used by all global filter algorithms (SEEK, SEIK, EnKF, ETKF).
     187
     188The interface for this routine is:
     189{{{
     190SUBROUTINE init_dim_obs(step, dim_obs_p)
     191
     192  INTEGER, INTENT(in)  :: step       ! Current time step
     193  INTEGER, INTENT(out) :: dim_obs_p  ! Dimension of observation vector
     194}}}
     195
     196The routine is called at the beginning of each analysis step.  It has to initialize the size `dim_obs_p` of the observation vector according to the current time step. Without parallelization `dim_obs_p` will be the size for the full model domain. When a domain-decomposed model is used, `dim_obs_p` will be the size of the observation vector for the sub-domain of the calling process.
     197
     198Some hints:
     199 * 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 locations of the observations, which will be used later, e.g. to implement the observation operator. An array for the locations can be defined in a module like `mod_assimilation` of the example implementation.
     200
     201
     202=== `U_obs_op` (obs_op_pdaf.F90) ===
     203
     204This routine is used by all global filter algorithms (SEEK, SEIK, EnKF, ETKF).
     205
     206The interface for this routine is:
     207{{{
     208SUBROUTINE obs_op(step, dim_p, dim_obs_p, state_p, m_state_p)
     209
     210  INTEGER, INTENT(in) :: step               ! Current time step
     211  INTEGER, INTENT(in) :: dim_p              ! PE-local dimension of state
     212  INTEGER, INTENT(in) :: dim_obs_p          ! Dimension of observed state
     213  REAL, INTENT(in)    :: state_p(dim_p)     ! PE-local model state
     214  REAL, INTENT(out) :: m_state_p(dim_obs_p) ! PE-local observed state
     215}}}
     216
     217The routine is called during the analysis step. It has to perform the operation of the observation operator acting on a state vector that is provided as `state_p`. The observed state has to be returned in `m_state_p`.
     218
     219For a model using domain decomposition, the operation is on the PE-local sub-domain of the model and has to provide the observed sub-state for the PE-local domain.
     220
     221Hint:
     222 * If the observation operator involves a global operation, e.g. some global integration, while using domain-decomposition one has to gather the information from the other model domains using MPI communication.
     223
     224
     225=== `U_init_obs` (init_obs_pdaf.F90) ===
     226
     227This routine is used by all global filter algorithms (SEEK, SEIK, EnKF, ETKF).
     228
     229The interface for this routine is:
     230{{{
     231SUBROUTINE init_obs(step, dim_obs_p, observation_p)
     232
     233  INTEGER, INTENT(in) :: step             ! Current time step
     234  INTEGER, INTENT(in) :: dim_obs_p        ! PE-local dimension of obs. vector
     235  REAL, INTENT(out)   :: observation_p(dim_obs_p) ! PE-local observation vector
     236}}}
     237
     238The routine is called during the analysis step.
     239It has to provide the vector of observations in `observation_p` for the current time step.
     240
     241For a model using domain decomposition, the vector of observations that exist on the model sub-domain for the calling process has to be initialized.
     242
     243
     244
     245=== `U_prodRinvA` (prodrinva_pdaf.F90) ===
     246
     247This routine is used by all filter algorithms that use the inverse of the observation error covariance matrix (SEEK, SEIK, and ETKF).
     248
     249The interface for this routine is:
     250{{{
     251SUBROUTINE prodRinvA(step, dim_obs_p, dim_ens, obs_p, A_p, C_p)
     252
     253  INTEGER, INTENT(in) :: step                ! Current time step
     254  INTEGER, INTENT(in) :: dim_obs_p           ! PE-local dimension of obs. vector
     255  INTEGER, INTENT(in) :: dim_ens             ! Ensemble size
     256  REAL, INTENT(in)    :: obs_p(dim_obs_p)    ! PE-local vector of observations
     257  REAL, INTENT(in)    :: A_p(dim_obs_p, dim_ens) ! Input matrix from analysis routine
     258  REAL, INTENT(out)   :: C_p(dim_obs_p, dim_ens) ! Output matrix
     259}}}
     260
     261The routine is called during the analysis step. In the algorithms the product of the inverse of the observation error covariance matrix with some matrix has to be computed. For the ETKF, this matrix holds the observed part of the ensemble perturbations. The matrix is provided as `A_p`. The product has to be given as `C_p`.
     262
     263For a model with domain decomposition, `A_p` contains the part of the matrix that resides on the model sub-domain of the calling process. The product has to be computed for this sub-domain, too.
     264
     265Hints:
     266 * 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_p` has to be implemented.
     267 * The observation vector `obs_p` is provided through the interface for cases where the observation error variance is relative to the actual value of the observations.
     268 * The interface has a difference for SEIK and ETKF: For ETKF the third argument is the ensemble size (`dim_ens`), while for SEIK it is the rank of the covariance matrix (usually ensemble size minus one). In addition, the second dimension of `A_p` and `C_p` has size `dim_ens` for ETKF, while it is `rank` for the SEIK filter.  (Practically, one can usually ignore this difference as the fourth argument of the interface can be named arbitrarily in the routine.)
     269
     270
     271
     272=== `U_cvt_ens` (cvt_ens_pdaf.F90) ===
     273
     274The interface for this routine is:
     275{{{
     276SUBROUTINE cvt_ens_pdaf(iter, dim_p, dim_ens, dim_cv_ens_p, ens_p, cv_p, Vcv_p)
     277
     278  INTEGER, INTENT(in) :: iter               ! Iteration of optimization
     279  INTEGER, INTENT(in) :: dim_p              ! PE-local observation dimension
     280  INTEGER, INTENT(in) :: dim_ens            ! Ensemble size
     281  INTEGER, INTENT(in) :: dim_cv_ens_p       ! Dimension of control vector
     282  REAL, INTENT(in) :: ens_p(dim_p, dim_ens) ! PE-local ensemble
     283  REAL, INTENT(in) :: cv_p(dim_cv_ens_p)    ! PE-local control vector
     284  REAL, INTENT(inout) :: Vcv_p(dim_p)       ! PE-local state increment
     285}}}
     286
     287The routine is called during the analysis step during the iterative minimization of the cost function.
     288It has to apply the control vector transformation to the control vector and return the transformed result vector. Usually this transformation is the multiplication with the square-root of the background error covariance matrix '''B'''. For the 3D Ensemble Var, this square root is usually expressed through the ensemble.
     289
     290If the control vector is decomposed in case of parallelization it first needs to the gathered on each processor and afterwards the transformation is computed on the potentially domain-decomposed state vector.
     291
     292
     293=== `U_cvt_adj_ens` (cvt_adj_ens_pdaf.F90) ===
     294
     295The interface for this routine is:
     296{{{
     297SUBROUTINE cvt_adj_ens_pdaf(iter, dim_p, dim_ens, dim_cv_ens_p, ens_p, Vcv_p, cv_p)
     298
     299  INTEGER, INTENT(in) :: iter                ! Iteration of optimization
     300  INTEGER, INTENT(in) :: dim_p               ! PE-local observation dimension
     301  INTEGER, INTENT(in) :: dim_ens             ! Ensemble size
     302  INTEGER, INTENT(in) :: dim_cv_ens_p        ! PE-local dimension of control vector
     303  REAL, INTENT(in) :: ens_p(dim_p, dim_ens)  ! PE-local ensemble
     304  REAL, INTENT(in)    :: Vcv_p(dim_p)        ! PE-local input vector
     305  REAL, INTENT(inout) :: cv_p(dim_cv_ens_p)  ! PE-local result vector
     306}}}
     307
     308The routine is called during the analysis step during the iterative minimization of the cost function.
     309It has to apply the adjoint control vector transformation to a state vector and return the control vector. Usually this transformation is the multiplication with transpose of the square-root of the background error covariance matrix '''B'''. or the 3D Ensemble Var, this square root is usually expressed through the ensemble.
     310
     311If the state vector is decomposed in case of parallelization one needs to take care that the application of the trasformation is complete. This usually requries a comminucation with MPI_Allreduce to obtain a global sun.
     312
     313
     314
     315=== `U_cvt` (cvt_pdaf.F90) ===
     316
     317The interface for this routine is:
     318{{{
     319SUBROUTINE cvt_pdaf(iter, dim_p, dim_cvec, cv_p, Vv_p)
     320
     321  INTEGER, INTENT(in) :: iter           ! Iteration of optimization
     322  INTEGER, INTENT(in) :: dim_p          ! PE-local observation dimension
     323  INTEGER, INTENT(in) :: dim_cvec       ! Dimension of control vector
     324  REAL, INTENT(in)    :: cv_p(dim_cvec) ! PE-local control vector
     325  REAL, INTENT(inout) :: Vv_p(dim_p)    ! PE-local result vector (state vector increment)
     326}}}
     327
     328The routine is called during the analysis step during the iterative minimization of the cost function.
     329It has to apply the control vector transformation to the control vector and return the transformed result vector. Usually this transformation is the multiplication with the square-root of the background error covariance matrix '''B'''.
     330
     331If the control vector is decomposed in case of parallelization it first needs to the gathered on each processor and afterwards the transformation is computed on the potentially domain-decomposed state vector.
     332
     333
     334=== `U_cvt_adj` (cvt_adj_pdaf.F90) ===
     335
     336The interface for this routine is:
     337{{{
     338SUBROUTINE cvt_adj_pdaf(iter, dim_p, dim_cvec, Vv_p, cv_p)
     339
     340  INTEGER, INTENT(in) :: iter           ! Iteration of optimization
     341  INTEGER, INTENT(in) :: dim_p          ! PE-local observation dimension
     342  INTEGER, INTENT(in) :: dim_cvec       ! Dimension of control vector
     343  REAL, INTENT(in)    :: Vv_p(dim_p)    ! PE-local result vector (state vector increment)
     344  REAL, INTENT(inout) :: cv_p(dim_cvec) ! PE-local control vector
     345}}}
     346
     347The routine is called during the analysis step during the iterative minimization of the cost function.
     348It has to apply the adjoint control vector transformation to a state vector and return the control vector. Usually this transformation is the multiplication with transposed of the square-root of the background error covariance matrix '''B'''.
     349
     350If the state vector is decomposed in case of parallelization one needs to take care that the application of the trasformation is complete. This usually requries a comminucation with MPI_Allreduce to obtain a global sun.
     351
     352
     353
     354=== `U_obs_op_lin` (obs_op_lin_pdaf.F90) ===
     355
     356This routine is used by all 3D-Var methods.
     357
     358The interface for this routine is:
     359{{{
     360SUBROUTINE obs_op_lin(step, dim_p, dim_obs_p, state_p, m_state_p)
     361
     362  INTEGER, INTENT(in) :: step               ! Current time step
     363  INTEGER, INTENT(in) :: dim_p              ! PE-local dimension of state
     364  INTEGER, INTENT(in) :: dim_obs_p          ! Dimension of observed state
     365  REAL, INTENT(in)    :: state_p(dim_p)     ! PE-local model state
     366  REAL, INTENT(out) :: m_state_p(dim_obs_p) ! PE-local observed state
     367}}}
     368
     369The routine is called during the analysis step. It has to perform the operation of the linearized observation operator acting on a state vector increment that is provided as `state_p`. The observed state has to be returned in `m_state_p`.
     370
     371For a model using domain decomposition, the operation is on the PE-local sub-domain of the model and has to provide the observed sub-state for the PE-local domain.
     372
     373Hint:
     374 * If the observation operator involves a global operation, e.g. some global integration, while using domain-decomposition one has to gather the information from the other model domains using MPI communication.
     375
     376
     377=== `U_obs_op_adj` (obs_op_adj_pdaf.F90) ===
     378
     379This routine is used by all 3D-Var methods.
     380
     381The interface for this routine is:
     382{{{
     383SUBROUTINE obs_op_adj(step, dim_p, dim_obs_p, state_p, m_state_p)
     384
     385  INTEGER, INTENT(in) :: step                 ! Current time step
     386  INTEGER, INTENT(in) :: dim_p                ! PE-local dimension of state
     387  INTEGER, INTENT(in) :: dim_obs_p            ! Dimension of observed state
     388  REAL, INTENT(in)    :: m_state_p(dim_obs_p) ! PE-local observed state
     389  REAL, INTENT(out)   :: state_p(dim_p)       ! PE-local model state
     390}}}
     391
     392The routine is called during the analysis step. It has to perform the operation of the adjoint observation operator acting on a vector in observation space that is provided as m_state_p. The resulting state vector has to be returned in `m_state_p`.
     393
     394For a model using domain decomposition, the operation is on the PE-local sub-domain of the model and has to provide the observed sub-state for the PE-local domain.
     395
     396Hint:
     397 * If the observation operator involves a global operation, e.g. some global integration, while using domain-decomposition one has to gather the information from the other model domains using MPI communication.
     398
     399
     400
     401
     402=== `U_init_dim_obs_f` (init_dim_obs_f_pdaf.F90) ===
     403
     404This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     405
     406The interface for this routine is:
     407{{{
     408SUBROUTINE init_dim_obs_f(step, dim_obs_f)
     409
     410  INTEGER, INTENT(in)  :: step       ! Current time step
     411  INTEGER, INTENT(out) :: dim_obs_f  ! Dimension of full observation vector
     412}}}
     413
     414The 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.
     415
     416Some hints:
     417 * 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`.
     418 * 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`.
     419
     420=== `U_obs_op_f` (obs_op_f_pdaf.F90) ===
     421
     422This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     423
     424The interface for this routine is:
     425{{{
     426SUBROUTINE obs_op_f(step, dim_p, dim_obs_f, state_p, m_state_f)
     427
     428  INTEGER, INTENT(in) :: step               ! Current time step
     429  INTEGER, INTENT(in) :: dim_p              ! PE-local dimension of state
     430  INTEGER, INTENT(in) :: dim_obs_f          ! Dimension of the full observed state
     431  REAL, INTENT(in)    :: state_p(dim_p)     ! PE-local model state
     432  REAL, INTENT(out) :: m_state_f(dim_obs_f) ! Full observed state
     433}}}
     434
     435The 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.
     436
     437Hint:
     438 * 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.
     439
     440=== `U_init_obs_f` (init_obs_f_pdaf.F90) ===
     441
     442This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     443The 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)
     444
     445The interface for this routine is:
     446{{{
     447SUBROUTINE init_obs_f(step, dim_obs_f, observation_f)
     448
     449  INTEGER, INTENT(in) :: step                     ! Current time step
     450  INTEGER, INTENT(in) :: dim_obs_f                ! Dimension of full observation vector
     451  REAL, INTENT(out)   :: observation_f(dim_obs_f) ! Full observation vector
     452}}}
     453
     454The 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).
     455
     456Hints:
     457 * 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.
     458 * If the adaptive forgetting factor is not used, this routine only has to exist. However, no functionality is required.
     459
     460
     461=== `U_init_obs_l` (init_obs_l_pdaf.F90) ===
     462
     463This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     464
     465The interface for this routine is:
     466{{{
     467SUBROUTINE init_obs_l(domain_p, step, dim_obs_l, observation_l)
     468
     469  INTEGER, INTENT(in) :: domain_p                 ! Current local analysis domain
     470  INTEGER, INTENT(in) :: step                     ! Current time step
     471  INTEGER, INTENT(in) :: dim_obs_l                ! Local dimension of observation vector
     472  REAL, INTENT(out)   :: observation_l(dim_obs_l) ! Local observation vector
     473}}}
     474
     475The routine is called during the analysis step during the loop over the local analysis domain.
     476It 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.
     477
     478Hints:
     479 * For parallel efficiency, the LETKF 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.
     480 * 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.
     481
     482
     483
     484
     485=== `U_prodRinvA_l` (prodrinva_l_pdaf.F90) ===
     486
     487This routine is used by the local filters (LSEIK and LETKF). There is a slight difference between LSEIK and LETKF for this routine, which is described below.
     488
     489The interface for this routine is:
     490{{{
     491SUBROUTINE prodRinvA_l(domain_p, step, dim_obs_l, dim_ens, obs_l, A_l, C_l)
     492
     493  INTEGER, INTENT(in) :: domain_p             ! Current local analysis domain
     494  INTEGER, INTENT(in) :: step                 ! Current time step
     495  INTEGER, INTENT(in) :: dim_obs_l            ! Dimension of local observation vector
     496  INTEGER, INTENT(in) :: dim_ens              ! Ensemble size
     497  REAL, INTENT(in)    :: obs_l(dim_obs_l)     ! Local vector of observations
     498  REAL, INTENT(inout) :: A_l(dim_obs_l, dim_ens) ! Input matrix from analysis routine
     499  REAL, INTENT(out)   :: C_l(dim_obs_l, dim_ens) ! Output matrix
     500}}}
     501
     502The 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`.
     503
     504This routine is also the place to perform observation localization. To initialize a vector of weights, the routine `PDAF_local_weight` can be called. The procedure is used in the example implementation and also demonstrated in the template routine.
     505
     506Hints:
     507 * 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.
     508 * 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.
     509 * 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.
     510 * The interface has a difference for SEIK and ETKF: For ETKF the third argument is the ensemble size (`dim_ens`), while for SEIK 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 ETKF, while it is `rank` for the SEIK filter. (Practically, one can usually ignore this difference as the fourth argument of the interface can be named arbitrarily in the routine.)
     511
     512
     513=== `U_init_n_domains` (init_n_domains_pdaf.F90) ===
     514
     515This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     516
     517The interface for this routine is:
     518{{{
     519SUBROUTINE init_n_domains(step, n_domains_p)
     520
     521  INTEGER, INTENT(in)  :: step        ! Current time step
     522  INTEGER, INTENT(out) :: n_domains_p ! Number of analysis domains for local model sub-domain
     523}}}
     524
     525The routine is called during the analysis step before the loop over the local analysis domains is entered.
     526It 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.
     527
     528Hints:
     529 * 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.
     530
     531
     532=== `U_init_dim_l` (init_dim_l_pdaf.F90) ===
     533
     534This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     535
     536The interface for this routine is:
     537{{{
     538SUBROUTINE init_dim_l(step, domain_p, dim_l)
     539
     540  INTEGER, INTENT(in)  :: step        ! Current time step
     541  INTEGER, INTENT(in)  :: domain_p    ! Current local analysis domain
     542  INTEGER, INTENT(out) :: dim_l       ! Local state dimension
     543}}}
     544
     545The routine is called during the loop over the local analysis domains in the analysis step.
     546It has to provide in `dim_l` the dimension of the state vector for the local analysis domain with index `domain_p`.
     547
     548Hints:
     549 * 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.
     550
     551
     552=== `U_init_dim_obs_l` (init_dim_obs_l_pdaf.F90) ===
     553
     554This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     555
     556The interface for this routine is:
     557{{{
     558SUBROUTINE init_dim_obs_l(domain_p, step, dim_obs_f, dim_obs_l)
     559
     560  INTEGER, INTENT(in)  :: domain_p   ! Current local analysis domain
     561  INTEGER, INTENT(in)  :: step       ! Current time step
     562  INTEGER, INTENT(in)  :: dim_obs_f  ! Full dimension of observation vector
     563  INTEGER, INTENT(out) :: dim_obs_l  ! Local dimension of observation vector
     564}}}
     565
     566The routine is called during the loop over the local analysis domains in the analysis step.
     567It has to initialize in `dim_obs_l` the size of the observation vector used for the local analysis domain with index `domain_p`.
     568
     569Some hints:
     570 * 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.
     571 * 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_local` 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.
     572 * 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`.
     573
     574
     575=== `U_g2l_state` (g2l_state_pdaf.F90) ===
     576
     577This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     578
     579The interface for this routine is:
     580{{{
     581SUBROUTINE global2local_state(step, domain_p, dim_p, state_p, dim_l, state_l)
     582
     583  INTEGER, INTENT(in) :: step           ! Current time step
     584  INTEGER, INTENT(in) :: domain_p       ! Current local analysis domain
     585  INTEGER, INTENT(in) :: dim_p          ! State dimension for model sub-domain
     586  INTEGER, INTENT(in) :: dim_l          ! Local state dimension
     587  REAL, INTENT(in)    :: state_p(dim_p) ! State vector for model sub-domain
     588  REAL, INTENT(out)   :: state_l(dim_l) ! State vector on local analysis domain
     589}}}
     590
     591The 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.
     592
     593Hints:
     594 * 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`.
     595
     596
     597=== `U_l2g_state` (l2g_state_pdaf.F90) ===
     598
     599This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     600
     601The interface for this routine is:
     602{{{
     603SUBROUTINE l2g_state(step, domain_p, dim_l, state_l, dim_p, state_p)
     604
     605  INTEGER, INTENT(in) :: step           ! Current time step
     606  INTEGER, INTENT(in) :: domain_p       ! Current local analysis domain
     607  INTEGER, INTENT(in) :: dim_p          ! State dimension for model sub-domain
     608  INTEGER, INTENT(in) :: dim_l          ! Local state dimension
     609  REAL, INTENT(in)    :: state_p(dim_p) ! State vector for model sub-domain
     610  REAL, INTENT(out)   :: state_l(dim_l) ! State vector on local analysis domain
     611}}}
     612
     613The 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.
     614
     615Hints:
     616 * 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`.
     617
     618
     619=== `U_g2l_obs` (g2l_obs_pdaf.F90) ===
     620
     621This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) and is independent of the particular algorithm.
     622
     623The interface for this routine is:
     624{{{
     625SUBROUTINE g2l_obs(domain_p, step, dim_obs_f, dim_obs_l, mstate_f, mstate_l)
     626
     627  INTEGER, INTENT(in) :: domain_p              ! Current local analysis domain
     628  INTEGER, INTENT(in) :: step                  ! Current time step
     629  INTEGER, INTENT(in) :: dim_obs_f             ! Dimension of full observation vector for model sub-domain
     630  INTEGER, INTENT(in) :: dim_obs_l             ! Dimension of observation vector for local analysis domain
     631  REAL, INTENT(in)    :: mstate_f(dim_obs_f)   ! Full observation vector for model sub-domain
     632  REAL, INTENT(out)   :: mstate_l(dim_obs_l)   ! Observation vector for local analysis domain
     633}}}
     634
     635The 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.
     636
     637Hints:
     638 * The  vector `mstate_f` that is provided to the routine is one of the observed state vectors that are produced by `U_obs_op_full`.
     639 * 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_global2local_obs`)
     640
     641
     642=== `U_init_obsvar` (init_obsvar_pdaf.F90) ===
     643
     644This routine is used by the global filter algorithms SEIK and  ETKF as well as the local filters LSEIK and LETKF. 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.
     645
     646The interface for this routine is:
     647{{{
     648SUBROUTINE init_obsvar(step, dim_obs_f, obs_f, meanvar_f)
     649
     650  INTEGER, INTENT(in) :: step             ! Current time step
     651  INTEGER, INTENT(in) :: dim_obs_f        ! Full dimension of observation vector
     652  REAL, INTENT(in)    :: obs_f(dim_obs_f) ! Full observation vector
     653  REAL, INTENT(out)   :: meanvar_f        ! Mean observation error variance
     654}}}
     655
     656The 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`).
     657The routine has to initialize an average full observation error variance, which should be consistent with the observation vector initialized in `U_init_ob_f`.
     658
     659
     660Hints:
     661 * 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`).
     662 * 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.
     663 * If the adaptive forgetting factor is not used, this routine has only to exist for the compilation, but it does not need functionality.
     664
     665
     666=== `U_init_obsvar_l` (init_obsvar_l_pdaf.F90) ===
     667
     668This routine is used by all filter algorithms with domain-localization (LSEIK, LETKF) 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).
     669
     670The interface for this routine is:
     671{{{
     672SUBROUTINE init_obsvar_l(domain_p, step, dim_obs_l, obs_l, meanvar_l)
     673
     674  INTEGER, INTENT(in) :: domain_p         ! Current local analysis domain
     675  INTEGER, INTENT(in) :: step             ! Current time step
     676  INTEGER, INTENT(in) :: dim_obs_l        ! Local dimension of observation vector
     677  REAL, INTENT(in)    :: obs_l(dim_obs_l) ! Local observation vector
     678  REAL, INTENT(out)   :: meanvar_l        ! Mean local observation error variance
     679}}}
     680
     681The 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_local`). The routine has to initialize a local mean observation error variance for all observations used for the analysis in the current local analysis domain.
     682
     683Hints:
     684 * If the local adaptive forgetting factor is not used, this routine has only to exist for the compilation, but it does not need functionality.
     685
     686=== `U_prepoststep` (prepoststep_ens_pdaf.F90) ===
     687
     688The routine has already been described for modifying the model for the ensemble integration and for inserting the analysis step.
     689
     690See the page on [InsertAnalysisStep#U_prepoststepprepoststep_ens_pdaf.F90 inserting the analysis step] for the description of this routine.
     691
     692
     693=== `U_next_observation` (next_observation_pdaf.F90) ===
     694
     695This routine is independent of the filter algorithm used.
     696
     697See the page on [InsertAnalysisStep#U_next_observationnext_observation_pdaf.F90 inserting the analysis step] for the description of this routine.
     698
     699
     700== Execution order of user-supplied routines ==
     701
     702The user-supplied routines are essentially executed in the order they are listed in the interfaces to the routines. An except is the order of the routines for the local ESTKF. The order can be important as some routines can perform preparatory work for later routines. For example, `U_init_dim_obs` prepares an index array that provides the information for executing the observation operator in `U_obs_op`.
     703
     704Before the analysis step is called the following routine is executed:
     705 1. [#U_collect_statecollect_state_pdaf.F90 U_collect_state]
     706
     707The analysis step is executed when the ensemble integration of the forecast is completed. During the analysis step the following routines are executed in the given order:
     708 1. [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep] (Call to act on the forecast ensemble, called with negative value of the time step)
     709 1. [#U_init_dim_obsinit_dim_obs_pdaf.F90 U_init_dim_obs]
     710 1. [#U_obs_opobs_op_pdaf.F90 U_obs_op]
     711 1. [#U_init_obsinit_obs_pdaf.F90 U_init_obs]
     712
     713Inside the analysis step the interative optimization is computed. This involves the repeated call of the routines:
     714 1. [#U_cvtcvt_pdaf.F90 U_cvt]
     715 1. [#U_obs_op_linobs_op_lin_pdaf.F90 U_obs_op_lin]
     716 1. [#U_prodRinvAprodrinva_pdaf.F90 U_prodRinvA]
     717 1. [#U_obs_op_adjobs_op_adj_pdaf.F90 U_obs_op_adj]
     718 1. [#U_cvt_adjcvt_adj_pdaf.F90 U_cvt_adj]
     719
     720After the iterative optimization the following routines are executes to complte the analysis step:
     721 1. [#U_cvt_enscvt_ens_pdaf.F90 U_cvt_ens] (Call to the control vector transform to compute the final state vector increment
     722 1. [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep] (Call to act on the analysis ensemble, called with (positive) value of the time step)
     723
     724The iterative optimization abovve computes an updated ensemble mean state. Subsequently, the ensemble perturbations are updated using the LESTKF or ESTKF. The execution of the routines for these filters is described on the [wiki:ImplementAnalysislestkf page on implementing the analysis step of the LESTKF] and on the [wiki:ImplementAnalysisestkf page on implementing the analysis step of the ESTKF].
     725
     726In case of the routines `PDAF_assimilate_*`, the following routines are executed after the analysis step:
     727 1. [#U_distribute_statedistribute_state_pdaf.F90 U_distribute_state]
     728 1. [#U_next_observationnext_observation_pdaf.F90 U_next_observation]