%%%%%%%%%%%%%%%%%%% Create Monthly Excel Files from Daily ones %%%%%%%%%%%%%%%%%%%% % >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DATES LIST of Data Loggers CHANGES in each station: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< % % KEF-3 / PERIOD 2 >> '020A0029' after 21/07/2016 > > > after 1/7/2016 in the HD Directory % KEF-1 / PERIOD 2 >> '020A0022' after 14/08/2017 > > > after 1/8/2017 in the HD Directory % KEF-2 / PERIOD 2 >> '041A0260' after 18/08/2017 > > > after 1/9/2017 in the HD Directory % KEF-2 / PERIOD 3 >> '041A0267' after 22/09/2018 > > > after 1/10/2018 in the HD Directory % KEF-3 / PERIOD 3 >> '041A0262' after 23/09/2018 > > > after 1/9/2018 in the HD Directory % KTL-1 / PERIOD 3 >> '049A0638' after 04/01/2022 > > > after 1/1/2022 in the HD Directory % PAX-1 / PERIOD 2 >> '041A0261' after 29/07/2020 > > > after 1/08/2020 in the HD Directory % % >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< % >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DATA LOGGERS LOCATION and IDENTITY S/N <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< % ist==1; STATION= ('otranto', 'APL-1', 'OTRANTO-APULIA'); % ist==2; STATION= ('leuca', 'APL-2', 'LEUCA-APULIA'); % ist==3; STATION= ('lecce', 'APL-3', 'LECCE-APULIA'); % ist==4; STATION= ('041A0258', 'CRF-1', 'AYLIOTES-CORFU'); % 'CRF-1'/ PERIOD 2 >> '041A0263' after 1/8/2021 > > > after 1/8/2021 in the HD Directory % ist==5; STATION= ('041A0264', 'CRF-2', 'TEMPLONI-CORFU'); % ist==6; STATION= ('041A0266', 'CRF-3', 'KORISION-CORFU'); % ist==7; STATION= ('041A0263', 'PAX-1', 'PAXOS'); % PAX-1 / PERIOD 2 >> '041A0261' after 29/07/2020 > > > after 1/8/2020 in the HD Directory % ist==8; STATION= ('041A0259', 'LFK-1', 'LEFKADA'); % ist==9; STATION= ('041A0260', 'KEF-1', 'ANTYPATA-CEPHALONIA'); % KEF-1 / PERIOD 2 >> '020A0022' after 14/08/2017 > > > after 1/8/2017 in the HD Directory % ist==10; STATION=('041A0261', 'KEF-2', 'KIPOURIA-CEPHALONIA'); % KEF-2 / PERIOD 2 >> '041A0260' after 18/08/2017 > > > after 1/9/2017 in the HD Directory % KEF-2 / PERIOD 3 >> '041A0267' after 22/09/2018 > > > after 1/10/2018 in the HD Directory % ist==11; STATION=('041A0262', 'KEF-3', 'SKALA-CEPHALONIA'); % KEF-3 / PERIOD 2 >> '020A0029' after 21/07/2016; % KEF-3 / PERIOD 3 >> '041A0262' after 23/09/2018 > > > after 1/9/2018 in the HD Directory % ist==12; STATION=('041A0268', 'ZKT-3', 'SKINARI-ZAKYNTHOS'); % ist==13; STATION=('041A0270', 'ZKT-2', 'AIRPORT-ZAKYNTHOS'); % ist==14; STATION=('041A0265', 'ZKT-1', 'AGALAS-ZAKYNTHOS'); % ist==15; STATION=('041A0271', 'KTL-1', 'KATAKOLO-ILIA'); % KTL-1 / PERIOD 2 >> '041A0273' after 2/12/2019 > > > after 1/12/2019 in the HD Directory % KTL-1 / PERIOD 3 >> '049A0638' after 4/ 1/2022 > > > after 1/ 1/2022 in the HD Directory % ist==16; STATION=('041A0273', 'CRF-4', 'CORFU-TOWN') begun in 23 Sep 2020 ; % ist==17; STATION=('041A0269', 'ZKT-4', 'XENIA'); clear; station='LFK-1'; %% ist==8; STATION= ('041A0259', 'LFK-1', 'LEFKADA') year='2022'; pathIN = pwd; %% use current folder pathIN = 'C:\A_A_PROJECTS\A_A_INTEREG_IV\STATIONS\A_CLIMATIC_BASE'; %% Define the DAILY data INPUT Directory pathIN=[pathIN '\' year]; pathOUT = 'C:\A_A_PROJECTS\A_A_INTEREG_IV\STATIONS\A_CLIMATIC_BASE\REVIEWS\MONTHLY_MATRIXES\IW_STATs'; %% Define the MONTHLY Matrices OUTPUT Directory pathOUT=[pathOUT '\' station '\MandA Data\' station '_' year]; S = dir(fullfile(pathIN, '*', '041A0259.xls')); folders_to_export = numel(S); %% export folders by month columns_to_keep = (1:37); %% select columns (indexes) to keep --> all columns folders_month_numbers = extractBetween([S.folder],'-','-'); %get list of monthes (unique) folders_month_numbers = unique(str2double(folders_month_numbers)); % unique and sorted month values %% main loop month_number_old = folders_month_numbers(1); % init to first month number extracted from above (folders_month_numbers) out = []; for ci = 1:folders_to_export % export folders according to values in vector 'folders_to_export' folder_name = S(ci).folder; file_name = S(ci).name; % detect month month_number = extractBetween(folder_name,'-','-'); month_number = str2num(month_number{:}); if month_number > month_number_old % we are switching to the next month % 1 / save previous month data month_name = datestr(datetime(1,month_number_old,1),'mmmm'); filename_out = [station '_' month_name '_' year '.xls']; %% the excel output name contains the selected folders writetable(out,fullfile(pathOUT,filename_out)); % 2 / start a new data concat (1st iteration) month_number_old = month_number; % update month_number_old F = fullfile(folder_name,file_name); data = readtable(F,'ReadVariableNames',true); out = [data(:,columns_to_keep)]; % vertical concatenation else % we are still in the same month so keep concat data F = fullfile(folder_name,file_name); data = readtable(F,'ReadVariableNames',true); out = [out;data(:,columns_to_keep)]; % vertical concatenation end if ci == folders_to_export month_name = datestr(datetime(1,month_number,1),'mmmm'); filename_out = [station '_' month_name '_' year '.xls']; %% the excel output name contains the selected folders writetable(out,fullfile(pathOUT,filename_out)); end end