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/2015/dev_merge_2015/NEMOGCM/NEMO/OPA_SRC/ASM – NEMO

source: branches/2015/dev_merge_2015/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90 @ 6069

Last change on this file since 6069 was 6069, checked in by timgraham, 8 years ago

Merge of dev_MetOffice_merge_2015 into branch (only NEMO directory for now).

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