* Last processed by NICE on 12-Jun-2000 15:53:00
* Customized for :  IEEE, LINUX, UNIX, MOTIF, F77
      SUBROUTINE READ_DATA (LINE,COMM,ERROR)
      CHARACTER*(*) LINE,COMM
      LOGICAL ERROR
*
      INCLUDE 'setup.inc'
      INCLUDE 'size.inc'
      INCLUDE 'data.inc'
*
      REAL*8 FTIE(NMAX)                  ! Work array for time
      INTEGER ISCAN(NMAX)                ! Work array for scan numbers
      INTEGER ICODE(NMAX)                ! Work array for code (1 Az - 0 El)
      REAL*8 FRMS(NMAX)
      CHARACTER*12 SOU(NMAX)             ! Work array for sources
      INTEGER I1,L1,L,N,LENC,IER,JANT
      CHARACTER*4 STAT
      REAL*8 PI,FAC,SFAC,RTS
      LOGICAL REFRAC
      PARAMETER (PI=3.14159265358979323846D0)
*
      SFAC = PI/180D0/3600D0
      FAC  = 180D0/PI
      RTS  = 1.D0/SFAC
*
      FITTED = .FALSE.
      CALL SIC_I4 (LINE,0,1,JANT,.TRUE.,ERROR)
      IF (ERROR) RETURN
*
      OPEN (UNIT=2,FILE=CFILE,STATUS='OLD',
C+VMS+ULTRIX+HPUX
c     $READONLY,
C-VMS-ULTRIX-HPUX
     $IOSTAT=IER)
      IF (IER.NE.0) THEN
         N = MIN (LENC(CFILE),50)
         WRITE(6,*) 'E-READ_DATA,  Error opening file '//CFILE(1:N)
         CALL PUTIOS ('E-READ_DATA,  ',IER)
         GOTO 99
      ENDIF
*
      IF (CTYPE.EQ.'O') THEN
         CALL RDATA_OP(AZIS,ELES,ERAZ,EREL,TIEM,NDATA,VALPRE,
     $   JANT,STAT,REFRAC)
         CALL SET_OPTICAL (REFRAC)
         NPT = 2*NDATA
         I1 = NDATA
         DO L=1,NDATA
            X(1,L)=AZIS(L)/FAC
            X(2,L)=ELES(L)/FAC
            X(3,L)=0.
            I1=I1+1
            X(1,I1)=AZIS(L)/FAC
            X(2,I1)=ELES(L)/FAC
            X(3,I1)=1.
            FOBS(L)=ERAZ(L)*SFAC
            FOBS(I1)=EREL(L)*SFAC
            SCAN(L)=L
            SCAN(I1)=L
            SOURCE(L) = ' '
            SOURCE(I1) = ' '
            RMS(L) = 0.0
            RMS(I1) = 0.0
            AZIS(I1) = AZIS(L)
            ELES(I1) = ELES(L)
            TIEM(I1) = TIEM(L)
         ENDDO
      ELSEIF (CTYPE.EQ.'R' .OR. CTYPE.EQ.'I') THEN
         IF (CTYPE.EQ.'R') THEN
            CALL RDATA_RA (AZIS,ELES,ERAZ,EREL,FTIE,NDATA,VALPRE,
     $      ICODE,ISCAN,JANT,STAT,SOU,FRMS)
         ELSE
            CALL RDATA_IN (AZIS,ELES,ERAZ,EREL,FTIE,NDATA,VALPRE,
     $      ICODE,ISCAN,JANT,STAT,SOU,FRMS)
         ENDIF
         NDATA=NDATA/2
         NPT = 2*NDATA
         CALL SET_RADIO(JANT)
         I1=NDATA
         L1=0
         DO L=1,NPT
            IF (ICODE(L).EQ.1) THEN
               L1=L1+1
               X(1,L1)=AZIS(L)/FAC       !radian
               X(2,L1)=ELES(L)/FAC       !radian
               FOBS(L1)=ERAZ(L)*SFAC     !radian
               TIEM(L1)=FTIE(L)
               X(3,L1)=0.
               SCAN(L1) = ISCAN(L)
               SOURCE(L1) = SOU(L)
               RMS(L1) = FRMS(L)
            ELSE
               I1=I1+1
               X(1,I1)=AZIS(L)/FAC
               X(2,I1)=ELES(L)/FAC
               X(3,I1)=1.
               FOBS(I1)=EREL(L)*SFAC
               SCAN(I1)=ISCAN(L)
               TIEM(I1)=FTIE(L)
               SOURCE(I1) = SOU(L)
               RMS(I1) = FRMS(L)
            ENDIF
         ENDDO
*
* Reorder AZ and EL values
         DO L=1,NPT
            AZIS(L) = X(1,L)*FAC
            ELES(L) = X(2,L)*FAC
         ENDDO
      ENDIF
      DO L=1,NPT
         BADRE(L) = .FALSE.
         BADUS(L) = .FALSE.
         BADTI(L) = .FALSE.
      ENDDO
      CALL FLAG_EL(NPT,ELMIN,ELMAX)
      CALL FLAG_RM(NPT,RMSMAX)
      CLOSE (UNIT=2)
      IF (NDATA.EQ.0) THEN
         WRITE(6,*) 'E-READ,  No data in file'
         ERROR = .TRUE.
         RETURN
      ENDIF
      CALL GET_GOOD (NPT,KP)
      WRITE (STAT_ANT,'(a,i1,a)') 'A',JANT,' on '//STAT
      RETURN
99    CLOSE (UNIT=2)
      ERROR = .TRUE.
      END
