'Grd2Lat.bas converts a GRD or DEM file to a 2D curvilinear LAT file ' for Voxler. 09 Mar 06 - TB. Sub Main Debug.Print "----- ";Time;" -----" On Error Resume Next Set surf = GetObject(,"surfer.application") If Err<>0 Then Set surf = CreateObject("surfer.application") On Error GoTo 0 path1 = surf.Path+"\samples\" path2 = "c:\incoming\" grdfile1 = "c:\incoming\demogrid.grd" tempgrd1 = path2 + "tempgrd1.grd" tempdat1 = path2 + "tempxyz1.dat" grdfile1 = GetFilePath(grdfile1,"grd;dem",path2,"Get GRD or DEM File") latfile1 = grdfile1 + ".lat" If grdfile1 = "" Then End 'LAT header strings. srfgridfmts7 lathdr1 = "#!/usr/explorer/bin/explorer cxLattice plain 1.0" + vbCrLf + _ "# nDim, number of dimensions." + vbCrLf + _ " 2" + vbCrLf + _ "# dims, the vector of dimensions (size of the Array: columns x rows x layers)." lathdr2 = "# nDataVar, number of data variables at each node." + vbCrLf + _ " 1" + vbCrLf + _ "# primType, primitive type of data." + vbCrLf + _ "# 0=Byte, 1=short Int*2, 2=Long Int*4, 3=float*4, 4=Double*8." + vbCrLf + _ " 3" + vbCrLf + _ "# coordType, coordinate type." + vbCrLf + _ "# 0=uniform, 1=perimeter, 2=curvilinear." + vbCrLf + _ " 2" + vbCrLf + _ "# nSteps, number of data structures In the file." + vbCrLf + _ " 1" + vbCrLf + _ "# nCoordVar (Curvilinear lattices only)." + vbCrLf + _ " 3" + vbCrLf + _ "# coordinate values." + vbCrLf + _ "# For uniform lattices, these are the bounding box coordinates" + vbCrLf + _ "# For rectilinear (perimeter) lattices, these are the values of the edge points." + vbCrLf + _ "# For curvilinear lattices, these are the node locations." lathdr3 = "#data values" surf.GridConvert(grdfile1,tempgrd1,srfGridFmtAscii) surf.GridConvert(grdfile1,tempdat1,srfGridFmtXYZ) Open tempgrd1 For Input As #1 Open tempdat1 For Input As #2 Open latfile1 For Output As #3 Print #3, lathdr1 'Read GRD file. Get cols and rows, skip other header info. Line Input #1, a 'DSAA Line Input #1, ncolsrows 'number of columns and rows. Print #3, ncolsrows Line Input #1, a 'x min max Line Input #1, a 'y min max Line Input #1, a 'z min max 'Write XYZ nodes to LAT. Print #3, lathdr2 While Not EOF(2) Line Input #2, a Print #3, a Wend 'Write Z values to LAT. Print #3, lathdr3 'Read rest of file and write to LAT file. While Not EOF(1) Line Input #1, a Print #3, a Wend Debug.Print latfile1; " has been created." MsgBox (latfile1+ " has been created.") End Sub