source: issm/trunk-jpl/src/m/contrib/chenggong/modeldata/interpdH.m@ 28163

Last change on this file since 28163 was 28163, checked in by Cheng Gong, 13 months ago

ADD: interpolate dHdt map of Greenland

File size: 1.5 KB
Line 
1function dH = interpdH(X, Y, time, ncdata)
2%INTERPDH - interpolate monthly reconstructed dH onto X and Y, within the given time period
3%
4% Usage:
5% dH = interpdH(md.mesh.x, md.mesh.y, [md.timestepping.start_time, md.timestepping.final_time]);
6%
7% - X, Y: coordinates of the mesh or grid
8% - time: the starting and end point of the time series
9% - optional 4th input argument: path to the data file, by default it is the path on totten
10%
11
12if nargin < 4
13 ncdata = '/totten_1/ModelData/Greenland/DHDTKhan/dH_monthly_1km.nc';
14end
15
16x = ncread(ncdata, 'x');
17y = ncread(ncdata, 'y');
18t = ncread(ncdata, 'time');
19
20offset=2;
21
22% get x-index covers the domain
23xmin=min(X(:)); xmax=max(X(:));
24idx = sort(find((x>=xmin) & (x<=xmax)));
25idx_min = max(idx(1)-offset, 1);
26idx_max = min(idx(end)+offset, length(x));
27x = x(idx_min:idx_max);
28
29% get y-index covers the domain
30ymin=min(Y(:)); ymax=max(Y(:));
31idy = sort(find((y>=ymin) & (y<=ymax)));
32idy_min = max(idy(1)-offset, 1);
33idy_max = min(idy(end)+offset, length(y));
34y = y(idy_min:idy_max);
35
36% get time index
37idt_min = max([find(t<=time(1), 1, 'last'), 1]);
38idt_max = min([find(t>=time(end), 1, 'first'), length(t)]);
39t = t(idt_min:idt_max);
40
41% load dH
42data = ncread(ncdata, 'dH', [idx_min, idy_min, idt_min], [idx_max-idx_min+1, idy_max-idy_min+1, idt_max-idt_min+1], [1,1,1]);
43
44% Convert to ice_levelset values
45dH = zeros(numel(X)+1, numel(t));
46dH(end,:) = t;
47for i = 1:numel(t)
48 dH(1:end-1, i) = InterpFromGrid(x, y, data(:,:,i)', X, Y,'nearest');
49end
Note: See TracBrowser for help on using the repository browser.