;+
; Convert channel number to frequency (Hz) using
; the supplied data container. Optionally return the frequency in
; another reference frame
;
; @param data {in}{required}{type=spectrum} The spectrum data
; container to use to get the necessary header information.
;
; @param chans {in}{required} The channel numbers to convert, may be
; an array of values.
;
; @keyword frame {in}{optional}{type=string} The rest frame to convert
; to. Known rest frames are listed in
; frame_velocity.html. Defaults to the frame given in
; the data.frequency_type.
;
; @keyword true_frame {out}{optional}{type=string} The actual rest frame used in
; constructing the frequencies. The only way this will not equal
; the frame argument is if that argument was invalid. In that
; case, this keyword will be the same as the frame in
; data.frequency_type.
;
; @returns frequencies (Hz)
;
; @uses data_valid
; @uses frame_velocity
;
; @version $Id: chantofreq.pro,v 1.6 2005/03/24 22:41:06 bgarwood Exp $
;-
function chantofreq, data, chans, frame=frame, true_frame=true_frame
compile_opt idl2
; argument check on data
if (data_valid(data, name=name) le 0) then begin
message, "invalid or undefined data structure"
; message will cause things to fail here.
endif
if (name ne 'SPECTRUM') then begin
message, "data must be a spectrum structure"
; message will cause things to fail here.
endif
if (n_elements(frame) eq 0) then begin
frame = data.frequency_type
endif else begin
if (size(frame,/type) ne 7) then begin
message, "refframe has the wrong type, using value from data.frequency_type",/info
frame = data.frequency_type
endif else begin
if (frame eq "OBS") then frame = "TOPO"
endelse
endelse
; start by constructing the frequency axis
result = double(chans)
result = result - data.reference_channel
result = result * data.frequency_interval
result = result + data.reference_frequency
offset = 0.0
; result is now in frame given in data.frequency_type
result = freqtofreq(data, result, frame, data.frequency_type)
true_frame = frame
return, result
end