!!Stack= 0

c
c     Copyright by Dwight Meglan 1990
c
c     Purpose: Reset ANZ to a state where a the full body OSU marker set is expected.
c              This routine and others similar to it can be used to implement different
c              marker and body segment configurations. See the following routine which
c              describes a simple upper body/right arm only marker set that was used for
c              a short term study at the Gait Lab. See the documentation for descriptions
c              of how the body connectivity is defined.
c
      subroutine InitFullBodyAnalysis( InitCycle,InitAnlType )
      implicit none
      include 'a_const.inc'

      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_names.inc'
      include 'a_mrk.inc'
      include 'a_seg.inc'                       
      include 'a_jnt.inc'
      include 'a_gls2.inc'
      include 'a_frc.inc'
                                                             
      integer*4 i,j
      logical*4 InitCycle,InitAnlType            
c
c     Initialize segment & joint names/connectivity
c
      call SetUpFullBodyParam
c
c     Set up marker info - eventually this data should be included in a
c     parameter file so that other marker layouts can be used without
c     reprogramming.
c
      num_init_empty_mrk= 6
      init_empty_mrk(1)= 4  ! rthp
      init_empty_mrk(2)= 5  ! lfhp
      init_empty_mrk(3)= 6  ! neck
      init_empty_mrk(4)= 13 ! sacrum
      init_empty_mrk(5)= 26 ! rtmidft
      init_empty_mrk(6)= 27 ! lfmidft
c
c     initialize marker names- note these will change if marker set is changed.
c         toe,ankle,heel,calf,knee,thigh,hip,asis,wrist,elbow,shldr,sacrum,neck
c
      MRK_NUM(rt).toe=9
      MRK_NUM(rt).ankle=8
      MRK_NUM(rt).heel=20
      MRK_NUM(rt).calf=24
      MRK_NUM(rt).knee=7
      MRK_NUM(rt).thigh=22
      MRK_NUM(rt).hip=4
      MRK_NUM(rt).asis=1
      MRK_NUM(rt).wrist=16
      MRK_NUM(rt).elbow=15
      MRK_NUM(rt).shldr=14
      MRK_NUM(rt).sacrum=2
      MRK_NUM(rt).neck=6
      
      MRK_NUM(lf).toe=12
      MRK_NUM(lf).ankle=11
      MRK_NUM(lf).heel=21
      MRK_NUM(lf).calf=25
      MRK_NUM(lf).knee=10
      MRK_NUM(lf).thigh=23
      MRK_NUM(lf).hip=5
      MRK_NUM(lf).asis=3
      MRK_NUM(lf).wrist=19
      MRK_NUM(lf).elbow=18
      MRK_NUM(lf).shldr=17
      MRK_NUM(lf).sacrum=2
      MRK_NUM(lf).neck=6
c                                          
c     Setup segment data - this should also be in a parameter file
c                   
      SP(rtft).num_mrk=3
      SP(rtcf).num_mrk=3
      SP(rtth).num_mrk=3
      SP(lfft).num_mrk=3
      SP(lfcf).num_mrk=3
      SP(lfth).num_mrk=3
      SP(pelv).num_mrk=3
      SP(trnk).num_mrk=4
      SP(head).num_mrk=1
      SP(rtua).num_mrk=2
      SP(rtla).num_mrk=2
      SP(lfua).num_mrk=2
      SP(lfla).num_mrk=2
c      SP(rthd).num_mrk=0
c      SP(lfhd).num_mrk=0  
c               
c     NOTE that at present the first pair of markers are assumed to define
c     the long axis of the segment and therefore the distance between them
c     is assumed to be the segment length.  This may change later if the
c     method used to find segment ends is changed from assuming that they
c     lie at the end markers to a method which uses the screw axis between
c     rigid bodies to find the segment "end" independent of marker placement.
c     At present the simple method is used because others have reported
c     problems using the screw axis approach and besides I'm already months
c     late getting this damn package done!
c
      SP(rtft).mrk_num(1)= MRK_NUM(rt).toe
      SP(rtft).mrk_num(2)= MRK_NUM(rt).heel
      SP(rtft).mrk_num(3)= MRK_NUM(rt).ankle
      
      SP(rtcf).mrk_num(1)= MRK_NUM(rt).ankle
      SP(rtcf).mrk_num(2)= MRK_NUM(rt).knee
      SP(rtcf).mrk_num(3)= MRK_NUM(rt).calf
      
      SP(rtth).mrk_num(1)= MRK_NUM(rt).knee
      SP(rtth).mrk_num(2)= MRK_NUM(rt).hip
      SP(rtth).mrk_num(3)= MRK_NUM(rt).thigh
      
      SP(lfft).mrk_num(1)= MRK_NUM(lf).toe
      SP(lfft).mrk_num(2)= MRK_NUM(lf).heel
      SP(lfft).mrk_num(3)= MRK_NUM(lf).ankle
      
      SP(lfcf).mrk_num(1)= MRK_NUM(lf).ankle
      SP(lfcf).mrk_num(2)= MRK_NUM(lf).knee
      SP(lfcf).mrk_num(3)= MRK_NUM(lf).calf
      
      SP(lfth).mrk_num(1)= MRK_NUM(lf).knee
      SP(lfth).mrk_num(2)= MRK_NUM(lf).hip
      SP(lfth).mrk_num(3)= MRK_NUM(lf).thigh
      
      SP(pelv).mrk_num(1)= MRK_NUM(rt).hip
      SP(pelv).mrk_num(2)= MRK_NUM(lf).hip
      SP(pelv).mrk_num(3)= MRK_NUM(rt).sacrum
      
      SP(trnk).mrk_num(1)= MRK_NUM(rt).asis
      SP(trnk).mrk_num(2)= MRK_NUM(lf).asis
      SP(trnk).mrk_num(3)= MRK_NUM(rt).shldr
      SP(trnk).mrk_num(4)= MRK_NUM(lf).shldr
      
      SP(rtua).mrk_num(1)= MRK_NUM(rt).shldr
      SP(rtua).mrk_num(2)= MRK_NUM(rt).elbow
      
      SP(rtla).mrk_num(1)= MRK_NUM(rt).elbow
      SP(rtla).mrk_num(2)= MRK_NUM(rt).wrist
      
      SP(lfua).mrk_num(1)= MRK_NUM(lf).shldr      
      SP(lfua).mrk_num(2)= MRK_NUM(lf).elbow
      
      SP(lfla).mrk_num(1)= MRK_NUM(lf).elbow
      SP(lfla).mrk_num(2)= MRK_NUM(lf).wrist
      
      SP(head).mrk_num(1)= MRK_NUM(rt).neck  
      SP(head).mrk_num(2)= MRK_NUM(rt).neck  
                                                            
      SP(rtft).num_MrkDist=3
      SP(rtcf).num_MrkDist=3
      SP(rtth).num_MrkDist=3
      SP(lfft).num_MrkDist=3
      SP(lfcf).num_MrkDist=3
      SP(lfth).num_MrkDist=3
      SP(pelv).num_MrkDist=3
      SP(trnk).num_MrkDist=6
      SP(rtua).num_MrkDist=1
      SP(rtla).num_MrkDist=1
      SP(lfua).num_MrkDist=1
      SP(lfla).num_MrkDist=1
      SP(head).num_MrkDist=0     
