| 1 | function [output] = interpRTopo2(X,Y,varargin),
|
|---|
| 2 | %INTERPRTOPO2 - interp from RTOPO-2 onto X and Y
|
|---|
| 3 | %
|
|---|
| 4 | % Usage:
|
|---|
| 5 | % bed = interpRTopo2(X,Y,varargin),
|
|---|
| 6 | %
|
|---|
| 7 | % varargin = 1 (Greenland), default
|
|---|
| 8 | % -1 (Antarctica)
|
|---|
| 9 |
|
|---|
| 10 | switch oshostname(),
|
|---|
| 11 | case {'ronne'}
|
|---|
| 12 | rootname='/home/ModelData/Global/RTopo-2/RTopo-2.0.1_30sec_bedrock_topography.nc';
|
|---|
| 13 | otherwise
|
|---|
| 14 | error('machine not supported yet');
|
|---|
| 15 | end
|
|---|
| 16 | verbose = 1;
|
|---|
| 17 |
|
|---|
| 18 | if nargin==3,
|
|---|
| 19 | hemisphere = varargin{1};
|
|---|
| 20 | else
|
|---|
| 21 | hemisphere = +1;
|
|---|
| 22 | end
|
|---|
| 23 | if abs(hemisphere)~=1,
|
|---|
| 24 | error('hemisphere should be +/-1');
|
|---|
| 25 | end
|
|---|
| 26 |
|
|---|
| 27 | if hemisphere==+1,
|
|---|
| 28 | if verbose, disp(' -- RTopo-2: convert to lat/lon using Greenland projection'); end
|
|---|
| 29 | [LAT, LON ] = xy2ll(double(X(:)),double(Y(:)),+1,45,70);
|
|---|
| 30 | else
|
|---|
| 31 | if verbose, disp(' -- RTopo-2: convert to lat/lon using Antarctica projection'); end
|
|---|
| 32 | [LAT, LON ] = xy2ll(double(X(:)),double(Y(:)),-1,0,71);
|
|---|
| 33 | end
|
|---|
| 34 |
|
|---|
| 35 | Y=reshape(LAT,size(X)); X=reshape(LON,size(X));
|
|---|
| 36 |
|
|---|
| 37 | xdata = double(ncread(rootname,'lon'));
|
|---|
| 38 | ydata = double(ncread(rootname,'lat'));
|
|---|
| 39 |
|
|---|
| 40 | offset=2;
|
|---|
| 41 |
|
|---|
| 42 | xmin=min(X(:)); xmax=max(X(:));
|
|---|
| 43 | posx=find(xdata<=xmax);
|
|---|
| 44 | id1x=max(1,find(xdata>=xmin,1)-offset);
|
|---|
| 45 | id2x=min(numel(xdata),posx(end)+offset);
|
|---|
| 46 |
|
|---|
| 47 | ymin=min(Y(:)); ymax=max(Y(:));
|
|---|
| 48 | posy=find(ydata<=ymax);
|
|---|
| 49 | id1y=max(1,find(ydata>=ymin,1)-offset);
|
|---|
| 50 | id2y=min(numel(ydata),posy(end)+offset);
|
|---|
| 51 |
|
|---|
| 52 | if verbose, disp(' -- RTopo-2: reading bed topography'); end
|
|---|
| 53 | data = double(ncread(rootname,'bedrock_topography',[id1x id1y],[id2x-id1x+1 id2y-id1y+1],[1 1]))';
|
|---|
| 54 | xdata=xdata(id1x:id2x);
|
|---|
| 55 | ydata=ydata(id1y:id2y);
|
|---|
| 56 | data(find(data==-9999))=NaN;
|
|---|
| 57 |
|
|---|
| 58 | if verbose, disp(' -- RTopo-2: interpolating'); end
|
|---|
| 59 | output = InterpFromGrid(xdata,ydata,data,double(X),double(Y));
|
|---|