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

source: branches/2017/dev_CNRS_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 8885

Last change on this file since 8885 was 8885, checked in by clem, 6 years ago

remove useless references to clem's comments

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