I've made a program that controls a scanner, and the output file from this program contains the [X,Y] position of the data point and the depth Z. While the region that I'm scanning may be 200 mm by 500 mm in size, I only record the depth values at the most important points. The format of the output file (prior to mesh generation) might look like this (format is X Y Z):

884.3 -0.5 0.005
893.2 3.6 -0.066
898.4 -45.1 -0.965
865 -45.5 -0.838
846.6 -29.4 -1.158
838.8 -20.6 -0.279

After mesh generation, the file would be all filled in like this (in this example I told Surfer to use a 1mm grid spacing):

838.8 -45.5 -0.80678
839.793 -45.5 -0.813933
840.787 -45.5 -0.820559
841.78 -45.5 -0.826533
842.773 -45.5 -0.831739
…and so on …
893.433 3.6 -0.0660163
894.427 3.6 -0.0665912
895.42 3.6 -0.0682444
896.413 3.6 -0.0711039
897.407 3.6 -0.0751363
898.4 3.6 -0.0802335

Currently I'm using Surfer 6.1 (Golden Software) to generate a complete grid file (which can then be exported as a .txt), but I'd really like to move away from using this outside software and do everything within my scanner program. Basically, after I've finished scanning the points I'm interested in, I'd like to call a function that takes those points and returns the completed grid by interpolating all the points that I didn't scan. The method I use now in Surfer for interpolation is the default which is "inverse distance to a power" which seems to work fine, but most of the other methods seem to produce basically the same result.

I've scoured the internet including a number of different newsgroups looking for a simple C function that I could paste onto the end of my scanner program and call it within the main body of my code. Most of what I've found so far has been very complicated and didn't simply return a completed array. My C program runs in the console window, and really, my program so far is very very simple: if, then, else, while, select statements are pretty indicative of how uncomplicated it is.

I would assume that someone, somewhere, at some point has run into the same task and has already programmed a very simple little function that takes in an array of scattered points and returns a completed grid based on some interpolation method, and I just can't find it.

Can anyone help me?