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.
nemogcm.F90 in branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC – NEMO

source: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 6596

Last change on this file since 6596 was 6596, checked in by gm, 8 years ago

#1692 - branch SIMPLIF_2_usrdef: remove from namcfg and namdom many obsolete variables ; remove izoom/jzoom option

  • Property svn:keywords set to Id
File size: 42.4 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
11   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
12   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
15   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
16   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
17   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
18   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
19   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
20   !!             -   ! 2004-08  (C. Talandier) New trends organization
21   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
22   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
23   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
24   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
25   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
26   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
29   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!            3.4  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) add nemo_northcomms
31   !!             -   ! 2011-11  (C. Harris) decomposition changes for running with CICE
32   !!            3.6  ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening
33   !!             -   ! 2013-06  (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication
34   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
35   !!----------------------------------------------------------------------
36
37   !!----------------------------------------------------------------------
38   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
39   !!   nemo_init     : initialization of the NEMO system
40   !!   nemo_ctl      : initialisation of the contol print
41   !!   nemo_closefile: close remaining open files
42   !!   nemo_alloc    : dynamical allocation
43   !!   nemo_partition: calculate MPP domain decomposition
44   !!   factorise     : calculate the factors of the no. of MPI processes
45   !!----------------------------------------------------------------------
46   USE step_oce       ! module used in the ocean time stepping module (step.F90)
47   USE domcfg         ! domain configuration               (dom_cfg routine)
48   USE mppini         ! shared/distributed memory setting (mpp_init routine)
49   USE domain         ! domain initialization             (dom_init routine)
50#if defined key_nemocice_decomp
51   USE ice_domain_size, only: nx_global, ny_global
52#endif
53   USE tideini        ! tidal components initialization   (tide_ini routine)
54   USE bdyini         ! open boundary cond. setting       (bdy_init routine)
55   USE bdydta         ! open boundary cond. setting   (bdy_dta_init routine)
56   USE bdytides       ! open boundary cond. setting   (bdytide_init routine)
57   USE sbctide, ONLY  : lk_tide
58   USE istate         ! initial state setting          (istate_init routine)
59   USE ldfdyn         ! lateral viscosity setting      (ldfdyn_init routine)
60   USE ldftra         ! lateral diffusivity setting    (ldftra_init routine)
61   USE zdfini         ! vertical physics setting          (zdf_init routine)
62   USE phycst         ! physical constant                  (par_cst routine)
63   USE trdini         ! dyn/tra trends initialization     (trd_init routine)
64   USE asminc         ! assimilation increments     
65   USE asmbkg         ! writing out state trajectory
66   USE diaptr         ! poleward transports           (dia_ptr_init routine)
67   USE diadct         ! sections transports           (dia_dct_init routine)
68   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
69   USE diacfl         ! CFL diagnostics               (dia_cfl_init routine)
70   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
71   USE step           ! NEMO time-stepping                 (stp     routine)
72   USE icbini         ! handle bergs, initialisation
73   USE icbstp         ! handle bergs, calving, themodynamics and transport
74   USE cpl_oasis3     ! OASIS3 coupling
75   USE c1d            ! 1D configuration
76   USE step_c1d       ! Time stepping loop for the 1D configuration
77   USE dyndmp         ! Momentum damping
78   USE stopar         ! Stochastic param.: ???
79   USE stopts         ! Stochastic param.: ???
80#if defined key_top
81   USE trcini         ! passive tracer initialisation
82#endif
83   USE lib_mpp        ! distributed memory computing
84   USE diurnal_bulk   ! diurnal bulk SST
85   USE step_diu       ! diurnal bulk SST timestepping (called from here if run offline)
86#if defined key_iomput
87   USE xios           ! xIOserver
88#endif
89   USE crsini         ! initialise grid coarsening utility
90   USE lbcnfd , ONLY  : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges
91   USE sbc_oce, ONLY  : lk_oasis
92   USE diatmb         ! Top,middle,bottom output
93   USE dia25h         ! 25h mean output
94   USE wet_dry        ! Wetting and drying setting   (wad_init routine)
95   USE usrdef         ! user defined configuration
96
97   IMPLICIT NONE
98   PRIVATE
99
100   PUBLIC   nemo_gcm    ! called by model.F90
101   PUBLIC   nemo_init   ! needed by AGRIF
102   PUBLIC   nemo_alloc  ! needed by TAM
103
104   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
105
106   !!----------------------------------------------------------------------
107   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
108   !! $Id$
109   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
110   !!----------------------------------------------------------------------
111CONTAINS
112
113   SUBROUTINE nemo_gcm
114      !!----------------------------------------------------------------------
115      !!                     ***  ROUTINE nemo_gcm  ***
116      !!
117      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
118      !!              curvilinear mesh on the sphere.
119      !!
120      !! ** Method  : - model general initialization
121      !!              - launch the time-stepping (stp routine)
122      !!              - finalize the run by closing files and communications
123      !!
124      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
125      !!              Madec, 2008, internal report, IPSL.
126      !!----------------------------------------------------------------------
127      INTEGER ::   istp       ! time step index
128      !!----------------------------------------------------------------------
129      !
130#if defined key_agrif
131      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
132#endif
133
134      !                            !-----------------------!
135      CALL nemo_init               !==  Initialisations  ==!
136      !                            !-----------------------!
137#if defined key_agrif
138      CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
139      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA
140# if defined key_top
141      CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
142# endif
143# if defined key_lim2
144      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM
145# endif
146#endif
147      ! check that all process are still there... If some process have an error,
148      ! they will never enter in step and other processes will wait until the end of the cpu time!
149      IF( lk_mpp )   CALL mpp_max( nstop )
150
151      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
152
153      !                            !-----------------------!
154      !                            !==   time stepping   ==!
155      !                            !-----------------------!
156      istp = nit000
157#if defined key_c1d
158         DO WHILE ( istp <= nitend .AND. nstop == 0 )
159            CALL stp_c1d( istp )
160            istp = istp + 1
161         END DO
162#else
163          IF( lk_asminc ) THEN
164             IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 )    ! Output background fields
165             IF( ln_asmdin ) THEN                        ! Direct initialization
166                IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 )    ! Tracers
167                IF( ln_dyninc ) CALL dyn_asm_inc( nit000 - 1 )    ! Dynamics
168                IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 )    ! SSH
169             ENDIF
170          ENDIF
171
172#if defined key_agrif
173          CALL Agrif_Regrid()
174#endif
175
176         DO WHILE ( istp <= nitend .AND. nstop == 0 )
177#if defined key_agrif
178            CALL stp                         ! AGRIF: time stepping
179#else
180            IF ( .NOT. ln_diurnal_only ) THEN
181               CALL stp( istp )                 ! standard time stepping
182            ELSE
183               CALL stp_diurnal( istp )        ! time step only the diurnal SST
184            ENDIF 
185#endif
186            istp = istp + 1
187            IF( lk_mpp )   CALL mpp_max( nstop )
188         END DO
189#endif
190
191      IF( ln_diaobs   )   CALL dia_obs_wri
192      !
193      IF( ln_icebergs )   CALL icb_end( nitend )
194
195      !                            !------------------------!
196      !                            !==  finalize the run  ==!
197      !                            !------------------------!
198      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
199      !
200      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
201         WRITE(numout,cform_err)
202         WRITE(numout,*) nstop, ' error have been found'
203      ENDIF
204      !
205#if defined key_agrif
206      IF( .NOT. Agrif_Root() ) THEN
207                         CALL Agrif_ParentGrid_To_ChildGrid()
208         IF( ln_diaobs ) CALL dia_obs_wri
209         IF( nn_timing == 1 )   CALL timing_finalize
210                                CALL Agrif_ChildGrid_To_ParentGrid()
211      ENDIF
212#endif
213      IF( nn_timing == 1 )   CALL timing_finalize
214      !
215      CALL nemo_closefile
216      !
217#if defined key_iomput
218      CALL xios_finalize                  ! end mpp communications with xios
219      IF( lk_oasis )   CALL cpl_finalize  ! end coupling and mpp communications with OASIS
220#else
221      IF( lk_oasis ) THEN
222         CALL cpl_finalize              ! end coupling and mpp communications with OASIS
223      ELSE
224         IF( lk_mpp )   CALL mppstop    ! end mpp communications
225      ENDIF
226#endif
227      !
228   END SUBROUTINE nemo_gcm
229
230
231   SUBROUTINE nemo_init
232      !!----------------------------------------------------------------------
233      !!                     ***  ROUTINE nemo_init  ***
234      !!
235      !! ** Purpose :   initialization of the NEMO GCM
236      !!----------------------------------------------------------------------
237      INTEGER  ::   ji            ! dummy loop indices
238      INTEGER  ::   ilocal_comm   ! local integer
239      INTEGER  ::   ios, inum     !   -      -
240      REAL(wp) ::   ziglo, zjglo, zkglo   ! local scalars
241      CHARACTER(len=120), DIMENSION(16) ::   cltxt, cltxt2, clnam, clbug
242      !
243      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
244         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
245         &             nn_timing, nn_diacfl
246      NAMELIST/namcfg/ ln_read_cfg, cp_cfg, cp_cfz, jp_cfg,   &
247         &             jperio, ln_use_jattr
248      !!----------------------------------------------------------------------
249      !
250      cltxt  = ''
251      cltxt2 = ''
252      clnam  = '' 
253      clbug  = ''
254      cxios_context = 'nemo'
255      !
256      !                             ! Open reference namelist and configuration namelist files
257      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
258      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
259      !
260
261!!gm      WRITE(clbug(1),*) ' before namelist / namctl read    nstop', nstop     
262
263      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints
264      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
265901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
266
267      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints
268      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
269902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
270
271
272!!gm      WRITE(clbug(2),*) ' before namelist namcfg read    nstop', nstop     
273
274      !
275      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
276      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
277903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
278
279      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
280      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
281904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
282
283!!gm      WRITE(clbug(3),*) ' after namelist namcfg read    nstop', nstop
284
285      !                             !--------------------------!
286      !                             !  Set global domain size  !
287      !                             !--------------------------!
288      IF( ln_read_cfg ) THEN              ! Read sizes in configuration "mesh_mask" file
289         CALL iom_open( 'mesh_mask', inum )
290         CALL iom_get( inum, 'jpiglo', ziglo )   ;   jpiglo = INT( ziglo )
291         CALL iom_get( inum, 'jpjglo', zjglo )   ;   jpjglo = INT( zjglo )
292         CALL iom_get( inum, 'jpkglo', zkglo )   ;   jpkglo = INT( zkglo )
293         CALL iom_close( inum )
294         WRITE(cltxt2(1),*)       
295         WRITE(cltxt2(2),*) 'mesh_mask : domain size read in "mesh_mask" file : i,j,k = ', jpiglo, jpjglo, jpk       
296         WRITE(cltxt2(3),*) '~~~~~~~~~'       
297      ELSE                                ! user-defined namelist (control print return in cltxt2)
298         CALL usr_def_nam( cltxt2, clnam, jpiglo, jpjglo, jpkglo )
299      ENDIF
300      jpk    = jpkglo
301      jpidta = jpiglo         !!gm  jpidta, jpjdta : to be suppressed
302      jpjdta = jpjglo         !!gm   
303      jpkdta = jpkglo
304      !
305#if defined key_agrif
306      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
307         jpiglo  = nbcellsx + 2 + 2*nbghostcells
308         jpjglo  = nbcellsy + 2 + 2*nbghostcells
309         jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
310         jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
311         jpidta  = jpiglo
312         jpjdta  = jpjglo
313         nperio  = 0
314         jperio  = 0
315         ln_use_jattr = .false.
316      ENDIF
317#endif
318      !
319      !                             !--------------------------------------------!
320      !                             !  set communicator & select the local node  !
321      !                             !  NB: mynode also opens output.namelist.dyn !
322      !                             !      on unit number numond on first proc   !
323      !                             !--------------------------------------------!
324#if defined key_iomput
325      IF( Agrif_Root() ) THEN
326         IF( lk_oasis ) THEN
327            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
328            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
329         ELSE
330            CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
331         ENDIF
332      ENDIF
333      ! Nodes selection (control print return in cltxt)
334      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
335#else
336      IF( lk_oasis ) THEN
337         IF( Agrif_Root() ) THEN
338            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
339         ENDIF
340         ! Nodes selection (control print return in cltxt)
341         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
342      ELSE
343         ilocal_comm = 0
344         ! Nodes selection (control print return in cltxt)
345         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
346      ENDIF
347#endif
348
349      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
350
351      lwm = (narea == 1)                                    ! control of output namelists
352      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
353
354      IF(lwm) THEN
355         ! write merged namelists from earlier to output namelist now that the
356         ! file has been opened in call to mynode. nammpp has already been
357         ! written in mynode (if lk_mpp_mpi)
358         WRITE( numond, namctl )
359         WRITE( numond, namcfg )
360         IF( .NOT.ln_read_cfg ) THEN
361            DO ji = 1, SIZE(clnam)
362               IF( TRIM(clnam (ji)) /= '' )   WRITE(numond, * ) clnam(ji)    ! namusr_def print
363            END DO
364         ENDIF
365      ENDIF
366
367      ! If dimensions of processor grid weren't specified in the namelist file
368      ! then we calculate them here now that we have our communicator size
369      IF( jpni < 1 .OR. jpnj < 1 ) THEN
370#if   defined key_mpp_mpi
371         IF( Agrif_Root() )   CALL nemo_partition( mppsize )
372#else
373         jpni  = 1
374         jpnj  = 1
375         jpnij = jpni*jpnj
376#endif
377      ENDIF
378
379      IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
380#if defined key_nemocice_decomp
381         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
382         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
383#else
384         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
385         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
386#endif
387      ENDIF
388               
389      jpk = jpkdta                                             ! third dim
390     
391#if defined key_agrif
392      ! simple trick to use same vertical grid as parent but different number of levels:
393      ! Save maximum number of levels in jpkdta, then define all vertical grids with this number.
394      ! Suppress once vertical online interpolation is ok
395      IF(.NOT.Agrif_Root())   jpkdta = Agrif_Parent( jpkdta )
396#endif
397      jpim1 = jpi-1                                            ! inner domain indices
398      jpjm1 = jpj-1                                            !   "           "
399      jpkm1 = jpk-1                                            !   "           "
400      jpij  = jpi*jpj                                          !  jpi x j
401
402      IF(lwp) THEN                            ! open listing units
403         !
404         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
405         !
406
407         DO ji = 1, SIZE(clbug)
408            IF( TRIM(clbug (ji)) /= '' )   WRITE(numout,*) clbug(ji)      ! bug print
409         END DO
410         WRITE(numout,*)
411
412
413
414
415         WRITE(numout,*)
416         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
417         WRITE(numout,*) '                       NEMO team'
418         WRITE(numout,*) '            Ocean General Circulation Model'
419         WRITE(numout,*) '                  version 3.7  (2015) '
420         WRITE(numout,*)
421         WRITE(numout,*)
422         DO ji = 1, SIZE(cltxt)
423            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
424         END DO
425         WRITE(numout,*)
426         WRITE(numout,*)
427         DO ji = 1, SIZE(cltxt2)
428            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)     ! control print of domain size
429         END DO
430         !
431         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
432         !
433      ENDIF
434
435      ! Now we know the dimensions of the grid and numout has been set we can
436      ! allocate arrays
437      CALL nemo_alloc()
438
439      WRITE(numout,*) ' -after alloc--    nstop', nstop
440
441      !                             !-------------------------------!
442      !                             !  NEMO general initialization  !
443      !                             !-------------------------------!
444
445      CALL nemo_ctl                          ! Control prints
446
447      !                                      ! Domain decomposition
448      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
449      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
450      ENDIF
451      !
452      IF( nn_timing == 1 )  CALL timing_init
453      !
454      !                                      ! General initialization
455                            CALL     phy_cst    ! Physical constants
456                            CALL     eos_init   ! Equation of state
457      IF( lk_c1d        )   CALL     c1d_init   ! 1D column configuration
458                            CALL     wad_init   ! Wetting and drying options
459                            CALL     dom_cfg    ! Domain configuration
460                            CALL     dom_init   ! Domain
461      IF( ln_crs        )   CALL     crs_init   ! coarsened grid: domain initialization
462      IF( ln_nnogather )    CALL nemo_northcomms! northfold neighbour lists (must be done after the masks are defined)
463      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
464     
465      CALL diurnal_sst_bulk_init            ! diurnal sst
466      IF ( ln_diurnal ) CALL diurnal_sst_coolskin_init   ! cool skin   
467     
468      ! IF ln_diurnal_only, then we only want a subset of the initialisation routines
469      IF ( ln_diurnal_only ) THEN
470         CALL  istate_init   ! ocean initial state (Dynamics and tracers)
471         CALL     sbc_init   ! Forcings : surface module
472         CALL tra_qsr_init   ! penetrative solar radiation qsr
473         IF( ln_diaobs     ) THEN                  ! Observation & model comparison
474            CALL dia_obs_init            ! Initialize observational data
475            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
476         ENDIF     
477         !                                     ! Assimilation increments
478         IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
479                 
480         IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
481         RETURN
482      ENDIF
483     
484                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
485
486      !                                      ! external forcing
487!!gm to be added : creation and call of sbc_apr_init
488      IF( lk_tide       )   CALL    tide_init   ! tidal harmonics
489                            CALL     sbc_init   ! surface boundary conditions (including sea-ice)
490!!gm ==>> bdy_init should call bdy_dta_init and bdytide_init  NOT in nemogcm !!!
491      IF( lk_bdy        )   CALL     bdy_init   ! Open boundaries initialisation
492      IF( lk_bdy        )   CALL bdy_dta_init   ! Open boundaries initialisation of external data arrays
493      IF( lk_bdy .AND. lk_tide )   &
494         &                  CALL bdytide_init   ! Open boundaries initialisation of tidal harmonic forcing
495         
496      !                                      ! Ocean physics
497      !                                         ! Vertical physics
498                            CALL     zdf_init      ! namelist read
499                            CALL zdf_bfr_init      ! bottom friction
500      IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
501      IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
502      IF( lk_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
503      IF( lk_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
504      IF( lk_zdfddm     )   CALL zdf_ddm_init      ! double diffusive mixing
505         
506      !                                         ! Lateral physics
507                            CALL ldf_tra_init      ! Lateral ocean tracer physics
508                            CALL ldf_eiv_init      ! eddy induced velocity param.
509                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
510
511      !                                         ! Active tracers
512                            CALL tra_qsr_init      ! penetrative solar radiation qsr
513                            CALL tra_bbc_init      ! bottom heat flux
514      IF( lk_trabbl     )   CALL tra_bbl_init      ! advective (and/or diffusive) bottom boundary layer scheme
515                            CALL tra_dmp_init      ! internal tracer damping
516                            CALL tra_adv_init      ! horizontal & vertical advection
517                            CALL tra_ldf_init      ! lateral mixing
518                            CALL tra_zdf_init      ! vertical mixing and after tracer fields
519
520      !                                         ! Dynamics
521      IF( lk_c1d        )   CALL dyn_dmp_init      ! internal momentum damping
522                            CALL dyn_adv_init      ! advection (vector or flux form)
523                            CALL dyn_vor_init      ! vorticity term including Coriolis
524                            CALL dyn_ldf_init      ! lateral mixing
525                            CALL dyn_hpg_init      ! horizontal gradient of Hydrostatic pressure
526                            CALL dyn_zdf_init      ! vertical diffusion
527                            CALL dyn_spg_init      ! surface pressure gradient
528
529#if defined key_top
530      !                                      ! Passive tracers
531                            CALL     trc_init
532#endif
533      IF( l_ldfslp      )   CALL ldf_slp_init   ! slope of lateral mixing
534
535      !                                      ! Icebergs
536                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
537
538      !                                      ! Misc. options
539                            CALL sto_par_init   ! Stochastic parametrization
540      IF( ln_sto_eos     )  CALL sto_pts_init   ! RRandom T/S fluctuations
541     
542      !                                      ! Diagnostics
543      IF( lk_floats     )   CALL     flo_init   ! drifting Floats
544                            CALL dia_cfl_init   ! Initialise CFL diagnostics
545      IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
546                            CALL dia_ptr_init   ! Poleward TRansports initialization
547      IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
548                            CALL dia_hsb_init   ! heat content, salt content and volume budgets
549                            CALL     trd_init   ! Mixed-layer/Vorticity/Integral constraints trends
550                            CALL dia_obs_init            ! Initialize observational data
551      IF( ln_diaobs     )   CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
552
553      !                                         ! Assimilation increments
554      IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
555      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
556                            CALL dia_tmb_init  ! TMB outputs
557                            CALL dia_25h_init  ! 25h mean  outputs
558
559      !
560   END SUBROUTINE nemo_init
561
562
563   SUBROUTINE nemo_ctl
564      !!----------------------------------------------------------------------
565      !!                     ***  ROUTINE nemo_ctl  ***
566      !!
567      !! ** Purpose :   control print setting
568      !!
569      !! ** Method  : - print namctl information and check some consistencies
570      !!----------------------------------------------------------------------
571      !
572      IF(lwp) THEN                  ! control print
573         WRITE(numout,*)
574         WRITE(numout,*) 'nemo_ctl: Control prints'
575         WRITE(numout,*) '~~~~~~~ '
576         WRITE(numout,*) '   Namelist namctl'
577         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
578         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
579         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
580         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
581         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
582         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
583         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
584         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
585         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
586      ENDIF
587      !
588      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
589      nictls    = nn_ictls
590      nictle    = nn_ictle
591      njctls    = nn_jctls
592      njctle    = nn_jctle
593      isplt     = nn_isplt
594      jsplt     = nn_jsplt
595
596      IF(lwp) THEN                  ! control print
597         WRITE(numout,*)
598         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
599         WRITE(numout,*) '~~~~~~~ '
600         WRITE(numout,*) '   Namelist namcfg'
601         WRITE(numout,*) '      read configuration definition files          ln_read_cfg = ', ln_read_cfg
602         WRITE(numout,*) '      configuration name                               cp_cfg  = ', TRIM(cp_cfg)
603         WRITE(numout,*) '      configuration zoom name                          cp_cfz  = ', TRIM(cp_cfz)
604         WRITE(numout,*) '      configuration resolution                         jp_cfg  = ', jp_cfg
605         WRITE(numout,*) '      lateral cond. type (between 0 and 6)             jperio  = ', jperio   
606         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
607      ENDIF
608      !                             ! Parameter control
609      !
610      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
611         IF( lk_mpp .AND. jpnij > 1 ) THEN
612            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
613         ELSE
614            IF( isplt == 1 .AND. jsplt == 1  ) THEN
615               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
616                  &           ' - the print control will be done over the whole domain' )
617            ENDIF
618            ijsplt = isplt * jsplt            ! total number of processors ijsplt
619         ENDIF
620         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
621         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
622         !
623         !                              ! indices used for the SUM control
624         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
625            lsp_area = .FALSE.
626         ELSE                                             ! print control done over a specific  area
627            lsp_area = .TRUE.
628            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
629               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
630               nictls = 1
631            ENDIF
632            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
633               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
634               nictle = jpiglo
635            ENDIF
636            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
637               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
638               njctls = 1
639            ENDIF
640            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
641               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
642               njctle = jpjglo
643            ENDIF
644         ENDIF
645      ENDIF
646      !
647      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
648         &                                               'f2003 standard. '                              ,  &
649         &                                               'Compile with key_nosignedzero enabled' )
650      !
651   END SUBROUTINE nemo_ctl
652
653
654   SUBROUTINE nemo_closefile
655      !!----------------------------------------------------------------------
656      !!                     ***  ROUTINE nemo_closefile  ***
657      !!
658      !! ** Purpose :   Close the files
659      !!----------------------------------------------------------------------
660      !
661      IF( lk_mpp )   CALL mppsync
662      !
663      CALL iom_close                                 ! close all input/output files managed by iom_*
664      !
665      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
666      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
667      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
668      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
669      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
670      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
671      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
672      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
673      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
674      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
675      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
676      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
677      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
678      !
679      numout = 6                                     ! redefine numout in case it is used after this point...
680      !
681   END SUBROUTINE nemo_closefile
682
683
684   SUBROUTINE nemo_alloc
685      !!----------------------------------------------------------------------
686      !!                     ***  ROUTINE nemo_alloc  ***
687      !!
688      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
689      !!
690      !! ** Method  :
691      !!----------------------------------------------------------------------
692      USE diawri    , ONLY: dia_wri_alloc
693      USE dom_oce   , ONLY: dom_oce_alloc
694      USE trc_oce   , ONLY: trc_oce_alloc
695#if defined key_diadct 
696      USE diadct    , ONLY: diadct_alloc 
697#endif 
698#if defined key_bdy
699      USE bdy_oce   , ONLY: bdy_oce_alloc
700#endif
701      !
702      INTEGER :: ierr
703      !!----------------------------------------------------------------------
704      !
705      ierr =        oce_alloc       ()          ! ocean
706      ierr = ierr + dia_wri_alloc   ()
707      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
708      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
709      !
710      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
711      !
712#if defined key_diadct 
713      ierr = ierr + diadct_alloc    ()          !
714#endif 
715#if defined key_bdy
716      ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
717#endif
718      !
719      IF( lk_mpp    )   CALL mpp_sum( ierr )
720      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
721      !
722   END SUBROUTINE nemo_alloc
723
724
725   SUBROUTINE nemo_partition( num_pes )
726      !!----------------------------------------------------------------------
727      !!                 ***  ROUTINE nemo_partition  ***
728      !!
729      !! ** Purpose :
730      !!
731      !! ** Method  :
732      !!----------------------------------------------------------------------
733      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
734      !
735      INTEGER, PARAMETER :: nfactmax = 20
736      INTEGER :: nfact ! The no. of factors returned
737      INTEGER :: ierr  ! Error flag
738      INTEGER :: ji
739      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
740      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
741      !!----------------------------------------------------------------------
742      !
743      ierr = 0
744      !
745      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
746      !
747      IF( nfact <= 1 ) THEN
748         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
749         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
750         jpnj = 1
751         jpni = num_pes
752      ELSE
753         ! Search through factors for the pair that are closest in value
754         mindiff = 1000000
755         imin    = 1
756         DO ji = 1, nfact-1, 2
757            idiff = ABS( ifact(ji) - ifact(ji+1) )
758            IF( idiff < mindiff ) THEN
759               mindiff = idiff
760               imin = ji
761            ENDIF
762         END DO
763         jpnj = ifact(imin)
764         jpni = ifact(imin + 1)
765      ENDIF
766      !
767      jpnij = jpni*jpnj
768      !
769   END SUBROUTINE nemo_partition
770
771
772   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
773      !!----------------------------------------------------------------------
774      !!                     ***  ROUTINE factorise  ***
775      !!
776      !! ** Purpose :   return the prime factors of n.
777      !!                knfax factors are returned in array kfax which is of
778      !!                maximum dimension kmaxfax.
779      !! ** Method  :
780      !!----------------------------------------------------------------------
781      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
782      INTEGER                    , INTENT(  out) ::   kerr, knfax
783      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
784      !
785      INTEGER :: ifac, jl, inu
786      INTEGER, PARAMETER :: ntest = 14
787      INTEGER, DIMENSION(ntest) ::   ilfax
788      !!----------------------------------------------------------------------
789      !
790      ! lfax contains the set of allowed factors.
791      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
792      !
793      ! Clear the error flag and initialise output vars
794      kerr  = 0
795      kfax  = 1
796      knfax = 0
797      !
798      ! Find the factors of n.
799      IF( kn == 1 )   GOTO 20
800
801      ! nu holds the unfactorised part of the number.
802      ! knfax holds the number of factors found.
803      ! l points to the allowed factor list.
804      ! ifac holds the current factor.
805      !
806      inu   = kn
807      knfax = 0
808      !
809      DO jl = ntest, 1, -1
810         !
811         ifac = ilfax(jl)
812         IF( ifac > inu )   CYCLE
813
814         ! Test whether the factor will divide.
815
816         IF( MOD(inu,ifac) == 0 ) THEN
817            !
818            knfax = knfax + 1            ! Add the factor to the list
819            IF( knfax > kmaxfax ) THEN
820               kerr = 6
821               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
822               return
823            ENDIF
824            kfax(knfax) = ifac
825            ! Store the other factor that goes with this one
826            knfax = knfax + 1
827            kfax(knfax) = inu / ifac
828            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
829         ENDIF
830         !
831      END DO
832      !
833   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
834      !
835   END SUBROUTINE factorise
836
837#if defined key_mpp_mpi
838
839   SUBROUTINE nemo_northcomms
840      !!----------------------------------------------------------------------
841      !!                     ***  ROUTINE  nemo_northcomms  ***
842      !! ** Purpose :   Setup for north fold exchanges with explicit
843      !!                point-to-point messaging
844      !!
845      !! ** Method :   Initialization of the northern neighbours lists.
846      !!----------------------------------------------------------------------
847      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
848      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
849      !!----------------------------------------------------------------------
850      INTEGER  ::   sxM, dxM, sxT, dxT, jn
851      INTEGER  ::   njmppmax
852      !!----------------------------------------------------------------------
853      !
854      njmppmax = MAXVAL( njmppt )
855      !
856      !initializes the north-fold communication variables
857      isendto(:) = 0
858      nsndto     = 0
859      !
860      !if I am a process in the north
861      IF ( njmpp == njmppmax ) THEN
862          !sxM is the first point (in the global domain) needed to compute the
863          !north-fold for the current process
864          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
865          !dxM is the last point (in the global domain) needed to compute the
866          !north-fold for the current process
867          dxM = jpiglo - nimppt(narea) + 2
868
869          !loop over the other north-fold processes to find the processes
870          !managing the points belonging to the sxT-dxT range
871 
872          DO jn = 1, jpni
873                !sxT is the first point (in the global domain) of the jn
874                !process
875                sxT = nfiimpp(jn, jpnj)
876                !dxT is the last point (in the global domain) of the jn
877                !process
878                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
879                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
880                   nsndto = nsndto + 1
881                     isendto(nsndto) = jn
882                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
883                   nsndto = nsndto + 1
884                     isendto(nsndto) = jn
885                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
886                   nsndto = nsndto + 1
887                     isendto(nsndto) = jn
888                END IF
889          END DO
890          nfsloop = 1
891          nfeloop = nlci
892          DO jn = 2,jpni-1
893           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
894              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
895                 nfsloop = nldi
896              ENDIF
897              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
898                 nfeloop = nlei
899              ENDIF
900           ENDIF
901        END DO
902
903      ENDIF
904      l_north_nogather = .TRUE.
905   END SUBROUTINE nemo_northcomms
906
907#else
908   SUBROUTINE nemo_northcomms      ! Dummy routine
909      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
910   END SUBROUTINE nemo_northcomms
911#endif
912
913   !!======================================================================
914END MODULE nemogcm
915
Note: See TracBrowser for help on using the repository browser.