The principal purpose of this function is to perform a Delaunay triangulation
for the set of points defined by the input argument ‘g’. This is achieved via
routines in the 3rd-party package qhull.
This is designed to be a generic function to read the grid data from file. It is
assumed that the data will be stored in several tables of different size,
corresponding to the different dimensionalities of the elements of the ‘grid’
struct. See ‘writeGrid’ for a description.
The algorithm works its way up the list of points with one index and down with
another. The ‘up’ travel stops at the 1st sink point it finds, the ‘down’ at the
1st non-sink point. If at that point the ‘up’ index is lower in value than the
‘down’, the points are swapped. This is just a tiny bit tricky because we also
need to make sure all the neigh pointers are swapped. That’s why we make an
ordered list of indices and perform the swaps on that as well.