c      SP(rthd).num_MrkDist=0
c      SP(lfhd).num_MrkDist=0 

      SP(rtft).num_end= 1
      SP(rtcf).num_end= 2
      SP(rtth).num_end= 2
      SP(lfft).num_end= 1 
      SP(lfcf).num_end= 2
      SP(lfth).num_end= 2
      SP(pelv).num_end= 3
      SP(trnk).num_end= 4
      SP(rtua).num_end= 2
      SP(rtla).num_end= 2
      SP(lfua).num_end= 2
      SP(lfla).num_end= 2
      SP(head).num_end= 1
c      SP(rthd).num_end= 1
c      SP(lfhd).num_end= 1
c                             
c     Set up joint connectivity information
c
      call SetupFullBodyKinetics

c
c     Set up some general parameters
c
      if ( InitAnlType ) GP.analysis_type=  FULL_ANL
      GP.num_seg= MAX_SEG
      GP.num_jnt= MAX_JNT
      do i= 1, MAX_SEG
        GP.seg_num(i)= i
        GP.jnt_num(i)= i
      end do

      if ( InitCycle ) then
        MP.num_cycle= 0
        History(1).NumHistory= 1
        History(1).NumLine= 0
      end if

      return          
      end
c                
c
c
      subroutine SetupFullBodyKinetics
      implicit none
      include 'a_const.inc'

      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_names.inc'
      include 'a_mrk.inc'
      include 'a_seg.inc'                       
      include 'a_jnt.inc'
      include 'a_gls2.inc'
      include 'a_frc.inc'

      integer*4 i,j
c
c     Initialize data about joint connectivity of body.  This will later
c     be expanded to handle more than one marker set.  E.g., a set for the
c     entire body, a set for the upper body alone, and rigid body array
c     set for the lower body alone.  At present, the connectivities represent
c     all the possible combinations of known/unknown ground reactions and
c     rt/lf stance sides.  This big pyle of numbers is basically a way to
c     let me use the same joint reaction load calc routines for every joint in
c     the body no matter the calculation order.      
c
c     Ground reaction unknown - Right stance leg
c                                               
      JNT_TD(rt).num_jnt= 12
      
      JNT_TD(rt).jnt_order(1)=  neck
      JNT_TD(rt).jnt_order(2)=  rtel
      JNT_TD(rt).jnt_order(3)=  rtsh
      JNT_TD(rt).jnt_order(4)=  lfel
      JNT_TD(rt).jnt_order(5)=  lfsh
      JNT_TD(rt).jnt_order(6)=  pvtk
      JNT_TD(rt).jnt_order(7)=  lfak
      JNT_TD(rt).jnt_order(8)=  lfkn
      JNT_TD(rt).jnt_order(9)=  lfhp
      JNT_TD(rt).jnt_order(10)= rthp
      JNT_TD(rt).jnt_order(11)= rtkn
      JNT_TD(rt).jnt_order(12)= rtak
                             
      JNT_TD(rt).jnt_seg(1)=  head
      JNT_TD(rt).jnt_seg(2)=  rtla
      JNT_TD(rt).jnt_seg(3)=  rtua
      JNT_TD(rt).jnt_seg(4)=  lfla
      JNT_TD(rt).jnt_seg(5)=  lfua
      JNT_TD(rt).jnt_seg(6)=  trnk
      JNT_TD(rt).jnt_seg(7)=  lfft
      JNT_TD(rt).jnt_seg(8)=  lfcf
      JNT_TD(rt).jnt_seg(9)=  lfth
      JNT_TD(rt).jnt_seg(10)= pelv
      JNT_TD(rt).jnt_seg(11)= rtth
      JNT_TD(rt).jnt_seg(12)= rtcf
      
      JNT_TD(rt).calc_jnt_num(1)=  proximal
      JNT_TD(rt).calc_jnt_num(2)=  proximal
      JNT_TD(rt).calc_jnt_num(3)=  proximal
      JNT_TD(rt).calc_jnt_num(4)=  proximal
      JNT_TD(rt).calc_jnt_num(5)=  proximal
      JNT_TD(rt).calc_jnt_num(6)=  3
      JNT_TD(rt).calc_jnt_num(7)=  proximal
      JNT_TD(rt).calc_jnt_num(8)=  proximal
      JNT_TD(rt).calc_jnt_num(9)=  proximal
      JNT_TD(rt).calc_jnt_num(10)= rt
      JNT_TD(rt).calc_jnt_num(11)= distal
      JNT_TD(rt).calc_jnt_num(12)= distal
      
      JNT_TD(rt).num_conn_jnt(1)=  0
      JNT_TD(rt).num_conn_jnt(2)=  0
      JNT_TD(rt).num_conn_jnt(3)=  1   
      JNT_TD(rt).num_conn_jnt(4)=  0
      JNT_TD(rt).num_conn_jnt(5)=  1
      JNT_TD(rt).num_conn_jnt(6)=  3 
      JNT_TD(rt).num_conn_jnt(7)=  0
      JNT_TD(rt).num_conn_jnt(8)=  1   
      JNT_TD(rt).num_conn_jnt(9)=  1
      JNT_TD(rt).num_conn_jnt(10)= 2     
      JNT_TD(rt).num_conn_jnt(11)= 1
      JNT_TD(rt).num_conn_jnt(12)= 1 
                                     
      JNT_TD(rt).conn_jnt_num(1,1)=  0    ! neck
      JNT_TD(rt).conn_jnt_num(1,2)=  0    ! rtel
      JNT_TD(rt).conn_jnt_num(1,3)=  rtel ! rtsh
      JNT_TD(rt).conn_jnt_num(1,4)=  0    ! lfel
      JNT_TD(rt).conn_jnt_num(1,5)=  lfel ! lfsh
      JNT_TD(rt).conn_jnt_num(1,6)=  neck ! pvtk
      JNT_TD(rt).conn_jnt_num(2,6)=  rtsh
      JNT_TD(rt).conn_jnt_num(3,6)=  lfsh
      JNT_TD(rt).conn_jnt_num(1,7)=  0    ! lfak
      JNT_TD(rt).conn_jnt_num(1,8)=  lfak ! lfkn
      JNT_TD(rt).conn_jnt_num(1,9)=  lfkn ! lfhp
      JNT_TD(rt).conn_jnt_num(1,10)= lfhp ! rthp
      JNT_TD(rt).conn_jnt_num(2,10)= pvtk
      JNT_TD(rt).conn_jnt_num(1,11)= rthp ! rtkn
      JNT_TD(rt).conn_jnt_num(1,12)= rtkn ! rtak
                                     
      JNT_TD(rt).conn_jnt_seg(1,1)=  0      ! head
      JNT_TD(rt).conn_jnt_seg(1,2)=  0      ! rtla
      JNT_TD(rt).conn_jnt_seg(1,3)=  distal ! rtua
      JNT_TD(rt).conn_jnt_seg(1,4)=  0      ! lfla
      JNT_TD(rt).conn_jnt_seg(1,5)=  distal ! lfua
      JNT_TD(rt).conn_jnt_seg(1,6)=  4      ! trnk
      JNT_TD(rt).conn_jnt_seg(2,6)=  rt
      JNT_TD(rt).conn_jnt_seg(3,6)=  lf  
      JNT_TD(rt).conn_jnt_seg(1,7)=  0      ! lfft
      JNT_TD(rt).conn_jnt_seg(1,8)=  distal ! lfcf
      JNT_TD(rt).conn_jnt_seg(1,9)=  distal ! lfth
      JNT_TD(rt).conn_jnt_seg(1,10)= lf     ! pelv
      JNT_TD(rt).conn_jnt_seg(2,10)= 3
      JNT_TD(rt).conn_jnt_seg(1,11)= proximal ! rtth
      JNT_TD(rt).conn_jnt_seg(1,12)= proximal ! rtcf

      do i= 1, 12
        JNT_TD(rt).num_ext_load(i)= 0
      end do

      do i= 1, 9
        JNT_TD(rt).CalcOrder(i)= DisttoProx
      end do
      do i= 10, 12
        JNT_TD(rt).CalcOrder(i)= ProxtoDist
      end do
