disp('backup_to_Lacie');

clear dir    %to make sure we don't keep the Wind direction variable called also 'dir'!
clear ii

%****   copy raw data   **************************************************************************
% copyfile([way_raw_data_flux yyyy(3:4) num2str(ddd)],[way_backup_data 'flux\Raw\' yyyy(3:4) num2str(ddd)]);

%Check if some folders have not been backed-up for any reasons
dirraw=dir(way_raw_data_flux);
dirLacie=dir([way_backup_data 'flux\Raw\']);
if ~isempty(dirLacie) && ~isempty(dirraw)
    ii=find(~ismember(char(dirraw(:).name),char(dirLacie(:).name),'rows'));  %find files which are not in both sides (does not check time, might consider it later)
    for ll=1:length(ii)
        copyfile([way_raw_data_flux , dirraw(ii(ll)).name],[way_backup_data 'flux\Raw\' dirraw(ii(ll)).name]);
    end;
end;
%****   copy processed data and images   **************************************************************************
 copyfile([way_proc_data_flux '*' num2str(ddd) '*.txt'],[way_backup_data 'flux\Processed\']);
 %copyfile([way_spec_data_flux '*' num2str(ddd) '*.txt'],[way_backup_data 'flux\Processed\']);
 copyfile([way_images_flux '*' num2str(ddd) '*.png'],[way_backup_data 'flux\Processed_Images\']);

%Check if some folders have not been backed-up for any reasons
dirproc=dir(way_proc_data_flux);
dirLacie=dir([way_backup_data 'flux\Processed\']);
if ~isempty(dirLacie)  && ~isempty(dirproc)
    ii=find(~ismember(char(dirproc(:).name),char(dirLacie(:).name),'rows'));  %find files which are not in both sides (does not check time, might consider it later)
    for ll=1:length(ii)
        copyfile([way_proc_data_flux , dirproc(ii(ll)).name],[way_backup_data 'flux\Processed\' dirproc(ii(ll)).name]);
    end;

    dirproc=dir(way_spec_data_flux);
    if ~isempty(dirproc)
        ii=find(~ismember(char(dirproc(:).name),char(dirLacie(:).name),'rows'));  %find files which are not in both sides (does not check time, might consider it later)
        for ll=1:length(ii)
            copyfile([way_spec_data_flux , dirproc(ii(ll)).name],[way_backup_data 'flux\Processed\' dirproc(ii(ll)).name]);
        end;
    end;
end;

dirim=dir(way_images_flux);
dirLacie=dir([way_backup_data 'flux\Processed_Images\']);
if ~isempty(dirim)  && ~isempty(dirLacie)
    ii=find(~ismember(char(dirim(:).name),char(dirLacie(:).name),'rows'));  %find files which are not in both sides (does not check time, might consider it later)
    for ll=1:length(ii)
        copyfile([way_images_flux , dirim(ii(ll)).name],[way_backup_data 'flux\Raw_Images\' dirim(ii(ll)).name]);
    end;

end;

% %backup ceilo data
% dirraw=dir([way_raw_data_ceilo '*.DAT']);
% dirLacie=dir([way_backup_data 'ceilometer\raw\*.DAT']);
% if ~isempty(dirLacie)  && ~isempty(dirraw)
%     ii=find(~ismember(char(dirraw(:).name),char(dirLacie(:).name),'rows'));  %find files which are not in both sides (does not check time, might consider it later)
%     for ll=1:length(ii)
%         copyfile([way_raw_data_ceilo , dirraw(ii(ll)).name],[way_backup_data 'ceilometer\raw\' dirraw(ii(ll)).name]);
%     end;
% end;
% 
% %backup ceilo plots
% dirim=dir([way_images_ceilo '*.png']);
% dirLacie=dir([way_backup_data 'ceilometer\raw_images\*.png']);
% if ~isempty(dirLacie)  && ~isempty(dirim)
%     ii=find(~ismember(char(dirim(:).name),char(dirLacie(:).name),'rows'));  %find files which are not in both sides (does not check time, might consider it later)
%     for ll=1:length(ii)
%         copyfile([way_images_ceilo , dirim(ii(ll)).name],[way_backup_data 'ceilometer\raw_images\' dirim(ii(ll)).name]);
%     end;
% end;
% 
% %backup ceilo processed data
% dirproc=dir([way_proc_data_ceilo '*']);
% dirLacie=dir([way_backup_data 'ceilometer\Processed\*']);
% if ~isempty(dirLacie) && ~isempty(dirproc)
%     ii=find(~ismember(char(dirproc(:).name),char(dirLacie(:).name),'rows'));  %find files which are not in both sides (does not check time, might consider it later)
%     for ll=1:length(ii)
%         copyfile([way_proc_data_ceilo , dirproc(ii(ll)).name],[way_backup_data 'ceilometer\processed\' dirproc(ii(ll)).name]);
%     end;
% end;
