
function [power_time,mean_I,mean_Q,mean_I2,mean_Q2,velocity,width,noise_threshold,n_gates,ad_sampling,start_date]=read_xband_datfile(file_name)

% get time from file name
	
	[k]=findstr(file_name,'moments.');
	T=file_name(k+8:end);

	year=str2num(T(1:4));
	month=str2num(T(5:6));
	day=str2num(T(7:8));

	hour=str2num(T(10:11));
	min=str2num(T(12:13));
	sec=str2num(T(14:15));
 	msec=str2num(T(17:19));
	
% start_date=time_to_year_fraction(year,month,day,hour,min,sec+1E-3*msec) ;
start_date=time_to_year_fraction(year,month,day,0,0,0) ;
start_date = [year month day hour min sec msec];	
% if gzip ... then copy to unzipped version ... temporarily
if( strcmp(file_name(end-2:end),'.gz') )
	test=unix(['gzip -d -c ' file_name ' >temp.dat' ])
	fid=fopen('temp.dat','r','l');
else
	fid=fopen([file_name],'r','l');
end

N_time_samples=fread(fid,[1 1],'int');  % number of radar pulse acquire per moment
n_gates=fread(fid,[1 1],'int');
ad_sampling=fread(fid,[1 1],'int');
size_of_record=4*(6*n_gates+6);
a=dir(file_name);
n_rows=1024;  % number of profiles for each moment

%mean_I=NaN(n_gates,n_rows);
%mean_Q=NaN(n_gates,n_rows);
%mean_I2=NaN(n_gates,n_rows);
%mean_Q2=NaN(n_gates,n_rows);
%velocity=NaN(n_gates,n_rows);
%width=NaN(n_gates,n_rows);
%noise_threshold=NaN(n_gates,n_rows);
%power_time=NaN(1,n_rows);



data=1;
count=0;
while(~isempty(data) & count < (n_rows+1))

	% read time header data
	data=fread(fid,[4 1],'int');
	
	if(~isempty(data))

		count=count+1;
		power_time(count)=data(1)+data(2)/60+(data(3)+0.001*data(4))/3600;

		
	        mean_I(1:n_gates,count)=-1*fread(fid,[n_gates 1],'float');
        	mean_Q(1:n_gates,count)=-1*fread(fid,[n_gates 1],'float');
        
	        mean_I2(1:n_gates,count)=fread(fid,[n_gates 1],'float');
        	mean_Q2(1:n_gates,count)=fread(fid,[n_gates 1],'float');      
	
		data=fread(fid,[n_gates 1],'float');
		velocity(1:n_gates,count)=data;

		data=fread(fid,[n_gates 1],'float');
		width(1:n_gates,count)=data;
        
                data=fread(fid,[n_gates 1],'float');
		noise_threshold(1:n_gates,count)=data;
        
	end
end

fclose(fid);

return
