New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
nemogcm.F90 in branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OFF_SRC – NEMO

source: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 7225

Last change on this file since 7225 was 7225, checked in by flavoni, 7 years ago

#1692 - branch SIMPLIF_2_usrdef: updates: rm jpidta in agrif_user, rm dom_cfg for OFFLINE

  • Property svn:keywords set to Id
File size: 32.0 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! OFF-line Ocean   : passive tracer evolution, dynamics read in files
5   !!======================================================================
6   !! History :  3.3  ! 2010-05  (C. Ethe)  Full reorganization of the off-line: phasing with the on-line
7   !!            4.0  ! 2011-01  (C. Ethe, A. R. Porter, STFC Daresbury) dynamical allocation
8   !!            4.0  ! 2016-10  (C. Ethe, G. Madec, S. Flavoni)  domain configuration / user defined interface
9   !!----------------------------------------------------------------------
10
11   !!----------------------------------------------------------------------
12   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
13   !!   nemo_init     : initialization of the NEMO system
14   !!   nemo_ctl      : initialisation of the contol print
15   !!   nemo_closefile: close remaining open files
16   !!   nemo_alloc    : dynamical allocation
17   !!   nemo_partition: calculate MPP domain decomposition
18   !!   factorise     : calculate the factors of the no. of MPI processes
19   !!   istate_init   : ocean variables set to zero
20   !!   stp_ctl       : step control for OFF-line
21   !!----------------------------------------------------------------------
22   USE dom_oce         ! ocean space domain variables
23   USE oce             ! dynamics and tracers variables
24   USE c1d             ! 1D configuration
25   USE domain          ! domain initialization   (dom_init & dom_cfg routines)
26   USE usrdef_nam      ! user defined configuration
27   USE eosbn2          ! equation of state            (eos bn2 routine)
28   !              ! ocean physics
29   USE ldftra          ! lateral diffusivity setting    (ldf_tra_init routine)
30   USE ldfslp          ! slopes of neutral surfaces     (ldf_slp_init routine)
31   USE traqsr          ! solar radiation penetration    (tra_qsr_init routine)
32   USE trabbl          ! bottom boundary layer          (tra_bbl_init routine)
33   USE traldf          ! lateral physics                (tra_ldf_init routine)
34   USE zdfini          ! vertical physics: initialization
35   USE sbcmod          ! surface boundary condition       (sbc_init     routine)
36   USE phycst          ! physical constant                  (par_cst routine)
37   USE dtadyn          ! Lecture and Interpolation of the dynamical fields
38   USE trcini          ! Initilization of the passive tracers
39   USE daymod          ! calendar                         (day     routine)
40   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
41   USE dtadyn          ! Lecture and interpolation of the dynamical fields
42   !              ! Passive tracers needs
43   USE trc             ! passive tracer : variables
44   USE trcnam          ! passive tracer : namelist
45   USE trcrst          ! passive tracer restart
46   USE diaptr          ! Need to initialise this as some variables are used in if statements later
47   USE sbc_oce  , ONLY : ln_rnf
48   USE sbcrnf          ! surface boundary condition : runoffs
49   !              ! I/O & MPP
50   USE iom             ! I/O library
51   USE in_out_manager  ! I/O manager
52   USE mppini          ! shared/distributed memory setting (mpp_init routine)
53   USE lib_mpp         ! distributed memory computing
54#if defined key_iomput
55   USE xios
56#endif
57   USE prtctl          ! Print control                    (prt_ctl_init routine)
58   USE timing          ! Timing
59   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
60   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
61
62   IMPLICIT NONE
63   PRIVATE
64   
65   PUBLIC   nemo_gcm   ! called by nemo.F90
66
67   CHARACTER (len=64) ::   cform_aaa="( /, 'AAAAAAAA', / ) "   ! flag for output listing
68
69   !!----------------------------------------------------------------------
70   !! NEMO/OFF 4.0 , NEMO Consortium (2016)
71   !! $Id$
72   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
73   !!----------------------------------------------------------------------
74CONTAINS
75
76   SUBROUTINE nemo_gcm
77      !!----------------------------------------------------------------------
78      !!                     ***  ROUTINE nemo_gcm  ***
79      !!
80      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
81      !!              curvilinear mesh on the sphere.
82      !!
83      !! ** Method  : - model general initialization
84      !!              - launch the time-stepping (dta_dyn and trc_stp)
85      !!              - finalize the run by closing files and communications
86      !!
87      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
88      !!              Madec, 2008, internal report, IPSL.
89      !!----------------------------------------------------------------------
90      INTEGER :: istp, indic   ! time step index
91      !!----------------------------------------------------------------------
92
93      !                            !-----------------------!
94      CALL nemo_init               !==  Initialisations  ==!
95      !                            !-----------------------!
96
97      ! check that all process are still there... If some process have an error,
98      ! they will never enter in step and other processes will wait until the end of the cpu time!
99      IF( lk_mpp )   CALL mpp_max( nstop )
100
101      !                            !-----------------------!
102      !                            !==   time stepping   ==!
103      !                            !-----------------------!
104      istp = nit000
105      !
106      ! Initialize arrays of runoffs structures and read data from the namelist
107      IF ( ln_rnf ) CALL sbc_rnf(istp)
108      !
109      CALL iom_init( cxios_context )            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
110      !
111      DO WHILE ( istp <= nitend .AND. nstop == 0 )    ! time stepping
112         !
113         IF( istp /= nit000 )   CALL day      ( istp )         ! Calendar (day was already called at nit000 in day_init)
114                                CALL iom_setkt( istp - nit000 + 1, "nemo" )   ! say to iom that we are at time step kstp
115                                CALL dta_dyn  ( istp )         ! Interpolation of the dynamical fields
116                                CALL trc_stp  ( istp )         ! time-stepping
117                                CALL stp_ctl  ( istp, indic )  ! Time loop: control and print
118         istp = istp + 1
119         IF( lk_mpp )   CALL mpp_max( nstop )
120      END DO
121#if defined key_iomput
122      CALL iom_context_finalize( cxios_context ) ! needed for XIOS+AGRIF
123#endif
124
125      !                            !------------------------!
126      !                            !==  finalize the run  ==!
127      !                            !------------------------!
128      IF(lwp) WRITE(numout,cform_aaa)        ! Flag AAAAAAA
129      !
130      IF( nstop /= 0 .AND. lwp ) THEN        ! error print
131         WRITE(numout,cform_err)
132         WRITE(numout,*) nstop, ' error have been found'
133      ENDIF
134      !
135      IF( nn_timing == 1 )   CALL timing_finalize
136      !
137      CALL nemo_closefile
138      !
139#if defined key_iomput
140      CALL xios_finalize                     ! end mpp communications
141#else
142      IF( lk_mpp )   CALL mppstop            ! end mpp communications
143#endif
144      !
145   END SUBROUTINE nemo_gcm
146
147
148   SUBROUTINE nemo_init
149      !!----------------------------------------------------------------------
150      !!                     ***  ROUTINE nemo_init  ***
151      !!
152      !! ** Purpose :   initialization of NEMO in off-line mode
153      !!----------------------------------------------------------------------
154      INTEGER  ::   ji            ! dummy loop indices
155      INTEGER  ::   ilocal_comm   ! local integer
156      INTEGER  ::   ios, inum     !   -      -
157      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
158      !
159      NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
160         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
161         &             nn_timing, nn_diacfl
162      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
163      !!----------------------------------------------------------------------
164      !
165      cltxt  = ''
166      cltxt2 = ''
167      clnam  = '' 
168      cxios_context = 'nemo'
169      !
170      !                             ! Open reference namelist and configuration namelist files
171      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
172      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
173      !
174      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints
175      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
176901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
177      !
178      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
179      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
180902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
181      !
182      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints
183      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
184903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
185
186      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
187      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
188904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
189
190      !                             !--------------------------!
191      !                             !  Set global domain size  !   (control print return in cltxt2)
192      !                             !--------------------------!
193      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
194         CALL domain_cfg ( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
195         !
196      ELSE                                ! user-defined namelist
197         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
198      ENDIF
199      jpk    = jpkglo
200      !
201      !                             !--------------------------------------------!
202      !                             !  set communicator & select the local node  !
203      !                             !  NB: mynode also opens output.namelist.dyn !
204      !                             !      on unit number numond on first proc   !
205      !                             !--------------------------------------------!
206#if defined key_iomput
207      CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )
208      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
209#else
210      ilocal_comm = 0
211      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
212#endif
213
214      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
215
216      lwm = (narea == 1)                      ! control of output namelists
217      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
218
219      IF(lwm) THEN               ! write merged namelists from earlier to output namelist
220         !                       ! now that the file has been opened in call to mynode.
221         !                       ! NB: nammpp has already been written in mynode (if lk_mpp_mpi)
222         WRITE( numond, namctl )
223         WRITE( numond, namcfg )
224         IF( .NOT.ln_read_cfg ) THEN
225            DO ji = 1, SIZE(clnam)
226               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
227            END DO
228         ENDIF
229      ENDIF
230
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         CALL nemo_partition( mppsize )
236#else
237         jpni  = 1
238         jpnj  = 1
239         jpnij = jpni*jpnj
240#endif
241      ENDIF
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      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
247      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
248      jpim1 = jpi-1                                            ! inner domain indices
249      jpjm1 = jpj-1                                            !   "           "
250      jpkm1 = jpk-1                                            !   "           "
251      jpij  = jpi*jpj                                          !  jpi x j
252
253      IF(lwp) THEN                            ! open listing units
254         !
255         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
256         !
257         WRITE(numout,*)
258         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
259         WRITE(numout,*) '                       NEMO team'
260         WRITE(numout,*) '            Ocean General Circulation Model'
261         WRITE(numout,*) '                  version 3.7  (2016) '
262         WRITE(numout,*)
263         WRITE(numout,*)
264         DO ji = 1, SIZE(cltxt)
265            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) cltxt(ji)    ! control print of mynode
266         END DO
267         WRITE(numout,*)
268         WRITE(numout,*)
269         DO ji = 1, SIZE(cltxt2)
270            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)   ! control print of domain size
271         END DO
272         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
273         !
274      ENDIF
275
276      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
277      CALL nemo_alloc()
278      !                             !-------------------------------!
279      !                             !  NEMO general initialization  !
280      !                             !-------------------------------!
281
282      CALL nemo_ctl                          ! Control prints
283
284      !                                      ! Domain decomposition
285      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
286      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
287      ENDIF
288      !
289      IF( nn_timing == 1 )  CALL timing_init
290      !
291      !                                      ! General initialization
292      IF( nn_timing == 1 )  CALL timing_start( 'nemo_init')
293      !
294                            CALL     phy_cst    ! Physical constants
295                            CALL     eos_init   ! Equation of state
296      IF( lk_c1d        )   CALL     c1d_init   ! 1D column configuration
297
298                            CALL     dom_init   ! Domain
299
300                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
301
302      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
303
304      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
305
306                            CALL     sbc_init   ! Forcings : surface module
307
308                            CALL ldf_tra_init   ! Lateral ocean tracer physics
309                            CALL ldf_eiv_init   ! Eddy induced velocity param
310                            CALL tra_ldf_init   ! lateral mixing
311      IF( l_ldfslp )        CALL ldf_slp_init   ! slope of lateral mixing
312
313                            CALL tra_qsr_init   ! penetrative solar radiation qsr
314      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
315
316                            CALL trc_nam_run    ! Needed to get restart parameters for passive tracers
317                            CALL trc_rst_cal( nit000, 'READ' )   ! calendar
318                            CALL dta_dyn_init   ! Initialization for the dynamics
319
320                            CALL     trc_init   ! Passive tracers initialization
321                            CALL dia_ptr_init   ! Initialise diaptr as some variables are used
322      !                                         ! in various advection and diffusion routines
323      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
324      !
325      IF( nn_timing == 1 )  CALL timing_stop( 'nemo_init')
326      !
327   END SUBROUTINE nemo_init
328
329
330   SUBROUTINE nemo_ctl
331      !!----------------------------------------------------------------------
332      !!                     ***  ROUTINE nemo_ctl  ***
333      !!
334      !! ** Purpose :   control print setting
335      !!
336      !! ** Method  : - print namctl information and check some consistencies
337      !!----------------------------------------------------------------------
338      !
339      IF(lwp) THEN                  ! control print
340         WRITE(numout,*)
341         WRITE(numout,*) 'nemo_ctl: Control prints'
342         WRITE(numout,*) '~~~~~~~ '
343         WRITE(numout,*) '   Namelist namctl'
344         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
345         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
346         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
347         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
348         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
349         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
350         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
351         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
352         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
353      ENDIF
354      !
355      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
356      nictls    = nn_ictls
357      nictle    = nn_ictle
358      njctls    = nn_jctls
359      njctle    = nn_jctle
360      isplt     = nn_isplt
361      jsplt     = nn_jsplt
362
363      IF(lwp) THEN                  ! control print
364         WRITE(numout,*)
365         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
366         WRITE(numout,*) '~~~~~~~ '
367         WRITE(numout,*) '   Namelist namcfg'
368         WRITE(numout,*) '      read domain configuration files               ln_read_cfg      = ', ln_read_cfg
369         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
370         WRITE(numout,*) '      write  configuration definition files         ln_write_cfg     = ', ln_write_cfg
371         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
372         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
373      ENDIF
374      !                             ! Parameter control
375      !
376      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
377         IF( lk_mpp .AND. jpnij > 1 ) THEN
378            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
379         ELSE
380            IF( isplt == 1 .AND. jsplt == 1  ) THEN
381               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
382                  &           ' - the print control will be done over the whole domain' )
383            ENDIF
384            ijsplt = isplt * jsplt            ! total number of processors ijsplt
385         ENDIF
386         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
387         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
388         !
389         !                              ! indices used for the SUM control
390         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
391            lsp_area = .FALSE.
392         ELSE                                             ! print control done over a specific  area
393            lsp_area = .TRUE.
394            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
395               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
396               nictls = 1
397            ENDIF
398            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
399               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
400               nictle = jpiglo
401            ENDIF
402            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
403               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
404               njctls = 1
405            ENDIF
406            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
407               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
408               njctle = jpjglo
409            ENDIF
410         ENDIF
411      ENDIF
412      !
413      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
414         &                                               'f2003 standard. '                              ,  &
415         &                                               'Compile with key_nosignedzero enabled' )
416      !
417   END SUBROUTINE nemo_ctl
418
419
420   SUBROUTINE nemo_closefile
421      !!----------------------------------------------------------------------
422      !!                     ***  ROUTINE nemo_closefile  ***
423      !!
424      !! ** Purpose :   Close the files
425      !!----------------------------------------------------------------------
426      !
427      IF( lk_mpp )   CALL mppsync
428      !
429      CALL iom_close                                 ! close all input/output files managed by iom_*
430      !
431      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
432      IF( numnam_ref /= -1 )   CLOSE( numnam_ref )   ! oce reference namelist
433      IF( numnam_cfg /= -1 )   CLOSE( numnam_cfg )   ! oce configuration namelist
434      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
435      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
436
437      numout = 6                                     ! redefine numout in case it is used after this point...
438      !
439   END SUBROUTINE nemo_closefile
440
441
442   SUBROUTINE nemo_alloc
443      !!----------------------------------------------------------------------
444      !!                     ***  ROUTINE nemo_alloc  ***
445      !!
446      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
447      !!
448      !! ** Method  :
449      !!----------------------------------------------------------------------
450      USE diawri ,      ONLY: dia_wri_alloc
451      USE dom_oce,      ONLY: dom_oce_alloc
452      USE zdf_oce,      ONLY: zdf_oce_alloc
453      USE trc_oce,      ONLY: trc_oce_alloc
454      !
455      INTEGER :: ierr
456      !!----------------------------------------------------------------------
457      !
458      ierr =        oce_alloc       ()          ! ocean
459      ierr = ierr + dia_wri_alloc   ()
460      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
461      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
462      !
463      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
464      !
465      IF( lk_mpp    )   CALL mpp_sum( ierr )
466      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
467      !
468   END SUBROUTINE nemo_alloc
469
470
471   SUBROUTINE nemo_partition( num_pes )
472      !!----------------------------------------------------------------------
473      !!                 ***  ROUTINE nemo_partition  ***
474      !!
475      !! ** Purpose :   
476      !!
477      !! ** Method  :
478      !!----------------------------------------------------------------------
479      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
480      !
481      INTEGER, PARAMETER :: nfactmax = 20
482      INTEGER :: nfact ! The no. of factors returned
483      INTEGER :: ierr  ! Error flag
484      INTEGER :: ji
485      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
486      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
487      !!----------------------------------------------------------------------
488      !
489      ierr = 0
490      !
491      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
492      !
493      IF( nfact <= 1 ) THEN
494         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
495         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
496         jpnj = 1
497         jpni = num_pes
498      ELSE
499         ! Search through factors for the pair that are closest in value
500         mindiff = 1000000
501         imin    = 1
502         DO ji = 1, nfact-1, 2
503            idiff = ABS( ifact(ji) - ifact(ji+1) )
504            IF( idiff < mindiff ) THEN
505               mindiff = idiff
506               imin = ji
507            ENDIF
508         END DO
509         jpnj = ifact(imin)
510         jpni = ifact(imin + 1)
511      ENDIF
512      !
513      jpnij = jpni*jpnj
514      !
515   END SUBROUTINE nemo_partition
516
517
518   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
519      !!----------------------------------------------------------------------
520      !!                     ***  ROUTINE factorise  ***
521      !!
522      !! ** Purpose :   return the prime factors of n.
523      !!                knfax factors are returned in array kfax which is of
524      !!                maximum dimension kmaxfax.
525      !! ** Method  :
526      !!----------------------------------------------------------------------
527      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
528      INTEGER                    , INTENT(  out) ::   kerr, knfax
529      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
530      !
531      INTEGER :: ifac, jl, inu
532      INTEGER, PARAMETER :: ntest = 14
533      INTEGER, DIMENSION(ntest) ::   ilfax
534      !!----------------------------------------------------------------------
535      !
536      ! lfax contains the set of allowed factors.
537      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
538      !
539      ! Clear the error flag and initialise output vars
540      kerr  = 0
541      kfax  = 1
542      knfax = 0
543      !
544      ! Find the factors of n.
545      IF( kn == 1 )   GOTO 20
546
547      ! nu holds the unfactorised part of the number.
548      ! knfax holds the number of factors found.
549      ! l points to the allowed factor list.
550      ! ifac holds the current factor.
551      !
552      inu   = kn
553      knfax = 0
554      !
555      DO jl = ntest, 1, -1
556         !
557         ifac = ilfax(jl)
558         IF( ifac > inu )   CYCLE
559
560         ! Test whether the factor will divide.
561
562         IF( MOD(inu,ifac) == 0 ) THEN
563            !
564            knfax = knfax + 1            ! Add the factor to the list
565            IF( knfax > kmaxfax ) THEN
566               kerr = 6
567               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
568               return
569            ENDIF
570            kfax(knfax) = ifac
571            ! Store the other factor that goes with this one
572            knfax = knfax + 1
573            kfax(knfax) = inu / ifac
574            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
575         ENDIF
576         !
577      END DO
578      !
579   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
580      !
581   END SUBROUTINE factorise
582
583#if defined key_mpp_mpi
584
585   SUBROUTINE nemo_northcomms
586      !!----------------------------------------------------------------------
587      !!                     ***  ROUTINE  nemo_northcomms  ***
588      !! ** Purpose :   Setup for north fold exchanges with explicit
589      !!                point-to-point messaging
590      !!
591      !! ** Method :   Initialization of the northern neighbours lists.
592      !!----------------------------------------------------------------------
593      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
594      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
595      !!----------------------------------------------------------------------
596      INTEGER  ::   sxM, dxM, sxT, dxT, jn
597      INTEGER  ::   njmppmax
598      !!----------------------------------------------------------------------
599      !
600      njmppmax = MAXVAL( njmppt )
601      !
602      !initializes the north-fold communication variables
603      isendto(:) = 0
604      nsndto     = 0
605      !
606      !if I am a process in the north
607      IF ( njmpp == njmppmax ) THEN
608          !sxM is the first point (in the global domain) needed to compute the
609          !north-fold for the current process
610          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
611          !dxM is the last point (in the global domain) needed to compute the
612          !north-fold for the current process
613          dxM = jpiglo - nimppt(narea) + 2
614
615          !loop over the other north-fold processes to find the processes
616          !managing the points belonging to the sxT-dxT range
617 
618          DO jn = 1, jpni
619                !sxT is the first point (in the global domain) of the jn
620                !process
621                sxT = nfiimpp(jn, jpnj)
622                !dxT is the last point (in the global domain) of the jn
623                !process
624                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
625                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
626                   nsndto = nsndto + 1
627                     isendto(nsndto) = jn
628                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
629                   nsndto = nsndto + 1
630                     isendto(nsndto) = jn
631                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
632                   nsndto = nsndto + 1
633                     isendto(nsndto) = jn
634                END IF
635          END DO
636          nfsloop = 1
637          nfeloop = nlci
638          DO jn = 2,jpni-1
639           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
640              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
641                 nfsloop = nldi
642              ENDIF
643              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
644                 nfeloop = nlei
645              ENDIF
646           ENDIF
647        END DO
648
649      ENDIF
650      l_north_nogather = .TRUE.
651   END SUBROUTINE nemo_northcomms
652
653#else
654   SUBROUTINE nemo_northcomms      ! Dummy routine
655      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
656   END SUBROUTINE nemo_northcomms
657#endif
658
659   SUBROUTINE istate_init
660      !!----------------------------------------------------------------------
661      !!                   ***  ROUTINE istate_init  ***
662      !!
663      !! ** Purpose :   Initialization to zero of the dynamics and tracers.
664      !!----------------------------------------------------------------------
665      !
666      !     now fields         !     after fields      !
667      un   (:,:,:)   = 0._wp   ;   ua(:,:,:) = 0._wp   !
668      vn   (:,:,:)   = 0._wp   ;   va(:,:,:) = 0._wp   !
669      wn   (:,:,:)   = 0._wp   !                       !
670      hdivn(:,:,:)   = 0._wp   !                       !
671      tsn  (:,:,:,:) = 0._wp   !                       !
672      !
673      rhd  (:,:,:) = 0.e0
674      rhop (:,:,:) = 0.e0
675      rn2  (:,:,:) = 0.e0
676      !
677   END SUBROUTINE istate_init
678
679
680   SUBROUTINE stp_ctl( kt, kindic )
681      !!----------------------------------------------------------------------
682      !!                    ***  ROUTINE stp_ctl  ***
683      !!
684      !! ** Purpose :   Control the run
685      !!
686      !! ** Method  : - Save the time step in numstp
687      !!
688      !! ** Actions :   'time.step' file containing the last ocean time-step
689      !!----------------------------------------------------------------------
690      INTEGER, INTENT(in   ) ::   kt      ! ocean time-step index
691      INTEGER, INTENT(inout) ::   kindic  ! indicator of solver convergence
692      !!----------------------------------------------------------------------
693      !
694      IF( kt == nit000 .AND. lwp ) THEN
695         WRITE(numout,*)
696         WRITE(numout,*) 'stp_ctl : time-stepping control'
697         WRITE(numout,*) '~~~~~~~'
698         ! open time.step file
699         CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
700      ENDIF
701      !
702      IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
703      IF(lwp) REWIND( numstp )                       ! --------------------------
704      !
705   END SUBROUTINE stp_ctl
706
707   !!======================================================================
708END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.