function [thelabels,data,thenames,nameslabels] = GetData(thefile,delim,cell,namecols)
%[thelabels,data,thenames,nameslabels] = GetData(thefile,delim,cell,namecols)
%reads input text file and seperates labels and data 
%returns a cell on the labels and double array of the data
%does not read any data after a % (percent sign) on that line
%
%INPUT
%thefile = the file to be read
%delim = the delimating charactor in the file
%cell = should numeric data be converted into an array of doubles
%namecols = names of any columns that should be seperated (for instance a column of 
%strings in a array of doubles
%
%OUTPUT
%thelabels = the first row which are string labels and outputed as a cell array
%data = the numeric data, outputed as a cellarray of doubles or as a double array 
%depending on value of cell
%thenames = the columns removed (cell array of strings
%nameslabels = labels of columns that are removed 
%
%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 13, 2003

if nargin ==  1 | nargin == 2
    cell = 'null';
    namecols = [];
end
if nargin == 3
    namecols = [];
end
data = fileread4(thefile,delim); %the input data 
thelabels = data(1,:); %First row of input cell is the labels
data(1,:) = []; %removing label row from cell
if ~isempty(namecols)    
    thenames = data(:,namecols);
    data(:,namecols) = [];
    nameslabels = thelabels(namecols);
    thelabels(namecols) = [];
else
    nameslabels = [];
    thenames = [];
end
if cell == 'null' | cell == 0
    data = cell2double(data); %converting data to double array
end
