disp('read_scs_STRATUS_2015.m')
fclose('all');

% loading mat file of ship data
scs_path = fullfile(data_drive,cruise,ship,'SCS','WHOIsShipWXT.mat');
load(scs_path);

rdcon = pi/180;

jd_scs = scs.mday - datenum(2014,12,31);
jd_scs = round(jd_scs*1440)/1440;
ii = find(floor(jd_scs)==ddd);
jd_scs = jd_scs(ii);
% imum = scs.wspd(ii)*0.5144; % m/s
% imdm = scs.wdir(ii);
% imuxm = imum'.*cos(imdm'*rdcon); %convert to N
% imuym = imum'.*sin(imdm'*rdcon); %convert to E
impresm = scs.bpr(ii);
tam = scs.atmp(ii);
rhm = scs.hrh(ii);
lrgm = scs.heading(ii);
lrgcm = cos(lrgm'*rdcon);       % convert to N
lrgsm = sin(lrgm'*rdcon);       % convert to E
sogm = scs.speed(ii).*0.51444;    % m/s
sogxm = sogm'.*lrgcm;           % convert to N
sogym = sogm'.*lrgsm;           % convert to E
cogm = lrgm;                    % use heading for cog...
odecm = sogm;                   % use sog for odec

% loading mat file of ship wind data
wind_path = fullfile(data_drive,cruise,ship,'SCS','STRATUS_2015_scs_winds.mat');
load(wind_path);
jd_scs_winds = winds(:,1);
imum =  winds(:,2);
imdm = winds(:,3);
imuxm = imum'.*cos(imdm'*rdcon); %convert to N
imuym = imum'.*sin(imdm'*rdcon); %convert to E
imrwspdm = winds(:,4);
imrwdirm = winds(:,5);
imrwdirm(imrwdirm>180) = imrwdirm(imrwdirm>180) - 360;

% other variables are missing...
latm = jd_scs*NaN;
lonm = jd_scs*NaN;
tsgm = jd_scs*NaN;        
tssm = jd_scs*NaN;         
irm = jd_scs*NaN;  	    
solarm = jd_scs*NaN; 	      
rainm = jd_scs*NaN; 	   

[month,day] = yd2md(2015,ddd);
Vdate = [2015 month day];

if plotit && ~isempty(imum)

    figure;subplot(2,1,1)
     plot(jd_scs_winds,imum,'r');
     xlabel('Hour (UTC)');ylabel('Wind speed (m/s)');xlim([ddd ddd+1])
     title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS Wind speed',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
     set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
     xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
     grid
     subplot(2,1,2)
     plot(jd_scs_winds,imdm,'.')
     xlabel('Hour (UTC)');ylabel('Wind direction (deg)');axis([ddd ddd+1 0 360])
     title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS Wind direction',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
     set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
     xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
     grid;
     annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
     if prtit
         ppath = fullfile(way_images_flux,[cruise,'_SCS_Wind_Speed_Dir_',sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd),graphformat]);
         print(graphdevice,ppath);
     end;

    figure;
    plot(jd_scs,tam);
    xlabel('Hour (UTC)');ylabel('Tair, C');xlim([ddd ddd+1]);
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS Air Temperature',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid;
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit
        ppath = fullfile(way_images_flux,[cruise,'_SCS_Tair_',sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd),graphformat]);
        print(graphdevice,ppath);
    end;

    figure;
    plot(jd_scs,rhm);
    xlabel('Hour (UTC)');ylabel('RH (%)');axis([ddd ddd+1 40 100])
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS Relative Humidity',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid;
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit
        ppath = fullfile(way_images_flux,[cruise,'_SCS_RH_',sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd),graphformat]);
        print(graphdevice,ppath);
    end;


    figure;
    plot(jd_scs,impresm);
    xlabel('Hour (UTC)');ylabel('Pressure (mb)');
    axis([ddd ddd+1 median(impresm(~isnan(impresm)))-10  median(impresm(~isnan(impresm)))+10]);
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  SCS barometric pressure',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
    set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
    xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
    grid;
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit
        ppath = fullfile(way_images_flux,[cruise,'_SCS_pressure_',sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd),graphformat]);
        print(graphdevice,ppath);
    end;
end;

