Accessing directly grid values

Post in this forum all topics related to all sesarray softwares, not a particular one.
Site Admin
Posts: 424
Joined: Mon Aug 13, 2007 11:48 am
Location: ISTerre

Accessing directly grid values

Postby admin » Fri Jan 30, 2009 8:49 am

Currently there is no direct way to export these values. This article present a workaround that requires some programming skills.

First save the grid into a file (context menu 'Save as a page').

Code: Select all

tar xvfpz

It creates two files: 'contents.xml' and 'bin_data_1000'

The format of 'bin_data_1000' is given in the following table. Sizes and offsets are given in hexadecimal.

Code: Select all

Size     Type      Comments
----     ----      --------
22       string    Tag "IrregularGrid2D" in UTF-16
                   first 4 bytes contains the size of the tag (30 bytes in this case)
4        int       Number of cells along X axis (nx)
4        int       Number of cells along Y axis (ny)
nx*8     double    X coordinates of cell centers
nx*8     double    Y coordinates of cell centers
nx*ny*8  double    Grid values, v[ix][iy] is found at index ix+nx*iy

This example reads file 'bin_data_1000' and print grid trough stdout:

Code: Select all

#include <QTextStream>
#include <QFile>
#include <QDataStream>

int main()
  QFile f("bin_data_1000");
  if (! return 2;
  QDataStream sb(&f);
  QString tag;
  int nx, ny;
  sb >> tag >> nx >> ny;
  double x[nx], y[ny], val[nx*ny];
  sb.readRawData((char *)x, sizeof( double )* nx );
  sb.readRawData((char *)y, sizeof( double )* ny );
  sb.readRawData((char *)val, sizeof( double )* nx * ny );
  QTextStream st(stdout);
  st << "x y z" << endl;
  double * valPtr = val;
  for ( int iy = 0;iy < ny;iy++ ) {
    for ( int ix = 0;ix < nx;ix++ )
      st << x[ix] << " " << y[iy] << " " << *(valPtr++) << endl;
  return 0;

Create a directory (e.g. 'readgrid'). Insert this code in a file 'readgrid/main.cpp'. To compile it:

Code: Select all

cd readgrid
qmake -project

Return to “General usage”

Who is online

Users browsing this forum: No registered users and 1 guest