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 trunk/NEMOGCM/NEMO/OFF_SRC – NEMO

source: trunk/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 6140

Last change on this file since 6140 was 6140, checked in by timgraham, 8 years ago

Merge of branches/2015/dev_merge_2015 back into trunk. Merge excludes NEMOGCM/TOOLS/OBSTOOLS/ for now due to issues with the change of file type. Will sort these manually with further commits.

Branch merged as follows:
In the working copy of branch ran:
svn merge svn+ssh://forge.ipsl.jussieu.fr/ipsl/forge/projets/nemo/svn/trunk@HEAD
Small conflicts due to bug fixes applied to trunk since the dev_merge_2015 was copied. Bug fixes were applied to the branch as well so these were easy to resolve.
Branch committed at this stage

In working copy run:
svn switch svn+ssh://forge.ipsl.jussieu.fr/ipsl/forge/projets/nemo/svn/trunk
to switch working copy

Run:
svn merge --reintegrate svn+ssh://forge.ipsl.jussieu.fr/ipsl/forge/projets/nemo/svn/branches/2015/dev_merge_2015
to merge the branch into the trunk and then commit - no conflicts at this stage.

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