C$Procedure SUBINT ( Calculates a sets of Chebyshev polynomuals
C                    coefficients for a given subinterval )

      SUBROUTINE SUBINT ( I0, NSUB, U, F, IVEL, D, DM, C )
      
C$ Abstract
C
C     Subroutine returns a set of factors to Chebyshev's polynomials
C     and errors of approximation with various polynomials degrees
C     for subinterval
C
C$ Declarations
C

      IMPLICIT            NONE
      
      INCLUDE             'ckparam.inc'
      INCLUDE             'makeck4.inc'

      INTEGER             I0
      INTEGER             NSUB
      DOUBLE PRECISION    U    ( * )
      DOUBLE PRECISION    F    ( QAVSIZ, * )
      INTEGER             IVEL
      DOUBLE PRECISION    D    ( QAVSIZ, * )
      DOUBLE PRECISION    DM   ( QAVSIZ, * )
      DOUBLE PRECISION    C    ( QAVSIZ, * )
C
C$ Copyright
C
C     Copyright (1997-1998), Jet Propulsion Laboratory
C
C$ Required_Reading
C
C   
C  Keywords
C
C     CHEBYSHEV
C     POLYNOMIAL APPROXIMATION
C
C
C$ Brief_I/O
C
C     Variable  I/O  Description
C     --------  ---  --------------------------------------------------
C     I0         I   start number of immediate subinterval under
C                    processing.
C     NSUB       I   number of nodes in the subinterval - 1.
C     U          I   array of input arguments (time of telemetric
C                    measurements).
C     F          I   array of function values, corresponding to the
C                    input arguments.
C     IVEL       I   pointer: if a data about angular velocities is
C                    included (IVEL = 1) or not included (IVEL = 0).
C     D          O   array of mean root deviations for various orders
C                    of polynomials.
C     DM         O   array of maximum modules of deviations for
C                    different orders of polynomials.
C     C          O   array of a set of factors to Chebyshev's
C                    polynomials.
C
C$ Local parameters

C
C     Parameters from 'ckparam.inc'
C
C     CK4MXD         Max degree of Chebyshev polynomials.
C
C     QSIZ           count of the quaternion components.
C
C     QAVSIZ         count of the quaternion and angular rate 
C                    components together.
C

C
C     Local parameters.
C
C     NCOEFF         Max number of coefficients in each polynomial.
C
C
      INTEGER               NCOEFF
      PARAMETER           ( NCOEFF = CK4MXD + 1 )

C
C     Local variables.
C
      DOUBLE PRECISION  US    ( NUMPNT )
      DOUBLE PRECISION  FS    ( QAVSIZ, NUMPNT )
      DOUBLE PRECISION  FSJ   ( NUMPNT )
      DOUBLE PRECISION  CJ    ( NCOEFF )
      DOUBLE PRECISION  DJ    ( NCOEFF )
      DOUBLE PRECISION  DMJ   ( NCOEFF )

      INTEGER           NODES
      INTEGER           I
      INTEGER           J
      INTEGER           NPAR
      
C
C     Determine number of parameters (QAVSIZ if angular velocities are
C     included or QSIZ if not included)
C
      IF ( IVEL .EQ. 1 ) THEN
         NPAR = QAVSIZ
      ELSE
         NPAR = QSIZ
      END IF

C
C     Fill in array US with subinterval's nodes
C
      NODES = NSUB +1  

C
C     Cycle for subinterval nodes
C
      DO I = 1, NODES
         US( I ) = U( I - 1 + I0 )
      END DO

C
C     Fill out array with subinterval function values
C
C     Cycle for parameters numbers
C
      DO J = 1, NPAR

C
C        Cycle for function values
C
         DO I = 1, NODES
         
            FS( J, I ) = F( J, I - 1 + I0 )
            
         END DO
         
      END DO
      
C
C     Cycle for parameters numbers
C
      DO J = 1, NPAR
      
C
C        Cycle for subinterval nodes, extract a string of values
C        for given parameter number J
C
         DO I = 1, NODES
         
            FSJ( I ) = FS( J, I )
            
         END DO
         
C
C        Calculation of approximation parameters for parameter number J
C
         CALL CHEBPL ( US, FSJ, NODES, DJ, DMJ, CJ )
         
C
C        Fill in arrays with factors, mean square root deviations (D)
C        and maximum modules of deviations (DM)
C
         DO I = 1, NCOEFF
         
            C( J, I ) = CJ( I )
            D ( J, I ) = DJ( I )
            DM( J, I ) = DMJ( I )
            
         END DO

      END DO

      RETURN
      END
