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_spmd/src/OCE – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd/src/OCE/nemogcm.F90 @ 15276

Last change on this file since 15276 was 15276, checked in by vsmart, 3 years ago

Merge in changes from couple_stage2_spmd branch to allow for running from the Fortran cap

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