
	PROGRAM PREAMP
C
C	THIS PROGRAM CALCULATES THE ELECTRIC PREAMP RESPONSE, 
C	WITH (ICOMP=1)  OR WITHOUT (ICOMP=0) COMPENSATION FILTER
C	IT WRITES A FILE FOR011.DAT TO BE PLOTTED BY MONGO
C
	COMPLEX Z1,Z2,Z3,Z4,Y1,Y2,VIN,VAC,VDC,V1,V2,V3
	DATA ICOMP /0/
	DATA C9 /22.E-12/
	DATA R9,R10 /5.E8,5.E8/
	DATA R33 /1.E4/
	DATA C16 /1.E-8/
	DATA C12,C13,C15/15.E-9,4.7E-9,180.E-12/
	DATA R28,R29,R32 /1.E5, 1.2E3, 2.2E3/
	DATA R2C,C2C /4.64E3,1.E-6/
	DATA TWOPI /6.2831853/
	DATA FHZMIN,FHZMAX,NF /1.,200.E3,120/
C
	FRAT = ALOG(FHZMAX/FHZMIN)/(NF-1)
	FRAT = EXP(FRAT)
	FHZ = FHZMIN
	VIN = 1.
	DO 100 NN = 1,NF
	W = TWOPI*FHZ
C
C	GAIN OF THE INPUT CIRCUIT, BEFORE Q1
C
	Y1 = CMPLX(1./R9, W*C9)
	Z1 = 1./Y1
	V1 = VIN*R10/(R10 + Z1)
C
C	GAIN OF THE DC OUTPUT
C
	Z1 = CMPLX(R33,-1./W/C16)
	Z2 = CMPLX(0.,-1./W/C16)
	VDC = V1*Z2/Z1
C
C	GAIN OF THE OUTPUT CIRCUIT AROUND U2
C	V1 IS THE RELAY OUTPUT
C
	Z1 = CMPLX(R28,-1./(W*C12))
C	V2 IS THE INPUT AT PIN 3 OF U2
	V2 = V1*R28/Z1
C	V3 IS THE OUTPUT VOLTAGE AT PIN 6 OF U2
	Y1 = CMPLX(1./R32,W*C15)
	Z1 = 1./Y1
	Z2 = CMPLX(R29,-1./W/C13)
	V3 = V2*(Z2 + Z1)/Z2
	IF(ICOMP.NE.0) THEN
C
C	  COMPENSATION NETWORK FOR INPUT CIRCUIT, CONSISTING OF
C	  R1C IN SERIES WITH R2C AND C2C
C
	  V2 = VDC
	  Z1 = CMPLX(R2C,-1./W/C2C)
	  Z2 = CMPLX(R1C,0.)
	  VDC = V2*Z1/(Z2 + Z1)
	ENDIF
C
C	WRITE OUTPUT FILE
C
	VAC = V3
	GAINAC = CABS(VAC)
	VR = VAC
	VI = AIMAG(VAC)
	PHAC = 57.29578*ATAN2(VI,VR)
	GAINDC = CABS(VDC)
	VR = VDC
	VI = AIMAG(VDC)
	PHDC = 57.29578*ATAN2(VI,VR)
C
	WRITE(11,1001) FHZ,VAC,GAINAC,PHAC,VDC,GAINDC,PHDC
 1001	FORMAT(E13.4,3F7.3,F6.1,2X,3F7.3,F6.1)
	PRINT*,FHZ,VAC,GAINAC,PHAC
	FHZ = FHZ*FRAT
 100	CONTINUE
	STOP
	END
	SUBROUTINE MGO
C	THIS IS  PREAMP.MGO
C	STORED HERE FOR REFERENCE--TO BE RUN INTERACTIVELY
C
C	DATA FOR011.DAT
C	FORMAT (E13.4,3F7.3,F6.1,2X,3F7.3,F6.1)
C	XCOLUMN 1
C	XLOGARITHM 1
C	YCOLUMN 4                 ! GAIN AC
C	LIMITS  -0.5  6.   0.  4.
C	CONNECT
C	BOX
C	XCOLUMN 1
C	XLOGARITHM 1
C	YCOLUMN 8                 ! GAIN DC
C	LIMITS 0.  6.  0.  5.
C	CONNECT
C	XLABEL LOG FREQUENCY (HZ)
C	YLABEL GAIN
C	ID
	RETURN
	END
