function database_write(catena,IDcentralina,DTcatena,...
        X,Y,Z,Xlocal,Ylocal,Zlocal,HShift,HShift_local,AlfaX,AlfaY,Azimuth,TempDef_TL,...
        Speed_local,Speed,Acceleration,Acceleration_local,ErrTiltLink,ARRAYdateTL,...
        X_HD,Y_HD,Z_HD,Xlocal_HD,Ylocal_HD,Zlocal_HD,HShift_HD,HShift_local_HD,...
        AlfaX_HD,AlfaY_HD,Azimuth_HD,tempHD,Speed_HD,Speed_local_HD,Acceleration_HD,...
        Acceleration_local_HD,ErrTiltLinkHD,ARRAYdateHD,ACCdefRisHD,MAGdefRisHD,...
        X_HDVR,Y_HDVR,Z_HDVR,Xlocal_HDVR,Ylocal_HDVR,Zlocal_HDVR,HShift_HDVR,HShift_local_HDVR,...
        AlfaX_HDVR,AlfaY_HDVR,Azimuth_HDVR,tempHDVR,Speed_HDVR,Speed_local_HDVR,Acceleration_HDVR,...
        Acceleration_local_HDVR,ErrTiltLinkHDVR,ARRAYdateHDVR,ACCdefRisHDVR,MAGdefRisHDVR,...
        Y_TLH,Z_TLH,Xlocal_TLH,Ylocal_TLH,Zlocal_TLH,AlfaX_TLH,AlfaY_TLH,TempDef_TLH,Speed_TLH,Traversine,...
        Speed_local_TLH,Acceleration_TLH,Acceleration_local_TLH,ErrTiltLinkH,ARRAYdateTLH,...
        X_IPL,Y_IPL,Z_IPL,Xlocal_IPL,Ylocal_IPL,Zlocal_IPL,HShift_IPL,...
        HShift_local_IPL,Azimuth_IPL,TempDef_IPL,Speed_local_IPL,Speed_IPL,...
        Acceleration_local_IPL,Acceleration_IPL,AlfaX_IPL,AlfaY_IPL,ErrInPlaceLink,ARRAYdateIPL,...
        X_HR,Y_HR,Z_HR,Xlocal_HR,Ylocal_HR,Zlocal_HR,HShift_HR,HShift_local_HR,...
        AlfaX_HR,AlfaY_HR,Azimuth_HR,TempDef_TLHR,Speed_local_HR,Speed_HR,...
        Acceleration_HR,Acceleration_local_HR,ErrTiltLinkHR,ARRAYdateTLHR,...
        Y_TLHRH,Z_TLHRH,Ylocal_TLHRH,Zlocal_TLHRH,AlfaX_TLHRH,AlfaY_TLHRH,TempDef_TLHRH,Speed_TLHRH,...
        Speed_local_TLHRH,Acceleration_TLHRH,Acceleration_local_TLHRH,ErrTiltLinkHRH,ARRAYdateTLHRH,...
        X_IPLHR,Y_IPLHR,Z_IPLHR,Xlocal_IPLHR,Ylocal_IPLHR,Zlocal_IPLHR,HShift_IPLHR,...
        HShift_local_IPLHR,AlfaX_IPLHR,AlfaY_IPLHR,TempDef_IPLHR,Azimuth_IPLHR,Speed_IPLHR,...
        Speed_local_IPLHR,Acceleration_IPLHR,Acceleration_local_IPLHR,ErrInPlaceLinkHR,ARRAYdateIPLHR,...
        Livello,PiezDef,PiezDefT,ErrPiezoLink,ARRAYdatePL,BaroDef,BaroDefT,ErrBaroLink,ARRAYdateBL,...
        DatiLoad,ErrLoadLink,ARRAYdateLL,Rain,RainCum,ErrRainLink,ARRAYdateRL,SPP,ARRAYdateSPP,...
        Snow,SnowCum,ErrSnowLink,ARRAYdateSL,ANGdefKL,TdefKL,ErrKlinoLink,ARRAYdateKL,NodoKlinoLink,...
        ANGdefKLHR,TdefKLHR,ErrKlinoLinkHR,ARRAYdateKLHR,...
        Dati_ThL,ErrThermLink,ARRAYdateThL,Dati_PT100,ErrPT100Link,ARRAYdatePT100,...
        Dati_PE,ErrPendulum,ARRAYdatePE,Dati_WL,Portata,TdefWL,ErrWeirLink,NodoWeirLink,ARRAYdateWL,...
        conn,FileName)

