close all
clear all

cast_dir = 'CastDepths/';
filenames = dir([cast_dir '*.asc']);

StartOfDay = datenum(2014,4,2,0,0,0);

all_time = [];
all_depth = [];
all_temp = [];
all_xmiss = [];
all_wetstar = [];
all_sal = [];

for i = 1:length(filenames)
    
   castdata{i} = importdata([cast_dir filenames(i).name]);
   
   time{i} = castdata{i}.data(:,1);
   time{i} = StartOfDay + mod(time{i},floor(time{i}));  %Convert to Unix Time.
   
   depth{i} = castdata{i}.data(:,3);
   temp{i} = castdata{i}.data(:,4);
   xmiss{i} = castdata{i}.data(:,8);
   wetstar{i} = castdata{i}.data(:,10);
   sal{i} = castdata{i}.data(:,16);
   
  % subplot(2,length(filenames),i)
  % plot(time{i},-depth{i},'-x');
  % datetick('x');
  % xlabel('time (UTC)');
  % ylabel('depth (m)');
  % title(filenames(i).name);

   all_time = [all_time ; time{i} ; NaN];
   all_depth = [all_depth ; depth{i} ; NaN];
   all_temp = [all_temp ; temp{i}; NaN];
   all_xmiss = [all_xmiss ; xmiss{i}; NaN];
   all_wetstar = [all_wetstar ; wetstar{i}; NaN];
   all_sal = [all_sal ; sal{i}; NaN];

end


%subplot(2,length(filenames),[5 6 7 8])
figure('Position', [705 390 1777 1108],'PaperSize',[11 17],'PaperOrientation','landscape','PaperPositionMode','auto','PaperPosition',[.5 .5 16.5 10.5])

subplot(5,1,1)
plot(all_time,-all_depth,'-x');
datetick('x');
ylabel('depth (m)');
title('April 2nd, 2014  -  All Casts');

subplot(5,1,2)
plot(all_time,all_temp,'-x');
datetick('x');
ylabel('temp (deg C)');

subplot(5,1,3)
plot(all_time,all_sal,'-x');
datetick('x');
ylabel('salinity');

subplot(5,1,4)
plot(all_time,all_xmiss,'-x');
datetick('x');
ylabel('xmiss (%)');

subplot(5,1,5)
plot(all_time,all_wetstar,'-x');
datetick('x');
ylabel('Clorophyll Flouresence');
xlabel('time (UTC)');


print('-dpdf','04022014_CTD_Data');

for i = 1:2:7
    
figure('Position', [705 72 1138 1426],'PaperSize',[11 17],'PaperOrientation','portrait','PaperPositionMode','auto','PaperPosition',[.5 .5 10.5 16.5])

subplot(4,1,1)
plot(-depth{i}(2:end-1),temp{i}(2:end-1),'-x',-depth{i+1}(2:end-1),temp{i+1}(2:end-1),'-o');
ylabel('temp (deg C)');
xlabel('depth (m)');
legend('DownCast','UpCast','Location','NorthWest');
title(['April 2nd, 2014  -  Cast number ' num2str((i+1)/2)]);

subplot(4,1,2)
plot(-depth{i}(2:end-1),sal{i}(2:end-1),'-x',-depth{i+1}(2:end-1),sal{i+1}(2:end-1),'-o');
legend('DownCast','UpCast');
ylabel('salinity');
xlabel('depth (m)');

subplot(4,1,3)
plot(-depth{i}(2:end-1),xmiss{i}(2:end-1),'-x',-depth{i+1}(2:end-1),xmiss{i+1}(2:end-1),'-o');
legend('DownCast','UpCast');
ylabel('xmiss (%)');
xlabel('depth (m)');

subplot(4,1,4)
plot(-depth{i}(2:end-1),wetstar{i}(2:end-1),'-x',-depth{i+1}(2:end-1),wetstar{i+1}(2:end-1),'-o');
ylabel('Clorophyll Flouresence');
legend('DownCast','UpCast','Location','NorthWest');
xlabel('depth (m)');


print('-dpdf',['04022014_CTD_Data_Cast_' num2str((i+1)/2)]);


end


