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

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