Follow

How can I calculate the volume of my grid in a Surfer script?

This article contains a sample script for calculating the volume and area of a grid file and writing the results to the worksheet.

To run this script:

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

*********

'GridVolume.bas calculates the volume and area of a grid file.
'The results are written to the worksheet and saved in a DAT file.

'=======================================

Sub Main

'Declare SurferApp as an object
	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

'-------------User Input Required------------------------
'Specifies the upper and lower surfaces. They can be a grid file or a constant Z value.

	UpperSurface = SurferApp.Path+"\samples\demogrid.grd"
	LowerSurface = 0

'------------------------------------------------------

'Calculates the volume and area. This method does not display the report window
	Dim Results() As Double
	SurferApp.GridVolume(upper:=UpperSurface,lower:=LowerSurface, presults:=Results, showreport:=False)
	
'Create a new worksheet window
	Set Wks = SurferApp.Documents.Add(srfDocWks)

'Put the contents of pResults (the Grid Volume report) in the worksheet cells

	Wks.Cells("A1").Value = "Upper Surface:"
	Wks.Cells("B1").Value =	UpperSurface

	Wks.Cells("A2").Value = "Lower Surface"
	Wks.Cells("B2").Value =	LowerSurface

	Wks.Cells("A4").Value = "VOLUMES"

	Wks.Cells("A5").Value = "Trapezoidal Rule:"
	Wks.Cells("B5").Value =	Results(srfGVTrapVol)

	Wks.Cells("A6").Value = "Simpson's Rule:"
	Wks.Cells("B6").Value = Results(srfGVSimpVol)

	Wks.Cells("A7").Value = "Simpson's 3/8 Rule:"
	Wks.Cells("B7").Value = Results(srfGVSimp38Vol)

	Wks.Cells("A9").Value = "CUT & FILL VOLUMES"

	Wks.Cells("A10").Value = "Positive Volume [Cut]:"
	Wks.Cells("B10").Value = Results(srfGVPosVol)

	Wks.Cells("A11").Value = "Negative Volume [Fill]:"
	Wks.Cells("B11").Value = Results(srfGVNegVol)

	Wks.Cells("A12").Value = "Cut minus Fill:"
	Wks.Cells("B12").Value = Results(srfGVPosVol) - Results(srfGVNegVol)

	Wks.Cells("A14").Value = "AREAS"

	Wks.Cells("A15").Value = "Positive Planar Area:"
	Wks.Cells("B15").Value = Results(srfGVPosPlanarArea)

	Wks.Cells("A16").Value = "Negative Planar Area:"
	Wks.Cells("B16").Value = Results(srfGVNegPlanarArea)

	Wks.Cells("A17").Value = "Blanked Planar Area:"
	Wks.Cells("B17").Value = Results(srfGVBlankedArea)

	Wks.Cells("A18").Value = "Total Planar Area"
	Wks.Cells("B18").Value = Results(srfGVPosPlanarArea)+ Results(srfGVNegPlanarArea) + Results(srfGVBlankedArea)

	Wks.Cells("A20").Value = "Positive Surface Area:"
	Wks.Cells("B20").Value = Results(srfGVPosArea)

	Wks.Cells("A21").Value = "Negative Surface Area:"
	Wks.Cells("B21").Value = Results(srfGVNegArea)

'Saves the worksheet
	Wks.SaveAs("C:\temp\VolumeReport.dat")

End Sub

 

Updated February 13, 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.