!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
***s/r sergoff  - suspend or resume time series/grid point diagnostics
*                 extractions
#include "model_macros_f.h"
*

      subroutine sergoff() 1
*
      implicit none
*
*author
*     Andre Methot - aug 94 - v0_14
*
*revision
* v2_00 - Desgagne M.       - initial MPI version
* v3_30 - Winger K.         - correct time series handling in climate mode
*
*object
*         This subroutine suspend or resume time series/grid point
*         diagnostics extractions IF it is required.
*
*     This subroutine was designed to skip extractions during the
*     second half of digital filter initialization.
*     It is called a each timestep.
*
*     The routine is also used to stop time series extractions after
*     a user given timestep.
*	
*arguments
*      none
*
*implicits
#include "p_serg.cdk"
#include "init.cdk"
#include "lctl.cdk"
#include "lun.cdk"
#include "rstr.cdk"
#include "xst.cdk"
#include "glb_ld.cdk"
#include "clim.cdk"
*
      integer pnerr, pnistat
**
*
*     ---------------------------------------------------------------
*        time series package is stopped at Lctl_step = P_serg_serstp
*     ---------------------------------------------------------------
*
      if (Xst_nstat .gt. 0) then
         if (Clim_climat_L) then
            if (Rstri_sdon .eq. (P_serg_serstp+1)) then
               if (lun_out.gt.0) write(Lun_out,1002)
               P_serg_sroff_L=.true.
            endif
         else
            if (Lctl_step .eq. (P_serg_serstp+1)) then
               if (lun_out.gt.0) write(Lun_out,1002)
               P_serg_sroff_L=.true.
            endif
         endif
      endif
*
*     ----------------------------------------------------------------
*C      criterias to suspend or resume in the context of initialisation
*     ----------------------------------------------------------------
*
*            if time series were requested
*            AND
*            if user given parameter allow suspension
*            AND
*            if initialisation is requested
*
      if ( (Xst_nstat .gt. 0) .and. P_serg_srsus_L .and. 
     $     Init_balgm_L ) then
*
         if ( .not. Rstri_idon_L ) then
*
*               ---------------------------------
*               IF INITIALISATION IS NOT DONE...
*C              Additionnal criterias to suspend:
*               ---------------------------------
*
*               timestep correspond to the second half
*               of the initialisation
*               AND
*               the package is not already suspended
*
            if ( (Lctl_step .ge. ( (Init_dfnp-1)/2 + 1) )
     %           .and.
     %           (.not. P_serg_sroff_L)                  ) then
*     
               if (Lun_out.gt.0) write(Lun_out,1000)
               P_serg_sroff_L=.true.
*     
            endif
*     
         else
*
*               ---------------------------------
*               IF INITIALISATION IS DONE...
*C              Additionnal criterias to resume:
*               ---------------------------------
*
*               the package is still suspended
*
            if ( P_serg_sroff_L ) then
*     
               if (Lun_out.gt.0) write(Lun_out,1001)
               P_serg_sroff_L=.false.
*     
            endif
*     
         endif
*     
      endif
*
 1000 format(/,'REQUEST TO SUSPEND TIME SERIES EXTRACTION(S/R SERGOFF)',
     +       /,'======================================================')
*
 1001 format(/,'REQUEST TO RESUME TIME SERIES EXTRACTION(S/R SERGOFF)',
     +       /,'=====================================================')
*
 1002 format(/,'REQUEST TO STOP TIME SERIES EXTRACTION(S/R SERGOFF)',
     +       /,'======================================================')
*
      return
      end