	SUBROUTINE BTRVD(L2PRV,L2CUR,L2REM,ISGN,WORK,L2NEL,NELEM,
     *  NRECT,IRECO,L2TRU)
C	PERMUTE THE DATA BY BIT REVERSAL AND DIVIDE BY SQRT(2**L2TRU).
C	DIMENSION DATA(NPREV,N,NREM)
C	(NPREV = 2**L2PRV, N = 2**L2CUR, NREM = 2**L2REM)
C	COMPLEX DATA
C	EXCHANGE DATA(J1,J4REV,J5) WITH DATA(J1,J4,J5) FOR ALL J1 FROM 1
C	TO NPREV, ALL J4 FROM 1 TO N, AND ALL J5 FROM 1 TO NREM.  J4REV-1
C	IS THE BIT REVERSAL OF J4-1.  E.G., FOR N = 32, J4-1 = 10011 AND
C	J4REV-1 = 11001, ETC.
	DIMENSION WORK(1)
	SQRTN=SQRT(2.**L2TRU)
	IP0=2
	NWORD=NELEM*IP0
	IP5Q=NRECT
	IF (L2PRV-L2NEL) 100,10,10
C
C	NELEM IS LESS THAN OR EQUAL TO NPREV, SO WE PERMUTE BY EXCHANGING
C	WHOLE RECORDS.  EFFECTIVELY WE HAVE--
C	DIMENSION DATA(NELEM,NPREV/NELEM,N,NREM)
10	IP1Q=2**(L2PRV-L2NEL)
	IP4Q=IP1Q*2**L2CUR
	GO TO 30
20	IP1Q=1
30	DO 90 I5Q=1,IP5Q,IP4Q
	I4QRV=I5Q
	I4QMX=I5Q+IP4Q-IP1Q
	DO 90 I4Q=I5Q,I4QMX,IP1Q
	IF (I4Q-I4QRV) 40,40,60
40	IRECA=I4Q+IRECO
	IRECB=I4QRV+IRECO
	DO 50 I1Q=1,IP1Q
	CALL DREAD(IRECA,WORK,1,NELEM)
	CALL DREAD(IRECB,WORK(NWORD+1),1,NELEM)
	IMAX=2*NWORD
	DO 45 I=1,IMAX
45	WORK(I)=WORK(I)/SQRTN
	CALL DWRITE(IRECB,WORK,1,NELEM)
	CALL DWRITE(IRECA,WORK(NWORD+1),1,NELEM)
	IRECA=IRECA+1
50	IRECB=IRECB+1
C	ADD 1 TO THE HIGH ORDER BIT AND PROPAGATE A DOWNWARD CARRY
60	IP3Q=IP4Q/2
70	IF (I4QRV-I5Q-IP3Q) 90,80,80
80	I4QRV=I4QRV-IP3Q
	IP3Q=IP3Q/2
	IF (IP3Q-IP1Q) 90,70,70
90	I4QRV=I4QRV+IP3Q
	RETURN
100	IF (L2CUR-L2NEL+L2PRV-1) 170,170,110
C
C	NELEM IS GREATER THAN NPREV BUT LESS THAN NPREV*N/2.  WE EXCHANGE
C	LINEAR SEQUENCES IN SEVERAL PASSES.  EFFECTIVELY WE HAVE --
C	DIMENSION DATA(NPREV*(2**K),2,N/4**(K+1),2,(2**K)*NREM)
C	AND WE EXCHANGE DATA(J1,1,J3,2,J5) WITH DATA(J1,2,J3,1,J5) FOR
C	ALL K FROM 0 UP.  SHOWING RECORD BOUNDARIES, WE REALLY HAVE--
C	DIMENSION DATA(NELEM,(N/4**(K+1))/NELEM,2,(2**K)*NREM)
C	WHEN K BECOMES LARGE ENOUGH, WE SWITCH TO ANOTHER CASE, USING THE
C	UPDATED VALUES FOR NPREV AND NREM.
110	IP4Q=2**(L2CUR-L2NEL+L2PRV)
	IP3Q=IP4Q/2
	IP1=IP0*2**L2PRV
	IP2=IP1*2
