c
c
c
c
c     Copyright by Dwight Meglan 1990
c
c     Purpose: This file contains a number of routines to export information
c              derived from force plate data.
c
      subroutine ExportFrc( CMND,inc,RegHeader,IgorHeader,
     &                      FF,SF,OF )
      implicit none
      include 'a_const.inc'

      include 'a_struct.inc'
      include 'a_prm.inc'
      include 'a_names.inc'
      
      record /CmndLine/     CMND
      record /force_flag/   FF
      record /segment_flag/ SF
      record /option_flag/  OF

      integer*4 inc
      logical*4 IgorHeader,RegHeader

      integer*4 NumExpFrcVar,ExpVarNumCmnd(10),CSType,i,ExpVarNum,
     &          NumCmnd,PltNum,Start,NumOpt,LogtoInt
      real*4    LegLength(2)
      character LineText*80,ExpFrcVarName(10)*3,OptText(5)*3
      logical*4 OpenTextFile,ExpPlt,ExpFoot,ExpComb,NormWt,GetCSType,
     &          NormWtHt,NormWtLeg,AnimateGRL,UsUnits,Error,Animate,
     &          NegateGRL,ExpSIMM

      data NumExpFrcVar / 10 /
      data ExpFrcVarName / 'GRL','CPR','LCP','WRE','SI ',
     &                     'IN1','IN2','PMA','PWA','CPV' /
      data ExpVarNumCmnd / 5,5,4,5,4,5,5,4,4,4 /
                 
c
c     Check validity of export quantity name
c
      Error= .true.
      do i= 1, NumExpFrcVar
        if ( CMND.CmndText(3) .eq. ExpFrcVarName(i) ) then
          Error= .false.
          ExpVarNum= i
        end if
      end do
      if ( Error ) goto 1000 ! bad name
c
c     Now check options if present on command # 3                  
c
      NormWt=    .false.
      NormWtHt=  .false.
      NormWtLeg= .false.
      UsUnits=   .false.
      Animate=   .false.
      NegateGRL= .false.
      ExpSIMM=   .false.
      CSType= PRO_CS
      if ( CMND.NumOpt(3) .gt. 0 ) then
        NumOpt= CMND.NumOpt(3)            ! stupid trick needed to make mac 
        do i= 1, CMND.NumOpt(3)           ! version work correctly !!!!
          OptText(i)= CMND.OptText(i,3)
        end do
        do i= 1, CMND.NumOpt(3)
          if ( (ExpVarNum .eq. 1) .and.
     &         ((OptText(i) .eq. 'NWT') .or. 
     &          (OptText(i) .eq. 'NWH') .or.
     &          (OptText(i) .eq. 'NWL')     ) ) then
            if ( OptText(i) .eq. 'NWT' ) then
              if ( GP.weight .lt. 1.0e-5 ) goto 1280 ! error
              NormWt=    .true.           
              NormWtHt=  .false.
              NormWtLeg= .false.
            else if ( OptText(i) .eq. 'NWH' ) then
              if ( GP.weight .lt. 1.0e-5 ) goto 1280 ! error
              if ( GP.height .lt. 1.0e-5 ) goto 1290 ! error
              NormWt=    .false.
              NormWtHt=  .true.
              NormWtLeg= .false.
            else if ( OptText(i) .eq. 'NWL' ) then
              if ( GP.weight .lt. 1.0e-5 ) goto 1280 ! error
              if ( .not. SF.param ) goto 1320 ! error
              if ( (SP(rtcf).length .lt. 1.0e-5) .or.
     &             (SP(rtth).length .lt. 1.0e-5) .or.
     &             (SP(lfcf).length .lt. 1.0e-5) .or.
     &             (SP(lfth).length .lt. 1.0e-5)      ) goto 1310 ! error
              LegLength(rt)= SP(rtcf).length + SP(rtth).length
              LegLength(lf)= SP(lfcf).length + SP(lfth).length
              NormWt=    .false.             
              NormWtHt=  .false.
              NormWtLeg= .true.
            end if
          else if ( (ExpVarNum .eq. 1) .and.
     &              (OptText(i) .eq. 'LBS') ) then
            UsUnits= .true.
          else if ( (ExpVarNum .eq. 1) .and.
     &              ( (OptText(i) .eq. 'ANI') .or. 
     &                (OptText(i) .eq. 'VIS') .or.
     &                (OptText(i) .eq. 'SIM')     )  ) then
            Animate= .true.
            if ( OptText(i) .eq. 'SIM' ) ExpSIMM= .true.
          else if ( (ExpVarNum .eq. 1) .and.
     &              (OptText(i) .eq. 'NEG') ) then
            NegateGRL= .true.
          else if ( (ExpVarNum .eq. 8)  .or. (ExpVarNum .eq. 9) ) then
            if ( .not. GetCSType( NumOpt,OptText,CSType) ) goto 1010
            if ( (CSType .eq. EUL_CS) .or. 
     &           (CSType .eq. LCS_CS) .or.
     &           (CSType .eq. JCS_CS)      ) goto 1010
          else
            goto 1020 ! error - no options valid
          end if
        end do
      end if
c
c     Figure out whether plate, foot, or combined will be exported
c     if applicable to the quantity being exported
c
      NumCmnd= ExpVarNumCmnd(ExpVarNum)
      if ( CMND.NumCmnd .lt. NumCmnd ) goto 1030 ! error
      ExpPlt= .false.
      ExpFoot=  .false.
      ExpComb=  .false.
      if ( NumCmnd .gt. 4 ) then ! quantity will be plt, ft, or comb
        if ( CMND.CmndText(4) .eq. 'PLT' ) then
          NumCmnd= NumCmnd + 1
          if ( CMND.NumCmnd .lt. 6 ) goto 1030 ! error
          if ( .not. CMND.CmndNumOK(5) ) goto 1040
          if ( (CMND.CmndIntVal(5) .lt. 1) .or.
     &         (CMND.CmndIntVal(5) .gt. FP.num_plt) ) goto 1040
          ExpPlt= .true.
          PltNum= CMND.CmndIntVal(5)
        else if ( CMND.CmndText(4)(1:2) .eq. 'FT' ) then
          ExpFoot= .true.
        else if ( CMND.CmndText(4) .eq. 'COM' ) then
          ExpComb= .true.
        else
          goto 1050 ! error - bad command
        end if   
      end if
c
c     Special option check if EXP FRC GRL FT for coord system
c
      if ( (ExpVarNum .eq. 1) .and. ExpFoot ) then
        CSType= GCS_CS
        AnimateGRL= .false.
        if ( CMND.NumOpt(4) .gt. 0 ) then
          do i= 1, CMND.NumOpt(4)
            if ( CMND.OptText(i,4) .eq. 'GCS' ) then
              CSType= GCS_CS
            else if ( CMND.OptText(i,4) .eq. 'LCS' ) then
              CSType= LCS_CS
            else if ( (CMND.OptText(i,4) .eq. 'ANI') .or.
     &                (CMND.OptText(i,4) .eq. 'VIS') .or.
     &                (CMND.OptText(i,4) .eq. 'SIM')     ) then
              AnimateGRL= .true.
              CSType= GCS_CS
              if ( CMND.OptText(i,4) .eq. 'SIM' ) ExpSIMM= .true.
            else if ( CMND.OptText(i,4) .eq. 'NEG' ) then
              NegateGRL= .true.
            else
              goto 1070 ! error
            end if
          end do
        end if
      end if
c
c     Special option check if EXP FRC GRL COM for animation flag
c
      if ( (ExpVarNum .eq. 1) .and. ExpComb ) then
        AnimateGRL= .false.
        if ( CMND.NumOpt(4) .gt. 0 ) then
          do i= 1, CMND.NumOpt(4)
            if ( (CMND.OptText(i,4) .eq. 'ANI') .or.
     &           (CMND.OptText(i,4) .eq. 'VIS') .or.
     &           (CMND.OptText(i,4) .eq. 'SIM')    ) then
              AnimateGRL= .true.
              if (CMND.OptText(i,4) .eq. 'SIM') ExpSIMM= .true.
            else if ( CMND.OptText(i,4) .eq. 'NEG' ) then
              NegateGRL= .true.
            else
              goto 1090 ! error
            end if
          end do
        end if              
      end if
c
c     Open Text output file...
c
      LineText= CMND.Text(1)  
      Start= CMND.CmndStart(NumCmnd)
      if ( .not. OpenTextFile(LineText,Start,.true.) ) goto 2000 ! error
c
c     Now dump whatever has been requested
c
      if ( ExpVarNum .eq. 1 ) then ! Ground Reaction Load
        call ExpFrcGRL( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                  ExpComb,AnimateGRL,ExpSIMM,NegateGRL,NormWt,NormWtHt,
     &                  NormWtLeg,LegLength,UsUnits,CSType,PltNum,
     &                  FF,OF,error )

      else if ( ExpVarNum .eq. 2 ) then ! GRL Center of Pressure
        call ExpFrcCPR( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                  ExpComb,PltNum,FF,OF,error )

      else if ( ExpVarNum .eq. 3 ) then ! GRL Center of Pressure in Foot LCS
        call ExpFrcLCP( inc,RegHeader,IgorHeader,FF,OF,error )

      else if ( ExpVarNum .eq. 4 ) then ! GRL Wrench
        call ExpFrcWre( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                  ExpComb,PltNum,FF,OF,error )

      else if ( ExpVarNum .eq. 5 ) then ! Foot Strike Index
        call ExpFrcSI( inc,RegHeader,IgorHeader,FF,OF,error )

      else if ( ExpVarNum .eq. 6 ) then ! GRL First Integral
        call ExpFrcInt1( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                  ExpComb,PltNum,FF,OF,error )

      else if ( ExpVarNum .eq. 7 ) then ! GRL Second Integral
        call ExpFrcInt2( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                  ExpComb,PltNum,FF,OF,error )

      else if ( ExpVarNum .eq. 8 ) then ! Pitching Moment Arm
        call ExpFrcPma( inc,RegHeader,IgorHeader,CSType,
     &                  FF,OF,error )

      else if ( ExpVarNum .eq. 9 ) then ! Pitching Wrench Arm
        call ExpFrcPwa( inc,RegHeader,IgorHeader,CSType,
     &                  FF,OF,error )

      else if ( ExpVarNum .eq. 10 ) then ! Center of Pressure Velocity
        call ExpFrcCpv( inc,RegHeader,IgorHeader,FF,OF,error )

      end if
      close(unit=2)
      return
      
