Home > . > proj_grid.m

proj_grid

PURPOSE ^

'proj_grid': project fields with unstructured coordinantes on a regular grid

SYNOPSIS ^

function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)

DESCRIPTION ^

'proj_grid': project  fields with unstructured coordinantes on a regular grid
 -------------------------------------------------------------------------
 function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %'proj_grid': project  fields with unstructured coordinantes on a regular grid
0002 % -------------------------------------------------------------------------
0003 % function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
0004 
0005 
0006 function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
0007     if length(vec_Y)<2
0008         warndlg_uvmat('less than 2 points in proj_grid.m','ERROR');
0009         return; 
0010     end
0011     diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
0012     index=find(diffy);% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)
0013     if isempty(index); warndlg_uvmat('points aligned along abscissa in proj_grid.m','ERROR'); return; end;%points aligned% A FAIRE: switch to line plot.
0014     diff2=diff(diffy(index));% diff2 = fluctuations of the detected vertical grid mesh dy
0015     if max(abs(diff2))>0.001*abs(diffy(index(1))) % if max(diff2) is larger than 1/1000 of the first mesh dy
0016         % the data are not regularly spaced and must be interpolated  on a regular grid
0017         if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
0018             rangx=rgx_in; % first and last positions
0019             rangy=rgy_in;
0020 %             npxy=npxy_in;
0021             dxy(1)=1/(npxy_in(1)-1);%grid mesh in y
0022             dxy(2)=1/(npxy_in(2)-1);%grid mesh in x
0023             dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);%grid mesh in y
0024             dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);%grid mesh in x
0025         else % interpolation grid automatically determined
0026             rangx(1)=min(vec_X);
0027             rangx(2)=max(vec_X);
0028             rangy(2)=min(vec_Y);
0029             rangy(1)=max(vec_Y);
0030             dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X));
0031             dxy=[-dxymod/4 dxymod/4];% increase the resolution 4 times
0032         end
0033         xi=[rangx(1):dxy(2):rangx(2)];
0034         yi=[rangy(1):dxy(1):rangy(2)];
0035         [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
0036         A=griddata_uvmat(vec_X,vec_Y,vec_A,xi,yi'); 
0037         A=reshape(A,length(yi),length(xi));
0038     else
0039         x=vec_X(1:index(1));% the set of abscissa (obtained on the first line)
0040         indexend=index(end);% last vector index of line change
0041         ymax=vec_Y(indexend+1);% y coordinate AFTER line change
0042         ymin=vec_Y(index(1));
0043         %y=[vec_Y(index) ymax]; % the set of y ordinates including the last one
0044         y=vec_Y(index);
0045         y(length(y)+1)=ymax;
0046         nx=length(x);   %number of grid points in x
0047         ny=length(y);   % number of grid points in y
0048         B=(reshape(vec_A,nx,ny))'; %vec_A reshaped as a rectangular matrix
0049         [X,Y]=meshgrid(x,y);% positions X and Y also reshaped as matrix
0050         
0051         %linear interpolation to improve the image resolution and/or adjust
0052         %to prescribed positions
0053         test_interp=1;
0054         if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
0055             rangx=rgx_in; % first and last positions
0056             rangy=rgy_in;
0057             npxy=npxy_in;
0058         else        
0059             rangx=[vec_X(1) vec_X(nx)];% first and last position found for x
0060 %             rangy=[ymin ymax];
0061               rangy=[max(ymax,ymin) min(ymax,ymin)];
0062             if max(nx,ny) <= 64 & isequal(npxy_in,'np>256')
0063                 npxy=[8*ny 8*nx];% increase the resolution 8 times
0064             elseif max(nx,ny) <= 128 & isequal(npxy_in,'np>256')
0065                 npxy=[4*ny 4*nx];% increase the resolution 4 times
0066             elseif max(nx,ny) <= 256 & isequal(npxy_in,'np>256')
0067                 npxy=[2*ny 2*nx];% increase the resolution 2 times
0068             else
0069                 npxy=[ny nx];
0070                 test_interp=0; % no interpolation done
0071             end
0072         end
0073         if test_interp==1%if we interpolate
0074             xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)];
0075             yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)];
0076             [XI,YI]=meshgrid(xi,yi);
0077             A = interp2(X,Y,B,XI,YI);
0078         else %no interpolation for a resolution higher than 256
0079             A=B;
0080             XI=X;
0081             YI=Y;
0082         end
0083     end

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003