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

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

dev_r5218_CNRS17_coupling: bugfix in sas

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