120	DO 140 I5Q=1,IP5Q,IP4Q
	IRMAX=I5Q+IP3Q-1
	DO 140 IREC=I5Q,IRMAX
	IRECA=IREC+IRECO
	CALL DREAD(IRECA,WORK,1,NELEM)
	IRECB=IRECA+IP3Q
	CALL DREAD(IRECB,WORK(NWORD+1),1,NELEM)
	DO 130 I3=1,NWORD,IP2
	I1MAX=I3+IP1-IP0
	DO 130 I1=I3,I1MAX,IP0
	I2A=I1+IP1
	I2B=I1+NWORD
	TEMPR=WORK(I2A)
	TEMPI=WORK(I2A+1)
	WORK(I2A)=WORK(I2B)
	WORK(I2A+1)=WORK(I2B+1)
	WORK(I2B)=TEMPR
130	WORK(I2B+1)=TEMPI
	IMAX=2*NWORD
	DO 135 I=1,IMAX
135	WORK(I)=WORK(I)/SQRTN
	CALL DWRITE(IRECA,WORK,1,NELEM)
140	CALL DWRITE(IRECB,WORK(NWORD+1),1,NELEM)
	SQRTN=1.
	IP1=2*IP1
	IP2=2*IP2
	IP3Q=IP3Q/2
	IP4Q=IP4Q/2
	IF (IP4Q-IP2/NWORD) 290,290,150
150	IF (IP1-NWORD) 160,20,20
160	IF (IP3Q-1) 180,180,120
C
C	NELEM IS GREATER THAN OR EQUAL TO NPREV*N/2.  EFFECTIVELY WE HAVE
C	DIMENSION DATA(NPREV,N/2,2*NELEM/(NPREV*N),(NPREV*N*NREM)/NELEM)
C	WE READ IN TWO ADJACENT RECORDS AND EXCHANGE ELEMENTS IN THOSE
C	RECORDS.  TO REDUCE I/O, DFT2R IS CALLED TO TRANSFORM THE
C	ELEMENTS IN THOSE RECORDS.
170	IP1=IP0*2**L2PRV
	IP4=IP1*2**L2CUR
	GO TO 190
180	IP4=IP4Q*NWORD
190	NREC=2
	I5MAX=2*NWORD
	IF (NRECT-1) 200,200,210
200	NREC=1
	I5MAX=IP4*2**L2REM
210	DO 280 IREC=1,NRECT,2
	CALL DREAD(IREC+IRECO,WORK,NREC,NELEM)
	DO 270 I5=1,I5MAX,IP4
	I3REV=I5
	I3MAX=I5+IP4-IP1
	DO 270 I3=I5,I3MAX,IP1
	IF (I3-I3REV) 220,220,240
220	I1MAX=I3+IP1-IP0
	DO 230 I1=I3,I1MAX,IP0
	I2A=I1
	I2B=I2A+I3REV-I3
	TEMPR=WORK(I2A)
	TEMPI=WORK(I2A+1)
	WORK(I2A)=WORK(I2B)/SQRTN
	WORK(I2A+1)=WORK(I2B+1)/SQRTN
	WORK(I2B)=TEMPR/SQRTN
230	WORK(I2B+1)=TEMPI/SQRTN
C	ADD 1 TO THE HIGH ORDER BIT AND PROPAGATE A DOWNWARD CARRY
240	IP3=IP4/2
250	IF (I3REV-I5-IP3) 270,260,260
260	I3REV=I3REV-IP3
	IP3=IP3/2
	IF (IP3-IP1) 270,250,250
270	I3REV=I3REV+IP3
	CALL DFT2R(WORK,L2PRV,L2CUR,ISGN,L2NEL,I5MAX/(2*IP0))
280	CALL DWRITE(IREC+IRECO,WORK,NREC,NELEM)
290	RETURN
	END
