anchor.diff:     ErrStat = ErrID_None
      ErrMsg  = ""
                  
  -   ! note that we assume this block matrix has been initialized to the identity matrix before calling this routine
  -   ! We need to make six calls to SetBlockMatrix for the different output to input mappings
  -   ! LIN-TODO: Are this row and col still valid GJH 7/31/2020
  -   ! 1) Row 3, Col 1
  -   ! 2) Row 5, Col 1
  -   ! 3) Row 9, Col 7
  -   ! 4) Row 11, Col 7
  -   ! 5) Row 15, Col 13
  -   ! 6) Row 17, Col 13
      
      ! look at how the translational displacement gets transfered to the translational velocity and translational acceleration:
      !-------------------------------------------------------------------------------------------------
  
positive.code:                
        end if  ! if ( p_FAST%LinOutMod )
     end if     ! if ( p_FAST%CompMooring  == Module_MAP )
     
     !.....................
     ! SubDyn
     !.....................
     if ( p_FAST%CompSub == Module_SD ) then 
        ! get the jacobians
        call SD_JacobianPInput( t_global, SD%Input(1), SD%p, SD%x(STATE_CURR), SD%xd(STATE_CURR), &
                SD%z(STATE_CURR), SD%OtherSt(STATE_CURR),  SD%y, SD%m, ErrStat2, ErrMsg2, &
                dYdu=y_FAST%Lin%Modules(Module_SD)%Instance(1)%D, dXdu=y_FAST%Lin%Modules(Module_SD)%Instance(1)%B )
        if(Failed()) return;
  
        call SD_JacobianPContState( t_global, SD%Input(1), SD%p, SD%x(STATE_CURR), SD%xd(STATE_CURR), &
            SD%z(STATE_CURR), SD%OtherSt(STATE_CURR), SD%y, SD%m, ErrStat2, ErrMsg2,&
            dYdx=y_FAST%Lin%Modules(Module_SD)%Instance(1)%C, dXdx=y_FAST%Lin%Modules(Module_SD)%Instance(1)%A )
        if(Failed()) return;
  
        ! get the operating point
        call SD_GetOP(t_global, SD%Input(1), SD%p, SD%x(STATE_CURR), SD%xd(STATE_CURR), SD%z(STATE_CURR),&
            SD%OtherSt(STATE_CURR), SD%y, SD%m, ErrStat2, ErrMsg2, u_op=y_FAST%Lin%Modules(Module_SD)%Instance(1)%op_u,&
            y_op=y_FAST%Lin%Modules(Module_SD)%Instance(1)%op_y, &
            x_op=y_FAST%Lin%Modules(Module_SD)%Instance(1)%op_x, dx_op=y_FAST%Lin%Modules(Module_SD)%Instance(1)%op_dx)
        if(Failed()) return;
  
        ! write the module matrices:
        if (p_FAST%LinOutMod) then
           OutFileName = trim(LinRootName)//'.'//TRIM(y_FAST%Module_Abrev(Module_SD))      
           call WrLinFile_txt_Head(t_global, p_FAST, y_FAST, y_FAST%Lin%Modules(Module_SD)%Instance(1), OutFileName, Un, ErrStat2, ErrMsg2)
           if(Failed()) return;
  
           if (p_FAST%LinOutJac) then
              ! Jacobians
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_SD)%Instance(1)%A, Un, p_FAST%OutFmt, 'dXdx')
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_SD)%Instance(1)%B, Un, p_FAST%OutFmt, 'dXdu', UseCol=y_FAST%Lin%Modules(Module_SD)%Instance(1)%use_u)
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_SD)%Instance(1)%C, Un, p_FAST%OutFmt, 'dYdx', UseRow=y_FAST%Lin%Modules(Module_SD)%Instance(1)%use_y)
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_SD)%Instance(1)%D, Un, p_FAST%OutFmt, 'dYdu', UseRow=y_FAST%Lin%Modules(Module_SD)%Instance(1)%use_y, &
                                                                                                                 UseCol=y_FAST%Lin%Modules(Module_SD)%Instance(1)%use_u)
           end if
           ! finish writing the file
           call WrLinFile_txt_End(Un, p_FAST, y_FAST%Lin%Modules(Module_SD)%Instance(1) )
        end if
  
     !.....................
     ! ExtPtfm
     !.....................
     elseif ( p_FAST%CompSub == Module_ExtPtfm ) then 
        ! get the jacobians
        call ExtPtfm_JacobianPInput( t_global, ExtPtfm%Input(1), ExtPtfm%p, ExtPtfm%x(STATE_CURR), ExtPtfm%xd(STATE_CURR), &
                ExtPtfm%z(STATE_CURR), ExtPtfm%OtherSt(STATE_CURR),  ExtPtfm%y, ExtPtfm%m, ErrStat2, ErrMsg2, &
                dYdu=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%D, dXdu=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%B )
        if(Failed()) return;
  
        call ExtPtfm_JacobianPContState( t_global, ExtPtfm%Input(1), ExtPtfm%p, ExtPtfm%x(STATE_CURR), ExtPtfm%xd(STATE_CURR), &
            ExtPtfm%z(STATE_CURR), ExtPtfm%OtherSt(STATE_CURR), ExtPtfm%y, ExtPtfm%m, ErrStat2, ErrMsg2,&
            dYdx=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%C, dXdx=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%A )
        if(Failed()) return;
  
        ! get the operating point
        call ExtPtfm_GetOP(t_global, ExtPtfm%Input(1), ExtPtfm%p, ExtPtfm%x(STATE_CURR), ExtPtfm%xd(STATE_CURR), ExtPtfm%z(STATE_CURR),&
            ExtPtfm%OtherSt(STATE_CURR), ExtPtfm%y, ExtPtfm%m, ErrStat2, ErrMsg2, u_op=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%op_u,&
            y_op=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%op_y, &
            x_op=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%op_x, dx_op=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%op_dx)
        if(Failed()) return;
  
        ! write the module matrices:
        if (p_FAST%LinOutMod) then
           OutFileName = trim(LinRootName)//'.'//TRIM(y_FAST%Module_Abrev(Module_ExtPtfm))      
           call WrLinFile_txt_Head(t_global, p_FAST, y_FAST, y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1), OutFileName, Un, ErrStat2, ErrMsg2)
           if(Failed()) return;
              
           if (p_FAST%LinOutJac) then
              ! Jacobians
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%A, Un, p_FAST%OutFmt, 'dXdx')
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%B, Un, p_FAST%OutFmt, 'dXdu', UseCol=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%use_u)
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%C, Un, p_FAST%OutFmt, 'dYdx', UseRow=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%use_y)
              call WrPartialMatrix(y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%D, Un, p_FAST%OutFmt, 'dYdu', UseRow=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%use_y, &
                                                                                                                 UseCol=y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1)%use_u)
           end if
           ! finish writing the file
           call WrLinFile_txt_End(Un, p_FAST, y_FAST%Lin%Modules(Module_ExtPtfm)%Instance(1) )
       end if
     end if ! ExtPtfm
     
     
     !.....................
     ! Linearization of glue code Input/Output solve:
  
negative.code: 
     ! local variables
     INTEGER(IntKi)                          :: k                   ! generic loop counters
     INTEGER(IntKi)                          :: i, iStart           ! generic loop counters
     INTEGER(IntKi)                          :: iBody               ! WAMIT body loop counter
     INTEGER(IntKi)                          :: j                   ! generic loop counters
     INTEGER(IntKi)                          :: indx                ! generic loop counters
  