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.
istate.f90 in NEMO/trunk/tools/DOMAINcfg/src – NEMO

source: NEMO/trunk/tools/DOMAINcfg/src/istate.f90 @ 9598

Last change on this file since 9598 was 9598, checked in by nicolasmartin, 6 years ago

Reorganisation plan for NEMO repository: changes to make compilation succeed with new structure
Juste one issue left with AGRIF_NORDIC with AGRIF preprocessing
Standardisation of routines header with version 4.0 and year 2018
Fix for some broken symlinks

File size: 24.8 KB
Line 
1MODULE istate
2   !!======================================================================
3   !!                     ***  MODULE  istate  ***
4   !! Ocean state   :  initial state setting
5   !!=====================================================================
6   !! History :  OPA  !  1989-12  (P. Andrich)  Original code
7   !!            5.0  !  1991-11  (G. Madec)  rewritting
8   !!            6.0  !  1996-01  (G. Madec)  terrain following coordinates
9   !!            8.0  !  2001-09  (M. Levy, M. Ben Jelloul)  istate_eel
10   !!            8.0  !  2001-09  (M. Levy, M. Ben Jelloul)  istate_uvg
11   !!   NEMO     1.0  !  2003-08  (G. Madec, C. Talandier)  F90: Free form, modules + EEL R5
12   !!             -   !  2004-05  (A. Koch-Larrouy)  istate_gyre
13   !!            2.0  !  2006-07  (S. Masson)  distributed restart using iom
14   !!            3.3  !  2010-10  (C. Ethe) merge TRC-TRA
15   !!            3.4  !  2011-04  (G. Madec) Merge of dtatem and dtasal & suppression of tb,tn/sb,sn
16   !!----------------------------------------------------------------------
17
18   !!----------------------------------------------------------------------
19   !!   istate_init   : initial state setting
20   !!   istate_tem    : analytical profile for initial Temperature
21   !!   istate_sal    : analytical profile for initial Salinity
22   !!   istate_eel    : initial state setting of EEL R5 configuration
23   !!   istate_gyre   : initial state setting of GYRE configuration
24   !!   istate_uvg    : initial velocity in geostropic balance
25   !!----------------------------------------------------------------------
26   USE oce             ! ocean dynamics and active tracers
27   USE dom_oce         ! ocean space and time domain
28   USE c1d             ! 1D vertical configuration
29   USE daymod          ! calendar
30   USE eosbn2          ! eq. of state, Brunt Vaisala frequency (eos     routine)
31   USE ldftra          ! lateral physics: ocean active tracers
32   USE zdf_oce         ! ocean vertical physics
33   USE phycst          ! physical constants
34   USE dtatsd          ! data temperature and salinity   (dta_tsd routine)
35   USE dtauvd          ! data: U & V current             (dta_uvd routine)
36   USE domvvl          ! varying vertical mesh
37   USE iscplrst        ! ice sheet coupling
38   !
39   USE in_out_manager  ! I/O manager
40   USE iom             ! I/O library
41   USE lib_mpp         ! MPP library
42   USE restart         ! restart
43   USE wrk_nemo        ! Memory allocation
44   USE timing          ! Timing
45
46   IMPLICIT NONE
47   PRIVATE
48
49   PUBLIC   istate_init   ! routine called by step.F90
50
51   !! * Substitutions
52   !!----------------------------------------------------------------------
53   !!                   ***  vectopt_loop_substitute  ***
54   !!----------------------------------------------------------------------
55   !! ** purpose :   substitute the inner loop start/end indices with CPP macro
56   !!                allow unrolling of do-loop (useful with vector processors)
57   !!----------------------------------------------------------------------
58   !!----------------------------------------------------------------------
59   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
60   !! $Id: vectopt_loop_substitute.h90 4990 2014-12-15 16:42:49Z timgraham $
61   !! Software governed by the CeCILL licence (./LICENSE)
62   !!----------------------------------------------------------------------
63   !!----------------------------------------------------------------------
64   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
65   !! $Id: istate.F90 6140 2015-12-21 11:35:23Z timgraham $
66   !! Software governed by the CeCILL licence     (./LICENSE)
67   !!----------------------------------------------------------------------
68CONTAINS
69
70   SUBROUTINE istate_init
71      !!----------------------------------------------------------------------
72      !!                   ***  ROUTINE istate_init  ***
73      !!
74      !! ** Purpose :   Initialization of the dynamics and tracer fields.
75      !!----------------------------------------------------------------------
76      INTEGER ::   ji, jj, jk   ! dummy loop indices
77      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zuvd    ! U & V data workspace
78      !!----------------------------------------------------------------------
79      !
80      IF( nn_timing == 1 )   CALL timing_start('istate_init')
81      !
82
83      IF(lwp) WRITE(numout,*)
84      IF(lwp) WRITE(numout,*) 'istate_ini : Initialization of the dynamics and tracers'
85      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
86
87                     CALL dta_tsd_init        ! Initialisation of T & S input data
88      IF( lk_c1d )   CALL dta_uvd_init        ! Initialization of U & V input data
89
90      rhd  (:,:,:  ) = 0._wp   ;   rhop (:,:,:  ) = 0._wp      ! set one for all to 0 at level jpk
91      rn2b (:,:,:  ) = 0._wp   ;   rn2  (:,:,:  ) = 0._wp      ! set one for all to 0 at levels 1 and jpk
92      tsa  (:,:,:,:) = 0._wp                                   ! set one for all to 0 at level jpk
93      rab_b(:,:,:,:) = 0._wp   ;   rab_n(:,:,:,:) = 0._wp      ! set one for all to 0 at level jpk
94
95      IF( ln_rstart ) THEN                    ! Restart from a file
96         !                                    ! -------------------
97         CALL rst_read                        ! Read the restart file
98         IF (ln_iscpl)       CALL iscpl_stp   ! extraloate restart to wet and dry
99         CALL day_init                        ! model calendar (using both namelist and restart infos)
100      ELSE
101         !                                    ! Start from rest
102         !                                    ! ---------------
103         numror = 0                              ! define numror = 0 -> no restart file to read
104         neuler = 0                              ! Set time-step indicator at nit000 (euler forward)
105         CALL day_init                           ! model calendar (using both namelist and restart infos)
106         !                                       ! Initialization of ocean to zero
107         !   before fields      !       now fields     
108         sshb (:,:)   = 0._wp   ;   sshn (:,:)   = 0._wp
109         ub   (:,:,:) = 0._wp   ;   un   (:,:,:) = 0._wp
110         vb   (:,:,:) = 0._wp   ;   vn   (:,:,:) = 0._wp 
111                                    hdivn(:,:,:) = 0._wp
112         !
113         IF( cp_cfg == 'eel' ) THEN
114            CALL istate_eel                      ! EEL   configuration : start from pre-defined U,V T-S fields
115         ELSEIF( cp_cfg == 'gyre' ) THEN         
116            CALL istate_gyre                     ! GYRE  configuration : start from pre-defined T-S fields
117         ELSE                                    ! Initial T-S, U-V fields read in files
118            IF ( ln_tsd_init ) THEN              ! read 3D T and S data at nit000
119               CALL dta_tsd( nit000, tsb ) 
120               tsn(:,:,:,:) = tsb(:,:,:,:)
121               !
122            ELSE                                 ! Initial T-S fields defined analytically
123               CALL istate_t_s
124            ENDIF
125            IF ( ln_uvd_init .AND. lk_c1d ) THEN ! read 3D U and V data at nit000
126               CALL wrk_alloc( jpi,jpj,jpk,2,   zuvd )
127               CALL dta_uvd( nit000, zuvd )
128               ub(:,:,:) = zuvd(:,:,:,1) ;  un(:,:,:) = ub(:,:,:)
129               vb(:,:,:) = zuvd(:,:,:,2) ;  vn(:,:,:) = vb(:,:,:)
130               CALL wrk_dealloc( jpi,jpj,jpk,2,   zuvd )
131            ENDIF
132         ENDIF
133         !
134!!gm This is to be changed !!!!
135         ! - ML - sshn could be modified by istate_eel, so that initialization of e3t_b is done here
136         IF( .NOT.ln_linssh ) THEN
137            DO jk = 1, jpk
138               e3t_b(:,:,jk) = e3t_n(:,:,jk)
139            END DO
140         ENDIF
141!!gm
142         !
143      ENDIF
144      !
145      ! Initialize "now" and "before" barotropic velocities:
146      ! Do it whatever the free surface method, these arrays being eventually used
147      !
148      un_b(:,:) = 0._wp   ;   vn_b(:,:) = 0._wp
149      ub_b(:,:) = 0._wp   ;   vb_b(:,:) = 0._wp
150      !
151!!gm  the use of umsak & vmask is not necessary belox as un, vn, ub, vb are always masked
152      DO jk = 1, jpkm1
153         DO jj = 1, jpj
154            DO ji = 1, jpi
155               un_b(ji,jj) = un_b(ji,jj) + e3u_n(ji,jj,jk) * un(ji,jj,jk) * umask(ji,jj,jk)
156               vn_b(ji,jj) = vn_b(ji,jj) + e3v_n(ji,jj,jk) * vn(ji,jj,jk) * vmask(ji,jj,jk)
157               !
158               ub_b(ji,jj) = ub_b(ji,jj) + e3u_b(ji,jj,jk) * ub(ji,jj,jk) * umask(ji,jj,jk)
159               vb_b(ji,jj) = vb_b(ji,jj) + e3v_b(ji,jj,jk) * vb(ji,jj,jk) * vmask(ji,jj,jk)
160            END DO
161         END DO
162      END DO
163      !
164      un_b(:,:) = un_b(:,:) * r1_hu_n(:,:)
165      vn_b(:,:) = vn_b(:,:) * r1_hv_n(:,:)
166      !
167      ub_b(:,:) = ub_b(:,:) * r1_hu_b(:,:)
168      vb_b(:,:) = vb_b(:,:) * r1_hv_b(:,:)
169      !
170      IF( nn_timing == 1 )   CALL timing_stop('istate_init')
171      !
172   END SUBROUTINE istate_init
173
174
175   SUBROUTINE istate_t_s
176      !!---------------------------------------------------------------------
177      !!                  ***  ROUTINE istate_t_s  ***
178      !!   
179      !! ** Purpose :   Intialization of the temperature field with an
180      !!      analytical profile or a file (i.e. in EEL configuration)
181      !!
182      !! ** Method  : - temperature: use Philander analytic profile
183      !!              - salinity   : use to a constant value 35.5
184      !!
185      !! References :  Philander ???
186      !!----------------------------------------------------------------------
187      INTEGER  ::   ji, jj, jk
188      REAL(wp) ::   zsal = 35.50_wp
189      !!----------------------------------------------------------------------
190      !
191      IF(lwp) WRITE(numout,*)
192      IF(lwp) WRITE(numout,*) 'istate_t_s : Philander s initial temperature profile'
193      IF(lwp) WRITE(numout,*) '~~~~~~~~~~   and constant salinity (',zsal,' psu)'
194      !
195      DO jk = 1, jpk
196         tsn(:,:,jk,jp_tem) = (  ( ( 7.5 - 0. * ABS( gphit(:,:) )/30. ) * ( 1.-TANH((gdept_n(:,:,jk)-80.)/30.) )   &
197            &                + 10. * ( 5000. - gdept_n(:,:,jk) ) /5000.)  ) * tmask(:,:,jk)
198         tsb(:,:,jk,jp_tem) = tsn(:,:,jk,jp_tem)
199      END DO
200      tsn(:,:,:,jp_sal) = zsal * tmask(:,:,:)
201      tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
202      !
203   END SUBROUTINE istate_t_s
204
205
206   SUBROUTINE istate_eel
207      !!----------------------------------------------------------------------
208      !!                   ***  ROUTINE istate_eel  ***
209      !!
210      !! ** Purpose :   Initialization of the dynamics and tracers for EEL R5
211      !!      configuration (channel with or without a topographic bump)
212      !!
213      !! ** Method  : - set temprature field
214      !!              - set salinity field
215      !!              - set velocity field including horizontal divergence
216      !!                and relative vorticity fields
217      !!----------------------------------------------------------------------
218      USE divhor     ! hor. divergence      (div_hor routine)
219      USE iom
220      !
221      INTEGER  ::   inum              ! temporary logical unit
222      INTEGER  ::   ji, jj, jk        ! dummy loop indices
223      INTEGER  ::   ijloc
224      REAL(wp) ::   zh1, zh2, zslope, zcst, zfcor   ! temporary scalars
225      REAL(wp) ::   zt1  = 15._wp                   ! surface temperature value (EEL R5)
226      REAL(wp) ::   zt2  =  5._wp                   ! bottom  temperature value (EEL R5)
227      REAL(wp) ::   zsal = 35.0_wp                  ! constant salinity (EEL R2, R5 and R6)
228      REAL(wp) ::   zueel = 0.1_wp                  ! constant uniform zonal velocity (EEL R5)
229      REAL(wp), DIMENSION(jpiglo,jpjglo) ::   zssh  ! initial ssh over the global domain
230      !!----------------------------------------------------------------------
231      !
232      SELECT CASE ( jp_cfg ) 
233         !                                              ! ====================
234         CASE ( 5 )                                     ! EEL R5 configuration
235            !                                           ! ====================
236            !
237            ! set temperature field with a linear profile
238            ! -------------------------------------------
239            IF(lwp) WRITE(numout,*)
240            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: linear temperature profile'
241            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
242            !
243            zh1 = gdept_1d(  1  )
244            zh2 = gdept_1d(jpkm1)
245            !
246            zslope = ( zt1 - zt2 ) / ( zh1 - zh2 )
247            zcst   = ( zt1 * ( zh1 - zh2) - ( zt1 - zt2 ) * zh1 ) / ( zh1 - zh2 )
248            !
249            DO jk = 1, jpk
250               tsn(:,:,jk,jp_tem) = ( zt2 + zt1 * exp( - gdept_n(:,:,jk) / 1000 ) ) * tmask(:,:,jk)
251               tsb(:,:,jk,jp_tem) = tsn(:,:,jk,jp_tem)
252            END DO
253            !
254            ! set salinity field to a constant value
255            ! --------------------------------------
256            IF(lwp) WRITE(numout,*)
257            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
258            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
259            !
260            tsn(:,:,:,jp_sal) = zsal * tmask(:,:,:)
261            tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
262            !
263            ! set the dynamics: U,V, hdiv (and ssh if necessary)
264            ! ----------------
265            ! Start EEL5 configuration with barotropic geostrophic velocities
266            ! according the sshb and sshn SSH imposed.
267            ! we assume a uniform grid (hence the use of e1t(1,1) for delta_y)
268            ! we use the Coriolis frequency at mid-channel.   
269            ub(:,:,:) = zueel * umask(:,:,:)
270            un(:,:,:) = ub(:,:,:)
271            ijloc = mj0(INT(jpjglo-1)/2)
272            zfcor = ff(1,ijloc)
273            !
274            DO jj = 1, jpjglo
275               zssh(:,jj) = - (FLOAT(jj)- FLOAT(jpjglo-1)/2.)*zueel*e1t(1,1)*zfcor/grav 
276            END DO
277            !
278            IF(lwp) THEN
279               WRITE(numout,*) ' Uniform zonal velocity for EEL R5:',zueel
280               WRITE(numout,*) ' Geostrophic SSH profile as a function of y:'
281               WRITE(numout,'(12(1x,f6.2))') zssh(1,:)
282            ENDIF
283            !
284            DO jj = 1, nlcj
285               DO ji = 1, nlci
286                  sshb(ji,jj) = zssh( mig(ji) , mjg(jj) ) * tmask(ji,jj,1)
287               END DO
288            END DO
289            sshb(nlci+1:jpi,      :   ) = 0.e0      ! set to zero extra mpp columns
290            sshb(      :   ,nlcj+1:jpj) = 0.e0      ! set to zero extra mpp rows
291            !
292            sshn(:,:) = sshb(:,:)                   ! set now ssh to the before value
293            !
294            IF( nn_rstssh /= 0 ) THEN 
295               nn_rstssh = 0                        ! hand-made initilization of ssh
296               CALL ctl_warn( 'istate_eel: force nn_rstssh = 0' )
297            ENDIF
298            !
299!!gm  Check  here call to div_hor should not be necessary
300!!gm         div_hor call runoffs  not sure they are defined at that level
301            CALL div_hor( nit000 )                  ! horizontal divergence and relative vorticity (curl)
302            ! N.B. the vertical velocity will be computed from the horizontal divergence field
303            ! in istate by a call to wzv routine
304
305
306            !                                     ! ==========================
307         CASE ( 2 , 6 )                           ! EEL R2 or R6 configuration
308            !                                     ! ==========================
309            !
310            ! set temperature field with a NetCDF file
311            ! ----------------------------------------
312            IF(lwp) WRITE(numout,*)
313            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R2 or R6: read initial temperature in a NetCDF file'
314            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
315            !
316            CALL iom_open ( 'eel.initemp', inum )
317            CALL iom_get ( inum, jpdom_data, 'initemp', tsb(:,:,:,jp_tem) ) ! read before temprature (tb)
318            CALL iom_close( inum )
319            !
320            tsn(:,:,:,jp_tem) = tsb(:,:,:,jp_tem)                            ! set nox temperature to tb
321            !
322            ! set salinity field to a constant value
323            ! --------------------------------------
324            IF(lwp) WRITE(numout,*)
325            IF(lwp) WRITE(numout,*) 'istate_eel : EEL R5: constant salinity field, S = ', zsal
326            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
327            !
328            tsn(:,:,:,jp_sal) = zsal * tmask(:,:,:)
329            tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
330            !
331            !                                    ! ===========================
332         CASE DEFAULT                            ! NONE existing configuration
333            !                                    ! ===========================
334            WRITE(ctmp1,*) 'EEL with a ', jp_cfg,' km resolution is not coded'
335            CALL ctl_stop( ctmp1 )
336            !
337      END SELECT
338      !
339   END SUBROUTINE istate_eel
340
341
342   SUBROUTINE istate_gyre
343      !!----------------------------------------------------------------------
344      !!                   ***  ROUTINE istate_gyre  ***
345      !!
346      !! ** Purpose :   Initialization of the dynamics and tracers for GYRE
347      !!      configuration (double gyre with rotated domain)
348      !!
349      !! ** Method  : - set temprature field
350      !!              - set salinity   field
351      !!----------------------------------------------------------------------
352      INTEGER :: ji, jj, jk  ! dummy loop indices
353      INTEGER            ::   inum          ! temporary logical unit
354      INTEGER, PARAMETER ::   ntsinit = 0   ! (0/1) (analytical/input data files) T&S initialization
355      !!----------------------------------------------------------------------
356      !
357      SELECT CASE ( ntsinit)
358      !
359      CASE ( 0 )                  ! analytical T/S profil deduced from LEVITUS
360         IF(lwp) WRITE(numout,*)
361         IF(lwp) WRITE(numout,*) 'istate_gyre : initial analytical T and S profil deduced from LEVITUS '
362         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
363         !
364         DO jk = 1, jpk
365            DO jj = 1, jpj
366               DO ji = 1, jpi
367                  tsn(ji,jj,jk,jp_tem) = (  16. - 12. * TANH( (gdept_n(ji,jj,jk) - 400) / 700 )         )   &
368                       &           * (-TANH( (500-gdept_n(ji,jj,jk)) / 150 ) + 1) / 2               &
369                       &       + (      15. * ( 1. - TANH( (gdept_n(ji,jj,jk)-50.) / 1500.) )       &
370                       &                - 1.4 * TANH((gdept_n(ji,jj,jk)-100.) / 100.)               &   
371                       &                + 7.  * (1500. - gdept_n(ji,jj,jk)) / 1500.             )   & 
372                       &           * (-TANH( (gdept_n(ji,jj,jk) - 500) / 150) + 1) / 2
373                  tsn(ji,jj,jk,jp_tem) = tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
374                  tsb(ji,jj,jk,jp_tem) = tsn(ji,jj,jk,jp_tem)
375
376                  tsn(ji,jj,jk,jp_sal) =  (  36.25 - 1.13 * TANH( (gdept_n(ji,jj,jk) - 305) / 460 )  )  &
377                     &              * (-TANH((500 - gdept_n(ji,jj,jk)) / 150) + 1) / 2          &
378                     &          + (  35.55 + 1.25 * (5000. - gdept_n(ji,jj,jk)) / 5000.         &
379                     &                - 1.62 * TANH( (gdept_n(ji,jj,jk) - 60.  ) / 650. )       &
380                     &                + 0.2  * TANH( (gdept_n(ji,jj,jk) - 35.  ) / 100. )       &
381                     &                + 0.2  * TANH( (gdept_n(ji,jj,jk) - 1000.) / 5000.)    )  &
382                     &              * (-TANH((gdept_n(ji,jj,jk) - 500) / 150) + 1) / 2 
383                  tsn(ji,jj,jk,jp_sal) = tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
384                  tsb(ji,jj,jk,jp_sal) = tsn(ji,jj,jk,jp_sal)
385               END DO
386            END DO
387         END DO
388         !
389      CASE ( 1 )                  ! T/S data fields read in dta_tem.nc/data_sal.nc files
390         IF(lwp) WRITE(numout,*)
391         IF(lwp) WRITE(numout,*) 'istate_gyre : initial T and S read from dta_tem.nc/data_sal.nc files'
392         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
393         IF(lwp) WRITE(numout,*) '              NetCDF FORMAT'
394
395         ! Read temperature field
396         ! ----------------------
397         CALL iom_open ( 'data_tem', inum )
398         CALL iom_get ( inum, jpdom_data, 'votemper', tsn(:,:,:,jp_tem) ) 
399         CALL iom_close( inum )
400
401         tsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem) * tmask(:,:,:) 
402         tsb(:,:,:,jp_tem) = tsn(:,:,:,jp_tem)
403
404         ! Read salinity field
405         ! -------------------
406         CALL iom_open ( 'data_sal', inum )
407         CALL iom_get ( inum, jpdom_data, 'vosaline', tsn(:,:,:,jp_sal) ) 
408         CALL iom_close( inum )
409
410         tsn(:,:,:,jp_sal) = tsn(:,:,:,jp_sal) * tmask(:,:,:) 
411         tsb(:,:,:,jp_sal) = tsn(:,:,:,jp_sal)
412         !
413      END SELECT
414      !
415      IF(lwp) THEN
416         WRITE(numout,*)
417         WRITE(numout,*) '              Initial temperature and salinity profiles:'
418         WRITE(numout, "(9x,' level   gdept_1d   temperature   salinity   ')" )
419         WRITE(numout, "(10x, i4, 3f10.2)" ) ( jk, gdept_1d(jk), tsn(2,2,jk,jp_tem), tsn(2,2,jk,jp_sal), jk = 1, jpk )
420      ENDIF
421      !
422   END SUBROUTINE istate_gyre
423
424
425   SUBROUTINE istate_uvg
426      !!----------------------------------------------------------------------
427      !!                  ***  ROUTINE istate_uvg  ***
428      !!
429      !! ** Purpose :   Compute the geostrophic velocities from (tn,sn) fields
430      !!
431      !! ** Method  :   Using the hydrostatic hypothesis the now hydrostatic
432      !!      pressure is computed by integrating the in-situ density from the
433      !!      surface to the bottom.
434      !!                 p=integral [ rau*g dz ]
435      !!----------------------------------------------------------------------
436      USE divhor          ! hor. divergence                       (div_hor routine)
437      USE lbclnk          ! ocean lateral boundary condition (or mpp link)
438      !
439      INTEGER ::   ji, jj, jk        ! dummy loop indices
440      REAL(wp) ::   zmsv, zphv, zmsu, zphu, zalfg     ! temporary scalars
441      REAL(wp), POINTER, DIMENSION(:,:,:) :: zprn
442      !!----------------------------------------------------------------------
443      !
444      CALL wrk_alloc( jpi,jpj,jpk,   zprn)
445      !
446      IF(lwp) WRITE(numout,*) 
447      IF(lwp) WRITE(numout,*) 'istate_uvg : Start from Geostrophy'
448      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
449
450      ! Compute the now hydrostatic pressure
451      ! ------------------------------------
452
453      zalfg = 0.5 * grav * rau0
454     
455      zprn(:,:,1) = zalfg * e3w_n(:,:,1) * ( 1 + rhd(:,:,1) )       ! Surface value
456
457      DO jk = 2, jpkm1                                              ! Vertical integration from the surface
458         zprn(:,:,jk) = zprn(:,:,jk-1)   &
459            &         + zalfg * e3w_n(:,:,jk) * ( 2. + rhd(:,:,jk) + rhd(:,:,jk-1) )
460      END DO 
461
462      ! Compute geostrophic balance
463      ! ---------------------------
464      DO jk = 1, jpkm1
465         DO jj = 2, jpjm1
466            DO ji = 2, jpim1   ! vertor opt.
467               zmsv = 1. / MAX(  umask(ji-1,jj+1,jk) + umask(ji  ,jj+1,jk)   &
468                               + umask(ji-1,jj  ,jk) + umask(ji  ,jj  ,jk) , 1.  )
469               zphv = ( zprn(ji  ,jj+1,jk) - zprn(ji-1,jj+1,jk) ) * umask(ji-1,jj+1,jk) / e1u(ji-1,jj+1)   &
470                    + ( zprn(ji+1,jj+1,jk) - zprn(ji  ,jj+1,jk) ) * umask(ji  ,jj+1,jk) / e1u(ji  ,jj+1)   &
471                    + ( zprn(ji  ,jj  ,jk) - zprn(ji-1,jj  ,jk) ) * umask(ji-1,jj  ,jk) / e1u(ji-1,jj  )   &
472                    + ( zprn(ji+1,jj  ,jk) - zprn(ji  ,jj  ,jk) ) * umask(ji  ,jj  ,jk) / e1u(ji  ,jj  )
473               zphv = 1. / rau0 * zphv * zmsv * vmask(ji,jj,jk)
474
475               zmsu = 1. / MAX(  vmask(ji+1,jj  ,jk) + vmask(ji  ,jj  ,jk)   &
476                               + vmask(ji+1,jj-1,jk) + vmask(ji  ,jj-1,jk) , 1.  )
477               zphu = ( zprn(ji+1,jj+1,jk) - zprn(ji+1,jj  ,jk) ) * vmask(ji+1,jj  ,jk) / e2v(ji+1,jj  )   &
478                    + ( zprn(ji  ,jj+1,jk) - zprn(ji  ,jj  ,jk) ) * vmask(ji  ,jj  ,jk) / e2v(ji  ,jj  )   &
479                    + ( zprn(ji+1,jj  ,jk) - zprn(ji+1,jj-1,jk) ) * vmask(ji+1,jj-1,jk) / e2v(ji+1,jj-1)   &
480                    + ( zprn(ji  ,jj  ,jk) - zprn(ji  ,jj-1,jk) ) * vmask(ji  ,jj-1,jk) / e2v(ji  ,jj-1)
481               zphu = 1. / rau0 * zphu * zmsu * umask(ji,jj,jk)
482
483               ! Compute the geostrophic velocities
484               un(ji,jj,jk) = -2. * zphu / ( ff(ji,jj) + ff(ji  ,jj-1) )
485               vn(ji,jj,jk) =  2. * zphv / ( ff(ji,jj) + ff(ji-1,jj  ) )
486            END DO
487         END DO
488      END DO
489
490      IF(lwp) WRITE(numout,*) '         we force to zero bottom velocity'
491
492      ! Susbtract the bottom velocity (level jpk-1 for flat bottom case)
493      ! to have a zero bottom velocity
494
495      DO jk = 1, jpkm1
496         un(:,:,jk) = ( un(:,:,jk) - un(:,:,jpkm1) ) * umask(:,:,jk)
497         vn(:,:,jk) = ( vn(:,:,jk) - vn(:,:,jpkm1) ) * vmask(:,:,jk)
498      END DO
499
500      CALL lbc_lnk( un, 'U', -1. )
501      CALL lbc_lnk( vn, 'V', -1. )
502     
503      ub(:,:,:) = un(:,:,:)
504      vb(:,:,:) = vn(:,:,:)
505     
506      !
507!!gm  Check  here call to div_hor should not be necessary
508!!gm         div_hor call runoffs  not sure they are defined at that level
509      CALL div_hor( nit000 )            ! now horizontal divergence
510      !
511      CALL wrk_dealloc( jpi,jpj,jpk,   zprn)
512      !
513   END SUBROUTINE istate_uvg
514
515   !!=====================================================================
516END MODULE istate
Note: See TracBrowser for help on using the repository browser.