c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine ReadAnzFileParam( filename,FileNum,error )
      implicit none
      
      include 'tel_cons.inc'                                       
      include 'tel_strc.inc'
      include 't_a_file.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'         
      include 'tel_grph.inc'

      integer*4 FileNum
      character filename*40
      logical*4 error
                         
      record /anz_layout/ ptr,scale                 
      record /general_param/     GEN_PRM
      record /general_param_INT/ GEN_PRM_ANZ
      record /motion_param/      MTN_PRM
      record /motion_param_VerB/ MTN_PRM_VERB
      record /force_param/       FRC_PRM
      record /force_param_INT/   FRC_PRM_ANZ
      record /seg_param/         SEG_PRM(MAX_SEG)
      record /seg_param_INT/     SEG_PRM_ANZ(MAX_SEG)
      record /cycle/             CYC_INFO
      record /cycle_INT/         CYC_INFO_ANZ       
      record /emg_param/         EMG_PRM
      record /SegJntInfo/        SegJntInfo         ! added 1/93

      record /MarkerFlag/  MRK_FLG
      record /SegmentFlag/ SEG_FLG
      record /JointFlag/   JNT_FLG
      record /ForceFlag/   FRC_FLG
      record /AvgPosFlag/  AVG_FLG
      record /CycleFlag/   CYC_FLG
      record /EMGFlag/     EMG_FLG
      record /MiscFlags/   MISC_FLG
      record /CmndHistory/ History
                                      
      integer*4 ErrNum,PntrNum,i,j,k,l,seg_num,NumVar,NumVarTotal,VarNum(128),
     &          VarCnt,LUN,StartPtr,ft,frm,jnt,plt,side,SegNum,TempVarNum,
     &          FtFrm(2,4),NumFtFrm
      real*4    Data(MAX_ELEC_FRM),FtPosGCS(3,4)
      logical*4 SegOK,FixIt(4),FtPresent(2),rbody               
      character ANZFileVersion*1
      
      data ANZFileVersion / 'e' /
c
c     Open file
c
      error= .true.
      LUN= FD(FileNum).LU
      open( unit=LUN,file=filename,status='old',access='direct',recl=512,
     &      form='unformatted',recordtype='fixed',
     &      iostat=ErrNum,err=1000 )
c                   
c     Read the pointer and scaling blocks
c              
      read(LUN,rec=1,err=1010,iostat=ErrNum) ptr.array   
      read(LUN,rec=2,err=1010,iostat=ErrNum) scale.array
      FD(FileNum).Ptr= ptr
      FD(FileNum).Scale= scale
*$ifdef DEBUG
      write(3,995) filename
      write(6,995) filename
 995  format(' ReadAnzFileParam'/' Filename: ',a40/
     &       '  #        VarName        Pointer     Scale')
      do i= 1, 128
         write(3,996) i,AnzVarName(i),ptr.array(i),scale.array(i)
         write(6,996) i,AnzVarName(i),ptr.array(i),scale.array(i)
 996     format(i3,1x,a20,1x,i10,1x,i10)
      end do
*$endif
c
c     Scan the pointer block and figure out how many individual
c     quantities are going to be read in.  This will be used for
c     a status display
c                
      NumVar= 0
      VarCnt= 0
      NumVarTotal= ptr.array(128)
      if ( NumVarTotal .gt. 128 ) NumVarTotal= 110 ! there is a problem....
      do i= 1, NumVarTotal ! at present total number of variables is 110
        if ( ptr.array(i) .ne. 0 ) then
          NumVar= NumVar + 1
          VarNum(NumVar)= i                                  
        end if
      end do
      FD(FileNum).TotalNumVar= NumVarTotal
c           
c     Read in the parameter structures.
c     Convert the GEN,FRC,MTN,SEG,CYC structures from integer to real format
c     This conversion is done so that the ANZ file contains only integers
c     and characters in the hopes that the file will be device independent.
c     Thus, the same ANZ file could be used on a VAX, mac, UNIX box or Macintosh.
c
      call WriteStatus( FileNum,Ptr.PRM_GEN )
      read(LUN,rec=ptr.PRM_GEN,err=1010,iostat=ErrNum) GEN_PRM_ANZ.array
      if ( GEN_PRM_ANZ.num_seg .gt. MAX_SEG ) goto 3000
      if ( GEN_PRM_ANZ.num_jnt .gt. MAX_JNT ) goto 3010
      call GenItoR( GEN_PRM_ANZ, scale.PRM_GEN, GEN_PRM )
      FD(FileNum).GP= GEN_PRM

c
c     Check of byteorder number in GEN_PRM structure- This should always be equal
c     to 1.  If it is not then give error message indicating that byteorder is
c     probably not correct.  This will occur if an ANZ file created on a VAX and
c     transfered to a Macintosh and read without the rea/byte switch.  The 
c     converse is also true- creating the file on a macintosh and sending it to
c     a VAX later on.
c
      if ( GEN_PRM.ByteOrderCheck .ne. 1 ) write(6,111) GEN_PRM.ByteOrderCheck 
111     format(' Warning- The byte order check number has a value of ',i8/
     &         '          It should be 1 if the file is being correctly read.'/
     &         '          The data is probably being read incorrectly.'/
     &         '          Try reading the file into ANZ with the switch /byte'/
     &         '          and then resave it')
c
c     Read in the flags which indicate what and how calculations had
c     been carried out in the ANZ file
c
      if ( Ptr.FLAGS .ne. 0 ) then
        if ( ichar(GEN_PRM.FileFormatVersion) .ge. ichar('b') ) then
          call WriteStatus( FileNum,Ptr.FLAGS )
          read(LUN,rec=Ptr.FLAGS,err=1010,iostat=ErrNum)   MRK_FLG.flag 
          read(LUN,rec=Ptr.FLAGS+1,err=1010,iostat=ErrNum) SEG_FLG.flag 
          read(LUN,rec=Ptr.FLAGS+2,err=1010,iostat=ErrNum) JNT_FLG.flag 
          read(LUN,rec=Ptr.FLAGS+3,err=1010,iostat=ErrNum) FRC_FLG.flag 
          read(LUN,rec=Ptr.FLAGS+4,err=1010,iostat=ErrNum) EMG_FLG.flag 
          read(LUN,rec=Ptr.FLAGS+5,err=1010,iostat=ErrNum) MISC_FLG.flag 
          FD(FileNum).MF= MRK_FLG
          FD(FileNum).SF= SEG_FLG
          FD(FileNum).JF= JNT_FLG
          FD(FileNum).FF= FRC_FLG
          FD(FileNum).EF= EMG_FLG
          FD(FileNum).AF= MISC_FLG.AvgFlag
          FD(FileNum).CF= MISC_FLG.CycFlag
          call WriteStatus( FileNum,Ptr.History )
          read(LUN,rec=Ptr.History,err=1010,iostat=ErrNum)   History.array
          FD(FileNum).History(1)= History
          if ( FD(FileNum).History(1).NumHistory .gt. MAX_NUM_HISTORY ) then
            write(6,511) MAX_NUM_HISTORY
511         format(/' NOTE- Number of command histories truncated at ',i2/)
            FD(FileNum).History(1).NumHistory= MAX_NUM_HISTORY
          end if
          do i= 2, History.NumHistory
            read(LUN,rec=Ptr.History+i-1,err=1010,iostat=ErrNum)   History.array
            FD(FileNum).History(i)= History
          end do
        else                    
          FD(FileNum).MF.NumProcOps= 0
          FD(FileNum).SF.NumProcOps= 0
          FD(FileNum).JF.NumProcOps= 0
          FD(FileNum).History(1).NumHistory= 1
          FD(FileNum).History(1).NumLine= 1
          FD(FileNum).History(1).Line(1)= 'No History Available'          
          write(6,500) GEN_PRM.FileFormatVersion,ANZFileVersion
