- Location:
- /trunk/src
- Files:
-
- 9 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk/src/imadoc2struct.m
r20 r30 21 21 s.TimeUnit=[]; %default 22 22 s.GeometryCalib=[]; 23 nom_type_ima=[];%default24 ext_ima=[];%default23 % nom_type_ima=[];%default 24 % ext_ima=[];%default 25 25 % abs_time=[];%initiation 26 26 % GeometryCalib.CoordUnit='cm';%default 27 mode=[]; %default28 NbSlice=1;%default29 npx=[];%default30 npy=[];%default27 % mode=[]; %default 28 % NbSlice=1;%default 29 % npx=[];%default 30 % npy=[];%default 31 31 % GeometryCalib.Pxcmx=1; 32 32 % GeometryCalib.Pxcmy=1; 33 33 % GeometryCalib=[]; 34 NbDtj=1;34 % NbDtj=1; 35 35 tsai=[];%default 36 36 % if ~exist('testime','var') … … 64 64 end 65 65 s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value'); 66 FirstImage=s.Heading.ImageName;67 if ~isempty(FirstImage)68 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage);69 end66 % FirstImage=s.Heading.ImageName; 67 % if ~isempty(FirstImage) 68 % [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage); 69 % end 70 70 end 71 71 … … 78 78 xindex=findstr(ImageSize,'x'); 79 79 if length(xindex)>=2 80 npx=str2num(ImageSize(1:xindex(1)-1));81 npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));82 end 83 end 84 uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice');85 if ~isempty(uid_NbSlice)86 NbSlice=str2num(get(t,children(t,uid_NbSlice),'value'));87 if isempty(NbSlice),NbSlice=1;end; %default88 end80 % npx=str2num(ImageSize(1:xindex(1)-1)); 81 % npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1)); 82 end 83 end 84 % uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice'); 85 % if ~isempty(uid_NbSlice) 86 % NbSlice=str2num(get(t,children(t,uid_NbSlice),'value')); 87 % % if isempty(NbSlice),NbSlice=1;end; %default 88 % end 89 89 uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit'); 90 90 if ~isempty(uid_TimeUnit) … … 94 94 if ~isempty(uid_BurstTiming) 95 95 for k=1:length(uid_BurstTiming) 96 Dtj=[];%default97 NbDtj=1;%default96 % Dtj=[];%default 97 % NbDtj=1;%default 98 98 subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming 99 99 % reading Dtk … … 121 121 % reading Dtk 122 122 Dtk=get_value(subt,'/BurstTiming/Dtk',[]); 123 NbDtk=get_value(subt,'/BurstTiming/NbDtk',1) 123 NbDtk=get_value(subt,'/BurstTiming/NbDtk',1); 124 124 if isempty(Dtk) 125 125 s.Time=[s.Time;Time_val]; … … 141 141 if ~isempty(uid_GeometryCalib) 142 142 if length(uid_GeometryCalib)>1 143 error =['More than one GeometryCalib in ' filecivxml];143 errormsg=['More than one GeometryCalib in ' filecivxml]; 144 144 return 145 145 end … … 149 149 uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx'); 150 150 uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy'); 151 if ~isempty(uid_pixcmx) & ~isempty(uid_pixcmy)%NON UTILISE151 if ~isempty(uid_pixcmx) && ~isempty(uid_pixcmy)%NON UTILISE 152 152 pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value')); 153 153 if isempty(pixcmx),pixcmx=1;end; %default … … 180 180 uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz'); 181 181 uid_R=find(subt,'/GeometryCalib/R'); 182 if ~isempty(uid_focal) & ~isempty(uid_dpx_dpy)& ~isempty(uid_Cx_Cy)182 if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_Cx_Cy) 183 183 tsai.f=str2num(get(subt,children(subt,uid_focal),'value')); 184 184 dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value')); -
/trunk/src/nomtype2pair.m
r20 r30 30 30 % Dtj: ~=0 if i index pairs are used 31 31 32 function [nom_type_pair]=nomtype2pair(nom_type,Dti,Dtj) ;32 function [nom_type_pair]=nomtype2pair(nom_type,Dti,Dtj) 33 33 34 34 %determine nom_type_nc: 35 nom_type_ nc=[];%default35 nom_type_pair=[];%default 36 36 switch nom_type 37 37 case {'_i_j'} -
/trunk/src/series.m
r20 r30 55 55 %-------------------------------------------------------------------------- 56 56 function series_OpeningFcn(hObject, eventdata, handles,param) 57 57 global nb_builtin 58 58 % Choose default command line output for series 59 59 handles.output = hObject; … … 129 129 set(handles.filter2,'Value',param.filter2); 130 130 end 131 %set(hObject,'UserData', SeriesData)132 131 set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles}) 133 132 NomType_Callback(hObject, eventdata, handles) 134 %mode_Callback(hObject, eventdata, handles)135 133 136 134 %loads the information stored in prefdir to initiate the browser and the list of functions 137 menu_str=get(handles.ACTION,'String');%list of functions included in 'series.m' 138 menu_str(end)=[];%remove from the list the last option 'more...' 139 path_series=which('series');%path of the function 'series' 135 menu_str={'check_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'}; 136 nb_builtin=numel(menu_str); %number of functions 137 138 %remove from the list the last option 'more...' 139 [path_series,name,ext]=fileparts(which('series')); 140 path_series=fullfile(path_series,'/series');%path of the function 'series' 141 140 142 for ilist=1:length(menu_str) 141 143 fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m' … … 151 153 menu_str=[menu_str; {file}]; 152 154 end 153 menu_str=[menu_str;{'more...'}]; 154 set(handles.ACTION,'String',menu_str) 155 end 156 end 155 end 156 end 157 158 menu_str=[menu_str;{'more...'}]; 159 set(handles.ACTION,'String',menu_str) 157 160 set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION 158 161 … … 286 289 function MenuBrowse_insert_Callback(hObject, eventdata, handles) 287 290 288 %hseries=get(handles.browse_root,'parent'); 289 RootPathCell=get(handles.RootPath,'String'); 290 % SubDirCell=get(handles.SubDir,'String'); 291 RootPathCell=get(handles.RootPath,'String'); 291 292 RootFileCell=get(handles.RootFile,'String'); 292 293 oldfile=''; %default … … 392 393 % refresh the GUI data after introduction of a new file series 393 394 function update_file(hObject, eventdata, handles,fileinput,addtest) 394 hseries=get(handles.RootPath,'parent'); 395 %hseries=get(handles.RootPath,'parent'); 396 if ~exist(fileinput,'file') 397 msgbox_uvmat('ERROR',['input file ' fileinput ' does not exist']) 398 return 399 end 400 hseries=handles.figure1; 395 401 % refresh input root name, indices, file extension and nomenclature 396 402 [RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput); 397 403 %check for movie image files 404 if ~isempty(FileExt) 398 405 if ~isempty(imformats(FileExt(2:end))) 399 406 imainfo=imfinfo(fileinput); … … 402 409 [RootPath,RootFile]=fileparts(fileinput); 403 410 end 411 end 404 412 end 405 413 NcType='none';%default … … 486 494 drawnow 487 495 488 % hseries=get(handles.RootFile,'parent');489 % SeriesData=get(hseries,'UserData');%read information set by the browser490 % ext_ima_read=[];491 % field_count=1;%default492 % pxcmx=1;493 % pxcmy=1;494 496 TimeUnit=''; %default 495 % CoordUnit='';%default496 497 time=[];%default 497 498 GeometryCalib=[];%default 498 499 nb_field=[];%default 499 500 nb_field2=[];%default 500 % Heading=[];501 % [PD,Device]=fileparts(RootPathCell{1});502 501 SeriesData.PathCampaign=get(handles.PathCampaign,'String'); 503 502 504 503 % read timing and total frame number from the current file (movie files) !! may be overrid by xml file 505 %icell=length(RootPathCell);506 504 FileBase=fullfile(RootPath,RootFile); 507 505 … … 884 882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 885 883 function mode_Callback(hObject, eventdata, handles) 886 hseries=get(handles.mode,'parent'); 884 %hseries=get(handles.mode,'parent'); 885 hseries=handles.figure1; 887 886 SeriesData=get(hseries,'UserData'); 888 887 mode_list=get(handles.mode,'String'); … … 985 984 %---------------------------------------------------------------- 986 985 function find_netcpair_civ(hObject, eventdata, handles,Val) 987 hseries=get(handles.list_pair_civ,'parent');988 SeriesData=get(h series,'UserData');986 %hseries=get(handles.list_pair_civ,'parent'); 987 SeriesData=get(handles.figure1,'UserData'); 989 988 % NomTypeCell=get(handles.NomType,'String'); 990 989 NomTypeCell=SeriesData.NomType; … … 1167 1166 SeriesData.displ_num(iview,:)=(displ_num(:,val))'; 1168 1167 SeriesData.ref_time=ref_time; 1169 set(h series,'UserData',SeriesData)1168 set(handles.figure1,'UserData',SeriesData) 1170 1169 list_pair_civ_Callback(hObject, eventdata, handles) 1171 1170 … … 1179 1178 Val=get(handles.RootPath,'Value'); 1180 1179 IndexCell=get(handles.NomType,'String'); 1181 hseries=get(handles.list_pair_civ,'parent');1182 SeriesData=get(h series,'UserData');1180 %hseries=get(handles.list_pair_civ,'parent'); 1181 SeriesData=get(handles.figure1,'UserData'); 1183 1182 NomType=SeriesData.NomType{Val}; 1184 1183 list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs … … 1241 1240 set(handles.NomType,'String',IndexCell) 1242 1241 SeriesData.displ_num(Val,:)=displ_num; 1243 set(h series,'UserData',SeriesData)1242 set(handles.figure1,'UserData',SeriesData) 1244 1243 % set(handles.NomType,'Value',Val) 1245 1244 … … 1290 1289 %read root name and field type 1291 1290 set(handles.RUN,'BusyAction','queue'); 1292 hseries=get(handles.RUN,'parent');1293 set(0,'CurrentFigure',h series)1291 %hseries=get(handles.RUN,'parent'); 1292 set(0,'CurrentFigure',handles.figure1) 1294 1293 if isequal(get(handles.GetObject,'Value'),1) 1295 1294 Series.GetObject=1; … … 1298 1297 Series.GetObject=0; 1299 1298 end 1300 SeriesData=get(h series,'UserData');1299 SeriesData=get(handles.figure1,'UserData'); 1301 1300 if isfield(SeriesData,'sethandles') 1302 1301 if iscell(SeriesData.sethandles) … … 1481 1480 end 1482 1481 end 1482 % fct_path 1483 eval(['h_fun=@' action ';']) 1484 if ~isequal(fct_path,path_series) 1485 rmpath(fct_path)% add the prescribed path if not the current one 1486 end 1487 1483 1488 Series.Action=action;%name of the processing programme 1484 1489 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784]) 1485 1490 drawnow 1486 1491 if length(RootPath)>1 1487 feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series); 1488 else 1489 feval(action,num_i1,num_i2,num_j1,num_j2,Series); 1492 % feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series); 1493 h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series); 1494 else 1495 h_fun(num_i1,num_i2,num_j1,num_j2,Series); 1496 % feval(action,num_i1,num_i2,num_j1,num_j2,Series); 1490 1497 end 1491 1498 set(handles.RUN,'BackgroundColor',[1 0 0]) … … 1518 1525 %---------------------------------------------- 1519 1526 function last_i_Callback(hObject, eventdata, handles) 1520 hseries=get(handles.last_i,'parent');1527 % hseries=get(handles.last_i,'parent'); 1521 1528 first_i=str2num(get(handles.first_i,'String')); 1522 1529 last_i=str2num(get(handles.last_i,'String')); … … 1524 1531 set(handles.ref_i,'String', num2str(ref_i)) 1525 1532 ref_i_Callback(hObject, eventdata, handles) 1526 SeriesData=get(h series,'UserData');1533 SeriesData=get(handles.figure1,'UserData'); 1527 1534 if ~isfield(SeriesData,'Time') 1528 1535 SeriesData.Time{1}=[]; … … 1536 1543 %------------------------------------------------------- 1537 1544 function last_j_Callback(hObject, eventdata, handles) 1538 hseries=get(handles.last_i,'parent');1545 % hseries=get(handles.last_i,'parent'); 1539 1546 first_j=str2num(get(handles.first_j,'String')); 1540 1547 last_j=str2num(get(handles.last_j,'String')); … … 1543 1550 1544 1551 ref_j_Callback(hObject, eventdata, handles) 1545 SeriesData=get(h series,'UserData');1552 SeriesData=get(handles.figure1,'UserData'); 1546 1553 if ~isfield(SeriesData,'Time') 1547 1554 SeriesData.Time{1}=[]; … … 1557 1564 mode_value=get(handles.mode,'Value'); 1558 1565 mode=mode_list{mode_value}; 1559 hseries=get(handles.ref_i,'parent');1560 SeriesData=get(h series,'UserData');1566 %hseries=get(handles.ref_i,'parent'); 1567 SeriesData=get(handles.figure1,'UserData'); 1561 1568 %NomTypeCell=get(handles.NomType,'String'); 1562 1569 NomTypeCell=SeriesData.NomType; … … 1578 1585 mode_value=get(handles.mode,'Value'); 1579 1586 mode=mode_list{mode_value}; 1580 hseries=get(handles.ref_i,'parent'); 1581 SeriesData=get(hseries,'UserData'); 1582 %NomTypeCell=get(handles.NomType,'String'); 1587 %hseries=get(handles.ref_i,'parent'); 1588 SeriesData=get(handles.figure1,'UserData'); 1583 1589 NomTypeCell=SeriesData.NomType; 1584 1590 if ~isempty(NomTypeCell) 1585 Val=get(handles.NomType,'Value'); 1586 NomType=NomTypeCell{Val}; 1587 % NomType=get(handles.NomType,'String'); 1591 Val=get(handles.NomType,'Value'); 1592 NomType=NomTypeCell{Val}; 1588 1593 if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2') 1589 1594 if isequal(mode,'series(Dj)') 1590 1595 find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files 1591 % break1592 1596 end 1593 1597 end … … 1597 1601 % --- Executes on selection change in ACTION. 1598 1602 function ACTION_Callback(hObject, eventdata, handles) 1603 global nb_builtin 1599 1604 list_ACTION=get(handles.ACTION,'String');% list menu fields 1600 1605 index_ACTION=get(handles.ACTION,'Value');% selected string index … … 1602 1607 path_series=which('series');%path to series.m 1603 1608 list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION 1604 nb_builtin=0; 1605 for ilist=1:length(list_path) 1606 if isequal(list_path{ilist},path_series) 1607 nb_builtin=nb_builtin+1; 1608 else 1609 break 1610 end 1611 end 1612 if nb_builtin==0% the path of series has been changed, reinitialize 1613 series_OpeningFcn(hObject, eventdata, handles) 1614 return 1615 end 1616 1617 % add a new function to the menu 1609 1610 % add a new function to the menu if the selected item is 'more...' 1618 1611 if isequal(ACTION,'more...') 1619 1612 pathfct=fileparts(path_series); 1620 browse_name=fullfile(path_series,'SERIES_FCT');%go to UVMAT/SERIES_FCTby default1621 if length(list_path)>nb_builtin1622 browse_name=list_path{end};% initialize browser with the path of the last introduced function1623 end1613 % browse_name=fullfile(path_series,'series');%go to UVMAT/series by default 1614 % if length(list_path)>nb_builtin 1615 % browse_name=list_path{end};% initialize browser with the path of the last introduced function 1616 % end 1624 1617 [FileName, PathName, filterindex] = uigetfile( ... 1625 1618 {'*.m', ' (*.m)'; 1626 1619 '*.m', '.m files '; ... 1627 1620 '*.*', 'All Files (*.*)'}, ... 1628 'Pick a file', browse_name);1621 'Pick a file',list_path{end}); 1629 1622 if length(FileName)<2 1630 1623 return 1631 end 1632 ext_fct=FileName(end-1:end);1624 end 1625 [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end); 1633 1626 if ~isequal(ext_fct,'.m') 1634 1627 msgbox_uvmat('ERROR','a Matlab function .m must be introduced'); 1635 1628 return 1636 1629 end 1637 ACTION=FileName(1:end-2);% ACTION choice updated by the selected item1638 1630 1639 1631 % insert the choice in the action menu … … 1641 1633 index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list 1642 1634 list_path{index_ACTION}=PathName; 1643 if length(menu_str)>nb_builtin+5; 1635 if length(menu_str)>nb_builtin+5; %nb_builtin=nbre of functions always remaining in the initial menu 1644 1636 nbremove=length(menu_str)-nb_builtin-5; 1645 1637 menu_str(nb_builtin+1:end-5)=[]; … … 1675 1667 %check the current path to the selected function 1676 1668 PathName=list_path{index_ACTION};%current recorded path 1677 if ~isequal(path_series,PathName)1678 CurrentPath=fileparts(which(ACTION));1679 if ~isequal(CurrentPath,PathName)&&~isequal(CurrentPath,fullfile(PathName,'private'))1680 addpath(PathName)1681 errormsg=check_functions;1682 msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])1683 end1684 end1669 % if ~isequal(path_series,PathName) 1670 % CurrentPath=fileparts(which(ACTION)); 1671 % if ~isequal(CurrentPath,PathName) 1672 % addpath(PathName) 1673 % errormsg=check_functions; 1674 % msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg]) 1675 % end 1676 % end 1685 1677 set(handles.path,'String',PathName); %show the path to the senlected function 1686 1678 … … 1719 1711 %set the displayed GUI item needed for input parameters 1720 1712 %list_input=feval(ACTION);% input list asked by the selected function 1721 varargout=feval(ACTION);% input list asked by the selected function 1713 if ~isequal(path_series,PathName) 1714 addpath(PathName) 1715 end 1716 eval(['h_function=@' ACTION ';']); 1717 if ~isequal(path_series,PathName) 1718 rmpath(PathName) 1719 end 1720 1721 varargout=h_function(); 1722 %varargout=feval(ACTION);% input list asked by the selected function 1722 1723 Param_list={}; 1723 1724 % RootPath=get(handles.RootPath,'String'); … … 1851 1852 delete(hget_field)%delete opened versions of get_field 1852 1853 end 1853 hseries=get(handles.FieldMenu,'parent');1854 SeriesData=get(h series,'UserData');1854 %hseries=get(handles.FieldMenu,'parent'); 1855 SeriesData=get(handles.figure1,'UserData'); 1855 1856 filename=SeriesData.CurrentInputFile; 1856 1857 if exist(filename,'file') … … 1879 1880 delete(hget_field) 1880 1881 end 1881 hseries=get(handles.FieldMenu,'parent');1882 SeriesData=get(h series,'UserData');1882 %hseries=get(handles.FieldMenu,'parent'); 1883 SeriesData=get(handles.figure1,'UserData'); 1883 1884 filename=SeriesData.CurrentInputFile_1; 1884 1885 if exist(filename,'file') … … 1897 1898 1898 1899 1899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1900 %detect the chosen series of files and check their date of modification: 1901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1902 %INPUT: 1903 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 1904 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 1905 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) 1906 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) 1907 %OTHER INPUTS given by the structure Series 1908 function GUI_input=check_files(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param); 1909 1910 %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) 1911 if ~exist('num_i1_cell','var') 1912 GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') 1913 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) 1914 'RootFile';'on';... %root input file name ('on' by default) 1915 'FileExt';'on';... %input file extension ('on' by default) 1916 'NomType';'on';...%type of file indexing ('on' by default) 1917 'NbSlice';'on'; ...%nbre of slices ('off' by default) 1918 %'VelTypeMenu';'on';...% menu for selecting the velocity type (civ1,..) 'off' by default) 1919 %'FieldMenu';'on';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 1920 %'CoordType';'on'...%can use a transform function 'off' by default 1921 %'GetObject';'on'...%can use projection object ,'off' by default 1922 %'GetMask';'on'...%can use mask option ,'off' by default 1923 %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 1924 ''}; 1925 return %exit the function 1926 end 1927 1928 %standard parameters for waitbar and STOP action (do not modify) 1929 hseries=guidata(Series.hseries);%handles of the GUI series 1930 WaitbarPos=get(hseries.waitbar_frame,'Position'); 1931 1932 %%%%%%%%%%%%%%%%%%%%%%%% 1933 1934 % number of slices 1935 NbSlice=str2num(get(hseries.NbSlice,'String')); 1936 if isempty(NbSlice) 1937 NbSlice=1; 1938 end 1939 NbSlice_name=num2str(NbSlice); 1940 if isequal(NbSlice,[]),NbSlice=1; end; %default 1941 1942 % number of views 1943 count=0; 1944 testcell=iscell(Series.RootFile); 1945 if ~testcell 1946 Series.RootPath={Series.RootPath}; 1947 Series.RootFile={Series.RootFile}; 1948 Series.SubDir={Series.SubDir}; 1949 Series.FileExt={Series.FileExt}; 1950 Series.NomType={Series.NomType}; 1951 end 1952 nbview=length(Series.RootFile); 1953 for iview=1:nbview 1954 filebase=fullfile(Series.RootPath{iview},Series.RootFile{iview});%root file name 1955 if testcell 1956 num_i1=num_i1_cell{iview}; num_i2=num_i2_cell{iview}; num_j1=num_j1_cell{iview}; num_j2=num_j2_cell{iview}; 1957 else 1958 num_i1=num_i1_cell; num_i2=num_i2_cell; num_j1=num_j1_cell; num_j2=num_j2_cell; 1959 end 1960 siz=size(num_i1); 1961 nbfield2=siz(1); %nb of consecutive fields at each level(burst 1962 nbfield=siz(1)*siz(2); 1963 nbfield=floor(nbfield/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices) 1964 if isequal(lower(Series.FileExt{iview}),'.avi') 1965 info=aviinfo([filebase Series.FileExt{iview}]); 1966 message{1}=info.Filename; 1967 message{2}=info.FileModDate; 1968 message{3}=[num2str(info.FramesPerSecond) ' frames/s ']; 1969 message{4}=info.ImageType; 1970 message{5}=[' compression' info.VideoCompression]; 1971 message{6}=[ 'quality ' num2str(info.Quality)]; 1972 Tabchar=message; 1973 else 1974 datnum=[]; 1975 Tabchar={}; 1976 %LOOP ON SLICES 1977 for i_slice=1:NbSlice 1978 for ifield=1:nbfield 1979 indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice 1980 end 1981 for index=1:nbfield*nbfield2 1982 stopstate=get(hseries.RUN,'BusyAction'); 1983 if isequal(stopstate,'queue')% enable STOP command 1984 update_waitbar(hseries.waitbar,WaitbarPos,index/(nbfield*nbfield2)) 1985 ifile=indselect(index); 1986 file=... 1987 name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2(ifile),num_j2(ifile),Series.SubDir{iview}); 1988 [Path,Name,ext]=fileparts(file); 1989 detect=exist(file,'file'); % check the existence of the file 1990 if detect==0 1991 count=count+1; 1992 lastfield='not found'; 1993 else 1994 datfile=dir(file); 1995 datnum(ifile)=datenum(datfile.date); 1996 filefound(ifile)={datfile.name}; 1997 lastfield=''; 1998 if isequal(Series.FileExt{iview},'.nc') || isequal(Series.FileExt{iview},'.cdf') 1999 % check the content netcdf file 2000 Data=nc2struct(file,'ListGlobalAttribute','patch2','fix2','civ2','patch','fix','absolut_time_T0','hart'); 2001 if ~isempty(Data.patch2) && isequal(Data.patch2,1) 2002 lastfield='patch2'; 2003 elseif ~isempty(Data.fix2) && isequal(Data.fix2,1) 2004 lastfield='fix2'; 2005 elseif ~isempty(Data.civ2) && isequal(Data.civ2,1); 2006 lastfield='civ2'; 2007 elseif ~isempty(Data.patch) && isequal(Data.patch,1); 2008 lastfield='patch1'; 2009 elseif ~isempty(Data.fix) && isequal(Data.fix,1); 2010 lastfield='fix1'; 2011 elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) 2012 lastfield='civ1'; 2013 end 2014 end 2015 end 2016 Tabchar(1,i_slice)={['slice #' num2str(i_slice)]}; 2017 Tabchar(index+1,i_slice)={[file ' ' lastfield]}; 2018 end 2019 end 2020 end 2021 if isempty(datnum) 2022 if NbSlice>1 2023 message=['no set of ' num2str(NbSlice) ' (NbSlices) files found']; 2024 else 2025 message='no file found'; 2026 end 2027 else 2028 datnum=datnum(find(datnum));%keep the non zero values corresponding to existing files 2029 [first,ind]=min(datnum); 2030 [last,indlast]=max(datnum); 2031 message={['oldest modification: ' cell2mat(filefound(ind)) ' : ' datestr(first)];... 2032 ['latest modification: ' cell2mat(filefound(indlast)) ' : ' datestr(last)]}; 2033 end 2034 if ~isempty(Tabchar) 2035 Tabchar=reshape(Tabchar,NbSlice*(nbfield*nbfield2+1),1); 2036 end 2037 end 2038 hfig=figure(iview); 2039 clf 2040 if iview>1 2041 pos=get(iview-1,'Position'); 2042 pos(1)=pos(1)+(iview-1)*pos(1)/nbview; 2043 set(hfig,'Position',pos) 2044 end 2045 set(hfig,'name',['view= ' num2str(iview)]) 2046 2047 h=uicontrol('Style','listbox', 'Position', [20 20 500 300], 'String', Tabchar, 'Callback', @ncbrowser_uvmat); 2048 hh=uicontrol('Style','listbox', 'Position', [20 340 500 40], 'String', message); 2049 end 2050 %---------------------------------------------------- 2051 % determine the list of index pairs of processing file 2052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2053 function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode) 2054 num_i1=num_i;% set of first image numbers by default 2055 num_i2=num_i; 2056 num_j1=num_j; 2057 num_j2=num_j; 2058 num_i_out=num_i; 2059 num_j_out=num_j; 2060 if isequal (NomType,'_i1-i2_j') |isequal (NomType,'_i1-i2') 2061 num_i1_line=num_i+ind_shift(3);% set of first image numbers 2062 num_i2_line=num_i+ind_shift(4); 2063 % adjust the first and last field number 2064 indsel=find(num_i1_line >= 1); 2065 num_i_out=num_i(indsel); 2066 num_i1_line=num_i1_line(indsel); 2067 num_i2_line=num_i2_line(indsel); 2068 num_j1=meshgrid(num_j,ones(size(num_i1_line))); 2069 num_j2=meshgrid(num_j,ones(size(num_i1_line))); 2070 [xx,num_i1]=meshgrid(num_j,num_i1_line); 2071 [xx,num_i2]=meshgrid(num_j,num_i2_line); 2072 elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab') 2073 if isequal(mode,'bursts') %case of bursts (png_old or png_2D) 2074 num_j1=ind_shift(1)*ones(size(num_i)); 2075 num_j2=ind_shift(2)*ones(size(num_i)); 2076 else 2077 num_j1_col=num_j+ind_shift(1);% set of first image numbers 2078 num_j2_col=num_j+ind_shift(2); 2079 % adjust the first field number 2080 indsel=find((num_j1_col >= 1)); 2081 num_j_out=num_j(indsel); 2082 num_j1_col=num_j1_col(indsel); 2083 num_j2_col=num_j2_col(indsel); 2084 [num_i1,num_j1]=meshgrid(num_i,num_j1_col); 2085 [num_i2,num_j2]=meshgrid(num_i,num_j2_col); 2086 end 2087 end 2088 2089 2090 %---------------------------------------------------------------------- 2091 % --- make average on a series of files 2092 %---------------------------------------------------------------------- 2093 %INPUT: 2094 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 2095 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 2096 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) 2097 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) 2098 %OTHER INPUTS given by the structure Series 2099 % Series.Time: 2100 % Series.GeometryCalib: 2101 function GUI_input=aver_stat(num_i1,num_i2,num_j1,num_j2,Series) 2102 %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) 2103 if ~exist('num_i1','var') 2104 GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') 2105 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) 2106 'RootFile';'on';... %root input file name ('on' by default) 2107 'FileExt';'on';... %input file extension ('on' by default) 2108 'NomType';'on';...%type of file indexing ('on' by default) 2109 'NbSlice';'on'; ...%nbre of slices ('off' by default) 2110 'VelTypeMenu';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) 2111 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 2112 'CoordType'; 'on';...%can use a transform function 2113 'GetObject';'on';...%can use projection object(option 'off'/'one'/'two', 2114 %'GetMask';'on'...%can use mask option 2115 %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter 2116 ''}; 2117 return 2118 end 2119 2120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2121 hseries=guidata(Series.hseries);%handles of the GUI series 2122 WaitbarPos=get(hseries.waitbar_frame,'Position'); 2123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2124 2125 %root input file and type 2126 if ~iscell(Series.RootPath)% case of a single input field series 2127 num_i1={num_i1};num_j1={num_j1};num_i2={num_i2};num_j2={num_j2}; 2128 RootPath={Series.RootPath}; 2129 RootFile={Series.RootFile}; 2130 SubDir={Series.SubDir}; 2131 FileExt={Series.FileExt}; 2132 NomType={Series.NomType}; 2133 else 2134 RootPath=Series.RootPath; 2135 RootFile=Series.RootFile; 2136 SubDir=Series.SubDir; 2137 NomType=Series.NomType; 2138 FileExt=Series.FileExt; 2139 end 2140 ext=FileExt{1}; 2141 form=imformats(ext([2:end]));%test valid Matlab image formats 2142 testima=0; 2143 if ~isempty(form)||isequal(lower(ext),'.avi')||isequal(lower(ext),'.vol') 2144 testima(1)=1; 2145 end 2146 if length(FileExt)>=2 2147 ext_1=FileExt{2}; 2148 form=imformats(ext_1([2:end]));%test valid Matlab image formats 2149 if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol') 2150 testima(2)=1; 2151 end 2152 if testima(2)~=testima(1) 2153 msgbox_uvmat('ERROR','images and netcdf files cannot be compared') 2154 return 2155 end 2156 end 2157 2158 %Number of input series: this function accepts two input file series at most (then it operates on the difference of fields) 2159 nbview=length(RootPath); 2160 if nbview>2 2161 RootPath=RootPath(1:2); 2162 set(hseries.RootPath,'String',RootPath) 2163 SubDir=SubDir(1:2); 2164 set(hseries.SubDir,'String',SubDir) 2165 RootFile=RootFile(1:2); 2166 set(hseries.RootFile,'String',RootFile) 2167 NomType=NomType(1:2); 2168 FileExt=FileExt(1:2); 2169 set(hseries.FileExt,'String',FileExt) 2170 nbview=2; 2171 end 2172 hhh=which('mmreader'); 2173 for iview=1:nbview 2174 test_movie(iview)=0; 2175 if ~isequal(hhh,'')&& mmreader.isPlatformSupported() 2176 if isequal(lower(FileExt{iview}),'.avi') 2177 MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}])); 2178 test_movie(iview)=1; 2179 end 2180 end 2181 end 2182 2183 % number of slices 2184 NbSlice=str2num(get(hseries.NbSlice,'String')); 2185 if isempty(NbSlice) 2186 NbSlice=1; 2187 end 2188 NbSlice_name=num2str(NbSlice); 2189 2190 % Field and velocity type (the same for the two views) 2191 Field_str=get(hseries.FieldMenu,'String'); 2192 FieldName=[]; %default 2193 testfield=get(hseries.FieldMenu,'Visible'); 2194 if isequal(testfield,'on') 2195 val=get(hseries.FieldMenu,'Value'); 2196 FieldName=Field_str(val);%the same set of fields for all views 2197 if isequal(FieldName,{'get_field...'}) 2198 hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI 2199 if length(hget_field)>1 2200 delete(hget_field(2:end)) 2201 elseif isempty(hget_field) 2202 filename=... 2203 name_generator(fullfile(RootPath{1},RootFile{1}),num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 2204 get_field(filename); 2205 return 2206 end 2207 %hhget_field=guidata(hget_field);%handles of GUI elements in get_field 2208 SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI 2209 end 2210 end 2211 %detect whether the two files are 'images' or 'netcdf' 2212 testima=0; 2213 testvol=0; 2214 testcivx=0; 2215 testnc=0; 2216 FileExt=get(hseries.FileExt,'String'); 2217 % test_movie=0; 2218 for iview=1:nbview 2219 ext=FileExt{iview}; 2220 form=imformats(ext([2:end])); 2221 if isequal(lower(ext),'.vol') 2222 testvol=testvol+1; 2223 elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab 2224 testima=testima+1; 2225 elseif isequal(ext,'.nc') 2226 testnc=testnc+1; 2227 end 2228 end 2229 if testvol 2230 msgbox_uvmat('ERROR','volume images not implemented yet') 2231 return 2232 end 2233 if testnc~=nbview && testima~=nbview && testvol~=nbview 2234 msgbox_uvmat('ERROR','compare two image series or two netcdf files with the same fields as input') 2235 return 2236 end 2237 if ~isequal(FieldName,{'get_field...'}) 2238 testcivx=testnc; 2239 end 2240 2241 if testcivx 2242 VelType_str=get(hseries.VelTypeMenu,'String'); 2243 VelType_val=get(hseries.VelTypeMenu,'Value'); 2244 VelType{1}=VelType_str{VelType_val}; 2245 if nbview==2 2246 VelType_str=get(hseries.VelTypeMenu_1,'String'); 2247 VelType_val=get(hseries.VelTypeMenu_1,'Value'); 2248 VelType{2}=VelType_str{VelType_val}; 2249 end 2250 end 2251 2252 %Calibration data and timing: read the ImaDoc files 2253 mode=''; %default 2254 timecell={}; 2255 itime=0; 2256 NbSlice_calib={}; 2257 for iview=1:nbview%Loop on views 2258 XmlData{iview}=[];%default 2259 filebase{iview}=fullfile(RootPath{iview},RootFile{iview}); 2260 if exist([filebase{iview} '.xml'],'file') 2261 [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 2262 if isfield(XmlData{iview},'Time') 2263 itime=itime+1; 2264 timecell{itime}=XmlData{iview}.Time; 2265 end 2266 if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') 2267 NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform 2268 if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) 2269 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); 2270 end 2271 end 2272 elseif exist([filebase{iview} '.civ'],'file') 2273 [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']); 2274 itime=itime+1; 2275 timecell{itime}=time; 2276 XmlData{iview}.Time=time; 2277 GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0]; 2278 GeometryCalib.Tx=0; 2279 GeometryCalib.Ty=0; 2280 GeometryCalib.Tz=1; 2281 GeometryCalib.dpx=1; 2282 GeometryCalib.dpy=1; 2283 GeometryCalib.sx=1; 2284 GeometryCalib.Cx=0; 2285 GeometryCalib.Cy=0; 2286 GeometryCalib.f=1; 2287 GeometryCalib.kappa1=0; 2288 GeometryCalib.CoordUnit='cm'; 2289 XmlData{iview}.GeometryCalib=GeometryCalib; 2290 if error==1 2291 msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file'); 2292 end 2293 end 2294 end 2295 2296 %check coincidence in time 2297 multitime=0; 2298 if length(timecell)==0 2299 time=[]; 2300 elseif length(timecell)==1 2301 time=timecell{1}; 2302 elseif length(timecell)>1 2303 multitime=1; 2304 for icell=1:length(timecell) 2305 if ~isequal(size(timecell{icell}),size(timecell{1})) 2306 msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') 2307 time=timecell{1}; 2308 multitime=0; 2309 break 2310 end 2311 end 2312 end 2313 if multitime 2314 for icell=1:length(timecell) 2315 time(icell,:,:)=timecell{icell}; 2316 end 2317 diff_time=max(max(diff(time))); 2318 if diff_time>0 2319 msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)]) 2320 end 2321 end 2322 if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 2323 time=[]; 2324 end 2325 2326 % Root name of output files (TO GENERALISE FOR TWO INPUT SERIES) 2327 filebasesub=fullfile(RootPath{1},SubDir{1},RootFile{1}); 2328 if isempty(SubDir{1}) % create a subdirectory '/mean' 2329 subdir_result='mean'; 2330 % filebasemean=fullfile(RootPath{1},subdir_result); 2331 if ~exist(fullfile(RootPath{1},subdir_result),'dir') 2332 dircur=pwd; %record current working directory 2333 cd(RootPath{1})% goes to the iamge directory 2334 [m1,m2,m3]=mkdir(subdir_result); 2335 if ~isequal(m2,'') 2336 msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation 2337 end 2338 cd(dircur) %back to the initial working directory 2339 end 2340 filebase_out=filebase{1}; 2341 else 2342 subdir_result=SubDir{1}; 2343 filebase_out=[filebase{1} '_mean'];% output root name obtained by adding the suffix _mean to the input 2344 end 2345 %output nomtype (to generalise) 2346 NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1)); 2347 2348 if NbSlice==1 2349 filebase_out=[filebasesub '_mean']; 2350 else 2351 filebase_out=[filebasesub '_' NbSlice_name 'mean']; 2352 answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']}); 2353 if ~isequal(answeryes,'Yes') 2354 return 2355 end 2356 end 2357 2358 % coordinate transform or other user defined transform 2359 Coord_menu=get(hseries.CoordType,'String'); 2360 menu_val=get(hseries.CoordType,'Value'); 2361 usrfct=Coord_menu{menu_val}; 2362 testfct=~isequal(usrfct,''); 2363 2364 %slice loop 2365 siz=size(num_i1{1}); 2366 lengthtot=siz(1)*siz(2); 2367 nbfield=floor(lengthtot/(siz(1)*NbSlice));%total number of i indexes (adjusted to an integer number of slices) 2368 nbfield_slice=nbfield*siz(1);% number of fields per slice 2369 2370 for i_slice=1:NbSlice 2371 S=0; %initiate the image sum S 2372 nbfiles=0; 2373 nbmissing=0; 2374 %averaging loop 2375 for ifile=i_slice:NbSlice:lengthtot 2376 stopstate=get(hseries.RUN,'BusyAction'); 2377 if isequal(stopstate,'queue') % enable STOP command 2378 update_waitbar(hseries.waitbar,WaitbarPos,ifile/lengthtot) 2379 for iview=1:nbview 2380 [filename]=... 2381 name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview}); 2382 if testima 2383 Data{iview}.ListVarName={'A'}; 2384 Data{iview}.AName='image'; 2385 if test_movie(iview) 2386 Data{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile)); 2387 else 2388 Data{iview}.A=read_image(filename,NomType{iview},num_i1{iview}(ifile));% read the image, num2 is the counter for avi files 2389 end 2390 Atype{iview}=class(Data{iview}.A); 2391 Data{iview}.A=double(Data{iview}.A); 2392 elseif testcivx 2393 [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); 2394 else 2395 [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data 2396 Data{iview}.VarAttribute=SubField.VarAttribute; 2397 end 2398 if isfield(Data{iview},'Txt') 2399 msgbox_uvmat('ERROR',['error of input reading: ' Data{iview}.Txt]) 2400 return 2401 end 2402 end 2403 % coordinate transform (or other user defined transform) 2404 if ~isequal(Series.CoordType,'') 2405 % z index 2406 if ~isempty(NbSlice_calib) 2407 Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform 2408 end 2409 if nbview==2 2410 [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2}); 2411 if isempty(Data{2}) 2412 Data(2)=[]; 2413 end 2414 else 2415 Data{1}=feval(Series.CoordType,Data{1},XmlData); 2416 end 2417 end 2418 if testcivx 2419 Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) 2420 end 2421 if length(Data)==2 2422 [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields 2423 if ~isempty(errormsg) 2424 msgbox_uvmat('ERROR',['error in aver_stat/sub_field:' errormsg]) 2425 return 2426 end 2427 else 2428 Field=Data{1}; 2429 end 2430 if isfield(Series,'ProjObject') 2431 [Field,errormsg]=proj_field(Field,Series.ProjObject); 2432 if ~isempty(errormsg) 2433 msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg]) 2434 return 2435 end 2436 end 2437 nbfiles=nbfiles+1; 2438 if nbfiles==1 %first field 2439 time_1=[]; 2440 if isfield(Field,'Time') 2441 time_1=Field.Time(1); 2442 end 2443 DataMean=Field;%default 2444 else 2445 for ivar=1:length(Field.ListVarName) 2446 VarName=Field.ListVarName{ivar}; 2447 eval(['sizmean=size(DataMean.' VarName ');']); 2448 eval(['siz=size(Field.' VarName ');']); 2449 if ~isequal(siz,sizmean) 2450 warndlg_uvmat(['unequal size of input field ' VarName ', need to interpolate on a grid'],'WARNING') 2451 nbmissing=nbmissing+1; 2452 break 2453 else 2454 eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum 2455 end 2456 end 2457 end 2458 % else 2459 % nbmissing=nbmissing+1; 1900 % %group the variables (fields of 'FieldData') in cells of variables with the same dimensions 1901 % %%%%%%%%%%%%%%%%%%%%%%% Function independante maintenant 1902 % %----------------------------------------------------------------- 1903 % [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1}); 1904 % %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 1905 % % CellVarIndex=cells of variable index arrays 1906 % ivar_new=0; % index of the current variable in the projected field 1907 % icoord=0; 1908 % for icell=1:length(CellVarIndex) 1909 % if NbDim(icell)==1 1910 % continue 1911 % end 1912 % VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 1913 % VarType=VarTypeCell{icell}; 1914 % ivar_X=VarType.coord_x; 1915 % ivar_Y=VarType.coord_y; 1916 % ivar_FF=VarType.errorflag; 1917 % if isempty(ivar_X) 1918 % test_grid=1;%test for input data on regular grid (e.g. image)coordinates 1919 % else 1920 % if length(ivar_Y)~=1 1921 % warndlg_uvmat('y coordinate missing in proj_field.m','ERROR') 1922 % return 1923 % end 1924 % test_grid=0; 1925 % end 1926 % % DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell) 1927 % %case of input fields with unstructured coordinates 1928 % if ~test_grid 1929 % for ivar=VarIndex 1930 % VarName=MergeData.ListVarName{ivar}; 1931 % for iview=1:nbview 1932 % eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName ';']) 2460 1933 % end 2461 end 2462 end %end averaging loop 2463 for ivar=1:length(Field.ListVarName) 2464 VarName=Field.ListVarName{ivar}; 2465 eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean 2466 end 2467 if nbmissing~=0 2468 msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted']) 2469 end 2470 if isempty(time) % time read from files prevails 2471 time_end=[]; 2472 if isfield(Field,'Time') 2473 time_end=Field.Time(1);%last time read 2474 if ~isempty(time_1) 2475 DataMean.Time=time_1; 2476 DataMean.Time_end=time_end; 2477 end 2478 end 2479 else % time from ImaDoc prevails 2480 DataMean.Time=time(1,num_i1{1}(1),num_j1{1}(1)); 2481 DataMean.Time_end=time(end,num_i1{end}(end),num_j1{end}(end)); 2482 end 2483 2484 %writing the result file 2485 if testima 2486 if NbSlice==1 2487 [filemean]=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.png',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end)); 2488 else % label the file number by the slice # for simplicity 2489 [filemean]=name_generator(filebase_out,i_slice,1,'.png','_i'); 2490 end 2491 if exist(filemean,'file') 2492 backupfile=filemean; 2493 testexist=2; 2494 while testexist==2 2495 backupfile=[backupfile(1:end-4) '~.png']; 2496 testexist=exist(backupfile,'file'); 2497 end 2498 [success,message]=copyfile(filemean,backupfile);%make backup 2499 if ~isequal(success,1) 2500 msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup']) 2501 return 2502 end 2503 end 2504 if isequal(Atype{1},'uint16') 2505 imwrite(uint16(DataMean.A),filemean,'BitDepth',16); 2506 else 2507 imwrite(uint8(DataMean.A),filemean,'BitDepth',8); 2508 end 2509 display([filemean ' written']); 2510 else %determine global attributes 2511 DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Series.Action}]; 2512 ActionKey='Action'; 2513 while isfield(DataMean,ActionKey) 2514 ActionKey=[ActionKey '_1']; 2515 end 2516 eval(['DataMean.' ActionKey '=Series.Action;']) 2517 DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {ActionKey}]; 2518 if isfield(DataMean,'Time') 2519 DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {'Time','Time_end'}]; 2520 end 2521 if NbSlice==1 2522 filemean=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.nc',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end)); 2523 else % label the file number by the slice # for simplicity 2524 [filemean]=name_generator(filebase_out,i_slice,1,'.nc','_i'); 2525 end 2526 if exist(filemean,'file') 2527 backupfile=filemean; 2528 testexist=2; 2529 while testexist==2 2530 backupfile=[backupfile(1:end-3) '~.nc']; 2531 testexist=exist(backupfile,'file'); 2532 end 2533 [success,message]=copyfile(filemean,backupfile);%make backup 2534 if ~isequal(success,1) 2535 msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup']) 2536 display(['previous file result ' filemean ' already exists, problem in backup']) 2537 return 2538 end 2539 end 2540 errormsg=struct2nc(filemean,DataMean); %save result file 2541 if isempty(errormsg) 2542 display([filemean ' written']); 2543 else 2544 msgbox_uvmat('ERROR',['error in writting result file: ' errormsg]) 2545 display(errormsg) 2546 end 2547 end 2548 end 2549 hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI 2550 delete(hget_field) 2551 'TEST' 2552 uvmat(filemean) 2553 2554 2555 % %---------------------------------------------------------------------- 2556 % % --makes a time averaged velocity field 2557 % %---------------------------------------------------------------------- 2558 % function aver_vel(num_i1,num_i2,num_j1,num_j2,Series) 2559 % %handles of the GUI series 2560 % 2561 % hseries=guidata(Series.hseries);%handles of the GUI series 2562 % WaitbarPos=get(hseries.waitbar_frame,'Position'); 2563 % Field_list=get(hseries.FieldMenu,'String'); 2564 % val=get(hseries.FieldMenu,'Value'); 2565 % FieldName=Field_list{val(1)}; 2566 % set(hseries.FieldMenu,'Value',val(1))% select only one input field 2567 % if isequal(FieldName,'get_field...') 2568 % hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI 2569 % end 2570 % %root input file and type 2571 % RootPath=get(hseries.RootPath,'String'); 2572 % SubDir=get(hseries.SubDir,'String'); 2573 % RootFile=get(hseries.RootFile,'String'); 2574 % %NomType=get(hseries.NomType,'String'); 2575 % NomType=Series.NomType; 2576 % FileExt=get(hseries.FileExt,'String'); 2577 % ext=FileExt{1}; 2578 % VelType_str=get(hseries.VelTypeMenu,'String'); 2579 % VelType_val=get(hseries.VelTypeMenu,'Value'); 2580 % VelType{1}=VelType_str{VelType_val}; 2581 % 2582 % time=0; %default 2583 % % number of slices 2584 % NbSlice=str2num(get(hseries.NbSlice,'String')); 2585 % if isempty(NbSlice) 2586 % NbSlice=1; 2587 % end 2588 % NbSlice_name=num2str(NbSlice); 2589 % filebase=fullfile(RootPath{1},RootFile{1}); 2590 % Calib=[]; 2591 % if exist([filebase '.xml'],'file') 2592 % %[error,Heading,nom_type_read,ext_ima_read,time_imadoc,TimeUnit,mode,NbSlice,npx,npy,Calib]=read_imadoc([filebase '.xml']); 2593 % [XmlData,warntext]=imadoc2struct([filebase '.xml']); 2594 % end 2595 % if NbSlice==1 2596 % filebase_mean=[filebase '_mean']; %root name for the result 2597 % else 2598 % filebase_mean=[filebase '_' NbSlice_name 'mean']; %root name for the results 2599 % answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_mean ' ...']}); 2600 % if ~isequal(answeryes,'Yes') 2601 % return 1934 % end 1935 % %case of fields defined on a structured grid 1936 % else 1937 % % DimValue=MergeData.DimValue(DimIndices);%set of dimension values 1938 % testFF=0; 1939 % for iview=2:nbview 1940 % % if ~isequal(DimValue,Data{iview}.DimValue(DimIndices)) 1941 % % MergeData.Txt='ERROR: attempt at merging structured fields with different sizes'; 1942 % % return 1943 % % end 1944 % for ivar=VarIndex 1945 % VarName=MergeData.ListVarName{ivar}; 1946 % if isfield(MergeData,'VarAttribute') 1947 % if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag') 1948 % testFF=1; 1949 % end 1950 % end 1951 % eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';']) 1952 % end 1953 % end 1954 % if testFF 1955 % nbaver=nbview-MergeData.FF; 1956 % indgood=find(nbaver>0); 1957 % for ivar=VarIndex 1958 % VarName=MergeData.ListVarName{ivar}; 1959 % eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);']) 1960 % end 1961 % else 1962 % for ivar=VarIndex 1963 % VarName=MergeData.ListVarName{ivar}; 1964 % eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;']) 1965 % end 1966 % end 2602 1967 % end 2603 1968 % end 2604 % siz=size(num_i1); 2605 % nbfield2=siz(1); %nb of consecutive fields at each level(burst) 2606 % lengthtot=siz(1)*siz(2); 2607 % nbfield=floor(lengthtot/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices) 2608 % nbfield_slice=nbfield*nbfield2;% number of fields per slice 2609 % %projection object 2610 % GridX=[]; 2611 % GridY=[]; 2612 % if isfield(Series,'sethandles') 2613 % Series.ProjObject=read_set_object(Series.sethandles); 2614 % if isfield(Series.ProjObject,'Style') 2615 % answeryes=questdlg({['statistics on field series projected on ' Series.ProjObject.Style]}); 2616 % if ~isequal(answeryes,'Yes') 2617 % return 2618 % end 2619 % end 2620 % end 2621 % 2622 % %LOOP ON SLICES 2623 % for i_slice=1:NbSlice 2624 % %select the series of image indices at the level islice 2625 % for ifield=1:nbfield 2626 % indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice 2627 % end 2628 % %name of result file 2629 % [filemean,idetect]=... 2630 % name_generator(filebase_mean,num_i1(i_slice),num_j1(1),Series.FileExt{1},'_i1-i2_j1-j2',1,num_i2(i_slice+nbfield_slice*NbSlice-1),num_j2(end),Series.SubDir{1}); 2631 % 2632 % % field=get(handles.civ1,'UserData');%read current selected field type (civ1,civ2...) 2633 % itime=0; 2634 % dt=[]; 2635 % %LOOP ON FIELDS IN A SLICE 2636 % test_interpolate=0;%default 2637 % for index=1:nbfield*nbfield2 2638 % ifile=indselect(index); 2639 % stopstate=get(hseries.RUN,'BusyAction'); 2640 % if isequal(stopstate,'queue')% enable STOP command 2641 % update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield*nbfield2)) 2642 % %name of the current file 2643 % [filename,idetect]=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{1},Series.NomType{1},1,num_i2(ifile),num_j2(ifile),Series.SubDir{1}); 2644 % %read input file 2645 % itime=itime+1; 2646 % if isequal(FieldName,'get_field...') 2647 % hhget_field=guidata(hget_field);%handles of GUI elements in get_field 2648 % hObject=0; 2649 % eventdata=0; 2650 % SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI 2651 % [Data,var_detect]=nc2struct(filename,SubField.ListVarName); %read input data 2652 % time(itime)=itime; 2653 % dt=1; 2654 % Calib_read=[]; 2655 % else 2656 % [nb_coord,nb_dim,Civ,CivStage,timeread,Data,VelTypeOut,Calib_read]=read_ncfield(filename,VelType{1});%reading the first file 2657 % time(itime)=timeread; 2658 % if isequal(Civ,1) 2659 % Data.CoordType='px';%test for pixel coordinates 2660 % if isequal(itime,1) 2661 % dt=Data.dt; 2662 % elseif ~isequal(Data.dt,dt) 2663 % warndlg_uvmat('series with non constant dt, need phys coordinates','ERROR') 2664 % return 2665 % end 2666 % end 2667 % end 2668 % %increment the detected fields, skip the others 2669 % if idetect==0 2670 % warndlg_uvmat(['input file ' filename ' not found'],'ERROR') 2671 % %A FAIRE STOCKER LE RESULT ACTUEL S'IL EXISTE 2672 % end 2673 % % itime=itime+1; 2674 % % time(itime)=timeread; 2675 % 2676 % %coordinate transform 2677 % if isempty(Calib) 2678 % Calib=Calib_read;%use Calib from xml file in priority, then Calib from the current file 2679 % end 2680 % if ~isequal(Series.CoordType,'') 2681 % Data=feval(Series.CoordType,Data,Calib); 2682 % end 2683 % %projection on object if defined 2684 % if isfield(Series,'ProjObject'); 2685 % Data=proj_field(Data,Series.ProjObject); 2686 % if isequal(itime,1)%use the positions on the first field for the whole series, ou utiliser grille 2687 % if isfield(Data,'Txt')%display error message 2688 % warndlg(Data.Txt,'ERROR') 2689 % return 2690 % end 2691 % end 2692 % else%remove false vectors and interpolate on the positions of the first field 2693 % Data=document_field(Data); 2694 % Data.Style='plane'; 2695 % end 2696 % %%%%%%%%% initiate the average at the first iteration: check list and structure of variables 2697 % if ifile==i_slice%first field in the slice 2698 % testfalse=0; 2699 % ListIndex={}; 2700 % testnewcell=1; 2701 % %group the variables (fields of 'Data') in cells of variables with the same dimensions 2702 % [DimVarIndex,CellVarIndex]=find_field_indices(Data); 2703 % VarIndex=CellVarIndex{1}; % ONLY THE FIRST VAR GROUP IS AVERAGED 2704 % DimIndex=Data.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell) 2705 % MeanData=Data;%transfer heading 2706 % MeanData.Time=[time(1) time(end)]; 2707 % MeanData.Action=Series.Action;%name of the processing programme 2708 % MeanData.ListDimName=Data.ListDimName(DimIndex);%name of dimension 2709 % MeanData.DimValue=Data.DimValue(DimIndex);%values of dimension (nbre of vectors) 2710 % MeanData.ListVarName=Data.ListVarName; 2711 % MeanData.VarDimIndex=Data.VarDimIndex; 2712 % MeanData.ListVarAttribute={'Role'};%list of variable attribute names A FAIRE: transferer les autres attributs 2713 % testsum=ones(size(VarIndex)); 2714 % indexfalse=0; 2715 % CoordName={}; 2716 % indexremove=[]; 2717 % if isfield(Data,'Role') % look for coordinate and flag variables 2718 % for ivar=1:length(VarIndex) 2719 % VarName=Data.ListVarName{VarIndex(ivar)}; 2720 % var_role=Data.Role{VarIndex(ivar)};%'role' of the variable 2721 % MeanData.Role{ivar}=var_role; 2722 % if isequal(var_role,'falseflag') 2723 % indexfalse=ivar; %test for false flag 2724 % indexremove=ivar; 2725 % FFName=VarName; 2726 % testsum(ivar)=0; 2727 % eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable 2728 % end 2729 % if isequal(var_role,'warnflag') 2730 % testsum(ivar)=0; %do not sum warn flag 2731 % eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable 2732 % indexremove=[indexremove ivar]; 2733 % end 2734 % if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|isequal(var_role,'coord_z') 2735 % eval(['MeanData.' VarName '=Data.' VarName ';']); 2736 % testsum(ivar)=0; 2737 % eval(['CoordName=[CoordName ''' VarName '''];']); 2738 % end 2739 % if testsum(ivar)~=0 2740 % eval(['MeanData.' VarName '=zeros(size(Data.' VarName '));']);%initialise sum 2741 % end 2742 % end 2743 % end 2744 % findsum=find(testsum); 2745 % VarIndexSum=VarIndex(findsum);%indices of variables to sum (not coordinates nor flags) 2746 % if length(CoordName)==0 2747 % if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates, prepare histograms 2748 % for ilist=1:length(VarIndexSum) 2749 % VarName=Data.ListVarName{VarIndexSum(ilist)}; 2750 % eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable 2751 % indexremove=[indexremove ilist]; 2752 % eval(['[MeanData.' VarName 'hist,MeanData.' VarName 'val]=hist(Data.' VarName ',100);']);%make histo 2753 % eval(['sizhist=size(MeanData.' VarName 'hist);']) 2754 % if sizhist(1)==1 2755 % eval(['MeanData.' VarName 'hist=MeanData.' VarName 'hist'';']) 2756 % end 2757 % eval(['maxval=max(MeanData.' VarName 'val);']); 2758 % eval(['minval=min(MeanData.' VarName 'val);']); 2759 % dC(ilist)=(maxval-minval)/100;%size of the histogram bin 2760 % end 2761 % else 2762 % % icoord=0; 2763 % % for ilist=1:length(DimVarIndex) 2764 % % VarDim=Data.ListVarName{DimVarIndex(ilist)}; 2765 % % icoord=icoord+1; 2766 % % % eval(['Coord{' num2str(icord) '}=[' CoordName ''' VarName ''']']); 2767 % % %eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']); 2768 % % end 2769 % end 2770 % end 2771 % if ~isempty(indexremove) 2772 % MeanData.ListVarName(VarIndex(indexremove))=[]; 2773 % MeanData.VarDimIndex(VarIndex(indexremove))=[]; 2774 % if isfield(MeanData,'Role')%generaliser aus autres attributs 2775 % MeanData.Role(VarIndex(indexremove))=[]; 2776 % end 2777 % end 2778 % % END OF INITIALISATION 2779 % 2780 % end 2781 % 2782 % % A FAIRE: regular grid if coord_x undefined 2783 % if indexfalse~=0 %suppress false data 2784 % eval(['testexist=isfield(Data,''' FFName ''');']) 2785 % if testexist 2786 % eval(['indsel=find(Data.' FFName '==0);']); 2787 % for icoord=1:length(CoordName) 2788 % eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']); 2789 % end 2790 % end 2791 % end 2792 % for ilist=1:length(VarIndexSum) 2793 % VarName=Data.ListVarName{VarIndexSum(ilist)}; 2794 % if indexfalse~=0 & testexist 2795 % eval(['Data.' VarName '=Data.' VarName '(indsel);']); 2796 % end 2797 % if length(CoordName)==0%no variable use dfor unstructured coordinates 2798 % if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates 2799 % % %update histogram with the current field #ifile 2800 % str_left=['[MeanData.' VarName 'val,MeanData.' VarName 'hist]=']; 2801 % str_right=['hist_update(MeanData.' VarName 'val,MeanData.' VarName 'hist,Data.' VarName ',dC(ilist));']; 2802 % eval([str_left str_right]);%update global histo 2803 % else 2804 % %INTERPOLER 2805 % 2806 % eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum%CAS x,y change 2807 % end 2808 % else 2809 % if length(CoordName)==2 2810 % eval(['test_interp= ~isequal(Data.' CoordName{1} ',MeanData.' CoordName{1} ... 2811 % ')|~isequal(Data.' CoordName{2} ',MeanData.' CoordName{2} ');']) 2812 % if test_interp 2813 % eval(['Data.' VarName '=griddata_uvmat(Data.' CoordName{1} ',Data.' CoordName{2}... 2814 % ',Data.' VarName ',MeanData.' CoordName{1} ',MeanData.' CoordName{2} ');']); 2815 % test_interpolate=1; 2816 % end 2817 % end 2818 % eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum 2819 % end 2820 % end 2821 % end 2822 % end 2823 % if length(CoordName)~=0 | ~isequal(DimVarIndex,0)% no coordinate variable for structured coordinates 2824 % for ilist=1:length(VarIndexSum) 2825 % VarName=Data.ListVarName{VarIndexSum(ilist)}; 2826 % eval(['MeanData.' VarName '=MeanData.' VarName '/itime;']);%normalize sum by the number of fields 2827 % end 2828 % else 2829 % MeanData.NbDim=1; 2830 % MeanData.ListDimName={}; 2831 % MeanData.DimValue=[]; 2832 % for ilist=1:length(VarIndexSum) 2833 % VarName=Data.ListVarName{VarIndexSum(ilist)}; 2834 % MeanData.ListVarName=[MeanData.ListVarName {[VarName 'val']} {[VarName 'hist']}]; 2835 % MeanData.VarDimIndex=[MeanData.VarDimIndex {[ilist]} {[ilist]}]; 2836 % MeanData.ListDimName=[MeanData.ListDimName {[VarName 'val']}]; 2837 % eval(['MeanData.DimValue=[MeanData.DimValue length(MeanData.' VarName 'val)];']); 2838 % end 2839 % end 2840 % figure 2841 % haxes=axes; 2842 % plot_field(MeanData,haxes)%plot the resulting average 2843 % % change variable names for consitency with civ1 data (need to generalize these programs) 2844 % if length(MeanData.ListVarName) >= 4 & isequal(MeanData.ListVarName(1:4), {'X' 'Y' 'U' 'V'}) 2845 % MeanData.ListGlobalAttribute={'nb_coord','nb_dim','dt','absolut_time_T0','pixcmx','pixcmy','hart','civ','fix'}; 2846 % MeanData.nb_coord=2; 2847 % MeanData.nb_dim=2; 2848 % MeanData.dt=1; 2849 % MeanData.absolut_time_T0=0; 2850 % MeanData.pixcmx=1; %pix per cm (1 by default) 2851 % MeanData.pixcmy=1; %pix per cm (1 by default) 2852 % MeanData.hart=0; 2853 % if isequal(Data.CoordType,'px') 2854 % MeanData.civ=1; 2855 % else 2856 % MeanData.civ=0; 2857 % end 2858 % MeanData.fix=0; 2859 % MeanData.ListVarName(1:4)={'vec_X' 'vec_Y' 'vec_U' 'vec_V'}; 2860 % MeanData.vec_X=MeanData.X; 2861 % MeanData.vec_Y=MeanData.Y; 2862 % MeanData.vec_U=MeanData.U; 2863 % MeanData.vec_V=MeanData.V; 2864 % end 2865 % error=struct2nc(filemean,MeanData); %save result file 2866 % if isequal(error,0) 2867 % if test_interpolate 2868 % 'fields interpolated to the positions of the first one' 2869 % end 2870 % [filemean ' written'] 2871 % else 2872 % warndlg_uvmat(error,'ERROR') 2873 % end 2874 % end 2875 2876 %---------------------------------------------------------------------- 2877 % --project fields on a projection object (e. g. a regular grid), possibly 2878 % merge several fields 2879 %---------------------------------------------------------------------- 2880 %INPUT: 2881 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 2882 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 2883 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) 2884 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) 2885 %OTHER INPUTS given by the structure Series 2886 function GUI_input=merge_proj(num_i1,num_i2,num_j1,num_j2,Series); 2887 2888 %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) 2889 if ~exist('num_i1','var') 2890 GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') 2891 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) 2892 'RootFile';'on';... %root input file name ('on' by default) 2893 'FileExt';'on';... %input file extension ('on' by default) 2894 'NomType';'on';...%type of file indexing ('on' by default) 2895 'NbSlice';'on'; ...%nbre of slices ('off' by default) 2896 'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default) 2897 'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 2898 'CoordType';'on';...%can use a transform function 'off' by default 2899 'GetObject';'on';...%can use projection object ,'off' by default 2900 %'GetMask';'on'...%can use mask option ,'off' by default 2901 %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 2902 ''}; 2903 return %exit the function 2904 end 2905 2906 %------------------------------------------------- 2907 hseries=guidata(Series.hseries);%handles of the GUI series 2908 WaitbarPos=get(hseries.waitbar_frame,'Position'); %positiopn of waitbar frame 2909 %------------------------------------------------- 2910 2911 %numbers of view fields (nbre of inputs in RootPath) 2912 testcell=iscell(Series.RootFile); 2913 if ~testcell 2914 Series.RootPath={Series.RootPath}; 2915 Series.RootFile={Series.RootFile}; 2916 Series.SubDir={Series.SubDir}; 2917 Series.FileExt={Series.FileExt}; 2918 Series.NomType={Series.NomType}; 2919 num_i1={num_i1}; 2920 num_i2={num_i2}; 2921 num_j1={num_j1}; 2922 num_j2={num_j2}; 2923 end 2924 nbview=length(Series.RootFile);%number of views (file series to merge) 2925 nbfield=size(num_i1{1},1)*size(num_i1{1},2);%number of fields in the time series 2926 transform=Series.CoordType; % field transform function 2927 hhh=which('mmreader'); 2928 for iview=1:nbview 2929 test_movie(iview)=0; 2930 if ~isequal(hhh,'')&& mmreader.isPlatformSupported() 2931 if isequal(lower(FileExt{iview}),'.avi') 2932 MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}])); 2933 test_movie(iview)=1; 2934 end 2935 end 2936 end 2937 2938 %Calibration data and timing: read the ImaDoc files 2939 mode=''; %default 2940 timecell={}; 2941 itime=0; 2942 NbSlice_calib={}; %test for z index 2943 for iview=1:nbview%Loop on views 2944 XmlData{iview}=[];%default 2945 filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview}); 2946 if exist([filebase{iview} '.xml'],'file') 2947 [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 2948 if isfield(XmlData{iview},'Time') 2949 itime=itime+1; 2950 timecell{itime}=XmlData{iview}.Time; 2951 end 2952 if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') 2953 NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1); 2954 if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) 2955 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); 2956 end 2957 end 2958 elseif exist([filebase{iview} '.civ'],'file') 2959 [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']); 2960 itime=itime+1; 2961 timecell{itime}=time; 2962 XmlData{iview}.Time=time; 2963 GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0]; 2964 GeometryCalib.Tx=0; 2965 GeometryCalib.Ty=0; 2966 GeometryCalib.Tz=1; 2967 GeometryCalib.dpx=1; 2968 GeometryCalib.dpy=1; 2969 GeometryCalib.sx=1; 2970 GeometryCalib.Cx=0; 2971 GeometryCalib.Cy=0; 2972 GeometryCalib.f=1; 2973 GeometryCalib.kappa1=0; 2974 GeometryCalib.CoordUnit='cm'; 2975 XmlData{iview}.GeometryCalib=GeometryCalib; 2976 if error==1 2977 msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file'); 2978 end 2979 end 2980 end 2981 2982 %check coincidence in time 2983 multitime=0; 2984 if length(timecell)==0 2985 time=[]; 2986 elseif length(timecell)==1 2987 time=timecell{1}; 2988 elseif length(timecell)>1 2989 multitime=1; 2990 for icell=1:length(timecell) 2991 if ~isequal(size(timecell{icell}),size(timecell{1})) 2992 msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') 2993 time=timecell{1}; 2994 multitime=0; 2995 break 2996 end 2997 end 2998 end 2999 if multitime 3000 for icell=1:length(timecell) 3001 time(icell,:,:)=timecell{icell}; 3002 end 3003 diff_time=max(max(diff(time))); 3004 if diff_time>0 3005 msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)]) 3006 end 3007 end 3008 if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 3009 time=[]; 3010 end 3011 3012 % Field and velocity type (the same for all views) 3013 Field_str=get(hseries.FieldMenu,'String'); 3014 val=get(hseries.FieldMenu,'Value'); 3015 FieldName=Field_str(val);%the same set of fields for all views 3016 VelType_str=get(hseries.VelTypeMenu,'String'); 3017 VelType_val=get(hseries.VelTypeMenu,'Value'); 3018 VelType=VelType_str{VelType_val}; %the same for all views 3019 if isequal(FieldName,'get_field...') 3020 hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI 3021 % hhget_field=guidata(hget_field);%handles of GUI elements in get_field 3022 SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI 3023 % if isequal(get(hhget_field.menu_coord,'Visible'),'on') 3024 % list_transform=get(hhget_field.menu_coord,'String'); 3025 % val_list=get(hhget_field.menu_coord,'Value'); 3026 % transform=list_transform{val_list}; 3027 % end 3028 end 3029 %detect whether all the files are 'images' or 'netcdf' 3030 testima=0; 3031 testvol=0; 3032 testcivx=0; 3033 testnc=0; 3034 FileExt=get(hseries.FileExt,'String'); 3035 for iview=1:nbview 3036 ext=FileExt{iview}; 3037 form=imformats(ext([2:end])); 3038 if isequal(lower(ext),'.vol') 3039 testvol=testvol+1; 3040 elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab 3041 testima=testima+1; 3042 elseif isequal(ext,'.nc') 3043 testnc=testnc+1; 3044 end 3045 end 3046 if testvol 3047 msgbox_uvmat('ERROR','volume images not implemented yet') 3048 return 3049 end 3050 if testnc~=nbview && testima~=nbview && testvol~=nbview 3051 msgbox_uvmat('ERROR','need a set of images or a set of netcdf files with the same fields as input') 3052 return 3053 end 3054 if ~isequal(FieldName,'get_field...') 3055 testcivx=testnc; 3056 end 3057 %name of output files and directory: 3058 % res_subdir=fullfile(Series.RootPath{1},[Series.SubDir{1} '_STAT']); 3059 ProjectDir=fileparts(fileparts(Series.RootPath{1}));% preoject directory (GERK) 3060 prompt={['result directory (in' ProjectDir ')']}; 3061 RootPath=get(hseries.RootPath,'String'); 3062 SubDir=get(hseries.SubDir,'String'); 3063 if isequal(length(RootPath),1) 3064 fulldir=RootPath{1}; 3065 subdir='GRID'; 3066 res_subdir=fullfile(fulldir,subdir); 3067 else 3068 def={fullfile(ProjectDir,'0_RESULTS')}; 3069 dlgTitle='result directory'; 3070 lineNo=1; 3071 answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def); 3072 fulldir=answer{1}; 3073 subdir=[]; 3074 dirlist=sort(Series.RootFile); 3075 for iview=1:nbview 3076 if ~isempty(subdir) 3077 subdir=[subdir '-']; 3078 end 3079 subdir=[subdir dirlist{iview}]; 3080 end 3081 res_subdir=fullfile(fulldir,subdir); 3082 end 3083 ext=FileExt{1}; 3084 if ~exist(fulldir,'dir') 3085 msgbox_uvmat('ERROR',['directory ' fulldir ' needs to be created']) 3086 return 3087 end 3088 if ~exist(res_subdir,'dir') 3089 dircur=pwd; 3090 cd(fulldir) 3091 error=mkdir(subdir); 3092 cd(dircur) 3093 end 3094 filebasesub=fullfile(res_subdir,Series.RootFile{1}); 3095 filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files 3096 3097 %projection object 3098 if isfield(Series,'sethandles') 3099 if ishandle(Series.sethandles.set_object) 3100 Series.ProjObject=read_set_object(Series.sethandles); 3101 if ~isfield(Series.ProjObject,'Style') 3102 msgbox_uvmat('ERROR','Undefined projection object style') 3103 return 3104 end 3105 if ~isequal(Series.ProjObject.Style,'plane') 3106 msgbox_uvmat('ERROR','The projection object must be a plane') 3107 return 3108 end 3109 end 3110 end 3111 3112 %MAIN LOOP 3113 for ifile=1:nbfield 3114 stopstate=get(hseries.RUN,'BusyAction'); 3115 if isequal(stopstate,'queue')% enable STOP command from the 'series' interface 3116 update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) 3117 Amerge=0; 3118 3119 %----------LOOP ON VIEWS---------------------- 3120 nbtime=0; 3121 for iview=1:nbview 3122 %name of the current file 3123 filename=name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview}); 3124 if ~exist(filename,'file') 3125 msgbox_uvmat('ERROR',['missing input file' filename]) 3126 break 3127 end 3128 3129 %reading the current file 3130 if testima 3131 if test_movie(iview) 3132 Field{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile)); 3133 else 3134 Field{iview}.A=read_image(filename,Series.NomType{iview},num_i1{iview}(ifile)); 3135 end % TODO: introduce ListVarName 3136 npxy=size(Field{iview}.A); 3137 Field{iview}.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers 3138 Field{iview}.AY=[npxy(1)-0.5 0.5]; 3139 Field{iview}.CoordType='px'; 3140 Field{iview}.AName='image'; 3141 else 3142 if testcivx 3143 [Field{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); 3144 else 3145 [Field{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data 3146 Field{iview}.VarAttribute=SubField.VarAttribute; 3147 end 3148 if isfield(Field{iview},'Time') 3149 timeread(iview)=Field{iview}.Time; 3150 nbtime=nbtime+1; 3151 end 3152 end 3153 % coord transform 3154 % z index 3155 if ~isempty(NbSlice_calib) 3156 Field{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1; 3157 end 3158 if ~isequal(transform,'') 3159 Field{iview}=feval(Series.CoordType,Field{iview},XmlData{iview});%transform to phys if requested 3160 end 3161 if testcivx 3162 Field{iview}=calc_field(FieldName,Field{iview}); 3163 end 3164 3165 %projection on object (gridded plane) 3166 if isfield(Series,'ProjObject') 3167 Field{iview}=proj_field(Field{iview},Series.ProjObject); 3168 end 3169 end 3170 3171 %----------END LOOP ON VIEWS---------------------- 3172 3173 %merge the nbview fields 3174 MergeData=merge_field(Field); 3175 if isfield(MergeData,'Txt') 3176 msgbox_uvmat('ERROR',MergeData.Txt) 3177 return 3178 end 3179 3180 % generating the name of the merged field 3181 mergename=name_generator(filebase_merge,num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile)); 3182 3183 % time: 3184 time_i=0;%default 3185 if isempty(time)% time from ImaDoc prevails 3186 time_i=sum(timeread)/nbtime; 3187 else 3188 time_i=(time(iview,num_i1{iview}(ifile),num_j1{iview}(ifile))+time(iview,num_i2{iview}(ifile),num_j2{iview}(ifile)))/2; 3189 end 3190 3191 % recording the merged field 3192 if testima %in case of input images an image is produced 3193 if isa(MergeData.A,'uint8') 3194 bitdepth=8; 3195 elseif isa(MergeData.A,'uint16') 3196 bitdepth=16; 3197 end 3198 imwrite(MergeData.A,mergename,'BitDepth',bitdepth); 3199 %write xml calibration file 3200 siz=size(MergeData.A); 3201 npy=siz(1); 3202 npx=siz(2); 3203 if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1') 3204 Rangx=MergeData.VarAttribute{1}.Coord_2; 3205 Rangy=MergeData.VarAttribute{1}.Coord_1; 3206 elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY') 3207 Rangx=[MergeData.AX(1) MergeData.AX(end)]; 3208 Rangy=[MergeData.AY(1) MergeData.AY(end)]; 3209 else 3210 Rangx=[0.5 npx-0.5]; 3211 Rangy=[npy-0.5 0.5];%default 3212 end 3213 pxcmx=(npx-1)/(Rangx(2)-Rangx(1)); 3214 pxcmy=(npy-1)/(Rangy(1)-Rangy(2)); 3215 T_x=-pxcmx*Rangx(1)+0.5; 3216 T_y=-pxcmy*Rangy(2)+0.5; 3217 GeometryCal.focal=1; 3218 GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1]; 3219 GeometryCal.Tx_Ty_Tz=[T_x T_y 1]; 3220 ImaDoc.GeometryCalib=GeometryCal; 3221 t=struct2xml(ImaDoc); 3222 t=set(t,1,'name','ImaDoc'); 3223 save(t,[filebase_merge '.xml']) 3224 display([filebase_merge '.xml saved']) 3225 else 3226 MergeData.ListGlobalAttribute={'Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'}; 3227 MergeData.nb_coord=2; 3228 MergeData.nb_dim=2; 3229 MergeData.dt=1; 3230 MergeData.Time=time_i; 3231 error=struct2nc(mergename,MergeData); %save result file 3232 if isempty(error) 3233 display(['output file ' mergename ' written']) 3234 else 3235 display(error) 3236 end 3237 end 3238 end 3239 end 3240 3241 %-------------------------------------------------------------------------- 3242 function MergeData=merge_field(Data) 3243 % initiate Matlab structure for physical field 3244 if isempty(Data)||~iscell(Data) 3245 MergeData=[]; 3246 return 3247 end 3248 MergeData=Data{1};%default 3249 error=0; 3250 nbview=length(Data); 3251 if nbview==1 3252 return 3253 end 3254 for iview=1:nbview 3255 if ~isequal(MergeData.ListDimName,Data{iview}.ListDimName) 3256 error=1; 3257 end 3258 if ~isequal(MergeData.ListVarName,Data{iview}.ListVarName) 3259 error=1; 3260 end 3261 % if ~isequal(MergeData.VarDimIndex,Data{iview}.VarDimIndex) 3262 % error=1; 3263 % end 3264 end 3265 if error 3266 MergeData.Txt='ERROR: attempt at merging fields of incompatible type'; 3267 return 3268 end 3269 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions 3270 %----------------------------------------------------------------- 3271 [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1}); 3272 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 3273 % CellVarIndex=cells of variable index arrays 3274 ivar_new=0; % index of the current variable in the projected field 3275 icoord=0; 3276 for icell=1:length(CellVarIndex) 3277 if NbDim(icell)==1 3278 continue 3279 end 3280 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 3281 VarType=VarTypeCell{icell}; 3282 ivar_X=VarType.coord_x; 3283 ivar_Y=VarType.coord_y; 3284 ivar_FF=VarType.errorflag; 3285 if isempty(ivar_X) 3286 test_grid=1;%test for input data on regular grid (e.g. image)coordinates 3287 else 3288 if length(ivar_Y)~=1 3289 warndlg_uvmat('y coordinate missing in proj_field.m','ERROR') 3290 return 3291 end 3292 test_grid=0; 3293 end 3294 % DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell) 3295 %case of input fields with unstructured coordinates 3296 if ~test_grid 3297 for ivar=VarIndex 3298 VarName=MergeData.ListVarName{ivar}; 3299 for iview=1:nbview 3300 eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName ';']) 3301 end 3302 end 3303 %case of fields defined on a structured grid 3304 else 3305 % DimValue=MergeData.DimValue(DimIndices);%set of dimension values 3306 testFF=0; 3307 for iview=2:nbview 3308 % if ~isequal(DimValue,Data{iview}.DimValue(DimIndices)) 3309 % MergeData.Txt='ERROR: attempt at merging structured fields with different sizes'; 3310 % return 3311 % end 3312 for ivar=VarIndex 3313 VarName=MergeData.ListVarName{ivar}; 3314 if isfield(MergeData,'VarAttribute') 3315 if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag') 3316 testFF=1; 3317 end 3318 end 3319 eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';']) 3320 end 3321 end 3322 if testFF 3323 nbaver=nbview-MergeData.FF; 3324 indgood=find(nbaver>0); 3325 for ivar=VarIndex 3326 VarName=MergeData.ListVarName{ivar}; 3327 eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);']) 3328 end 3329 else 3330 for ivar=VarIndex 3331 VarName=MergeData.ListVarName{ivar}; 3332 eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;']) 3333 end 3334 end 3335 end 3336 end 3337 3338 3339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3340 %detect the chosen series of files and check their date of modification: 3341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3342 %INPUT: 3343 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 3344 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 3345 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) 3346 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) 3347 %OTHER INPUTS given by the structure Series 3348 function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param); 3349 3350 %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) 3351 if ~exist('num_i1','var') 3352 GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') 3353 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) 3354 %'RootFile';'on';... %root input file name ('on' by default) 3355 %'FileExt';'on';... %input file extension ('on' by default) 3356 %'NomType';'on';...%type of file indexing ('on' by default) 3357 %'NbSlice';'on'; ...%nbre of slices ('off' by default) 3358 %'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default) 3359 %'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 3360 %'CoordType';'on'...%can use a transform function 'off' by default 3361 %'GetObject';'on'...%can use projection object ,'off' by default 3362 %'GetMask';'on'...%can use mask option ,'off' by default 3363 %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 3364 ''}; 3365 return %exit the function 3366 end 3367 %--------------------------------------------------------- 3368 hseries=guidata(Series.hseries);%handles of the GUI series 3369 WaitbarPos=get(hseries.waitbar_frame,'Position'); 3370 3371 %%%%%%%%%%%%%%%%%%%%%%%% 3372 message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)'; 3373 answer=msgbox_uvmat('INPUT_Y-N',message); 3374 if ~isequal(answer,'Yes') 3375 return 3376 end 3377 nbdelete=0; 3378 testcell=iscell(Series.RootFile); 3379 if ~testcell 3380 Series.RootPath={Series.RootPath}; 3381 Series.RootFile={Series.RootFile}; 3382 Series.SubDir={Series.SubDir}; 3383 Series.FileExt={Series.FileExt}; 3384 Series.NomType={Series.NomType}; 3385 end 3386 for iview=1:length(Series.RootFile) 3387 hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files 3388 for ilist=1:length(hdir) 3389 update_waitbar(hseries.waitbar,WaitbarPos,ilist/length(hdir)) 3390 FileName=hdir(ilist).name; 3391 [dd,ff,Ext]=fileparts(FileName); 3392 if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors') 3393 delete(fullfile(Series.RootPath{iview},Series.SubDir{iview},FileName)) 3394 nbdelete=nbdelete+1; 3395 end 3396 end 3397 end 3398 msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx']) 3399 3400 3401 3402 1969 % 3403 1970 3404 1971 %----------------------------- … … 3607 2174 3608 2175 3609 %---------------------------------------------------------------------- 3610 % --- make a time series analysis 3611 %---------------------------------------------------------------------- 3612 %INPUT: 3613 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 3614 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 3615 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) 3616 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) 3617 %OTHER INPUTS given by the structure Series 3618 function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series) 3619 3620 %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) 3621 if ~exist('num_i1','var') 3622 GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') 3623 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) 3624 'RootFile';'on';... %root input file name ('on' by default) 3625 'FileExt';'on';... %input file extension ('on' by default) 3626 'NomType';'on';...%type of file indexing ('on' by default) 3627 'NbSlice';'on'; ...%nbre of slices ('off' by default) 3628 'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default) 3629 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 3630 'CoordType';'on';...%can use a transform function 'off' by default 3631 'GetObject';'on';...%can use projection object ,'off' by default 3632 %'GetMask';'on'...%can use mask option ,'off' by default 3633 %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 3634 ''}; 3635 return %exit the function 3636 end 3637 3638 %------------------------------------------------------ 3639 hseries=guidata(Series.hseries);%handles in the GUI series 3640 WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame 3641 3642 %projection object 3643 test_object=get(hseries.GetObject,'Value'); 3644 if test_object%isfield(Series,'sethandles') 3645 Series.ProjObject=read_set_object(Series.sethandles); 3646 %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]}); 3647 answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' Series.ProjObject.Style]); 3648 if ~isequal(answeryes,'Yes') 3649 return 3650 end 3651 else 3652 msgbox_uvmat('ERROR','a projection object is needed'); 3653 return 3654 end 3655 3656 % root names 3657 if iscell(Series.RootPath) 3658 RootPath=Series.RootPath; 3659 RootFile=Series.RootFile; 3660 SubDir=Series.SubDir; 3661 FileExt=Series.FileExt; 3662 NomType=Series.NomType; 3663 else 3664 RootPath={Series.RootPath}; 3665 RootFile={Series.RootFile}; 3666 SubDir={Series.SubDir}; 3667 FileExt={Series.FileExt}; 3668 NomType={Series.NomType}; 3669 num_i1={num_i1}; 3670 num_i2={num_i2}; 3671 num_j1={num_j1}; 3672 num_j2={num_j2}; 3673 end 3674 ext=FileExt{1}; 3675 form=imformats(ext([2:end]));%test valid Matlab image formats 3676 testima=0; 3677 if ~isempty(form)||isequal(lower(ext),'.avi') 3678 testima=1; 3679 end 3680 nbview=length(RootPath);%number of series (1 or 2) 3681 nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series 3682 3683 %Number of input series: this function accepts only a single input file series 3684 nbview=length(RootPath); 3685 if nbview==2 3686 %TODO: choose between difference and two series 3687 elseif nbview>2 % TODO: make multiple series 3688 % RootPath=RootPath(1:2); 3689 % set(hseries.RootPath,'String',RootPath) 3690 % SubDir=SubDir(1:2); 3691 % set(hseries.SubDir,'String',SubDir) 3692 % RootFile=RootFile(1:2); 3693 % set(hseries.RootFile,'String',RootFile) 3694 % NomType=NomType(1:2); 3695 % %set(hseries.NomType,'String',NomType) 3696 % FileExt=FileExt(1:2); 3697 % set(hseries.FileExt,'String',FileExt) 3698 % nbview=2; 3699 end 3700 hhh=which('mmreader'); 3701 for iview=1:nbview 3702 test_movie(iview)=0; 3703 if ~isequal(hhh,'')&& mmreader.isPlatformSupported() 3704 if isequal(lower(FileExt{iview}),'.avi') 3705 MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}])); 3706 test_movie(iview)=1; 3707 end 3708 end 3709 end 3710 filebase{1}=fullfile(RootPath{1},RootFile{1}); 3711 3712 % number of slices 3713 NbSlice=str2num(get(hseries.NbSlice,'String')); 3714 if isempty(NbSlice) 3715 NbSlice=1; 3716 end 3717 NbSlice_name=num2str(NbSlice); 3718 3719 % Field and velocity type (the same for the two views) 3720 if isfield(Series,'Field') 3721 FieldName=Series.Field;%the same set of fields for all views 3722 else 3723 FieldName={''}; 3724 end 3725 if isequal(FieldName,{'get_field...'}) 3726 hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI 3727 if numel(hget_field)>1 3728 delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld 3729 elseif isempty(hget_field) 3730 filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 3731 idetect(iview)=exist(filename,'file'); 3732 hget_field=get_field(filename); 3733 return 3734 end 3735 %hhget_field=guidata(hget_field);%handles of GUI elements in get_field 3736 SubField=read_get_field(hget_field) %read the names of the variables to plot in the get_field GUI 3737 if isempty(SubField) 3738 delete(hget_field) 3739 filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 3740 hget_field=get_field(filename); 3741 SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI 3742 end 3743 % if isequal(get(hhget_field.menu_coord,'Visible'),'on') 3744 % list_transform=get(hhget_field.menu_coord,'String'); 3745 % val_list=get(hhget_field.menu_coord,'Value'); 3746 % transform=list_transform{val_list}; 3747 % end 3748 end 3749 3750 %detect whether the two files are 'images' or 'netcdf' 3751 testima=0; 3752 testvol=0; 3753 testcivx=0; 3754 testnc=0; 3755 FileExt=get(hseries.FileExt,'String'); 3756 for iview=1:nbview 3757 ext=FileExt{iview}; 3758 form=imformats(ext([2:end])); 3759 if isequal(lower(ext),'.vol') 3760 testvol=testvol+1; 3761 elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab 3762 testima=testima+1; 3763 elseif isequal(ext,'.nc') 3764 testnc=testnc+1; 3765 end 3766 end 3767 if testvol 3768 msgbox_uvmat('ERROR','volume images not implemented yet') 3769 return 3770 end 3771 if testnc~=nbview && testima~=nbview && testvol~=nbview 3772 msgbox_uvmat('need a set of images or a set of netcdf files with the same fields as input','ERROR') 3773 return 3774 end 3775 if ~isequal(FieldName,{'get_field...'}) 3776 testcivx=testnc; 3777 end 3778 3779 % Root name of output files (TO GENERALISE FOR TWO INPUT SERIES) 3780 filebasesub=fullfile(RootPath{1},RootFile{1}); 3781 if NbSlice==1 3782 filebase_out=[filebasesub '_time']; 3783 else 3784 filebase_out=[filebasesub '_' NbSlice_name 'mtim']; 3785 increment=num_i1{1}(2)-num_i1{1}(1); 3786 if ~isequal(increment,1) % if an increment is set 3787 answeryes=msgbox_uvmat('INPUT_Y-N',['will take time series in ' num2str(NbSlice) 'slices with increment = ' num2str(increment) '!']); 3788 else 3789 answeryes=msgbox_uvmat('INPUT_Y-N',{['will take time series in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']}); 3790 end 3791 if ~isequal(answeryes,'Yes') 3792 return 3793 end 3794 end 3795 VelType_str=get(hseries.VelTypeMenu,'String'); 3796 VelType_val=get(hseries.VelTypeMenu,'Value'); 3797 VelType{1}=VelType_str{VelType_val}; 3798 if nbview==2 3799 VelType_str=get(hseries.VelTypeMenu_1,'String'); 3800 VelType_val=get(hseries.VelTypeMenu_1,'Value'); 3801 VelType{2}=VelType_str{VelType_val}; 3802 end 3803 3804 %Calibration data and timing: read the ImaDoc files 3805 mode=''; %default 3806 timecell={}; 3807 XmlData={}; 3808 itime=0; 3809 NbSlice_calib={}; 3810 for iview=1:nbview%Loop on views 3811 XmlData{iview}=[];%default 3812 filebase{iview}=fullfile(RootPath{iview},RootFile{iview}); 3813 if exist([filebase{iview} '.xml'],'file') 3814 [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 3815 if isfield(XmlData{iview},'Time') 3816 itime=itime+1; 3817 timecell{itime}=XmlData{iview}.Time; 3818 end 3819 if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') 3820 NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform 3821 if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) 3822 msgbox_uvmat('WARNING','inconsistent number of Z indices for the field series'); 3823 end 3824 end 3825 elseif exist([filebase{iview} '.civ'],'file') 3826 [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']); 3827 itime=itime+1; 3828 timecell{itime}=time; 3829 XmlData{iview}.Time=time; 3830 GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0]; 3831 GeometryCalib.Tx=0; 3832 GeometryCalib.Ty=0; 3833 GeometryCalib.Tz=1; 3834 GeometryCalib.dpx=1; 3835 GeometryCalib.dpy=1; 3836 GeometryCalib.sx=1; 3837 GeometryCalib.Cx=0; 3838 GeometryCalib.Cy=0; 3839 GeometryCalib.f=1; 3840 GeometryCalib.kappa1=0; 3841 GeometryCalib.CoordUnit='cm'; 3842 XmlData{iview}.GeometryCalib=GeometryCalib; 3843 if error==1 3844 msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file'); 3845 end 3846 end 3847 end 3848 3849 %check coincidence in time 3850 multitime=0; 3851 if length(timecell)==0 3852 time=[]; 3853 elseif length(timecell)==1 3854 time=timecell{1}; 3855 elseif length(timecell)>1 3856 multitime=1; 3857 for icell=1:length(timecell) 3858 if ~isequal(size(timecell{icell}),size(timecell{1})) 3859 warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING') 3860 time=timecell{1}; 3861 multitime=0; 3862 break 3863 end 3864 end 3865 end 3866 if multitime 3867 for icell=1:length(timecell) 3868 time(icell,:,:)=timecell{icell}; 3869 end 3870 diff_time=max(max(diff(time))); 3871 if diff_time>0 3872 warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING') 3873 end 3874 end 3875 if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 3876 time=[]; 3877 end 3878 3879 % image or scalar processing programme set by user 3880 Coord_menu=get(hseries.CoordType,'String'); 3881 menu_val=get(hseries.CoordType,'Value'); 3882 usrfct=Coord_menu{menu_val}; 3883 testfct=~isequal(usrfct,''); 3884 3885 % to update: 3886 VelType_str=get(hseries.VelTypeMenu,'String'); 3887 VelType_val=get(hseries.VelTypeMenu,'Value'); 3888 VelType{1}=VelType_str{VelType_val}; 3889 if nbview==2 3890 VelType_str=get(hseries.VelTypeMenu_1,'String'); 3891 VelType_val=get(hseries.VelTypeMenu_1,'Value'); 3892 VelType{2}=VelType_str{VelType_val}; 3893 end 3894 3895 %LOOP ON SLICES 3896 for i_slice=1:NbSlice 3897 dt=[]; 3898 nbmissing=0; %number of undetected files 3899 nbfiles=0; 3900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%LOOP ON FIELDS IN A SLICE 3901 for ifile=i_slice:NbSlice:nbfield 3902 stopstate=get(hseries.RUN,'BusyAction'); 3903 if isequal(stopstate,'queue')% enable STOP command 3904 update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) 3905 for iview=1:nbview 3906 filename=... 3907 name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview}); 3908 idetect(iview)=exist(filename,'file'); 3909 Data{iview}=[]; %default 3910 if testima 3911 Data{iview}.ListVarName={'A'}; 3912 Data{iview}.AName='image'; 3913 if test_movie(iview) 3914 A=read(MovieObject{iview},num_i1{iview}(ifile)); 3915 else 3916 A=double(read_image(filename,NomType{iview},num_i1{iview}(ifile)));% read the image, num2 is the counter for avi files 3917 end 3918 Data{iview}.ListVarName={'coord_y','coord_x','A'}; % 3919 npy=size(A,1); 3920 npx=size(A,2); 3921 nbcolor=size(A,3); 3922 if nbcolor==3 3923 Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x','rgb'}}; 3924 else 3925 Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'}}; 3926 end 3927 Data{iview}.coord_y=[npy-0.5 0.5]; 3928 Data{iview}.coord_x=[0.5 npx-0.5]; 3929 Data{iview}.A=A; 3930 Data{iview}.CoordType='px'; 3931 elseif testcivx 3932 [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); 3933 else 3934 [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data 3935 Data{iview}.VarAttribute=SubField.VarAttribute; 3936 end 3937 if ~isempty(NbSlice_calib) % z index 3938 Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1; 3939 end 3940 end 3941 % geometry transform or other user defined transform 3942 if ~isequal(Series.CoordType,'') 3943 if nbview==2 3944 [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2}); 3945 if isempty(Data{2}) 3946 Data(2)=[]; 3947 end 3948 else 3949 Data{1}=feval(Series.CoordType,Data{1},XmlData{1}); 3950 end 3951 end 3952 if testcivx 3953 Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) 3954 end 3955 if length(Data)==2 3956 [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields 3957 if ~isempty(errormsg) 3958 msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg]) 3959 return 3960 end 3961 else 3962 Field=Data{1}; 3963 end 3964 if isfield(Series,'ProjObject') 3965 Series.ProjObject 3966 [Field,errormsg]=proj_field(Field,Series.ProjObject); 3967 if ~isempty(errormsg) 3968 msgbox_uvmat('ERROR',['error in time_series/proj_field:' errormsg]) 3969 return 3970 end 3971 end 3972 if min(idetect)>=1% the input file(s) have been detected 3973 nbfiles=nbfiles+1; 3974 if nbfiles==1 %first field: initiate the time series 3975 RecordData=Field;%default 3976 RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots 3977 nbvar=length(Field.ListVarName); 3978 if nbvar==0 3979 msgbox_uvmat('ERROR','no input variable selected in get_field') 3980 return 3981 end 3982 testsum=2*ones(1,nbvar);%initiate flag for action on each variable 3983 indexfalse=0; 3984 CoordName={}; 3985 indexremove=[]; 3986 if isfield(Field,'VarAttribute') % look for coordinate and flag variables 3987 for ivar=1:nbvar 3988 if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') 3989 var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable 3990 if isequal(var_role,'errorflag') 3991 msgbox_uvmat('ERROR','do not handle error flags in time series') 3992 return 3993 end 3994 if isequal(var_role,'warnflag') 3995 testsum(ivar)=0; % not recorded variable 3996 eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable 3997 end 3998 if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... 3999 isequal(var_role,'coord_z')|isequal(var_role,'coord') 4000 testsum(ivar)=1; %constant coordinates, record without time evolution 4001 end 4002 % check whether the variable ivar is a dimension variable 4003 %index=Field.VarDimIndex{ivar};%dimension indices of the variable #ivar 4004 DimCell=Field.VarDimName{ivar}; 4005 if ischar(DimCell) 4006 DimCell={DimCell}; 4007 end 4008 if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables 4009 testsum(ivar)=1; 4010 end 4011 end 4012 end 4013 end 4014 for ivar=1:nbvar 4015 if testsum(ivar)==2 4016 eval(['RecordData.' Field.ListVarName{ivar} '=[];']) 4017 end 4018 end 4019 RecordData.ListVarName=[{'Time'} RecordData.ListVarName]; 4020 end 4021 for ivar=1:length(Field.ListVarName) 4022 VarName=Field.ListVarName{ivar}; 4023 eval(['VarVal=Field.' VarName ';']); 4024 if testsum(ivar)==2% test for recorded variable 4025 eval(['VarVal=Field.' VarName ';']); 4026 if isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode 4027 if isempty(VarVal) 4028 msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))]) 4029 return 4030 end 4031 VarVal=mean(VarVal,1); 4032 end 4033 VarVal=shiftdim(VarVal,-1); %shift dimension 4034 eval(['RecordData.' VarName '=cat(1,RecordData.' VarName ',VarVal);']);%concanete the current field to the time series 4035 elseif testsum(ivar)==1% variable representing fixed coordinates 4036 eval(['VarInit=RecordData.' VarName ';']); 4037 if ~isequal(VarVal,VarInit) 4038 msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName]) 4039 return 4040 end 4041 end 4042 end 4043 % time: 4044 if isempty(time)% time read in ncfiles 4045 if isfield(Field,'Time') 4046 RecordData.Time(nbfiles,1)=Field.Time; 4047 else 4048 RecordData.Time(nbfiles,1)=nbfiles;%default 4049 end 4050 else % time from ImaDoc prevails 4051 RecordData.Time(nbfiles,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2; 4052 end 4053 else 4054 nbmissing=nbmissing+1; 4055 end 4056 end 4057 end 4058 %remove time for global attributes if exists 4059 for iattr=1:numel(RecordData.ListGlobalAttribute) 4060 if strcmp(RecordData.ListGlobalAttribute{iattr},'Time') 4061 RecordData.ListGlobalAttribute(iattr)=[]; 4062 break 4063 end 4064 end 4065 for ivar=1:numel(RecordData.ListVarName) 4066 VarName=RecordData.ListVarName{ivar}; 4067 eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons 4068 end 4069 % add time dimension and update VarDimIndex: 4070 %if ~isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode 4071 for ivar=1:length(Field.ListVarName) 4072 % vardimindex=Field.VarDimIndex{ivar};% array of dimension indices for variable VarIndex(ivar) 4073 DimCell=Field.VarDimName(ivar); 4074 if testsum(ivar)==2%variable used as time series 4075 % RecordData.VarDimIndex{ivar}=[1 vardimindex+1]; 4076 RecordData.VarDimName{ivar}=[{'Time'} DimCell]; 4077 elseif testsum(ivar)==1 4078 % RecordData.VarDimIndex{ivar}=[vardimindex+1]; 4079 RecordData.VarDimName{ivar}=DimCell; 4080 end 4081 end 4082 % end 4083 indexremove=find(~testsum); 4084 if ~isempty(indexremove) 4085 RecordData.ListVarName(1+indexremove)=[]; 4086 RecordData.VarDimName(indexremove)=[]; 4087 if isfield(RecordData,'Role')&~isempty(RecordData.Role{1})%generaliser aus autres attributs 4088 RecordData.Role(1+indexremove)=[]; 4089 end 4090 end 4091 %RecordData.VarDimIndex=[{[1]} RecordData.VarDimIndex]; %time dimension 4092 %shift variable attributes 4093 if isfield(RecordData,'VarAttribute') 4094 RecordData.VarAttribute=[{[]} RecordData.VarAttribute]; 4095 end 4096 RecordData.VarDimName=[{'Time'} RecordData.VarDimName]; 4097 RecordData.Action=Series.Action;%name of the processing programme 4098 %name of result file 4099 [filemean]=... 4100 name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),SubDir{1}); 4101 errormsg=struct2nc(filemean,RecordData); %save result file 4102 if isempty(errormsg) 4103 display([filemean ' written']) 4104 else 4105 msgbox_uvmat('ERROR',['error in Series/struct2nc' errormsg]) 4106 end 4107 end 4108 figure 4109 haxes=axes; 4110 4111 plot_field(RecordData,haxes) 4112 hget_field=findobj(allchild(0),'name','get_field'); 4113 if ~isempty(hget_field) 4114 delete(hget_field) 4115 end 4116 get_field(filemean,RecordData) 4117 4118 %----------------------------------------------------------------------- 4119 % --- Executes on selection change in CoordType. 4120 function CoordType_Callback(hObject, eventdata, handles) 4121 menu_str=get(handles.CoordType,'String'); 4122 ind_coord=get(handles.CoordType,'Value'); 4123 coord_option=menu_str{ind_coord}; 4124 if isequal(coord_option,'more...'); 4125 fct_name=''; 4126 if exist('./TMP/current_usr_fct.mat','file')% if a file is found 4127 h=load('./TMP/current_usr_fct.mat'); 4128 if isfield(h,'fct_name'); 4129 fct_name=h.fct_name; 4130 end 4131 end 4132 prompt = {'Enter the name of the transform function'}; 4133 dlg_title = 'user defined transform'; 4134 num_lines= 1; 4135 [FileName, PathName, filterindex] = uigetfile( ... 4136 {'*.m', ' (*.m)'; 4137 '*.m', '.m files '; ... 4138 '*.*', 'All Files (*.*)'}, ... 4139 'Pick a file', fct_name); 4140 fct_name=fullfile(PathName,FileName); 4141 addpath(PathName);%add the path to the selected fct 4142 [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER 4143 if ~exist(fct_name,'file') 4144 warndlg(['image procesing fct ' fct_name ' not found']) 4145 else 4146 transform=FileName(1:end-2);% 4147 update_menu(handles.CoordType,transform)%add the selected fct to the menu 4148 % set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu 4149 %save ('./TMP/current_usr_fct.mat','fct_name'); 4150 end 4151 end 4152 ind_coord=get(handles.CoordType,'Value'); 4153 4154 %--------------------------------------------------------------------- 4155 % --- Executes on selection change in ProjObject. 4156 function ProjObject_Callback(hObject, eventdata, handles) 4157 4158 list_object=get(handles.ProjObject,'String'); 4159 index=get(handles.ProjObject,'Value'); 4160 hseries=get(handles.ProjObject,'Parent'); 4161 SeriesData=get(hseries,'UserData'); 4162 Obj=SeriesData.ProjObject{index}; 4163 [SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index}); 4164 set(hseries,'UserData',SeriesData); 4165 4166 %------------------------------------------------------------- 4167 %generates a series of file names with reference numbers between range1 and 4168 %range2 with increment incr. The reference number num_ref is the image number at the middle of the 4169 %image pair. The set of first numbers num1 of the image pairs is also 4170 %given as output 4171 %------------------------------------------------------ 4172 function [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(filebase,subdir,mode,first_i,incr_i,last_i,first_j,incr_j,last_j) 4173 [Path,Name]=fileparts(filebase); 4174 filebasesub=fullfile(Path,subdir,Name); 4175 filecell={};%default 4176 num_i1=[]; 4177 num_i2=[]; 4178 num_j1=[]; 4179 num_j2=[]; 4180 ind0_i=first_i:incr_i:last_i; 4181 nbcolumn=length(ind0_i); 4182 ind0_j=first_j:incr_j:last_j; 4183 nbline=length(ind0_j); 4184 if isequal(mode,'#_ab') 4185 dirpair=dir([filebasesub '*_*.nc']); 4186 elseif isequal(mode,'bursts')|isequal(mode,'series(Dj)') 4187 dirpair=dir([filebasesub '_*_*-*.nc']); 4188 elseif isequal(mode,'series(Di)') 4189 dirpair=dir([filebasesub '_*-*_*.nc']); 4190 else 4191 errordlg('option *|* not yet implemented') 4192 return 4193 end 4194 if isempty(dirpair) 4195 errordlg('no pair detected in the selected range') 4196 return 4197 end 4198 %ind0_i=first_i:incr_i:last_i; 4199 %nbcolumn=length(ind0_i); 4200 %dirpair=dir([filebasesub '_*_*-*.nc']); 4201 if isequal(mode,'bursts')|isequal(mode,'#_ab') 4202 icount=0; 4203 for ifile=1:length(dirpair) 4204 [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name); 4205 4206 % if isempty(str2num(str_1)) 4207 % dirpair(ifile).name 4208 % end 4209 num1_r=str2num(str_1); 4210 if isequal(RootFile,Name) & ~isempty(num1_r) 4211 num_i1(ifile)=num1_r; 4212 num_a(ifile)=stra2num(str_a); 4213 num_b(ifile)=stra2num(str_b); 4214 % icount=icount+1; 4215 end 4216 end 4217 length(dirpair) 4218 % num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files 4219 test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range 4220 ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices 4221 select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory 4222 ind_i=ind_i(select);%set of selected indices ind_i 4223 [ind_i,indsort]=sort(ind_i);%sorted list of ind_i 4224 select=select(indsort); 4225 num_i1=num_i1(select); 4226 num_a=num_a(select); 4227 num_b=num_b(select); 4228 dirpair=dirpair(select); 4229 [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn); 4230 ind_i(ind_remove)=[]; 4231 num_a(ind_remove)=[]; 4232 num_b(ind_remove)=[]; 4233 num_j1=zeros(1,nbcolumn);%default 4234 num_j2=num_j1; 4235 num_j1(ind_i)=num_a; 4236 num_j2(ind_i)=num_b; 4237 num_i1=first_i:incr_i:last_i; 4238 num_i2=num_i1; 4239 nbmissing=nbcolumn-length(ind_i); 4240 4241 elseif isequal(mode,'series(Di)') 4242 %ind0_i=first_i:incr_i:last_i; 4243 %nbcolumn=length(ind0_i); 4244 %ind0_j=first_j:incr_j:last_j; 4245 %nbline=length(ind0_j); 4246 %dirpair=dir([filebasesub '_*-*_*.nc']); 4247 for ifile=1:length(dirpair) 4248 [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name); 4249 num_i1_r(ifile)=str2num(str_1); 4250 num_i2_r(ifile)=str2num(str_2); 4251 num_j(ifile)=str2num(str_a); 4252 end 4253 num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files 4254 test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range 4255 ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices 4256 ind_j=((num_j-first_j)/incr_j)+1; 4257 ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices 4258 select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory 4259 ind_ij=ind_ij(select);%set of selected indices ind_ij 4260 [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij 4261 select=select(indsort); 4262 num_i1_r=num_i1_r(select); 4263 num_i2_r=num_i2_r(select); 4264 % num_j=num_j(select); 4265 dirpair=dirpair(select); 4266 [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ; 4267 ind_ij(ind_remove)=[]; 4268 num_i1_r(ind_remove)=[]; 4269 num_i2_r(ind_remove)=[]; 4270 num_i1=zeros(1,nbline*nbcolumn);%default 4271 num_i2=num_i1; 4272 num_i1(ind_ij)=num_i1_r; 4273 num_j2(ind_ij)=num_i2_r; 4274 num_i1=reshape(num_i1,nbline,nbcolumn); 4275 num_i2=reshape(num_i2,nbline,nbcolumn); 4276 num_j1=meshgrid(ind0_i,ind0_j); 4277 num_j2=num_j1; 4278 nbmissing=nbline*nbcolumn-length(ind_ij); 4279 elseif isequal(mode,'series(Dj)') 4280 % ind0_i=first_i:incr_i:last_i; 4281 % nbcolumn=length(ind0_i); 4282 % ind0_j=first_j:incr_j:last_j; 4283 % nbline=length(ind0_j); 4284 % dirpair=dir([filebasesub '_*_*-*.nc']); 4285 for ifile=1:length(dirpair) 4286 [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name); 4287 num_i(ifile)=str2num(str_1); 4288 num_a(ifile)=str2num(str_a); 4289 num_b(ifile)=str2num(str_b); 4290 end 4291 num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files 4292 test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range 4293 ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices 4294 ind_j=((num_j-first_j)/incr_j)+1; 4295 ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices 4296 select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory 4297 ind_ij=ind_ij(select);%set of selected indices ind_ij 4298 [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij 4299 select=select(indsort); 4300 num_i=num_i(select); 4301 num_a=num_a(select); 4302 num_b=num_b(select); 4303 dirpair=dirpair(select); 4304 [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ; 4305 ind_ij(ind_remove)=[]; 4306 num_a(ind_remove)=[]; 4307 num_b(ind_remove)=[]; 4308 num_j1=zeros(1,nbline*nbcolumn);%default 4309 num_j2=num_j1; 4310 num_j1(ind_ij)=num_a; 4311 num_j2(ind_ij)=num_b; 4312 num_j1=reshape(num_j1,nbline,nbcolumn); 4313 num_j2=reshape(num_j2,nbline,nbcolumn); 4314 num_i1=meshgrid(ind0_i,ind0_j); 4315 num_i2=num_i1; 4316 nbmissing=nbline*nbcolumn-length(ind_ij); 4317 % for i=1:length(indsel);%A SUPPRIMER ULTERIEUREMENT 4318 % if indsel(i)==0 4319 % filecell{i}=''; 4320 % else 4321 % Name=dirpair(indsel(i)).name; 4322 % filecell{i}=fullfile(Path,subdir,Name); 4323 % end 4324 % end 4325 %else 4326 % errordlg('option *|* not yet implemented') 4327 % return 4328 end 2176 4329 2177 4330 2178 %%%%%%%%%%%%% … … 4399 2247 last_j2 =last_j +ind_shift(2); 4400 2248 siz=size(SeriesData.Time{1}); 4401 if first_i1>=1 && first_j1 4402 >=1 && siz(1)>=last_i2 && siz(2)>=last_j2 2249 if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2 4403 2250 time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2; 4404 2251 time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2; -
/trunk/src/update_imadoc.m
r20 r30 10 10 testappend=0; 11 11 if exist(outputfile,'file');%=1 if the output file already exists, 0 else 12 testappend=1; 12 13 t=xmltree(outputfile); %read the file 13 14 backupfile=outputfile; … … 28 29 [t,uid_calib]=add(t,1,'element','GeometryCalib'); 29 30 else %if GeometryCalib already exists, delete its content 30 % backupfile=outputfile;31 % testexist=2;32 % while testexist==233 % backupfile=[backupfile '~'];34 % testexist=exist(backupfile,'file');35 % end36 % [success,message]=copyfile(outputfile,backupfile);%make backup37 31 if isequal(success,1) 38 32 delete(outputfile) … … 42 36 uid_child=children(t,uid_calib); 43 37 t=delete(t,uid_child); 44 testappend=1;45 38 end 46 39 end … … 49 42 t=set(t,1,'name','ImaDoc'); 50 43 [t,uid_calib]=add(t,1,'element','GeometryCalib'); 51 % t=struct2xml(GeometryCalib,t,uid_calib);52 44 end 53 45 t=struct2xml(GeometryCalib,t,uid_calib); -
/trunk/src/uvmat.m
r20 r30 325 325 else 326 326 if ishandle(handles.UVMAT_title) 327 set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; 'version 2.2.beta';date_str};errormsg]); 327 fid=fopen('revision.log') 328 if fid 329 a=textscan(fid,'%s%s%s',1,'HeaderLines',1,'Delimiter','|'); 330 set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; ['at revision ' a{1}{1}]};a{3}{1};errormsg]); 331 fclose(fid); 332 else 333 set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; 'version 2.2.beta';date_str};errormsg]); 334 end 328 335 end 329 336 end … … 470 477 %---------------------------------------------------------------- 471 478 function display_file_name(hObject, eventdata, handles,fileinput) 479 if ~exist(fileinput,'file') 480 msgbox_uvmat('ERROR',['input file ' fileinput ' does not exist']) 481 return 482 end 472 483 [RootPath,RootFile,i1,i2,str_a,str_b,ext,NomType,SubDir]=name2display(fileinput); 473 form=imformats(ext(2:end));%test valid Matlab image formats 474 if ~isempty(form) 475 ext_test='.image'; 476 imainfo=imfinfo(fileinput); 477 if length(imainfo) >1 %case of image with multiple frames 484 ext_test=''; %default 485 if ~isempty(ext) 486 form=imformats(ext(2:end));%test valid Matlab image formats 487 if ~isempty(form) 488 ext_test='.image'; 489 imainfo=imfinfo(fileinput); 490 if length(imainfo) >1 %case of image with multiple frames 491 i1='1'; % set the frame counter to 1 by default 492 i2=''; 493 str_a=''; 494 str_b=''; 495 NomType='*'; %indicate a set of indexed frames within a single file 496 [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file 497 end 498 elseif isequal(lower(ext),'.avi') 499 ext_test='.image'; 478 500 i1='1'; % set the frame counter to 1 by default 479 501 i2=''; … … 482 504 NomType='*'; %indicate a set of indexed frames within a single file 483 505 [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file 484 end 485 elseif isequal(lower(ext),'.avi') 486 ext_test='.image'; 487 i1='1'; % set the frame counter to 1 by default 488 i2=''; 489 str_a=''; 490 str_b=''; 491 NomType='*'; %indicate a set of indexed frames within a single file 492 [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file 493 else 494 ext_test=lower(ext); 506 else 507 ext_test=lower(ext); 508 end 495 509 end 496 510 switch ext_test
Note: See TracChangeset
for help on using the changeset viewer.