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 NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd2/src/OCE – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd2/src/OCE/nemogcm.F90 @ 15544

Last change on this file since 15544 was 15544, checked in by vsmart, 2 years ago

Merge changes for running from the Fortran cap

File size: 38.6 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)  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   !!             -   ! 2011-11  (C. Harris) decomposition changes for running with CICE
31   !!            3.6  ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening
32   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
33   !!            4.0  ! 2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface
34   !!----------------------------------------------------------------------
35
36   !!----------------------------------------------------------------------
37   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
38   !!   nemo_init     : initialization of the NEMO system
39   !!   nemo_ctl      : initialisation of the contol print
40   !!   nemo_closefile: close remaining open files
41   !!   nemo_alloc    : dynamical allocation
42   !!----------------------------------------------------------------------
43#if defined key_oasis3
44   USE mod_oasis      ! For coupling
45#endif
46   USE step_oce       ! module used in the ocean time stepping module (step.F90)
47   USE phycst         ! physical constant                  (par_cst routine)
48   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
49   USE closea         ! treatment of closed seas (for ln_closea)
50   USE usrdef_nam     ! user defined configuration
51   USE tideini        ! tidal components initialization   (tide_ini routine)
52   USE bdy_oce,  ONLY : ln_bdy
53   USE bdyini         ! open boundary cond. setting       (bdy_init routine)
54   USE istate         ! initial state setting          (istate_init routine)
55   USE ldfdyn         ! lateral viscosity setting      (ldfdyn_init routine)
56   USE ldftra         ! lateral diffusivity setting    (ldftra_init routine)
57   USE trdini         ! dyn/tra trends initialization     (trd_init routine)
58   USE asminc         ! assimilation increments     
59   USE asmbkg         ! writing out state trajectory
60   USE diaptr         ! poleward transports           (dia_ptr_init routine)
61   USE diadct         ! sections transports           (dia_dct_init routine)
62   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
63   USE diacfl         ! CFL diagnostics               (dia_cfl_init routine)
64   USE diaharm        ! tidal harmonics diagnostics  (dia_harm_init routine)
65   USE step           ! NEMO time-stepping                 (stp     routine)
66   USE icbini         ! handle bergs, initialisation
67   USE icbstp         ! handle bergs, calving, themodynamics and transport
68   USE cpl_oasis3     ! OASIS3 coupling
69   USE c1d            ! 1D configuration
70   USE step_c1d       ! Time stepping loop for the 1D configuration
71   USE dyndmp         ! Momentum damping
72   USE stopar         ! Stochastic param.: ???
73   USE stopts         ! Stochastic param.: ???
74   USE diurnal_bulk   ! diurnal bulk SST
75   USE step_diu       ! diurnal bulk SST timestepping (called from here if run offline)
76   USE crsini         ! initialise grid coarsening utility
77   USE diatmb         ! Top,middle,bottom output
78   USE dia25h         ! 25h mean output
79   USE sbc_oce , ONLY : lk_oasis
80   USE wet_dry        ! Wetting and drying setting   (wad_init routine)
81#if defined key_top
82   USE trcini         ! passive tracer initialisation
83#endif
84#if defined key_nemocice_decomp
85   USE ice_domain_size, only: nx_global, ny_global
86#endif
87   !
88   USE lib_mpp        ! distributed memory computing
89   USE mppini         ! shared/distributed memory setting (mpp_init routine)
90   USE lbcnfd  , ONLY : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges
91   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
92   USE sbccpl 
93#if defined key_iomput
94   USE xios           ! xIOserver
95#endif
96#if defined key_agrif
97   USE agrif_all_update   ! Master Agrif update
98#endif
99
100   IMPLICIT NONE
101   PRIVATE
102
103   PUBLIC   nemo_gcm    ! called by model.F90
104   PUBLIC   nemo_gcm_init ! called by nemo_gcm or external subroutine
105   PUBLIC   nemo_gcm_run ! called by nemo_gcm or external subroutine
106   PUBLIC   nemo_gcm_finalise ! called by nemo_gcm or external subroutine
107   PUBLIC   nemo_init   ! needed by AGRIF
108   PUBLIC   nemo_alloc  ! needed by TAM
109
110   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
111
112#if defined key_mpp_mpi
113   ! need MPI_Wtime
114   INCLUDE 'mpif.h'
115#endif
116
117   !!----------------------------------------------------------------------
118   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
119   !! $Id$
120   !! Software governed by the CeCILL license (see ./LICENSE)
121   !!----------------------------------------------------------------------
122CONTAINS
123
124   SUBROUTINE nemo_gcm
125      !!----------------------------------------------------------------------
126      !!                     ***  ROUTINE nemo_gcm  ***
127      !!
128      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
129      !!              curvilinear mesh on the sphere.
130      !!
131      !! ** Method  : - calls nemo_gcm_init, nemo_gcm_run, nemo_gcm_finalise
132      !!
133      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
134      !!              Madec, 2008, internal report, IPSL.
135      !!----------------------------------------------------------------------
136      CALL nemo_gcm_init
137      CALL nemo_gcm_run
138      CALL nemo_gcm_finalise
139   END SUBROUTINE nemo_gcm
140
141   SUBROUTINE nemo_gcm_init
142      !!----------------------------------------------------------------------
143      !!                     ***  ROUTINE nemo_gcm_init  ***
144      !!
145      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
146      !!              curvilinear mesh on the sphere.
147      !!
148      !! ** Method  : - model general initialization
149      !!
150      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
151      !!              Madec, 2008, internal report, IPSL.
152      !!----------------------------------------------------------------------
153#if defined key_agrif
154      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
155#endif
156      !                            !-----------------------!
157      CALL nemo_init               !==  Initialisations  ==!
158      !                            !-----------------------!
159#if defined key_agrif
160      CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
161      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA
162# if defined key_top
163      CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
164# endif
165# if defined key_si3
166      CALL Agrif_Declare_Var_ice   !  "      "   "   "      "  Sea ice
167# endif
168#endif
169   END SUBROUTINE nemo_gcm_init
170
171   SUBROUTINE nemo_gcm_run
172      !!----------------------------------------------------------------------
173      !!                     ***  ROUTINE nemo_gcm_run  ***
174      !!
175      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
176      !!              curvilinear mesh on the sphere.
177      !!
178      !! ** Method  : - launch the time-stepping (stp routine)
179      !!
180      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
181      !!              Madec, 2008, internal report, IPSL.
182      !!----------------------------------------------------------------------
183      INTEGER ::   istp   ! time step index
184      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
185      !!----------------------------------------------------------------------
186      !
187      ! check that all process are still there... If some process have an error,
188      ! they will never enter in step and other processes will wait until the end of the cpu time!
189      CALL mpp_max( 'nemogcm', nstop )
190
191      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
192      WRITE(numout,*)"RSRH at time stepping" ; flush(numout)
193
194
195      !                            !-----------------------!
196      !                            !==   time stepping   ==!
197      !                            !-----------------------!
198      istp = nit000
199      !
200#if defined key_c1d
201      DO WHILE ( istp <= nitend .AND. nstop == 0 )    !==  C1D time-stepping  ==!
202         CALL stp_c1d( istp )
203         istp = istp + 1
204      END DO
205#else
206      !
207# if defined key_agrif
208      !                                               !==  AGRIF time-stepping  ==!
209      CALL Agrif_Regrid()
210      !
211      ! Recursive update from highest nested level to lowest:
212      CALL Agrif_step_child_adj(Agrif_Update_All)
213      !
214      DO WHILE( istp <= nitend .AND. nstop == 0 )
215         CALL stp
216         istp = istp + 1
217      END DO
218      !
219      IF( .NOT. Agrif_Root() ) THEN
220         CALL Agrif_ParentGrid_To_ChildGrid()
221         IF( ln_diaobs )   CALL dia_obs_wri
222         IF( ln_timing )   CALL timing_finalize
223         CALL Agrif_ChildGrid_To_ParentGrid()
224      ENDIF
225      !
226# else
227      !
228      IF( .NOT.ln_diurnal_only ) THEN                 !==  Standard time-stepping  ==!
229         !
230         DO WHILE( istp <= nitend .AND. nstop == 0 )
231
232            ncom_stp = istp
233            IF( ln_timing ) THEN
234               zstptiming = MPI_Wtime()
235               IF ( istp == ( nit000 + 1 ) ) elapsed_time = zstptiming
236               IF ( istp ==         nitend ) elapsed_time = zstptiming - elapsed_time
237            ENDIF
238           
239            ! RSRH. You can compile with OASIS but not want to do any
240            ! coupling. We need to cater for that properly!
241            IF (ln_cpl .OR. ln_couple_test) CALL sbc_cpl_snd( istp )  ! Coupling to atmos
242            ! RSRH. For test purposes we call the receive here. For proper
243            ! runs we need to do this elsewhere (reference UKESM/GC3 etc) 
244            !IF (ln_cpl .OR. ln_couple_test) CALL sbc_cpl_rcv( istp )  ! Coupling from atmos
245
246            CALL stp        ( istp ) 
247            istp = istp + 1
248
249            IF( lwp .AND. ln_timing )   WRITE(numtime,*) 'timing step ', istp-1, ' : ', MPI_Wtime() - zstptiming
250
251         END DO
252         !
253      ELSE                                            !==  diurnal SST time-steeping only  ==!
254         !
255         DO WHILE( istp <= nitend .AND. nstop == 0 )
256            CALL stp_diurnal( istp )   ! time step only the diurnal SST
257            istp = istp + 1
258         END DO
259         !
260      ENDIF
261      !
262# endif
263      !
264#endif
265      !
266      IF( ln_diaobs   )   CALL dia_obs_wri
267      !
268      IF( ln_icebergs )   CALL icb_end( nitend )
269
270      !                            !------------------------!
271      !                            !==  finalize the run  ==!
272      !                            !------------------------!
273      WRITE(numout,*)"RSRH at finalize" ; flush(numout)
274      IF(lwp) WRITE(numout,cform_aaa)        ! Flag AAAAAAA
275      !
276      IF( nstop /= 0 .AND. lwp ) THEN        ! error print
277         WRITE(ctmp1,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
278         CALL ctl_stop( ctmp1 )
279      ENDIF
280      !
281      IF( ln_timing )   CALL timing_finalize
282      !
283      write(numout,*) "RSRH calling nemo_closefile " , lk_oasis; flush(numout)
284      CALL nemo_closefile
285      !
286   END SUBROUTINE nemo_gcm_run
287
288   SUBROUTINE nemo_gcm_finalise
289      !!----------------------------------------------------------------------
290      !!                     ***  ROUTINE nemo_gcm_finalise  ***
291      !!
292      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
293      !!              curvilinear mesh on the sphere.
294      !!
295      !! ** Method  : - finalize the run by closing files and communications
296      !!
297      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
298      !!              Madec, 2008, internal report, IPSL.
299      !!----------------------------------------------------------------------
300      integer :: nerror
301      !!----------------------------------------------------------------------
302      !
303#if defined key_iomput
304      CALL xios_finalize()  ! end mpp communications with xios
305
306#if defined key_oasis3
307      IF (lk_oasis)  THEN
308         CALL oasis_terminate(nerror)
309         CALL mppstop      ! end mpp communications
310      ELSEIF( lk_mpp   ) THEN
311         CALL mppstop ! RSRH temp for development
312      ENDIF
313#endif
314
315#else
316      ! RSRH It's unclear if the following will work
317      ! since we never compile w/o key_iomput
318      IF    ( lk_oasis ) THEN   
319          CALL cpl_finalize()   ! end coupling and mpp communications with OASIS
320      ELSEIF( lk_mpp   ) THEN
321          CALL mppstop      ! end mpp communications
322      ENDIF
323#endif
324      !
325      IF (.NOT. mpi_pre_initialised) THEN
326         IF(lwm) THEN
327            IF( nstop == 0 ) THEN   
328                  STOP 0
329            ELSE       
330                  STOP 123
331            ENDIF
332         ENDIF
333      ENDIF
334      !
335   END SUBROUTINE nemo_gcm_finalise
336
337
338   SUBROUTINE nemo_init
339      !!----------------------------------------------------------------------
340      !!                     ***  ROUTINE nemo_init  ***
341      !!
342      !! ** Purpose :   initialization of the NEMO GCM
343      !!----------------------------------------------------------------------
344      INTEGER ::   ios, ilocal_comm, nerror, ncomp_id, llmpi_init, ierr  ! local integers
345      !!
346      NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
347         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
348         &             ln_timing, ln_diacfl
349      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
350      !!----------------------------------------------------------------------
351      !
352      cxios_context = 'nemo'
353      !
354      !                             !-------------------------------------------------!
355      !                             !     set communicator & select the local rank    !
356      !                             !  must be done as soon as possible to get narea  !
357      !                             !-------------------------------------------------!
358      !
359      CALL set_mpi_pre_initialised()
360#if defined key_iomput
361      IF( Agrif_Root() ) THEN
362        IF(.not.lk_oasis) THEN
363          CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
364        ENDIF
365      ENDIF 
366
367#if defined key_oasis3
368      IF( lk_oasis ) THEN
369          IF (.NOT. mpi_pre_initialised) THEN
370              CALL mpi_init(nerror)
371          ENDIF
372          CALL oasis_init_comp ( ncomp_id, "toyoce", nerror, .TRUE. )
373          CALL oasis_get_localcomm ( ilocal_comm , nerror )
374          CALL xios_initialize( "toyoce", local_comm =ilocal_comm )
375      ENDIF
376#endif
377
378      CALL mpp_start( ilocal_comm )
379#endif
380
381      !
382      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
383      lwm = (narea == 1)                ! control of output namelists
384      !
385      !                             !---------------------------------------------------------------!
386      !                             ! Open output files, reference and configuration namelist files !
387      !                             !---------------------------------------------------------------!
388      !
389      ! open ocean.output as soon as possible to get all output prints (including errors messages)
390      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
391      ! open reference and configuration namelist files
392                  CALL ctl_opn( numnam_ref,        'namelist_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
393                  CALL ctl_opn( numnam_cfg,        'namelist_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
394      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
395      ! open /dev/null file to be able to supress output write easily
396                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
397      !
398      !                             !--------------------!
399      !                             ! Open listing units !  -> need ln_ctl from namctl to define lwp
400      !                             !--------------------!
401      !
402      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
403      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
404901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
405      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
406      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
407902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
408      !
409      lwp = (narea == 1) .OR. ln_ctl    ! control of all listing output print
410      !
411      IF(lwp) THEN                      ! open listing units
412         !
413         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
414            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
415         !
416
417         WRITE(numout,*)
418         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
419         WRITE(numout,*) '                       NEMO team'
420         WRITE(numout,*) '            Ocean General Circulation Model'
421         WRITE(numout,*) '                NEMO version 4.0  (2019) '
422         WRITE(numout,*)
423         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
424         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
425         WRITE(numout,*)
426         WRITE(numout,*) "           o         _,           _,             "
427         WRITE(numout,*) "            o      .' (        .-' /             "
428         WRITE(numout,*) "           o     _/..._'.    .'   /              "
429         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
430         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
431         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
432         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
433         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
434         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
435         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
436         WRITE(numout,*)
437         !
438         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
439         !
440      ENDIF
441      !
442      ! finalize the definition of namctl variables
443      IF( sn_cfctl%l_config ) THEN
444         ! Activate finer control of report outputs
445         ! optionally switch off output from selected areas (note this only
446         ! applies to output which does not involve global communications)
447         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
448           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
449           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
450      ELSE
451         ! Use ln_ctl to turn on or off all options.
452         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
453      ENDIF
454      !
455      IF(lwm) WRITE( numond, namctl )
456      !
457      !                             !------------------------------------!
458      !                             !  Set global domain size parameters !
459      !                             !------------------------------------!
460      !
461      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
462      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
463903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
464      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
465      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
466904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
467      !
468      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
469         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
470      ELSE                              ! user-defined namelist
471         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
472      ENDIF
473      !
474      IF(lwm)   WRITE( numond, namcfg )
475      !
476      !                             !-----------------------------------------!
477      !                             ! mpp parameters and domain decomposition !
478      !                             !-----------------------------------------!
479      CALL mpp_init
480
481      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
482      CALL nemo_alloc()
483
484      !                             !-------------------------------!
485      !                             !  NEMO general initialization  !
486      !                             !-------------------------------!
487
488      CALL nemo_ctl                          ! Control prints
489      !
490      !                                      ! General initialization
491      IF( ln_timing    )   CALL timing_init     ! timing
492      IF( ln_timing    )   CALL timing_start( 'nemo_init')
493      !
494                           CALL     phy_cst         ! Physical constants
495                           CALL     eos_init        ! Equation of state
496      IF( lk_c1d       )   CALL     c1d_init        ! 1D column configuration
497                           CALL     wad_init        ! Wetting and drying options
498                           CALL     dom_init("OPA") ! Domain
499      IF( ln_crs       )   CALL     crs_init        ! coarsened grid: domain initialization
500      IF( ln_ctl       )   CALL prt_ctl_init        ! Print control
501     
502      CALL diurnal_sst_bulk_init                ! diurnal sst
503      IF( ln_diurnal   )   CALL diurnal_sst_coolskin_init   ! cool skin   
504      !                           
505      IF( ln_diurnal_only ) THEN                   ! diurnal only: a subset of the initialisation routines
506         CALL  istate_init                            ! ocean initial state (Dynamics and tracers)
507         CALL     sbc_init                            ! Forcings : surface module
508         CALL tra_qsr_init                            ! penetrative solar radiation qsr
509         IF( ln_diaobs ) THEN                         ! Observation & model comparison
510            CALL dia_obs_init                            ! Initialize observational data
511            CALL dia_obs( nit000 - 1 )                   ! Observation operator for restart
512         ENDIF     
513         IF( lk_asminc )   CALL asm_inc_init          ! Assimilation increments
514         !
515         RETURN                                       ! end of initialization
516      ENDIF
517     
518                           CALL  istate_init    ! ocean initial state (Dynamics and tracers)
519
520      !                                      ! external forcing
521                           CALL    tide_init    ! tidal harmonics
522                           CALL     sbc_init    ! surface boundary conditions (including sea-ice)
523                           CALL     bdy_init    ! Open boundaries initialisation
524
525      !                                      ! Ocean physics
526                           CALL zdf_phy_init    ! Vertical physics
527                                     
528      !                                         ! Lateral physics
529                           CALL ldf_tra_init      ! Lateral ocean tracer physics
530                           CALL ldf_eiv_init      ! eddy induced velocity param.
531                           CALL ldf_dyn_init      ! Lateral ocean momentum physics
532
533      !                                      ! Active tracers
534      IF( ln_traqsr    )   CALL tra_qsr_init      ! penetrative solar radiation qsr
535                           CALL tra_bbc_init      ! bottom heat flux
536                           CALL tra_bbl_init      ! advective (and/or diffusive) bottom boundary layer scheme
537                           CALL tra_dmp_init      ! internal tracer damping
538                           CALL tra_adv_init      ! horizontal & vertical advection
539                           CALL tra_ldf_init      ! lateral mixing
540
541      !                                      ! Dynamics
542      IF( lk_c1d       )   CALL dyn_dmp_init      ! internal momentum damping
543                           CALL dyn_adv_init      ! advection (vector or flux form)
544                           CALL dyn_vor_init      ! vorticity term including Coriolis
545                           CALL dyn_ldf_init      ! lateral mixing
546                           CALL dyn_hpg_init      ! horizontal gradient of Hydrostatic pressure
547                           CALL dyn_spg_init      ! surface pressure gradient
548
549#if defined key_top
550      !                                      ! Passive tracers
551                           CALL     trc_init
552#endif
553      IF( l_ldfslp     )   CALL ldf_slp_init    ! slope of lateral mixing
554
555      !                                      ! Icebergs
556                           CALL icb_init( rdt, nit000)   ! initialise icebergs instance
557
558      !                                      ! Misc. options
559                           CALL sto_par_init    ! Stochastic parametrization
560      IF( ln_sto_eos   )   CALL sto_pts_init    ! RRandom T/S fluctuations
561     
562      !                                      ! Diagnostics
563                           CALL     flo_init    ! drifting Floats
564      IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
565                           CALL dia_ptr_init    ! Poleward TRansports initialization
566                           CALL dia_dct_init    ! Sections tranports
567                           CALL dia_hsb_init    ! heat content, salt content and volume budgets
568                           CALL     trd_init    ! Mixed-layer/Vorticity/Integral constraints trends
569                           CALL dia_obs_init    ! Initialize observational data
570                           CALL dia_tmb_init    ! TMB outputs
571                           CALL dia_25h_init    ! 25h mean  outputs
572                           CALL dia_harm_init   ! tidal harmonics outputs
573     IF( ln_diaobs    )    CALL dia_obs( nit000-1 )   ! Observation operator for restart
574
575      !                                      ! Assimilation increments
576      IF( lk_asminc    )   CALL asm_inc_init    ! Initialize assimilation increments
577      !
578      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
579     
580      IF (nstop > 0) THEN
581        CALL CTL_STOP('STOP','Critical errors in NEMO initialisation')
582      END IF
583     
584      !
585      IF( ln_timing    )   CALL timing_stop( 'nemo_init')
586      !
587   END SUBROUTINE nemo_init
588
589
590   SUBROUTINE nemo_ctl
591      !!----------------------------------------------------------------------
592      !!                     ***  ROUTINE nemo_ctl  ***
593      !!
594      !! ** Purpose :   control print setting
595      !!
596      !! ** Method  : - print namctl and namcfg information and check some consistencies
597      !!----------------------------------------------------------------------
598      !
599      IF(lwp) THEN                  ! control print
600         WRITE(numout,*)
601         WRITE(numout,*) 'nemo_ctl: Control prints'
602         WRITE(numout,*) '~~~~~~~~'
603         WRITE(numout,*) '   Namelist namctl'
604         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
605         WRITE(numout,*) '       finer control over o/p sn_cfctl%l_config  = ', sn_cfctl%l_config
606         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
607         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
608         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
609         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
610         WRITE(numout,*) '                              sn_cfctl%l_mppout  = ', sn_cfctl%l_mppout
611         WRITE(numout,*) '                              sn_cfctl%l_mpptop  = ', sn_cfctl%l_mpptop
612         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
613         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
614         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
615         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
616         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
617         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
618         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
619         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
620         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
621         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
622         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
623         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
624         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
625      ENDIF
626      !
627      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
628      nictls    = nn_ictls
629      nictle    = nn_ictle
630      njctls    = nn_jctls
631      njctle    = nn_jctle
632      isplt     = nn_isplt
633      jsplt     = nn_jsplt
634
635      IF(lwp) THEN                  ! control print
636         WRITE(numout,*)
637         WRITE(numout,*) '   Namelist namcfg'
638         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
639         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
640         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
641         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
642         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
643         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
644      ENDIF
645      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
646      !
647      !                             ! Parameter control
648      !
649      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
650         IF( lk_mpp .AND. jpnij > 1 ) THEN
651            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
652         ELSE
653            IF( isplt == 1 .AND. jsplt == 1  ) THEN
654               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
655                  &           ' - the print control will be done over the whole domain' )
656            ENDIF
657            ijsplt = isplt * jsplt            ! total number of processors ijsplt
658         ENDIF
659         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
660         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
661         !
662         !                              ! indices used for the SUM control
663         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
664            lsp_area = .FALSE.
665         ELSE                                             ! print control done over a specific  area
666            lsp_area = .TRUE.
667            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
668               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
669               nictls = 1
670            ENDIF
671            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
672               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
673               nictle = jpiglo
674            ENDIF
675            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
676               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
677               njctls = 1
678            ENDIF
679            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
680               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
681               njctle = jpjglo
682            ENDIF
683         ENDIF
684      ENDIF
685      !
686      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
687         &                                                'Compile with key_nosignedzero enabled:',   &
688         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
689      !
690#if defined key_agrif
691      IF( ln_timing )   CALL ctl_stop( 'AGRIF not implemented with ln_timing = true')
692#endif
693      !
694   END SUBROUTINE nemo_ctl
695
696
697   SUBROUTINE nemo_closefile
698      !!----------------------------------------------------------------------
699      !!                     ***  ROUTINE nemo_closefile  ***
700      !!
701      !! ** Purpose :   Close the files
702      !!----------------------------------------------------------------------
703      !
704      IF( lk_mpp )   CALL mppsync
705      !
706      CALL iom_close                                 ! close all input/output files managed by iom_*
707
708      !
709      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
710      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
711      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
712      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
713      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
714      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
715      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
716      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
717      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
718      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
719      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
720      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
721      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
722      !
723!      numout = 6                                     ! redefine numout in case it is used after this point...
724      !
725   END SUBROUTINE nemo_closefile
726
727
728   SUBROUTINE nemo_alloc
729      !!----------------------------------------------------------------------
730      !!                     ***  ROUTINE nemo_alloc  ***
731      !!
732      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
733      !!
734      !! ** Method  :
735      !!----------------------------------------------------------------------
736      USE diawri    , ONLY : dia_wri_alloc
737      USE dom_oce   , ONLY : dom_oce_alloc
738      USE trc_oce   , ONLY : trc_oce_alloc
739      USE bdy_oce   , ONLY : bdy_oce_alloc
740      !
741      INTEGER :: ierr
742      !!----------------------------------------------------------------------
743      !
744      ierr =        oce_alloc    ()    ! ocean
745      ierr = ierr + dia_wri_alloc()
746      ierr = ierr + dom_oce_alloc()    ! ocean domain
747      ierr = ierr + zdf_oce_alloc()    ! ocean vertical physics
748      ierr = ierr + trc_oce_alloc()    ! shared TRC / TRA arrays
749      ierr = ierr + bdy_oce_alloc()    ! bdy masks (incl. initialization)
750      !
751      CALL mpp_sum( 'nemogcm', ierr )
752      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
753      !
754   END SUBROUTINE nemo_alloc
755
756   
757   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto, for_all )
758      !!----------------------------------------------------------------------
759      !!                     ***  ROUTINE nemo_set_cfctl  ***
760      !!
761      !! ** Purpose :   Set elements of the output control structure to setto.
762      !!                for_all should be .false. unless all areas are to be
763      !!                treated identically.
764      !!
765      !! ** Method  :   Note this routine can be used to switch on/off some
766      !!                types of output for selected areas but any output types
767      !!                that involve global communications (e.g. mpp_max, glob_sum)
768      !!                should be protected from selective switching by the
769      !!                for_all argument
770      !!----------------------------------------------------------------------
771      LOGICAL :: setto, for_all
772      TYPE(sn_ctl) :: sn_cfctl
773      !!----------------------------------------------------------------------
774      IF( for_all ) THEN
775         sn_cfctl%l_runstat = setto
776         sn_cfctl%l_trcstat = setto
777      ENDIF
778      sn_cfctl%l_oceout  = setto
779      sn_cfctl%l_layout  = setto
780      sn_cfctl%l_mppout  = setto
781      sn_cfctl%l_mpptop  = setto
782   END SUBROUTINE nemo_set_cfctl
783
784   !!======================================================================
785END MODULE nemogcm
786
Note: See TracBrowser for help on using the repository browser.