Changeset 25631


Ignore:
Timestamp:
10/06/20 08:49:23 (4 years ago)
Author:
Mathieu Morlighem
Message:

CHG: fixed conflict with interpBedmap2

Location:
issm/trunk-jpl/src/m/contrib
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/contrib/morlighem/modeldata/interpBedmap2.m

    r23875 r25631  
    1919
    2020nc = '/home/ModelData/Antarctica/BedMap2/bedmap2_bin/Bedmap2.nc';
     21if exist(nc,'file')
     22        if strcmp(string,'thickness_uncertainty_5km')
     23                xdata = double(ncread(nc,'x_5km'));
     24                ydata = double(ncread(nc,'y_5km'));
     25        else
     26                xdata = double(ncread(nc,'x'));
     27                ydata = double(ncread(nc,'y'));
     28        end
    2129
    22 if strcmp(string,'thickness_uncertainty_5km')
    23         xdata = double(ncread(nc,'x_5km'));
    24         ydata = double(ncread(nc,'y_5km'));
     30        offset=2;
     31
     32        xmin=min(X(:)); xmax=max(X(:));
     33        posx=find(xdata<=xmax);
     34        id1x=max(1,find(xdata>=xmin,1)-offset);
     35        id2x=min(numel(xdata),posx(end)+offset);
     36
     37        ymin=min(Y(:)); ymax=max(Y(:));
     38        posy=find(ydata>=ymin);
     39        id1y=max(1,find(ydata<=ymax,1)-offset);
     40        id2y=min(numel(ydata),posy(end)+offset);
     41
     42        data  = double(ncread(nc,string,[id1x id1y],[id2x-id1x+1 id2y-id1y+1],[1 1]))';
     43        xdata=xdata(id1x:id2x);
     44        ydata=ydata(id1y:id2y);
     45
     46        if ~strcmp(string,'coverage'),
     47                data(find(data==-9999))=NaN;
     48        end
     49
     50        if strcmpi(string,'icemask_grounded_and_shelves') | strcmpi(string,'rockmask'),
     51                output = InterpFromGrid(xdata,ydata,data,double(X),double(Y),'nearest');
     52        else
     53                output = InterpFromGrid(xdata,ydata,data,double(X),double(Y)); % linear interpolation is default
     54        end
     55        return;
     56
     57%For Eric's computer (using Binary files)
     58elseif exist('/Users/larour/ModelData/BedMap2/bedmap2_bin/','dir')
     59        % ================================  OLD ===============================================
     60        path='/Users/larour/ModelData/BedMap2/bedmap2_bin/'
     61        if strcmp(string,'gl04c_geoid_to_wgs84'),
     62                filepath = [path '/gl04c_geiod_to_wgs84.flt'];
     63        else
     64                filepath = [path '/bedmap2_' string '.flt'];
     65        end
     66        fid=fopen(filepath,'r','l');
     67        data=fread(fid,[6667,6667],'float32');
     68        fclose(fid);
     69
     70        % define grid
     71        if strcmp(string,'thickness_uncertainty_5km'),
     72                ncols    =1361;
     73                nrows    =1361;
     74                xll      =-3401000;
     75                yll      =-3402000;
     76                gridsize =5000;
     77        else
     78                ncols    =6667;
     79                nrows    =6667;
     80                xll      =-3333000;
     81                yll      =-3333000;
     82                gridsize =1000;
     83        end
     84        x_m=xll+(0:1:ncols-1)'*gridsize;
     85        y_m=yll+(0:1:nrows-1)'*gridsize;
     86
     87        %Change default to NaN
     88        if ~strcmp(string,'coverage'),
     89                data(find(data==-9999))=NaN;
     90        end
     91
     92        %rotate 90 degrees clockwise
     93        data = rot90(data);
     94
     95        %Interpolate
     96        if strcmpi(string,'icemask_grounded_and_shelves') | strcmpi(string,'rockmask'),
     97                dataout = InterpFromGrid(x_m,y_m,data,double(X),double(Y),'nearest');
     98        else
     99                dataout = InterpFromGrid(x_m,y_m,data,double(X),double(Y));
     100        end
    25101else
    26         xdata = double(ncread(nc,'x'));
    27         ydata = double(ncread(nc,'y'));
     102        error('not supported');
    28103end
    29 
    30 offset=2;
    31 
    32 xmin=min(X(:)); xmax=max(X(:));
    33 posx=find(xdata<=xmax);
    34 id1x=max(1,find(xdata>=xmin,1)-offset);
    35 id2x=min(numel(xdata),posx(end)+offset);
    36 
    37 ymin=min(Y(:)); ymax=max(Y(:));
    38 posy=find(ydata>=ymin);
    39 id1y=max(1,find(ydata<=ymax,1)-offset);
    40 id2y=min(numel(ydata),posy(end)+offset);
    41 
    42 data  = double(ncread(nc,string,[id1x id1y],[id2x-id1x+1 id2y-id1y+1],[1 1]))';
    43 xdata=xdata(id1x:id2x);
    44 ydata=ydata(id1y:id2y);
    45 
    46 if ~strcmp(string,'coverage'),
    47         data(find(data==-9999))=NaN;
    48 end
    49 
    50 if strcmpi(string,'icemask_grounded_and_shelves') | strcmpi(string,'rockmask'),
    51         output = InterpFromGrid(xdata,ydata,data,double(X),double(Y),'nearest');
    52 else
    53         output = InterpFromGrid(xdata,ydata,data,double(X),double(Y)); % linear interpolation is default
    54 end
    55 
    56 return;
    57 % ================================  OLD ===============================================
    58 %read data
    59 path=['/home/ModelData/Antarctica/BedMap2/bedmap2_bin/'];
    60 if strcmp(string,'gl04c_geoid_to_wgs84'),
    61         filepath = [path '/gl04c_geiod_to_wgs84.flt'];
    62 else
    63         filepath = [path '/bedmap2_' string '.flt'];
    64 end
    65 fid=fopen(filepath,'r','l');
    66 data=fread(fid,[6667,6667],'float32');
    67 fclose(fid);
    68 
    69 % define grid
    70 if strcmp(string,'thickness_uncertainty_5km'),
    71         ncols    =1361;
    72         nrows    =1361;
    73         xll      =-3401000;
    74         yll      =-3402000;
    75         gridsize =5000;
    76 else
    77         ncols    =6667;
    78         nrows    =6667;
    79         xll      =-3333000;
    80         yll      =-3333000;
    81         gridsize =1000;
    82 end
    83 x_m=xll+(0:1:ncols-1)'*gridsize;
    84 y_m=yll+(0:1:nrows-1)'*gridsize;
    85 
    86 %Change default to NaN
    87 if ~strcmp(string,'coverage'),
    88         data(find(data==-9999))=NaN;
    89 end
    90 
    91 %rotate 90 degrees clockwise
    92 data = rot90(data);
    93 
    94 %Interpolate
    95 if strcmpi(string,'icemask_grounded_and_shelves') | strcmpi(string,'rockmask'),
    96         dataout = InterpFromGrid(x_m,y_m,data,double(X),double(Y),'nearest');
    97 else
    98         dataout = InterpFromGrid(x_m,y_m,data,double(X),double(Y));
    99 end
Note: See TracChangeset for help on using the changeset viewer.