How can I create a time-animated model in Surfer from x, y, z1, z2, ... data?

Surfer does not currently have the ability to create a time-animated model, but there is an easy way to emulate this end-result via a script. If you have data with one x column, one y column, and multiple z columns, run the script below and then upload all of the output GIF files to an animated GIF creator. Many of these are available online for free.

To run this script:

  1. Copy the script below, or download the attached BAS file: GridZCols_ExportGIF_Loop.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\GoldenSoftware\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. Update the values in the User Defined Variables section near the top of the script.
  7. Click Script | Run to run the script. 

' This script loops through z columns in a data file, gridding them and creating a
' contour map from the grid, then exporting the grid as a GIF to be animated by
' a third-party program

Sub Main

'Initializes Surfer
	Dim SurferApp, Plot, MapFrame, ContourLayer As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

'                                        USER DEFINED VARIABLES
	data_dir = "C:\program files\golden software\surfer 15\samples\"		'directory where the data file is located
	data_file = "Sample1.dat"	'data file name
	grid_dir = "C:\users\username\desktop\"		'directory where grids will be saved
	gif_dir = "C:\users\username\desktop\"		'directory where gifs will be saved

	numrows = 200		'number of rows in the grid file
	numcols = 200		'number of columns in the grid file
	x = 1		'x column from the data file
	y = 2		'y column from the data file
	z = 3		'z column from the data file

	colormap_min = 40		'minimum data value for the colormap
	colormap_max = 100		'maximum data value for the colormap
	grad = "Rainbow"		'color gradient preset for the colormap

'Open the data file in Surfer's worksheet and get the last column value
	Dim Wks, WksRange As Object
	Set Wks = SurferApp.Documents.Open(data_dir+data_file)
	Set WksRange = Wks.Rows(1, 1)

'Loops through all of the z columns in the data file
	For i=3 To WksRange.ColumnCount

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

		'Define output grid file directory & name
		grid_file = grid_dir + Left(data_file, Len(data_file)-(Len(data_file)-InStrRev(data_file,".")+1) ) + "_zcol"+Str(i)+".grd"

		'Grid the data file
		SurferApp.GridData2(DataFile:= data_dir + data_file, xCol:=1, yCol:=2, zCol:=i, Algorithm:=srfKriging, ShowReport:=False, OutGrid:=grid_file, OutFmt:=srfGridFmtS7)
		Debug.Print "zCol = "+Str(i)

		'Create a contour map
		Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=grid_file)
		Set ContourLayer = MapFrame.Overlays(1)

		'Fill contours
		ContourLayer.FillContours = True

		'Assign a preset to the colormap

		'Set colormap data limits so all exports use the same color scale
		ContourLayer.FillForegroundColorMap.SetDataLimits (DataMin:=colormap_min, DataMax:=colormap_max)

		'Define the name of the output GIF file as the data file name with a GIF extension
		export_file	= gif_dir + Left(data_file, Len(data_file)-(Len(data_file)-InStrRev(data_file,".")+1) ) + "_zcol"+Str(i)+ ".gif"

		'Export to a GIF
		Plot.Export2(FileName:=export_file, FilterID:=gif)

	Next i

'Close Surfer

End Sub


Updated December 11, 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.