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:          ! Calculate outputs at n
  
        CALL HydroDyn_CalcOutput( Time, u(1), p, x, xd, z, OtherState, y, 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
  
        
        
           ! Get state variables at next step: INPUT at step n, OUTPUT at step n + 1
  
        CALL HydroDyn_UpdateStates( Time, n, u, InputTime, p, x, xd, z, OtherState, 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     
        
        !-----------------------------------------------------------------------------
        ! DEBUG - Print Mesh Information
        !WRITE(MeshDebugFile,'("HD_MeshInfo_",I2,".txt")' )  n
        !CALL GetNewUnit( UnMeshDebug ) 
        !CALL OpenFOutFile ( UnMeshDebug, TRIM(MeshDebugFile), ErrStat   )  ! Open WAMIT inputs file.
        !WRITE(UnMeshDebug,'("u(1)%Morison%DistribMesh")')
        !CALL MeshPrintInfo ( UnMeshDebug, u(1)%Morison%DistribMesh,100)
        !WRITE(UnMeshDebug,'("y%Morison%DistribMesh")')
        !CALL MeshPrintInfo ( UnMeshDebug, y%Morison%DistribMesh,100)
        !CLOSE(UnMeshDebug)
        !-----------------------------------------------------------------------------
        
  
        ! Write output to a file which is managed by the driver program and not the individual modules
        ! TODO
        
     END DO
  
     ! For Debug:  TODO  Remove when no longer needed GJH 9/30/2013 
     !Write(AngleMsg, '(F10.4)') ,maxAngle
     !CALL WrScr('The largest input rotation angle was: '//AngleMsg)
     
     CALL HydroDyn_DestroyDiscState( xd_new, 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
  
     CALL HydroDyn_DestroyContState( x_new, 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
  
  
  ! For now, finish here.
  
   
     !...............................................................................................................................
     ! Routine to terminate program execution (again)
     !...............................................................................................................................
  
     CALL HydroDyn_End( u(1), p, x, xd, z, OtherState, y, ErrStat, ErrMsg )
     IF ( ErrStat /= ErrID_None ) THEN
        CALL WrScr( ErrMsg )
        ! TODO Add additional error handling and terminate
     END IF
  
  
  CONTAINS
  
  !====================================================================================================
  SUBROUTINE CleanupEchoFile( EchoFlag, UnEcho)
  !     The routine cleans up the module echo file and resets the NWTC_Library, reattaching it to 
  
negative.code:    !...............................................................................................................................
     ! Routines called in loose coupling -- the glue code may implement this in various ways
     !...............................................................................................................................
     Time = 0.0
     CALL SimStatus_FirstTime( TiLstPrn, PrevClockTime, SimStrtTime, UsrTime2, time, InitInData%TMax )
  
     DO n = 1, drvrInitInp%NSteps
  
  