      CHARACTER DSN*80,IHDR(45)*4,PVRD*77,TYPE*4,FILEID*4
      INTEGER*2 PTIME(6)
      INTEGER*4 INAV(126,2)
      REAL*4 RNAV(126,2),PV(3,3)
      EQUIVALENCE( IHDR(1), INAV(1,1) )
C
      IUNIT = 66
      OPEN(IUNIT,FILE='SATURN.SDR',FORM='FORMATTED',STATUS='NEW',
     &     RECORDTYPE='VARIABLE',RECL=200)
      GOTO 201
C
C OPEN POINTING VECTOR FILE FOR READING
C
      WRITE(6,*) 'ENTER POINTING VECTOR FILE NAME'
      READ(5,'(A)') DSN
      OPEN(40,FILE=DSN,STATUS='OLD',FORM='FORMATTED',READONLY)
      WRITE(68,*) 'POINTING VECTOR FILE NAME: ',DSN
C
C READ POINTING VECTOR FILE HEADER.  EXPECT $$VGR AT HEADER START AND
C $$EOH AT HEADER END.
C
      READ(40,'(A77)') PVRD
    4 CONTINUE
      IF ( PVRD(1:5).NE.'$$VGR' ) THEN 
       WRITE(IUNIT,804)
       STOP
      END IF
      WRITE(IUNIT,*)
      WRITE(IUNIT,*) 'POINTING VECTOR FILE INFO'
      DO WHILE ( PVRD(1:5).NE.'$$EOH' )
       READ(40,'(A77)') PVRD
       IF ( PVRD(1:1).NE.'*' ) WRITE(IUNIT,*) PVRD
      END DO
C
C READ POINTING VECTOR DATA
C
    5 CONTINUE
      READ(40,'(A77)',END=200) PVRD
      IF (PVRD(1:5).EQ.'$$VGR') GOTO 4  ! NEW HEADER BLOCK
      IF (PVRD(1:1).EQ.'*') THEN
       WRITE(IUNIT,*) 
       WRITE(IUNIT,*) 'POINTING VECTOR FILE INFO'
       WRITE(IUNIT,'(A77)') PVRD 
       GOTO 5
      END IF
      CALL EXTRACTDATE(PTIME,PVRD)
      WRITE(IUNIT,810) PTIME
C
C LOAD 3X3 SENSOR POINTING MATRIX.  INSTRUMENT AXIS VECTORS ARE COLUMN
C ORIENTED.
C
C X AXIS VECTOR TO COLUMN 1
C
       READ(PVRD,'(34X,2(E13.12,2X),E13.12)') (PV(I,1),I=1,3)
       WRITE(IUNIT,*) (PV(I,1),I=1,3)
C
C Y AXIS VECTOR TO COLUMN 2
C
       READ(40,'(A77)',END=200) PVRD
       READ(PVRD,'(34X,2(E13.12,2X),E13.12)') (PV(I,2),I=1,3)
       WRITE(IUNIT,*) (PV(I,2),I=1,3)
C
C Z AXIS VECTOR TO COLUMN 3
C
       READ(40,'(A77)',END=200) PVRD
       READ(PVRD,'(34X,2(E13.12,2X),E13.12)') (PV(I,3),I=1,3)
       WRITE(IUNIT,*) (PV(I,3),I=1,3)
C
      GOTO 5
  200 CONTINUE
      CLOSE(41)
C
C OPEN NAVIGATION FILE FOR READING.  EXPECT UNFORMATTED, VAXG FLOATING
C POINT DATA.
C
  201 CONTINUE
      WRITE(6,*) 'ENTER NAVIGATION FILE NAME'
      READ(5,'(A)') DSN
      OPEN(41,FILE=DSN,STATUS='OLD',CONVERT='VAXG',
     &     FORM='UNFORMATTED',RECORDTYPE='VARIABLE',READONLY)
      WRITE(68,*) 'NAVIGATION FILE NAME: ',DSN
C
C GET NAVIGATION FILE HEADER RECORD.  CONTAINS CHARACTER AND INTEGER DATA.
C
      READ(41) IHDR
      IF ( IHDR(2).NE.'SEDR' ) THEN
       WRITE(IUNIT,805)
       STOP
      END IF
    9 CONTINUE
      WRITE(IUNIT,*)
      WRITE(IUNIT,*) 'NAVIGATION FILE INFO'
      WRITE(IUNIT,'(1X,''PROJECT ID:  '',A4)') IHDR(1) 
      WRITE(IUNIT,'(1X,''FILE TYPE:   '',A4)') IHDR(2)
      WRITE(IUNIT,'(1X,''FLIGHT:      '',I2.2)') INAV(3,1)
      WRITE(IUNIT,'(1X,''FILE ID:     '',2A4)') IHDR(4),IHDR(5)
      WRITE(IUNIT,'(1X,''FILE FORMAT: '',2A4)') IHDR(14),IHDR(15)
      TYPE = IHDR(14)
C
C GET NAVIGATION DATA RECORDS.  CONTAINS INTEGER AND FLOATING POINT DATA.
C FLOATING POINT VALUES ARE CONVERTED FROM VAXG TO IEEE REPRESENTATION BY
C DEC FORTRAN CONVERT PARAMETER IN OPEN STATEMENT WHEN SOURCE CODE IS 
C COMPILED USING THE FLOAT=IEEE FLAG.
C
      WRITE(6,*) 'PROCESSING NAVIGATION DATA ...'
   10 CONTINUE
       READ(41,END=100,ERR=11) (INAV(I,1),I=1,6),(RNAV(I,1),I=7,126),
     &                         (RNAV(I,2),I=1,126)
   11  CONTINUE
C
C GET NAVIGATION RECORD TIME TAG.  USE 2 DIGIT YEAR.
C
       IF ( IHDR(2).EQ.'SEDR' ) GOTO 9  ! DETECT HDR REC IN CONCAT SEDRS
C       WRITE(6,811) (INAV(I,1),I=1,6),RNAV(83,1)
       WRITE(IUNIT,811) (INAV(I,1),I=1,6),(RNAV(J,1),J=19,24),
     &  (RNAV(K,1),K=67,72),RNAV(76,1),RNAV(77,1),RNAV(83,1)
C
      GOTO 10
  100 CONTINUE
      WRITE(6,*) 'NAVIGATION DATA PROCESSING COMPLETE.'
      CLOSE(40)
C
  804 FORMAT(1X,'*GETSEDR*  ERROR!  ',
     &       'INVALID POINTING VECTOR FILE HEADER.')
  805 FORMAT(1X,'*GETSEDR*  ERROR!  ',
     &       'INVALID NAVIGATION FILE HEADER.')
  810 FORMAT(1X,I4,1X,I3,3(1X,I2),1X,I3)
  811 FORMAT(1X,I4,1X,I3,3(1X,I2),1X,I3,15(1X,E10.4))
C  811 FORMAT(1X,I4,1X,I3,3(1X,I2),1X,I3,1(1X,E10.4))
C
      END
      SUBROUTINE EXTRACTDATE(TIME,PVRD)                  
C
C EXTRACT POINTING VECTOR RECORD TIME
C
      INTEGER*2 TIME(6)
      CHARACTER PVRD*77
C                                                 
      READ(UNIT=PVRD,FMT=89) TIME
C
      RETURN                                                            
  89  FORMAT(I2,1X,I3,3(1X,I2),1X,I3)
      END
