# FTR_SORT -- Sort two arrays based on the values on the first one. procedure ftr_sort$t (a, b, npts) PIXEL a[npts], b[npts] # arrays to sort int npts # number of points int i pointer index, buffer pointer sp, ptr int ftr_cmp$t() extern ftr_cmp$t begin # Allocate memory for indices and data call smark (sp) call salloc (index, npts, TY_POINTER) call salloc (buffer, npts, TY_PIXEL) # Copy first array into temporary buffer call amov$t (a, Mem$t[buffer], npts) # Initialize pointers do i = 1, npts Memi[index + i - 1] = buffer + i - 1 # Sort pointers call qsort (Memi[index], npts, ftr_cmp$t) # Rearrange first array do i = 1, npts { ptr = Memi[index + i - 1] a[i] = Mem$t[ptr] } # Rearrange second array call amov$t (b, Mem$t[buffer], npts) do i = 1, npts { ptr = Memi[index + i - 1] b[i] = Mem$t[ptr] } # Free memory call sfree (sp) end # FTR_COMP -- Sort comparison function (ascending order). int procedure ftr_cmp$t (i, j) pointer i, j # element pointers begin # Compare elements if (Mem$t[i] < Mem$t[j]) return (-1) else if (Mem$t[i] > Mem$t[j]) return (1) else return (0) end