1000  write(6,1005) (ExpFrcVarName(i),i=1,NumExpFrcVar)
      if ( OF.ToLog ) write(3,1005) (ExpFrcVarName(i),i=1,NumExpFrcVar)
1005  format(' Error- Invalid EXPort FoRCe command'/
     &       '        Valid commands are: ',5a5/29x,5a5)
      return             
   
1010  write(5,1015) OptText(i)
      if ( OF.ToLog ) write(3,1015) OptText(i)
1015  format(' Error- ',a3,'is an invalid Coord system option'/
     &       '        Valid Coord systems are : /GCS /PRO /DIS')
      return                                            
      
1020  write(6,1025) OptText(i),CMND.CmndText(3)
      if ( OF.ToLog ) write(3,1025) OptText(i),CMND.CmndText(3)
1025  format(' Error- ',a3,' is not a valid option for EXPort FoRCe ',a3/
     &       '        Valid options are:'/
     &       9x,'GRL      : (NWT,NWH,NWL), LBS, VIS, SIMM'/
     &       9x,'PMA, PWA : (GCS,PRO,DIS)')
      return

1030  write(6,1035) CMND.NumCmnd,NumCmnd
      if ( OF.ToLog ) write(6,1035) CMND.NumCmnd,NumCmnd
1035  format(' Error- There are only ',i2,' commands present for EXP FRC'/
     &       '        but there must be ',i2,' commands for this quantity')
      return

1040  write(6,1045) CMND.CmndText(5),FP.num_plt
      if ( OF.ToLog ) write(6,1045) CMND.CmndText(5),FP.num_plt
1045  format(' Error- ',a3,' is not a valid force plate number'/
     &       '        Valid plate #''s are : 1 - ',i2)
      return

1050  write(6,1055) CMND.CmndText(4),CMND.CmndText(3)
      if ( OF.ToLog ) write(3,1055) CMND.CmndText(4),CMND.CmndText(3)
1055  format(' Error- ',a3,' is not a valid export quantity for EXP FRC ',a3/
     &       '        Valid quantities are: PLT COM FT')        
      return               

1060  write(6,1065) CMND.NumOpt(4),CMND.CmndText(3)
      if ( OF.ToLog ) write(3,1065) CMND.NumOpt(4),CMND.CmndText(3)
1065  format(' Error- There are ',i2,' options present for EXP FRC ',a3,' FT'/
     &       '        but only one is required (/GCS /LCS /ANImate /VIS /SIM)')
      return               

1070  write(6,1075) CMND.OptText(1,4),CMND.CmndText(3)
      if ( OF.ToLog ) write(3,1075) CMND.OptText(1,4),CMND.CmndText(3)
1075  format(' Error- ',a3,' is an invalid option for EXP FRC ',a3,' FT'/
     &       '        Valid options are: /GCS, /LCS /ANImate /VIS /SIM')        
      return               

1080  write(6,1085) CMND.NumOpt(4)
      if ( OF.ToLog ) write(3,1085) CMND.NumOpt(4)
1085  format(' Error- There are ',i2,' options present for EXP FRC GRL COM'/
     &       '        but only one is available /ANI /VIS')        
      return               

1090  write(6,1095) CMND.OptText(1,4)
      if ( OF.ToLog ) write(3,1095) CMND.OptText(1,4)
1095  format(' Error- ',a3,' is an invalid option for EXP FRC GRL COM'/
     &       '        Valid option is: /ANImate /VIS /SIM')        
      return               

2000  write(6,2005)                 
      if ( OF.ToLog ) write(3,2005)
2005  format(' Error- File could not be opened')        
      return               
                                          
1280  write(6,1285) GP.weight
      if ( OF.ToLog ) write(3,1285) GP.weight
1285  format(' Error- Normaization requires a patient weight > 0.0'/
     &       '        In this case the weight is ',f10.4)
      return

1290  write(6,1295) GP.height
      if ( OF.ToLog ) write(3,1295) GP.height
1295  format(' Error- Normaization requires a patient height > 0.0'/
     &       '        In this case the height is ',f10.4)
      return

1310  write(6,1315) 
      if ( OF.ToLog ) write(3,1315) 
1315  format(' Error- Weight*Leg length normalization requires the calf and '/
     &       '        thigh of both legs to be > 0.0 which they are not')
      return

1320  write(6,1325) 
      if ( OF.ToLog ) write(3,1325) 
1325  format(' Error- Weight*Leg length normalization requires the segment'/
     &       '        parameters to have been calculated which they have not')
      return
      end                                 
c
c
c                   
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ConvGRL( LoadSet,NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                    Weight,Height,LegLength,Side,NormLoad )
      implicit none
                    
      real*4    LoadSet(6),Weight,Height,LegLength(2),NormLoad(6)
      integer*4 Side
      logical*4 NormWt,NormWtHt,NormWtLeg,UsUnits

      real*4    Lbs,In,Gravity
      integer*4 i

      data Lbs,In,Gravity / 0.22481,39.370,9.871 / ! lbs/N,in/m,m/s^2

      if ( NormWt ) then
        do i= 1, 6
          NormLoad(i)= LoadSet(i)/(Weight*Gravity)
        end do
        if ( UsUnits ) then
          do i= 4, 6
            NormLoad(i)= NormLoad(i)*In
          end do
        end if
      else if ( NormWtHt ) then
        do i= 1, 6
          NormLoad(i)= LoadSet(i)/(Weight*Gravity*Height)
        end do
        if ( UsUnits ) then
          do i= 1,3
            NormLoad(i)= NormLoad(i)/In
          end do
        end if
      else if ( NormWtLeg ) then
        if ( Side .eq. 1 ) then ! right
          do i= 1, 6
            NormLoad(i)= LoadSet(i)/(Weight*Gravity*LegLength(1))
          end do
        else if ( Side .eq. 2 ) then ! left
          do i= 1, 6
            NormLoad(i)= LoadSet(i)/(Weight*Gravity*LegLength(2))
          end do
        else ! neither side - use average leg length
          do i= 1, 6
            NormLoad(i)= 2.0*LoadSet(i)/
     &                   (Weight*Gravity*(LegLength(1)+LegLength(2)))
          end do
        end if      
        if ( UsUnits ) then
          do i= 1,3
            NormLoad(i)= NormLoad(i)/In
          end do
        end if
      else ! no normalization...
        do i= 1, 6
          NormLoad(i)= LoadSet(i)
        end do
        if ( UsUnits ) then
          do i= 1,3
            NormLoad(i)=   NormLoad(i)*Lbs
            NormLoad(i+3)= NormLoad(i+3)*Lbs*In
          end do
        end if
      end if
      return
      end           
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcGRL( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                      ExpComb,AnimateGRL,ExpSIMM,NegateGRL,
     &                      NormWt,NormWtHt,NormWtLeg,LegLength,
     &                      UsUnits,CSType,PltNum,FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      real*4    LegLength(2)
      integer*4 PltNum,inc,CSType
      logical*4 Error,RegHeader,IgorHeader,ExpPlt,ExpFoot,ExpComb,
     &          AnimateGRL,NormWt,NormWtHt,NormWtLeg,UsUnits,NegateGRL,
     &          ExpSIMM

      real*4    TimeInc,TempLoad(12),s
      integer*4 i,j,gait_events(MAX_ELC),MtnFrm1,MtnFrm,LogtoInt
      character CompName(12)*8,LoadName(6)*2,UnitName(2)*3
      
      data LoadName / 'Fx','Fy','Fz','Mx','My','Mz' /

      Error= .true.
      if ( .not. FF.read ) goto 1000 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( UsUnits ) then
        UnitName(1)= 'lbf'
        UnitName(2)= 'ilb'
      else
        UnitName(1)= 'N  '
        UnitName(2)= 'Nm '
      end if
      if ( ExpPlt ) then         ! Export Force plate GRL data
        if ( IgorHeader ) then
          do i= 1, 6
            CompName(i)= 'GrlP'//char(48+PltNum)//LoadName(i)
          end do
          write(2,100) (CompName(i),i=1,6)
100       format(' IGOR'/
     &           ' WAVES ',a7,', ',a7,', ',a7,', ',
     &                     a7,', ',a7,', ',a7/
     &           ' BEGIN')
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              call ConvGRL( FpData(fx,i,PltNum),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,0,TempLoad )
              write(2,110) (TempLoad(j),j=1,6)
110           format(2x,6(e13.5,1x))
            else
              write(2,110) 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            end if
          end do
          write(2,119)
119       format(' END')
          do i= 1, 3
            write(2,120) TimeInc,CompName(i),UnitName(1),CompName(i)
          end do
          do i= 4, 6
            write(2,120) TimeInc,CompName(i),UnitName(2),CompName(i)
          end do
120       format(' X SetScale /P x 0,',f10.6,',"sec", ',a7/
     &           ' X SetScale y 0,0,"',a2,'", ',a7/ )
        else ! regular export
          if ( RegHeader ) then
            if ( FF.adjusted ) then
              write(2,200) PltNum,FP.frm_rate
200           format(' Individual Force Plate Data in GCS'/
     &               ' Plate # : ',i1,'   Sample Rate : ',i4,' Hz'/)
            else
              write(2,210) PltNum,FP.frm_rate
210           format(' Individual Force Plate Data in plate LCS'/
     &               ' Plate # : ',i1,'   Sample Rate : ',i4,' Hz'/)
            end if
            call PrintGRLHeader( NormWt,NormWtHt,NormWtLeg,UsUnits )
            write(2,220) 
220         format(/' Frame',2x,'OK',6x,'Fx',9x,'Fy',9x,'Fz',9x,
     &                                  'Mx',9x,'My',9x,'Mz'/)
          end if ! print header  
          do i= 1, FP.nfrm, inc
            if ( FF.adjusted ) then
              if ( FpDataOK(i,PltNum) ) then
                call ConvGRL( FpData(fx,i,PltNum),
     &                        NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                        GP.weight,GP.height,
     &                        LegLength,0,TempLoad )
                write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),
     &                       (TempLoad(j),j=1,6)