500       format(/' NOTE - This file''s format is version "',a1,'" whereas'/
     &           '        this version of TELIO reads format version "',a1,'"'/
     &           '        Most data can be read but some FLAGS data will'/
     &           '        not be read properly'//)                       
        end if ! file format is new enough to contain proper flags
      end if ! flags are present             

      if ( ptr.PRM_MTN .ne. 0 ) then
        call WriteStatus( FileNum,Ptr.PRM_MTN )
        if ( ichar(GEN_PRM.FileFormatVersion) .lt. ichar('c') ) then
          read(LUN,rec=ptr.PRM_MTN,err=1010,iostat=ErrNum) MTN_PRM_VERB.array
          do i= 1, 128
            MTN_PRM.array(i)= MTN_PRM_VERB.array(i)
          end do
          MTN_PRM.first_frm= MTN_PRM_VERB.first_frm
          do i= 1, 30
            MTN_PRM.mrk_name(i)= MTN_PRM_VERB.mrk_name(i)
          end do
        else
          read(LUN,rec=ptr.PRM_MTN,err=1010,iostat=ErrNum) MTN_PRM.array
        end if
        FD(FileNum).ExcessNumMtnFrm= .false.
        if ( FD(FileNum).MP.num_frm .gt. MAX_MTN_FRM ) then ! this check is just a
          FD(FileNum).OrigNumMtnFrm= FD(FileNum).MP.num_frm ! precaution...
          FD(FileNum).MP.num_frm= MAX_MTN_FRM
          FD(FileNum).ExcessNumMtnFrm= .true.
          write(6,201) FD(FileNum).Name,MAX_MTN_FRM,FD(FileNum).OrigNumMtnFrm
201       format(' Warning- Motion data from ',a40,' will be clipped'/
     &           '          at ',i5,' points. File contains ',i5,' data points')
        end if
        if ( MTN_PRM.num_cycle .ne. 0 ) then
          FD(FileNum).CF.GaitEvent= .true.        ! reconstruct event array
          do i= 1, MTN_PRM.num_frm     
            FD(FileNum).GaitEvent(i)= 0
          end do
          do i= 1, MTN_PRM.num_rhs
            if ( MTN_PRM.rhs_frm(i) .le. 0 ) MTN_PRM.rhs_frm(i)= 1
            if ( MTN_PRM.rhs_frm(i) .gt. MTN_PRM.num_frm )
     &        MTN_PRM.rhs_frm(i)= MTN_PRM.num_frm
            FD(FileNum).GaitEvent(MTN_PRM.rhs_frm(i))= 1
          end do
          do i= 1, MTN_PRM.num_lhs
            if ( MTN_PRM.lhs_frm(i) .le. 0 ) MTN_PRM.lhs_frm(i)= 1
            if ( MTN_PRM.lhs_frm(i) .gt. MTN_PRM.num_frm )
     &        MTN_PRM.lhs_frm(i)= MTN_PRM.num_frm
            FD(FileNum).GaitEvent(MTN_PRM.lhs_frm(i))= 2
          end do
          do i= 1, MTN_PRM.num_rto
            if ( MTN_PRM.rto_frm(i) .le. 0 ) MTN_PRM.rto_frm(i)= 1
            if ( MTN_PRM.rto_frm(i) .gt. MTN_PRM.num_frm )
     &        MTN_PRM.rto_frm(i)= MTN_PRM.num_frm
            FD(FileNum).GaitEvent(MTN_PRM.rto_frm(i))= 3
          end do
          do i= 1, MTN_PRM.num_lto
            if ( MTN_PRM.lto_frm(i) .le. 0 ) MTN_PRM.lto_frm(i)= 1
            if ( MTN_PRM.lto_frm(i) .gt. MTN_PRM.num_frm )
     &        MTN_PRM.lto_frm(i)= MTN_PRM.num_frm
            FD(FileNum).GaitEvent(MTN_PRM.lto_frm(i))= 4        
          end do
        end if
        FD(FileNum).MP= MTN_PRM
        if ( Ptr.FLAGS .ne. 0 ) then
          FD(FileNum).rMtnFrmRate= 0.001*float(FD(FileNum).MP.frm_rate)
          FD(FileNum).MP.frm_rate= nint(0.001*float(FD(FileNum).MP.frm_rate))
        else
          FD(FileNum).rMtnFrmRate= float(FD(FileNum).MP.frm_rate)
        end if
      else
         FD(FileNum).CF.GaitEvent= .false.
      end if                               
      if ( ptr.PRM_FRC .ne. 0 ) then
        call WriteStatus( FileNum,Ptr.PRM_FRC )
        read(LUN,rec=ptr.PRM_FRC,err=1010,iostat=ErrNum) FRC_PRM_ANZ.array
        call FrcItoR( FRC_PRM_ANZ, scale.PRM_FRC, FRC_PRM )
        FD(FileNum).FP= FRC_PRM
        FD(FileNum).ExcessNumFrcFrm= .false.
        if ( FD(FileNum).FP.num_frm .gt. MAX_ELEC_FRM ) then ! this check is just a
          FD(FileNum).OrigNumFrcFrm= FD(FileNum).FP.num_frm  ! precaution...
          FD(FileNum).FP.num_frm= MAX_ELEC_FRM
          FD(FileNum).ExcessNumFrcFrm= .true.
          write(6,202) FD(FileNum).Name,MAX_ELEC_FRM,FD(FileNum).OrigNumFrcFrm
202       format(' Warning- Force plate data from ',a40,' will be clipped'/
     &           '          at ',i5,' points. File contains ',i5,' data points')
        end if                   
      end if                            
      if ( ptr.PRM_CYC .ne. 0 ) then ! gait cycle statistics are present
        call WriteStatus( FileNum,Ptr.PRM_CYC )
        read(LUN,rec=ptr.PRM_CYC,err=1010,iostat=ErrNum) CYC_INFO_ANZ.array
        call CycleItoR( CYC_INFO_ANZ, scale.PRM_CYC, CYC_INFO )
        FD(FileNum).CF.statistics= .true.                         
        FD(FileNum).CP= CYC_INFO                                       
      end if     
      if ( ptr.PRM_EMG .ne. 0 ) then   
        call WriteStatus( FileNum,Ptr.PRM_EMG )
        read(LUN,rec=ptr.PRM_EMG,err=1010,iostat=ErrNum) EMG_PRM.array
        FD(FileNum).EP= EMG_PRM
        FD(FileNum).ExcessNumEmgFrm= .false.
        if ( FD(FileNum).EP.NumSamples .gt. MAX_EMG_FRM ) then ! this check is just a
          FD(FileNum).OrigNumEmgFrm= FD(FileNum).EP.NumSamples  ! precaution...
          FD(FileNum).EP.NumSamples= MAX_EMG_FRM
          FD(FileNum).ExcessNumEmgFrm= .true.
          write(6,203) FD(FileNum).Name,MAX_EMG_FRM,FD(FileNum).OrigNumEmgFrm
203       format(' Warning- EMG data from ',a40,' will be clipped'/     
     &           '          at ',i5,' points. File contains ',i5,' data points')
        end if                   
      end if
c
c     Read in the segment and joint names and connectivity data if the
c     file version is 'd' or greater, otherwise set the names/connectivity
c     to the default values
c     Added by dam 1/93 to allow non-locomotion analyses
c
      if ( (GEN_PRM.FileFormatVersion .ge. 'd') .and.
     &     (Ptr.SegJntInfo .ne. 0)                   ) then
        read(LUN,rec=Ptr.SegJntInfo,err=1010,iostat=ErrNum) SegJntInfo.array
        do i= 1, GEN_PRM.num_seg
          SegNames(i)= SegJntInfo.seg_names(i)
        end do
        do i= 1, GEN_PRM.num_jnt
          JntNames(i)= SegJntInfo.jnt_names(i)
          JntSegNum(1,i)= SegJntInfo.jnt_seg_num(1,i)
          JntSegNum(2,i)= SegJntInfo.jnt_seg_num(2,i)
        end do
      else
        call SetUpFullBodyNames
      end if
c                                      
c     Now check for each group of data using the value of the pointer in the
c     ptr structure as an indicator of whether the data is present or not.
c     If ptr is 0, then the data has not been calculated and saved in the
c     ANZ file.             
c
c     marker data                    
c         
      if ( Ptr.FLAGS .eq. 0 ) then ! manual assignment of flags is needed                        
        if ( ptr.MrkPosGCS .ne. 0 ) then
          FD(FileNum).MF.read=         .true.
          FD(FileNum).MF.interpolated= .true. 
          FD(FileNum).MF.adjusted=     .true.
        end if
        if ( ptr.MrkPosLCS .ne. 0 )  FD(FileNum).MF.diagnostics=  .true. 
        if ( ptr.MrkVel .ne. 0 ) then
          FD(FileNum).MF.VelAcc= .true.
          FD(FileNum).MF.Smoothed= .true.
        end if
      end if
c                                                      
c     Segment data
c
      if ( ptr.SegParam .ne. 0 ) then
        if ( ichar(GEN_PRM.FileFormatVersion) .ge. ichar('c') ) rbody= .true.
        PntrNum= ptr.SEGParam
        call WriteStatus( FileNum,Ptr.SegParam )
        do i= 1, GEN_PRM.num_seg        
          seg_num= GEN_PRM.seg_num(i)
          read(LUN,rec=PntrNum,err=1010,iostat=ErrNum) SEG_PRM_ANZ(seg_num).array
*$ifdef DEBUG
          write(3,997) i,seg_num
          write(6,997) i,seg_num
 997      format(' Index: ',i2,'  Segment number: ',i2)
*$endif
          call SegItoR( SEG_PRM_ANZ(seg_num), scale.SegParam, 
     &                  SEG_PRM(seg_num),rbody )
          FD(FileNum).SP(seg_num)= SEG_PRM(seg_num)
          PntrNum= PntrNum + 1                
        end do
        FD(FileNum).SF.Param= .true.
      end if  
               
      if ( Ptr.FLAGS .eq. 0 ) then ! manual assignment of flags is needed                        
        if ( ptr.SegPos .ne. 0 )      FD(FileNum).SF.Pos= .true.                 
        if ( ptr.SegVelGCS .ne. 0 )   FD(FileNum).SF.VelAcc= .true.
        if ( ptr.SegKE .ne. 0 )       FD(FileNum).SF.energy= .true.          
        if ( ptr.ScrewFinGCS .ne. 0 ) FD(FileNum).SF.FiniteScrew= .true.  
        if ( ptr.ScrewInsGCS .ne. 0 ) FD(FileNum).SF.InstantScrew= .true.
        if ( ptr.BodyCM .ne. 0 )      FD(FileNum).SF.CntrMass= .true.
        if ( ptr.BCMVel .ne. 0 )      FD(FileNum).SF.BCMVel= .true.
        if ( ptr.SegMom .ne. 0 )      FD(FileNum).SF.Momentum= .true.
        if ( ptr.SegAngGCS .ne. 0 )   FD(FileNum).SF.Angle= .true.
      end if    
c
c     Force plate data               
c
      if ( ptr.FpData .ne. 0 ) then                  
        FD(FileNum).FF.read=     .true.     
        if ( FRC_PRM.num_frm .eq. MTN_PRM.num_frm ) 
     &    FD(FileNum).FF.DataClipped= .true.
      end if   
                                      
      if ( ptr.CombGRL .ne. 0 )  FD(FileNum).FF.adjusted= .true.
      
      if ( ptr.FtDataOK .ne. 0 ) then
        call WriteStatus( FileNum,Ptr.FtDataOK )
        do ft= rt, lf
          if ( FD(FileNum).ExcessNumFrcFrm ) then
            StartPtr= (ft-1)*FD(FileNum).OrigNumFrcFrm
          else
            StartPtr= (ft-1)*FD(FileNum).FP.num_frm + 1
          end if
          call ReadAnzDataSet( LUN,Ptr.FtDataOK,
     &                         StartPtr,1,FD(FileNum).FP.num_frm,
     &                         Scale.FtDataOK,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010
          do frm= 1, FD(FileNum).FP.num_frm
            FtDataOK(frm,ft,FileNum)= .false.
            if ( abs(Data(frm)+1.0) .lt. 1.0e-5 ) 
     &        FtDataOK(frm,ft,FileNum)= .true.
            end do     
        end do 
        FD(FileNum).FF.Read=     .true.
        FD(FileNum).FF.Adjusted= .true.                  
        FD(FileNum).FF.IndFt=    .true.
      else
        do frm= 1, FD(FileNum).FP.num_frm
          do ft= rt, lf
            FtDataOK(frm,ft,FileNum)= .false.
          end do                        
        end do                       
      endif
      
      if ( ptr.FpDataOK .ne. 0 ) then
        call WriteStatus( FileNum,Ptr.FpDataOK )
        do plt= 1, FD(FileNum).FP.num_plt
          if ( FD(FileNum).ExcessNumFrcFrm ) then
            StartPtr= (plt-1)*FD(FileNum).OrigNumFrcFrm
          else
            StartPtr= (plt-1)*FD(FileNum).FP.num_frm + 1
          end if
          call ReadAnzDataSet( LUN,Ptr.FpDataOK,
     &                         StartPtr,1,FD(FileNum).FP.num_frm,
     &                         Scale.FpDataOK,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010
          do frm= 1, FD(FileNum).FP.num_frm
            FpDataOK(frm,plt,FileNum)= .false.
            if ( abs(Data(frm)+1.0) .lt. 1.0e-5 ) 
     &        FpDataOK(frm,plt,FileNum)= .true.
            end do                     
        end do ! plt                           
        StartPtr= 1
        call WriteStatus( FileNum,Ptr.FcDataOK )
        call ReadAnzDataSet( LUN,Ptr.FcDataOK,
     &                       StartPtr,1,FD(FileNum).FP.num_frm,
     &                       Scale.FcDataOK,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010
        do frm= 1, FD(FileNum).FP.num_frm
          FcDataOK(frm,FileNum)= .false.
          if ( abs(Data(frm)+1.0) .lt. 1.0e-5 ) FcDataOK(frm,FileNum)= .true.
        end do                     
        FD(FileNum).FF.Read=     .true.
        FD(FileNum).FF.Adjusted= .true.                  
      else
        do frm= 1, FD(FileNum).FP.num_frm
          do plt= 1, MAX_PLT
            FpDataOK(frm,plt,FileNum)= .true.
          end do
          FcDataOK(frm,FileNum)= .true.
        end do                       
      endif       
                
      if ( ptr.FloorContact .ne. 0 ) then
        call WriteStatus( FileNum,Ptr.FloorContact )
        do ft= rt, lf
          if ( FD(FileNum).ExcessNumMtnFrm ) then
            StartPtr= (ft-1)*FD(FileNum).OrigNumMtnFrm
          else
            StartPtr= (ft-1)*FD(FileNum).MP.num_frm + 1
          end if
          call ReadAnzDataSet( LUN,Ptr.FloorContact,
     &                         StartPtr,1,FD(FileNum).MP.num_frm,
     &                         Scale.FloorContact,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010
          do frm= 1, FD(FileNum).MP.num_frm
            FloorContact(frm,ft,FileNum)= .false.
            if ( abs(Data(frm)+1.0) .lt. 1.0e-5 ) 
     &        FloorContact(frm,ft,FileNum)= .true.
            end do     
        end do                                         
      else
        do frm= 1, FD(FileNum).MP.num_frm
          do ft= rt, lf
            FloorContact(frm,ft,FileNum)= .false.
          end do                        
        end do                       
      endif
                                  
      if ( Ptr.FLAGS .eq. 0 ) then ! manual assignment of flags is needed                        
        if ( ptr.FtCp .ne. 0 )     FD(FileNum).FF.CpGCS= .true.            
        if ( ptr.FtCpLCS .ne. 0 )  FD(FileNum).FF.CpLCS= .true.
        if ( ptr.FtSI .ne. 0 )     FD(FileNum).FF.Si= .true. 
        if ( ptr.FtWrench .ne. 0 ) FD(FileNum).FF.Wrench= .true.
        if ( ptr.FtInt1 .ne. 0 )   FD(FileNum).FF.Integral= .true.                 
        if ( ptr.FpCp .ne. 0 )     FD(FileNum).FF.CpGCS=    .true.
        if ( ptr.FpWrench .ne. 0 ) FD(FileNum).FF.Wrench=     .true.        
        if ( ptr.PmaPnt .ne. 0 )   FD(FileNum).FF.PitchMomArm= .true.
        if ( ptr.PwaPnt .ne. 0 )   FD(FileNum).FF.PitchWreArm= .true.
        if ( ptr.FtCpVelGCS .ne. 0 )  FD(FileNum).FF.CpVelGCS= .true.
      end if
c
c     Reconstructed Ground Reaction Load
c
      if ( ptr.FtGRLRecLCS .ne. 0 ) FD(FileNum).FF.Rec= .true.
c       
c     Joint data                               
c                       
      if ( Ptr.FLAGS .eq. 0 ) then ! manual assignment of flags is needed                        
        if ( ptr.JntAngJCS .ne. 0 )     FD(FileNum).JF.AngJCS= .true.
        if ( ptr.JntVelJCS .ne. 0 )     FD(FileNum).JF.VelAccJCS= .true.
        if ( ptr.JntAngEUL .ne. 0 )     FD(FileNum).JF.AngEUL= .true.
        if ( ptr.JntVelEUL .ne. 0 )     FD(FileNum).JF.VelAccEUL= .true.
      end if
      
      if ( ptr.JntLoadGCS .ne. 0 ) then
        call WriteStatus( FileNum,Ptr.JntCalcOK )
        do i= 1, FD(FileNum).GP.num_jnt
          jnt= FD(FileNum).GP.jnt_num(i)
          if ( FD(FileNum).ExcessNumMtnFrm ) then
            StartPtr= (i-1)*FD(FileNum).OrigNumMtnFrm
          else
            StartPtr= (i-1)*FD(FileNum).MP.num_frm + 1
          end if
          call ReadAnzDataSet( LUN,Ptr.JntCalcOK,
     &                         StartPtr,1,FD(FileNum).MP.num_frm,
     &                         Scale.JntCalcOK,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010
          do frm= 1, FD(FileNum).MP.num_frm
            JntCalcOK(frm,jnt,FileNum)= .false.
            if ( abs(Data(frm)+1.0) .lt. 1.0e-5 ) 
     &        JntCalcOK(frm,jnt,FileNum)= .true.
          end do
        end do ! i => jnt                
        FD(FileNum).JF.Load= .true.        
      else
        do i= 1, FD(FileNum).GP.num_jnt
          jnt= FD(FileNum).GP.jnt_num(i)
          do frm= 1, FD(FileNum).MP.num_frm
            JntCalcOK(frm,jnt,FileNum)= .false.
          end do
        end do ! i => jnt                   
      end if
      
      if ( Ptr.FLAGS .eq. 0 ) then ! manual assignment of flags is needed                        
c        if ( ptr.JntLoadLegJCS .ne. 0 ) FD(FileNum).JF.LegLoad= .true.
        if ( ptr.JntWrenchLCS .ne. 0 )  FD(FileNum).JF.Wrench= .true.    
        if ( ptr.JntPower .ne. 0 )      FD(FileNum).JF.Power= .true.        
c        if ( ptr.JntPowerLeg .ne. 0 )   FD(FileNum).JF.LegPower= .true.        
        if ( ptr.ScrewFinLCS .ne. 0 )   FD(FileNum).JF.FiniteScrew= .true.       
        if ( ptr.ScrewInsLCS .ne. 0 )   FD(FileNum).JF.InstantScrew= .true.
        if ( ptr.JntTransGCS .ne. 0 )   FD(FileNum).JF.Translation=  .true.
        if ( ptr.JntFscAngJCS .ne. 0 )  FD(FileNum).JF.ScrewAngle=   .true.
        if ( ptr.JntMomArmGCS .ne. 0 )  FD(FileNum).JF.MomentArm=    .true.
        if ( ptr.JntWreArmGCS .ne. 0 )  FD(FileNum).JF.WrenchArm=    .true.
      End if
c
c     average position data
c
      if ( Ptr.FLAGS .eq. 0 ) then ! manual assignment of flags is needed                        
        if ( ptr.AvgSegPos .ne. 0 ) then
          FD(FileNum).AF.Read= .true.
          FD(FileNum).AF.Pos= .true.
        end if                              
        if ( ptr.AvgAngJCS .ne. 0 )  FD(FileNum).AF.AngJCS= .true.            
        if ( ptr.AvgAngEUL .ne. 0 )  FD(FileNum).AF.AngEUL= .true.
      end if
c
c     Read EMG data if present
c                    
      if ( ptr.PRM_EMG .ne. 0 )  FD(FileNum).EF.read= .true.         
c
c     Read in and set up foot outlines in LCS and GCS if data is present
c
c     First the LCS outlines
c
      if ( FD(FileNum).SF.Param ) then ! read in outlines in foot LCS
        do side= rt, lf
          SegNum= rtft                             
          if ( side .eq. lf ) SegNum= lfft
          i= 1
          do while ( (.not. SegOK) .and. (i .le. FD(FileNum).GP.num_seg) )
            if ( SegNum .eq. FD(FileNum).GP.seg_num(i) ) SegOK= .true.
            i= i + 1
          end do
          if ( .not. SegOK ) then
            FD(FileNum).FtOutLineLcsOK(side)= .false.
            FD(FileNum).FtOutLineGcsOK(side)= .false.
            do i= 1, 4
              do j= 1, 3
                FD(FileNum).FtOutLineLCS(j,i,side)= 0.0
              end do
            end do
          else
            FD(FileNum).FtOutLineLcsOK(side)= .true.
            do i= 1, 4
              do j= 1, 3
                FD(FileNum).FtOutLineLCS(j,i,side)= 
     &            FD(FileNum).SP(SegNum).Shape(j,i)
              end do
            end do
          end if ! is foot segment shape data present ?
        end do ! right and left sides
      else ! zero out both LCS and GCS foot outlines
        do side= rt, lf
          FD(FileNum).FtOutLineLcsOK(side)= .false.
          FD(FileNum).FtOutLineGcsOK(side)= .false.
          do i= 1, 4
            do j= 1, 3
              FD(FileNum).FtOutLineLCS(j,i,side)= 0.0
              FD(FileNum).FtOutLineGCS(j,i,side)= 0.0
            end do
          end do
        end do ! side
      end if                
c
c     Now the GCS outlines
c     There are four outlines corresponding the four times the feet are on the
c     ground during the gait cycle 
c     rt: 1,3
c     lf: 2,4
c
      if ( (.not. FD(FileNum).SF.Pos) .or. 
     &     (.not. FD(FileNum).FF.IndFt) .or.
     &     (.not. FD(FileNum).CF.GaitEvent)      ) then
        FD(FileNum).FtOutLineGcsOK(rt)= .false.
        FD(FileNum).FtOutLineGcsOK(lf)= .false.
      else                           
        FD(FileNum).Type= ANZ_FILE    
        TempVarNum= SPN_DATA
        if ( FD(FileNum).MP.first_ft .eq. rt ) then
          FtFrm(1,2)= FD(FileNum).MP.rhs_frm(1)
          FtFrm(2,2)= FD(FileNum).MP.lto_frm(1)
          FtFrm(1,1)= FD(FileNum).MP.rhs_frm(1)
          FtFrm(2,1)= FD(FileNum).MP.rto_frm(1)
          FtFrm(1,4)= FD(FileNum).MP.lhs_frm(1)
          FtFrm(2,4)= FD(FileNum).MP.rhs_frm(2)
          FtFrm(1,3)= FD(FileNum).MP.rhs_frm(2)
          FtFrm(2,3)= FD(FileNum).MP.rhs_frm(2)
        else
          FtFrm(1,1)= FD(FileNum).MP.lhs_frm(1)
          FtFrm(2,1)= FD(FileNum).MP.rto_frm(1)
          FtFrm(1,2)= FD(FileNum).MP.lhs_frm(1)
          FtFrm(2,2)= FD(FileNum).MP.lto_frm(1)
          FtFrm(1,3)= FD(FileNum).MP.rhs_frm(1)
          FtFrm(2,3)= FD(FileNum).MP.lhs_frm(2)
          FtFrm(1,4)= FD(FileNum).MP.lhs_frm(2)
          FtFrm(2,4)= FD(FileNum).MP.lhs_frm(2)
        end if
c
c         Special trap for nongait data such as CKC which is what blew this
c         up in the first place...                   7/92 dam
c
        FtPresent(rt)= .false.
        FtPresent(lf)= .false.
        do i= 1, FD(FileNum).GP.num_seg
          if ( FD(FileNum).GP.seg_num(i) .eq. rtft ) FtPresent(rt)= .true.
          if ( FD(FileNum).GP.seg_num(i) .eq. lfft ) FtPresent(lf)= .true.
        end do
        do k= 1, 4
          if ( FtPresent(rt) .and. FtPresent(lf) ) then
            if ( (k .eq. 1) .or. (k .eq. 3) ) then
              SegNum=rtft
              side= rt
            else
              SegNum= lfft
              side= lf
            end if 
          else if ( FtPresent(rt) ) then
            SegNum= rtft
            side= rt
          else
            SegNum= lfft
            side= lf
          end if
          do i= 1, 4
            FixIt(i)= .false.
            if ( (FtFrm(1,i) .le. 0) .and. (FtFrm(2,i) .le. 0) ) FixIt(i)= .true.
            if ( FtFrm(1,i) .gt. FtFrm(2,i) ) FixIt(i)= .true.
            if ( FtFrm(1,i) .eq. 0 ) FtFrm(1,i)= 1
            if ( FtFrm(2,i) .eq. 0 ) FtFrm(2,i)= 1
          end do 
          do i= 1, 4
            if ( FixIt(i) ) then
               FtFrm(1,i)= FD(FileNum).MP.num_frm/2 - FD(FileNum).MP.num_frm/10
               FtFrm(2,i)= FD(FileNum).MP.num_frm/2 + FD(FileNum).MP.num_frm/10
            end if
          end do
c
c         Now continue on...
c                   
          NumFtFrm= FtFrm(2,k) - FtFrm(1,k) + 1
          if ( FD(FileNum).FtOutLineLcsOK(side) ) then
            do i= 1, 4         
              do j= 1, 3
               call ReadFileData( FileNum,TempVarNum,SegNum,j,i,0,
     &                            FtFrm(1,k),FtFrm(2,k),
     &                            PltData(1,1,MAX_PLT,MAX_GRAPH),
     &                            PltDataOK(1,MAX_PLT,MAX_GRAPH),error   )
                FtPosGCS(j,i)= 0.0
                do l= 1, NumFtFrm
                  FtPosGCS(j,i)= FtPosGCS(j,i) + PltData(1,1,MAX_PLT,MAX_GRAPH)
                end do
                FtPosGCS(j,i)= FtPosGCS(j,i)/float(NumFtFrm)
              end do ! j
            end do ! i                                                
            do i= 1, 4                            
              call PntChangeCS( FtPosGCS,
     &                          FD(FileNum).FtOutLineLCS(x,i,side),
     &                          FD(FileNum).FtOutLineGCS(x,i,k)  )
            end do
            FD(FileNum).FtOutLineGcsOK(side)= .true.  
          else ! this side is not present in data...
            FD(FileNum).FtOutLineGcsOK(side)= .false. 
          end if
        end do ! side
      end if ! is segment position and foot force data present ? 
      error= .false.
      return                            
                     
1000  write(6,1005) filename,ErrNum                
1005  format(' ErrNum- Trouble opening ',a40/
     &       '        ErrNum number ',i2,' occurred.'/)
      return           
      
1010  write(6,1015) ErrNum,filename
1015  format(' ErrNum- ErrNum # ',i2,' occured while reading ',a40)
      return      

3000  write(6,3005) GEN_PRM.num_seg,MAX_SEG
3005  format(' Error- Number of segments in file (',i2,') exceeds the'/
     &       '        maximum number of segments allowed (',i2,')')
      return      

3010  write(6,3015) GEN_PRM.num_jnt,MAX_JNT
3015  format(' Error- Number of segments in file (',i2,') exceeds the'/
     &       '        maximum number of segments allowed (',i2,')')
      return      
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine ReadANZFileData( FileNum,VarNum,CompNum,Axis1Num,Axis2Num,
     &                            CSNum,Start,End,Data,DataOK,error )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'
      include 'tel_name.inc'
                       
      integer*4 FileNum,VarNum,CompNum,Axis1Num,Axis2Num,Start,End,CSNum
      real*4    Data(MAX_PLOT_SIZE)
      logical*4 error,DataOK(MAX_PLOT_SIZE)

      integer*4 NumPnts,PtrInc,StartPtr,ErrNum,i,jnt,MtnNumFrm,FrcNumFrm,
     &          EmgNumFrm

c
c     debug code
c
c      write(6,10) FileNum,VarNum,CompNum,Axis1Num,Axis2Num,CSNum,Start,End
c 10   format(' File Number     : ',i2/
c     &       ' Variable Number : ',i2/
c     &       ' Component Number: ',i2/
c     &       ' Axis 1 Number   : ',i2/
c     &       ' Axis 2 Number   : ',i2/
c     &       ' Coord Sys Number: ',i2/
c     &       ' Start           : ',i2/
c     &       ' End             : ',i2//)
c
c     Set up number of frames in case of too big a file for arrays
c
      if ( FD(FileNum).ExcessNumMtnFrm ) then
        MtnNumFrm= FD(FileNum).OrigNumMtnFrm
      else
        MtnNumFrm= FD(FileNum).MP.num_frm
      end if
      if ( FD(FileNum).ExcessNumFrcFrm ) then
        FrcNumFrm= FD(FileNum).OrigNumFrcFrm
      else
        FrcNumFrm= FD(FileNum).FP.num_frm
      end if
      if ( FD(FileNum).ExcessNumEmgFrm ) then
        EmgNumFrm= FD(FileNum).OrigNumEmgFrm
      else
        EmgNumFrm= FD(FileNum).EP.NumSamples
      end if
c                            
c     Select the variable to be read based upon VarNum and read in from
c     the ANZ file
c
c     marker data                    
c                           
      error= .true.                                            
      NumPnts= End-Start+1
      if ( VarNum .eq. MPN_DATA ) then                        ! CompNum= Mrk
        call WriteStatus( FileNum,FD(FileNum).Ptr.MrkPosGCS ) ! Axis1Num= x,y,z
        PtrInc= 3
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm + (Axis1Num-1) +
     &            (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.MrkPosGCS,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.MrkPosGCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                            
        call SetAllDataOK( DataOK )                            
        error= .false.

      else if ( VarNum .eq. MVL_DATA ) then                   ! CompNum= Mrk
        call WriteStatus( FileNum,FD(FileNum).Ptr.MrkVel )    ! Axis1Num= x,y,z
        PtrInc= 3
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm + (Axis1Num-1) +
     &            (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.MrkVel,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.MrkVel,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )                            
        error= .false.

      else if ( VarNum .eq. MAC_DATA ) then                   ! CompNum= Mrk
        call WriteStatus( FileNum,FD(FileNum).Ptr.MrkAcc )    ! Axis1Num= x,y,z
        PtrInc= 3
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm + (Axis1Num-1) +
     &            (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.MrkAcc,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.MrkAcc,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )                            
        error= .false.

      else if ( VarNum .eq. SMP_DATA ) then                   ! CompNum= Seg
        call WriteStatus( FileNum,FD(FileNum).Ptr.MrkPosLCS ) ! Axis1Num= x,y,z
        PtrInc= 3*5                                           ! Axis2Num= Mrk
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + 3*(Axis2Num-1) + 
     &            (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.MrkPosLCS,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.MrkPosLCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )                            
        error= .false.           

      else if ( VarNum .eq. SMD_DATA ) then                 ! CompNum= Seg
        call WriteStatus( FileNum,FD(FileNum).Ptr.MrkDist ) ! Axis1Num= Mrk
        PtrInc= 6
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.MrkDist,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.MrkDist,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )
        error= .false.
c                                                      
c     Segment data                                             
c
      else if ( VarNum .eq. SPN_DATA ) then                ! CompNum = Seg
        call WriteStatus( FileNum,FD(FileNum).Ptr.SegPos ) ! Axis1Num= x,y,z
        PtrInc= 3*4                                        ! Axis2Num= x,y,z,c
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + 3*(Axis2Num-1) + 
     &            (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegPos,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.SegPos,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )
        error= .false.
                                                
      else if ( VarNum .eq. SVL_DATA ) then    ! CompNum = Seg
        if ( CSNum .eq. GCS_CST ) then         ! Axis1Num = x - rz
          call WriteStatus( FileNum,FD(FileNum).Ptr.SegVelGCS )
          PtrInc= 6
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegVelGCS,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.SegVelGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )                     
          error= .false.
        else if ( CSNum .eq. LCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.SegVelLCS )
          PtrInc= 6
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegVelLCS,
     &                         StartPtr,PtrInc,NumPnts,         
     &                         FD(FileNum).Scale.SegVelLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
        end if

      else if ( VarNum .eq. SAC_DATA ) then          ! CompNum = Seg
        if ( CSNum .eq. GCS_CST ) then               ! Axis1Num = x - rz
          call WriteStatus( FileNum,FD(FileNum).Ptr.SegAccGCS )
          PtrInc= 6
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegAccGCS,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.SegAccGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.                           
        else if ( CSNum .eq. LCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.SegAccLCS )
          PtrInc= 6
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegAccLCS,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.SegAccLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
        end if
                                                      
      else if ( VarNum .eq. SKE_DATA ) then                 ! CompNum= Seg
          call WriteStatus( FileNum,FD(FileNum).Ptr.SegKE ) ! Axis1Num= t,r,m
          PtrInc= 3
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegKE,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.SegKE,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
                            
      else if ( VarNum .eq. SPE_DATA ) then                 ! CompNum= Seg
          call WriteStatus( FileNum,FD(FileNum).Ptr.SegPE ) 
          PtrInc= 1
          StartPtr= (CompNum-1)*MtnNumFrm + (Start-1) + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegPE,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.SegPE,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )                             
          error= .false.

      else if ( VarNum .eq. STE_DATA ) then                 ! CompNum= Seg
          call WriteStatus( FileNum,FD(FileNum).Ptr.SegTE ) 
          PtrInc= 1
          StartPtr= (CompNum-1)*MtnNumFrm + (Start-1) + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegTE,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.SegTE,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
                                                      
      else if ( VarNum .eq. BKE_DATA ) then                 ! CompNum= r,t,m
          call WriteStatus( FileNum,FD(FileNum).Ptr.BodyKE ) 
          PtrInc= 3
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.BodyKE,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.BodyKE,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
                   
      else if ( VarNum .eq. BPE_DATA ) then           
          call WriteStatus( FileNum,FD(FileNum).Ptr.BodyPE ) 
          PtrInc= 1
          StartPtr= Start
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.BodyPE,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.BodyPE,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.

      else if ( VarNum .eq. BTE_DATA ) then           
          call WriteStatus( FileNum,FD(FileNum).Ptr.BodyTE ) 
          PtrInc= 1
          StartPtr= Start
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.BodyTE,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.BodyTE,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )            
          error= .false.
    
      else if ( VarNum .eq. SFS_DATA ) then             ! CompNum= Seg
        call WriteStatus( FileNum,FD(FileNum).Ptr.ScrewFinGCS ) 
        PtrInc= 8                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.ScrewFinGCS,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.ScrewFinGCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )                    
        error= .false.                                            

      else if ( VarNum .eq. SIS_DATA ) then             ! CompNum= Seg
        call WriteStatus( FileNum,FD(FileNum).Ptr.ScrewInsGCS ) 
        PtrInc= 8                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.ScrewInsGCS,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.ScrewInsGCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )
        error= .false.                                            
                                                     
      else if ( VarNum .eq. BCM_DATA ) then                 ! CompNum= x,y,z
          call WriteStatus( FileNum,FD(FileNum).Ptr.BodyCM ) 
          PtrInc= 3
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.BodyCM,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.BodyCM,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
                   
      else if ( VarNum .eq. BCV_DATA ) then                 ! CompNum= x,y,z
          call WriteStatus( FileNum,FD(FileNum).Ptr.BCMVel ) 
          PtrInc= 3
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.BCMVel,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.BCMVel,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
                   
      else if ( VarNum .eq. SMM_DATA ) then             ! CompNum= Seg
        call WriteStatus( FileNum,FD(FileNum).Ptr.SegMom ) 
        PtrInc= 8                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegMom,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.SegMom,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )
        error= .false.                                            
                                                     
      else if ( VarNum .eq. BMM_DATA ) then               ! CompNum= component
          call WriteStatus( FileNum,FD(FileNum).Ptr.BodyMom ) 
          PtrInc= 8
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.BodyMom,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.BodyMom,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call SetAllDataOK( DataOK )
          error= .false.
                   
      else if ( VarNum .eq. SAN_DATA ) then             ! CompNum= Seg
        call WriteStatus( FileNum,FD(FileNum).Ptr.SegAngGCS ) 
        PtrInc= 3                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.SegAngGCS,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.SegAngGCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call SetAllDataOK( DataOK )
        error= .false.                                            
c
c     Force plate data               
c                                  
      else if ( VarNum .eq. FPL_DATA ) then             ! CompNum= Plate#
        call WriteStatus( FileNum,FD(FileNum).Ptr.FpData ) 
        PtrInc= 6                                       ! Axis1Num= fx-mz
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FpData,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.FpData,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFpDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                                            
                   
      else if ( VarNum .eq. FCB_DATA ) then               ! CompNum= fx-mz
        call WriteStatus( FileNum,FD(FileNum).Ptr.CombGRL ) 
        PtrInc= 6
        StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.CombGRL,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.CombGRL,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFcDataOK( FileNum,Start,End,DataOK )
        error= .false.
                     
      else if ( VarNum .eq. FFT_DATA ) then             ! CompNum= rt,lf
        if ( CSNum .ne. LCS_CST ) then                  ! Axis1Num= fx-mz
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtGRL ) 
          PtrInc= 6                                       
          StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtGRL,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.FtGRL,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010 
          call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                            
        else ! foot load in foot LCS
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtGRLLCS ) 
          PtrInc= 6                                 
          StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtGRLLCS,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.FtGRLLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010 
          call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                            
        end if
                   
      else if ( VarNum .eq. FCP_DATA ) then             ! CompNum= plate#
        call WriteStatus( FileNum,FD(FileNum).Ptr.FpCp ) 
        PtrInc= 3                                       ! Axis1Num= x,y,z
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FpCp,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.FpCp,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                           
        call AssignFpDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                                            
                                                   
      else if ( VarNum .eq. FCC_DATA ) then               ! CompNum= x,y,z
        call WriteStatus( FileNum,FD(FileNum).Ptr.CombCp ) 
        PtrInc= 3
        StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.CombCp,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.CombCp,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFcDataOK( FileNum,Start,End,DataOK )
        error= .false.
                   
      else if ( VarNum .eq. FCF_DATA ) then             ! CompNum= rt,lf
        if ( CSNum .eq. GCS_CST ) then     
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtCp ) 
          PtrInc= 3                                       ! Axis1Num= x,y,z
          StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtCp,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.FtCp,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                           
        else if ( CSNum .eq. LCS_CST ) then                 
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtCpLCS ) 
          PtrInc= 3                                       ! Axis1Num= x,y,z
          StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtCpLCS,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.FtCpLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                           
        end if                                     
                                                        
      else if ( VarNum .eq. FSI_DATA ) then               ! CompNum= rt,lf
        call WriteStatus( FileNum,FD(FileNum).Ptr.FtSi ) 
        PtrInc= 1
        StartPtr= (CompNum-1)*MtnNumFrm + (Start-1) + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtSi,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.FtSi,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.
                                                       
      else if ( VarNum .eq. FWP_DATA ) then             ! CompNum= Plate#
        call WriteStatus( FileNum,FD(FileNum).Ptr.FpWrench ) 
        PtrInc= 8                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FpWrench,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.FpWrench,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFpDataOK( FileNum,CompNum,Start,End,DataOK )
        if ( Axis1Num .eq. 7 ) then
          do i= 1, NumPnts
            Data(i)= Data(i)*10000.0   ! special scaling compensation...
          end do
        end if
        error= .false.                                            
                                                       
      else if ( VarNum .eq. FWC_DATA ) then               ! CompNum= component
        call WriteStatus( FileNum,FD(FileNum).Ptr.CombWrench ) 
        PtrInc= 8
        StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.CombWrench,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.CombWrench,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFcDataOK( FileNum,Start,End,DataOK )
        if ( Axis1Num .eq. 7 ) then
          do i= 1, NumPnts
            Data(i)= Data(i)*10000.0   ! special scaling compensation...
          end do
        end if
        error= .false.
                   
      else if ( VarNum .eq. FWF_DATA ) then             ! CompNum= rt,lf
        call WriteStatus( FileNum,FD(FileNum).Ptr.FtWrench ) 
        PtrInc= 8                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +           
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtWrench,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.FtWrench,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                           
        call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
        if ( Axis1Num .eq. 7 ) then
          do i= 1, NumPnts
            Data(i)= Data(i)*10000.0   ! special scaling compensation...
          end do
        end if
        error= .false.                                            
                                                       
      else if ( VarNum .eq. FP1_DATA ) then             ! CompNum= Plate#
        call WriteStatus( FileNum,FD(FileNum).Ptr.FpInt1 ) 
        PtrInc= 4                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FpInt1,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.FpInt1,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFpDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                                            
                   
      else if ( VarNum .eq. FC1_DATA ) then               ! CompNum= component
        call WriteStatus( FileNum,FD(FileNum).Ptr.CombInt1 ) 
        PtrInc= 4                             
        StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.CombInt1,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.CombInt1,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFcDataOK( FileNum,Start,End,DataOK )
        error= .false.
                   
      else if ( VarNum .eq. FF1_DATA ) then             ! CompNum= rt,lf
        call WriteStatus( FileNum,FD(FileNum).Ptr.FtInt1 ) 
        PtrInc= 4                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtInt1,
     &                       StartPtr,PtrInc,NumPnts,  
     &                       FD(FileNum).Scale.FtInt1,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                           
        call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                                            

      else if ( VarNum .eq. FP2_DATA ) then             ! CompNum= Plate#
        call WriteStatus( FileNum,FD(FileNum).Ptr.FpInt2 ) 
        PtrInc= 4                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FpInt2,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.FpInt2,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFpDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                                            
                   
      else if ( VarNum .eq. FC2_DATA ) then               ! CompNum= component
        call WriteStatus( FileNum,FD(FileNum).Ptr.CombInt2 ) 
        PtrInc= 4                             
        StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.CombInt2,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.CombInt2,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignFcDataOK( FileNum,Start,End,DataOK )
        error= .false.
                   
      else if ( VarNum .eq. FF2_DATA ) then             ! CompNum= rt,lf
        call WriteStatus( FileNum,FD(FileNum).Ptr.FtInt2 ) 
        PtrInc= 4                                       ! Axis1Num= component
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtInt2,
     &                       StartPtr,PtrInc,NumPnts,  
     &                       FD(FileNum).Scale.FtInt2,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                           
        call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                                            

      else if ( VarNum .eq. PMA_DATA ) then               ! CompNum= x,y,z,mag
        if ( CSNum .eq. GCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.PmaGCS ) 
          PtrInc= 4                                    
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.PmaGCS,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.PmaGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call AssignFcDataOK( FileNum,Start,End,DataOK )
          error= .false.
        else if ( CSNum .eq. PLV_CST ) then            
          call WriteStatus( FileNum,FD(FileNum).Ptr.PmaPlv ) 
          PtrInc= 3
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.PmaPlv,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.PmaPlv,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call AssignFcDataOK( FileNum,Start,End,DataOK )
          error= .false.
        else if ( CSNum .eq. TRK_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.PmaTrk ) 
          PtrInc= 3
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.PmaTrk,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.PmaTrk,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call AssignFcDataOK( FileNum,Start,End,DataOK )
          error= .false.
        end if

      else if ( VarNum .eq. PWA_DATA ) then               ! CompNum= x,y,z,mag
        if ( CSNum .eq. GCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.PwaGCS ) 
          PtrInc= 4                                    
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.PwaGCS,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.PwaGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call AssignFcDataOK( FileNum,Start,End,DataOK )
          error= .false.
        else if ( CSNum .eq. PLV_CST ) then            
          call WriteStatus( FileNum,FD(FileNum).Ptr.PwaPlv ) 
          PtrInc= 3
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.PwaPlv,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.PwaPlv,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call AssignFcDataOK( FileNum,Start,End,DataOK )       
          error= .false.
        else if ( CSNum .eq. TRK_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.PwaTrk ) 
          PtrInc= 3
          StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.PwaTrk,
     &                         StartPtr,PtrInc,NumPnts,
     &                         FD(FileNum).Scale.PwaTrk,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                  
          call AssignFcDataOK( FileNum,Start,End,DataOK )       
          error= .false.
        end if

      else if ( VarNum .eq. FCV_DATA ) then             ! CompNum= rt,lf
        call WriteStatus( FileNum,FD(FileNum).Ptr.FtCpVelGCS ) 
        PtrInc= 3                                       ! Axis1Num= x,y,z
        StartPtr= (CompNum-1)*PtrInc*FrcNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtCpVelGCS,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.FtCpVelGCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                           
        call AssignFtDataOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                           
