C		PROGRAM FOURIER
C  
C      TO FOURIER TRANSFORM A SPECTRUM.
C
C  J.C. PHILLIPS, EMBL OUTSTATION, HAMBURG.
C		  9/12/79
C	ADAPTED FOR SUNY X21 COMPUTER BY JCP 10/12/85
C
	DIMENSION FK(512),F(512),FP(512),R(256),FI(256),X(256),Y(256)
	BYTE FILNAM(10)
	DATA CON1,CON2 /10000.,3989.4228/
C	TWOPI=6.2318
C
C  READ IN INPUT FILENAMES, NO. OF POINTS,RANGE.
C
	WRITE(5,100)
	READ(5,101)FILNAM
	CALL RFILE(FK,FILNAM,NCHAN)
	WRITE(5,102)
	READ(5,101) FILNAM
	CALL RFILE(F,FILNAM,NCHAN)
	WRITE(5,105)
	TWOPI=2.
	READ(5,106) NLOW,NHI,NK,RANGE,WINCEN,WINSIG,ITWOPI
	IF(NLOW.LE.0) NLOW=1
	IF(NHI.LE.0) CALL EXIT
	IF(RANGE.LT.0.1) RANGE=6.0
	IF(ITWOPI.NE.0) TWOPI=6.2832
	DO 5 I=1,NCHAN
	FK(I)=0.1*FK(I)
	F(I)=F(I)/CON1
5	CONTINUE
	DELX=RANGE/256.
	FKMID=WINCEN
	IF(WINCEN.LT.0.0001) FKMID=(FK(NLOW)+FK(NHI))/2.
	SIGSQ=(WINSIG**2)/2.
	IF(WINSIG.LT.0.0001) SIGSQ=(FKMID**2)/2.
C
C  ENTER OUTPUT FILENAMES.
C
 	WRITE(5,104)
	READ(5,101) FILNAM
	NTOP=NHI-1
	NBOT=NLOW+1
	DO 1 I=NBOT,NTOP
	FP(I)=F(I)*(FK(I+1)-FK(I-1))*EXP(-((FK(I)-FKMID)**2)/SIGSQ)
	IF(NK.GT.0) FP(I)=FP(I)*(FK(I)**NK)
1	CONTINUE
	CLOW=F(NLOW)*(FK(NBOT)-FK(NLOW))
	CLOW=CLOW*EXP(-((FK(NLOW)-FKMID)**2)/SIGSQ)
	CHI=F(NHI)*(FK(NHI)-FK(NTOP))*EXP(-((FK(NHI)-FKMID)**2)/SIGSQ)
	IF(NK.LT.1) GO TO 2
	CLOW=CLOW*(FK(NLOW)**NK)
	CHI=CHI*(FK(NHI)**NK)
2	DO 3 I=1,256
	X(I)=DELX*I*TWOPI
	R(I)=CLOW*COS(FK(NLOW)*X(I))+CHI*COS(FK(NHI)*X(I))
	FI(I)=CLOW*SIN(FK(NLOW)*X(I))+CHI*SIN(FK(NHI)*X(I))
	DO 4 J=NBOT,NTOP
	R(I)=R(I)+FP(J)*COS(FK(J)*X(I))
	FI(I)=FI(I)+FP(J)*SIN(FK(J)*X(I))
4	CONTINUE
	X(I)=X(I)/TWOPI
	Y(I)=SQRT(R(I)**2+FI(I)**2)
3	CONTINUE
C
C  OUTPUT RESULTS
C
	DO 7 I=1,256
	X(I)=1000*X(I)
	Y(I)=Y(I)*CON2
	R(I)=R(I)*CON2
	FI(I)=FI(I)*CON2
7	CONTINUE
	
	CALL WFILE(Y,FILNAM,256)
	FILNAM(8)='R'
	FILNAM(9)='E'
	FILNAM(10)='A'
	CALL WFILE(R,FILNAM,256)
	FILNAM(8)='I'
	FILNAM(9)='M'
	FILNAM(10)='A'
	CALL WFILE(FI,FILNAM,256)
	FILNAM(8)='R'
	FILNAM(9)='S'
	FILNAM(10)='P'
	CALL WFILE(X,FILNAM,256)
	CALL EXIT
100	FORMAT('$ K FILENAME        ? ')
101	FORMAT(10A1)
102	FORMAT('$ F(K) FILENAME     ? ')
103	FORMAT('$ X FILENAME        ? ')
104	FORMAT('$ F(X) FILENAME     ? ')
105	FORMAT('$ NLOW,NHI,NK,RANGE,WINCEN,WINSIG,TWOPI ? ')
106	FORMAT(3I5,3F12.5,I5)
	END
