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

source: branches/2015/dev_r5218_CNRS17_coupling/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 5362

Last change on this file since 5362 was 5352, checked in by smasson, 9 years ago

dev_r5218_CNRS17_coupling: update for fraqsr

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