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

source: branches/2011/dev_r2787_NOCS_NEPTUNE/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 2795

Last change on this file since 2795 was 2795, checked in by acc, 13 years ago

First set of changes for simplified laplacian Neptune, see ticket #843

  • Property svn:keywords set to Id
File size: 29.1 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)
8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
[2104]9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
[1593]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,
[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)
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
[2236]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
[2715]29   !!            4.0  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
[1593]30   !!----------------------------------------------------------------------
[3]31
32   !!----------------------------------------------------------------------
[2496]33   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
34   !!   nemo_init      : initialization of the NEMO system
35   !!   nemo_ctl       : initialisation of the contol print
36   !!   nemo_closefile : close remaining open files
[2715]37   !!   nemo_alloc     : dynamical allocation
38   !!   nemo_partition : calculate MPP domain decomposition
39   !!   factorise      : calculate the factors of the no. of MPI processes
[3]40   !!----------------------------------------------------------------------
[2382]41   USE step_oce        ! module used in the ocean time stepping module
[888]42   USE sbc_oce         ! surface boundary condition: ocean
[2392]43   USE cla             ! cross land advection               (tra_cla routine)
[3]44   USE domcfg          ! domain configuration               (dom_cfg routine)
45   USE mppini          ! shared/distributed memory setting (mpp_init routine)
46   USE domain          ! domain initialization             (dom_init routine)
47   USE obcini          ! open boundary cond. initialization (obc_ini routine)
[911]48   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
[3]49   USE istate          ! initial state setting          (istate_init routine)
50   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
51   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
[2392]52   USE zdfini          ! vertical physics setting          (zdf_init routine)
[3]53   USE phycst          ! physical constant                  (par_cst routine)
[2236]54   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
55   USE asminc          ! assimilation increments       (asm_inc_init routine)
56   USE asmtrj          ! writing out state trajectory
57   USE sshwzv          ! vertical velocity used in asm
58   USE diaptr          ! poleward transports           (dia_ptr_init routine)
59   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
[2496]60   USE step            ! NEMO time-stepping                 (stp     routine)
[532]61#if defined key_oasis3
[1359]62   USE cpl_oasis3      ! OASIS3 coupling
[599]63#elif defined key_oasis4
[1359]64   USE cpl_oasis4      ! OASIS4 coupling (not working)
[532]65#endif
[900]66   USE c1d             ! 1D configuration
67   USE step_c1d        ! Time stepping loop for the 1D configuration
[2795]68   USE dynnept         ! simplified form of Neptune effect
[1594]69#if defined key_top
[1593]70   USE trcini          ! passive tracer initialisation
[1594]71#endif
[1593]72   USE lib_mpp         ! distributed memory computing
[1412]73#if defined key_iomput
74   USE mod_ioclient
[1359]75#endif
[268]76
[2715]77   IMPLICIT NONE
[3]78   PRIVATE
79
[2496]80   PUBLIC   nemo_gcm    ! called by model.F90
81   PUBLIC   nemo_init   ! needed by AGRIF
[467]82
[2498]83   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
[1593]84
[3]85   !!----------------------------------------------------------------------
[2715]86   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
[2392]87   !! $Id$
[2329]88   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
[3]89   !!----------------------------------------------------------------------
90CONTAINS
91
[2496]92   SUBROUTINE nemo_gcm
[3]93      !!----------------------------------------------------------------------
[2496]94      !!                     ***  ROUTINE nemo_gcm  ***
[3]95      !!
[2496]96      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
[1593]97      !!              curvilinear mesh on the sphere.
[3]98      !!
99      !! ** Method  : - model general initialization
100      !!              - launch the time-stepping (stp routine)
[1593]101      !!              - finalize the run by closing files and communications
[3]102      !!
[2715]103      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
[1593]104      !!              Madec, 2008, internal report, IPSL.
[3]105      !!----------------------------------------------------------------------
106      INTEGER ::   istp       ! time step index
[389]107      !!----------------------------------------------------------------------
[2382]108      !
[392]109#if defined key_agrif
[1593]110      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
[389]111#endif
112
[1593]113      !                            !-----------------------!
[2496]114      CALL nemo_init               !==  Initialisations  ==!
[1593]115      !                            !-----------------------!
[2715]116#if defined key_agrif
117      CALL Agrif_Declare_Var       ! AGRIF: set the meshes
118# if defined key_top
119      CALL Agrif_Declare_Var_Top   ! AGRIF: set the meshes
120# endif
121#endif
[682]122      ! check that all process are still there... If some process have an error,
123      ! they will never enter in step and other processes will wait until the end of the cpu time!
[900]124      IF( lk_mpp )   CALL mpp_max( nstop )
[682]125
[1593]126      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
127
128      !                            !-----------------------!
129      !                            !==   time stepping   ==!
130      !                            !-----------------------!
[900]131      istp = nit000
[2236]132#if defined key_c1d
[389]133         DO WHILE ( istp <= nitend .AND. nstop == 0 )
[900]134            CALL stp_c1d( istp )
[389]135            istp = istp + 1
136         END DO
[2236]137#else
138          IF( lk_asminc ) THEN
139             IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 )    ! Output background fields
140             IF( ln_trjwri ) CALL asm_trj_wri( nit000 - 1 )    ! Output trajectory fields
141             IF( ln_asmdin ) THEN                        ! Direct initialization
142                IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 )    ! Tracers
143                IF( ln_dyninc ) THEN
144                   CALL dyn_asm_inc( nit000 - 1 )    ! Dynamics
145                   IF ( ln_asmdin ) CALL ssh_wzv ( nit000 - 1 )      ! update vertical velocity
146                ENDIF
147                IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 )    ! SSH
148             ENDIF
149          ENDIF
150       
[389]151         DO WHILE ( istp <= nitend .AND. nstop == 0 )
[392]152#if defined key_agrif
[1593]153            CALL Agrif_Step( stp )           ! AGRIF: time stepping
[389]154#else
[1593]155            CALL stp( istp )                 ! standard time stepping
[389]156#endif
157            istp = istp + 1
[900]158            IF( lk_mpp )   CALL mpp_max( nstop )
[389]159         END DO
[2236]160#endif
161
162      IF( lk_diaobs ) CALL dia_obs_wri
[1593]163       
164      !                            !------------------------!
165      !                            !==  finalize the run  ==!
166      !                            !------------------------!
167      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
168      !
169      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
[682]170         WRITE(numout,cform_err)
171         WRITE(numout,*) nstop, ' error have been found' 
[389]172      ENDIF
[1593]173      !
[2496]174      CALL nemo_closefile
[532]175#if defined key_oasis3 || defined key_oasis4
[1976]176      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
[532]177#else
[1593]178      IF( lk_mpp )   CALL mppstop       ! end mpp communications
[532]179#endif
[900]180      !
[2496]181   END SUBROUTINE nemo_gcm
[389]182
183
[2496]184   SUBROUTINE nemo_init
[389]185      !!----------------------------------------------------------------------
[2496]186      !!                     ***  ROUTINE nemo_init  ***
[389]187      !!
[2496]188      !! ** Purpose :   initialization of the NEMO GCM
[389]189      !!----------------------------------------------------------------------
[2715]190      INTEGER ::   ji            ! dummy loop indices
191      INTEGER ::   ilocal_comm   ! local integer
192      CHARACTER(len=80), DIMENSION(16) ::   cltxt
[1593]193      !!
[1601]194      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
[1976]195         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle, nn_bench
[3]196      !!----------------------------------------------------------------------
[1593]197      !
[2496]198      cltxt = ''
199      !
[1593]200      !                             ! open Namelist file
[1581]201      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
[1593]202      !
203      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
204      !
205      !                             !--------------------------------------------!
206      !                             !  set communicator & select the local node  !
207      !                             !--------------------------------------------!
[1412]208#if defined key_iomput
[2200]209      IF( Agrif_Root() ) THEN
[1412]210# if defined key_oasis3 || defined key_oasis4
[2715]211         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
[1412]212# endif
[2715]213         CALL  init_ioclient( ilocal_comm )                 ! exchange io_server nemo local communicator with the io_server
[2200]214      ENDIF
[2715]215      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
[532]216#else
[1412]217# if defined key_oasis3 || defined key_oasis4
[2236]218      IF( Agrif_Root() ) THEN
[2715]219         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
[2236]220      ENDIF
[2715]221      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
[1412]222# else
[2082]223      ilocal_comm = 0
[2715]224      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt)
[1412]225# endif
[532]226#endif
[2715]227      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
[3]228
[2715]229      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
[1579]230
[2715]231      ! If dimensions of processor grid weren't specified in the namelist file
232      ! then we calculate them here now that we have our communicator size
233      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
234#if   defined key_mpp_mpi
235         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
236#else
237         jpni  = 1
238         jpnj  = 1
239         jpnij = jpni*jpnj
240#endif
241      END IF
242
243      ! Calculate domain dimensions given calculated jpni and jpnj
244      ! This used to be done in par_oce.F90 when they were parameters rather
245      ! than variables
246      IF( Agrif_Root() ) THEN
247         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
248         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
249         jpk = jpkdta                                             ! third dim
250         jpim1 = jpi-1                                            ! inner domain indices
251         jpjm1 = jpj-1                                            !   "           "
252         jpkm1 = jpk-1                                            !   "           "
253         jpij  = jpi*jpj                                          !  jpi x j
254      ENDIF
255
[1593]256      IF(lwp) THEN                            ! open listing units
257         !
[1581]258         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
[1593]259         !
[1579]260         WRITE(numout,*)
[1593]261         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
262         WRITE(numout,*) '                       NEMO team'
[1579]263         WRITE(numout,*) '            Ocean General Circulation Model'
[2104]264         WRITE(numout,*) '                  version 3.3  (2010) '
[1579]265         WRITE(numout,*)
266         WRITE(numout,*)
[1593]267         DO ji = 1, SIZE(cltxt) 
268            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
[1579]269         END DO
[1593]270         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
271         !
[473]272      ENDIF
[2715]273
274      ! Now we know the dimensions of the grid and numout has been set we can
275      ! allocate arrays
276      CALL nemo_alloc()
277
[2496]278      !                             !-------------------------------!
279      !                             !  NEMO general initialization  !
280      !                             !-------------------------------!
[473]281
[2496]282      CALL nemo_ctl                          ! Control prints & Benchmark
[531]283
[2082]284      !                                      ! Domain decomposition
[1593]285      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
286      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
[3]287      ENDIF
[2382]288      !
[2082]289      !                                      ! General initialization
[2027]290                            CALL     phy_cst    ! Physical constants
291                            CALL     eos_init   ! Equation of state
292                            CALL     dom_cfg    ! Domain configuration
293                            CALL     dom_init   ! Domain
[413]294
[2027]295      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
296
297      IF( lk_obc        )   CALL     obc_init   ! Open boundaries
298      IF( lk_bdy        )   CALL     bdy_init   ! Unstructured open boundaries
299
[2795]300                            CALL flush(numout)
301                            CALL dyn_nept_init  ! simplified form of Neptune effect
302                            CALL flush(numout)
303
[2027]304                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
305
[3]306      !                                     ! Ocean physics
[2104]307                            CALL     sbc_init   ! Forcings : surface module
[2082]308      !                                         ! Vertical physics
309                            CALL     zdf_init      ! namelist read
310                            CALL zdf_bfr_init      ! bottom friction
311      IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
[2329]312      IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
313      IF( lk_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
314      IF( lk_zdfkpp     )   CALL zdf_kpp_init      ! KPP closure scheme
[2082]315      IF( lk_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
[2027]316      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   & 
[2082]317         &                  CALL zdf_ddm_init      ! double diffusive mixing
318      !                                         ! Lateral physics
319                            CALL ldf_tra_init      ! Lateral ocean tracer physics
320                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
[2392]321      IF( lk_ldfslp     )   CALL ldf_slp_init      ! slope of lateral mixing
[2082]322
[2027]323      !                                     ! Active tracers
324                            CALL tra_qsr_init   ! penetrative solar radiation qsr
[2325]325                            CALL tra_bbc_init   ! bottom heat flux
[2027]326      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
327      IF( lk_tradmp     )   CALL tra_dmp_init   ! internal damping trends
328                            CALL tra_adv_init   ! horizontal & vertical advection
329                            CALL tra_ldf_init   ! lateral mixing
330                            CALL tra_zdf_init   ! vertical mixing and after tracer fields
331
332      !                                     ! Dynamics
333                            CALL dyn_adv_init   ! advection (vector or flux form)
[2104]334                            CALL dyn_vor_init   ! vorticity term including Coriolis
[2027]335                            CALL dyn_ldf_init   ! lateral mixing
[2104]336                            CALL dyn_hpg_init   ! horizontal gradient of Hydrostatic pressure
[2027]337                            CALL dyn_zdf_init   ! vertical diffusion
338                            CALL dyn_spg_init   ! surface pressure gradient
[2392]339                           
340      !                                     ! Misc. options
341      IF( nn_cla == 1   )   CALL cla_init       ! Cross Land Advection
342     
[1594]343#if defined key_top
[2027]344      !                                     ! Passive tracers
[2082]345                            CALL     trc_init
[1594]346#endif
[2382]347      !                                     ! Diagnostics
[2027]348                            CALL     iom_init   ! iom_put initialization
[2392]349      IF( lk_floats     )   CALL     flo_init   ! drifting Floats
350      IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
[2027]351                            CALL dia_ptr_init   ! Poleward TRansports initialization
[2148]352                            CALL dia_hsb_init   ! heat content, salt content and volume budgets
[2027]353                            CALL trd_mod_init   ! Mixed-layer/Vorticity/Integral constraints trends
[2392]354      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
[2382]355                            CALL dia_obs_init            ! Initialize observational data
356                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
[2236]357      ENDIF     
[2382]358      !                                     ! Assimilation increments
[2392]359      IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
[2382]360      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
[1593]361      !
[2496]362   END SUBROUTINE nemo_init
[467]363
364
[2496]365   SUBROUTINE nemo_ctl
[467]366      !!----------------------------------------------------------------------
[2496]367      !!                     ***  ROUTINE nemo_ctl  ***
[467]368      !!
[2442]369      !! ** Purpose :   control print setting
[467]370      !!
[2442]371      !! ** Method  : - print namctl information and check some consistencies
[467]372      !!----------------------------------------------------------------------
[2442]373      !
[2496]374      IF(lwp) THEN                  ! control print
[531]375         WRITE(numout,*)
[2496]376         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
[531]377         WRITE(numout,*) '~~~~~~~ '
[1593]378         WRITE(numout,*) '   Namelist namctl'
[1601]379         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
380         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
381         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
382         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
383         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
384         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
385         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
386         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
387         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
[531]388      ENDIF
[2442]389      !
[1601]390      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
391      nictls    = nn_ictls
392      nictle    = nn_ictle
393      njctls    = nn_jctls
394      njctle    = nn_jctle
395      isplt     = nn_isplt
396      jsplt     = nn_jsplt
397      nbench    = nn_bench
[2442]398      !                             ! Parameter control
[1593]399      !
400      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
401         IF( lk_mpp ) THEN
[2496]402            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
[531]403         ELSE
404            IF( isplt == 1 .AND. jsplt == 1  ) THEN
[1593]405               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
406                  &           ' - the print control will be done over the whole domain' )
[531]407            ENDIF
[1593]408            ijsplt = isplt * jsplt            ! total number of processors ijsplt
[531]409         ENDIF
410         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
411         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
[1593]412         !
413         !                              ! indices used for the SUM control
414         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
415            lsp_area = .FALSE.                       
416         ELSE                                             ! print control done over a specific  area
[531]417            lsp_area = .TRUE.
418            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
419               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
420               nictls = 1
421            ENDIF
422            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
423               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
424               nictle = jpiglo
425            ENDIF
426            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
427               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
428               njctls = 1
429            ENDIF
430            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
431               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
432               njctle = jpjglo
433            ENDIF
[1593]434         ENDIF
435      ENDIF
[2442]436      !
437      IF( nbench == 1 ) THEN              ! Benchmark
[531]438         SELECT CASE ( cp_cfg )
[1593]439         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
440         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
441            &                                 ' key_gyre must be used or set nbench = 0' )
[531]442         END SELECT
443      ENDIF
[1593]444      !
[2496]445      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
446         &                                               'with the IOM Input/Output manager. '         ,   &
[2442]447         &                                               'Compile with key_iomput enabled' )
[2409]448      !
[2496]449   END SUBROUTINE nemo_ctl
[467]450
451
[2496]452   SUBROUTINE nemo_closefile
[467]453      !!----------------------------------------------------------------------
[2496]454      !!                     ***  ROUTINE nemo_closefile  ***
[467]455      !!
456      !! ** Purpose :   Close the files
457      !!----------------------------------------------------------------------
[1593]458      !
459      IF( lk_mpp )   CALL mppsync
460      !
[1685]461      CALL iom_close                                 ! close all input/output files managed by iom_*
[1593]462      !
[1685]463      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
464      IF( numsol     /= -1 )   CLOSE( numsol     )   ! solver file
465      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
466      IF( numnam_ice /= -1 )   CLOSE( numnam_ice )   ! ice namelist
467      IF( numevo_ice /= -1 )   CLOSE( numevo_ice )   ! ice variables (temp. evolution)
468      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
[1593]469      !
[2442]470      numout = 6                                     ! redefine numout in case it is used after this point...
471      !
[2496]472   END SUBROUTINE nemo_closefile
[467]473
[2715]474
475   SUBROUTINE nemo_alloc
476      !!----------------------------------------------------------------------
477      !!                     ***  ROUTINE nemo_alloc  ***
478      !!
479      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
480      !!
481      !! ** Method  :
482      !!----------------------------------------------------------------------
483      USE diawri    , ONLY: dia_wri_alloc
484      USE dom_oce   , ONLY: dom_oce_alloc
485      USE ldfdyn_oce, ONLY: ldfdyn_oce_alloc
486      USE ldftra_oce, ONLY: ldftra_oce_alloc
487      USE trc_oce   , ONLY: trc_oce_alloc
488      USE wrk_nemo  , ONLY: wrk_alloc
489      !
490      INTEGER :: ierr
491      !!----------------------------------------------------------------------
492      !
493      ierr =        oce_alloc       ()          ! ocean
494      ierr = ierr + dia_wri_alloc   ()
495      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
496      ierr = ierr + ldfdyn_oce_alloc()          ! ocean lateral  physics : dynamics
497      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
498      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
499      !
500      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
501      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
502      !
503      ierr = ierr + wrk_alloc(numout, lwp)      ! workspace
504      !
505      IF( lk_mpp    )   CALL mpp_sum( ierr )
506      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
507      !
508   END SUBROUTINE nemo_alloc
509
510
511   SUBROUTINE nemo_partition( num_pes )
512      !!----------------------------------------------------------------------
513      !!                 ***  ROUTINE nemo_partition  ***
514      !!
515      !! ** Purpose :   
516      !!
517      !! ** Method  :
518      !!----------------------------------------------------------------------
519      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
520      !
521      INTEGER, PARAMETER :: nfactmax = 20
522      INTEGER :: nfact ! The no. of factors returned
523      INTEGER :: ierr  ! Error flag
524      INTEGER :: ji
525      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
526      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
527      !!----------------------------------------------------------------------
528
529      ierr = 0
530
531      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
532
533      IF( nfact <= 1 ) THEN
534         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
535         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
536         jpnj = 1
537         jpni = num_pes
538      ELSE
539         ! Search through factors for the pair that are closest in value
540         mindiff = 1000000
541         imin    = 1
542         DO ji = 1, nfact-1, 2
543            idiff = ABS( ifact(ji) - ifact(ji+1) )
544            IF( idiff < mindiff ) THEN
545               mindiff = idiff
546               imin = ji
547            ENDIF
548         END DO
549         jpnj = ifact(imin)
550         jpni = ifact(imin + 1)
551      ENDIF
552      !
553      jpnij = jpni*jpnj
554      !
555   END SUBROUTINE nemo_partition
556
557
558   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
559      !!----------------------------------------------------------------------
560      !!                     ***  ROUTINE factorise  ***
561      !!
562      !! ** Purpose :   return the prime factors of n.
563      !!                knfax factors are returned in array kfax which is of
564      !!                maximum dimension kmaxfax.
565      !! ** Method  :
566      !!----------------------------------------------------------------------
567      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
568      INTEGER                    , INTENT(  out) ::   kerr, knfax
569      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
570      !
571      INTEGER :: ifac, jl, inu
572      INTEGER, PARAMETER :: ntest = 14
573      INTEGER :: ilfax(ntest)
574
575      ! lfax contains the set of allowed factors.
576      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
577         &                            128,   64,   32,   16,    8,   4,   2  /
578      !!----------------------------------------------------------------------
579
580      ! Clear the error flag and initialise output vars
581      kerr = 0
582      kfax = 1
583      knfax = 0
584
585      ! Find the factors of n.
586      IF( kn == 1 )   GOTO 20
587
588      ! nu holds the unfactorised part of the number.
589      ! knfax holds the number of factors found.
590      ! l points to the allowed factor list.
591      ! ifac holds the current factor.
592
593      inu   = kn
594      knfax = 0
595
596      DO jl = ntest, 1, -1
597         !
598         ifac = ilfax(jl)
599         IF( ifac > inu )   CYCLE
600
601         ! Test whether the factor will divide.
602
603         IF( MOD(inu,ifac) == 0 ) THEN
604            !
605            knfax = knfax + 1            ! Add the factor to the list
606            IF( knfax > kmaxfax ) THEN
607               kerr = 6
608               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
609               return
610            ENDIF
611            kfax(knfax) = ifac
612            ! Store the other factor that goes with this one
613            knfax = knfax + 1
614            kfax(knfax) = inu / ifac
615            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
616         ENDIF
617         !
618      END DO
619
620   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
621      !
622   END SUBROUTINE factorise
623
[3]624   !!======================================================================
[2496]625END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.