        SUBROUTINE SAX_ACC_OPEN_TLM(LU,PACKET)
C
C----------------------------------------------------------------------
C
C.IDENTIFICATION: Subroutine SAX_ACC_OPEN_TLM
C.LIBRARY:        FOTLIB                     
C.AUTHOR:         L.Chiappetti - IFCTR Milano
C.VERSIONS:       0.0 - 10 May 93 - Original DUMMY version
C                 0.1 - 03 Oct 94 - support for ground BTB data (in DATADIR)
C                 0.2 - 28 Dec 94 - now looks for ground BTB data in FOTDIR
C                 0.3 - 23 Mar 95 - support to observation chains
C                 0.4 - 27 Mar 95 - minor bug in error message fixed
C                 0.5 - 05 Jul 95 - added extra argument & FOT support
C                 0.6 - 19 Jun 96 - changed handling of "no data" observations
C                 0.7 - 21 Nov 96 - removed support to ground data
C.PURPOSE:        Open telemetry file             
C.METHOD:         load recl from packetcap and call Z_OPEN
C.SYNTAX:         CALL  SAX_ACC_OPEN_TLM(LU,PACKET)
C.PARAMETERS:     INTEGER  lu        : logical unit
C.                CHARACTER packet   : packet type     
C.RESTRICTIONS:   it is responsability of the caller to check that the
C                 observation contains data (ACCUMCOMMON_NREC NE 0)
C.NOTES:          this routine shall construct the filename
C.FILES:          
C.REFERENCES      
C
C----------------------------------------------------------------------
C   
        INTEGER LU,LUTMP
        CHARACTER*(*) PACKET
        INTEGER ITYPE,IOBS,I,TRUE_LENGTH,NREC,IERR,J
        LOGICAL FOUND
C-->    lemngth of file name is provisional
        CHARACTER DUMMY,TLMFILE*80,TLMNAME*80,ROOTNAME*6
*       CHARACTER FLIGHTDATA*3
        CHARACTER OBSREC*40
        INCLUDE  'hcommon.inc'
        INCLUDE  'bincommon.inc'
        INCLUDE  'accumcommon.inc'
        LOGICAL  VOSERROR
C
C-->   so far handle a single "packet" telemetry file at a time
C-->   so far open just one file here ... later it might open further files
C-->   for other observations transparently within SAXACCUMLOOP or descendants
       CALL PKTCAP_LOOKUP('pl',ITYPE,ACCUMCOMMON_RECL,DUMMY,FOUND)
       IF(.NOT.FOUND)THEN
C-->     error handling is provisional
         WRITE(*,*)'  pl field missing in packetcap'
         CALL Z_EXIT(99)
       ENDIF
C
C      save requested packet type (redundant beyond first time)
       ACCUMCOMMON_PACKET=PACKET
C
C-->   temporary switch for flight/ground data
*      CALL GET_GLOBAL_DEFAULT('FLIGHT','ON',FLIGHTDATA)
*      CALL UPCASE(FLIGHTDATA)
C
C      open observation directory
C
       CALL SAX_OPEN_DIR(LUTMP,0,ROOTNAME)
C-->   provisional error handling
       IF(LUTMP.EQ.-1)RETURN
C
C      read directory to get expected number of records
C
       TLMFILE=' '
       NREC=0
*      IF(FLIGHTDATA.EQ.'ON')THEN
C
C         FOT data
C         osbdir contains only packet type, full file name must be constructed
 1071     CONTINUE
C-->      the IOSTAT clause allows to read records with NULLs which otherwise give errors
C-->      might check last I is the same RECL in ACCUMCOMMON
          READ(LUTMP,'(A)',END=108)OBSREC
          READ(OBSREC(1:37),*,IOSTAT=IERR)DUMMY,I,TLMFILE,I,I,NREC
*         write(*,*)dummy,tlmfile,i,nrec
          CALL LOWCASE(TLMFILE)
          IF(TLMFILE.EQ.PACKET)THEN
             TLMFILE=ROOTNAME//'.'//PACKET
             write(*,*)' file selected ',TLMFILE,NREC
             GOTO 108
          ELSE
             NREC=0
             GOTO 1071
          ENDIF
C
*      ELSE
C
C         ground data from BTB dump
*107      CONTINUE
*         READ(LUTMP,*,END=108)TLMFILE,NREC
*         CALL LOWCASE(TLMFILE)
*         write(*,*)tlmfile,nrec,packet
*         IF(INDEX(TLMFILE,PACKET).NE.0)GOTO 108
*          GOTO 107
*      ENDIF
 108   CONTINUE
       ACCUMCOMMON_NREC=NREC
       CLOSE(LUTMP)
       IF(NREC.NE.0) THEN
C        open telemetry file
         I=TRUE_LENGTH(TLMFILE)
         write (*,*)' Opening telemetry file ',tlmfile(:i)
         CALL BUILDPATH(TLMFILE,'FOT',TLMNAME)
         CALL Z_OPEN(LU,TLMNAME,'DIR','OLD',ACCUMCOMMON_RECL)
         ACCUMCOMMON_LU=LU
C-->     any VOS error handled in main
       ELSE
          WRITE(*,*)' No file ',PACKET,' found in observation directory'
*         TLMFILE='notfound'
C-->      caller shall check ACCUMCOMMON_NREC ne 0 !
       ENDIF
       RETURN
       END
