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

source: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 2618

Last change on this file since 2618 was 2618, checked in by gm, 13 years ago

dynamic mem: #785 ; move dyn allocation from nemogcm to module when possible (continuation)

  • Property svn:keywords set to Id
File size: 33.1 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   !!            4.0  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!----------------------------------------------------------------------
31
32   !!----------------------------------------------------------------------
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
37   !!   nemo_alloc     : dynamical allocation
38   !!   nemo_partition : ???
39   !!   nemo_partition : ???
40   !!   factorise      : ???
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 mppini          ! shared/distributed memory setting (mpp_init routine)
47   USE domain          ! domain initialization             (dom_init routine)
48   USE obcini          ! open boundary cond. initialization (obc_ini routine)
49   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
50   USE istate          ! initial state setting          (istate_init routine)
51   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
52   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
53   USE zdfini          ! vertical physics setting          (zdf_init routine)
54   USE phycst          ! physical constant                  (par_cst routine)
55   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
56   USE asminc          ! assimilation increments       (asm_inc_init routine)
57   USE asmtrj          ! writing out state trajectory
58   USE sshwzv          ! vertical velocity used in asm
59   USE diaptr          ! poleward transports           (dia_ptr_init routine)
60   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
61   USE step            ! NEMO time-stepping                 (stp     routine)
62#if defined key_oasis3
63   USE cpl_oasis3      ! OASIS3 coupling
64#elif defined key_oasis4
65   USE cpl_oasis4      ! OASIS4 coupling (not working)
66#endif
67   USE c1d             ! 1D configuration
68   USE step_c1d        ! Time stepping loop for the 1D configuration
69#if defined key_top
70   USE trcini          ! passive tracer initialisation
71#endif
72   USE lib_mpp         ! distributed memory computing
73#if defined key_iomput
74   USE mod_ioclient
75#endif
76
77   IMPLICIT NONE
78   PRIVATE
79
80   PUBLIC   nemo_gcm    ! called by model.F90
81   PUBLIC   nemo_init   ! needed by AGRIF
82
83   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
84
85   !!----------------------------------------------------------------------
86   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
87   !! $Id$
88   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
89   !!----------------------------------------------------------------------
90CONTAINS
91
92   SUBROUTINE nemo_gcm
93      !!----------------------------------------------------------------------
94      !!                     ***  ROUTINE nemo_gcm  ***
95      !!
96      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
97      !!              curvilinear mesh on the sphere.
98      !!
99      !! ** Method  : - model general initialization
100      !!              - launch the time-stepping (stp routine)
101      !!              - finalize the run by closing files and communications
102      !!
103      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
104      !!              Madec, 2008, internal report, IPSL.
105      !!----------------------------------------------------------------------
106      INTEGER ::   istp       ! time step index
107      !!----------------------------------------------------------------------
108      !
109#if defined key_agrif
110      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
111#endif
112
113      !                            !-----------------------!
114      CALL nemo_init               !==  Initialisations  ==!
115      !                            !-----------------------!
116
117      ! check that all process are still there... If some process have an error,
118      ! they will never enter in step and other processes will wait until the end of the cpu time!
119      IF( lk_mpp )   CALL mpp_max( nstop )
120
121      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
122
123      !                            !-----------------------!
124      !                            !==   time stepping   ==!
125      !                            !-----------------------!
126      istp = nit000
127#if defined key_c1d
128         DO WHILE ( istp <= nitend .AND. nstop == 0 )
129            CALL stp_c1d( istp )
130            istp = istp + 1
131         END DO
132#else
133          IF( lk_asminc ) THEN
134             IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 )    ! Output background fields
135             IF( ln_trjwri ) CALL asm_trj_wri( nit000 - 1 )    ! Output trajectory fields
136             IF( ln_asmdin ) THEN                        ! Direct initialization
137                IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 )    ! Tracers
138                IF( ln_dyninc ) THEN
139                   CALL dyn_asm_inc( nit000 - 1 )    ! Dynamics
140                   IF ( ln_asmdin ) CALL ssh_wzv ( nit000 - 1 )      ! update vertical velocity
141                ENDIF
142                IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 )    ! SSH
143             ENDIF
144          ENDIF
145       
146         DO WHILE ( istp <= nitend .AND. nstop == 0 )
147#if defined key_agrif
148            CALL Agrif_Step( stp )           ! AGRIF: time stepping
149#else
150            CALL stp( istp )                 ! standard time stepping
151#endif
152            istp = istp + 1
153            IF( lk_mpp )   CALL mpp_max( nstop )
154         END DO
155#endif
156
157      IF( lk_diaobs ) CALL dia_obs_wri
158       
159      !                            !------------------------!
160      !                            !==  finalize the run  ==!
161      !                            !------------------------!
162      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
163      !
164      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
165         WRITE(numout,cform_err)
166         WRITE(numout,*) nstop, ' error have been found' 
167      ENDIF
168      !
169      CALL nemo_closefile
170#if defined key_oasis3 || defined key_oasis4
171      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
172#else
173      IF( lk_mpp )   CALL mppstop       ! end mpp communications
174#endif
175      !
176   END SUBROUTINE nemo_gcm
177
178
179   SUBROUTINE nemo_init
180      !!----------------------------------------------------------------------
181      !!                     ***  ROUTINE nemo_init  ***
182      !!
183      !! ** Purpose :   initialization of the NEMO GCM
184      !!----------------------------------------------------------------------
185      INTEGER ::   ji            ! dummy loop indices
186      INTEGER ::   ilocal_comm   ! local integer
187      CHARACTER(len=80), DIMENSION(10) ::   cltxt
188      !!
189      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
190         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle, nn_bench
191      !!----------------------------------------------------------------------
192      !
193      cltxt = ''
194      !
195      !                             ! open Namelist file
196      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
197      !
198      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
199      !
200      !                             !--------------------------------------------!
201      !                             !  set communicator & select the local node  !
202      !                             !--------------------------------------------!
203#if defined key_iomput
204      IF( Agrif_Root() ) THEN
205# if defined key_oasis3 || defined key_oasis4
206         CALL cpl_prism_init( ilocal_comm )   ! nemo local communicator given by oasis
207# endif
208         CALL  init_ioclient( ilocal_comm )   ! exchange io_server nemo local communicator with the io_server
209      ENDIF
210      narea = mynode( cltxt, ilocal_comm )    ! Nodes selection
211#else
212# if defined key_oasis3 || defined key_oasis4
213      IF( Agrif_Root() ) THEN
214         CALL cpl_prism_init( ilocal_comm )   ! nemo local communicator given by oasis
215      ENDIF
216      narea = mynode( cltxt, ilocal_comm )    ! Nodes selection (control print return in cltxt)
217# else
218      ilocal_comm = 0
219      narea = mynode( cltxt )                 ! Nodes selection (control print return in cltxt)
220# endif
221#endif
222      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
223
224      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
225
226      ! Decide on size of grid now that we have our communicator size
227      ! If we're not using dynamic memory then mpp_partition does nothing.
228
229#if   defined key_mpp_mpi   ||   defined key_mpp_shmem
230      CALL nemo_partition(mppsize)
231#else
232      jpni = 1
233      jpnj = 1
234      jpnij = jpni*jpnj
235#endif
236      ! Calculate domain dimensions given calculated jpni and jpnj
237      ! This used to be done in par_oce.F90 when they were parameters rather
238      ! than variables
239      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci !: first  dim.
240      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj !: second dim.
241      jpim1 = jpi-1                                          !: inner domain indices
242      jpjm1 = jpj-1                                          !:   "           "
243      jpkm1 = jpk-1                                          !:   "           "
244      jpij  = jpi*jpj                                        !:  jpi x j
245
246      ! Now we know the dimensions of the grid, allocate arrays
247      CALL nemo_alloc()
248
249      IF(lwp) THEN                            ! open listing units
250         !
251         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
252         !
253         WRITE(numout,*)
254         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
255         WRITE(numout,*) '                       NEMO team'
256         WRITE(numout,*) '            Ocean General Circulation Model'
257         WRITE(numout,*) '                  version 3.3  (2010) '
258         WRITE(numout,*)
259         WRITE(numout,*)
260         DO ji = 1, SIZE(cltxt) 
261            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
262         END DO
263         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
264         !
265      ENDIF
266      !                             !-------------------------------!
267      !                             !  NEMO general initialization  !
268      !                             !-------------------------------!
269
270      CALL nemo_ctl                          ! Control prints & Benchmark
271
272      !                                      ! Domain decomposition
273      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
274      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
275      ENDIF
276      !
277      !                                      ! General initialization
278                            CALL     phy_cst    ! Physical constants
279                            CALL     eos_init   ! Equation of state
280                            CALL     dom_cfg    ! Domain configuration
281                            CALL     dom_init   ! Domain
282
283      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
284
285      IF( lk_obc        )   CALL     obc_init   ! Open boundaries
286      IF( lk_bdy        )   CALL     bdy_init   ! Unstructured open boundaries
287
288                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
289
290      !                                     ! Ocean physics
291                            CALL     sbc_init   ! Forcings : surface module
292      !                                         ! Vertical physics
293                            CALL     zdf_init      ! namelist read
294                            CALL zdf_bfr_init      ! bottom friction
295      IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
296      IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
297      IF( lk_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
298      IF( lk_zdfkpp     )   CALL zdf_kpp_init      ! KPP closure scheme
299      IF( lk_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
300      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   & 
301         &                  CALL zdf_ddm_init      ! double diffusive mixing
302      !                                         ! Lateral physics
303                            CALL ldf_tra_init      ! Lateral ocean tracer physics
304                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
305      IF( lk_ldfslp     )   CALL ldf_slp_init      ! slope of lateral mixing
306
307      !                                     ! Active tracers
308                            CALL tra_qsr_init   ! penetrative solar radiation qsr
309                            CALL tra_bbc_init   ! bottom heat flux
310      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
311      IF( lk_tradmp     )   CALL tra_dmp_init   ! internal damping trends
312                            CALL tra_adv_init   ! horizontal & vertical advection
313                            CALL tra_ldf_init   ! lateral mixing
314                            CALL tra_zdf_init   ! vertical mixing and after tracer fields
315
316      !                                     ! Dynamics
317                            CALL dyn_adv_init   ! advection (vector or flux form)
318                            CALL dyn_vor_init   ! vorticity term including Coriolis
319                            CALL dyn_ldf_init   ! lateral mixing
320                            CALL dyn_hpg_init   ! horizontal gradient of Hydrostatic pressure
321                            CALL dyn_zdf_init   ! vertical diffusion
322                            CALL dyn_spg_init   ! surface pressure gradient
323                           
324      !                                     ! Misc. options
325      IF( nn_cla == 1   )   CALL cla_init       ! Cross Land Advection
326     
327#if defined key_top
328      !                                     ! Passive tracers
329                            CALL     trc_init
330#endif
331      !                                     ! Diagnostics
332                            CALL     iom_init   ! iom_put initialization
333      IF( lk_floats     )   CALL     flo_init   ! drifting Floats
334      IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
335                            CALL dia_ptr_init   ! Poleward TRansports initialization
336                            CALL dia_hsb_init   ! heat content, salt content and volume budgets
337                            CALL trd_mod_init   ! Mixed-layer/Vorticity/Integral constraints trends
338      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
339                            CALL dia_obs_init            ! Initialize observational data
340                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
341      ENDIF     
342      !                                     ! Assimilation increments
343      IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
344      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
345      !
346   END SUBROUTINE nemo_init
347
348
349   SUBROUTINE nemo_ctl
350      !!----------------------------------------------------------------------
351      !!                     ***  ROUTINE nemo_ctl  ***
352      !!
353      !! ** Purpose :   control print setting
354      !!
355      !! ** Method  : - print namctl information and check some consistencies
356      !!----------------------------------------------------------------------
357      !
358      IF(lwp) THEN                  ! control print
359         WRITE(numout,*)
360         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
361         WRITE(numout,*) '~~~~~~~ '
362         WRITE(numout,*) '   Namelist namctl'
363         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
364         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
365         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
366         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
367         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
368         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
369         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
370         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
371         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
372      ENDIF
373      !
374      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
375      nictls    = nn_ictls
376      nictle    = nn_ictle
377      njctls    = nn_jctls
378      njctle    = nn_jctle
379      isplt     = nn_isplt
380      jsplt     = nn_jsplt
381      nbench    = nn_bench
382      !                             ! Parameter control
383      !
384      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
385         IF( lk_mpp ) THEN
386            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
387         ELSE
388            IF( isplt == 1 .AND. jsplt == 1  ) THEN
389               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
390                  &           ' - the print control will be done over the whole domain' )
391            ENDIF
392            ijsplt = isplt * jsplt            ! total number of processors ijsplt
393         ENDIF
394         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
395         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
396         !
397         !                              ! indices used for the SUM control
398         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
399            lsp_area = .FALSE.                       
400         ELSE                                             ! print control done over a specific  area
401            lsp_area = .TRUE.
402            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
403               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
404               nictls = 1
405            ENDIF
406            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
407               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
408               nictle = jpiglo
409            ENDIF
410            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
411               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
412               njctls = 1
413            ENDIF
414            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
415               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
416               njctle = jpjglo
417            ENDIF
418         ENDIF
419      ENDIF
420      !
421      IF( nbench == 1 ) THEN              ! Benchmark
422         SELECT CASE ( cp_cfg )
423         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
424         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
425            &                                 ' key_gyre must be used or set nbench = 0' )
426         END SELECT
427      ENDIF
428      !
429      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
430         &                                               'with the IOM Input/Output manager. '         ,   &
431         &                                               'Compile with key_iomput enabled' )
432      !
433   END SUBROUTINE nemo_ctl
434
435
436   SUBROUTINE nemo_closefile
437      !!----------------------------------------------------------------------
438      !!                     ***  ROUTINE nemo_closefile  ***
439      !!
440      !! ** Purpose :   Close the files
441      !!----------------------------------------------------------------------
442      !
443      IF( lk_mpp )   CALL mppsync
444      !
445      CALL iom_close                                 ! close all input/output files managed by iom_*
446      !
447      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
448      IF( numsol     /= -1 )   CLOSE( numsol     )   ! solver file
449      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
450      IF( numnam_ice /= -1 )   CLOSE( numnam_ice )   ! ice namelist
451      IF( numevo_ice /= -1 )   CLOSE( numevo_ice )   ! ice variables (temp. evolution)
452      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
453      !
454      numout = 6                                     ! redefine numout in case it is used after this point...
455      !
456   END SUBROUTINE nemo_closefile
457
458
459   SUBROUTINE nemo_alloc
460     !!----------------------------------------------------------------------
461     !!                     ***  ROUTINE nemo_alloc  ***
462     !!
463     !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
464     !!
465     !! ** Method  :
466     !!----------------------------------------------------------------------
467     USE diawri,       ONLY: dia_wri_alloc
468     USE dom_oce,      ONLY: dom_oce_alloc
469     USE ldfdyn_oce,   ONLY: ldfdyn_oce_alloc
470     USE ldftra_oce,   ONLY: ldftra_oce_alloc
471
472     
473     USE dynzdf_exp,   ONLY: dyn_zdf_exp_alloc
474     USE geo2ocean,    ONLY: geo2oce_alloc
475#if   defined key_mpp_mpi 
476     USE lib_mpp,      ONLY: lib_mpp_alloc
477#endif
478#if defined key_obc
479     USE obcdta ,      ONLY: obc_dta_alloc
480     USE obc_oce,      ONLY: obc_oce_alloc
481#endif
482     USE sbcblk_clio,  ONLY: sbc_blk_clio_alloc
483#if defined key_oasis3 || defined key_oasis4
484     USE sbccpl,       ONLY: sbc_cpl_init_alloc
485#endif
486     USE sbcdcy,       ONLY: sbc_dcy_alloc
487     USE sbcfwb,       ONLY: sbc_fwb_alloc
488     USE sbc_oce,      ONLY: sbc_oce_alloc
489     USE sbcrnf,       ONLY: sbc_rnf_alloc
490     USE sbcssr,       ONLY: sbc_ssr_alloc
491     USE sol_oce,      ONLY: sol_oce_alloc
492     USE solmat,       ONLY: sol_mat_alloc
493     USE traadv,       ONLY: tra_adv_alloc
494     USE traadv_cen2,  ONLY: tra_adv_cen2_alloc
495#if   defined key_trabbl   ||   defined key_esopa
496     USE trabbl,       ONLY: tra_bbl_alloc
497#endif
498#if   defined key_tradmp   ||   defined key_esopa
499     USE tradmp,       ONLY: tra_dmp_alloc
500#endif
501     USE traldf,       ONLY: tra_ldf_alloc
502#if   defined key_ldfslp   ||   defined key_esopa
503     USE traldf_iso_grif,ONLY: tra_ldf_iso_grif_alloc
504#endif
505     USE traldf_lap,   ONLY: tra_ldf_lap_alloc
506     USE tranxt,       ONLY: tra_nxt_alloc
507     USE trazdf,       ONLY: tra_zdf_alloc
508
509     ! TOP-related alloc routines...
510#if defined key_top
511      USE trcadv,       ONLY: trc_adv_alloc
512      USE trc,          ONLY: trc_alloc
513      USE trcnxt,       ONLY: trc_nxt_alloc
514      USE trczdf,       ONLY: trc_zdf_alloc
515      USE trdmod_trc_oce,ONLY: trd_mod_trc_oce_alloc
516#endif
517#if defined key_top && ! defined key_iomput
518      USE trcdia,       ONLY: trc_dia_alloc
519#endif
520#if  defined key_top && defined key_trcdmp 
521      USE trcdmp,       ONLY: trc_dmp_alloc
522#endif
523#if  defined key_top  &&  defined key_dtatrc
524      USE trcdta,       ONLY: trc_dta_alloc
525#endif
526#if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
527      USE trdmld_trc,   ONLY: trd_mld_trc_alloc
528#endif
529#if defined key_cfc
530     USE trcsms_cfc,   ONLY: trc_sms_cfc_alloc
531#endif
532      ! ...end of TOP-related alloc routines
533
534      ! LOBSTER-related alloc routines...
535#if defined key_lobster
536      USE sms_lobster,  ONLY: sms_lobster_alloc
537#endif
538      ! ...end of LOBSTER-related alloc routines
539
540      USE trc_oce,      ONLY: trc_oce_alloc
541#if   defined key_trdmld   ||   defined key_esopa
542      USE trdmld,       ONLY: trd_mld_alloc
543#endif
544      USE trdmld_oce,   ONLY: trdmld_oce_alloc
545#if  defined key_trdtra || defined key_trdmld || defined key_trdmld_trc 
546      USE trdtra,       ONLY: trd_tra_alloc
547#endif
548#if defined key_trdvor   ||   defined key_esopa
549      USE trdvor,       ONLY: trd_vor_alloc
550#endif
551      USE wrk_nemo,     ONLY: wrk_alloc
552
553      INTEGER :: ierr
554      INTEGER :: i
555      !!----------------------------------------------------------------------
556
557      ierr =        oce_alloc       ()    ! ocean
558      ierr = ierr + dia_wri_alloc   ()
559      ierr = ierr + dom_oce_alloc   ()    ! ocean domain
560      ierr = ierr + ldfdyn_oce_alloc()    ! ocean lateral  physics : dynamics
561      ierr = ierr + ldftra_oce_alloc()    ! ocean lateral  physics : tracers
562      ierr = ierr + zdf_oce_alloc()       ! ocean vertical physics
563
564
565
566      ierr = ierr + dyn_zdf_exp_alloc()
567      ierr = ierr + geo2oce_alloc()
568#if defined key_mpp_mpi 
569      ierr = ierr + lib_mpp_alloc()
570#endif
571#if defined key_obc
572      ierr = ierr + obc_dta_alloc()
573      ierr = ierr + obc_oce_alloc()
574#endif
575      ierr = ierr + sbc_blk_clio_alloc()
576#if defined key_oasis3 || defined key_oasis4
577      ierr = ierr + sbc_cpl_init_alloc()
578#endif
579      ierr = ierr + sbc_dcy_alloc()
580      ierr = ierr + sbc_fwb_alloc()
581      ierr = ierr + sbc_oce_alloc()
582      ierr = ierr + sbc_rnf_alloc()
583      ierr = ierr + sbc_ssr_alloc()
584      ierr = ierr + sol_oce_alloc()
585      ierr = ierr + sol_mat_alloc()
586      ierr = ierr + tra_adv_alloc()
587      ierr = ierr + tra_adv_cen2_alloc()
588#if defined key_trabbl   ||   defined key_esopa
589      ierr = ierr + tra_bbl_alloc()
590#endif
591#if defined key_tradmp   ||   defined key_esopa
592      ierr = ierr + tra_dmp_alloc()
593#endif
594      ierr = ierr + tra_ldf_alloc()
595#if defined key_ldfslp   ||   defined key_esopa
596      ierr = ierr + tra_ldf_iso_grif_alloc()
597#endif
598      ierr = ierr + tra_ldf_lap_alloc()
599      ierr = ierr + tra_nxt_alloc()
600      ierr = ierr + tra_zdf_alloc()
601
602      ! Start of TOP-related alloc routines...
603#if defined key_top
604      ierr = ierr + trc_adv_alloc()
605      ierr = ierr + trc_alloc()
606      ierr = ierr + trc_nxt_alloc()
607      ierr = ierr + trc_zdf_alloc()
608      ierr = ierr + trd_mod_trc_oce_alloc()
609#endif
610#if defined key_top && ! defined key_iomput
611      ierr = ierr + trc_dia_alloc()
612#endif
613#if  defined key_top && defined key_trcdmp 
614      ierr = ierr + trc_dmp_alloc()
615#endif
616#if  defined key_top  &&  defined key_dtatrc
617      ierr = ierr + trc_dta_alloc()
618#endif
619#if   defined key_top && ( defined key_trdmld_trc   ||   defined key_esopa )
620      ierr = ierr + trd_mld_trc_alloc()
621#endif
622      ! ...end of TOP-related alloc routines
623
624      ! Start of LOBSTER-related alloc routines
625#if defined key_lobster
626      ierr = ierr + sms_lobster_alloc()
627#endif
628      ! ...end of LOBSTER-related alloc routines
629
630      ierr = ierr + trc_oce_alloc()
631#if   defined key_trdmld   ||   defined key_esopa
632      ierr = ierr + trd_mld_alloc()
633#endif
634      ierr = ierr + trdmld_oce_alloc()
635#if  defined key_trdtra || defined key_trdmld || defined key_trdmld_trc 
636      ierr = ierr + trd_tra_alloc()
637#endif
638#if defined key_trdvor   ||   defined key_esopa
639      ierr = ierr + trd_vor_alloc()
640#endif
641      ierr = ierr + wrk_alloc()
642
643      IF( lk_mpp    )   CALL mpp_sum( ierr )
644      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
645      !
646   END SUBROUTINE nemo_alloc
647
648
649   SUBROUTINE nemo_partition( num_pes )
650      !!----------------------------------------------------------------------
651      !!                 ***  ROUTINE nemo_partition  ***
652      !!
653      !! ** Purpose :   
654      !!
655      !! ** Method  :
656      !!----------------------------------------------------------------------
657      USE par_oce
658      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
659      ! Local variables
660      INTEGER, PARAMETER :: nfactmax = 20
661      INTEGER :: nfact ! The no. of factors returned
662      INTEGER :: ierr  ! Error flag
663      INTEGER :: i
664      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
665      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
666      !!----------------------------------------------------------------------
667
668      ierr = 0
669
670      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
671
672      IF( nfact <= 1 ) THEN
673         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
674         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
675         jpnj = 1
676         jpni = num_pes
677      ELSE
678         ! Search through factors for the pair that are closest in value
679         mindiff = 1000000
680         imin    = 1
681         DO i=1,nfact-1,2
682            idiff = ABS(ifact(i) - ifact(i+1))
683            IF(idiff < mindiff)THEN
684               mindiff = idiff
685               imin = i
686            END IF
687         END DO
688         jpnj = ifact(imin)
689         jpni = ifact(imin + 1)
690      ENDIF
691      jpnij = jpni*jpnj
692
693      WRITE(*,*) 'ARPDBG: jpni = ',jpni,'jpnj = ',jpnj,'jpnij = ',jpnij
694      !
695   END SUBROUTINE nemo_partition
696
697
698   SUBROUTINE factorise( ifax, maxfax, nfax, n, ierr )
699      !!----------------------------------------------------------------------
700      !!                     ***  ROUTINE factorise  ***
701      !!
702      !! ** Purpose :   return the prime factors of n.
703      !!                nfax factors are returned in array ifax which is of
704      !!                maximum dimension maxfax.
705      !! ** Method  :
706      !!----------------------------------------------------------------------
707      INTEGER, INTENT(in)  :: n, maxfax
708      INTEGER, INTENT(Out) :: ierr, nfax
709      INTEGER, INTENT(out) :: ifax(maxfax)
710      ! Local variables.
711      INTEGER :: i, ifac, l, nu
712      INTEGER, PARAMETER :: ntest = 14
713      INTEGER :: lfax(ntest)
714
715      ! lfax contains the set of allowed factors.
716      data (lfax(i),i=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
717         &                         128,   64,   32,   16,    8,   4,   2  /
718      !!----------------------------------------------------------------------
719
720      ! Clear the error flag and initialise output vars
721      ierr = 0
722      ifax = 1
723      nfax = 0
724
725      ! Find the factors of n.
726      IF( n == 1 ) GOTO 20
727
728      ! nu holds the unfactorised part of the number.
729      ! nfax holds the number of factors found.
730      ! l points to the allowed factor list.
731      ! ifac holds the current factor.
732
733      nu   = n
734      nfax = 0
735
736      DO l = ntest, 1, -1
737         !
738         ifac = lfax(l)
739         IF(ifac > nu)CYCLE
740
741         ! Test whether the factor will divide.
742
743         IF( MOD(nu,ifac) == 0 ) THEN
744            !
745            nfax = nfax+1            ! Add the factor to the list
746            IF( nfax > maxfax ) THEN
747               ierr = 6
748               write (*,*) 'FACTOR: insufficient space in factor array ',nfax
749               return
750            ENDIF
751            ifax(nfax) = ifac
752            ! Store the other factor that goes with this one
753            nfax = nfax + 1
754            ifax(nfax) = nu / ifac
755            !WRITE (*,*) 'ARPDBG, factors ',nfax-1,' & ',nfax,' are ', &
756            !            ifax(nfax-1),' and ',ifax(nfax)
757         ENDIF
758         !
759      END DO
760
761   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
762      !
763      RETURN
764      !
765  END SUBROUTINE factorise
766
767  !!======================================================================
768END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.