Home > custom > grid_tools > par_resample_grid.m

par_resample_grid

PURPOSE ^

% Preallocate memory for large arrays

SYNOPSIS ^

function par_resample_grid(sourcename,targetname,asciiout)

DESCRIPTION ^

% Preallocate memory for large arrays
 % note: this backfires when the allocated memory is not big enough!
 disp('Preallocatinng memory for input DEMs')
 [rows, cols]=get_gridsize([sourcename]);
 srtm=zeros(cols, rows);
 [rows, cols]=get_gridsize([targetname]);
 globe=zeros(cols,rows);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function par_resample_grid(sourcename,targetname,asciiout)
0002 
0003 
0004 %% Preallocate memory for large arrays
0005 % % note: this backfires when the allocated memory is not big enough!
0006 % disp('Preallocatinng memory for input DEMs')
0007 % [rows, cols]=get_gridsize([sourcename]);
0008 % srtm=zeros(cols, rows);
0009 % [rows, cols]=get_gridsize([targetname]);
0010 % globe=zeros(cols,rows);
0011 
0012 
0013 %% read in source
0014 disp('Reading in Source')
0015 [sxcoords,sycoords,srtm,sheader]=asciigrid2mat([sourcename]);
0016 disp('Done...')
0017 %% read in globe
0018 disp('Reading in Target')
0019 [gxcoords,gycoords,globe,gheader]=asciigrid2mat([targetname]);
0020 disp('Done...')
0021 
0022 
0023 %% resample srtm to globe
0024 
0025 disp('Resampling Source to Target resolution using mean of cells and snapping to Target grid.')
0026 newsrtm=zeros(size(gycoords,2),size(gxcoords,2));
0027 for rows = 1:size(globe,1);
0028     for cols = 1:size(globe,2);
0029         newsrtm(rows,cols) = resample_mean(sheader.cellsize,gheader.cellsize, gxcoords(cols), gycoords(rows),min(sxcoords),min(sycoords), srtm);
0030     end;
0031 end; 
0032 disp('Done...')
0033 clear srtm;
0034 
0035 %% crop
0036 % determine larger raster and crop NaNs
0037 % Note: if GLOBE originally had a larger extent then SRTM, border cells
0038 % are filled with NaNs. If SRTM was larger, everything is ok
0039 if (max(gxcoords)-min(gxcoords))*(max(gycoords)-min(gycoords))  >  (max(sxcoords)-min(sxcoords))*(max(sycoords)-min(sycoords))
0040     disp('Cropping NaN borders on grids.')
0041     [gxcoords,gycoords,globe,newsrtm] = crop_compare_nan2(gxcoords,gycoords,globe,newsrtm);  
0042 end
0043 %% write out
0044 mat2grid([asciiout],gxcoords,gycoords,newsrtm)

Generated on Tue 24-Feb-2009 19:14:50 by m2html © 2003