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/SAS_SRC – NEMO

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 9019

Last change on this file since 9019 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   !! StandAlone Surface module : surface fluxes + sea-ice + iceberg floats
5   !!======================================================================
6   !! History :  3.6  ! 2011-11  (S. Alderson, G. Madec) original code
7   !!             -   ! 2013-06  (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication
8   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
9   !!            4.0  ! 2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
14   !!   nemo_init     : initialization of the NEMO system
15   !!   nemo_ctl      : initialisation of the contol print
16   !!   nemo_closefile: close remaining open files
17   !!   nemo_alloc    : dynamical allocation
18   !!   nemo_partition: calculate MPP domain decomposition
19   !!   factorise     : calculate the factors of the no. of MPI processes
20   !!----------------------------------------------------------------------
21   USE step_oce       ! module used in the ocean time stepping module
22   USE sbc_oce        ! surface boundary condition: ocean
23   USE phycst         ! physical constant                  (par_cst routine)
24   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
25   USE usrdef_nam     ! user defined configuration
26   USE daymod         ! calendar
27   USE restart        ! open  restart file
28   USE step           ! NEMO time-stepping                 (stp     routine)
29   USE cpl_oasis3     !
30   USE sbcssm         !
31   USE icbini         ! handle bergs, initialisation
32   USE icbstp         ! handle bergs, calving, themodynamics and transport
33   USE bdyini         ! open boundary cond. setting       (bdy_init routine). mandatory for sea-ice
34   USE bdydta         ! open boundary cond. setting   (bdy_dta_init routine). mandatory for sea-ice
35   !
36   USE lib_mpp        ! distributed memory computing
37   USE mppini         ! shared/distributed memory setting (mpp_init routine)
38   USE lbcnfd   , ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
39   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
40#if defined key_iomput
41   USE xios           ! xIOserver
42#endif
43
44   IMPLICIT NONE
45   PRIVATE
46
47   PUBLIC   nemo_gcm    ! called by model.F90
48   PUBLIC   nemo_init   ! needed by AGRIF
49
50   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
51
52   !!----------------------------------------------------------------------
53   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
54   !! $Id$
55   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
56   !!----------------------------------------------------------------------
57CONTAINS
58
59   SUBROUTINE nemo_gcm
60      !!----------------------------------------------------------------------
61      !!                     ***  ROUTINE nemo_gcm  ***
62      !!
63      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
64      !!              curvilinear mesh on the sphere.
65      !!
66      !! ** Method  : - model general initialization
67      !!              - launch the time-stepping (stp routine)
68      !!              - finalize the run by closing files and communications
69      !!
70      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
71      !!              Madec, 2008, internal report, IPSL.
72      !!----------------------------------------------------------------------
73      INTEGER ::   istp   ! time step index
74      !!----------------------------------------------------------------------
75      !
76#if defined key_agrif
77     CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
78#endif
79      !
80      !                            !-----------------------!
81      CALL nemo_init               !==  Initialisations  ==!
82      !                            !-----------------------!
83#if defined key_agrif
84      CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
85      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA
86# if defined key_top
87      CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
88# endif
89# if defined key_lim3
90      CALL Agrif_Declare_Var_lim3  !  "      "   "   "      "  LIM3
91# endif
92#endif
93      ! check that all process are still there... If some process have an error,
94      ! they will never enter in step and other processes will wait until the end of the cpu time!
95      IF( lk_mpp )   CALL mpp_max( nstop )
96
97      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
98
99      !                            !-----------------------!
100      !                            !==   time stepping   ==!
101      !                            !-----------------------!
102      istp = nit000
103#if defined key_agrif
104      CALL Agrif_Regrid()
105#endif
106
107      DO WHILE ( istp <= nitend .AND. nstop == 0 )
108#if defined key_agrif
109         CALL stp                         ! AGRIF: time stepping
110#else
111         IF ( .NOT. ln_diurnal_only ) THEN
112            CALL stp( istp )                 ! standard time stepping
113         ELSE
114            CALL stp_diurnal( istp )        ! time step only the diurnal SST
115         ENDIF 
116#endif
117         istp = istp + 1
118         IF( lk_mpp )   CALL mpp_max( nstop )
119         END DO
120      !
121      IF( ln_icebergs )   CALL icb_end( nitend )
122
123      !                            !------------------------!
124      !                            !==  finalize the run  ==!
125      !                            !------------------------!
126      IF(lwp) WRITE(numout,cform_aaa)        ! Flag AAAAAAA
127      !
128      IF( nstop /= 0 .AND. lwp ) THEN        ! error print
129         WRITE(numout,cform_err)
130         WRITE(numout,*) nstop, ' error have been found'
131      ENDIF
132      !
133#if defined key_agrif
134         CALL Agrif_ParentGrid_To_ChildGrid()
135         IF( ln_timing )   CALL timing_finalize
136         CALL Agrif_ChildGrid_To_ParentGrid()
137#endif
138      IF( ln_timing )   CALL timing_finalize
139      !
140      CALL nemo_closefile
141      !
142#if defined key_iomput
143      CALL xios_finalize                     ! end mpp communications with xios
144      IF( lk_oasis )   CALL cpl_finalize     ! end coupling and mpp communications with OASIS
145#else
146      IF( lk_oasis ) THEN
147         CALL cpl_finalize                   ! end coupling and mpp communications with OASIS
148      ELSE
149         IF( lk_mpp )   CALL mppstop         ! end mpp communications
150      ENDIF
151#endif
152      !
153   END SUBROUTINE nemo_gcm
154
155
156   SUBROUTINE nemo_init
157      !!----------------------------------------------------------------------
158      !!                     ***  ROUTINE nemo_init  ***
159      !!
160      !! ** Purpose :   initialization of the NEMO GCM
161      !!----------------------------------------------------------------------
162      INTEGER  ::   ji            ! dummy loop indices
163      INTEGER  ::   ilocal_comm   ! local integer
164      INTEGER  ::   ios, inum     !   -      -
165      INTEGER  ::   iiarea, ijarea     ! local integers
166      INTEGER  ::   iirest, ijrest     ! local integers
167      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
168      CHARACTER(len=80)                 ::   clname
169      !
170      NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
171         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
172         &             ln_timing, ln_diacfl
173      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
174      !!----------------------------------------------------------------------
175      !
176      cltxt  = ''
177      cltxt2 = ''
178      clnam  = '' 
179      cxios_context = 'nemo'
180      !
181      !                             ! Open reference namelist and configuration namelist files
182      IF( lk_oasis ) THEN
183         CALL ctl_opn( numnam_ref, 'namelist_sas_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
184         CALL ctl_opn( numnam_cfg, 'namelist_sas_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
185         cxios_context = 'sas'
186         clname = 'output.namelist_sas.dyn'
187      ELSE
188         CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
189         CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
190         cxios_context = 'nemo'
191         clname = 'output.namelist.dyn'
192   ENDIF
193      !
194      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints
195      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
196901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
197      !
198      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
199      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
200902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
201      !
202      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints
203      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
204903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
205
206      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
207      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
208904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
209
210      !                             !--------------------------!
211      !                             !  Set global domain size  !   (control print return in cltxt2)
212      !                             !--------------------------!
213      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
214         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
215         !
216      ELSE                                ! user-defined namelist
217         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
218      ENDIF
219      !
220      !
221      !                             !--------------------------------------------!
222      !                             !  set communicator & select the local node  !
223      !                             !  NB: mynode also opens output.namelist.dyn !
224      !                             !      on unit number numond on first proc   !
225      !                             !--------------------------------------------!
226#if defined key_iomput
227      IF( Agrif_Root() ) THEN
228         IF( lk_oasis ) THEN
229            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis
230            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
231         ELSE
232            CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
233         ENDIF
234      ENDIF
235      narea = mynode ( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )  ! Nodes selection
236#else
237      IF( lk_oasis ) THEN
238         IF( Agrif_Root() ) THEN
239            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis
240         ENDIF
241         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
242      ELSE
243         ilocal_comm = 0
244         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
245      ENDIF
246#endif
247
248      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
249
250      lwm = (narea == 1)                                    ! control of output namelists
251      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
252
253      IF(lwm) THEN               ! write merged namelists from earlier to output namelist
254         !                       ! now that the file has been opened in call to mynode.
255         !                       ! NB: nammpp has already been written in mynode (if lk_mpp_mpi)
256         WRITE( numond, namctl )
257         WRITE( numond, namcfg )
258         IF( .NOT.ln_read_cfg ) THEN
259            DO ji = 1, SIZE(clnam)
260               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
261            END DO
262         ENDIF
263      ENDIF
264
265      ! If dimensions of processor grid weren't specified in the namelist file
266      ! then we calculate them here now that we have our communicator size
267      IF( jpni < 1 .OR. jpnj < 1 ) THEN
268#if   defined key_mpp_mpi
269         IF( Agrif_Root() )   CALL nemo_partition( mppsize )
270#else
271         jpni  = 1
272         jpnj  = 1
273         jpnij = jpni*jpnj
274#endif
275      ENDIF
276      !
277#if defined key_agrif
278      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
279         jpiglo  = nbcellsx + 2 + 2*nbghostcells
280         jpjglo  = nbcellsy + 2 + 2*nbghostcells
281         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
282         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
283         jpimax  = jpi
284         jpjmax  = jpj
285         nperio  = 0
286         jperio  = 0
287         ln_use_jattr = .false.
288      ENDIF
289#endif
290
291      IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
292         iiarea = 1 + MOD( narea - 1 , jpni )
293         ijarea = 1 + ( narea - 1 ) / jpni
294         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
295         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
296#if defined key_nemocice_decomp
297         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
298         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
299         jpimax  = jpi
300         jpjmax  = jpj
301         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
302         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
303#else
304         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
305         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
306         jpimax  = jpi
307         jpjmax  = jpj
308         IF( iiarea > iirest ) jpi = jpi - 1
309         IF( ijarea > ijrest ) jpj = jpj - 1
310#endif
311      ENDIF
312
313      jpk = jpkglo                                             ! third dim
314
315#if defined key_agrif
316      ! simple trick to use same vertical grid as parent but different number of levels:
317      ! Save maximum number of levels in jpkglo, then define all vertical grids with this number.
318      ! Suppress once vertical online interpolation is ok
319      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
320#endif
321      jpim1 = jpi-1                                            ! inner domain indices
322      jpjm1 = jpj-1                                            !   "           "
323      jpkm1 = MAX( 1, jpk-1 )                                  !   "           "
324      jpij  = jpi*jpj                                          !  jpi x j
325
326      IF(lwp) THEN                            ! open listing units
327         !
328         IF( lk_oasis ) THEN
329            CALL ctl_opn( numout,   'sas.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
330         ELSE
331            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
332         ENDIF
333         !
334         WRITE(numout,*)
335         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
336         WRITE(numout,*) '                       NEMO team'
337         WRITE(numout,*) '            Ocean General Circulation Model'
338         WRITE(numout,*) '                  version 3.7  (2016) '
339         WRITE(numout,*) '             StandAlone Surface version (SAS) '
340         WRITE(numout,*)
341         WRITE(numout,*)
342         DO ji = 1, SIZE(cltxt)
343            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) cltxt(ji)    ! control print of mynode
344         END DO
345         WRITE(numout,*)
346         WRITE(numout,*)
347         DO ji = 1, SIZE(cltxt2)
348            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)   ! control print of domain size
349         END DO
350         !
351         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
352         !
353      ENDIF
354
355      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
356      CALL nemo_alloc()
357      !                             !-------------------------------!
358      !                             !  NEMO general initialization  !
359      !                             !-------------------------------!
360
361      CALL nemo_ctl                          ! Control prints
362
363      !                                      ! Domain decomposition
364      CALL mpp_init
365      !
366      IF( ln_timing    )   CALL timing_init
367      !
368      !                                     ! General initialization
369                           CALL phy_cst    ! Physical constants
370                           CALL eos_init   ! Equation of state
371                           CALL dom_init   ! Domain
372
373     IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
374
375      IF( ln_ctl      )    CALL prt_ctl_init   ! Print control
376                           CALL day_init   ! model calendar (using both namelist and restart infos)
377      IF( ln_rstart )       CALL rst_read_open
378
379                           CALL sbc_init   ! Forcings : surface module
380
381      ! ==> clem: open boundaries init. is mandatory for sea-ice because ice BDY is not decoupled from 
382      !           the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules.
383      !           This is not clean and should be changed in the future.
384                           CALL bdy_init
385      ! ==>
386                           CALL icb_init( rdt, nit000)   ! initialise icebergs instance
387     
388      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
389      !
390   END SUBROUTINE nemo_init
391
392
393   SUBROUTINE nemo_ctl
394      !!----------------------------------------------------------------------
395      !!                     ***  ROUTINE nemo_ctl  ***
396      !!
397      !! ** Purpose :   control print setting
398      !!
399      !! ** Method  : - print namctl information and check some consistencies
400      !!----------------------------------------------------------------------
401      !
402      IF(lwp) THEN                  ! control print
403         WRITE(numout,*)
404         WRITE(numout,*) 'nemo_ctl: Control prints'
405         WRITE(numout,*) '~~~~~~~ '
406         WRITE(numout,*) '   Namelist namctl'
407         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
408         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
409         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
410         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
411         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
412         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
413         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
414         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
415         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
416         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
417      ENDIF
418      !
419      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
420      nictls    = nn_ictls
421      nictle    = nn_ictle
422      njctls    = nn_jctls
423      njctle    = nn_jctle
424      isplt     = nn_isplt
425      jsplt     = nn_jsplt
426!!gm to be remove at the end of the 2017 merge party
427      if( ln_timing ) then  ;  nn_timing = 1
428      else                  ;  nn_timing = 0
429      endif
430!!gm end
431
432      IF(lwp) THEN                  ! control print
433         WRITE(numout,*)
434         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
435         WRITE(numout,*) '~~~~~~~ '
436         WRITE(numout,*) '   Namelist namcfg'
437         WRITE(numout,*) '      read domain configuration files               ln_read_cfg      = ', ln_read_cfg
438         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
439         WRITE(numout,*) '      write  configuration definition files         ln_write_cfg     = ', ln_write_cfg
440         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
441         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
442      ENDIF
443      !                             ! Parameter control
444      !
445      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
446         IF( lk_mpp .AND. jpnij > 1 ) THEN
447            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
448         ELSE
449            IF( isplt == 1 .AND. jsplt == 1  ) THEN
450               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
451                  &           ' - the print control will be done over the whole domain' )
452            ENDIF
453            ijsplt = isplt * jsplt            ! total number of processors ijsplt
454         ENDIF
455         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
456         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
457         !
458         !                              ! indices used for the SUM control
459         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
460            lsp_area = .FALSE.
461         ELSE                                             ! print control done over a specific  area
462            lsp_area = .TRUE.
463            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
464               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
465               nictls = 1
466            ENDIF
467            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
468               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
469               nictle = jpiglo
470            ENDIF
471            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
472               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
473               njctls = 1
474            ENDIF
475            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
476               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
477               njctle = jpjglo
478            ENDIF
479         ENDIF
480      ENDIF
481      !
482      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
483         &                                               'f2003 standard. '                              ,  &
484         &                                               'Compile with key_nosignedzero enabled' )
485      !
486   END SUBROUTINE nemo_ctl
487
488
489   SUBROUTINE nemo_closefile
490      !!----------------------------------------------------------------------
491      !!                     ***  ROUTINE nemo_closefile  ***
492      !!
493      !! ** Purpose :   Close the files
494      !!----------------------------------------------------------------------
495      !
496      IF( lk_mpp )   CALL mppsync
497      !
498      CALL iom_close                                 ! close all input/output files managed by iom_*
499      !
500      IF( numstp          /= -1 )   CLOSE( numstp      )   ! time-step file     
501      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
502      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
503      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
504      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
505      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
506      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
507      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
508      IF( numout          /=  6 )   CLOSE( numout      )   ! standard model output file
509      !
510      numout = 6                                     ! redefine numout in case it is used after this point...
511      !
512   END SUBROUTINE nemo_closefile
513
514
515   SUBROUTINE nemo_alloc
516      !!----------------------------------------------------------------------
517      !!                     ***  ROUTINE nemo_alloc  ***
518      !!
519      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
520      !!
521      !! ** Method  :
522      !!----------------------------------------------------------------------
523      USE diawri    , ONLY: dia_wri_alloc
524      USE dom_oce   , ONLY: dom_oce_alloc
525      USE bdy_oce   , ONLY: ln_bdy, bdy_oce_alloc
526      USE oce       ! mandatory for sea-ice because needed for bdy arrays
527      !
528      INTEGER :: ierr
529      !!----------------------------------------------------------------------
530      !
531      ierr =        dia_wri_alloc   ()
532      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
533      ierr = ierr + oce_alloc       ()          ! (tsn...) needed for agrif and/or ESIM and bdy
534      ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
535      !
536      IF( lk_mpp    )   CALL mpp_sum( ierr )
537      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
538      !
539   END SUBROUTINE nemo_alloc
540
541
542   SUBROUTINE nemo_partition( num_pes )
543      !!----------------------------------------------------------------------
544      !!                 ***  ROUTINE nemo_partition  ***
545      !!
546      !! ** Purpose :   
547      !!
548      !! ** Method  :
549      !!----------------------------------------------------------------------
550      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
551      !
552      INTEGER, PARAMETER :: nfactmax = 20
553      INTEGER :: nfact ! The no. of factors returned
554      INTEGER :: ierr  ! Error flag
555      INTEGER :: ji
556      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
557      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
558      !!----------------------------------------------------------------------
559      !
560      ierr = 0
561      !
562      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
563      !
564      IF( nfact <= 1 ) THEN
565         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
566         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
567         jpnj = 1
568         jpni = num_pes
569      ELSE
570         ! Search through factors for the pair that are closest in value
571         mindiff = 1000000
572         imin    = 1
573         DO ji = 1, nfact-1, 2
574            idiff = ABS( ifact(ji) - ifact(ji+1) )
575            IF( idiff < mindiff ) THEN
576               mindiff = idiff
577               imin = ji
578            ENDIF
579         END DO
580         jpnj = ifact(imin)
581         jpni = ifact(imin + 1)
582      ENDIF
583      !
584      jpnij = jpni*jpnj
585      !
586   END SUBROUTINE nemo_partition
587
588
589   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
590      !!----------------------------------------------------------------------
591      !!                     ***  ROUTINE factorise  ***
592      !!
593      !! ** Purpose :   return the prime factors of n.
594      !!                knfax factors are returned in array kfax which is of
595      !!                maximum dimension kmaxfax.
596      !! ** Method  :
597      !!----------------------------------------------------------------------
598      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
599      INTEGER                    , INTENT(  out) ::   kerr, knfax
600      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
601      !
602      INTEGER :: ifac, jl, inu
603      INTEGER, PARAMETER :: ntest = 14
604      INTEGER, DIMENSION(ntest) ::   ilfax
605      !!----------------------------------------------------------------------
606      !
607      ! lfax contains the set of allowed factors.
608      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
609      !
610      ! Clear the error flag and initialise output vars
611      kerr  = 0
612      kfax  = 1
613      knfax = 0
614      !
615      ! Find the factors of n.
616      IF( kn .NE. 1 ) THEN
617
618         ! nu holds the unfactorised part of the number.
619         ! knfax holds the number of factors found.
620         ! l points to the allowed factor list.
621         ! ifac holds the current factor.
622         !
623         inu   = kn
624         knfax = 0
625         !
626         DO jl = ntest, 1, -1
627            !
628            ifac = ilfax(jl)
629            IF( ifac > inu )   CYCLE
630   
631            ! Test whether the factor will divide.
632   
633            IF( MOD(inu,ifac) == 0 ) THEN
634               !
635               knfax = knfax + 1            ! Add the factor to the list
636               IF( knfax > kmaxfax ) THEN
637                  kerr = 6
638                  write (*,*) 'FACTOR: insufficient space in factor array ', knfax
639                  return
640               ENDIF
641               kfax(knfax) = ifac
642               ! Store the other factor that goes with this one
643               knfax = knfax + 1
644               kfax(knfax) = inu / ifac
645               !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
646            ENDIF
647            !
648         END DO
649         !
650      ENDIF
651      !
652   END SUBROUTINE factorise
653
654#if defined key_mpp_mpi
655
656   SUBROUTINE nemo_northcomms
657      !!----------------------------------------------------------------------
658      !!                     ***  ROUTINE  nemo_northcomms  ***
659      !! ** Purpose :   Setup for north fold exchanges with explicit
660      !!                point-to-point messaging
661      !!
662      !! ** Method :   Initialization of the northern neighbours lists.
663      !!----------------------------------------------------------------------
664      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
665      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
666      !!----------------------------------------------------------------------
667      INTEGER  ::   sxM, dxM, sxT, dxT, jn
668      INTEGER  ::   njmppmax
669      !!----------------------------------------------------------------------
670      !
671      njmppmax = MAXVAL( njmppt )
672      !
673      !initializes the north-fold communication variables
674      isendto(:) = 0
675      nsndto     = 0
676      !
677      !if I am a process in the north
678      IF ( njmpp == njmppmax ) THEN
679          !sxM is the first point (in the global domain) needed to compute the
680          !north-fold for the current process
681          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
682          !dxM is the last point (in the global domain) needed to compute the
683          !north-fold for the current process
684          dxM = jpiglo - nimppt(narea) + 2
685
686          !loop over the other north-fold processes to find the processes
687          !managing the points belonging to the sxT-dxT range
688 
689          DO jn = 1, jpni
690                !sxT is the first point (in the global domain) of the jn
691                !process
692                sxT = nfiimpp(jn, jpnj)
693                !dxT is the last point (in the global domain) of the jn
694                !process
695                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
696                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
697                   nsndto = nsndto + 1
698                     isendto(nsndto) = jn
699                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
700                   nsndto = nsndto + 1
701                   isendto(nsndto) = jn
702                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
703                   nsndto = nsndto + 1
704                   isendto(nsndto) = jn
705                ENDIF
706          END DO
707          nfsloop = 1
708          nfeloop = nlci
709          DO jn = 2,jpni-1
710           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
711              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
712                 nfsloop = nldi
713              ENDIF
714              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
715                 nfeloop = nlei
716              ENDIF
717           ENDIF
718        END DO
719
720      ENDIF
721      l_north_nogather = .TRUE.
722   END SUBROUTINE nemo_northcomms
723
724#else
725   SUBROUTINE nemo_northcomms      ! Dummy routine
726      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
727   END SUBROUTINE nemo_northcomms
728#endif
729
730   !!======================================================================
731END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.