c
c
c
c
c     Copyright by Dwight Meglan 1990
c
c     Purpose: Display the state of the various quantities that can read in and 
c              computed by ANZ.
c
c
      subroutine DisplayStatus( CMND,MF,SF,FF,JF,AF,CF,EF,OF )
      implicit none     
                                                            
      include 'a_const.inc'
      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_names.inc'
      include 'a_gls2.inc'
      include 'a_frc.inc'

      record /CmndLine/       CMND
      record /marker_flag/    MF
      record /segment_flag/   SF
      record /force_flag/     FF      
      record /joint_flag/     JF
      record /avg_pos_flag/   AF                                   
      record /cycle_flag/     CF
      record /emg_flag/       EF
      record /option_flag/    OF

      integer*4 i,j,seg,AnalysisType
      character EMGType*7,LoadName(6)*2,hold*1,YesNo*3

      data LoadName /'fx','fy','fz','mx','my','mz'/
                                       
      if ( CMND.NumCmnd .lt. 2 ) goto 1000 ! error
      if ( (CMND.CmndText(2) .eq. 'GEN') .or.             
     &     (CMND.CmndText(2) .eq. 'PAT') .or.
     &     (CMND.CmndText(2) .eq. 'SUB')      ) then
        if ( (GP.Analysis_Type .lt. 1) .or.
     &       (GP.Analysis_Type .ge. MAX_ANL)      ) then
          AnalysisType= MAX_ANL
        else
          AnalysisType= GP.Analysis_Type
        end if
        write(6,100) GP.MtnFile,GP.AvgFile,
     &               GP.FrcFile,GP.last_updated,
     &               GP.FileFormatVersion,GP.name,GP.comment,
     &               GP.age,GP.Sex,GP.weight,
     &               GP.weight*2.22,GP.height,GP.height/.0254,
     &               ANLNames(AnalysisType)
        if ( OF.ToLog ) write(3,100) GP.MtnFile,
     &                          GP.AvgFile,GP.FrcFile,
     &                          GP.last_updated,GP.FileFormatVersion,
     &					       	GP.name,
     &                          GP.comment,GP.age,GP.Sex,
     &                          GP.weight,GP.weight*2.22,
     &                          GP.height,GP.height/.0254,
     &                          ANLNames(AnalysisType)
100     format(/' General Information'//
     &          ' Motion file  : ',a40/         
     &          ' Average file : ',a40/
     &          ' Force file   : ',a40/
     &          ' Analysis lasted updated : ',a9/
     &          ' ANZ file format version : ',a1//
     &          ' Patient name   : ',a40/
     &          ' Comment        : ',a80/
     &          ' Patient Age    : ',i2/
     &          ' Patient Sex    : ',a1/
     &          ' Patient weight : ',f7.3,' kg   ',f7.3,' lbs'/
     &          ' Patient height : ',f7.3,' m    ',f7.3,' in'//
     &          ' Analysis Type  : ',a20/   )
                                       
      else if ( CMND.CmndText(2) .eq. 'MRK' ) then
        write(6,110) MP.num_mrk,YesNo(MF.interpolated),
     &               YesNo(MF.adjusted),YesNo(MF.smoothed),
     &               YesNo(MF.VelAcc),
     &               YesNo(MF.diagnostics),GP.int_poly_order,
     &               MP.nfrm,rMtnFrmRate,MP.first_frm
        if ( OF.ToLog ) write(3,110) MP.num_mrk,
     &                          YesNo(MF.interpolated),
     &                          YesNo(MF.adjusted),YesNo(MF.smoothed),
     &                          YesNo(MF.VelAcc),
     &                          YesNo(MF.diagnostics),
     &                          GP.int_poly_order,MP.nfrm,
     &                          rMtnFrmRate,MP.first_frm
