Follow

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 12\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
	createnew:
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True
	skipnew:

'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
	xmin=WksStatistics.Minimum(1)
	xmax=WksStatistics.Maximum(1)
	ymin=WksStatistics.Minimum(2)
	ymax=WksStatistics.Maximum(2)
	wks.Close
	Debug.Print xmin;xmax;ymin;ymax

'Calculate number of columns and rows from desired spacing.
	ncol=1+(xmax-xmin)/gridspacing
	nrow=1+(ymax-ymin)/gridspacing

'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
	Plot.Shapes.AddContourMap(outfile1)

End Sub

 

Updated February 14, 2017

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

0 Comments

Please sign in to leave a comment.