forked from bishtgautam/matlab-script-for-clm-sparse-grid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReadLatLon.m
37 lines (26 loc) · 739 Bytes
/
ReadLatLon.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
34
35
36
37
% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
% Read latitude/longitude for site
% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function [lat,lon] = ReadLatLon(fname)
tmp_str = strsplit(fname,'.');
switch tmp_str{end}
case 'txt'
[lat,lon] = ReadLatLonFromTxt(fname);
otherwise
error('Unsupported format to read site level lat/lon');
end
end
function [lat,lon] = ReadLatLonFromTxt(fname)
fid = fopen(fname,'r');
if (fid == -1)
error(['Unable to open file: ' fname])
end
npts = fscanf(fid,'%d',1);
lon = zeros(npts,1);
lat = zeros(npts,1);
for ii = 1:npts
lat(ii,1) = fscanf(fid,'%f',1);
lon(ii,1) = fscanf(fid,'%f',1);
end
fclose(fid);
end