230             format(2x,i4,2x,i2,2x,6(e13.5,1x))
              else
                write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),
     &                       0.0, 0.0, 0.0, 0.0, 0.0, 0.0
              end if
            else
              call ConvGRL( FpData(fx,i,PltNum),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,0,TempLoad )
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),(TempLoad(j),j=1,6)
            end if
          end do
        end if ! Plate GRL Igor or Regular
                                          
      else if ( ExpComb ) then     ! Export combined GRL data
         if ( .not. FF.adjusted ) goto 1020 ! error
         if ( AnimateGRL ) then
            if ( .not. FF.cpr_GCS ) goto 1030 ! error
            if ( IgorHeader ) goto 1040 ! error
            if ( .not. ExpSIMM ) then
               s= -1.0
               if ( NegateGRL ) s= 1.0
               do i= 1, FP.nfrm, inc
                  write(2,235) i,float(i)*timeinc
 235              format(1x,i4,f10.4)
                  write(2,240) CmbCp(x,i), CmbCp(x,i), CmbCp(z,i),
     &                 s*CmbGrl(fx,i),s*CmbGrl(fy,i),s*CmbGrl(fz,i),
     &                 s*CmbGrl(mx,i),s*CmbGrl(my,i),s*CmbGrl(mz,i)
 240              format(9(1x,f10.4)/)
               end do   
            else
               write(2,236) 
 236           format('ground_force_px ground_force_py ground_force_pz ',
     &                'ground_force_vx ground_force_vy ground_force_vz'/)
               do i= 1, FP.nfrm, inc
                  write(2,241) CmbCp(x,i), CmbCp(x,i), CmbCp(z,i),
     &                 CmbGrl(fx,i),CmbGrl(fy,i),CmbGrl(fz,i)
 241              format(6(1x,f10.4))
               end do   
            end if

         else                   ! igor/regular export    
          if ( IgorHeader ) then   
            do i= 1, 6
              CompName(i)= 'GrlCb'//LoadName(i)
            end do
            write(2,100) (CompName(i),i=1,6)
            do i= 1, FP.nfrm, inc
              if ( FcDataOK(i) ) then
                call ConvGRL( CmbGrl(fx,i),
     &                        NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                        GP.weight,GP.height,
     &                        LegLength,0,TempLoad )
                write(2,110) (TempLoad(j),j=1,6)
              else
                write(2,110) 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
              end if
            end do
            write(2,119)
            do i= 1, 3
              write(2,120) TimeInc,CompName(i),UnitName(1),CompName(i)
            end do
            do i= 4, 6
              write(2,120) TimeInc,CompName(i),UnitName(2),CompName(i)
            end do
          else ! regular export
            if ( RegHeader ) then
              write(2,250) FP.frm_rate
250           format(' Combined Force Plate Data'/
     &               '   Sample Rate : ',i4,' Hz'/)
              call PrintGRLHeader( NormWt,NormWtHt,NormWtLeg,UsUnits )
              write(2,220) 
            end if ! print header  
            do i= 1, FP.nfrm, inc
              if ( FcDataOK(i) ) then
                call ConvGRL( CmbGrl(fx,i),
     &                        NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                        GP.weight,GP.height,
     &                        LegLength,0,TempLoad )
                write(2,230) i,LogtoInt(FcDataOK(i)),(TempLoad(j),j=1,6)
              else
                write(2,230) i,LogtoInt(FcDataOK(i)),
     &                       0.0, 0.0, 0.0, 0.0, 0.0, 0.0
              end if
            end do
          end if ! Combined GRL Igor or Regular
        end if ! normal combined GRL or AnimateGRL

      else ! ExpFoot
        if ( .not. FF.individual_feet ) goto 1050 ! error
        if ( (CSType .eq. LCS_CS) .and. 
     &       (.not. FF.cpr_LCS)    ) goto 1060 ! error
c                
c       Create an array with the gait events in it 
c
        do i= 1, MP.nfrm
          gait_events(i)= 0
        end do
        do i= 1, MP.num_rhs
          gait_events(MP.rhs_frm(i))= 1
        end do
        do i= 1, MP.num_lhs
          gait_events(MP.lhs_frm(i))= 2
        end do
        do i= 1, MP.num_rto
          gait_events(MP.rto_frm(i))= 3
        end do
        do i= 1, MP.num_lto
          gait_events(MP.lto_frm(i))= 4
        end do
        if ( (GP.analysis_type .eq. FULL_ANL) .or.
     &       (GP.analysis_type .eq. HH_ANL)   .or.
     &       (GP.analysis_type .eq. TDP_ANL)       ) then
          if ( MP.first_ft .eq. rt ) then
            MtnFrm1= MP.rhs_frm(1)
          else
            MtnFrm1= MP.lhs_frm(1)
          end if
          if ( MtnFrm1 .le. 0 ) MtnFrm1= 1
        else
          MtnFrm1= 1 ! trap added - 7/92 dam
        end if
        if ( IgorHeader ) then
          if ( CSType .eq. GCS_CS ) then
            do i= 1, 6
              CompName(i)=   'GrlFr'//LoadName(i)//'G'
              CompName(i+6)= 'GrlFl'//LoadName(i)//'G'
            end do
          else
            do i= 1, 6
              CompName(i)=   'GrlFr'//LoadName(i)//'L'
              CompName(i+6)= 'GrlFl'//LoadName(i)//'L'
            end do
          end if
          write(2,260) (CompName(i),i=1,12)
260       format(' IGOR'/
     &           ' WAVES ',11(a8,', '),a8/
     &           ' BEGIN')
          do i= 1, FP.nfrm, inc
            if ( CSType .eq. GCS_CS ) then
              call ConvGRL( FtGrl(fx,i,rt),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,rt,TempLoad(1) )
              call ConvGRL( FtGrl(fx,i,lf),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,lf,TempLoad(7) )
            else ! Foot LCS GRL
              call ConvGRL( FtGRLLCS(fx,i,rt),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,rt,TempLoad(1) )
              call ConvGRL( FtGRLLCS(fx,i,lf),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,lf,TempLoad(7) )
            end if
            write(2,270) (TempLoad(j),j=1,12)
270         format(2x,12(e13.5))
          end do
          write(2,279)
279       format(' END')
          do i= 1, 3
            write(2,280) TimeInc,CompName(i),UnitName(1),CompName(i)
          end do
          do i= 4, 6
            write(2,280) TimeInc,CompName(i),UnitName(2),CompName(i)
          end do
          do i= 7, 9
            write(2,280) TimeInc,CompName(i),UnitName(1),CompName(i)
          end do
          do i= 11, 12
            write(2,280) TimeInc,CompName(i),UnitName(2),CompName(i)
          end do
280       format(' X SetScale /P x 0,',f10.6,',"sec", ',a8/
     &           ' X SetScale y 0,0,"',a2,'", ',a8/ )
        else ! regular foot GRL export

          if ( RegHeader .and. (.not. AnimateGRL) ) then

            if ( CSType .eq. GCS_CS ) then
              write(2,290) FP.frm_rate
290           format(' Individual Foot GRL Data in Lab GCS'/
     &               '   Sample Rate : ',i4,' Hz'/)
            else ! Foot LCS
              write(2,300) FP.frm_rate
300           format(' Individual Foot GRL Data in Foot LCS'/
     &               '   Sample Rate : ',i4,' Hz'/)
            end if             

            call PrintGRLHeader( NormWt,NormWtHt,NormWtLeg,UsUnits )
            write(2,310) 
310         format('   Gait Events : 1- RHS  2- LHS'/               
     &             '                 3- RTO  4- LTO'//
     &             '   Data OK, Floor Contact : 0= false  -1=true'//
     &             ' Frame',2x,'Event',2x,'OK',2x,'Contact',5x,
     &             'RtFx',7x,'RtFy',7x,'RtFz',7x,
     &             'RtMx',7x,'RtMy',7x,'RtMz',7x,
     &              2x,'OK',2x,'Contact',5x,
     &             'LfFx',7x,'LfFy',7x,'LfFz',7x,
     &             'LfMx',7x,'LfMy',7x,'LfMz'/)
          else if ( AnimateGRL .and. ExpSIMM ) then
            write(2,311)
 311        format('ground_rt_force_px ground_rt_force_py ground_rt_force_pz',
     &             'ground_rt_force_vx ground_rt_force_vy ground_rt_force_vz'/
     &             'ground_lf_force_px ground_lf_force_py ground_lf_force_pz'/
     &             'ground_lf_force_vx ground_lf_force_vy ground_lf_force_vz')
          end if ! print header...

          s= -1.0
          if ( NegateGRL ) s= 1.0
          do i= 1, FP.nfrm, inc

            if ( CSType .eq. GCS_CS ) then
              call ConvGRL( FtGrl(fx,i,rt),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,rt,TempLoad(1) )
              call ConvGRL( FtGrl(fx,i,lf),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,lf,TempLoad(7) )
            else ! Ft LCS GRL
              call ConvGRL( FtGRLLCS(fx,i,rt),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,rt,TempLoad(1) )
              call ConvGRL( FtGRLLCS(fx,i,lf),
     &                      NormWt,NormWtHt,NormWtLeg,UsUnits,
     &                      GP.weight,GP.height,
     &                      LegLength,lf,TempLoad(7) )
            end if

            if ( FP.av_frm_ratio .gt. 0.0 ) then        
              MtnFrm= MtnFrm1 + float(i-FP.first_frm)/
     &                          FP.av_frm_ratio

              if ( MtnFrm .ge. MtnFrm1 ) then
                if ( AnimateGRL ) then
                  if ( .not. ExpSIMM ) then 
                    write(2,315) i,float(i)*timeinc
