arcpy.AddMessage(
    "Processing the Hubert Test for each segment ('Rank_UGO') - Step " +
    str(ncurrentstep) + "/" + str(nstep))
UGO = Rank_UGO[0]
for i in range(0, len(elem) - 1):
    if Rank_UGO[elem[i]] != UGO or i == 0:
        UGO = Rank_UGO[elem[i]]
        arcpy.AddMessage("        Hubert Test in processing : UGO " +
                         str(UGO) + "/" + str(NbUGO))
    if Metric[elem[i]:elem[i + 1]][0] == None:
        breaks.append([[elem[i], elem[i + 1]], [None]])
        HReach[breaks[i][0][0]:breaks[i][0][-1]] = [None] * len(
            Metric[elem[i]:elem[i + 1]])
    else:
        breaks.append(
            dPH.Hubert_segmentation(Metric[elem[i]:elem[i + 1]], alpha))
        breaks[i][0][:] = [x + elem[i] for x in breaks[i][0]]
        model = dPH.model_signal(Metric[breaks[i][0][0]:breaks[i][0][-1]],
                                 breaks[i][0])
        HReach[breaks[i][0][0]:breaks[i][0][-1]] = model[:]

#/back to ArcGIS : transfer of Rank_AGO and AGO_Val fields into the DGO-scale database
ncurrentstep += 1
arcpy.AddMessage("Transferring the 'Rank_AGO' and  'AGO_Val' - Step " +
                 str(ncurrentstep) + "/" + str(nstep))
arcpy.AddField_management(SortedTable, "Rank_AGO", "SHORT")
arcpy.AddField_management(SortedTable, "AGO_Val", "FLOAT")

p = 0
rows1 = arcpy.UpdateCursor(SortedTable)
rows2 = arcpy.SearchCursor(SortedTable)
                #    - the value estimated by the Hubert Test : 'AGO_Val'
                #    - a unique id, 'Rank_AGO', related to the homogeneous reach
                #It is a .txt file which will be used to create the output shapefile. 

ncurrentstep+=1
arcpy.AddMessage("Processing the Hubert Test for each segment ('Rank_UGO') - Step " + str(ncurrentstep) + "/" + str(nstep))
UGO = Rank_UGO[0]
for i in range(0, len(elem)-1) :
    if Rank_UGO[elem[i]] != UGO or i == 0:
        UGO = Rank_UGO[elem[i]]
        arcpy.AddMessage("        Hubert Test in processing : UGO " + str(UGO) + "/" + str(NbUGO))
    if Metric[elem[i]:elem[i+1]][0] == None :
        breaks.append([[elem[i], elem[i+1]],[None]])
        HReach [breaks[i][0][0]:breaks[i][0][-1]] = [None]*len(Metric[elem[i]:elem[i+1]])
    else :
        breaks.append(dPH.Hubert_segmentation(Metric[elem[i]:elem[i+1]], alpha))
        breaks[i][0][:] = [x+elem[i] for x in breaks[i][0]]
        model = dPH.model_signal(Metric[breaks[i][0][0]:breaks[i][0][-1]], breaks[i][0])
        HReach [breaks[i][0][0]:breaks[i][0][-1]] = model[:]




#/back to ArcGIS : transfer of Rank_AGO and AGO_Val fields into the DGO-scale database 
ncurrentstep+=1
arcpy.AddMessage("Transferring the 'Rank_AGO' and  'AGO_Val' - Step " + str(ncurrentstep) + "/" + str(nstep))
arcpy.AddField_management(SortedTable, "Rank_AGO", "SHORT")
arcpy.AddField_management(SortedTable, "AGO_Val", "FLOAT")

p=0
rows1 = arcpy.UpdateCursor(SortedTable)