'Grd2arc converts a Surfer GRD file to ArcView, ArcINFO, ' Spatial Analyst ASC format. ' Converted from srf7_2aiGRD.frm from Johan.Kabout@MI.DHV.NL - TB Jan 00. ' TB - 19 Mar 00. Sub Main Set srf = CreateObject("Surfer.application") Set plot = srf.Documents.Add(srfDocPlot) srf.Visible = False TempFile = Srf.Path+"\samples\temp.dat" SurferGrid = GetFilePath(srf.Path+"\samples\demogrid.grd","grd", _ srf.Path+"\samples\","Open GRD File") 'Mirror Y in Surfer GRD file, save to ASCII format. ok = srf.GridTransform(SurferGrid, srfGridTransMirrorY, _ OutGrid:=TempFile,OutFmt:=srfGridFmtAscii) lengthstr = Len(SurferGrid) ArcGrid = Mid(SurferGrid, 1, Len(SurferGrid)-3) + "ASC" Open TempFile For Input As #1 Open ArcGrid For Output As #2 'Skip the first line of the file. Line Input #1,a 'Read number of columns and rows. Line Input #1,a nCol = Left(a,InStr(a," ")) nRow = Right(a,Len(a)-InStr(a," ")) 'Read X min max. Line Input #1,a xMin = Left(a,InStr(a," ")) xMax = Right(a,Len(a)-InStr(a," ")) 'Read Y min max. Line Input #1,a yMin = Left(a,InStr(a," ")) yMax = Right(a,Len(a)-InStr(a," ")) 'Read Z min max (not used in Arc grid file). Line Input #1,a zMin = Left(a,InStr(a," ")) zMax = Right(a,Len(a)-InStr(a," ")) xCellSize = ((Val(xMax) - Val(xMin)) / (Val(nCol) - 1)) yCellSize = ((Val(yMax) - Val(yMin)) / (Val(nRow) - 1)) Diff = 100*(xCellSize - yCellSize) / xCellSize 'Debug.Print "xCellSize, yCellSize, Diff =";xcellsize;" ";ycellsize;" ";diff If (xCellSize - yCellSize) / xCellSize > 1e-3 Then MsgBox("Cell dimensions are not square. The smaller grid spacing will be stretched by ("+Str(Diff)+"%) to match the larger grid spacing." + _ " The Arc grid will be created with xCellSize: " + Str(xCellSize) ) End If Print #2, "ncols "; nCol Print #2, "nrows "; nRow Print #2, "xllcorner "; xMin Print #2, "yllcorner "; yMin Print #2, "cellsize "; xCellSize Print #2, "NODATA_value 1.70141e+038" Print #2, " " Do While Not EOF(1) Line Input #1, instring Print #2, instring Loop Close #1 Close #2 MsgBox ("The Arc grid file "+ArcGrid + " has been created.") srf.Quit End Sub