      program checkrc3
c     PROGRAM READ_RC3
C
C     INPUT:  rc39b.all, path specified by PATH constant below
c             This originally read RC3 as 23 1000-line files, so the
c             "INPUT" line looked like this:
c     INPUT:  rc39b.[01], path specified by PATH constant below
c             The original code is commented out and replaced by code
c             that simply reads one file.
C
C     DESCRIPTION:  READS IN RC3 FILE, and checks formatting.
C
C     A quick and dirty RC3 reader by Linda Hermans (IPAC): 28 March 1991
C     Various mods by David Way (Astron. Dept., UTx): Dec. 1991; Nov. 1992
c     Various bug fixes/mods by H. Corwin (IPAC): Nov. 1992, Mar. 1994, 
c       Aug. 1995, and (retired!) Jun. 2020
c     With thanks to Dave Burstein and Carol Lonsdale for suggestions
c       for improvements.
C**********************************************************************
c---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
      CHARACTER *(*)PATH
c  Change the path in the following statement to reflect the location of
c   the RC3 files on your machine.
      PARAMETER (PATH = '/scr/hgcjr/rc3/')
C
      CHARACTER DSIGN1*1,CAT1*4,TYP*10,NAM1*11,radot1*1
      INTEGER   RH1,RM1,DD1,DM1,DS1,PA,V21,V21E,rs1d
      REAL      rs1,rsp1,ras1,D25,D25E,BT,BTE,BVT,BVTE,BVE,BVEE,M21,M21E
C
      CHARACTER CAT2*4,NAM2*11,ST*1,NL*4
      INTEGER   VOPT,VOPTE,W20,W20E
      REAL      GLON,GLAT,R25,R25E,AG,MB,MBE,UBT,UBTE,UBE,UBEE
C
      CHARACTER CAT3*4,NAM3*11
      INTEGER   W50,W50E,VGSR
      REAL      SGLON,SGLAT,T,TE,AE,AEE,AI,MFIR,BVTO,ME,MEE
C
      CHARACTER DSIGN2*1,CAT4*3,radot2*1
      INTEGER   RH2,RM2,DD2,DM2,DS2,NAM4,V3K,rs2d
      REAL      rsp2,RS2,L,LE,DO,A21,BTO,UBTO,M25,M25E,HI
C
      CHARACTER FILE*9 /'rc39b.all'/
c     CHARACTER FILE*8 /'rc39b.01'/
      INTEGER   TOTAL,REC,LINE,COUNT,I
c  positions.out is a check file containing only names (from lines 1 and 4)
c   and sexagesimal positions.  It simply echoes the input.
c     open(3,file='positions.out')
      TOTAL = 0
      REC = 0
