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_r6409_SIMPLIF_2_usrdef_tools/NEMOGCM/NEMO/OPA_SRC – NEMO

source: branches/2016/dev_r6409_SIMPLIF_2_usrdef_tools/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 6827

Last change on this file since 6827 was 6827, checked in by flavoni, 8 years ago

#1692 - branch SIMPLIF_2_usrdef: commit routines Fortran to create domain_cfg.nc file, to have domain (input) files for new simplification branch. To be moved in TOOLS directory

  • Property svn:keywords set to Id
File size: 29.8 KB
RevLine 
[2496]1MODULE nemogcm
[2442]2   !!======================================================================
[2496]3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
[2442]5   !!======================================================================
[1593]6   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
[3764]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
[1593]10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
[3764]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,
[2104]13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
[1593]14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
[3764]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
[1593]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
[3764]27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
[2236]28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
[3294]29   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
[5836]30   !!            3.4  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) add nemo_northcomms
31   !!             -   ! 2011-11  (C. Harris) decomposition changes for running with CICE
32   !!            3.6  ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening
33   !!             -   ! 2013-06  (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication
34   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
[1593]35   !!----------------------------------------------------------------------
[3]36
37   !!----------------------------------------------------------------------
[6140]38   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
39   !!   nemo_init     : initialization of the NEMO system
40   !!   nemo_ctl      : initialisation of the contol print
41   !!   nemo_closefile: close remaining open files
42   !!   nemo_alloc    : dynamical allocation
43   !!   nemo_partition: calculate MPP domain decomposition
44   !!   factorise     : calculate the factors of the no. of MPI processes
[3]45   !!----------------------------------------------------------------------
[6140]46   USE step_oce       ! module used in the ocean time stepping module (step.F90)
47   USE domcfg         ! domain configuration               (dom_cfg routine)
48   USE mppini         ! shared/distributed memory setting (mpp_init routine)
49   USE domain         ! domain initialization             (dom_init routine)
50   USE phycst         ! physical constant                  (par_cst routine)
51   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
52   USE lib_mpp        ! distributed memory computing
[1412]53#if defined key_iomput
[6140]54   USE xios           ! xIOserver
[1359]55#endif
[6140]56   USE lbcnfd , ONLY  : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges
[268]57
[2715]58   IMPLICIT NONE
[3]59   PRIVATE
60
[2496]61   PUBLIC   nemo_gcm    ! called by model.F90
62   PUBLIC   nemo_init   ! needed by AGRIF
[3764]63   PUBLIC   nemo_alloc  ! needed by TAM
[467]64
[2498]65   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
[1593]66
[3]67   !!----------------------------------------------------------------------
[5836]68   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
[2392]69   !! $Id$
[2329]70   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
[3]71   !!----------------------------------------------------------------------
72CONTAINS
73
[2496]74   SUBROUTINE nemo_gcm
[3]75      !!----------------------------------------------------------------------
[2496]76      !!                     ***  ROUTINE nemo_gcm  ***
[3]77      !!
[3764]78      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
[1593]79      !!              curvilinear mesh on the sphere.
[3]80      !!
81      !! ** Method  : - model general initialization
82      !!              - launch the time-stepping (stp routine)
[1593]83      !!              - finalize the run by closing files and communications
[3]84      !!
[2715]85      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
[1593]86      !!              Madec, 2008, internal report, IPSL.
[3]87      !!----------------------------------------------------------------------
88      INTEGER ::   istp       ! time step index
[389]89      !!----------------------------------------------------------------------
[2382]90      !
[392]91#if defined key_agrif
[1593]92      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
[389]93#endif
94
[1593]95      !                            !-----------------------!
[2496]96      CALL nemo_init               !==  Initialisations  ==!
[1593]97      !                            !-----------------------!
[2715]98#if defined key_agrif
[3680]99      CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
100      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA
[2715]101#endif
[682]102      ! check that all process are still there... If some process have an error,
103      ! they will never enter in step and other processes will wait until the end of the cpu time!
[900]104      IF( lk_mpp )   CALL mpp_max( nstop )
[682]105
[1593]106      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
107
108      !                            !-----------------------!
109      !                            !==  finalize the run  ==!
110      !                            !------------------------!
111      !
112      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
[682]113         WRITE(numout,cform_err)
[3764]114         WRITE(numout,*) nstop, ' error have been found'
[389]115      ENDIF
[1593]116      !
[3294]117#if defined key_agrif
[6140]118      IF( .NOT. Agrif_Root() ) THEN
[6827]119                                CALL Agrif_ParentGrid_To_ChildGrid()
[5536]120         IF( nn_timing == 1 )   CALL timing_finalize
[5836]121                                CALL Agrif_ChildGrid_To_ParentGrid()
[5536]122      ENDIF
[3294]123#endif
124      IF( nn_timing == 1 )   CALL timing_finalize
125      !
[2496]126      CALL nemo_closefile
[4990]127      !
[3769]128#if defined key_iomput
[5836]129      CALL xios_finalize                  ! end mpp communications with xios
[532]130#else
[6827]131      IF( lk_mpp )   CALL mppstop    ! end mpp communications
[532]132#endif
[900]133      !
[2496]134   END SUBROUTINE nemo_gcm
[389]135
136
[2496]137   SUBROUTINE nemo_init
[389]138      !!----------------------------------------------------------------------
[2496]139      !!                     ***  ROUTINE nemo_init  ***
[389]140      !!
[2496]141      !! ** Purpose :   initialization of the NEMO GCM
[389]142      !!----------------------------------------------------------------------
[2715]143      INTEGER ::   ji            ! dummy loop indices
144      INTEGER ::   ilocal_comm   ! local integer
[4147]145      INTEGER ::   ios
[2715]146      CHARACTER(len=80), DIMENSION(16) ::   cltxt
[4990]147      !
148      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
[3294]149         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
[6140]150         &             nn_bench, nn_timing, nn_diacfl
[4147]151      NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
[5118]152         &             jpizoom, jpjzoom, jperio, ln_use_jattr
[3]153      !!----------------------------------------------------------------------
[1593]154      !
[2496]155      cltxt = ''
[5407]156      cxios_context = 'nemo'
[2496]157      !
[4147]158      !                             ! Open reference namelist and configuration namelist files
159      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
160      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
[1593]161      !
[4147]162      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
163      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
[4289]164901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
[4147]165
166      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
167      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
[4289]168902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
[4147]169
[1593]170      !
[4147]171      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
172      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
[4289]173903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
[4147]174
175      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
176      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
[4289]177904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
[4309]178
[4147]179! Force values for AGRIF zoom (cf. agrif_user.F90)
180#if defined key_agrif
181   IF( .NOT. Agrif_Root() ) THEN
182      jpiglo  = nbcellsx + 2 + 2*nbghostcells
183      jpjglo  = nbcellsy + 2 + 2*nbghostcells
184      jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
185      jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
186      jpidta  = jpiglo
187      jpjdta  = jpjglo
188      jpizoom = 1
189      jpjzoom = 1
190      nperio  = 0
191      jperio  = 0
[5118]192      ln_use_jattr = .false.
[4147]193   ENDIF
194#endif
195      !
[1593]196      !                             !--------------------------------------------!
197      !                             !  set communicator & select the local node  !
[4624]198      !                             !  NB: mynode also opens output.namelist.dyn !
199      !                             !      on unit number numond on first proc   !
[1593]200      !                             !--------------------------------------------!
[1412]201#if defined key_iomput
[2200]202      IF( Agrif_Root() ) THEN
[5407]203            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
[2200]204      ENDIF
[5407]205      ! Nodes selection (control print return in cltxt)
206      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
[532]207#else
[4990]208         ilocal_comm = 0
[5407]209         ! Nodes selection (control print return in cltxt)
210         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
[532]211#endif
[2715]212      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
[3]213
[4624]214      lwm = (narea == 1)                                    ! control of output namelists
[2715]215      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
[1579]216
[4624]217      IF(lwm) THEN
218         ! write merged namelists from earlier to output namelist now that the
219         ! file has been opened in call to mynode. nammpp has already been
220         ! written in mynode (if lk_mpp_mpi)
221         WRITE( numond, namctl )
222         WRITE( numond, namcfg )
223      ENDIF
224
[3764]225      ! If dimensions of processor grid weren't specified in the namelist file
[2715]226      ! then we calculate them here now that we have our communicator size
[5836]227      IF( jpni < 1 .OR. jpnj < 1 ) THEN
[2715]228#if   defined key_mpp_mpi
[5836]229         IF( Agrif_Root() )   CALL nemo_partition( mppsize )
[2715]230#else
231         jpni  = 1
232         jpnj  = 1
233         jpnij = jpni*jpnj
234#endif
[5836]235      ENDIF
[2715]236
237      ! Calculate domain dimensions given calculated jpni and jpnj
[5836]238      ! This used to be done in par_oce.F90 when they were parameters rather than variables
[2715]239      IF( Agrif_Root() ) THEN
[3294]240#if defined key_nemocice_decomp
[5836]241         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
242         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
[3294]243#else
[5836]244         jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
245         jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
[3294]246#endif
[5656]247      ENDIF         
[2715]248         jpk = jpkdta                                             ! third dim
[5656]249#if defined key_agrif
[5836]250         ! simple trick to use same vertical grid as parent but different number of levels:
251         ! Save maximum number of levels in jpkdta, then define all vertical grids with this number.
[5656]252         ! Suppress once vertical online interpolation is ok
[5836]253         IF(.NOT.Agrif_Root())   jpkdta = Agrif_Parent( jpkdta )
[5656]254#endif
[2715]255         jpim1 = jpi-1                                            ! inner domain indices
256         jpjm1 = jpj-1                                            !   "           "
257         jpkm1 = jpk-1                                            !   "           "
258         jpij  = jpi*jpj                                          !  jpi x j
259
[1593]260      IF(lwp) THEN                            ! open listing units
261         !
[1581]262         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
[1593]263         !
[1579]264         WRITE(numout,*)
[3294]265         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
[1593]266         WRITE(numout,*) '                       NEMO team'
[1579]267         WRITE(numout,*) '            Ocean General Circulation Model'
[5836]268         WRITE(numout,*) '                  version 3.7  (2015) '
[1579]269         WRITE(numout,*)
270         WRITE(numout,*)
[3764]271         DO ji = 1, SIZE(cltxt)
[1593]272            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
[1579]273         END DO
[1593]274         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
275         !
[473]276      ENDIF
[2715]277
[3764]278      ! Now we know the dimensions of the grid and numout has been set we can
[2715]279      ! allocate arrays
280      CALL nemo_alloc()
281
[2496]282      !                             !-------------------------------!
283      !                             !  NEMO general initialization  !
284      !                             !-------------------------------!
[473]285
[2496]286      CALL nemo_ctl                          ! Control prints & Benchmark
[531]287
[2082]288      !                                      ! Domain decomposition
[1593]289      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
290      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
[3]291      ENDIF
[2382]292      !
[3294]293      IF( nn_timing == 1 )  CALL timing_init
294      !
[2082]295      !                                      ! General initialization
[2027]296                            CALL     phy_cst    ! Physical constants
297                            CALL     eos_init   ! Equation of state
298                            CALL     dom_cfg    ! Domain configuration
299                            CALL     dom_init   ! Domain
300      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
[1593]301      !
[2496]302   END SUBROUTINE nemo_init
[467]303
304
[2496]305   SUBROUTINE nemo_ctl
[467]306      !!----------------------------------------------------------------------
[2496]307      !!                     ***  ROUTINE nemo_ctl  ***
[467]308      !!
[3764]309      !! ** Purpose :   control print setting
[467]310      !!
[2442]311      !! ** Method  : - print namctl information and check some consistencies
[467]312      !!----------------------------------------------------------------------
[2442]313      !
[2496]314      IF(lwp) THEN                  ! control print
[531]315         WRITE(numout,*)
[2496]316         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
[531]317         WRITE(numout,*) '~~~~~~~ '
[1593]318         WRITE(numout,*) '   Namelist namctl'
[1601]319         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
320         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
321         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
322         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
323         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
324         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
325         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
326         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
327         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
[3610]328         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
[531]329      ENDIF
[2442]330      !
[1601]331      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
332      nictls    = nn_ictls
333      nictle    = nn_ictle
334      njctls    = nn_jctls
335      njctle    = nn_jctle
336      isplt     = nn_isplt
337      jsplt     = nn_jsplt
338      nbench    = nn_bench
[4147]339
340      IF(lwp) THEN                  ! control print
341         WRITE(numout,*)
342         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
343         WRITE(numout,*) '~~~~~~~ '
344         WRITE(numout,*) '   Namelist namcfg'
[5836]345         WRITE(numout,*) '      configuration name                               cp_cfg  = ', TRIM(cp_cfg)
346         WRITE(numout,*) '      configuration zoom name                          cp_cfz  = ', TRIM(cp_cfz)
347         WRITE(numout,*) '      configuration resolution                         jp_cfg  = ', jp_cfg
348         WRITE(numout,*) '      1st lateral dimension ( >= jpiglo )              jpidta  = ', jpidta
349         WRITE(numout,*) '      2nd    "         "    ( >= jpjglo )              jpjdta  = ', jpjdta
350         WRITE(numout,*) '      3nd    "         "                               jpkdta  = ', jpkdta
351         WRITE(numout,*) '      1st dimension of global domain in i              jpiglo  = ', jpiglo
352         WRITE(numout,*) '      2nd    -                  -    in j              jpjglo  = ', jpjglo
[4147]353         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
354         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
[5836]355         WRITE(numout,*) '      lateral cond. type (between 0 and 6)             jperio  = ', jperio   
[5118]356         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
[4147]357      ENDIF
[2442]358      !                             ! Parameter control
[1593]359      !
360      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
[3294]361         IF( lk_mpp .AND. jpnij > 1 ) THEN
[2496]362            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
[531]363         ELSE
364            IF( isplt == 1 .AND. jsplt == 1  ) THEN
[1593]365               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
366                  &           ' - the print control will be done over the whole domain' )
[531]367            ENDIF
[1593]368            ijsplt = isplt * jsplt            ! total number of processors ijsplt
[531]369         ENDIF
370         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
371         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
[1593]372         !
373         !                              ! indices used for the SUM control
374         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
[3764]375            lsp_area = .FALSE.
[1593]376         ELSE                                             ! print control done over a specific  area
[531]377            lsp_area = .TRUE.
378            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
379               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
380               nictls = 1
381            ENDIF
382            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
383               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
384               nictle = jpiglo
385            ENDIF
386            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
387               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
388               njctls = 1
389            ENDIF
390            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
391               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
392               njctle = jpjglo
393            ENDIF
[1593]394         ENDIF
395      ENDIF
[2442]396      !
[3764]397      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
398         &                                               'f2003 standard. '                              ,  &
399         &                                               'Compile with key_nosignedzero enabled' )
400      !
[2496]401   END SUBROUTINE nemo_ctl
[467]402
403
[2496]404   SUBROUTINE nemo_closefile
[467]405      !!----------------------------------------------------------------------
[2496]406      !!                     ***  ROUTINE nemo_closefile  ***
[467]407      !!
408      !! ** Purpose :   Close the files
409      !!----------------------------------------------------------------------
[1593]410      !
411      IF( lk_mpp )   CALL mppsync
412      !
[1685]413      CALL iom_close                                 ! close all input/output files managed by iom_*
[1593]414      !
[4147]415      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
416      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
417      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
418      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
[4624]419      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
[4147]420      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
421      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
[4624]422      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
[4147]423      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
424      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
425      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
426      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
427      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
[1593]428      !
[2442]429      numout = 6                                     ! redefine numout in case it is used after this point...
430      !
[2496]431   END SUBROUTINE nemo_closefile
[467]432
[2715]433
434   SUBROUTINE nemo_alloc
435      !!----------------------------------------------------------------------
436      !!                     ***  ROUTINE nemo_alloc  ***
437      !!
438      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
439      !!
440      !! ** Method  :
441      !!----------------------------------------------------------------------
442      USE dom_oce   , ONLY: dom_oce_alloc
443      !
444      INTEGER :: ierr
445      !!----------------------------------------------------------------------
446      !
[3764]447      ierr =        oce_alloc       ()          ! ocean
[2715]448      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
449      !
450      IF( lk_mpp    )   CALL mpp_sum( ierr )
451      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
452      !
453   END SUBROUTINE nemo_alloc
454
455
456   SUBROUTINE nemo_partition( num_pes )
457      !!----------------------------------------------------------------------
458      !!                 ***  ROUTINE nemo_partition  ***
459      !!
[3764]460      !! ** Purpose :
[2715]461      !!
462      !! ** Method  :
463      !!----------------------------------------------------------------------
[4990]464      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
[2715]465      !
466      INTEGER, PARAMETER :: nfactmax = 20
467      INTEGER :: nfact ! The no. of factors returned
468      INTEGER :: ierr  ! Error flag
469      INTEGER :: ji
470      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
471      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
472      !!----------------------------------------------------------------------
[4990]473      !
[2715]474      ierr = 0
[4990]475      !
[2715]476      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
[4990]477      !
[2715]478      IF( nfact <= 1 ) THEN
479         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
480         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
481         jpnj = 1
482         jpni = num_pes
483      ELSE
484         ! Search through factors for the pair that are closest in value
485         mindiff = 1000000
486         imin    = 1
487         DO ji = 1, nfact-1, 2
488            idiff = ABS( ifact(ji) - ifact(ji+1) )
489            IF( idiff < mindiff ) THEN
490               mindiff = idiff
491               imin = ji
492            ENDIF
493         END DO
494         jpnj = ifact(imin)
495         jpni = ifact(imin + 1)
496      ENDIF
497      !
498      jpnij = jpni*jpnj
499      !
500   END SUBROUTINE nemo_partition
501
502
503   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
504      !!----------------------------------------------------------------------
505      !!                     ***  ROUTINE factorise  ***
506      !!
507      !! ** Purpose :   return the prime factors of n.
[3764]508      !!                knfax factors are returned in array kfax which is of
[2715]509      !!                maximum dimension kmaxfax.
510      !! ** Method  :
511      !!----------------------------------------------------------------------
512      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
513      INTEGER                    , INTENT(  out) ::   kerr, knfax
514      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
515      !
516      INTEGER :: ifac, jl, inu
517      INTEGER, PARAMETER :: ntest = 14
[5836]518      INTEGER, DIMENSION(ntest) ::   ilfax
[5656]519      !!----------------------------------------------------------------------
[5836]520      !
[2715]521      ! lfax contains the set of allowed factors.
[5656]522      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
[5836]523      !
[2715]524      ! Clear the error flag and initialise output vars
[5836]525      kerr  = 0
526      kfax  = 1
[2715]527      knfax = 0
[5836]528      !
[2715]529      ! Find the factors of n.
530      IF( kn == 1 )   GOTO 20
531
532      ! nu holds the unfactorised part of the number.
533      ! knfax holds the number of factors found.
534      ! l points to the allowed factor list.
535      ! ifac holds the current factor.
[5836]536      !
[2715]537      inu   = kn
538      knfax = 0
[5836]539      !
[2715]540      DO jl = ntest, 1, -1
541         !
542         ifac = ilfax(jl)
543         IF( ifac > inu )   CYCLE
544
545         ! Test whether the factor will divide.
546
547         IF( MOD(inu,ifac) == 0 ) THEN
548            !
549            knfax = knfax + 1            ! Add the factor to the list
550            IF( knfax > kmaxfax ) THEN
551               kerr = 6
552               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
553               return
554            ENDIF
555            kfax(knfax) = ifac
556            ! Store the other factor that goes with this one
557            knfax = knfax + 1
558            kfax(knfax) = inu / ifac
559            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
560         ENDIF
561         !
562      END DO
[5836]563      !
[2715]564   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
565      !
566   END SUBROUTINE factorise
567
[3294]568#if defined key_mpp_mpi
[4990]569
[3294]570   SUBROUTINE nemo_northcomms
[5836]571      !!----------------------------------------------------------------------
[3294]572      !!                     ***  ROUTINE  nemo_northcomms  ***
[5836]573      !! ** Purpose :   Setup for north fold exchanges with explicit
574      !!                point-to-point messaging
[3764]575      !!
[5836]576      !! ** Method :   Initialization of the northern neighbours lists.
[3294]577      !!----------------------------------------------------------------------
[3764]578      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
[4230]579      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
[3294]580      !!----------------------------------------------------------------------
[4230]581      INTEGER  ::   sxM, dxM, sxT, dxT, jn
582      INTEGER  ::   njmppmax
[5836]583      !!----------------------------------------------------------------------
584      !
[4230]585      njmppmax = MAXVAL( njmppt )
[5836]586      !
[4230]587      !initializes the north-fold communication variables
588      isendto(:) = 0
[5836]589      nsndto     = 0
590      !
[4230]591      !if I am a process in the north
592      IF ( njmpp == njmppmax ) THEN
593          !sxM is the first point (in the global domain) needed to compute the
594          !north-fold for the current process
595          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
596          !dxM is the last point (in the global domain) needed to compute the
597          !north-fold for the current process
598          dxM = jpiglo - nimppt(narea) + 2
[3294]599
[4230]600          !loop over the other north-fold processes to find the processes
601          !managing the points belonging to the sxT-dxT range
[4671]602 
603          DO jn = 1, jpni
[4230]604                !sxT is the first point (in the global domain) of the jn
605                !process
[4671]606                sxT = nfiimpp(jn, jpnj)
[4230]607                !dxT is the last point (in the global domain) of the jn
608                !process
[4671]609                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
[4230]610                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
611                   nsndto = nsndto + 1
[4671]612                     isendto(nsndto) = jn
[4645]613                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
[4230]614                   nsndto = nsndto + 1
[4671]615                     isendto(nsndto) = jn
[4230]616                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
617                   nsndto = nsndto + 1
[4671]618                     isendto(nsndto) = jn
[4230]619                END IF
620          END DO
[4671]621          nfsloop = 1
622          nfeloop = nlci
623          DO jn = 2,jpni-1
624           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
625              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
626                 nfsloop = nldi
627              ENDIF
628              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
629                 nfeloop = nlei
630              ENDIF
631           ENDIF
632        END DO
633
[3294]634      ENDIF
[4230]635      l_north_nogather = .TRUE.
[3294]636   END SUBROUTINE nemo_northcomms
[5836]637
[3294]638#else
639   SUBROUTINE nemo_northcomms      ! Dummy routine
640      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
641   END SUBROUTINE nemo_northcomms
642#endif
[4990]643
[3]644   !!======================================================================
[2496]645END MODULE nemogcm
[4354]646
Note: See TracBrowser for help on using the repository browser.