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

source: branches/UKMO/dev_r8126_LIM3_couple/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 8879

Last change on this file since 8879 was 8879, checked in by frrh, 6 years ago

Merge in http://fcm3/projects/NEMO.xm/log/branches/UKMO/dev_r8183_ICEMODEL_svn_removed
revisions 8738:8847 inclusive.

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