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

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 9119

Last change on this file since 9119 was 9019, checked in by timgraham, 6 years ago

Merge of dev_CNRS_2017 into branch

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