disp('Transfer_DAS_to_psddata_folder');
%transfer PSD data from DAS to Lidar's group psd_data subdirectory.

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

%%%%%%%%%%%%%%%%%%%Modifies current directory and search path%%%%%%%%%%%%%%
Fluxroot='D:\Data\DYNAMO_2011\Revelle\Scientific_analysis\programs\';  % name of the path where the 'flux' folder + read_parameters file are installed.
% Fluxroot='C:\Data\cruises\DYNAMO_2011\Revelle\Scientific_analysis\programs\on DAS\';  % name of the path where the 'flux' folder + read_parameters file are installed.
cd([Fluxroot])         %Changes current directory to fluxroot/flux
addpath(genpath(Fluxroot))     %adds flux folder and all of its subdirectories to the top of the MATLAB search path. 

%%%%%%%%%%%  Read parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
read_parameters_DYNAMO_2011;     %reads the parameters for the cruise.
graphformat='.png';  %select graphics format files


%%%%%%%%%%%%%%%%%%%%%%%% Gets day-of-year, and year %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dv = clock;  % gets current date and time as date vector.
Vdate=datevec(datenum(dv(1),dv(2),dv(3)-1));
ddd=datenum(Vdate)-datenum(Vdate(1),1,0);  %same as md2yd(V(1),V(2),V(3))
jd=sprintf('%03i',ddd);
yyyy=sprintf('%04i',Vdate(1));
% [m,d]=yd2md(str2num(yyyy), ddd);   

%################## Defines some options and parameters ##################################
destinationdir='C:\Data\CRUISES\DYNAMO_2011\destination\';   %in here specify the path to psd_data subdirectory (where to send the data)
tempdir='C:\Data\CRUISES\DYNAMO_2011\test\';   %in here specify the path for temporary transit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%  Get the flux data and zip them to tempdir %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
zipfilename=[cruise, '_', ship, '_', 'flux', '_', sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd)];
% if ~isempty(dir([way_proc_data_flux, '*', jd, '*.txt'])) && ~isempty(dir([way_images_flux, '*', jd, graphformat]))
try
    entrynames=zip([tempdir, zipfilename, '.zip'],{[way_proc_data_flux, '*', jd, '.txt'],[way_images_flux, '*', jd, '*',graphformat]}); %compress selected files into a big zip file
end
%%%%%%%%%%%  Get the ceilo data and zip them to tempdir  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
zipfilename=[cruise, '_', ship, '_', 'ceilo', '_', sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd)];
% if ~isempty(dir([way_proc_data_ceilo, '*', jd, '*.txt'])) && ~isempty(dir([way_images_ceilo, '*', jd, '*',graphformat]))
try
    entrynames=zip([tempdir, zipfilename, '.zip'],{[way_proc_data_ceilo, '*', jd, '.txt'],[way_images_ceilo, '*', jd, graphformat]}); %compress selected files into a big zip file
end
%%%%%%%%%%%  Get the micro data and zip them to tempdir  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
zipfilename=[cruise, '_', ship, '_', 'mailbox', '_', sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd)];
% if ~isempty(dir([way_proc_data_mb, '*_', yyyy(3:4), sprintf('%02i%02i',Vdate(2),Vdate(3)), '.txt'])) && ~isempty(dir([way_raw_images_mb, '*', jd, '*',graphformat]))
try
    entrynames=zip([tempdir, zipfilename, '.zip'],{[way_proc_data_mb, '*_', yyyy(3:4), sprintf('%02i%02i',Vdate(2),Vdate(3)), '*.txt'],[way_raw_images_mb, '*', jd, graphformat]}); %compress selected files into a big zip file
end
%%%%%%%%%%%  Get the Wband data and zip them to tempdir  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
zipfilename=[cruise, '_', ship, '_', 'Wband', '_', sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd)];
% if ~isempty(dir([way_cloud_data_wband, '*', jd, '*.txt'])) && ~isempty(dir([way_raw_images_wband, '*', jd, '*',graphformat]))
try
    entrynames=zip([tempdir, zipfilename, '.zip'],{[way_cloud_data_wband, '*', jd, '.txt'],[way_raw_images_wband, '*', jd, graphformat]}); %compress selected files into a big zip file
end

%################## Move zip files to final destination ##################################
if ~isempty(dir([tempdir , '*.zip']))               %makes sure there are zip files to move
    movefile([tempdir , '*.zip'],destinationdir,'f');   %if so, moves the files
end    
%NOTE: If you have problem moving the files, it might be due to security rights, or connection. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%################## Zip files to one to be manually transfered ##################################
% bigzipfilename=[cruise, '_', ship, '_', 'PSDdata', '_', sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd)];
% entrynames=zip([tempdir, bigzipfilename, '.zip'],[tempdir , '*.zip']); %compress zip files into a big zip file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




