function datastr = convertYSI6600_profile2MAT(filename)
  

[r,c]=size(filename)

for k=1:r
    
    fname = filename(k,:)

fid=fopen([fname '.CDF']);

head1=fgetl(fid);
head2=fgetl(fid);

count = 1;
while ~feof(fid)

t2=fgetl(fid);
space=strfind(t2,'"');
datestring=t2(space(1)+1:space(2)-1)
    datesep =strfind(datestring, '/');
    ctddate(count, 1)=str2num(datestring(1:datesep(1)-1));          %month
    ctddate(count, 2)=str2num(datestring(datesep(1)+1:datesep(2)-1)); %day
    ctddate(count, 3)=str2num(datestring(datesep(2)+1:end)); %year

timestring=t2(space(3)+1:space(4)-1);
    timesep = strfind(timestring, ':');
    hour=str2num(timestring(1:timesep(1)-1));
    min=str2num(timestring(timesep(1)+1:timesep(2)-1));
    sec=str2num(timestring(timesep(2)+1:end));
    
    ctdtime(count, 1) = hour ;
    ctdtime(count, 2) = min;
    ctdtime(count, 3) = sec;
    
nums = t2(space(4)+1:end);
numsep = strfind(nums,',');

for i = 1:length(numsep)-1
val(i)=str2num(nums(numsep(i)+1:numsep(i+1)-1));
end

i=i+1;
val(i)=str2num(nums(numsep(i)+1 : end))

% test for same number of values on each line
if length(val)==7
    data(count,:)=val;
    count = count+1;
end
end

ctdpress=data(:,6);
ctdtemp=data(:,1);
ctdturbidity=data(:,7);
ctdresist=data(:,3);%updated 10/7/14 to use ctd that get rsitivity and tds
ctdtds=data(:,4);
%ctdsal=data(:,3);
%ctdsal=data(:,4);%Updated to use with YSI6600 CTD V18416
ctdsal=data(:,5);
ctdcond=data(:,2);


eval (['save ' fname '  ctddate ctdtime ctdpress ctdtemp ctdturbidity ctdsal ctdcond ctdresist ctdtds '])

figure (100)
plot (-ctdpress)
[x y]=ginput
x=round(x)



prodate=ctddate(x(1):x(2),:);
protime=ctdtime(x(1):x(2),:);
propress=data(x(1):x(2),7)
protemp=data(x(1):x(2),1);
proturbidity=data(x(1):x(2),5);
prosal=data(x(1):x(2),6);
procond=data(x(1):x(2),3);
proresist=data(x(1):x(2),4);
protds=data(x(1):x(2),5);
eval (['save ' fname '-pro  prodate protime propress protemp proturbidity prosal procond  '])

eval (['save ' fname 'index.asc x -ascii'])  %1st 2 are profile start and stop times and rest are TSS depth start and stop times

fclose(fid);

clear ctddate ctdtime ctdpress ctdtemp ctdobs ctdsal ctdcond ctddensity
clear prodate protime propress protemp proobs prosal procond prodensity 
clear x
end;