      PROGRAM SUMMREAD
C
      CHARACTER RECTYPE*4,TELFMT*4,FLTID*4,TIMEFMT*4,DSN*50,MODE*4
C
      INTEGER*2 TIME(6),MODCNT(3),DATAID(2)
C
      INTEGER*4 IB192(25),IB96(5),IB48,SIB48
C
      LOGICAL*1 MAGSYS(32),REC(10000)
C
      REAL*4 B192(3,25),DEL192(25),LAM192(25),FMOD192(25),
     &       FMAG192(25),RMS192(3,25),
     &       B96(3,5),DEL96(5),LAM96(5),FMOD96(5),
     &       FMAG96(5),RMS96(3,5),
     &       B48(3),DEL48,LAM48,FMOD48,
     &       FMAG48,RMS48(3)
C
      REAL*4 SRMS48(3),SX48,SY48,SZ48,SFMOD48
C
      REAL*4 MTB(3,3),MTB5(3,3),MHG(3,3),POS(3),ANG(2),VEL(3)
C
      REAL*4 HDR1(100),HDR(32),DATA(341),SCFLD(155),POSN(13),ATTD(27),
     &       SUMOUT(568)
C
      REAL*8 DD,TD,TN,TP
C
      EQUIVALENCE (HDR(1),RECTYPE),    (HDR(2),TELFMT),
     &            (HDR(3),FLTID),      (HDR(4),TIME(1)),
     &            (HDR(7),DD),         (HDR(9),TD),
     &            (HDR(11),TIMEFMT),   (HDR(12),TIMEPD),
     &            (HDR(13),MODCNT(1)), (HDR(17),DATAID(1))
C
      EQUIVALENCE (HDR1(77), MAGSYS(1))
C
      EQUIVALENCE (DATA(1),FMAG48),      (DATA(2),FMOD48),
     &            (DATA(3),DEL48),       (DATA(4),LAM48),     
     &            (DATA(5),B48(1)),      (DATA(8),RMS48(1)),
     &            (DATA(11),IB48),       (DATA(12),FMAG96(1)),
     &            (DATA(17),FMOD96(1)),  (DATA(22),DEL96(1)),  
     &            (DATA(27),LAM96(1)),   (DATA(32),B96(1,1)),  
     &            (DATA(47),RMS96(1,1)), (DATA(62),IB96(1)),
     &            (DATA(67),FMAG192(1)), (DATA(92),FMOD192(1)),
     &            (DATA(117),DEL192(1)), (DATA(142),LAM192(1)),
     &            (DATA(167),B192(1,1)), (DATA(242),RMS192(1,1)),
     &            (DATA(317),IB192(1))
C
      EQUIVALENCE (SCFLD(148),SRMS48(1)), (SCFLD(151),SIB48),
     &            (SCFLD(152),SX48),      (SCFLD(153),SY48),
     &            (SCFLD(154),SZ48),      (SCFLD(155),SFMOD48)
C
      EQUIVALENCE (POSN(1),TN),     (POSN(3),TP),
     &            (POSN(5),POS(1)), (POSN(11),RANGE),
     &            (POSN(12),ANG(1)),(POSN(8),VEL(1))
C
      EQUIVALENCE (ATTD(1),MTB(1,1)), (ATTD(10),MTB5(1,1)),
     &            (ATTD(19),MHG(1,1))
C
      EQUIVALENCE (SUMOUT(1),HDR(1)),     (SUMOUT(33),DATA(1)),
     &            (SUMOUT(342),SCFLD(1)), (SUMOUT(529),POSN(1)),
     &            (SUMOUT(542),ATTD(1)),  (SUMOUT(1),HDR1(1))
C
      EQUIVALENCE (SUMOUT(1),REC(1))
