function f_result=loadsegytraces(filename,ns,sl,fs,locator)
% LOADSEGYTRACES(filename,ns,sl,fs,locator) Keywords: SEG-Y, segy
% filename is the path string
% ns is the number of samples in a trace
% sl=length of a sample, in bytes (4 for float32)
% fs can be 'float32', etc. (format of samples)
% locator is a vector with the positions of the traces to be read
% example: locator=1:2:1200 will read every third trace including the 1200th
% trace on file.
% Output: a structure that has the following fields: S.traces, that has as many 
% columns (traces) as there are elements in the locator vector, and S.locator,
% that is identic with the input 'locator' vector
%
% See also LOADSEGYHEADERS, HEADERS

% Last revised: Nick Vlad, Jan. 2001

reel=3600;	% length of reel header in bytes
hl=240;		% trace header length in bytes

FID = fopen(filename,'r','n'); % The SEG-Y file is now OPEN for reading
if FID==-1 error(cat(2,'Cannot open ',filename));end
f_result.traces=zeros(ns,length(locator));
for i=1:length(locator)
	W(i)=reel+hl*locator(i)+ns*sl*(locator(i)-1);
	status=fseek(FID,reel+hl*locator(i)+ns*sl*(locator(i)-1),'bof');
	for j=1:ns
		f_result.traces(j,i)=fread(FID,1,fs);
	end
end
fclose(FID);
f_result.locator=reshape(locator,1,length(locator));
