Attribute VB_Name = "Module1" Type TreeObservation Plot_ID As Long Tree_id As Long STRS_Status As Long Field_Status As Long X As Double Y As Double SigmaX As Double sigmaY As Double Zbutt As Double Ztop_foto As Double Ztop_LiDAR As Double Sp_foto As Long Sp_ref As Long h_foto As Double h_LiDAR As Double Dcrm_foto As Double Dcrm_LiDAR As Double Dcrm_LiDAR_RMSE As Double d13_foto As Double d13_foto_LiDAR As Double d13_ref As Double Sample_tree As Long h_ref As Double h_ref_nasl As Double hc_ref As Double Usable As Long yNasl As Double v_ref As Double v_saw_ref As Double v_pulp_ref As Double v_waste_ref As Double End Type 'Public T() As TreeObservation Type PlotObs Plot_ID As Long X As Double Y As Double Npine As Long Nspruce As Long Nbroad As Long End Type Public Sub indexx(ByVal N As Long, ra() As Single, indx() As Long) Rem Heapsort from Numerical recipes Rem indx(1 to N) is an index table, returned Rem ra(1 to N) is the data to be sorted, left as is. Dim i As Long, j As Long, l As Long, ir As Long, indxt As Long Dim q As Single Dim apu As Integer On Error GoTo virhe_sort For j = 1 To N indx(j) = j Next j l = N / 2 + 1 ir = N 10: If (l > 1) Then l = l - 1 indxt = indx(l) q = ra(indxt) Else indxt = indx(ir) q = ra(indxt) indx(ir) = indx(1) ir = ir - 1 If (ir = 1) Then indx(1) = indxt Exit Sub End If End If i = l j = l + l 20: If j <= ir Then If j < ir Then If (ra(indx(j)) < ra(indx(j + 1))) Then j = j + 1 End If If (q < ra(indx(j))) Then indx(i) = indx(j) i = j j = j + j Else j = ir + 1 End If GoTo 20 End If indx(i) = indxt GoTo 10 virhe_sort: MsgBox ("Error in Heapsort, l is " & l) End Sub