%% Attivo/disattivo la scrittura
[scrivoTL,scrivoTLH,scrivoIPL,scrivoHD,scrivoHDVR,scrivoTLHR,scrivoTLHRH,scrivoIPLHR,...
    scrivoPL,scrivoBL,scrivoLL,scrivoKL,scrivoKLHR,scrivoRL,scrivoSL,scrivoThL,...
    scrivoPT100,scrivoWL,scrivoPE,scrivoSPP] = scrivo(X,Z_TLH,X_IPL,X_HD,X_HDVR,X_HR,Z_TLHRH,X_IPLHR,...
    Livello,BaroDef,DatiLoad,ANGdefKL,ANGdefKLHR,Rain,Snow,Dati_ThL,Dati_PT100,...
    Dati_WL,Dati_PE,SPP,FileName);

%% Contatori nodi
cTL = 1; % Tilt Link V
cTLH = 1; % Tilt Link H
cIPL = 1; % In Place Link
cHD = 1; % Tilt Link HD
cHDVR = 1; % Tilt Link HD VR
cTLHR = 1; % Tilt Link HR V
cTLHRH = 1; % Tilt Link HR H
cIPLHR = 1; % In Place Link HR
cPL = 1; % Piezo Link
cBL = 1; % Baro Link
cLL = 1; % Load Link
cKL = 1; % Klino Link
cKLHR = 1; % Klino Link HR
cRL = 1; % Rain Link
cThL = 1;% Therm Link
cPT100 = 1; % PT100
cWL = 1; % Weir Link
cPE = 1; % Pendulum
contPE = 1; % Secondo Contatore per i Pendulum
cSPP = 1; % SPP Link
cSL = 1; %% Snow Link