315                 format(1x,i4,2x,f10.4)
                    if ( CSType .eq. GCS_CS ) then
                       write(2,317) (FtCpGCS(j,MtnFrm,rt),j=1,3),
     &                              (s*TempLoad(j),j=1,6)
 317                   format(9(1x,f10.4))
                       write(2,317) (FtCpGCS(j,MtnFrm,lf),j=1,3),
     &                              (s*TempLoad(j),j=7,12)
                       write(2,319)
 319                   format(/)
                    else
                       write(2,317) (FtCpLCS(j,MtnFrm,rt),j=1,3),
     &                              (s*TempLoad(j),j=1,6)
                       write(2,317) (FtCpLCS(j,MtnFrm,lf),j=1,3),
     &                              (s*TempLoad(j),j=7,12)
                       write(2,319)
                    end if
                  else
                    if ( CSType .eq. GCS_CS ) then
                       write(2,317) (FtCpGCS(j,MtnFrm,rt),j=1,3),
     &                              (TempLoad(j),j=1,3)
                       write(2,317) (FtCpGCS(j,MtnFrm,lf),j=1,3),
     &                              (TempLoad(j),j=7,9)
                    else
                       write(2,317) (FtCpLCS(j,MtnFrm,rt),j=1,3),
     &                              (TempLoad(j),j=1,3)
                       write(2,317) (FtCpLCS(j,MtnFrm,lf),j=1,3),
     &                              (TempLoad(j),j=7,9)
                    end if
                  end if
                else
                  write(2,320) i,gait_events(MtnFrm),
     &                       LogtoInt(FtGrlOK(i,rt)),
     &                       LogtoInt(FlrCntct(MtnFrm,rt)),
     &                       (TempLoad(j),j=1,6),
     &                       LogtoInt(FtGrlOK(i,lf)),
     &                       LogtoInt(FlrCntct(MtnFrm,lf)),
     &                       (TempLoad(j),j=7,12)
320               format(2x,i4,2x,i1,2(2x,i2,2x,i2,2x,6(e12.4)))
                end if
              else
                if ( AnimateGRL ) then
                  if ( .not. ExpSIMM ) then
                    write(2,315) i,float(i)*timeinc
                    if ( CSType .eq. GCS_CS ) then
                       write(2,317) (FtCpGCS(j,i,rt),j=1,3),
     &                              (s*TempLoad(j),j=1,6)
                       write(2,317) (FtCpGCS(j,i,lf),j=1,3),
     &                              (s*TempLoad(j),j=7,12)
                    else
                       write(2,317) (FtCpLCS(j,i,rt),j=1,3),
     &                              (s*TempLoad(j),j=1,6)
                       write(2,317) (FtCpLCS(j,i,lf),j=1,3),
     &                              (s*TempLoad(j),j=7,12)
                    end if
                    write(2,319)
                  else
                    if ( CSType .eq. GCS_CS ) then
                       write(2,317) (FtCpGCS(j,i,rt),j=1,3),
     &                              (TempLoad(j),j=1,3)
                       write(2,317) (FtCpGCS(j,i,lf),j=1,3),
     &                              (TempLoad(j),j=7,9)
                    else
                       write(2,317) (FtCpLCS(j,i,rt),j=1,3),
     &                              (TempLoad(j),j=1,3)
                       write(2,317) (FtCpLCS(j,i,lf),j=1,3),
     &                              (TempLoad(j),j=7,9)
                    end if
                  end if
                else
                  write(2,320) i,0,
     &                       LogtoInt(FtGrlOK(i,rt)),0,(TempLoad(j),j=1,6),
     &                       LogtoInt(FtGrlOK(i,lf)),0,(TempLoad(j),j=7,12)
                end if
              end if

            else
              if ( AnimateGRL ) then
                if ( .not. ExpSIMM ) then
                  write(2,315) i,float(i)*timeinc
                  if ( CSType .eq. GCS_CS ) then
                     write(2,317) (FtCpGCS(j,i,rt),j=1,3),
     &                            (s*TempLoad(j),j=1,6)
                     write(2,317) (FtCpGCS(j,i,lf),j=1,3),
     &                            (s*TempLoad(j),j=7,12)
                  else
                     write(2,317) (FtCpLCS(j,i,rt),j=1,3),
     &                            (s*TempLoad(j),j=1,6)
                     write(2,317) (FtCpLCS(j,i,lf),j=1,3),
     &                            (s*TempLoad(j),j=7,12)
                  end if
                  write(2,319)
                else
                  if ( CSType .eq. GCS_CS ) then
                     write(2,317) (FtCpGCS(j,i,rt),j=1,3),
     &                            (s*TempLoad(j),j=1,6)
                     write(2,317) (FtCpGCS(j,i,lf),j=1,3),
     &                            (s*TempLoad(j),j=7,12)
                  else
                     write(2,317) (FtCpLCS(j,i,rt),j=1,3),
     &                            (s*TempLoad(j),j=1,3)
                     write(2,317) (FtCpLCS(j,i,lf),j=1,3),
     &                            (s*TempLoad(j),j=7,9)
                  end if
                end if
              else
                write(2,320) i,0,
     &                   LogtoInt(FtGrlOK(i,rt)),0,(TempLoad(j),j=1,6),
     &                   LogtoInt(FtGrlOK(i,lf)),0,(TempLoad(j),j=7,12)
              end if
            end if
          end do

        end if ! Igor or Regular export of foot GRL

      end if ! plate, combined or foot
      Error= .false.
      return

1000  write(5,1005)
      if ( OF.ToLog ) write(3,1005)
1005  format(' Error- Force plate data has not been read in yet')
      return
                                                      
1020  write(5,1025)
      if ( OF.ToLog ) write(3,1025)
1025  format(' Error- Force plate data has not been combined yet'/
     &       '        This is done with the FoRCe CONvert command')
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Force plate data center of pressure'/
     &       '        has not been calculated yet'/
     &       '        This is done with the FoRCe CPR command')
      return

1040  write(5,1045)
      if ( OF.ToLog ) write(3,1045)
1045  format(' Error- The /IGOr option is not valid for EXP FRC GRL COM')
      return

1050  write(5,1055)
      if ( OF.ToLog ) write(3,1055)
1055  format(' Error- GRL data has not been assigned to the feet yet'/
     &       '        This is done with the FoRCe ALIgn command')
      return

1060  write(5,1065)
      if ( OF.ToLog ) write(3,1065)
1065  format(' Error- GRL data center of pressure has not been'/
     &       '        calculated in the foot LCS yet'/
     &       '        This is done with the FoRCe LCP command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine PrintGRLHeader( NormWt,NormWtHt,NormWtLeg,UsUnits )
      implicit none

      logical*4 UsUnits,NormWt,NormWtHt,NormWtLeg
      
      if ( UsUnits ) then
        if ( NormWt ) then
          write(2,100)
100       format(' NOTE: Force plate data is normalized by patient''s weight'/
     &           '       GRL in units of lbf/lbf and inlbf/lbf')
        else if ( NormWtHt ) then
          write(2,110)
110       format(' NOTE: Force plate data is normalized by patient''s weight*height'/
     &           '       GRL in units of lbf/inlbf and inlbf/inlbf')
        else if ( NormWtLeg ) then
          write(2,120)
120       format(' NOTE: Force plate data is normalized by patient''s weight*leg length'/
     &           '       GRL in units of lbf/inlbf and inlbf/inlbf')
        else
          write(2,130)
130       format(' NOTE: GRL in units of lbf and inlbf')
        end if
      else
        if ( NormWt ) then
          write(2,140)
140       format(' NOTE: Force plate data is normalized by patient''s weight'/
     &           '       GRL in units of N/N and Nm/N')
        else if ( NormWtHt ) then
          write(2,150)
150       format(' NOTE: Force plate data is normalized by patient''s weight*height'/
     &           '       GRL in units of N/Nm and Nm/Nm')
        else if ( NormWtLeg ) then
          write(2,160)
160       format(' NOTE: Force plate data is normalized by patient''s weight*leg length'/
     &           '       GRL in units of N/Nm and Nm/Nm')
        else
          write(2,170)
170       format(' NOTE: GRL in units of N and Nm')
        end if
      end if
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcCPR( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                      ExpComb,PltNum,FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 PltNum,inc
      logical*4 Error,RegHeader,IgorHeader,ExpPlt,ExpFoot,ExpComb

      real*4    TimeInc
      integer*4 i,j,k,MtnFrm1,MtnFrm,LogtoInt
      character CompName(6)*8,DirName(3)*1
      
      data DirName / 'x','y','z' /

      Error= .true.
      if ( .not. FF.cpr_GCS ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( ExpPlt ) then         ! Export Force plate GRL data
        if ( IgorHeader ) then
          do i= 1, 3
            CompName(i)= 'CprP'//char(48+PltNum)//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,3)
100       format(' IGOR'/
     &           ' WAVES ',a6,', ',a6,', ',a6/
     &           ' BEGIN')
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,110) (FpCp(j,i,PltNum),j=1,3)
110           format(2x,3(e13.5,1x))
            else
              write(2,110) 0.0, 0.0, 0.0
            end if
          end do
          write(2,119)
119       format(' END')
          do i= 1, 3
            write(2,120) TimeInc,CompName(i),CompName(i)
          end do
120       format(' X SetScale /P x 0,',f10.6,',"sec", ',a6/
     &           ' X SetScale y 0,0,"m", ',a6/ )
        else ! regular export
          if ( RegHeader ) then
            if ( FF.adjusted ) then
              write(2,200) PltNum
200           format(' Centers of pressure (m) on force plate #',i1,' in GCS'//
     &               ' Frame  OK    x        y        z'/)
            else
              write(2,210) PltNum
210           format(' Centers of pressure (m) on force plate #',i1,' in plate LCS'//
     &             ' Frame  OK    x        y        z'/)
            end if
          end if ! print header  
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),
     &                     (FpCp(j,i,PltNum),j=1,3)
230           format(2x,i4,2x,i2,2x,3(e13.5,1x))
            else
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)), 0.0, 0.0, 0.0
            end if
          end do
        end if ! Plate CPR Igor or Regular
                                          
      else if ( ExpComb ) then     ! Export combined CPR data
        if ( .not. FF.adjusted ) goto 1020 ! error
        if ( IgorHeader ) then
          do i= 1, 3
            CompName(i)= 'CprCb'//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,3)
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,110) (CmbCp(j,i),j=1,3)
            else
              write(2,110) 0.0, 0.0, 0.0
            end if
          end do
          write(2,119)
          do i= 1, 3
            write(2,120) TimeInc,CompName(i),CompName(i)
          end do
        else ! regular export
          if ( RegHeader ) write(2,250)
