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 branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC – NEMO

source: branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 7069

Last change on this file since 7069 was 7069, checked in by clem, 8 years ago

agrif+lim3 update + trunk update

  • Property svn:keywords set to Id
File size: 33.5 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
11   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
12   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
15   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
16   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
17   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
18   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
19   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
20   !!             -   ! 2004-08  (C. Talandier) New trends organization
21   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
22   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
23   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
24   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
25   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
26   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
29   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!            3.4  ! 2011-11  (C. Harris) decomposition changes for running with CICE
31   !!----------------------------------------------------------------------
32
33   !!----------------------------------------------------------------------
34   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
35   !!   nemo_init      : initialization of the NEMO system
36   !!   nemo_ctl       : initialisation of the contol print
37   !!   nemo_closefile : close remaining open files
38   !!   nemo_alloc     : dynamical allocation
39   !!   nemo_partition : calculate MPP domain decomposition
40   !!   factorise      : calculate the factors of the no. of MPI processes
41   !!----------------------------------------------------------------------
42   USE step_oce        ! module used in the ocean time stepping module
43   USE sbc_oce         ! surface boundary condition: ocean
44   USE domcfg          ! domain configuration               (dom_cfg routine)
45   USE daymod          ! calendar
46   USE mppini          ! shared/distributed memory setting (mpp_init routine)
47   USE domain          ! domain initialization             (dom_init routine)
48   USE phycst          ! physical constant                  (par_cst routine)
49   USE step            ! NEMO time-stepping                 (stp     routine)
50   USE lib_mpp         ! distributed memory computing
51   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
52#if defined key_iomput
53   USE xios
54#endif
55   USE cpl_oasis3
56   USE sbcssm
57   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
58   USE icbini          ! handle bergs, initialisation
59   USE icbstp          ! handle bergs, calving, themodynamics and transport
60
61   USE bdyini          ! open boundary cond. setting       (bdy_init routine). clem: mandatory for LIM3
62   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine)           - -
63   USE bdy_par
64   
65   IMPLICIT NONE
66   PRIVATE
67
68   PUBLIC   nemo_gcm    ! called by model.F90
69   PUBLIC   nemo_init   ! needed by AGRIF
70
71   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
72
73   !!----------------------------------------------------------------------
74   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
75   !! $Id$
76   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
77   !!----------------------------------------------------------------------
78CONTAINS
79
80   SUBROUTINE nemo_gcm
81      !!----------------------------------------------------------------------
82      !!                     ***  ROUTINE nemo_gcm  ***
83      !!
84      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
85      !!              curvilinear mesh on the sphere.
86      !!
87      !! ** Method  : - model general initialization
88      !!              - launch the time-stepping (stp routine)
89      !!              - finalize the run by closing files and communications
90      !!
91      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
92      !!              Madec, 2008, internal report, IPSL.
93      !!----------------------------------------------------------------------
94      INTEGER ::   istp       ! time step index
95      !!----------------------------------------------------------------------
96      !
97#if defined key_agrif
98     CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
99#endif
100     
101      !                            !-----------------------!
102      CALL nemo_init               !==  Initialisations  ==!
103      !                            !-----------------------!
104#if defined key_agrif
105      CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
106      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA
107# if defined key_top
108      CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
109# endif
110# if defined key_lim2
111      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM
112# endif
113# if defined key_lim3
114      CALL Agrif_Declare_Var_lim3  !  "      "   "   "      "  LIM3 clem: useless?
115# endif
116#endif
117      ! check that all process are still there... If some process have an error,
118      ! they will never enter in step and other processes will wait until the end of the cpu time!
119      IF( lk_mpp )   CALL mpp_max( nstop )
120
121      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
122
123      !                            !-----------------------!
124      !                            !==   time stepping   ==!
125      !                            !-----------------------!
126      istp = nit000
127
128#if defined key_agrif
129          CALL Agrif_Regrid()
130#endif
131       
132      DO WHILE ( istp <= nitend .AND. nstop == 0 )
133#if defined key_agrif
134         CALL stp                         ! AGRIF: time stepping
135#else
136         CALL stp( istp )                 ! standard time stepping
137#endif
138         istp = istp + 1
139         IF( lk_mpp )   CALL mpp_max( nstop )
140      END DO
141      !
142      IF( ln_icebergs )   CALL icb_end( nitend )
143
144      !                            !------------------------!
145      !                            !==  finalize the run  ==!
146      !                            !------------------------!
147      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
148      !
149      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
150         WRITE(numout,cform_err)
151         WRITE(numout,*) nstop, ' error have been found' 
152      ENDIF
153      !
154#if defined key_agrif
155      IF( .NOT. Agrif_Root() ) THEN
156         CALL Agrif_ParentGrid_To_ChildGrid()
157         IF( nn_timing == 1 )   CALL timing_finalize
158         CALL Agrif_ChildGrid_To_ParentGrid()
159      ENDIF
160#endif
161      IF( nn_timing == 1 )   CALL timing_finalize
162      !
163      CALL nemo_closefile
164      !
165#if defined key_iomput
166      CALL xios_finalize                ! end mpp communications with xios
167      IF( lk_oasis ) CALL cpl_finalize    ! end coupling and mpp communications with OASIS
168#else
169      IF( lk_oasis ) THEN
170         CALL cpl_finalize              ! end coupling and mpp communications with OASIS
171      ELSE
172         IF( lk_mpp )   CALL mppstop    ! end mpp communications
173      ENDIF
174#endif
175      !
176   END SUBROUTINE nemo_gcm
177
178
179   SUBROUTINE nemo_init
180      !!----------------------------------------------------------------------
181      !!                     ***  ROUTINE nemo_init  ***
182      !!
183      !! ** Purpose :   initialization of the NEMO GCM
184      !!----------------------------------------------------------------------
185      INTEGER ::   ji            ! dummy loop indices
186      INTEGER ::   ilocal_comm   ! local integer     
187      INTEGER ::   ios
188      CHARACTER(len=80), DIMENSION(16) ::   cltxt
189      CHARACTER(len=80) ::   clname
190      !
191      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
192         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
193         &             nn_bench, nn_timing
194      NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
195         &             jpizoom, jpjzoom, jperio, ln_use_jattr
196      !!----------------------------------------------------------------------
197      !
198      cltxt = ''
199      !
200      !                             ! Open reference namelist and configuration namelist files
201      IF( lk_oasis ) THEN
202         CALL ctl_opn( numnam_ref, 'namelist_sas_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
203         CALL ctl_opn( numnam_cfg, 'namelist_sas_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
204         cxios_context = 'sas'
205         clname = 'output.namelist_sas.dyn'
206      ELSE
207         CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
208         CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
209         cxios_context = 'nemo'
210         clname = 'output.namelist.dyn'
211   ENDIF
212      !
213      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
214      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
215901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
216
217      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
218      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
219902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
220
221      !
222      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
223      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
224903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
225
226      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
227      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
228904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
229
230! Force values for AGRIF zoom (cf. agrif_user.F90)
231#if defined key_agrif
232   IF( .NOT. Agrif_Root() ) THEN
233      jpiglo  = nbcellsx + 2 + 2*nbghostcells
234      jpjglo  = nbcellsy + 2 + 2*nbghostcells
235      jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
236      jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
237      jpidta  = jpiglo
238      jpjdta  = jpjglo
239      jpizoom = 1
240      jpjzoom = 1
241      nperio  = 0
242      jperio  = 0
243      ln_use_jattr = .false.
244   ENDIF
245#endif
246      !
247      !                             !--------------------------------------------!
248      !                             !  set communicator & select the local node  !
249      !                             !  NB: mynode also opens output.namelist.dyn !
250      !                             !      on unit number numond on first proc   !
251      !                             !--------------------------------------------!
252#if defined key_iomput
253      IF( Agrif_Root() ) THEN
254         IF( lk_oasis ) THEN
255            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis
256            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
257         ELSE
258            CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )        ! nemo local communicator given by xios
259         ENDIF
260      ENDIF
261      narea = mynode ( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )  ! Nodes selection
262#else
263      IF( lk_oasis ) THEN
264         IF( Agrif_Root() ) THEN
265            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis
266         ENDIF
267         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
268      ELSE
269         ilocal_comm = 0
270         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
271      ENDIF
272#endif
273      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
274
275      lwm = (narea == 1)                                    ! control of output namelists
276      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
277
278      IF(lwm) THEN
279         ! write merged namelists from earlier to output namelist now that the
280         ! file has been opened in call to mynode. nammpp has already been
281         ! written in mynode (if lk_mpp_mpi)
282         WRITE( numond, namctl )
283         WRITE( numond, namcfg )
284      ENDIF
285
286      ! If dimensions of processor grid weren't specified in the namelist file
287      ! then we calculate them here now that we have our communicator size
288      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
289#if   defined key_mpp_mpi
290         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
291#else
292         jpni  = 1
293         jpnj  = 1
294         jpnij = jpni*jpnj
295#endif
296      ENDIF
297
298      ! Calculate domain dimensions given calculated jpni and jpnj
299      ! This used to be done in par_oce.F90 when they were parameters rather
300      ! than variables
301      IF( Agrif_Root() ) THEN
302#if defined key_nemocice_decomp
303         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first  dim.
304         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
305#else
306         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
307         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
308#endif
309      ENDIF
310#if defined key_sas2D
311         jpk = 1                                             ! third dim
312         jpkm1 = 1                                           !   "           "
313#else
314         jpk = jpkdta                                        ! third dim
315         jpkm1 = jpk-1                                       !   "           "
316#endif
317#if defined key_agrif
318         ! simple trick to use same vertical grid as parent
319         ! but different number of levels:
320         ! Save maximum number of levels in jpkdta, then define all vertical grids
321         ! with this number.
322         ! Suppress once vertical online interpolation is ok
323         IF(.NOT.Agrif_Root()) jpkdta = Agrif_Parent(jpkdta)
324#endif
325         jpim1 = jpi-1                                            ! inner domain indices
326         jpjm1 = jpj-1                                            !   "           "
327         jpij  = jpi*jpj                                          !  jpi x j
328
329      IF(lwp) THEN                            ! open listing units
330         !
331         IF( lk_oasis ) THEN
332            CALL ctl_opn( numout,   'sas.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
333         ELSE
334            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
335         ENDIF
336         !
337         WRITE(numout,*)
338         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
339         WRITE(numout,*) '                       NEMO team'
340         WRITE(numout,*) '            Ocean General Circulation Model'
341         WRITE(numout,*) '                  version 3.6  (2015) '
342         WRITE(numout,*) '             StandAlone Surface version (SAS) '
343         WRITE(numout,*)
344         WRITE(numout,*)
345         DO ji = 1, SIZE(cltxt) 
346            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
347         END DO
348         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
349         !
350      ENDIF
351
352      ! Now we know the dimensions of the grid and numout has been set we can allocate arrays
353      CALL nemo_alloc()
354
355      !                             !-------------------------------!
356      !                             !  NEMO general initialization  !
357      !                             !-------------------------------!
358
359      CALL nemo_ctl                          ! Control prints & Benchmark
360
361      !                                      ! Domain decomposition
362      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
363      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
364      ENDIF
365      !
366      IF( nn_timing == 1 )  CALL timing_init
367      !
368      !                                     ! General initialization
369                            CALL phy_cst    ! Physical constants
370                            CALL eos_init   ! Equation of state
371                            CALL dom_cfg    ! Domain configuration
372                            CALL dom_init   ! Domain
373
374     IF( ln_nnogather )     CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
375
376      IF( ln_ctl      )     CALL prt_ctl_init   ! Print control
377                            CALL day_init   ! model calendar (using both namelist and restart infos)
378
379                            CALL sbc_init   ! Forcings : surface module
380
381      ! ==> clem: open boundaries init. is mandatory for LIM3 because ice BDY is not decoupled from 
382      !           the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules.
383      !           This is not clean and should be changed in the future.
384      IF( lk_bdy        )   CALL     bdy_init
385      IF( lk_bdy        )   CALL bdy_dta_init
386      ! ==>
387                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
388     
389      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
390      !
391   END SUBROUTINE nemo_init
392
393
394   SUBROUTINE nemo_ctl
395      !!----------------------------------------------------------------------
396      !!                     ***  ROUTINE nemo_ctl  ***
397      !!
398      !! ** Purpose :   control print setting
399      !!
400      !! ** Method  : - print namctl information and check some consistencies
401      !!----------------------------------------------------------------------
402      !
403      IF(lwp) THEN                  ! control print
404         WRITE(numout,*)
405         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
406         WRITE(numout,*) '~~~~~~~ '
407         WRITE(numout,*) '   Namelist namctl'
408         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
409         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
410         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
411         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
412         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
413         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
414         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
415         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
416         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
417      ENDIF
418      !
419      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
420      nictls    = nn_ictls
421      nictle    = nn_ictle
422      njctls    = nn_jctls
423      njctle    = nn_jctle
424      isplt     = nn_isplt
425      jsplt     = nn_jsplt
426      nbench    = nn_bench
427
428      IF(lwp) THEN                  ! control print
429         WRITE(numout,*)
430         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
431         WRITE(numout,*) '~~~~~~~ '
432         WRITE(numout,*) '   Namelist namcfg'
433         WRITE(numout,*) '      configuration name              cp_cfg      = ', TRIM(cp_cfg)
434         WRITE(numout,*) '      configuration zoom name         cp_cfz      = ', TRIM(cp_cfz)
435         WRITE(numout,*) '      configuration resolution        jp_cfg      = ', jp_cfg
436         WRITE(numout,*) '      1st lateral dimension ( >= jpi ) jpidta     = ', jpidta
437         WRITE(numout,*) '      2nd    "         "    ( >= jpj ) jpjdta     = ', jpjdta
438         WRITE(numout,*) '      3nd    "         "               jpkdta     = ', jpkdta
439         WRITE(numout,*) '      1st dimension of global domain in i jpiglo  = ', jpiglo
440         WRITE(numout,*) '      2nd    -                  -    in j jpjglo  = ', jpjglo
441         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
442         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
443         WRITE(numout,*) '      lateral cond. type (between 0 and 6) jperio = ', jperio   
444         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
445      ENDIF
446      !                             ! Parameter control
447      !
448      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
449         IF( lk_mpp .AND. jpnij > 1 ) THEN
450            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
451         ELSE
452            IF( isplt == 1 .AND. jsplt == 1  ) THEN
453               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
454                  &           ' - the print control will be done over the whole domain' )
455            ENDIF
456            ijsplt = isplt * jsplt            ! total number of processors ijsplt
457         ENDIF
458         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
459         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
460         !
461         !                              ! indices used for the SUM control
462         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
463            lsp_area = .FALSE.                       
464         ELSE                                             ! print control done over a specific  area
465            lsp_area = .TRUE.
466            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
467               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
468               nictls = 1
469            ENDIF
470            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
471               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
472               nictle = jpiglo
473            ENDIF
474            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
475               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
476               njctls = 1
477            ENDIF
478            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
479               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
480               njctle = jpjglo
481            ENDIF
482         ENDIF
483      ENDIF
484      !
485      IF( nbench == 1 ) THEN              ! Benchmark
486         SELECT CASE ( cp_cfg )
487         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
488         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
489            &                                 ' cp_cfg="gyre" in namelist &namcfg or set nbench = 0' )
490         END SELECT
491      ENDIF
492      !
493      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
494         &                                               'f2003 standard. '                              ,  &
495         &                                               'Compile with key_nosignedzero enabled' )
496      !
497   END SUBROUTINE nemo_ctl
498
499
500   SUBROUTINE nemo_closefile
501      !!----------------------------------------------------------------------
502      !!                     ***  ROUTINE nemo_closefile  ***
503      !!
504      !! ** Purpose :   Close the files
505      !!----------------------------------------------------------------------
506      !
507      IF( lk_mpp )   CALL mppsync
508      !
509      CALL iom_close                                 ! close all input/output files managed by iom_*
510      !
511      IF( numstp          /= -1 )   CLOSE( numstp      )   ! time-step file     
512      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
513      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
514      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
515      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
516      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
517      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
518      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
519      IF( numout          /=  6 )   CLOSE( numout      )   ! standard model output file
520      !
521      numout = 6                                     ! redefine numout in case it is used after this point...
522      !
523   END SUBROUTINE nemo_closefile
524
525
526   SUBROUTINE nemo_alloc
527      !!----------------------------------------------------------------------
528      !!                     ***  ROUTINE nemo_alloc  ***
529      !!
530      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
531      !!
532      !! ** Method  :
533      !!----------------------------------------------------------------------
534      USE diawri    , ONLY: dia_wri_alloc
535      USE dom_oce   , ONLY: dom_oce_alloc
536      USE oce 
537#if defined key_bdy   
538      USE bdy_oce   , ONLY: bdy_oce_alloc
539#endif
540      !
541      INTEGER :: ierr
542      !!----------------------------------------------------------------------
543      !
544      ierr =        dia_wri_alloc   ()
545      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
546      ierr = ierr + oce_alloc       ()          ! (tsn...) needed for agrif and/or lim3 and bdy
547#if defined key_bdy
548      ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
549#endif
550      !
551      IF( lk_mpp    )   CALL mpp_sum( ierr )
552      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
553      !
554   END SUBROUTINE nemo_alloc
555
556
557   SUBROUTINE nemo_partition( num_pes )
558      !!----------------------------------------------------------------------
559      !!                 ***  ROUTINE nemo_partition  ***
560      !!
561      !! ** Purpose :   
562      !!
563      !! ** Method  :
564      !!----------------------------------------------------------------------
565      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
566      !
567      INTEGER, PARAMETER :: nfactmax = 20
568      INTEGER :: nfact ! The no. of factors returned
569      INTEGER :: ierr  ! Error flag
570      INTEGER :: ji
571      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
572      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
573      !!----------------------------------------------------------------------
574      !
575      ierr = 0
576      !
577      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
578      !
579      IF( nfact <= 1 ) THEN
580         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
581         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
582         jpnj = 1
583         jpni = num_pes
584      ELSE
585         ! Search through factors for the pair that are closest in value
586         mindiff = 1000000
587         imin    = 1
588         DO ji = 1, nfact-1, 2
589            idiff = ABS( ifact(ji) - ifact(ji+1) )
590            IF( idiff < mindiff ) THEN
591               mindiff = idiff
592               imin = ji
593            ENDIF
594         END DO
595         jpnj = ifact(imin)
596         jpni = ifact(imin + 1)
597      ENDIF
598      !
599      jpnij = jpni*jpnj
600      !
601   END SUBROUTINE nemo_partition
602
603
604   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
605      !!----------------------------------------------------------------------
606      !!                     ***  ROUTINE factorise  ***
607      !!
608      !! ** Purpose :   return the prime factors of n.
609      !!                knfax factors are returned in array kfax which is of
610      !!                maximum dimension kmaxfax.
611      !! ** Method  :
612      !!----------------------------------------------------------------------
613      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
614      INTEGER                    , INTENT(  out) ::   kerr, knfax
615      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
616      !
617      INTEGER :: ifac, jl, inu
618      INTEGER, PARAMETER :: ntest = 14
619      INTEGER, DIMENSION(ntest) :: ilfax
620      !!----------------------------------------------------------------------
621      !
622      ! lfax contains the set of allowed factors.
623      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
624
625      ! Clear the error flag and initialise output vars
626      kerr = 0
627      kfax = 1
628      knfax = 0
629
630      ! Find the factors of n.
631      IF( kn == 1 )   GOTO 20
632
633      ! nu holds the unfactorised part of the number.
634      ! knfax holds the number of factors found.
635      ! l points to the allowed factor list.
636      ! ifac holds the current factor.
637
638      inu   = kn
639      knfax = 0
640
641      DO jl = ntest, 1, -1
642         !
643         ifac = ilfax(jl)
644         IF( ifac > inu )   CYCLE
645
646         ! Test whether the factor will divide.
647
648         IF( MOD(inu,ifac) == 0 ) THEN
649            !
650            knfax = knfax + 1            ! Add the factor to the list
651            IF( knfax > kmaxfax ) THEN
652               kerr = 6
653               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
654               return
655            ENDIF
656            kfax(knfax) = ifac
657            ! Store the other factor that goes with this one
658            knfax = knfax + 1
659            kfax(knfax) = inu / ifac
660            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
661         ENDIF
662         !
663      END DO
664
665   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
666      !
667   END SUBROUTINE factorise
668
669#if defined key_mpp_mpi
670   SUBROUTINE nemo_northcomms
671      !!======================================================================
672      !!                     ***  ROUTINE  nemo_northcomms  ***
673      !! nemo_northcomms    :  Setup for north fold exchanges with explicit
674      !!                       point-to-point messaging
675      !!=====================================================================
676      !!----------------------------------------------------------------------
677      !!
678      !! ** Purpose :   Initialization of the northern neighbours lists.
679      !!----------------------------------------------------------------------
680      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
681      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
682      !!----------------------------------------------------------------------
683
684      INTEGER  ::   sxM, dxM, sxT, dxT, jn
685      INTEGER  ::   njmppmax
686
687      njmppmax = MAXVAL( njmppt )
688   
689      !initializes the north-fold communication variables
690      isendto(:) = 0
691      nsndto = 0
692
693      !if I am a process in the north
694      IF ( njmpp == njmppmax ) THEN
695          !sxM is the first point (in the global domain) needed to compute the
696          !north-fold for the current process
697          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
698          !dxM is the last point (in the global domain) needed to compute the
699          !north-fold for the current process
700          dxM = jpiglo - nimppt(narea) + 2
701
702          !loop over the other north-fold processes to find the processes
703          !managing the points belonging to the sxT-dxT range
704 
705          DO jn = 1, jpni
706                !sxT is the first point (in the global domain) of the jn
707                !process
708                sxT = nfiimpp(jn, jpnj)
709                !dxT is the last point (in the global domain) of the jn
710                !process
711                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
712                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
713                   nsndto = nsndto + 1
714                     isendto(nsndto) = jn
715                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
716                   nsndto = nsndto + 1
717                   isendto(nsndto) = jn
718                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
719                   nsndto = nsndto + 1
720                   isendto(nsndto) = jn
721                ENDIF
722          END DO
723          nfsloop = 1
724          nfeloop = nlci
725          DO jn = 2,jpni-1
726           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
727              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
728                 nfsloop = nldi
729              ENDIF
730              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
731                 nfeloop = nlei
732              ENDIF
733           ENDIF
734        END DO
735
736      ENDIF
737      l_north_nogather = .TRUE.
738   END SUBROUTINE nemo_northcomms
739
740#else
741   SUBROUTINE nemo_northcomms      ! Dummy routine
742      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
743   END SUBROUTINE nemo_northcomms
744#endif
745   !!======================================================================
746END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.