'#Reference {F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0#C:\WINDOWS\System32\comdlg32.ocx#Microsoft Common Dialog Control 6.0 'Arc2Grd.bas converts an ESRI grid file to Surfer ASCII GRD format. ' 14 May 04 - TB. ' Added code to adjust min and max by half cell width since ' ESRI grids are based on the cell centers and Surfer grids ' are based on the cell edges. 30 Mar 06 - TB. Sub Main Debug.Print "---- ";Time;" -----" 'file1 = InputBox("Enter ArcView grid name","Arc ASC Input","d:\download\sample.asc" path1 = "c:\incoming\" file1 = GetFilePath(path1+"sample.asc","asc;grd",,"Open Arc ASC Grid File") If file1 = "" Then End If LCase(Left(file1,3)) = "grd" Then file1 = file1 + ".asc" 'file2 = "d:\download\SampleAsc.grd" file2 = Left(file1,Len(file1)-4) + "ASC.grd" tmpfile1 = Left(file1,Len(file1)-4) + "Tmp1.grd" tmpfile2 = Left(file1,Len(file1)-4) + "Tmp2.grd" Debug.Print "Output Surfer GRD: ";file2 Set surf = GetObject(,"Surfer.Application") Set plotdoc1 = surf.ActiveDocument Set plotwin1 = surf.ActiveWindow surf.Visible=True Set wksdoc1 = surf.Documents.Open(file1, _ options:="delimiter=comma,tab,space;skipextradelimiters=1") '----- 'Display Arc grid header. With wksdoc1 Debug.Print "1: ";.Cells("a1");" ";.Cells("b1") Debug.Print "2: ";.Cells("a2");" ";.Cells("b2") Debug.Print "3: ";.Cells("a3");" ";.Cells("b3") Debug.Print "4: ";.Cells("a4");" ";.Cells("b4") Debug.Print "5: ";.Cells("a5");" ";.Cells("b5") Debug.Print "6: ";.Cells("a6");" ";.Cells("b6") Debug.Print "7: ";.Cells("a7");" ";.Cells("b7") nCols = .Cells("b1") nRows = .Cells("b2") xMin = .Cells("b3") yMin = .Cells("b4") CellSize = .Cells("b5") BlankingValue = .Cells("b6") End With xMin = xMin + 0.5*CellSize yMin = yMin + 0.5*CellSize xMax = xMin + CellSize*(nCols-1) yMax = yMin + CellSize*(nRows-1) zMin = -1 'dummy values. zMax = 1 'MsgBox ("Press OK to continue") Debug.Print "-----" Debug.Print "Surfer GRD Header" Debug.Print "DSAA" Debug.Print nCols;" ";nRows Debug.Print xMin;" ";xMax Debug.Print yMin;" ";yMax Debug.Print zMin;" ";zMax Open file1 For Input As #1 Open tmpfile1 For Output As #2 Print #2,"DSAA" Print #2, CStr(ncols) + " " + CStr(nrows) Print #2, CStr(xMin) + " " + CStr(xMax) Print #2, CStr(yMin) + " " + CStr(yMax) Print #2, CStr(zMin) + " " + CStr(zMax) For i = 1 To 6 Line Input #1,a Debug.Print i;" ";a If InStr(a,Chr(10)) <> 0 Or InStr(a,Chr(12)) <> 0 Then MsgBox("Invalid end-of-line characters.", _ vbOkOnly,"Error Reading File") End End If Next i Debug.Print "Writing ";tmpfile1 While Not EOF(1) Line Input #1,a Print #2,a Wend Close #2 Wait 1 Debug.Print "Mirror Y to ";tmpfile2 surf.GridTransform(ingrid:=tmpfile1, _ operation:=srfGridTransMirrorY, _ outgrid:=tmpfile2, _ outfmt:=srfGridFmtBinary) Debug.Print "Replace NODATA with blanking value to ";file2 surf.GridMath(Function:="c=if(a=" & blankingvalue & ",1.70141e38,a)", _ ingrida:=tmpfile2, _ outgridc:=file2) wksdoc1.Close(srfSaveChangesNo) plotdoc1.Shapes.AddImageMap(file2) MsgBox(file2 & " created.") End Sub