C
      WRITE(6,*)
      WRITE(6,*) 'ENTER SUMMARY DSN'
      READ(5,'(A)') DSN
      OPEN(70,FILE=DSN,STATUS='OLD',FORM='FORMATTED',
     &     RECORDTYPE='VARIABLE',RECL=8191,READONLY,
     &     CONVERT='NATIVE')
      WRITE(6,'(1X,A)') DSN
      WRITE(6,*)
      WRITE(6,*) 'ENTER DESIRED RESOLUTION'
      WRITE(6,*) '   1 - 48.0 SEC'
      WRITE(6,*) '   2 - 9.60 SEC'
      WRITE(6,*) '   3 - 1.92 SEC'
      READ(5,*) IRES
      WRITE(6,*) IRES
      WRITE(6,*)
C
      FILL = 999.0
      NCNT = 0
   10 CONTINUE
       READ(70,'(Q,<LEN>A4)',END=100,ERR=10) LEN,(SUMOUT(I),I=1,LEN/4)
       NCNT = NCNT + 1
C
       IF (DATAID(1).EQ.8) THEN
        IF (MAGSYS(21).AND.MAGSYS(22)) THEN
         MODE = 'ERR '
        ELSE IF (MAGSYS(21)) THEN
         MODE = 'PRI '
        ELSE IF (MAGSYS(22)) THEN
         MODE = 'SEC '
        ELSE 
         MODE = 'DUAL'
        END IF
        WRITE(6,801) NCNT,RECTYPE,TIME,MODE
        GOTO 10
       END IF
C
       IF (DATAID(1).NE.1) GOTO 10
       READ(FLTID,'(3X,I1)') ID
C
       IF (IRES.EQ.1) THEN
        I48 = 1
        F1 = DATA(1)
        F2 = DATA(2)
        DEL = DATA(3)
        LAM = DATA(4)
        BX = DATA(5)
        BY = DATA(6)
        BZ = DATA(7)
        WRITE(6,800) NCNT,I48,RECTYPE,TIME,F1,BX,BY,BZ
       ELSE IF (IRES.EQ.2) THEN
        DO I96 = 1,5
         F1 = DATA(12+I96-1)
         F2 = DATA(17+I96-1)
         DEL = DATA(22+I96-1)
         LAM = DATA(27+I96-1)
         BX = DATA(32+I96-1)
         BY = DATA(37+I96-1)
         BZ = DATA(42+I96-1)
         WRITE(6,800) NCNT,I96,RECTYPE,TIME,F1,BX,BY,BZ
        END DO
       ELSE IF (IRES.EQ.3) THEN
        DO I192 = 1,25
         F1 = DATA(67+I192-1)
         F2 = DATA(92+I192-1)
         DEL = DATA(117+I192-1)
         LAM = DATA(142+I192-1)
         BX = DATA(167+I192-1)
         BY = DATA(192+I192-1)
         BZ = DATA(217+I192-1)
         if ( (bx.gt.0.5.and.bx.ne.999.0) .or.
     &        (by.gt.0.5.and.by.ne.999.0) .or.
     &        (bz.gt.0.5.and.bz.ne.999.0) ) 
     &   WRITE(6,800) NCNT,I192,RECTYPE,TIME,F1,BX,BY,BZ
        END DO
       ELSE
        WRITE(6,*) 
        WRITE(6,*) 'SELECTION OUT OF BOUNDS.  EXITTING PROGRAM'
        STOP
       END IF
       GOTO 10
  100 CONTINUE
      WRITE(6,'(1X,''NUMBER OF RECORDS READ: '',I5)') NCNT
      CLOSE(70)
C
      STOP
  800 FORMAT(1X,I5,1X,I2,1X,A4,6(1X,I3),4(1X,F7.3))
  801 FORMAT(1X,I5,4X,A4,6(1X,I3),1X,A4)
  805 FORMAT(I1,1X,I2,1X,I3.3,3(1X,I2),1X,I3.3,2(1X,F7.3),2(1X,F5.1),
     &       3(1X,F7.3))
      END
