Thin data using Surfer automation

Data collection devices are generating larger, more dense data sets each year.  This resolution can be enormously helpful in many ways but it can also lead to increased processing time and increased noise.  If you have a large set of data and don't require the resolution provided, a script like the one below can be used to reduce the number of overall points (thin the data).

To run this script:

  1. Copy the script below, or download the attached BAS file: DataThin.bas .
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.


'DataThin.bas reads the data file and writes every nth point to a new file.

Sub Main
	Debug.Print "----- ";Time;" -----"
	file1 = GetFilePath(,"dat;txt;xyz",,"Open Data File")
	n = InputBox("Read every n-th data point","Enter 'n'","2")
	file2 = Left(file1,Len(file1)-4)+"_Thinned_"+n+".dat"
	Open file1 For Input As #1
	Open file2 For Output As #2
	linenum = 0
	While Not EOF(1)
		For i = 1 To n
			Line Input #1,a
		Next i
		Print #2,a
	Debug.Print file2+" has been created."
	MsgBox(file2+" has been created.")
End Sub


Updated November 2021

Was this article helpful?
1 out of 1 found this helpful



Please sign in to leave a comment.