250       format(' Centers of pressure (m) on combined force plate data'//
     &           ' Frame  OK    x        y        z'/)
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,230) i,LogtoInt(FcDataOK(i)),(CmbCp(j,i),j=1,3)
            else
              write(2,230) i,LogtoInt(FcDataOK(i)), 0.0, 0.0, 0.0
            end if
          end do
        end if ! Combined CPR Igor or Regular

      else ! ExpFoot
        if ( .not. FF.individual_feet ) goto 1050 ! error
        if ( (GP.analysis_type .eq. FULL_ANL) .or.
     &       (GP.analysis_type .eq. HH_ANL)   .or.
     &       (GP.analysis_type .eq. TDP_ANL)       ) then
          if ( MP.first_ft .eq. rt ) then
            MtnFrm1= MP.rhs_frm(1)
          else
            MtnFrm1= MP.lhs_frm(1)
          end if
        else
          MtnFrm1= 1 ! trap added - 7/92 dam
        end if
        if ( IgorHeader ) then
          do i= 1, 3
            CompName(i)=   'CprFr'//DirName(i)//'G'
            CompName(i+3)= 'CprFl'//DirName(i)//'G'
          end do
          write(2,260) (CompName(i),i=1,6)
260       format(' IGOR'/
     &           ' WAVES ',5(a7,', '),a7/
     &           ' BEGIN')
          do i= 1, FP.nfrm, inc
            if ( FP.av_frm_ratio .gt. 0.0 ) then        
              MtnFrm= MtnFrm1 + float(i-FP.first_frm)/FP.av_frm_ratio
              if ( MtnFrm .ge. MtnFrm1 ) then
                write(2,270) (FtCpGCS(j,i,rt),j=1,3),
     &                       (FtCpGCS(j,i,lf),j=1,3)
270             format(2x,6(e13.5))
              else
                write(2,270) ((0.0),k=1,6)
              end if
            else
              write(2,270) (FtCpGCS(j,i,rt),j=1,3),
     &                     (FtCpGCS(j,i,lf),j=1,3)
            end if
          end do
          write(2,279)
279       format(' END')
          do i= 1, 6
            write(2,280) TimeInc,CompName(i),CompName(i)
          end do
280       format(' X SetScale /P x 0,',f10.6,',"sec", ',a7/
     &           ' X SetScale y 0,0,"m", ',a7/ )
        else ! regular foot GRL export
          if ( RegHeader ) write(2,290) 
290       format(' Centers of pressure (m) for Right & Left Feet in Lab GCS'//
     &           '   Data OK, Floor Contact : 0= false  -1=true'//
     &           ' Frame  OK  Contact    Rtx        Rty        Rtz',
     &             '      OK  Contact    Lfx        Lfy        Lfz')
          do i= 1, FP.nfrm, inc
            if ( FP.av_frm_ratio .gt. 0.0 ) then        
              MtnFrm= MtnFrm1 + float(i-FP.first_frm)/
     &                          FP.av_frm_ratio
              if ( MtnFrm .ge. MtnFrm1 ) then
                write(2,320) i,LogtoInt(FtGrlOK(i,rt)),
     &                         LogtoInt(FlrCntct(MtnFrm,rt)),
     &                         (FtCpGCS(j,i,rt),j=1,3),
     &                         LogtoInt(FtGrlOK(i,lf)),
     &                         LogtoInt(FlrCntct(MtnFrm,lf)),
     &                         (FtCpGCS(j,i,lf),j=1,3)
320             format(2x,i4,2(2x,i2,2x,i2,2x,3(e12.4)))
              else
                write(2,320) i,LogtoInt(FtGrlOK(i,rt)),0,
     &                         (FtCpGCS(j,i,rt),j=1,3),
     &                         LogtoInt(FtGrlOK(i,lf)),0,
     &                         (FtCpGCS(j,i,lf),j=1,3)
              end if
            else
              write(2,320) i,LogtoInt(FtGrlOK(i,rt)),0,
     &                       (FtCpGCS(j,i,rt),j=1,3),
     &                       LogtoInt(FtGrlOK(i,lf)),0,
     &                       (FtCpGCS(j,i,lf),j=1,3)
            end if
          end do
        end if ! Igor or Regular export of foot CPR
      end if
      Error= .false.
      return

1020  write(5,1025)
      if ( OF.ToLog ) write(3,1025)
1025  format(' Error- Force plate data has not been combined yet'/
     &       '        This is done with the FoRCe CONvert command')
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Force plate data center of pressure'/
     &       '        has not been calculated yet'/
     &       '        This is done with the FoRCe CPR command')
      return

1050  write(5,1055)
      if ( OF.ToLog ) write(3,1055)
