Changeset 227 for trunk/src


Ignore:
Timestamp:
Mar 31, 2011, 1:42:51 PM (13 years ago)
Author:
sommeria
Message:

add function sub_field_series to apply the sub_field operation to a series of fileds (for instance subtracting a background to an image series)

Location:
trunk/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r225 r227  
    123123    catch
    124124        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
     125        return
    125126    end
    126127else
    127128    errormsg=[xmlfile ' not found: path to civx binaries undefined'];
     129    return
    128130end
    129131
     
    13211323set(gcf,'Pointer','arrow')
    13221324
    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
    14681326
    14691327
     
    15861444status_Callback(hObject, eventdata, handles)
    15871445end
     1446
    15881447%------------------------------------------------------------------------
    15891448% --- Lauch command called by RUN and BATCH: remote processing
     
    16451504%% set the list of files and check them
    16461505display('checking the files...')
     1506[ref_i,ref_j,errormsg]=find_ref_indices(handles);
     1507if ~isempty(errormsg)
     1508    msgbox_uvmat('ERROR',errormsg)
     1509    return
     1510end
    16471511[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);
    16491513set(handles.civ,'UserData',filecell);%store for futur use of status callback
    16501514if isempty(filecell)% (error message displayed in fct set_civ_filenames)
     
    16531517nbfield=numel(num1_civ1);
    16541518nbslice=numel(num_a_civ1);
    1655 
    16561519
    16571520%% read names of the .exe files for PIV and patch
     
    22482111        else       %run PIVlab if selected
    22492112            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, []);
    22522133               Data.ListGlobalAttribute={'title','Time','Dt'};
    22532134               Data.title='PIVlab';
     
    23122193saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
    23132194
    2314 
    2315 
    2316 
     2195%------------------------------------------------------------------------
     2196% --- determine the list of reference indices of processing file
     2197function [ref_i,ref_j,errormsg]=find_ref_indices(handles)
     2198%------------------------------------------------------------------------
     2199errormsg=''; %default error message
     2200first_i=str2double(get(handles.first_i,'String'));%first index i
     2201last_i=str2double(get(handles.last_i,'String'));%last index i
     2202incr_i=str2double(get(handles.incr_i,'String'));% increment
     2203if 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
     2207else
     2208    first_j=1;
     2209    last_j=1;
     2210    incr_j=1;
     2211end
     2212ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair)
     2213ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair)
     2214if isnan(first_i)||isnan(first_j)
     2215    errormsg='first field number not defined';
     2216elseif isnan(last_i)||isnan(last_j)
     2217    errormsg='last field number not defined';
     2218elseif isnan(incr_i)||isnan(incr_j)
     2219    errormsg='increment in field number not defined';
     2220elseif last_i < first_i || last_j < first_j
     2221    errormsg='last field number must be larger than the first one';
     2222end
     2223
     2224%------------------------------------------------------------------------
     2225% --- determine the list of filenames and indices needed for launch_job
    23172226function [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)
    23192228%------------------------------------------------------------------------
    23202229filecell=[];%default
     
    23512260if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
    23522261[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);
    23542263%determine the new filebase for 'displacement' mode (comparison of two series)
    23552264filebase_B=filebase;% root name of the second field series for stereo
     
    30342943
    30352944%------------------------------------------------------------------------
     2945% --- determine the list of index pairs of processing file
     2946function [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
     2950list_civ1=get(handles.list_pair_civ1,'String');
     2951index_civ1=get(handles.list_pair_civ1,'Value');
     2952str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
     2953if isempty(str_civ1)||isequal(str_civ1,'')
     2954    msgbox_uvmat('ERROR','no image pair selected for civ1')
     2955    return
     2956end
     2957list_civ2=get(handles.list_pair_civ2,'String');
     2958index_civ2=get(handles.list_pair_civ2,'Value');
     2959if index_civ2>length(list_civ2)
     2960    list_civ2=list_civ1;
     2961    index_civ2=index_civ1;
     2962end
     2963str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
     2964
     2965if 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
     2994elseif 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
     3021elseif 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);
     3031elseif 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;
     3040end
     3041
     3042
     3043%------------------------------------------------------------------------
    30363044% --- PATCH
    30373045function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin)
     
    45964604test_civ1=get(handles.TestCiv1,'Value');
    45974605if 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
    45984612    [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]);
    46004614    Data.ListVarName={'ny','nx','A'};
    46014615    Data.VarDimName={'ny','nx',{'ny','nx'}};
     
    46034617    Data.ny=[size(Data.A,1) 1];
    46044618    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);
    46054639    hh=view_field(Data);
     4640    set(0,'CurrentFigure',hh)
     4641    plot(PointCoord(:,2),PointCoord(:,1),'+')
    46064642    ViewData=get(hh,'UserData');
    46074643    ViewData.axes3.B=imread(filecell.ima2.civ1{1});%store the second image in the UserData of the GUI view_field
     
    46524688filecell=get(handles.civ,'UserData');
    46534689if ~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
    46554696end
    46564697
  • trunk/src/delete_object.m

    r156 r227  
    4444        end
    4545        UvData.Object(hObject)=[]; 
    46         list_str(hObject)=[];
     46        if ~isempty(list_str)
     47            list_str(hObject)=[];
     48        end
    4749    end
    4850elseif ishandle(hObject)%object handle
  • trunk/src/geometry_calib.m

    r213 r227  
    441441%------------------------------------------------------------------------
    442442% determine the parameters for a calibration by a linear transform matrix (rescale and rotation)
    443 function GeometryCalib=calib_linear(Coord,handles) %TO UPDATE
     443function GeometryCalib=calib_linear(Coord,handles)
    444444%------------------------------------------------------------------------
    445445X=Coord(:,1);
     
    461461GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1);
    462462GeometryCalib.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];
     464GeometryCalib.Tx_Ty_Tz=[a_X1(1)/GeometryCalib.fx_fy(1) a_Y1(1)/GeometryCalib.fx_fy(2) 1];
    464465R(1,:)=R(1,:)/GeometryCalib.fx_fy(1);
    465466R(2,:)=R(2,:)/GeometryCalib.fx_fy(2);
     
    10301031ind_sub_x=round(XLim);
    10311032ind_sub_y=np(1)-round(YLim);
    1032 Mfiltre=AxeData.A([ind_sub_y(2):ind_sub_y(1)] ,ind_sub_x,:);
     1033Mfiltre=AxeData.A(ind_sub_y(2):ind_sub_y(1) ,ind_sub_x,:);
    10331034Mfiltre_norm=double(Mfiltre);
    10341035Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm));
     
    10641065if ~isempty(ObjectData.Coord)
    10651066    if isequal(option,'phys')
    1066         ObjectData.Coord=ObjectData.Coord(:,[1:3]);
     1067        ObjectData.Coord=ObjectData.Coord(:,1:3);
    10671068    elseif isequal(option,'px')||isequal(option,'')
    1068         ObjectData.Coord=ObjectData.Coord(:,[4:5]);
     1069        ObjectData.Coord=ObjectData.Coord(:,4:5);
    10691070    else
    10701071        msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be '''', px or phys ')
     
    11351136function MenuDetectGrid_Callback(hObject, eventdata, handles)
    11361137%------------------------------------------------------------------------
    1137 %% initiate the grid
    1138 CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
    1139 grid_input=[];%default
    1140 if isfield(CalibData,'grid')
    1141     grid_input=CalibData.grid;%retrieve the previously used grid
    1142 end
    1143 [T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
    1144 set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
    1145 
    11461138%% read the four last point coordinates in pixels
    11471139Coord_cell=get(handles.ListCoord,'String');%read list of coordinates on geometry_calib
     
    11491141nbpoints=size(data.Coord,1); %nbre of calibration points
    11501142if 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')
    11521144    return
    11531145end
     
    11651157      corners_Y(3)=Y_end;
    11661158end
     1159
     1160%% initiate the grid
     1161CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
     1162grid_input=[];%default
     1163if isfield(CalibData,'grid')
     1164    grid_input=CalibData.grid;%retrieve the previously used grid
     1165end
     1166[T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
     1167set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
     1168
     1169
    11671170
    11681171%% read the current image, displayed in the GUI uvmat
  • trunk/src/get_field.m

    r213 r227  
    2222function varargout = get_field(varargin)
    2323
    24 % Last Modified by GUIDE v2.5 06-Feb-2010 09:58:13
     24% Last Modified by GUIDE v2.5 27-Mar-2011 19:13:26
    2525
    2626% Begin initialization code - DO NOT EDIT
     
    4949global nb_builtin % nbre of functions to include by default in the menu of  functions called by RUN
    5050
    51 %% look at the existing figures in the work space
    52 browse_fig(handles.list_fig)
     51
    5352
    5453%% Choose default command line output for get_field
     
    5857guidata(hObject, handles);
    5958
    60 %% activate the mouse action function: visualise the current field on work space by right click action
    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})
    6261
    6362%% prepare the list of RUN fcts and set their paths
     
    112111%% settings for 'slave' mode, called by uvamt, or 'master' mode
    113112if 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 field
     113    set(handles.inputfile,'String',filename)% prefill the input file name
     114    Field=nc2struct(filename,[]);% reads the whole field
    116115    if isfield(Field,'Txt')
    117116        msgbox_uvmat('ERROR',Field.Txt)
    118117    else
    119         set(handles.figure1,'UserData',Field);
     118        set(handles.get_field,'UserData',Field);
    120119        Field_input(eventdata,handles,Field);
    121120    end
    122121else  %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         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);
    144         end
     122    set(handles.inputfile,'String','')
     123end
     124
     125%% load the list of previously browsed files for the upper bar menu Open
     126dir_perso=prefdir;
     127profil_perso=fullfile(dir_perso,'uvmat_perso.mat');%
     128if 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);
    145144    end
    146145end
     
    168167%------------------------------------------------------------------------
    169168inputfile=get(handles.inputfile,'String');
    170 Field=nc2struct(inputfile);% reads the whole field
     169Field=nc2struct(inputfile,[]);% reads the  field description, without data
     170Field.ListGlobalAttribute
    171171if isfield(Field,'Txt')
    172172    msgbox_uvmat('ERROR',Field.Txt)
    173173else
    174 set(handles.figure1,'UserData',Field);
     174set(handles.get_field,'UserData',Field);
    175175Field_input(eventdata,handles,Field);
    176176end
     
    189189        Tabcell{iline,2}=num2str(Field.DimValue(iline));
    190190    end
    191     Tabchar=cell2tab(Tabcell,'=');
     191    Tabchar=cell2tab(Tabcell,' = ');
    192192    set(handles.dimensions,'String',Tabchar)
    193193end
     
    212212set(handles.coord_z_vectors,'String',[{''} Txt ])
    213213set(handles.scalar,'Value',1)
     214
    214215set(handles.scalar,'String', Txt )
    215216[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
     
    218219    return
    219220end 
     221for icell=1:numel(CellVarIndex)
     222    NbDim(icell)=max(NbDim(icell),numel(CellVarIndex{icell}));
     223end
    220224[maxdim,imax]=max(NbDim);
    221225   
     
    278282    check_vector_Callback(handles.check_vector, eventdata, handles)
    279283end
     284%scalar_Callback(handles.get_field, eventdata, handles)
     285%vector_x_Callback(handles.get_field, eventdata, handles)
    280286
    281287%------------------------------------------------------------------------
     
    315321% test_2D=get(handles.check_vector,'Value');% =1 for vector fields
    316322% test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields
    317 %if isequal(xdispindex,1)% blank selection, no selected variable for abscissa
     323%if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa
    318324%     Txt=Field.ListVarName;
    319325%     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
     
    329335%      end
    330336%     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)
    332338%     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 abscissa
     339%         index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa
    334340%         VarIndex=[];
    335341%         for ilist=1:length(Field.VarDimIndex)%detect
    336342%             index_i=Field.VarDimIndex{ilist};
    337343%             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 possible
     344%                 if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, RUN is possible
    339345%                     VarIndex=[VarIndex ilist];
    340346%                 end
     
    352358function scalar_Callback(hObject, eventdata, handles)
    353359%------------------------------------------------------------------------
    354 Aindex=get(handles.scalar,'Value');
    355 Astring=get(handles.scalar,'String');
    356 VarName=Astring{Aindex};
     360index=get(handles.scalar,'Value');
     361string=get(handles.scalar,'String');
     362VarName=string{index};
    357363update_field(hObject, eventdata, handles,VarName)
     364
     365%eliminate time
     366TimeDimName='';%default
     367if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on')
     368    TimeDimList=get(handles.TimeDimensionMenu,'String');
     369    TimeDimIndex=get(handles.TimeDimensionMenu,'Value');
     370    TimeDimName=TimeDimList{TimeDimIndex};
     371end
     372
     373%check possible coordinates
     374Field=get(handles.get_field,'UserData');
     375dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar
     376test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
     377for 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
     388end
     389test_coord(index)=0;%the coordinate variable must be different from the scalar
     390
     391string_coord=[{''};string(test_coord==1)];
     392val=get(handles.coord_x_scalar,'Value');
     393if val>numel(string_coord)
     394    set(handles.coord_x_scalar,'Value',1)
     395end
     396set(handles.coord_x_scalar,'String',string_coord);
     397val=get(handles.coord_y_scalar,'Value');
     398if val>numel(string_coord)
     399    set(handles.coord_y_scalar,'Value',1)
     400end
     401set(handles.coord_y_scalar,'String',string_coord);
     402val=get(handles.coord_y_scalar,'Value');
     403if val>numel(string_coord)
     404    set(handles.coord_y_scalar,'Value',1)
     405end
     406set(handles.coord_z_scalar,'String',string_coord);
     407
    358408
    359409%------------------------------------------------------------------------
     
    391441string=get(handles.vector_x,'String');
    392442VarName=string{index};
     443
     444%check possible coordinates
     445Field=get(handles.get_field,'UserData');
     446dim_var=Field.VarDimName{index};%list of dimensions of the selected scalar
     447test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
     448test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component
     449for 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
     460end
     461%eliminate time
     462if get(handles.TimeVariable,'Value')
     463    TimeName=get(handles.TimeName,'String');
     464    index_time=find(strcmp( TimeName,Field.ListVarName));
     465    test_coord(index_time)=0;
     466end
     467vlength=numel(string(test_component==1));
     468val=get(handles.vector_y,'Value');
     469if val>vlength
     470    set(handles.vector_y,'Value',1)
     471end
     472set(handles.vector_y,'String',[string(test_component==1)])
     473val=get(handles.vector_z,'Value');
     474if val>vlength+1
     475    set(handles.vector_z,'Value',1)
     476end
     477set(handles.vector_z,'String',[{''};string(test_component==1)])
     478val=get(handles.vec_color,'Value');
     479if val>vlength+1
     480    set(handles.vec_color,'Value',1)
     481end
     482set(handles.vec_color,'String',[{''};string(test_component==1)])
     483string_coord=[{''};string(test_coord==1)];
     484val=get(handles.coord_x_vectors,'Value');
     485if val>numel(string_coord)
     486    set(handles.coord_x_vectors,'Value',1)
     487end
     488set(handles.coord_x_vectors,'String',string_coord);
     489val=get(handles.coord_y_vectors,'Value');
     490if val>numel(string_coord)
     491    set(handles.coord_y_vectors,'Value',1)
     492end
     493set(handles.coord_y_vectors,'String',string_coord);
     494val=get(handles.coord_z_vectors,'Value');
     495if val>numel(string_coord)
     496    set(handles.coord_z_vectors,'Value',1)
     497end
     498set(handles.coord_z_vectors,'String',string_coord);
     499
    393500update_field(hObject, eventdata, handles,VarName)
    394501
     
    420527update_field(hObject, eventdata, handles,VarName)
    421528
    422 %-------------------------------------------------------
     529%------------------------------------------------------------------------
    423530% --- Executes on selection change in coord_y_vectors.
    424 %-------------------------------------------------------
    425531function coord_y_vectors_Callback(hObject, eventdata, handles)
     532%------------------------------------------------------------------------
    426533index=get(handles.coord_y_vectors,'Value');
    427534string=get(handles.coord_y_vectors,'String');
     
    429536update_field(hObject, eventdata, handles,VarName)
    430537
    431 %-------------------------------------------------------
     538%------------------------------------------------------------------------
    432539% --- Executes on selection change in coord_z_scalar.
    433540function coord_z_vectors_Callback(hObject, eventdata, handles)
    434 %-------------------------------------------------------
     541%------------------------------------------------------------------------
    435542index=get(handles.coord_z_vectors,'Value');
    436543string=get(handles.coord_z_vectors,'String');
     
    438545update_field(hObject, eventdata, handles,VarName)
    439546
    440 %-------------------------------------------------------
     547%------------------------------------------------------------------------
    441548% --- Executes on selection change in vec_color.
    442549function vec_color_Callback(hObject, eventdata, handles)
    443 %-------------------------------------------------------
     550%------------------------------------------------------------------------
    444551index=get(handles.vec_color,'Value');
    445552string=get(handles.vec_color,'String');
     
    447554update_field(hObject, eventdata, handles,VarName)
    448555
    449 %---------------------------------
     556%-----------------------------------------------------------------------
    450557function 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%-----------------------------------------------------------------------
     559Field=get(handles.get_field,'UserData');
    454560index=name2index(VarName,Field.ListVarName);
    455561if ~isempty(index)
     
    457563    variables_Callback(hObject, eventdata, handles)
    458564end
    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%------------------------------------------------------------------------
    541567% update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
    542568function update_UserData(handles)
    543 %---------------------------------------------------------
     569%------------------------------------------------------------------------
    544570return
    545571% global SubField
     
    615641    end
    616642    DimIndex=DimIndex_u;
    617     %TODO possibility of selecting 3 times the same variable for u, v, w components
    618 end
    619 
    620 
    621 % select the variable  index (or indices) for z coordinates
     643    %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components
     644end
     645
     646
     647% select the TimeVariable  index (or indices) for z coordinates
    622648test_grid=0;
    623649if test_scalar | test_vector
     
    658684        end
    659685%         if ~isempty(VarIndex_z)
    660 %             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable   
    661 %             if length(DimIndex_z)==1 & nbdim==3 %dimension variable
     686%             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable   
     687%             if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable
    662688%                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
    663689%                 ind_z=find(DimIndex==DimIndex_z(1));
     
    669695end
    670696
    671 % select the variable  index (or indices) for ordinate
     697% select the TimeVariable  index (or indices) for ordinate
    672698ystring=get(handles.ordinate,'String');
    673699yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
     
    701727end
    702728
    703 %select the variable index for the abscissa
     729%select the TimeVariable index for the abscissa
    704730xstring=get(handles.abscissa,'String');
    705731xindex=get(handles.abscissa,'Value');
     
    801827function RUN_Callback(hObject, eventdata, handles)
    802828%---------------------------------------------------------
    803 figcell=get(handles.list_fig,'String');
    804 index=get(handles.list_fig,'value');
    805 figstring=figcell{index};
     829set(handles.RUN,'BackgroundColor',[1 1 0])% mark use of RUN action
     830test_fig=get(handles.SelectFigure,'Value');
    806831
    807832% plot requested in uvmat
    808 if isequal(figstring,'uvmat')
     833if ~test_fig
    809834    inputfile=get(handles.inputfile,'String');
    810835    huvmat=findobj(allchild(0),'tag','uvmat');
     
    814839        set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases)
    815840        hhuvmat=guidata(huvmat);
     841        set(hhuvmat.Fields,'Value',1)
     842        set(hhuvmat.Fields,'String',{'get_field...'})
    816843        uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat
    817844    end
    818845   
    819846% other kind of plot
    820 else
     847else  %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};
    821851    index=get(handles.ACTION,'Value');
    822852    list_func=get(handles.ACTION,'UserData');
     
    824854    set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
    825855    drawnow
    826     SubField=h_fun(handles.figure1);%handles.figure1 =handles of the GUI get_field
     856    SubField=h_fun(handles.get_field);%handles.figure1 =handles of the GUI get_field
    827857    if ~isempty(SubField)
    828858        plot_get_field(SubField,handles)
     
    869899% % handles    structure with handles and user data (see GUIDATA)
    870900%
    871 % %time plots
     901% %timename plots
    872902% leg={};
    873903% n=0;
     
    10421072Tabcell=[];
    10431073hselect_field=get(handles.variables,'parent');
    1044 Field=get(hselect_field,'UserData');
     1074Field=get(handles.get_field,'UserData');
    10451075index=get(handles.variables,'Value');%index in the list 'variables'
    10461076if isequal(index,1)
    10471077    set(handles.attributes_txt,'String','global attributes')
    1048 % list global attribute names and values if index=1 (blank variable display) is selected
     1078% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
    10491079    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
    10501080        for iline=1:length(Field.ListGlobalAttribute)
     
    10621092    end
    10631093else
    1064 %list attribute names and values associated to the variable # injdex-1   
     1094%list TimeAttribute names and values associated to the TimeVariable # injdex-1   
    10651095    list_var=get(handles.variables,'String');
    10661096    var_select=list_var{index};
     
    11151145        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
    11161146    end
    1117     Tabchar=cell2tab(Tabdim,'=');
     1147    Tabchar=cell2tab(Tabdim,' = ');
    11181148    Tabchar=[{''} ;Tabchar];
     1149    set(handles.dimensions,'Value',1)
    11191150    set(handles.dimensions,'String',Tabchar) 
    11201151end 
     
    11531184end
    11541185
    1155 %------------------------------------------------------------------------
    1156 function mouse_up_gui(ggg,eventdata,handles)
    1157 %------------------------------------------------------------------------
    1158 if isequal(get(ggg,'SelectionType'),'alt')
    1159     message=''; 
    1160     global CurData
    1161     inputfield=get(handles.inputfile,'String');
    1162     if exist(inputfield,'file')
    1163         CurData=nc2struct(inputfield);
    1164     else
    1165         CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
    1166     end
    1167   %%%% TODO: put the matalb command window in front
    1168     evalin('base','global CurData')%make CurData global in the workspace
    1169     evalin('base','CurData') %display CurData in the workspace
    1170 end
     1186% %------------------------------------------------------------------------
     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
    11711202
    11721203%------------------------------------------------------------------------
     
    14141445%global inputfile
    14151446fileinput=[PathName FileName];%complete file name
    1416 testblank=findstr(fileinput,' ');%look for blanks
    1417 if ~isempty(testblank)
    1418     msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
    1419     return
    1420 end
    14211447sizf=size(fileinput);
    1422 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
     1448if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
    14231449set(handles.inputfile,'String',fileinput)
    14241450inputfile_Callback(hObject, eventdata, handles)
    1425 
    14261451
    14271452%update list of recent files in the menubar
     
    14641489inputfile_Callback(hObject, eventdata, handles)
    14651490
    1466 % --------------------------------------------------------------------
     1491% -----------------------------------------------------------------------
    14671492function MenuFile_3_Callback(hObject, eventdata, handles)
     1493% -----------------------------------------------------------------------
    14681494fileinput=get(handles.MenuFile_3,'Label');
    14691495set(handles.inputfile,'String',fileinput)
    14701496inputfile_Callback(hObject, eventdata, handles)
    14711497
    1472 % --------------------------------------------------------------------
     1498% -----------------------------------------------------------------------
    14731499function MenuFile_4_Callback(hObject, eventdata, handles)
     1500% -----------------------------------------------------------------------
    14741501fileinput=get(handles.MenuFile_4,'Label');
    14751502set(handles.inputfile,'String',fileinput)
    14761503inputfile_Callback(hObject, eventdata, handles)
    14771504
    1478 % --------------------------------------------------------------------
     1505% -----------------------------------------------------------------------
    14791506function MenuFile_5_Callback(hObject, eventdata, handles)
     1507% -----------------------------------------------------------------------
    14801508fileinput=get(handles.MenuFile_5,'Label');
    14811509set(handles.inputfile,'String',fileinput)
    14821510inputfile_Callback(hObject, eventdata, handles)
    14831511
    1484 % --------------------------------------------------------------------
     1512%------------------------------------------------------------------------
    14851513function MenuExportField_Callback(hObject, eventdata, handles)
     1514%------------------------------------------------------------------------
    14861515global Data_get_field
    14871516% huvmat=findobj(allchild(0),'Name','uvmat');
     
    14941523commandwindow;
    14951524
    1496 % --------------------------------------------------------------------
     1525%------------------------------------------------------------------------
    14971526function 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%------------------------------------------------------------------------
    15011528path_to_uvmat=which ('uvmat');% check the path of uvmat
    15021529pathelp=fileparts(path_to_uvmat);
     
    15071534end
    15081535
     1536% -----------------------------------------------------------------------
     1537function TimeName_Callback(hObject, eventdata, handles)
     1538
     1539scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates
     1540vector_x_Callback(hObject, eventdata, handles)
     1541
     1542%------------------------------------------------------------------------
     1543% --- Executes on button press in TimeAttribute.
     1544function TimeAttribute_Callback(hObject, eventdata, handles)
     1545%------------------------------------------------------------------------
     1546val=get(handles.TimeAttribute,'Value');
     1547if 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)
     1579else
     1580    set(handles.TimeAttributeMenu,'Visible','off')
     1581    set(handles.TimeValue,'Visible','off')
     1582end
     1583
     1584%------------------------------------------------------------------------
     1585% --- Executes on selection change in TimeAttributeMenu.
     1586function 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.
     1597function TimeDimension_Callback(hObject, eventdata, handles)
     1598%------------------------------------------------------------------------
     1599val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected
     1600if 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)
     1617else
     1618    set(handles.TimeDimensionMenu,'Visible','off')
     1619    set(handles.TimeIndexValue,'Visible','off')
     1620end
     1621
     1622%------------------------------------------------------------------------
     1623% --- Executes on selection change in TimeDimensionMenu.
     1624function TimeDimensionMenu_Callback(hObject, eventdata, handles)
     1625%------------------------------------------------------------------------
     1626index=get(handles.TimeDimensionMenu,'Value');
     1627DimList=get(handles.TimeDimensionMenu,'String');
     1628DimName=DimList{index};
     1629Field=get(handles.get_field,'UserData');
     1630DimIndex=find(strcmp(DimName,Field.ListDimName),1);
     1631ref_index=round(Field.DimValue(DimIndex)/2);   
     1632set(handles.TimeIndexValue,'String',num2str(ref_index))
     1633scalar_Callback(hObject, eventdata, handles)
     1634vector_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.
     1697function TimeVariableMenu_Callback(hObject, eventdata, handles)
     1698% -----------------------------------------------------------------------
     1699ListVar=get(handles.TimeVariableMenu,'String');
     1700index=get(handles.TimeVariableMenu,'Value');
     1701TimeVariable=ListVar{index};% name of the selected variable
     1702if isempty(TimeVariable)% case of blank selection
     1703    return
     1704end
     1705Field=get(handles.get_field,'UserData'); %index of
     1706VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
     1707DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
     1708set(handles.TimeDimensionMenu,'Value',1)
     1709set(handles.TimeDimensionMenu,'String',DimName)
     1710inputfile=get(handles.inputfile,'String');% read the input file
     1711SubField=nc2struct(inputfile,{TimeVariable});
     1712eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
     1713ref_index=round(TimeDimension/2);
     1714eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
     1715set(handles.TimeIndexValue,'String',num2str(ref_index))
     1716set(handles.TimeVarValue,'String',num2str(TimeValue))
     1717
     1718
     1719function TimeValue_Callback(hObject, eventdata, handles)
     1720%TO suppress
     1721
     1722% -----------------------------------------------------------------------
     1723function TimeIndexValue_Callback(hObject, eventdata, handles)
     1724% -----------------------------------------------------------------------
     1725TimeIndex=str2double(get(handles.TimeIndexValue,'String'));
     1726TimeVarName=Field.ListVarName{time_index};
     1727set(handles.TimeVariable,'Value',1)
     1728set(handles.TimeName,'String',TimeVarName)
     1729fileinput=get(handles.inputfile,'String');
     1730SubField=nc2struct(fileinput,{TimeVarName});
     1731eval(['TimeValue=SubField.' TimeVarName '(ref_index);']);
     1732set(handles.TimeValue,'Visible','on')
     1733set(handles.TimeValue,'String',num2str(TimeValue))
     1734
     1735% -----------------------------------------------------------------------
     1736function SelectFigure_Callback(hObject, eventdata, handles)
     1737% -----------------------------------------------------------------------
     1738val=get(handles.SelectFigure,'Value');
     1739if val
     1740    set(handles.list_fig,'Visible','on')
     1741    %% look at the existing figures in the work space
     1742    browse_fig(handles.list_fig)
     1743else
     1744   set(handles.list_fig,'Visible','off')
     1745end
     1746
     1747
     1748function TimeVarValue_Callback(hObject, eventdata, handles)
     1749
     1750
     1751
     1752% --- Executes on button press in check_rgb.
     1753function check_rgb_Callback(hObject, eventdata, handles)
     1754
     1755
     1756
  • trunk/src/nc2struct.m

    r188 r227  
    6565            nc=netcdf.open(nc,'NC_NOWRITE');
    6666            testfile=1;
    67             catch errormsg
    68               Data.Txt=['ERROR opening ' nc ': ' errormsg.identifier];
     67            catch ME
     68              Data.Txt=['ERROR opening ' nc ': ' ME.message];
    6969              return
    7070            end
     
    7777    end
    7878   
    79     %% short reading opion for global attributes only, if the first argument is 'ListGlobalAttribute'
     79    %% short reading option for global attributes only, if the first argument is 'ListGlobalAttribute'
    8080    if isequal(varargin{1},'ListGlobalAttribute')
    8181        for ilist=2:numel(varargin)
     82            valuestr=[];%default
    8283            try
    8384            valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist});
    84             catch
    85                 valuestr=[];
     85            catch ME
    8686            end
    8787            eval(['Data.' varargin{ilist} '=valuestr;'])
     
    9797    %%  -------- read all global attributes (constants)-----------
    9898    att_key={};%default
    99     iatt_g=0;
     99%     iatt_g=0;
    100100    Data.ListGlobalAttribute={};%default
    101101    for iatt=1:ngatts
    102102        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 '=[];'])
    120114            elseif isnumeric(valuestr)
    121                 iatt_g=iatt_g+1;
    122115                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} '=[];'])
    125123        end
    126124    end
     
    184182            attname = netcdf.inqAttName(nc,var_index(ivar)-1,iatt-1);
    185183            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
    186189            if ischar(valuestr)
     190               % valuestr=regexprep(valuestr,{'\\','\/','\.','\-',' '},{'_','_','_','_','_'});%remove  '\','.' or '-' if exists
    187191                eval(['Data.VarAttribute{ivar}.' attname '=''' valuestr ''';'])
    188192            elseif isempty(valuestr)
     
    190194            elseif isnumeric(valuestr)
    191195                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'';'])
    192202            end
    193203        end
  • trunk/src/pivlab.m

    r225 r227  
    11% 'pivlab': function piv.m adapted from PIVlab http://pivlab.blogspot.com/
    22%--------------------------------------------------------------------------
    3 % function [xtable ytable utable vtable typevector] = pivlab (image1,image2,interrogationarea, step, subpixfinder, mask, roi)
     3% function [xtable ytable utable vtable typevector] = pivlab (image1,image2,ibx,iby step, subpixfinder, mask, roi)
    44%
    55% OUTPUT:
     
    1414% image1:first image (matrix)
    1515% image2: second image (matrix)
    16 % interrogationarea: size of the correlation box (in px)
     16% ibx,iby: size of the correlation box along x and y (in px)
    1717% step: mesh of the measurement points (in px)
    1818% subpixfinder=1 or 2 controls the curve fitting of the image correlation
    1919% mask: =[] for no mask
    2020% 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,interrogationarea, step, subpixfinder, mask, roi)
     21function [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty, PointCoord, subpixfinder,mask)
    2222%this funtion performs the DCC PIV analysis. Recent window-deformation
    2323%methods perform better and will maybe be implemented in the future.
    2424warning off %MATLAB:log:logOfZero
    25 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
     25% 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
    3333    xroi=0;
    3434    yroi=0;
    3535    image1_roi=double(image1);
    3636    image2_roi=double(image2);
    37 end
     37% end
    3838if numel(mask)>0
    3939    cellmask=mask;
     
    4848end
    4949mask(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
     76image1_roi=padarray(image1_roi,[iby2 ibx2], min(min(image1_roi)));%add a border around the image with minimum image value
     77image2_roi=padarray(image2_roi,[iby2 ibx2], min(min(image1_roi)));
     78mask=padarray(mask,[iby2 ibx2],0);
     79SubPixOffset=0.5;%odd values chosen for ibx and iby
     80
     81nbvec=size(PointCoord,1);
     82xtable=zeros(nbvec,1);
    8583ytable=xtable;
    8684utable=xtable;
     
    8987v2table=xtable;
    9088s2n=xtable;
    91 typevector=ones(numelementsy,numelementsx);;
     89typevector=ones(size(xtable));
    9290
    9391nrx=0;
     
    9795
    9896%% 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
     97for 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
    121115           %reference: Oliver Pust, PIV: Direct Cross-Correlation
    122116           % image2_crop: sub image with the size of the search area in image 2
     
    132126                try
    133127                    if subpixfinder==1
    134                         [vector] = SUBPIXGAUSS (result_conv,interrogationarea,x,y,SubPixOffset);
     128                        [vector] = SUBPIXGAUSS (result_conv,ibx,iby,x,y,SubPixOffset);
    135129                    elseif subpixfinder==2
    136                         [vector] = SUBPIX2DGAUSS (result_conv,interrogationarea,x,y,SubPixOffset);
     130                        [vector] = SUBPIX2DGAUSS (result_conv,ibx,iby,x,y,SubPixOffset);
    137131                    end
    138132                catch
     
    144138        else %if mask was not 0 then
    145139            vector=[NaN NaN];
    146             typevector(nry,nrxreal)=0;
     140            typevector(ivec)=0;
    147141        end
    148142
    149143        %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));
     149end
     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
     161function [vector] = SUBPIXGAUSS (result_conv,ibx,iby,x,y,SubPixOffset)
    170162if size(x,1)>1 %if there are more than 1 peaks just take the first
    171163    x=x(1:1);
     
    186178    peakx = x+ (f1-f2)/(2*f1-4*f0+2*f2);
    187179    %
    188     SubpixelX=peakx-(interrogationarea/2)-SubPixOffset;
    189     SubpixelY=peaky-(interrogationarea/2)-SubPixOffset;
     180    SubpixelX=peakx-(ibx/2)-SubPixOffset;
     181    SubpixelY=peaky-(iby/2)-SubPixOffset;
    190182    vector=[SubpixelX, SubpixelY];
    191183else
     
    193185end
    194186
    195 function [vector] = SUBPIX2DGAUSS (result_conv,interrogationarea,x,y,SubPixOffset)
     187function [vector] = SUBPIX2DGAUSS (result_conv,ibx,iby,x,y,SubPixOffset)
    196188if size(x,1)>1 %if there are more than 1 peaks just take the first
    197189    x=x(1:1);
     
    229221    peaky=y+deltay;
    230222
    231     SubpixelX=peakx-(interrogationarea/2)-SubPixOffset;
    232     SubpixelY=peaky-(interrogationarea/2)-SubPixOffset;
     223    SubpixelX=peakx-(ibx/2)-SubPixOffset;
     224    SubpixelY=peaky-(iby/2)-SubPixOffset;
    233225    vector=[SubpixelX, SubpixelY];
    234226else
  • trunk/src/plot_field.m

    r221 r227  
    585585                XName=Data.ListVarName{ivar_X};
    586586                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);'])
    589589            elseif numel(VarType.coord)==2 && ~isequal(VarType.coord,[0 0]);%coordinates defines by dimension variables
    590590                eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';'])
     
    627627        eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image
    628628        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,[]);
    630631            XName=Data.ListVarName{ivar_X};
    631632            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,[]);'])
    634635            [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256');  % interpolate on a grid 
    635636            if isfield(Data,'VarAttribute')
  • trunk/src/proj_field.m

    r215 r227  
    946946cos_om=1;
    947947sin_om=0;
     948test90x=0;%=1 for 90 degree rotation alround x axis
     949test90y=0;%=1 for 90 degree rotation alround y axis
    948950if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0])
     951    test90y=isequal(ObjectData.Angle,[0 90 0]);
    949952    PlaneAngle=(pi/180)*ObjectData.Angle;
    950953    om=norm(PlaneAngle);%norm of rotation angle in radians
     
    958961    norm_plane(3)=OmAxis(3)*coeff+cos_om;
    959962end
    960 testangle=~isequal(PlaneAngle,[0 0 0]);
     963testangle=~isequal(PlaneAngle,[0 0 0]);% && ~test90y && ~test90x;%=1 for slanted plane
     964
    961965% Phi=0;%default
    962966% Theta=0;
     
    10711075        DimCell={DimCell};%name of dimensions
    10721076    end
    1073 
    1074 %% case of input fields with unstructured coordinates
     1077   
     1078    %% case of input fields with unstructured coordinates
    10751079    if testX
    10761080        XName=FieldData.ListVarName{ivar_X};
     
    10821086            eval(['coord_z=FieldData.' ZName ';'])
    10831087        end
    1084 
     1088       
    10851089        % translate  initial coordinates
    10861090        coord_x=coord_x-ObjectData.Coord(1,1);
     
    10931097        if length(ivar_Z)==1 &&  width > 0
    10941098            %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
    10961100            indcut=find(abs(fieldZ) <= width);
    10971101            size(indcut)
    10981102            for ivar=VarIndex
    10991103                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 REGULIERE             
     1104                eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
     1105                % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
    11021106            end
    11031107            coord_x=coord_x(indcut);
     
    11051109            coord_z=coord_z(indcut);
    11061110        end
    1107 
    1108        %rotate coordinates if needed
    1109         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 %             end
    1115 %         else
     1111       
     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
    11161120            coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
    11171121            coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
    1118 %         end
    1119 %         if ~isempty(ivar_Z)
     1122            %         end
     1123            %         if ~isempty(ivar_Z)
    11201124            coord_Y=coord_Y+coord_z *sin(Theta);
    1121 %         end
    1122 %         if testangle
    1123                 coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
    1124                 coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
     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));
    11251129        else
    11261130            coord_X=coord_x;
     
    11511155            for ivar=VarIndex
    11521156                VarName=FieldData.ListVarName{ivar};
    1153                 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])           
     1157                eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
    11541158            end
    11551159            coord_X=coord_X(indcut);
     
    11641168            %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
    11651169            %ProjData.DimValue=[ProjData.
    1166              %length(coord_X)];
    1167 
     1170            %length(coord_X)];
     1171           
    11681172            for ivar=VarIndex %transfer variables to the projection plane
    11691173                VarName=FieldData.ListVarName{ivar};
     
    11751179                    eval(['ProjData.' VarName '=FieldData.' VarName ';'])
    11761180                end
    1177                 if isempty(ivar_Z) || ivar~=ivar_Z 
     1181                if isempty(ivar_Z) || ivar~=ivar_Z
    11781182                    ProjData.ListVarName=[ProjData.ListVarName VarName];
    11791183                    ProjData.VarDimName=[ProjData.VarDimName DimCell];
     
    11831187                    end
    11841188                end
    1185             end 
     1189            end
    11861190        elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
    11871191            coord_x_proj=XMin:DX:XMax;
     
    11891193            DimCell={'coord_y','coord_x'};
    11901194            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;
    11931197            ProjData.coord_y=[YMin YMax];
    11941198            ProjData.coord_x=[XMin XMax];
     
    12111215            for ivar=VarIndex
    12121216                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)
    12141218                    ivar_new=ivar_new+1;
    12151219                    ProjData.ListVarName=[ProjData.ListVarName {VarName}];
     
    12451249                ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
    12461250                ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
    1247                ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
     1251                ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
    12481252                ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
    12491253            end
    12501254        end
    12511255       
    1252 %% case of input fields defined on a structured  grid
     1256        %% case of input fields defined on a structured  grid
    12531257    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
    12551260        eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
    1256         DimValue(DimValue==1)=[];%remove singleton dimensions       
     1261        DimValue(DimValue==1)=[];%remove singleton dimensions
    12571262        NbDim=numel(DimValue);%update number of space dimensions
    12581263        nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
     
    12701275            end
    12711276        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
    12741292        eval(['AX=FieldData.' AXName ';'])
    12751293        eval(['AY=FieldData.' AYName ';'])
    12761294        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}];
    12901297        Coord_z=[];
    12911298        Coord_y=[];
    1292         Coord_x=[];   
    1293 
     1299        Coord_x=[];
     1300       
    12941301        for idim=1:NbDim %loop on space dimensions
    12951302            test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
     
    12981305                eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
    12991306                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);
    13011308                else
    13021309                    DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
    13031310                    DCoord_min(idim)=min(DCoord);
    13041311                    DCoord_max=max(DCoord);
    1305                 %    test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
    1306                     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)
    13071314                        msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'])
    1308                                 return
    1309                     end               
     1315                        return
     1316                    end
    13101317                    test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
    13111318                end
     
    13211328            DY=abs(DCoord_min(NbDim-1));
    13221329        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
    13241331        if DX==0
    13251332            DX=abs(DCoord_min(NbDim));
    13261333        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
    13281335        for idim=1:NbDim
    13291336            if test_interp(idim)
    13301337                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
    13311338            end
    1332         end       
     1339        end
    13331340        Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
    13341341        test_direct_y=test_direct(NbDim-1);
     
    13361343        test_direct_x=test_direct(NbDim);
    13371344        DAX=DCoord_min(NbDim);
    1338         DAY=DCoord_min(NbDim-1); 
     1345        DAY=DCoord_min(NbDim-1);
    13391346        minAX=min(Coord_x);
    13401347        maxAX=max(Coord_x);
     
    13741381        end
    13751382        npX=floor((XMax-XMin)/DX+1);
    1376         npY=floor((YMax-YMin)/DY+1);   
     1383        npY=floor((YMax-YMin)/DY+1);
    13771384        if test_direct_y
    13781385            coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
     
    13841391        else
    13851392            coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
    1386         end
    1387        
     1393        end
    13881394        % case with no rotation and interpolation
    13891395        if isequal(ProjMode,'projection') && ~testangle
    13901396            if ~testXMin && ~testXMax && ~testYMin && ~testYMax && NbDim==2
    1391                 ProjData=FieldData; 
     1397                ProjData=FieldData;
    13921398            else
    13931399                indY=NbDim-1;
     
    14021408                    Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1);
    14031409                    Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1);
    1404                 end   
     1410                end
    14051411                if test_direct(NbDim)==1
    14061412                    min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;
     
    14121418                    max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1;
    14131419                    Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
     1420                   
     1421                   
    14141422                    Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
    1415                 end
    1416                 if NbDim==3
    1417                     DimCell(1)=[]; %suppress z variable
    1418                     DimValue(1)=[];
    1419                                         %structured coordinates
    1420                     if test_direct(1)
    1421                         iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
    1422                     else
    1423                         iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
    1424                     end
    14251423                end
    14261424                min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
    14271425                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
    14371448                    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
    14451475            end
    14461476        else       % case with rotation and/or interpolation
     
    14531483                XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
    14541484                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
    14561486                if isequal(ObjectData.ProjMode,'filter')
    14571487                    npx_filter=ceil(abs(DX/DAX));
     
    14661496                for ivar=VarIndex
    14671497                    VarName=FieldData.ListVarName{ivar};
    1468                     if test_interp(1) || test_interp(2)%interpolate on a regular grid       
    1469                           eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
     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
    14701500                    end
    14711501                    %filter the field (image) if option 'filter' is used
    1472                     if test_filter 
    1473                          Aclass=class(FieldData.A);
    1474                          eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
    1475                          if ~isequal(Aclass,'double')
    1476                              eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
    1477                          end
    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
    14801510                    %ind_in=find(flagin);
    14811511                    ind_out=find(~flagin);
    14821512                    ICOMB=(XIMA-1)*DimValue(1)+YIMA;
    14831513                    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,:);
    14851515                    for icolor=1:nbcolor
    14861516                        vec_B(ind_out,icolor)=zeros(size(ind_out));
     
    14901520                    if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
    14911521                        ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
    1492                     end     
     1522                    end
    14931523                    eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
    14941524                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
    14961526                ProjData.ListVarName=[ProjData.ListVarName 'FF'];
    14971527                ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
    14981528                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'');'])
    15171545                        end
    15181546                    end
    1519                 else
    1520                     errormsg='projection of structured coordinates on oblique plane not yet implemented';
    1521                     %TODO: use interp3
    1522                     return
    1523                 end
    1524             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   
    15281556    %% projection of  velocity components in the rotated coordinates
    15291557    if testangle && length(ivar_U)==1
     
    15331561        end
    15341562        UName=FieldData.ListVarName{ivar_U};
    1535         VName=FieldData.ListVarName{ivar_V};   
     1563        VName=FieldData.ListVarName{ivar_V};
    15361564        eval(['ProjData.' UName  '=cos(PlaneAngle(3))*ProjData.' UName '+ sin(PlaneAngle(3))*ProjData.' VName ';'])
    15371565        eval(['ProjData.' VName  '=cos(Theta)*(-sin(PlaneAngle(3))*ProjData.' UName '+ cos(PlaneAngle(3))*ProjData.' VName ');'])
    15381566        if ~isempty(ivar_W)
    15391567            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);'])%
    15411569            eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
    15421570        end
     
    18571885        VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
    18581886        eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
    1859         DimValue(find(DimValue==1))=[];%remove singleton dimensions       
     1887        DimValue(DimValue==1)=[];%remove singleton dimensions       
    18601888        NbDim=numel(DimValue);%update number of space dimensions
    18611889        nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
     
    18651893                return
    18661894            else
    1867                 VarType.coord
    18681895                if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate
    18691896                    nbcolor=DimValue(3);
  • trunk/src/read_field.m

    r221 r227  
    3131ParamOut=[];
    3232errormsg='';
    33 %FieldName=ParamIn.FieldName;
    3433VelType=ParamIn.VelType;
    3534
     
    4241    end
    4342    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
    4545        FieldList=calc_field;%list of possible fields for Civx data
    4646        ParamOut.ColorVar='';%default
    4747        field_index=strcmp(ParamOut.FieldName,FieldList);%look for ParamOut.FieldName in the list
    4848        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')
    5051            if ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)
    5152                ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
     
    8384        set(hhget_field.inputfile,'String',ObjectName)
    8485        set(hhget_field.list_fig,'Value',1)
     86        if exist('num','var')&&~isnan(num)
     87            set(hhget_field.TimeIndexValue,'String',num2str(num))
     88        end
    8589        funct_list=get(hhget_field.ACTION,'UserData');
    8690        funct_index=get(hhget_field.ACTION,'Value');
     
    107111            end
    108112        end
    109         set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
     113        %set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
    110114        ParamOut.CivStage=0;
    111115        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
    112122    end
    113123    if test_civx
     
    127137                A=read(ObjectName,num);
    128138                FieldName='image';
    129             catch
    130                 errormsg=lasterr;
     139            catch ME
     140                errormsg=ME.message;
    131141                return
    132142            end
     
    134144            try
    135145                mov=aviread(ObjectName,num);
    136             catch
    137                 errormsg=lasterr;
     146            catch ME
     147                errormsg=ME.message;
    138148                return
    139149            end
  • trunk/src/read_get_field.m

    r206 r227  
    124124        return
    125125    end
    126     val=get(handles.scalar,'Value');%selected indices in the ordinate listbox
    127     VarNameScalar=inputlist{val}; %name of the variable in the list
     126    val=get(handles.scalar,'Value');%selected index for the scalar variable
     127    VarNameScalar=inputlist{val}; %name of the variable
    128128    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
    130141    nbvar=nbvar+1;
    131142    ListVarName{nbvar}=Field.ListVarName{VarIndexA};
     
    157168            if iscell(dimname_x)
    158169                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
    160174                else
    161175                    errormsg='invalid x coordinate selection in get_field';
     
    190204                if numel(dimname_y)==1
    191205                    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
    192209                else
    193210                    errormsg='invalid y coordinate selection in get_field';
     
    214231            nbvar=nbvar+1;
    215232            ListVarName{nbvar}=Field.ListVarName{VarIndex};
    216             VarDimName{nbvar}=dimname_y;
     233            VarDimName{nbvar}=dimname_z;
    217234            if numel(VarAttribute)>=VarIndex
    218235                SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    219236            end
    220237            %check consistency of dimensions
    221             if ~isequal(dimname_y,dimname_A)% case of dimension variables
    222                 if iscell(dimname_y)
    223                     if numel(dimname_y)==1
    224                         dimname_y=dimname_y{1};%transform to char chain
     238            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
    225242                    else
    226                         errormsg='invalid y coordinate selection in get_field';
     243                        errormsg='invalid z coordinate selection in get_field';
    227244                        return
    228245                    end
     
    432449    end
    433450end
     451
     452
     453
    434454%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    435 
    436 % get the input field
     455%% get the input field
    437456inputfield=get(handles.inputfile,'String');
    438457if exist(inputfield,'file')% read the input data corresponding to the list of selected varaibles
     
    443462    SubField.VarDimName=VarDimName;
    444463end
    445 SubField.ListGlobalAttribute=['InputFile' SubField.ListGlobalAttribute];
     464if 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')); 
     467end
     468TimeValue=NaN;
     469if strcmp(get(handles.TimeVarValue,'Visible'),'on')
     470    TimeValue=str2double(get(handles.TimeVarValue,'String'));
     471elseif strcmp(get(handles.TimeValue,'Visible'),'on')
     472    TimeValue=str2double(get(handles.TimeValue,'String'));
     473end
     474if ~isnan(TimeValue)   
     475    SubField.ListGlobalAttribute=[{'TimeValue'} SubField.ListGlobalAttribute];
     476    SubField.TimeValue=str2double(get(handles.TimeVarValue,'String')); 
     477end
     478SubField.ListGlobalAttribute=[{'InputFile'} SubField.ListGlobalAttribute];
    446479SubField.InputFile=get(handles.inputfile,'String');
    447480SubField.VarAttribute=SubVarAttribute;
     
    453486    DimCellA=Field.VarDimName{VarIndexA};  %dimension names for the scalar variable
    454487    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
    455492    SingleCellA={};
    456493    if numel(npxy) < numel(DimCellA)
     
    461498    DimCellA=DimCellA(ind_select);%dimension names for the scalar variable, after removing singletons
    462499    npxy=npxy(ind_select);
     500%     if ~isempty(TimeVarIndex)%
     501%         DimCellA(TimeVarIndex)=[];%suppress the time dimension
     502%          npxy(TimeVarIndex)=[];
     503%     end
     504    NbDim=numel(npxy);
    463505    dimA=[];
    464     if test_zdimvar%dim_x && dim_y && ~isempty(VarSubIndexA)
     506    if test_zdimvar
    465507        NbDim=3;% field considered as 3D if a z coordinate is defined (to distinguish for instance from 2D color images with 3 components)
    466508        ind_singleton=find(strcmp(dimname_z,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions
     
    472514        dimA=[dimA icoord];
    473515    end
    474     if test_ydimvar%dim_x && dim_y && ~isempty(VarSubIndexA)
     516    if test_ydimvar
    475517        ind_singleton=find(strcmp(dimname_y,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions
    476518        if ~isempty(ind_singleton)
     
    481523        dimA=[dimA icoord];
    482524    end
    483     if test_xdimvar
    484         ind_singleton=find(strcmp(dimname_x,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions
    485         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)         
    486528             errormsg=['the singleton dimension ' dimname_x ' has been selected for ordinate'];
    487529             return
    488530        end
    489         icoord=find(strcmp(dimname_x,DimCellA),1);% a dimension variable
     531        icoord=find(strcmp(dimname_x{1},DimCellA),1);% a dimension variable
    490532        dimA=[dimA icoord];
    491533    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
    494559    DimCellA=DimCellA([dimA dimextra]);
    495     eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra]);'])
    496560    SubField.VarDimName{VarSubIndexA}=DimCellA; 
    497561    %add default coord_x and/or coord_y if empty
    498562    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) dimensions
     563        %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
    504568        end
    505569        ind_select=find(npxy~=1) ;%look for non singleton dimensions
    506         DimCell=DimCell(ind_select);%list of dimension names for the scalar, after singleton removal
     570        DimCellA=DimCellA(ind_select);%list of dimension names for the scalar, after singleton removal
    507571        npxy=npxy(ind_select);
    508572        testold=0;
     
    516580        end
    517581        if empty_coord_x       
    518                 coord_x_name=DimCell{NbDim};
     582                coord_x_name=DimCellA{NbDim};
    519583                SubField.ListVarName=[{coord_x_name} SubField.ListVarName];
    520584                SubField.VarDimName=[{coord_x_name} SubField.VarDimName]; 
     
    533597        end
    534598        if empty_coord_y
    535             coord_y_name=DimCell{NbDim-1};
     599            coord_y_name=DimCellA{NbDim-1};
    536600            SubField.ListVarName=[{coord_y_name} SubField.ListVarName];
    537601            SubField.VarDimName=[{coord_y_name} SubField.VarDimName];
     
    547611            end
    548612            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];   
    549629        end
    550630    end
     
    714794end
    715795
     796%% remove time variable
     797if 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)=[];
     804end
     805
     806
    716807%-------------------------------------------------
    717808% give index numbers of the strings str in the list ListvarName
  • trunk/src/set_object.m

    r215 r227  
    766766
    767767%% 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
     769if ~isempty(errormsg)
     770    msgbox_uvmat('ERROR', errormsg)
     771    return
     772end
    769773PlotParam=read_plot_param(PlotHandles);
    770774[PlotType,Object_out{IndexObj}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
     
    846850end
    847851msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
    848 %------------------------------------------------------------------------
     852
    849853%------------------------------------------------------------------------
    850854% --- Executes on slider movement.
     
    853857Z_value=get(handles.z_slider,'Value');
    854858%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
     859PlaneAngle=[0 0 0];
     860norm_plane=[0 0 1];
     861cos_om=1;
     862sin_om=0;
     863
     864PlaneAngle(1)=str2double(get(handles.Phi,'String'));%first  angle in degrees
     865PlaneAngle(2)=str2double(get(handles.Theta,'String'));%second  angle in degrees
     866PlaneAngle(3)=str2double(get(handles.Psi,'String'));%second  angle in degrees
     867PlaneAngle=(pi/180)*PlaneAngle;
    858868om=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;
     869if isequal(om,0)
     870    norm_plane=[0 0 1];
     871else
     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;
     880end
    867881
    868882%set new plane position and update graph
     
    871885set(handles.ZObject,'String',num2str(norm_plane(3)*Z_value,4))
    872886PLOT_Callback(hObject, eventdata, handles)
    873 %------------------------------------------------------------------------
     887
    874888%------------------------------------------------------------------------
    875889% --- Executes on button press in HELP.
    876890function HELP_Callback(hObject, eventdata, handles)
     891%------------------------------------------------------------------------
    877892path_to_uvmat=which ('uvmat');% check the path of uvmat
    878893pathelp=fileparts(path_to_uvmat);
  • trunk/src/uvmat.m

    r221 r227  
    232232
    233233%% refresh projection plane
    234 %UvData.Object{1}.Style='plane';%main plotting plane
    235234UvData.Object{1}.ProjMode='projection';%main plotting plane
    236 % if ~isfield(UvData.Object{1},'plotaxes')
    237 %     UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
    238 %     set(handles.list_object_1,'Value',1);
    239 %    % set(handles.list_object_1,'String',{'1-PLANE'});
    240 %    set(handles.list_object_1,'String',{''});
    241 % end
    242235set(handles.Fields,'Value',1)
    243236set(handles.Fields,'string',{''})
     
    331324            inputfile=input.InputFile;
    332325        end
    333         Field=input;
     326        if isfield(Field,'TimeIndex')
     327            set(handles.i1,num2str(Field.TimeIndex))
     328        end
    334329    elseif ischar(input)% file name introduced as input
    335330           inputfile=input;
     
    347342    end
    348343    if ~isempty(inputfile)
    349         %%%%% display the indput field %%%%%%%
     344        %%%%% display the input field %%%%%%%
    350345        display_file_name(hObject, eventdata, handles,inputfile)
    351346        %%%%%%%
     
    366361   end
    367362end
    368 % set(handles.uvmat,'UserData',UvData)
    369363
    370364%% plot input field if exists
     
    437431        '*.*',  'All Files (*.*)'}, ...
    438432        'Pick a file',oldfile);
    439 %global filebase
    440433fileinput=[PathName FileName];%complete file name
    441 % testblank=findstr(fileinput,' ');%look for blanks
    442 % if ~isempty(testblank)
    443 %     msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
    444 %     return
    445 % end
    446434sizf=size(fileinput);
    447435if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
     
    484472% --- Open again the file whose name has been recorded in MenuFile_1
    485473function MenuFile_1_Callback(hObject, eventdata, handles)
     474%------------------------------------------------------------------------
    486475fileinput=get(handles.MenuFile_1,'Label');
    487476display_file_name(hObject, eventdata, handles,fileinput)
     
    490479% --- Open again the file whose name has been recorded in MenuFile_2
    491480function MenuFile_2_Callback(hObject, eventdata, handles)
     481%------------------------------------------------------------------------
    492482fileinput=get(handles.MenuFile_2,'Label');
    493483display_file_name(hObject, eventdata, handles,fileinput)
     
    496486% --- Open again the file whose name has been recorded in MenuFile_3
    497487function MenuFile_3_Callback(hObject, eventdata, handles)
     488%------------------------------------------------------------------------
    498489fileinput=get(handles.MenuFile_3,'Label');
    499490display_file_name(hObject, eventdata, handles,fileinput)
     
    502493% --- Open again the file whose name has been recorded in MenuFile_4
    503494function MenuFile_4_Callback(hObject, eventdata, handles)
     495%------------------------------------------------------------------------
    504496fileinput=get(handles.MenuFile_4,'Label');
    505497display_file_name(hObject, eventdata, handles,fileinput)
     
    508500% --- Open again the file whose name has been recorded in MenuFile_5
    509501function MenuFile_5_Callback(hObject, eventdata, handles)
     502%------------------------------------------------------------------------
    510503fileinput=get(handles.MenuFile_5,'Label');
    511504display_file_name(hObject, eventdata, handles,fileinput)
     
    514507% --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
    515508function display_file_name(hObject, eventdata, handles,fileinput)
     509%------------------------------------------------------------------------
    516510if ~exist(fileinput,'file')
    517511    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
     
    871865% set default options in menu 'Fields'
    872866
    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 
     867if ~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
     897end
    900898
    901899%% set index navigation options and refresh plots
     
    13911389    set(handles.scan_i,'Value',0)
    13921390    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
    1393     NomType=get(handles.FileIndex,'UserData')
     1391    NomType=get(handles.FileIndex,'UserData');
    13941392    switch NomType
    13951393    case {'_i_j1-j2','#_ab','%3dab'},% pair with j index
     
    20472045num_j1=stra2num(get(handles.j1,'String'));
    20482046num_j2=stra2num(get(handles.j2,'String'));
     2047
    20492048errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
     2049
    20502050if ~isempty(errormsg)
    20512051      msgbox_uvmat('ERROR',errormsg);
     
    21672167        set(handles.npx,'String',num2str(ParamOut.Npx));% display image size on the interface
    21682168        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;
    21692175    end
    21702176end
     
    24342440end
    24352441if 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 '));'])
    24382444    UvData.Field.NbDim=NbDim;
    24392445    UvData.Field.XMax=XMax;
    24402446    UvData.Field.XMin=XMin;
    24412447    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 '));'])
    24442450        UvData.Field.YMax=YMax;
    24452451        UvData.Field.YMin=YMin;
     
    32563262    % transform netc type to the corresponding image type
    32573263%     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')
    32593265        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
    32603266%         set(handles.SubDir_1,'String','')
    32613267%         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')
    32633269            NomTypeNew='_i_j';
    32643270        elseif isequal(NomType_1,'#_ab')
     
    40794085set(handles.FixScal,'Value',1) %suppress auto mode
    40804086set(handles.FixScal,'BackgroundColor',[1 1 0])
     4087MinA=str2double(get(handles.MinA,'String'));
     4088MaxA=str2double(get(handles.MaxA,'String'));
     4089if 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));
     4095end
    40814096update_plot(handles);
    40824097
     
    40864101set(handles.FixScal,'Value',1) %suppress auto mode
    40874102set(handles.FixScal,'BackgroundColor',[1 1 0])
     4103MinA=str2double(get(handles.MinA,'String'));
     4104MaxA=str2double(get(handles.MaxA,'String'));
     4105if 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));
     4111end
    40884112update_plot(handles);
    40894113
Note: See TracChangeset for help on using the changeset viewer.