New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
asminc.F90 in branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM – NEMO

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90 @ 9254

Last change on this file since 9254 was 9254, checked in by smasson, 6 years ago

dev_merge_2017: missing use in asminc

  • Property svn:keywords set to Id
File size: 47.7 KB
RevLine 
[2128]1MODULE asminc
2   !!======================================================================
3   !!                       ***  MODULE asminc  ***
4   !! Assimilation increment : Apply an increment generated by data
5   !!                          assimilation
6   !!======================================================================
[2392]7   !! History :       ! 2007-03  (M. Martin)  Met Office version
8   !!                 ! 2007-04  (A. Weaver)  calc_date original code
9   !!                 ! 2007-04  (A. Weaver)  Merge with OPAVAR/NEMOVAR
10   !!   NEMO     3.3  ! 2010-05  (D. Lea)  Update to work with NEMO v3.2
11   !!             -   ! 2010-05  (D. Lea)  add calc_month_len routine based on day_init
[3764]12   !!            3.4  ! 2012-10  (A. Weaver and K. Mogensen) Fix for direct initialization
[6140]13   !!                 ! 2014-09  (D. Lea)  Local calc_date removed use routine from OBS
14   !!                 ! 2015-11  (D. Lea)  Handle non-zero initial time of day
[2392]15   !!----------------------------------------------------------------------
[2128]16
17   !!----------------------------------------------------------------------
[3785]18   !!   asm_inc_init   : Initialize the increment arrays and IAU weights
19   !!   tra_asm_inc    : Apply the tracer (T and S) increments
20   !!   dyn_asm_inc    : Apply the dynamic (u and v) increments
21   !!   ssh_asm_inc    : Apply the SSH increment
[9023]22   !!   ssh_asm_div    : Apply divergence associated with SSH increment
[3785]23   !!   seaice_asm_inc : Apply the seaice increment
[2128]24   !!----------------------------------------------------------------------
[9019]25   USE oce             ! Dynamics and active tracers defined in memory
26   USE par_oce         ! Ocean space and time domain variables
27   USE dom_oce         ! Ocean space and time domain
28   USE domvvl          ! domain: variable volume level
29   USE ldfdyn          ! lateral diffusion: eddy viscosity coefficients
30   USE eosbn2          ! Equation of state - in situ and potential density
31   USE zpshde          ! Partial step : Horizontal Derivative
32   USE asmpar          ! Parameters for the assmilation interface
[9254]33   USE asmbkg          !
[9019]34   USE c1d             ! 1D initialization
35   USE sbc_oce         ! Surface boundary condition variables.
36   USE diaobs   , ONLY : calc_date     ! Compute the calendar date on a given step
37#if defined key_lim3
38   USE ice      , ONLY : hm_i, at_i, at_i_b
[3764]39#endif
[9019]40   !
41   USE in_out_manager  ! I/O manager
42   USE iom             ! Library to read input files
43   USE lib_mpp         ! MPP library
[2128]44
45   IMPLICIT NONE
46   PRIVATE
[2392]47   
48   PUBLIC   asm_inc_init   !: Initialize the increment arrays and IAU weights
49   PUBLIC   tra_asm_inc    !: Apply the tracer (T and S) increments
50   PUBLIC   dyn_asm_inc    !: Apply the dynamic (u and v) increments
51   PUBLIC   ssh_asm_inc    !: Apply the SSH increment
[9023]52   PUBLIC   ssh_asm_div    !: Apply the SSH divergence
[3764]53   PUBLIC   seaice_asm_inc !: Apply the seaice increment
[2128]54
55#if defined key_asminc
[2392]56    LOGICAL, PUBLIC, PARAMETER :: lk_asminc = .TRUE.   !: Logical switch for assimilation increment interface
[2128]57#else
[2392]58    LOGICAL, PUBLIC, PARAMETER :: lk_asminc = .FALSE.  !: No assimilation increments
[2128]59#endif
[5836]60   LOGICAL, PUBLIC :: ln_bkgwri     !: No output of the background state fields
61   LOGICAL, PUBLIC :: ln_asmiau     !: No applying forcing with an assimilation increment
62   LOGICAL, PUBLIC :: ln_asmdin     !: No direct initialization
63   LOGICAL, PUBLIC :: ln_trainc     !: No tracer (T and S) assimilation increments
64   LOGICAL, PUBLIC :: ln_dyninc     !: No dynamics (u and v) assimilation increments
65   LOGICAL, PUBLIC :: ln_sshinc     !: No sea surface height assimilation increment
66   LOGICAL, PUBLIC :: ln_seaiceinc  !: No sea ice concentration increment
67   LOGICAL, PUBLIC :: ln_salfix     !: Apply minimum salinity check
[3764]68   LOGICAL, PUBLIC :: ln_temnofreeze = .FALSE. !: Don't allow the temperature to drop below freezing
[5836]69   INTEGER, PUBLIC :: nn_divdmp     !: Apply divergence damping filter nn_divdmp times
[2128]70
[2392]71   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   t_bkg   , s_bkg      !: Background temperature and salinity
72   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   u_bkg   , v_bkg      !: Background u- & v- velocity components
73   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   t_bkginc, s_bkginc   !: Increment to the background T & S
74   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   u_bkginc, v_bkginc   !: Increment to the u- & v-components
75   REAL(wp), PUBLIC, DIMENSION(:)    , ALLOCATABLE ::   wgtiau               !: IAU weights for each time step
[2128]76#if defined key_asminc
[9213]77   REAL(wp), PUBLIC, DIMENSION(:,:)  , ALLOCATABLE ::   ssh_iau              !: IAU-weighted sea surface height increment
[2128]78#endif
[2392]79   !                                !!! time steps relative to the cycle interval [0,nitend-nit000-1]
80   INTEGER , PUBLIC ::   nitbkg      !: Time step of the background state used in the Jb term
81   INTEGER , PUBLIC ::   nitdin      !: Time step of the background state for direct initialization
82   INTEGER , PUBLIC ::   nitiaustr   !: Time step of the start of the IAU interval
83   INTEGER , PUBLIC ::   nitiaufin   !: Time step of the end of the IAU interval
84   !
85   INTEGER , PUBLIC ::   niaufn      !: Type of IAU weighing function: = 0   Constant weighting
86   !                                 !: = 1   Linear hat-like, centred in middle of IAU interval
87   REAL(wp), PUBLIC ::   salfixmin   !: Ensure that the salinity is larger than this  value if (ln_salfix)
[2128]88
[2392]89   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ssh_bkg, ssh_bkginc   ! Background sea surface height and its increment
[3764]90   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   seaice_bkginc         ! Increment to the background sea ice conc
[8030]91#if defined key_cice && defined key_asminc
92   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ndaice_da             ! ice increment tendency into CICE
93#endif
[2128]94
[3294]95   !! * Substitutions
96#  include "vectopt_loop_substitute.h90"
[2287]97   !!----------------------------------------------------------------------
[6140]98   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
[2287]99   !! $Id$
[2392]100   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
[2287]101   !!----------------------------------------------------------------------
[2128]102CONTAINS
103
104   SUBROUTINE asm_inc_init
105      !!----------------------------------------------------------------------
106      !!                    ***  ROUTINE asm_inc_init  ***
107      !!         
108      !! ** Purpose : Initialize the assimilation increment and IAU weights.
109      !!
110      !! ** Method  : Initialize the assimilation increment and IAU weights.
111      !!
112      !! ** Action  :
113      !!----------------------------------------------------------------------
[4990]114      INTEGER :: ji, jj, jk, jt  ! dummy loop indices
115      INTEGER :: imid, inum      ! local integers
116      INTEGER :: ios             ! Local integer output status for namelist read
[2128]117      INTEGER :: iiauper         ! Number of time steps in the IAU period
118      INTEGER :: icycper         ! Number of time steps in the cycle
[6140]119      REAL(KIND=dp) :: ditend_date     ! Date YYYYMMDD.HHMMSS of final time step
120      REAL(KIND=dp) :: ditbkg_date     ! Date YYYYMMDD.HHMMSS of background time step for Jb term
121      REAL(KIND=dp) :: ditdin_date     ! Date YYYYMMDD.HHMMSS of background time step for DI
122      REAL(KIND=dp) :: ditiaustr_date  ! Date YYYYMMDD.HHMMSS of IAU interval start time step
123      REAL(KIND=dp) :: ditiaufin_date  ! Date YYYYMMDD.HHMMSS of IAU interval final time step
124
[2128]125      REAL(wp) :: znorm        ! Normalization factor for IAU weights
[4990]126      REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights (should be equal to one)
[2128]127      REAL(wp) :: z_inc_dateb  ! Start date of interval on which increment is valid
128      REAL(wp) :: z_inc_datef  ! End date of interval on which increment is valid
129      REAL(wp) :: zdate_bkg    ! Date in background state file for DI
130      REAL(wp) :: zdate_inc    ! Time axis in increments file
[4990]131      !
[9019]132      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zhdiv   ! 2D workspace
[2392]133      !!
[3764]134      NAMELIST/nam_asminc/ ln_bkgwri,                                      &
[2392]135         &                 ln_trainc, ln_dyninc, ln_sshinc,                &
136         &                 ln_asmdin, ln_asmiau,                           &
137         &                 nitbkg, nitdin, nitiaustr, nitiaufin, niaufn,   &
[4990]138         &                 ln_salfix, salfixmin, nn_divdmp
[2392]139      !!----------------------------------------------------------------------
[2128]140
141      !-----------------------------------------------------------------------
142      ! Read Namelist nam_asminc : assimilation increment interface
143      !-----------------------------------------------------------------------
[5836]144      ln_seaiceinc   = .FALSE.
[3764]145      ln_temnofreeze = .FALSE.
[2128]146
[4147]147      REWIND( numnam_ref )              ! Namelist nam_asminc in reference namelist : Assimilation increment
148      READ  ( numnam_ref, nam_asminc, IOSTAT = ios, ERR = 901)
[9168]149901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_asminc in reference namelist', lwp )
[4147]150      REWIND( numnam_cfg )              ! Namelist nam_asminc in configuration namelist : Assimilation increment
151      READ  ( numnam_cfg, nam_asminc, IOSTAT = ios, ERR = 902 )
[9168]152902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_asminc in configuration namelist', lwp )
[4624]153      IF(lwm) WRITE ( numond, nam_asminc )
[4147]154
[2128]155      ! Control print
156      IF(lwp) THEN
157         WRITE(numout,*)
158         WRITE(numout,*) 'asm_inc_init : Assimilation increment initialization :'
159         WRITE(numout,*) '~~~~~~~~~~~~'
[2392]160         WRITE(numout,*) '   Namelist namasm : set assimilation increment parameters'
161         WRITE(numout,*) '      Logical switch for writing out background state          ln_bkgwri = ', ln_bkgwri
162         WRITE(numout,*) '      Logical switch for applying tracer increments            ln_trainc = ', ln_trainc
163         WRITE(numout,*) '      Logical switch for applying velocity increments          ln_dyninc = ', ln_dyninc
164         WRITE(numout,*) '      Logical switch for applying SSH increments               ln_sshinc = ', ln_sshinc
165         WRITE(numout,*) '      Logical switch for Direct Initialization (DI)            ln_asmdin = ', ln_asmdin
[3764]166         WRITE(numout,*) '      Logical switch for applying sea ice increments        ln_seaiceinc = ', ln_seaiceinc
[2392]167         WRITE(numout,*) '      Logical switch for Incremental Analysis Updating (IAU)   ln_asmiau = ', ln_asmiau
168         WRITE(numout,*) '      Timestep of background in [0,nitend-nit000-1]            nitbkg    = ', nitbkg
169         WRITE(numout,*) '      Timestep of background for DI in [0,nitend-nit000-1]     nitdin    = ', nitdin
170         WRITE(numout,*) '      Timestep of start of IAU interval in [0,nitend-nit000-1] nitiaustr = ', nitiaustr
171         WRITE(numout,*) '      Timestep of end of IAU interval in [0,nitend-nit000-1]   nitiaufin = ', nitiaufin
172         WRITE(numout,*) '      Type of IAU weighting function                           niaufn    = ', niaufn
173         WRITE(numout,*) '      Logical switch for ensuring that the sa > salfixmin      ln_salfix = ', ln_salfix
174         WRITE(numout,*) '      Minimum salinity after applying the increments           salfixmin = ', salfixmin
[2128]175      ENDIF
176
[9019]177      nitbkg_r    = nitbkg    + nit000 - 1            ! Background time referenced to nit000
178      nitdin_r    = nitdin    + nit000 - 1            ! Background time for DI referenced to nit000
179      nitiaustr_r = nitiaustr + nit000 - 1            ! Start of IAU interval referenced to nit000
180      nitiaufin_r = nitiaufin + nit000 - 1            ! End of IAU interval referenced to nit000
[2128]181
[9019]182      iiauper     = nitiaufin_r - nitiaustr_r + 1     ! IAU interval length
183      icycper     = nitend      - nit000      + 1     ! Cycle interval length
[2128]184
[9019]185      CALL calc_date( nitend     , ditend_date    )   ! Date of final time step
186      CALL calc_date( nitbkg_r   , ditbkg_date    )   ! Background time for Jb referenced to ndate0
187      CALL calc_date( nitdin_r   , ditdin_date    )   ! Background time for DI referenced to ndate0
188      CALL calc_date( nitiaustr_r, ditiaustr_date )   ! IAU start time referenced to ndate0
189      CALL calc_date( nitiaufin_r, ditiaufin_date )   ! IAU end time referenced to ndate0
[6140]190
[2128]191      IF(lwp) THEN
192         WRITE(numout,*)
193         WRITE(numout,*) '   Time steps referenced to current cycle:'
194         WRITE(numout,*) '       iitrst      = ', nit000 - 1
195         WRITE(numout,*) '       nit000      = ', nit000
196         WRITE(numout,*) '       nitend      = ', nitend
197         WRITE(numout,*) '       nitbkg_r    = ', nitbkg_r
198         WRITE(numout,*) '       nitdin_r    = ', nitdin_r
199         WRITE(numout,*) '       nitiaustr_r = ', nitiaustr_r
200         WRITE(numout,*) '       nitiaufin_r = ', nitiaufin_r
201         WRITE(numout,*)
202         WRITE(numout,*) '   Dates referenced to current cycle:'
203         WRITE(numout,*) '       ndastp         = ', ndastp
204         WRITE(numout,*) '       ndate0         = ', ndate0
[6140]205         WRITE(numout,*) '       nn_time0       = ', nn_time0
206         WRITE(numout,*) '       ditend_date    = ', ditend_date
207         WRITE(numout,*) '       ditbkg_date    = ', ditbkg_date
208         WRITE(numout,*) '       ditdin_date    = ', ditdin_date
209         WRITE(numout,*) '       ditiaustr_date = ', ditiaustr_date
210         WRITE(numout,*) '       ditiaufin_date = ', ditiaufin_date
[2128]211      ENDIF
212
213
214      IF ( ( ln_asmdin ).AND.( ln_asmiau ) )   &
215         & CALL ctl_stop( ' ln_asmdin and ln_asmiau :', &
216         &                ' Choose Direct Initialization OR Incremental Analysis Updating')
217
218      IF (      ( ( .NOT. ln_asmdin ).AND.( .NOT. ln_asmiau ) ) &
[3764]219           .AND.( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ) .OR. ( ln_seaiceinc) )) &
220         & CALL ctl_stop( ' One or more of ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc is set to .true.', &
[2128]221         &                ' but ln_asmdin and ln_asmiau are both set to .false. :', &
222         &                ' Inconsistent options')
223
224      IF ( ( niaufn /= 0 ).AND.( niaufn /= 1 ) ) &
225         & CALL ctl_stop( ' niaufn /= 0 or niaufn /=1 :',  &
226         &                ' Type IAU weighting function is invalid')
227
[3764]228      IF ( ( .NOT. ln_trainc ).AND.( .NOT. ln_dyninc ).AND.( .NOT. ln_sshinc ).AND.( .NOT. ln_seaiceinc ) &
[2128]229         &                     )  &
[3764]230         & CALL ctl_warn( ' ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc are set to .false. :', &
[2128]231         &                ' The assimilation increments are not applied')
232
233      IF ( ( ln_asmiau ).AND.( nitiaustr == nitiaufin ) ) &
234         & CALL ctl_stop( ' nitiaustr = nitiaufin :',  &
235         &                ' IAU interval is of zero length')
236
237      IF ( ( ln_asmiau ).AND.( ( nitiaustr_r < nit000 ).OR.( nitiaufin_r > nitend ) ) ) &
238         & CALL ctl_stop( ' nitiaustr or nitiaufin :',  &
239         &                ' IAU starting or final time step is outside the cycle interval', &
240         &                 ' Valid range nit000 to nitend')
241
242      IF ( ( nitbkg_r < nit000 - 1 ).OR.( nitbkg_r > nitend ) ) &
243         & CALL ctl_stop( ' nitbkg :',  &
244         &                ' Background time step is outside the cycle interval')
245
246      IF ( ( nitdin_r < nit000 - 1 ).OR.( nitdin_r > nitend ) ) &
247         & CALL ctl_stop( ' nitdin :',  &
248         &                ' Background time step for Direct Initialization is outside', &
249         &                ' the cycle interval')
250
251      IF ( nstop > 0 ) RETURN       ! if there are any errors then go no further
252
253      !--------------------------------------------------------------------
254      ! Initialize the Incremental Analysis Updating weighting function
255      !--------------------------------------------------------------------
256
[9213]257      IF( ln_asmiau ) THEN
258         !
[2128]259         ALLOCATE( wgtiau( icycper ) )
[9213]260         !
[9019]261         wgtiau(:) = 0._wp
[9213]262         !
263         !                                !---------------------------------------------------------
264         IF( niaufn == 0 ) THEN           ! Constant IAU forcing
265            !                             !---------------------------------------------------------
[2128]266            DO jt = 1, iiauper
267               wgtiau(jt+nitiaustr-1) = 1.0 / REAL( iiauper )
268            END DO
[9213]269            !                             !---------------------------------------------------------
270         ELSEIF ( niaufn == 1 ) THEN      ! Linear hat-like, centred in middle of IAU interval
271            !                             !---------------------------------------------------------
[2128]272            ! Compute the normalization factor
[9213]273            znorm = 0._wp
274            IF( MOD( iiauper, 2 ) == 0 ) THEN   ! Even number of time steps in IAU interval
[2128]275               imid = iiauper / 2 
276               DO jt = 1, imid
277                  znorm = znorm + REAL( jt )
278               END DO
279               znorm = 2.0 * znorm
[9213]280            ELSE                                ! Odd number of time steps in IAU interval
[2128]281               imid = ( iiauper + 1 ) / 2       
282               DO jt = 1, imid - 1
283                  znorm = znorm + REAL( jt )
284               END DO
285               znorm = 2.0 * znorm + REAL( imid )
286            ENDIF
287            znorm = 1.0 / znorm
[9213]288            !
[2128]289            DO jt = 1, imid - 1
290               wgtiau(jt+nitiaustr-1) = REAL( jt ) * znorm
291            END DO
292            DO jt = imid, iiauper
293               wgtiau(jt+nitiaustr-1) = REAL( iiauper - jt + 1 ) * znorm
294            END DO
[9213]295            !
[2128]296         ENDIF
297
298         ! Test that the integral of the weights over the weighting interval equals 1
299          IF(lwp) THEN
300             WRITE(numout,*)
301             WRITE(numout,*) 'asm_inc_init : IAU weights'
302             WRITE(numout,*) '~~~~~~~~~~~~'
303             WRITE(numout,*) '             time step         IAU  weight'
304             WRITE(numout,*) '             =========     ====================='
305             ztotwgt = 0.0
306             DO jt = 1, icycper
307                ztotwgt = ztotwgt + wgtiau(jt)
308                WRITE(numout,*) '         ', jt, '       ', wgtiau(jt) 
309             END DO   
310             WRITE(numout,*) '         ==================================='
311             WRITE(numout,*) '         Time-integrated weight = ', ztotwgt
312             WRITE(numout,*) '         ==================================='
313          ENDIF
314         
315      ENDIF
316
317      !--------------------------------------------------------------------
318      ! Allocate and initialize the increment arrays
319      !--------------------------------------------------------------------
320
[9213]321      ALLOCATE( t_bkginc     (jpi,jpj,jpk) )   ;   t_bkginc     (:,:,:) = 0._wp
322      ALLOCATE( s_bkginc     (jpi,jpj,jpk) )   ;   s_bkginc     (:,:,:) = 0._wp
323      ALLOCATE( u_bkginc     (jpi,jpj,jpk) )   ;   u_bkginc     (:,:,:) = 0._wp
324      ALLOCATE( v_bkginc     (jpi,jpj,jpk) )   ;   v_bkginc     (:,:,:) = 0._wp
325      ALLOCATE( ssh_bkginc   (jpi,jpj)     )   ;   ssh_bkginc   (:,:)   = 0._wp
326      ALLOCATE( seaice_bkginc(jpi,jpj)     )   ;   seaice_bkginc(:,:)   = 0._wp
[2128]327#if defined key_asminc
[9213]328      ALLOCATE( ssh_iau      (jpi,jpj)     )   ;   ssh_iau      (:,:)   = 0._wp
[2128]329#endif
[8030]330#if defined key_cice && defined key_asminc
[9213]331      ALLOCATE( ndaice_da    (jpi,jpj)     )   ;   ndaice_da    (:,:)   = 0._wp
[8030]332#endif
[9213]333      !
334      IF ( ln_trainc .OR. ln_dyninc .OR.   &       !--------------------------------------
335         & ln_sshinc .OR. ln_seaiceinc   ) THEN    ! Read the increments from file
336         !                                         !--------------------------------------
[2128]337         CALL iom_open( c_asminc, inum )
[9213]338         !
339         CALL iom_get( inum, 'time'       , zdate_inc   ) 
[2128]340         CALL iom_get( inum, 'z_inc_dateb', z_inc_dateb )
341         CALL iom_get( inum, 'z_inc_datef', z_inc_datef )
342         z_inc_dateb = zdate_inc
343         z_inc_datef = zdate_inc
[9213]344         !
[2128]345         IF(lwp) THEN
346            WRITE(numout,*) 
[9213]347            WRITE(numout,*) 'asm_inc_init : Assimilation increments valid between dates ', z_inc_dateb,' and ', z_inc_datef
[2128]348            WRITE(numout,*) '~~~~~~~~~~~~'
349         ENDIF
[9213]350         !
351         IF ( ( z_inc_dateb < ndastp + nn_time0*0.0001_wp ) .OR.   &
352            & ( z_inc_datef > ditend_date ) ) &
353            &    CALL ctl_warn( ' Validity time of assimilation increments is ', &
354            &                   ' outside the assimilation interval' )
[2128]355
[6140]356         IF ( ( ln_asmdin ).AND.( zdate_inc /= ditdin_date ) ) &
[2128]357            & CALL ctl_warn( ' Validity time of assimilation increments does ', &
358            &                ' not agree with Direct Initialization time' )
359
360         IF ( ln_trainc ) THEN   
361            CALL iom_get( inum, jpdom_autoglo, 'bckint', t_bkginc, 1 )
362            CALL iom_get( inum, jpdom_autoglo, 'bckins', s_bkginc, 1 )
363            ! Apply the masks
364            t_bkginc(:,:,:) = t_bkginc(:,:,:) * tmask(:,:,:)
365            s_bkginc(:,:,:) = s_bkginc(:,:,:) * tmask(:,:,:)
366            ! Set missing increments to 0.0 rather than 1e+20
367            ! to allow for differences in masks
368            WHERE( ABS( t_bkginc(:,:,:) ) > 1.0e+10 ) t_bkginc(:,:,:) = 0.0
369            WHERE( ABS( s_bkginc(:,:,:) ) > 1.0e+10 ) s_bkginc(:,:,:) = 0.0
370         ENDIF
371
372         IF ( ln_dyninc ) THEN   
373            CALL iom_get( inum, jpdom_autoglo, 'bckinu', u_bkginc, 1 )             
374            CALL iom_get( inum, jpdom_autoglo, 'bckinv', v_bkginc, 1 )             
375            ! Apply the masks
376            u_bkginc(:,:,:) = u_bkginc(:,:,:) * umask(:,:,:)
377            v_bkginc(:,:,:) = v_bkginc(:,:,:) * vmask(:,:,:)
378            ! Set missing increments to 0.0 rather than 1e+20
379            ! to allow for differences in masks
380            WHERE( ABS( u_bkginc(:,:,:) ) > 1.0e+10 ) u_bkginc(:,:,:) = 0.0
381            WHERE( ABS( v_bkginc(:,:,:) ) > 1.0e+10 ) v_bkginc(:,:,:) = 0.0
382         ENDIF
383       
384         IF ( ln_sshinc ) THEN
385            CALL iom_get( inum, jpdom_autoglo, 'bckineta', ssh_bkginc, 1 )
386            ! Apply the masks
387            ssh_bkginc(:,:) = ssh_bkginc(:,:) * tmask(:,:,1)
388            ! Set missing increments to 0.0 rather than 1e+20
389            ! to allow for differences in masks
390            WHERE( ABS( ssh_bkginc(:,:) ) > 1.0e+10 ) ssh_bkginc(:,:) = 0.0
391         ENDIF
392
[3764]393         IF ( ln_seaiceinc ) THEN
394            CALL iom_get( inum, jpdom_autoglo, 'bckinseaice', seaice_bkginc, 1 )
395            ! Apply the masks
396            seaice_bkginc(:,:) = seaice_bkginc(:,:) * tmask(:,:,1)
397            ! Set missing increments to 0.0 rather than 1e+20
398            ! to allow for differences in masks
399            WHERE( ABS( seaice_bkginc(:,:) ) > 1.0e+10 ) seaice_bkginc(:,:) = 0.0
400         ENDIF
[9213]401         !
[2128]402         CALL iom_close( inum )
[9213]403         !
[2128]404      ENDIF
[9213]405      !
406      !                                            !--------------------------------------
407      IF ( ln_dyninc .AND. nn_divdmp > 0 ) THEN    ! Apply divergence damping filter
408         !                                         !--------------------------------------
[9019]409         ALLOCATE( zhdiv(jpi,jpj) ) 
[5836]410         !
411         DO jt = 1, nn_divdmp
412            !
[9019]413            DO jk = 1, jpkm1           ! zhdiv = e1e1 * div
414               zhdiv(:,:) = 0._wp
[3764]415               DO jj = 2, jpjm1
416                  DO ji = fs_2, fs_jpim1   ! vector opt.
[9019]417                     zhdiv(ji,jj) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * u_bkginc(ji  ,jj,jk)    &
418                        &            - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * u_bkginc(ji-1,jj,jk)    &
419                        &            + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * v_bkginc(ji,jj  ,jk)    &
420                        &            - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * v_bkginc(ji,jj-1,jk)  ) / e3t_n(ji,jj,jk)
[3764]421                  END DO
[3294]422               END DO
[9019]423               CALL lbc_lnk( zhdiv, 'T', 1. )   ! lateral boundary cond. (no sign change)
[5836]424               !
[3764]425               DO jj = 2, jpjm1
426                  DO ji = fs_2, fs_jpim1   ! vector opt.
[6140]427                     u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk)                         &
[9019]428                        &               + 0.2_wp * ( zhdiv(ji+1,jj) - zhdiv(ji  ,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
[6140]429                     v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk)                         &
[9019]430                        &               + 0.2_wp * ( zhdiv(ji,jj+1) - zhdiv(ji,jj  ) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
[3764]431                  END DO
[3294]432               END DO
433            END DO
[5836]434            !
[3764]435         END DO
[5836]436         !
[9019]437         DEALLOCATE( zhdiv ) 
[5836]438         !
[3294]439      ENDIF
[9213]440      !
441      !                             !-----------------------------------------------------
442      IF ( ln_asmdin ) THEN         ! Allocate and initialize the background state arrays
443         !                          !-----------------------------------------------------
[5836]444         !
[9213]445         ALLOCATE( t_bkg  (jpi,jpj,jpk) )   ;   t_bkg  (:,:,:) = 0._wp
446         ALLOCATE( s_bkg  (jpi,jpj,jpk) )   ;   s_bkg  (:,:,:) = 0._wp
447         ALLOCATE( u_bkg  (jpi,jpj,jpk) )   ;   u_bkg  (:,:,:) = 0._wp
448         ALLOCATE( v_bkg  (jpi,jpj,jpk) )   ;   v_bkg  (:,:,:) = 0._wp
449         ALLOCATE( ssh_bkg(jpi,jpj)     )   ;   ssh_bkg(:,:)   = 0._wp
[5836]450         !
451         !
[2128]452         !--------------------------------------------------------------------
453         ! Read from file the background state at analysis time
454         !--------------------------------------------------------------------
[5836]455         !
[2128]456         CALL iom_open( c_asmdin, inum )
[5836]457         !
[3764]458         CALL iom_get( inum, 'rdastp', zdate_bkg ) 
[5836]459         !
[2128]460         IF(lwp) THEN
461            WRITE(numout,*) 
[9213]462            WRITE(numout,*) '   ==>>>  Assimilation background state valid at : ', zdate_bkg
463            WRITE(numout,*)
[2128]464         ENDIF
[5836]465         !
[9213]466         IF ( zdate_bkg /= ditdin_date )   &
[2128]467            & CALL ctl_warn( ' Validity time of assimilation background state does', &
468            &                ' not agree with Direct Initialization time' )
[5836]469         !
[2128]470         IF ( ln_trainc ) THEN   
471            CALL iom_get( inum, jpdom_autoglo, 'tn', t_bkg )
472            CALL iom_get( inum, jpdom_autoglo, 'sn', s_bkg )
473            t_bkg(:,:,:) = t_bkg(:,:,:) * tmask(:,:,:)
474            s_bkg(:,:,:) = s_bkg(:,:,:) * tmask(:,:,:)
475         ENDIF
[5836]476         !
[2128]477         IF ( ln_dyninc ) THEN   
478            CALL iom_get( inum, jpdom_autoglo, 'un', u_bkg )
479            CALL iom_get( inum, jpdom_autoglo, 'vn', v_bkg )
480            u_bkg(:,:,:) = u_bkg(:,:,:) * umask(:,:,:)
481            v_bkg(:,:,:) = v_bkg(:,:,:) * vmask(:,:,:)
482         ENDIF
[5836]483         !
[2128]484         IF ( ln_sshinc ) THEN
485            CALL iom_get( inum, jpdom_autoglo, 'sshn', ssh_bkg )
486            ssh_bkg(:,:) = ssh_bkg(:,:) * tmask(:,:,1)
487         ENDIF
[5836]488         !
[2128]489         CALL iom_close( inum )
[5836]490         !
[2128]491      ENDIF
[2392]492      !
[9213]493      IF(lwp) WRITE(numout,*) '   ==>>>   Euler time step switch is ', neuler
494      !
495      IF( lk_asminc ) THEN                            !==  data assimilation  ==!
496         IF( ln_bkgwri )   CALL asm_bkg_wri( nit000 - 1 )      ! Output background fields
497         IF( ln_asmdin ) THEN                                  ! Direct initialization
498            IF( ln_trainc )   CALL tra_asm_inc( nit000 - 1 )      ! Tracers
499            IF( ln_dyninc )   CALL dyn_asm_inc( nit000 - 1 )      ! Dynamics
500            IF( ln_sshinc )   CALL ssh_asm_inc( nit000 - 1 )      ! SSH
501         ENDIF
502      ENDIF
503      !
[2128]504   END SUBROUTINE asm_inc_init
[9213]505   
506   
[2128]507   SUBROUTINE tra_asm_inc( kt )
508      !!----------------------------------------------------------------------
509      !!                    ***  ROUTINE tra_asm_inc  ***
510      !!         
511      !! ** Purpose : Apply the tracer (T and S) assimilation increments
512      !!
513      !! ** Method  : Direct initialization or Incremental Analysis Updating
514      !!
515      !! ** Action  :
516      !!----------------------------------------------------------------------
[5836]517      INTEGER, INTENT(IN) ::   kt   ! Current time step
[2392]518      !
[5836]519      INTEGER  :: ji, jj, jk
520      INTEGER  :: it
[2128]521      REAL(wp) :: zincwgt  ! IAU weight for current time step
[3764]522      REAL (wp), DIMENSION(jpi,jpj,jpk) :: fzptnz ! 3d freezing point values
[2392]523      !!----------------------------------------------------------------------
[5836]524      !
[3764]525      ! freezing point calculation taken from oc_fz_pt (but calculated for all depths)
526      ! used to prevent the applied increments taking the temperature below the local freezing point
[4990]527      DO jk = 1, jpkm1
[6140]528        CALL eos_fzp( tsn(:,:,jk,jp_sal), fzptnz(:,:,jk), gdept_n(:,:,jk) )
[4990]529      END DO
[5836]530         !
531         !                             !--------------------------------------
532      IF ( ln_asmiau ) THEN            ! Incremental Analysis Updating
533         !                             !--------------------------------------
534         !
[2128]535         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
[5836]536            !
[2128]537            it = kt - nit000 + 1
538            zincwgt = wgtiau(it) / rdt   ! IAU weight for the current time step
[5836]539            !
[2128]540            IF(lwp) THEN
541               WRITE(numout,*) 
[4990]542               WRITE(numout,*) 'tra_asm_inc : Tracer IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
[2128]543               WRITE(numout,*) '~~~~~~~~~~~~'
544            ENDIF
[5836]545            !
[2128]546            ! Update the tracer tendencies
547            DO jk = 1, jpkm1
[3764]548               IF (ln_temnofreeze) THEN
549                  ! Do not apply negative increments if the temperature will fall below freezing
550                  WHERE(t_bkginc(:,:,jk) > 0.0_wp .OR. &
551                     &   tsn(:,:,jk,jp_tem) + tsa(:,:,jk,jp_tem) + t_bkginc(:,:,jk) * wgtiau(it) > fzptnz(:,:,jk) ) 
552                     tsa(:,:,jk,jp_tem) = tsa(:,:,jk,jp_tem) + t_bkginc(:,:,jk) * zincwgt 
553                  END WHERE
554               ELSE
555                  tsa(:,:,jk,jp_tem) = tsa(:,:,jk,jp_tem) + t_bkginc(:,:,jk) * zincwgt 
556               ENDIF
557               IF (ln_salfix) THEN
558                  ! Do not apply negative increments if the salinity will fall below a specified
559                  ! minimum value salfixmin
560                  WHERE(s_bkginc(:,:,jk) > 0.0_wp .OR. &
561                     &   tsn(:,:,jk,jp_sal) + tsa(:,:,jk,jp_sal) + s_bkginc(:,:,jk) * wgtiau(it) > salfixmin ) 
562                     tsa(:,:,jk,jp_sal) = tsa(:,:,jk,jp_sal) + s_bkginc(:,:,jk) * zincwgt
563                  END WHERE
564               ELSE
565                  tsa(:,:,jk,jp_sal) = tsa(:,:,jk,jp_sal) + s_bkginc(:,:,jk) * zincwgt
566               ENDIF
[2128]567            END DO
[5836]568            !
[2128]569         ENDIF
[5836]570         !
[2128]571         IF ( kt == nitiaufin_r + 1  ) THEN   ! For bias crcn to work
572            DEALLOCATE( t_bkginc )
573            DEALLOCATE( s_bkginc )
574         ENDIF
[5836]575         !                             !--------------------------------------
576      ELSEIF ( ln_asmdin ) THEN        ! Direct Initialization
577         !                             !--------------------------------------
578         !           
[2128]579         IF ( kt == nitdin_r ) THEN
[5836]580            !
[2128]581            neuler = 0  ! Force Euler forward step
[5836]582            !
[2128]583            ! Initialize the now fields with the background + increment
[3764]584            IF (ln_temnofreeze) THEN
585               ! Do not apply negative increments if the temperature will fall below freezing
[4990]586               WHERE( t_bkginc(:,:,:) > 0.0_wp .OR. tsn(:,:,:,jp_tem) + t_bkginc(:,:,:) > fzptnz(:,:,:) ) 
[3764]587                  tsn(:,:,:,jp_tem) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
588               END WHERE
589            ELSE
590               tsn(:,:,:,jp_tem) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
591            ENDIF
[2128]592            IF (ln_salfix) THEN
[3764]593               ! Do not apply negative increments if the salinity will fall below a specified
594               ! minimum value salfixmin
[4990]595               WHERE( s_bkginc(:,:,:) > 0.0_wp .OR. tsn(:,:,:,jp_sal) + s_bkginc(:,:,:) > salfixmin ) 
[3764]596                  tsn(:,:,:,jp_sal) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
597               END WHERE
598            ELSE
599               tsn(:,:,:,jp_sal) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
[2128]600            ENDIF
601
[4990]602            tsb(:,:,:,:) = tsn(:,:,:,:)                 ! Update before fields
[2128]603
[4990]604            CALL eos( tsb, rhd, rhop, gdept_0(:,:,:) )  ! Before potential and in situ densities
605!!gm  fabien
606!            CALL eos( tsb, rhd, rhop )                ! Before potential and in situ densities
607!!gm
608
[6140]609            IF( ln_zps .AND. .NOT. lk_c1d .AND. .NOT. ln_isfcav)      &
610               &  CALL zps_hde    ( kt, jpts, tsb, gtsu, gtsv,        &  ! Partial steps: before horizontal gradient
611               &                              rhd, gru , grv          )  ! of t, s, rd at the last ocean level
612            IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav)      &
613               &  CALL zps_hde_isf( nit000, jpts, tsb, gtsu, gtsv, gtui, gtvi,    &    ! Partial steps for top cell (ISF)
614               &                                  rhd, gru , grv , grui, grvi     )    ! of t, s, rd at the last ocean level
615
[2128]616            DEALLOCATE( t_bkginc )
617            DEALLOCATE( s_bkginc )
618            DEALLOCATE( t_bkg    )
619            DEALLOCATE( s_bkg    )
620         ENDIF
[2392]621         
[2128]622      ENDIF
[3764]623      ! Perhaps the following call should be in step
[5836]624      IF ( ln_seaiceinc  )   CALL seaice_asm_inc ( kt )   ! apply sea ice concentration increment
[2392]625      !
[2128]626   END SUBROUTINE tra_asm_inc
627
[2392]628
[2128]629   SUBROUTINE dyn_asm_inc( kt )
630      !!----------------------------------------------------------------------
631      !!                    ***  ROUTINE dyn_asm_inc  ***
632      !!         
633      !! ** Purpose : Apply the dynamics (u and v) assimilation increments.
634      !!
635      !! ** Method  : Direct initialization or Incremental Analysis Updating.
636      !!
637      !! ** Action  :
638      !!----------------------------------------------------------------------
639      INTEGER, INTENT(IN) :: kt   ! Current time step
[2392]640      !
[2128]641      INTEGER :: jk
642      INTEGER :: it
643      REAL(wp) :: zincwgt  ! IAU weight for current time step
[2392]644      !!----------------------------------------------------------------------
[5836]645      !
646      !                          !--------------------------------------------
647      IF ( ln_asmiau ) THEN      ! Incremental Analysis Updating
648         !                       !--------------------------------------------
649         !
[2128]650         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
[5836]651            !
[2128]652            it = kt - nit000 + 1
653            zincwgt = wgtiau(it) / rdt   ! IAU weight for the current time step
[5836]654            !
[2128]655            IF(lwp) THEN
656               WRITE(numout,*) 
[5836]657               WRITE(numout,*) 'dyn_asm_inc : Dynamics IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
[2128]658               WRITE(numout,*) '~~~~~~~~~~~~'
659            ENDIF
[5836]660            !
[2128]661            ! Update the dynamic tendencies
662            DO jk = 1, jpkm1
663               ua(:,:,jk) = ua(:,:,jk) + u_bkginc(:,:,jk) * zincwgt
664               va(:,:,jk) = va(:,:,jk) + v_bkginc(:,:,jk) * zincwgt
665            END DO
[5836]666            !
[2128]667            IF ( kt == nitiaufin_r ) THEN
668               DEALLOCATE( u_bkginc )
669               DEALLOCATE( v_bkginc )
670            ENDIF
[5836]671            !
[2128]672         ENDIF
[5836]673         !                          !-----------------------------------------
674      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
675         !                          !-----------------------------------------
676         !         
[2128]677         IF ( kt == nitdin_r ) THEN
[5836]678            !
[2128]679            neuler = 0                    ! Force Euler forward step
[5836]680            !
[2128]681            ! Initialize the now fields with the background + increment
682            un(:,:,:) = u_bkg(:,:,:) + u_bkginc(:,:,:)
683            vn(:,:,:) = v_bkg(:,:,:) + v_bkginc(:,:,:) 
[5836]684            !
[2128]685            ub(:,:,:) = un(:,:,:)         ! Update before fields
686            vb(:,:,:) = vn(:,:,:)
[5836]687            !
[2128]688            DEALLOCATE( u_bkg    )
689            DEALLOCATE( v_bkg    )
690            DEALLOCATE( u_bkginc )
691            DEALLOCATE( v_bkginc )
692         ENDIF
[2392]693         !
[2128]694      ENDIF
[2392]695      !
[2128]696   END SUBROUTINE dyn_asm_inc
697
[2392]698
[2128]699   SUBROUTINE ssh_asm_inc( kt )
700      !!----------------------------------------------------------------------
701      !!                    ***  ROUTINE ssh_asm_inc  ***
702      !!         
703      !! ** Purpose : Apply the sea surface height assimilation increment.
704      !!
705      !! ** Method  : Direct initialization or Incremental Analysis Updating.
706      !!
707      !! ** Action  :
708      !!----------------------------------------------------------------------
709      INTEGER, INTENT(IN) :: kt   ! Current time step
[2392]710      !
[2128]711      INTEGER :: it
[3764]712      INTEGER :: jk
[2128]713      REAL(wp) :: zincwgt  ! IAU weight for current time step
[2392]714      !!----------------------------------------------------------------------
[5836]715      !
716      !                             !-----------------------------------------
717      IF ( ln_asmiau ) THEN         ! Incremental Analysis Updating
718         !                          !-----------------------------------------
719         !
[2128]720         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
[5836]721            !
[2128]722            it = kt - nit000 + 1
723            zincwgt = wgtiau(it) / rdt   ! IAU weight for the current time step
[5836]724            !
[2128]725            IF(lwp) THEN
726               WRITE(numout,*) 
727               WRITE(numout,*) 'ssh_asm_inc : SSH IAU at time step = ', &
728                  &  kt,' with IAU weight = ', wgtiau(it)
729               WRITE(numout,*) '~~~~~~~~~~~~'
730            ENDIF
[5836]731            !
[2128]732            ! Save the tendency associated with the IAU weighted SSH increment
733            ! (applied in dynspg.*)
734#if defined key_asminc
735            ssh_iau(:,:) = ssh_bkginc(:,:) * zincwgt
736#endif
737            IF ( kt == nitiaufin_r ) THEN
738               DEALLOCATE( ssh_bkginc )
739            ENDIF
[5836]740            !
[8552]741#if defined key_asminc
[8547]742         ELSE IF( kt == nitiaufin_r+1 ) THEN
[8546]743            !
744            ssh_iau(:,:) = 0._wp
745            !
[8552]746#endif
[2128]747         ENDIF
[5836]748         !                          !-----------------------------------------
749      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
750         !                          !-----------------------------------------
751         !
[2128]752         IF ( kt == nitdin_r ) THEN
[5836]753            !
754            neuler = 0                                   ! Force Euler forward step
755            !
756            sshn(:,:) = ssh_bkg(:,:) + ssh_bkginc(:,:)   ! Initialize the now fields the background + increment
757            !
758            sshb(:,:) = sshn(:,:)                        ! Update before fields
[6140]759            e3t_b(:,:,:) = e3t_n(:,:,:)
760!!gm why not e3u_b, e3v_b, gdept_b ????
[5836]761            !
[2128]762            DEALLOCATE( ssh_bkg    )
763            DEALLOCATE( ssh_bkginc )
[5836]764            !
[2128]765         ENDIF
[2392]766         !
[2128]767      ENDIF
[2392]768      !
[2128]769   END SUBROUTINE ssh_asm_inc
770
[9213]771
[9023]772   SUBROUTINE ssh_asm_div( kt, phdivn )
773      !!----------------------------------------------------------------------
774      !!                  ***  ROUTINE ssh_asm_div  ***
775      !!
776      !! ** Purpose :   ssh increment with z* is incorporated via a correction of the local divergence         
777      !!                across all the water column
778      !!
779      !! ** Method  :
780      !!                CAUTION : sshiau is positive (inflow) decreasing the
781      !!                          divergence and expressed in m/s
782      !!
783      !! ** Action  :   phdivn   decreased by the ssh increment
784      !!----------------------------------------------------------------------
785      INTEGER, INTENT(IN) :: kt                               ! ocean time-step index
786      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phdivn   ! horizontal divergence
787      !!
788      INTEGER  ::   jk                                        ! dummy loop index
789      REAL(wp), DIMENSION(:,:)  , POINTER       ::   ztim     ! local array
790      !!----------------------------------------------------------------------
791      !
792#if defined key_asminc
793      CALL ssh_asm_inc( kt ) !==   (calculate increments)
794      !
795      IF( ln_linssh ) THEN
796         phdivn(:,:,1) = phdivn(:,:,1) - ssh_iau(:,:) / e3t_n(:,:,1) * tmask(:,:,1)
797      ELSE
[9044]798         ALLOCATE( ztim(jpi,jpj) )
[9023]799         ztim(:,:) = ssh_iau(:,:) / ( ht_n(:,:) + 1.0 - ssmask(:,:) )
800         DO jk = 1, jpkm1                                 
801            phdivn(:,:,jk) = phdivn(:,:,jk) - ztim(:,:) * tmask(:,:,jk) 
802         END DO
803         !
[9044]804         DEALLOCATE(ztim)
[9023]805      ENDIF
806#endif
807      !
808   END SUBROUTINE ssh_asm_div
[3785]809
[9213]810
[3764]811   SUBROUTINE seaice_asm_inc( kt, kindic )
812      !!----------------------------------------------------------------------
813      !!                    ***  ROUTINE seaice_asm_inc  ***
814      !!         
815      !! ** Purpose : Apply the sea ice assimilation increment.
816      !!
817      !! ** Method  : Direct initialization or Incremental Analysis Updating.
818      !!
819      !! ** Action  :
820      !!
821      !!----------------------------------------------------------------------
[5836]822      INTEGER, INTENT(in)           ::   kt       ! Current time step
[3785]823      INTEGER, INTENT(in), OPTIONAL ::   kindic   ! flag for disabling the deallocation
824      !
825      INTEGER  ::   it
826      REAL(wp) ::   zincwgt   ! IAU weight for current time step
[9019]827#if defined key_lim3
[3785]828      REAL(wp), DIMENSION(jpi,jpj) ::   zofrld, zohicif, zseaicendg, zhicifinc  ! LIM
829      REAL(wp) ::   zhicifmin = 0.5_wp      ! ice minimum depth in metres
[3764]830#endif
[3785]831      !!----------------------------------------------------------------------
[5836]832      !
833      !                             !-----------------------------------------
834      IF ( ln_asmiau ) THEN         ! Incremental Analysis Updating
835         !                          !-----------------------------------------
836         !
[3764]837         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
[5836]838            !
[3764]839            it = kt - nit000 + 1
840            zincwgt = wgtiau(it)      ! IAU weight for the current time step
841            ! note this is not a tendency so should not be divided by rdt (as with the tracer and other increments)
[5836]842            !
[3764]843            IF(lwp) THEN
844               WRITE(numout,*) 
[5836]845               WRITE(numout,*) 'seaice_asm_inc : sea ice conc IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
[3764]846               WRITE(numout,*) '~~~~~~~~~~~~'
847            ENDIF
[5836]848            !
[9019]849            ! Sea-ice : LIM-3 case
[5836]850            !
[9019]851#if defined key_lim3
852            zofrld (:,:) = 1._wp - at_i(:,:)
853            zohicif(:,:) = hm_i(:,:)
[3785]854            !
[9019]855            at_i  (:,:) = 1. - MIN( MAX( 1.-at_i  (:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
856            at_i_b(:,:) = 1. - MIN( MAX( 1.-at_i_b(:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
857            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
[3785]858            !
[9019]859            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
[3785]860            !
[3764]861            ! Nudge sea ice depth to bring it up to a required minimum depth
[9019]862            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
863               zhicifinc(:,:) = (zhicifmin - hm_i(:,:)) * zincwgt   
[3764]864            ELSEWHERE
865               zhicifinc(:,:) = 0.0_wp
866            END WHERE
[3785]867            !
868            ! nudge ice depth
[9019]869            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
[3785]870            !
871            ! seaice salinity balancing (to add)
[3764]872#endif
[9213]873            !
[4245]874#if defined key_cice && defined key_asminc
[3785]875            ! Sea-ice : CICE case. Pass ice increment tendency into CICE
[3764]876            ndaice_da(:,:) = seaice_bkginc(:,:) * zincwgt / rdt
877#endif
[9213]878            !
[3764]879            IF ( kt == nitiaufin_r ) THEN
880               DEALLOCATE( seaice_bkginc )
881            ENDIF
[9213]882            !
[3764]883         ELSE
[9213]884            !
[4245]885#if defined key_cice && defined key_asminc
[5836]886            ndaice_da(:,:) = 0._wp        ! Sea-ice : CICE case. Zero ice increment tendency into CICE
[3764]887#endif
[9213]888            !
[3764]889         ENDIF
[5836]890         !                          !-----------------------------------------
891      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
892         !                          !-----------------------------------------
893         !
[3764]894         IF ( kt == nitdin_r ) THEN
[5836]895            !
[3764]896            neuler = 0                    ! Force Euler forward step
[5836]897            !
[9019]898            ! Sea-ice : LIM-3 case
[5836]899            !
[9019]900#if defined key_lim3
901            zofrld (:,:) = 1._wp - at_i(:,:)
902            zohicif(:,:) = hm_i(:,:)
[3785]903            !
[3764]904            ! Initialize the now fields the background + increment
[9019]905            at_i(:,:) = 1. - MIN( MAX( 1.-at_i(:,:) - seaice_bkginc(:,:), 0.0_wp), 1.0_wp)
906            at_i_b(:,:) = at_i(:,:) 
907            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
[3785]908            !
[9019]909            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
910            !
[3764]911            ! Nudge sea ice depth to bring it up to a required minimum depth
[9019]912            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
913               zhicifinc(:,:) = (zhicifmin - hm_i(:,:)) * zincwgt   
[3764]914            ELSEWHERE
[9019]915               zhicifinc(:,:) = 0.0_wp
[3764]916            END WHERE
[3785]917            !
918            ! nudge ice depth
[9019]919            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
[3785]920            !
921            ! seaice salinity balancing (to add)
[3764]922#endif
[5836]923            !
[4245]924#if defined key_cice && defined key_asminc
925            ! Sea-ice : CICE case. Pass ice increment tendency into CICE
[3764]926           ndaice_da(:,:) = seaice_bkginc(:,:) / rdt
927#endif
[5836]928            IF ( .NOT. PRESENT(kindic) ) THEN
929               DEALLOCATE( seaice_bkginc )
930            END IF
931            !
[3764]932         ELSE
[5836]933            !
934#if defined key_cice && defined key_asminc
935            ndaice_da(:,:) = 0._wp     ! Sea-ice : CICE case. Zero ice increment tendency into CICE
[3764]936#endif
[5836]937            !
[3764]938         ENDIF
939
[9019]940!#if defined defined key_lim3 || defined key_cice
[3764]941!
942!            IF (ln_seaicebal ) THEN       
943!             !! balancing salinity increments
944!             !! simple case from limflx.F90 (doesn't include a mass flux)
945!             !! assumption is that as ice concentration is reduced or increased
946!             !! the snow and ice depths remain constant
947!             !! note that snow is being created where ice concentration is being increased
948!             !! - could be more sophisticated and
949!             !! not do this (but would need to alter h_snow)
950!
951!             usave(:,:,:)=sb(:,:,:)   ! use array as a temporary store
952!
953!             DO jj = 1, jpj
954!               DO ji = 1, jpi
955!           ! calculate change in ice and snow mass per unit area
956!           ! positive values imply adding salt to the ocean (results from ice formation)
957!           ! fwf : ice formation and melting
958!
959!                 zfons = ( -nfresh_da(ji,jj)*soce + nfsalt_da(ji,jj) )*rdt
960!
961!           ! change salinity down to mixed layer depth
962!                 mld=hmld_kara(ji,jj)
963!
964!           ! prevent small mld
965!           ! less than 10m can cause salinity instability
966!                 IF (mld < 10) mld=10
967!
968!           ! set to bottom of a level
969!                 DO jk = jpk-1, 2, -1
970!                   IF ((mld > gdepw(ji,jj,jk)) .and. (mld < gdepw(ji,jj,jk+1))) THEN
971!                     mld=gdepw(ji,jj,jk+1)
972!                     jkmax=jk
973!                   ENDIF
974!                 ENDDO
975!
976!            ! avoid applying salinity balancing in shallow water or on land
977!            !
978!
979!            ! dsal_ocn (psu kg m^-2) / (kg m^-3 * m)
980!
981!                 dsal_ocn=0.0_wp
982!                 sal_thresh=5.0_wp        ! minimum salinity threshold for salinity balancing
983!
984!                 if (tmask(ji,jj,1) > 0 .AND. tmask(ji,jj,jkmax) > 0 ) &
985!                              dsal_ocn = zfons / (rhop(ji,jj,1) * mld)
986!
987!           ! put increments in for levels in the mixed layer
988!           ! but prevent salinity below a threshold value
989!
990!                   DO jk = 1, jkmax             
991!
992!                     IF (dsal_ocn > 0.0_wp .or. sb(ji,jj,jk)+dsal_ocn > sal_thresh) THEN
993!                           sb(ji,jj,jk) = sb(ji,jj,jk) + dsal_ocn
994!                           sn(ji,jj,jk) = sn(ji,jj,jk) + dsal_ocn
995!                     ENDIF
996!
997!                   ENDDO
998!
999!      !            !  salt exchanges at the ice/ocean interface
1000!      !            zpmess         = zfons / rdt_ice    ! rdt_ice is ice timestep
1001!      !
1002!      !! Adjust fsalt. A +ve fsalt means adding salt to ocean
1003!      !!           fsalt(ji,jj) =  fsalt(ji,jj) + zpmess     ! adjust fsalt 
1004!      !!               
1005!      !!           emps(ji,jj) = emps(ji,jj) + zpmess        ! or adjust emps (see icestp1d)
1006!      !!                                                     ! E-P (kg m-2 s-2)
1007!      !            emp(ji,jj) = emp(ji,jj) + zpmess          ! E-P (kg m-2 s-2)
1008!               ENDDO !ji
1009!             ENDDO !jj!
1010!
1011!            ENDIF !ln_seaicebal
1012!
1013!#endif
[5836]1014         !
[3764]1015      ENDIF
[5836]1016      !
[3764]1017   END SUBROUTINE seaice_asm_inc
[3785]1018   
[2392]1019   !!======================================================================
[2128]1020END MODULE asminc
Note: See TracBrowser for help on using the repository browser.