c                               
c     Ground reaction unknown - Left stance leg  
c
      JNT_TD(lf) = JNT_TD(rt)
      
      JNT_TD(lf).jnt_order(7)=  rtak
      JNT_TD(lf).jnt_order(8)=  rtkn
      JNT_TD(lf).jnt_order(9)=  rthp
      JNT_TD(lf).jnt_order(10)= lfhp
      JNT_TD(lf).jnt_order(11)= lfkn
      JNT_TD(lf).jnt_order(12)= lfak
                             
      JNT_TD(lf).jnt_seg(6)=  trnk
      JNT_TD(lf).jnt_seg(7)=  rtft
      JNT_TD(lf).jnt_seg(8)=  rtcf
      JNT_TD(lf).jnt_seg(9)=  rtth
      JNT_TD(lf).jnt_seg(10)= pelv
      JNT_TD(lf).jnt_seg(11)= lfth
      JNT_TD(lf).jnt_seg(12)= lfcf
      
      JNT_TD(lf).calc_jnt_num(10)= lf
      
      JNT_TD(lf).conn_jnt_num(1,7)=  0    ! rtak
      JNT_TD(lf).conn_jnt_num(1,8)=  rtak ! rtkn
      JNT_TD(lf).conn_jnt_num(1,9)=  rtkn ! rthp
      JNT_TD(lf).conn_jnt_num(1,10)= rthp ! lfhp
      JNT_TD(lf).conn_jnt_num(2,10)= pvtk
      JNT_TD(lf).conn_jnt_num(1,11)= lfhp ! lfkn
      JNT_TD(lf).conn_jnt_num(1,12)= lfkn ! lfak
                                       
      JNT_TD(lf).conn_jnt_seg(1,7)=  0      ! rtft
      JNT_TD(lf).conn_jnt_seg(1,8)=  distal ! rtcf
      JNT_TD(lf).conn_jnt_seg(1,9)=  distal ! rtth
      JNT_TD(lf).conn_jnt_seg(1,10)= rt     ! pelv
      JNT_TD(lf).conn_jnt_seg(2,10)= 3
      JNT_TD(lf).conn_jnt_seg(1,11)= proximal ! lfth
      JNT_TD(lf).conn_jnt_seg(1,12)= proximal ! lfcf
