function [hdrs,dat]=rdctd(fnam)
%
%  Program to read CTD processed file, determine
%    the number of variables in the file, and
%    load in the data into an arrary.  Must be
%    tab delimited and the first row contain
%    the column names where each column name
%    must begin with a letter and contain no
%    special characters (such as _, $,% etc..)
%
%  INPUTS
%    FNAM = file name to read in.
%
%  OUTPUTS
%    HDRs = character array that holds the column headers.
%
%    DAT2 = float array that holds the data
%
%
%  Written by Andrew Barnard, OSU, 1996.
%   


fid=fopen(fnam,'r');

if fid==-1
   fprintf('\r\n ERROR!!: %s not found EXIT\r\n', fnam)
   hdrs=-1;dat=-1;
   return
end

hdrs=fscanf(fid,'%s',[1]);
b=fscanf(fid,'%f',[1]);

btest=1;

while btest == 1
  b=fscanf(fid,'%f',[1]);
  btest=isempty(b);
  if btest == 1
   a=fscanf(fid,'%s',[1]);
   hdrs=str2mat(hdrs,a);
  end
end

ng=size(hdrs);
ncol=ng(1);

frewind(fid);
dum=fgetl(fid);
dat=fscanf(fid,'%f',[ncol inf]);


fclose(fid);



