Sub Main
	
	'Clear any output in the Imediate window
	Debug.Clear

	'Initialize Surfer
	Dim SurferApp As Object
	Set SurferApp = CreateObject("Surfer.Application")
	SurferApp.Visible = True

	'====================================================== 
	'USER-DEFINED VARIABLES 
	'======================================================
	path2inputGrid = SurferApp.Path + "\samples\demogrid.grd"
	meters2feet = 3.28084 'conversion factor to convert meters to feet
	zMinMeters = 25 'the minimum contour value in meters
	zMaxMeters = 100 'the maximum contour value in meters
	zIntMeters = 4 'the contour interval in meters 
	zMinFeet = zMinMeters * meters2feet
	zMaxFeet = zMaxMeters * meters2feet
	zIntFeet = zIntMeters * meters2feet
	'======================================================

	'Create a new plot document
	Dim Plot As Object
	Set Plot = SurferApp.Documents.Add
	Plot.PageSetup.Orientation = srfLandscape

	'Create a contour map from original grid file (meters)
	Dim MapFrame As Object, ContourLayer As Object
	Set MapFrame = Plot.Shapes.AddContourMap(GridFileName:=path2inputGrid)
	MapFrame.Name = "Map (m)"
	Set ContourLayer = MapFrame.Overlays(1)

	'Edit the contour layer properties
	With ContourLayer
		.LevelMethod = SrfConLevelMethodSimple
		.SetSimpleLevels(Min:=zMinMeters, Max:=zMaxMeters, Interval:=zIntMeters)
		.FillContours = True
		.FillForegroundColorMap.LoadPreset("Rainbow3")
		.FillForegroundColorMap.SetDataLimits(DataMin:=zMinMeters, DataMax:=zMaxMeters)
		.ShowMajorLabels = False
		.ShowMinorLabels = False
	End With

	'Add color scale and edit properties
	Dim ColorScale As Object
	ContourLayer.ShowColorScale=True
	Set ColorScale = ContourLayer.ColorScale
	With ColorScale
		.Name = "Color Scale (m)"
		.Title = "Elevation"
		.TitlePosition = srfColorScaleTitlePositionTop
		.TitleAngle = 0
		.TitleOffsetHorizontal = -0.2
		.LabelFormat.Postfix = " m"
		.Left = 9
	End With

	'Convert grid file to feet
  	Dim inGrid(1 To 1) As IGridMathInput
   	Set inGrid(1) = SurferApp.NewGridMathInput(SurferApp.Path + "\Samples\demogrid.grd", "A")
	SurferApp.GridMath3("A*" + Str(meters2feet), inGrid, "C:\temp\demogrid_feet.grd")

	'Create a new contour map
	Dim MapFrame2 As Object, ContourLayer2 As Object
	Set MapFrame2 = Plot.Shapes.AddContourMap(GridFileName:= "C:\temp\demogrid_feet.grd")
	MapFrame2.Name = "Map (ft)"
	Set ContourLayer2 = MapFrame2.Overlays(1)

	'Edit contour layer to have the same layer properties as for the other layer
	With ContourLayer2
		.LevelMethod = SrfConLevelMethodSimple
		.SetSimpleLevels(Min:=zMinFeet, Max:=zMaxFeet, Interval:=zIntFeet)
		.FillForegroundColorMap.LoadPreset("Rainbow3")
		.FillForegroundColorMap.SetDataLimits (DataMin:=zMinFeet, DataMax:=zMaxFeet)
		.ShowMajorLabels = False
		.ShowMinorLabels = False
	End With

	'Add a color scale to the new layer and edit properties
	Dim ColorScale2 As Object
	ContourLayer2.ShowColorScale = True
	Set ColorScale2 = ContourLayer2.ColorScale
	With ColorScale2
		.Name = "Color Scale (ft)"
		.Title = ""
		.LabelFormat.Type = srfLabFixed
		.LabelFormat.NumDigits = 1
		.LabelFormat.Postfix = " ft"
		.Left = 8.4
	End With

	'Hide the second contour map and the second color scale bar's lines
	MapFrame2.Visible = False
	ContourLayer2.MajorLine.Style = "Invisible"
	ContourLayer2.MinorLine.Style = "Invisible"
	ColorScale2.FrameLine.Style = "Invisible"
End Sub