c                                                          
c     Ground Reaction known - Right stance leg
c
      JNT_BU(rt).num_jnt= 12
      
      JNT_BU(rt).jnt_order(1)=  neck
      JNT_BU(rt).jnt_order(2)=  rtel
      JNT_BU(rt).jnt_order(3)=  rtsh
      JNT_BU(rt).jnt_order(4)=  lfel
      JNT_BU(rt).jnt_order(5)=  lfsh
      JNT_BU(rt).jnt_order(6)=  pvtk
      JNT_BU(rt).jnt_order(7)=  lfak
      JNT_BU(rt).jnt_order(8)=  lfkn
      JNT_BU(rt).jnt_order(9)=  lfhp
      JNT_BU(rt).jnt_order(10)= rtak
      JNT_BU(rt).jnt_order(11)= rtkn
      JNT_BU(rt).jnt_order(12)= rthp
                             
      JNT_BU(rt).jnt_seg(1)=  head
      JNT_BU(rt).jnt_seg(2)=  rtla
      JNT_BU(rt).jnt_seg(3)=  rtua
      JNT_BU(rt).jnt_seg(4)=  lfla
      JNT_BU(rt).jnt_seg(5)=  lfua
      JNT_BU(rt).jnt_seg(6)=  trnk
      JNT_BU(rt).jnt_seg(7)=  lfft
      JNT_BU(rt).jnt_seg(8)=  lfcf
      JNT_BU(rt).jnt_seg(9)=  lfth
      JNT_BU(rt).jnt_seg(10)= rtft
      JNT_BU(rt).jnt_seg(11)= rtcf
      JNT_BU(rt).jnt_seg(12)= rtth
      
      JNT_BU(rt).calc_jnt_num(1)=  distal
      JNT_BU(rt).calc_jnt_num(2)=  proximal
      JNT_BU(rt).calc_jnt_num(3)=  proximal
      JNT_BU(rt).calc_jnt_num(4)=  proximal
      JNT_BU(rt).calc_jnt_num(5)=  proximal
      JNT_BU(rt).calc_jnt_num(6)=  3
      JNT_BU(rt).calc_jnt_num(7)=  proximal
      JNT_BU(rt).calc_jnt_num(8)=  proximal
      JNT_BU(rt).calc_jnt_num(9)=  proximal
      JNT_BU(rt).calc_jnt_num(10)= proximal
      JNT_BU(rt).calc_jnt_num(11)= proximal
      JNT_BU(rt).calc_jnt_num(12)= proximal
      
      JNT_BU(rt).num_conn_jnt(1)=  0
      JNT_BU(rt).num_conn_jnt(2)=  0
      JNT_BU(rt).num_conn_jnt(3)=  1   
      JNT_BU(rt).num_conn_jnt(4)=  0
      JNT_BU(rt).num_conn_jnt(5)=  1
      JNT_BU(rt).num_conn_jnt(6)=  3 
      JNT_BU(rt).num_conn_jnt(7)=  0
      JNT_BU(rt).num_conn_jnt(8)=  1   
      JNT_BU(rt).num_conn_jnt(9)=  1
      JNT_BU(rt).num_conn_jnt(10)= 0     
      JNT_BU(rt).num_conn_jnt(11)= 1
      JNT_BU(rt).num_conn_jnt(12)= 1 
                                     
      JNT_BU(rt).conn_jnt_num(1,1)=  0    ! neck
      JNT_BU(rt).conn_jnt_num(1,2)=  0    ! rtel
      JNT_BU(rt).conn_jnt_num(1,3)=  rtel ! rtsh
      JNT_BU(rt).conn_jnt_num(1,4)=  0    ! lfel
      JNT_BU(rt).conn_jnt_num(1,5)=  lfel ! lfsh
      JNT_BU(rt).conn_jnt_num(1,6)=  neck ! pvtk
      JNT_BU(rt).conn_jnt_num(2,6)=  rtsh
      JNT_BU(rt).conn_jnt_num(3,6)=  lfsh
      JNT_BU(rt).conn_jnt_num(1,7)=  0    ! lfak
      JNT_BU(rt).conn_jnt_num(1,8)=  lfak ! lfkn
      JNT_BU(rt).conn_jnt_num(1,9)=  lfkn ! lfhp
      JNT_BU(rt).conn_jnt_num(1,10)= 0    ! rtak
      JNT_BU(rt).conn_jnt_num(1,11)= rtak ! rtkn
      JNT_BU(rt).conn_jnt_num(1,12)= rtkn ! rthp
                                     
      JNT_BU(rt).conn_jnt_seg(1,1)=  0      ! head
      JNT_BU(rt).conn_jnt_seg(1,2)=  0      ! rtla
      JNT_BU(rt).conn_jnt_seg(1,3)=  distal ! rtua
      JNT_BU(rt).conn_jnt_seg(1,4)=  0      ! lfla
      JNT_BU(rt).conn_jnt_seg(1,5)=  distal ! lfua
      JNT_BU(rt).conn_jnt_seg(1,6)=  4      ! trnk
      JNT_BU(rt).conn_jnt_seg(2,6)=  rt
      JNT_BU(rt).conn_jnt_seg(3,6)=  lf  
      JNT_BU(rt).conn_jnt_seg(1,7)=  0      ! lfft
      JNT_BU(rt).conn_jnt_seg(1,8)=  distal ! lfcf
      JNT_BU(rt).conn_jnt_seg(1,9)=  distal ! lfth
      JNT_BU(rt).conn_jnt_seg(1,10)= 0      ! rtft
      JNT_BU(rt).conn_jnt_seg(1,11)= distal ! rtcf
      JNT_BU(rt).conn_jnt_seg(1,12)= distal ! rtth

      do i= 1, 12
        JNT_BU(rt).num_ext_load(i)= 0
      end do
      JNT_BU(rt).num_ext_load(10)= 1  ! rtft

      do i= 1, 12
        do j= 1, 3
          JNT_BU(rt).ext_load_num(j,i)= 0
        end do
      end do                        
      JNT_BU(rt).ext_load_num(1,10)= 1    ! rtft
                
      do i= 1, 12
        JNT_BU(rt).CalcOrder(i)= DisttoProx
      end do
c
c     Ground reaction known - Left stance leg
c
      JNT_BU(lf)= JNT_BU(rt)
                             
      do i= 1, 12
        JNT_BU(lf).num_ext_load(i)= 0
      end do
      JNT_BU(lf).num_ext_load(7)= 1  ! lfft

      do i= 1, 12
        do j= 1, 3
          JNT_BU(lf).ext_load_num(j,i)= 0
        end do   
      end do
      JNT_BU(lf).ext_load_num(1,7)= 2    ! lfft
