Sub GridAll(Directory As String, File As String, Sample As String, MaxCol As Integer, XLabel As String, YLabel As String, ZLabel() as String) ' This is the routine that actually creates the output. It is appended to text output from PFW to ' create a complete surfer automation module. See XYSCAN2.BAS (Surfer 7) for a complete example. Dim OutputType as String Dim GridMethodType As Integer ' ATTENTION! ATTENTION! ATTENTION ATTENTION! ATTENTION! ATTENTION! (Surfer 7.0 version) ' The last UNcommented "OutputType$" variable will determine the output (edit as desired) OutputType$ = "TEST" 'OutputType$ = "PRINT" ' The last UNcommented "GridMethodType%" variable will determine the grid method (edit as desired) 'GridMethodType% = srfInverseDistance GridMethodType% = srfKriging 'GridMethodType% = srfMinCurvature 'GridMethodType% = srfShepards 'GridMethodType% = srfNaturalNeighbor 'GridMethodType% = srfNearestNeighbor 'GridMethodType% = srfRegression 'GridMethodType% = srfRadialBias 'GridMethodType% = srfTriangulation ' ATTENTION! ATTENTION! ATTENTION ATTENTION! ATTENTION! ATTENTION! Dim FileData as String Dim FileBlank as String Dim FileBlank2 as String Dim FileOut as String Dim FileGrid as String Dim FileFont as String Dim NoBLNFile as Integer Dim iMap As Integer ' Create the Surfer object Set SurferApp = CreateObject("Surfer.Application") ' First make sure that the file directory names are upper case Directory$ = UCASE$(Directory$) File$ = UCASE$(File$) if OutputType$ = "" then OutputType$ = "TEST" OutputType$ = UCASE$(OutputType$) ' Open the .DAT data file and then close the worksheet FileData$ = TRIM$(Directory$) & TRIM$(File$) & ".DAT" FileBlank$ = TRIM$(Directory$) & TRIM$(File$) & ".BLN" Debug.Print "Data File: " & FileData$ Debug.Print "Blanking (boundary) File: " & FileBlank$ ' Open data file If OutputType$ = "TEST" Then Debug.Print "Opening Data File : " & FileData$ SurferApp.Visible = True Set SurferWks = SurferApp.Documents.Open(FileData$) ' Open plot document Set SurferDoc = SurferApp.Documents.Add() ' Open plot window Set SurferPlot = SurferDoc.Windows(1) ' If in test mode enable auto-redraw If OutputType$ = "TEST" Then SurferPlot.AutoRedraw = True Else SurferPlot.AutoRedraw = False End If ' Specify Page Orientation (landscape) Set SurferPageSetup = SurferDoc.PageSetup SurferPageSetup.Orientation = srfLandscape if OutputType$ = "TEST" then Debug.Print "Setting Landscape Page Mode" ' Loop through columns and create the grids For iMap% = 1 To MaxCol% ' Check for blank elements If Asc(ZLabel$(iMap%)) = 0 Then GoTo NextColumn: ' Make the Output File Name (use whole ZLabel string for grid filename) FileOut$ = TRIM$(Directory$) & "OUT.GRD" FileGrid$ = Trim$(Directory$) & Trim$(File$) & "_" & Trim$(ZLabel$(iMap%)) & ".GRD" Debug.Print "Grid File (column " & Str$(iMap%) & "): " & FileGrid$ FileFont$ = "Times New Roman" ' Grid the current X,Y,Z data if OutputType$ = "TEST" then Debug.Print "Gridding Z Data " & Str$(iMap%) & " for " & ZLabel$(iMap%) If SurferApp.GridData(DataFile:=FileData$, OutGrid:=FileOut$, xCol:=1, yCol:=2, zCol:=iMap% + 2, NumRows:=40, NumCols:=40, Algorithm:=GridMethodType%, ShowReport:=False) = 0 Then End ' Spline smooth the grid and blank it if OutputType$ = "TEST" then Debug.Print "Smoothing Column " & STR$(iMap%) & " for " & ZLabel$(iMap%) If SurferApp.GridSplineSmooth(InGrid:=FileOut$, OutGrid:=FileOut$, nRow:=2, nCol:=2) = 0 Then End ' See if the .BLN file is present NoBLNFile% = 1 If Dir$(FileBlank$) <> "" Then NoBLNFile% = 0 ' If BLN file was found blank the grid If NoBLNFile% = 0 Then If OutputType$ = "TEST" Then Debug.Print "Blanking Column " & Str$(iMap%) & " for " & ZLabel$(iMap%) if SurferApp.GridBlank(InGrid:=FileOut$, OutGrid:=FileGrid$, BlankFile:=FileBlank$) = 0 then End ' If the BLN file was not found, spline smooth the grid (with no added nodes) to change the name Else If NoBLNFile% = 1 Then SurferApp.GridSplineSmooth(InGrid:=FileOut$, OutGrid:=FileGrid$, nRow:=0, nCol:=0) End If ' Set the Shapes collection Set SurferShapes = SurferDoc.Shapes ' Load base map if .BLN file is available If OutputType$ = "TEST" Then Debug.Print "Loading Base Map : " & FileBlank$ If NoBLNFile% = 0 Then SurferShapes.AddBaseMap(FileBlank$) ' Create a contour map If OutputType$ = "TEST" Then Debug.Print "Contouring Column" & Str$(iMap%) & " for " & ZLabel$(iMap%) Set SurferMapFrame = SurferShapes.AddContourMap(FileGrid$) ' Add post points from data file if OutputType$ = "TEST" then Debug.Print "Posting Column " & STR$(iMap%) & " for " & ZLabel$(iMap%) Set SurferMapFrame = SurferShapes.AddPostMap(FileData$) ' Select Base and grid and overlay maps if base map was loaded SurferShapes.SelectAll If OutputType$ = "TEST" Then Debug.Print "Overlaying Maps" Set SurferMapFrame = SurferDoc.Selection.OverlayMaps ' Create x, y axes and titles Call GridText(OutputType$, XLabel$, YLabel$, srfATLeft, srfATTop, Sample$, ZLabel$(iMap%), FileFont$) ' Output the plot Call GridOutput(OutPutType$, SurferPlot, SurferDoc) ' Select all objects and delete if OutputType$ = "TEST" then Debug.Print "Selecting and deleting contour plot" SurferShapes.SelectAll SurferDoc.Selection.Delete ' Now plot a 3d map If OutputType$ = "TEST" Then Debug.Print "Wire Framing Column " & Str$(iMap%) & " for " & ZLabel$(iMap%) Set SurferMapFrame = SurferShapes.AddWireframe(FileGrid$) ' Create x, y axes and titles (axis label positions are flipped because of landscape mode) Call GridText(OutputType$, XLabel$, YLabel$, srfATLeft, srfATTop, Sample$, ZLabel$(iMap%), FileFont$) ' Output the plot Call GridOutput(OutPutType$, SurferPlot, SurferDoc) ' Select all objects and delete for next plot If OutputType$ = "TEST" Then Debug.Print "Selecting and deleting surface plot" SurferShapes.SelectAll SurferDoc.Selection.Delete ' Now plot a shaded relief map If OutputType$ = "TEST" Then Debug.Print "Shaded Reliefing Column " & Str$(iMap%) & " for " & ZLabel$(iMap%) Set SurferMapFrame = SurferShapes.AddReliefMap(FileGrid$) ' Create x, y axes and titles Call GridText(OutputType$, XLabel$, YLabel$, srfATLeft, srfATTop, Sample$, ZLabel$(iMap%), FileFont$) ' Output the plot Call GridOutput(OutPutType$, SurferPlot, SurferDoc) ' Select all objects and delete for next plot If OutputType$ = "TEST" Then Debug.Print "Selecting and deleting surface plot" SurferShapes.SelectAll SurferDoc.Selection.Delete NextColumn: Next iMap% ' Close the Surfer App SurferApp.Documents.CloseAll(SaveChanges:=srfSaveChangesNo) SurferApp.Quit End Sub Sub GridText(OutputType$, XLabel$, Ylabel$, XLabelPosition%, YLabelPosition%, Sample$, Title$, FileFont$) If OutputType$ = "TEST" Then Debug.Print "Adding text for axes" Set SurferAxes = SurferMapFrame.Axes Set SurferAxis = SurferAxes(XLabelPosition%) SurferAxis.Title = XLabel$ ' Create y axis Set SurferAxes = SurferMapFrame.Axes Set SurferAxis = SurferAxes(YLabelPosition%) SurferAxis.Title = YLabel$ ' Add the sample name and title Set SurferText = SurferShapes.AddText(5.5, 1, Sample$) SurferText.Font.Face = FileFont$ SurferText.Font.Size = 14 Set SurferFontFormat = SurferText.Font SurferFontFormat.HAlign = srfTACenter Set SurferText = SurferShapes.AddText(5.5, .75, Title$) SurferText.Font.Face = FileFont$ SurferText.Font.Size = 18 Set SurferFontFormat = SurferText.Font SurferFontFormat.HAlign = srfTACenter End Sub Sub GridOutput(OutputType$, SurferPlot, SurferDoc) If OutputType$ = "PRINT" Then Debug.Print "Sending output to printer" SurferPlot.AutoRedraw = True SurferDoc.PrintOut(Method:=srfTruncate) SurferPlot.AutoRedraw = False End If If OutputType$ = "TEST" Then Debug.Print "Waiting for 8 seconds" Wait(8) End If End Sub