C
c  Here is the code that read the 23 individual files in turn.
c     DO 50 I=1,23
C
c     IF (I.LT.10) THEN
c       FILE(7:7) = '0'
c       WRITE (FILE(8:8),'(I1)') I
c     ELSE IF (I.LT.100) THEN
c     WRITE (FILE(7:8),'(I2)') I
c     ENDIF
C
      OPEN(UNIT=10,FILE=PATH//FILE)
      PRINT 15,PATH//FILE
c  Change the "a28" as needed if your path/filename is longer.
 15   FORMAT ('Reading ',a28)
      COUNT = 0
C
c---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
  5   LINE = 1
      READ(10,18,ERR=90,END=40) RH1,RM1,RS1,radot1,rs1d,DSIGN1,DD1,DM1,
     & DS1,CAT1,NAM1,TYP,D25,D25E,PA,BT,BTE,BVT,BVTE,BVE,BVEE,M21,M21E,
     & V21,V21E
C
 18   FORMAT(I2,I2,f2.0,a1,i1,A1,I2,I2,I2,1X,A4,A11,A10,F5.2,1X,F4.2,I5,
     & F6.2,2X,F3.2,F6.2,1X,F4.2,F6.2,1X,F4.2,F6.2,1X,F2.1,I6,1X,I3)
      TOTAL = TOTAL + 1
      COUNT = COUNT + 1
c  Check positions for formatting:  "hhmmss.d+ddmmss"  or "hhmm.d  +ddmm"
c    ras1 (real) is the reconstructed seconds of time; use it for calculations.
c    rsp1 (real) is the reconstructed minutes of time for writing.
      if(radot1.eq.'.') then
          ras1 = rs1 + 0.1*rs1d
c         write (3,10) cat1,nam1,rh1,rm1,ras1,dsign1,dd1,dm1,ds1
          go to 104
        else
          ras1 = 60.0*rs1
          ds1 = 0
          rsp1 = real(rs1)
c         write (3,11) cat1,nam1,rh1,rm1,rsp1,dsign1,dd1,dm1
          go to 104
      end if
  104 continue
   10 format (' J2000.0 position for ',a4,a11,3x,i2.2,1x,i2.2,1x,f4.1,
     & 1x,a1,3(i2.2,1x))
   11 format (' J2000.0 position for ',a4,a11,3x,i2.2,1x,i2.2,f2.1,3x,
     & 1x,a1,2(i2.2,1x))
C
      LINE = 2
      READ(10,22,ERR=90) GLON,GLAT,CAT2,NAM2,ST,NL,R25,R25E,AG,MB,MBE,
     +            UBT,UBTE,UBE,UBEE,W20,W20E,VOPT,VOPTE
C
 22   FORMAT(2F7.2,2X,A4,A11,A1,5X,A4,F5.2,1X,F4.2,F5.2,F6.2,2X,F3.2,
     +       F6.2,1X,F4.2,F6.2,1X,F4.2,I5,1X,I3,I6,1X,I3)
      TOTAL = TOTAL + 1
      COUNT = COUNT + 1
C
      LINE = 3
      READ(10,24,ERR=90) SGLON,SGLAT,CAT3,NAM3,T,TE,AE,AEE,AI,MFIR,
     +            BVTO,ME,MEE,W50,W50E,VGSR
C
 24   FORMAT(F7.2,F7.2,2X,A4,A11,F4.1,1X,F3.1,F7.2,1X,F4.2,F5.2,F6.2,
     +       5X,F6.2,5X,F6.2,1X,F4.2,I5,1X,I3,I6)
      TOTAL = TOTAL + 1
      COUNT = COUNT + 1
C
      LINE = 4
      READ(10,26,ERR=90) RH2,RM2,RS2,radot2,rs2d,DSIGN2,DD2,DM2,DS2,
     & CAT4,NAM4,L,LE,DO,A21,BTO,UBTO,M25,M25E,HI,V3K
C
 26   FORMAT(I2,I2,f2.0,a1,i1,A1,I2,I2,I2,1X,A3,I6,5X,F5.1,1X,F3.1,
     & F7.2,5X,F5.2,F6.2,5X,F6.2,5X,F6.2,1X,F4.2,F6.2,3X,I6)
      TOTAL = TOTAL + 1
      COUNT = COUNT + 1
c  Check positions for formatting:  "hhmmss.d+ddmmss"  or "hhmm.d  +ddmm"
c  This piece is no longer needed for "rc3.10.0.dat" -- RC3.10 has only
c   positions given as "hhmmss.d+ddmmss".  However, it is still needed for
c   the "rc39[b|c].all" versions.
c    ras2 (real) is the reconstructed seconds of time; use it for calculations.
c    rsp2 (real) is the reconstructed minutes of time for writing.
      if(radot2.eq.'.') then
          ras2 = rs2 + 0.1*rs2d
c         write (3,20) cat4,nam4,rh2,rm2,ras2,dsign2,dd2,dm2,ds2
          go to 105
        else
          ras2 = 60.0*rs2
          ds2 = 0
          rsp2 = real(rs2)
c         write (3,21) cat4,nam4,rh2,rm2,rsp2,dsign2,dd2,dm2
          go to 105
      end if
  105 continue
   20 format (' B1950.0 position for ',a3,i6,9x,i2.2,1x,i2.2,1x,f4.1,
     & 1x,a1,3(i2.2,1x))
   21 format (' B1950.0 position for ',a3,i6,9x,i2.2,1x,i2.2,f2.1,3x,
     & 1x,a1,2(i2.2,1x))
c---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
C
      REC = REC + 1
      GO TO 5
 40   CLOSE(UNIT=10)
c50   CONTINUE
      GO TO 99
 90   PRINT 91,REC,LINE,COUNT,FILE
 91   FORMAT ('Error in record ',I5,', line ',I1,' (line ',i5,
     1 ' of file ',A9,')')
 99   PRINT 100,REC,TOTAL
100   FORMAT (I6,' RC3 record(s) read (',I6,' lines)')
      I = REC * 4
      IF (I.NE.TOTAL) THEN
	PRINT 101
101   FORMAT ('*** ERROR: Record count * 4 does not equal line count.')
      ENDIF
      STOP
      END