c
c     Double stance - Both feet ground reactions known
c
      JNT_DBL(3).num_jnt= 12
      
      JNT_DBL(3).jnt_order(1)=  neck
      JNT_DBL(3).jnt_order(2)=  rtel
      JNT_DBL(3).jnt_order(3)=  rtsh
      JNT_DBL(3).jnt_order(4)=  lfel
      JNT_DBL(3).jnt_order(5)=  lfsh
      JNT_DBL(3).jnt_order(6)=  pvtk
      JNT_DBL(3).jnt_order(7)=  lfak
      JNT_DBL(3).jnt_order(8)=  lfkn
      JNT_DBL(3).jnt_order(9)=  lfhp
      JNT_DBL(3).jnt_order(10)= rtak
      JNT_DBL(3).jnt_order(11)= rtkn
      JNT_DBL(3).jnt_order(12)= rthp
                             
      JNT_DBL(3).jnt_seg(1)=  head
      JNT_DBL(3).jnt_seg(2)=  rtla
      JNT_DBL(3).jnt_seg(3)=  rtua
      JNT_DBL(3).jnt_seg(4)=  lfla
      JNT_DBL(3).jnt_seg(5)=  lfua
      JNT_DBL(3).jnt_seg(6)=  trnk
      JNT_DBL(3).jnt_seg(7)=  lfft
      JNT_DBL(3).jnt_seg(8)=  lfcf
      JNT_DBL(3).jnt_seg(9)=  lfth
      JNT_DBL(3).jnt_seg(10)= rtft
      JNT_DBL(3).jnt_seg(11)= rtcf
      JNT_DBL(3).jnt_seg(12)= rtth
      
      JNT_DBL(3).calc_jnt_num(1)=  distal
      JNT_DBL(3).calc_jnt_num(2)=  proximal
      JNT_DBL(3).calc_jnt_num(3)=  proximal
      JNT_DBL(3).calc_jnt_num(4)=  proximal
      JNT_DBL(3).calc_jnt_num(5)=  proximal
      JNT_DBL(3).calc_jnt_num(6)=  3
      JNT_DBL(3).calc_jnt_num(7)=  proximal
      JNT_DBL(3).calc_jnt_num(8)=  proximal
      JNT_DBL(3).calc_jnt_num(9)=  proximal
      JNT_DBL(3).calc_jnt_num(10)= proximal
      JNT_DBL(3).calc_jnt_num(11)= proximal
      JNT_DBL(3).calc_jnt_num(12)= proximal
      
      JNT_DBL(3).num_conn_jnt(1)=  0
      JNT_DBL(3).num_conn_jnt(2)=  0
      JNT_DBL(3).num_conn_jnt(3)=  1   
      JNT_DBL(3).num_conn_jnt(4)=  0
      JNT_DBL(3).num_conn_jnt(5)=  1
      JNT_DBL(3).num_conn_jnt(6)=  3 
      JNT_DBL(3).num_conn_jnt(7)=  0
      JNT_DBL(3).num_conn_jnt(8)=  1   
      JNT_DBL(3).num_conn_jnt(9)=  1
      JNT_DBL(3).num_conn_jnt(10)= 0     
      JNT_DBL(3).num_conn_jnt(11)= 1
      JNT_DBL(3).num_conn_jnt(12)= 1 
                                     
      JNT_DBL(3).conn_jnt_num(1,1)=  0    ! neck
      JNT_DBL(3).conn_jnt_num(1,2)=  0    ! rtel
      JNT_DBL(3).conn_jnt_num(1,3)=  rtel ! rtsh
      JNT_DBL(3).conn_jnt_num(1,4)=  0    ! lfel
      JNT_DBL(3).conn_jnt_num(1,5)=  lfel ! lfsh
      JNT_DBL(3).conn_jnt_num(1,6)=  neck ! pvtk
      JNT_DBL(3).conn_jnt_num(2,6)=  rtsh
      JNT_DBL(3).conn_jnt_num(3,6)=  lfsh
      JNT_DBL(3).conn_jnt_num(1,7)=  0    ! lfak
      JNT_DBL(3).conn_jnt_num(1,8)=  lfak ! lfkn
      JNT_DBL(3).conn_jnt_num(1,9)=  lfkn ! lfhp
      JNT_DBL(3).conn_jnt_num(1,10)= 0    ! rtak
      JNT_DBL(3).conn_jnt_num(1,11)= rtak ! rtkn
      JNT_DBL(3).conn_jnt_num(1,12)= rtkn ! rthp
                                     
      JNT_DBL(3).conn_jnt_seg(1,1)=  0      ! head
      JNT_DBL(3).conn_jnt_seg(1,2)=  0      ! rtla
      JNT_DBL(3).conn_jnt_seg(1,3)=  distal ! rtua
      JNT_DBL(3).conn_jnt_seg(1,4)=  0      ! lfla
      JNT_DBL(3).conn_jnt_seg(1,5)=  distal ! lfua
      JNT_DBL(3).conn_jnt_seg(1,6)=  4      ! trnk
      JNT_DBL(3).conn_jnt_seg(2,6)=  rt
      JNT_DBL(3).conn_jnt_seg(3,6)=  lf  
      JNT_DBL(3).conn_jnt_seg(1,7)=  0      ! lfft
      JNT_DBL(3).conn_jnt_seg(1,8)=  distal ! lfcf
      JNT_DBL(3).conn_jnt_seg(1,9)=  distal ! lfth
      JNT_DBL(3).conn_jnt_seg(1,10)= 0      ! rtft
      JNT_DBL(3).conn_jnt_seg(1,11)= distal ! rtcf
      JNT_DBL(3).conn_jnt_seg(1,12)= distal ! rtth

      do i= 1, 12
        JNT_DBL(3).num_ext_load(i)= 0
      end do
      JNT_DBL(3).num_ext_load(7)=  1  ! lfft
      JNT_DBL(3).num_ext_load(10)= 1  ! rtft

      do i= 1, 12
        do j= 1, 3
          JNT_DBL(3).ext_load_num(j,i)= 0
        end do
      end do
      JNT_DBL(3).ext_load_num(1,7)=  2    ! lfft
      JNT_DBL(3).ext_load_num(1,10)= 1    ! rtft
                
      do i= 1, 12
        JNT_DBL(3).CalcOrder(i)= DisttoProx
      end do
c
c     Double stance - Only Right foot ground reaction known
c
      JNT_DBL(rt)= JNT_DBL(3)
      
      JNT_DBL(rt).jnt_order(7)=  rtak
      JNT_DBL(rt).jnt_order(8)=  rtkn
      JNT_DBL(rt).jnt_order(9)=  rthp
      JNT_DBL(rt).jnt_order(10)= lfhp
      JNT_DBL(rt).jnt_order(11)= lfkn
      JNT_DBL(rt).jnt_order(12)= lfak
                                   
      JNT_DBL(rt).jnt_seg(7)=  rtft
      JNT_DBL(rt).jnt_seg(8)=  rtcf
      JNT_DBL(rt).jnt_seg(9)=  rtth
      JNT_DBL(rt).jnt_seg(10)= pelv
      JNT_DBL(rt).jnt_seg(11)= lfth
      JNT_DBL(rt).jnt_seg(12)= lfcf
      
      JNT_DBL(rt).calc_jnt_num(10)= lf
      JNT_DBL(rt).calc_jnt_num(11)= distal
      JNT_DBL(rt).calc_jnt_num(12)= distal
      
      JNT_DBL(rt).num_conn_jnt(10)= 2
                                   
      JNT_DBL(rt).conn_jnt_num(1,8)=  rtak ! rtkn
      JNT_DBL(rt).conn_jnt_num(1,9)=  rtkn ! rthp
      JNT_DBL(rt).conn_jnt_num(1,10)= rthp ! lfhp
      JNT_DBL(rt).conn_jnt_num(2,10)= pvtk 
      JNT_DBL(rt).conn_jnt_num(1,11)= lfhp ! lfkn
      JNT_DBL(rt).conn_jnt_num(1,12)= lfkn ! lfak
      
      JNT_DBL(rt).conn_jnt_seg(1,10)= rt       ! pelv
      JNT_DBL(rt).conn_jnt_seg(2,10)= 3    
      JNT_DBL(rt).conn_jnt_seg(1,11)= proximal ! lfth
      JNT_DBL(rt).conn_jnt_seg(1,12)= proximal ! lfcf
      
      do i= 1, 12
        JNT_DBL(rt).num_ext_load(i)= 0
      end do
      JNT_DBL(rt).num_ext_load(7)=  1  ! rtft
                  
      do i= 1, 12
        do j= 1, 3
          JNT_DBL(rt).ext_load_num(j,i)= 0
        end do
      end do     
      JNT_DBL(rt).ext_load_num(1,7)=  1    ! rtft
                
      do i= 1, 9
        JNT_DBL(rt).CalcOrder(i)= DisttoProx
      end do
      do i= 10, 12
        JNT_DBL(rt).CalcOrder(i)= ProxtoDist
      end do
