Changeset 356 for trunk/src/plot_field.m


Ignore:
Timestamp:
Jan 3, 2012, 12:58:52 AM (9 years ago)
Author:
sommeria
Message:

civ updated with new functions for opening files, consistently with uvmat
Bugs to be expected (use previous version then)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r334 r356  
    11801180end
    11811181
     1182%'proj_grid': project  fields with unstructured coordinantes on a regular grid
     1183% -------------------------------------------------------------------------
     1184% function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
     1185
     1186
     1187function [A,rangx,rangy]=proj_grid(vec_X,vec_Y,vec_A,rgx_in,rgy_in,npxy_in)
     1188if length(vec_Y)<2
     1189    msgbox_uvmat('ERROR','less than 2 points in proj_grid.m');
     1190    return;
     1191end
     1192diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
     1193index=find(diffy);% find the indices of vec_Y after wich a change of horizontal line occurs(diffy non zero)
     1194if isempty(index); msgbox_uvmat('ERROR','points aligned along abscissa in proj_grid.m'); return; end;%points aligned% A FAIRE: switch to line plot.
     1195diff2=diff(diffy(index));% diff2 = fluctuations of the detected vertical grid mesh dy
     1196if max(abs(diff2))>0.001*abs(diffy(index(1))) % if max(diff2) is larger than 1/1000 of the first mesh dy
     1197    % the data are not regularly spaced and must be interpolated  on a regular grid
     1198    if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
     1199        rangx=rgx_in; % first and last positions
     1200        rangy=rgy_in;
     1201%             npxy=npxy_in;
     1202        dxy(1)=1/(npxy_in(1)-1);%grid mesh in y
     1203        dxy(2)=1/(npxy_in(2)-1);%grid mesh in x
     1204        dxy(1)=(rangy(2)-rangy(1))/(npxy_in(1)-1);%grid mesh in y
     1205        dxy(2)=(rangx(2)-rangx(1))/(npxy_in(2)-1);%grid mesh in x
     1206    else % interpolation grid automatically determined
     1207        rangx(1)=min(vec_X);
     1208        rangx(2)=max(vec_X);
     1209        rangy(2)=min(vec_Y);
     1210        rangy(1)=max(vec_Y);
     1211        dxymod=sqrt((rangx(2)-rangx(1))*(rangy(1)-rangy(2))/length(vec_X));
     1212        dxy=[-dxymod/4 dxymod/4];% increase the resolution 4 times
     1213    end
     1214    xi=[rangx(1):dxy(2):rangx(2)];
     1215    yi=[rangy(1):dxy(1):rangy(2)];
     1216    [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
     1217    A=griddata_uvmat(vec_X,vec_Y,vec_A,xi,yi');
     1218    A=reshape(A,length(yi),length(xi));
     1219else
     1220    x=vec_X(1:index(1));% the set of abscissa (obtained on the first line)
     1221    indexend=index(end);% last vector index of line change
     1222    ymax=vec_Y(indexend+1);% y coordinate AFTER line change
     1223    ymin=vec_Y(index(1));
     1224    %y=[vec_Y(index) ymax]; % the set of y ordinates including the last one
     1225    y=vec_Y(index);
     1226    y(length(y)+1)=ymax;
     1227    nx=length(x);   %number of grid points in x
     1228    ny=length(y);   % number of grid points in y
     1229    B=(reshape(vec_A,nx,ny))'; %vec_A reshaped as a rectangular matrix
     1230    [X,Y]=meshgrid(x,y);% positions X and Y also reshaped as matrix
     1231
     1232    %linear interpolation to improve the image resolution and/or adjust
     1233    %to prescribed positions
     1234    test_interp=1;
     1235    if exist('rgx_in','var') & ~isempty (rgx_in) & isnumeric(rgx_in) & length(rgx_in)==2%  positions imposed from input
     1236        rangx=rgx_in; % first and last positions
     1237        rangy=rgy_in;
     1238        npxy=npxy_in;
     1239    else       
     1240        rangx=[vec_X(1) vec_X(nx)];% first and last position found for x
     1241%             rangy=[ymin ymax];
     1242          rangy=[max(ymax,ymin) min(ymax,ymin)];
     1243        if max(nx,ny) <= 64 & isequal(npxy_in,'np>256')
     1244            npxy=[8*ny 8*nx];% increase the resolution 8 times
     1245        elseif max(nx,ny) <= 128 & isequal(npxy_in,'np>256')
     1246            npxy=[4*ny 4*nx];% increase the resolution 4 times
     1247        elseif max(nx,ny) <= 256 & isequal(npxy_in,'np>256')
     1248            npxy=[2*ny 2*nx];% increase the resolution 2 times
     1249        else
     1250            npxy=[ny nx];
     1251            test_interp=0; % no interpolation done
     1252        end
     1253    end
     1254    if test_interp==1%if we interpolate
     1255        xi=[rangx(1):(rangx(2)-rangx(1))/(npxy(2)-1):rangx(2)];
     1256        yi=[rangy(1):(rangy(2)-rangy(1))/(npxy(1)-1):rangy(2)];
     1257        [XI,YI]=meshgrid(xi,yi);
     1258        A = interp2(X,Y,B,XI,YI);
     1259    else %no interpolation for a resolution higher than 256
     1260        A=B;
     1261        XI=X;
     1262        YI=Y;
     1263    end
     1264end
Note: See TracChangeset for help on using the changeset viewer.