110     format(/' Marker Information'//
     &          ' Number of markers    : ',i2/
     &          ' Markers interpolated : ',a3/
     &          ' Markers adjusted     : ',a3/
     &          ' Markers smoothed     : ',a3/
     &          ' Markers Vel/Accel    : ',a3/
     &          ' Marker diagnostics   : ',a3/
     &          ' Order of interpolating polynomial : ',i2/ 
     &          ' Number of frames     : ',i3/
     &          ' Frames per second    : ',f8.4/
     &          ' First frame number   : ',i4//)

        write(6,115) (MP.mrk_name(i),i=1, MP.num_mrk)
        if ( OF.ToLog) write(3,115) (MP.mrk_name(i),i=1, MP.num_mrk)
115     format(' Marker Names: ',8(a4,1x),3(/15x,8(a4,1x)) )

        if ( MF.NumProcOps .gt. 0 ) then
          write(6,116) MF.ProcOp(1)(1:30) 
          if ( OF.ToLog ) write(3,116) MF.ProcOp(1)(1:30)
116       format(/' Marker smoothing/filtering operations: 'a30)
          do i= 2, MF.NumProcOps
            write(6,117) MF.ProcOp(i)(1:30)
            if ( OF.ToLog ) write(3,117) MF.ProcOp(i)(1:30)
117         format(40x,a30)
          end do
        end if

      else if ( CMND.CmndText(2) .eq. 'SEG' ) then
        call DisplaySegment( CMND,SF,OF )
                 
      else if ( CMND.CmndText(2) .eq. 'FRC' ) then
        if ( (CMND.NumCmnd .eq. 3) .and. (CMND.CmndText(3) .eq. 'AVG') ) then
          write(6,138)
          if ( OF.ToLog ) write(3,138)
138       format(' Average force plate load values'//
     &           ' Plt#   Load     Mean     Std Dev    Zero')  
          do i= 1, FP.num_plt
            do j= 1, 6
              write(6,139) i,LoadName(j),FpAvg(j,i),FpSD(j,i),FpZero(j,i)
              if ( OF.ToLog ) 
     &          write(3,139) i,LoadName(j),FpAvg(j,i),FpSD(j,i),FpZero(j,i)
139           format(2x,i1,6x,a2,2x,3f10.4)
            end do
          end do                                   
        else
          write(6,140) YesNo(FF.read),YesNo(FF.adjusted),
     &                 YesNo(FF.filtered),FF.FiltOp,
     &                 YesNo(FF.aligned),YesNo(FF.DataClipped),
     &                 YesNo(FF.individual_feet),
     &                 YesNo(FF.cpr_GCS),YesNo(FF.cpr_LCS),
     &                 YesNo(FF.StrIdx),YesNo(FF.wrench),
     &                 YesNo(FF.Integral),YesNo(FF.reconstructed),
     &                 YesNo(FF.PitchMomArm),YesNo(FF.PitchWreArm),
     &                 YesNo(FF.CprVelGCS) ! ,
c     &                 FRC_COND.HS_tol_percent,FRC_COND.trig_percent,
c     &                 FRC_COND.num_idle_frm,FRC_COND.idle_percent
          if ( OF.ToLog ) 
     &      write(3,140) YesNo(FF.read),YesNo(FF.adjusted),
     &                   YesNo(FF.filtered),FF.FiltOp,
     &                   YesNo(FF.aligned),YesNo(FF.DataClipped),
     &                   YesNo(FF.individual_feet),
     &                   YesNo(FF.cpr_GCS),YesNo(FF.cpr_LCS),
     &                   YesNo(FF.StrIdx),YesNo(FF.wrench),
     &                   YesNo(FF.Integral),YesNo(FF.reconstructed),
     &                   YesNo(FF.PitchMomArm),YesNo(FF.PitchWreArm),
     &                   YesNo(FF.CprVelGCS) ! ,
c     &                   FRC_COND.HS_tol_percent,FRC_COND.trig_percent,
c     &                   FRC_COND.num_idle_frm,FRC_COND.idle_percent
140       format(' Force Plate Information'//
     &           ' Force data read          : ',a3/
     &           ' Forces adjusted          : ',a3/
     &           ' Force plate data filtered: ',a3/
     &           ' Filter command           : ',a40/
     &           ' Force aligned w/ motion  : ',a3/
     &           ' Force/Motion data clipped: ',a3/
     &           ' Force split between feet : ',a3/
     &           ' Center of pressure (GCS) : ',a3/
     &           ' Center of pressure (LCS) : ',a3/
     &           ' Strike Index             : ',a3/
     &           ' Force wrench             : ',a3/
     &           ' GRL Integrals            : ',a3/
     &           ' GRL reconstructed        : ',a3/
     &           ' Pitch moment arm         : ',a3/
     &           ' Wrench moment arm        : ',a3/
     &           ' GRL CPR Velocity         : ',a3// )
c     &           ' HeelStrike tolerance (%) : ',f6.3/
c     &           ' Foot strike trigger (%)  : ',f6.3/
c     &           ' Idle region size (frames): ',i4/
c     &           ' Idle region variation (%): ',f6.3  )
          if ( FF.read ) then
            write(6,148)
148         format(//' Press return to continue...')
            read(5,149) hold
149         format(a1)            
            write(6,150) FP.nfrm,FP.frm_rate,FP.av_frm_ratio,
     &                   FP.frm_offset,FP.num_plt ! ,FP.FirstFoot,
c     &                   FP.Direction
          if ( OF.ToLog ) 
     &        write(3,150) FP.nfrm,FP.frm_rate,FP.av_frm_ratio,
     &                     FP.frm_offset,FP.num_plt ! ,FP.FirstFoot,
c     &                     FP.Direction
150         format(//' Number of samples        : ',i4/
     &             ' Samples per second       : ',i4/
     &             ' Analog/video frame ratio : ',f8.5/
     &             ' Analog/video offset      : ',i4/
     &             ' Number of force plates   : ',i2// )
c     &             ' First foot (GLS)         : ',i4/
c     &             ' Direction  (GLS)         : ',i4)
          end if
        end if ! avg or regular
        
      else if ( CMND.CmndText(2) .eq. 'JNT' ) then
        write(6,160) YesNo(JF.angle_JCS),YesNo(JF.vel_acc_JCS),
     &               YesNo(JF.angle_EUL),YesNo(JF.vel_acc_EUL),
     &               YesNo(JF.load),YesNo(JF.legsummed),
     &               YesNo(JF.wrench),YesNo(JF.power),
     &               YesNo(JF.FiniteScrew),YesNo(JF.InstantScrew),
     &               YesNo(JF.Translation),YesNo(JF.ScrewAngle),
     &               YesNo(JF.MomentArm),YesNo(JF.WrenchArm),
     &               YesNo(JF.RefCorrectAng)
        if ( OF.ToLog ) write(3,160) 
     &               YesNo(JF.angle_JCS),YesNo(JF.vel_acc_JCS),
     &               YesNo(JF.angle_EUL),YesNo(JF.vel_acc_EUL),
     &               YesNo(JF.load),YesNo(JF.legsummed),
     &               YesNo(JF.wrench),YesNo(JF.power),
     &               YesNo(JF.FiniteScrew),YesNo(JF.InstantScrew),
     &               YesNo(JF.Translation),YesNo(JF.ScrewAngle),
     &               YesNo(JF.MomentArm),YesNo(JF.WrenchArm),
     &               YesNo(JF.RefCorrectAng)
160     format(' Joint Information'//                              
     &         ' JCS angles                : ',a3/ 
     &         ' JCS velocity/accel        : ',a3/
     &         ' Euler angles              : ',a3/
     &         ' Euler velocity/accel      : ',a3/
     &         ' Joint reaction loads      : ',a3/
     &         ' Summed leg loads          : ',a3/
     &         ' Joint wrench              : ',a3/
     &         ' Joint power transfer      : ',a3/
     &         ' Joint finite screw        : ',a3/
     &         ' Joint instantaneous screw : ',a3/
     &         ' Joint translation         : ',a3/
     &         ' Joint Screw Angle         : ',a3/
     &         ' Joint Moment Arm          : ',a3/
     &         ' Joint Wrench Arm          : ',a3/
     &         ' Angle Reference Correction: ',a3/)
        if ( GP.num_jnt .gt. 0 ) then
          write(6,170) GP.num_jnt,
     &	               (jnt_names(GP.jnt_num(i)),i=1,GP.num_jnt)
	  if ( OF.ToLog ) write(3,170) GP.num_jnt,
     &	                  (jnt_names(GP.jnt_num(i)),i=1,GP.num_jnt)

170       format(' Number of joints : ',i2/' Joint names :'
     &           8(a4,1x),/14x,8(a4,1x)/)
        end if
        if ( JF.NumProcOps .gt. 0 ) then
          write(6,171) JF.ProcOp(1)(1:30) 
          if ( OF.ToLog ) write(3,171) JF.ProcOp(1)(1:30)
171       format(/' Joint smoothing/filtering operations: 'a30)
          do i= 2, JF.NumProcOps
            write(6,117) JF.ProcOp(i)(1:30)
            if ( OF.ToLog ) write(3,117) JF.ProcOp(i)(1:30)
          end do
        end if             
                 
      else if ( CMND.CmndText(2) .eq. 'AVG' ) then
        call DisplayAverage( CMND,AF,OF )
                                        
      else if ( CMND.CmndText(2) .eq. 'CYC' ) then
        call DisplayCycle( CMND,CF,OF )
                 
      else if ( CMND.CmndText(2) .eq. 'EMG' ) then
        if ( EF.read ) then                        
          write(6,200) EP.NumChnl,EP.NumSamples,EP.SampleRate,
     &                 YesNo(EF.filtered),YesNo(EF.rectified),
     &                 YesNo(EF.integrated),YesNo(EF.averaged),
     &                 YesNo(EF.maximum),YesNo(EF.normalized),
     &                 (EF.ProcOp(i),i=1,EF.NumProcOps)
          if ( OF.ToLog ) 
     &      write(3,200) EP.NumChnl,EP.NumSamples,EP.SampleRate,
     &                   YesNo(EF.filtered),YesNo(EF.rectified),
     &                   YesNo(EF.integrated),YesNo(EF.averaged),
     &                 YesNo(EF.maximum),YesNo(EF.normalized),
     &                   (EF.ProcOp(i),i=1,EF.NumProcOps)
200       format(' EMG Information'//
     &           ' Number of Channels : ',i2/
     &           ' Number of Samples  : ',i5/
     &           ' Sample Rate        : ',i5,' Hz'//
     &           ' Filtered           : ',a3/
     &           ' Rectified          : ',a3/
     &           ' Integrated         : ',a3/
     &           ' Averaged           : ',a3/
     &           ' Maximum            : ',a3/
     &           ' Normalized         : ',a3//
     &           ' Processing operations : ',a40/4(25x,a40/))
          write(6,148)
          read(5,149) hold
          if ( .not. EF.maximum ) then
            write(6,205)
            if ( OF.ToLog ) write(3,205)
205         format(' Chnl#   Code#   Type     Name'/)
            do i= 1, EP.NumChnl           
              write(6,210) i,EP.CodeNum(i),EMGType(EP.Surface(i)),
     &                     EP.Name(i)     
210           format(3x,i2,6x,i2,5x,a7,3x,a20)
              if ( OF.ToLog ) 
     &          write(3,210) i,EP.CodeNum(i),EMGType(EP.Surface(i)),
     &                       EP.Name(i)
            end do ! i
          else
            write(6,207)
            if ( OF.ToLog ) write(3,207)
207         format(' Chnl#   Maximum   Type     Name'/)
            do i= 1, EP.NumChnl           
              write(6,212) i,float(EP.CodeNum(i))/1000.0,
     &                     EMGType(EP.Surface(i)),EP.Name(i)     
212           format(3x,i2,6x,f8.4,5x,a7,3x,a20)
              if ( OF.ToLog ) 
     &          write(3,212) i,float(EP.CodeNum(i))/1000.0,
     &                       EMGType(EP.Surface(i)),EP.Name(i)
            end do ! i
          end if
        else
          write(6,220)
          if ( OF.ToLog ) write(3,220)
220       format(' No EMG information read in yet.')
        end if
            
      else if ( CMND.CmndText(2) .eq. 'LIM' ) then
        write(6,560) MAX_MTN,MAX_ELC,MAX_EMF,
     &               MAX_MRK,MAX_JNT,MAX_SEG,MAX_PLT,MAX_EMG
560     format(/' Limits of this version of ANZ'//
     &          '  Max Motion Data Frames : ',i5/
     &          '  Max Force Plate Samples: ',i5/
     &          '  Max EMG Data Samples   : ',i5//
     &          '  Max Number of Markers  : ',i5/
     &          '  Max Number of Joints   : ',i5/
     &          '  Max Number of Segments : ',i5/
     &          '  Max Number of Force Plt: ',i5/
     &          '  Max Number of EMG''s    : ',i5/)

      else                                   
        write(6,300) CMND.CmndText(2)
        if ( OF.ToLog ) write(3,300) CMND.CmndText(2)
300     format(' Error- ',a3,' is not a valid STatus command.'/
     &         '        Available commands are: GENeral MaRKer  SEGment FoRCe'/
     &         '                                JoiNT   AVeraGe CYCle   LIMits')
      end if            
      return

1000  write(6,1005)
      if ( OF.ToLog ) write(3,1005)
1005  format(' Error- STAtus requires more than one command word.'/
     &       '        Available commands are: GENeral MaRKer  SEGment FoRCe'/
     &       '                                JoiNT   AVeraGe CYCle   LIMits')
      return
      end
c
c
c       
c
c     Copyright by Dwight Meglan 1990
c
c     Purpose: Display the status of the segment based quantities in ANZ
c
      subroutine DisplaySegment( CMND,SF,OF )
      implicit none

      include 'a_const.inc'
      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_seg.inc'
      include 'a_names.inc'

      record /CmndLine/     CMND
      record /segment_flag/ SF
      record /option_flag/  OF

      integer*4 i,j,seg,segnum
      character YesNo*3,segtext*3
      logical*4 getsegnum

      if ( CMND.CmndText(3) .eq. 'INE' ) then ! show mass-inertia parameters
        if ( SF.param ) then
          write(6,112)
          if ( OF.ToLog ) write(3,112)
112       format(' Segment mass-inertia parameters'/
     &           ' Segment  Mass           Mass moment of inertia'/
     &           '   Name   (kg)       X            Y            Z (kg*m^2)'//)
          do i= 1, GP.num_seg
            seg= GP.seg_num(i)           
            write(6,114) seg_names(seg),SP(seg).mass,
     &                   (SP(seg).inertia(j),j=1,3)
            if ( OF.ToLog ) write(3,114) seg_names(seg),SP(seg).mass,
     &                                   (SP(seg).inertia(j),j=1,3)
114         format(3x,a4,2x,f5.2,3(2x,e12.5))
          end do ! i
        else
          write(6,116)
          if ( OF.ToLog ) write(3,116)
116       format(' Segment mass-inertia parameters have not been calculated yet.')
        end if                                            

      else if ( CMND.CmndText(3) .eq. 'LCS' ) then ! show LCS info
          SegText= CMND.CmndText(4)
          if ( .not. GetSegNum( SegText,SegNum ) ) goto 1000
          write(6,300) seg_names(segnum),
     &                 (((SP(segnum).TCStoLCS(j,i)),i=1,4),j=1,3)
          if ( OF.ToLog ) write(3,300) seg_names(segnum),
     &                 (((SP(segnum).TCStoLCS(j,i)),i=1,4),j=1,3)
300       format(/' Segment: ',a4//
     &            ' TCStoLCS: ',4(f12.5,1x)/2(11x,4(f12.4,1x)/)/
     &            ' LCS Marker Position:'/
     &            '  #   Name    X          Y         Z'/)
          do i= 1, SP(segnum).nmTCS
            if ( OF.ToLog ) write(3,310) SP(segnum).mnTCS(i),
     &                   MP.mrk_name(SP(SegNum).mnTCS(j)),
     &                   ((SP(segnum).mpnLCS(j,i)),j=1,3)
            write(6,310) SP(segnum).mnTCS(i),
     &                   MP.mrk_name(SP(SegNum).mnTCS(j)),
     &                   ((SP(segnum).mpnLCS(j,i)),j=1,3)
310         format(2x,i2,3x,a4,1x,3(f12.5,1x))
          end do                                

      else if ( CMND.NumCmnd .ge. 3 ) then
        goto 1010
                                   
      else ! general segment info       
        write(6,120) YesNo(SF.param),YesNo(SF.position),
     &               YesNo(SF.vel_acc),YesNo(SF.energy),
     &               YesNo(SF.FiniteScrew),YesNo(SF.InstantScrew),
     &               YesNo(SF.cntr_mass),YesNo(SF.BCMVel),
     &               YesNo(SF.momentum),YesNo(SF.angle),
     &               YesNo(SF.RefCorrect),
     &               YesNo(SF.RightSideAlign),
     &               YesNo(SF.LeftSideAlign)
        if ( OF.ToLog ) write(3,120) YesNo(SF.param),
     &                          YesNo(SF.position),
     &                          YesNo(SF.vel_acc),YesNo(SF.energy),
     &                          YesNo(SF.FiniteScrew),
     &                          YesNo(SF.InstantScrew),
     &                          YesNo(SF.cntr_mass),YesNo(SF.BCMVel),
     &                          YesNo(SF.momentum),YesNo(SF.angle),
     &                          YesNo(SF.RefCorrect),
     &                          YesNo(SF.RightSideAlign),
     &                          YesNo(SF.LeftSideAlign)
120     format(' Segment Information'//
     &         ' Segment parameters            : ',a3/                       
     &         ' Segment position              : ',a3/
     &         ' Segment vel/accel             : ',a3/
     &         ' Segment energy                : ',a3/
     &         ' Segment finite screw          : ',a3/
     &         ' Segment instantaneous screw   : ',a3/
     &         ' Segment center mass           : ',a3/
     &         ' Segment center mass velocity  : ',a3/
     &         ' Segment momentum              : ',a3/
     &         ' Segment angle                 : ',a3/
     &         ' Anatomic reference correction : ',a3/
     &         ' Rigid Body Alignment- Right   : ',a3/
     &         ' Rigid Body Alignment- Left    : ',a3/)
        if ( GP.num_seg .gt. 0 ) then
          write(6,130) GP.num_seg,
     &                 (seg_names(GP.seg_num(i)),i=1,GP.num_seg)
          if ( OF.ToLog ) write(3,130) GP.num_seg,
     &                        (seg_names(GP.seg_num(i)),i=1,GP.num_seg)
130       format(' Number of segments  : ',i2/
     &           ' Segment names       : ',6(a4,1x)/23x,6(a4,1x)/23x,6(a4,1x)/ )
        end if
        if ( SF.NumProcOps .gt. 0 ) then
          write(6,121) SF.ProcOp(1)(1:30) 
          if ( OF.ToLog ) write(3,121) SF.ProcOp(1)(1:30)
121       format(/' Segment smoothing/filtering operations: 'a30)
          do i= 2, SF.NumProcOps
            write(6,122) SF.ProcOp(i)(1:30)
            if ( OF.ToLog ) write(3,122) SF.ProcOp(i)(1:30)
122         format(41x,a30)
          end do
        end if
      end if ! mass-inerita parameters or general segment info
      return

1000  write(6,1005) SegText,(seg_names(GP.seg_num(i)),
     &                       i= 1, GP.num_seg)
      if ( OF.ToLog ) write(6,1005) SegText,
     &                          (seg_names(GP.seg_num(i)),
     &                           i= 1, GP.num_seg)
1005  format(' Error- ',a3,' is not a valid segment name'/
     &       '        Valid segment names are : ',5a5/2(34x,5a5/))
      return

1010  write(6,1015) CMND.CmndText(3)
      if ( OF.ToLog ) write(3,1015) CMND.CmndText(3)
1015  format(' Error - ',a3,' is not a valid STA SEG command'/
     &       '         Valid commands are INErtia and LCS')
      return
      end
c
c         
c         
c
c     Copyright by Dwight Meglan 1990
c
c     Purpose: Display the gait cycle time-distance parameters
c
      subroutine DisplayCycle( CMND,CF,OF )
      implicit none

      include 'a_const.inc'
      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_names.inc'

      record /CmndLine/    CMND
      record /cycle_flag/  CF
      record /option_flag/ OF

      integer*4 i
      real*4    feet,inch
      character ans*1
                       
      data feet,inch / 3.2808,39.3696 /     ! conversion ft/m, in/m
      
      if ( CF.event ) then
        write(6,190) ( MP.rhs_frm(i),i= 1, MP.num_rhs )
190     format(' Cycle event frame #''s'//
     &         ' Right heel strike : ',5(i3,1x) )
        write(6,200) ( MP.lhs_frm(i),i= 1, MP.num_lhs )
200     format(' Left heel strike  : ',5(i3,1x) )
        write(6,210) ( MP.rto_frm(i),i= 1, MP.num_rto )
210     format(' Right toe off     : ',5(i3,1x) )
        write(6,220) ( MP.lto_frm(i),i= 1, MP.num_lto )
220     format(' Left toe off      : ',5(i3,1x) )
        write(6,223) MP.first_frm
223     format(/' First motion frame absolute frame # : ',i3/)
        if ( OF.ToLog ) then
          write(3,190) ( MP.rhs_frm(i),i= 1, MP.num_rhs )
          write(3,200) ( MP.lhs_frm(i),i= 1, MP.num_lhs )
          write(3,210) ( MP.rto_frm(i),i= 1, MP.num_rto )
          write(3,220) ( MP.lto_frm(i),i= 1, MP.num_lto )
          write(3,223) MP.first_frm
        end if
        if ( CF.statistics ) then
          write(6,225)
225       format(/' Press return to continue...')
          read(5,227) ans
227       format(a1)        
          write(6,240)
240       format(/' Gait cycle parameters'/)
          write(6,8) CP.velocity,          CP.velocity*feet,
     &           CP.velocity*inch,
     &           CP.NormVelocity,      CP.PctNormVelocity,
     &           CP.stride_length,     CP.stride_length*feet,
     &           CP.stride_length*inch,
     &           CP.NormStrideLength,  CP.PctNormStrideLength,
     &           CP.step_length(rt),   CP.step_length(rt)*feet,
     &           CP.step_length(rt)*inch,
     &           CP.NormStepLength(rt),CP.PctNormStepLength(rt),
     &           CP.step_length(lf),   CP.step_length(lf)*feet,
     &           CP.step_length(lf)*inch,
     &           CP.NormStepLength(lf),CP.PctNormStepLength(lf),
     &           CP.step_width,        CP.step_width*feet,
     &           CP.step_width*inch,
     &           CP.NormStepWidth,     CP.PctNormStepWidth,
     &           CP.cadence,        
     &           CP.NormCadence,       CP.PctNormCadence
8         format(16x,'meters',8x,'feet',8x,'inches',6x,'Normal(m)',3x,'% Normal'//
     &       ' Velocity   : ',5(f8.3,5x)/
     &       ' Stride     : ',5(f8.3,5x)/
     &       ' R Step     : ',5(f8.3,5x)/
     &       ' L Step     : ',5(f8.3,5x)/          
     &       ' Step Width : ',5(f8.3,5x)//
     &       ' Cadence    : ',f8.3,' step/min',22x,2(f8.3,5x)/)
          write(6,10) CP.total_time(rt),CP.total_percent(rt),
     &            CP.NormTotalPct(rt),
     &            CP.total_time(lf),CP.total_percent(lf),
     &            CP.NormTotalPct(lf),
     &            CP.sgl_time(rt),  CP.sgl_percent(rt),
     &            CP.NormSglPct(rt),
     &            CP.sgl_time(lf),  CP.sgl_percent(lf),
     &            CP.NormSglPct(lf),
     &            CP.dbl_time(rt),  CP.dbl_percent(rt),
     &            CP.NormDblPct(rt),
     &            CP.dbl_time(lf),  CP.dbl_percent(lf),
     &            CP.NormDblPct(lf)
10        format('            Time (s)        Percent Cycle        Normal'/
     &       ' R TLST  ',3(f8.3,11x)/
     &       ' L TLST  ',3(f8.3,11x)/
     &       ' R SLST  ',3(f8.3,11x)/
     &       ' L SLST  ',3(f8.3,11x)/
     &       ' R DLS   ',3(f8.3,11x)/
     &       ' L DLS   ',3(f8.3,11x)/)       
          if ( CP.first_side .eq. rt ) then
            write(6,12) CP.HS_percent(1),CP.NormHsPct(1),
     &              CP.TO_percent(1),CP.NormToPct(1),
     &              CP.HS_percent(2),CP.NormHsPct(2),
     &              CP.TO_percent(2),CP.NormToPct(2),
     &              CP.HS_percent(3),CP.NormHsPct(3)
12         format(' RHS                        ',f8.3,11x,f8.3/
     &       ' LTO                        ',f8.3,11x,f8.3/
     &       ' LHS                        ',f8.3,11x,f8.3/
     &       ' RTO                        ',f8.3,11x,f8.3/
     &       ' RHS                        ',f8.3,11x,f8.3/ )
          else
            write(6,14) CP.HS_percent(1),CP.NormHsPct(1),
     &              CP.TO_percent(1),CP.NormToPct(1),
     &              CP.HS_percent(2),CP.NormHsPct(2),
     &              CP.TO_percent(2),CP.NormToPct(2),
     &              CP.HS_percent(3),CP.NormHsPct(3)
14         format(' LHS                        ',f8.3,11x,f8.3/
     &       ' RTO                        ',f8.3,11x,f8.3/
     &       ' RHS                        ',f8.3,11x,f8.3/
     &       ' LTO                        ',f8.3,11x,f8.3/
     &       ' LHS                        ',f8.3,11x,f8.3/ )
          end if ! first_side
        else
          write(6,290)
          if ( OF.ToLog ) write(3,290)
290       format(/' Cycle Statistics not calculated.')
        end if ! Statistics present
      else                 
        write(6,230)
230     format(' Cycle Information '//
     &         ' Events     : no'/
     &         ' Statistics : no' )
      end if
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
c     Purpose: Display the status of the average joint and segment quantities
c
      subroutine DisplayAverage( CMND,AF,OF )
      implicit none

      include 'a_const.inc'
      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_seg.inc'
      include 'a_jnt.inc'
      include 'a_names.inc'

      record /CmndLine/     CMND
      record /avg_pos_flag/ AF
      record /option_flag/  OF

      integer*4 i,seg,j,k,jnt
      character YesNo*3

      if ( CMND.CmndText(3) .eq. 'POS' ) then
        if ( .not. AF.position ) goto 1000
        if ( (CMND.NumCmnd .eq. 3) .or. (CMND.CmndText(4) .eq. 'CNT') ) then
          write(6,110)
          if ( OF.ToLog ) write(3,110)
110       format(/' Segment average location'//
     &            ' Segment          Position (m)'/
     &            '  Name        X       Y      Z'/)
          do i= 1, GP.num_seg
            seg= GP.seg_num(i)
            write(6,120) seg_names(seg),(SgpAvg(j,cntr,seg),j=x,z)
            if ( OF.ToLog ) write(3,120) seg_names(seg),
     &                                   (SgpAvg(j,cntr,seg),j=x,z)
120         format(2x,a4,5x,3(f7.3))
          end do ! i
        else
          write(6,130)
          if ( OF.ToLog ) write(3,130)
130       format(/' Segment average orientation'//
     &            ' Segment          X                    Y                  Z'/
     &            '  Name     ',3('x      y      z      ')/)
          do i= 1, GP.num_seg
            seg= GP.seg_num(i)
            write(6,140) seg_names(seg),((SgpAvg(j,k,seg),j=x,z),k=x,z)
            if ( OF.ToLog ) write(3,140) seg_names(seg),
     &                              ((SgpAvg(j,k,seg),j=x,z),k=x,z)
140         format(2x,a4,5x,9(f7.3))
          end do
        end if ! center or orientation
        
      else if ( CMND.CmndText(3) .eq. 'ANG' ) then
        if ( (CMND.NumCmnd .eq. 3) .or. (CMND.CmndText(4) .eq. 'JCS') ) then
          if ( .not. AF.angle_JCS ) goto 1010
          write(6,150)
          if ( OF.ToLog ) write(3,150)
150       format(/' Average JCS joint angle'//
     &            ' Joint           Angle'/
     &            ' Name       Flex    Inex    Abad'/)
          do i= 1, GP.num_jnt
            jnt= GP.jnt_num(i)
            write(6,160) jnt_names(jnt),(JangAvgJCS(j,jnt),j=1,3)
            if ( OF.ToLog ) write(3,160) jnt_names(jnt),
     &                                   (JangAvgJCS(j,jnt),j=1,3)
160         format(1x,a4,4x,3f8.2)
          end do ! i
        else
          if ( .not. AF.angle_EUL ) goto 1020
          write(6,170)
          if ( OF.ToLog ) write(3,170)
170       format(/' Average euler joint angle'//
     &            ' Joint           Angle'/
     &            ' Name       Flex    Inex    Abad'/)
          do i= 1, GP.num_jnt                
            jnt= GP.jnt_num(i)
            write(6,160) jnt_names(jnt),(JangAvgEUL(j,jnt),j=1,3)
            if ( OF.ToLog ) write(3,160) jnt_names(jnt),
     &                                   (JangAvgEUL(j,jnt),j=1,3)
          end do ! i
        end if ! JCS or euler angles
        
      else if ( CMND.NumCmnd .eq. 2 ) then
        write(6,100) GP.AvgFile,YesNo(AF.position),
     &               YesNo(AF.angle_EUL),YesNo(AF.angle_JCS),
     &               YesNo(AF.RefCorrectAng)
        if ( OF.ToLog ) write(3,100) 
     &               GP.AvgFile,YesNo(AF.position),
     &               YesNo(AF.angle_EUL),YesNo(AF.angle_JCS),
     &               YesNo(AF.RefCorrectAng)
100     format(' Average information'//           
     &         ' Source file      : ',a40/            
     &         ' Position         : ',a3/
     &         ' JCS angles       : ',a3/
     &         ' Euler angles     : ',a3/
     &         ' Anat Ref Correct : ',a3)
     
      else
        write(6,180)
        if ( OF.ToLog ) write(3,180)
180     format(' Error- Invalid STAtus AVeraGe command.'/
     &         '        Valid commands are: POS CeNTer'/
     &         '                                ORIentation'/
     &         '                            ANGle JCS'/
     &         '                                  EULer')
      end if
      return

1000  write(6,1005)
      if ( OF.ToLog ) write(3,1005)
1005  format(' Error- Average segment position has not been calculated yet.')
      return
      
1010  write(6,1015)
      if ( OF.ToLog ) write(3,1015)
1015  format(' Error- Average JCS joint angles have not been calculated yet.')
      return
      
1020  write(6,1025)
      if ( OF.ToLog ) write(3,1025)
1025  format(' Error- Average euler joint angles have not been calculated yet.')
      return
      end



      character*3 function YesNo( flag )
      implicit none

      logical*4 flag

      if ( flag ) then
         YesNo= 'yes'
      else
         YesNo= 'no '
      endif
      return
      end


      character*7 function EMGType( flag )
      implicit none

      logical*4 flag

      if ( flag ) then
         EMGType= 'Surface'
      else
         EMGType= 'Wire   '
      endif
      return
      end
