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.
      Note: If you're running Surfer 12 or an earlier version, download GridSpacing_S12.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer 16.
  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 values in the User-defined variables section as desired.
  7. Click Script | Run to run the script.

'Creates a GRD file with user defined grid spacing.
'This script is for only Surfer 13 and later. Surfer 12 and earlier did not have the grid spacing option.

Sub Main

'Gets the existing Surfer instance. If Surfer isn't open, it opens it.
    On Error GoTo createnew
  	Set SurferApp = GetObject(, "Surfer.Application")
    On Error GoTo 0
	GoTo skipnew
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

'User-defined variables
'Specifies the file path where the data file to grid resides
    path1 = "c:\program files\golden software\surfer 16\samples\"

'Specifies the data file
    infile1 = path1+"demogrid.dat"

'Specifies the file to save the output grid to
    outfile1 = path1+"demogrid.grd"

'Specifies the grid spacing
    gridspacing =  0.1

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

'Grids the data
    SurferApp.GridData4(DataFile:=infile1, xSize:=gridspacing, ySize:=gridspacing, Outgrid:=outfile1)

'Creates a contour map

End Sub


Updated November 8, 2018

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


Please sign in to leave a comment.