How can I automate the process of creating a contour map from each of my Surfer grid files?

This article contains a sample script for creating a map from all GRD files in a specified directory and saving each as an SRF file.

To run this script:

  1. Copy the script below, or download the attached BAS file: MapAll.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. Click Script | Run to run the script.


'For each GRD in the specified directory, the script creates a new window, a contour map in the window, saves and closes the SRF file.
'Then repeats for the next GRD in the directory.

Sub Main

''''''''''''' User Variables ''''''''''''''''''
'You must enter the path to the grid files and the name of the BLN file

file_directory	= "C:\program files\golden software\surfer 15\samples\"   'make sure has a trailing \

file_extension	= "grd"  'no "." preceding the extension


'Opens Surfer
	Set SurferApp = CreateObject("surfer.application")
	SurferApp.Visible = True 'Progress for each file can be seen in the status bar of the application.

'Start the loop
	file_extension	= LCase(Right(file_extension,(Len(file_extension) - InStrRev(file_extension,"."))))
	If  Len(file_directory)-InStrRev(file_directory,"\") <> 0 Then file_directory = file_directory + "\"

	grid_file = Dir( file_directory  + "*." + file_extension)

	On Error GoTo FileError
	While grid_file <> ""
		'Opens new Surfer window
			Dim Plot As Object
			Set Plot = SurferApp.Documents.Add
		'Creates the map
			Dim MapFrame As Object
			Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=file_directory + grid_file)
		'Saves the file as SRF
			Plot.SaveAs (file_directory + Left(grid_file, Len(grid_file)-(Len(grid_file)-InStrRev(grid_file,".")+1) )  +".srf")
		Debug.Print grid_file
		grid_file = Dir() 'get next file

'Closes Surfer
	Exit Sub

'Error instructions
	Debug.Print  "Error:	" + grid_file + "						" + Err.Description
	Resume Next

End Sub


Updated November 12, 2018

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


Please sign in to leave a comment.