'============================================================================
'  SAMPLE3.BAS
'
'  This script creates several maps from a single data file.  The data
'  file is organized with columns corresponding to X, Y, Z1, Z2, etc.
'  A contour map is created for each set of data: X,Y,Z1, X,Y,Z2, etc.
'  The first row of the data file contains column headings.  This is
'  extracted and used to title the corresponding map.
'
'============================================================================

' Create the Surfer application object.
Set Surf = CreateObject("Surfer.App")

' Specify the input data file
Path$ = Surf.StartupPath()
File$ = Path$+"\SAMPLE3"

' Load the data file into a worksheet window
hWnd = Surf.FileOpen(File$+".DAT",1)
if hWnd = 0 then end

' Create a new plot window
Surf.FileNew()

' Turn off redraw so things go faster
Surf.ViewAutoRedraw(0)

' Loop for each Z column...

for iMap=0 to 5

   ' Form the map title by concatenating the column
   ' titles in the first row of the worksheet

   Title$ = Surf.GetWksCell(hWnd,0,0) +    \
            Surf.GetWksCell(hWnd,0,1) +    \
            Surf.GetWksCell(hWnd,0,iMap+2)

   ' Grid the current X,Y,Z data
   if Surf.GridData(File$+".DAT", xCol=0, yCol=1, zCol=iMap+2) = 0 then end

   ' Create a contour map
   if Surf.MapContour(File$, ID=Title$) = 0 then end

   ' Select the map just created
   Surf.Deselect()
   Surf.Select(Title$)

   ' Calculate the map position on the page
   Width  = 3
   Height = 3
   Left   = 0.5 + int(iMap/3) * (Width+1)
   Bottom = 0.5 + (iMap mod 3) * (Height+.5)

   'Position the map on the page
   Surf.TransformSel(Left,Bottom,Width,Height)

   ' Label the map
   Surf.DrawText(Left+Width/2-.5, Bottom-.1, "Plot of " + Title$)

next

' Turn auto redraw back on and refresh the window
Surf.ViewAutoRedraw(1)
Surf.ViewRedraw()