c                                       
c     Joint data                               
c                                                  
      else if ( VarNum .eq. JAN_DATA ) then             ! CompNum= jnt
        if ( CSNum .eq. JCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntAngJCS ) 
          PtrInc= 3                                     ! Axis1Num= component
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntAngJCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntAngJCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )                     
          error= .false.                                            
        else if ( CSNum .eq. EUL_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntAngEUL ) 
          PtrInc= 3                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntAngEUL,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntAngEUL,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )                  
          error= .false.                            
        end if ! which Coordinate System                
                                                          
      else if ( VarNum .eq. JVL_DATA ) then             ! CompNum= jnt
        if ( CSNum .eq. JCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntVelJCS ) 
          PtrInc= 3                                     ! Axis1Num= component
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntVelJCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntVelJCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )                     
          error= .false.                                            
        else if ( CSNum .eq. EUL_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntVelEUL ) 
          PtrInc= 3                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntVelEUL,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntVelEUL,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )                  
          error= .false.                            
        end if ! which Coordinate System                
                                                          
      else if ( VarNum .eq. JAC_DATA ) then             ! CompNum= jnt
        if ( CSNum .eq. JCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntAccJCS ) 
          PtrInc= 3                                     ! Axis1Num= component
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntAccJCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntAccJCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )                     
          error= .false.                                            
        else if ( CSNum .eq. EUL_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntAccEUL ) 
          PtrInc= 3                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntAccEUL,
     &                         StartPtr,PtrInc,NumPnts,   
     &                         FD(FileNum).Scale.JntAccEUL,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )                  
          error= .false.                                  
        end if ! which Coordinate System                
                            
      else if ( VarNum .eq. JLD_DATA ) then             ! CompNum= jnt
        if ( CSNum .eq. JCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntLoadJCS ) 
          PtrInc= 8                                     ! Axis1Num= fx-mom
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntLoadJCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntLoadJCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                            
        else if ( CSNum .eq. GCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntLoadGCS ) 
          PtrInc= 6                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntLoadGCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntLoadGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                            
        else if ( CSNum .eq. PRO_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntLoadProxLCS ) 
          PtrInc= 6                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntLoadProxLCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntLoadProxLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                            
        else if ( CSNum .eq. DIS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntLoadDistLCS ) 
          PtrInc= 6                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntLoadDistLCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.JntLoadDistLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                    
        end if ! which Coordinate System                   
                                                              
      else if ( VarNum .eq. JLL_DATA ) then    ! CompNum= rt,lf
        if ( CSNum .eq. JCS_CST ) then    ! Axis1Num= fx-mz
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntLoadLegJCS ) 
          PtrInc= 6                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntLoadLegJCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.JntLoadLegJCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010
          error= .false.                                    
        else if ( CSNum .eq. GCS_CST ) then 
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntLoadLegGCS ) 
          PtrInc= 6                                  
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntLoadLegGCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.JntLoadLegGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                                 
          error= .false.                                    
        end if ! which coordinate system
        if ( CompNum .eq. rt ) then
          do i= Start, End
            DataOK(i-Start+1)= .true.
            do jnt= rtak, rthp
              if ( .not. JntCalcOK(i,jnt,FileNum) )  DataOK(i-Start+1)= .false.
            end do
          end do   
        else
          do i= Start, End
            DataOK(i-Start+1)= .true.
            do jnt= lfak, lfhp
              if ( .not. JntCalcOK(i,jnt,FileNum) )  DataOK(i-Start+1)= .false.
            end do
          end do   
        end if

      else if ( VarNum .eq. JWR_DATA ) then    ! CompNum= jnt
        call WriteStatus( FileNum,FD(FileNum).Ptr.JntWrenchLCS ) 
        PtrInc= 8                         ! Axis1Num= component         
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntWrenchLCS,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.JntWrenchLCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                    
        call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.                                    
                                                          
      else if ( VarNum .eq. JPW_DATA ) then               ! CompNum= jnt
        call WriteStatus( FileNum,FD(FileNum).Ptr.JntPower ) ! Axis1Num= fem,
        PtrInc= 4                                            !  aam,iem,mag
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm + 
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntPower,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.JntPower,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
        error= .false.
                   
      else if ( VarNum .eq. JPL_DATA ) then               ! CompNum= rt, lf
        call WriteStatus( FileNum,FD(FileNum).Ptr.JntPowerLeg ) 
        PtrInc= 4                                      ! Axis1Num= fem,aam,iem,
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +    ! mag
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntPowerLeg,
     &                       StartPtr,PtrInc,NumPnts,
     &                       FD(FileNum).Scale.JntPowerLeg,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                  
        if ( CompNum .eq. rt ) then
          do i= Start, End
            DataOK(i-Start+1)= .true.
            do jnt= rtak, rthp
              if ( .not. JntCalcOK(i,jnt,FileNum) )  DataOK(i-Start+1)= .false.
            end do
          end do   
        else
          do i= Start, End
            DataOK(i-Start+1)= .true.
            do jnt= lfak, lfhp
              if ( .not. JntCalcOK(i,jnt,FileNum) )  DataOK(i-Start+1)= .false.
            end do
          end do   
        end if
        error= .false.                         
                   
      else if ( VarNum .eq. JIS_DATA ) then    ! CompNum= jnt
        call WriteStatus( FileNum,FD(FileNum).Ptr.ScrewInsLCS ) 
        PtrInc= 8                         ! Axis1Num= component         
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.ScrewInsLCS,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.ScrewInsLCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                    
        call SetAllDataOK( DataOK )
        error= .false.                                    
                                                          
      else if ( VarNum .eq. JFS_DATA ) then    ! CompNum= jnt
        call WriteStatus( FileNum,FD(FileNum).Ptr.ScrewFinLCS ) 
        PtrInc= 8                         ! Axis1Num= component         
        StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &            (Axis1Num-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.ScrewFinLCS,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.ScrewFinLCS,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                    
        call SetAllDataOK( DataOK )
        error= .false.                                    

      else if ( VarNum .eq. JTR_DATA ) then    ! CompNum= jnt
        if ( CSNum .eq. JCS_CST ) then         ! Axis1Num= mlt,aat,cdt,mag
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntTransJCS ) 
          PtrInc= 4                                 
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntTransJCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntLoadJCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )
          error= .false.                                            
        else if ( CSNum .eq. GCS_CST ) then       ! Axis1Num= x,y,z,mag
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntTransGCS ) 
          PtrInc= 4
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntTransGCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntTransGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )
          error= .false.                            
        else if ( CSNum .eq. PRO_CST ) then                ! Axis1Num= x,y,z,mag
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntTransProxLCS ) 
          PtrInc= 4
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntTransProxLCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntTransProxLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                                       
          call SetAllDataOK( DataOK )
          error= .false.                            
        else if ( CSNum .eq. DIS_CST ) then               ! Axis1Num= x,y,z,mag
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntTransDistLCS ) 
          PtrInc= 4
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntTransDistLCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.JntTransDistLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )
          error= .false.                                    
        end if ! which Coordinate System                   

      else if ( VarNum .eq. JSA_DATA ) then    ! CompNum= jnt
        if ( CSNum .eq. JCS_CST ) then         ! Axis1Num= fle,abd,int
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntFscAngJCS ) 
          PtrInc= 3
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntFscAngJCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntFscAngJCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )
          error= .false.                                            
        else if ( CSNum .eq. PRO_CST ) then                ! Axis1Num= x,y,z
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntFscAngProxLCS ) 
          PtrInc= 3
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntFscAngProxLCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntFscAngProxLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                                       
          call SetAllDataOK( DataOK )
          error= .false.                            
        else if ( CSNum .eq. DIS_CST ) then               ! Axis1Num= x,y,z,mag
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntFscAngDistLCS ) 
          PtrInc= 3
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntFscAngDistLCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.JntFscAngDistLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call SetAllDataOK( DataOK )
          error= .false.                                    
        end if ! which Coordinate System                   
                                                           
      else if ( VarNum .eq. JMA_DATA ) then             ! CompNum= jnt
        if ( CSNum .eq. GCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntMomArmGCS ) 
          PtrInc= 4                                     ! Axis1Num= x,y,z,mag
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntMomArmGCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntMomArmGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                            
        else if ( CSNum .eq. PRO_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntMomArmProxLCS ) 
          PtrInc= 3                                     ! Axis1Num= x,y,z
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntMomArmProxLCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntMomArmProxLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                                   
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                            
        else if ( CSNum .eq. DIS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntMomArmDistLCS ) 
          PtrInc= 3                                     ! Axis1Num= x,y,z
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntMomArmDistLCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntMomArmDistLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                                   
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.
        end if

      else if ( VarNum .eq. JWA_DATA ) then             ! CompNum= jnt
        if ( CSNum .eq. GCS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntWreArmGCS ) 
          PtrInc= 4                                     ! Axis1Num= x,y,z,mag
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntWreArmGCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntWreArmGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                           
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                            
        else if ( CSNum .eq. PRO_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntWreArmProxLCS ) 
          PtrInc= 3                                     ! Axis1Num= x,y,z
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntWreArmProxLCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntWreArmProxLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                                   
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.                                            
        else if ( CSNum .eq. DIS_CST ) then
          call WriteStatus( FileNum,FD(FileNum).Ptr.JntWreArmDistLCS ) 
          PtrInc= 3                                     ! Axis1Num= x,y,z
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.JntWreArmDistLCS,
     &                         StartPtr,PtrInc,NumPnts,  
     &                         FD(FileNum).Scale.JntWreArmDistLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                                   
          call AssignJntCalcOK( FileNum,CompNum,Start,End,DataOK )
          error= .false.
        end if
