How can I use Surfer Scripter to reformat my BNA file(s) for import into CMG?

This article provides a full script for changing which column of a BNA header row the z information is located in.

Q: I want to get my contour map into CMG so I've exported them to BNA, but they aren't loading. CMG support says it's the headers that are the issue. Surfer is exporting a header with the z value in column A and an empty column in column B, but CMG expects the z value in column B and an empty column in column A. How can I update the header information without having to manually go through thousands of lines?


A: This is the perfect instance where a script can do all this manual work for you.

    1. In Windows Explorer, navigate to C:\Program Files\Golden Software\Surfer 16\Scripter and double click on Scripter.exe to launch Scripter.
    2. Delete the existing two lines of script and copy/paste in this script:
      Sub Main
          'Initialize Surfer
          Dim SurferApp, Wks, WksRangeA, WksRangeB As Object
          Set SurferApp = CreateObject("Surfer.Application")
          SurferApp.Visible = True 'Make Surfer visible
          'Prompt the user for the name of the data file to process.
          InFile = GetFilePath("","BNA", CurDir(), "Select data file", 0)
          'Open BNA
          Set Wks = SurferApp.Documents.Open(FileName:=InFile)
          Set WksRangeA = Wks.Columns(Col1:=1, Col2:=1)
          Set WksRangeB = Wks.Columns(Col1:=2, Col2:=2)
          'Loop through rows
          numrows = WksRangeA.RowCount
          For i=1 To numrows
              'If col B in row is empty, cut col A cell for that row and paste it into col B
              If WksRangeB.Cells(i)="" Then
              End If
          'Saves the BNA to the same name
          'Closes Surfer
      End Sub
    3. Click Script | Run.
    4. Choose your BNA file and click Open.


If you have multiple BNA files, you can update line 8 of this script to instead loop through BNA files in a certain directory.


Updated November 8, 2018

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.