anchor.diff:  
        !  Parse the FileInfo_In structure of data from the inputfile into the InitInp%InputFile structure
      CALL ParseInputFileInfo( PriPath, InitInp%InputFile, TRIM(InitInp%RootName), FileInfo_In, InputFileData, Interval, ErrStat2, ErrMsg2 )
  -      CALL CheckError( ErrStat2, ErrMsg2 )
  -      IF (ErrStat >= AbortErrLev) RETURN
  +      if (Failed())  return;
   
      CALL ValidatePrimaryData( InitInp, InputFileData, ErrStat2, ErrMsg2 )
  -      CALL CheckError( ErrStat2, ErrMsg2 )
  -      IF (ErrStat >= AbortErrLev) RETURN
  +      if (Failed())  return;
         
      if ( (InitInp%NumCtrl2SC  > 0 .and. InitInp%NumCtrl2SC <= 0) .or. &
           (InitInp%NumSC2Ctrl <= 0 .and. InitInp%NumSC2Ctrl  > 0) ) then      
  -      call CheckError( ErrID_Fatal, "If supercontroller is used, there must be at least one supercontroller input and one supercontroller output." )
  +      call SetErrStat( ErrID_Fatal, "If supercontroller is used, there must be at least one supercontroller input and one supercontroller output.",ErrStat,ErrMsg,RoutineName)
  +      call Cleanup()
         return
      end if
           
  
