function OutData = ParseLine(tempstring)
%OutData = ParseLine(tempstring)
%OutData = ParseLine(tempstring)
%Parseline is a rudimentary string parser
%Parseline removes comments, and returns a cell array
%in which each cell is a string defined by whitespace
%seperated data
%
%INPUT
%tempstring = the string to be parsed
%
%OUTPUT
%OutData = a cell array of string in which each cell
%is a whitespace sepetated portion of tempstring
%
%Written by K. Steffen (ksteffen@unm.edu) at the University of New Mexico,
%Department of Earch and Planetary Science
%Copyright 2003 Kurt Steffen
%
%Last Modified June 17, 2003

CommentIndex = findstr(tempstring,'%');
if ~isempty(CommentIndex) %removing comments
	tempstring = tempstring(1:CommentIndex-1);
end

commaindex1 = findstr(tempstring,'	');
commaindex2 = findstr(tempstring,' ');
commaindex = [commaindex1 commaindex2];
commaindex = sort(commaindex);
if ~isempty(commaindex)
	if commaindex(end) == length(tempstring) %removing trailing spaces/tabs
		temp = commaindex(end);
		commaindex(end) = [];
		for l = length(commaindex):-1:1
			if temp-1 == commaindex(l)
				temp = commaindex(l);
				commaindex(l) = [];
			else
				break
			end
		end
	end
end
for k = length(commaindex):-1:2  %removing duplicate spaces/tabs
	if commaindex(k)-1 == commaindex(k-1)
		commaindex(k) = [];
	end
end
if isempty(commaindex) %adding single space/tab to end of input
    	commaindex(1) = length(tempstring) + 1;
else
	commaindex(length(commaindex)+1) = length(tempstring)+1;    	
end
OutData = cell(0);

for k = 1:length(commaindex) %reading strings
	if k ==  1
      		shortstring = tempstring(1:commaindex(1)-1);
        	temp  = sscanf(shortstring,'%s',1);
        	OutData(k) = {temp};
    	elseif k == length(commaindex)
        	shortstring = tempstring(commaindex(k-1)+1:end);
        	temp  = sscanf(shortstring,'%s',1);
        	OutData(k) = {temp};       
    	else
        	shortstring = tempstring(commaindex(k-1)+1:commaindex(k)-1);
        	temp  = sscanf(shortstring,'%s',1);
        	OutData(k) = {temp};   
    	end
end