Surfer 7 Grid File Format
(The really useful stuff is the "example" table and sample code at the very bottom.)
Surfer 7 grid files [.GRD] use a tag-based binary format to allow for future enhancements. Each section is preceded by a tag structure, which indicates the type and size of the following data. If a program does not understand or want a particular type of data, it can read the associated tag and quickly skip to the next section. In general, sections can appear in any order except for the first, which must be a Header section.
Data types used in Surfer 7 grid files:
Type |
Description |
long |
32 bit signed integer |
double |
64 bit double precision floating point value |
Each section is preceded by a tag structure with the following format:
Element |
Type |
Description |
Id |
long |
The type of data in the following section. See the next table for a list of valid values. |
Size |
long |
The number of bytes in the section (not including this tag). Skipping this many bytes after reading the tag will align the file pointer on the next tag. |
Tag Id values. The 0x prefix indicates a hexadecimal value:
Id |
Description |
0x42525344 |
Header section – must be the first section within the file. |
0x44495247 |
Grid section – describes a 2D matrix of Z values. |
0x41544144 |
Data section – contains a variable amount of data. The size of the data section is given by the Size field in the tag structure. |
0x49544c46 |
Fault Info section – describes the fault traces used when creating the grid. |
The Header section must be the first section in the file and has the following format:
Element |
Type |
Description |
Version |
long |
Version number of the file format. Currently must be set to 1. |
The Grid section consists of a header that describes a 2D matrix of values, followed by the matrix itself. This section encapsulates all of the data that was traditionally referred to as a grid:
Element |
Type |
Description |
nRow |
long |
number of rows in the grid |
nCol |
long |
number of columns in the grid |
xLL |
double |
X coordinate of the lower left corner of the grid |
yLL |
double |
Y coordinate of the lower left corner of the grid |
xSize |
double |
spacing between adjacent nodes in the X direction (between columns) |
ySize |
double |
spacing between adjacent nodes in the Y direction (between rows) |
zMin |
double |
minimum Z value within the grid |
zMax |
double |
maximum Z value within the grid |
Rotation |
double |
not currently used |
BlankValue |
double |
nodes are blanked if greater or equal to this value |
A Data section containing the 2D matrix of values (doubles) must immediately follow a Grid section. Within the Data section, the grid is stored in row-major order, with the lowest row (minimum Y) first
A Fault Info section describes the fault geometry used to create the grid. Fault Info sections have the following format:
Element |
Type |
Description |
nTraces |
long |
number of fault traces (polylines) |
nVertices |
long |
total number of vertices in all the traces |
data section |
|
variable-sized data block consisting of an array of Trace structures immediately followed by the array of vertices |
A Data section containing an array of Trace structures and an array of Vertex structures must immediately follow a Fault Info section. The number of Trace structures in the array is nTraces , and the number of Vertex structures is nVertices .
Trace structure:
Element |
Type |
Description |
iFirst |
long |
0-based index into the vertex array for the first vertex of this trace |
nPts |
long |
number of vertices in this trace |
Vertex structure:
Element |
Type |
Description |
x |
double |
X coordinate of the vertex |
y |
double |
Y coordinate of the vertex |
Example
The following example illustrates the layout for a 5 row by 10 column grid (byte position is base 1):
Element |
Byte Pos. |
Type |
Description |
0x42525344 |
1 |
long |
Tag: Id for Header section |
4 |
5 |
long |
Tag: Size of Header section |
1 |
9 |
long |
Header Section: Version |
0x44495247 |
13 |
long |
Tag: ID indicating a grid section |
72 |
17 |
long |
Tag: Length in bytes of the grid section |
5 |
21 |
long |
Grid Section: nRow |
10 |
25 |
long |
Grid Section: nCol |
0.0 |
29 |
double |
Grid Section: xLL |
0.0 |
37 |
double |
Grid Section: yLL |
1.0 |
45 |
double |
Grid Section: xSize |
1.75 |
53 |
double |
Grid Section: ySize |
25.0 |
61 |
double |
Grid Section: zMin |
101.6 |
69 |
double |
Grid Section: zMax |
0.0 |
77 |
double |
Grid Section: Rotation |
1.70141e38 |
85 |
double |
Grid Section: BlankValue |
0x41544144 |
93 |
long |
Tag: ID indicating a data section |
400 |
97 |
long |
Tag: Length in bytes of the data section (5 rows x 10 columns x 8 bytes per double) |
Z1, Z2, … |
101,109... (step 8 bytes to end of file)...
|
double |
Grid data. First value is the lower left node, and the subsequent nodes procede across the row until the end, then up to the second row, etc., until finishing at the upper right node. |
Sample Code
Use the example table to determine what data type you should use for each header value. For example, if you want to get the xMin value of the grid in Scripter, you would insert the following code:
Dim xMin As Double
Open [your filename] For Binary As #1
Get #1,29,xMin
Close #1
Or, if you wanted to load all of the data into an array, you would use this:
Dim xCols As Long
Dim yRows As Long
Dim myData() As Double
Open [your filename] For Binary As #1
Get #1,5,yRows
Get #1,10,xCols
ReDim myData((xCols * yRows) -1)
Get #1,101,myData
Close #1