anchor.diff:           ! Initialize the module
      Interval = drvrInitInp%TimeInterval
      CALL HydroDyn_Init( InitInData, u(1), p,  x, xd, z, OtherState, y, Interval, InitOutData, ErrStat, ErrMsg )
  - 
  -   IF ( ErrStat /= ErrID_None ) THEN          ! Check if there was an error and do something about it if necessary
  -      CALL WrScr( ErrMsg )
  -      IF ( ErrStat >= ErrID_Fatal ) THEN
  -         CALL HydroDyn_End( u(1), p, x, xd, z, OtherState, y, ErrStat, ErrMsg )
  -         IF ( ErrStat /= ErrID_None ) THEN
  -            CALL WrScr( ErrMsg )     
  -         END IF
  -         STOP
  -      END IF
  -   END IF
  +   if (errStat >= AbortErrLev) then
  +         ! Clean up and exit
  +      call HD_DvrCleanup()
  +   end if
   
      IF ( Interval /= drvrInitInp%TimeInterval) THEN
         CALL WrScr('The HydroDyn Module attempted to change timestep interval, but this is not allowed.  The HydroDyn Module must use the Driver Interval.')
  -      CALL HydroDyn_End( u(1), p, x, xd, z, OtherState, y, ErrStat, ErrMsg )  
  -      STOP
  +      call HD_DvrCleanup() 
  +      
      END IF
   
   
         ! Write the gridded wave elevation data to a file
   
      IF ( drvrInitInp%WaveElevSeriesFlag )     CALL WaveElevGrid_Output  (drvrInitInp, InitInData, InitOutData, p, ErrStat, ErrMsg)
  -   IF ( ErrStat /= ErrID_None ) THEN 
  -      CALL WrScr( ErrMsg )
  -      IF ( ErrStat >= ErrID_Fatal ) THEN
  -         CALL HydroDyn_End( u(1), p, x, xd, z, OtherState, y, ErrStat, ErrMsg )
  -         IF ( ErrStat /= ErrID_None ) THEN
  -            CALL WrScr( ErrMsg )     
  -         END IF
  -         STOP
  -      END IF
  -   END IF
  +   if (errStat >= AbortErrLev) then
  +         ! Clean up and exit
  +      call HD_DvrCleanup()
  +   end if
   
      
         ! Destroy initialization data
  
positive.code: !        /fpp                  because of they both have preprocessor statements
  ! ----------------------------------------------------------------------------------- 
  
  
  
     INTEGER(IntKi), PARAMETER                           :: NumInp = 1           ! Number of inputs sent to HydroDyn_UpdateStates
  