% conto i dati
[~,colTL] = size(X); % controllo quanti dati ho
[~,colTLH] = size(Z_TLH); % controllo quanti dati ho
[~,colIPL] = size(X_IPL); % controllo quanti dati ho
[~,colHD] = size(X_HD); % controllo quanti dati ho
[~,colHDVR] = size(X_HDVR); % controllo quanti dati ho
[~,colTLHR] = size(X_HR); % controllo quanti dati ho
[~,colTLHRH] = size(Z_TLHRH); % controllo quanti dati ho
[~,colIPLHR] = size(X_IPLHR); % controllo quanti dati ho
[~,colPL] = size(Livello'); % controllo quanti dati ho
[~,colBL] = size(BaroDef'); % controllo quanti dati ho
[~,colLL] = size(DatiLoad'); % controllo quanti dati ho
[~,colKL] = size(ANGdefKL'); % controllo quanti dati ho
[~,colKLHR] = size(ANGdefKLHR'); % controllo quanti dati ho
[~,colRL] = size(Rain'); % controllo quanti dati ho
[~,colThL] = size(Dati_ThL'); % controllo quanti dati ho
[~,colPT100] = size(Dati_PT100'); % controllo quanti dati ho
[~,colWL] = size(Dati_WL'); % controllo quanti dati ho
[~,colPE] = size(Dati_PE'); % controllo quanti dati ho
[~,colSPP] = size(SPP'); % controllo quanti dati ho
[~,colSL] = size(Snow'); % controllo quanti dati ho
[rC,~] = size(catena);
idNodo = cell2mat(catena(:,1));

text = 'Upload of the results in the DB started';
fileID = fopen(FileName,'a');
fmt = '%s \r';
fprintf(fileID,fmt,text);

%% Scrittura risultati su DB
for a = 1:rC
    NodeNum = cell2mat(catena(a,3));
    
    %% Tilt Link V
    if  idNodo(a,1) == 1
        if scrivoTL == 1 % se ho correttamente tutti i dati
            ListaDate = colTL;
            
            DATAinsert = cellMakerTL(IDcentralina,DTcatena,NodeNum,cTL,ListaDate,...
                ErrTiltLink,ARRAYdateTL,X,Y,Z,Xlocal,Ylocal,Zlocal,HShift,HShift_local,...
                AlfaX,AlfaY,Azimuth,TempDef_TL,Speed,Speed_local,Acceleration,Acceleration_local);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateTL,conn);
            
            DBwriteTL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cTL = cTL+1;
            clear DATAinsert
            % Logfile
            text = ['Tilt Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Tilt Link H
    elseif  idNodo(a,1) == 11
        if scrivoTLH == 1 % se ho correttamente tutti i dati
            ListaDate = colTLH;
            
            DATAinsert = cellMakerTLH(IDcentralina,DTcatena,NodeNum,cTLH,ListaDate,...
                ErrTiltLinkH,ARRAYdateTLH,Y_TLH,Z_TLH,Xlocal_TLH,Ylocal_TLH,Zlocal_TLH,...
                AlfaX_TLH,AlfaY_TLH,TempDef_TLH,Speed_TLH,Speed_local_TLH,...
                Acceleration_TLH,Acceleration_local_TLH);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateTLH,conn);
            
            DBwriteTLH(DATAinsert,idElabData,ListaDate,NodeNum,DTcatena,IDcentralina,Traversine,conn);
            
            cTLH = cTLH+1;
            clear DATAinsert
            % Logfile
            text = ['Tilt Link H node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% In Place Link
    elseif  idNodo(a,1) == 42
        if scrivoIPL == 1 % se ho correttamente tutti i dati
            ListaDate = colIPL;
            
            DATAinsert = cellMakerIPL(IDcentralina,DTcatena,NodeNum,cIPL,ListaDate,...
                ErrInPlaceLink,ARRAYdateIPL,X_IPL,Y_IPL,Z_IPL,Xlocal_IPL,...
                Ylocal_IPL,Zlocal_IPL,HShift_IPL,HShift_local_IPL,...
                AlfaX_IPL,AlfaY_IPL,Azimuth_IPL,TempDef_IPL,Speed_IPL,...
                Speed_local_IPL,Acceleration_IPL,Acceleration_local_IPL);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateIPL,conn);
            
            DBwriteIPL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cIPL = cIPL+1;
            clear DATAinsert
            % Logfile
            text = ['In Place Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Tilt Link HD
    elseif  idNodo(a,1) == 67
        if scrivoHD == 1 % se ho correttamente tutti i dati
            ListaDate = colHD;
            
            DATAinsert = cellMakerHD(IDcentralina,DTcatena,NodeNum,cHD,ListaDate,...
                ErrTiltLinkHD,ARRAYdateHD,X_HD,Y_HD,Z_HD,Xlocal_HD,Ylocal_HD,Zlocal_HD,...
                HShift_HD,HShift_local_HD,AlfaX_HD,AlfaY_HD,Azimuth_HD,tempHD,Speed_HD,...
                Speed_local_HD,Acceleration_HD,Acceleration_local_HD,ACCdefRisHD,MAGdefRisHD);
            
            % Controllo se i dati sono da scrivere o aggiornare
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateHD,conn);
            % Controllo se i dati delle risultanti sono da scrivere o aggiornare
            idElabData_RIS = DB_date_time_RIS(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateHD,conn);
            
            DBwriteHD(DATAinsert,idElabData,idElabData_RIS,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cHD = cHD+1;
            clear DATAinsert
            % Logfile
            text = ['Tilt Link HD node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Tilt Link HD VR
    elseif  idNodo(a,1) == 61
        if scrivoHDVR == 1 % se ho correttamente tutti i dati
            ListaDate = colHDVR;
            
            DATAinsert = cellMakerHDVR(IDcentralina,DTcatena,NodeNum,cHDVR,ListaDate,...
                ErrTiltLinkHDVR,ARRAYdateHDVR,X_HDVR,Y_HDVR,Z_HDVR,Xlocal_HDVR,Ylocal_HDVR,Zlocal_HDVR,...
                HShift_HDVR,HShift_local_HDVR,AlfaX_HDVR,AlfaY_HDVR,Azimuth_HDVR,tempHDVR,Speed_HDVR,...
                Speed_local_HDVR,Acceleration_HDVR,Acceleration_local_HDVR,ACCdefRisHDVR,MAGdefRisHDVR);
            
            % Controllo se i dati sono da scrivere o aggiornare
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateHDVR,conn);
            % Controllo se i dati delle risultanti sono da scrivere o aggiornare
            idElabData_RIS = DB_date_time_RIS(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateHDVR,conn);
            
            DBwriteHDVR(DATAinsert,idElabData,idElabData_RIS,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cHDVR = cHDVR+1;
            clear DATAinsert
            % Logfile
            text = ['Tilt Link HD VR node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Tilt Link HR V
    elseif  idNodo(a,1) == 5
        if scrivoTLHR == 1 % se ho correttamente tutti i dati
            ListaDate = colTLHR;
            
            DATAinsert = cellMakerTLHR(IDcentralina,DTcatena,NodeNum,cTLHR,ListaDate,...
                ErrTiltLinkHR,ARRAYdateTLHR,X_HR,Y_HR,Z_HR,Xlocal_HR,Ylocal_HR,Zlocal_HR,...
                HShift_HR,HShift_local_HR,AlfaX_HR,AlfaY_HR,Azimuth_HR,TempDef_TLHR,Speed_HR,...
                Speed_local_HR,Acceleration_HR,Acceleration_local_HR);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateTLHR,conn);
            
            DBwriteTLHR(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cTLHR = cTLHR+1;
            clear DATAinsert
            % Logfile
            text = ['Tilt Link HR node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Tilt Link HR H
    elseif  idNodo(a,1) == 12
        if scrivoTLHRH == 1 % se ho correttamente tutti i dati
            ListaDate = colTLHRH;
            
            DATAinsert = cellMakerTLHRH(IDcentralina,DTcatena,NodeNum,cTLHRH,ListaDate,...
                ErrTiltLinkHRH,ARRAYdateTLHRH,Y_TLHRH,Z_TLHRH,Ylocal_TLHRH,Zlocal_TLHRH,...
                AlfaX_TLHRH,AlfaY_TLHRH,TempDef_TLHRH,Speed_TLHRH,Speed_local_TLHRH,...
                Acceleration_TLHRH,Acceleration_local_TLHRH);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateTLHRH,conn);
            
            DBwriteTLHRH(DATAinsert,idElabData,ListaDate,NodeNum,DTcatena,IDcentralina,conn);
            
            cTLHRH = cTLHRH+1;
            clear DATAinsert
            % Logfile
            text = ['Tilt Link HR H node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% In Place Link HR
    elseif  idNodo(a,1) == 43
        if scrivoIPLHR == 1 % se ho correttamente tutti i dati
            ListaDate = colIPLHR;
            
            DATAinsert = cellMakerIPLHR(IDcentralina,DTcatena,NodeNum,cIPLHR,ListaDate,...
                ErrInPlaceLinkHR,ARRAYdateIPLHR,X_IPLHR,Y_IPLHR,Z_IPLHR,Xlocal_IPLHR,Ylocal_IPLHR,...
                Zlocal_IPLHR,HShift_IPLHR,HShift_local_IPLHR,AlfaX_IPLHR,AlfaY_IPLHR,Azimuth_IPLHR,...
                TempDef_IPLHR,Speed_IPLHR,Speed_local_IPLHR,Acceleration_IPLHR,Acceleration_local_IPLHR);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateIPLHR,conn);
            
            DBwriteIPLHR(DATAinsert,idElabData,ListaDate,NodeNum,DTcatena,IDcentralina,conn);
            
            cIPLHR = cIPLHR+1;
            clear DATAinsert
            % Logfile
            text = ['In Place Link HR node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
        %% Piezo Link
    elseif  idNodo(a,1) == 2
        if scrivoPL == 1 % se ho correttamente tutti i dati
            ListaDate = colPL;
            
            DATAinsert = cellMakerPL(IDcentralina,DTcatena,NodeNum,cPL,ListaDate,...
                ARRAYdatePL,Livello,PiezDef,PiezDefT,ErrPiezoLink);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdatePL,conn);
            
            DBwritePL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cPL = cPL+1;
            clear DATAinsert
            % Logfile
            text = ['Piezo Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
        %% Baro Link
    elseif  idNodo(a,1) == 3
        if scrivoBL == 1
            ListaDate = colBL;
            
            DATAinsert = cellMakerBL(IDcentralina,DTcatena,NodeNum,ListaDate,...
                ARRAYdateBL,BaroDef,BaroDefT,ErrBaroLink);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateBL,conn);
            
            DBwriteBL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cBL = cBL+1;
            clear DATAinsert
            % Logfile
            text = ['Baro Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
        %% Load Link
    elseif  idNodo(a,1) == 15
        if scrivoLL == 1
            ListaDate = colLL;
            
            DATAinsert = cellMakerLL(IDcentralina,DTcatena,NodeNum,cLL,...
                ListaDate,ARRAYdateLL,DatiLoad,ErrLoadLink);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateLL,conn);
            
            DBwriteLL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cLL = cLL+1;
            clear DATAinsert
            % Logfile
            text = ['Load Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
        %% Klino Link
    elseif  idNodo(a,1) == 26
        if scrivoKL == 1
            ListaDate = colKL;
            
            DATAinsert = cellMakerKL(IDcentralina,DTcatena,NodeNum,cKL,ListaDate,...
                ARRAYdateKL,ANGdefKL,TdefKL,ErrKlinoLink,NodoKlinoLink);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateKL,conn);
            
            DBwriteKL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn,NodoKlinoLink);
            
            cKL = cKL+1;
            clear DATAinsert
            % Logfile
            text = ['Klino Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Klino Link HR
    elseif  idNodo(a,1) == 44
        if scrivoKLHR == 1
            ListaDate = colKLHR;
            
            DATAinsert = cellMakerKLHR(IDcentralina,DTcatena,NodeNum,cKLHR,...
                ListaDate,ARRAYdateKLHR,ANGdefKLHR,TdefKLHR,ErrKlinoLinkHR);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateKLHR,conn);
            
            DBwriteKLHR(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cKLHR = cKLHR+1;
            clear DATAinsert
            % Logfile
            text = ['Klino Link HR node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Rain Link
    elseif  idNodo(a,1) == 27
        if scrivoRL == 1
            ListaDate = colRL;
            
            DATAinsert = cellMakerRL(IDcentralina,DTcatena,NodeNum,ListaDate,...
                ARRAYdateRL,Rain,RainCum,cRL,ErrRainLink);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateRL,conn);
            
            DBwriteRL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cRL = cRL+1;
            clear DATAinsert
            % Logfile
            text = ['Rain Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% SPP Link
    elseif  idNodo(a,1) == 64
        if scrivoSPP == 1
            ListaDate = colSPP;
            
            DATAinsert = cellMakerSPP(IDcentralina,DTcatena,NodeNum,ListaDate,...
                ARRAYdateSPP,SPP,cSPP);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateSPP,conn);
            
            DBwriteSPP(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cSPP = cSPP+1;
            clear DATAinsert
            % Logfile
            text = ['SPP Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end

    %% Snow Link
    elseif  idNodo(a,1) == 78
        if scrivoSL == 1
            ListaDate = colSL;
            
            DATAinsert = cellMakerSL(IDcentralina,DTcatena,NodeNum,ListaDate,...
                ARRAYdateSL,Snow,SnowCum,cSL,ErrSnowLink);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateSL,conn);
            
            DBwriteSL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cSL = cSL+1;
            clear DATAinsert
            % Logfile
            text = ['Snow Link node no. ' num2str(NodeNum) ' of ' ...
                num2str(rC) ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
    %% Therm Link
    elseif  idNodo(a,1) == 4
        if scrivoThL == 1
            ListaDate = colThL;
            
            DATAinsert = cellMakerThL(IDcentralina,DTcatena,NodeNum,ListaDate,...
                ARRAYdateThL,Dati_ThL,cThL,ErrThermLink);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateThL,conn);
            
            DBwriteThL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cThL = cThL+1;
            clear DATAinsert
            % Logfile
            text = ['Therm Link node no. ' num2str(NodeNum) ' of ' num2str(rC) ...
                ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
        %% PT100
    elseif  idNodo(a,1) == 28
        if scrivoPT100 == 1
            ListaDate = colPT100;
            
            DATAinsert = cellMakerPT100(IDcentralina,DTcatena,NodeNum,ListaDate,...
                ARRAYdatePT100,Dati_PT100,cPT100,ErrPT100Link);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdatePT100,conn);
            
            DBwritePT100(DATAinsert,idElabData,ListaDate,NodeNum,DTcatena,IDcentralina,conn);
            
            cPT100 = cPT100+1;
            clear DATAinsert
            % Logfile
            text = ['PT100 Link node no. ' num2str(NodeNum) ' of ' num2str(rC) ...
                ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
        %% Weir Link
    elseif idNodo(a,1) == 53
        if scrivoWL == 1
            ListaDate = colWL;
            Therm = cell2mat(NodoWeirLink(:,6));
            
            DATAinsert = cellMakerWL(IDcentralina,DTcatena,NodeNum,cWL,ListaDate,ARRAYdateWL,...
                Dati_WL,Portata,TdefWL,ErrWeirLink,Therm);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdateWL,conn);
            
            DBwriteWL(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,cWL,Therm,conn);
            
            cWL = cWL+1;
            clear DATAinsert
            % Logfile
            text = ['Weir Link node no. ' num2str(NodeNum) ' of ' num2str(rC) ...
                ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
        
        %% Pendulum
    elseif  idNodo(a,1) == 52
        if scrivoPE == 1
            ListaDate = colPE;
            
            DATAinsert = cellMakerPE(IDcentralina,DTcatena,NodeNum,cPE,contPE,ListaDate,...
                ARRAYdatePE,Dati_PE,ErrPendulum);
            
            idElabData = DB_date_time(IDcentralina,DTcatena,NodeNum,ListaDate,ARRAYdatePE,conn);
            
            DBwritePE(DATAinsert,idElabData,ListaDate,NodeNum,IDcentralina,DTcatena,conn);
            
            cPE = cPE+1;
            contPE = contPE+2;
            clear DATAinsert
            % Logfile
            text = ['Pendulum node no. ' num2str(NodeNum) ' of ' num2str(rC) ...
                ' of unit ' IDcentralina ' and chain ' DTcatena ' written in the DB!'];
            fprintf(fileID,fmt,text);
        end
    end
    
end

text = 'DB upload completed';
fprintf(fileID,fmt,text);
fclose(fileID);

end