c
c     Double stance - Only Left foot ground reaction known
c                               
      JNT_DBL(lf)= JNT_DBL(3)
      
      JNT_DBL(lf).jnt_order(7)=  lfak
      JNT_DBL(lf).jnt_order(8)=  lfkn
      JNT_DBL(lf).jnt_order(9)=  lfhp
      JNT_DBL(lf).jnt_order(10)= rthp
      JNT_DBL(lf).jnt_order(11)= rtkn
      JNT_DBL(lf).jnt_order(12)= rtak
                                   
      JNT_DBL(lf).jnt_seg(7)=  lfft
      JNT_DBL(lf).jnt_seg(8)=  lfcf
      JNT_DBL(lf).jnt_seg(9)=  lfth
      JNT_DBL(lf).jnt_seg(10)= pelv
      JNT_DBL(lf).jnt_seg(11)= rtth
      JNT_DBL(lf).jnt_seg(12)= rtcf
      
      JNT_DBL(lf).calc_jnt_num(10)= rt
      JNT_DBL(lf).calc_jnt_num(11)= distal
      JNT_DBL(lf).calc_jnt_num(12)= distal
      
      JNT_DBL(lf).num_conn_jnt(10)= 2
                                   
      JNT_DBL(lf).conn_jnt_num(1,8)=  lfak ! lfkn
      JNT_DBL(lf).conn_jnt_num(1,9)=  lfkn ! lfhp
      JNT_DBL(lf).conn_jnt_num(1,10)= lfhp ! rthp
      JNT_DBL(lf).conn_jnt_num(2,10)= pvtk 
      JNT_DBL(lf).conn_jnt_num(1,11)= rthp ! rtkn
      JNT_DBL(lf).conn_jnt_num(1,12)= rtkn ! rtak
      
      JNT_DBL(lf).conn_jnt_seg(1,10)= lf       ! pelv
      JNT_DBL(lf).conn_jnt_seg(2,10)= 3    
      JNT_DBL(lf).conn_jnt_seg(1,11)= proximal ! lfth
      JNT_DBL(lf).conn_jnt_seg(1,12)= proximal ! lfcf
      
      do i= 1, 12
        JNT_DBL(lf).num_ext_load(i)= 0
      end do
      JNT_DBL(lf).num_ext_load(7)=  1  ! lfft
                  
      do i= 1, 12
        do j= 1, 3
          JNT_DBL(lf).ext_load_num(j,i)= 0
        end do
      end do    
      JNT_DBL(lf).ext_load_num(1,7)=  2    ! lfft
                
      do i= 1, 9
        JNT_DBL(lf).CalcOrder(i)= DisttoProx
      end do
      do i= 10, 12
        JNT_DBL(lf).CalcOrder(i)= ProxtoDist
      end do
c
c     Double stance - No ground reactions known
c
      JNT_DBL(4).num_jnt= 6

      JNT_DBL(4).jnt_order(1)= neck
      JNT_DBL(4).jnt_order(2)= rtel
      JNT_DBL(4).jnt_order(3)= rtsh
      JNT_DBL(4).jnt_order(4)= lfel
      JNT_DBL(4).jnt_order(5)= lfsh
      JNT_DBL(4).jnt_order(6)= pvtk
      
      JNT_DBL(4).jnt_seg(1)= head
      JNT_DBL(4).jnt_seg(2)= rtla
      JNT_DBL(4).jnt_seg(3)= rtua
      JNT_DBL(4).jnt_seg(4)= lfla
      JNT_DBL(4).jnt_seg(5)= lfua
      JNT_DBL(4).jnt_seg(6)= trnk
      
      JNT_DBL(4).calc_jnt_num(1)= distal
      JNT_DBL(4).calc_jnt_num(2)= proximal
      JNT_DBL(4).calc_jnt_num(3)= proximal
      JNT_DBL(4).calc_jnt_num(4)= proximal
      JNT_DBL(4).calc_jnt_num(5)= proximal
      JNT_DBL(4).calc_jnt_num(6)= 3
      
      JNT_DBL(4).num_conn_jnt(1)= 0
      JNT_DBL(4).num_conn_jnt(2)= 0
      JNT_DBL(4).num_conn_jnt(3)= 1
      JNT_DBL(4).num_conn_jnt(4)= 0
      JNT_DBL(4).num_conn_jnt(5)= 1
      JNT_DBL(4).num_conn_jnt(6)= 3
      
      JNT_DBL(4).conn_jnt_num(1,1)= 0    ! neck
      JNT_DBL(4).conn_jnt_num(1,2)= 0    ! rtel
      JNT_DBL(4).conn_jnt_num(1,3)= rtel ! rtsh
      JNT_DBL(4).conn_jnt_num(1,4)= 0    ! lfel
      JNT_DBL(4).conn_jnt_num(1,5)= lfel ! lfsh
      JNT_DBL(4).conn_jnt_num(1,6)= neck ! pvtk
      JNT_DBL(4).conn_jnt_num(2,6)= rtsh 
      JNT_DBL(4).conn_jnt_num(3,6)= lfsh
      
      JNT_DBL(4).conn_jnt_seg(1,1)= 0      ! head
      JNT_DBL(4).conn_jnt_seg(1,2)= 0      ! rtla
      JNT_DBL(4).conn_jnt_seg(1,3)= distal ! rtua
      JNT_DBL(4).conn_jnt_seg(1,4)= 0      ! lfla
      JNT_DBL(4).conn_jnt_seg(1,5)= distal ! lfua
      JNT_DBL(4).conn_jnt_seg(1,6)= 4      ! trnk
      JNT_DBL(4).conn_jnt_seg(2,6)= rt 
      JNT_DBL(4).conn_jnt_seg(3,6)= lf
                  
      do i= 1, 12
        JNT_DBL(4).num_ext_load(i)= 0
      end do
                
      do i= 1, 6
        JNT_DBL(4).CalcOrder(i)= DisttoProx
      end do