positive.code:       
     END IF
           
     
  !FIXME: split out this sectino as a subroutine.  Must allocate the spaces for each of these.
  !      !............................................................................................
  !      ! Initialize the StrucCtrl module for Nacelle:
  !      !............................................................................................
  !   IF (p%CompNStC) THEN
  !      
  !      StC_InitInp%InputFile      =  InputFileData%NStCfile
  !      StC_InitInp%RootName       =  TRIM(p%RootName)//'.NStC'
  !      StC_InitInp%Gravity        =  InitInp%gravity
  !      StC_InitInp%NumMeshPts     =  1_IntKi        ! single point mesh for Nacelle 
  !
  !      CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !      CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !      StC_InitInp%InitPosition(:,1)      = InitInp%NacPosition
  !      StC_InitInp%InitOrientation(:,:,1) = InitInp%NacOrientation
  !      
  !      CALL StC_Init( StC_InitInp, u%NStC, p%NStC, x%NStC, xd%NStC, z%NStC, OtherState%NStC, y%NStC, m%NStC, Interval, StC_InitOut, ErrStat2, ErrMsg2 )
  !!print*,'SrvD_Init: after StC_Init CompNStC: ', ErrStat2,ErrMsg2
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !      
  !      IF (.NOT. EqualRealNos( Interval, p%DT ) ) THEN
  !         CALL CheckError( ErrID_Fatal, "Nacelle StrucCtrl time step differs from SrvD time step." )
  !         RETURN
  !      END IF
  !
  !      CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )   
  !   
  !   END IF
  !   
  !      !............................................................................................
  !      ! Initialize the StrucCtrl module for tower:
  !      !............................................................................................
  !   IF (p%CompTStC) THEN
  !      
  !      StC_InitInp%InputFile      =  InputFileData%TStCfile
  !      StC_InitInp%RootName       =  TRIM(p%RootName)//'.TStC'
  !      StC_InitInp%Gravity        =  InitInp%gravity
  !      StC_InitInp%NumMeshPts     =  1_IntKi        ! single point mesh for Tower 
  !
  !      CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !      CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !      StC_InitInp%InitPosition(:,1)      = InitInp%TwrBasePos
  !      StC_InitInp%InitOrientation(:,:,1) = InitInp%TwrBaseOrient
  !      
  !      CALL StC_Init( StC_InitInp, u%TStC, p%TStC, x%TStC, xd%TStC, z%TStC, OtherState%TStC, y%TStC, m%TStC, Interval, StC_InitOut, ErrStat2, ErrMsg2 )
  !!print*,'SrvD_Init: after StC_Init CompTStC: ', ErrStat2,ErrMsg2
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !      
  !      IF (.NOT. EqualRealNos( Interval, p%DT ) ) THEN
  !         CALL CheckError( ErrID_Fatal, "Tower StrucCtrl time step differs from SrvD time step." )
  !         RETURN
  !      END IF
  !
  !      CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )   
  !   
  !   END IF
  !    
  !      !............................................................................................
  !      ! Initialize the StrucCtrl module for blade:
  !      !............................................................................................
  !   IF (p%CompBStC) THEN
  !      
  !      StC_InitInp%InputFile      =  InputFileData%BStCfile
  !      StC_InitInp%RootName       =  TRIM(p%RootName)//'.BStC'
  !      StC_InitInp%Gravity        =  InitInp%gravity
  !      StC_InitInp%NumMeshPts     =  p%NumBl        ! p%NumBl points for blades 
  !
  !      CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !      CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !      do k=1,StC_InitInp%NumMeshPts
  !         StC_InitInp%InitPosition(:,k)      = InitInp%BladeRootPosition(:,k)
  !         StC_InitInp%InitOrientation(:,:,k) = InitInp%BladeRootOrientation(:,:,k)
  !      enddo
  !      CALL StC_Init( StC_InitInp, u%BStC, p%BStC, x%BStC, xd%BStC, z%BStC, OtherState%BStC, y%BStC, m%BStC, Interval, StC_InitOut, ErrStat2, ErrMsg2 )
  !!print*,'SrvD_Init: after StC_Init CompBStC: ', ErrStat2,ErrMsg2
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !      
  !      IF (.NOT. EqualRealNos( Interval, p%DT ) ) THEN
  !         CALL CheckError( ErrID_Fatal, "Blade StrucCtrl time step differs from SrvD time step." )
  !         RETURN
  !      END IF
  !
  !      CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )   
  !   
  !   END IF
  !   
  !
  !      !............................................................................................
  !      ! Initialize the StrucCtrl module for hydrodynamics platform: (multiple instances will be called for multiple platform points)
  !      !............................................................................................
  !   IF (p%CompPtfmStC) THEN
  !
  !      StC_InitInp%InputFile      =  InputFileData%PtfmStCfile
  !      StC_InitInp%RootName       =  TRIM(p%RootName)//'.PtfmStC'
  !      StC_InitInp%Gravity        =  InitInp%gravity
  !      StC_InitInp%NumMeshPts     =  1_IntKi        ! single point mesh for Platform
  !
  !      CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !      CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation', errStat2, ErrMsg2)
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !      StC_InitInp%InitPosition(:,1)      = InitInp%NacPosition
  !      StC_InitInp%InitOrientation(:,:,1) = InitInp%NacOrientation
  !
  !      CALL StC_Init( StC_InitInp, u%PtfmStC, p%PtfmStC, x%PtfmStC, xd%PtfmStC, z%PtfmStC, OtherState%PtfmStC, y%PtfmStC, m%PtfmStC, Interval, StC_InitOut, ErrStat2, ErrMsg2 )
  !!print*,'SrvD_Init: after StC_Init CompPtfmStC: ', ErrStat2,ErrMsg2
  !         CALL CheckError( ErrStat2, ErrMsg2 )
  !         IF (ErrStat >= AbortErrLev) RETURN
  !
  !      IF (.NOT. EqualRealNos( Interval, p%DT ) ) THEN
  !         CALL CheckError( ErrID_Fatal, "Platform StrucCtrl time step differs from SrvD time step." )
  !         RETURN
  !      END IF
  !
  !      CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )   
  !
  !   END IF
  
  
        !............................................................................................
  
