function [ ] = analizza( req )

%% carica ambaradan
if ~exist('data')
    data = [];
    load data
end

%% chiedi i file (non li carica usa data.mat)
if ~exist('req')
[files, path] = uigetfile('*.dat','MultiSelect','on')
start = 1;
if iscell(files) == 0
    files = {files};
end
req = [];
for k = 1:length(files)
    txt = cell2mat(files(k));
    req(k,:) = txt(end-6:end-4);    
end
end
%% trova la posizione del nome
reqN = name2pos(req,data);

%% disegna i motes
figure(1)
for k = 1:length(data.name)
    if ismember(k,reqN)
        tipo = 'or';
    else
        tipo = '+';
    end
    plot3(data.p(k,1),data.p(k,2),data.p(k,3),tipo)
    text(data.p(k,1)+0.1,data.p(k,2)+0.1,data.p(k,3),data.name(k,:))
    hold on
end
xlabel('x')
ylabel('y')
zlabel('z')

%% grafica

t = (0:length(data.T)-1);

figure(2)
plot(t,data.T(reqN,:))
xlabel('n')
ylabel('°C')
title('Temperature') 
legend(char(req))
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@labellizza)

figure(3)
plot(t,data.H(reqN,:))
title('Humidity concentration')
xlabel('n')
ylabel('%')
legend(char(req))
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@labellizza)

figure(4)
plot(t,data.Ht(reqN,:))
title('Humidity concentration (true)')
xlabel('n')
ylabel('%')
legend(char(req))
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@labellizza)

figure(5)
plot(t,data.aR(reqN,:))
title('Active radiation')
xlabel('n')
ylabel('lux')
legend(char(req))
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@labellizza)

figure(6)
plot(t,data.tR(reqN,:))
title('Total solar radiation')
xlabel('n')
ylabel('lux')
legend(char(req))
axis tight
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@labellizza)

function out = labellizza(obj,event_obj)
pos = get(event_obj,'Position');
out = sprintf('%5.3f @ %s',pos(2),datestr(data.start+pos(1)*data.dt,'HH:MM:SS dd/mm'));
end

end

