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/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/SAO_SRC – NEMO

source: branches/2016/dev_r6409_SIMPLIF_2_usrdef/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90 @ 6982

Last change on this file since 6982 was 6982, checked in by flavoni, 8 years ago

update SETTE, SAS, AMM12 and namelists to run simplif-2 branch

  • Property svn:keywords set to Id
File size: 30.3 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
11   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
12   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
15   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
16   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
17   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
18   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
19   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
20   !!             -   ! 2004-08  (C. Talandier) New trends organization
21   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
22   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
23   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
24   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
25   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
26   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
29   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!            3.4  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) add nemo_northcomms
31   !!             -   ! 2011-11  (C. Harris) decomposition changes for running with CICE
32   !!            3.6  ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening
33   !!             -   ! 2013-06  (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication
34   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
35   !!----------------------------------------------------------------------
36
37   !!----------------------------------------------------------------------
38   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
39   !!   nemo_init      : initialization of the NEMO system
40   !!   nemo_ctl       : initialisation of the contol print
41   !!   nemo_closefile : close remaining open files
42   !!   nemo_alloc     : dynamical allocation
43   !!   nemo_partition : calculate MPP domain decomposition
44   !!   factorise      : calculate the factors of the no. of MPI processes
45   !!----------------------------------------------------------------------
46   USE step_oce       ! module used in the ocean time stepping module (step.F90)
47   USE domcfg         ! domain configuration               (dom_cfg routine)
48   USE mppini         ! shared/distributed memory setting (mpp_init routine)
49   USE domain         ! domain initialization             (dom_init routine)
50#if defined key_nemocice_decomp
51   USE ice_domain_size, only: nx_global, ny_global
52#endif
53   USE istate          ! initial state setting          (istate_init routine)
54   USE phycst          ! physical constant                  (par_cst routine)
55   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
56   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
57   USE step            ! NEMO time-stepping                 (stp     routine)
58   USE cpl_oasis3      ! OASIS3 coupling
59   USE lib_mpp         ! distributed memory computing
60#if defined key_iomput
61   USE xios           ! xIOserver
62#endif
63   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
64
65   ! Stand Alone Observation operator modules
66   USE sao_data
67   USE sao_intp
68
69   IMPLICIT NONE
70   PRIVATE
71
72   PUBLIC   nemo_gcm    ! called by model.F90
73   PUBLIC   nemo_init   ! needed by AGRIF
74   PUBLIC   nemo_alloc  ! needed by TAM
75
76   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
77
78   !!----------------------------------------------------------------------
79   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
80   !! $Id$
81   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
82   !!----------------------------------------------------------------------
83CONTAINS
84
85   SUBROUTINE nemo_gcm
86         !!----------------------------------------------------------------------
87         !!                    ***  SUBROUTINE offline_obs_oper ***
88         !!
89         !! ** Purpose : To use NEMO components to interpolate model fields
90         !!              to observation space.
91         !!
92         !! ** Method : 1. Initialise NEMO
93         !!             2. Initialise offline obs_oper
94         !!             3. Cycle through match ups
95         !!             4. Write results to file
96         !!
97         !!----------------------------------------------------------------------
98         !! Initialise NEMO
99         CALL nemo_init
100         !! Initialise Stand Alone Observation operator data
101         CALL sao_data_init
102         !! Initialise obs_oper
103         CALL dia_obs_init
104         !! Interpolate to observation space
105         CALL sao_interp
106         !! Pipe to output files
107         CALL dia_obs_wri
108         !! Reset the obs_oper between
109         CALL dia_obs_dealloc
110         !! Safely stop MPI
111         IF(lk_mpp) CALL mppstop  ! end mpp communications
112   END SUBROUTINE nemo_gcm
113
114
115   SUBROUTINE nemo_init
116      !!----------------------------------------------------------------------
117      !!                     ***  ROUTINE nemo_init  ***
118      !!
119      !! ** Purpose :   initialization of the NEMO GCM
120      !!----------------------------------------------------------------------
121      INTEGER ::   ji            ! dummy loop indices
122      INTEGER ::   ilocal_comm   ! local integer
123      INTEGER ::   ios
124!!gm      CHARACTER(len=80), DIMENSION(16) ::   cltxt
125      CHARACTER(len=80), DIMENSION(-10:16) ::   cltxt
126      !
127      NAMELIST/namctl/ ln_ctl, nn_print, nn_ictls, nn_ictle,   &
128         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
129         &             nn_timing, nn_diacfl
130      NAMELIST/namcfg/ ln_read_cfg, ln_write_cfg, cp_cfg, jp_cfg, ln_use_jattr
131      !!----------------------------------------------------------------------
132      !
133      cltxt = ''
134      cxios_context = 'nemo'
135      !
136      !                             ! Open reference namelist and configuration namelist files
137      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
138      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
139      !
140      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
141      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
142901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
143
144      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
145      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
146902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
147
148      !
149      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
150      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
151903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
152
153      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
154      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
155904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
156
157!!gm      WRITE(clbug(3),*) ' after namelist namcfg read    nstop', nstop
158
159      !                             !--------------------------!
160      !                             !  Set global domain size  !   (control print return in cltxt2)
161      !                             !--------------------------!
162      IF( ln_read_cfg ) THEN              ! Read sizes in configuration "mesh_mask" file
163         CALL iom_open( 'domain_cfg', inum )
164         CALL iom_get( inum, 'jpiglo', ziglo  )   ;   jpiglo = INT( ziglo )
165         CALL iom_get( inum, 'jpjglo', zjglo  )   ;   jpjglo = INT( zjglo )
166         CALL iom_get( inum, 'jpkglo', zkglo  )   ;   jpkglo = INT( zkglo )
167         CALL iom_get( inum, 'jperio', zperio )   ;   jperio = INT( zperio )
168         CALL iom_close( inum )
169         WRITE(cltxt2(1),*)       
170         WRITE(cltxt2(2),*) 'domain_cfg : domain size read in "domain_cfg" file : jp(i,j,k)glo = ', jpiglo, jpjglo, jpkglo       
171         WRITE(cltxt2(3),*) '~~~~~~~~~~   lateral boudary type of the global domain      jperio= ', jperio
172         !       
173      ELSE                                ! user-defined namelist
174         CALL usr_def_nam( cltxt2, clnam, jpiglo, jpjglo, jpkglo, jperio )
175      ENDIF
176      jpk    = jpkglo
177      !
178#if defined key_agrif
179      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
180         jpiglo  = nbcellsx + 2 + 2*nbghostcells
181         jpjglo  = nbcellsy + 2 + 2*nbghostcells
182         jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
183         jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
184         nperio  = 0
185         jperio  = 0
186         ln_use_jattr = .false.
187      ENDIF
188#endif
189      !
190      !                             !--------------------------------------------!
191      !                             !  set communicator & select the local node  !
192      !                             !  NB: mynode also opens output.namelist.dyn !
193      !                             !      on unit number numond on first proc   !
194      !                             !--------------------------------------------!
195#if defined key_iomput
196      IF( Agrif_Root() ) THEN
197         IF( lk_oasis ) THEN
198            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
199            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
200         ELSE
201            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
202         ENDIF
203      ENDIF
204      ! Nodes selection (control print return in cltxt)
205      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
206#else
207      IF( lk_oasis ) THEN
208         IF( Agrif_Root() ) THEN
209            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
210         ENDIF
211         ! Nodes selection (control print return in cltxt)
212         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
213      ELSE
214         ilocal_comm = 0
215         ! Nodes selection (control print return in cltxt)
216         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
217      ENDIF
218#endif
219      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
220
221      lwm = (narea == 1)                                    ! control of output namelists
222      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
223
224      IF(lwm) THEN
225         ! write merged namelists from earlier to output namelist now that the
226         ! file has been opened in call to mynode. nammpp has already been
227         ! written in mynode (if lk_mpp_mpi)
228         WRITE( numond, namctl )
229         WRITE( numond, namcfg )
230         IF( .NOT.ln_read_cfg ) THEN
231            DO ji = 1, SIZE(clnam)
232               IF( TRIM(clnam (ji)) /= '' )   WRITE(numond, * ) clnam(ji)    ! namusr_def print
233            END DO
234         ENDIF
235      ENDIF
236
237      ! If dimensions of processor grid weren't specified in the namelist file
238      ! then we calculate them here now that we have our communicator size
239      IF( jpni < 1 .OR. jpnj < 1 ) THEN
240#if   defined key_mpp_mpi
241         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
242#else
243         jpni  = 1
244         jpnj  = 1
245         jpnij = jpni*jpnj
246#endif
247      ENDIF
248
249      ! Calculate domain dimensions given calculated jpni and jpnj
250      ! This used to be done in par_oce.F90 when they were parameters rather
251      ! than variables
252      IF( Agrif_Root() ) THEN
253#if defined key_nemocice_decomp
254         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first  dim.
255         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
256#else
257         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
258         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
259#endif
260      ENDIF
261
262!!gm ???    why here  it has already been done in line 301 !
263      jpk = jpkglo                                             ! third dim
264!!gm end
265      jpim1 = jpi-1                                            ! inner domain indices
266      jpjm1 = jpj-1                                            !   "           "
267      jpkm1 = jpk-1                                            !   "           "
268      jpij  = jpi*jpj                                          !  jpi x j
269
270      IF(lwp) THEN                            ! open listing units
271         !
272         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
273         !
274
275         DO ji = 1, SIZE(clbug)
276            IF( TRIM(clbug (ji)) /= '' )   WRITE(numout,*) clbug(ji)      ! bug print
277         END DO
278         WRITE(numout,*)
279
280
281
282
283         WRITE(numout,*)
284         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
285         WRITE(numout,*) '                       NEMO team'
286         WRITE(numout,*) '            Stand Alone Observation operator'
287         WRITE(numout,*) '                  version 1.0  (2015) '
288         WRITE(numout,*)
289         WRITE(numout,*)
290         DO ji = 1, SIZE(cltxt)
291            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
292         END DO
293         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
294         !
295      ENDIF
296
297      ! Now we know the dimensions of the grid and numout has been set we can
298      ! allocate arrays
299      CALL nemo_alloc()
300
301      !                             !-------------------------------!
302      !                             !  NEMO general initialization  !
303      !                             !-------------------------------!
304
305      CALL nemo_ctl                          ! Control prints & Benchmark
306
307      !                                      ! Domain decomposition
308      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
309      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
310      ENDIF
311      !
312      IF( nn_timing == 1 )  CALL timing_init
313      !
314      !                                      ! General initialization
315                            CALL     phy_cst    ! Physical constants
316                            CALL     eos_init   ! Equation of state
317                            CALL     dom_cfg    ! Domain configuration
318                            CALL     dom_init   ! Domain
319
320      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
321
322      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
323
324                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
325   END SUBROUTINE nemo_init
326
327
328   SUBROUTINE nemo_ctl
329      !!----------------------------------------------------------------------
330      !!                     ***  ROUTINE nemo_ctl  ***
331      !!
332      !! ** Purpose :   control print setting
333      !!
334      !! ** Method  : - print namctl information and check some consistencies
335      !!----------------------------------------------------------------------
336      !
337      IF(lwp) THEN                  ! control print
338         WRITE(numout,*)
339         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
340         WRITE(numout,*) '~~~~~~~ '
341         WRITE(numout,*) '   Namelist namctl'
342         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
343         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
344         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
345         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
346         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
347         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
348         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
349         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
350         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
351      ENDIF
352      !
353      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
354      nictls    = nn_ictls
355      nictle    = nn_ictle
356      njctls    = nn_jctls
357      njctle    = nn_jctle
358      isplt     = nn_isplt
359      jsplt     = nn_jsplt
360
361      IF(lwp) THEN                  ! control print
362         WRITE(numout,*)
363         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
364         WRITE(numout,*) '~~~~~~~ '
365         WRITE(numout,*) '   Namelist namcfg'
366         WRITE(numout,*) '      read configuration definition files          ln_read_cfg = ', ln_read_cfg
367         WRITE(numout,*) '      configuration name                               cp_cfg  = ', TRIM(cp_cfg)
368         WRITE(numout,*) '      configuration resolution                         jp_cfg  = ', jp_cfg
369         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
370      ENDIF
371      !                             ! Parameter control
372      !
373      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
374         IF( lk_mpp .AND. jpnij > 1 ) THEN
375            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
376         ELSE
377            IF( isplt == 1 .AND. jsplt == 1  ) THEN
378               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
379                  &           ' - the print control will be done over the whole domain' )
380            ENDIF
381            ijsplt = isplt * jsplt            ! total number of processors ijsplt
382         ENDIF
383         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
384         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
385         !
386         !                              ! indices used for the SUM control
387         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
388            lsp_area = .FALSE.
389         ELSE                                             ! print control done over a specific  area
390            lsp_area = .TRUE.
391            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
392               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
393               nictls = 1
394            ENDIF
395            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
396               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
397               nictle = jpiglo
398            ENDIF
399            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
400               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
401               njctls = 1
402            ENDIF
403            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
404               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
405               njctle = jpjglo
406            ENDIF
407         ENDIF
408      ENDIF
409      !
410      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
411         &                                               'f2003 standard. '                              ,  &
412         &                                               'Compile with key_nosignedzero enabled' )
413      !
414   END SUBROUTINE nemo_ctl
415
416
417   SUBROUTINE nemo_closefile
418      !!----------------------------------------------------------------------
419      !!                     ***  ROUTINE nemo_closefile  ***
420      !!
421      !! ** Purpose :   Close the files
422      !!----------------------------------------------------------------------
423      !
424      IF( lk_mpp )   CALL mppsync
425      !
426      CALL iom_close                                 ! close all input/output files managed by iom_*
427      !
428      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
429      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
430      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
431      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
432      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
433      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
434      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
435      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
436      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
437      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
438      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
439      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
440      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
441
442      !
443      numout = 6                                     ! redefine numout in case it is used after this point...
444      !
445   END SUBROUTINE nemo_closefile
446
447
448   SUBROUTINE nemo_alloc
449      !!----------------------------------------------------------------------
450      !!                     ***  ROUTINE nemo_alloc  ***
451      !!
452      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
453      !!
454      !! ** Method  :
455      !!----------------------------------------------------------------------
456      USE diawri    , ONLY: dia_wri_alloc
457      USE dom_oce   , ONLY: dom_oce_alloc
458      !
459      INTEGER :: ierr
460      !!----------------------------------------------------------------------
461      !
462      ierr =        oce_alloc       ()          ! ocean
463      ierr = ierr + dia_wri_alloc   ()
464      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
465      !
466      IF( lk_mpp    )   CALL mpp_sum( ierr )
467      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
468      !
469   END SUBROUTINE nemo_alloc
470
471
472   SUBROUTINE nemo_partition( num_pes )
473      !!----------------------------------------------------------------------
474      !!                 ***  ROUTINE nemo_partition  ***
475      !!
476      !! ** Purpose :
477      !!
478      !! ** Method  :
479      !!----------------------------------------------------------------------
480      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
481      !
482      INTEGER, PARAMETER :: nfactmax = 20
483      INTEGER :: nfact ! The no. of factors returned
484      INTEGER :: ierr  ! Error flag
485      INTEGER :: ji
486      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
487      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
488      !!----------------------------------------------------------------------
489      !
490      ierr = 0
491      !
492      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
493      !
494      IF( nfact <= 1 ) THEN
495         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
496         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
497         jpnj = 1
498         jpni = num_pes
499      ELSE
500         ! Search through factors for the pair that are closest in value
501         mindiff = 1000000
502         imin    = 1
503         DO ji = 1, nfact-1, 2
504            idiff = ABS( ifact(ji) - ifact(ji+1) )
505            IF( idiff < mindiff ) THEN
506               mindiff = idiff
507               imin = ji
508            ENDIF
509         END DO
510         jpnj = ifact(imin)
511         jpni = ifact(imin + 1)
512      ENDIF
513      !
514      jpnij = jpni*jpnj
515      !
516   END SUBROUTINE nemo_partition
517
518
519   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
520      !!----------------------------------------------------------------------
521      !!                     ***  ROUTINE factorise  ***
522      !!
523      !! ** Purpose :   return the prime factors of n.
524      !!                knfax factors are returned in array kfax which is of
525      !!                maximum dimension kmaxfax.
526      !! ** Method  :
527      !!----------------------------------------------------------------------
528      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
529      INTEGER                    , INTENT(  out) ::   kerr, knfax
530      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
531      !
532      INTEGER :: ifac, jl, inu
533      INTEGER, PARAMETER :: ntest = 14
534      INTEGER :: ilfax(ntest)
535      !
536      ! lfax contains the set of allowed factors.
537      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
538         &                            128,   64,   32,   16,    8,   4,   2  /
539      !!----------------------------------------------------------------------
540
541      ! Clear the error flag and initialise output vars
542      kerr = 0
543      kfax = 1
544      knfax = 0
545
546      ! Find the factors of n.
547      IF( kn == 1 )   GOTO 20
548
549      ! nu holds the unfactorised part of the number.
550      ! knfax holds the number of factors found.
551      ! l points to the allowed factor list.
552      ! ifac holds the current factor.
553
554      inu   = kn
555      knfax = 0
556
557      DO jl = ntest, 1, -1
558         !
559         ifac = ilfax(jl)
560         IF( ifac > inu )   CYCLE
561
562         ! Test whether the factor will divide.
563
564         IF( MOD(inu,ifac) == 0 ) THEN
565            !
566            knfax = knfax + 1            ! Add the factor to the list
567            IF( knfax > kmaxfax ) THEN
568               kerr = 6
569               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
570               return
571            ENDIF
572            kfax(knfax) = ifac
573            ! Store the other factor that goes with this one
574            knfax = knfax + 1
575            kfax(knfax) = inu / ifac
576            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
577         ENDIF
578         !
579      END DO
580
581   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
582      !
583   END SUBROUTINE factorise
584
585#if defined key_mpp_mpi
586
587   SUBROUTINE nemo_northcomms
588      !!======================================================================
589      !!                     ***  ROUTINE  nemo_northcomms  ***
590      !! nemo_northcomms    :  Setup for north fold exchanges with explicit
591      !!                       point-to-point messaging
592      !!=====================================================================
593      !!----------------------------------------------------------------------
594      !!
595      !! ** Purpose :   Initialization of the northern neighbours lists.
596      !!----------------------------------------------------------------------
597      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
598      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
599      !!----------------------------------------------------------------------
600
601      INTEGER  ::   sxM, dxM, sxT, dxT, jn
602      INTEGER  ::   njmppmax
603
604      njmppmax = MAXVAL( njmppt )
605   
606      !initializes the north-fold communication variables
607      isendto(:) = 0
608      nsndto = 0
609
610      !if I am a process in the north
611      IF ( njmpp == njmppmax ) THEN
612          !sxM is the first point (in the global domain) needed to compute the
613          !north-fold for the current process
614          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
615          !dxM is the last point (in the global domain) needed to compute the
616          !north-fold for the current process
617          dxM = jpiglo - nimppt(narea) + 2
618
619          !loop over the other north-fold processes to find the processes
620          !managing the points belonging to the sxT-dxT range
621 
622          DO jn = 1, jpni
623                !sxT is the first point (in the global domain) of the jn
624                !process
625                sxT = nfiimpp(jn, jpnj)
626                !dxT is the last point (in the global domain) of the jn
627                !process
628                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
629                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
630                   nsndto = nsndto + 1
631                     isendto(nsndto) = jn
632                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
633                   nsndto = nsndto + 1
634                     isendto(nsndto) = jn
635                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
636                   nsndto = nsndto + 1
637                     isendto(nsndto) = jn
638                END IF
639          END DO
640          nfsloop = 1
641          nfeloop = nlci
642          DO jn = 2,jpni-1
643           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
644              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
645                 nfsloop = nldi
646              ENDIF
647              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
648                 nfeloop = nlei
649              ENDIF
650           ENDIF
651        END DO
652
653      ENDIF
654      l_north_nogather = .TRUE.
655   END SUBROUTINE nemo_northcomms
656#else
657   SUBROUTINE nemo_northcomms      ! Dummy routine
658      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
659   END SUBROUTINE nemo_northcomms
660#endif
661
662   !!======================================================================
663END MODULE nemogcm
664
665
Note: See TracBrowser for help on using the repository browser.