c                                                                 
c     Read reconstructed ground reaction force
c                                                           
      else if ( VarNum .eq. RFT_DATA) then    ! CompNum= rt,lf
        if ( CSNum .eq. GCS_CST ) then        ! Axis1Num= fx-mz         
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtGRLRecGCS ) 
          PtrInc= 6                         
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtGRLRecGCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.FtGRLRecGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                    
          call AssignFloorContactDataOK( FileNum,CompNum,Start,End,DataOK)
          error= .false.                                    
        else if ( CSNum .eq. LCS_CST ) then        
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtGRLRecLCS ) 
          PtrInc= 6                         
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtGRLRecLCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.FtGRLRecLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                    
          call AssignFloorContactDataOK( FileNum,CompNum,Start,End,DataOK)
          error= .false.                                  
        end if  
                                                          
      else if ( VarNum .eq. RCB_DATA ) then  ! CompNum= fx-mz
        call WriteStatus( FileNum,FD(FileNum).Ptr.CombGRLRec ) 
        PtrInc= 6                         
        StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.CombGRLRec,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.CombGRLRec,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                    
        call SetAllDataOK( DataOK )
        error= .false.                             
       
      else if ( VarNum .eq. RCF_DATA) then    ! CompNum= rt,lf
        if ( CSNum .eq. GCS_CST ) then        ! Axis1Num= x,y,z
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtCpRecGCS ) 
          PtrInc= 3
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtCpRecGCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.FtCpRecGCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                    
          call AssignFloorContactDataOK( FileNum,CompNum,Start,End,DataOK)
          error= .false.
        else if ( CSNum .eq. LCS_CST ) then        
          call WriteStatus( FileNum,FD(FileNum).Ptr.FtCpRecLCS ) 
          PtrInc= 3                           
          StartPtr= (CompNum-1)*PtrInc*MtnNumFrm +
     &              (Axis1Num-1) + (Start-1)*PtrInc + 1
          call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtCpRecLCS,
     &                         StartPtr,PtrInc,NumPnts,     
     &                         FD(FileNum).Scale.FtCpRecLCS,Data,ErrNum )
          if ( ErrNum .ne. 0 ) goto 1010                    
          call AssignFloorContactDataOK( FileNum,CompNum,Start,End,DataOK)
          error= .false.                                    
        end if  
                                                          
      else if ( VarNum .eq. RCC_DATA ) then  ! CompNum= x, y, z
        call WriteStatus( FileNum,FD(FileNum).Ptr.CombCpRec ) 
        PtrInc= 3                         
        StartPtr= (CompNum-1) + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.CombCpRec,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.CombCpRec,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                    
        call SetAllDataOK( DataOK )
        error= .false.                             
                                              
      else if ( VarNum .eq. RSI_DATA ) then  ! CompNum= rt, lf
        call WriteStatus( FileNum,FD(FileNum).Ptr.FtSiRec ) 
        PtrInc= 1                         
        StartPtr= (CompNum-1)*MtnNumFrm + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.FtSiRec,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.FtSiRec,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                    
        call AssignFloorContactDataOK( FileNum,CompNum,Start,End,DataOK)
        error= .false.                             
