anchor.diff:      
       !> Checks that all inputs were correctly read
       subroutine CheckAllInputsRead()
  -        if (ErrStat2/=0) return
  -        if (p%nTot<0)                   then ; ErrStat2=ErrID_Fatal; ErrMsg2='ExtPtfm_MCKF, the total number of DOF was not set'; endif
  -        if (.not.allocated(p%PtfmAM))   then ; ErrStat2=ErrID_Fatal; ErrMsg2='ExtPtfm_MCKF, the mass matrix was not allocated.' ; endif
  -        if (.not.allocated(p%Stff))     then ; ErrStat2=ErrID_Fatal; ErrMsg2='ExtPtfm_MCKF, the stiffness matrix was not allocated.' ; endif
  -        if (.not.allocated(p%Damp))     then ; ErrStat2=ErrID_Fatal; ErrMsg2='ExtPtfm_MCKF, the damping matrix was not allocated.' ; endif
  -        if (.not.allocated(p%PtfmFt))   then ; ErrStat2=ErrID_Fatal; ErrMsg2='ExtPtfm_MCKF, the loads were not allocated.';endif
  -        if (.not.allocated(p%PtfmFt_t)) then ; ErrStat2=ErrID_Fatal; ErrMsg2='ExtPtfm_MCKF, the time vector was not allocated.'; endif
  +        if (ErrStat/=0) return
  +        if (p%nTot<0)                   then ; ErrStat=ErrID_Fatal; ErrMsg='The total number of DOF was not set'; endif
  +        if (.not.allocated(p%PtfmAM))   then ; ErrStat=ErrID_Fatal; ErrMsg='The mass matrix was not allocated.' ; endif
  +        if (.not.allocated(p%Stff))     then ; ErrStat=ErrID_Fatal; ErrMsg='The stiffness matrix was not allocated.' ; endif
  +        if (.not.allocated(p%Damp))     then ; ErrStat=ErrID_Fatal; ErrMsg='The damping matrix was not allocated.' ; endif
  +        if (.not.allocated(p%PtfmFt))   then ; ErrStat=ErrID_Fatal; ErrMsg='The loads were not allocated.';endif
  +        if (.not.allocated(p%PtfmFt_t)) then ; ErrStat=ErrID_Fatal; ErrMsg='The time vector was not allocated.'; endif
       end subroutine CheckAllInputsRead
   
      !> Reads a FLEX ASCII file for Guyan or CraigBampton reductions
      SUBROUTINE ReadFlexASCII()
  -       logical :: AllSet 
          REAL(ReKi) :: dt !< time step
          REAL(ReKi) :: T  !< total simulation time
   
  -       AllSet = .FALSE.
          T=-1
          dt=-1
          ! Get an available unit number for the file.
  -       CALL GetNewUnit( UnIn, ErrStat2, ErrMsg2 );               if ( ErrStat2 /= 0 ) return
  +       CALL GetNewUnit( UnIn, ErrStat, ErrMsg );               if ( ErrStat /= 0 ) return
          ! Open the Primary input file.
  -       CALL OpenFInpFile ( UnIn, InputFile, ErrStat2, ErrMsg2 ); if ( ErrStat2 /= 0 ) return
  +       CALL OpenFInpFile ( UnIn, InputFile, ErrStat, ErrMsg ); if ( ErrStat /= 0 ) return
   
          ! --- Reading file line by line
  -       ErrStat2=0
  +       ErrStat=0
          iLine=0
  -       do while (ErrStat2==0)
  +       do while (ErrStat==0)
              iLine=iLine+1
  -           read(UnIn,'(A)', iostat=ErrStat2) Line
  -           if (ErrStat2/=0) then
  -               if (ErrStat2 < 0) then
  -                   ErrStat2=0 ! End of file is fine
  +           read(UnIn,'(A)', iostat=ErrStat) Line
  +           if (ErrStat/=0) then
  +               if (ErrStat < 0) then
  +                   ErrStat=0 ! End of file is fine
                  else
  -                   ErrMsg2='Error while reading file '//trim(InputFile)// ' line '//Num2LStr(iLine)
  +                   ErrMsg='Error while reading file '//trim(InputFile)// ' line '//Num2LStr(iLine)
                  endif
                  exit
              endif
              ! Line content is analyzed as case incensitive 
              call Conv2UC(Line)
              if (index(Line,'!DIMENSION')==1) then
  -               p%nTot = ReadIntFromStr(Line(12:), '`dimension`, line '//Num2LStr(iLine), ErrStat2, ErrMsg2); if (ErrStat2 /= 0) exit
  +               p%nTot = ReadIntFromStr(Line(12:), '`dimension`, file '//trim(InputFile)//', line '//Num2LStr(iLine), ErrStat, ErrMsg); if (ErrStat /= 0) exit
                  p%nCB=p%nTot-6
   
              else if (index(Line,'!TIME INCREMENT IN SIMULATION:')==1) then
  -               dt =  ReadFloatFromStr(Line(31:), '`time increment`, line '//Num2LStr(iLine), ErrStat2, ErrMsg2); if (ErrStat2 /= 0) exit
  +               dt =  ReadFloatFromStr(Line(31:), '`time increment`, file '//trim(InputFile)//', line '//Num2LStr(iLine), ErrStat, ErrMsg); if (ErrStat /= 0) exit
   
              else if (index(Line,'!TOTAL SIMULATION TIME IN FILE:')==1) then
  -               T =  ReadFloatFromStr(Line(32:), '`total simulation time`, line '//Num2LStr(iLine), ErrStat2, ErrMsg2 ); if (ErrStat2 /= 0) exit
  +               T =  ReadFloatFromStr(Line(32:), '`total simulation time`, file '//trim(InputFile)//', line '//Num2LStr(iLine), ErrStat, ErrMsg ); if (ErrStat /= 0) exit
   
              else if (index(Line,'!MASS MATRIX')==1) then
                  iLine=iLine+1
  -               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat2, ErrMsg2); if (ErrStat2 /= 0) exit
  +               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat, ErrMsg); if (ErrStat /= 0) exit
                  if (p%nTot<0) exit
  -               call ReadRealMatrix(UnIn, InputFile, p%PtfmAM, 'Mass Matrix', p%nTot, p%nTot, ErrStat2, ErrMsg2, iLine)
  +               call ReadRealMatrix(UnIn, InputFile, p%PtfmAM, 'Mass Matrix', p%nTot, p%nTot, ErrStat, ErrMsg, iLine)
   
              else if (index(Line,'!STIFFNESS MATRIX')==1) then
                  iLine=iLine+1
  -               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat2, ErrMsg2);  if (ErrStat2 /= 0) exit
  +               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat, ErrMsg);  if (ErrStat /= 0) exit
                  if (p%nTot<0) exit
  -               call ReadRealMatrix(UnIn, InputFile, p%Stff, 'Stiffness Matrix', p%nTot, p%nTot, ErrStat2, ErrMsg2, iLine)
  +               call ReadRealMatrix(UnIn, InputFile, p%Stff, 'Stiffness Matrix', p%nTot, p%nTot, ErrStat, ErrMsg, iLine)
   
              else if (index(Line,'!DAMPING MATRIX')==1) then
                  iLine=iLine+1
  -               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat2, ErrMsg2); if (ErrStat2 /= 0) exit
  +               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat, ErrMsg); if (ErrStat /= 0) exit
                  if (p%nTot<0) exit
  -               call ReadRealMatrix(UnIn, InputFile, p%Damp, 'Damping Matrix', p%nTot, p%nTot, ErrStat2, ErrMsg2, iLine)
  +               call ReadRealMatrix(UnIn, InputFile, p%Damp, 'Damping Matrix', p%nTot, p%nTot, ErrStat, ErrMsg, iLine)
   
              else if (index(Line,'!LOADING AND WAVE ELEVATION')==1) then
                  iLine=iLine+1
  -               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat2, ErrMsg2)
  -               if (ErrStat2 /= 0) exit
  +               CALL ReadCom( UnIn, InputFile, 'Comment - Line '//Num2LStr(iLine), ErrStat, ErrMsg)
  +               if (ErrStat /= 0) exit
                  p%nPtfmFt = nint(T/dt)+1
                  if (p%nTot<0) exit
  -               call allocAry( p%PtfmFt,   max(1,p%nPtfmFt), p%nTot, 'p%PtfmFt',   ErrStat2, ErrMsg2); if (ErrStat2 /= 0) exit
  -               call allocAry( p%PtfmFt_t, max(1,p%nPtfmFt),         'p%PtfmFt_t', ErrStat2, ErrMsg2); if (ErrStat2 /= 0) exit
  +               call allocAry( p%PtfmFt,   max(1,p%nPtfmFt), p%nTot, 'p%PtfmFt',   ErrStat, ErrMsg); if (ErrStat /= 0) exit
  +               call allocAry( p%PtfmFt_t, max(1,p%nPtfmFt),         'p%PtfmFt_t', ErrStat, ErrMsg); if (ErrStat /= 0) exit
                  if (p%nPtfmFt == 0) then
                     p%PtfmFt   = 0.0_ReKi
                     p%PtfmFt_t = 0.0_ReKi
  
positive.code: 
  CONTAINS
      logical function Failed()
          CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
          Failed =  ErrStat >= AbortErrLev
      end function Failed
  END SUBROUTINE SetStateMatrices
  
negative.code:    CHARACTER(*),                      INTENT(  OUT)  :: ErrMsg      !< Error message if ErrStat /= ErrID_None
     ! Local variables
     INTEGER(IntKi)                                  :: I                 !< Generic counters
     real(ReKi), dimension(6)                        :: Fc                !< Output coupling force
     ! Compute the loads `fr1 fr2` at t (fr1 without added mass) by time interpolation of the inputs loads p%PtfmFt
     call InterpStpMat(REAL(t,ReKi), p%PtfmFt_t, p%PtfmFt, m%Indx, p%nPtfmFt, m%PtfmFt)
  
     ! --- Flatening vectors and using linear state formulation y=Cx+Du+Fy
     ! u flat (x1, \dot{x1}, \ddot{x1})
     m%uFlat(1:3)   = u%PtfmMesh%TranslationDisp(:,1)
     m%uFlat(4:6)   = GetSmllRotAngs(u%PtfmMesh%Orientation(:,:,1), ErrStat, ErrMsg); CALL SetErrStatSimple(ErrStat, ErrMsg, 'ExtPtfm_CalcOutput')
     m%uFlat(7:9  ) = u%PtfmMesh%TranslationVel(:,1)
     m%uFlat(10:12) = u%PtfmMesh%RotationVel   (:,1)
     m%uFlat(13:15) = u%PtfmMesh%TranslationAcc(:,1)
  