Attribute VB_Name = "Module2" ' Script3.bas 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. Sub Main 'On Error GoTo Err_Handling Dim SurferApp As Object Dim Doc As Object Dim Plotwindow As Object Dim Map As Object Dim MapTitle1 As Object Dim MapTitle2 As Object Dim MethodLabel As Variant Dim retValue As Boolean Dim Data As String Dim Grid As String Dim Path As String Dim Method As Integer Dim GifFileName,TimeFileName As String Data = "data.dat" Grid = "RAINRT\data.grd" MethodLabel = Array("Kriging", "Inverse Distance", "Minimum Curvature", _ "Modified Shepard's Method", "Natural Neighbor", "Nearest Neighbor", _ "Polynomial Regression", "Radial Basis Functions", _ "Triangulation with Linear Interpolation") 'Creates an instance of the Surfer Application object and assigns it to the 'variable named "SurferApp" Set SurferApp = CreateObject("Surfer.Application") 'Assigns the location of the data and grid files to the variable named "Path" Path = "C:\Inetpub\wwwroot\AUTORUN\" 'Disables Plotwindow's AutoRedraw to speed up the script 'Plotwindow.AutoRedraw = False Method =1 'Grids the specified data file using the Kriging algorithm and 'assigns the return value to the variable named "retValue" retValue = SurferApp.GridData(DataFile:=Path+"RAINRT\Data3hrs.xls",xcol:=1,ycol:=2,zcol:=3 ,xmin:=97.4465,xmax:=105.641418, _ ymin:=5.61075,ymax:=20.46511,numcols:=800,numrows:=1000,Algorithm:=Method, _ ShowReport:=False, OutGrid:=Path + Grid) SurferApp.GridBlank(InGrid:=Path+Grid , _ BlankFile:=Path+"SURFDATA\thailand.bln" , _ OutGrid:=Path+"SURFDATA\out.grd" , _ OutFmt:=srfGridFmtS7) 'Creates a contour map from the gridded data and assigns it to the variable 'named "Map" Dim Plot As Object Set Plot = SurferApp.Documents.Add(srfDocPlot) 'Declares Shapes as an object Dim Shapes As Object 'Assigns the Shapes collection to the variable named "Shapes" Set Shapes = Plot.Shapes 'Declares MapFrame as an object Dim BaseMap As Object 'Creates a base map and assigns the map coordinate system to the 'variable named "MapFrame" Set MapFrame1 = Shapes.AddContourMap(GridFileName:=Path+"SURFDATA\out.grd") For Each Axis In MapFrame1.Axes Axis.ShowLabels = False Axis.MajorTickType = srfTickNone Axis.MinorTickType = srfTickNone Axis.Visible = False Next Axis Dim ContourMap As Object 'Assigns the contour map properties to the variable named "ContourMap" Set ContourMap = MapFrame1.Overlays(1) ContourMap.LabelFont.Size=10 ContourMap.LabelFont.Face="AngsanaUPC" ContourMap.LabelLabelDist = 0.5 ContourMap.LabelEdgeDist = 0.1 'Declares Levels as an object Dim Levels As Object Dim LevelFileName As String 'Assigns the Levels collection to the variable named "Levels" Set Levels = ContourMap.Levels Dim TextUnit,TextTitle As Object LevelFileName =Path+"LEVELCOLOR\Temp_Travel1.lvl" Set TextTitle = Shapes.AddText(3.42,9.62,"TEMPERATURE") Set TextUnit = Shapes.AddText(5.0,5.9,"Temperature : C ") GifFileName="GIFMAP3hrs\TEMP" & DateFilename() With TextUnit.Font .Face = "AngsanaUPC" .Size = 14 .Bold =True .Color=srfColorDarkBlue End With With TextTitle.Font .Face = "AngsanaUPC" .Size = 18 .Bold =True .Color=srfColorDarkBlue End With Levels.LoadFile(LevelFileName) Dim ColorScale As Object Set ColorScale=ContourMap.ColorScale ContourMap.ShowColorScale = True ContourMap.FillContours=True Dim DiscreteColorScale As Object 'Assigns the color scale properties to the variable named 'DiscreteColorScale" Set DiscreteColorScale = ContourMap.ColorScale DiscreteColorScale.Left=5.25 DiscreteColorScale.Top=5.5 DiscreteColorScale.Width=0.5 DiscreteColorScale.Height=2.5 DiscreteColorScale.LabelFont.Face = "AngsanaUPC" DiscreteColorScale.LabelFont.Size = 18 Set BaseMap = Shapes.AddBaseMap(ImportFileName:=Path+"SHAPEFILE\province.shp") Dim baseMap1 As Object For Each Axis In BaseMap.Axes Axis.ShowLabels = False Axis.MajorTickType = srfTickNone Axis.MinorTickType = srfTickNone Axis.Visible = False Next Axis Set Plot = BaseMap.Parent Set baseMap1=BaseMap.Overlays(1) baseMap1.Line.ForeColor=srfColorBabyBlue Set PostMap = Shapes.AddClassedPostMap(Path+"SURFDATA\postmap_travel.xls", _ xCol:=1, yCol:=2, zCol:=4,labcol:=3) PostMap.BackgroundFill.ForeColor = srfColorWhite PostMap.BackgroundFill.Pattern = "Solid" Set clpost1 = PostMap.Overlays("Classed Post") clPost1.NumClasses = 3 clpost1.ShowLegend = False clpost1.LabelFont.Face = "AngsanaUPC" clpost1.LabelFont.Size = 10 clpost1.LabelFont.Bold = True clpost1.LabelFont.Color = srfColorDarkBlueGreen For i = 1 To 3 With clpost1.BinSymbol(i) .Set = "GSI Default Symbols" .Index = 11 .Size = 0.02 End With Next i clpost1.BinSymbol(1).Color =srfColorRed clpost1.BinSymbol(2).Color =srfColorDarkBlueGreen clpost1.BinSymbol(3).Color =srfColorBlue ' Clear all selections and then select the two MapFrame objects Plot.Selection.DeselectAll BaseMap.Selected = True MapFrame1.Selected = True PostMap.Selected=True Dim TextDate As Object Dim DateString As String Set TextDate = Shapes.AddText(3.3,9.3,Day(Date()) &" "& NameOfMonth(Month(Date())) &" "& Year(Date()) & " " & Hour(Now()) & ":00") With TextDate.Font .Face = "AngsanaUPC" .Size = 16 .Bold =True .Color=srfColorDarkGreen End With Dim TextMet As Object Set TextMet = Shapes.AddText(3.2,2.7,"THAI METEOROLOGICAL DEPARTMENT ") With TextMet.Font .Face = "AngsanaUPC" .Size = 12 .Bold =True .Color=srfColorDarkGreen End With Dim MetLoGo As Object Set MetLoGo=Shapes.AddBaseMap(ImportFileName:=Path+"SURFDATA\LoGo.bmp") MetLoGo.Left=2.37 MetLoGo.Top=2.85 MetLoGo.Width=.6 MetLoGo.Height=.6 For Each Axis In MetLoGo.Axes Axis.ShowLabels = False Axis.MajorTickType = srfTickNone Axis.MinorTickType = srfTickNone Axis.Visible = False Next Axis 'Overlay the selected maps Plot.Selection.OverlayMaps Plot.Export(FileName:=Path+ GifFileName+ ".gif", Options:="Width=325, height=600") 'SurferApp.Visible=True 'Err_Handling: ' Exit Sub End Sub Function DateFilename() Dim Dday,Mmonth,Yyear As String Dim Nday,Nmonth As Integer If Day(Date()) < 10 Then Dday="0" & Day(Date()) Else Dday="" & Day(Date()) End If If Month(Date()) < 10 Then Mmonth="0" & Month(Date()) Else Mmonth="" & Month(Date()) End If Yyear= "" & Year(Date()) Yyear= Right(Yyear,2) DateFilename=Dday & Mmonth & Yyear & Hour(Now()) End Function Function FileName() If Hour(Now()) <10 Then FileName="0" & Hour(Now()) & "00" Else FileName= Hour(Now()) & "00" End If End Function Function NameOfMonth(m) Select Case m Case 1 NameOfMonth="JANUARY" Case 2 NameOfMonth="FEBUARY" Case 3 NameOfMonth="MARCH" Case 4 NameOfMonth="APRIL" Case 5 NameOfMonth="MAY" Case 6 NameOfMonth="JUNE" Case 7 NameOfMonth="JULY" Case 8 NameOfMonth="AUGUST" Case 9 NameOfMonth="SEPEMTER" Case 10 NameOfMonth="OCTOBER" Case 11 NameOfMonth="NOVEMBER" Case 12 NameOfMonth="DECEMBER" End Select End Function