Loop through columns in a data file to create multiple grids via Surfer automation

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\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. Change the file paths/names and gridding columns in the User Variables section at the top of the script.
  7. Click Script | Run to run the script. 

Sub Main
Debug.Clear

'==================================================
'User Variables
'==================================================
'Input and output file directories and input data file name
in_directory = "C:\program files\golden software\surfer\samples\"
data_file = "Sample1.dat"
out_directory = "C:\users\leslie\desktop\"

'X, Y, and first Z column in data file to use for gridding
xcol=1
ycol=2
firstzcol = 3
'==================================================

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)
For i=firstzcol 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.GridData6(DataFile:= in_directory + data_file, xCol:=xcol, yCol:=ycol, zCol:=i, Algorithm:=srfKriging, ShowReport:=False, OutGrid:=grid_file, OutFmt:=srfGridFmtS7)
	Debug.Print "zCol = "+Str(i)
Next i
End Sub

 

Updated January 2022

Was this article helpful?
4 out of 5 found this helpful

Comments

0 comments

Please sign in to leave a comment.