'=============================================================================
' Surfer v8 script file for contouring and posting inversion model section.
' Created by ModSect v4.41c on 21/01/08
'=============================================================================
 
 Sub Main
'=============================================================================
' Declare object and string variables used in script
 Dim SurferApp, Plot, Shapes As Object
 Dim MapFrame, StnMapFrame, PostMapFrame As Object
'=============================================================================
 
' Initialize script variables
 pageunits$="inch"
 puscale#=2.540 ' (cm/pu)
 PageOrientation%=srfLandscape
 xpagemax#=17.00 ' (inch)
 ypagemax#=8.50 ' (inch)
 sFileStem$= "C:\FIELD_DATA\job.780_arcadia_tas_ip\Processed_Data\04\04R"
 LengthUnits$= "m"
 xmin#=         15.00
 xmax#=        485.00
 xinc#=         20.00
 xscale#=       50.80 ' (m/inch)
 ymin#=        -90.00
 ymax#=          0.00
 yinc#=         10.00
 yscale#=       50.80 ' (m/inch)
 ncntdec%=0
 nsdec%=0
 sBrgLeft$="South"
 sBrgRight$="North"
 sLnTitle$ = _
   "Scottsdale" & vbCrLf & _
   "Line 04"
 sJobName$ = "Scottsdale"
 sLineName$ = "Line 04"
 sTbGloss$ = _
   "Transmitter Data:" & vbCrLf & _
   "Length = 20 by 20" & vbCrLf & _
   "Ramp Time = 2 usec" & vbCrLf & _
   "Inversion Control Parameters:" & vbCrLf & _
   " " & vbCrLf & _
   "Receiver Data:" & vbCrLf & _
   "Effective Area = 2.50E+2 m^2" & vbCrLf & _
   " " & vbCrLf & _
   "Inversion Control Parameters:" & vbCrLf & _
   "dpW=1, dzW=3"
 dim sTbLabel$(6)
 sTbLabel$(1)="AUTHOR"
 sTbLabel$(2)="DRAWN"
 sTbLabel$(3)="DATE"
 sTbLabel$(4)="SCALE"
 sTbLabel$(5)="REPORT"
 sTbLabel$(6)="REF:"
 dim sTbText$(8)
 sTbText$(1)="Zonge"
 sTbText$(2)="Zonge"
 sTbText$(3)="18/01/08"
 sTbText$(4)="1:2000"
 sTbText$(5)="Job 780"
 sTbText$(6)="04.m1d"
 sTbText$(7)=" "
 sTbText$(8)=" "
 sTbTitle$ = _
   "Arcadia Resources" & vbCrLf & _
   "Scottsdale Line 04" & vbCrLf & _
   " " & vbCrLf & _
   "1D Smooth-Model Inversion" & vbCrLf & _
   "Moving-In-Loop TEM dB/dt Data"
 
' Plot margins (inch)
 xlmargin#=1.50/puscale#
 xumargin#=12.50/puscale#
 ylmargin#=4.25/puscale#
 yumargin#=5.25/puscale#
 
'Plot reference points (inch)
 xoffset#=1.0/puscale#
 dx#=(xmax#-xmin#)/xscale#
 xdcmin#=xoffset# + xlmargin#
 xdcmax#=xdcmin# + dx#
 xdcmid#=(xdcmin# + xdcmax#)/2
 xpgmax#=xdcmax# + xumargin#
 yoffset#=1.0/puscale#
 dy#=(ymax#-ymin#)/yscale#
 ydcmin#=yoffset# + ylmargin#
 ydcmax#=ydcmin# + dy#
 ydcmid#=(ydcmin# + ydcmax#)/2
 ypgmax#=ydcmax# + yumargin#
 
' Make file names
 CSTxtFile$ = TRIM$(sFileStem$)+".txt"
 CSCsvFile$ = TRIM$(sFileStem$)+".csv"
 CSBlnFile$ = TRIM$(sFileStem$)+".bln"
 CSLvlFile$ = TRIM$(sFileStem$)+".lvl"
 CSSrfFile$ = TRIM$(sFileStem$)+".srf"
 CSGrdFile$ = TRIM$(sFileStem$)+".grd"
 
