% read RAW-IMET data stream and SAMOS rel wind for comparison
% SAMOS 1 min avg and IMET 5 sec raw data
% Dwolfe 3/10/2016
clear
close all

% im = load('IMET1145.TXT');

% IMET-Wind-201603101009.TXT
% im = load('IMET-Wind-201603101009.TXT');
im = load('IMET-Wind-201603101550.TXT'); %local time 

load('Samos70.mat'); %
jdd70 = jdd;
rws70 = rws;
rwd70 = rwd;
clear jdd rws rwd
load('Samos71.mat'); %
jdd71 = jdd;
rws71 = rws;
rwd71 = rwd;
clear jdd rws rwd

% data files starts at 1145 local (1745 UTC) 3/9/2016
% convert counts to time
ll = length(im);
dt = 5/60/60/24; % time increment 5 sec in Year day
% convert 8 hr to Year day decimal
d8 = (8/24);
yd = datenum(2016,3,10,15,50,0)-datenum(2016-1,12,31,00,00,00); 
yd(1) = yd(1) + d8; % add 8 hrs to first time
for j = 2:ll
    yd(j) = ((j*dt) + yd(1));
end
% calculate hour UTC (Local + 8)
hh = (((yd-70) * 24) + 8) - 24;


figure(1)
subplot(2,1,1),plot(yd,im(:,2),'k');
title('Prop-Vane')
ylabel('Spd m/s');
subplot(2,1,2),plot(yd,im(:,4),'k');
ylabel('Dir ?)');
ylim([ 0 360]);
xlabel('Year Day UTC');

figure(2)
subplot(2,1,1),plot(hh,im(:,2),'k');
title('Prop-Vane')
ylabel('Spd m/s');
subplot(2,1,2),plot(hh,im(:,4),'k');
ylabel('Dir ?)');
xlabel('Hr UTC');

% plot SAMOS relative winds

figure(9)
    subplot(2,1,1),plot(jdd70,rws70,'k')
    hold
    subplot(2,1,1),plot(jdd71,rws71,'k')
    ylim([ 0 30]);
    title('SAMOS');
    ylabel('Wind Spd Rel (ms^-^1)');
    subplot(2,1,2),plot(jdd70,rwd70,'k')
    hold
    subplot(2,1,2),plot(jdd71,rwd71,'k')
    ylabel('Wind Dir Rel');
    ylim([ 0 360]);

    % add 90 to IMET and subtract 360 if GT 360
    lm = length(im);
    
    for k = 1:lm
        im(k,4) = im(k,4) + 90;
        if im(k,4) > 360;
            im(k,4) = im(k,4) - 360;
        end
    end
    
    figure(3)
    subplot(2,1,1),plot(jdd70,rws70,'k')
    hold
    subplot(2,1,1),plot(jdd71,rws71,'k')
    subplot(2,1,1),plot(yd,im(:,2),'r');
    ylim([ 0 15]);
    title('SAMOS');
    ylabel('Wind Spd Rel (ms^-^1)');
    axis ([ 70.9900   71.0500         0  15.0000])
    legend('','SAMOS','PV','location','Northeast');
    grid
    
    subplot(2,1,2),plot(jdd70,rwd70,'k')
    hold
    subplot(2,1,2),plot(jdd71,rwd71,'k')
    subplot(2,1,2),plot(yd,im(:,4),'r');
    ylabel('Wind Dir Rel');
    ylim([ 0 360]);
     axis ([ 70.9900   71.0500         0  360.0000])
     grid
     