c
c     Read EMG data if present
c                              
      else if ( VarNum .eq. EMG_DATA ) then  ! CompNum= channel#
        call WriteStatus( FileNum,FD(FileNum).Ptr.EmgData ) 
        PtrInc= 1                         
        StartPtr= (CompNum-1)*EmgNumFrm + (Start-1)*PtrInc + 1
        call ReadAnzDataSet( FD(FileNum).LU,FD(FileNum).Ptr.EmgData,
     &                       StartPtr,PtrInc,NumPnts,     
     &                       FD(FileNum).Scale.EmgData,Data,ErrNum )
        if ( ErrNum .ne. 0 ) goto 1010                    
        call SetAllDataOK( DataOK )
        error= .false.                             

      end if
      return                            

1010  write(6,1015) ErrNum,FD(FileNum).Name
1015  format(' Error- Error #',i4,' occured while reading from ',a40)
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine ReadAnzDataSet( LUN,RecNum1,StartPtr,PtrInc,NumPnts,
     &                           Scale,Data,ErrNum )
      implicit none

      integer*4 StartPtr,PtrInc,NumPnts,ErrNum,Scale,LUN,RecNum1
      real*4    Data(1)   
            
      integer*4 i,RecNum,Ptr,buffer(128)
                              
      ErrNum= 0
      i= 1
      RecNum= RecNum1
      Ptr= StartPtr
      read(LUN,rec=RecNum,err=999,iostat=ErrNum) buffer
      do while ( Ptr .gt. 128 ) ! get to the right section of data
        Ptr= Ptr - 128
        RecNum= RecNum + 1
        read(LUN,rec=RecNum,err=999,iostat=ErrNum) buffer
      end do
      do while ( i .le. NumPnts )
        if ( Ptr .gt. 128 ) then
          Ptr= Ptr - 128
          RecNum= RecNum + 1
          read(LUN,rec=RecNum,err=999,iostat=ErrNum) buffer
        end if
        Data(i)= float(buffer(Ptr))/10.0**Scale
        i= i + 1
        Ptr= Ptr + PtrInc  
      end do