negative.code: 
  end subroutine print_help
  
  !----------------------------------------------------------------------------------------------------------------------------------
  SUBROUTINE SimStatus_FirstTime( PrevSimTime, PrevClockTime, SimStrtTime, UsrTimeSim, ZTime, TMax )
  ! This routine displays a message that gives that status of the simulation.
  !..................................................................................................................................
  
     IMPLICIT                        NONE
  
        ! Passed variables
     REAL(DbKi), INTENT(IN   )    :: ZTime                                           ! Current simulation time (s)
     REAL(DbKi), INTENT(IN   )    :: TMax                                            ! Expected simulation time (s)
     REAL(DbKi), INTENT(  OUT)    :: PrevSimTime                                     ! Previous time message was written to screen (s > 0)
     REAL(ReKi), INTENT(  OUT)    :: PrevClockTime                                   ! Previous clock time in seconds past midnight
     INTEGER,    INTENT(  OUT)    :: SimStrtTime (8)                                 ! An array containing the elements of the start time.
     REAL,       INTENT(  OUT)    :: UsrTimeSim                                      ! User CPU time for simulation (without intialization)
  
        ! Local variables.
  
     REAL(ReKi)                   :: CurrClockTime                                   ! Current time in seconds past midnight.
  
  
        ! How many seconds past midnight?
  
     CALL DATE_AND_TIME ( Values=SimStrtTime )
     CALL CPU_TIME ( UsrTimeSim )                                                    ! Initial CPU time   
     CurrClockTime = TimeValues2Seconds( SimStrtTime )
  
  
     CALL WrScr ( ' Timestep: '//TRIM( Num2LStr( NINT( ZTime ) ) )//' of '//TRIM( Num2LStr( TMax ) )//' seconds.')
  
  
     ! Let's save this time as the previous time for the next call to the routine
     PrevClockTime = CurrClockTime
     PrevSimTime   = ZTime
  
     RETURN
  END SUBROUTINE SimStatus_FirstTime
  
  !----------------------------------------------------------------------------------------------------------------------------------
  SUBROUTINE SimStatus( PrevSimTime, PrevClockTime, ZTime, TMax )
  ! This routine displays a message that gives that status of the simulation and the predicted end time of day.
  !..................................................................................................................................
  
     IMPLICIT                        NONE
  
        ! Passed variables
     REAL(DbKi), INTENT(IN)       :: ZTime                                           ! Current simulation time (s)
     REAL(DbKi), INTENT(IN)       :: TMax                                            ! Expected simulation time (s)
     REAL(DbKi), INTENT(INOUT)    :: PrevSimTime                                     ! Previous time message was written to screen (s > 0)
     REAL(ReKi), INTENT(INOUT)    :: PrevClockTime                                   ! Previous clock time in seconds past midnight
  
  
        ! Local variables.
  
     REAL(ReKi)                   :: CurrClockTime                                   ! Current time in seconds past midnight.
     REAL(ReKi)                   :: DeltTime                                        ! The amount of time elapsed since the last call.
     REAL(ReKi)                   :: EndTime                                         ! Approximate time of day when simulation will complete.
     REAL(ReKi), PARAMETER        :: InSecHr  = 1.0_ReKi/3600.0_ReKi                 ! Inverse of the number of seconds in an hour
     REAL(ReKi), PARAMETER        :: InSecMn  = 1.0_ReKi/  60.0_ReKi                 ! Inverse of the number of seconds in a minute
     REAL(ReKi)                   :: SimTimeLeft                                     ! Approximate clock time remaining before simulation completes
  
     REAL(ReKi), PARAMETER        :: SecPerDay = 24*60*60.0_ReKi                     ! Number of seconds per day
  
     INTEGER(4)                   :: EndHour                                         ! The hour when the simulations is expected to complete.
     INTEGER(4)                   :: EndMin                                          ! The minute when the simulations is expected to complete.
     INTEGER(4)                   :: EndSec                                          ! The second when the simulations is expected to complete.
     INTEGER(4)                   :: TimeAry  (8)                                    ! An array containing the elements of the start time.
  
     CHARACTER( 8)                :: ETimeStr                                        ! String containing the end time.
  
  
     IF ( ZTime <= PrevSimTime ) RETURN
  
  
        ! How many seconds past midnight?
  
     CALL DATE_AND_TIME ( Values=TimeAry )
     CurrClockTime = TimeValues2Seconds( TimeAry )
  
        ! Calculate elapsed clock time
  
     DeltTime = CurrClockTime - PrevClockTime
  
  
        ! We may have passed midnight since the last revoultion.  We will assume that (ZTime - PrevSimTime) of simulation time doesn't take more than a day.
  
     IF ( CurrClockTime < PrevClockTime )  THEN
        DeltTime = DeltTime + SecPerDay
     ENDIF
  
  
        ! Estimate the end time in hours, minutes, and seconds
  
     SimTimeLeft = REAL( ( TMax - ZTime )*DeltTime/( ZTime - PrevSimTime ), ReKi )          ! DeltTime/( ZTime - PrevSimTime ) is the delta_ClockTime divided by the delta_SimulationTime
     EndTime  =  MOD( CurrClockTime+SimTimeLeft, SecPerDay )
     EndHour  =  INT(   EndTime*InSecHr )
     EndMin   =  INT( ( EndTime - REAL( 3600*EndHour ) )*InSecMn )
     EndSec   = NINT(   EndTime - REAL( 3600*EndHour + 60*EndMin ) ) !bjj: this NINT can make the seconds say "60"
  
     WRITE (ETimeStr,"(I2.2,2(':',I2.2))")  EndHour, EndMin, EndSec
  
     CALL WrOver ( ' Timestep: '//TRIM( Num2LStr( NINT( ZTime ) ) )//' of '//TRIM( Num2LStr( TMax ) )// &
                   ' seconds.  Estimated final completion at '//ETimeStr//'.'                             )
  
  
        ! Let's save this time as the previous time for the next call to the routine
     PrevClockTime = CurrClockTime
     PrevSimTime   = ZTime
  
     RETURN
  END SUBROUTINE SimStatus
  !----------------------------------------------------------------------------------------------------------------------------------
  FUNCTION TimeValues2Seconds( TimeAry )
  ! This routine takes an array of time values such as that returned from
  !     CALL DATE_AND_TIME ( Values=TimeAry )
  ! and converts TimeAry to the number of seconds past midnight.
  !..................................................................................................................................
  
        ! Passed variables:
     INTEGER, INTENT(IN)          :: TimeAry  (8)                                    ! An array containing the elements of the time
     REAL(ReKi)                   :: TimeValues2Seconds                              ! Current time in seconds past midnight
  
  
     TimeValues2Seconds = 3600*TimeAry(5) + 60*TimeAry(6) + TimeAry(7) + 0.001_ReKi*TimeAry(8)
  
  END FUNCTION TimeValues2Seconds
  !----------------------------------------------------------------------------------------------------------------------------------
  
  END PROGRAM HydroDynDriver
  
  