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/dev_r12866_HPC-02_Daley_Tiling_trial_extra_halo/src/SAO – NEMO

source: NEMO/branches/UKMO/dev_r12866_HPC-02_Daley_Tiling_trial_extra_halo/src/SAO/nemogcm.F90 @ 12958

Last change on this file since 12958 was 12958, checked in by hadcv, 4 years ago

Merge in trunk changes to r12933

  • Property svn:keywords set to Id
File size: 21.0 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 :  3.6  ! 2015-12  (A. Ryan) Original code   (from OCE/)
7   !!            4.0  ! 2016-11  (G. Madec, S. Flavoni)  domain configuration / user defined interface
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
12   !!   nemo_init     : initialization of the NEMO system
13   !!   nemo_ctl      : initialisation of the contol print
14   !!   nemo_closefile: close remaining open files
15   !!   nemo_alloc    : dynamical allocation
16   !!----------------------------------------------------------------------
17   USE step_oce       ! module used in the ocean time stepping module (step.F90)
18   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
19   USE istate         ! initial state setting          (istate_init routine)
20   USE phycst         ! physical constant                  (par_cst routine)
21   USE step           ! NEMO time-stepping                 (stp     routine)
22   USE cpl_oasis3     ! OASIS3 coupling
23   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
24#if defined key_nemocice_decomp
25   USE ice_domain_size, only: nx_global, ny_global
26#endif
27   !           ! Stand Alone Observation operator modules
28   USE sao_data
29   USE sao_intp
30   !
31   USE in_out_manager ! I/O manager
32   USE lib_mpp        ! distributed memory computing
33   USE mppini         ! shared/distributed memory setting (mpp_init routine)
34   USE lbcnfd  , ONLY : isendto, nsndto ! Setup of north fold exchanges
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   USE halo_mng
40
41   IMPLICIT NONE
42   PRIVATE
43
44   PUBLIC   nemo_gcm    ! called by model.F90
45   PUBLIC   nemo_init   ! needed by AGRIF
46   PUBLIC   nemo_alloc  ! needed by TAM
47
48   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
49
50   !!----------------------------------------------------------------------
51   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
52   !! $Id$
53   !! Software governed by the CeCILL license (see ./LICENSE)
54   !!----------------------------------------------------------------------
55CONTAINS
56
57   SUBROUTINE nemo_gcm
58         !!----------------------------------------------------------------------
59         !!                    ***  SUBROUTINE offline_obs_oper ***
60         !!
61         !! ** Purpose : To use NEMO components to interpolate model fields
62         !!              to observation space.
63         !!
64         !! ** Method : 1. Initialise NEMO
65         !!             2. Initialise offline obs_oper
66         !!             3. Cycle through match ups
67         !!             4. Write results to file
68         !!----------------------------------------------------------------------
69         !
70         CALL nemo_init       ! Initialise NEMO
71         !
72         CALL sao_data_init   ! Initialise Stand Alone Observation operator data
73         !
74         CALL dia_obs_init    ! Initialise obs_operator
75         !
76         CALL sao_interp      ! Interpolate to observation space
77         !
78         CALL dia_obs_wri     ! Pipe to output files
79         !
80         CALL dia_obs_dealloc ! Reset the obs_oper between
81         !
82         IF(lk_mpp)   CALL mppstop  ! Safely stop MPI (end mpp communications)
83         !
84   END SUBROUTINE nemo_gcm
85
86
87   SUBROUTINE nemo_init
88      !!----------------------------------------------------------------------
89      !!                     ***  ROUTINE nemo_init  ***
90      !!
91      !! ** Purpose :   initialization of the NEMO GCM
92      !!----------------------------------------------------------------------
93      INTEGER ::   ios, ilocal_comm   ! local integer
94      !
95      NAMELIST/namctl/ sn_cfctl,  nn_print, nn_ictls, nn_ictle,             &
96         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
97         &             ln_timing, ln_diacfl
98      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
99      !!----------------------------------------------------------------------
100      !
101      cxios_context = 'nemo'
102      nn_hls = 1
103      !
104      !                             !-------------------------------------------------!
105      !                             !     set communicator & select the local rank    !
106      !                             !  must be done as soon as possible to get narea  !
107      !                             !-------------------------------------------------!
108      !
109#if defined key_iomput
110      IF( Agrif_Root() ) THEN
111         IF( lk_oasis ) THEN
112            CALL cpl_init( "oceanx", ilocal_comm )                               ! nemo local communicator given by oasis
113            CALL xios_initialize( "not used"       , local_comm =ilocal_comm )   ! send nemo communicator to xios
114         ELSE
115            CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
116         ENDIF
117      ENDIF
118      CALL mpp_start( ilocal_comm )
119#else
120      IF( lk_oasis ) THEN
121         IF( Agrif_Root() ) THEN
122            CALL cpl_init( "oceanx", ilocal_comm )          ! nemo local communicator given by oasis
123         ENDIF
124         CALL mpp_start( ilocal_comm )
125      ELSE
126         CALL mpp_start( )
127      ENDIF
128#endif
129      !
130      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
131      lwm = (narea == 1)                ! control of output namelists
132      !
133      !                             !---------------------------------------------------------------!
134      !                             ! Open output files, reference and configuration namelist files !
135      !                             !---------------------------------------------------------------!
136      !
137      ! open ocean.output as soon as possible to get all output prints (including errors messages)
138      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
139      ! open reference and configuration namelist files
140                  CALL load_nml( numnam_ref,        'namelist_ref',                                           -1, lwm )
141                  CALL load_nml( numnam_cfg,        'namelist_cfg',                                           -1, lwm )
142      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
143      ! open /dev/null file to be able to supress output write easily
144      IF( Agrif_Root() ) THEN
145                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
146#ifdef key_agrif
147      ELSE
148                  numnul = Agrif_Parent(numnul)   
149#endif
150      ENDIF
151      !
152      !                             !--------------------!
153      !                             ! Open listing units !  -> need sn_cfctl from namctl to define lwp
154      !                             !--------------------!
155      !
156      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
157901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
158      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
159902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
160      !
161      ! finalize the definition of namctl variables
162      IF( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax .OR. MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 )   &
163         &   CALL nemo_set_cfctl( sn_cfctl, .FALSE. )
164      !
165      lwp = (narea == 1) .OR. sn_cfctl%l_oceout    ! control of all listing output print
166      !
167      IF(lwp) THEN                      ! open listing units
168         !
169         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
170            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
171         !
172         WRITE(numout,*)
173         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
174         WRITE(numout,*) '                       NEMO team'
175         WRITE(numout,*) '            Stand Alone Observation operator'
176         WRITE(numout,*) '                NEMO version 4.0  (2019) '
177         WRITE(numout,*)
178         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
179         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
180         WRITE(numout,*)
181         WRITE(numout,*) "           o         _,           _,             "
182         WRITE(numout,*) "            o      .' (        .-' /             "
183         WRITE(numout,*) "           o     _/..._'.    .'   /              "
184         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
185         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
186         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
187         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
188         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
189         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
190         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
191         WRITE(numout,*)
192         !
193         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
194         !
195      ENDIF
196      !
197      IF(lwm) WRITE( numond, namctl )
198      !
199      !                             !------------------------------------!
200      !                             !  Set global domain size parameters !
201      !                             !------------------------------------!
202      !
203      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
204903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
205      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
206904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
207      !
208      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
209         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
210      ELSE                              ! user-defined namelist
211         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
212      ENDIF
213      !
214      IF(lwm)   WRITE( numond, namcfg )
215      !
216      !                             !-----------------------------------------!
217      !                             ! mpp parameters and domain decomposition !
218      !                             !-----------------------------------------!
219      CALL mpp_init
220
221      CALL halo_mng_init()
222      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
223      CALL nemo_alloc()
224
225      !                             !-------------------------------!
226      !                             !  NEMO general initialization  !
227      !                             !-------------------------------!
228
229      CALL nemo_ctl                          ! Control prints
230      !
231      !                                         ! General initialization
232      IF( ln_timing    )   CALL timing_init     ! timing
233      IF( ln_timing    )   CALL timing_start( 'nemo_init')
234      !
235                           CALL phy_cst            ! Physical constants
236                           CALL eos_init           ! Equation of state
237                           CALL dom_init( Nbb, Nnn, Naa, 'SAO')    ! Domain
238
239
240      IF( sn_cfctl%l_prtctl )   &
241         &                 CALL prt_ctl_init       ! Print control
242
243                           CALL istate_init        ! ocean initial state (Dynamics and tracers)
244   END SUBROUTINE nemo_init
245
246
247   SUBROUTINE nemo_ctl
248      !!----------------------------------------------------------------------
249      !!                     ***  ROUTINE nemo_ctl  ***
250      !!
251      !! ** Purpose :   control print setting
252      !!
253      !! ** Method  : - print namctl and namcfg information and check some consistencies
254      !!----------------------------------------------------------------------
255      !
256      IF(lwp) THEN                  ! control print
257         WRITE(numout,*)
258         WRITE(numout,*) 'nemo_ctl: Control prints'
259         WRITE(numout,*) '~~~~~~~~'
260         WRITE(numout,*) '   Namelist namctl'
261         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
262         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
263         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
264         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
265         WRITE(numout,*) '                              sn_cfctl%l_prtctl  = ', sn_cfctl%l_prtctl
266         WRITE(numout,*) '                              sn_cfctl%l_prttrc  = ', sn_cfctl%l_prttrc
267         WRITE(numout,*) '                              sn_cfctl%l_oasout  = ', sn_cfctl%l_oasout
268         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
269         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
270         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
271         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
272         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
273         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
274         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
275         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
276         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
277         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
278         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
279         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
280         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
281      ENDIF
282      !
283      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
284      nictls    = nn_ictls
285      nictle    = nn_ictle
286      njctls    = nn_jctls
287      njctle    = nn_jctle
288      isplt     = nn_isplt
289      jsplt     = nn_jsplt
290
291      IF(lwp) THEN                  ! control print
292         WRITE(numout,*)
293         WRITE(numout,*) '   Namelist namcfg'
294         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
295         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
296         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
297         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
298         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
299         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
300      ENDIF
301      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
302      !
303      !                             ! Parameter control
304      !
305      IF( sn_cfctl%l_prtctl .OR. sn_cfctl%l_prttrc ) THEN              ! sub-domain area indices for the control prints
306         IF( lk_mpp .AND. jpnij > 1 ) THEN
307            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
308         ELSE
309            IF( isplt == 1 .AND. jsplt == 1  ) THEN
310               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
311                  &           ' - the print control will be done over the whole domain' )
312            ENDIF
313            ijsplt = isplt * jsplt            ! total number of processors ijsplt
314         ENDIF
315         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
316         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
317         !
318         !                              ! indices used for the SUM control
319         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
320            lsp_area = .FALSE.
321         ELSE                                             ! print control done over a specific  area
322            lsp_area = .TRUE.
323            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
324               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
325               nictls = 1
326            ENDIF
327            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
328               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
329               nictle = jpiglo
330            ENDIF
331            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
332               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
333               njctls = 1
334            ENDIF
335            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
336               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
337               njctle = jpjglo
338            ENDIF
339         ENDIF
340      ENDIF
341      !
342      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
343         &                                                'Compile with key_nosignedzero enabled:',   &
344         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
345      !
346   END SUBROUTINE nemo_ctl
347
348
349   SUBROUTINE nemo_closefile
350      !!----------------------------------------------------------------------
351      !!                     ***  ROUTINE nemo_closefile  ***
352      !!
353      !! ** Purpose :   Close the files
354      !!----------------------------------------------------------------------
355      !
356      IF( lk_mpp )   CALL mppsync
357      !
358      CALL iom_close                                 ! close all input/output files managed by iom_*
359      !
360      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
361      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
362      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
363      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
364      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
365      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
366      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
367      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
368      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
369      !
370      numout = 6                                     ! redefine numout in case it is used after this point...
371      !
372   END SUBROUTINE nemo_closefile
373
374
375   SUBROUTINE nemo_alloc
376      !!----------------------------------------------------------------------
377      !!                     ***  ROUTINE nemo_alloc  ***
378      !!
379      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
380      !!
381      !! ** Method  :
382      !!----------------------------------------------------------------------
383      USE diawri    , ONLY: dia_wri_alloc
384      USE dom_oce   , ONLY: dom_oce_alloc
385      !
386      INTEGER :: ierr
387      !!----------------------------------------------------------------------
388      !
389      ierr =        oce_alloc       ()          ! ocean
390      ierr = ierr + dia_wri_alloc   ()
391      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
392      !
393      CALL mpp_sum( 'nemogcm', ierr )
394      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
395      !
396   END SUBROUTINE nemo_alloc
397
398   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto )
399      !!----------------------------------------------------------------------
400      !!                     ***  ROUTINE nemo_set_cfctl  ***
401      !!
402      !! ** Purpose :   Set elements of the output control structure to setto.
403      !!
404      !! ** Method  :   Note this routine can be used to switch on/off some
405      !!                types of output for selected areas.
406      !!----------------------------------------------------------------------
407      TYPE(sn_ctl), INTENT(inout) :: sn_cfctl
408      LOGICAL     , INTENT(in   ) :: setto
409      !!----------------------------------------------------------------------
410      sn_cfctl%l_runstat = setto
411      sn_cfctl%l_trcstat = setto
412      sn_cfctl%l_oceout  = setto
413      sn_cfctl%l_layout  = setto
414      sn_cfctl%l_prtctl  = setto
415      sn_cfctl%l_prttrc  = setto
416      sn_cfctl%l_oasout  = setto
417   END SUBROUTINE nemo_set_cfctl
418
419   !!======================================================================
420END MODULE nemogcm
421
Note: See TracBrowser for help on using the repository browser.