Convert GRD files to DATs without NoData values via Surfer automation
If you have multiple grid files in a directory and you want to convert them to XYZ data files without the NoData values, you can use the script below to do this.
To run this script:
- 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. - 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. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
- Change the file path in the User-defined variables section at the top of the script.
- 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 2021
Comments
0 comments
Please sign in to leave a comment.