Code covered by the BSD License  

Highlights from
grdread2

4.0
4.0 | 2 ratings Rate this file 63 Downloads (last 30 days) File Size: 2.69 KB File ID: #25683 Version: 1.2

grdread2

by

Kelsey Jordahl (view profile)

 

29 Oct 2009 (Updated )

Uses built-in netCDF capability to load a grid file created by GMT (Generic Mapping Tools) v3 or v4

| Watch this File

File Information
Description

Z=GRDREAD2('filename.grd') will return the data as a matrix in Z
 
[X,Y,Z]=GRDREAD2('filename.grd') will also return X and Y vectors suitable for use in Matlab commands such as IMAGE or CONTOUR.
  e.g., imagesc(X,Y,Z); axis xy
 
This function will load COARDS compliant netCDF grdfiles, the standard format in GMT 4 and later, as well as GMT v3 netCDF formats. The data matrix Z will have a MATLAB data type appropriate to the data type used in the netCDF file. Although both gridline and pixel registered grids can be read, pixel registration will be converted to gridline registration for the x- and y-vectors in MATLAB.

This program currently does little error checking and makes some assumptions about the content and structure of netCDF files that may not always be valid (especially in grids created in other software, even if they can be read by GMT). It has been tested on grid files created in a number of GMT versions since 3.1, using MATLAB R2009b in OS X, Linux and Windows, and in R2008b in OS X. It will not work with any binary grid file formats. It is the responsibility of the user to determine whether this program is appropriate for any given task.
 
For more information on GMT grid file formats, see:
http://www.soest.hawaii.edu/gmt/gmt/doc/gmt/html/GMT_Docs/node70.html

GMT (Generic Mapping Tools) was developed by Paul Wessel and Walter H. F. Smith
(http://gmt.soest.hawaii.edu)

See also GRDWRITE2, GRDINFO2

Acknowledgements

This file inspired Grdinfo2 and Grdwrite2.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
30 Jan 2013 François Beauducel

Works perfectly with a huge .grd DEM. Thanks very much for this effort.

31 Mar 2012 Kelsey Jordahl

Kelsey Jordahl (view profile)

David,

Could you provide more details about how it is not working? I can confirm that it still works for me on OS X 10.7.3 (Lion) and R2012a, with files created by GMT 4.5.7-1 in multiple grid formats.

grdinfo output for the .grd file and MATLAB error message would be helpful.

Comment only
27 Mar 2012 David

David (view profile)

Not working on R2011a under OS X Snow Leopard (maci64). GRD files created by GMT 4.5.7-1.

I tried replacing netcdf in your routine by ncdisp, ncread, etc. embebed on R2011a and still no success.

What a pitty! Therefore I had to use grd2xyz GMT function to read XYZ in Matlab.

Cheers.

01 Dec 2009 Kelsey Jordahl

Kelsey Jordahl (view profile)

It works for me on R2009b, at least on Mac OS X (maci64). It doesn't seem to work any differently from R2008b for me, but I haven't tried it yet on other platforms.

Are you sure that you have a COARDS-compliant NetCDF grid generated by GMT version 4 or later? It will not work with grids generated by earlier versions of GMT, even though v3 was also NetCDF based, but it was not COARDS. I am working on an updated version of grdread2.m that will read these grids. Also, it will not necessarily work on more general COARDS-compliant NetCDF files generated by other programs, even though GMT may be able to read them.

Comment only
01 Dec 2009 Paul

Paul (view profile)

doesn't work on R2009b

Comment only
Updates
03 Dec 2009 1.1

now supports all GMT netCDF grids, including those created by GMT v3.x.

06 Jan 2010 1.2

Minor documentation changes to indicate the related files grdwrite2 and grdinfo2.

Contact us