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

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

dev_merge_2017: nemogcm.F90 : updated in SAS & OFF + data assimilation initial calls (asm_bkg_wri , tra_asm_inc ...) moved to asm_inc_init + closed sea : restructure namcfg & its control print + set ln_closea = false if domcfg file not read (ln_domcfg=F

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