		function Chanfreq,Channel,Receiver

;+
; The CHANFREQ function returns the frequency corresponding to
; the channel number given or vice versa, in dependency of the
; input value "Chan":
; 	if "Chan" is less than 2,000,000, then "Chan" is
;	interpreted as a channel number; if not, then "Chan"
;	is interpreted as a frequency.
;
;  Rec_type is a type of the receiver: 0 is MFB (180 channels),
;  1 is AOR (192 channels). For the calculations concerning
;  AOR the measured regression dependency "channel-frequen-
;  cy" is used. The edges of the operation band are of no
;  significance (e.g. you can put and get the channel numbers
;  -257.789 as well as +1576.985).
;
;  All the output variables are floating-point, double precision.
;
;  If input variable "Chan" is array, then CHANFREQ returns also
;  an array of the same sizes as the input variable.
;
;	EXAMPLES:
;
;	Fx = CHANFREQ(198,0)	returns the frequency Fx
;		corresponding to the effective channel of
;		number 198 for the MFB receiver.
;
;	Nx = CHANFREQ(5.4789d9,1) returns the effective channel
;		number Nx of the AOR receiver corresponding to
;		the frequency 5.4789E+9
;
;	Nmfb = CHANFREQ(CHANFREQ(Naor,1),0) returns channel
;		number of MFB corresponding to the same
;		frequency as the AOR channel Naor.
;
;-

	a=double(Channel)	&	M=double(Receiver)

Dc0=0;10000
Dc1=0;0.01d6
Dc2=0;1500



Dfmin=0

Mc=[0,3]
Fmin=[5.675241d9, 5.676136d9+Dfmin]

Df1=[0.652d6, 0.584d6+Dc0+Dc1]
Df2=[0.642d6, 0.584d6+Dc0]
Df3=[0.642d6, 0.584d6+Dc0]
Ddf=[0.6222273d6, 0.584d6+Dc2]

f1=Fmin+(44+Mc)*Ddf+Df1/2.
f2=Fmin+2*(44+Mc)*Ddf+Df1+Df2/2.
f3=Fmin+3*(44+Mc)*Ddf+Df1+Df2+Df3/2.


	if a(0) lt 2d6 then begin

	B=Fmin(M)+(a-1)*Ddf(M)

	B=B+	$
	(-Ddf(M)+Df1(M))*(a gt 45+Mc(M) and a le 90+2*Mc(M))+ $
	(-2*Ddf(M)+Df1(M)+Df2(M))*(a gt 90+2*Mc(M)and a le 135+3*Mc(M))+ $
	(-3*Ddf(M)+Df1(M)+Df2(M)+Df3(M))*(a gt 135+3*Mc(M))

	endif else begin

	B=(a-Fmin(M))/Ddf(M)+1

	B=B+	$
	(-Df1(M)/Ddf(M)+1)*(a gt f1(M) and a le f2(M))+ $
	((-Df1(M)-Df2(M))/Ddf(M)+2)*(a gt f2(M) and a le f3(M))+ $
	((-Df1(M)-Df2(M)-Df3(M))/Ddf(M)+3)*(a gt f3(M))

	endelse

return,B


end
