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/2020/r12581_ticket2418/tests/STATION_ASF/MY_SRC – NEMO

source: NEMO/branches/2020/r12581_ticket2418/tests/STATION_ASF/MY_SRC/stpctl.F90 @ 12593

Last change on this file since 12593 was 12593, checked in by smasson, 4 years ago

r12581_ticket2418, first commit see #2418

File size: 7.6 KB
Line 
1MODULE stpctl
2   !!======================================================================
3   !!                       ***  MODULE  stpctl  ***
4   !! Ocean run control :  gross check of the ocean time stepping
5   !!                      version for STATION_ASF test-case
6   !!======================================================================
7   !! History :  OPA  ! 1991-03  (G. Madec) Original code
8   !!            6.0  ! 1992-06  (M. Imbard)
9   !!            8.0  ! 1997-06  (A.M. Treguier)
10   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
11   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
12   !!            3.7  ! 2016-09  (G. Madec)  Remove solver
13   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
14   !!----------------------------------------------------------------------
15
16   !!----------------------------------------------------------------------
17   !!   stp_ctl      : Control the run
18   !!----------------------------------------------------------------------
19   USE dom_oce         ! ocean space and time domain variables
20   USE sbc_oce         ! surface fluxes and stuff
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
27   USE netcdf          ! NetCDF library
28   IMPLICIT NONE
29   PRIVATE
30
31   PUBLIC stp_ctl           ! routine called by step.F90
32
33   INTEGER  ::   nrunid, ntauid, nqnsid, nempid
34   !!----------------------------------------------------------------------
35   !! NEMO/SAS 4.0 , NEMO Consortium (2018)
36   !! $Id: stpctl.F90 10603 2019-01-29 11:18:09Z acc $
37   !! Software governed by the CeCILL license (see ./LICENSE)
38   !!----------------------------------------------------------------------
39CONTAINS
40
41   SUBROUTINE stp_ctl( kt, Kbb, Kmm )
42      !!----------------------------------------------------------------------
43      !!                    ***  ROUTINE stp_ctl  ***
44      !!
45      !! ** Purpose :   Control the run
46      !!
47      !! ** Method  : - Save the time step in numstp
48      !!              - Print it each 50 time steps
49      !!              - Stop the run IF problem encountered by setting indic=-3
50      !!
51      !! ** Actions :   "time.step" file = last ocean time-step
52      !!                "run.stat"  file = run statistics
53      !!                nstop indicator sheared among all local domain (lk_mpp=T)
54      !!----------------------------------------------------------------------
55      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
56      INTEGER, INTENT(in   ) ::   Kbb, Kmm      ! ocean time level index
57      !!
58      INTEGER                ::   idtime, istatus
59      REAL(wp), DIMENSION(3) ::   zmax
60      LOGICAL                ::   ll_wrtstp, ll_colruns, ll_wrtruns
61      LOGICAL, DIMENSION(jpi,jpj) ::   llmsk
62      CHARACTER(len=20) :: clname
63      !!----------------------------------------------------------------------
64      !
65      ll_wrtstp  = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
66      ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat
67      ll_wrtruns = ll_colruns .AND. lwm
68      !
69      IF( kt == nit000 ) THEN
70         !
71         IF( lwp ) THEN
72            WRITE(numout,*)
73            WRITE(numout,*) 'stp_ctl : time-stepping control'
74            WRITE(numout,*) '~~~~~~~'
75         ENDIF
76         !                                ! open time.step    ascii file, done only by 1st subdomain
77         IF( lwm )   CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
78         !
79         IF( ll_wrtruns ) THEN
80            !                             ! open run.stat     ascii file, done only by 1st subdomain
81            CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
82            !                             ! open run.stat.nc netcdf file, done only by 1st subdomain
83            clname = 'run.stat.nc'
84            IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
85            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid )
86            istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime )
87            istatus = NF90_DEF_VAR( nrunid, 'tau_max', NF90_DOUBLE, (/ idtime /), ntauid )
88            istatus = NF90_DEF_VAR( nrunid, 'qns_max', NF90_DOUBLE, (/ idtime /), nqnsid   )
89            istatus = NF90_DEF_VAR( nrunid, 'emp_max', NF90_DOUBLE, (/ idtime /), nempid   )
90            istatus = NF90_ENDDEF(nrunid)
91         ENDIF
92         !   
93      ENDIF
94      !
95      !                                   !==              write current time step              ==!
96      !                                   !==  done only by 1st subdomain at writting timestep  ==!
97      IF( lwm .AND. ll_wrtstp ) THEN
98         WRITE ( numstp, '(1x, i8)' )   kt
99         REWIND( numstp )
100      ENDIF
101      !                                   !==            test of local extrema           ==!
102      !                                   !==  done by all processes at every time step  ==!
103      llmsk(:,:) = tmask(:,:,1) == 1._wp
104      zmax(1) = MAXVAL(     taum(:,:)   , mask = llmsk )   ! max wind stress module
105      zmax(2) = MAXVAL( ABS( qns(:,:) ) , mask = llmsk )   ! max non-solar heat flux
106      zmax(3) = MAXVAL( ABS( emp(:,:) ) , mask = llmsk )   ! max E-P
107      !
108      IF( ll_colruns ) THEN
109         CALL mpp_max( "stpctl", zmax )          ! max over the global domain
110         nstop = NINT( zmax(3) )                 ! nstop indicator sheared among all local domains
111      ENDIF
112      !                                   !==  run statistics  ==!   ("run.stat" files)
113      IF( ll_wrtruns ) THEN
114         WRITE(numrun,9500) kt, zmax(1), zmax(2), zmax(3)
115         istatus = NF90_PUT_VAR( nrunid, ntauid, (/ zmax(1)/), (/kt/), (/1/) )
116         istatus = NF90_PUT_VAR( nrunid, nqnsid, (/ zmax(2)/), (/kt/), (/1/) )
117         istatus = NF90_PUT_VAR( nrunid, nempid, (/ zmax(3)/), (/kt/), (/1/) )
118         IF( MOD( kt , 100 ) == 0 ) istatus = NF90_SYNC(nrunid)
119         IF( kt == nitend         ) istatus = NF90_CLOSE(nrunid)
120      END IF
121      !                                   !==  error handling  ==!
122      IF( ( sn_cfctl%l_glochk .OR. lsomeoce ) .AND. (   &  ! domain contains some ocean points, check for sensible ranges
123         &  zmax(1) >    5._wp .OR.   &             ! too large wind stress ( > 5 N/m^2 )
124         &  zmax(2) > 2000._wp .OR.   &             ! too large non-solar heat flux ( > 2000 W/m^2)
125         &  zmax(3) > 1.E-3_wp .OR.   &             ! too large net freshwater flux ( kg/m^2/s)
126         &  ISNAN( zmax(1) + zmax(2) + zmax(3) ) ) ) THEN   ! NaN encounter in the tests
127
128         !! We are 1D so no need to find a spatial location of the rogue point.
129
130         WRITE(ctmp1,*) ' stp_ctl: |tau_mod| > 5 N/m2  or  |qns| > 2000 W/m2  or |emp| > 1.E-3 or  NaN encounter in the tests'
131         WRITE(ctmp2,9500) kt,   zmax(1), zmax(2), zmax(3)
132         WRITE(ctmp6,*) '      ===> output of last computed fields in output.abort.nc file'
133
134         CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
135
136         IF( .NOT. sn_cfctl%l_glochk ) THEN
137            WRITE(ctmp8,*) 'E R R O R message from sub-domain: ', narea
138            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ' ', ctmp6, ' ' )
139         ELSE
140            CALL ctl_stop( ctmp1, ' ', ctmp2, ' ', ctmp6, ' ' )
141         ENDIF
142
143         kindic = -3
144         !
145      ENDIF
146      !
1479500  FORMAT(' it :', i8, '    tau_max: ', D23.16, ' |qns|_max: ', D23.16,' |emp|_max: ', D23.16)
148      !
149   END SUBROUTINE stp_ctl
150
151   !!======================================================================
152END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.