negative.code:       ! Clean up the local variables:
        !............................................................................................
     CALL SrvD_DestroyInputFile( InputFileData, ErrStat2, ErrMsg2 )
     CALL StC_DestroyInitOutput(StC_InitOut, ErrStat2, ErrMsg2 )
  
     RETURN
  
  contains
     logical function Failed()
        CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
        Failed = ErrStat >= AbortErrLev
        if (Failed)    call Cleanup()
     end function Failed
     subroutine Cleanup()    ! Ignore any errors here
        CALL SrvD_DestroyInputFile(InputFileData, ErrStat2, ErrMsg2 )
        CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )
        CALL StC_DestroyInitOutput(StC_InitOut, ErrStat2, ErrMsg2 )
     end subroutine Cleanup
  END SUBROUTINE SrvD_Init
  !----------------------------------------------------------------------------------------------------------------------------------
  
  !----------------------------------------------------------------------------------------------------------------------------------
  !> This routine sets the data structures for the structural control (StC) module -- Nacelle Instances
  subroutine StC_Nacelle_Setup(SrvD_InitInp,SrvD_p,InputFileData,u,p,x,xd,z,OtherState,y,m,ErrStat,ErrMsg)
     type(SrvD_InitInputType),                    intent(in   )  :: SrvD_InitInp   !< Input data for initialization routine
     type(SrvD_ParameterType),                    intent(in   )  :: SrvD_p         !< Parameters
     TYPE(SrvD_InputFile),                        intent(in   )  :: InputFileData  ! Data stored in the module's input file
     type(StC_InputType),             allocatable,intent(  out)  :: u(:)           !< An initial guess for the input; input mesh must be defined
     type(StC_ParameterType),         allocatable,intent(  out)  :: p(:)           !< Parameters
     type(StC_ContinuousStateType),   allocatable,intent(  out)  :: x(:)           !< Initial continuous states
     type(StC_DiscreteStateType),     allocatable,intent(  out)  :: xd(:)          !< Initial discrete states
     type(StC_ConstraintStateType),   allocatable,intent(  out)  :: z(:)           !< Initial guess of the constraint states
     type(StC_OtherStateType),        allocatable,intent(  out)  :: OtherState(:)  !< Initial other states
     type(StC_OutputType),            allocatable,intent(  out)  :: y(:)           !< Initial system outputs (outputs are not calculated;
     type(StC_MiscVarType),           allocatable,intent(  out)  :: m(:)           !< Misc (optimization) variables
     integer(IntKi),                              intent(  out)  :: ErrStat        !< Error status of the operation
     character(*),                                intent(  out)  :: ErrMsg         !< Error message if ErrStat /= ErrID_None
  
     integer(IntKi)             :: ErrStat2       ! temporary Error status of the operation
     character(ErrMsgLen)       :: ErrMsg2        ! temporary Error message if ErrStat /= ErrID_None
     integer(IntKi)             :: j              ! Counter for the instances
     real(DbKi)                 :: Interval       !< Coupling interval in seconds from StC
     type(StC_InitInputType)    :: StC_InitInp    !< data to initialize StC module
     type(StC_InitOutputType)   :: StC_InitOut    !< data from StC module initialization (not currently used)
     character(*), parameter    :: RoutineName = 'StC_Nacelle_Setup'
  
     ErrStat  = ErrID_None
     ErrMsg   = ""
  
     if (SrvD_p%CompNStC > 0_IntKi) then
        allocate(u(SrvD_p%CompNStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, u') )            return;
        allocate(p(SrvD_p%CompNStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, p') )            return;
        allocate(x(SrvD_p%CompNStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, x') )            return;
        allocate(xd(SrvD_p%CompNStC),STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, xd') )           return;
        allocate(z(SrvD_p%CompNStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, z') )            return;
        allocate(OtherState(SrvD_p%CompNStC), STAT=ErrStat2); if ( AllErr('Could not allocate StrucCtrl input array, OtherState') )   return;
        allocate(y(SrvD_p%CompNStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, y') )            return;
        allocate(m(SrvD_p%CompNStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, m') )            return;
  
        do j=1,SrvD_p%CompNStC
           StC_InitInp%InputFile      =  InputFileData%NStCfile(j)
           StC_InitInp%RootName       =  TRIM(SrvD_p%RootName)//'.NStC'
           StC_InitInp%Gravity        =  SrvD_InitInp%gravity
           StC_InitInp%NumMeshPts     =  1_IntKi        ! single point mesh for Nacelle
  
           CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition',     errStat2, ErrMsg2);  if (Failed())  return;
           CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation',  errStat2, ErrMsg2);  if (Failed())  return;
           StC_InitInp%InitPosition(:,1)      = SrvD_InitInp%NacPosition
           StC_InitInp%InitOrientation(:,:,1) = SrvD_InitInp%NacOrientation
  
           CALL StC_Init( StC_InitInp, u(j), p(j), x(j), xd(j), z(j), OtherState(j), y(j), m(j), Interval, StC_InitOut, ErrStat2, ErrMsg2 )
           if (Failed())  return;
  
           IF (.NOT. EqualRealNos( Interval, SrvD_p%DT ) ) &
              CALL SetErrStat( ErrID_Fatal, "Nacelle StrucCtrl (instance "//trim(num2lstr(j))//") time step differs from SrvD time step.",ErrStat,ErrMsg,RoutineName )
           if (Failed())  return;
  
           call Cleanup()
        enddo
     endif
  contains
     logical function Failed()
        CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
        Failed = ErrStat >= AbortErrLev
        if (Failed)    call Cleanup()
     end function Failed
     logical function AllErr(Msg)
        character(*), intent(in) :: Msg
        if(ErrStat2 /= 0) then
           CALL SetErrStat( ErrID_Fatal, Msg, ErrStat, ErrMsg, RoutineName )
        endif
        AllErr = ErrStat >= AbortErrLev
        if (AllErr)    call Cleanup()
     end function AllErr
     subroutine Cleanup()    ! Ignore any errors here
        CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )
        CALL StC_DestroyInitOutput(StC_InitOut, ErrStat2, ErrMsg2 )
     end subroutine Cleanup
  end subroutine StC_Nacelle_Setup
  !----------------------------------------------------------------------------------------------------------------------------------
  !> This routine sets the data structures for the structural control (StC) module -- Tower instances
  subroutine StC_Tower_Setup(SrvD_InitInp,SrvD_p,InputFileData,u,p,x,xd,z,OtherState,y,m,ErrStat,ErrMsg)
     type(SrvD_InitInputType),                    intent(in   )  :: SrvD_InitInp   !< Input data for initialization routine
     type(SrvD_ParameterType),                    intent(in   )  :: SrvD_p         !< Parameters
     TYPE(SrvD_InputFile),                        intent(in   )  :: InputFileData  ! Data stored in the module's input file
     type(StC_InputType),             allocatable,intent(  out)  :: u(:)           !< An initial guess for the input; input mesh must be defined
     type(StC_ParameterType),         allocatable,intent(  out)  :: p(:)           !< Parameters
     type(StC_ContinuousStateType),   allocatable,intent(  out)  :: x(:)           !< Initial continuous states
     type(StC_DiscreteStateType),     allocatable,intent(  out)  :: xd(:)          !< Initial discrete states
     type(StC_ConstraintStateType),   allocatable,intent(  out)  :: z(:)           !< Initial guess of the constraint states
     type(StC_OtherStateType),        allocatable,intent(  out)  :: OtherState(:)  !< Initial other states
     type(StC_OutputType),            allocatable,intent(  out)  :: y(:)           !< Initial system outputs (outputs are not calculated;
     type(StC_MiscVarType),           allocatable,intent(  out)  :: m(:)           !< Misc (optimization) variables
     integer(IntKi),                              intent(  out)  :: ErrStat        !< Error status of the operation
     character(*),                                intent(  out)  :: ErrMsg         !< Error message if ErrStat /= ErrID_None
  
     integer(IntKi)             :: ErrStat2       ! temporary Error status of the operation
     character(ErrMsgLen)       :: ErrMsg2        ! temporary Error message if ErrStat /= ErrID_None
     integer(IntKi)             :: j              ! Counter for the instances
     real(DbKi)                 :: Interval       !< Coupling interval in seconds from StC
     type(StC_InitInputType)    :: StC_InitInp    !< data to initialize StC module
     type(StC_InitOutputType)   :: StC_InitOut    !< data from StC module initialization (not currently used)
     character(*), parameter    :: RoutineName = 'StC_Tower_Setup'
  
     ErrStat  = ErrID_None
     ErrMsg   = ""
  
     if (SrvD_p%CompTStC > 0_IntKi) then
        allocate(u(SrvD_p%CompTStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, u') )            return;
        allocate(p(SrvD_p%CompTStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, p') )            return;
        allocate(x(SrvD_p%CompTStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, x') )            return;
        allocate(xd(SrvD_p%CompTStC),STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, xd') )           return;
        allocate(z(SrvD_p%CompTStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, z') )            return;
        allocate(OtherState(SrvD_p%CompTStC), STAT=ErrStat2); if ( AllErr('Could not allocate StrucCtrl input array, OtherState') )   return;
        allocate(y(SrvD_p%CompTStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, y') )            return;
        allocate(m(SrvD_p%CompTStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, m') )            return;
  
        do j=1,SrvD_p%CompTStC
           StC_InitInp%InputFile      =  InputFileData%TStCfile(j)
           StC_InitInp%RootName       =  TRIM(SrvD_p%RootName)//'.TStC'
           StC_InitInp%Gravity        =  SrvD_InitInp%gravity
           StC_InitInp%NumMeshPts     =  1_IntKi        ! single point mesh for Tower
  
           CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition',     errStat2, ErrMsg2);  if (Failed())  return;
           CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation',  errStat2, ErrMsg2);  if (Failed())  return;
           StC_InitInp%InitPosition(:,1)      = SrvD_InitInp%TwrBasePos
           StC_InitInp%InitOrientation(:,:,1) = SrvD_InitInp%TwrBaseOrient
  
           CALL StC_Init( StC_InitInp, u(j), p(j), x(j), xd(j), z(j), OtherState(j), y(j), m(j), Interval, StC_InitOut, ErrStat2, ErrMsg2 )
           if (Failed())  return;
  
           IF (.NOT. EqualRealNos( Interval, SrvD_p%DT ) ) &
              CALL SetErrStat( ErrID_Fatal, "Tower StrucCtrl (instance "//trim(num2lstr(j))//") time step differs from SrvD time step.",ErrStat,ErrMsg,RoutineName )
           if (Failed())  return;
  
           call Cleanup()
        enddo
     endif
  contains
     logical function Failed()
        CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
        Failed = ErrStat >= AbortErrLev
        if (Failed)    call Cleanup()
     end function Failed
     logical function AllErr(Msg)
        character(*), intent(in) :: Msg
        if(ErrStat2 /= 0) then
           CALL SetErrStat( ErrID_Fatal, Msg, ErrStat, ErrMsg, RoutineName )
        endif
        AllErr = ErrStat >= AbortErrLev
        if (AllErr)    call Cleanup()
     end function AllErr
     subroutine Cleanup()    ! Ignore any errors here
        CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )
        CALL StC_DestroyInitOutput(StC_InitOut, ErrStat2, ErrMsg2 )
     end subroutine Cleanup
  end subroutine StC_Tower_Setup
  !----------------------------------------------------------------------------------------------------------------------------------
  !> This routine sets the data structures for the structural control (StC) module -- Blade instances
  subroutine StC_Blade_Setup(SrvD_InitInp,SrvD_p,InputFileData,u,p,x,xd,z,OtherState,y,m,ErrStat,ErrMsg)
     type(SrvD_InitInputType),                    intent(in   )  :: SrvD_InitInp   !< Input data for initialization routine
     type(SrvD_ParameterType),                    intent(in   )  :: SrvD_p         !< Parameters
     TYPE(SrvD_InputFile),                        intent(in   )  :: InputFileData  ! Data stored in the module's input file
     type(StC_InputType),             allocatable,intent(  out)  :: u(:)           !< An initial guess for the input; input mesh must be defined
     type(StC_ParameterType),         allocatable,intent(  out)  :: p(:)           !< Parameters
     type(StC_ContinuousStateType),   allocatable,intent(  out)  :: x(:)           !< Initial continuous states
     type(StC_DiscreteStateType),     allocatable,intent(  out)  :: xd(:)          !< Initial discrete states
     type(StC_ConstraintStateType),   allocatable,intent(  out)  :: z(:)           !< Initial guess of the constraint states
     type(StC_OtherStateType),        allocatable,intent(  out)  :: OtherState(:)  !< Initial other states
     type(StC_OutputType),            allocatable,intent(  out)  :: y(:)           !< Initial system outputs (outputs are not calculated;
     type(StC_MiscVarType),           allocatable,intent(  out)  :: m(:)           !< Misc (optimization) variables
     integer(IntKi),                              intent(  out)  :: ErrStat        !< Error status of the operation
     character(*),                                intent(  out)  :: ErrMsg         !< Error message if ErrStat /= ErrID_None
  
     integer(IntKi)             :: ErrStat2       ! temporary Error status of the operation
     character(ErrMsgLen)       :: ErrMsg2        ! temporary Error message if ErrStat /= ErrID_None
     integer(IntKi)             :: j              ! Counter for the instances
     real(DbKi)                 :: Interval       !< Coupling interval in seconds from StC
     type(StC_InitInputType)    :: StC_InitInp    !< data to initialize StC module
     type(StC_InitOutputType)   :: StC_InitOut    !< data from StC module initialization (not currently used)
     character(*), parameter    :: RoutineName = 'StC_Blade_Setup'
  
     ErrStat  = ErrID_None
     ErrMsg   = ""
  
     if (SrvD_p%CompBStC > 0_IntKi) then
        allocate(u(SrvD_p%CompBStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, u') )            return;
        allocate(p(SrvD_p%CompBStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, p') )            return;
        allocate(x(SrvD_p%CompBStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, x') )            return;
        allocate(xd(SrvD_p%CompBStC),STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, xd') )           return;
        allocate(z(SrvD_p%CompBStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, z') )            return;
        allocate(OtherState(SrvD_p%CompBStC), STAT=ErrStat2); if ( AllErr('Could not allocate StrucCtrl input array, OtherState') )   return;
        allocate(y(SrvD_p%CompBStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, y') )            return;
        allocate(m(SrvD_p%CompBStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, m') )            return;
  
        do j=1,SrvD_p%CompBStC
           StC_InitInp%InputFile      =  InputFileData%BStCfile(j)
           StC_InitInp%RootName       =  TRIM(SrvD_p%RootName)//'.BStC'
           StC_InitInp%Gravity        =  SrvD_InitInp%gravity
           StC_InitInp%NumMeshPts     =  SrvD_p%NumBl        ! p%NumBl points for blades
  
           CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition',     errStat2, ErrMsg2);  if (Failed())  return;
           CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation',  errStat2, ErrMsg2);  if (Failed())  return;
           StC_InitInp%InitPosition(:,1)      = SrvD_InitInp%TwrBasePos
           StC_InitInp%InitOrientation(:,:,1) = SrvD_InitInp%TwrBaseOrient
  
           CALL StC_Init( StC_InitInp, u(j), p(j), x(j), xd(j), z(j), OtherState(j), y(j), m(j), Interval, StC_InitOut, ErrStat2, ErrMsg2 )
           if (Failed())  return;
  
           IF (.NOT. EqualRealNos( Interval, SrvD_p%DT ) ) &
              CALL SetErrStat( ErrID_Fatal, "Blade StrucCtrl (instance "//trim(num2lstr(j))//") time step differs from SrvD time step.",ErrStat,ErrMsg,RoutineName )
           if (Failed())  return;
  
           call Cleanup()
        enddo
     endif
  contains
     logical function Failed()
        CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
        Failed = ErrStat >= AbortErrLev
        if (Failed)    call Cleanup()
     end function Failed
     logical function AllErr(Msg)
        character(*), intent(in) :: Msg
        if(ErrStat2 /= 0) then
           CALL SetErrStat( ErrID_Fatal, Msg, ErrStat, ErrMsg, RoutineName )
        endif
        AllErr = ErrStat >= AbortErrLev
        if (AllErr)    call Cleanup()
     end function AllErr
     subroutine Cleanup()    ! Ignore any errors here
        CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )
        CALL StC_DestroyInitOutput(StC_InitOut, ErrStat2, ErrMsg2 )
     end subroutine Cleanup
  end subroutine StC_Blade_Setup
  !----------------------------------------------------------------------------------------------------------------------------------
  !> This routine sets the data structures for the structural control (StC) module -- hydrodynamics platform instances
  subroutine StC_Ptfm_Setup(SrvD_InitInp,SrvD_p,InputFileData,u,p,x,xd,z,OtherState,y,m,ErrStat,ErrMsg)
     type(SrvD_InitInputType),                    intent(in   )  :: SrvD_InitInp   !< Input data for initialization routine
     type(SrvD_ParameterType),                    intent(in   )  :: SrvD_p         !< Parameters
     TYPE(SrvD_InputFile),                        intent(in   )  :: InputFileData  ! Data stored in the module's input file
     type(StC_InputType),             allocatable,intent(  out)  :: u(:)           !< An initial guess for the input; input mesh must be defined
     type(StC_ParameterType),         allocatable,intent(  out)  :: p(:)           !< Parameters
     type(StC_ContinuousStateType),   allocatable,intent(  out)  :: x(:)           !< Initial continuous states
     type(StC_DiscreteStateType),     allocatable,intent(  out)  :: xd(:)          !< Initial discrete states
     type(StC_ConstraintStateType),   allocatable,intent(  out)  :: z(:)           !< Initial guess of the constraint states
     type(StC_OtherStateType),        allocatable,intent(  out)  :: OtherState(:)  !< Initial other states
     type(StC_OutputType),            allocatable,intent(  out)  :: y(:)           !< Initial system outputs (outputs are not calculated;
     type(StC_MiscVarType),           allocatable,intent(  out)  :: m(:)           !< Misc (optimization) variables
     integer(IntKi),                              intent(  out)  :: ErrStat        !< Error status of the operation
     character(*),                                intent(  out)  :: ErrMsg         !< Error message if ErrStat /= ErrID_None
  
     integer(IntKi)             :: ErrStat2       ! temporary Error status of the operation
     character(ErrMsgLen)       :: ErrMsg2        ! temporary Error message if ErrStat /= ErrID_None
     integer(IntKi)             :: j              ! Counter for the instances
     real(DbKi)                 :: Interval       !< Coupling interval in seconds from StC
     type(StC_InitInputType)    :: StC_InitInp    !< data to initialize StC module
     type(StC_InitOutputType)   :: StC_InitOut    !< data from StC module initialization (not currently used)
     character(*), parameter    :: RoutineName = 'StC_Ptfm_Setup'
  
     ErrStat  = ErrID_None
     ErrMsg   = ""
  
     if (SrvD_p%CompPtfmStC > 0_IntKi) then
        allocate(u(SrvD_p%CompPtfmStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, u') )            return;
        allocate(p(SrvD_p%CompPtfmStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, p') )            return;
        allocate(x(SrvD_p%CompPtfmStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, x') )            return;
        allocate(xd(SrvD_p%CompPtfmStC),STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, xd') )           return;
        allocate(z(SrvD_p%CompPtfmStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, z') )            return;
        allocate(OtherState(SrvD_p%CompPtfmStC), STAT=ErrStat2); if ( AllErr('Could not allocate StrucCtrl input array, OtherState') )   return;
        allocate(y(SrvD_p%CompPtfmStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, y') )            return;
        allocate(m(SrvD_p%CompPtfmStC), STAT=ErrStat2);          if ( AllErr('Could not allocate StrucCtrl input array, m') )            return;
  
        do j=1,SrvD_p%CompPtfmStC
           StC_InitInp%InputFile      =  InputFileData%PtfmStCfile(j)
           StC_InitInp%RootName       =  TRIM(SrvD_p%RootName)//'.PtfmStC'
           StC_InitInp%Gravity        =  SrvD_InitInp%gravity
           StC_InitInp%NumMeshPts     =  1_IntKi        ! single point mesh for Platform
  
           CALL AllocAry( StC_InitInp%InitPosition,      3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitPosition',     errStat2, ErrMsg2);  if (Failed())  return;
           CALL AllocAry( StC_InitInp%InitOrientation,3, 3, StC_InitInp%NumMeshPts, 'StC_InitInp%InitOrientation',  errStat2, ErrMsg2);  if (Failed())  return;
  !FIXME: this is not correct -- should be platform point or something like that.
           StC_InitInp%InitPosition(:,1)      = SrvD_InitInp%TwrBasePos
           StC_InitInp%InitOrientation(:,:,1) = SrvD_InitInp%TwrBaseOrient
  
           CALL StC_Init( StC_InitInp, u(j), p(j), x(j), xd(j), z(j), OtherState(j), y(j), m(j), Interval, StC_InitOut, ErrStat2, ErrMsg2 )
           if (Failed())  return;
  
           IF (.NOT. EqualRealNos( Interval, SrvD_p%DT ) ) &
              CALL SetErrStat( ErrID_Fatal, "Platform StrucCtrl (instance "//trim(num2lstr(j))//") time step differs from SrvD time step.",ErrStat,ErrMsg,RoutineName )
           if (Failed())  return;
  
           call Cleanup()
        enddo
     endif
  contains
     logical function Failed()
        CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
        Failed = ErrStat >= AbortErrLev
        if (Failed)    call Cleanup()
     end function Failed
     logical function AllErr(Msg)
        character(*), intent(in) :: Msg
        if(ErrStat2 /= 0) then
           CALL SetErrStat( ErrID_Fatal, Msg, ErrStat, ErrMsg, RoutineName )
        endif
        AllErr = ErrStat >= AbortErrLev
        if (AllErr)    call Cleanup()
     end function AllErr
     subroutine Cleanup()    ! Ignore any errors here
        CALL StC_DestroyInitInput(StC_InitInp, ErrStat2, ErrMsg2 )
        CALL StC_DestroyInitOutput(StC_InitOut, ErrStat2, ErrMsg2 )
     end subroutine Cleanup
  end subroutine StC_Ptfm_Setup
  
  !----------------------------------------------------------------------------------------------------------------------------------
  !> This routine is called at the end of the simulation.
  SUBROUTINE SrvD_End( u, p, x, xd, z, OtherState, y, m, ErrStat, ErrMsg )
  