Assign NoData to all grid files in a directory using Surfer automation

Batch processing of multiple files can be required for a variety of reasons such as editing public data sets to focus on your desired area.  In this instance, a script is used to Assign NoData to every grid file in the specified directory using the same BLN boundary polygon.

 

To run this script:

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

*********

 

'BlankAll.BAS blanks all grid files in a specified directory with a specific BLN file.
'You must specify the file directory and BLN file below.
'If the script appears to do nothing, make sure file_directory is valid.

Sub Main
Debug.Clear
''''''''''''' User Variables ''''''''''''''''''
'You must enter the path to the grid files and the name of the BLN file
file_directory	= "C:\temp\GRIDS\"
BLN_file = file_directory+"DemoRect.bln"
'''''''''''''''''''''''''''''''''''''''''''''''
	file_extension	= "grd"
	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 + "\"
	grid_file = Dir( file_directory  + "*." + file_extension)
	On Error GoTo FileError
	While grid_file <> ""
		'Define output grid file directory & name
		blanked_file	= file_directory + Left(grid_file, Len(grid_file)-(Len(grid_file)-InStrRev(grid_file,".")+1) ) + "_blanked.grd"
		'Grid the data file with the current Surfer defaults (but do not fill the screen with grid reports)
		surf.GridBlank(file_directory + grid_file, BLN_file, blanked_file)
		Debug.Print grid_file
		grid_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:	" + blanked_file + "						" + Err.Description
	Resume Next
End Sub

 

Updated November 2021

Was this article helpful?
3 out of 5 found this helpful

Comments

0 comments

Please sign in to leave a comment.