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 @ 13286

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

trunk: merge extra halos branch in trunk, see #2366

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