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:
- Copy the script below, or download the attached BAS file: Loop-SelectDataFile.bas.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer 16.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- 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.
- 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 November 13, 2018