added C++ version of Fortran code used by closemeshKD
finally switched completely to C++ routines.