-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgrd_read_v2.m
33 lines (28 loc) · 1 KB
/
grd_read_v2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function [matrix xmin xmax ymin ymax]=grd_read_v2(namefile)
% Function to read a GRD file
% (from Golden Software Surfer, ASCII format)
%
% [matrix xmin xmax ymin ymax]=grd_read_v2(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
%
% Coded by Alberto Avila Armella.
% UPDATED & IMPROVED BY Jose Maria Garcia-Valdecasas
grdfile=fopen(namefile,'r'); % Open file
code=fgetl(grdfile); % Reads surfer code 'DSAA'
% Grid dimensions (number of nodes)
aux=str2num(fgetl(grdfile)); nx=aux(1); ny=aux(2);
% X limits
aux=str2num(fgetl(grdfile)); xmin=aux(1); xmax=aux(2);
% Y limits
aux=str2num(fgetl(grdfile)); ymin=aux(1); ymax=aux(2);
% Z limits
aux=str2num(fgetl(grdfile)); zmin=aux(1); aux(2);
% Read matrix
[matrix,count] = fscanf(grdfile, '%f', [nx,ny]);
matrix=matrix'; % Trasposes matrix
fclose(grdfile);