1055  format(' Error- GRL data has not been assigned to the feet yet'/
     &       '        This is done with the FoRCe ALIgn command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcLCP( inc,RegHeader,IgorHeader,
     &                      FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 inc
      logical*4 Error,RegHeader,IgorHeader

      real*4    TimeInc
      integer*4 i,j,LogtoInt
      character CompName(6)*8,DirName(3)*1
      
      data DirName / 'x','y','z' /

      Error= .true.
      if ( .not. FF.cpr_LCS ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( IgorHeader ) then
        do i= 1, 3
          CompName(i)=   'CprFr'//DirName(i)//'L'
          CompName(i+3)= 'CprFl'//DirName(i)//'L'
        end do
        write(2,260) (CompName(i),i=1,6)
260     format(' IGOR'/
     &         ' WAVES ',5(a7,', '),a7/
     &         ' BEGIN')
        do i= 1, FP.nfrm, inc
          write(2,270) (FtCpLCS(j,i,rt),j=1,3),
     &                 (FtCpLCS(j,i,lf),j=1,3)
270       format(2x,6(e13.5))
        end do
        write(2,279)
279     format(' END')
        do i= 1, 6
          write(2,280) TimeInc,CompName(i),CompName(i)
        end do
280     format(' X SetScale /P x 0,',f10.6,',"sec", ',a7/
     &         ' X SetScale y 0,0,"m", ',a7/ )
     
      else ! regular foot LCP export
        if ( RegHeader ) write(2,290) 
290     format(' Centers of pressure (m) for Right & Left Feet in foot LCS'//
     &         '   Data OK, Floor Contact : 0= false  -1=true'//
     &         ' Frame  OK  Contact    Rtx        Rty        Rtz',
     &           '      OK  Contact    Lfx        Lfy        Lfz')
        do i= 1, FP.nfrm, inc
          write(2,320) i,LogtoInt(FtGrlOK(i,rt)),
     &                   LogtoInt(FlrCntct(i,rt)),
     &                   (FtCpLCS(j,i,rt),j=1,3),
     &                   LogtoInt(FtGrlOK(i,lf)),
     &                   LogtoInt(FlrCntct(i,lf)),
     &                   (FtCpLCS(j,i,lf),j=1,3)
320       format(2x,i4,2(2x,i2,2x,i2,2x,3(e12.4)))
        end do
      end if ! Igor or Regular export of foot LCP
      Error= .false.
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Foot LCS center of pressure has not been calculated yet'/
     &       '        This is done with the FoRCe LCP command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcWre( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                      ExpComb,PltNum,FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 PltNum,inc
      logical*4 Error,RegHeader,IgorHeader,ExpPlt,ExpFoot,ExpComb

      real*4    TimeInc
      integer*4 i,j,k,side,LogtoInt
      character CompName(8)*12,DirName(8)*3,UnitName(8)*3
      
      data DirName / 'Nx ','Ny ','Nz ','Px ','Py ','Pz ','Mom','Frc' /
      data UnitName / 'cos','cos','cos','m  ','m  ','m  ','Nm ','N  '/
     
      Error= .true.
      if ( .not. FF.Wrench ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( ExpPlt ) then         ! Export Force plate Wrench data
        if ( IgorHeader ) then
          do i= 1, 8
            CompName(i)= 'GrlWreP'//char(48+PltNum)//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,8)
100       format(' IGOR'/
     &           ' WAVES ',7(a11,', '),a11/
     &           ' BEGIN')
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,110) (FpWre(j,i,PltNum),j=1,8)
110           format(2x,8(e13.5,1x))
            else
              write(2,110) ((0.0),k=1,8)
            end if
          end do
          write(2,119)
119       format(' END')
          do i= 1, 8
            write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
          end do
120       format(' X SetScale /P x 0,',f10.6,',"sec", ',a11/
     &           ' X SetScale y 0,0,"',a3,'", ',a11/ )
        else ! regular export
          if ( RegHeader ) then
            if ( FF.adjusted ) then
              write(2,200) PltNum
200           format(' Ground Reaction Load Wrenches on force plate #',i1,
     &               ' in GCS'//)
            else
              write(2,210) PltNum
210           format(' Ground Reaction Load Wrenches on force plate #',i1,
     &               ' in plate LCS'//)
            end if
            write(2,220)
220         format(' Frame',2x,'DataOK',11x,'Wrench Axis',18x,
     &             'Point on Wrench (m)',10x,
     &             'Moment (Nm)',2x,'Force (N)'//)         
          end if ! print header  
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),
     &                     (FpWre(j,i,PltNum),j=1,8)
230           format(2x,i4,2x,i2,2x,8(e13.5,1x))
            else
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),((0.0),k=1,8)
            end if
          end do
        end if ! Plate Wrench Igor or Regular
                                          
      else if ( ExpComb ) then     ! Export combined CPR data
        if ( .not. FF.adjusted ) goto 1020 ! error
        if ( IgorHeader ) then
          do i= 1, 8
            CompName(i)= 'GrlWreCb'//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,8)
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,110) (CmbGrlWre(j,i),j=1,8)
            else
              write(2,110) ((0.0),k=1,8)
            end if
          end do
          write(2,119)
          do i= 1, 8
            write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
          end do
        else ! regular export
          if ( RegHeader ) then
            write(2,250)
250         format(' GRL Wrenches for combined force plate data'/)
            write(2,220)
          end if
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,230) i,LogtoInt(FcDataOK(i)),(CmbGrlWre(j,i),j=1,8)
            else
              write(2,230) i,LogtoInt(FcDataOK(i)),((0.0),k=1,8)
            end if
          end do
        end if ! Combined wrench Igor or Regular

      else ! ExpFoot
        if ( .not. FF.individual_feet ) goto 1050 ! error
        if ( IgorHeader ) then
          do side= rt, lf
            if ( side .eq. rt ) then
              do i= 1, 8
                CompName(i)= 'GrlWreFr'//DirName(i)
              end do
            else
              do i= 1, 8
                CompName(i)= 'GrlWreFl'//DirName(i)
              end do
            end if
            write(2,100) (CompName(i),i=1,8)
            do i= 1, FP.nfrm, inc
              if ( FtGrlOK(i,side) ) then
                write(2,110) (FtGRLWre(j,i,side),j=1,8)
              else
                write(2,110) ((0.0),k=1,8)
              end if
            end do
            write(2,119)
            do i= 1, 8
              write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
            end do
          end do ! side
        else ! regular foot GRL export
          if ( RegHeader ) write(2,290) 
290       format(' Wrenches for Right & Left Feet in Lab GCS'//
     &           ' Frame',11x,'Wrench Axis',18x,'Point on Wrench',10x,
     &           'Moment (Nm)',2x,'Force (N)'/
     &            8x,'RtNx        RtNy        RtNz    ',
     &           '    RtPx        RtPy        RtPz    ',
     &           '    RtMom       RtFrc    ',
     &           '    LfNx        LfNy        LfNz    ',
     &           '    LfPx        LfPy        LfPz    ',
     &           '    LfMom       LfFrc'/)
          do i= 1, FP.nfrm, inc
            if ( FtGrlOK(i,rt) .and. FtGrlOK(i,lf) ) then
              write(2,320) i,(FtGRLWre(j,i,rt),j=1,8),
     &                       (FtGRLWre(j,i,lf),j=1,8)
320           format(2x,i4,2x,16(e12.4))
            else if ( FtGrlOK(i,rt) ) then
               write(2,320) i,(FtGRLWre(j,i,rt),j=1,8),
     &                        ((0.0),k=1,8)
            else if ( FtGrlOK(i,lf) ) then
              write(2,320) i,((0.0),k=1,8),
     &                       (FtGRLWre(j,i,lf),j=1,8)
            else
              write(2,320) i,((0.0),k=1,16)
            end if
         end do
        end if ! Igor or Regular export of foot wrench
      end if
      Error= .false.
      return

1020  write(5,1025)
      if ( OF.ToLog ) write(3,1025)
1025  format(' Error- Force plate data has not been combined yet'/
     &       '        This is done with the FoRCe CONvert command')
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Force plate wrench data has not been calculated yet'/
     &       '        This is done with the FoRCe WREnch command')
      return

1050  write(5,1055)
      if ( OF.ToLog ) write(3,1055)
1055  format(' Error- GRL data has not been assigned to the feet yet'/
     &       '        This is done with the FoRCe ALIgn command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcSI( inc,RegHeader,IgorHeader,
     &                     FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 inc
      logical*4 Error,RegHeader,IgorHeader

      real*4    TimeInc
      integer*4 i,j
      
      Error= .true.
      if ( .not. FF.StrIdx ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( IgorHeader ) then
        write(2,260) 
260     format(' IGOR'/
     &         ' WAVES GrlFsiR, GrlFsiL'/
     &         ' BEGIN')
        do i= 1, FP.nfrm, inc
          if ( FtGrlOK(i,rt) .and. FtGrlOK(i,lf) ) then
            write(2,270) (StrIdx(i,j),j=1,2)
270         format(2x,2(e12.4))
          else if ( FtGrlOK(i,rt) ) then
            write(2,270) StrIdx(i,rt), 0.0
          else if ( FtGrlOK(i,lf) ) then
            write(2,270) 0.0, StrIdx(i,lf)
          else
            write(2,270) 0.0, 0.0
          end if
        end do
        write(2,280) ((TimeInc),i=1,2)
280     format(' END'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", GrlFsiR'/
     &         ' X SetScale y 0,0,"m", GrlFsiR'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", GrlFsiL'/
     &         ' X SetScale y 0,0,"m", GrlFsiL')
      else ! regular foot SI export
        if ( RegHeader ) write(2,290) 
290     format(' Strike Index for feet'//
     &         ' Frame      Right     Left'/)
        do i= 1, FP.nfrm, inc
          if ( FtGrlOK(i,rt) .and. FtGrlOK(i,lf) ) then
            write(2,300) i,(StrIdx(i,j),j=1,2)
300         format(2x,i4,2x,2f11.4)
          else if ( FtGrlOK(i,rt) ) then
            write(2,300) i,StrIdx(i,rt), 0.0
          else if ( FtGrlOK(i,lf) ) then
            write(2,300) i, 0.0, StrIdx(i,lf)
          else   
            write(2,300) i, 0.0, 0.0
          end if
        end do
      end if ! Igor or Regular export of foot SI
      Error= .false.
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Foot Strike Index has not been calculated yet'/
     &       '        This is done with the FoRCe FSI command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcInt1( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                       ExpComb,PltNum,FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 PltNum,inc
      logical*4 Error,RegHeader,IgorHeader,ExpPlt,ExpFoot,ExpComb

      real*4    TimeInc
      integer*4 i,j,k,side,LogtoInt
      character CompName(4)*10,DirName(4)*2,UnitName(4)*3
      
      data DirName / 'Fx','Fy','Fz','Mz' /
      data UnitName / 'Ns ','Ns ','Ns ','Nms' /
     
      Error= .true.
      if ( .not. FF.Integral ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( ExpPlt ) then         ! Export Force plate 1st Integral
        if ( IgorHeader ) then
          do i= 1, 4
            CompName(i)= 'GrlIntP'//char(48+PltNum)//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,4)
100       format(' IGOR'/
     &           ' WAVES ',3(a10,', '),a10/
     &           ' BEGIN')
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,110) (PltIntegral(j,i,PltNum),j=1,4)
110           format(2x,4(e13.5,1x))
            else
              write(2,110) ((0.0),k=1,4)
            end if
          end do
          write(2,119)
119       format(' END')
          do i= 1, 4
            write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
          end do
120       format(' X SetScale /P x 0,',f10.6,',"sec", ',a10/
     &           ' X SetScale y 0,0,"',a3,'", ',a10/ )
        else ! regular export
          if ( RegHeader ) then
            if ( FF.adjusted ) then
              write(2,200) PltNum
200           format(' First Integral of GRL on force plate #',i1,
     &               ' in GCS'//)
            else
              write(2,210) PltNum
210           format(' First Integral of GRL on force plate #',i1,
     &               ' in plate LCS'//)
            end if
            write(2,220)
220         format(' Frame',2x,'DataOK',11x,'First Integral (Ns,Js)'/
     &             16x,'Fx',11x,'Fy',11x,'Fz',11x,'Mz'/)
          end if ! print header  
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),
     &                       (PltIntegral(j,i,PltNum),j=1,4)
230           format(2x,i4,2x,i2,2x,4(e13.5,1x))
            else
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),((0.0),k=1,4)
            end if
          end do
        end if ! Plate 1st Integral Igor or Regular
                                          
      else if ( ExpComb ) then     ! Export combined GRL 1st Integral data
        if ( .not. FF.adjusted ) goto 1020 ! error
        if ( IgorHeader ) then
          do i= 1, 4
            CompName(i)= 'GrlIntCb'//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,4)
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,110) (CombIntegral(j,i),j=1,4)
            else
              write(2,110) ((0.0),k=1,4)
            end if
          end do
          write(2,119)
          do i= 1, 4
            write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
          end do
        else ! regular export
          if ( RegHeader ) then
            write(2,250)
250         format(' First Integral of combined GRL data'/)
            write(2,220)
          end if
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,230) i,LogtoInt(FcDataOK(i)),
     &                       (CombIntegral(j,i),j=1,4)
            else
              write(2,230) i,LogtoInt(FcDataOK(i)),((0.0),k=1,4)
            end if
          end do
        end if ! Combined 1st Integral Igor or Regular

      else ! ExpFoot
        if ( .not. FF.individual_feet ) goto 1050 ! error
        if ( IgorHeader ) then
          do side= rt, lf
            if ( side .eq. rt ) then
              do i= 1, 4
                CompName(i)= 'GrlIntFr'//DirName(i)
              end do
            else
              do i= 1, 4
                CompName(i)= 'GrlIntFl'//DirName(i)
              end do
            end if
            if ( side .eq. rt ) then
              write(2,100) (CompName(i),i=1,4)
            else
              write(2,285) (CompName(i),i=1,4)
