Follow

How can I convert my GRD files to DATs without NoData values in Surfer Scripter?

If you have multiple GRD files in a directory and you want to convert them to DAT files without the NoData values, you can use the script below to do this.

To run this script:

  1. Copy the script below, or download the attached BAS file: GRD2DAT_WithoutNoData.BAS.
       Note: If you're using Surfer 14 or earlier, instead download GRD2DAT_WithoutNoData_S14.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. Change the file path in the User-defined variables section at the top of the script.
  7. Click Script | Run to run the script. 
     

Sub Main
	Debug.Clear

	'====================
	'User-defined variables
	'====================
	file_directory	= "C:\surfer\"
	'====================

	'Initialize Surfer
	Dim surf  As Object
	Set surf = CreateObject("surfer.application")
	surf.Visible = True

	'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 + "\"

	'Define variable new_grids as the grid files in the file_directory
	new_grids = Dir( file_directory  + "*.grd")

	'Loop through the GRD files
	While new_grids <> ""
		'Define output DAT file directory & name
		new_dats = file_directory + Left(new_grids, Len(new_grids)-(Len(new_grids)-InStrRev(new_grids,".")+1) ) + ".dat"

		'Convert the grid file to a DAT file
                surf.GridConvert2(InGrid:= file_directory + new_grids, OutGrid:=new_dats, OutFmt:=srfGridFmtXYZ, OutGridOptions:="NoBlanks=1")

		'Print out the name of the grid file being converted
		Debug.Print new_grids

		'Get the next file
		new_grids = Dir()

	Wend

	'Close Surfer
	surf.Quit

End Sub

Updated November 9, 2018

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

0 Comments

Please sign in to leave a comment.