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

Last change on this file since 2668 was 2668, checked in by trackstand2, 13 years ago

Added jpni, jpnj and jpnij to nammpp namelist. Suppressed nammpp_dyndist section.

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