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 @ 7200

Last change on this file since 7200 was 7200, checked in by gm, 7 years ago

#1692 - branch SIMPLIF_2_usrdef: add depth_e3 module + management of ORCA family + domain_cfg filename (in&out) given in namelist

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