%This program is made daily sensitive to the data from the Vaissala
%ceilometer CT25

clear;
close('all');
fclose('all');


%try

Fluxroot='E:\AtlanticTransect_2014\PolarStern\Scientific_analysis\programs\';  % name of the path where the 'flux' folder + read_parameters file are installed.
cd([Fluxroot])         %Changes current directory to fluxroot/flux

%%%%%%%%%%%  Read parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Gets the last uploaded parameter file from Fluxroot directory
dirfluxroot=dir([Fluxroot 'read_parameters_*.m']);
MostrecentPARfile=dirfluxroot(cellfun(@(x) x==max([dirfluxroot.datenum]),{dirfluxroot(:).datenum})).name;
disp(['Most recent parameters being used: ' MostrecentPARfile])
eval(strtok(MostrecentPARfile, '.'));

%%%%%%%%%%%%%%%%%%%Modifies current directory and search path%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ceiloroot='E:\AtlanticTransect_2014\PolarStern\Scientific_analysis\programs\';  % name of the path where the 'flux' folder + read_parameters file are installed.
cd([Ceiloroot, 'ceilo'])         %Changes current directory to fluxroot
addpath(genpath(Ceiloroot))     %adds flux folder and all of its subdirectories to the top of the MATLAB search path.

%%%%%%%%%%%  Defines some options %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plotit=true; % for making plots.
prtit=true;  % for printing plots--ineffective unless plotit is also true
graphformat='.png';  %select graphics format files
graphdevice='-dpng'; %select graphic device
saveit=true; % for saving data files
clearit=true;% for clearing data sometimes to save memory
emailconf=false; %for sending email confirmation to NOAA email recipient list (Send_email_to_PSD3group.m)
%set to false as it does not seem to work from DAS computers :(
report=[];
data_ftp=false;     %to activate ftp to Boulder server
data_backup=true;    %true;  %to activate backup to Lacie hardrive (if present)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

cruise_name=cruise;%'WGC';
    %%%%%%%%%%%%%%%%%%%%%%%% Gets day-of-year and year %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    display('Assumes data have been copied from Ceilometer PC to DAS02 cruise directory') %;['D:\' cruise  '\' ship '\ceilometer\Raw\'] directory'
    if ~exist('yyyy','var'); yyyy=input('Input year to evaluate (yyyy).... ','s'); end;
    if ~exist('mndy','var'); mndy=input('Input monthday to evaluate (mmdd).... '); end;

% dd = clock;  % date vector
% edn=datenum(dd(1),dd(2),dd(3),dd(4),dd(5),dd(6)); %MATLAB day
% bdn=edn-1;    % this is to get the prevuous days data.
% ddv = datevec(bdn);
% yyyy =  sprintf('%04i',ddv(1));

ddv =datevec(sprintf('%s/%02d/%02d', yyyy,floor(mndy/100),mndy-100*floor(mndy/100)));
%reads in all file for the same day (in case of reboots, etc...)    
    fname= sprintf('C%c%04d*.DAT', yyyy(4),mndy);  %Aymmddhh.DAT   
%     hr = 00;   % assumes ceilometer program hasn't restarted
%     fname=sprintf('R%c%02d%02d%02d.DAT', yyyy(4), ddv(2), ddv(3), hr)  %Aymmddhh.DAT
%     
%     if exist(['D:\Data\ceilometer\' fname],'file')
%         copyfile(['D:\Data\ceilometer\' fname],[way_raw_data_ceilo]); % copy yesterdays file from ceilometer PC (Y:) to D:
%     end;

ls([way_raw_data_ceilo '*.DAT'])   % ls files in directory
%
%
 eval([ 'read_daily_rawceilo_CT25_', cruise])
 eval([ 'ceilo_daily_plot_program_', cruise])
    
