1 | function 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 |
|
---|
12 | if nargin < 4
|
---|
13 | ncdata = '/totten_1/ModelData/Greenland/DHDTKhan/dH_monthly_1km.nc';
|
---|
14 | end
|
---|
15 |
|
---|
16 | x = ncread(ncdata, 'x');
|
---|
17 | y = ncread(ncdata, 'y');
|
---|
18 | t = ncread(ncdata, 'time');
|
---|
19 |
|
---|
20 | offset=2;
|
---|
21 |
|
---|
22 | % get x-index covers the domain
|
---|
23 | xmin=min(X(:)); xmax=max(X(:));
|
---|
24 | idx = sort(find((x>=xmin) & (x<=xmax)));
|
---|
25 | idx_min = max(idx(1)-offset, 1);
|
---|
26 | idx_max = min(idx(end)+offset, length(x));
|
---|
27 | x = x(idx_min:idx_max);
|
---|
28 |
|
---|
29 | % get y-index covers the domain
|
---|
30 | ymin=min(Y(:)); ymax=max(Y(:));
|
---|
31 | idy = sort(find((y>=ymin) & (y<=ymax)));
|
---|
32 | idy_min = max(idy(1)-offset, 1);
|
---|
33 | idy_max = min(idy(end)+offset, length(y));
|
---|
34 | y = y(idy_min:idy_max);
|
---|
35 |
|
---|
36 | % get time index
|
---|
37 | idt_min = max([find(t<=time(1), 1, 'last'), 1]);
|
---|
38 | idt_max = min([find(t>=time(end), 1, 'first'), length(t)]);
|
---|
39 | t = t(idt_min:idt_max);
|
---|
40 |
|
---|
41 | % load dH
|
---|
42 | data = 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
|
---|
45 | dH = zeros(numel(X)+1, numel(t));
|
---|
46 | dH(end,:) = t;
|
---|
47 | for i = 1:numel(t)
|
---|
48 | dH(1:end-1, i) = InterpFromGrid(x, y, data(:,:,i)', X, Y,'nearest');
|
---|
49 | end
|
---|