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

source: trunk/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 8583

Last change on this file since 8583 was 8583, checked in by cbricaud, 7 years ago

fix ticket #1944 in trunk ( SAS restartability)

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