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

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 9200

Last change on this file since 9200 was 9200, checked in by clem, 6 years ago

correct a bug (for SAS) introduced at r9161

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