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

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

LIM3 and Agrif compatibility

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