
function [spectra,spectra_velocity,wavelength,IPP,gates_selected]=read_spectra_data_file(file_name)

	fid=fopen([file_name],'r','l');


wavelength=fread(fid,[1 1],'float');
IPP=fread(fid,[1 1],'float');

n_points_in_fft=fread(fid,[1 1],'int');
n_gates=fread(fid,[1 1],'int');

gates_selected=fread(fid,[1 n_gates],'short');

% calculate fft velocity
dummy=0.5*wavelength/(n_points_in_fft*IPP);
for i=1:n_points_in_fft
	spectra_velocity(i)=(i - 0.5*n_points_in_fft -1)*dummy;
end


spectra=zeros([n_gates n_points_in_fft]);
for j=1:n_gates;
	if(gates_selected(j))
		spectra(j,(0.5*n_points_in_fft+1):n_points_in_fft)=fread(fid,[1 0.5*n_points_in_fft],'float');
		spectra(j,1:(0.5*n_points_in_fft))=fread(fid,[1 0.5*n_points_in_fft],'float');

	end
		spectra(j,129)=(spectra(j,130)+spectra(j,128))/2;
	       
end


fclose(fid);

return
