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/trunk/tests/STATION_ASF/MY_SRC – NEMO

source: NEMO/trunk/tests/STATION_ASF/MY_SRC/nemogcm.F90 @ 14072

Last change on this file since 14072 was 14072, checked in by laurent, 3 years ago

Merging branch "2020/dev_r13648_ASINTER-04_laurent_bulk_ice", ticket #2369

File size: 20.1 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#if defined key_mpp_mpi
49   ! need MPI_Wtime
50   INCLUDE 'mpif.h'
51#endif
52
53   !!----------------------------------------------------------------------
54   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
55   !! $Id: nemogcm.F90 13286 2020-07-09 15:48:29Z smasson $
56   !! Software governed by the CeCILL license (see ./LICENSE)
57   !!----------------------------------------------------------------------
58CONTAINS
59
60   SUBROUTINE nemo_gcm
61      !!----------------------------------------------------------------------
62      !!                     ***  ROUTINE nemo_gcm  ***
63      !!
64      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
65      !!              curvilinear mesh on the sphere.
66      !!
67      !! ** Method  : - model general initialization
68      !!              - launch the time-stepping (stp routine)
69      !!              - finalize the run by closing files and communications
70      !!
71      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
72      !!              Madec, 2008, internal report, IPSL.
73      !!----------------------------------------------------------------------
74      INTEGER ::   istp   ! time step index
75      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
76      !!----------------------------------------------------------------------
77      !
78      !                            !-----------------------!
79      CALL nemo_init               !==  Initialisations  ==!
80      !                            !-----------------------!
81      ! check that all process are still there... If some process have an error,
82      ! they will never enter in step and other processes will wait until the end of the cpu time!
83      CALL mpp_max( 'nemogcm', nstop )
84
85      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
86
87      !                            !-----------------------!
88      !                            !==   time stepping   ==!
89      !                            !-----------------------!
90      !
91      !                                               !== set the model time-step  ==!
92      !
93      istp = nit000
94      !
95      DO WHILE ( istp <= nitend .AND. nstop == 0 )    !==  C1D time-stepping  ==!
96         CALL stp_c1d( istp )
97         istp = istp + 1
98      END DO
99      !
100      !                            !------------------------!
101      !                            !==  finalize the run  ==!
102      !                            !------------------------!
103      IF(lwp) WRITE(numout,cform_aaa)        ! Flag AAAAAAA
104      !
105      IF( nstop /= 0 .AND. lwp ) THEN        ! error print
106         WRITE(ctmp1,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
107         WRITE(ctmp2,*) '           Look for "E R R O R" messages in all existing ocean_output* files'
108         CALL ctl_stop( ' ', ctmp1, ' ', ctmp2 )
109      ENDIF
110      !
111      IF( ln_timing )   CALL timing_finalize
112      !
113      CALL nemo_closefile
114      !
115#if defined key_iomput
116      CALL xios_finalize  ! end mpp communications with xios
117#else
118      IF( lk_mpp )                  CALL mppstop      ! end mpp communications
119#endif
120      !
121      IF(lwm) THEN
122         IF( nstop == 0 ) THEN   ;   STOP 0
123         ELSE                    ;   STOP 123
124         ENDIF
125      ENDIF
126      !
127   END SUBROUTINE nemo_gcm
128
129
130   SUBROUTINE nemo_init
131      !!----------------------------------------------------------------------
132      !!                     ***  ROUTINE nemo_init  ***
133      !!
134      !! ** Purpose :   initialization of the NEMO GCM
135      !!----------------------------------------------------------------------
136      INTEGER ::   ios, ilocal_comm   ! local integers
137      !!
138      NAMELIST/namctl/ sn_cfctl, ln_timing, ln_diacfl,                                &
139         &             nn_isplt,  nn_jsplt,  nn_ictls, nn_ictle, nn_jctls, nn_jctle
140      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
141      !!----------------------------------------------------------------------
142      !
143      cxios_context = 'nemo'
144      !
145      !                             !-------------------------------------------------!
146      !                             !     set communicator & select the local rank    !
147      !                             !  must be done as soon as possible to get narea  !
148      !                             !-------------------------------------------------!
149      !
150#if defined key_iomput
151      IF( Agrif_Root() ) THEN
152         CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
153      ENDIF
154      CALL mpp_start( ilocal_comm )
155#else
156      CALL mpp_start( )
157#endif
158      !
159      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
160      lwm = (narea == 1)                ! control of output namelists
161      !
162      !                             !---------------------------------------------------------------!
163      !                             ! Open output files, reference and configuration namelist files !
164      !                             !---------------------------------------------------------------!
165      !
166      ! open ocean.output as soon as possible to get all output prints (including errors messages)
167      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
168      ! open reference and configuration namelist files
169      CALL load_nml( numnam_ref,        'namelist_ref',                                           -1, lwm )
170      CALL load_nml( numnam_cfg,        'namelist_cfg',                                           -1, lwm )
171      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
172      ! open /dev/null file to be able to supress output write easily
173      IF( Agrif_Root() ) THEN
174         CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
175#ifdef key_agrif
176      ELSE
177         numnul = Agrif_Parent(numnul)
178#endif
179      ENDIF
180      !                             !--------------------!
181      !                             ! Open listing units !  -> need sn_cfctl from namctl to define lwp
182      !                             !--------------------!
183      !
184      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
185901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
186      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
187902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
188      !
189      ! finalize the definition of namctl variables
190      IF( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax .OR. MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 )   &
191         &   CALL nemo_set_cfctl( sn_cfctl, .FALSE. )
192      !
193      lwp = (narea == 1) .OR. sn_cfctl%l_oceout    ! control of all listing output print
194      !
195      IF(lwp) THEN                      ! open listing units
196         !
197         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
198            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
199         !
200         WRITE(numout,*)
201         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
202         WRITE(numout,*) '                       NEMO team'
203         WRITE(numout,*) '            Ocean General Circulation Model'
204         WRITE(numout,*) '                NEMO version 4.0  (2019) '
205         WRITE(numout,*) '                      STATION_ASF '
206         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
207         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
208         WRITE(numout,*)
209         WRITE(numout,*) "           o         _,           _,             "
210         WRITE(numout,*) "            o      .' (        .-' /             "
211         WRITE(numout,*) "           o     _/..._'.    .'   /              "
212         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
213         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
214         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
215         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
216         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
217         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
218         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
219         WRITE(numout,*)
220
221         ! Print the working precision to ocean.output
222         IF (wp == dp) THEN
223            WRITE(numout,*) "Working precision = double-precision"
224         ELSE
225            WRITE(numout,*) "Working precision = single-precision"
226         ENDIF
227         WRITE(numout,*)
228         !
229         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
230         !
231      ENDIF
232      !
233      IF(lwm) WRITE( numond, namctl )
234      !
235      !                             !------------------------------------!
236      !                             !  Set global domain size parameters !
237      !                             !------------------------------------!
238      !
239      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
240903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
241      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
242904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )
243      !
244      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
245         CALL domain_cfg ( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, jperio )
246      ELSE                              ! user-defined namelist
247         CALL usr_def_nam( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, jperio )
248      ENDIF
249      !
250      IF(lwm)   WRITE( numond, namcfg )
251      !
252      !                             !-----------------------------------------!
253      !                             ! mpp parameters and domain decomposition !
254      !                             !-----------------------------------------!
255      CALL mpp_init
256
257      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
258      CALL nemo_alloc()
259
260      ! Initialise time level indices
261      Nbb = 1; Nnn = 2; Naa = 3; Nrhs = Naa
262
263      !                             !-------------------------------!
264      !                             !  NEMO general initialization  !
265      !                             !-------------------------------!
266
267      CALL nemo_ctl                          ! Control prints
268      !
269      !                                      ! General initialization
270      IF( ln_timing    )   CALL timing_init     ! timing
271      IF( ln_timing    )   CALL timing_start( 'nemo_init')
272      !
273                           CALL     phy_cst         ! Physical constants
274                           CALL     eos_init        ! Equation of state
275      IF( lk_c1d       )   CALL     c1d_init        ! 1D column configuration
276                           CALL     dom_init( Nbb, Nnn, Naa ) ! Domain
277      IF( sn_cfctl%l_prtctl )   &
278         &                 CALL prt_ctl_init        ! Print control
279
280                           CALL  istate_init( Nbb, Nnn, Naa )    ! ocean initial state (Dynamics and tracers)
281
282      !                                      ! external forcing
283                           CALL     sbc_init( Nbb, Nnn, Naa )    ! surface boundary conditions (including sea-ice)
284
285      !#LB:
286#if defined key_si3
287      IF(lwp) WRITE(numout,*) 'LOLO: nemo_init@nemogcm.F90: shape of fr_i ==>', SIZE(fr_i,1), SIZE(fr_i,2)
288      fr_i(:,:) = 0._wp
289#endif
290      !#LB.
291
292      !
293      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
294      !
295      IF( ln_timing    )   CALL timing_stop( 'nemo_init')
296      !
297   END SUBROUTINE nemo_init
298
299
300   SUBROUTINE nemo_ctl
301      !!----------------------------------------------------------------------
302      !!                     ***  ROUTINE nemo_ctl  ***
303      !!
304      !! ** Purpose :   control print setting
305      !!
306      !! ** Method  : - print namctl and namcfg information and check some consistencies
307      !!----------------------------------------------------------------------
308      !
309      IF(lwp) THEN                  ! control print
310         WRITE(numout,*)
311         WRITE(numout,*) 'nemo_ctl: Control prints'
312         WRITE(numout,*) '~~~~~~~~'
313         WRITE(numout,*) '   Namelist namctl'
314         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
315         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
316         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
317         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
318         WRITE(numout,*) '                              sn_cfctl%l_prtctl  = ', sn_cfctl%l_prtctl
319         WRITE(numout,*) '                              sn_cfctl%l_prttrc  = ', sn_cfctl%l_prttrc
320         WRITE(numout,*) '                              sn_cfctl%l_oasout  = ', sn_cfctl%l_oasout
321         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin
322         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax
323         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr
324         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr
325         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
326         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
327      ENDIF
328      !
329      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
330      IF(lwp) THEN                  ! control print
331         WRITE(numout,*)
332         WRITE(numout,*) '   Namelist namcfg'
333         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
334         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
335         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
336         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
337         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
338         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
339      ENDIF
340      !
341      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
342         &                                                'Compile with key_nosignedzero enabled:',   &
343         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
344      !
345   END SUBROUTINE nemo_ctl
346
347
348   SUBROUTINE nemo_closefile
349      !!----------------------------------------------------------------------
350      !!                     ***  ROUTINE nemo_closefile  ***
351      !!
352      !! ** Purpose :   Close the files
353      !!----------------------------------------------------------------------
354      !
355      IF( lk_mpp )   CALL mppsync
356      !
357      CALL iom_close                                 ! close all input/output files managed by iom_*
358      !
359      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
360      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
361      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
362      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
363      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
364      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
365      !
366      numout = 6                                     ! redefine numout in case it is used after this point...
367      !
368   END SUBROUTINE nemo_closefile
369
370
371   SUBROUTINE nemo_alloc
372      !!----------------------------------------------------------------------
373      !!                     ***  ROUTINE nemo_alloc  ***
374      !!
375      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
376      !!
377      !! ** Method  :
378      !!----------------------------------------------------------------------
379      USE diawri    , ONLY : dia_wri_alloc
380      USE dom_oce   , ONLY : dom_oce_alloc
381      !
382      INTEGER :: ierr
383      !!----------------------------------------------------------------------
384      !
385      ierr =        oce_alloc    ()    ! ocean
386      ierr = ierr + dia_wri_alloc()
387      ierr = ierr + dom_oce_alloc()    ! ocean domain
388      !
389      CALL mpp_sum( 'nemogcm', ierr )
390      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
391      !
392   END SUBROUTINE nemo_alloc
393
394
395   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto )
396      !!----------------------------------------------------------------------
397      !!                     ***  ROUTINE nemo_set_cfctl  ***
398      !!
399      !! ** Purpose :   Set elements of the output control structure to setto.
400      !!
401      !! ** Method  :   Note this routine can be used to switch on/off some
402      !!                types of output for selected areas.
403      !!----------------------------------------------------------------------
404      TYPE(sn_ctl), INTENT(inout) :: sn_cfctl
405      LOGICAL     , INTENT(in   ) :: setto
406      !!----------------------------------------------------------------------
407      sn_cfctl%l_runstat = setto
408      sn_cfctl%l_trcstat = setto
409      sn_cfctl%l_oceout  = setto
410      sn_cfctl%l_layout  = setto
411      sn_cfctl%l_prtctl  = setto
412      sn_cfctl%l_prttrc  = setto
413      sn_cfctl%l_oasout  = setto
414   END SUBROUTINE nemo_set_cfctl
415
416   !!======================================================================
417END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.