- Timestamp:
- Mar 2, 2010, 4:22:23 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series.m
r25 r26 135 135 136 136 %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' 137 menu_str={'check_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'}; 138 139 % menu_str=get(handles.ACTION,'String');%list of functions included in 'series.m' 140 141 %remove from the list the last option 'more...' 142 [path_series,name,ext]=fileparts(which('series')); 143 path_series=fullfile(path_series,'/series');%path of the function 'series' 144 140 145 for ilist=1:length(menu_str) 141 146 fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m' … … 151 156 menu_str=[menu_str; {file}]; 152 157 end 153 menu_str=[menu_str;{'more...'}]; 154 set(handles.ACTION,'String',menu_str) 155 end 156 end 158 end 159 end 160 161 menu_str=[menu_str;{'more...'}]; 162 set(handles.ACTION,'String',menu_str) 157 163 set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION 158 164 … … 1481 1487 end 1482 1488 end 1489 % fct_path 1490 eval(['h_fun=@' action]) 1491 if ~isequal(fct_path,path_series) 1492 rmpath(fct_path)% add the prescribed path if not the current one 1493 end 1494 1483 1495 Series.Action=action;%name of the processing programme 1484 1496 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784]) 1485 1497 drawnow 1486 1498 if length(RootPath)>1 1487 feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series); 1499 % feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series); 1500 h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series); 1488 1501 else 1489 feval(action,num_i1,num_i2,num_j1,num_j2,Series); 1502 h_fun(num_i1,num_i2,num_j1,num_j2,Series); 1503 % feval(action,num_i1,num_i2,num_j1,num_j2,Series); 1490 1504 end 1491 1505 set(handles.RUN,'BackgroundColor',[1 0 0]) … … 1611 1625 end 1612 1626 if nb_builtin==0% the path of series has been changed, reinitialize 1613 series_OpeningFcn(hObject, eventdata, handles)1627 % series_OpeningFcn(hObject, eventdata, handles) 1614 1628 return 1615 1629 end … … 1618 1632 if isequal(ACTION,'more...') 1619 1633 pathfct=fileparts(path_series); 1620 browse_name=fullfile(path_series,' SERIES_FCT');%go to UVMAT/SERIES_FCT by default1634 browse_name=fullfile(path_series,'series');%go to UVMAT/SERIES_FCT by default 1621 1635 if length(list_path)>nb_builtin 1622 1636 browse_name=list_path{end};% initialize browser with the path of the last introduced function … … 1630 1644 return 1631 1645 end 1632 ext_fct=FileName(end-1:end); 1646 1647 1648 1649 ext_fct=FileName(end-1:end);% to be replaced by fileparts 1633 1650 if ~isequal(ext_fct,'.m') 1634 1651 msgbox_uvmat('ERROR','a Matlab function .m must be introduced'); … … 1636 1653 end 1637 1654 ACTION=FileName(1:end-2);% ACTION choice updated by the selected item 1655 1656 addpath(PathName) 1657 eval(['h_function=@' ACTION]); 1658 if ~isequal(path_series,PathName) 1659 rmpath(PathName) 1660 end 1661 functions(h_function) 1638 1662 1639 1663 % insert the choice in the action menu … … 1895 1919 update_menu(handles.FieldMenu_1,scalar) 1896 1920 end 1897 1898 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 Series1908 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 default1921 %'GetObject';'on'...%can use projection object ,'off' by default1922 %'GetMask';'on'...%can use mask option ,'off' by default1923 %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter1924 ''};1925 return %exit the function1926 end1927 1928 %standard parameters for waitbar and STOP action (do not modify)1929 hseries=guidata(Series.hseries);%handles of the GUI series1930 WaitbarPos=get(hseries.waitbar_frame,'Position');1931 1932 %%%%%%%%%%%%%%%%%%%%%%%%1933 1934 % number of slices1935 NbSlice=str2num(get(hseries.NbSlice,'String'));1936 if isempty(NbSlice)1937 NbSlice=1;1938 end1939 NbSlice_name=num2str(NbSlice);1940 if isequal(NbSlice,[]),NbSlice=1; end; %default1941 1942 % number of views1943 count=0;1944 testcell=iscell(Series.RootFile);1945 if ~testcell1946 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 end1952 nbview=length(Series.RootFile);1953 for iview=1:nbview1954 filebase=fullfile(Series.RootPath{iview},Series.RootFile{iview});%root file name1955 if testcell1956 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 else1958 num_i1=num_i1_cell; num_i2=num_i2_cell; num_j1=num_j1_cell; num_j2=num_j2_cell;1959 end1960 siz=size(num_i1);1961 nbfield2=siz(1); %nb of consecutive fields at each level(burst1962 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 else1974 datnum=[];1975 Tabchar={};1976 %LOOP ON SLICES1977 for i_slice=1:NbSlice1978 for ifield=1:nbfield1979 indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice1980 end1981 for index=1:nbfield*nbfield21982 stopstate=get(hseries.RUN,'BusyAction');1983 if isequal(stopstate,'queue')% enable STOP command1984 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 file1990 if detect==01991 count=count+1;1992 lastfield='not found';1993 else1994 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 file2000 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 end2014 end2015 end2016 Tabchar(1,i_slice)={['slice #' num2str(i_slice)]};2017 Tabchar(index+1,i_slice)={[file ' ' lastfield]};2018 end2019 end2020 end2021 if isempty(datnum)2022 if NbSlice>12023 message=['no set of ' num2str(NbSlice) ' (NbSlices) files found'];2024 else2025 message='no file found';2026 end2027 else2028 datnum=datnum(find(datnum));%keep the non zero values corresponding to existing files2029 [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 end2034 if ~isempty(Tabchar)2035 Tabchar=reshape(Tabchar,NbSlice*(nbfield*nbfield2+1),1);2036 end2037 end2038 hfig=figure(iview);2039 clf2040 if iview>12041 pos=get(iview-1,'Position');2042 pos(1)=pos(1)+(iview-1)*pos(1)/nbview;2043 set(hfig,'Position',pos)2044 end2045 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 end2050 %----------------------------------------------------2051 % determine the list of index pairs of processing file2052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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 default2055 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 numbers2062 num_i2_line=num_i+ind_shift(4);2063 % adjust the first and last field number2064 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 else2077 num_j1_col=num_j+ind_shift(1);% set of first image numbers2078 num_j2_col=num_j+ind_shift(2);2079 % adjust the first field number2080 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 end2087 end2088 2089 2090 %----------------------------------------------------------------------2091 % --- make average on a series of files2092 %----------------------------------------------------------------------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 Series2099 % 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 function2113 'GetObject';'on';...%can use projection object(option 'off'/'one'/'two',2114 %'GetMask';'on'...%can use mask option2115 %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter2116 ''};2117 return2118 end2119 2120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2121 hseries=guidata(Series.hseries);%handles of the GUI series2122 WaitbarPos=get(hseries.waitbar_frame,'Position');2123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2124 2125 %root input file and type2126 if ~iscell(Series.RootPath)% case of a single input field series2127 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 else2134 RootPath=Series.RootPath;2135 RootFile=Series.RootFile;2136 SubDir=Series.SubDir;2137 NomType=Series.NomType;2138 FileExt=Series.FileExt;2139 end2140 ext=FileExt{1};2141 form=imformats(ext([2:end]));%test valid Matlab image formats2142 testima=0;2143 if ~isempty(form)||isequal(lower(ext),'.avi')||isequal(lower(ext),'.vol')2144 testima(1)=1;2145 end2146 if length(FileExt)>=22147 ext_1=FileExt{2};2148 form=imformats(ext_1([2:end]));%test valid Matlab image formats2149 if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol')2150 testima(2)=1;2151 end2152 if testima(2)~=testima(1)2153 msgbox_uvmat('ERROR','images and netcdf files cannot be compared')2154 return2155 end2156 end2157 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>22161 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 end2172 hhh=which('mmreader');2173 for iview=1:nbview2174 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 end2180 end2181 end2182 2183 % number of slices2184 NbSlice=str2num(get(hseries.NbSlice,'String'));2185 if isempty(NbSlice)2186 NbSlice=1;2187 end2188 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=[]; %default2193 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 views2197 if isequal(FieldName,{'get_field...'})2198 hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI2199 if length(hget_field)>12200 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 return2206 end2207 %hhget_field=guidata(hget_field);%handles of GUI elements in get_field2208 SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI2209 end2210 end2211 %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:nbview2219 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 Matlab2224 testima=testima+1;2225 elseif isequal(ext,'.nc')2226 testnc=testnc+1;2227 end2228 end2229 if testvol2230 msgbox_uvmat('ERROR','volume images not implemented yet')2231 return2232 end2233 if testnc~=nbview && testima~=nbview && testvol~=nbview2234 msgbox_uvmat('ERROR','compare two image series or two netcdf files with the same fields as input')2235 return2236 end2237 if ~isequal(FieldName,{'get_field...'})2238 testcivx=testnc;2239 end2240 2241 if testcivx2242 VelType_str=get(hseries.VelTypeMenu,'String');2243 VelType_val=get(hseries.VelTypeMenu,'Value');2244 VelType{1}=VelType_str{VelType_val};2245 if nbview==22246 VelType_str=get(hseries.VelTypeMenu_1,'String');2247 VelType_val=get(hseries.VelTypeMenu_1,'Value');2248 VelType{2}=VelType_str{VelType_val};2249 end2250 end2251 2252 %Calibration data and timing: read the ImaDoc files2253 mode=''; %default2254 timecell={};2255 itime=0;2256 NbSlice_calib={};2257 for iview=1:nbview%Loop on views2258 XmlData{iview}=[];%default2259 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 end2266 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 transform2268 if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})2269 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');2270 end2271 end2272 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==12291 msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');2292 end2293 end2294 end2295 2296 %check coincidence in time2297 multitime=0;2298 if length(timecell)==02299 time=[];2300 elseif length(timecell)==12301 time=timecell{1};2302 elseif length(timecell)>12303 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 break2310 end2311 end2312 end2313 if multitime2314 for icell=1:length(timecell)2315 time(icell,:,:)=timecell{icell};2316 end2317 diff_time=max(max(diff(time)));2318 if diff_time>02319 msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])2320 end2321 end2322 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 end2325 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 directory2333 cd(RootPath{1})% goes to the iamge directory2334 [m1,m2,m3]=mkdir(subdir_result);2335 if ~isequal(m2,'')2336 msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation2337 end2338 cd(dircur) %back to the initial working directory2339 end2340 filebase_out=filebase{1};2341 else2342 subdir_result=SubDir{1};2343 filebase_out=[filebase{1} '_mean'];% output root name obtained by adding the suffix _mean to the input2344 end2345 %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==12349 filebase_out=[filebasesub '_mean'];2350 else2351 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 return2355 end2356 end2357 2358 % coordinate transform or other user defined transform2359 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 loop2365 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 slice2369 2370 for i_slice=1:NbSlice2371 S=0; %initiate the image sum S2372 nbfiles=0;2373 nbmissing=0;2374 %averaging loop2375 for ifile=i_slice:NbSlice:lengthtot2376 stopstate=get(hseries.RUN,'BusyAction');2377 if isequal(stopstate,'queue') % enable STOP command2378 update_waitbar(hseries.waitbar,WaitbarPos,ifile/lengthtot)2379 for iview=1:nbview2380 [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 testima2383 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 else2388 Data{iview}.A=read_image(filename,NomType{iview},num_i1{iview}(ifile));% read the image, num2 is the counter for avi files2389 end2390 Atype{iview}=class(Data{iview}.A);2391 Data{iview}.A=double(Data{iview}.A);2392 elseif testcivx2393 [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);2394 else2395 [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data2396 Data{iview}.VarAttribute=SubField.VarAttribute;2397 end2398 if isfield(Data{iview},'Txt')2399 msgbox_uvmat('ERROR',['error of input reading: ' Data{iview}.Txt])2400 return2401 end2402 end2403 % coordinate transform (or other user defined transform)2404 if ~isequal(Series.CoordType,'')2405 % z index2406 if ~isempty(NbSlice_calib)2407 Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform2408 end2409 if nbview==22410 [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});2411 if isempty(Data{2})2412 Data(2)=[];2413 end2414 else2415 Data{1}=feval(Series.CoordType,Data{1},XmlData);2416 end2417 end2418 if testcivx2419 Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)2420 end2421 if length(Data)==22422 [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields2423 if ~isempty(errormsg)2424 msgbox_uvmat('ERROR',['error in aver_stat/sub_field:' errormsg])2425 return2426 end2427 else2428 Field=Data{1};2429 end2430 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 return2435 end2436 end2437 nbfiles=nbfiles+1;2438 if nbfiles==1 %first field2439 time_1=[];2440 if isfield(Field,'Time')2441 time_1=Field.Time(1);2442 end2443 DataMean=Field;%default2444 else2445 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 break2453 else2454 eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum2455 end2456 end2457 end2458 % else2459 % nbmissing=nbmissing+1;2460 % end2461 end2462 end %end averaging loop2463 for ivar=1:length(Field.ListVarName)2464 VarName=Field.ListVarName{ivar};2465 eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean2466 end2467 if nbmissing~=02468 msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])2469 end2470 if isempty(time) % time read from files prevails2471 time_end=[];2472 if isfield(Field,'Time')2473 time_end=Field.Time(1);%last time read2474 if ~isempty(time_1)2475 DataMean.Time=time_1;2476 DataMean.Time_end=time_end;2477 end2478 end2479 else % time from ImaDoc prevails2480 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 end2483 2484 %writing the result file2485 if testima2486 if NbSlice==12487 [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 simplicity2489 [filemean]=name_generator(filebase_out,i_slice,1,'.png','_i');2490 end2491 if exist(filemean,'file')2492 backupfile=filemean;2493 testexist=2;2494 while testexist==22495 backupfile=[backupfile(1:end-4) '~.png'];2496 testexist=exist(backupfile,'file');2497 end2498 [success,message]=copyfile(filemean,backupfile);%make backup2499 if ~isequal(success,1)2500 msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])2501 return2502 end2503 end2504 if isequal(Atype{1},'uint16')2505 imwrite(uint16(DataMean.A),filemean,'BitDepth',16);2506 else2507 imwrite(uint8(DataMean.A),filemean,'BitDepth',8);2508 end2509 display([filemean ' written']);2510 else %determine global attributes2511 DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Series.Action}];2512 ActionKey='Action';2513 while isfield(DataMean,ActionKey)2514 ActionKey=[ActionKey '_1'];2515 end2516 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 end2521 if NbSlice==12522 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 simplicity2524 [filemean]=name_generator(filebase_out,i_slice,1,'.nc','_i');2525 end2526 if exist(filemean,'file')2527 backupfile=filemean;2528 testexist=2;2529 while testexist==22530 backupfile=[backupfile(1:end-3) '~.nc'];2531 testexist=exist(backupfile,'file');2532 end2533 [success,message]=copyfile(filemean,backupfile);%make backup2534 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 return2538 end2539 end2540 errormsg=struct2nc(filemean,DataMean); %save result file2541 if isempty(errormsg)2542 display([filemean ' written']);2543 else2544 msgbox_uvmat('ERROR',['error in writting result file: ' errormsg])2545 display(errormsg)2546 end2547 end2548 end2549 hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI2550 delete(hget_field)2551 'TEST'2552 uvmat(filemean)2553 2554 2555 1921 % %---------------------------------------------------------------------- 2556 1922 % % --makes a time averaged velocity field … … 3337 2703 3338 2704 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 Series3348 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 default3361 %'GetObject';'on'...%can use projection object ,'off' by default3362 %'GetMask';'on'...%can use mask option ,'off' by default3363 %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter3364 ''};3365 return %exit the function3366 end3367 %---------------------------------------------------------3368 hseries=guidata(Series.hseries);%handles of the GUI series3369 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 return3376 end3377 nbdelete=0;3378 testcell=iscell(Series.RootFile);3379 if ~testcell3380 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 end3386 for iview=1:length(Series.RootFile)3387 hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files3388 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 end3396 end3397 end3398 msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx'])3399 3400 3401 3402 2705 3403 2706 … … 3607 2910 3608 2911 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 2912 4329 2913 4330 2914 %%%%%%%%%%%%%
Note: See TracChangeset
for help on using the changeset viewer.