How can I grid a file in Surfer Scripter and specify my own grid spacing?

This article contains a sample script for creating a GRD file with user defined grid spacing.

To run this script:

  1. Copy the script below, or download the attached BAS file: GridSpacing.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\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. Click Script | Run to run the script.


'GridSpacing.bas creates a GRD file with user defined grid spacing.

Sub Main
	Debug.Print "----- ";Time;" -----"
	On Error GoTo createnew
  	Set SurferApp = GetObject(, "Surfer.Application")
  On Error GoTo 0
	GoTo skipnew
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

'Specifies the data file to grid
	path1 = SurferApp.Path+"\samples\"
	infile1 = GetFilePath(path1+"demogrid.dat","dat;csv;xls",path1,"Input Data File",0)
	Debug.Print infile1

'Specifies where to save the GRD file
	outfile1 = GetFilePath(,"grd",SurferApp.Path+"\samples\","Outfile",2)
	Debug.Print outfile1

'Specify the grid spacing you want
	gridspacing = InputBox("Enter Grid Spacing","Grid Spacing")
	Debug.Print gridspacing
	Set Wks = SurferApp.Documents.Open(infile1)
	Set WksRange = Wks.Columns(Col1:=1, Col2:=2)
	Set WksStatistics = WksRange.Statistics

'Calculates the min/max for the X and Y columns
	Debug.Print xmin;xmax;ymin;ymax

'Calculate number of columns and rows from desired spacing.

'Creates a plot document window
	Set Plot = SurferApp.Documents.Add

'Grids the data
	SurferApp.GridData(infile1, NumCols:=ncol, NumRows:=nrow, Outgrid:=outfile1)

'Creates a contour map

End Sub


Updated September 14, 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.