Follow

How do I blank a Surfer grid file above or below a given Z value with Scripter?

This article provides a Surfer script to blank a grid file above or below a given Z value.

 

To run this script:

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

********* 

'BlankByLevel blanks a grid above or below a given Z value,
'and saves the blanked grid to a new grid file.

Sub Main

Debug.Clear

    Dim SurferApp As Object
    Set SurferApp = CreateObject("Surfer.Application")
    SurferApp.Visible = True

    Set Plot = SurferApp.Documents.Add(srfDocPlot)
    Set Shapes = Plot.Shapes
    Set Grid = SurferApp.NewGrid

'Choose a grid file
    gridfilepath = GetFilePath( , "grd",SurferApp.Path+"\samples\","Open Grid File",0)

    Set Grid2 = Grid.LoadFile(gridfilepath,False)

    Debug.Print "Grid Min =";Grid.zMin
    Debug.Print "Grid Max =";Grid.zMax

' Set level cutoff and flag above or below
    Dim level As Double
    Dim below As Boolean

    Begin Dialog UserDialog 270,112 ' %GRID:10,7,1,1
        Text 10,7,90,14,"Z Level value:",.Text0
        TextBox 10,28,180,21,.LevlVal
        OptionGroup .Group1
            OptionButton 20,77,130,14,"Blank Below",.below
            OptionButton 20,56,130,14,"Blank Above",.above
        OKButton 170,70,80,21
    End Dialog
    Dim entervalue As UserDialog

    Dialog entervalue
        level = Val(entervalue.LevlVal$)
        Debug.Print "Z Level Value = ";entervalue.LevlVal$
        If entervalue.Group1 = 0 Then below = True
        If entervalue.Group1 = 1 Then below = False

    Debug.Print "Processing GridRow:"
    For row=1 To Grid.NumRows()
    For col=1 To Grid.NumCols()
        If below = True Then
          If Grid.GetNode(row,col) < level And Grid.IsBlanked(row,col) = False Then Grid.BlankNode(row,col)
        ElseIf below = False Then
          If Grid.GetNode(row,col) > level And Grid.IsBlanked(row,col) = False Then Grid.BlankNode(row,col)
        End If

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

'Saves the grid to a new name
    gridfilepath = Left(gridfilepath,InStrRev(gridfilepath,".")-1) + "_Blanked.grd
    Grid.SaveFile(gridfilepath, srfGridFmtS7)
    Debug.Print "" 'newline
    Debug.Print "" 'newline
    Debug.Print "File saved as ";gridfilepath

'Creates a contour map of new grid
    Shapes.AddContourMap(gridfilepath)

End Sub

 

Updated November 08, 2018

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

4 Comments

  • 0
    Avatar
    Felipe Camargo de Almeida

    Where do I set the Z value which will blank the values above or below it? This algorithm seems like the normal blanking.

  • 0
    Avatar
    Brittany Bodane

    Hi Felipe,

    Thank you for posting your question! It appears the wrong script was included this article, but the attachment was correct. My apologies for the confusion. I have updated the article so you can copy/paste the correct script should you prefer that to downloading it. 

    You will now see where to set the Z level on line 39. Please let me know if you have any other questions.

     

    Thank you,

    Brittany Bodane

    Technical Support

  • 0
    Avatar
    Michael Huber

    I am trying to print Grid Statistics for Z, specifically the 99 percentile. Does anyone know how I can accomplish this?

    My code currently displays the zMin & zMax (snip from above) but when I use Debug.Print Grid.Statistics.Percentile99 it returns the 99Percentile of X and I'm not sure how to specify Z. 

    Alternatively, I would be okay with the entire grid statistics running / opening & saving. Then I could scroll for the specific stats I need and open the statistics document at a later date if required, but I cant seem to find out a code for this either.

    I am also confused as to why Debug.Print row; is used at the end, as I get hundreds of numbers printing due to this and it doesn't seem to stop..

    Any advice would be greatly appreciated! :)

    Edited by Michael Huber
  • 1
    Avatar
    Brittany Bodane

    Hi Michael,

     

    Thank you for posting your question. Percentile99 pertains to the Z value by default, so you should be seeing this data for the Z value. You can verify this number by looking at the Grid Report for your grid. If you are still not seeing this in relation to your Z values, please email your script and a data file you are seeing this behavior with to support@goldensoftware.com

    If you would like to have the Grid Report open and save via automation, this can be done during the gridding process. We have a sample script for this you may be interested in: https://support.goldensoftware.com/hc/en-us/articles/227873488-How-can-I-save-a-grid-report-when-using-Surfer-Scripter-. 

    Regarding your last question about Debug.Print row being used at the end of the this sample script, I believe this is included so you can see the script is working, and which row it is on. However, it is not necessary for the function of the script and you can delete these lines if you choose. 

     

    Thanks,

    Brittany

    Technical Support

    Golden Software

Please sign in to leave a comment.