No BSD License  

Highlights from
Surfer Grid import/export

5.0

5.0 | 4 ratings Rate this file 44 Downloads (last 30 days) File Size: 1.18 KB File ID: #20880

Surfer Grid import/export

by Alberto Avila Armella

 

28 Jul 2008 (Updated 13 Apr 2009)

Import and export GS ASCII (GRD files) from and to Golden Software Applications like Surfer and Grap

| Watch this File

File Information
Description

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

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
19 Sep 2008 Sarah Reed

Hi, this may be just be due to my beginner's level in Matlab, but I keep getting the "Undefined function or variable" error for the surfer grid I want to import. I called the function with the name of the Surfer grid ascii file, with and without the extension. The grid file is in the current directory with the function. Do I need to do something to set the path? Thanks for any thoughts you could offer.

03 Apr 2009 Frederic DONDIN

Very helpfull

23 Apr 2009 Gabriel Ruiz

Cool, man!!! I just tested this new version of grd_read and... it's very nice!!! The improvement really works.

10 Feb 2011 Mel

Following Sarah Reed's post.
Make sure that you create a string file called "namefile" to run the grd_read_v2 function.
This may be done using "strcat" if the file name contains numbers and letters. e.g.
namefile=strcat('dem',num2str(1999),'.grd');
then run the function
>> [matrix xmin xmax ymin ymax]=grd_read_v2(namefile);

Hope this helps anyone in the future who uses this code (I encountered the same error as Sarah initially too).

09 Aug 2011 Josh

Awesome! Now that you can create the .grd file from Matlab, it would be great if you could also use Matlab to open surfer, using something like:

!C:\Program Files (x86)\Golden Software\Surfer 9\surfer.exe

(though hopefully more elegant) and then load the file as well. I am creating a Matlab GUI, and would love to be able to invoke and graph matlab data through Surfer.

16 Sep 2011 XIAOMING  
Please login to add a comment or rating.
Updates
13 Apr 2009

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.

Tag Activity for this File
Tag Applied By Date/Time
data import Alberto Avila Armella 22 Oct 2008 10:12:08
data export Alberto Avila Armella 22 Oct 2008 10:12:08
golden software Alberto Avila Armella 22 Oct 2008 10:12:08
surfer Alberto Avila Armella 22 Oct 2008 10:12:09
grid Alberto Avila Armella 22 Oct 2008 10:12:09
grapher Alberto Avila Armella 22 Oct 2008 10:12:09
import Alberto Avila Armella 22 Oct 2008 10:12:09
export Alberto Avila Armella 22 Oct 2008 10:12:09

Contact us at files@mathworks.com