%{
    PlotFastP_STRATUS_2017.m
    
    Read one day of Paro fast pressure data, plot a few spectra
    and plot a timeseries

    May 2017 BWB
%}

%%  initialize parameters
clear;
close('all');
fclose('all');

% set date range for run, whole STRATUS 2017 cruise is 116:139
jdStart = 122;
jdStop = 122;

% other options
plotit = true; % for doing plots.
prtit = true;  % for saving plots--plotit must also be true
graphformat = '.png';  % select graphics format files
graphdevice = '-dpng'; % select graphic device
fpressure = 10;
cruise = 'STRATUS_2017';    % Cruise name
yyyy = '2017';              % year string
ship = 'RHB';               % Research vessel

% system specific path definitions
sysType = computer;
if strncmp(sysType,'MACI64',7)       % set Mac paths
    data_drive = '/Users/byronb/Raw_Data_Files.noindex';
    path_prog = '/Users/byronb/Documents/MATLAB/2017_STRATUS/';
elseif strncmp(sysType,'PCWIN',7)  % set PSD DAC paths
    data_drive = 'D:\Data';
    path_prog = fullfile(data_drive,cruise,ship,'Scientific_analysis','programs');
end

% set matlab script path
restoredefaultpath              % reset matlab path
addpath(genpath(fullfile(path_prog,'flux')));	% add scripts to path
savepath; rehash;
cd (fullfile(path_prog,'flux'));

% paths relative to data_drive - first 2 should be preexisting
path_raw_data = fullfile(data_drive,cruise,ship,'flux','Raw');
path_raw_images = fullfile(data_drive,cruise,ship,'flux','Raw_Images');
mkdir(path_raw_images);

% Fast P box height -  assume same as Vaisala T/RH
zP = 17;

%% Read data

for ddd = jdStart:jdStop
    [m,d] = yd2md(str2num(yyyy), ddd);
    Vdate = [str2num(yyyy),m,d];
    path_working_ddd = fullfile(path_raw_data,[yyyy(3:4),sprintf('%03i',ddd)]);
    if (exist(path_working_ddd,'dir')==0)
        disp(['PATH ',path_working_ddd,' NOT FOUND']);
        continue    % go to next day if folder is not found
    end

    % read Paro fast pressure sensor data, fpsm is 86400x3 array
    fpsm = read_paroP_day_STRATUS_2017(path_working_ddd,ddd,yyyy,...
    fpressure,prtit,path_raw_images,graphformat,graphdevice);

    % plot time series for this day
    figure; plot(fpsm(:,1), fpsm(:,2)+0.125*zP,'r-','linewidth',1); grid;
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  FastPressure',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none');
    xlabel('Hour (UTC)'); ylabel('Sea Level Pressure (mb)');
    xlim([ddd ddd+1]); 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));
    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(path_raw_images,[cruise,'_FastP_',sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd),graphformat]);
        print(graphdevice,ppath);
    end
end