999   return
      end
c        
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine SetAllDataOK ( DataOK )
      implicit none
 
      include 'tel_cons.inc'
                                     
      logical*4 DataOK(1)
      integer*4 i

      do i= 1, MAX_PLOT_SIZE
        DataOK(i)= .true.
      end do
      return
      end
c                        
c   Copyright (c) 1990 by Dwight Meglan                        
c
      subroutine AssignFtDataOK( FileNum,ft,Start,End,DataOK )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'

      integer*4 FileNum,ft,Start,End,i
      logical*4 DataOK(1)

      do i= Start, End
        DataOK(i-Start+1)= FtDataOK(i,ft,FileNum)
      end do
      return
      end
c                        
c   Copyright (c) 1990 by Dwight Meglan                        
c
      subroutine AssignFpDataOK( FileNum,plt,Start,End,DataOK )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'

      integer*4 FileNum,plt,Start,End,i
      logical*4 DataOK(1)
                                      
      do i= Start, End
        DataOK(i-Start+1)= FpDataOK(i,plt,FileNum)
      end do
      return
      end                 
c                        
c   Copyright (c) 1990 by Dwight Meglan                        
c
      subroutine AssignFcDataOK( FileNum,Start,End,DataOK )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'

      integer*4 FileNum,Start,End,i
      logical*4 DataOK(1)

      do i= Start, End
        DataOK(i-Start+1)= FcDataOK(i,FileNum)
      end do
      return
      end
c                        
c   Copyright (c) 1990 by Dwight Meglan                        
c
      subroutine AssignFloorContactDataOK( FileNum,ft,Start,End,DataOK )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'

      integer*4 FileNum,ft,Start,End,i
      logical*4 DataOK(1)

      do i= Start, End
        DataOK(i-Start+1)= FloorContact(i,ft,FileNum)
      end do
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan                       
c                         
      subroutine AssignJntCalcOK( FileNum,jnt,Start,End,DataOK )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'          

      integer*4 FileNum,jnt,Start,End,i
      logical*4 DataOK(1)

      do i= Start, End
        DataOK(i-Start+1)= JntCalcOK(i,jnt,FileNum)
      end do
      return
      end
c         
c   Copyright (c) 1990 by Dwight Meglan                           
c
      subroutine WriteStatus( FileNum,Address )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 'tel_file.inc'  
      include 'tel_name.inc'
                    
      integer*4 Address,i,FileNum
      character Blank20*20

      data Blank20 / '                    ' /      

      i= 1
      do while ( (FD(FileNum).Ptr.array(i) .ne. Address) .and. 
     &           (i .le. FD(FileNum).TotalNumVar) )
        i= i + 1
      end do
      if ( i .le. FD(FileNum).TotalNumVar ) then
