Follow

How do I replace the blanking value in a grid file with 0 in a Surfer script?

This article provides a Surfer script for replacing the Z values of blanked nodes in a grid file with 0. This does not change the Blank Value in the grid header.

 

To run this script:

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

*********

 

'Blank0.bas replaces the blanking value in a grid file with 0.
'The new grid is saved to a new grid file "<filepath>\<filename>_Blank0.grd"
'A contour map is created from the new grid.


Sub Main
	'Use existing Surfer instance with a Plot1 window.
	'Set surf = GetObject(,"Surfer.application")
	'Set plot = surf.Documents("Plot1")

	'Open a new Surfer instance.
	Set surf = CreateObject("Surfer.Application")
	Set plot = surf.Documents.Add(srfDocPlot)
	surf.Visible=True
	Set shapes = plot.Shapes
	Set grid = surf.NewGrid

	'grid.LoadFile(surf.Path+"\samples\DemoRectBlank.grd",False)

	'Select the [.GRD] file and its directory path
	gridFilePath = GetFilePath( , "grd",surf.Path+"\samples\","Open Grid File",0)
	'Load the selected [.GRD] file
	grid.LoadFile(gridFilePath,False)

	Debug.Print "Processing GridRow:"
	For row=1 To Grid.NumRows()
    For col=1 To Grid.NumCols()
    	'If Grid.IsBlanked(row,col) = True Then Grid.SetNode(row,col) = 0
      If Grid.IsBlanked(row,col) Then Grid.SetNode(row,col,0)
      	'Grid.SetNode(row,col) = 0.0
      	'Grid.SetNode(row,col,0)
      'End If
    Next col

   Debug.Print row;
    If row Mod 20 = 0 Then Debug.Print
	Next row

	'Append "_Blank0_" to the outup [.GRD] filename
	gridFilePath = Left(gridFilePath,InStrRev(gridFilePath,".")-1) & "_Blank0" & Mid(gridFilePath,InStrRev(gridFilePath,"."),4)

	Debug.Print 'CR

	'Save the modified Grid
	Grid.SaveFile(gridFilePath, srfGridFmtS7)
	'Create a ContourMap using this grid
	shapes.AddContourMap(gridFilePath)

End Sub

 

Updated October 10, 2017

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.