       SUBROUTINE SAX_FROOT_NAME( FROOTNAME )
C
C----------------------------------------------------------------------
C
C.IDENTIFICATION: Subroutine SAX_FROOT_NAME
C.LIBRARY:        FOTLIB                     
C.AUTHOR:         L. Nicastro - ITeSRE Bologna
C.VERSIONS:       0.0 - 25 Jun 96 - original version
C                 0.1 - 28 Jun 96 - Use "Reset" in GET_OBS_CHAIN call
C                 0.2 - 24 Dec 96 - default FLIGHT is on (LC)
C.PURPOSE:        construct and return observation root file name (with path)
C.METHOD:         
C                 
C.SYNTAX:         CALL  SAX_FROOT_NAME( FROOTNAME )
C.PARAMETERS:     CHAR FROOTNAME (out) filename root for FOT files
C.RESTRICTIONS:
C.NOTES:          provisional version in pdslib
C.FILES:          
C.REFERENCES      
C
C----------------------------------------------------------------------
C   
       INTEGER IOBS
C-->   length of file name is provisional
       CHARACTER ROOT*40,FLIGHTDATA*3
       CHARACTER INSTR*4,SLEW,FROOTNAME*(*)
*--
*
C-->   temporary switch for flight/ground data
       CALL GET_GLOBAL_DEFAULT('FLIGHT','ON',FLIGHTDATA)
       CALL UPCASE(FLIGHTDATA)
*
C      retrieve instrument from context
       CALL GET_GLOBAL_DEFAULT('INSTRUMENT','NONE',INSTR)
C-->   existence should have been pre-checked by caller,
C-- thus no error check here
*
C      retrieve current observation chain from context
       CALL GET_OBS_CHAIN(IOBS,'Reset')
*
C      Observation directory handling
C
       IF(FLIGHTDATA.EQ.'ON')THEN
*
C        FOT data
*
C        get type of pointing (i,f,n for ingoing,final,normal)
         CALL GET_GLOBAL_DEFAULT('SLEW','n',SLEW)
         CALL LOWCASE(SLEW)
C-->     provisional error handling
         IF(INDEX('inf',SLEW).EQ.0)THEN
           WRITE(*,*)' illegal slew code ',slew
           RETURN
         ENDIF
*
C        build observation directory file name
*
         WRITE(ROOT,102)SLEW,INSTR(1:2),IOBS
 102     FORMAT(A1,A2,I3.3)  
       ELSE
*
C        ground data from BTB dump
*
C        build run directory file name
         WRITE(ROOT,106)IOBS
 106     FORMAT('btb',I5.5)        
       ENDIF
*
C        build observation/run file name
*
         CALL BUILDPATH(ROOT,'FOT',FROOTNAME)
         RETURN
*
         END
