'Matlab2Bln.bas converts a Matlab coastline file to BLN format. ' Work in progress. ' Source of files: http://rimmer.ngdc.noaa.gov/coast/ ' 11 Jul 01 - TB ' More work done. 23 Feb 04 - TB ' New source URL: ' http://www.ngdc.noaa.gov/mgg/shorelines/shorelines.html ' 09 Nov 04 - TB. ' New source URL: ' http://rimmer.ngdc.noaa.gov/mgg/coast/getcoast.html ' 18 Aug 05 - TB Sub Main Debug.Print "----- ";Time;" -----" 'Use existing Surfer instance, or create new one if none exists. On Error Resume Next Set surf = GetObject(,"surfer.application") If Err <> 0 Then Set surf = CreateObject("surfer.application") surf.Documents.Add(srfDocPlot) End If On Error GoTo 0 surf.Visible = True 'Set plotdoc1 = surf.ActiveDocument 'If plotdoc1.Type <> srfDocPlot Or _ ' (plotdoc1.Type = srfDocPlot And plotdoc1.Shapes.Count<>0) Then ' Set plotdoc1 = surf.Documents.Add(srfDocPlot) 'End If 'Set plotwin1 = surf.ActiveWindow 'Set shapes1 = plotdoc1.Shapes Debug.Print surf.Version 'plotwin1.AutoRedraw=False file1 = GetFilePath("c:\download\*matlab*.dat") Set wksdoc1 = surf.Documents.Open(file1) Debug.Print "Last row = ";wksdoc1.UsedRange.LastRow Set wkswindow1 = surf.ActiveWindow If Left(wksdoc1.Cells("A1"),3) <> "nan" Then MsgBox("Not a Matlab file." + vbCrLf + "Terminating script.") End End If headerrow = 1 objectcount = 0 vertexcount = 0 For i = 2 To wksdoc1.UsedRange.LastRow currentcell = wksdoc1.Cells(row:=i, col:=1) If currentcell = "nan nan" Or i = wksdoc1.UsedRange.LastRow Then Debug.Print "" objectcount = objectcount + 1 Debug.Print i;" ";Format(i/wksdoc1.UsedRange.LastRow,"0%"); _ " ";objectcount;" ";headerrow;" ";vertexcount; wksdoc1.Cells(row:=headerrow,col:=1).Value = vertexcount wkswindow1.TopRow = headerrow Wait .1 vertexcount = 0 headerrow = i Else vertexcount = vertexcount + 1 If vertexcount Mod 10 = 0 Then Debug.Print "."; End If Next 'i outfile1 = Left(file1,Len(file1)-3) & "bln" wksdoc1.SaveAs(outfile1) Debug.Print outfile1 & " has been saved." MsgBox (outfile1 & " has been saved.",vbOkOnly, "BLN File Saved") End Sub