c
c     Special case of double support with only right GRL known, but limit 
c     calculation to right leg only
c
      JNT_DBL(5).num_jnt= 3
      
      JNT_DBL(5).jnt_order(1)= rtak
      JNT_DBL(5).jnt_order(2)= rtkn
      JNT_DBL(5).jnt_order(3)= rthp

      JNT_DBL(5).jnt_seg(1)= rtft
      JNT_DBL(5).jnt_seg(2)= rtcf
      JNT_DBL(5).jnt_seg(3)= rtth
                               
      JNT_DBL(5).calc_jnt_num(1)= proximal
      JNT_DBL(5).calc_jnt_num(2)= proximal
      JNT_DBL(5).calc_jnt_num(3)= proximal

      JNT_DBL(5).num_conn_jnt(1)= 0
      JNT_DBL(5).num_conn_jnt(2)= 1
      JNT_DBL(5).num_conn_jnt(3)= 1

      JNT_DBL(5).conn_jnt_num(1,1)= 0
      JNT_DBL(5).conn_jnt_num(1,2)= rtak
      JNT_DBL(5).conn_jnt_num(1,3)= rtkn

      JNT_DBL(5).conn_jnt_seg(1,1)= 0
      JNT_DBL(5).conn_jnt_seg(1,2)= distal
      JNT_DBL(5).conn_jnt_seg(1,3)= distal

      JNT_DBL(5).num_ext_load(1)= 1
      JNT_DBL(5).num_ext_load(2)= 0
      JNT_DBL(5).num_ext_load(3)= 0

      JNT_DBL(5).ext_load_num(1,1)=  1    ! rtft
                
      do i= 1, 3
        JNT_DBL(5).CalcOrder(i)= DisttoProx
      end do
c
c     Special case of double support with only left GRL known, but limit 
c     calculation to left leg only
c
      JNT_DBL(6).num_jnt= 3
      
      JNT_DBL(6).jnt_order(1)= lfak
      JNT_DBL(6).jnt_order(2)= lfkn
      JNT_DBL(6).jnt_order(3)= lfhp

      JNT_DBL(6).jnt_seg(1)= lfft
      JNT_DBL(6).jnt_seg(2)= lfcf
      JNT_DBL(6).jnt_seg(3)= lfth
                               
      JNT_DBL(6).calc_jnt_num(1)= proximal
      JNT_DBL(6).calc_jnt_num(2)= proximal
      JNT_DBL(6).calc_jnt_num(3)= proximal

      JNT_DBL(6).num_conn_jnt(1)= 0
      JNT_DBL(6).num_conn_jnt(2)= 1
      JNT_DBL(6).num_conn_jnt(3)= 1

      JNT_DBL(6).conn_jnt_num(1,1)= 0
      JNT_DBL(6).conn_jnt_num(1,2)= lfak
      JNT_DBL(6).conn_jnt_num(1,3)= lfkn

      JNT_DBL(6).conn_jnt_seg(1,1)= 0
      JNT_DBL(6).conn_jnt_seg(1,2)= distal
      JNT_DBL(6).conn_jnt_seg(1,3)= distal
 
      JNT_DBL(6).num_ext_load(1)= 1
      JNT_DBL(6).num_ext_load(2)= 0
      JNT_DBL(6).num_ext_load(3)= 0
                
      JNT_DBL(6).ext_load_num(1,1)=  2    ! lfft

      do i= 1, 3
        JNT_DBL(6).CalcOrder(i)= DisttoProx
      end do
      return
      end
c
c
c     Copyright by Dwight Meglan 1990
c
c     Purpose: Set up a very simple marker set to do foot motion and time distance
c              calculations. This uses only the standard 3 foot markers of the OSU marker
c              set on each foot. 
c
      subroutine InitTimeDistAnalysis( InitCycle )
      implicit none
      include 'a_const.inc'

      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_names.inc'
      include 'a_mrk.inc'
      include 'a_seg.inc'                                  
      include 'a_jnt.inc'
      include 'a_gls2.inc'
      include 'a_frc.inc'
      include 'a_upper.inc'

      integer*4 i,j
      logical*4 InitCycle

      GP.analysis_type= TDP_ANL
      GP.num_seg= 2
      GP.seg_num(1)= rtft
      GP.seg_num(2)= lfft
      GP.num_jnt= 0

      num_init_empty_mrk= 0      
      init_empty_mrk(1)= -1
                           
      MRK_NUM(rt).toe=   1
      MRK_NUM(rt).ankle= 2
      MRK_NUM(rt).heel=  3
      MRK_NUM(lf).toe=   4
      MRK_NUM(lf).ankle= 5
      MRK_NUM(lf).heel=  6
                              
      MP.num_mrk= 6

      MP.mrk_name(1)= 'RTTO'
      MP.mrk_name(2)= 'RTAK'
      MP.mrk_name(3)= 'RTHE'
      MP.mrk_name(4)= 'LFTO'
      MP.mrk_name(5)= 'LFAK'
      MP.mrk_name(6)= 'LFHE'

      do i= 1, MAX_SEG
        SP(i).num_mrk= 0
        SP(i).num_MrkDist= 0
        do j= 1, 4
          SP(i).mrk_num(j)= 0
        end do
      end do

      SP(rtft).num_mrk=3
      SP(lfft).num_mrk=3

      SP(rtft).mrk_num(1)= 1
      SP(rtft).mrk_num(2)= 2
      SP(rtft).mrk_num(3)= 3

      SP(lfft).mrk_num(1)= 4
      SP(lfft).mrk_num(2)= 5
      SP(lfft).mrk_num(3)= 6

      SP(rtft).num_MrkDist=3
      SP(lfft).num_MrkDist=3     

      SP(rtft).num_end= 0
      SP(lfft).num_end= 0

      if ( InitCycle ) MP.num_cycle= 0
      call SetUpFullBodyParam
      return
      end
