function [DatiElabTunnelLink,DatiElabRadialLink,DatiElabTiltLinkH,DatiElabTiltLinkHRH,...
    DatiElabPreConvLink,DatiElabPreConvLinkHR,DatiElabAnalogLink,DatiElabDistoMTLink]...
    = checkdata(yesTuL,yesRL,yesTLH,yesTLHRH,yesPCL,yesPCLHR,yesAL,yesDM,...
    DatiElabTunnelLink,DatiElabRadialLink,DatiElabTiltLinkH,DatiElabTiltLinkHRH,...
    DatiElabPreConvLink,DatiElabPreConvLinkHR,DatiElabAnalogLink,DatiElabDistoMTLink,...
    datainiTuL,tempoiniTuL,datainiRL,tempoiniRL,datainiTLH,tempoiniTLH,...
    datainiTLHRH,tempoiniTLHRH,datainiPCL,tempoiniPCL,datainiPCLHR,tempoiniPCLHR,...
    datainiAL,tempoiniAL,datainiDM,tempoiniDM,rTuL,rRL,rTLH,rTLHRH,rPCL,rPCLHR,rAL,rDM,...
    NodoTunnelLink,NodoRadialLink,NodoTiltLinkH,NodoTiltLinkHRH,NodoPreConvLink,...
    NodoPreConvLinkHR,NodoAnalogLink,NodoDistoMTLink,NuovoZeroTuL,NuovoZeroRL,NuovoZeroTLH,...
    NuovoZeroTLHRH,NuovoZeroPCL,NuovoZeroPCLHR,NuovoZeroAL,NuovoZeroDM,...
    IDcentralina,DTcatena,conn,FileName)

text = 'checkdata function started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);

%% Tunnel Link
if yesTuL == 1 
    if NuovoZeroTuL == 1
        data1 = datenum([char(DatiElabTunnelLink(1,1)) ' ' char(DatiElabTunnelLink(1,2))]); % Prima data elaborata
        data2 = datenum([datainiTuL(1,1:10),' ',tempoiniTuL]); % Prima data grezza
        if data2 ~= data1 % devo riscaricare l'ultimo dato elaborato a partire da dataini
            datainiTuL = datestr(data2,'yyyy-mm-dd');
            tempoiniTuL = datestr(data2,'HH:MM:SS');
            DatiElabTunnelLink = LastElab_bisTuL(conn,NodoTunnelLink,rTuL,...
                datainiTuL,tempoiniTuL,IDcentralina,DTcatena,FileName);
        end
    end
end

%% Radial Link
if yesRL == 1
    if NuovoZeroRL == 1
        data1 = datenum([char(DatiElabRadialLink(1,1)) ' ' char(DatiElabRadialLink(1,2))]); % Prima data elaborata
        data2 = datenum([datainiRL(1,1:10),' ',tempoiniRL]); % Prima data grezza
        if data2 ~= data1 % devo riscaricare l'ultimo dato elaborato a partire da dataini
            datainiRL = datestr(data2,'yyyy-mm-dd');
            tempoiniRL = datestr(data2,'HH:MM:SS');
            DatiElabRadialLink = LastElab_bisRL(conn,NodoRadialLink,rRL,...
                datainiRL,tempoiniRL,IDcentralina,DTcatena,FileName);
        end
    end
end

%% Tilt Link H
if yesTLH == 1
    if NuovoZeroTLH == 1
        data1 = datenum([char(DatiElabTiltLinkH(1,1)) ' ' char(DatiElabTiltLinkH(1,2))]); % Prima data elaborata
        data2 = datenum([datainiTLH(1,1:10),' ',tempoiniTLH]); % Prima data grezza
        if data2 ~= data1 % devo riscaricare l'ultimo dato elaborato a partire da dataini
            datainiTLH = datestr(data2,'yyyy-mm-dd');
            tempoiniTLH = datestr(data2,'HH:MM:SS');
            DatiElabTiltLinkH = LastElab_bisTLH(conn,NodoTiltLinkH,rTLH,...
                datainiTLH,tempoiniTLH,IDcentralina,DTcatena,FileName);
        end
    end
end

%% Tilt Link HR H
if yesTLHRH == 1
    if NuovoZeroTLHRH == 1
        data1 = datenum([char(DatiElabTiltLinkHRH(1,1)) ' ' char(DatiElabTiltLinkHRH(1,2))]); % Prima data elaborata
        data2 = datenum([datainiTLHRH(1,1:10),' ',tempoiniTLHRH]); % Prima data grezza
        if data2 ~= data1 % devo riscaricare l'ultimo dato elaborato a partire da dataini
            datainiTLHRH = datestr(data2,'yyyy-mm-dd');
            tempoiniTLHRH = datestr(data2,'HH:MM:SS');
            DatiElabTiltLinkHRH = LastElab_bisTLHRH(conn,NodoTiltLinkHRH,rTLHRH,...
                datainiTLHRH,tempoiniTLHRH,IDcentralina,DTcatena,FileName);
        end
    end
end

%% PreConv Link
if yesPCL == 1
    if NuovoZeroPCL == 1
        data1 = datenum([char(DatiElabPreConvLink(1,1)) ' ' char(DatiElabPreConvLink(1,2))]); % Prima data elaborata
        data2 = datenum([datainiPCL(1,1:10),' ',tempoiniPCL]); % Prima data grezza
        if data2 ~= data1 % devo riscaricare l'ultimo dato elaborato a partire da dataini
            datainiPCL = datestr(data2,'yyyy-mm-dd');
            tempoiniPCL = datestr(data2,'HH:MM:SS');
            DatiElabPreConvLink = LastElab_bisPCL(conn,NodoPreConvLink,rPCL,...
                datainiPCL,tempoiniPCL,IDcentralina,DTcatena,FileName);
        end
    end
end

%% PreConv Link HR
if yesPCLHR == 1
    if NuovoZeroPCLHR == 1
        data1 = datenum([char(DatiElabPreConvLinkHR(1,1)) ' ' char(DatiElabPreConvLinkHR(1,2))]); % Prima data elaborata
        data2 = datenum([datainiPCLHR(1,1:10),' ',tempoiniPCLHR]); % Prima data grezza
        if data2 ~= data1 % devo riscaricare l'ultimo dato elaborato a partire da dataini
            datainiPCLHR = datestr(data2,'yyyy-mm-dd');
            tempoiniPCLHR = datestr(data2,'HH:MM:SS');
            DatiElabPreConvLinkHR = LastElab_bisPCLHR(conn,NodoPreConvLinkHR,rPCLHR,...
                datainiPCLHR,tempoiniPCLHR,IDcentralina,DTcatena,FileName);
        end
    end
end

%% Analog Link
if yesAL == 1
    if NuovoZeroAL == 1
        data1 = datenum([char(DatiElabAnalogLink(1,1)) ' ' char(DatiElabAnalogLink(1,2))]); % Prima data elaborata
        data2 = datenum([datainiAL(1,1:10),' ',tempoiniAL]); % Prima data grezza
        if data2 ~= data1 % devo riscaricare l'ultimo dato elaborato a partire da dataini
            datainiAL = datestr(data2,'yyyy-mm-dd');
            tempoiniAL = datestr(data2,'HH:MM:SS');
            DatiElabAnalogLink = LastElab_bisAL(conn,NodoAnalogLink,rAL,...
                datainiAL,tempoiniAL,IDcentralina,DTcatena,FileName);
        end
    end
end

text = 'checkdata function worked correctly';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);
fclose(fileID);

end