*$ifdef DEBUG
        write(3,110) AnzVarName(i),i,FD(FileNum).TotalNumVar,Address
        write(6,110) AnzVarName(i),i,FD(FileNum).TotalNumVar,Address
 110    format(' Reading data item : ',a20,3x,i3,'/',i3,'  Address: ',i4)
*$else
        write(6,100) Blank20
        write(6,100) AnzVarName(i)
100     format('+ Reading data item :'a20)
*$endif
      end if            
      return
      end                           
c                                                
c   Copyright (c) 1990 by Dwight Meglan
c        
      subroutine GenItoR( GEN_PRM_ANZ, scale_factor, GEN_PRM )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 't_a_file.inc'

      record /general_param/     GEN_PRM
      record /general_param_INT/ GEN_PRM_ANZ
      integer*4 scale_factor

      integer*4 i,j   

      GEN_PRM.motion_file=  GEN_PRM_ANZ.motion_file
      GEN_PRM.average_file= GEN_PRM_ANZ.average_file
      GEN_PRM.force_file=   GEN_PRM_ANZ.force_file
      GEN_PRM.last_updated= GEN_PRM_ANZ.last_updated
      GEN_PRM.name=         GEN_PRM_ANZ.name
      GEN_PRM.comment=      GEN_PRM_ANZ.comment
      GEN_PRM.age=          GEN_PRM_ANZ.age
      GEN_PRM.weight=       GEN_PRM_ANZ.weight/(10.0**scale_factor)
      GEN_PRM.height=       GEN_PRM_ANZ.height/(10.0**scale_factor)
      GEN_PRM.num_seg=      GEN_PRM_ANZ.num_seg
      do i= 1, GEN_PRM.num_seg
        GEN_PRM.seg_num(i)= GEN_PRM_ANZ.seg_num(i)
      end do
      GEN_PRM.num_jnt=      GEN_PRM_ANZ.num_jnt
      do i= 1, GEN_PRM.num_jnt
        GEN_PRM.jnt_num(i)= GEN_PRM_ANZ.jnt_num(i)
      end do
      GEN_PRM.single_cycle=   GEN_PRM_ANZ.single_cycle
      GEN_PRM.normalized=     GEN_PRM_ANZ.normalized
      GEN_PRM.seg_unrotated=  GEN_PRM_ANZ.seg_unrotated
      GEN_PRM.seg_smooth=     GEN_PRM_ANZ.seg_smooth
      GEN_PRM.int_poly_order= GEN_PRM_ANZ.int_poly_order
      GEN_PRM.analysis_type=  GEN_PRM_ANZ.analysis_type
      GEN_PRM.BYteOrderCheck= GEN_PRM_ANZ.ByteOrderCheck
      GEN_PRM.Sex=            GEN_PRM_ANZ.Sex
      GEN_PRM.FileFormatVersion=  GEN_PRM_ANZ.FileFormatVersion

