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

source: branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 8568

Last change on this file since 8568 was 8568, checked in by gm, 7 years ago

#1911 (ENHANCE-09): PART I.2 - _NONE option + remove zts + see associated wiki page

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