Home > mapstuff > read_gmt.m

read_gmt

PURPOSE ^

READ_GMT reads GMT grid file into Matlab arrays x,y,z

SYNOPSIS ^

function [x,y,z]=read_gmt(grdfile)

DESCRIPTION ^

 READ_GMT reads GMT grid file into Matlab arrays x,y,z
   Usage: [x,y,z]=read_gmt(grdfile);
    where 
          x = east coordinate vector (eg. longitude)
          y = north coordinate vector (eg. latitude)
          z = matrix of gridded values (eg. bathy grid)

   Example:
           [x,y,z]=read_gmt('foo.grd');
           contour(x,y,z)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x,y,z]=read_gmt(grdfile)
0002 % READ_GMT reads GMT grid file into Matlab arrays x,y,z
0003 %   Usage: [x,y,z]=read_gmt(grdfile);
0004 %    where
0005 %          x = east coordinate vector (eg. longitude)
0006 %          y = north coordinate vector (eg. latitude)
0007 %          z = matrix of gridded values (eg. bathy grid)
0008 %
0009 %   Example:
0010 %           [x,y,z]=read_gmt('foo.grd');
0011 %           contour(x,y,z)
0012 
0013 % Rich Signell
0014 % rsignell@usgs.gov
0015   
0016 cdfid=mexcdf('open',grdfile,'nowrite');
0017 oldopts=mexcdf('setopts',0);
0018 x_range=mexcdf('varget',cdfid,'x_range',0,2);
0019 y_range=mexcdf('varget',cdfid,'y_range',0,2);
0020 spacing=mexcdf('varget',cdfid,'spacing',0,2);
0021 dims=mexcdf('varget',cdfid,'dimension',0,2);
0022 nx=dims(1);
0023 ny=dims(2);
0024 xysize=nx*ny;
0025 z=mexcdf('varget',cdfid,'z',0,xysize);
0026 mexcdf('close',cdfid);
0027 z=reshape(z,nx,ny);
0028 z=flipud(z.');
0029 x=x_range(1)+[0:(nx-1)]*spacing(1);
0030 y=y_range(1)+[0:(ny-1)]*spacing(2);
0031

Generated on Wed 30-Nov-2005 15:38:18 by m2html © 2003