Follow

How can I grid data and create contour maps for many data files with Surfer Scripter?

This article contains a sample script for looping through the process of selecting a data file, gridding the data, creating a map, and saving the SRF file.

To run this script:

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

*********

'Loop-SelectDataFile.bas loops the process of selecting a data file, gridding the data,
'creating a map, and saving the SRF file.

'By default, the X, Y and Z columns in the data file must be in columns A, B and C.
'You can change this in the GridData line.

'================================================

Sub Main

	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

Do
	'Opens a new plot document
		Dim Plot As Object
		Set Plot = SurferApp.Documents.Add

	'Prompt the user for the name of the data file to process.
		InFile = GetFilePath(" ","DAT;TXT;CSV;XLS",CurDir(), "Select Data File", 0)
		If InFile = "" Then Exit Do

	'Get file name without the extension (for example, "week5.txt becomse "week5")
		BaseName = InFile
		ExtStart = InStrRev(InFile, ".")
		If ExtStart >1 Then BaseName = Left(InFile,ExtStart-1)

	'Create a grid from the specified data file
		GridFile = BaseName + ".grd"
		SurferApp.GridData (DataFile:= InFile, OutGrid:= GridFile)

	'Creates a contour map from the grid file
		Dim Map As Object
		Set Map = Plot.Shapes.AddContourMap(GridFileName:=GridFile)

	'Save to SRF
		Plot.SaveAs (FileName:=BaseName+".srf")

	'Closes the plot
		Plot.Close
Loop


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.