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/2020/dev_r12558_HPC-08_epico_Extra_Halo/tests/STATION_ASF/MY_SRC – NEMO

source: NEMO/branches/2020/dev_r12558_HPC-08_epico_Extra_Halo/tests/STATION_ASF/MY_SRC/nemogcm.F90 @ 12939

Last change on this file since 12939 was 12939, checked in by smasson, 4 years ago

Extra_Halo: update with trunk@12933, see #2366

File size: 22.5 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !!                      STATION_ASF (SAS meets C1D)
5   !!======================================================================
6   !! History :  3.6  ! 2011-11  (S. Alderson, G. Madec) original code
7   !!             -   ! 2013-06  (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication
8   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
9   !!            4.0  ! 2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface
10   !!            4.x  ! 2019-12  (L. Brodeau)  STATION_ASF test-case
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
15   !!   nemo_init     : initialization of the NEMO system
16   !!   nemo_ctl      : initialisation of the contol print
17   !!   nemo_closefile: close remaining open files
18   !!   nemo_alloc    : dynamical allocation
19   !!----------------------------------------------------------------------
20   USE step_oce       ! module used in the ocean time stepping module (step.F90)
21   USE phycst         ! physical constant                  (par_cst routine)
22   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
23   USE closea         ! treatment of closed seas (for ln_closea)
24   USE usrdef_nam     ! user defined configuration
25   USE istate         ! initial state setting          (istate_init routine)
26   USE step, ONLY : Nbb, Nnn, Naa, Nrhs ! time level indices
27   USE daymod         ! calendar
28   USE restart        ! open  restart file
29   USE c1d            ! 1D configuration
30   USE step_c1d       ! Time stepping loop for the 1D configuration
31   !
32   USE in_out_manager ! I/O manager
33   USE lib_mpp        ! distributed memory computing
34   USE mppini         ! shared/distributed memory setting (mpp_init routine)
35   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
36#if defined key_iomput
37   USE xios           ! xIOserver
38#endif
39
40   IMPLICIT NONE
41   PRIVATE
42
43   PUBLIC   nemo_gcm    ! called by model.F90
44   PUBLIC   nemo_init   ! needed by AGRIF
45
46   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
47
48   !!----------------------------------------------------------------------
49   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
50   !! $Id: nemogcm.F90 12489 2020-02-28 15:55:11Z davestorkey $
51   !! Software governed by the CeCILL license (see ./LICENSE)
52   !!----------------------------------------------------------------------
53CONTAINS
54
55   SUBROUTINE nemo_gcm
56      !!----------------------------------------------------------------------
57      !!                     ***  ROUTINE nemo_gcm  ***
58      !!
59      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
60      !!              curvilinear mesh on the sphere.
61      !!
62      !! ** Method  : - model general initialization
63      !!              - launch the time-stepping (stp routine)
64      !!              - finalize the run by closing files and communications
65      !!
66      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
67      !!              Madec, 2008, internal report, IPSL.
68      !!----------------------------------------------------------------------
69      INTEGER ::   istp   ! time step index
70      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
71      !!----------------------------------------------------------------------
72      !
73      !                            !-----------------------!
74      CALL nemo_init               !==  Initialisations  ==!
75      !                            !-----------------------!
76      ! check that all process are still there... If some process have an error,
77      ! they will never enter in step and other processes will wait until the end of the cpu time!
78      CALL mpp_max( 'nemogcm', nstop )
79
80      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
81
82      !                            !-----------------------!
83      !                            !==   time stepping   ==!
84      !                            !-----------------------!
85      !
86      !                                               !== set the model time-step  ==!
87      !
88      istp = nit000
89      !
90      DO WHILE ( istp <= nitend .AND. nstop == 0 )    !==  C1D time-stepping  ==!
91         CALL stp_c1d( istp )
92         istp = istp + 1
93      END DO
94      !
95      !                            !------------------------!
96      !                            !==  finalize the run  ==!
97      !                            !------------------------!
98      IF(lwp) WRITE(numout,cform_aaa)        ! Flag AAAAAAA
99      !
100      IF( nstop /= 0 .AND. lwp ) THEN        ! error print
101         WRITE(ctmp1,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
102         CALL ctl_stop( ctmp1 )
103      ENDIF
104      !
105      IF( ln_timing )   CALL timing_finalize
106      !
107      CALL nemo_closefile
108      !
109#if defined key_iomput
110                                    CALL xios_finalize  ! end mpp communications with xios
111#else
112      IF( lk_mpp )                  CALL mppstop      ! end mpp communications
113#endif
114      !
115      IF(lwm) THEN
116         IF( nstop == 0 ) THEN   ;   STOP 0
117         ELSE                    ;   STOP 123
118         ENDIF
119      ENDIF
120      !
121   END SUBROUTINE nemo_gcm
122
123
124   SUBROUTINE nemo_init
125      !!----------------------------------------------------------------------
126      !!                     ***  ROUTINE nemo_init  ***
127      !!
128      !! ** Purpose :   initialization of the NEMO GCM
129      !!----------------------------------------------------------------------
130      INTEGER ::   ios, ilocal_comm   ! local integers
131      !!
132      NAMELIST/namctl/ sn_cfctl,  nn_print, nn_ictls, nn_ictle,             &
133         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
134         &             ln_timing, ln_diacfl
135      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
136      !!----------------------------------------------------------------------
137      !
138      cxios_context = 'nemo'
139      !
140      !                             !-------------------------------------------------!
141      !                             !     set communicator & select the local rank    !
142      !                             !  must be done as soon as possible to get narea  !
143      !                             !-------------------------------------------------!
144      !
145#if defined key_iomput
146      IF( Agrif_Root() ) THEN
147            CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
148      ENDIF
149      CALL mpp_start( ilocal_comm )
150#else
151         CALL mpp_start( )
152#endif
153      !
154      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
155      lwm = (narea == 1)                ! control of output namelists
156      !
157      !                             !---------------------------------------------------------------!
158      !                             ! Open output files, reference and configuration namelist files !
159      !                             !---------------------------------------------------------------!
160      !
161      ! open ocean.output as soon as possible to get all output prints (including errors messages)
162      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
163      ! open reference and configuration namelist files
164                  CALL load_nml( numnam_ref,        'namelist_ref',                                           -1, lwm )
165                  CALL load_nml( numnam_cfg,        'namelist_cfg',                                           -1, lwm )
166      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
167      ! open /dev/null file to be able to supress output write easily
168      IF( Agrif_Root() ) THEN
169                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
170#ifdef key_agrif
171      ELSE
172                  numnul = Agrif_Parent(numnul)   
173#endif
174      ENDIF
175      !
176      !                             !--------------------!
177      !                             ! Open listing units !  -> need sn_cfctl from namctl to define lwp
178      !                             !--------------------!
179      !
180      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
181901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
182      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
183902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
184      !
185      ! finalize the definition of namctl variables
186      IF( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax .OR. MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 )   &
187         &   CALL nemo_set_cfctl( sn_cfctl, .FALSE. )
188      !
189      lwp = (narea == 1) .OR. sn_cfctl%l_oceout    ! control of all listing output print
190      !
191      IF(lwp) THEN                      ! open listing units
192         !
193         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
194            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
195         !
196         WRITE(numout,*)
197         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
198         WRITE(numout,*) '                       NEMO team'
199         WRITE(numout,*) '            Ocean General Circulation Model'
200         WRITE(numout,*) '                NEMO version 4.0  (2019) '
201         WRITE(numout,*) '                      STATION_ASF '
202         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
203         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
204         WRITE(numout,*)
205         WRITE(numout,*) "           o         _,           _,             "
206         WRITE(numout,*) "            o      .' (        .-' /             "
207         WRITE(numout,*) "           o     _/..._'.    .'   /              "
208         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
209         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
210         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
211         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
212         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
213         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
214         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
215         WRITE(numout,*)
216         !
217         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
218         !
219      ENDIF
220      !
221      IF(lwm) WRITE( numond, namctl )
222      !
223      !                             !------------------------------------!
224      !                             !  Set global domain size parameters !
225      !                             !------------------------------------!
226      !
227      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
228903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
229      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
230904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
231      !
232      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
233         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
234      ELSE                              ! user-defined namelist
235         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
236      ENDIF
237      !
238      IF(lwm)   WRITE( numond, namcfg )
239      !
240      !                             !-----------------------------------------!
241      !                             ! mpp parameters and domain decomposition !
242      !                             !-----------------------------------------!
243      CALL mpp_init
244
245      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
246      CALL nemo_alloc()
247
248      ! Initialise time level indices
249      Nbb = 1; Nnn = 2; Naa = 3; Nrhs = Naa
250
251      !                             !-------------------------------!
252      !                             !  NEMO general initialization  !
253      !                             !-------------------------------!
254
255      CALL nemo_ctl                          ! Control prints
256      !
257      !                                      ! General initialization
258      IF( ln_timing    )   CALL timing_init     ! timing
259      IF( ln_timing    )   CALL timing_start( 'nemo_init')
260      !
261                           CALL     phy_cst         ! Physical constants
262                           CALL     eos_init        ! Equation of state
263      IF( lk_c1d       )   CALL     c1d_init        ! 1D column configuration
264                           CALL     dom_init( Nbb, Nnn, Naa, "OPA") ! Domain
265      IF( sn_cfctl%l_prtctl )   &
266         &                 CALL prt_ctl_init        ! Print control
267      !
268     
269                           CALL  istate_init( Nbb, Nnn, Naa )    ! ocean initial state (Dynamics and tracers)
270
271      !                                      ! external forcing
272                           CALL     sbc_init( Nbb, Nnn, Naa )    ! surface boundary conditions (including sea-ice)
273
274      !
275      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
276      !
277      IF( ln_timing    )   CALL timing_stop( 'nemo_init')
278      !
279   END SUBROUTINE nemo_init
280
281
282   SUBROUTINE nemo_ctl
283      !!----------------------------------------------------------------------
284      !!                     ***  ROUTINE nemo_ctl  ***
285      !!
286      !! ** Purpose :   control print setting
287      !!
288      !! ** Method  : - print namctl and namcfg information and check some consistencies
289      !!----------------------------------------------------------------------
290      !
291      IF(lwp) THEN                  ! control print
292         WRITE(numout,*)
293         WRITE(numout,*) 'nemo_ctl: Control prints'
294         WRITE(numout,*) '~~~~~~~~'
295         WRITE(numout,*) '   Namelist namctl'
296         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
297         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
298         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
299         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
300         WRITE(numout,*) '                              sn_cfctl%l_prtctl  = ', sn_cfctl%l_prtctl
301         WRITE(numout,*) '                              sn_cfctl%l_prttrc  = ', sn_cfctl%l_prttrc
302         WRITE(numout,*) '                              sn_cfctl%l_oasout  = ', sn_cfctl%l_oasout
303         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
304         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
305         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
306         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
307         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
308         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
309         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
310         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
311         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
312         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
313         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
314         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
315         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
316      ENDIF
317      !
318      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
319      nictls    = nn_ictls
320      nictle    = nn_ictle
321      njctls    = nn_jctls
322      njctle    = nn_jctle
323      isplt     = nn_isplt
324      jsplt     = nn_jsplt
325
326      IF(lwp) THEN                  ! control print
327         WRITE(numout,*)
328         WRITE(numout,*) '   Namelist namcfg'
329         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
330         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
331         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
332         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
333         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
334         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
335      ENDIF
336      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
337      !
338      !                             ! Parameter control
339      !
340      IF( sn_cfctl%l_prtctl .OR. sn_cfctl%l_prttrc ) THEN              ! sub-domain area indices for the control prints
341         IF( lk_mpp .AND. jpnij > 1 ) THEN
342            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
343         ELSE
344            IF( isplt == 1 .AND. jsplt == 1  ) THEN
345               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
346                  &           ' - the print control will be done over the whole domain' )
347            ENDIF
348            ijsplt = isplt * jsplt            ! total number of processors ijsplt
349         ENDIF
350         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
351         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
352         !
353         !                              ! indices used for the SUM control
354         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
355            lsp_area = .FALSE.
356         ELSE                                             ! print control done over a specific  area
357            lsp_area = .TRUE.
358            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
359               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
360               nictls = 1
361            ENDIF
362            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
363               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
364               nictle = jpiglo
365            ENDIF
366            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
367               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
368               njctls = 1
369            ENDIF
370            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
371               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
372               njctle = jpjglo
373            ENDIF
374         ENDIF
375      ENDIF
376      !
377      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
378         &                                                'Compile with key_nosignedzero enabled:',   &
379         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
380      !
381   END SUBROUTINE nemo_ctl
382
383
384   SUBROUTINE nemo_closefile
385      !!----------------------------------------------------------------------
386      !!                     ***  ROUTINE nemo_closefile  ***
387      !!
388      !! ** Purpose :   Close the files
389      !!----------------------------------------------------------------------
390      !
391      IF( lk_mpp )   CALL mppsync
392      !
393      CALL iom_close                                 ! close all input/output files managed by iom_*
394      !
395      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
396      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
397      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
398      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
399      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
400      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
401      !
402      numout = 6                                     ! redefine numout in case it is used after this point...
403      !
404   END SUBROUTINE nemo_closefile
405
406
407   SUBROUTINE nemo_alloc
408      !!----------------------------------------------------------------------
409      !!                     ***  ROUTINE nemo_alloc  ***
410      !!
411      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
412      !!
413      !! ** Method  :
414      !!----------------------------------------------------------------------
415      USE diawri    , ONLY : dia_wri_alloc
416      USE dom_oce   , ONLY : dom_oce_alloc
417      !
418      INTEGER :: ierr
419      !!----------------------------------------------------------------------
420      !
421      ierr =        oce_alloc    ()    ! ocean
422      ierr = ierr + dia_wri_alloc()
423      ierr = ierr + dom_oce_alloc()    ! ocean domain
424      !
425      CALL mpp_sum( 'nemogcm', ierr )
426      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
427      !
428   END SUBROUTINE nemo_alloc
429
430   
431   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto )
432      !!----------------------------------------------------------------------
433      !!                     ***  ROUTINE nemo_set_cfctl  ***
434      !!
435      !! ** Purpose :   Set elements of the output control structure to setto.
436      !!
437      !! ** Method  :   Note this routine can be used to switch on/off some
438      !!                types of output for selected areas.
439      !!----------------------------------------------------------------------
440      TYPE(sn_ctl), INTENT(inout) :: sn_cfctl
441      LOGICAL     , INTENT(in   ) :: setto
442      !!----------------------------------------------------------------------
443      sn_cfctl%l_runstat = setto
444      sn_cfctl%l_trcstat = setto
445      sn_cfctl%l_oceout  = setto
446      sn_cfctl%l_layout  = setto
447      sn_cfctl%l_prtctl  = setto
448      sn_cfctl%l_prttrc  = setto
449      sn_cfctl%l_oasout  = setto
450   END SUBROUTINE nemo_set_cfctl
451
452   !!======================================================================
453END MODULE nemogcm
454
Note: See TracBrowser for help on using the repository browser.