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

source: branches/2015/nemo_v3_6_STABLE/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 8581

Last change on this file since 8581 was 8581, checked in by cbricaud, 6 years ago

fix ticket #1944 in nemo_v3_6_STABLE ( SAS restartability)

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