285           format(/' WAVES ',3(a10,', '),a10/' BEGIN')
            end if
            do i= 1, FP.nfrm, inc
              if ( FtGrlOK(i,side) ) then
                write(2,110) (FtIntegral(j,i,side),j=1,4)
              else
                write(2,110) ((0.0),k=1,4)
              end if
            end do
            write(2,119)
            do i= 1, 4
              write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
            end do
          end do ! side
        else ! regular foot GRL export
          if ( RegHeader ) write(2,290) 
290       format(' First Integral for Right & Left Feet GRL in Lab GCS'//
     &           ' Frame',10x,'Right First Integral (Ns,Js)',
     &                    20x,'Left First Integral (Ns,Js)'/
     &            2(16x,'Fx',11x,'Fy',11x,'Fz',11x,'Mz')/)
          do i= 1, FP.nfrm, inc
            if ( FtGrlOK(i,rt) .and. FtGrlOK(i,lf) ) then
              write(2,320) i,(FtIntegral(j,i,rt),j=1,4),
     &                       (FtIntegral(j,i,lf),j=1,4)
320           format(2x,i4,2x,8(e12.4))
            else if ( FtGrlOK(i,rt) ) then
               write(2,320) i,(FtIntegral(j,i,rt),j=1,4),
     &                        ((0.0),k=1,4)
            else if ( FtGrlOK(i,lf) ) then
              write(2,320) i,((0.0),k=1,4),
     &                       (FtIntegral(j,i,lf),j=1,4)
            else
              write(2,320) i,((0.0),k=1,8)
            end if
         end do
        end if ! Igor or Regular export of foot GRL 1st Integral
      end if
      Error= .false.
      return

1020  write(5,1025)
      if ( OF.ToLog ) write(3,1025)
1025  format(' Error- Force plate data has not been combined yet'/
     &       '        This is done with the FoRCe CONvert command')
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Force plate Integral data has not been calculated yet'/
     &       '        This is done with the FoRCe INTegrate command')
      return

1050  write(5,1055)
      if ( OF.ToLog ) write(3,1055)
1055  format(' Error- GRL data has not been assigned to the feet yet'/
     &       '        This is done with the FoRCe ALIgn command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcInt2( inc,RegHeader,IgorHeader,ExpPlt,ExpFoot,
     &                       ExpComb,PltNum,FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 PltNum,inc
      logical*4 Error,RegHeader,IgorHeader,ExpPlt,ExpFoot,ExpComb

      real*4    TimeInc
      integer*4 i,j,k,side,LogtoInt
      character CompName(4)*11,DirName(4)*2,UnitName(4)*3
      
      data DirName / 'Fx','Fy','Fz','Mz' /
      data UnitName / 'Ns2','Ns2','Ns2','Js2' /
     
      Error= .true.
      if ( .not. FF.Integral ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( ExpPlt ) then         ! Export Force plate 2nd Integral
        if ( IgorHeader ) then
          do i= 1, 4
            CompName(i)= 'GrlInt2P'//char(48+PltNum)//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,4)
100       format(' IGOR'/
     &           ' WAVES ',3(a11,', '),a11/
     &           ' BEGIN')
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,110) (PltIntegral2(j,i,PltNum),j=1,4)
110           format(2x,4(e13.5,1x))
            else
              write(2,110) ((0.0),k=1,4)
            end if
          end do
          write(2,119)
119       format(' END')
          do i= 1, 4
            write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
          end do
120       format(' X SetScale /P x 0,',f10.6,',"sec", ',a11/
     &           ' X SetScale y 0,0,"',a3,'", ',a11/ )
        else ! regular export
          if ( RegHeader ) then
            if ( FF.adjusted ) then
              write(2,200) PltNum
200           format(' Second Integral of GRL on force plate #',i1,
     &               ' in GCS'//)
            else
              write(2,210) PltNum
210           format(' Second Integral of GRL on force plate #',i1,
     &               ' in plate LCS'//)
            end if
            write(2,220)
220         format(' Frame',2x,'DataOK',11x,'Second Integral (Ns^2,Js^2)'/
     &             16x,'Fx',11x,'Fy',11x,'Fz',11x,'Mz'/)
          end if ! print header  
          do i= 1, FP.nfrm, inc
            if ( FpDataOK(i,PltNum) ) then
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),
     &                       (PltIntegral2(j,i,PltNum),j=1,4)
230           format(2x,i4,2x,i2,2x,4(e13.5,1x))
            else
              write(2,230) i,LogtoInt(FpDataOK(i,PltNum)),((0.0),k=1,4)
            end if
          end do
        end if ! Plate 2nd Integral Igor or Regular
                                          
      else if ( ExpComb ) then     ! Export combined GRL 2nd Integral data
        if ( .not. FF.adjusted ) goto 1020 ! error
        if ( IgorHeader ) then
          do i= 1, 4
            CompName(i)= 'GrlInt2Cb'//DirName(i)
          end do
          write(2,100) (CompName(i),i=1,4)
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,110) (CombIntegral2(j,i),j=1,4)
            else
              write(2,110) ((0.0),k=1,4)
            end if
          end do
          write(2,119)
          do i= 1, 4
            write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
          end do
        else ! regular export
          if ( RegHeader ) then
            write(2,250)
250         format(' Second Integral of combined GRL data'/)
            write(2,220)
          end if
          do i= 1, FP.nfrm, inc
            if ( FcDataOK(i) ) then
              write(2,230) i,LogtoInt(FcDataOK(i)),
     &                       (CombIntegral2(j,i),j=1,4)
            else
              write(2,230) i,LogtoInt(FcDataOK(i)),((0.0),k=1,4)
            end if
          end do
        end if ! Combined 2nd Integral Igor or Regular

      else ! ExpFoot
        if ( .not. FF.individual_feet ) goto 1050 ! error
        if ( IgorHeader ) then
          do side= rt, lf
            if ( side .eq. rt ) then
              do i= 1, 4
                CompName(i)= 'GrlInt2Fr'//DirName(i)
              end do
            else
              do i= 1, 4
                CompName(i)= 'GrlInt2Fl'//DirName(i)
              end do
            end if
            if ( side .eq. rt ) then
              write(2,100) (CompName(i),i=1,4)
            else
              write(2,285) (CompName(i),i=1,4)
285           format(/' WAVES ',3(a10,', '),a10/' BEGIN')
            end if
            do i= 1, FP.nfrm, inc
              if (FtGrlOK(i,side) ) then        
                write(2,110) (FtIntegral2(j,i,side),j=1,4)
              else
                write(2,110) ((0.0),k=1,4)
              end if
            end do
            write(2,119)
            do i= 1, 4
              write(2,120) TimeInc,CompName(i),UnitName(i),CompName(i)
            end do
          end do ! side
        else ! regular foot GRL export
          if ( RegHeader ) write(2,290) 
290       format(' Second Integral for Right & Left Feet GRL in Lab GCS'//
     &           ' Frame',10x,'Right First Integral (Ns^2,Js^2)',
     &                    20x,'Left First Integral (Ns^2,Js^2)'/
     &            2(16x,'Fx',11x,'Fy',11x,'Fz',11x,'Mz')/)
          do i= 1, FP.nfrm, inc
            if ( FtGrlOK(i,rt) .and. FtGrlOK(i,lf) ) then
              write(2,320) i,(FtIntegral2(j,i,rt),j=1,4),
     &                       (FtIntegral2(j,i,lf),j=1,4)
320           format(2x,i4,2x,8(e12.4))
            else if ( FtGrlOK(i,rt) ) then
               write(2,320) i,(FtIntegral2(j,i,rt),j=1,4),
     &                        ((0.0),k=1,4)
            else if ( FtGrlOK(i,lf) ) then
              write(2,320) i,((0.0),k=1,4),
     &                       (FtIntegral2(j,i,lf),j=1,4)
            else
              write(2,320) i,((0.0),k=1,8)
            end if
         end do
        end if ! Igor or Regular export of foot GRL 2nd Integral
      end if
      Error= .false.
      return

1020  write(5,1025)
      if ( OF.ToLog ) write(3,1025)
1025  format(' Error- Force plate data has not been combined yet'/
     &       '        This is done with the FoRCe CONvert command')
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Force plate Integral data has not been calculated yet'/
     &       '        This is done with the FoRCe INTegrate command')
      return

1050  write(5,1055)
      if ( OF.ToLog ) write(3,1055)
