Surfer Grid import/export

Import and export GS ASCII (GRD files) from and to Golden Software Applications like Surfer and Grap
5.3K Downloads
Updated 13 Apr 2009

No License

Surfer Grid, import/export.

Matlab <-> Golden Software Surfer and Grapher

The pack contains two simple routines: grd_write.m and grd_read.m. They communicate Matlab with Golden Software Surfer by the GRD file format (ASCII version).

grd_write(matrix,xmin,xmax,ymin,ymax,namefile)
Input:
matrix = matrix to export
xmin,xmax,ymin,ymax = grid limits
namefile = name of the file to be written (include ".grd" extension)
Output:
grd file in current directory

[matrix xmin xmax ymin ymax]=grd_read(name of file)
Input:
nomarch = name of the file to be read, including ".grd" extension
Output:
matrix = matrix of the read data
xmin xmax ymin ymax = grid limits

* NOTE: Previous version of grd_read worked only with files saved in Surfer (or Grapher), but now is SOLVED. It runs faster also.

Example of use:

Creation of a matrix in Matlab:

x=linspace(-4,4,100);
y=linspace(-5,5,100);
[X,Y]=meshgrid(x,y);
Z=cos(sqrt(X.^2+Y.^2));

Export to surfer:

grd_write(Z,min(x),max(x),min(y),max(y),'example.grd')

Open in surfer and save as:

Open example.grd in Surfer (as a grid: file-> open). Then save it, for example with the name example_saved_by_surfer.grd. Remember to chose “GS ASCII (*.grd)”.

Load the saved file in Matlab

[matrix xmin xmax ymin ymax]=grd_read('example_saved_by_surfer.grd');

---Coded by Alberto Avila Armella, updated and improved by Jose Maria Garcia-Valdecasas

Cite As

Alberto Avila Armella (2024). Surfer Grid import/export (https://www.mathworks.com/matlabcentral/fileexchange/20880-surfer-grid-import-export), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: xyz2grd

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

Previous version of grd_read worked only with files saved in Surfer (or Grapher), but now is SOLVED (by Jose Maria Garcia-Valdecasas). It runs faster also.

1.0.0.0