c
c
c
      subroutine SetUpFullBodyParam
      implicit none

      include 'a_const.inc'
      include 'a_names.inc'
      include 'a_jnt.inc'

      integer*4 i,j

      seg_names(1)=  'RTFT'
      seg_names(2)=  'RTCF'
      seg_names(3)=  'RTTH'
      seg_names(4)=  'LFFT'
      seg_names(5)=  'LFCF'
      seg_names(6)=  'LFTH'
      seg_names(7)=  'PELV'
      seg_names(8)=  'TRNK'
      seg_names(9)=  'RTUA'
      seg_names(10)= 'RTLA'
      seg_names(11)= 'LFUA'
      seg_names(12)= 'LFLA'
      seg_names(13)= 'HEAD'
      seg_names(14)= 'RTHD'
      seg_names(15)= 'LFHD'

      jnt_names(1)=  'RTAK'
      jnt_names(2)=  'RTKN'
      jnt_names(3)=  'RTHP'
      jnt_names(4)=  'LFAK'
      jnt_names(5)=  'LFKN'
      jnt_names(6)=  'LFHP'
      jnt_names(7)=  'PVLB'
      jnt_names(8)=  'PVTK'
      jnt_names(9)=  'RTEL'
      jnt_names(10)= 'RTSH'
      jnt_names(11)= 'LFEL'
      jnt_names(12)= 'LFSH'
      jnt_names(13)= 'NECK'
      jnt_names(14)= 'RTWR'
      jnt_names(15)= 'LFWR'

      JntSegNum(distal,rtak)=   rtft
      JntSegNum(proximal,rtak)= rtcf
      JntSegNum(distal,rtkn)=   rtcf
      JntSegNum(proximal,rtkn)= rtth
      JntSegNum(distal,rthp)=   rtth
      JntSegNum(proximal,rthp)= pelv
      JntSegNum(distal,lfak)=   lfft
      JntSegNum(proximal,lfak)= lfcf
      JntSegNum(distal,lfkn)=   lfcf
      JntSegNum(proximal,lfkn)= lfth
      JntSegNum(distal,lfhp)=   lfth
      JntSegNum(proximal,lfhp)= pelv
      JntSegNum(distal,pvlb)=   pelv
      JntSegNum(proximal,pvlb)= 0     ! Lab Global Coordinate System
      JntSegNum(distal,pvtk)=   trnk
      JntSegNum(proximal,pvtk)= pelv
      JntSegNum(distal,rtel)=   rtla
      JntSegNum(proximal,rtel)= rtua
      JntSegNum(distal,rtsh)=   rtua
      JntSegNum(proximal,rtsh)= trnk
      JntSegNum(distal,lfel)=   lfla
      JntSegNum(proximal,lfel)= lfua
      JntSegNum(distal,lfsh)=   lfua
      JntSegNum(proximal,lfsh)= trnk
      JntSegNum(distal,neck)=   head
      JntSegNum(proximal,neck)= head
      JntSegNum(distal,rtwr)=   rthd
      JntSegNum(proximal,rtwr)= rtla
      JntSegNum(distal,lfwr)=   lfhd
      JntSegNum(proximal,lfwr)= lfla

      do i= 1, MAX_SEG
	do j= 1, 4
	  SegJntNum(j,i)= 0
	end do
      end do	

      SegJntNum(distal,rtft)=   0
      SegJntNum(proximal,rtft)= rtak
      SegJntNum(distal,rtcf)=   rtak
      SegJntNum(proximal,rtcf)= rtkn
      SegJntNum(distal,rtth)=   rtkn
      SegJntNum(proximal,rtth)= rthp
      SegJntNum(distal,lfft)=   0
      SegJntNum(proximal,lfft)= lfak
      SegJntNum(distal,lfcf)=   lfak
      SegJntNum(proximal,lfcf)= lfkn
      SegJntNum(distal,lfth)=   lfkn
      SegJntNum(proximal,lfth)= lfhp
      SegJntNum(rt,pelv)=       rthp
      SegJntNum(lf,pelv)=       lfhp
      SegJntNum(3,pelv)=        pvtk
      SegJntNum(rt,trnk)=       rtsh
      SegJntNum(lf,trnk)=       lfsh
      SegJntNum(3,trnk)=        pvtk
      SegJntNum(4,trnk)=        neck
      SegJntNum(distal,rtua)=   rtel
      SegJntNum(proximal,rtua)= rtsh
      SegJntNum(distal,rtla)=   rtwr
      SegJntNum(proximal,rtla)= rtel
      SegJntNum(distal,lfua)=   lfel
      SegJntNum(proximal,lfua)= lfsh
      SegJntNum(distal,lfla)=   lfwr
      SegJntNum(proximal,lfla)= lfel
c 
c     Number of the joint (end) in the segment's parameters (SP) which 
c     describe the joint's position in the segment LCS's distal and proximal 
c     of the joint
c
      LocalSegEndJntNum(distal,rtak)=   proximal  ! rtft
      LocalSegEndJntNum(proximal,rtak)= distal    ! rtcf
      LocalSegEndJntNum(distal,rtkn)=   proximal  ! rtcf
      LocalSegEndJntNum(proximal,rtkn)= distal    ! rtth
      LocalSegEndJntNum(distal,rthp)=   proximal  ! rtth
      LocalSegEndJntNum(proximal,rthp)= rt        ! pelv
      LocalSegEndJntNum(distal,lfak)=   proximal  ! lfft
      LocalSegEndJntNum(proximal,lfak)= distal    ! lfcf
      LocalSegEndJntNum(distal,lfkn)=   proximal  ! lfcf
      LocalSegEndJntNum(proximal,lfkn)= distal    ! lfth
      LocalSegEndJntNum(distal,lfhp)=   proximal  ! lfth
      LocalSegEndJntNum(proximal,lfhp)= lf        ! pelv
      LocalSegEndJntNum(distal,pvlb)=   0         ! nothing
      LocalSegEndJntNum(proximal,pvlb)= 0         ! nothing
      LocalSegEndJntNum(distal,pvtk)=   3         ! trunk
      LocalSegEndJntNum(proximal,pvtk)= 3         ! pelv
      LocalSegEndJntNum(distal,rtel)=   proximal  ! rtla
      LocalSegEndJntNum(proximal,rtel)= distal    ! rtua
      LocalSegEndJntNum(distal,rtsh)=   proximal  ! rtua
      LocalSegEndJntNum(proximal,rtsh)= rt        ! trunk
      LocalSegEndJntNum(distal,lfel)=   proximal  ! lfla
      LocalSegEndJntNum(proximal,lfel)= distal    ! lfua
      LocalSegEndJntNum(distal,lfsh)=   proximal  ! lfua
      LocalSegEndJntNum(proximal,lfsh)= lf        ! trunk
      LocalSegEndJntNum(distal,neck)=   proximal  ! head
      LocalSegEndJntNum(proximal,neck)= 4         ! trunk
      LocalSegEndJntNum(distal,rtwr)=   proximal  ! rthd
      LocalSegEndJntNum(proximal,rtwr)= distal    ! rtla
      LocalSegEndJntNum(distal,lfwr)=   proximal  ! lfhd
      LocalSegEndJntNum(proximal,lfwr)= distal    ! lfla

      return
      end
