function [xi,yi,cart_vel]=cart_grid(az,rg,data,pas)
%rg=67:67:67*100;
c=1; %initialize counter
u_angle=find(az >=270 & az <360);
mod_az=az;
mod_az(u_angle)=360-mod_az(u_angle)+90;
u_angle=find(az>=0 & az<270);
mod_az(u_angle)=90-mod_az(u_angle);
mod_az=round(mod_az);
for a=1:length(az)
        for rr=1:length(rg); %assumes 200 gates of data
        [h,i]=pol2cart(deg2rad(mod_az(a)),rg(rr));    
         x(c)=h;
         y(c)=i;
        r(c)=rg(rr);
        vel(c)=data(rr,a);
        c=c+1;
        end
    end
    
% u_NaN=find(~isnan(vel));
% x=x(u_NaN);
% y=y(u_NaN);
% vel=vel(u_NaN);
% r=r(u_NaN);
[xi,yi]=meshgrid(min(x):pas:max(x),min(y):pas:max(y));
 cart_vel=griddata(x,y,vel,xi,yi,'linear');
 cart_vel=cart_vel';
 xi=round(xi(1,:));
 yi=round(yi(:,1))';