Grid all data files in a directory at once in Surfer automation
When starting a project you may find that you have numerous sets of different data for your site. Automation can be used to generate grids of the same size and resolution for each of these files in just minutes using scripts like the one below.
To run this script:
- Copy the script below (GridAll.bas)
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Surfer.
- 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.
- Edit the file_extension and file_directory in the User Variables section to match your files and location.
- Click Script | Run to run the script.
*********
' GridAll.bas grids all of the specified type of data file in the specified directory. ' You must specify the file extension and file directory below in the script. ' Grid files are saved in the same directory. ' ' If you run the script and nothing appears to happen, make sure the file_directory is valid. ' See bottom of script for common errors Sub Main Debug.Clear ''''''''''''' User Variables '''''''''''''''''' file_extension = "dat" file_directory = "C:\samples\dat\" ''''''''''''''''''''''''''''''''''''''''''''''' Set surf = CreateObject("surfer.application") surf.Visible = True 'Progress for each file can be seen in the status bar of the application. 'Make sure the file extension has no extra . and the data directory has a trailing \ 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 + "\" data_file = Dir( file_directory + "*." + file_extension) On Error GoTo FileError While data_file <> "" 'Define output grid file directory & name grid_file = file_directory + Left(data_file, Len(data_file)-(Len(data_file)-InStrRev(data_file,".")+1) ) + ".grd" 'Grid the data file with the current Surfer defaults (but do not fill the screen with grid reports) surf.GridData(DataFile:= file_directory + data_file, ShowReport:=False, OutGrid:=grid_file) ' You can uncomment line below to make explicit changes to Gridding options. Make ' sure to comment out the line above or files will be gridded twice. ' ' For more inforomation about using these options and thier definitions please see ' the Surfer Help File, available by using the menu command HELP | ABOUT and then ' searching for "GridData". ' 'surf.GridData(DataFile:= file_directory + data_file, xCol:=1, yCol:=2, zCol:=3, Algorithm:=srfKriging, ShowReport:=False, SearchEnable:=True, KrigStdDevGrid:=surf.Path+"\Samples\StdDev.grd", OutGrid:=grid_file, OutFmt:=srfGridFmtS7) Debug.Print data_file data_file = Dir() 'get next file Wend surf.Quit Exit Sub 'Print a meaningful error message for each file that did not grid correctly FileError: Debug.Print "Error: " + data_file + " " + Err.Description Resume Next End Sub ' Helpful error hints: ' 'a) If the script appears to do nothing, make sure file_directory is valid. 'b) "xMin must be < xMax" usually means there is no griddable data. Check if there really is data, if it is in columns ABC, and that it is formatted as number and not as text or general. 'c) "Insufficient data in worksheet" means there are less than three griddable Z values in the worksheet. 'd) "Inadequate data (all data lie in a horizontal plane)" means that all Z values are the same. 'e) "Unknown worksheet import format" the file format was incompatible with Surfer. Common if the file was an Excel 2007 spreadsheet and your Surfer version is 8 or lower.
Updated April, 2022
Comments
0 comments
Please sign in to leave a comment.