*$ifdef DEBUG
      write(3,100) GEN_PRM.motion_file,GEN_PRM.average_file,
     &             GEN_PRM.force_file,GEN_PRM.last_updated,
     &             GEN_PRM.name,GEN_PRM.comment,GEN_PRM.age,
     &             GEN_PRM.weight,GEN_PRM.height,GEN_PRM.num_seg
      write(6,100) GEN_PRM.motion_file,GEN_PRM.average_file,
     &             GEN_PRM.force_file,GEN_PRM.last_updated,
     &             GEN_PRM.name,GEN_PRM.comment,GEN_PRM.age,
     &             GEN_PRM.weight,GEN_PRM.height,GEN_PRM.num_seg
 100  format(/' General Parameters'/
     &        ' Motion file : ',a40/
     &        ' Average file: ',a40/
     &        ' Force file  : ',a40/
     &        ' Last Update : ',a9/
     &        ' Name        : ',a40/
     &        ' Comment     : ',a40/
     &        ' Age         : ',i2/
     &        ' Weight      : ',f8.4/
     &        ' Height      : ',f8.4/
     &       /' Num of Segs : ',i2/
     &        ' Segs:',$)
      do i= 1, GEN_PRM.num_seg
         write(3,110) GEN_PRM.seg_num(i)
         write(6,110) GEN_PRM.seg_num(i)
 110     format(1x,i2,$)
      end do

      write(3,120) GEN_PRM.num_jnt
      write(6,120) GEN_PRM.num_jnt
 120  format(/' Num of Jnts : ',i2/
     &        ' Jnts: ',$)
      do i= 1, GEN_PRM.num_jnt
         write(3,110) GEN_PRM.jnt_num(i)
         write(6,110) GEN_PRM.jnt_num(i)
      end do
      
      write(3,130) GEN_PRM.single_cycle,GEN_PRM.normalized,
     &             GEN_PRM.seg_unrotated,GEN_PRM.seg_smooth,
     &             GEN_PRM.int_poly_order,GEN_PRM.analysis_type,
     &             GEN_PRM.BYteOrderCheck,GEN_PRM.Sex,
     &             GEN_PRM.FileFormatVersion
      write(6,130) GEN_PRM.single_cycle,GEN_PRM.normalized,
     &             GEN_PRM.seg_unrotated,GEN_PRM.seg_smooth,
     &             GEN_PRM.int_poly_order,GEN_PRM.analysis_type,
     &             GEN_PRM.BYteOrderCheck,GEN_PRM.Sex,
     &             GEN_PRM.FileFormatVersion
 130  format(/' Single Cycle: ',l2/
     &        ' Normalized  : ',l2/ 
     &        ' Unrotated   : ',l2/ 
     &        ' Seg Smoothed: ',l2/ 
     &        ' Int Poly Ord: ',i2/ 
     &        ' Analysis Typ: ',i2/ 
     &        ' ByteOrderChk: ',i2/ 
     &        ' Sex         : ',a1/ 
     &        ' Format Vers : ',a1//)
*$endif      
      return
      end
c
c   Copyright (c) 1990 by Dwight Meglan                 
c
      subroutine FrcItoR( FRC_PRM_ANZ, scale_factor, FRC_PRM )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 't_a_file.inc'

      record /force_param/     FRC_PRM
      record /force_param_INT/ FRC_PRM_ANZ
      integer*4 scale_factor

      integer*4 i,j,k

      FRC_PRM.num_frm=      FRC_PRM_ANZ.num_frm
      FRC_PRM.frm_rate=     FRC_PRM_ANZ.frm_rate
      FRC_PRM.av_frm_ratio= (FRC_PRM_ANZ.av_frm_ratio)/(10.0**scale_factor)
      FRC_PRM.frm_offset=   FRC_PRM_ANZ.frm_offset
      FRC_PRM.first_frm=    FRC_PRM_ANZ.first_frm
      FRC_PRM.last_frm=     FRC_PRM_ANZ.last_frm
      FRC_PRM.num_plt=      FRC_PRM_ANZ.num_plt
      do i= 1, 2
        do j= 1, 4
          FRC_PRM.plt_size(i,j)= FRC_PRM_ANZ.plt_size(i,j)/(10.0**scale_factor)
        end do
      end do
      do i= 1, 4
        do j= 1, 3
          do k= 1, 4
            FRC_PRM.plt_loc(i).LCS(j,k)= 
     &                    FRC_PRM_ANZ.plt_loc(i).LCS(j,k)/(10.0**scale_factor)
          end do
        end do
      end do
      FRC_PRM.num_rtft_plt= FRC_PRM_ANZ.num_rtft_plt
      FRC_PRM.num_lfft_plt= FRC_PRM_ANZ.num_lfft_plt
      do i= 1, 4
        FRC_PRM.rtft_plt(i)= FRC_PRM_ANZ.rtft_plt(i)
        FRC_PRM.lfft_plt(i)= FRC_PRM_ANZ.lfft_plt(i)
      end do
      FRC_PRM.dbl_stance_OK= FRC_PRM_ANZ.dbl_stance_OK
      FRC_PRM.FirstFoot=     FRC_PRM_ANZ.FirstFoot
      FRC_PRM.Direction=     FRC_PRM_ANZ.Direction
      return
      end   
c                                                                             
c   Copyright (c) 1990 by Dwight Meglan           
c        
      subroutine SegItoR( SEG_PRM_ANZ, scale_factor, SEG_PRM, rbody )
      implicit none

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 't_a_file.inc'

      record /seg_param/     SEG_PRM
      record /seg_param_INT/ SEG_PRM_ANZ
      integer*4 scale_factor
      logical*4 rbody
                   
      integer*4 i,j
      real*4    scale

 
*$ifdef DEBUG
      
      write(3,100) scale_factor,SEG_PRM_ANZ.length
      write(6,100) scale_factor,SEG_PRM_ANZ.length
 100  format(' Scale : 10^',i2/' Length: ',i12)

      write(3,110) SEG_PRM_ANZ.mass,SEG_PRM_ANZ.avg_cntr(1),
     &             SEG_PRM_ANZ.avg_cntr(2),
     &             SEG_PRM_ANZ.avg_cntr(3),SEG_PRM_ANZ.num_end
      write(6,110) SEG_PRM_ANZ.mass,SEG_PRM_ANZ.avg_cntr(1),
     &             SEG_PRM_ANZ.avg_cntr(2),
     &             SEG_PRM_ANZ.avg_cntr(3),SEG_PRM_ANZ.num_end
 110  format(' Mass  : ',i12/' Center: ',3(i12,1x)/,' # Ends: ',i12)

      write(3,120) SEG_PRM_ANZ.inertia(1),SEG_PRM_ANZ.inertia(2),
     &             SEG_PRM_ANZ.inertia(3)
      write(6,120) SEG_PRM_ANZ.inertia(1),SEG_PRM_ANZ.inertia(2),
     &             SEG_PRM_ANZ.inertia(3)
 120  format(' Inertia: ',3(i12,1x))

      write(3,130)
      write(6,130)
 130  format(' Shape:')
      do j= 1, 8
         write(3,140) SEG_PRM_ANZ.shape(1,j),SEG_PRM_ANZ.shape(2,j),
     &                SEG_PRM_ANZ.shape(3,j)
         write(6,140) SEG_PRM_ANZ.shape(1,j),SEG_PRM_ANZ.shape(2,j),
     &                SEG_PRM_ANZ.shape(3,j)
 140     format(3(i12,1x))
      end do

      write(3,150)
      write(6,150)
 150  format(' Ends:')
      do j= 1, 4
         write(3,140) SEG_PRM_ANZ.end(1,j),SEG_PRM_ANZ.end(2,j),
     &                SEG_PRM_ANZ.end(3,j)
         write(6,140) SEG_PRM_ANZ.end(1,j),SEG_PRM_ANZ.end(2,j),
     &                SEG_PRM_ANZ.end(3,j)
      end do    

      write(3,160) SEG_PRM_ANZ.num_mrk
      write(6,160) SEG_PRM_ANZ.num_mrk
 160  format(' # Mrk : ',i12)

      do i= 1, 5
         write(3,170) SEG_PRM_ANZ.mrk_num(i)
         write(6,170) SEG_PRM_ANZ.mrk_num(i)
 170     format(1x,i12)
      end do                                                               

      write(3,180) SEG_PRM_ANZ.num_mrk_dist
      write(6,180) SEG_PRM_ANZ.num_mrk_dist
 180  format(' # MrkD: ',i12)
 
      do i= 1, 5
         write(3,190) SEG_PRM_ANZ.dist_mrk_num(1,i),
     &                SEG_PRM_ANZ.dist_mrk_num(2,i)
         write(6,190) SEG_PRM_ANZ.dist_mrk_num(1,i),
     &                SEG_PRM_ANZ.dist_mrk_num(2,i)
 190     format(1x,i12,1x,i12)
      end do                                                               

      if ( rbody ) then

         write(3,200)
         write(6,200)
 200     format(' Rigid Body parameters'/' TCStoLCS'/)
         do i= 1, 4
            write(3,140) SEG_PRM_ANZ.TCStoLCS(1,i),
     &                   SEG_PRM_ANZ.TCStoLCS(2,i),       
     &                   SEG_PRM_ANZ.TCStoLCS(3,i)
         end do

         write(3,210) SEG_PRM_ANZ.nmTCS
         write(6,210) SEG_PRM_ANZ.nmTCS
 210     format('# Mrk : ',i12)
         SEG_PRM.nmTCS= SEG_PRM_ANZ.nmTCS
         do i= 1, 5
            write(3,220) SEG_PRM_ANZ.mnTCS(i),
     &                   SEG_PRM_ANZ.mpnLCS(1,i),
     &                   SEG_PRM_ANZ.mpnLCS(2,i),
     &                   SEG_PRM_ANZ.mpnLCS(3,i)
 220        format(1x,i12,3(i12,1x))
         end do
      end if
*$endif


      scale= 10.0**scale_factor
      SEG_PRM.length= float(SEG_PRM_ANZ.length)/scale
      do i= 1, 3
        SEG_PRM.avg_cntr(i)= float(SEG_PRM_ANZ.avg_cntr(i))/scale
      end do
      SEG_PRM.mass=   float(SEG_PRM_ANZ.mass)/scale
      SEG_PRM.num_end= SEG_PRM_ANZ.num_end
      do i= 1, 3 
        SEG_PRM.inertia(i)= float(SEG_PRM_ANZ.inertia(i))/scale
        do j= 1, 8
          SEG_PRM.shape(i,j)= float(SEG_PRM_ANZ.shape(i,j))/scale
        end do
        do j= 1, SEG_PRM.num_end
          SEG_PRM.end(i,j)= float(SEG_PRM_ANZ.end(i,j))/scale
        end do    
      end do
      SEG_PRM.num_mrk= SEG_PRM_ANZ.num_mrk
      if ( SEG_PRM.num_mrk .gt. 5 ) SEG_PRM.num_mrk= 0
      do i= 1, SEG_PRM.num_mrk
        SEG_PRM.mrk_num(i)= SEG_PRM_ANZ.mrk_num(i)
      end do                                                               
      SEG_PRM.num_mrk_dist= SEG_PRM_ANZ.num_mrk_dist
      if ( SEG_PRM.num_mrk_dist .gt. 10 ) SEG_PRM.num_mrk_dist= 0
      do i= 1, SEG_PRM.num_mrk_dist
        do j= 1,2
          SEG_PRM.dist_mrk_num(j,i)= SEG_PRM_ANZ.dist_mrk_num(j,i)
        end do
      end do
      if ( rbody ) then
        do i= 1, 4
          do j= 1, 3
            SEG_PRM.TCStoLCS(j,i)= SEG_PRM_ANZ.TCStoLCS(j,i)/scale
          end do
        end do
        SEG_PRM.nmTCS= SEG_PRM_ANZ.nmTCS
        do i= 1, 5
          do j= 1, 3
            SEG_PRM.mpnLCS(j,i)= SEG_PRM_ANZ.mpnLCS(j,i)/scale
          end do
          SEG_PRM.mnTCS(i)= SEG_PRM_ANZ.mnTCS(i)
        end do
      end if
      return
      end            
c                 
c   Copyright (c) 1990 by Dwight Meglan
c                                                                   
      subroutine CycleItoR( CYC_INFO_ANZ, scale_factor, CYC_INFO )
      implicit none 

      include 'tel_cons.inc'
      include 'tel_strc.inc'
      include 't_a_file.inc'

      record /cycle/     CYC_INFO
      record /cycle_INT/ CYC_INFO_ANZ
      integer*4 scale_factor,event(MAX_MTN_FRM)

      real*4    Scale
      integer*4 i

      Scale= 10.0**scale_factor
      CYC_INFO.first_side=          CYC_INFO_ANZ.first_side
      CYC_INFO.stride_length=       CYC_INFO_ANZ.stride_length/Scale
      CYC_INFO.NormStrideLength=    CYC_INFO_ANZ.NormStrideLength/Scale
      CYC_INFO.PctNormStrideLength= CYC_INFO_ANZ.PctNormStrideLength/Scale
      CYC_INFO.step_width=          CYC_INFO_ANZ.step_width/Scale
      CYC_INFO.NormStepWidth=       CYC_INFO_ANZ.NormStepWidth/Scale
      CYC_INFO.PctNormStepWidth=    CYC_INFO_ANZ.PctNormStepWidth/Scale
      CYC_INFO.cycle_time=          CYC_INFO_ANZ.cycle_time/Scale
      CYC_INFO.NormCycleTime=       CYC_INFO_ANZ.NormCycleTime/Scale
      CYC_INFO.PctNormCycleTime=    CYC_INFO_ANZ.PctNormCycleTime/Scale
      CYC_INFO.cadence=             CYC_INFO_ANZ.cadence/Scale
      CYC_INFO.NormCadence=         CYC_INFO_ANZ.NormCadence/Scale
      CYC_INFO.PctNormCadence=      CYC_INFO_ANZ.PctNormCadence/Scale
      CYC_INFO.velocity=            CYC_INFO_ANZ.velocity/Scale
      CYC_INFO.NormVelocity=        CYC_INFO_ANZ.NormVelocity/Scale
      CYC_INFO.PctNormVelocity=     CYC_INFO_ANZ.PctNormVelocity/Scale
      do i= 1, 2      
        CYC_INFO.step_length(i)=        CYC_INFO_ANZ.step_length(i)/Scale
        CYC_INFO.NormStepLength(i)=     CYC_INFO_ANZ.NormStepLength(i)/Scale
        CYC_INFO.PctNormStepLength(i)=  CYC_INFO_ANZ.PctNormStepLength(i)/Scale
        CYC_INFO.sgl_time(i)=           CYC_INFO_ANZ.sgl_time(i)/Scale
        CYC_INFO.sgl_percent(i)=        CYC_INFO_ANZ.sgl_percent(i)/Scale
        CYC_INFO.NormSglPct(i)=         CYC_INFO_ANZ.NormSglPct(i)/Scale
        CYC_INFO.dbl_time(i)=           CYC_INFO_ANZ.dbl_time(i)/Scale
        CYC_INFO.dbl_percent(i)=        CYC_INFO_ANZ.dbl_percent(i)/Scale
        CYC_INFO.NormDblPct(i)=         CYC_INFO_ANZ.NormDblPct(i)/Scale
        CYC_INFO.total_time(i)=         CYC_INFO_ANZ.total_time(i)/Scale
        CYC_INFO.total_percent(i)=      CYC_INFO_ANZ.total_percent(i)/Scale
        CYC_INFO.NormTotalPct(i)=       CYC_INFO_ANZ.NormTotalPct(i)/Scale
        CYC_INFO.to_percent(i)=         CYC_INFO_ANZ.to_percent(i)/Scale
        CYC_INFO.NormToPct(i)=          CYC_INFO_ANZ.NormToPct(i)/Scale
      end do                                                  
      do i= 1, 3                                                        
        CYC_INFO.hs_percent(i)= CYC_INFO_ANZ.hs_percent(i)/Scale
        CYC_INFO.NormHsPct(i)=  CYC_INFO_ANZ.NormHsPct(i)/Scale
      end do
      return          
      end                        
                 
c                            
c   Copyright (c) 1990 by Dwight Meglan
c                               
      subroutine Read1DimArray( LUN,rec_num,data,dim1,size1,scale_factor,ErrNum )
c                           
c     This subroutine will read a two dimensional real array from an ANZ
c     file 
c
      implicit none
                         
      integer*4 rec_num,dim1,size1,scale_factor,ErrNum,LUN
      real*4    data(dim1)
      
      integer*4 i,j,pntr,buffer(128)

      ErrNum= 0
      read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer
      pntr= 1
      do i= 1, size1    
        data(i)= buffer(pntr)/(10.0**scale_factor)
        pntr= pntr+1
        if ( pntr .gt. 128 ) then
          if ( i .ge. size1 ) return
          rec_num= rec_num+1
          read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer
          pntr= 1
        end if
      end do ! i
999   return  
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine Read2dimArray( LUN,rec_num,data,dim1,dim2,size1,size2,
     &                          scale_factor,ErrNum )
c 
c     This subroutine will read a two dimensional real array from an ANZ
c     file 
c
      implicit none

      integer*4 rec_num,dim1,dim2,size1,size2,scale_factor,ErrNum,LUN
      real*4    data(dim1,dim2)

      integer*4 i,j,pntr,buffer(128),NumElements

      ErrNum= 0
      NumElements= size1*size2
      read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer
      pntr= 1
      do i= 1, size2    
        do j= 1, size1       
          data(j,i)= buffer(pntr)/(10.0**scale_factor)
          pntr= pntr+1
          if ( pntr .gt. 128 ) then
            if ( i*j .ge. NumElements ) return
            rec_num= rec_num+1
            read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer
            pntr= 1
          end if
        end do ! j
      end do ! i        
999   return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine Read3dimArray( LUN,rec_num,data,dim1,dim2,dim3,
     &                          size1,size2,size3,scale_factor,ErrNum )
c 
c     This subroutine will read a three dimensional real array from an ANZ
c     file.
c             
      implicit none

      integer*4 rec_num,dim1,dim2,dim3,size1,size2,size3,scale_factor,ErrNum,
     &          LUN
      real*4    data(dim1,dim2,dim3)

      integer*4 i,j,k,pntr,buffer(128),NumElements

      ErrNum= 0
      NumElements= size1*size2*size3
      read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer
      pntr= 1
      do i= 1, size3    
        do j= 1, size2       
          do k= 1, size1
            data(k,j,i)= buffer(pntr)/(10.0**scale_factor)
            pntr= pntr+1
            if ( pntr .gt. 128 ) then
              if ( i*j*k .ge. NumElements ) return
              rec_num= rec_num+1
              read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer
              pntr= 1
            end if                   
          end do ! k
        end do ! j
      end do ! i
999   return
      end
c
c   Copyright (c) 1990 by Dwight Meglan
c
      subroutine Read4dimArray( LUN,rec_num,data,dim1,dim2,dim3,dim4,
     &                          size1,size2,size3,size4,scale_factor,ErrNum )
c 
c     This subroutine will read a four dimensional real array from an ANZ
c     file 
c
      implicit none

      integer*4 rec_num,size1,size2,size3,size4,ErrNum,dim1,dim2,dim3,dim4,
     &          scale_factor,LUN
      real*4    data(dim1,dim2,dim3,dim4)

      integer*4 i,j,k,l,pntr,buffer(128),NumElements

      ErrNum= 0
      NumElements= size1*size2*size3*size4
      read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer 
      pntr= 1
      do i= 1, size4    
        do j= 1, size3       
          do k= 1, size2
            do l= 1, size1
              data(l,k,j,i)= buffer(pntr)/(10.0**scale_factor)
              pntr= pntr+1
              if ( pntr .gt. 128 ) then
                if ( i*j*k*l .ge. NumElements ) return
                rec_num= rec_num+1
                read(LUN,rec=rec_num,err=999,iostat=ErrNum) buffer
                pntr= 1
              end if
            end do ! l  
          end do ! k
        end do ! j
      end do ! i
999   return
      end
c
c
c
      subroutine SetUpFullBodyNames
      implicit none

      include 'tel_cons.inc'
      include 'tel_name.inc'

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

      JntNames(1)=  'RTAK'
      JntNames(2)=  'RTKN'
      JntNames(3)=  'RTHP'
      JntNames(4)=  'LFAK'
      JntNames(5)=  'LFKN'
      JntNames(6)=  'LFHP'
      JntNames(7)=  'PVLB'
      JntNames(8)=  'PVTK'
      JntNames(9)=  'RTEL'
      JntNames(10)= 'RTSH'
      JntNames(11)= 'LFEL'
      JntNames(12)= 'LFSH'
      JntNames(13)= 'NECK'
      JntNames(14)= 'RTWR'
      JntNames(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

      return
      end
