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_merge_2016/NEMOGCM/NEMO/SAS_SRC – NEMO

source: branches/2016/dev_merge_2016/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 7412

Last change on this file since 7412 was 7412, checked in by lovato, 8 years ago

Merge dev_NOC_CMCC_merge_2016 into branch

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