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

Last change on this file since 9169 was 9169, checked in by gm, 6 years ago

dev_merge_2017: all SRC: finalize the removal of useless warning when reading namelist_cfg + remove all nn_closea + nn_msh replaced by a logical

  • Property svn:keywords set to Id
File size: 32.1 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      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
198      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
199902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
200      !
201      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints
202      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
203903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
204      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
205      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
206904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
207
208      !                             !--------------------------!
209      !                             !  Set global domain size  !   (control print return in cltxt2)
210      !                             !--------------------------!
211      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
212         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
213         !
214      ELSE                                ! user-defined namelist
215         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
216      ENDIF
217      !
218      !
219      !                             !--------------------------------------------!
220      !                             !  set communicator & select the local node  !
221      !                             !  NB: mynode also opens output.namelist.dyn !
222      !                             !      on unit number numond on first proc   !
223      !                             !--------------------------------------------!
224#if defined key_iomput
225      IF( Agrif_Root() ) THEN
226         IF( lk_oasis ) THEN
227            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis
228            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
229         ELSE
230            CALL xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
231         ENDIF
232      ENDIF
233      narea = mynode ( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )  ! Nodes selection
234#else
235      IF( lk_oasis ) THEN
236         IF( Agrif_Root() ) THEN
237            CALL cpl_init( "sas", ilocal_comm )                          ! nemo local communicator given by oasis
238         ENDIF
239         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
240      ELSE
241         ilocal_comm = 0
242         narea = mynode( cltxt, clname, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
243      ENDIF
244#endif
245
246      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
247
248      lwm = (narea == 1)                                    ! control of output namelists
249      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
250
251      IF(lwm) THEN               ! write merged namelists from earlier to output namelist
252         !                       ! now that the file has been opened in call to mynode.
253         !                       ! NB: nammpp has already been written in mynode (if lk_mpp_mpi)
254         WRITE( numond, namctl )
255         WRITE( numond, namcfg )
256         IF( .NOT.ln_read_cfg ) THEN
257            DO ji = 1, SIZE(clnam)
258               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
259            END DO
260         ENDIF
261      ENDIF
262
263      ! If dimensions of processor grid weren't specified in the namelist file
264      ! then we calculate them here now that we have our communicator size
265      IF( jpni < 1 .OR. jpnj < 1 ) THEN
266#if   defined key_mpp_mpi
267         IF( Agrif_Root() )   CALL nemo_partition( mppsize )
268#else
269         jpni  = 1
270         jpnj  = 1
271         jpnij = jpni*jpnj
272#endif
273      ENDIF
274      !
275#if defined key_agrif
276      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
277         jpiglo  = nbcellsx + 2 + 2*nbghostcells
278         jpjglo  = nbcellsy + 2 + 2*nbghostcells
279         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
280         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
281         jpimax  = jpi
282         jpjmax  = jpj
283         nperio  = 0
284         jperio  = 0
285         ln_use_jattr = .false.
286      ENDIF
287#endif
288
289      IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
290         iiarea = 1 + MOD( narea - 1 , jpni )
291         ijarea = 1 + ( narea - 1 ) / jpni
292         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
293         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
294#if defined key_nemocice_decomp
295         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
296         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
297         jpimax  = jpi
298         jpjmax  = jpj
299         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
300         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
301#else
302         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
303         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
304         jpimax  = jpi
305         jpjmax  = jpj
306         IF( iiarea > iirest ) jpi = jpi - 1
307         IF( ijarea > ijrest ) jpj = jpj - 1
308#endif
309      ENDIF
310
311      jpk = jpkglo                                             ! third dim
312
313#if defined key_agrif
314      ! simple trick to use same vertical grid as parent but different number of levels:
315      ! Save maximum number of levels in jpkglo, then define all vertical grids with this number.
316      ! Suppress once vertical online interpolation is ok
317      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
318#endif
319      jpim1 = jpi-1                                            ! inner domain indices
320      jpjm1 = jpj-1                                            !   "           "
321      jpkm1 = MAX( 1, jpk-1 )                                  !   "           "
322      jpij  = jpi*jpj                                          !  jpi x j
323
324      IF(lwp) THEN                            ! open listing units
325         !
326         IF( lk_oasis ) THEN
327            CALL ctl_opn( numout,   'sas.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
328         ELSE
329            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
330         ENDIF
331         !
332         WRITE(numout,*)
333         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
334         WRITE(numout,*) '                       NEMO team'
335         WRITE(numout,*) '            Ocean General Circulation Model'
336         WRITE(numout,*) '                  version 3.7  (2016) '
337         WRITE(numout,*) '             StandAlone Surface version (SAS) '
338         WRITE(numout,*)
339         WRITE(numout,*)
340         DO ji = 1, SIZE(cltxt)
341            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) cltxt(ji)    ! control print of mynode
342         END DO
343         WRITE(numout,*)
344         WRITE(numout,*)
345         DO ji = 1, SIZE(cltxt2)
346            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)   ! control print of domain size
347         END DO
348         !
349         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
350         !
351      ENDIF
352
353      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
354      CALL nemo_alloc()
355      !                             !-------------------------------!
356      !                             !  NEMO general initialization  !
357      !                             !-------------------------------!
358
359      CALL nemo_ctl                          ! Control prints
360
361      !                                      ! Domain decomposition
362      CALL mpp_init
363      !
364      IF( ln_timing    )   CALL timing_init
365      !
366      !                                     ! General initialization
367                           CALL phy_cst    ! Physical constants
368                           CALL eos_init   ! Equation of state
369                           CALL dom_init   ! Domain
370
371     IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
372
373      IF( ln_ctl      )    CALL prt_ctl_init   ! Print control
374                           CALL day_init   ! model calendar (using both namelist and restart infos)
375      IF( ln_rstart )       CALL rst_read_open
376
377                           CALL sbc_init   ! Forcings : surface module
378
379      ! ==> clem: open boundaries init. is mandatory for sea-ice because ice BDY is not decoupled from 
380      !           the environment of ocean BDY. Therefore bdy is called in both OPA and SAS modules.
381      !           This is not clean and should be changed in the future.
382                           CALL bdy_init
383      ! ==>
384                           CALL icb_init( rdt, nit000)   ! initialise icebergs instance
385     
386      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
387      !
388   END SUBROUTINE nemo_init
389
390
391   SUBROUTINE nemo_ctl
392      !!----------------------------------------------------------------------
393      !!                     ***  ROUTINE nemo_ctl  ***
394      !!
395      !! ** Purpose :   control print setting
396      !!
397      !! ** Method  : - print namctl information and check some consistencies
398      !!----------------------------------------------------------------------
399      !
400      IF(lwp) THEN                  ! control print
401         WRITE(numout,*)
402         WRITE(numout,*) 'nemo_ctl: Control prints'
403         WRITE(numout,*) '~~~~~~~ '
404         WRITE(numout,*) '   Namelist namctl'
405         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
406         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
407         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
408         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
409         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
410         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
411         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
412         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
413         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
414         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
415      ENDIF
416      !
417      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
418      nictls    = nn_ictls
419      nictle    = nn_ictle
420      njctls    = nn_jctls
421      njctle    = nn_jctle
422      isplt     = nn_isplt
423      jsplt     = nn_jsplt
424
425      IF(lwp) THEN                  ! control print
426         WRITE(numout,*)
427         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
428         WRITE(numout,*) '~~~~~~~ '
429         WRITE(numout,*) '   Namelist namcfg'
430         WRITE(numout,*) '      read domain configuration files               ln_read_cfg      = ', ln_read_cfg
431         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
432         WRITE(numout,*) '      write  configuration definition files         ln_write_cfg     = ', ln_write_cfg
433         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
434         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
435      ENDIF
436      !                             ! Parameter control
437      !
438      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
439         IF( lk_mpp .AND. jpnij > 1 ) THEN
440            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
441         ELSE
442            IF( isplt == 1 .AND. jsplt == 1  ) THEN
443               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
444                  &           ' - the print control will be done over the whole domain' )
445            ENDIF
446            ijsplt = isplt * jsplt            ! total number of processors ijsplt
447         ENDIF
448         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
449         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
450         !
451         !                              ! indices used for the SUM control
452         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
453            lsp_area = .FALSE.
454         ELSE                                             ! print control done over a specific  area
455            lsp_area = .TRUE.
456            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
457               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
458               nictls = 1
459            ENDIF
460            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
461               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
462               nictle = jpiglo
463            ENDIF
464            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
465               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
466               njctls = 1
467            ENDIF
468            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
469               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
470               njctle = jpjglo
471            ENDIF
472         ENDIF
473      ENDIF
474      !
475      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
476         &                                               'f2003 standard. '                              ,  &
477         &                                               'Compile with key_nosignedzero enabled' )
478      !
479   END SUBROUTINE nemo_ctl
480
481
482   SUBROUTINE nemo_closefile
483      !!----------------------------------------------------------------------
484      !!                     ***  ROUTINE nemo_closefile  ***
485      !!
486      !! ** Purpose :   Close the files
487      !!----------------------------------------------------------------------
488      !
489      IF( lk_mpp )   CALL mppsync
490      !
491      CALL iom_close                                 ! close all input/output files managed by iom_*
492      !
493      IF( numstp          /= -1 )   CLOSE( numstp      )   ! time-step file     
494      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
495      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
496      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
497      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
498      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
499      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
500      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
501      IF( numout          /=  6 )   CLOSE( numout      )   ! standard model output file
502      !
503      numout = 6                                     ! redefine numout in case it is used after this point...
504      !
505   END SUBROUTINE nemo_closefile
506
507
508   SUBROUTINE nemo_alloc
509      !!----------------------------------------------------------------------
510      !!                     ***  ROUTINE nemo_alloc  ***
511      !!
512      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
513      !!
514      !! ** Method  :
515      !!----------------------------------------------------------------------
516      USE diawri    , ONLY: dia_wri_alloc
517      USE dom_oce   , ONLY: dom_oce_alloc
518      USE bdy_oce   , ONLY: ln_bdy, bdy_oce_alloc
519      USE oce       ! mandatory for sea-ice because needed for bdy arrays
520      !
521      INTEGER :: ierr
522      !!----------------------------------------------------------------------
523      !
524      ierr =        dia_wri_alloc   ()
525      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
526      ierr = ierr + oce_alloc       ()          ! (tsn...) needed for agrif and/or ESIM and bdy
527      ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
528      !
529      IF( lk_mpp    )   CALL mpp_sum( ierr )
530      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
531      !
532   END SUBROUTINE nemo_alloc
533
534
535   SUBROUTINE nemo_partition( num_pes )
536      !!----------------------------------------------------------------------
537      !!                 ***  ROUTINE nemo_partition  ***
538      !!
539      !! ** Purpose :   
540      !!
541      !! ** Method  :
542      !!----------------------------------------------------------------------
543      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
544      !
545      INTEGER, PARAMETER :: nfactmax = 20
546      INTEGER :: nfact ! The no. of factors returned
547      INTEGER :: ierr  ! Error flag
548      INTEGER :: ji
549      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
550      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
551      !!----------------------------------------------------------------------
552      !
553      ierr = 0
554      !
555      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
556      !
557      IF( nfact <= 1 ) THEN
558         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
559         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
560         jpnj = 1
561         jpni = num_pes
562      ELSE
563         ! Search through factors for the pair that are closest in value
564         mindiff = 1000000
565         imin    = 1
566         DO ji = 1, nfact-1, 2
567            idiff = ABS( ifact(ji) - ifact(ji+1) )
568            IF( idiff < mindiff ) THEN
569               mindiff = idiff
570               imin = ji
571            ENDIF
572         END DO
573         jpnj = ifact(imin)
574         jpni = ifact(imin + 1)
575      ENDIF
576      !
577      jpnij = jpni*jpnj
578      !
579   END SUBROUTINE nemo_partition
580
581
582   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
583      !!----------------------------------------------------------------------
584      !!                     ***  ROUTINE factorise  ***
585      !!
586      !! ** Purpose :   return the prime factors of n.
587      !!                knfax factors are returned in array kfax which is of
588      !!                maximum dimension kmaxfax.
589      !! ** Method  :
590      !!----------------------------------------------------------------------
591      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
592      INTEGER                    , INTENT(  out) ::   kerr, knfax
593      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
594      !
595      INTEGER :: ifac, jl, inu
596      INTEGER, PARAMETER :: ntest = 14
597      INTEGER, DIMENSION(ntest) ::   ilfax
598      !!----------------------------------------------------------------------
599      !
600      ! lfax contains the set of allowed factors.
601      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
602      !
603      ! Clear the error flag and initialise output vars
604      kerr  = 0
605      kfax  = 1
606      knfax = 0
607      !
608      ! Find the factors of n.
609      IF( kn .NE. 1 ) THEN
610
611         ! nu holds the unfactorised part of the number.
612         ! knfax holds the number of factors found.
613         ! l points to the allowed factor list.
614         ! ifac holds the current factor.
615         !
616         inu   = kn
617         knfax = 0
618         !
619         DO jl = ntest, 1, -1
620            !
621            ifac = ilfax(jl)
622            IF( ifac > inu )   CYCLE
623   
624            ! Test whether the factor will divide.
625   
626            IF( MOD(inu,ifac) == 0 ) THEN
627               !
628               knfax = knfax + 1            ! Add the factor to the list
629               IF( knfax > kmaxfax ) THEN
630                  kerr = 6
631                  write (*,*) 'FACTOR: insufficient space in factor array ', knfax
632                  return
633               ENDIF
634               kfax(knfax) = ifac
635               ! Store the other factor that goes with this one
636               knfax = knfax + 1
637               kfax(knfax) = inu / ifac
638               !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
639            ENDIF
640            !
641         END DO
642         !
643      ENDIF
644      !
645   END SUBROUTINE factorise
646
647#if defined key_mpp_mpi
648
649   SUBROUTINE nemo_northcomms
650      !!----------------------------------------------------------------------
651      !!                     ***  ROUTINE  nemo_northcomms  ***
652      !! ** Purpose :   Setup for north fold exchanges with explicit
653      !!                point-to-point messaging
654      !!
655      !! ** Method :   Initialization of the northern neighbours lists.
656      !!----------------------------------------------------------------------
657      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
658      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
659      !!----------------------------------------------------------------------
660      INTEGER  ::   sxM, dxM, sxT, dxT, jn
661      INTEGER  ::   njmppmax
662      !!----------------------------------------------------------------------
663      !
664      njmppmax = MAXVAL( njmppt )
665      !
666      !initializes the north-fold communication variables
667      isendto(:) = 0
668      nsndto     = 0
669      !
670      !if I am a process in the north
671      IF ( njmpp == njmppmax ) THEN
672          !sxM is the first point (in the global domain) needed to compute the
673          !north-fold for the current process
674          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
675          !dxM is the last point (in the global domain) needed to compute the
676          !north-fold for the current process
677          dxM = jpiglo - nimppt(narea) + 2
678
679          !loop over the other north-fold processes to find the processes
680          !managing the points belonging to the sxT-dxT range
681 
682          DO jn = 1, jpni
683                !sxT is the first point (in the global domain) of the jn
684                !process
685                sxT = nfiimpp(jn, jpnj)
686                !dxT is the last point (in the global domain) of the jn
687                !process
688                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
689                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
690                   nsndto = nsndto + 1
691                     isendto(nsndto) = jn
692                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
693                   nsndto = nsndto + 1
694                   isendto(nsndto) = jn
695                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
696                   nsndto = nsndto + 1
697                   isendto(nsndto) = jn
698                ENDIF
699          END DO
700          nfsloop = 1
701          nfeloop = nlci
702          DO jn = 2,jpni-1
703           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
704              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
705                 nfsloop = nldi
706              ENDIF
707              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
708                 nfeloop = nlei
709              ENDIF
710           ENDIF
711        END DO
712
713      ENDIF
714      l_north_nogather = .TRUE.
715   END SUBROUTINE nemo_northcomms
716
717#else
718   SUBROUTINE nemo_northcomms      ! Dummy routine
719      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
720   END SUBROUTINE nemo_northcomms
721#endif
722
723   !!======================================================================
724END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.