Format of Gwyddion Files

Gwyddion native data files consists of a tree-like structure of serialized objects. Generally, these objects can be of various kind and contain other embedded objects (hence the tree-like structure). It can be instructive to play with gwydump, a simple file structure visualizer available in on the project's web, for a while and examine the contents of various files.

First of all, we will describe physical file structure without regard to possible interpretation of contained data.

Byte Order

All data is stored in little-endian (also known as LSB or Intel) byte order.

File Header

The file header consists of four bytes (magic number) with the values of ASCII characters GWYP.

This is the new file format, an older version of file format with magic header GWYO also exists. It will not be discussed here.

File Data

The rest of the file consists of a serialized GwyContainer object that contains all the data. It is stored exactly the same way as any other object, that is as described in the next section.

Object Layout

An object consists of three parts (in the following order):

  • Type name, stored as a NUL-terminated string of ASCII characters. This is the type name in GObject type system.
  • Serialized data size, stored as an unsigned 32bit integer. It does not include the size of the type name and the size of self.
  • Component list. Components are named parts of object data, each of particular data type: an atomic type, an array of atomic types, or again an object. They are stored in no particular order.

Components

Each component consits of three parts (in the following order):

  • Name, stored as a NUL-terminated string.
  • Type, stored as a signle unsigned byte (character). The table of possible component types is presented below.
  • Data, stored as whatever is appropriate for a particular type.

Data Types

Available atomic data types are listed in following table:

TypeCharacterNote
booleanb Stored as a byte, zero is false, nonzero (normally 1) is true
characterc 
32bit integeri 
64bit integerq 
doubled IEEE 754 double precession floating point number
strings NUL-terminated
objecto Serialized object as described above

Each atomic type except boolean has its array counterpart. The type character of array types is the same as of the corresponding atomic type, except it is uppercase. Arrays are stored as unsigned 32bit array length (the number of items), followed by the item values. Array data types are listed in following table:

TypeCharacterNote
array of charactersC Not NUL-terminated
array of 32bit integersI 
array of 64bit integersQ 
array of doublesD 
array of stringsS 
array of objectsOUppercase Oh, not zero

Particular Objects

To be written.