anchor.diff:  CONTAINS
       !> 
       logical function Failed()
  -        CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName )
  +        CALL SetErrStatSimple( ErrStat, ErrMsg, 'ExtPtfm_ReadPrimaryFile' )
           Failed =  ErrStat >= AbortErrLev
           if(Failed) call cleanup()
       end function Failed
  
positive.code:    if (allocated(p%K11))  deallocate(p%C11)
     if (allocated(p%K22))  deallocate(p%C22)
     ! Allocation
     call allocAry(p%AMat, nX, nX, 'p%AMat', ErrStat2, ErrMsg2); if(Failed()) return ; p%AMat(1:nX,1:nX) =0
     call allocAry(p%BMat, nX, nU, 'p%BMat', ErrStat2, ErrMsg2); if(Failed()) return ; p%BMat(1:nX,1:nU) =0
     call allocAry(p%FX  , nX,     'p%FX'  , ErrStat2, ErrMsg2); if(Failed()) return ; p%Fx  (1:nX)      =0
     call allocAry(p%CMat, nY, nX, 'p%CMat', ErrStat2, ErrMsg2); if(Failed()) return ; p%CMat(1:nY,1:nX) =0
     call allocAry(p%DMat, nY, nU, 'p%DMat', ErrStat2, ErrMsg2); if(Failed()) return ; p%DMat(1:nY,1:nU) =0
     call allocAry(p%FY  , nY,     'p%FY'  , ErrStat2, ErrMsg2); if(Failed()) return ; p%FY  (1:nY)      =0
     call allocAry(p%M11 , n1, n1, 'p%M11' , ErrStat2, ErrMsg2); if(Failed()) return ; p%M11 (1:n1,1:n1) =0
     call allocAry(p%K11 , n1, n1, 'p%K11' , ErrStat2, ErrMsg2); if(Failed()) return ; p%K11 (1:n1,1:n1) =0
     call allocAry(p%C11 , n1, n1, 'p%C11' , ErrStat2, ErrMsg2); if(Failed()) return ; p%C11 (1:n1,1:n1) =0
     call allocAry(p%M22 , n2, n2, 'p%M22' , ErrStat2, ErrMsg2); if(Failed()) return ; p%M22 (1:n2,1:n2) =0
     call allocAry(p%K22 , n2, n2, 'p%K22' , ErrStat2, ErrMsg2); if(Failed()) return ; p%K22 (1:n2,1:n2) =0
     call allocAry(p%C22 , n2, n2, 'p%C22' , ErrStat2, ErrMsg2); if(Failed()) return ; p%C22 (1:n2,1:n2) =0
     call allocAry(p%M12 , n1, n2, 'p%M12' , ErrStat2, ErrMsg2); if(Failed()) return ; p%M12 (1:n1,1:n2) =0
     call allocAry(p%C12 , n1, n2, 'p%C12' , ErrStat2, ErrMsg2); if(Failed()) return ; p%C12 (1:n1,1:n2) =0
     call allocAry(p%M21 , n2, n1, 'p%M21' , ErrStat2, ErrMsg2); if(Failed()) return ; p%M21 (1:n2,1:n1) =0
     call allocAry(p%C21 , n2, n1, 'p%C21' , ErrStat2, ErrMsg2); if(Failed()) return ; p%C21 (1:n2,1:n1) =0
     call allocAry(  I22 , n2, n2, '  I22' , ErrStat2, ErrMsg2); if(Failed()) return ;   I22 (1:n2,1:n2) =0
     do I=1,n2 ; I22(I,I)=1; enddo ! Identity matrix
     ! Submatrices
     p%M11(1:n1,1:n1) = p%PtfmAM(1:n1      ,1:n1      )
  
negative.code:    z%DummyConstrState         = 0.0_ReKi
     ! allocate OtherState%xdot if using multi-step method; initialize n
     if ( ( p%IntMethod .eq. 2) .OR. ( p%IntMethod .eq. 3)) THEN
         allocate( OtherState%xdot(4), STAT=ErrStat )
         ErrMsg='Error allocating OtherState%xdot'
         if(Failed()) return
     endif
  
     ! Initialize Misc Variables:
     m%Indx = 1 ! used to optimize interpolation of loads in time
     call AllocAry( m%PtfmFt, p%nTot,'Loads at t', ErrStat,ErrMsg); if(Failed()) return
     do I=1,p%nTot; m%PtfmFt(I)=0; end do
     call AllocAry( m%xFlat, 2*p%nCB,'xFlat', ErrStat,ErrMsg); if(Failed()) return
     do I=1,2*p%nCB; m%xFlat(I)=0; end do
     do I=1,18; m%uFlat(I)=0; end do
     
     ! Define initial guess (set up mesh first) for the system inputs here:
     call Init_meshes(u, y, ErrStat, ErrMsg); if(Failed()) return
  
     ! Define system output initializations (set up mesh) here:
     call AllocAry( y%WriteOutput,        p%NumOuts,'WriteOutput',   ErrStat,ErrMsg); if(Failed()) return
     call AllocAry(InitOut%WriteOutputHdr,p%NumOuts,'WriteOutputHdr',ErrStat,ErrMsg); if(Failed()) return
     call AllocAry(InitOut%WriteOutputUnt,p%NumOuts,'WriteOutputUnt',ErrStat,ErrMsg); if(Failed()) return
  
     InitOut%Ver = ExtPtfm_Ver
        
     if (InitInp%Linearize) then
        ! If the module does not implement the four Jacobian routines at the end of this template, or the module cannot
        ! linearize with the features that are enabled, stop the simulation if InitInp%Linearize is true.
        CALL SetErrStat( ErrID_Fatal, 'ExtPtfm_MCKF cannot perform linearization analysis.', ErrStat, ErrMsg, 'ExtPtfm_Init')
        ! Otherwise, if the module does allow linearization, return the appropriate Jacobian row/column names and rotating-frame flags here:   
        ! Allocate and set these variables: InitOut%LinNames_y, InitOut%LinNames_x, InitOut%LinNames_xd, InitOut%LinNames_z, InitOut%LinNames_u 
        ! Allocate and set these variables: InitOut%RotFrame_y, InitOut%RotFrame_x, InitOut%RotFrame_xd, InitOut%RotFrame_z, InitOut%RotFrame_u 
     end if
  CONTAINS
      logical function Failed()
          CALL SetErrStatSimple(ErrStat, ErrMsg, 'ExtPtfm_Init')
          Failed =  ErrStat >= AbortErrLev
      end function Failed
  END SUBROUTINE ExtPtfm_Init
  