%Read SCS Event file
% Each Event is stopped and started to creat daily files (UTC)
% DEW LB 7/10/2013
% Gave copy to WHOI
disp('Read_SCS_WHOTS_2013');

clear
close all

cruise='WHOTS_2013';     % Cruise name, for example 'STRATUS_2009', 'TOTO_1969', etc...
ship='Hiialakai';                % Research vessel
data_drive='D:\';
Lacie_drive='G:\';
plotit = 0;  % print plot to png


way_proc_data_flux = [data_drive cruise  '\' ship '\flux\Processed\'];     % Processed data path
way_images_flux = [data_drive cruise  '\' ship '\flux\Raw_Images\' ];

ev = input('Input SCS event number to read (011) ','s');

%Ludo's read
clear dir
dr=dir(['D:\WHOTS_2013\Hiialakai\SCS\Raw\WHOTS-OBS_' ev '.elg']);
e=dr(1).name;
disp(['Reading scs file ',e]);
flist=fopen(['D:\WHOTS_2013\Hiialakai\SCS\Raw\WHOTS-OBS_' ev '.elg']);
temp=[];scsdata=[];
if flist>0,                                 %if the file exists,
    while ~feof(flist)
%             temp=textscan(flist,'%f %f %f %*c %f %f %f %*c %f %f %*c %f %f %*c %f %f %*c %f %f %*c %f %f %f %f %f  %*[^\n]','delimiter', ' ', 'treatAsEmpty', {'SBE-21','****','FWD','Temp'}, 'headerlines', 1,  'emptyvalue', NaN);
            temp=textscan(flist,'%2f/%2f/%4f %2f:%2f:%2f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %*4c %f %f %f %*6c %f %*c %f %*c %*4c %f %f %f  %*[^\n]','delimiter', ', ', 'headerlines', 1,  'emptyvalue', NaN);
            scsdata=[scsdata cell2mat(temp)'];        
    end;  %end while
end;      %     end if list
scs = scsdata;

% a=['D:\WHOTS_2013\Hiialakai\SCS\Raw\WHOTS-OBS_' bds '.dat'];
% scs = load(a);
% 1-3 Date
% 4-6 Time UTC
% 7 SAMOS-Lat-VALUE
% 8 SAMOS-Lon-VALUE
% 9 SAMOS-Gyro-VALUE
% 10 SAMOS-COG-VALUE
% 11 SAMOS-SOG-VALUE
% 12 SAMOS-AirTemp-VALUE                 **** RMYoung deg C
% 13 SAMOS-Barometer-VALUE             Bad RMYoung
% 14 SAMOS-RelHumidity-VALUE            **** RMY %
% 15 SAMOS-RelWind-Dir-VALUE
% 16 SAMOS-RelWind-Spd-VALUE
% 17 SAMOS-TrueWind-Dir-VALUE           *** Prop-Vane deg T
% 18 SAMOS-TrueWind-Spd-VALUE              *** Prop-Vane kts
% 19 SAMOS-TSG-Temp-VALUE              **** SST deg C
% 20 SAMOS-TSG-Cond-VALUE
% 21 SAMOS-TSG-Sal-VALUE
% 22 SAMOS-TSG-SV-VALUE
% 23 WINCH-PAYOUT
% 24 WINCH-SPD
% 25 WINCH-TENSION
% 26 WIND-85004-Ultrasonic-Anemometer   Rel dir deg 
% 27 WIND-85004-Ultrasonic-Anemometer   Rel spd kts
% 28 Depth-Meters
% 29 Vaisala-Barometer--               Good Station pressure mb
% 30 Baro-Pressure  **Bad RMY

% Calculate Decimal year day
yd_scs=datenum(scsdata(3,:),scsdata(1,:),scsdata(2,:),scsdata(4,:),scsdata(5,:),scsdata(6,:))-datenum(scsdata(3,1),1,0);   %Day-Of-Year
bd = fix(yd_scs(1));
ed = bd + 1;
bds = num2str(bd);

figure
plot(yd_scs,scs(29,:),'b')  %Vaisala-Barometer-
ylabel('Pressure (mb)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 Pressure');
grid
xlim([ bd ed ]);
ylim([ 1010 1030]);
legend('SCS','location','best');

if plotit
    print_buffer = [way_images_flux cruise '_SCS_PSD_P_' bds '.png'];
    print('-dpng ', print_buffer);
end

%  Plot RMY and other pressures
if 0
figure
plot(yd_scs,scs(:,35),'b') %Baro-Pressure
hold
plot(yd_scs,scs(:,34),'r') %Vaisala-Barometer-
plot(yd_scs,scs(:,13),'g')  %Samos-Barometer-Value
plot(met(1,:),met(12,:),'k.')  % PSD
ylabel('Pressure (mb)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 Pressure');
grid
xlim([ bd ed ]);
legend('RMY','SCS','RMY','PSD','location','best');

if plotit
    print_buffer = [way_images_flux cruise '_SCS_PSD_Pall_' bds '.png'];
    print('-dpng ', print_buffer);
end

end

figure
plot(yd_scs,scs(19,:),'b') % Samos-TSG-Temp
ylabel('SST (C)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 SST');
grid
xlim([ bd ed ]);
legend('SCS','location','best');

if plotit
    print_buffer = [way_images_flux cruise '_SCS_PSD_SST_' bds '.png'];
    print('-dpng ', print_buffer);
end

figure
subplot(2,1,1),plot(yd_scs,scs(12,:),'b') % Samos-AirTemp
ylabel('Air T (C)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 Air Temp');
grid
xlim([ bd ed ]);
legend('SCS','location','best');

subplot(2,1,2),plot(yd_scs,scs(14,:),'b') % Samos-RH-Temp
ylabel('RH(%)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 RH');
ylim([ 0 100]);
grid
xlim([ bd ed ]);

if plotit
    print_buffer = [way_images_flux cruise '_SCS_PSD_TRH_' bds '.png'];
    print('-dpng ', print_buffer);
end

figure
subplot(2,1,1),plot(yd_scs,scs(17,:),'b.') % Samos-TrueWind-Dir
ylabel('Dir (T)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 Dir True');
ylim([ 0 360]);
grid
xlim([ bd ed ]);
legend('SCS P-V','location','best');

subplot(2,1,2),plot(yd_scs,scs(18,:)*.55,'b') % Samos TruWind Speed
ylabel('Spd (m/s)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 Spd True');
ylim([ 0 25]);
xlim([ bd ed ]);
grid

if plotit
    print_buffer = [way_images_flux cruise '_SCS_PSD_DirSpdT_' bds '.png'];
    print('-dpng ', print_buffer);
end


figure
subplot(2,1,1),plot(yd_scs,scs(15,:),'b.') % Samos WindDir-Rel
hold
plot(yd_scs,scs(26,:),'r.')  % Ultra Sonic
ylabel('Dir (Rel)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 Dir Rel');
ylim([ 0 360]);
grid
xlim([ bd ed ]);
legend('SCS P-V','SCS Son','location','best');

subplot(2,1,2),plot(yd_scs,scs(16,:)*.55,'b') % Samos-WindRel Rel
hold
plot(yd_scs,scs(27,:)*.55,'r') % Ultra Sonic
ylabel('Spd (m/s)');
xlabel('Year Day (UTC)')
title('WHOTS 2013 Spd Rel');
ylim([ 0 25]);
grid
xlim([ bd ed ]);

if plotit
    print_buffer = [way_images_flux cruise '_SCS_PSD_DirSpdR_' bds '.png'];
    print('-dpng ', print_buffer);
end
