anchor.diff:              DO i=1,6 !call ED_CalcOutput
                     
                  CALL ED_CopyInput(  u_ED, u_ED_perturb, MESH_UPDATECOPY, ErrStat2, ErrMsg2 )
  -                  CALL CheckError( ErrStat2, ErrMsg2  )
  -                  IF ( ErrStat >= AbortErrLev ) RETURN            
  +                  CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )            
                  u_perturb = u            
                  CALL Perturb_u( i, u_perturb, u_ED_perturb=u_ED_perturb, perturb=ThisPerturb ) ! perturb u and u_ED by ThisPerturb [routine sets ThisPerturb]
                     
                  ! calculate outputs with perturbed inputs:
                  CALL ED_CalcOutput( this_time, u_ED_perturb, p_ED, x_ED, xd_ED, z_ED, OtherSt_ED, y_ED_perturb, ErrStat2, ErrMsg2 ) !calculate y_ED_perturb
  -                  CALL CheckError( ErrStat2, ErrMsg2  )
  -                  IF ( ErrStat >= AbortErrLev ) RETURN            
  +                  CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )            
                     
                     
                  CALL U_ED_HD_Residual(y_ED_perturb, y_HD, u_perturb, Fn_U_perturb) ! get this perturbation, U_perturb
                     IF ( ErrStat >= AbortErrLev ) RETURN ! U_ED_HD_Residual checks for error
  +                  
  +               IF (ErrStat >= AbortErrLev) THEN
  +                  CALL CleanUp()
  +                  RETURN
  +               END IF         
  +                  
                     
                  MeshMapData%Jacobian_ED_SD_HD(:,i) = (Fn_U_perturb - Fn_U_Resid) / ThisPerturb
                     
  
positive.code:    ! Check to see if we should output data this time step:
     !----------------------------------------------------------------------------------------
  
     CALL WriteOutputToFile(m_FAST%t_global, p_FAST, y_FAST, ED, AD, IfW, HD, SD, SrvD, MAPp, FEAM, IceF, IceD, ErrStat, ErrMsg)
        
     !----------------------------------------------------------------------------------------
     ! Display simulation status every SttsTime-seconds (i.e., n_SttsTime steps):
     !----------------------------------------------------------------------------------------   
  
negative.code:          u_delta = -Fn_U_Resid
           CALL LAPACK_getrs( TRANS="N", N=p_FAST%SizeJac_ED_SD_HD(4), A=MeshMapData%Jacobian_ED_SD_HD, &
                              IPIV=MeshMapData%Jacobian_pivot, B=u_delta, ErrStat=ErrStat2, ErrMsg=ErrMsg2 )
                 CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName  )
                 IF ( ErrStat >= AbortErrLev ) THEN
                    CALL CleanUp()
                    RETURN 
                 END IF
  
           !-------------------------------------------------------------------------------------------------
           ! check for error, update inputs (u_ED and u_HD), and iterate again
  