Reformat BNA file(s) for import into CMG using Surfer automation

CMG's (Computer Modeling Group's) simulation software requires a BNA header that does not match Surfer's export format. Surfer exports a BNA 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. Rather than update the header information manually in a text editor, a script can be used to save time and ensure accuracy.
  1. In Windows Explorer, navigate to C:\Program Files\Golden Software\Surfer 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 2021

Was this article helpful?
1 out of 1 found this helpful



Please sign in to leave a comment.