1055  format(' Error- GRL data has not been assigned to the feet yet'/
     &       '        This is done with the FoRCe ALIgn command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcPma( inc,RegHeader,IgorHeader,CSType,
     &                      FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 inc,CSType
      logical*4 Error,RegHeader,IgorHeader

      real*4    TimeInc
      integer*4 i,j,LogtoInt
      character CS*3
      
      Error= .true.
      if ( .not. FF.PitchMomArm ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( IgorHeader ) then
        if ( CSType .eq. PRO_CS ) then ! Pelvis
          CS= 'Plv'
        else if ( CSType .eq. DIS_CS ) then ! trunk
          CS= 'Trk'
        else ! GCS
          CS= 'Gcs'
        end if
        write(2,260) (CS,i=1,4)
260     format(' IGOR'/
     &         ' WAVES Pma',a3,'X, Pma',a3,'Y, Pma',a3,'Z, Pma',a3,'Mag'/
     &         ' BEGIN')
        do i= 1, FP.nfrm, inc
          if ( FcDataOK(i) ) then
            if ( CSType .eq. PRO_CS ) then
              write(2,270) (PmaPlvLCS(j,i),j=1,3),
     &                     PmaGCS(4,i)
270           format(2x,4(e13.5))
            else if ( CSType .eq. DIS_CS ) then
              write(2,270) (PmaTrkLCS(j,i),j=1,3),
     &                     PmaGCS(4,i)
            else ! GCS
              write(2,270) (PmaGCS(j,i),j=1,4)
            end if
          else
            write(2,270) 0.0, 0.0, 0.0, 0.0
          end if
        end do
        write(2,280) TimeInc,CS,CS,TimeInc,CS,CS,TimeInc,CS,CS,TimeInc,CS,CS
280     format(' END'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pma',a3,'X'/
     &         ' X SetScale y 0,0,"m", Pma',a3,'X'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pma',a3,'Y'/
     &         ' X SetScale y 0,0,"m", Pma',a3,'Y'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pma',a3,'Z'/
     &         ' X SetScale y 0,0,"m", Pma',a3,'Z'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pma',a3,'Mag'/
     &         ' X SetScale y 0,0,"m", Pma',a3,'Mag')
      else ! regular pitch moment arm export
        if ( RegHeader ) then
          if ( CSType .eq. PRO_CS ) then
            write(2,290) 
290         format(' Pitching Moment Arm (m) relative to pelvis LCS'/)
          else if ( CSType .eq. DIS_CS ) then
            write(2,292) 
292         format(' Pitching Moment Arm (m) relative to trunk LCS'/)
          else 
            write(2,294) 
294         format(' Pitching Moment Arm (m) relative to Lab GCS'/)
          end if
          write(2,296)
296       format(' Frame',6x,'X',12x,'Y',12x,'Z',11x,'Mag'/)
        end if
        do i= 1, FP.nfrm, inc
          if ( FcDataOK(i) ) then
            if ( CSType .eq. PRO_CS ) then
              write(2,300) i,(PmaPlvLCS(j,i),j=1,3),
     &                       PmaGCS(4,i)
300           format(2x,i4,2x,4(e13.5))
            else if ( CSType .eq. DIS_CS ) then
              write(2,300) i,(PmaTrkLCS(j,i),j=1,3),
     &                       PmaGCS(4,i)
            else ! GCS
              write(2,300) i,(PmaGCS(j,i),j=1,4)
            end if
          else
            write(2,300) i, 0.0, 0.0, 0.0, 0.0
          end if
        end do
      end if ! Igor or Regular export of pitch moment arm
      Error= .false.
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Pitching Moment Arm has not been calculated yet'/
     &       '        This is done with the command FRC PMA')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcPwa( inc,RegHeader,IgorHeader,CSType,
     &                      FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 inc,CSType
      logical*4 Error,RegHeader,IgorHeader

      real*4    TimeInc
      integer*4 i,j,LogtoInt
      character CS*3
      
      Error= .true.
      if ( .not. FF.PitchWreArm ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( IgorHeader ) then
        if ( CSType .eq. PRO_CS ) then ! Pelvis
          CS= 'Plv'
        else if ( CSType .eq. DIS_CS ) then ! trunk
          CS= 'Trk'
        else ! GCS
          CS= 'Gcs'
        end if
        write(2,260) (CS,i=1,4)
260     format(' IGOR'/
     &         ' WAVES Pwa',a3,'X, Pwa',a3,'Y, Pwa',a3,'Z, Pwa',a3,'Mag'/
     &         ' BEGIN')
        do i= 1, FP.nfrm, inc
          if ( FcDataOK(i) ) then
            if ( CSType .eq. PRO_CS ) then
              write(2,270) (PwaPlvLCS(j,i),j=1,3),
     &                     PwaGCS(4,i)
270           format(2x,4(e13.5))
            else if ( CSType .eq. DIS_CS ) then
              write(2,270) (PwaTrkLCS(j,i),j=1,3),
     &                     PwaGCS(4,i)
            else ! GCS
              write(2,270) (PwaGCS(j,i),j=1,4)
            end if
          else
            write(2,270) 0.0, 0.0, 0.0, 0.0
          end if
        end do
        write(2,280) TimeInc,CS,CS,TimeInc,CS,CS,TimeInc,CS,CS,TimeInc,CS,CS
280     format(' END'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pwa',a3,'X'/
     &         ' X SetScale y 0,0,"m", Pwa',a3,'X'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pwa',a3,'Y'/
     &         ' X SetScale y 0,0,"m", Pwa',a3,'Y'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pwa',a3,'Z'/
     &         ' X SetScale y 0,0,"m", Pwa',a3,'Z'/
     &         ' X SetScale /P x 0,',f10.6,',"sec", Pwa',a3,'Mag'/
     &         ' X SetScale y 0,0,"m", Pwa',a3,'Mag')
      else ! regular pitch wrench arm export
        if ( RegHeader ) then
          if ( CSType .eq. PRO_CS ) then
            write(2,290) 
290         format(' Pitching Wrench Arm (m) relative to pelvis LCS'/)
          else if ( CSType .eq. DIS_CS ) then
            write(2,292) 
292         format(' Pitching Wrench Arm (m) relative to trunk LCS'/)
          else 
            write(2,294) 
294         format(' Pitching Wrench Arm (m) relative to Lab GCS'/)
          end if
          write(2,296)
296       format(' Frame',6x,'X',12x,'Y',12x,'Z',11x,'Mag'/)
        end if
        do i= 1, FP.nfrm, inc
          if ( FcDataOK(i) ) then
            if ( CSType .eq. PRO_CS ) then
              write(2,300) i,(PwaPlvLCS(j,i),j=1,3),
     &                       PwaGCS(4,i)
300           format(2x,i4,2x,4(e13.5))
            else if ( CSType .eq. DIS_CS ) then
              write(2,300) i,(PwaTrkLCS(j,i),j=1,3),
     &                       PwaGCS(4,i)
            else ! GCS
              write(2,300) i,(PwaGCS(j,i),j=1,4)
            end if
          else
            write(2,300) i, 0.0, 0.0, 0.0, 0.0
          end if
        end do
      end if ! Igor or Regular export of pitch wrench arm
      Error= .false.
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- Pitching Wrench Arm has not been calculated yet'/
     &       '        This is done with the FoRCe PWA command')
      return
      end
c
c
c
c
c     Copyright by Dwight Meglan 1990
c
      subroutine ExpFrcCpv( inc,RegHeader,IgorHeader,
     &                      FF,OF,error )
      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 /force_flag/   FF
      record /option_flag/  OF
      
      integer*4 inc
      logical*4 Error,RegHeader,IgorHeader

      real*4    TimeInc
      integer*4 i,j,k,LogtoInt
      character CompName(6)*9
      
      data CompName / 'CprVelRtX','CprVelRtY','CprVelRtZ',
     &                'CprVelLfX','CprVelLfY','CprVelLfZ' /
      
      Error= .true.
      if ( .not. FF.CprVelGCS ) goto 1030 ! error
      TimeInc= float(inc)/float(FP.frm_rate)
      if ( IgorHeader ) then
        write(2,260) (CompName(i),i=1,6)
260     format(' IGOR'/
     &         ' WAVES ',5(a9,', '),a9/
     &         ' BEGIN')
        do i= 1, FP.nfrm, inc
          if ( FtGrlOK(i,rt) .and. FtGrlOK(i,lf) ) then
            write(2,270) ((FtCprVelGCS(k,i,j),k=1,3),j=1,2)
270         format(2x,6(e12.4))
          else if ( FtGrlOK(i,rt) ) then
            write(2,270) (FtCprVelGCS(k,i,rt),k=1,3), 0.0, 0.0, 0.0
          else if ( FtGrlOK(i,lf) ) then
            write(2,270) 0.0, 0.0, 0.0, (FtCprVelGCS(k,i,lf),k=1,3)
          else
            write(2,270) ((0.0),k=1,6)
          end if
        end do
        write(2,279)
279     format(' END')
        do i= 1, 6
          write(2,280) TimeInc,CompName(i),CompName(i)
        end do
280     format(' X SetScale /P x 0,',f10.6,',"sec", ',a9/
     &         ' X SetScale y 0,0,"m/s", ',a9/ )
      else ! regular CPR Velocity export
        if ( RegHeader ) write(2,290) 
290     format(' Center of Pressure Velocity (m/s) for feet in GCS'//
     &         ' Frame',6x,'RtX',10x,'RtY',10x,'RtZ',10x,
     &                     'LfX',10x,'LfY',10x,'LfZ'/)
        do i= 1, FP.nfrm, inc
          if ( FtGrlOK(i,rt) .and. FtGrlOK(i,lf) ) then
            write(2,300) i,((FtCprVelGCS(k,i,j),k=1,3),j=1,2)
300         format(2x,i4,2x,6(e13.5))
          else if ( FtGrlOK(i,rt) ) then
            write(2,300) i,(FtCprVelGCS(k,i,rt),k=1,3), 0.0, 0.0, 0.0
          else if ( FtGrlOK(i,lf) ) then
            write(2,300) i, 0.0, 0.0, 0.0, (FtCprVelGCS(k,i,lf),k=1,3)
          else
            write(2,300) i,((0.0),k=1,6)
          end if
        end do
      end if ! Igor or Regular export of CPR Velocity
      Error= .false.
      return

1030  write(5,1035)
      if ( OF.ToLog ) write(3,1035)
1035  format(' Error- CPR velocity has not been calculated yet'/
     &       '        This is done with the FoRCe CPV command')
      return
      end
c
c
c
      function LogtoInt( logval )
      implicit none

      logical*4 logval
      integer*4 LogtoInt

      LogtoInt= 0
      if ( logval ) LogtoInt= 1
      return
      end 
