forked from bishtgautam/matlab-script-for-clm-sparse-grid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComputeLatLonAtVertex.m
29 lines (25 loc) · 947 Bytes
/
ComputeLatLonAtVertex.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
% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
% Computes latitude/longitude at vertices of grid cells.
% Only supports quadrilateral grid cells.
%
% INPUT:
% lon = Vector containing longitude @ cell-center.
% lat = Vector containing latitude @ cell-center.
% dlat = Latitudinal grid spacing
% dlon = Longitudinal grid spacing
%
% OUTPUT:
% latv = Vector containing latitude @ cell-vertex.
% lonv = Vector containing longitude @ cell-vertex.
%
% Gautam Bisht ([email protected])
% 05-28-2015
% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function [latv,lonv] = ComputeLatLonAtVertex(lat, lon, dlat, dlon)
npts = length(lat);
latv = zeros(npts,4);
lonv = zeros(npts,4);
for ii = 1:npts
lonv(ii,:) = [lon(ii)-dlon/2 lon(ii)+dlon/2 lon(ii)+dlon/2 lon(ii)-dlon/2];
latv(ii,:) = [lat(ii)-dlat/2 lat(ii)-dlat/2 lat(ii)+dlat/2 lat(ii)+dlat/2];
end