C-----------------------------------------------------------------------
C  Routine to read or write the alignment angles from IDATA.DA
C 
C  The call is   CALL ANGRW (IRDWRT,NANG,NUM,NRECS,IOFF)  where
C     IRDWRT is 0/1 for read or write;
C     NANG   is the number of angles to be used;
C     NUM    is the number of reflections;
C     NRECS  is the record number to start the operation;
C     IOFF   is the offset in the ACOUNT array.
C  The ACOUNT array is equivalenced to the angle arrays as :--
C      DIMENSION THETAS(NSIZE),OMEGAS(NSIZE),CHIS(NSIZE),PHIS(NSIZE),
C     $          ICNT(NSIZE),
C     $          THETAP(NSIZE),OMEGAP(NSIZE),CHIP(NSIZE),PHIP(NSIZE)
C      EQUIVALENCE (ACOUNT(        1),THETAS(1)),
C     $            (ACOUNT(  NSIZE*1),OMEGAS(1)),
C     $            (ACOUNT(2*NSIZE+1),CHIS(1)),
C     $            (ACOUNT(3*NSIZE+1),PHIS(1)),
C     $            (ACOUNT(4*NSIZE+1),ICNT(1)),
C     $            (ACOUNT(5*NSIZE+1),THETAP(1)),
C     $            (ACOUNT(6*NSIZE+1),OMEGAP(1)),
C     $            (ACOUNT(7*NSIZE+1),CHIP(1)),
C     $            (ACOUNT(8*NSIZE+1),PHIP(1))
C-----------------------------------------------------------------------
      SUBROUTINE ANGRW (IRDWRT,NANG,NUM,NRECS,IOFF)
      INCLUDE 'COMDIF'
C-----------------------------------------------------------------------
C  Calculate the ACOUNT address offset and number of reads or writes
C-----------------------------------------------------------------------
      NOFF = 0
      IF (IOFF .EQ. 1) NOFF = 5*NSIZE
      NRW = (NSIZE + 79)/80
      NADD = NOFF
      NREC = NRECS
C-----------------------------------------------------------------------
C  Read data from the file
C-----------------------------------------------------------------------
      IF (IRDWRT .EQ. 0) THEN
        DO 110 N = 1,NANG
          NADD1 = NADD + 1
          NADD2 = NADD + 80
          DO 100 J = 1,NRW
            IF (N .EQ. 1 .AND. J .EQ. 1) THEN
              READ (ISD,REC=NREC) NUM,(ACOUNT(I),I = NADD1,NADD2)
            ELSE
              READ (ISD,REC=NREC) (ACOUNT(I),I = NADD1,NADD2)
            ENDIF
            NREC = NREC + 1
            NADD1 = NADD2 + 1
            NADD2 = NADD2 + 80
            IF (NADD2 .GT. NADD+NSIZE) NADD2 = NADD + NSIZE
  100     CONTINUE
          NADD = NADD + NSIZE
  110   CONTINUE
C-----------------------------------------------------------------------
C  Write data to the file
C-----------------------------------------------------------------------
      ELSE
        DO 130 N = 1,NANG
          NADD1 = NADD + 1
          NADD2 = NADD + 80
          DO 120 J = 1,NRW
            IF (N .EQ. 1 .AND. J .EQ. 1) THEN
              WRITE (ISD,REC=NREC) NUM,(ACOUNT(I),I = NADD1,NADD2)
            ELSE
              WRITE (ISD,REC=NREC) (ACOUNT(I),I = NADD1,NADD2)
            ENDIF
            NREC = NREC + 1
            NADD1 = NADD2 + 1
            NADD2 = NADD2 + 80
            IF (NADD2 .GT. NADD+NSIZE) NADD2 = NADD + NSIZE
  120     CONTINUE
          NADD = NADD + NSIZE
  130   CONTINUE
      ENDIF
      RETURN
      END
