* Last processed by NICE on 12-Jun-2000 15:53:00
* Customized for :  IEEE, LINUX, UNIX, MOTIF, F77
      SUBROUTINE RDATA_RA (AZIS,ELES,ERAZ,EREL,TIEM,NP,VALPRE,
     $ICODE,SCAN,JANT,STAT,SOURCE,RMS)
C----------------------------------------------------------------------
C POINTING
C	Read CLASS ANALYSE\PRINT POINTING output files
C
C----------------------------------------------------------------------
* Call
      REAL*8 AZIS(1),ELES(1),ERAZ(1),EREL(1),TIEM(1),VALPRE(1),RMS(1)
      INTEGER ICODE(1),SCAN(1),JANT
      CHARACTER*(*) STAT,SOURCE(1)
* Local
      REAL*8 FAC,RTS,PI,AZI,ELE,TEMP,POS,DPOS,WID,DWI,ERR
      INTEGER IAZ,IEL,ICOUNT,IC,JSCAN,IER,IOBS,ISCAN,JCODE,NP,JNDEX,
     $IANT,ISTA,JSTA
      CHARACTER*132 CHAIN
      CHARACTER*3 ARM(3)
      CHARACTER*12 NAME
      LOGICAL NEW
      DATA ARM/'N','W','E'/
*
      PI = ACOS(-1.0D0)
      FAC = PI/180.D0
      RTS = 3600.0D0/FAC
*
* Skip header lines (4)
      READ(2,*)
      READ(2,*)
      READ(2,*)
      READ(2,'(A)') CHAIN
      NEW = INDEX(CHAIN,'A#').NE.0
*
      IF (NEW .AND. JANT.EQ.0) THEN
         WRITE(6,'(1X,A,$)') 'Enter selected antenna '
         READ(6,*) JANT
      ENDIF
*
      IAZ = 0
      IEL = 0
      ICOUNT = 0
      WRITE(6,*) 'I-POINTING,  Reading RADIO data'
      IC = 0
      JSCAN=-5
      JSTA = 0
*
      DO WHILE (.TRUE.)
         IF (NEW) THEN
            READ(2,*,IOSTAT=IER,END=110) IOBS,ISCAN,JCODE,AZI,ELE,
     $      TEMP,POS,DPOS,IANT,ISTA, WID,DWI,ERR,ERR,NAME
            IF (IER.NE.0) THEN
               WRITE(6,*) 'W-RDATA_RA,  Read error in input file'
               GOTO 30
            ENDIF
            IF (IANT.NE.JANT) GOTO 30
            IF (JSTA.NE.0) THEN
               IF (ISTA.NE.JSTA) THEN
                  WRITE(6,*) 'E-POINT, Station change at ',ISCAN
                  GOTO 30
               ENDIF
            ELSE
               JSTA = ISTA
            ENDIF
         ELSE
            READ(2,*,IOSTAT=IER,END=110) IOBS,ISCAN,JCODE,AZI,ELE,
     $      TEMP,POS
            IF (IER.NE.0) THEN
               WRITE(6,*) 'W-RDATA_RA,  Read error in input file'
               GOTO 30
            ENDIF
         ENDIF
*
* check whether scan number change
         IF (ISCAN.NE.JSCAN) THEN
* check whether first scan or last scan complete
            IF (IAZ.NE.0 .AND. IEL.NE.0) THEN
               ICOUNT=ICOUNT+2
            ELSEIF (JSCAN.NE.-5) THEN
               WRITE(6,*) 'W-RDATA_RA,  Scan ignored',
     $         JSCAN
            ENDIF
            JSCAN = ISCAN
            IAZ=0
            IEL=0
         ENDIF
*
* Azimuth drift
         IF (JCODE.EQ.1) THEN
            IF (IAZ.EQ.0) THEN
               IAZ=1
               JNDEX=ICOUNT+IAZ+IEL
               AZIS(JNDEX)=AZI
               ELES(JNDEX)=ELE
               TIEM(JNDEX)=TEMP
               ERAZ(JNDEX)=POS
               EREL(JNDEX)=0.
               ICODE(JNDEX)=JCODE
               SCAN(JNDEX) =JSCAN
               RMS(JNDEX) = DPOS
               SOURCE(JNDEX) = NAME
            ENDIF
*
* Elevation drift
         ELSEIF (JCODE.EQ.0) THEN
            IF (IEL.EQ.0) THEN
               IEL=1
               JNDEX=ICOUNT+IAZ+IEL
               AZIS(JNDEX)=AZI
               ELES(JNDEX)=ELE
               TIEM(JNDEX)=TEMP
               EREL(JNDEX)=POS
               ERAZ(JNDEX)=0.
               ICODE(JNDEX)=JCODE
               SCAN(JNDEX) =JSCAN
               RMS(JNDEX) = DPOS
               SOURCE(JNDEX) = NAME
            ENDIF
         ELSE
            WRITE(6,*) 'W-RDATA_RA,  Scan ',ISCAN,
     $      ' is neither Azimuth nor Elevation'
         ENDIF
30    ENDDO
110   NP = ICOUNT
* Last scan complete
      IF (IAZ.EQ.1 .AND.IEL.EQ.1) NP=NP+2
      WRITE(STAT,'(1X,I2.2)') MOD(JSTA,100)
      JSTA = JSTA/100
      IF (JSTA.GT.0 .AND. JSTA.LE.3) STAT(1:1) = ARM(JSTA)
      END
