function do_grids(name,x_size,y_size)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function do_grids tekee pisteparvista 0.5 m griddataa         
%    
% Copyright Juha Hyyppä 5.3.2006
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      

eval(['load ',name,'.txt'])
file=eval(name);
name
pause
eval(['clear ',name])

x_lower=min(file(:,2))-1;
y_lower=min(file(:,1))-1;
malli=zeros(x_size,y_size,1);
malli(:,:,1)=0;
l=length(file);
for i=1:l
    x_coord=file(i,2)-x_lower;
    y_coord=file(i,1)-y_lower;
    z_coord=file(i,3);
    x_coord=fix(x_coord*2+0.5);
    y_coord=fix(y_coord*2+0.5);
    if x_coord<x_size+1 & y_coord<y_size+1 & x_coord>0 & y_coord>0
      if malli(x_coord,y_coord,1)<z_coord
         malli(x_coord,y_coord,1)=z_coord;
      end
    end
end

[x,y]=find(malli>0);
b=(malli>0);
z=malli(b);
[x1,y1]=meshgrid(1:x_size,1:y_size);
%clear osa
chm=griddata(x,y,z,x1,y1,'cubic')';

tulos=chm;
imagesc(chm);
colorbar
pause
clear file
eval(['save ',name,' chm malli x_lower y_lower'])
