Changeset 227
- Timestamp:
- Mar 31, 2011, 1:42:51 PM (13 years ago)
- Location:
- trunk/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/civ.m
r225 r227 123 123 catch 124 124 errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr}; 125 return 125 126 end 126 127 else 127 128 errormsg=[xmlfile ' not found: path to civx binaries undefined']; 129 return 128 130 end 129 131 … … 1321 1323 set(gcf,'Pointer','arrow') 1322 1324 1323 %------------------------------------------------------------------------ 1324 % determine the list of index pairs of processing file 1325 function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=... 1326 find_pair_indices(handles,mode) 1327 %------------------------------------------------------------------------ 1328 first_i=str2double(get(handles.first_i,'String'));%first index i 1329 last_i=str2double(get(handles.last_i,'String'));%last index i 1330 incr=str2double(get(handles.incr_i,'String'));% increment 1331 num_i=first_i:incr:last_i;% list of i indices (reference values for each pair) 1332 if isequal(get(handles.first_j,'Visible'),'on') 1333 first_j=str2double(get(handles.first_j,'String'));%first index j 1334 last_j=str2double(get(handles.last_j,'String'));%last index j 1335 incr_j=str2double(get(handles.incr_j,'String'));% increment 1336 else 1337 first_j=1; 1338 last_j=1; 1339 incr_j=1; 1340 end 1341 num_j=[first_j:incr_j:last_j];% list of j indices (reference values for each pair) 1342 list_civ1=get(handles.list_pair_civ1,'String'); 1343 index_civ1=get(handles.list_pair_civ1,'Value'); 1344 str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1 1345 if isempty(str_civ1)||isequal(str_civ1,'') 1346 msgbox_uvmat('ERROR','no image pair selected for civ1') 1347 return 1348 end 1349 list_civ2=get(handles.list_pair_civ2,'String'); 1350 index_civ2=get(handles.list_pair_civ2,'Value'); 1351 if index_civ2>length(list_civ2) 1352 list_civ2=list_civ1; 1353 index_civ2=index_civ1; 1354 end 1355 str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2 1356 if isempty(first_i)||isempty(first_j), msgbox_uvmat('ERROR','first field number not defined'),... 1357 return,end; 1358 if isequal(last_i,[])|| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),... 1359 return,end; 1360 if isequal(incr,[])|| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),... 1361 return,end; 1362 if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),... 1363 return,end; 1364 if isequal (mode,'series(Di)') 1365 %recognize the pair civ1 from the display 1366 indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters 1367 str_raw=str_civ1(indsel); 1368 indsepar=find(str_raw=='|'); %character index of the separator 1369 d1=str2double(str_civ1(indsel(indsepar-1)+1:indsel(indsepar)-1)); 1370 if indsepar==length(str_raw) 1371 d2=str2double(str_civ1(indsel(indsepar)+1:end)); 1372 else 1373 d2=str2double(str_civ1(indsel(indsepar)+1:indsel(indsepar+1)-1)); 1374 end 1375 num1_civ1=num_i-d1;% set of first image numbers 1376 num2_civ1=num_i+d2; 1377 num_a_civ1=num_j; 1378 num_b_civ1=num_j; 1379 1380 %recognize the pair civ2 from the display 1381 indsel=find((double(str_civ2)<48)|(double(str_civ2)>57));% character indices of non numerical characters 1382 str_raw=str_civ2(indsel); 1383 indsepar=find(str_raw=='|'); %character index of the separator 1384 d1=str2double(str_civ2(indsel(indsepar-1)+1:indsel(indsepar)-1)); 1385 if indsepar==length(str_raw) 1386 d2=str2double(str_civ2(indsel(indsepar)+1:end)); 1387 else 1388 d2=str2double(str_civ2(indsel(indsepar)+1:indsel(indsepar+1)-1)); 1389 end 1390 if isnan(d1) 1391 num1_civ2=num_i; 1392 else 1393 num1_civ2=num_i-d1;% set of first image numbers 1394 end 1395 if isnan(d2) 1396 num2_civ2=num_i; 1397 else 1398 num2_civ2=num_i+d2; 1399 end 1400 num_a_civ2=num_j; 1401 num_b_civ2=num_j; 1402 1403 % adjust the first and last field number 1404 lastfield=str2double(get(handles.nb_field,'String')); 1405 if isequal(lastfield,[]) 1406 indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1)); 1407 else 1408 indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1)); 1409 end 1410 if length(indsel)>=1 1411 firstind=indsel(1); 1412 lastind=indsel(end); 1413 set(handles.first_i,'String',num2str(num_i(firstind)))%update the display of first and last fields 1414 set(handles.last_i,'String',num2str(num_i(lastind))) 1415 num_i=num_i(indsel); 1416 num1_civ1=num1_civ1(indsel); 1417 num1_civ2=num1_civ2(indsel); 1418 num2_civ1=num2_civ1(indsel); 1419 num2_civ2=num2_civ2(indsel); 1420 end 1421 elseif isequal (mode,'series(Dj)') 1422 lastfield_j=str2double(get(handles.nb_field2,'String')); 1423 num1_civ1=num_i;% set of first image numbers 1424 num2_civ1=num_i; 1425 num_a_civ1=num_j-floor(index_civ1/2)*ones(size(num_j)); 1426 num_b_civ1=num_j+ceil(index_civ1/2)*ones(size(num_j)); 1427 num1_civ2=num_i; 1428 num2_civ2=num_i; 1429 num_a_civ2=num_j-floor(index_civ2/2)*ones(size(num_j)); 1430 num_b_civ2=num_j+ceil(index_civ2/2)*ones(size(num_j)); 1431 % adjust the first and last field number 1432 if isnan(lastfield_j) 1433 indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1)); 1434 else 1435 indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1)); 1436 end 1437 if length(indsel)>=1 1438 firstind=indsel(1); 1439 lastind=indsel(end); 1440 set(handles.first_j,'String',num2str(num_j(firstind)))%update the display of first and last fields 1441 set(handles.last_j,'String',num2str(num_j(lastind))) 1442 num_j=num_j(indsel); 1443 num_a_civ1=num_a_civ1(indsel); 1444 num_a_civ2=num_a_civ2(indsel); 1445 num_b_civ1=num_b_civ1(indsel); 1446 num_b_civ2=num_b_civ2(indsel); 1447 end 1448 elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D) 1449 num1_civ1=num_i; 1450 num1_civ2=num_i; 1451 displ_num=get(handles.list_pair_civ1,'UserData'); 1452 num2_civ1=num_i; 1453 num_a_civ1=displ_num(1,index_civ1); 1454 num_b_civ1=displ_num(2,index_civ1); 1455 num2_civ2=num_i; 1456 num_a_civ2=displ_num(1,index_civ2); 1457 num_b_civ2=displ_num(2,index_civ2); 1458 elseif isequal(mode,'displacement') 1459 num1_civ1=num_i; 1460 num2_civ1=num_i; 1461 num_a_civ1=num_j; 1462 num_b_civ1=num_j; 1463 num1_civ2=num_i; 1464 num2_civ2=num_i; 1465 num_a_civ2=num_j; 1466 num_b_civ2=num_j; 1467 end 1325 1468 1326 1469 1327 … … 1586 1444 status_Callback(hObject, eventdata, handles) 1587 1445 end 1446 1588 1447 %------------------------------------------------------------------------ 1589 1448 % --- Lauch command called by RUN and BATCH: remote processing … … 1645 1504 %% set the list of files and check them 1646 1505 display('checking the files...') 1506 [ref_i,ref_j,errormsg]=find_ref_indices(handles); 1507 if ~isempty(errormsg) 1508 msgbox_uvmat('ERROR',errormsg) 1509 return 1510 end 1647 1511 [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=... 1648 set_civ_filenames(handles, box_test);1512 set_civ_filenames(handles,ref_i,ref_j,box_test); 1649 1513 set(handles.civ,'UserData',filecell);%store for futur use of status callback 1650 1514 if isempty(filecell)% (error message displayed in fct set_civ_filenames) … … 1653 1517 nbfield=numel(num1_civ1); 1654 1518 nbslice=numel(num_a_civ1); 1655 1656 1519 1657 1520 %% read names of the .exe files for PIV and patch … … 2248 2111 else %run PIVlab if selected 2249 2112 image1=imread(par_civ1.filename_ima_a); 2250 image2=imread(par_civ1.filename_ima_b); 2251 [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,str2num(par_civ1.ibx), str2num(par_civ1.dx), 1, [], []); 2113 image2=imread(par_civ1.filename_ima_b); 2114 stepx=str2num(par_civ1.dx); 2115 stepy=str2num(par_civ1.dy); 2116 ibx2=ceil(str2num(par_civ1.ibx)/2); 2117 iby2=ceil(str2num(par_civ1.iby)/2); 2118 isx2=ceil(str2num(par_civ1.isx)/2); 2119 isy2=ceil(str2num(par_civ1.isy)/2); 2120 shiftx=str2num(par_civ1.shiftx); 2121 shifty=str2num(par_civ1.shifty); 2122 % ibx=2*ibx2-1;%ibx and iby odd, reduced by 1 if even 2123 % iby=2*iby2-1; 2124 miniy=max(1+isy2-shifty,1+iby2); 2125 minix=max(1+isx2-shiftx,1+ibx2); 2126 maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2); 2127 maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2); 2128 % maxix=stepx*(floor(size(image1_roi,2)/stepx))-(2*ibx2-2)+ibx2; 2129 [GridX,GridY]=meshgrid(miniy:stepy:maxiy,minix:stepx:maxix); 2130 PointCoord(:,1)=reshape(GridX,[],1); 2131 PointCoord(:,2)=reshape(GridY,[],1); 2132 [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty,PointCoord, 1, []); 2252 2133 Data.ListGlobalAttribute={'title','Time','Dt'}; 2253 2134 Data.title='PIVlab'; … … 2312 2193 saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER .xml) 2313 2194 2314 2315 2316 2195 %------------------------------------------------------------------------ 2196 % --- determine the list of reference indices of processing file 2197 function [ref_i,ref_j,errormsg]=find_ref_indices(handles) 2198 %------------------------------------------------------------------------ 2199 errormsg=''; %default error message 2200 first_i=str2double(get(handles.first_i,'String'));%first index i 2201 last_i=str2double(get(handles.last_i,'String'));%last index i 2202 incr_i=str2double(get(handles.incr_i,'String'));% increment 2203 if isequal(get(handles.first_j,'Visible'),'on') 2204 first_j=str2double(get(handles.first_j,'String'));%first index j 2205 last_j=str2double(get(handles.last_j,'String'));%last index j 2206 incr_j=str2double(get(handles.incr_j,'String'));% increment 2207 else 2208 first_j=1; 2209 last_j=1; 2210 incr_j=1; 2211 end 2212 ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair) 2213 ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair) 2214 if isnan(first_i)||isnan(first_j) 2215 errormsg='first field number not defined'; 2216 elseif isnan(last_i)||isnan(last_j) 2217 errormsg='last field number not defined'; 2218 elseif isnan(incr_i)||isnan(incr_j) 2219 errormsg='increment in field number not defined'; 2220 elseif last_i < first_i || last_j < first_j 2221 errormsg='last field number must be larger than the first one'; 2222 end 2223 2224 %------------------------------------------------------------------------ 2225 % --- determine the list of filenames and indices needed for launch_job 2317 2226 function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=... 2318 set_civ_filenames(handles, box_test)2227 set_civ_filenames(handles,ref_i,ref_j,box_test) 2319 2228 %------------------------------------------------------------------------ 2320 2229 filecell=[];%default … … 2351 2260 if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default 2352 2261 [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=... 2353 find_pair_indices(handles, mode);2262 find_pair_indices(handles,ref_i,ref_j,mode); 2354 2263 %determine the new filebase for 'displacement' mode (comparison of two series) 2355 2264 filebase_B=filebase;% root name of the second field series for stereo … … 3034 2943 3035 2944 %------------------------------------------------------------------------ 2945 % --- determine the list of index pairs of processing file 2946 function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=... 2947 find_pair_indices(handles,ref_i,ref_j,mode) 2948 %------------------------------------------------------------------------ 2949 2950 list_civ1=get(handles.list_pair_civ1,'String'); 2951 index_civ1=get(handles.list_pair_civ1,'Value'); 2952 str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1 2953 if isempty(str_civ1)||isequal(str_civ1,'') 2954 msgbox_uvmat('ERROR','no image pair selected for civ1') 2955 return 2956 end 2957 list_civ2=get(handles.list_pair_civ2,'String'); 2958 index_civ2=get(handles.list_pair_civ2,'Value'); 2959 if index_civ2>length(list_civ2) 2960 list_civ2=list_civ1; 2961 index_civ2=index_civ1; 2962 end 2963 str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2 2964 2965 if isequal (mode,'series(Di)') 2966 lastfield=str2double(get(handles.nb_field,'String')); 2967 num1_civ1=ref_i-floor(index_civ1/2)*ones(size(ref_i));% set of first image numbers 2968 num2_civ1=ref_i+ceil(index_civ1/2)*ones(size(ref_i)); 2969 num_a_civ1=ref_j; 2970 num_b_civ1=ref_j; 2971 num1_civ2=ref_i-floor(index_civ2/2)*ones(size(ref_i));; 2972 num2_civ2=ref_i+ceil(index_civ2/2)*ones(size(ref_i)); 2973 num_a_civ2=ref_j; 2974 num_b_civ2=ref_j; 2975 2976 % adjust the first and last field number 2977 lastfield=str2double(get(handles.nb_field,'String')); 2978 if isnan(lastfield) 2979 indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1)); 2980 else 2981 indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1)); 2982 end 2983 if length(indsel)>=1 2984 firstind=indsel(1); 2985 lastind=indsel(end); 2986 set(handles.first_i,'String',num2str(ref_i(firstind)))%update the display of first and last fields 2987 set(handles.last_i,'String',num2str(ref_i(lastind))) 2988 ref_i=ref_i(indsel); 2989 num1_civ1=num1_civ1(indsel); 2990 num1_civ2=num1_civ2(indsel); 2991 num2_civ1=num2_civ1(indsel); 2992 num2_civ2=num2_civ2(indsel); 2993 end 2994 elseif isequal (mode,'series(Dj)') 2995 lastfield_j=str2double(get(handles.nb_field2,'String')); 2996 num1_civ1=ref_i;% set of first image numbers 2997 num2_civ1=ref_i; 2998 num_a_civ1=ref_j-floor(index_civ1/2)*ones(size(ref_j)); 2999 num_b_civ1=ref_j+ceil(index_civ1/2)*ones(size(ref_j)); 3000 num1_civ2=ref_i; 3001 num2_civ2=ref_i; 3002 num_a_civ2=ref_j-floor(index_civ2/2)*ones(size(ref_j)); 3003 num_b_civ2=ref_j+ceil(index_civ2/2)*ones(size(ref_j)); 3004 % adjust the first and last field number 3005 if isnan(lastfield_j) 3006 indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1)); 3007 else 3008 indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1)); 3009 end 3010 if length(indsel)>=1 3011 firstind=indsel(1); 3012 lastind=indsel(end); 3013 set(handles.first_j,'String',num2str(ref_j(firstind)))%update the display of first and last fields 3014 set(handles.last_j,'String',num2str(ref_j(lastind))) 3015 ref_j=ref_j(indsel); 3016 num_a_civ1=num_a_civ1(indsel); 3017 num_b_civ1=num_b_civ1(indsel); 3018 num_a_civ2=num_a_civ2(indsel); 3019 num_b_civ2=num_b_civ2(indsel); 3020 end 3021 elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D) 3022 displ_num=get(handles.list_pair_civ1,'UserData'); 3023 num1_civ1=ref_i; 3024 num2_civ1=ref_i; 3025 num_a_civ1=displ_num(1,index_civ1); 3026 num_b_civ1=displ_num(2,index_civ1); 3027 num1_civ2=ref_i; 3028 num2_civ2=ref_i; 3029 num_a_civ2=displ_num(1,index_civ2); 3030 num_b_civ2=displ_num(2,index_civ2); 3031 elseif isequal(mode,'displacement') 3032 num1_civ1=ref_i; 3033 num2_civ1=ref_i; 3034 num_a_civ1=ref_j; 3035 num_b_civ1=ref_j; 3036 num1_civ2=ref_i; 3037 num2_civ2=ref_i; 3038 num_a_civ2=ref_j; 3039 num_b_civ2=ref_j; 3040 end 3041 3042 3043 %------------------------------------------------------------------------ 3036 3044 % --- PATCH 3037 3045 function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin) … … 4596 4604 test_civ1=get(handles.TestCiv1,'Value'); 4597 4605 if test_civ1 4606 ref_i=str2double(get(handles.ref_i,'String')); 4607 if strcmp(get(handles.ref_j,'Visible'),'on') 4608 ref_j=str2double(get(handles.ref_j,'String')); 4609 else 4610 ref_j=1;%default 4611 end 4598 4612 [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=... 4599 set_civ_filenames(handles, [1 0 0 0 0 0]);4613 set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]); 4600 4614 Data.ListVarName={'ny','nx','A'}; 4601 4615 Data.VarDimName={'ny','nx',{'ny','nx'}}; … … 4603 4617 Data.ny=[size(Data.A,1) 1]; 4604 4618 Data.nx=[1 size(Data.A,2)]; 4619 par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1}); 4620 4621 stepx=str2num(par_civ1.dx); 4622 stepy=str2num(par_civ1.dy); 4623 ibx2=ceil(str2num(par_civ1.ibx)/2); 4624 iby2=ceil(str2num(par_civ1.iby)/2); 4625 isx2=ceil(str2num(par_civ1.isx)/2); 4626 isy2=ceil(str2num(par_civ1.isy)/2); 4627 shiftx=str2num(par_civ1.shiftx); 4628 shifty=str2num(par_civ1.shifty); 4629 % ibx=2*ibx2-1;%ibx and iby odd, reduced by 1 if even 4630 % iby=2*iby2-1; 4631 miniy=max(1+isy2-shifty,1+iby2); 4632 minix=max(1+isx2-shiftx,1+ibx2); 4633 maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2); 4634 maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2); 4635 % maxix=stepx*(floor(size(image1_roi,2)/stepx))-(2*ibx2-2)+ibx2; 4636 [GridX,GridY]=meshgrid(miniy:stepy:maxiy,minix:stepx:maxix); 4637 PointCoord(:,1)=reshape(GridX,[],1); 4638 PointCoord(:,2)=reshape(GridY,[],1); 4605 4639 hh=view_field(Data); 4640 set(0,'CurrentFigure',hh) 4641 plot(PointCoord(:,2),PointCoord(:,1),'+') 4606 4642 ViewData=get(hh,'UserData'); 4607 4643 ViewData.axes3.B=imread(filecell.ima2.civ1{1});%store the second image in the UserData of the GUI view_field … … 4652 4688 filecell=get(handles.civ,'UserData'); 4653 4689 if ~isfield(filecell,'nc') 4654 filecell=set_civ_filenames(handles,box_test);%determine the list of output files expected from the GUI status 4690 [ref_i,ref_j,errormsg]=find_ref_indices(handles); 4691 if ~isempty(errormsg) 4692 msgbox_uvmat('ERROR',errormsg) 4693 return 4694 end 4695 filecell=set_civ_filenames(handles,ref_i,ref_j,box_test);%determine the list of output files expected from the GUI status 4655 4696 end 4656 4697 -
trunk/src/delete_object.m
r156 r227 44 44 end 45 45 UvData.Object(hObject)=[]; 46 list_str(hObject)=[]; 46 if ~isempty(list_str) 47 list_str(hObject)=[]; 48 end 47 49 end 48 50 elseif ishandle(hObject)%object handle -
trunk/src/geometry_calib.m
r213 r227 441 441 %------------------------------------------------------------------------ 442 442 % determine the parameters for a calibration by a linear transform matrix (rescale and rotation) 443 function GeometryCalib=calib_linear(Coord,handles) %TO UPDATE443 function GeometryCalib=calib_linear(Coord,handles) 444 444 %------------------------------------------------------------------------ 445 445 X=Coord(:,1); … … 461 461 GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1); 462 462 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 463 GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) 1]; 463 %GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) 1]; 464 GeometryCalib.Tx_Ty_Tz=[a_X1(1)/GeometryCalib.fx_fy(1) a_Y1(1)/GeometryCalib.fx_fy(2) 1]; 464 465 R(1,:)=R(1,:)/GeometryCalib.fx_fy(1); 465 466 R(2,:)=R(2,:)/GeometryCalib.fx_fy(2); … … 1030 1031 ind_sub_x=round(XLim); 1031 1032 ind_sub_y=np(1)-round(YLim); 1032 Mfiltre=AxeData.A( [ind_sub_y(2):ind_sub_y(1)],ind_sub_x,:);1033 Mfiltre=AxeData.A(ind_sub_y(2):ind_sub_y(1) ,ind_sub_x,:); 1033 1034 Mfiltre_norm=double(Mfiltre); 1034 1035 Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm)); … … 1064 1065 if ~isempty(ObjectData.Coord) 1065 1066 if isequal(option,'phys') 1066 ObjectData.Coord=ObjectData.Coord(:, [1:3]);1067 ObjectData.Coord=ObjectData.Coord(:,1:3); 1067 1068 elseif isequal(option,'px')||isequal(option,'') 1068 ObjectData.Coord=ObjectData.Coord(:, [4:5]);1069 ObjectData.Coord=ObjectData.Coord(:,4:5); 1069 1070 else 1070 1071 msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be '''', px or phys ') … … 1135 1136 function MenuDetectGrid_Callback(hObject, eventdata, handles) 1136 1137 %------------------------------------------------------------------------ 1137 %% initiate the grid1138 CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib1139 grid_input=[];%default1140 if isfield(CalibData,'grid')1141 grid_input=CalibData.grid;%retrieve the previously used grid1142 end1143 [T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T1144 set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use1145 1146 1138 %% read the four last point coordinates in pixels 1147 1139 Coord_cell=get(handles.ListCoord,'String');%read list of coordinates on geometry_calib … … 1149 1141 nbpoints=size(data.Coord,1); %nbre of calibration points 1150 1142 if nbpoints~=4 1151 msgbox_uvmat('ERROR','four points must have be selected by the mouse , beginning by the new x axis, to delimitate the phys grid area')1143 msgbox_uvmat('ERROR','four points must have be selected by the mouse to delimitate the phys grid area; the Ox axis will be defined by the two first points') 1152 1144 return 1153 1145 end … … 1165 1157 corners_Y(3)=Y_end; 1166 1158 end 1159 1160 %% initiate the grid 1161 CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib 1162 grid_input=[];%default 1163 if isfield(CalibData,'grid') 1164 grid_input=CalibData.grid;%retrieve the previously used grid 1165 end 1166 [T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T 1167 set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use 1168 1169 1167 1170 1168 1171 %% read the current image, displayed in the GUI uvmat -
trunk/src/get_field.m
r213 r227 22 22 function varargout = get_field(varargin) 23 23 24 % Last Modified by GUIDE v2.5 06-Feb-2010 09:58:1324 % Last Modified by GUIDE v2.5 27-Mar-2011 19:13:26 25 25 26 26 % Begin initialization code - DO NOT EDIT … … 49 49 global nb_builtin % nbre of functions to include by default in the menu of functions called by RUN 50 50 51 %% look at the existing figures in the work space 52 browse_fig(handles.list_fig) 51 53 52 54 53 %% Choose default command line output for get_field … … 58 57 guidata(hObject, handles); 59 58 60 %% 61 set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})59 %%activate the mouse action function: visualise the current field on work space by right click action 60 %set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles}) 62 61 63 62 %% prepare the list of RUN fcts and set their paths … … 112 111 %% settings for 'slave' mode, called by uvamt, or 'master' mode 113 112 if exist('filename','var') && ischar(filename) %transfer input file name in slave mode 114 set(handles.inputfile,'String',filename)% prefill the input file name 115 Field=nc2struct(filename );% reads the whole field113 set(handles.inputfile,'String',filename)% prefill the input file name 114 Field=nc2struct(filename,[]);% reads the whole field 116 115 if isfield(Field,'Txt') 117 116 msgbox_uvmat('ERROR',Field.Txt) 118 117 else 119 set(handles. figure1,'UserData',Field);118 set(handles.get_field,'UserData',Field); 120 119 Field_input(eventdata,handles,Field); 121 120 end 122 121 else %master mode 123 set(handles.inputfile,'String','') 124 % set(handles.RUN,'String','RUN')% 125 % load the list of previously browsed files for the upper bar menu Open 126 dir_perso=prefdir; 127 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% 128 if exist(profil_perso,'file') 129 h=load (profil_perso); 130 if isfield(h,'MenuFile_1')131 set(handles.MenuFile_1,'Label',h.MenuFile_1);132 end133 if isfield(h,'MenuFile_1')134 set(handles.MenuFile_2,'Label',h.MenuFile_2);135 end136 if isfield(h,'MenuFile_1')137 set(handles.MenuFile_3,'Label',h.MenuFile_3);138 end139 if isfield(h,'MenuFile_1')140 set(handles.MenuFile_4,'Label',h.MenuFile_4);141 end142 if isfield(h,'MenuFile_1')143 set(handles.MenuFile_5,'Label',h.MenuFile_5);144 end122 set(handles.inputfile,'String','') 123 end 124 125 %% load the list of previously browsed files for the upper bar menu Open 126 dir_perso=prefdir; 127 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% 128 if exist(profil_perso,'file') 129 h=load (profil_perso); 130 if isfield(h,'MenuFile_1') 131 set(handles.MenuFile_1,'Label',h.MenuFile_1); 132 end 133 if isfield(h,'MenuFile_1') 134 set(handles.MenuFile_2,'Label',h.MenuFile_2); 135 end 136 if isfield(h,'MenuFile_1') 137 set(handles.MenuFile_3,'Label',h.MenuFile_3); 138 end 139 if isfield(h,'MenuFile_1') 140 set(handles.MenuFile_4,'Label',h.MenuFile_4); 141 end 142 if isfield(h,'MenuFile_1') 143 set(handles.MenuFile_5,'Label',h.MenuFile_5); 145 144 end 146 145 end … … 168 167 %------------------------------------------------------------------------ 169 168 inputfile=get(handles.inputfile,'String'); 170 Field=nc2struct(inputfile);% reads the whole field 169 Field=nc2struct(inputfile,[]);% reads the field description, without data 170 Field.ListGlobalAttribute 171 171 if isfield(Field,'Txt') 172 172 msgbox_uvmat('ERROR',Field.Txt) 173 173 else 174 set(handles. figure1,'UserData',Field);174 set(handles.get_field,'UserData',Field); 175 175 Field_input(eventdata,handles,Field); 176 176 end … … 189 189 Tabcell{iline,2}=num2str(Field.DimValue(iline)); 190 190 end 191 Tabchar=cell2tab(Tabcell,' =');191 Tabchar=cell2tab(Tabcell,' = '); 192 192 set(handles.dimensions,'String',Tabchar) 193 193 end … … 212 212 set(handles.coord_z_vectors,'String',[{''} Txt ]) 213 213 set(handles.scalar,'Value',1) 214 214 215 set(handles.scalar,'String', Txt ) 215 216 [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field); … … 218 219 return 219 220 end 221 for icell=1:numel(CellVarIndex) 222 NbDim(icell)=max(NbDim(icell),numel(CellVarIndex{icell})); 223 end 220 224 [maxdim,imax]=max(NbDim); 221 225 … … 278 282 check_vector_Callback(handles.check_vector, eventdata, handles) 279 283 end 284 %scalar_Callback(handles.get_field, eventdata, handles) 285 %vector_x_Callback(handles.get_field, eventdata, handles) 280 286 281 287 %------------------------------------------------------------------------ … … 315 321 % test_2D=get(handles.check_vector,'Value');% =1 for vector fields 316 322 % test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields 317 %if isequal(xdispindex,1)% blank selection, no selected variable for abscissa323 %if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa 318 324 % Txt=Field.ListVarName; 319 325 % set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates … … 329 335 % end 330 336 % set(handles.variables,'Value',xindex+1)%outline in the list of variables 331 % variables_Callback(hObject, eventdata, handles) %display properties of the variable (dim, attributes)337 % variables_Callback(hObject, eventdata, handles) %display properties of the TimeVariable (dim, attributes) 332 338 % if ~test_2D & ~test_scalar% look for possible varaibles to RUN in ordinate 333 % index=Field.VarDimIndex{xindex};%dimension indices of the variable selected for abscissa339 % index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa 334 340 % VarIndex=[]; 335 341 % for ilist=1:length(Field.VarDimIndex)%detect 336 342 % index_i=Field.VarDimIndex{ilist}; 337 343 % if ~isempty(index_i) 338 % if isequal(index_i(1),index(1))%if the first dimension of the variable coincide with the selected one, RUN is possible344 % if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, RUN is possible 339 345 % VarIndex=[VarIndex ilist]; 340 346 % end … … 352 358 function scalar_Callback(hObject, eventdata, handles) 353 359 %------------------------------------------------------------------------ 354 Aindex=get(handles.scalar,'Value');355 Astring=get(handles.scalar,'String');356 VarName= Astring{Aindex};360 index=get(handles.scalar,'Value'); 361 string=get(handles.scalar,'String'); 362 VarName=string{index}; 357 363 update_field(hObject, eventdata, handles,VarName) 364 365 %eliminate time 366 TimeDimName='';%default 367 if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on') 368 TimeDimList=get(handles.TimeDimensionMenu,'String'); 369 TimeDimIndex=get(handles.TimeDimensionMenu,'Value'); 370 TimeDimName=TimeDimList{TimeDimIndex}; 371 end 372 373 %check possible coordinates 374 Field=get(handles.get_field,'UserData'); 375 dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar 376 test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate 377 for ilist=1:numel(Field.VarDimName) 378 dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist 379 if isequal(dimnames,{TimeDimName}) 380 test_coord(ilist)=0;%mark time variables fo elimination 381 end 382 for idim=1:numel(dimnames) 383 if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable 384 test_coord(ilist)=0; 385 break 386 end 387 end 388 end 389 test_coord(index)=0;%the coordinate variable must be different from the scalar 390 391 string_coord=[{''};string(test_coord==1)]; 392 val=get(handles.coord_x_scalar,'Value'); 393 if val>numel(string_coord) 394 set(handles.coord_x_scalar,'Value',1) 395 end 396 set(handles.coord_x_scalar,'String',string_coord); 397 val=get(handles.coord_y_scalar,'Value'); 398 if val>numel(string_coord) 399 set(handles.coord_y_scalar,'Value',1) 400 end 401 set(handles.coord_y_scalar,'String',string_coord); 402 val=get(handles.coord_y_scalar,'Value'); 403 if val>numel(string_coord) 404 set(handles.coord_y_scalar,'Value',1) 405 end 406 set(handles.coord_z_scalar,'String',string_coord); 407 358 408 359 409 %------------------------------------------------------------------------ … … 391 441 string=get(handles.vector_x,'String'); 392 442 VarName=string{index}; 443 444 %check possible coordinates 445 Field=get(handles.get_field,'UserData'); 446 dim_var=Field.VarDimName{index};%list of dimensions of the selected scalar 447 test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate 448 test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component 449 for ilist=1:numel(Field.VarDimName) 450 dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist 451 if ~isequal(dimnames,dim_var) 452 test_component(ilist)=0; 453 end 454 for idim=1:numel(dimnames) 455 if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable 456 test_coord(ilist)=0; 457 break 458 end 459 end 460 end 461 %eliminate time 462 if get(handles.TimeVariable,'Value') 463 TimeName=get(handles.TimeName,'String'); 464 index_time=find(strcmp( TimeName,Field.ListVarName)); 465 test_coord(index_time)=0; 466 end 467 vlength=numel(string(test_component==1)); 468 val=get(handles.vector_y,'Value'); 469 if val>vlength 470 set(handles.vector_y,'Value',1) 471 end 472 set(handles.vector_y,'String',[string(test_component==1)]) 473 val=get(handles.vector_z,'Value'); 474 if val>vlength+1 475 set(handles.vector_z,'Value',1) 476 end 477 set(handles.vector_z,'String',[{''};string(test_component==1)]) 478 val=get(handles.vec_color,'Value'); 479 if val>vlength+1 480 set(handles.vec_color,'Value',1) 481 end 482 set(handles.vec_color,'String',[{''};string(test_component==1)]) 483 string_coord=[{''};string(test_coord==1)]; 484 val=get(handles.coord_x_vectors,'Value'); 485 if val>numel(string_coord) 486 set(handles.coord_x_vectors,'Value',1) 487 end 488 set(handles.coord_x_vectors,'String',string_coord); 489 val=get(handles.coord_y_vectors,'Value'); 490 if val>numel(string_coord) 491 set(handles.coord_y_vectors,'Value',1) 492 end 493 set(handles.coord_y_vectors,'String',string_coord); 494 val=get(handles.coord_z_vectors,'Value'); 495 if val>numel(string_coord) 496 set(handles.coord_z_vectors,'Value',1) 497 end 498 set(handles.coord_z_vectors,'String',string_coord); 499 393 500 update_field(hObject, eventdata, handles,VarName) 394 501 … … 420 527 update_field(hObject, eventdata, handles,VarName) 421 528 422 %------------------------------------------------------- 529 %------------------------------------------------------------------------ 423 530 % --- Executes on selection change in coord_y_vectors. 424 %-------------------------------------------------------425 531 function coord_y_vectors_Callback(hObject, eventdata, handles) 532 %------------------------------------------------------------------------ 426 533 index=get(handles.coord_y_vectors,'Value'); 427 534 string=get(handles.coord_y_vectors,'String'); … … 429 536 update_field(hObject, eventdata, handles,VarName) 430 537 431 %------------------------------------------------------- 538 %------------------------------------------------------------------------ 432 539 % --- Executes on selection change in coord_z_scalar. 433 540 function coord_z_vectors_Callback(hObject, eventdata, handles) 434 %------------------------------------------------------- 541 %------------------------------------------------------------------------ 435 542 index=get(handles.coord_z_vectors,'Value'); 436 543 string=get(handles.coord_z_vectors,'String'); … … 438 545 update_field(hObject, eventdata, handles,VarName) 439 546 440 %------------------------------------------------------- 547 %------------------------------------------------------------------------ 441 548 % --- Executes on selection change in vec_color. 442 549 function vec_color_Callback(hObject, eventdata, handles) 443 %------------------------------------------------------- 550 %------------------------------------------------------------------------ 444 551 index=get(handles.vec_color,'Value'); 445 552 string=get(handles.vec_color,'String'); … … 447 554 update_field(hObject, eventdata, handles,VarName) 448 555 449 %--------------------------------- 556 %----------------------------------------------------------------------- 450 557 function update_field(hObject, eventdata, handles,VarName) 451 % VarName= input variable name for scalar or vector plots 452 hselect_field=get(handles.inputfile,'parent'); 453 Field=get(hselect_field,'UserData'); 558 %----------------------------------------------------------------------- 559 Field=get(handles.get_field,'UserData'); 454 560 index=name2index(VarName,Field.ListVarName); 455 561 if ~isempty(index) … … 457 563 variables_Callback(hObject, eventdata, handles) 458 564 end 459 % 460 % 461 % hselect_field=get(handles.inputfile,'parent'); 462 % Field=get(hselect_field,'UserData'); 463 % ivar_sel=[];%default 464 % for ivar=1:length(Field.ListVarName)%detect 465 % if isequal(Field.ListVarName{ivar},VarName) 466 % ivar_sel=ivar; %ivar_sel = index of the input variable in the list ListVarName 467 % break 468 % end 469 % end 470 % if isempty(ivar_sel) 471 % return 472 % end 473 % set(handles.variables,'Value',ivar_sel+1)%select the corresponding item in the displayed list 'variables' 474 % variables_Callback(hObject, eventdata, handles)%show the dimensions and attributes of the input variable 475 % 476 % index=Field.VarDimIndex{ivar_sel};%dimension indices of the input variable 477 % DimValue=Field.DimValue(index);%dimension values of the input variable 478 % ind_1=find(DimValue==1); 479 % index(ind_1)=[];%Mremove singletons 480 % 481 % 482 % % detect possible variables for abscissa and ordinate 483 % VarIndex=[];%initiate list of selected variable indices 484 % ind_coordvar=[]; %initiate list of coordinate variables 485 % for ilist=1:length(Field.VarDimIndex) 486 % if ~isequal(ilist,ivar_sel) 487 % index_i=Field.VarDimIndex{ilist};%indices of dimensions associated with variable #ilist 488 % if length(index_i)>1 489 % DimValue=Field.DimValue(index_i); 490 % ind_1=find(DimValue==1); 491 % index_i(ind_1)=[];%Mremove singletons 492 % if isequal(index,index_i) 493 % VarIndex=[VarIndex ilist]; %selected variable withb the same dimensions of the input variable 494 % end 495 % else 496 % idim=find(index==index_i(1)); 497 % if ~isempty(idim) 498 % VarIndex=[VarIndex ilist]; %possible dimension variable 499 % if isequal(Field.ListDimName{index_i(1)},Field.ListVarName{ilist}) 500 % ind_coordvar=[ind_coordvar length(VarIndex)]; 501 % end 502 % end 503 % end 504 % end 505 % end 506 % % val=get(handles.abscissa,'Value'); 507 % % if val>length(Field.ListVarName(VarIndex))+1 508 % % set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1) 509 % % end 510 % % val=get(handles.ordinate,'Value'); 511 % % if val>length(Field.ListVarName(VarIndex))+1 512 % % set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1) 513 % % end 514 % % val=get(handles.coord_z_vectors_scalar,'Value'); 515 % % if val>length(Field.ListVarName(VarIndex))+1 516 % % set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1) 517 % % end 518 % set(handles.abscissa,'Value',1)%default 519 % set(handles.ordinate,'Value',1)%default 520 % set(handles.coord_z_scalar,'Value',1)%default 521 % set(handles.abscissa,'String',[{''} Field.ListVarName(VarIndex) ]) 522 % set(handles.ordinate,'String',[{''} Field.ListVarName(VarIndex) ]) 523 % set(handles.coord_z_scalar,'String',[{''} Field.ListVarName(VarIndex) ]) 524 % if length(ind_coordvar)>=1 525 % set(handles.abscissa,'Value',ind_coordvar(1)+1) 526 % elseif length(index)==1 && length(VarIndex)>=1 527 % set(handles.abscissa,'Value',2) 528 % end 529 % if length(ind_coordvar)>=2 530 % set(handles.ordinate,'Value',ind_coordvar(2)+1) 531 % elseif length(index)==1 && length(VarIndex)>=2 532 % set(handles.ordinate,'Value',3) 533 % end 534 % if length(ind_coordvar)>=3 535 % set(handles.coord_z_scalar,'Value',ind_coordvar(3)+1) 536 % elseif length(index)==1 && length(VarIndex)>=3 537 % set(handles.coord_z_scalar,'Value',4) 538 % end 539 540 %--------------------------------------------------------- 565 566 %------------------------------------------------------------------------ 541 567 % update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback) 542 568 function update_UserData(handles) 543 %--------------------------------------------------------- 569 %------------------------------------------------------------------------ 544 570 return 545 571 % global SubField … … 615 641 end 616 642 DimIndex=DimIndex_u; 617 %TODO possibility of selecting 3 times the same variable for u, v, w components618 end 619 620 621 % select the variable index (or indices) for z coordinates643 %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components 644 end 645 646 647 % select the TimeVariable index (or indices) for z coordinates 622 648 test_grid=0; 623 649 if test_scalar | test_vector … … 658 684 end 659 685 % if ~isempty(VarIndex_z) 660 % DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable661 % if length(DimIndex_z)==1 & nbdim==3 %dimension variable686 % DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable 687 % if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable 662 688 % VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; 663 689 % ind_z=find(DimIndex==DimIndex_z(1)); … … 669 695 end 670 696 671 % select the variable index (or indices) for ordinate697 % select the TimeVariable index (or indices) for ordinate 672 698 ystring=get(handles.ordinate,'String'); 673 699 yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox … … 701 727 end 702 728 703 %select the variable index for the abscissa729 %select the TimeVariable index for the abscissa 704 730 xstring=get(handles.abscissa,'String'); 705 731 xindex=get(handles.abscissa,'Value'); … … 801 827 function RUN_Callback(hObject, eventdata, handles) 802 828 %--------------------------------------------------------- 803 figcell=get(handles.list_fig,'String'); 804 index=get(handles.list_fig,'value'); 805 figstring=figcell{index}; 829 set(handles.RUN,'BackgroundColor',[1 1 0])% mark use of RUN action 830 test_fig=get(handles.SelectFigure,'Value'); 806 831 807 832 % plot requested in uvmat 808 if isequal(figstring,'uvmat')833 if ~test_fig 809 834 inputfile=get(handles.inputfile,'String'); 810 835 huvmat=findobj(allchild(0),'tag','uvmat'); … … 814 839 set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases) 815 840 hhuvmat=guidata(huvmat); 841 set(hhuvmat.Fields,'Value',1) 842 set(hhuvmat.Fields,'String',{'get_field...'}) 816 843 uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat 817 844 end 818 845 819 846 % other kind of plot 820 else 847 else %TODO: check and update: add plot on an existing axes 848 figcell=get(handles.list_fig,'String'); 849 index=get(handles.list_fig,'value'); 850 figstring=figcell{index}; 821 851 index=get(handles.ACTION,'Value'); 822 852 list_func=get(handles.ACTION,'UserData'); … … 824 854 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784]) 825 855 drawnow 826 SubField=h_fun(handles. figure1);%handles.figure1 =handles of the GUI get_field856 SubField=h_fun(handles.get_field);%handles.figure1 =handles of the GUI get_field 827 857 if ~isempty(SubField) 828 858 plot_get_field(SubField,handles) … … 869 899 % % handles structure with handles and user data (see GUIDATA) 870 900 % 871 % %time plots901 % %timename plots 872 902 % leg={}; 873 903 % n=0; … … 1042 1072 Tabcell=[]; 1043 1073 hselect_field=get(handles.variables,'parent'); 1044 Field=get(h select_field,'UserData');1074 Field=get(handles.get_field,'UserData'); 1045 1075 index=get(handles.variables,'Value');%index in the list 'variables' 1046 1076 if isequal(index,1) 1047 1077 set(handles.attributes_txt,'String','global attributes') 1048 % list global attribute names and values if index=1 (blank variable display) is selected1078 % list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected 1049 1079 if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute) 1050 1080 for iline=1:length(Field.ListGlobalAttribute) … … 1062 1092 end 1063 1093 else 1064 %list attribute names and values associated to the variable # injdex-11094 %list TimeAttribute names and values associated to the TimeVariable # injdex-1 1065 1095 list_var=get(handles.variables,'String'); 1066 1096 var_select=list_var{index}; … … 1115 1145 Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline))); 1116 1146 end 1117 Tabchar=cell2tab(Tabdim,' =');1147 Tabchar=cell2tab(Tabdim,' = '); 1118 1148 Tabchar=[{''} ;Tabchar]; 1149 set(handles.dimensions,'Value',1) 1119 1150 set(handles.dimensions,'String',Tabchar) 1120 1151 end … … 1153 1184 end 1154 1185 1155 % ------------------------------------------------------------------------1156 function mouse_up_gui(ggg,eventdata,handles)1157 % ------------------------------------------------------------------------1158 if isequal(get(ggg,'SelectionType'),'alt')1159 message='';1160 global CurData1161 inputfield=get(handles.inputfile,'String');1162 if exist(inputfield,'file')1163 CurData=nc2struct(inputfield);1164 else1165 CurData=get(ggg,'UserData');% get_field opened from a input field, not a file1166 end1167 %%%% TODO: put the matalb command window in front1168 evalin('base','global CurData')%make CurData global in the workspace1169 evalin('base','CurData') %display CurData in the workspace1170 end1186 % %------------------------------------------------------------------------ 1187 % function mouse_up_gui(ggg,eventdata,handles) 1188 % %------------------------------------------------------------------------ 1189 % if isequal(get(ggg,'SelectionType'),'alt') 1190 % message=''; 1191 % global CurData 1192 % inputfield=get(handles.inputfile,'String'); 1193 % if exist(inputfield,'file') 1194 % CurData=nc2struct(inputfield); 1195 % else 1196 % CurData=get(ggg,'UserData');% get_field opened from a input field, not a file 1197 % end 1198 % %%%% TODO: put the matalb command window in front 1199 % evalin('base','global CurData')%make CurData global in the workspace 1200 % evalin('base','CurData') %display CurData in the workspace 1201 % end 1171 1202 1172 1203 %------------------------------------------------------------------------ … … 1414 1445 %global inputfile 1415 1446 fileinput=[PathName FileName];%complete file name 1416 testblank=findstr(fileinput,' ');%look for blanks1417 if ~isempty(testblank)1418 msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])1419 return1420 end1421 1447 sizf=size(fileinput); 1422 if (~ischar(fileinput)| ~isequal(sizf(1),1)),return;end1448 if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end 1423 1449 set(handles.inputfile,'String',fileinput) 1424 1450 inputfile_Callback(hObject, eventdata, handles) 1425 1426 1451 1427 1452 %update list of recent files in the menubar … … 1464 1489 inputfile_Callback(hObject, eventdata, handles) 1465 1490 1466 % -------------------------------------------------------------------- 1491 % ----------------------------------------------------------------------- 1467 1492 function MenuFile_3_Callback(hObject, eventdata, handles) 1493 % ----------------------------------------------------------------------- 1468 1494 fileinput=get(handles.MenuFile_3,'Label'); 1469 1495 set(handles.inputfile,'String',fileinput) 1470 1496 inputfile_Callback(hObject, eventdata, handles) 1471 1497 1472 % -------------------------------------------------------------------- 1498 % ----------------------------------------------------------------------- 1473 1499 function MenuFile_4_Callback(hObject, eventdata, handles) 1500 % ----------------------------------------------------------------------- 1474 1501 fileinput=get(handles.MenuFile_4,'Label'); 1475 1502 set(handles.inputfile,'String',fileinput) 1476 1503 inputfile_Callback(hObject, eventdata, handles) 1477 1504 1478 % -------------------------------------------------------------------- 1505 % ----------------------------------------------------------------------- 1479 1506 function MenuFile_5_Callback(hObject, eventdata, handles) 1507 % ----------------------------------------------------------------------- 1480 1508 fileinput=get(handles.MenuFile_5,'Label'); 1481 1509 set(handles.inputfile,'String',fileinput) 1482 1510 inputfile_Callback(hObject, eventdata, handles) 1483 1511 1484 % 1512 %------------------------------------------------------------------------ 1485 1513 function MenuExportField_Callback(hObject, eventdata, handles) 1514 %------------------------------------------------------------------------ 1486 1515 global Data_get_field 1487 1516 % huvmat=findobj(allchild(0),'Name','uvmat'); … … 1494 1523 commandwindow; 1495 1524 1496 % 1525 %------------------------------------------------------------------------ 1497 1526 function MenuHelp_Callback(hObject, eventdata, handles) 1498 % hObject handle to MenuHelp (see GCBO) 1499 % eventdata reserved - to be defined in a future version of MATLAB 1500 % handles structure with handles and user data (see GUIDATA) 1527 %------------------------------------------------------------------------ 1501 1528 path_to_uvmat=which ('uvmat');% check the path of uvmat 1502 1529 pathelp=fileparts(path_to_uvmat); … … 1507 1534 end 1508 1535 1536 % ----------------------------------------------------------------------- 1537 function TimeName_Callback(hObject, eventdata, handles) 1538 1539 scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates 1540 vector_x_Callback(hObject, eventdata, handles) 1541 1542 %------------------------------------------------------------------------ 1543 % --- Executes on button press in TimeAttribute. 1544 function TimeAttribute_Callback(hObject, eventdata, handles) 1545 %------------------------------------------------------------------------ 1546 val=get(handles.TimeAttribute,'Value'); 1547 if val 1548 set(handles.TimeAttributeMenu,'Visible','on') 1549 Field=get(handles.get_field,'UserData'); 1550 time_value=zeros(size(Field.ListGlobalAttribute)); 1551 test_time=zeros(size(Field.ListGlobalAttribute)); 1552 for ilist=1:numel(Field.ListGlobalAttribute) 1553 if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}])) 1554 eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';']) 1555 if ~isempty(time_val) 1556 time_value(ilist)=time_val; 1557 test_time(ilist)=1; 1558 end 1559 end 1560 end 1561 ListTimeAttribute=Field.ListGlobalAttribute(test_time==1); 1562 attr_index=get(handles.TimeAttributeMenu,'Value'); 1563 if attr_index>numel(ListTimeAttribute) 1564 attr_index=1; 1565 set(handles.TimeAttributeMenu,'Value',1); 1566 end 1567 if isempty(ListTimeAttribute) 1568 set(handles.TimeAttributeMenu,'String',{''}) 1569 set(handles.TimeValue,'Visible','off') 1570 else 1571 set(handles.TimeValue,'Visible','on') 1572 set(handles.TimeAttributeMenu,'String',ListTimeAttribute) 1573 set(handles.TimeValue,'String',num2str(time_value(attr_index))) 1574 end 1575 set(handles.TimeDimension,'Value',0) 1576 TimeDimension_Callback(hObject, eventdata, handles) 1577 set(handles.TimeVariable,'Value',0) 1578 TimeVariable_Callback(hObject, eventdata, handles) 1579 else 1580 set(handles.TimeAttributeMenu,'Visible','off') 1581 set(handles.TimeValue,'Visible','off') 1582 end 1583 1584 %------------------------------------------------------------------------ 1585 % --- Executes on selection change in TimeAttributeMenu. 1586 function TimeAttributeMenu_Callback(hObject, eventdata, handles) 1587 ListTimeAttribute=get(handles.TimeAttributeMenu,'String'); 1588 index=get(handles.TimeAttributeMenu,'Value'); 1589 AttrName=ListTimeAttribute{index}; 1590 Field=get(handles.get_field,'UserData'); 1591 eval(['time_val=Field.' AttrName ';']) 1592 set(handles.TimeValue,'String',num2str(time_val)) 1593 %------------------------------------------------------------------------ 1594 1595 %------------------------------------------------------------------------ 1596 % --- Executes on button press in TimeVariable. 1597 function TimeDimension_Callback(hObject, eventdata, handles) 1598 %------------------------------------------------------------------------ 1599 val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected 1600 if val %if check box TimeDimension is selected 1601 Field=get(handles.get_field,'UserData');% structure describing the currently opened field 1602 previous_menu=get(handles.TimeDimensionMenu,'String'); 1603 if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu 1604 ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time' 1605 if isempty(ind_select) 1606 ind_select=1;% select the first item in the list if 'time' is not found 1607 end 1608 set(handles.TimeDimensionMenu,'Value',ind_select); 1609 set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu 1610 end 1611 set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible 1612 set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible 1613 TimeDimensionMenu_Callback(hObject, eventdata, handles) 1614 set(handles.TimeAttribute,'Value',0) %deselect alternative options for time 1615 set(handles.TimeVariable,'Value',0) 1616 TimeAttribute_Callback(hObject, eventdata, handles) 1617 else 1618 set(handles.TimeDimensionMenu,'Visible','off') 1619 set(handles.TimeIndexValue,'Visible','off') 1620 end 1621 1622 %------------------------------------------------------------------------ 1623 % --- Executes on selection change in TimeDimensionMenu. 1624 function TimeDimensionMenu_Callback(hObject, eventdata, handles) 1625 %------------------------------------------------------------------------ 1626 index=get(handles.TimeDimensionMenu,'Value'); 1627 DimList=get(handles.TimeDimensionMenu,'String'); 1628 DimName=DimList{index}; 1629 Field=get(handles.get_field,'UserData'); 1630 DimIndex=find(strcmp(DimName,Field.ListDimName),1); 1631 ref_index=round(Field.DimValue(DimIndex)/2); 1632 set(handles.TimeIndexValue,'String',num2str(ref_index)) 1633 scalar_Callback(hObject, eventdata, handles) 1634 vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time) 1635 % look for a corresponding time variable and value 1636 time_test=zeros(size(Field.VarDimName)); 1637 for ilist=1:numel(Field.VarDimName) 1638 if isequal(Field.VarDimName{ilist},{DimName}) 1639 time_test(ilist)=1; 1640 end 1641 end 1642 ListVariable=Field.ListVarName(time_test==1); 1643 set(handles.TimeVariableMenu,'Value',1) 1644 if isempty(ListVariable) 1645 set(handles.TimeVariableMenu,'String',{''}) 1646 set(handles.TimeVarValue,'String','') 1647 else 1648 set(handles.TimeVariableMenu,'String',ListVariable) 1649 TimeVarName=ListVariable{1}; 1650 VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables 1651 inputfile=get(handles.inputfile,'String');% read the input file 1652 SubField=nc2struct(inputfile,{TimeVarName}); 1653 eval(['TimeValue=SubField.' TimeVarName '(ref_index);']) 1654 set(handles.TimeVarValue,'Visible','on') 1655 set(handles.TimeVariableMenu,'Visible','on') 1656 set(handles.TimeVarValue,'String',num2str(TimeValue)) 1657 end 1658 1659 1660 % % ----------------------------------------------------------------------- 1661 % % --- Executes on button press in TimeVariable. 1662 % function TimeVariable_Callback(hObject, eventdata, handles) 1663 % % ----------------------------------------------------------------------- 1664 % val=get(handles.TimeVariable,'Value'); 1665 % if val 1666 % Field=get(handles.get_field,'UserData'); 1667 % time_test=zeros(size(Field.VarDimName)); 1668 % for ilist=1:numel(Field.VarDimName) 1669 % if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension 1670 % time_test(ilist)=1; 1671 % end 1672 % end 1673 % ind_test=find(time_test); 1674 % if isempty(time_test) 1675 % set(handles.TimeVariable,'Value',0) 1676 % set(handles.TimeVariableMenu,'Visible','off') 1677 % set(handles.TimeVarValue,'Visible','off') 1678 % else 1679 % set(handles.TimeVariableMenu,'Visible','on') 1680 % set(handles.TimeVarValue,'Visible','on') 1681 % if get(handles.TimeVariableMenu,'Value')>numel(ind_test) 1682 % set(handles.TimeVariableMenu,'Value',1) 1683 % end 1684 % set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test)) 1685 % TimeVariableMenu_Callback(hObject, eventdata, handles) 1686 % set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time 1687 % set(handles.TimeAttribute,'Value',0) 1688 % TimeAttribute_Callback(hObject, eventdata, handles) 1689 % end 1690 % else 1691 % set(handles.TimeVariableMenu,'Visible','off') 1692 % set(handles.TimeVarValue,'Visible','off') 1693 % end 1694 1695 % ----------------------------------------------------------------------- 1696 % --- Executes on selection change in TimeVariableMenu. 1697 function TimeVariableMenu_Callback(hObject, eventdata, handles) 1698 % ----------------------------------------------------------------------- 1699 ListVar=get(handles.TimeVariableMenu,'String'); 1700 index=get(handles.TimeVariableMenu,'Value'); 1701 TimeVariable=ListVar{index};% name of the selected variable 1702 if isempty(TimeVariable)% case of blank selection 1703 return 1704 end 1705 Field=get(handles.get_field,'UserData'); %index of 1706 VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables 1707 DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable 1708 set(handles.TimeDimensionMenu,'Value',1) 1709 set(handles.TimeDimensionMenu,'String',DimName) 1710 inputfile=get(handles.inputfile,'String');% read the input file 1711 SubField=nc2struct(inputfile,{TimeVariable}); 1712 eval(['TimeDimension=numel(SubField.' TimeVariable ');']) 1713 ref_index=round(TimeDimension/2); 1714 eval(['TimeValue=SubField.' TimeVariable '(ref_index);']) 1715 set(handles.TimeIndexValue,'String',num2str(ref_index)) 1716 set(handles.TimeVarValue,'String',num2str(TimeValue)) 1717 1718 1719 function TimeValue_Callback(hObject, eventdata, handles) 1720 %TO suppress 1721 1722 % ----------------------------------------------------------------------- 1723 function TimeIndexValue_Callback(hObject, eventdata, handles) 1724 % ----------------------------------------------------------------------- 1725 TimeIndex=str2double(get(handles.TimeIndexValue,'String')); 1726 TimeVarName=Field.ListVarName{time_index}; 1727 set(handles.TimeVariable,'Value',1) 1728 set(handles.TimeName,'String',TimeVarName) 1729 fileinput=get(handles.inputfile,'String'); 1730 SubField=nc2struct(fileinput,{TimeVarName}); 1731 eval(['TimeValue=SubField.' TimeVarName '(ref_index);']); 1732 set(handles.TimeValue,'Visible','on') 1733 set(handles.TimeValue,'String',num2str(TimeValue)) 1734 1735 % ----------------------------------------------------------------------- 1736 function SelectFigure_Callback(hObject, eventdata, handles) 1737 % ----------------------------------------------------------------------- 1738 val=get(handles.SelectFigure,'Value'); 1739 if val 1740 set(handles.list_fig,'Visible','on') 1741 %% look at the existing figures in the work space 1742 browse_fig(handles.list_fig) 1743 else 1744 set(handles.list_fig,'Visible','off') 1745 end 1746 1747 1748 function TimeVarValue_Callback(hObject, eventdata, handles) 1749 1750 1751 1752 % --- Executes on button press in check_rgb. 1753 function check_rgb_Callback(hObject, eventdata, handles) 1754 1755 1756 -
trunk/src/nc2struct.m
r188 r227 65 65 nc=netcdf.open(nc,'NC_NOWRITE'); 66 66 testfile=1; 67 catch errormsg68 Data.Txt=['ERROR opening ' nc ': ' errormsg.identifier];67 catch ME 68 Data.Txt=['ERROR opening ' nc ': ' ME.message]; 69 69 return 70 70 end … … 77 77 end 78 78 79 %% short reading op ion for global attributes only, if the first argument is 'ListGlobalAttribute'79 %% short reading option for global attributes only, if the first argument is 'ListGlobalAttribute' 80 80 if isequal(varargin{1},'ListGlobalAttribute') 81 81 for ilist=2:numel(varargin) 82 valuestr=[];%default 82 83 try 83 84 valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist}); 84 catch 85 valuestr=[]; 85 catch ME 86 86 end 87 87 eval(['Data.' varargin{ilist} '=valuestr;']) … … 97 97 %% -------- read all global attributes (constants)----------- 98 98 att_key={};%default 99 iatt_g=0;99 % iatt_g=0; 100 100 Data.ListGlobalAttribute={};%default 101 101 for iatt=1:ngatts 102 102 keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1); 103 indstr1=regexp(keystr,'\\','once');%detect '\\' 104 indstr2=regexp(keystr,'\.','once');%detect '\.' 105 %indtitle=regexp(keystr,'title','once');%detect 'title'(bad characters) 106 if isempty(indstr1) && isempty(indstr2)%&&isempty(indtitle) 107 valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),keystr); 108 if ischar(valuestr) & length(valuestr)<200 & double(valuestr)<=122 & double(valuestr)>=48 %usual characters 109 iatt_g=iatt_g+1; 110 indstr1=regexp(keystr,'\\','once');%detect '\\' 111 indstr2=regexp(keystr,'\.','once');%detect '\.' 112 if isempty(indstr1) && isempty(indstr2) 113 eval(['Data.' keystr '=''' valuestr ''';']) 114 att_key{iatt_g}=keystr; 115 end 116 elseif isempty(valuestr) 117 iatt_g=iatt_g+1; 118 eval(['Data.' keystr '=[];']) 119 att_key{iatt_g}=keystr; 103 valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),keystr); 104 keystr=regexprep(keystr,{'\','/','\.','-',' '},{'','','','',''});%remove '\','.' or '-' if exists 105 if strcmp(keystr(1),'_') 106 keystr(1)=[]; 107 end 108 try 109 if ischar(valuestr) & length(valuestr)<200 & double(valuestr)<=122 & double(valuestr)>=48 %usual characters 110 % valuestr=regexprep(valuestr,{'\\','\/','\.','\-',' '},{'_','_','_','_','_'})%remove '\','.' or '-' if exists 111 eval(['Data.' keystr '=''' valuestr ''';']) 112 % elseif isempty(valuestr) 113 % eval(['Data.' keystr '=[];']) 120 114 elseif isnumeric(valuestr) 121 iatt_g=iatt_g+1;122 115 eval(['Data.' keystr '=valuestr;']) 123 att_key{iatt_g}=keystr; 124 end 116 else 117 eval(['Data.' keystr '='';']) 118 end 119 att_key{iatt}=keystr; 120 catch ME 121 att_key{iatt}=['attr_' num2str(iatt)]; 122 eval(['Data.' att_key{iatt} '=[];']) 125 123 end 126 124 end … … 184 182 attname = netcdf.inqAttName(nc,var_index(ivar)-1,iatt-1); 185 183 valuestr= netcdf.getAtt(nc,var_index(ivar)-1,attname); 184 attname=regexprep(attname,{'\','/','\.','-',' '},{'','','','',''});%remove '\','.' or '-' if exists 185 if strcmp(attname(1),'_') 186 attname(1)=[]; 187 end 188 try 186 189 if ischar(valuestr) 190 % valuestr=regexprep(valuestr,{'\\','\/','\.','\-',' '},{'_','_','_','_','_'});%remove '\','.' or '-' if exists 187 191 eval(['Data.VarAttribute{ivar}.' attname '=''' valuestr ''';']) 188 192 elseif isempty(valuestr) … … 190 194 elseif isnumeric(valuestr) 191 195 eval(['Data.VarAttribute{ivar}.' attname '=valuestr;']) 196 end 197 catch ME 198 display(attname) 199 display(valuestr) 200 display(ME.message) 201 eval(['Data.VarAttribute{ivar}.atrr_' num2str(iatt) '=''not read'';']) 192 202 end 193 203 end -
trunk/src/pivlab.m
r225 r227 1 1 % 'pivlab': function piv.m adapted from PIVlab http://pivlab.blogspot.com/ 2 2 %-------------------------------------------------------------------------- 3 % function [xtable ytable utable vtable typevector] = pivlab (image1,image2,i nterrogationarea,step, subpixfinder, mask, roi)3 % function [xtable ytable utable vtable typevector] = pivlab (image1,image2,ibx,iby step, subpixfinder, mask, roi) 4 4 % 5 5 % OUTPUT: … … 14 14 % image1:first image (matrix) 15 15 % image2: second image (matrix) 16 % i nterrogationarea: size of the correlation box(in px)16 % ibx,iby: size of the correlation box along x and y (in px) 17 17 % step: mesh of the measurement points (in px) 18 18 % subpixfinder=1 or 2 controls the curve fitting of the image correlation 19 19 % mask: =[] for no mask 20 20 % roi: 4 element vector defining a region of interest: x position, y position, width, height, (in image indices), for the whole image, roi=[]; 21 function [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,i nterrogationarea, step, subpixfinder, mask, roi)21 function [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty, PointCoord, subpixfinder,mask) 22 22 %this funtion performs the DCC PIV analysis. Recent window-deformation 23 23 %methods perform better and will maybe be implemented in the future. 24 24 warning off %MATLAB:log:logOfZero 25 if numel(roi)>026 xroi=roi(1);27 yroi=roi(2);28 widthroi=roi(3);29 heightroi=roi(4);30 image1_roi=double(image1(yroi:yroi+heightroi,xroi:xroi+widthroi));31 image2_roi=double(image2(yroi:yroi+heightroi,xroi:xroi+widthroi));32 else25 % if numel(roi)>0 26 % xroi=roi(1); 27 % yroi=roi(2); 28 % widthroi=roi(3); 29 % heightroi=roi(4); 30 % image1_roi=double(image1(yroi:yroi+heightroi,xroi:xroi+widthroi)); 31 % image2_roi=double(image2(yroi:yroi+heightroi,xroi:xroi+widthroi)); 32 % else 33 33 xroi=0; 34 34 yroi=0; 35 35 image1_roi=double(image1); 36 36 image2_roi=double(image2); 37 end37 % end 38 38 if numel(mask)>0 39 39 cellmask=mask; … … 48 48 end 49 49 mask(mask>1)=1; 50 51 miniy=1+(ceil(interrogationarea/2)); 52 minix=1+(ceil(interrogationarea/2)); 53 maxiy=step*(floor(size(image1_roi,1)/step))-(interrogationarea-1)+(ceil(interrogationarea/2)); %statt size deltax von ROI nehmen 54 maxix=step*(floor(size(image1_roi,2)/step))-(interrogationarea-1)+(ceil(interrogationarea/2)); 55 56 numelementsy=floor((maxiy-miniy)/step+1); 57 numelementsx=floor((maxix-minix)/step+1); 58 59 LAy=miniy; 60 LAx=minix; 61 LUy=size(image1_roi,1)-maxiy; 62 LUx=size(image1_roi,2)-maxix; 63 shift4centery=round((LUy-LAy)/2); 64 shift4centerx=round((LUx-LAx)/2); 65 if shift4centery<0 %shift4center will be negative if in the unshifted case the left border is bigger than the right border. the vectormatrix is hence not centered on the image. the matrix cannot be shifted more towards the left border because then image2_crop would have a negative index. The only way to center the matrix would be to remove a column of vectors on the right side. but then we weould have less data.... 66 shift4centery=0; 67 end 68 if shift4centerx<0 %shift4center will be negative if in the unshifted case the left border is bigger than the right border. the vectormatrix is hence not centered on the image. the matrix cannot be shifted more towards the left border because then image2_crop would have a negative index. The only way to center the matrix would be to remove a column of vectors on the right side. but then we weould have less data.... 69 shift4centerx=0; 70 end 71 miniy=miniy+shift4centery; 72 minix=minix+shift4centerx; 73 maxix=maxix+shift4centerx; 74 maxiy=maxiy+shift4centery; 75 76 image1_roi=padarray(image1_roi,[ceil(interrogationarea/2) ceil(interrogationarea/2)], min(min(image1_roi))); 77 image2_roi=padarray(image2_roi,[ceil(interrogationarea/2) ceil(interrogationarea/2)], min(min(image1_roi))); 78 mask=padarray(mask,[ceil(interrogationarea/2) ceil(interrogationarea/2)],0); 79 if (rem(interrogationarea,2) == 0) %for the subpixel displacement measurement 80 SubPixOffset=1; 81 else 82 SubPixOffset=0.5; 83 end 84 xtable=zeros(numelementsy,numelementsx); 50 % ibx=2*ibx2-1%ibx and iby odd, reduced by 1 if even 51 % iby=2*iby2-1 52 % miniy=1+iby2 53 % minix=1+ibx2 54 % maxiy=step*(floor(size(image1_roi,1)/step))-(iby-1)+iby2 %statt size deltax von ROI nehmen 55 % maxix=step*(floor(size(image1_roi,2)/step))-(ibx-1)+ibx2 56 % numelementsy=floor((maxiy-miniy)/step+1); 57 % numelementsx=floor((maxix-minix)/step+1); 58 % 59 % LAy=miniy; 60 % LAx=minix; 61 % LUy=size(image1_roi,1)-maxiy; 62 % LUx=size(image1_roi,2)-maxix; 63 % shift4centery=round((LUy-LAy)/2); 64 % shift4centerx=round((LUx-LAx)/2); 65 % if shift4centery<0 %shift4center will be negative if in the unshifted case the left border is bigger than the right border. the vectormatrix is hence not centered on the image. the matrix cannot be shifted more towards the left border because then image2_crop would have a negative index. The only way to center the matrix would be to remove a column of vectors on the right side. but then we weould have less data.... 66 % shift4centery=0; 67 % end 68 % if shift4centerx<0 %shift4center will be negative if in the unshifted case the left border is bigger than the right border. the vectormatrix is hence not centered on the image. the matrix cannot be shifted more towards the left border because then image2_crop would have a negative index. The only way to center the matrix would be to remove a column of vectors on the right side. but then we weould have less data.... 69 % shift4centerx=0; 70 % end 71 % miniy=miniy+shift4centery; 72 % minix=minix+shift4centerx; 73 % maxix=maxix+shift4centerx; 74 % maxiy=maxiy+shift4centery; 75 76 image1_roi=padarray(image1_roi,[iby2 ibx2], min(min(image1_roi)));%add a border around the image with minimum image value 77 image2_roi=padarray(image2_roi,[iby2 ibx2], min(min(image1_roi))); 78 mask=padarray(mask,[iby2 ibx2],0); 79 SubPixOffset=0.5;%odd values chosen for ibx and iby 80 81 nbvec=size(PointCoord,1); 82 xtable=zeros(nbvec,1); 85 83 ytable=xtable; 86 84 utable=xtable; … … 89 87 v2table=xtable; 90 88 s2n=xtable; 91 typevector=ones( numelementsy,numelementsx);;89 typevector=ones(size(xtable)); 92 90 93 91 nrx=0; … … 97 95 98 96 %% MAINLOOP 99 %handles=guihandles(getappdata(0,'hgui')); 100 for j = miniy:step:maxiy %vertical loop 101 nry=nry+1; 102 % if increments<6 %reduced display refreshing rate 103 % increments=increments+1; 104 % else 105 % increments=1; 106 % %set(handles.progress, 'string' , ['Frame progress: ' int2str(j/maxiy*100) '%']);drawnow; 107 % end 108 n=round((j-miniy)/maxiy*100); 109 for i = minix:step:maxix % horizontal loop 110 nrx=nrx+1;%used to determine the pos of the vector in resulting matrix 111 if nrxreal < numelementsx 112 nrxreal=nrxreal+1; 113 else 114 nrxreal=1; 115 end 116 startpoint=[i j]; 117 image1_crop=image1_roi(j:j+interrogationarea-1, i:i+interrogationarea-1); 118 image2_crop=image2_roi(ceil(j-interrogationarea/2):ceil(j+1.5*interrogationarea-1), ceil(i-interrogationarea/2):ceil(i+1.5*interrogationarea-1)); 119 corrmax=0; 120 if mask(round(j+interrogationarea/2),round(i+interrogationarea/2))==0 97 for ivec=1:nbvec 98 iref=PointCoord(ivec,1); 99 jref=PointCoord(ivec,2); 100 image1_crop=image1_roi(jref-iby2:jref+iby2,iref-ibx2:iref+ibx2); 101 image2_crop=image2_roi(jref+shifty-isy2:jref+shifty+isy2,iref+shiftx-isx2:iref+shiftx+isx2); 102 % n=round((j-miniy)/maxiy*100); 103 % for i = minix:step:maxix % horizontal loop 104 % nrx=nrx+1;%used to determine the pos of the vector in resulting matrix 105 % if nrxreal < numelementsx 106 % nrxreal=nrxreal+1; 107 % else 108 % nrxreal=1; 109 % end 110 % startpoint=[i j]; 111 % image1_crop=image1_roi(j:j+iby-1, i:i+ibx-1); 112 % image2_crop=image2_roi(ceil(j-iby/2):ceil(j+1.5*iby-1), ceil(i-ibx/2):ceil(i+1.5*ibx-1)); 113 % corrmax=0; 114 if mask(jref,iref)==0 121 115 %reference: Oliver Pust, PIV: Direct Cross-Correlation 122 116 % image2_crop: sub image with the size of the search area in image 2 … … 132 126 try 133 127 if subpixfinder==1 134 [vector] = SUBPIXGAUSS (result_conv,i nterrogationarea,x,y,SubPixOffset);128 [vector] = SUBPIXGAUSS (result_conv,ibx,iby,x,y,SubPixOffset); 135 129 elseif subpixfinder==2 136 [vector] = SUBPIX2DGAUSS (result_conv,i nterrogationarea,x,y,SubPixOffset);130 [vector] = SUBPIX2DGAUSS (result_conv,ibx,iby,x,y,SubPixOffset); 137 131 end 138 132 catch … … 144 138 else %if mask was not 0 then 145 139 vector=[NaN NaN]; 146 typevector( nry,nrxreal)=0;140 typevector(ivec)=0; 147 141 end 148 142 149 143 %Create the vector matrix x, y, u, v 150 xtable(nry,nrxreal)=startpoint(1)+interrogationarea/2; 151 ytable(nry,:)=startpoint(1,2)+interrogationarea/2; 152 utable(nry,nrxreal)=vector(1); 153 vtable(nry,nrxreal)=vector(2); 154 ctable(nry,nrxreal)=corrmax/sum(sum(image1_crop.*image1_crop)); 155 end 156 157 end 158 xtable=xtable-ceil(interrogationarea/2); 159 ytable=ytable-ceil(interrogationarea/2); 160 161 xtable=xtable+xroi; 162 ytable=ytable+yroi; 163 164 utable(utable>interrogationarea/1.5)=NaN; 165 vtable(utable>interrogationarea/1.5)=NaN; 166 vtable(vtable>interrogationarea/1.5)=NaN; 167 utable(vtable>interrogationarea/1.5)=NaN; 168 169 function [vector] = SUBPIXGAUSS (result_conv,interrogationarea,x,y,SubPixOffset) 144 xtable(ivec)=PointCoord(ivec,2); 145 ytable(ivec)=PointCoord(ivec,1); 146 utable(ivec)=vector(1); 147 vtable(ivec)=vector(2); 148 ctable(ivec)=corrmax/sum(sum(image1_crop.*image1_crop)); 149 end 150 % xtable=xtable-ibx2; 151 % ytable=ytable-iby2; 152 % 153 % xtable=xtable+xroi; 154 % ytable=ytable+yroi; 155 % 156 % utable(utable>ibx/1.5)=NaN; 157 % vtable(utable>ibx/1.5)=NaN; 158 % vtable(vtable>iby/1.5)=NaN; 159 % utable(vtable>iby/1.5)=NaN; 160 161 function [vector] = SUBPIXGAUSS (result_conv,ibx,iby,x,y,SubPixOffset) 170 162 if size(x,1)>1 %if there are more than 1 peaks just take the first 171 163 x=x(1:1); … … 186 178 peakx = x+ (f1-f2)/(2*f1-4*f0+2*f2); 187 179 % 188 SubpixelX=peakx-(i nterrogationarea/2)-SubPixOffset;189 SubpixelY=peaky-(i nterrogationarea/2)-SubPixOffset;180 SubpixelX=peakx-(ibx/2)-SubPixOffset; 181 SubpixelY=peaky-(iby/2)-SubPixOffset; 190 182 vector=[SubpixelX, SubpixelY]; 191 183 else … … 193 185 end 194 186 195 function [vector] = SUBPIX2DGAUSS (result_conv,i nterrogationarea,x,y,SubPixOffset)187 function [vector] = SUBPIX2DGAUSS (result_conv,ibx,iby,x,y,SubPixOffset) 196 188 if size(x,1)>1 %if there are more than 1 peaks just take the first 197 189 x=x(1:1); … … 229 221 peaky=y+deltay; 230 222 231 SubpixelX=peakx-(i nterrogationarea/2)-SubPixOffset;232 SubpixelY=peaky-(i nterrogationarea/2)-SubPixOffset;223 SubpixelX=peakx-(ibx/2)-SubPixOffset; 224 SubpixelY=peaky-(iby/2)-SubPixOffset; 233 225 vector=[SubpixelX, SubpixelY]; 234 226 else -
trunk/src/plot_field.m
r221 r227 585 585 XName=Data.ListVarName{ivar_X}; 586 586 YName=Data.ListVarName{ivar_Y}; 587 eval(['vec_X= Data.' XName ';'])588 eval(['vec_Y= Data.' YName ';'])587 eval(['vec_X=reshape(Data.' XName ',[],1);']) 588 eval(['vec_Y=reshape(Data.' YName ',[],1);']) 589 589 elseif numel(VarType.coord)==2 && ~isequal(VarType.coord,[0 0]);%coordinates defines by dimension variables 590 590 eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';']) … … 627 627 eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image 628 628 test_ima=1; 629 if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty) 629 if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates (then ivar_X and ivar_Y not empty) 630 A=reshape(A,1,[]); 630 631 XName=Data.ListVarName{ivar_X}; 631 632 YName=Data.ListVarName{ivar_Y}; 632 eval(['AX= Data.' XName ';'])633 eval(['AY= Data.' YName ';'])633 eval(['AX=reshape(Data.' XName ',1,[]);']) 634 eval(['AY=reshape(Data.' YName ',1,[]);']) 634 635 [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256'); % interpolate on a grid 635 636 if isfield(Data,'VarAttribute') -
trunk/src/proj_field.m
r215 r227 946 946 cos_om=1; 947 947 sin_om=0; 948 test90x=0;%=1 for 90 degree rotation alround x axis 949 test90y=0;%=1 for 90 degree rotation alround y axis 948 950 if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0]) 951 test90y=isequal(ObjectData.Angle,[0 90 0]); 949 952 PlaneAngle=(pi/180)*ObjectData.Angle; 950 953 om=norm(PlaneAngle);%norm of rotation angle in radians … … 958 961 norm_plane(3)=OmAxis(3)*coeff+cos_om; 959 962 end 960 testangle=~isequal(PlaneAngle,[0 0 0]); 963 testangle=~isequal(PlaneAngle,[0 0 0]);% && ~test90y && ~test90x;%=1 for slanted plane 964 961 965 % Phi=0;%default 962 966 % Theta=0; … … 1071 1075 DimCell={DimCell};%name of dimensions 1072 1076 end 1073 1074 %% case of input fields with unstructured coordinates1077 1078 %% case of input fields with unstructured coordinates 1075 1079 if testX 1076 1080 XName=FieldData.ListVarName{ivar_X}; … … 1082 1086 eval(['coord_z=FieldData.' ZName ';']) 1083 1087 end 1084 1088 1085 1089 % translate initial coordinates 1086 1090 coord_x=coord_x-ObjectData.Coord(1,1); … … 1093 1097 if length(ivar_Z)==1 && width > 0 1094 1098 %components of the unitiy vector normal to the projection plane 1095 fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane 1099 fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane 1096 1100 indcut=find(abs(fieldZ) <= width); 1097 1101 size(indcut) 1098 1102 for ivar=VarIndex 1099 1103 VarName=FieldData.ListVarName{ivar}; 1100 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);']) 1101 % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE1104 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);']) 1105 % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE 1102 1106 end 1103 1107 coord_x=coord_x(indcut); … … 1105 1109 coord_z=coord_z(indcut); 1106 1110 end 1107 1108 %rotate coordinates if needed1109 if testangle 1110 % coord_X=coord_x;1111 % coord_Y=coord_y;1112 % if ~isequal(Theta,0)1113 % coord_Y=coord_Y *cos(Theta);1114 % end1115 % else1111 1112 %rotate coordinates if needed: 1113 if testangle && ~test90y && ~test90x;%=1 for slanted plane 1114 % coord_X=coord_x; 1115 % coord_Y=coord_y; 1116 % if ~isequal(Theta,0) 1117 % coord_Y=coord_Y *cos(Theta); 1118 % end 1119 % else 1116 1120 coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi)); 1117 1121 coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta); 1118 % end1119 % if ~isempty(ivar_Z)1122 % end 1123 % if ~isempty(ivar_Z) 1120 1124 coord_Y=coord_Y+coord_z *sin(Theta); 1121 % end1122 % if testangle1123 1124 1125 % end 1126 % if testangle 1127 coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER 1128 coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi)); 1125 1129 else 1126 1130 coord_X=coord_x; … … 1151 1155 for ivar=VarIndex 1152 1156 VarName=FieldData.ListVarName{ivar}; 1153 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);']) 1157 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);']) 1154 1158 end 1155 1159 coord_X=coord_X(indcut); … … 1164 1168 %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions 1165 1169 %ProjData.DimValue=[ProjData. 1166 1167 1170 %length(coord_X)]; 1171 1168 1172 for ivar=VarIndex %transfer variables to the projection plane 1169 1173 VarName=FieldData.ListVarName{ivar}; … … 1175 1179 eval(['ProjData.' VarName '=FieldData.' VarName ';']) 1176 1180 end 1177 if isempty(ivar_Z) || ivar~=ivar_Z 1181 if isempty(ivar_Z) || ivar~=ivar_Z 1178 1182 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1179 1183 ProjData.VarDimName=[ProjData.VarDimName DimCell]; … … 1183 1187 end 1184 1188 end 1185 end 1189 end 1186 1190 elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid 1187 1191 coord_x_proj=XMin:DX:XMax; … … 1189 1193 DimCell={'coord_y','coord_x'}; 1190 1194 ProjData.ListVarName={'coord_y','coord_x'}; 1191 ProjData.VarDimName={'coord_y','coord_x'}; 1192 nbcoord=2; 1195 ProjData.VarDimName={'coord_y','coord_x'}; 1196 nbcoord=2; 1193 1197 ProjData.coord_y=[YMin YMax]; 1194 1198 ProjData.coord_x=[XMin XMax]; … … 1211 1215 for ivar=VarIndex 1212 1216 VarName=FieldData.ListVarName{ivar}; 1213 if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1) 1217 if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1) 1214 1218 ivar_new=ivar_new+1; 1215 1219 ProjData.ListVarName=[ProjData.ListVarName {VarName}]; … … 1245 1249 ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj)); 1246 1250 ProjData.ListVarName=[ProjData.ListVarName {'FF'}]; 1247 ProjData.VarDimName=[ProjData.VarDimName {DimCell}];1251 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1248 1252 ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag'; 1249 1253 end 1250 1254 end 1251 1255 1252 %% case of input fields defined on a structured grid 1256 %% case of input fields defined on a structured grid 1253 1257 else 1254 VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions 1258 'TESTproj' 1259 VarName=FieldData.ListVarName{VarIndex(1)}%get the first variable of the cell to get the input matrix dimensions 1255 1260 eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions 1256 DimValue(DimValue==1)=[];%remove singleton dimensions 1261 DimValue(DimValue==1)=[];%remove singleton dimensions 1257 1262 NbDim=numel(DimValue);%update number of space dimensions 1258 1263 nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate … … 1270 1275 end 1271 1276 end 1272 AYName=FieldData.ListVarName{VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection) 1273 AXName=FieldData.ListVarName{VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection) 1277 testangle 1278 if testangle% TODO modify name also in case of origin shift in x or y 1279 AYName='Y'; 1280 AXName='X'; 1281 count=0; 1282 %modify coordinate names if they are already used 1283 while ~(isempty(find(strcmp('AXName',ProjData.ListVarName),1)) && isempty(find(strcmp('AYName',ProjData.ListVarName),1))) 1284 count=count+1; 1285 AYName=[AYName '_' num2str(count)]; 1286 AXName=[AXName '_' num2str(count)]; 1287 end 1288 else 1289 AYName=FieldData.ListVarName{VarType.coord(NbDim-1)}%name of input x coordinate (name preserved on projection) 1290 AXName=FieldData.ListVarName{VarType.coord(NbDim)}%name of input y coordinate (name preserved on projection) 1291 end 1274 1292 eval(['AX=FieldData.' AXName ';']) 1275 1293 eval(['AY=FieldData.' AYName ';']) 1276 1294 ListDimName=FieldData.VarDimName{VarIndex(1)}; 1277 ProjData.ListVarName=[ProjData.ListVarName {AYName} {AXName}]; %TODO: check if it already exists in Projdata (several cells) 1278 ProjData.VarDimName=[ProjData.VarDimName {AYName} {AXName}]; 1279 1280 % for idim=1:length(ListDimName) 1281 % DimName=ListDimName{idim}; 1282 % if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i') 1283 % nbcolor=DimValue(idim); 1284 % DimValue(idim)=[]; 1285 % end 1286 % if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED 1287 % DimValue(idim)=[]; 1288 % end 1289 % end 1295 ProjData.ListVarName=[ProjData.ListVarName {AYName} {AXName}]; %TODO: check if it already exists in Projdata (several cells) 1296 ProjData.VarDimName=[ProjData.VarDimName {AYName} {AXName}]; 1290 1297 Coord_z=[]; 1291 1298 Coord_y=[]; 1292 Coord_x=[]; 1293 1299 Coord_x=[]; 1300 1294 1301 for idim=1:NbDim %loop on space dimensions 1295 1302 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default … … 1298 1305 eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field 1299 1306 if numel(Coord{idim})==2 %input array defined on a regular grid 1300 DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);1307 DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim); 1301 1308 else 1302 1309 DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field 1303 1310 DCoord_min(idim)=min(DCoord); 1304 1311 DCoord_max=max(DCoord); 1305 % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise1306 if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000) 1312 % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise 1313 if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000) 1307 1314 msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m']) 1308 1309 end 1315 return 1316 end 1310 1317 test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity 1311 1318 end … … 1321 1328 DY=abs(DCoord_min(NbDim-1)); 1322 1329 end 1323 npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol 1330 npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol 1324 1331 if DX==0 1325 1332 DX=abs(DCoord_min(NbDim)); 1326 1333 end 1327 npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol 1334 npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol 1328 1335 for idim=1:NbDim 1329 1336 if test_interp(idim) 1330 1337 DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri 1331 1338 end 1332 end 1339 end 1333 1340 Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY); 1334 1341 test_direct_y=test_direct(NbDim-1); … … 1336 1343 test_direct_x=test_direct(NbDim); 1337 1344 DAX=DCoord_min(NbDim); 1338 DAY=DCoord_min(NbDim-1); 1345 DAY=DCoord_min(NbDim-1); 1339 1346 minAX=min(Coord_x); 1340 1347 maxAX=max(Coord_x); … … 1374 1381 end 1375 1382 npX=floor((XMax-XMin)/DX+1); 1376 npY=floor((YMax-YMin)/DY+1); 1383 npY=floor((YMax-YMin)/DY+1); 1377 1384 if test_direct_y 1378 1385 coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line … … 1384 1391 else 1385 1392 coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line 1386 end 1387 1393 end 1388 1394 % case with no rotation and interpolation 1389 1395 if isequal(ProjMode,'projection') && ~testangle 1390 1396 if ~testXMin && ~testXMax && ~testYMin && ~testYMax && NbDim==2 1391 ProjData=FieldData; 1397 ProjData=FieldData; 1392 1398 else 1393 1399 indY=NbDim-1; … … 1402 1408 Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1); 1403 1409 Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1); 1404 end 1410 end 1405 1411 if test_direct(NbDim)==1 1406 1412 min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1; … … 1412 1418 max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1; 1413 1419 Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1); 1420 1421 1414 1422 Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1); 1415 end1416 if NbDim==31417 DimCell(1)=[]; %suppress z variable1418 DimValue(1)=[];1419 %structured coordinates1420 if test_direct(1)1421 iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;1422 else1423 iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;1424 end1425 1423 end 1426 1424 min_indy=max(min_indy,1);% deals with margin (bound lower than the first index) 1427 1425 min_indx=max(min_indx,1); 1428 max_indy=min(max_indy,DimValue(1)); 1429 max_indx=min(max_indx,DimValue(2)); 1430 for ivar=VarIndex% loop on non coordinate variables 1431 VarName=FieldData.ListVarName{ivar}; 1432 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1433 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1434 if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar 1435 ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; 1436 end 1426 1427 if test90y 1428 'TEST3D' 1429 ind_new=[3 2 1]; 1430 DimCell=DimCell(ind_new); 1431 DimValue=DimValue(ind_new); 1432 DimCell(1)=[]; %suppress x variable 1433 DimValue(1)=[]; 1434 iz=ceil((ObjectData.Coord(1,1)-Coord{3}(1))/DX)+1; 1435 for ivar=VarIndex 1436 VarName=FieldData.ListVarName{ivar}; 1437 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1438 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1439 ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes 1440 eval(['size(FieldData.' VarName ')']) 1441 eval(['ProjData.' VarName '=permute(FieldData.' VarName ',ind_new)'])% permute x and z indices for 90 degree rotation 1442 eval(['size(ProjData.' VarName ')']) 1443 eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz 1444 end 1445 eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates 1446 eval(['ProjData.' AXName '=[Coord{1}(end),Coord{1}(1)];']) %record the new (projected ) x coordinates 1447 else 1437 1448 if NbDim==3 1438 eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']); 1439 else 1440 eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']); 1441 end 1442 end 1443 eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates 1444 eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates 1449 DimCell(1)=[]; %suppress z variable 1450 DimValue(1)=[]; 1451 if test_direct(1) 1452 iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1; 1453 else 1454 iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1; 1455 end 1456 end 1457 max_indy=min(max_indy,DimValue(1));%introduce bounds in y and x indices 1458 max_indx=min(max_indx,DimValue(2)); 1459 for ivar=VarIndex% loop on non coordinate variables 1460 VarName=FieldData.ListVarName{ivar}; 1461 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1462 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1463 if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar 1464 ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; 1465 end 1466 if NbDim==3 1467 eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']); 1468 else 1469 eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']); 1470 end 1471 end 1472 eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates 1473 eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates 1474 end 1445 1475 end 1446 1476 else % case with rotation and/or interpolation … … 1453 1483 XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line' 1454 1484 YIMA=reshape(round(YIMA),1,npX*npY); 1455 flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image 1485 flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image 1456 1486 if isequal(ObjectData.ProjMode,'filter') 1457 1487 npx_filter=ceil(abs(DX/DAX)); … … 1466 1496 for ivar=VarIndex 1467 1497 VarName=FieldData.ListVarName{ivar}; 1468 if test_interp(1) || test_interp(2)%interpolate on a regular grid 1469 1498 if test_interp(1) || test_interp(2)%interpolate on a regular grid 1499 eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST 1470 1500 end 1471 1501 %filter the field (image) if option 'filter' is used 1472 if test_filter 1473 1474 1475 1476 1477 1478 end 1479 eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line 1502 if test_filter 1503 Aclass=class(FieldData.A); 1504 eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');']) 1505 if ~isequal(Aclass,'double') 1506 eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values 1507 end 1508 end 1509 eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line 1480 1510 %ind_in=find(flagin); 1481 1511 ind_out=find(~flagin); 1482 1512 ICOMB=(XIMA-1)*DimValue(1)+YIMA; 1483 1513 ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A 1484 vec_B(flagin,1:nbcolor)=vec_A(ICOMB,:); 1514 vec_B(flagin,1:nbcolor)=vec_A(ICOMB,:); 1485 1515 for icolor=1:nbcolor 1486 1516 vec_B(ind_out,icolor)=zeros(size(ind_out)); … … 1490 1520 if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar 1491 1521 ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar}; 1492 end 1522 end 1493 1523 eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']); 1494 1524 end 1495 ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur 1525 ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur 1496 1526 ProjData.ListVarName=[ProjData.ListVarName 'FF']; 1497 1527 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1498 1528 ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag'; 1499 else %3D case 1500 if ~testangle 1501 % unstructured z coordinate 1502 test_sup=(Coord{1}>=ObjectData.Coord(1,3)); 1503 iz_sup=find(test_sup); 1504 iz=iz_sup(1); 1505 if iz>=1 & iz<=npz 1506 %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)]; 1507 %ProjData.DimValue=[ProjData.DimValue npY npX]; 1508 for ivar=VarIndex 1509 VarName=FieldData.ListVarName{ivar}; 1510 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1511 ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes 1512 eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz 1513 %TODO : do a vertical average for a thick plane 1514 if test_interp(2) || test_interp(3) 1515 eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');']) 1516 end 1529 elseif ~testangle 1530 % unstructured z coordinate 1531 test_sup=(Coord{1}>=ObjectData.Coord(1,3)); 1532 iz_sup=find(test_sup); 1533 iz=iz_sup(1); 1534 if iz>=1 & iz<=npz 1535 %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)]; 1536 %ProjData.DimValue=[ProjData.DimValue npY npX]; 1537 for ivar=VarIndex 1538 VarName=FieldData.ListVarName{ivar}; 1539 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1540 ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes 1541 eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz 1542 %TODO : do a vertical average for a thick plane 1543 if test_interp(2) || test_interp(3) 1544 eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');']) 1517 1545 end 1518 1546 end 1519 e lse1520 errormsg='projection of structured coordinates on oblique plane not yet implemented';1521 %TODO: use interp31522 return1523 end1524 end 1525 end 1526 end 1527 1547 end 1548 else 1549 errormsg='projection of structured coordinates on oblique plane not yet implemented'; 1550 %TODO: use interp3 1551 return 1552 end 1553 end 1554 end 1555 1528 1556 %% projection of velocity components in the rotated coordinates 1529 1557 if testangle && length(ivar_U)==1 … … 1533 1561 end 1534 1562 UName=FieldData.ListVarName{ivar_U}; 1535 VName=FieldData.ListVarName{ivar_V}; 1563 VName=FieldData.ListVarName{ivar_V}; 1536 1564 eval(['ProjData.' UName '=cos(PlaneAngle(3))*ProjData.' UName '+ sin(PlaneAngle(3))*ProjData.' VName ';']) 1537 1565 eval(['ProjData.' VName '=cos(Theta)*(-sin(PlaneAngle(3))*ProjData.' UName '+ cos(PlaneAngle(3))*ProjData.' VName ');']) 1538 1566 if ~isempty(ivar_W) 1539 1567 WName=FieldData.ListVarName{ivar_W}; 1540 eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])% 1568 eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])% 1541 1569 eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']); 1542 1570 end … … 1857 1885 VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions 1858 1886 eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions 1859 DimValue( find(DimValue==1))=[];%remove singleton dimensions1887 DimValue(DimValue==1)=[];%remove singleton dimensions 1860 1888 NbDim=numel(DimValue);%update number of space dimensions 1861 1889 nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate … … 1865 1893 return 1866 1894 else 1867 VarType.coord1868 1895 if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate 1869 1896 nbcolor=DimValue(3); -
trunk/src/read_field.m
r221 r227 31 31 ParamOut=[]; 32 32 errormsg=''; 33 %FieldName=ParamIn.FieldName;34 33 VelType=ParamIn.VelType; 35 34 … … 42 41 end 43 42 test_civx=0; 44 if ~strcmp(ParamOut.FieldName,'get_field...')% if get_field is not requested, look for Civx data 43 ParamIn 44 if ~strcmp(ParamIn.FieldName,'get_field...')% if get_field is not requested, look for Civx data 45 45 FieldList=calc_field;%list of possible fields for Civx data 46 46 ParamOut.ColorVar='';%default 47 47 field_index=strcmp(ParamOut.FieldName,FieldList);%look for ParamOut.FieldName in the list 48 48 if isempty(find(field_index,1))% ParamOut.FieldName is not in the list, check whether Civx data exist 49 Data=nc2struct(ObjectName,'ListGlobalAttribute','absolut_time_T0','civ'); 49 'TESTnc1' 50 Data=nc2struct(ObjectName,'ListGlobalAttribute','absolut_time_T0','civ') 50 51 if ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0) 51 52 ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default … … 83 84 set(hhget_field.inputfile,'String',ObjectName) 84 85 set(hhget_field.list_fig,'Value',1) 86 if exist('num','var')&&~isnan(num) 87 set(hhget_field.TimeIndexValue,'String',num2str(num)) 88 end 85 89 funct_list=get(hhget_field.ACTION,'UserData'); 86 90 funct_index=get(hhget_field.ACTION,'Value'); … … 107 111 end 108 112 end 109 set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field113 %set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field 110 114 ParamOut.CivStage=0; 111 115 ParamOut.VelType=[]; 116 if isfield(Field,'TimeIndex') 117 ParamOut.TimeIndex=Field.TimeIndex; 118 end 119 if isfield(Field,'TimeValue') 120 ParamOut.TimeValue=Field.TimeValue; 121 end 112 122 end 113 123 if test_civx … … 127 137 A=read(ObjectName,num); 128 138 FieldName='image'; 129 catch 130 errormsg= lasterr;139 catch ME 140 errormsg=ME.message; 131 141 return 132 142 end … … 134 144 try 135 145 mov=aviread(ObjectName,num); 136 catch 137 errormsg= lasterr;146 catch ME 147 errormsg=ME.message; 138 148 return 139 149 end -
trunk/src/read_get_field.m
r206 r227 124 124 return 125 125 end 126 val=get(handles.scalar,'Value');%selected ind ices in the ordinate listbox127 VarNameScalar=inputlist{val}; %name of the variable in the list126 val=get(handles.scalar,'Value');%selected index for the scalar variable 127 VarNameScalar=inputlist{val}; %name of the variable 128 128 VarIndexA=name2index(VarNameScalar,Field.ListVarName);%index of the variable in ListVarName 129 dimname_A=Field.VarDimName{VarIndexA}; 129 dimname_A=Field.VarDimName{VarIndexA};% list of dimension names for the scalar variable (cell array) 130 %remove time dimension if defined 131 TimeVarIndex=[]; %default 132 if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on') 133 dim_list=get(handles.TimeDimensionMenu,'String'); 134 dim_index=get(handles.TimeDimensionMenu,'Value'); 135 Time_dim=dim_list{dim_index}; 136 TimeVarIndex=find(strcmp(Time_dim,dimname_A),1); 137 if ~isempty(TimeVarIndex) 138 dimname_A(TimeVarIndex)=[]; 139 end 140 end 130 141 nbvar=nbvar+1; 131 142 ListVarName{nbvar}=Field.ListVarName{VarIndexA}; … … 157 168 if iscell(dimname_x) 158 169 if numel(dimname_x)==1 159 dimname_x=dimname_x{1};%transform to char chain 170 %dimname_x=dimname_x{1};%transform to char chain 171 elseif numel(dimname_x)==2 172 index1_x = find(strcmp(dimname_x{1},dimname_A));%index of diname_x(1) in dimname_A 173 index2_x = find(strcmp(dimname_x{2},dimname_A));%index of diname_x(2) in dimname_A 160 174 else 161 175 errormsg='invalid x coordinate selection in get_field'; … … 190 204 if numel(dimname_y)==1 191 205 dimname_y=dimname_y{1};%transform to char chain 206 elseif numel(dimname_y)==2 207 index1_y = find(strcmp(dimname_y{1},dimname_A));%index of diname_x(1) in dimname_A 208 index2_y = find(strcmp(dimname_y{2},dimname_A));%index of diname_x(2) in dimname_A 192 209 else 193 210 errormsg='invalid y coordinate selection in get_field'; … … 214 231 nbvar=nbvar+1; 215 232 ListVarName{nbvar}=Field.ListVarName{VarIndex}; 216 VarDimName{nbvar}=dimname_ y;233 VarDimName{nbvar}=dimname_z; 217 234 if numel(VarAttribute)>=VarIndex 218 235 SubVarAttribute{nbvar}=VarAttribute{VarIndex}; 219 236 end 220 237 %check consistency of dimensions 221 if ~isequal(dimname_ y,dimname_A)% case of dimension variables222 if iscell(dimname_ y)223 if numel(dimname_ y)==1224 dimname_ y=dimname_y{1};%transform to char chain238 if ~isequal(dimname_z,dimname_A)% case of dimension variables 239 if iscell(dimname_z) 240 if numel(dimname_z)==1 241 dimname_z=dimname_z{1};%transform to char chain 225 242 else 226 errormsg='invalid ycoordinate selection in get_field';243 errormsg='invalid z coordinate selection in get_field'; 227 244 return 228 245 end … … 432 449 end 433 450 end 451 452 453 434 454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 435 436 % get the input field 455 %% get the input field 437 456 inputfield=get(handles.inputfile,'String'); 438 457 if exist(inputfield,'file')% read the input data corresponding to the list of selected varaibles … … 443 462 SubField.VarDimName=VarDimName; 444 463 end 445 SubField.ListGlobalAttribute=['InputFile' SubField.ListGlobalAttribute]; 464 if strcmp(get(handles.TimeIndexValue,'Visible'),'on') && ~isempty(get(handles.TimeIndexValue,'String')) 465 SubField.ListGlobalAttribute=[{'TimeIndex'} SubField.ListGlobalAttribute]; 466 SubField.TimeIndex=str2double(get(handles.TimeIndexValue,'String')); 467 end 468 TimeValue=NaN; 469 if strcmp(get(handles.TimeVarValue,'Visible'),'on') 470 TimeValue=str2double(get(handles.TimeVarValue,'String')); 471 elseif strcmp(get(handles.TimeValue,'Visible'),'on') 472 TimeValue=str2double(get(handles.TimeValue,'String')); 473 end 474 if ~isnan(TimeValue) 475 SubField.ListGlobalAttribute=[{'TimeValue'} SubField.ListGlobalAttribute]; 476 SubField.TimeValue=str2double(get(handles.TimeVarValue,'String')); 477 end 478 SubField.ListGlobalAttribute=[{'InputFile'} SubField.ListGlobalAttribute]; 446 479 SubField.InputFile=get(handles.inputfile,'String'); 447 480 SubField.VarAttribute=SubVarAttribute; … … 453 486 DimCellA=Field.VarDimName{VarIndexA}; %dimension names for the scalar variable 454 487 eval(['npxy=size(SubField.' VarNameA ');'])%zize of the scalar variable 488 % if ~isempty(TimeVarIndex)% 489 % DimCellA(TimeVarIndex)=[];%suppress the time dimension 490 % npxy(TimeVarIndex)=[]; 491 % end 455 492 SingleCellA={}; 456 493 if numel(npxy) < numel(DimCellA) … … 461 498 DimCellA=DimCellA(ind_select);%dimension names for the scalar variable, after removing singletons 462 499 npxy=npxy(ind_select); 500 % if ~isempty(TimeVarIndex)% 501 % DimCellA(TimeVarIndex)=[];%suppress the time dimension 502 % npxy(TimeVarIndex)=[]; 503 % end 504 NbDim=numel(npxy); 463 505 dimA=[]; 464 if test_zdimvar %dim_x && dim_y && ~isempty(VarSubIndexA)506 if test_zdimvar 465 507 NbDim=3;% field considered as 3D if a z coordinate is defined (to distinguish for instance from 2D color images with 3 components) 466 508 ind_singleton=find(strcmp(dimname_z,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions … … 472 514 dimA=[dimA icoord]; 473 515 end 474 if test_ydimvar %dim_x && dim_y && ~isempty(VarSubIndexA)516 if test_ydimvar 475 517 ind_singleton=find(strcmp(dimname_y,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions 476 518 if ~isempty(ind_singleton) … … 481 523 dimA=[dimA icoord]; 482 524 end 483 if test_xdimvar 484 ind_singleton=find(strcmp(dimname_x ,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions485 if ~isempty(ind_singleton) 525 if test_xdimvar% a varible has been selected for x coordinate 526 ind_singleton=find(strcmp(dimname_x{1},SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions 527 if ~isempty(ind_singleton) 486 528 errormsg=['the singleton dimension ' dimname_x ' has been selected for ordinate']; 487 529 return 488 530 end 489 icoord=find(strcmp(dimname_x ,DimCellA),1);% a dimension variable531 icoord=find(strcmp(dimname_x{1},DimCellA),1);% a dimension variable 490 532 dimA=[dimA icoord]; 491 533 end 492 dimextra=(1:numel(DimCellA)); 493 dimextra(dimA)=[]; %list of unselected dimension indices 534 dimextra=(1:numel(DimCellA)); %list of initial dimension indices 535 if isempty(TimeVarIndex)% 536 dimextra(dimA)=[]; %list of unselected dimension indices 537 DimCellA=DimCellA([dimA dimextra]); 538 eval(['SubField.' VarNameA '=squeeze(SubField.' VarNameA ');']) 539 if ~isempty(dimA)&& ~isempty(dimextra) 540 eval(['SubField.' VarNameA '=permute(SubField.' VarNameA ',[dimA dimextra]);']) 541 end 542 else 543 time_index=str2double(get(handles.TimeIndexValue,'String')); 544 dimextra([dimA TimeVarIndex])=[]; 545 %DimCellA=DimCellA([dimA dimextra TimeVarIndex])%put the time dimension at the end 546 eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra TimeVarIndex]);'])%put time variable as the last dimension 547 nbdimA=numel(dimA)+numel(dimextra); 548 switch nbdimA 549 case 1 550 colon_str='(:'; 551 case 2 552 colon_str='(:,:'; 553 case 3 554 colon_str='(:,:,:'; 555 end 556 eval(['SubField.' VarNameA '=SubField.' VarNameA colon_str ',time_index);']) 557 NbDim=NbDim-1; 558 end 494 559 DimCellA=DimCellA([dimA dimextra]); 495 eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra]);'])496 560 SubField.VarDimName{VarSubIndexA}=DimCellA; 497 561 %add default coord_x and/or coord_y if empty 498 562 if empty_coord_x || empty_coord_y 499 VarName=Field.ListVarName{field_var_index};500 DimCell=Field.VarDimName{field_var_index};501 eval(['npxy=size(SubField.' VarName ');'])502 if numel(npxy) < numel(DimCell )503 DimCell =DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions563 %VarName=Field.ListVarName{field_var_index} 564 %DimCell=Field.VarDimName{field_var_index} 565 eval(['npxy=size(SubField.' VarNameA ')']) 566 if numel(npxy) < numel(DimCellA) 567 DimCellA=DimCellA(end-numel(npxy)+1:end); %suppress the first singletons) dimensions 504 568 end 505 569 ind_select=find(npxy~=1) ;%look for non singleton dimensions 506 DimCell =DimCell(ind_select);%list of dimension names for the scalar, after singleton removal570 DimCellA=DimCellA(ind_select);%list of dimension names for the scalar, after singleton removal 507 571 npxy=npxy(ind_select); 508 572 testold=0; … … 516 580 end 517 581 if empty_coord_x 518 coord_x_name=DimCell {NbDim};582 coord_x_name=DimCellA{NbDim}; 519 583 SubField.ListVarName=[{coord_x_name} SubField.ListVarName]; 520 584 SubField.VarDimName=[{coord_x_name} SubField.VarDimName]; … … 533 597 end 534 598 if empty_coord_y 535 coord_y_name=DimCell {NbDim-1};599 coord_y_name=DimCellA{NbDim-1}; 536 600 SubField.ListVarName=[{coord_y_name} SubField.ListVarName]; 537 601 SubField.VarDimName=[{coord_y_name} SubField.VarDimName]; … … 547 611 end 548 612 SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute]; 613 end 614 if empty_coord_z && NbDim==3 615 coord_z_name=DimCellA{NbDim-2}; 616 SubField.ListVarName=[{coord_z_name} SubField.ListVarName]; 617 SubField.VarDimName=[{coord_z_name} SubField.VarDimName]; 618 if testold 619 eval(['SubField.' coord_z_name '=linspace(Coord_3(1),Coord_3(end),npxy(1));']) 620 else 621 eval(['SubField.' coord_z_name '=[0.5 npxy(NbDim-2)-0.5];']) 622 end 623 if ~testold 624 coord_z_attr.units='index'; 625 else 626 coord_z_attr.units='cm'; 627 end 628 SubField.VarAttribute=[{coord_z_attr} SubField.VarAttribute]; 549 629 end 550 630 end … … 714 794 end 715 795 796 %% remove time variable 797 if get(handles.TimeDimension,'Value') 798 799 % TimeName=get(handles.TimeName,'String'); 800 % time_index=find(strcmp(TimeName,SubField.ListVarName),1); 801 % SubField.ListVarName(TimeVarIndex)=[]; 802 % SubField.VarDimName(TimeVarIndex)=[]; 803 % SubField.VarAttribute(TimeVarIndex)=[]; 804 end 805 806 716 807 %------------------------------------------------- 717 808 % give index numbers of the strings str in the list ListvarName -
trunk/src/set_object.m
r215 r227 766 766 767 767 %% plot the field projected on the object and store in the corresponding figue 768 ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData 768 [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData 769 if ~isempty(errormsg) 770 msgbox_uvmat('ERROR', errormsg) 771 return 772 end 769 773 PlotParam=read_plot_param(PlotHandles); 770 774 [PlotType,Object_out{IndexObj}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot … … 846 850 end 847 851 msgbox_uvmat('CONFIRMATION',[answer{1} ' saved']) 848 %------------------------------------------------------------------------ 852 849 853 %------------------------------------------------------------------------ 850 854 % --- Executes on slider movement. … … 853 857 Z_value=get(handles.z_slider,'Value'); 854 858 %rotation angles 855 PlaneAngle(1)=str2num(get(handles.Phi,'String'));%first angle in degrees 856 PlaneAngle(2)=str2num(get(handles.Theta,'String'));%second angle in degrees 857 PlaneAngle(3)=str2num(get(handles.Psi,'String'));%second angle in degrees 859 PlaneAngle=[0 0 0]; 860 norm_plane=[0 0 1]; 861 cos_om=1; 862 sin_om=0; 863 864 PlaneAngle(1)=str2double(get(handles.Phi,'String'));%first angle in degrees 865 PlaneAngle(2)=str2double(get(handles.Theta,'String'));%second angle in degrees 866 PlaneAngle(3)=str2double(get(handles.Psi,'String'));%second angle in degrees 867 PlaneAngle=(pi/180)*PlaneAngle; 858 868 om=norm(PlaneAngle);%norm of rotation angle in radians 859 OmAxis=PlaneAngle/om; %unit vector marking the rotation axis 860 cos_om=cos(pi*om/180); 861 sin_om=sin(pi*om/180); 862 coeff=OmAxis(3)*(1-cos_om); 863 %components of the unity vector norm_plane normal to the projection plane 864 norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om; 865 norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; 866 norm_plane(3)=OmAxis(3)*coeff+cos_om; 869 if isequal(om,0) 870 norm_plane=[0 0 1]; 871 else 872 OmAxis=PlaneAngle/om; %unit vector marking the rotation axis 873 cos_om=cos(om); 874 sin_om=sin(om); 875 coeff=OmAxis(3)*(1-cos_om); 876 %components of the unity vector norm_plane normal to the projection plane 877 norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om; 878 norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om; 879 norm_plane(3)=OmAxis(3)*coeff+cos_om; 880 end 867 881 868 882 %set new plane position and update graph … … 871 885 set(handles.ZObject,'String',num2str(norm_plane(3)*Z_value,4)) 872 886 PLOT_Callback(hObject, eventdata, handles) 873 %------------------------------------------------------------------------ 887 874 888 %------------------------------------------------------------------------ 875 889 % --- Executes on button press in HELP. 876 890 function HELP_Callback(hObject, eventdata, handles) 891 %------------------------------------------------------------------------ 877 892 path_to_uvmat=which ('uvmat');% check the path of uvmat 878 893 pathelp=fileparts(path_to_uvmat); -
trunk/src/uvmat.m
r221 r227 232 232 233 233 %% refresh projection plane 234 %UvData.Object{1}.Style='plane';%main plotting plane235 234 UvData.Object{1}.ProjMode='projection';%main plotting plane 236 % if ~isfield(UvData.Object{1},'plotaxes')237 % UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis238 % set(handles.list_object_1,'Value',1);239 % % set(handles.list_object_1,'String',{'1-PLANE'});240 % set(handles.list_object_1,'String',{''});241 % end242 235 set(handles.Fields,'Value',1) 243 236 set(handles.Fields,'string',{''}) … … 331 324 inputfile=input.InputFile; 332 325 end 333 Field=input; 326 if isfield(Field,'TimeIndex') 327 set(handles.i1,num2str(Field.TimeIndex)) 328 end 334 329 elseif ischar(input)% file name introduced as input 335 330 inputfile=input; … … 347 342 end 348 343 if ~isempty(inputfile) 349 %%%%% display the in dput field %%%%%%%344 %%%%% display the input field %%%%%%% 350 345 display_file_name(hObject, eventdata, handles,inputfile) 351 346 %%%%%%% … … 366 361 end 367 362 end 368 % set(handles.uvmat,'UserData',UvData)369 363 370 364 %% plot input field if exists … … 437 431 '*.*', 'All Files (*.*)'}, ... 438 432 'Pick a file',oldfile); 439 %global filebase440 433 fileinput=[PathName FileName];%complete file name 441 % testblank=findstr(fileinput,' ');%look for blanks442 % if ~isempty(testblank)443 % msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])444 % return445 % end446 434 sizf=size(fileinput); 447 435 if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end … … 484 472 % --- Open again the file whose name has been recorded in MenuFile_1 485 473 function MenuFile_1_Callback(hObject, eventdata, handles) 474 %------------------------------------------------------------------------ 486 475 fileinput=get(handles.MenuFile_1,'Label'); 487 476 display_file_name(hObject, eventdata, handles,fileinput) … … 490 479 % --- Open again the file whose name has been recorded in MenuFile_2 491 480 function MenuFile_2_Callback(hObject, eventdata, handles) 481 %------------------------------------------------------------------------ 492 482 fileinput=get(handles.MenuFile_2,'Label'); 493 483 display_file_name(hObject, eventdata, handles,fileinput) … … 496 486 % --- Open again the file whose name has been recorded in MenuFile_3 497 487 function MenuFile_3_Callback(hObject, eventdata, handles) 488 %------------------------------------------------------------------------ 498 489 fileinput=get(handles.MenuFile_3,'Label'); 499 490 display_file_name(hObject, eventdata, handles,fileinput) … … 502 493 % --- Open again the file whose name has been recorded in MenuFile_4 503 494 function MenuFile_4_Callback(hObject, eventdata, handles) 495 %------------------------------------------------------------------------ 504 496 fileinput=get(handles.MenuFile_4,'Label'); 505 497 display_file_name(hObject, eventdata, handles,fileinput) … … 508 500 % --- Open again the file whose name has been recorded in MenuFile_5 509 501 function MenuFile_5_Callback(hObject, eventdata, handles) 502 %------------------------------------------------------------------------ 510 503 fileinput=get(handles.MenuFile_5,'Label'); 511 504 display_file_name(hObject, eventdata, handles,fileinput) … … 514 507 % --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput' 515 508 function display_file_name(hObject, eventdata, handles,fileinput) 509 %------------------------------------------------------------------------ 516 510 if ~exist(fileinput,'file') 517 511 msgbox_uvmat('ERROR',['input file ' fileinput ' does not exist']) … … 871 865 % set default options in menu 'Fields' 872 866 873 if testima 874 elseif isequal(FileExt,'.nc')||isequal(FileExt,'.cdf') 875 Data=nc2struct(FileName,'ListGlobalAttribute','absolut_time_T0','civ'); 876 %col_vec=get(handles.col_vec,'String'); 877 if ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)%if the new input is Civx 878 FieldList=calc_field; 879 set(handles.Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data 880 set(handles.Fields,'Value',2) % set menu to 'velocity' 881 col_vec=FieldList; 882 col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar) 883 else %general netcdf file (not civx) 884 set(handles.Fields,'Value',1) % set menu to 'get_field... 885 set(handles.Fields,'String',{'get_field...'}) 886 col_vec={'get_field...'}; 887 hget_field=findobj('Name','get_field'); 888 if ~isempty(hget_field)%delete any existing get_field GUI for reinitialisation withthe new file series 889 hhget_field=guidata(hget_field); 890 if ~strcmp(get(hhget_field.inputfile,'String'),FileName)%delete any existing get_field GUI with file name different than the input 891 delete(hget_field) 892 end 893 end 894 end 895 set(handles.col_vec,'String',col_vec) 896 else 897 msgbox_uvmat('ERROR',['invalid input file extension ' FileExt]) 898 return 899 end 867 if ~testima 868 testcivx=0; 869 hget_field=findobj('Name','get_field'); 870 % if isequal(FileExt,'.nc')||isequal(FileExt,'.cdf') 871 if isempty(hget_field) 872 Data=nc2struct(FileName,'ListGlobalAttribute','absolut_time_T0','civ'); 873 if ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)%if the new input is Civx 874 FieldList=calc_field; 875 set(handles.Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data 876 set(handles.Fields,'Value',2) % set menu to 'velocity' 877 col_vec=FieldList; 878 col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar) 879 testcivx=1; 880 end 881 else 882 hhget_field=guidata(hget_field); 883 if ~strcmp(get(hhget_field.inputfile,'String'),FileName)%delete any existing get_field GUI with file name different than the input 884 delete(hget_field) 885 end 886 end 887 if ~testcivx 888 set(handles.Fields,'Value',1) % set menu to 'get_field... 889 set(handles.Fields,'String',{'get_field...'}) 890 col_vec={'get_field...'}; 891 end 892 set(handles.col_vec,'String',col_vec) 893 % else 894 % msgbox_uvmat('ERROR',['invalid input file extension ' FileExt]) 895 % return 896 % end 897 end 900 898 901 899 %% set index navigation options and refresh plots … … 1391 1389 set(handles.scan_i,'Value',0) 1392 1390 set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784]) 1393 NomType=get(handles.FileIndex,'UserData') 1391 NomType=get(handles.FileIndex,'UserData'); 1394 1392 switch NomType 1395 1393 case {'_i_j1-j2','#_ab','%3dab'},% pair with j index … … 2047 2045 num_j1=stra2num(get(handles.j1,'String')); 2048 2046 num_j2=stra2num(get(handles.j2,'String')); 2047 2049 2048 errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2); 2049 2050 2050 if ~isempty(errormsg) 2051 2051 msgbox_uvmat('ERROR',errormsg); … … 2167 2167 set(handles.npx,'String',num2str(ParamOut.Npx));% display image size on the interface 2168 2168 set(handles.npy,'String',num2str(ParamOut.Npy)); 2169 end 2170 if isfield(ParamOut,'TimeIndex') 2171 set(handles.i1,'String',num2str(ParamOut.TimeIndex)) 2172 end 2173 if isfield(ParamOut,'TimeValue') 2174 Field{1}.Time=ParamOut.TimeValue; 2169 2175 end 2170 2176 end … … 2434 2440 end 2435 2441 if exist('XName','var') 2436 eval(['XMax=max( UvData.Field.' XName ');'])2437 eval(['XMin=min( UvData.Field.' XName ');'])2442 eval(['XMax=max(max(UvData.Field.' XName '));']) 2443 eval(['XMin=min(min(UvData.Field.' XName '));']) 2438 2444 UvData.Field.NbDim=NbDim; 2439 2445 UvData.Field.XMax=XMax; 2440 2446 UvData.Field.XMin=XMin; 2441 2447 if NbDim >1 2442 eval(['YMax=max( UvData.Field.' YName ');'])2443 eval(['YMin=min( UvData.Field.' YName ');'])2448 eval(['YMax=max(max(UvData.Field.' YName '));']) 2449 eval(['YMin=min(min(UvData.Field.' YName '));']) 2444 2450 UvData.Field.YMax=YMax; 2445 2451 UvData.Field.YMin=YMin; … … 3256 3262 % transform netc type to the corresponding image type 3257 3263 % set(handles.FileExt_1,'String','.png'); 3258 if isequal(NomType_1,'_i1-i2_j')| isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')3264 if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')|| isequal(NomType_1,'#_ab')|| isequal(NomType_1,'_i1-i2') 3259 3265 UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory 3260 3266 % set(handles.SubDir_1,'String','') 3261 3267 % set(handles.FileExt_1,'String','.png'); 3262 if isequal(NomType_1,'_i1-i2_j')| isequal(NomType_1,'_i_j1-j2')3268 if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2') 3263 3269 NomTypeNew='_i_j'; 3264 3270 elseif isequal(NomType_1,'#_ab') … … 4079 4085 set(handles.FixScal,'Value',1) %suppress auto mode 4080 4086 set(handles.FixScal,'BackgroundColor',[1 1 0]) 4087 MinA=str2double(get(handles.MinA,'String')); 4088 MaxA=str2double(get(handles.MaxA,'String')); 4089 if MinA>MaxA% switch minA and maxA in case of error 4090 MinA_old=MinA; 4091 MinA=MaxA; 4092 MaxA=MinA_old; 4093 set(handles.MinA,'String',num2str(MinA,5)); 4094 set(handles.MaxA,'String',num2str(MaxA,5)); 4095 end 4081 4096 update_plot(handles); 4082 4097 … … 4086 4101 set(handles.FixScal,'Value',1) %suppress auto mode 4087 4102 set(handles.FixScal,'BackgroundColor',[1 1 0]) 4103 MinA=str2double(get(handles.MinA,'String')); 4104 MaxA=str2double(get(handles.MaxA,'String')); 4105 if MinA>MaxA% switch minA and maxA in case of error 4106 MinA_old=MinA; 4107 MinA=MaxA; 4108 MaxA=MinA_old; 4109 set(handles.MinA,'String',num2str(MinA,5)); 4110 set(handles.MaxA,'String',num2str(MaxA,5)); 4111 end 4088 4112 update_plot(handles); 4089 4113
Note: See TracChangeset
for help on using the changeset viewer.