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

source: NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage2/src/OCE/nemogcm.F90 @ 13443

Last change on this file since 13443 was 13443, checked in by frrh, 4 years ago

Commit changes which allow first working 2 way coupling exchanges between GO8
and LFRic aquaplanet.

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