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.
stpctl.F90 in NEMO/branches/UKMO/dev_r9950_GO8_package/tests/CANAL/MY_SRC – NEMO

source: NEMO/branches/UKMO/dev_r9950_GO8_package/tests/CANAL/MY_SRC/stpctl.F90 @ 10322

Last change on this file since 10322 was 10322, checked in by davestorkey, 5 years ago

UKMO/dev_r9950_GO8_package: Update to be relative to rev 10321 of NEMO4_beta_mirror branch.

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1MODULE stpctl
2   !!======================================================================
3   !!                       ***  MODULE  stpctl  ***
4   !! Ocean run control :  gross check of the ocean time stepping
5   !!======================================================================
6   !! History :  OPA  ! 1991-03  (G. Madec) Original code
7   !!            6.0  ! 1992-06  (M. Imbard)
8   !!            8.0  ! 1997-06  (A.M. Treguier)
9   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
10   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
11   !!            3.7  ! 2016-09  (G. Madec)  Remove solver
12   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
13   !!----------------------------------------------------------------------
14
15   !!----------------------------------------------------------------------
16   !!   stp_ctl      : Control the run
17   !!----------------------------------------------------------------------
18   USE oce             ! ocean dynamics and tracers variables
19   USE dom_oce         ! ocean space and time domain variables
20   USE c1d             ! 1D vertical configuration
21   USE diawri          ! Standard run outputs       (dia_wri_state routine)
22   !
23   USE in_out_manager  ! I/O manager
24   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
25   USE lib_mpp         ! distributed memory computing
26   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
27
28   USE netcdf          ! NetCDF library
29   IMPLICIT NONE
30   PRIVATE
31
32   PUBLIC stp_ctl           ! routine called by step.F90
33
34   INTEGER  ::   idrun, idtime, idssh, idu, ids, istatus
35   !!----------------------------------------------------------------------
36   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
37   !! $Id$
38   !! Software governed by the CeCILL license (see ./LICENSE)
39   !!----------------------------------------------------------------------
40CONTAINS
41
42   SUBROUTINE stp_ctl( kt, kindic )
43      !!----------------------------------------------------------------------
44      !!                    ***  ROUTINE stp_ctl  ***
45      !!                     
46      !! ** Purpose :   Control the run
47      !!
48      !! ** Method  : - Save the time step in numstp
49      !!              - Print it each 50 time steps
50      !!              - Stop the run IF problem encountered by setting indic=-3
51      !!                Problems checked: |ssh| maximum larger than 10 m
52      !!                                  |U|   maximum larger than 10 m/s
53      !!                                  negative sea surface salinity
54      !!
55      !! ** Actions :   "time.step" file = last ocean time-step
56      !!                "run.stat"  file = run statistics
57      !!                nstop indicator sheared among all local domain (lk_mpp=T)
58      !!----------------------------------------------------------------------
59      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
60      INTEGER, INTENT(inout) ::   kindic   ! error indicator
61      !!
62      INTEGER  ::   ji, jj, jk             ! dummy loop indices
63      INTEGER  ::   iih, ijh               ! local integers
64      INTEGER  ::   iiu, iju, iku          !   -       -
65      INTEGER  ::   iis, ijs, iks          !   -       -
66      REAL(wp) ::   zzz                    ! local real
67      INTEGER , DIMENSION(3) ::   ilocu, ilocs
68      INTEGER , DIMENSION(2) ::   iloch
69      REAL(wp), DIMENSION(4) ::   zmax
70      !!----------------------------------------------------------------------
71      !
72      IF( kt == nit000 .AND. lwp ) THEN
73         WRITE(numout,*)
74         WRITE(numout,*) 'stp_ctl : time-stepping control'
75         WRITE(numout,*) '~~~~~~~'
76         !                                ! open time.step file
77         CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
78         !                                ! open run.stat file
79         CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
80
81         IF( lwm ) THEN
82            istatus = NF90_CREATE( 'run.stat.nc', NF90_CLOBBER, idrun )
83            istatus = NF90_DEF_DIM( idrun, 'time', NF90_UNLIMITED, idtime )
84            istatus = NF90_DEF_VAR( idrun, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), idssh )
85            istatus = NF90_DEF_VAR( idrun,   'abs_u_max', NF90_DOUBLE, (/ idtime /), idu )
86            istatus = NF90_ENDDEF(idrun)
87         ENDIF
88         
89      ENDIF
90      !
91      IF(lwp) THEN                        !==  current time step  ==!   ("time.step" file)
92         WRITE ( numstp, '(1x, i8)' )   kt
93         REWIND( numstp )
94      ENDIF
95      !
96      !                                   !==  test of extrema  ==!
97      IF( ll_wd ) THEN
98         zmax(1) = MAXVAL(  ABS( sshn(:,:) + ssh_ref*tmask(:,:,1) )  )        ! ssh max
99      ELSE
100         zmax(1) = MAXVAL(  ABS( sshn(:,:) )  )                               ! ssh max
101      ENDIF
102      zmax(2) = MAXVAL(  ABS( un(:,:,:) )  )                                  ! velocity max (zonal only)
103!     zmax(3) = MAXVAL( -tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp )   ! minus salinity max
104      zmax(3) = 0.0_wp
105      zmax(4) = REAL( nstop , wp )                                            ! stop indicator
106      !
107      IF( lk_mpp ) THEN
108         CALL mpp_max_multiple( zmax(:), 4 )    ! max over the global domain
109         !
110         nstop = INT( zmax(4) )                 ! nstop indicator sheared among all local domains
111      ENDIF
112      !
113      IF( MOD( kt, nwrite ) == 1 .AND. lwp ) THEN
114         WRITE(numout,*) ' ==>> time-step= ', kt, ' |ssh| max: ',   zmax(1), ' |U| max: ', zmax(2)
115      ENDIF
116      !
117      IF (  zmax(1) >  50._wp .OR.   &                     ! too large sea surface height ( > 10 m)
118         &  zmax(2) >  20._wp .OR.   &                     ! too large velocity ( > 10 m/s)
119!!$         &  zmax(3) >=  0._wp .OR.   &                     ! negative or zero sea surface salinity
120         &  ISNAN( zmax(1) + zmax(2) + zmax(3) )  ) THEN   ! NaN encounter in the tests
121         IF( lk_mpp ) THEN
122            CALL mpp_maxloc( ABS(sshn)        , ssmask(:,:)  , zzz, iih, ijh )
123            CALL mpp_maxloc( ABS(un)          , umask (:,:,:), zzz, iiu, iju, iku )
124!           CALL mpp_minloc( tsn(:,:,:,jp_sal), tmask (:,:,:), zzz, iis, ijs, iks )
125         ELSE
126            iloch = MINLOC( ABS( sshn(:,:)   )                               )
127            ilocu = MAXLOC( ABS( un  (:,:,:) )                               )
128!           ilocs = MINLOC( tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp )
129            iih = iloch(1) + nimpp - 1   ;   ijh = iloch(2) + njmpp - 1
130            iiu = ilocu(1) + nimpp - 1   ;   iju = ilocu(2) + njmpp - 1   ;   iku = ilocu(3)
131!           iis = ilocs(1) + nimpp - 1   ;   ijs = ilocs(2) + njmpp - 1   ;   iks = ilocu(3)
132         ENDIF
133         IF(lwp) THEN
134            WRITE(numout,cform_err)
135            WRITE(numout,*) ' stp_ctl: |ssh| > 50 m   or   |U| > 20 m/s   or   NaN encounter in the tests'
136            WRITE(numout,*) ' ======= '
137            WRITE(numout,9100) kt,   zmax(1), iih, ijh
138            WRITE(numout,9200) kt,   zmax(2), iiu, iju, iku
139!!$            WRITE(numout,9300) kt, - zmax(3), iis, ijs, iks
140            WRITE(numout,*)
141            WRITE(numout,*) '          output of last computed fields in output.abort.nc file'
142         ENDIF
143         kindic = -3
144         !
145         nstop = nstop + 1                            ! increase nstop by 1 (on all local domains)
146         CALL dia_wri_state( 'output.abort', kt )     ! create an output.abort file
147         !
148      ENDIF
1499100  FORMAT (' kt=',i8,'   |ssh| max: ',1pg11.4,', at  i j  : ',2i5)
1509200  FORMAT (' kt=',i8,'   |U|   max: ',1pg11.4,', at  i j k: ',3i5)
1519300  FORMAT (' kt=',i8,'   S     min: ',1pg11.4,', at  i j  : ',2i5)
152      !
153      !                                            !==  run statistics  ==!   ("run.stat" file)
154!     IF(lwp) WRITE(numrun,9400) kt, zmax(1), zmax(2), - zmax(3)
155      IF(lwp) WRITE(numrun,9400) kt, zmax(1), zmax(2)
156      IF( lwm ) THEN
157         istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) )
158         istatus = NF90_PUT_VAR( idrun,   idu, (/ zmax(2)/), (/kt/), (/1/) )
159!        istatus = NF90_PUT_VAR( idrun,   ids, (/-zmax(3)/), (/kt/), (/1/) )
160         IF( MOD( kt , 100 ) == 0 ) istatus = NF90_SYNC(idrun)
161         IF( kt == nitend         ) istatus = NF90_CLOSE(idrun)
162      END IF
163      !
164!9400  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16)
1659400  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16)
166      !
167   END SUBROUTINE stp_ctl
168
169   !!======================================================================
170END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.