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

source: branches/UKMO/r8395_mix-lyr_diag/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 11290

Last change on this file since 11290 was 11290, checked in by jcastill, 5 years ago

Remove svn keywords

File size: 31.5 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( nn_timing == 1 )   CALL timing_finalize
139         CALL Agrif_ChildGrid_To_ParentGrid()
140      ENDIF
141#endif
142      IF( nn_timing == 1 )   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         &             nn_timing, nn_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( nn_timing == 1 )  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 activated    (0/1)       nn_timing  = ', nn_timing
404      ENDIF
405      !
406      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
407      nictls    = nn_ictls
408      nictle    = nn_ictle
409      njctls    = nn_jctls
410      njctle    = nn_jctle
411      isplt     = nn_isplt
412      jsplt     = nn_jsplt
413
414      IF(lwp) THEN                  ! control print
415         WRITE(numout,*)
416         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
417         WRITE(numout,*) '~~~~~~~ '
418         WRITE(numout,*) '   Namelist namcfg'
419         WRITE(numout,*) '      read domain configuration files               ln_read_cfg      = ', ln_read_cfg
420         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
421         WRITE(numout,*) '      write  configuration definition files         ln_write_cfg     = ', ln_write_cfg
422         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
423         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
424      ENDIF
425      !                             ! Parameter control
426      !
427      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
428         IF( lk_mpp .AND. jpnij > 1 ) THEN
429            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
430         ELSE
431            IF( isplt == 1 .AND. jsplt == 1  ) THEN
432               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
433                  &           ' - the print control will be done over the whole domain' )
434            ENDIF
435            ijsplt = isplt * jsplt            ! total number of processors ijsplt
436         ENDIF
437         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
438         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
439         !
440         !                              ! indices used for the SUM control
441         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
442            lsp_area = .FALSE.
443         ELSE                                             ! print control done over a specific  area
444            lsp_area = .TRUE.
445            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
446               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
447               nictls = 1
448            ENDIF
449            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
450               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
451               nictle = jpiglo
452            ENDIF
453            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
454               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
455               njctls = 1
456            ENDIF
457            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
458               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
459               njctle = jpjglo
460            ENDIF
461         ENDIF
462      ENDIF
463      !
464      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
465         &                                               'f2003 standard. '                              ,  &
466         &                                               'Compile with key_nosignedzero enabled' )
467      !
468   END SUBROUTINE nemo_ctl
469
470
471   SUBROUTINE nemo_closefile
472      !!----------------------------------------------------------------------
473      !!                     ***  ROUTINE nemo_closefile  ***
474      !!
475      !! ** Purpose :   Close the files
476      !!----------------------------------------------------------------------
477      !
478      IF( lk_mpp )   CALL mppsync
479      !
480      CALL iom_close                                 ! close all input/output files managed by iom_*
481      !
482      IF( numstp          /= -1 )   CLOSE( numstp      )   ! time-step file     
483      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
484      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
485      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
486      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
487      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
488      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
489      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
490      IF( numout          /=  6 )   CLOSE( numout      )   ! standard model output file
491      !
492      numout = 6                                     ! redefine numout in case it is used after this point...
493      !
494   END SUBROUTINE nemo_closefile
495
496
497   SUBROUTINE nemo_alloc
498      !!----------------------------------------------------------------------
499      !!                     ***  ROUTINE nemo_alloc  ***
500      !!
501      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
502      !!
503      !! ** Method  :
504      !!----------------------------------------------------------------------
505      USE diawri    , ONLY: dia_wri_alloc
506      USE dom_oce   , ONLY: dom_oce_alloc
507      USE bdy_oce   , ONLY: ln_bdy, bdy_oce_alloc
508      USE oce         ! clem: mandatory for LIM3 because needed for bdy arrays
509      !
510      INTEGER :: ierr
511      !!----------------------------------------------------------------------
512      !
513      ierr =        dia_wri_alloc   ()
514      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
515      ierr = ierr + oce_alloc       ()          ! (tsn...) needed for agrif and/or lim3 and bdy
516      ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
517      !
518      IF( lk_mpp    )   CALL mpp_sum( ierr )
519      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
520      !
521   END SUBROUTINE nemo_alloc
522
523
524   SUBROUTINE nemo_partition( num_pes )
525      !!----------------------------------------------------------------------
526      !!                 ***  ROUTINE nemo_partition  ***
527      !!
528      !! ** Purpose :   
529      !!
530      !! ** Method  :
531      !!----------------------------------------------------------------------
532      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
533      !
534      INTEGER, PARAMETER :: nfactmax = 20
535      INTEGER :: nfact ! The no. of factors returned
536      INTEGER :: ierr  ! Error flag
537      INTEGER :: ji
538      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
539      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
540      !!----------------------------------------------------------------------
541      !
542      ierr = 0
543      !
544      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
545      !
546      IF( nfact <= 1 ) THEN
547         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
548         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
549         jpnj = 1
550         jpni = num_pes
551      ELSE
552         ! Search through factors for the pair that are closest in value
553         mindiff = 1000000
554         imin    = 1
555         DO ji = 1, nfact-1, 2
556            idiff = ABS( ifact(ji) - ifact(ji+1) )
557            IF( idiff < mindiff ) THEN
558               mindiff = idiff
559               imin = ji
560            ENDIF
561         END DO
562         jpnj = ifact(imin)
563         jpni = ifact(imin + 1)
564      ENDIF
565      !
566      jpnij = jpni*jpnj
567      !
568   END SUBROUTINE nemo_partition
569
570
571   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
572      !!----------------------------------------------------------------------
573      !!                     ***  ROUTINE factorise  ***
574      !!
575      !! ** Purpose :   return the prime factors of n.
576      !!                knfax factors are returned in array kfax which is of
577      !!                maximum dimension kmaxfax.
578      !! ** Method  :
579      !!----------------------------------------------------------------------
580      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
581      INTEGER                    , INTENT(  out) ::   kerr, knfax
582      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
583      !
584      INTEGER :: ifac, jl, inu
585      INTEGER, PARAMETER :: ntest = 14
586      INTEGER, DIMENSION(ntest) ::   ilfax
587      !!----------------------------------------------------------------------
588      !
589      ! lfax contains the set of allowed factors.
590      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
591      !
592      ! Clear the error flag and initialise output vars
593      kerr  = 0
594      kfax  = 1
595      knfax = 0
596      !
597      ! Find the factors of n.
598      IF( kn == 1 )   GOTO 20
599
600      ! nu holds the unfactorised part of the number.
601      ! knfax holds the number of factors found.
602      ! l points to the allowed factor list.
603      ! ifac holds the current factor.
604      !
605      inu   = kn
606      knfax = 0
607      !
608      DO jl = ntest, 1, -1
609         !
610         ifac = ilfax(jl)
611         IF( ifac > inu )   CYCLE
612
613         ! Test whether the factor will divide.
614
615         IF( MOD(inu,ifac) == 0 ) THEN
616            !
617            knfax = knfax + 1            ! Add the factor to the list
618            IF( knfax > kmaxfax ) THEN
619               kerr = 6
620               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
621               return
622            ENDIF
623            kfax(knfax) = ifac
624            ! Store the other factor that goes with this one
625            knfax = knfax + 1
626            kfax(knfax) = inu / ifac
627            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
628         ENDIF
629         !
630      END DO
631      !
632   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
633      !
634   END SUBROUTINE factorise
635
636#if defined key_mpp_mpi
637
638   SUBROUTINE nemo_northcomms
639      !!----------------------------------------------------------------------
640      !!                     ***  ROUTINE  nemo_northcomms  ***
641      !! ** Purpose :   Setup for north fold exchanges with explicit
642      !!                point-to-point messaging
643      !!
644      !! ** Method :   Initialization of the northern neighbours lists.
645      !!----------------------------------------------------------------------
646      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
647      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
648      !!----------------------------------------------------------------------
649      INTEGER  ::   sxM, dxM, sxT, dxT, jn
650      INTEGER  ::   njmppmax
651      !!----------------------------------------------------------------------
652      !
653      njmppmax = MAXVAL( njmppt )
654      !
655      !initializes the north-fold communication variables
656      isendto(:) = 0
657      nsndto     = 0
658      !
659      !if I am a process in the north
660      IF ( njmpp == njmppmax ) THEN
661          !sxM is the first point (in the global domain) needed to compute the
662          !north-fold for the current process
663          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
664          !dxM is the last point (in the global domain) needed to compute the
665          !north-fold for the current process
666          dxM = jpiglo - nimppt(narea) + 2
667
668          !loop over the other north-fold processes to find the processes
669          !managing the points belonging to the sxT-dxT range
670 
671          DO jn = 1, jpni
672                !sxT is the first point (in the global domain) of the jn
673                !process
674                sxT = nfiimpp(jn, jpnj)
675                !dxT is the last point (in the global domain) of the jn
676                !process
677                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
678                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
679                   nsndto = nsndto + 1
680                     isendto(nsndto) = jn
681                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
682                   nsndto = nsndto + 1
683                   isendto(nsndto) = jn
684                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
685                   nsndto = nsndto + 1
686                   isendto(nsndto) = jn
687                ENDIF
688          END DO
689          nfsloop = 1
690          nfeloop = nlci
691          DO jn = 2,jpni-1
692           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
693              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
694                 nfsloop = nldi
695              ENDIF
696              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
697                 nfeloop = nlei
698              ENDIF
699           ENDIF
700        END DO
701
702      ENDIF
703      l_north_nogather = .TRUE.
704   END SUBROUTINE nemo_northcomms
705
706#else
707   SUBROUTINE nemo_northcomms      ! Dummy routine
708      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
709   END SUBROUTINE nemo_northcomms
710#endif
711
712   !!======================================================================
713END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.