% close all, clear all

leggenda = 1;

%% Setup tempo
global startTime dt

startTime = datenum('Jun 15, 2007  15:45:00.0000'); % anno mese giorno ora minuti secondi
dt = datenum('Jan 0, 0000  0:00:30.0000'); % tempo di campionamento

datestr(startTime,'HH:MM:SS:FFF dd/mm')
datestr(dt,'HH:MM:SS:FFF dd/mm')

%% load csv files

[files, path] = uigetfile('*.dat','MultiSelect','on')

start = 1;

if iscell(files) == 0
    files = {files};
end

for j = 1:length(files)
    log(j) = leggi_dat(fullfile(path,cell2mat(files(j))));    
end

m = inf;
for j = 1:length(files)
    if ( length( log(j).temperature ) < m )
        m = length( log(j).temperature )
    end
end

for j = 1:length(files)
    log(j).time = log(j).time(1:m);
    log(j).temperature = log(j).temperature(1:m);
    log(j).humidity = log(j).humidity(1:m);
    log(j).humidity_true = log(j).humidity_true(1:m);
    log(j).activeRadiation = log(j).activeRadiation(1:m);
    log(j).totalRadiation = log(j).totalRadiation(1:m);
    log(j).internalVoltage = log(j).internalVoltage(1:m);                            % [V]
end



%% plots

leg = [];
if leggenda
    for j = 1:length(files)
        leg = [leg {log(j).name}];
    end
end

t = (0:m-1);

figure(1)
plot(t,[log.temperature])
xlabel('n')
ylabel('°C')
title('Temperature')
if leggenda 
    legend(leg)
end
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@myfunction)

figure(2)
plot(t,[log.humidity])
title('Humidity concentration')
xlabel('n')
ylabel('%')
if leggenda 
    legend(leg)
end
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@myfunction)

figure(3)
plot(t,[log.humidity_true])
title('Humidity concentration (true)')
xlabel('n')
ylabel('%')
if leggenda 
    legend(leg)
end
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@myfunction)

figure(4)
plot(t, [log.activeRadiation])
title('Active radiation')
xlabel('n')
ylabel('lux')
if leggenda 
    legend(leg)
end
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@myfunction)

figure(5)
plot(t, [log.totalRadiation])
title('Total solar radiation')
xlabel('n')
ylabel('lux')
if leggenda 
    legend(leg)
end
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@myfunction)


