How can I use a script to loop through z values in a data file to create multiple Surfer grids?

If you have a single data file containing multiple Z columns, and you want to grid the x,y values with each z column, you can use the script below to do this.

To run this script:

  1. Copy the script below, or download the attached BAS file:grid_loop_through_zcol.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\GoldenSoftware\Surfer 15\Scripter.
  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. Change the in_directory, data_file, and out_directory values at the beginning of the script to the directory containing your data file, the data file name, and the directory you want to write the grid files to.
  7. Click Script | Run to run the script. 

Sub Main

'                User Variables
in_directory = "C:\program files\golden software\surfer 15\samples\"
data_file = "Sample1.dat"
out_directory = "C:\users\username\desktop\"


	Set surf = CreateObject("surfer.application")
	surf.Visible = True

	'Open the data file in Surfer's worksheet and get the last column value
	Dim Wks, WksRange As Object
	Set Wks = surf.Documents.Open(in_directory+data_file)
	Set WksRange = Wks.Rows(1, 1)

	'Loop through z columns, beginning with column 3 and ending at the last column in the data file
	For i=3 To WksRange.ColumnCount
		'Define output grid file directory & name
		grid_file = out_directory + Left(data_file, Len(data_file)-(Len(data_file)-InStrRev(data_file,".")+1) ) + "_zcol"+Str(i)+".grd"

		'Grid the data file
		surf.GridData3(DataFile:= in_directory + data_file, xCol:=1, yCol:=2, zCol:=i, Algorithm:=srfKriging, ShowReport:=False, OutGrid:=grid_file, OutFmt:=srfGridFmtS7)

		Debug.Print "zCol = "+Str(i)
	Next i

End Sub


Updated December 11, 2017

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.