%generatore_U.m

clc;
clear;
close all;

%load LOG_DATA_12_2494.mat;
load LOG_DATA_11_2494.mat;
%load LOG_DATA_12_1648.mat;

%variabili che potrebbero essere passate
% p;            %quanti passi fare
% y;            %quale ingresso selezionare
% lung;         %se inserire tutti i campioni o solo i primi
% campioni;     %quanti campioni inserire
%v;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%  passaggio misure, da testo oppure come variabili, in futuro funzione%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% inp=input('Quanti passi indietro vuoi usare: ');if isempty(inp);inp=0;end
% p=inp;
% inp=input('Quale sensore vuoi usare come uscita: ');if isempty(inp);inp=1;end
% y=inp;
% inp=input('Segna 1 se vuoi tutti i dati, 0 se vuoi esprimere qaunti dati prendere: ');if isempty(inp);inp=1;end
% lung=inp;

%if lung==0
%    inp=input('Quanti campioni vuoi: ');if isempty(inp);inp=500;end
%    campioni=inp;
%end

%v=[];
% inp=input('Segna 1 se vuoi inserire la temperatura,0 altrimenti: ');if isempty(inp);inp=1;end
% v(1)=inp;
% inp=input('Segna 1 se vuoi inserire la humidity,0 altrimenti: ');if isempty(inp);inp=1;end
% v(2)=inp;
% inp=input('Segna 1 se vuoi inserire la humidity_true,0 altrimenti: ');if isempty(inp);inp=1;end
% v(3)=inp;
% inp=input('Segna 1 se vuoi inserire la activeRadiation,0 altrimenti: ');if isempty(inp);inp=1;end
% v(4)=inp;
% inp=input('Segna 1 se vuoi inserire la totalRadiation a,0 altrimenti: ');if isempty(inp);inp=1;end
% v(5)=inp;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%fine richiesta dati passaggio manuale dati uso per funzione
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
p=1;
y=1;
lung=1;
campioni=1000;

%v=[temperature1 humidity2 humidity_true3 activieRadiotion4 totalRadiation5]
v=[ 1 1 0 1 0];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%  CREAZIONE del log tmp in cui manca la variabile da stimare   %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



if y<1;                                 log_tmp=log(2:length(log));     y=1;
elseif y==1;                            log_tmp=log(2:length(log));
elseif ( (y>1) || (y<length(log)) );    log_tmp=[log(1:y-1) log(y+1:length(log))];
elseif y==length(log);                  log_tmp=log(1:length(log)-1);
elseif y>length(log);                   log_tmp=log(1:length(log)-1);   y=length(log);  
end



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%  CREAZIONE DELLA VARIABILE U    %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

U=[];


%u=[u dato]
%colonne sono i vettori dei dati indipendenti
%u=[ sens_2_t_0 ... sens_2_t_-p ... sens_i_t_0 ... sens_i_t_-p , sens_2_h_0 ... sens_2_h_-p ... sens_i_h_0 ... sens_i_h_-p]
if lung==1;

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%%%%%%%%  VISIONE FINA ALLA FINE    %%%%%%%%%%%%%%%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        if v(1)==1    
            for i=1:length(log_tmp);
                for j=1:p
                    U = [ U , log_tmp(i).temperature( j : length(log_tmp(i).temperature) -p +j )];
                end
            end
        end
        
        if v(2)==1    
            for i=1:length(log_tmp);
                for j=1:p
                    U = [ U , log_tmp(i).humidity( j : length(log_tmp(i).humidity) -p + j )];
                end
            end
        end
            
        if v(3)==1
            for i=1:length(log_tmp);
                for j=1:p
                    U = [ U , log_tmp(i).humidity_true( j : length(log_tmp(i).humidity_true) -p + j)];
                end
            end
        end
        
        if v(4)==1
            for i=1:length(log_tmp);
                for j=1:p
                    U = [ U , log_tmp(i).activeRadiation( j : length(log_tmp(i).activeRadiation) -p + j )];
                end
            end
        end
        
        if v(5)==1    
            for i=1:length(log_tmp);
                for j=1:p
                    U = [ U , log_tmp(i).totalRadiation( j : length(log_tmp(i).totalRadiation) - p + j )];
                end
            end
        end

elseif lung==0

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        %%%%%%%%%  FINO AI SU    %%%%%%%%%%%%%%%%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        if (campioni+p) > length(log(y).temperature);

            campioni = length(log(y).temperature) - p - 1 ;

        end
        
        
        if v(1)==1 
            for i=1:length(log_tmp);
                for j=1:p;
                    U = [ U , log_tmp(i).temperature(j:campioni+j )];
                end
            end
        end
        
        if v(2)==1
            for i=1:length(log_tmp);
                for j=1:p;
                    U = [ U , log_tmp(i).humidity(j:campioni+j )];
                end
            end
        end
        
        if v(3)==1
            for i=1:length(log_tmp);
                for j=1:p;
                    U = [ U , log_tmp(i).humidity_true(j:campioni+j )];
                end
            end
        end
        
        if v(4)==1
            for i=1:length(log_tmp);
                for j=1:p;
                    U = [ U , log_tmp(i).activeRadiation(j:campioni+j)];
                end
            end
        end
        
        if v(5)==1 
            for i=1:length(log_tmp);
                for j=1:p;
                    U = [ U , log_tmp(i).totalRadiation(j:campioni+j)];
                end
            end
        end

end



str_p = num2str(p);
str_y = num2str(y);

if lung==1;
    str_camp = num2str(length(log(y).temperature));
elseif lung==0
    str_camp = num2str(campioni);
end

str_v=[];
for i=1:length(v)
    tmp=num2str(v(i));
    str_v=[ str_v tmp ];
end

str_save=['data_U_y_' str_y '_p_' str_p  '_camp_' str_camp '_' str_v];


save(str_save, 'U')  % Use when filename is stored in a variable

str_save



