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 NEMO/trunk/src/SAO – NEMO

source: NEMO/trunk/src/SAO/nemogcm.F90 @ 10227

Last change on this file since 10227 was 10068, checked in by nicolasmartin, 6 years ago

First part of modifications to have a common default header : fix typos and SVN keywords properties

  • Property svn:keywords set to Id
File size: 18.7 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  3.6  ! 2015-12  (A. Ryan) Original code   (from OCE/)
7   !!            4.0  ! 2016-11  (G. Madec, S. Flavoni)  domain configuration / user defined interface
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
12   !!   nemo_init     : initialization of the NEMO system
13   !!   nemo_ctl      : initialisation of the contol print
14   !!   nemo_closefile: close remaining open files
15   !!   nemo_alloc    : dynamical allocation
16   !!----------------------------------------------------------------------
17   USE step_oce       ! module used in the ocean time stepping module (step.F90)
18   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
19   USE istate         ! initial state setting          (istate_init routine)
20   USE phycst         ! physical constant                  (par_cst routine)
21   USE step           ! NEMO time-stepping                 (stp     routine)
22   USE cpl_oasis3     ! OASIS3 coupling
23   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
24#if defined key_nemocice_decomp
25   USE ice_domain_size, only: nx_global, ny_global
26#endif
27   !           ! Stand Alone Observation operator modules
28   USE sao_data
29   USE sao_intp
30   !
31   USE lib_mpp        ! distributed memory computing
32   USE mppini         ! shared/distributed memory setting (mpp_init routine)
33   USE lbcnfd  , ONLY : isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
34   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
35#if defined key_iomput
36   USE xios           ! xIOserver
37#endif
38
39   IMPLICIT NONE
40   PRIVATE
41
42   PUBLIC   nemo_gcm    ! called by model.F90
43   PUBLIC   nemo_init   ! needed by AGRIF
44   PUBLIC   nemo_alloc  ! needed by TAM
45
46   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
47
48   !!----------------------------------------------------------------------
49   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
50   !! $Id$
51   !! Software governed by the CeCILL license (see ./LICENSE)
52   !!----------------------------------------------------------------------
53CONTAINS
54
55   SUBROUTINE nemo_gcm
56         !!----------------------------------------------------------------------
57         !!                    ***  SUBROUTINE offline_obs_oper ***
58         !!
59         !! ** Purpose : To use NEMO components to interpolate model fields
60         !!              to observation space.
61         !!
62         !! ** Method : 1. Initialise NEMO
63         !!             2. Initialise offline obs_oper
64         !!             3. Cycle through match ups
65         !!             4. Write results to file
66         !!----------------------------------------------------------------------
67         !
68         CALL nemo_init       ! Initialise NEMO
69         !
70         CALL sao_data_init   ! Initialise Stand Alone Observation operator data
71         !
72         CALL dia_obs_init    ! Initialise obs_operator
73         !
74         CALL sao_interp      ! Interpolate to observation space
75         !
76         CALL dia_obs_wri     ! Pipe to output files
77         !
78         CALL dia_obs_dealloc ! Reset the obs_oper between
79         !
80         IF(lk_mpp)   CALL mppstop  ! Safely stop MPI (end mpp communications)
81         !
82   END SUBROUTINE nemo_gcm
83
84
85   SUBROUTINE nemo_init
86      !!----------------------------------------------------------------------
87      !!                     ***  ROUTINE nemo_init  ***
88      !!
89      !! ** Purpose :   initialization of the NEMO GCM
90      !!----------------------------------------------------------------------
91      INTEGER ::   ji                 ! dummy loop indices
92      INTEGER ::   ios, ilocal_comm   ! local integer
93      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
94      !
95      NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
96         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
97         &             ln_timing, ln_diacfl
98      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
99      !!----------------------------------------------------------------------
100      !
101      cltxt  = ''
102      cltxt2 = ''
103      clnam  = '' 
104      cxios_context = 'nemo'
105      !
106      !                             ! Open reference namelist and configuration namelist files
107      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
108      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
109      !
110      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints
111      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
112901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
113      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
114      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
115902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
116      !
117      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints
118      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
119903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
120      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
121      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
122904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
123
124      !                             !--------------------------!
125      !                             !  Set global domain size  !   (control print return in cltxt2)
126      !                             !--------------------------!
127      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
128         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
129         !
130      ELSE                                ! user-defined namelist
131         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
132      ENDIF
133      !
134      !
135      !                             !--------------------------------------------!
136      !                             !  set communicator & select the local node  !
137      !                             !  NB: mynode also opens output.namelist.dyn !
138      !                             !      on unit number numond on first proc   !
139      !                             !--------------------------------------------!
140#if defined key_iomput
141      IF( Agrif_Root() ) THEN
142         IF( lk_oasis ) THEN
143            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
144            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
145         ELSE
146            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
147         ENDIF
148      ENDIF
149      ! Nodes selection (control print return in cltxt)
150      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
151#else
152      IF( lk_oasis ) THEN
153         IF( Agrif_Root() ) THEN
154            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
155         ENDIF
156         ! Nodes selection (control print return in cltxt)
157         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
158      ELSE
159         ilocal_comm = 0                                    ! Nodes selection (control print return in cltxt)
160         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
161      ENDIF
162#endif
163
164      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
165
166      lwm = (narea == 1)                                    ! control of output namelists
167      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
168
169      IF(lwm) THEN
170         ! write merged namelists from earlier to output namelist now that the
171         ! file has been opened in call to mynode. nammpp has already been
172         ! written in mynode (if lk_mpp_mpi)
173         WRITE( numond, namctl )
174         WRITE( numond, namcfg )
175         IF( .NOT.ln_read_cfg ) THEN
176            DO ji = 1, SIZE(clnam)
177               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
178            END DO
179         ENDIF
180      ENDIF
181
182      IF(lwp) THEN                            ! open listing units
183         !
184         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
185         !
186         WRITE(numout,*)
187         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
188         WRITE(numout,*) '                       NEMO team'
189         WRITE(numout,*) '            Stand Alone Observation operator'
190         WRITE(numout,*) '                NEMO version 4.0  (2017) '
191         WRITE(numout,*)
192         WRITE(numout,*)
193         DO ji = 1, SIZE(cltxt)
194            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) cltxt(ji)    ! control print of mynode
195         END DO
196         WRITE(numout,*)
197         WRITE(numout,*)
198         DO ji = 1, SIZE(cltxt2)
199            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)   ! control print of domain size
200         END DO
201         !
202         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
203         !
204      ENDIF
205      !                                      ! Domain decomposition
206      CALL mpp_init                          ! MPP
207
208      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
209      CALL nemo_alloc()
210
211      !                             !-------------------------------!
212      !                             !  NEMO general initialization  !
213      !                             !-------------------------------!
214
215      CALL nemo_ctl                          ! Control prints
216      !
217      !                                         ! General initialization
218      IF( ln_timing    )   CALL timing_init     ! timing
219      IF( ln_timing    )   CALL timing_start( 'nemo_init')
220      !
221                           CALL phy_cst            ! Physical constants
222                           CALL eos_init           ! Equation of state
223                           CALL dom_init('SAO')    ! Domain
224
225
226      IF( ln_ctl       )   CALL prt_ctl_init    ! Print control
227
228                           CALL istate_init     ! ocean initial state (Dynamics and tracers)
229   END SUBROUTINE nemo_init
230
231
232   SUBROUTINE nemo_ctl
233      !!----------------------------------------------------------------------
234      !!                     ***  ROUTINE nemo_ctl  ***
235      !!
236      !! ** Purpose :   control print setting
237      !!
238      !! ** Method  : - print namctl information and check some consistencies
239      !!----------------------------------------------------------------------
240      !
241      IF(lwp) THEN                  ! control print
242         WRITE(numout,*)
243         WRITE(numout,*) 'nemo_ctl: Control prints'
244         WRITE(numout,*) '~~~~~~~~'
245         WRITE(numout,*) '   Namelist namctl'
246         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
247         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
248         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
249         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
250         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
251         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
252         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
253         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
254         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
255         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
256      ENDIF
257      !
258      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
259      nictls    = nn_ictls
260      nictle    = nn_ictle
261      njctls    = nn_jctls
262      njctle    = nn_jctle
263      isplt     = nn_isplt
264      jsplt     = nn_jsplt
265
266      IF(lwp) THEN                  ! control print
267         WRITE(numout,*)
268         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
269         WRITE(numout,*) '~~~~~~~ '
270         WRITE(numout,*) '   Namelist namcfg'
271         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
272         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
273         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
274         WRITE(numout,*) '      write configuration definition file           ln_write_cfg     = ', ln_write_cfg
275         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
276         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
277      ENDIF
278      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
279      !
280      !                             ! Parameter control
281      !
282      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
283         IF( lk_mpp .AND. jpnij > 1 ) THEN
284            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
285         ELSE
286            IF( isplt == 1 .AND. jsplt == 1  ) THEN
287               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
288                  &           ' - the print control will be done over the whole domain' )
289            ENDIF
290            ijsplt = isplt * jsplt            ! total number of processors ijsplt
291         ENDIF
292         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
293         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
294         !
295         !                              ! indices used for the SUM control
296         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
297            lsp_area = .FALSE.
298         ELSE                                             ! print control done over a specific  area
299            lsp_area = .TRUE.
300            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
301               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
302               nictls = 1
303            ENDIF
304            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
305               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
306               nictle = jpiglo
307            ENDIF
308            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
309               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
310               njctls = 1
311            ENDIF
312            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
313               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
314               njctle = jpjglo
315            ENDIF
316         ENDIF
317      ENDIF
318      !
319      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
320         &                                               'f2003 standard. '                              ,  &
321         &                                               'Compile with key_nosignedzero enabled' )
322      !
323   END SUBROUTINE nemo_ctl
324
325
326   SUBROUTINE nemo_closefile
327      !!----------------------------------------------------------------------
328      !!                     ***  ROUTINE nemo_closefile  ***
329      !!
330      !! ** Purpose :   Close the files
331      !!----------------------------------------------------------------------
332      !
333      IF( lk_mpp )   CALL mppsync
334      !
335      CALL iom_close                                 ! close all input/output files managed by iom_*
336      !
337      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
338      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
339      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
340      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
341      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
342      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
343      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
344      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
345      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
346      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
347      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
348      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
349      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
350      !
351      numout = 6                                     ! redefine numout in case it is used after this point...
352      !
353   END SUBROUTINE nemo_closefile
354
355
356   SUBROUTINE nemo_alloc
357      !!----------------------------------------------------------------------
358      !!                     ***  ROUTINE nemo_alloc  ***
359      !!
360      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
361      !!
362      !! ** Method  :
363      !!----------------------------------------------------------------------
364      USE diawri    , ONLY: dia_wri_alloc
365      USE dom_oce   , ONLY: dom_oce_alloc
366      !
367      INTEGER :: ierr
368      !!----------------------------------------------------------------------
369      !
370      ierr =        oce_alloc       ()          ! ocean
371      ierr = ierr + dia_wri_alloc   ()
372      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
373      !
374      IF( lk_mpp    )   CALL mpp_sum( ierr )
375      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
376      !
377   END SUBROUTINE nemo_alloc
378
379   !!======================================================================
380END MODULE nemogcm
381
Note: See TracBrowser for help on using the repository browser.