' Create a Surfer Application object and assign it to variable SurferApp
 Set SurferApp = CreateObject("Surfer.Application")
 SurferApp.Visible = True
 SurferApp.WindowState = srfWindowStateMaximized
 SurferApp.ScreenUpdating = False
 
' Create a plot document in Surfer and assign it to variable Plot
 Set Plot = SurferApp.Documents.Add(srfDocPlot)
 Set Shapes = Plot.Shapes
 
' Set page layout
 With Plot.PageSetup
   .Orientation = PageOrientation%
   .Width = xpagemax#
   .Height = ypagemax#
 End With
' Set default font attributes
 With Plot.DefaultFont
   .Face = "Arial"
   .Size = 10
   .Color = srfColorBlack
   .HAlign = srfTACenter
   .VAlign = srfTABaseline
 End With
 
'=============================================================================
' Surfer script for drawing text and surround box.
'=============================================================================
' Draw line-title text
 With Shapes.AddText(x:=xdcmid#, y:=ydcmax#+1.5/puscale#, Text:=sLnTitle$)
   .Name = "sLnTitle"
   .Font.Size = 14
   .Font.HAlign = srfTACenter
   .Font.VAlign = srfTABottom
 End With
 With Shapes.AddText(x:=xdcmin#, y:=ydcmax#+0.5/puscale#, Text:=sBrgLeft$)
   .Name = "sBrgLeft"
   .Font.Size = 10
   .Font.HAlign = srfTARight
   .Font.VAlign = srfTABaseline
 End With
 With Shapes.AddText(x:=xdcmax#+0.2/puscale#, y:=ydcmax#+0.5/puscale#, Text:=sBrgRight$)
   .Name = "sBrgRight"
   .Font.Size = 10
   .Font.HAlign = srfTALeft
   .Font.VAlign = srfTABaseline
 End With
 
' Draw surround box
 With Shapes.AddRectangle(Left:=xoffset#, Bottom:=yoffset#, Right:=xpgmax#, Top:=ypgmax# )
   .Line.Width = 0.05/puscale#
 End With
 
' Draw title-block lines
 With Shapes.AddRectangle(Left:=xpgmax#-10.0/puscale#, Bottom:=yoffset#, Right:=xpgmax#, Top:=yoffset#+5.5/puscale# )
   .Line.Width = 0.02/puscale#
 End With
 Plot.DefaultLine.Width = 0.02/puscale#
 With Shapes
   .AddRectangle(Left:=xpgmax#-10.0/puscale#, Bottom:=yoffset#, Right:=xpgmax#, Top:=yoffset#+5.5/puscale# )
   .AddRectangle(Left:=xpgmax#-10.0/puscale#, Bottom:=yoffset#+0.5/puscale#, Right:=xpgmax#, Top:=yoffset#+1.0/puscale# )
   .AddRectangle(Left:=xpgmax#-10.0/puscale#, Bottom:=yoffset#+1.0/puscale#, Right:=xpgmax#, Top:=yoffset#+1.5/puscale#)
   .AddRectangle(Left:=xpgmax#-8.0/puscale#, Bottom:=yoffset#+0.5/puscale#, Right:=xpgmax#-6.0/puscale#, Top:=yoffset#+1.5/puscale# )
   .AddRectangle(Left:=xpgmax#-4.0/puscale#, Bottom:=yoffset#, Right:=xpgmax#-2.0/puscale#, Top:=yoffset#+1.5/puscale# )
 End With
 
' Draw line-title text in title block
 xc#= xpgmax# - 5.0/puscale#
 yc#= ypgmax# - 1.5/puscale#
 With Shapes.AddText(x:=xc#, y:=yc#, Text:=sJobName$)
   .Name = "sJobName"
   .Font.Size = 14
   .Font.HAlign = srfTACenter
   .Font.VAlign = srfTABottom
 End With
 xc#= xpgmax# - 5.0/puscale#
 yc#= ypgmax# - 2.2/puscale#
 With Shapes.AddText(x:=xc#, y:=yc#, Text:=sLineName$)
   .Name = "line"
   .Font.Size = 14
   .Font.HAlign = srfTACenter
   .Font.VAlign = srfTABottom
 End With
 
' TB title
 xc#= xpgmax# - 5.0/puscale#
 yc#= yoffset# + 4.65/puscale#
 With Shapes.AddText(x:=xc#, y:=yc#, Text:=sTbTitle$)
   .Name = "sTbTitle"
   .Font.Size = 14
   .Font.HAlign = srfTACenter
   .Font.VAlign = srfTATop
 End With
 
' TB gloss
 xc#= xpgmax# - 9.0/puscale#
 yc#= yoffset# + 7.0/puscale#
 With Shapes.AddText(x:=xc#, y:=yc#, Text:=sTbGloss$)
   .Name = "sTbGloss"
   .Font.Size = 10
   .Font.HAlign = srfTALeft
   .Font.VAlign = srfTABottom
 End With
 
' TB labels
 With Plot.DefaultFont
   .Size = 8
   .HAlign = srfTACenter
   .VAlign = srfTAVCenter
 End With
 xc#= xpgmax# - 11.0/puscale#
 yc#= yoffset# + 1.2/puscale#
 dx#= 2.0/puscale#
 With Shapes
   .AddText( x:=xc#+1*dx#, y:=yc#, Text:=sTbLabel$(1) )
   .AddText( x:=xc#+1*dx#, y:=yc#, Text:=sTbLabel$(1) )
   .AddText( x:=xc#+2*dx#, y:=yc#, Text:=sTbLabel$(2) )
   .AddText( x:=xc#+3*dx#, y:=yc#, Text:=sTbLabel$(3) )
   .AddText( x:=xc#+4*dx#, y:=yc#, Text:=sTbLabel$(4) )
   .AddText( x:=xc#+5*dx#, y:=yc#, Text:=sTbLabel$(5) )
    xc#= xpgmax# - 9.6/puscale#
    yc#= yoffset# + 0.2/puscale#
   .AddText( x:=xc#, y:=yc#, Text:=sTbLabel$(6) )
 End With
 
' TB text
 xc#= xpgmax# - 11.0/puscale#
 yc#= yoffset# + 0.7/puscale#
 dx#= 2.0/puscale#
 With Shapes
   .AddText( x:=xc#+1*dx#, y:=yc#, Text:=sTbText$(1) )
   .AddText( x:=xc#+2*dx#, y:=yc#, Text:=sTbText$(2) )
   .AddText( x:=xc#+3*dx#, y:=yc#, Text:=sTbText$(3) )
   .AddText( x:=xc#+4*dx#, y:=yc#, Text:=sTbText$(4) )
   .AddText( x:=xc#+5*dx#, y:=yc#, Text:=sTbText$(5) )
    yc#= yoffset# + 0.2/puscale#
    xc#= xpgmax# - 8.5/puscale#
   .AddText( x:=xc#, y:=yc#, Text:=sTbText$(6) )
    xc#= xpgmax# - 3.0/puscale#
   .AddText( x:=xc#, y:=yc#, Text:=sTbText$(7) )
 End With
 
'=============================================================================
' Surfer script for contouring and posting smooth-model resistivity.
'=============================================================================
' Indicies of *.csv x, y & z columns (starting with number 1), zCol used for posting.
 xCol%=1
 yCol%=2
 zCol%=4
 
' Create a filled contour map
 Set MapFrame = Shapes.AddContourMap(CSGrdFile$)
 Set ContourMap = MapFrame.Overlays(1)
 With ContourMap
   .Name = "InvMod Contour"
   .Levels.LoadFile(CSLvlFile$)
   .Levels.SetLabelFrequency(FirstIndex:=1, NumberToSet:=1, NumberToSkip:=2)
   .Levels.SetHachFrequency( FirstIndex:=1, NumberToSet:=1, NumberToSkip:=0 )
   .HachDirection = srfConHachDownhill
   .HachLength = 0.02/puscale#
   .LabelLabelDist = 5.0/puscale#
   .LabelEdgeDist = 0.6/puscale#
   .LabelFormat.NumDigits = ncntdec%
   .LabelFont.Size = 8
   .LabelFormat.Type=srfLabFixed
   .SmoothContours = srfConSmoothNone
   .FillContours = True
 End With
 
' Post data value positions
 Set PostMapFrame = Shapes.AddPostMap( DataFileName:=CSCsvFile$, xCol:=xCol%, yCol:=yCol% )
 With PostMapFrame.Overlays(1)
   .Name = "InvMod Post"
   .SetSymbolScaling( Method:=srfPostFixed, SymbolHeight1:=0.13/puscale# )
   .Symbol.Index = 0
 End With
 
' Post station positions
 Set StnMapFrame = Shapes.AddPostMap( DataFileName:=CSTxtFile$, xCol:=1, yCol:=2, LabCol:=3 )
 With StnMapFrame.Overlays(1)
   .Name = "InvMod Station"
   .SetSymbolScaling( Method:=srfPostFixed, SymbolHeight1:=0.25/puscale# )
   .Symbol.Index = 0
    With .LabelFont
      .Size = 10
      .HAlign = srfTARight
      .VAlign = srfTACenter
    End With
   .LabelAngle = -90
   .LabelPos = srfPostPosAbove
   .LabelFormat.Type = srfLabFixed
   .LabelFormat.NumDigits = nsdec%
 End With
 
' Load topographic outline
 Set BaseMapFrame = Shapes.AddBaseMap( ImportFileName:=CSBlnFile$)
 With BaseMapFrame.Overlays(1)
   .Name = "InvMod Topo"
    With .Fill
      .ForeColor = srfColorWhite
      .Pattern = "Solid"
      .Transparent = False
    End With
 End With
 
' Overlay contour, post and base maps
 Plot.Selection.DeselectAll
 MapFrame.Selected = True
 StnMapFrame.Selected = True
 BaseMapFrame.Selected = True
 PostMapFrame.Selected = True
 Plot.Selection.OverlayMaps
 Plot.Selection.DeselectAll
 MapFrame.Name =  "InvMod"
 
' Mask out topography
 With MapFrame
   .Overlays("InvMod Post").SetZOrder(Zorder:=srfZOToFront)
   .Overlays("InvMod Topo").SetZOrder(Zorder:=srfZOToFront)
   .Overlays("InvMod Contour").SetZOrder(Zorder:=srfZOToBack)
 End With
 
' Set top axis attributes
 With MapFrame.Axes("Top Axis")
   .SetScale( Minimum:=xmin#, Maximum:=xmax#, MajorInterval:=xinc#, _
      FirstMajorTick:=xmin#, LastMajorTick:=xmax#, Cross1:=ymax# )
   .Title = lntitle2$
   .TitleFont.Size = 12
   .TitleOffset2 = 1.0/puscale#
   .ShowLabels = False
   .LabelFont.Size = 10
   .LabelFormat.NumDigits = 0
   .LabelFormat.Type = srfLabFixed
   .LabelAngle = -90
   .MajorTickType = srfTickNone
   .MinorTickType = srfTickNone
 End With
 
' Set bottom axis attributes
 With MapFrame.Axes("Bottom Axis")
   .SetScale( Minimum:=xmin#, Maximum:=xmax#, MajorInterval:=xinc#, _
      FirstMajorTick:=xmin#, LastMajorTick:=xmax#, Cross1:=ymin# )
   .ShowLabels = False
   .LabelFont.Size = 10
   .LabelFormat.NumDigits = 0
   .LabelFormat.Type = srfLabFixed
   .LabelAngle = -90
   .MajorTickType = srfTickNone
   .MinorTickType = srfTickNone
 End With
 
' Set left axis attributes (leave labels and ticks off until map is repositioned)
 FirstYTic#=CInt(ymin#/yinc#)*yinc#
 If FirstYTic# < ymin# Then FirstYTic#=FirstYTic#+yinc#
 If FirstYTic# < ymin# Then FirstYTic#=FirstYTic#+yinc#
 With MapFrame.Axes("Left Axis")
   .SetScale( Minimum:=ymin#, Maximum:=ymax#, MajorInterval:=yinc#, _
      FirstMajorTick:=FirstYTic#, LastMajorTick:=ymax#, Cross1:=xmin# )
   .ShowLabels = False
   .LabelFont.Size = 10
   .LabelFormat.NumDigits = 0
   .LabelFormat.Type = srfLabFixed
   .LabelAngle = -90
   .LabelOffset = 0.1/puscale#
   .MajorTickLength = 0.127/puscale#
   .MajorTickType = srfTickNone
   .MinorTickType = srfTickNone
 End With
 
' Set right axis attributes
 With MapFrame.Axes("Right Axis")
   .SetScale( Minimum:=ymin#, Maximum:=ymax#, MajorInterval:=yinc#, _
      FirstMajorTick:=FirstYTic#, LastMajorTick:=ymax#, Cross1:=xmax# )
   .Title = "Elevation ("+LengthUnits$+")"
    With .TitleFont
      .Size = 12
      .HAlign = srfTACenter
      .VAlign = srfTAVCenter
    End With
   .TitleOffset1 = 0.0
   .TitleOffset2 = 0.0
   .TitleAngle = 180
   .ShowLabels = True
   .LabelFont.Size = 10
   .LabelFormat.NumDigits = 0
   .LabelFormat.Type = srfLabFixed
   .LabelAngle = -90
   .LabelOffset = 0.1/puscale#
   .MajorTickLength = 0.127/puscale#
   .MajorTickType = srfTickOut
   .MinorTickType = srfTickNone
 End With
 
' Move and size the map
 With MapFrame
   .xMapPerPU = xscale#
   .yMapPerPU = yscale#
   .Selected = True
 End With
 With Plot.Selection
   .Left = xdcmin#
   .Top = ydcmin# + .Height
   .DeselectAll
 End With
 
' Turn left-axis ticks and tick labels on.
 With MapFrame.Axes("Left Axis")
   .ShowLabels = True
   .MajorTickType = srfTickOut
   .MinorTickType = srfTickNone
 End With
 
' Draw length scale bar
 With MapFrame.ScaleBars.Add
   .Name = "Scale Bar"
   .Axis = srfTrackX
   .CycleSpacing = 1*xinc#
   .LabelIncrement = 1*xinc#
    With .LabelFormat
      .NumDigits = 0
      .Type = srfLabFixed
      .Postfix = LengthUnits$
    End With
   .LabelFont.Size = 8
   .Selected = True
 End With
' Move length scale bar to bottom of map
 With Plot.Selection
   .Left = xdcmid#- 4*xinc#/xscale#
   .Top = yoffset#+ylmargin#/2.0 + .Height
   .DeselectAll
 End With
' Draw color scale bar
 With MapFrame.Overlays("InvMod Contour")
   .ShowColorScale = True
   Set ColorScale = .ColorScale
 End With
' Get color scale height (page units)
  ColorScale.Selected = True
  csheight# = Plot.Selection.Height
  cswidth# = Plot.Selection.Width
  csratio# = (ypgmax# - 10.0/puscale#)/csheight#
  If csratio#>1 Then csratio# = 1
  With ColorScale
    .FirstLabel = 1
    .LabelFrequency = Round(2/csratio#)
    .LabelFont.Size = Round(10/csratio#)
     With .LabelFormat
       .NumDigits = ncntdec%
       .Type = srfLabFixed
     End With
  End With
' Move color scale bar to right margin and size to fit
 xc#= xpgmax# - 2.0/puscale#
 yc#= yoffset# + 5.9/puscale#
 csheight# = csheight#*csratio#
 cswidth# = cswidth#*csratio#
 With Plot.Selection
   .Height = csheight#
   .Width = cswidth#
   .Left = xc#
   .Top = yc# + .Height
   .DeselectAll
 End With
 With Shapes.AddText(x:=xc#+cswidth#*0.3, y:=yc#+csheight#+0.1/puscale#, Text:="Model Resistivity"& vbCrLf & "(ohm-m)")
   .Name = "color_scale_label"
   .Font.Size = 10
   .Font.HAlign = srfTACenter
   .Font.VAlign = srfTABottom
 End With
 
' Turn redraw back on
 Plot.ShowObjectManager = False
 Plot.Windows(1).Zoom(srfZoomFitToWindow)
 SurferApp.ScreenUpdating = True
 
' Save as Surfer file
 Plot.SaveAs(CSSrfFile$)
 
 End Sub
