Sub Main
Debug.Clear

'Declare the variable that will reference the application
	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

'Declares Plot as an object
	Dim Plot As Object
	Set Plot = SurferApp.Documents.Add

'Define the input and output files
	DataFile = SurferApp.Path + "\samples\demogrid.dat"
	OutGrid = SurferApp.Path + "\samples\demofault.grd"
	Faultfile = SurferApp.Path + "\samples\demoslice.bln"
	BlankFile = SurferApp.Path + "\samples\demorect.bln"
	BlankedGrid = SurferApp.Path + "\samples\demoblanked.grd"

'Grids the data with a fault file using Minimum Curvature
	SurferApp.GridData (DataFile:=DataFile, Algorithm:= srfMinCurvature, _
	NumRows:=200, NumCols:=200, ShowReport:=False, FaultFileName:=Faultfile, OutGrid:=OutGrid)

'Blanks the grid file using a BLN file
	SurferApp.GridBlank (InGrid:=OutGrid, BlankFile:=BlankFile, Outgrid:=BlankedGrid)

'Declares MapFrame as Object
	Dim MapFrame As Object

'Creates a contour map and assigns the map frame to the variable "MapFrame"
	Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=BlankedGrid)

'Changes the limits and scale of the map
	MapFrame.SetLimits (xMin:=0.5, xMax:=4.5, yMin:=0.5, yMax:=3.5)
	MapFrame.xLength=6
	MapFrame.yLength=4

'Declares ContourLayer as an Object and assigns the contour map to variable "ContourLayer"
	Dim ContourLayer As Object
	Set ContourLayer = MapFrame.Overlays(1)

'Renames the Object ID from "Contours" to "Topography Contour Map"
	ContourLayer.Name = "Topography Contour Map"

'Smooths the contours
	ContourLayer.SmoothContours = srfConSmoothHigh

'Changes the fault line properties
	ContourLayer.FaultLine.ForeColorRGBA.Color = srfColorRed
	ContourLayer.FaultLine.Width = 0.05
	ContourLayer.FaultLine.Style = "Dash Dot Dot"

'Changes the blanking fill and line properties
	ContourLayer.BlankFill.ForeColorRGBA.Color = srfColorCyan
	ContourLayer.BlankFill.ForeColorRGBA.Opacity = 20
	ContourLayer.BlankFill.Pattern = "Solid"

	ContourLayer.BlankLine.ForeColorRGBA.Color = srfColorBrown
	ContourLayer.BlankLine.Style = "Solid"
	ContourLayer.BlankLine.Width = 0.02

'Fill contours
	ContourLayer.FillContours = True

'Assigns a preset to the colormap
	ContourLayer.FillForegroundColorMap.LoadPreset("Rainbow")

'Adjusts the colormap properties
	'Sets colormap data limits
		ContourLayer.FillForegroundColorMap.SetDataLimits (DataMin:=40, DataMax:=100)

	'Sets the node positions and colors for those nodes to create a custom color spectrum
	'The data position is recorded as a value from 0.0 (minimum) to 1.0 (maximum).
		Dim Positions(3) As Double
		Positions(0)=0.0
		Positions(1)=0.3
		Positions(2)=0.6
		Positions(3)=1.0

		Dim Colors(3) As Long
		Colors(0)=srfColorBlack
		Colors(1)=srfColorOrange
		Colors(2)=srfColorCyan
		Colors(3)=srfColorYellow

		ContourLayer.FillForegroundColorMap.SetNodes(Positions:=Positions, Colors:=Colors)

	'Reverses the colormap
		ContourLayer.FillForegroundColorMap.Reverse

'Sets label properties. See LabelFormat object and FontFormat object for more format and font properties.
	ContourLayer.LabelTolerance = 8
	ContourLayer.LabelLabelDist = 0.25
	ContourLayer.LabelEdgeDist = 1.5
	ContourLayer.LabelFormat.Type=srfLabFixed
	ContourLayer.LabelFormat.NumDigits = 2
	ContourLayer.OrientLabelsUphill = True
	ContourLayer.LabelFont.Face = "Arial"
	ContourLayer.LabelFont.Size = 8

'Creates a discrete color scale
	ContourLayer.ShowColorScale=True

'Declares DiscreteColorScale as an object and sets a title
	Dim DiscreteColorScale As Object
	Set DiscreteColorScale = ContourLayer.ColorScale
	DiscreteColorScale.Title = "Contours Elevation"

'Exports the contours to a 3D DXF file
	ContourLayer.ExportContours(FileName:=SurferApp.Path+"\Samples\Contours.dxf", Format:=srfConFormatDXF)

'Positions the contour map on the page
	MapFrame.Top=7
	MapFrame.Left=0.5

'Sets the opacity for the contours layer to 50%
	ContourLayer.Opacity = 50

End Sub
