source: trunk/src/uvmat.m @ 251

Last change on this file since 251 was 251, checked in by sommeria, 13 years ago

bug corrected in mouse_motion (display of z)
civ_uvmat corrected to use mask in fix (not implemented in civx fortran programmes)

File size: 213.0 KB
RevLine 
[199]1%'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
2%------------------------------------------------------------------------
3% function huvmat=uvmat(input)
4%
5%OUTPUT
6% huvmat=current handles of the GUI uvmat.fig
7%%
8%
9%INPUT:
10% input: input file name (if character chain), or input image matrix to
11% visualize, or Matlab structure representing  netcdf fields (with fields
12% ListVarName....)
13%
14%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
15%  Copyright Joel Sommeria,  2008, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr.
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%     This open is part of the toolbox UVMAT.
18%
19%     UVMAT is free software; you can redistribute it and/or modify
20%     it under the terms of the GNU General Public License as published by
21%     the Free Software Foundation; either version 2 of the License, or
22%     (at your option) any later version.
23%
24%     UVMAT is distributed in the hope that it will be useful,
25%     but WITHOUT ANY WARRANTY; without even the implied warranty of
26%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27%     GNU General Public License (open UVMAT/COPYING.txt) for more details.
28%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
29%
30% Information stored on the interface:
31%    'Strings' of all edit boxes and menus: get(handles.Tag,'String')
32%    'Values' of all menus and toggle buttons: get(handles.Tag,'Value')
33%     Matlab structure called UvData stored as 'UserData' of the figure uvmat.fig,(can be obtained by right mouse click on the interface).
34%          It contains the following fields:
35%     - Fixed specifiacation of plotting figures and axes (defined bu uvmat_OpeningFcn)
36%          .PosColorbar: [0.8210 0.4710 0.0190 0.4450]; specified position of the colorbar on figures
37%     - Information read in the documentation open of a series (activated by RootPath_Callback) :
38%          .XmlData, with fields:
39%               .Time: matrix of times of the images with index i and j
40%               .GeometryCalib: [1x1 struct]
41%     - Information defined from the interface:
42%           .NewSeries: =1 when the first view of a new field series is displayed, else 0
43%           .filename:(char string)
44%           .VelType:(char string) type of velocity field selected
45%           .VelType_1:(char string)  REMPLACER LE CELL ACTUEL
46%           .FieldName: (char string) main field selected('image', 'velocity'...)
47%           .FieldName_1:(char string) second field selected('image', 'velocity'...)
48%           .CName: (char string)name of the scalar used for vector colors
49%          .MovieObject: movie object representing an input movie
50%          .MovieObject_1: idem for a second input series (_1)
51%          .filename_1 : last second input file name (to deal with a constant second input without reading again the file)
[236]52%          .VelType_1: last velocity type (VelType, civ2...) for the second input series
[199]53%          .FieldName_1: last field name(velocity, vorticity...) for the second input series
54%          .ZMin, .ZMax: range of the z coordinate
55%..... to complement
56%     - Information on  projection objects
57%           .Object: {[1x1 struct]}
58%           .CurrentObjectIndex: index of the projection object .Object currently selected for editing
59%     -Information on the current field (Field{i})
60%            .Txt : text information to display (e.g. error message)
61%            .NbDim: number of dimensions (=0 by default)
62%            .NbCoord: number of vector components
63%            .CoordType: expresses the type of coordinate ('px' for image, 'sig' for instruments, or 'phys')
64%            .dt: time interval for the corresponding image pair
65%            .Mesh: estimated typical distance between vectors
66%            .ZMax:
67%            .ZMin:
68%            .X, .Y, .Z: set of vector coordinates
69%            .U,.V,.W: corresponding set of vector components
70%            .F: corresponding set of warning flags
71%            .FF: corresponding set of false flags, =0 for good vectors
72%            .C: corresponding values of the scalar used for vector color
73%             (.X, .Y, .Z,.U,.V,.W,.F,.FF,.C are matlab vectors of the same length,
74%                     equal to the number of vectors stored in the input open)
75%            .CName: name of the scalar .C
76%            .CType: type of the scalar .C, setting how the scalar is obtained (see 'Scalars' below)
77%            .A image or scalar
78%            .AX: vector of dimension 2 representing the first and last values
79%              of the X coordinates for the image or scalar known on a regular grid,
80%              or vector of dimension .A for a scaler defined on irregular grid.
81%            .AY: same as .AX along the Y direction
82%            .AName: name of the scalar, ='image' for an image
83
84% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   DATA FLOW  (for run0_Callback) %%%%%%%%%%%%%%%%%%%%:
85%
86% fields are opened and visualised by the sub-function refresh_field.m
87% (called by uvmat_opening, RUN0, runp and runm)
88% The function first reads the name of the input file from the edit boxes  of the GUI
89% A second input file can be introduced for filed comparison
90% It then reads the input file(s) with the appropriate function, read for
91% images, read_civxdata.m for CIVx PIV data, nc2struct for other netcdf
92% files.
93%               Main input open   second input open(_1)        second image (pair animation)
94%            |                 |                             
95%            |                 |                                               
96%                     Field{1}         Field{2}               
97%                                                                         |
98% coord transform (phys.m) or other user defined  fct acting on Field{i}  |
99%                                                                   Field{i}
100%                                                                    |
101% calc_field.m: calculate scalar or other derived fields (vort, div..).
102%
103% sub_field.m: combine the input Field{i} in a single set of fields (vector + scalar):
104%              Field{i=1->3}.X --> UvData.X                          |
105%                                                                    |
106%                                                                 UvData
107%                                                                    |
108% plot histograms of the whole  field
109% proj_field.m: project the set of fields on the current projection objects defined by UvData.Object
110%                                                                    |                                                                          |
111%                                                                ObjectData
112%                                                                    |
113% plot_field.m: plot the projected fields and store them as          |
114% UvData.axes3                                        |
115%                                                                    |
116%                                                                AxeData
117%
118%%%%%%%%%%%%%%    SCALARS: %%%%%%%%%%%%??%%%
119% scalars are displayed either as an image or countour plot, either as a color of
120% velocity vectors. The scalar values in the first case is represented by
121% UvData.Field.A, and by UvData.Field.C in the second case. The corresponding set of X
122% and Y coordinates are represented by UvData.Field.AX and UvData.Field.AY, and .X and
123% .Y for C (the same as velocity vectors). If A is a nxxny matrix (scalar
124% on a regtular grid), then .AX andf.AY contains only two elements, represneting the
125% coordinates of the four image corners. The scalar name is represented by
126% the strings .AName and/or .CName.
127% If the scalar exists in an input open (image or scalar stored under its
128% name in a netcdf open), it is directly read at the level of Field{1}or Field{2}.
129% Else only its name AName is recorded in Field{i}, and its field is then calculated
130%by the fuction calc_scal after the coordinate transform or after projection on an edit_object
131     
132% Properties attached to plotting figures (standard Matlab properties):
133%    'CurrentAxes'= gca or get(gcf,'CurrentAxes');
134%    'CurrentPoint'=get(gcf,'CurrentPoint'): figure coordinates of the point over which the mouse is positioned
135%    'CurrentCharacter'=get(gcf,'CurrentCharacter'): last character typed  over the figure where the mouse is positioned
136%    'WindowButtonMotionFcn': function permanently called by mouse motion over the figure
137%    'KeyPressFcn': function called by pressing a key on the key board
138%    'WindowButtonDownFcn':  function called by pressing the mouse over the  figure
139%    'WindowButtonUpFcn': function called by releasing  the mouse pressure over the  figure
140
141% Properties attached to plotting axes:
142%    'CurrentPoint'=get(gca,'CurrentPoint'); (standard Matlab) same as for the figure, but position in plot coordinates.
143%     AxeData:=get(gca,'UserData');
144%     AxeData.Drawing  = create: create a new object
145%                       = deform: modify an existing object by moving its defining create
146%                      = off: no current drawing action
147%                     = translate: translate an existing object
148%                    = calibration: move a calibration point
149%                    = zoom: isolate a subregion for zoom in=1 if an object is being currently drawn, 0 else (set to 0 by releasing mouse button)
150%            .CurrentOrigin: Origin of a curently drawn edit_object
151%            .CurrentLine: currently drawn menuline (A REVOIR)
152%            .CurrentObject: handle of the currently drawn edit_object
153%            .CurrentRectZoom: current rectangle used for zoom
154
155% Properties attached to projection objects (create, menuline, menuplane...):
156%    'Tag'='proj_object': for all projection objects
157%    ObjectData.Style=...: style of projection object:
158%              .ProjMode
159%              .Coord: defines the position of the object
160%              .XMin,YMin....
161%              .XMax,YMax....
162%              .DX,DY,DZ
163%              .Phi, .Theta, .Psi : Euler angles
164%              .X,.Y,.U,.V.... : field data projected on the object
165%              .IndexObj: index in the list of UvData.Object
166           %during plotting
167%               .plotaxes: handles of the current axes used to plot the  result of field projection on the object
168%               .plothandle: vector of handle(s) of the object graphic represnetation in all the opened plotting axes
169% To each projection object #iobj, corresponds an axis
170% Object{iobj}.plotaxes and nbobj representation graphs  Object{iobj}.plothandles(:) (where nbobj is the
171% nbre of current objects opened in uvmat. Note that Object{iobj}.plothandles(iobj)=[] : an object is not represented in its own projection field;
172
173%------------------------------------------------------------------------
174%------------------------------------------------------------------------
175%  I - MAIN FUNCTION UVMAT (DO NOT MODIFY)
176%------------------------------------------------------------------------
177%------------------------------------------------------------------------
178function varargout = uvmat(varargin)
179
180% Begin initialization code - DO NOT EDIT
181gui_Singleton = 1;
182gui_State = struct('gui_Name',          mfilename, ...
183                   'gui_Singleton',     gui_Singleton, ...
184                   'gui_OpeningFcn',    @uvmat_OpeningFcn, ...
185                   'gui_OutputFcn',     @uvmat_OutputFcn, ...
186                   'gui_LayoutFcn',     [], ...
187                   'gui_Callback',      []);
188if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
189    gui_State.gui_Callback = str2func(varargin{1});
190end
191
192if nargout
193    varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:});
194else
195    gui_mainfcn(gui_State, varargin{:});
196end
197% End initialization code - DO NOT EDIT
198
199%------------------------------------------------------------------------
200% --- Executes just before the GUI uvmat is made visible.
201function uvmat_OpeningFcn(hObject, eventdata, handles, input )
202%------------------------------------------------------------------------
203
204%% Choose default command menuline output for uvmat (standard GUI)
205handles.output = hObject;
206
207%% Update handles structure (standard GUI)
208guidata(hObject, handles);
209
210%% set the position of colorbar and ancillary GUIs:
211set(hObject,'Units','Normalized')
212movegui(hObject,'center')
213UvData.OpenParam.PosColorbar=[0.805 0.022 0.019 0.445];
214UvData.OpenParam.SetObjectOrigin=[-0.05 -0.03]; %position for set_object
215UvData.OpenParam.SetObjectSize=[0.3 0.7];
216UvData.OpenParam.CalOrigin=[0.95 -0.03];%position for geometry_calib (TO IMPROVE)
217UvData.OpenParam.CalSize=[0.28 1];
218UvData.axes3=[];%initiate the record of plotted field
219UvData.axes2=[];
220UvData.axes1=[];
221AxeData.LimEditBox=1; %initialise AxeData
222set(handles.axes3,'UserData',AxeData)
223
224%% set functions for the mouse and keyboard
225set(handles.histo_u,'NextPlot','replacechildren');
226set(handles.histo_v,'NextPlot','replacechildren');
227set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
228set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio
229set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
230set(hObject,'WindowButtonUpFcn',{'mouse_up',handles})
231set(hObject,'DeleteFcn',{@closefcn})%
232
233%% refresh projection plane
234UvData.Object{1}.ProjMode='projection';%main plotting plane
235set(handles.Fields,'Value',1)
236set(handles.Fields,'string',{''})
237
238%% TRANSFORM menu: builtin fcts
239menu_str={'';'phys';'px';'phys_polar'};
240UvData.OpenParam.NbBuiltin=numel(menu_str); %number of functions
241path_uvmat=fileparts(which('uvmat'));
242addpath(fullfile(path_uvmat,'transform_field'))
243fct_handle{1,1}=[];
244testexist=zeros(size(menu_str'));%default
245testexist(1)=1;
246for ilist=2:length(menu_str)
247    if exist(menu_str{ilist},'file')
248        fct_handle{ilist,1}=str2func(menu_str{ilist});
249        testexist(ilist)=1;
250    else
251        testexist(ilist)=0;
252    end
253end
254rmpath(fullfile(path_uvmat,'transform_field'))
255
256%% load the list of previously browsed files in menus Open and Open_1
257 dir_perso=prefdir; % path to the directory .matlab for personal data
258 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab
259 if exist(profil_perso,'file')
260      h=load (profil_perso);
261      if isfield(h,'MenuFile_1')
262          set(handles.MenuFile_1,'Label',h.MenuFile_1);
263          set(handles.MenuFile_1_1,'Label',h.MenuFile_1);
264      end
265      if isfield(h,'MenuFile_2')
266          set(handles.MenuFile_2,'Label',h.MenuFile_2);
267          set(handles.MenuFile_2_1,'Label',h.MenuFile_2);
268      end
269      if isfield(h,'MenuFile_3')
270          set(handles.MenuFile_3,'Label',h.MenuFile_3);
271          set(handles.MenuFile_3_1,'Label',h.MenuFile_3);
272      end
273      if isfield(h,'MenuFile_4')
274          set(handles.MenuFile_4,'Label',h.MenuFile_4);
275          set(handles.MenuFile_4_1,'Label',h.MenuFile_4);
276      end
277      if isfield(h,'MenuFile_5')
278          set(handles.MenuFile_5,'Label',h.MenuFile_5);
279          set(handles.MenuFile_5_1,'Label',h.MenuFile_5);
280      end
281      if isfield(h,'transform_fct') && iscell(h.transform_fct)
282         for ilist=1:length(h.transform_fct);
283             if exist(h.transform_fct{ilist},'file')
284                [path,file]=fileparts(h.transform_fct{ilist});
285                addpath(path)
286                h_func=str2func(file);
287                rmpath(path)
288                testexist=[testexist 1];
289             else
290                file='';
291                h_func=[];
292                testexist=[testexist 0];
293             end
294             fct_handle=[fct_handle; {h_func}]; %concatene the list of paths
295             menu_str=[menu_str; {file}];
296         end
297      end
298 end
299menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
300fct_handle=fct_handle(testexist==1);
301menu_str=[menu_str;{'more...'}];
302set(handles.transform_fct,'String',menu_str)
303set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
304
[231]305
[199]306%% check the path and date of modification of all functions in uvmat
307path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat
308[errormsg,date_str]=check_functions;%check the path of the functions called by uvmat.m
309date_str=['last modification: ' date_str];
310
311%% case of an input argument for uvmat
312testinputfield=0;
313inputfile=[];
314Field=[];
315if exist('input','var')
316    if ~isempty(errormsg)
317        msgbox_uvmat('WARNING',errormsg)
318    end
319    if ishandle(handles.UVMAT_title)
320        delete(handles.UVMAT_title)
321    end   
322    if isstruct(input)
323        if isfield(input,'InputFile')
324            inputfile=input.InputFile;
325        end
[231]326        if isfield(input,'TimeIndex')
327            set(handles.i1,num2str(input.TimeIndex))
[227]328        end
[231]329        if isfield(input,'FieldsString')
330%             set(handles.Fields,'Value',1)
331            UvData.FieldsString=input.FieldsString;
332        end
[199]333    elseif ischar(input)% file name introduced as input
334           inputfile=input;
335    elseif isnumeric(input)%simple matrix introduced as input
336        sizinput=size(input);
337        if sizinput(1)<=1 || sizinput(2)<=1
338            msgbox_uvmat('ERROR','bad input for uvmat: file name, structure or numerical matrix accepted')
339            return
340        end
[231]341        UvData.Field.ListVarName={'A','coord_y','coord_x'};
342        UvData.Field.VarDimName={{'coord_y','coord_x'},'cord_y','coord_x'};
343        UvData.Field.A=input;
344        UvData.Field.coord_x=[0.5 size(input,2)-0.5];
345        UvData.Field.coord_y=[size(input,1)-0.5 0.5];
[199]346        testinputfield=1;
347    end
348else
349   if ishandle(handles.UVMAT_title)
[234]350       fid=fopen('revision.info');
[199]351       if fid~=-1
[238]352         a=textscan(fid,'%s%s%s',1,'HeaderLines',4,'Delimiter',' ');
353         set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG'};{'GNU General Public License'}; {path_to_uvmat}; ...
354           {['at revision ' a{3}{1}]};{date_str};errormsg]);
[199]355         fclose(fid);
356       else
357          set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG'};{'GNU General Public License'};{path_to_uvmat};...
358               {date_str};errormsg]);
359       end
360   end
361end
[231]362set(handles.uvmat,'UserData',UvData)
363if ~isempty(inputfile)
364    %%%%% display the input field %%%%%%%
365    display_file_name(hObject, eventdata, handles,inputfile)
366    %%%%%%%
367    testinputfield=1;
368end
[199]369
370%% plot input field if exists
371if testinputfield
372    %delete drawn objects
373    hother=findobj(handles.axes3,'Tag','proj_object');%find all the proj objects
374    for iobj=1:length(hother)
375        delete_object(hother(iobj))
376    end 
377    if isempty(inputfile)
378        errormsg=refresh_field(handles,[],[],[],[],[],[],{Field});
379        set(handles.MenuTools,'Enable','on')
380        set(handles.OBJECT_txt,'Visible','on')
381        set(handles.edit_object,'Visible','on')
382        set(handles.list_object_1,'Visible','on')
383        set(handles.frame_object,'Visible','on')
384        if ~isempty(errormsg)
385            msgbox_uvmat('ERROR',errormsg)
386        end
387    end
388end
[236]389
[199]390set_vec_col_bar(handles) %update the display of color code for vectors
391
392%------------------------------------------------------------------------
393% --- Outputs from this function are returned to the command menuline.
394function varargout = uvmat_OutputFcn(hObject, eventdata, handles)
395varargout{1} = handles.output;% the only output argument is the handle to the GUI figure
396
397%------------------------------------------------------------------------
398%------------------------------------------------------------------------
399%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
400% automatically sets the global properties when the rootfile name is introduced
401% then activate the view-field action if selected
402% it is activated either by clicking on the RootPath window or by the
403% browser
404%------------------------------------------------------------------------
405%------------------------------------------------------------------------
406% --- Executes on the menu Open/Browse...
407% search the files, recognize their type according to their name and fill the rootfile input windows
408function MenuBrowse_Callback(hObject, eventdata, handles)
409oldfile=read_file_boxes(handles);
410
411if isempty(oldfile)||isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
412         dir_perso=prefdir;
413         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
414         if exist(profil_perso,'file')
415              h=load (profil_perso);
416             if isfield(h,'MenuFile_1')
417                  oldfile=h.MenuFile_1;
418             end
419         end
420end
421[FileName, PathName] = uigetfile( ...
422       {'*.xml;*.xls;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol;*.nc;*.cmx;*.fig;*.log;*.dat;*.bat;', ' (*.xml,*.xls,*.civ,*.jpg ,*.png, .tif, *.avi,*.vol,*.nc,*.cmx,*.fig,*.log,*.dat,*.bat)';
423       '*.xml',  '.xml files '; ...
424        '*.xls',  '.xls files '; ...
425        '*.civ',  '.civ files '; ...
426        '*.jpg',' jpeg image files'; ...
427        '*.png','.png image files'; ...
428        '*.tif','.tif image files'; ...
429        '*.avi;*.AVI','.avi movie files'; ...
430        '*.vol','.volume images (png)'; ...
431        '*.nc','.netcdf files'; ...
432        '*.cdf','.netcdf files'; ...
433        '*.cmx','.cmx text files ';...
434        '*.fig','.fig files (matlab fig)';...
435        '*.log','.log text files ';...
436        '*.dat','.dat text files ';...
437        '*.bat','.bat system command text files';...
438        '*.*',  'All Files (*.*)'}, ...
439        'Pick a file',oldfile);
440fileinput=[PathName FileName];%complete file name
441sizf=size(fileinput);
442if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
443
444% display the selected field and related information
445display_file_name(hObject, eventdata, handles,fileinput)
446
447%update list of recent files in the menubar
448MenuFile_1=fileinput;
449MenuFile_2=get(handles.MenuFile_1,'Label');
450MenuFile_3=get(handles.MenuFile_2,'Label');
451MenuFile_4=get(handles.MenuFile_3,'Label');
452MenuFile_5=get(handles.MenuFile_4,'Label');
453set(handles.MenuFile_1,'Label',MenuFile_1)
454set(handles.MenuFile_2,'Label',MenuFile_2)
455set(handles.MenuFile_3,'Label',MenuFile_3)
456set(handles.MenuFile_4,'Label',MenuFile_4)
457set(handles.MenuFile_5,'Label',MenuFile_5)
458set(handles.MenuFile_1_1,'Label',MenuFile_1)
459set(handles.MenuFile_2_1,'Label',MenuFile_2)
460set(handles.MenuFile_3_1,'Label',MenuFile_3)
461set(handles.MenuFile_4_1,'Label',MenuFile_4)
462set(handles.MenuFile_5_1,'Label',MenuFile_5)
463dir_perso=prefdir;
464profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
465if exist(profil_perso,'file')
466    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
467else
468    txt=ver('MATLAB');
469    Release=txt.Release;
470    relnumb=str2double(Release(3:4));
471    if relnumb >= 14
472        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
473    else
474        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
475    end
476end
477
478% -----------------------------------------------------------------------
479% --- Open again the file whose name has been recorded in MenuFile_1
480function MenuFile_1_Callback(hObject, eventdata, handles)
[227]481%------------------------------------------------------------------------
[199]482fileinput=get(handles.MenuFile_1,'Label');
483display_file_name(hObject, eventdata, handles,fileinput)
484
485% -----------------------------------------------------------------------
486% --- Open again the file whose name has been recorded in MenuFile_2
487function MenuFile_2_Callback(hObject, eventdata, handles)
[227]488%------------------------------------------------------------------------
[199]489fileinput=get(handles.MenuFile_2,'Label');
490display_file_name(hObject, eventdata, handles,fileinput)
491
492% -----------------------------------------------------------------------
493% --- Open again the file whose name has been recorded in MenuFile_3
494function MenuFile_3_Callback(hObject, eventdata, handles)
[227]495%------------------------------------------------------------------------
[199]496fileinput=get(handles.MenuFile_3,'Label');
497display_file_name(hObject, eventdata, handles,fileinput)
498
499% -----------------------------------------------------------------------
500% --- Open again the file whose name has been recorded in MenuFile_4
501function MenuFile_4_Callback(hObject, eventdata, handles)
[227]502%------------------------------------------------------------------------
[199]503fileinput=get(handles.MenuFile_4,'Label');
504display_file_name(hObject, eventdata, handles,fileinput)
505
506% -----------------------------------------------------------------------
507% --- Open again the file whose name has been recorded in MenuFile_5
508function MenuFile_5_Callback(hObject, eventdata, handles)
[227]509%------------------------------------------------------------------------
[199]510fileinput=get(handles.MenuFile_5,'Label');
511display_file_name(hObject, eventdata, handles,fileinput)
512
513%------------------------------------------------------------------------
514% --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
515function display_file_name(hObject, eventdata, handles,fileinput)
[227]516%------------------------------------------------------------------------
[199]517if ~exist(fileinput,'file')
518    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
519    return
520end
[236]521[RootPath,RootFile,i1,i2,str_a,str_b,ext,NomType,SubDir]=name2display(fileinput);%extract information from the file name
[199]522ext_test=''; %default
[236]523if ~isempty(ext) % if a file extension is detected
[199]524    form=imformats(ext(2:end));%test valid Matlab image formats
525    if ~isempty(form)
526        ext_test='.image';
527        imainfo=imfinfo(fileinput); 
528        if length(imainfo) >1 %case of image with multiple frames
529            i1='1'; % set the frame counter to 1 by default
530            i2='';
531            str_a='';
532            str_b='';
533            NomType='*'; %indicate a set of indexed frames within a single file
534            [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
535        end
[236]536    elseif isequal(lower(ext),'.avi')%case of avi movie file
[199]537        ext_test='.image';
538        i1='1'; % set the frame counter to 1 by default
539        i2='';
540        str_a='';
541        str_b='';
542        NomType='*'; %indicate a set of indexed frames within a single file
543        [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
544    else
545        ext_test=lower(ext);
546    end
547end
548switch ext_test
549    case {'.civ','.log','.cmx','.cmx2','.txt','.bat'}  %display text file
550        edit(fileinput) 
551    case '.fig'                           %display matlab figure
552        hfig=open(fileinput);
553        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
554        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
555        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
556    case {'.xml','.xls'}                % edit xml or Excel files
557       editxml(fileinput);
558    case {'.avi','.image','.vol','.nc','.cdf'}   
559        set(handles.RootPath,'String',RootPath);
560        if  isequal(SubDir,'')
561            rootname=fullfile(RootPath,RootFile);
562        else
563            rootname=fullfile(RootPath,SubDir,RootFile);
564            SubDir=['/' SubDir]; %display the separator
565        end
566        set(handles.SubDir,'String',SubDir);
567        set(handles.RootFile,'String',['/' RootFile]); %display the separator
568        indices=fileinput(length(rootname)+1:end);
569        indices(end-length(ext)+1:end)=[]; %remove extension
570        set(handles.FileIndex,'String',indices);       
571        set(handles.FileIndex,'UserData',NomType);
572        set(handles.FileExt,'String',ext);
573        % fill file index counters
574        set(handles.i1,'String',i1);   
575        set(handles.i2,'String',i2);
576        set(handles.j1,'String',str_a);
577        set(handles.j2,'String',str_b);
578       
579        % synchronise indices of the second  input file if it exists
580        if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
581            [ff,rr,FileBase_1,ii,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
582            NomType_1=get(handles.FileIndex_1,'UserData');     
583            FileName_1=name_generator(FileBase_1,str2double(i1),str2double(i2),FileExt_1,NomType_1,1,stra2num(str_a),stra2num(str_b),SubDir_1);
584            if exist(FileName_1,'file')
585                FileIndex_1=name_generator('',str2double(i1),str2double(i2),'',NomType_1,1,stra2num(str_a),stra2num(str_b),'');
586                set(handles.FileIndex_1,'String',FileIndex_1)
587            else
588                set(handles.SubField,'Value',0)
589                SubField_Callback(hObject, eventdata, handles)
590            end
591        end 
592
593        %enable other menus
594        set(handles.MenuOpen_1,'Enable','on')
595        set(handles.MenuFile_1_1,'Enable','on')
596        set(handles.MenuFile_2_1,'Enable','on')
597        set(handles.MenuFile_3_1,'Enable','on')
598        set(handles.MenuFile_4_1,'Enable','on')
599        set(handles.MenuFile_5_1,'Enable','on')
600        set(handles.MenuExport,'Enable','on')
601        set(handles.MenuExportFigure,'Enable','on')
602        set(handles.MenuExportMovie,'Enable','on')
603        set(handles.MenuTools,'Enable','on')
604        set(handles.OBJECT_txt,'Visible','on')
605        set(handles.edit_object,'Visible','on')
606        set(handles.list_object_1,'Visible','on')
607        set(handles.frame_object,'Visible','on')
608         %%%%%% initiate input file:
609        update_rootinfo(hObject,eventdata,handles); 
610    otherwise
611       msgbox_uvmat('ERROR',['invalid input file extension' ext])
612end
613
614%------------------------------------------------------------------------
615% --- Called by action in RootPath edit box
616function RootPath_Callback(hObject,eventdata,handles)
617%------------------------------------------------------------------------
618update_rootinfo(hObject,eventdata,handles);
619
620%------------------------------------------------------------------------
621% --- Called by action in RootFile edit box
622function SubDir_Callback(hObject, eventdata, handles)
623%------------------------------------------------------------------------
624%refresh the menu of input fields
625Fields_Callback(hObject, eventdata, handles);
626% refresh the current field
627run0_Callback(hObject, eventdata, handles);
628
629%------------------------------------------------------------------------
630% --- Called by action in RootFile edit box
631function RootFile_Callback(hObject, eventdata, handles)
632%------------------------------------------------------------------------
633update_rootinfo(hObject,eventdata,handles)
634
635%------------------------------------------------------------------------
636% --- Called by action in FileIndex edit box
637function FileIndex_Callback(hObject, eventdata, handles)
638%------------------------------------------------------------------------
639FileIndices=get(handles.FileIndex,'String');
640if isempty(str2num(FileIndices))
641    [pp,ff,str1,str2,str_a,str_b]=name2display(FileIndices);
642else
643    str1=FileIndices;
644    str2='';
645    str_a='';
646    str_b='';
647end
648set(handles.i1,'String',str1);
649set(handles.i2,'String',str2);
650set(handles.j1,'String',str_a);
651set(handles.j2,'String',str_b);
652run0_Callback(hObject, eventdata, handles)
653
654%------------------------------------------------------------------------
655% --- Update information about a new field series (indices to scan, timing,
656%     calibration from an xml file, then refresh current plots
657function update_rootinfo(hObject,eventdata,handles)
658%------------------------------------------------------------------------
659set(handles.RootPath,'BackgroundColor',[1 1 0])
660drawnow
661set(handles.Fields,'UserData',[])% reinialize data from uvmat opening
662UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
663UvData.NewSeries=1; %flag for run0: begin a new series
664UvData.TestInputFile=1;
665set(handles.fix_pair,'Value',1) % activate by default the comp_input '-'input window
[236]666set(handles.FixVelType,'Value',0); %desactivate fixed veltype
[199]667[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
668if ~exist(FileName,'file')
669   msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
670    return
671end
672nbfield=[];%default
673nburst=[];%default
674
675% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
676XmlData.Time=[];%default
677XmlData.GeometryCalib=[];%default
678TimeUnit=[];%default
679testima=0; %test for image input
680imainfo=[];
681ColorType='falsecolor'; %default
682hhh='';
683if isequal(lower(FileExt),'.avi') %.avi file
684    testima=1;
685    imainfo=aviinfo([FileBase FileIndices FileExt]);
686    nbfield=imainfo.NumFrames;
687    nburst=1;
688    set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
689    XmlData.Time=(0:1/imainfo.FramesPerSecond:(imainfo.NumFrames-1)/imainfo.FramesPerSecond)';
690    TimeUnit='s';
691    hhh=which('mmreader');
692    ColorType=imainfo.ImageType;%='truecolor' for color images
693elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image
694    testima=1;
695    if ~isequal(SubDir,'')
696       RootFile=get(handles.RootFile,'String');
697        imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
698    else
699        imainfo=imfinfo([FileBase FileIndices FileExt]);
700    end
701    ColorType=imainfo.ColorType;%='truecolor' for color images
702    if length(imainfo) >1 %case of image with multiple frames
703        nbfield=length(imainfo);
704        nburst=1;
705    end
706end
707if ~strcmp(hhh,'')&& mmreader.isPlatformSupported()% if the function is found (recent version of matlab)
708    UvData.MovieObject=mmreader([FileBase FileIndices FileExt]);
709elseif isfield(UvData,'MovieObject')
710    UvData=rmfield(UvData,'MovieObject');
711end
712if isfield(imainfo,'Width') && isfield(imainfo,'Height')
713    set(handles.npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box
714    set(handles.npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box
715else
716    set(handles.npx,'String','');%fills nbre of pixels x box
717    set(handles.npy,'String','');%fills nbre of pixels x box
718end
719set(handles.BW,'Value',strcmp(ColorType,'grayscale'))% select handles.BW if grayscale image
720
721% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
722filexml=[FileBase '.xml'];
723fileciv=[FileBase '.civ'];
724warntext='';%default warning message
725NbSlice=1;%default
726
727if exist(filexml,'file')
728    set(handles.view_xml,'Visible','on')
729    set(handles.view_xml,'BackgroundColor',[1 1 0])
730    set(handles.RootPath,'BackgroundColor',[1 1 1])
731    set(handles.view_xml,'String','view .xml')
732    drawnow
733    [XmlData,warntext]=imadoc2struct(filexml);
734    if ~isempty(warntext)
735        msgbox_uvmat('WARNING',warntext)
736    end
737    if isfield(XmlData,'TimeUnit')
738        if isfield(XmlData,'TimeUnit')&& ~isempty(XmlData.TimeUnit)
739            TimeUnit=XmlData.TimeUnit;
740        end
741    end
742    set(handles.view_xml,'BackgroundColor',[1 1 1])
743    drawnow
744    if isfield(XmlData, 'GeometryCalib') && ~isempty(XmlData.GeometryCalib)
745        XmlData.GeometryCalib
746        if isfield(XmlData.GeometryCalib,'VolumeScan') && isequal(XmlData.GeometryCalib.VolumeScan,'y')
747            set (handles.nb_slice,'String','volume')
748        end
749        hgeometry_calib=findobj('tag','geometry_calib');
750        if ~isempty(hgeometry_calib)
751            GUserData=get(hgeometry_calib,'UserData');
752            if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,filexml))
753                answer=msgbox_uvmat('INPUT_Y-N','replace the display of geometry_calib with the new input data?');
754                if strcmp(answer,'Yes')
755                    geometry_calib(filexml);%diplay the new calibration points and parameters in geometry_calib
756                end
757            end
758        end
759    end 
760elseif exist(fileciv,'file')% if .civ file found
761    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
762    GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
763    GeometryCalib.Tx=0;
764    GeometryCalib.Ty=0;
765    GeometryCalib.Tz=1;
766    GeometryCalib.dpx=1;
767    GeometryCalib.dpy=1;
768    GeometryCalib.sx=1;
769    GeometryCalib.Cx=0;
770    GeometryCalib.Cy=0;
771    GeometryCalib.f=1;
772    GeometryCalib.kappa1=0;
773    GeometryCalib.CoordUnit='cm';
774    XmlData.GeometryCalib=GeometryCalib;
775    if error==2, warntext=['no file ' FileBase '.civ'];
776    elseif error==1, warntext='inconsistent number of fields in the .civ file';
777    end 
778    set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
779    set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
780    set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
781    set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
782    set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
783    set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
784    set(handles.view_xml,'Visible','on')   
785    set(handles.view_xml,'String','view .civ')
786else
787    set(handles.view_xml,'Visible','off')
788end
789
790% store last index in handles.lat_i and .last_j
791if ~isempty(XmlData.Time)
792    nbfield=size(XmlData.Time,1);
793    nburst=size(XmlData.Time,2);
794    %transform .Time to a column vector if it is a line vector the nomenclature uses a single index
795    if isequal(nbfield,1) && ~isequal(nburst,1)% .Time is a line vector
796        NomType=get(handles.FileIndex,'UserData');
797        if numel(NomType)>=2 &&(strcmp(NomType,'_i')||strcmp(NomType(1:2),'%0')||strcmp(NomType(1:2),'_%'))
798            XmlData.Time=(XmlData.Time)';
799            nbfield=nburst;
800            nburst=1;
801        end
802    end
803end
804last_i_cell=get(handles.last_i,'String');
805if isempty(nbfield)
806    last_i_cell{1}='';
807else
808    last_i_cell{1}=num2str(nbfield);
809end
810set(handles.last_i,'String',last_i_cell)
811last_j_cell=get(handles.last_j,'String');
812if isempty(nburst)
813     last_j_cell{1}='';
814else
815     last_j_cell{1}=num2str(nburst);
816end
817set(handles.last_j,'String',last_j_cell);
818
819% store geometric calibration in UvData
820if isfield(XmlData,'GeometryCalib')
821    GeometryCalib=XmlData.GeometryCalib;
822    if isempty(GeometryCalib)
823        set(handles.pxcm,'String','')
824        set(handles.pycm,'String','')
825        set(handles.transform_fct,'Value',1); %  no transform by default
826    else
827        if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||...
828            (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0))
829            set(handles.pxcm,'String','var')
830            set(handles.pycm,'String','var')
831        elseif isfield(GeometryCalib,'fx_fy')
832            pixcmx=GeometryCalib.fx_fy(1);%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
833            pixcmy=GeometryCalib.fx_fy(2);%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
834            set(handles.pxcm,'String',num2str(pixcmx))
835            set(handles.pycm,'String',num2str(pixcmy))
836        end
837        if ~get(handles.FixLimits,'Value')
838            set(handles.transform_fct,'Value',2); % phys transform by default if fixedLimits is off
839        end
840        if isfield(GeometryCalib,'SliceCoord')
841           
842           siz=size(GeometryCalib.SliceCoord);
843           if siz(1)>1
844               NbSlice=siz(1);
845               set(handles.slices,'Visible','on')
846               set(handles.slices,'Value',1)
847           end
848           if isfield(GeometryCalib,'VolumeScan') && isequal(GeometryCalib.VolumeScan,'y')
849               set(handles.nb_slice,'String','volume')
850           else
851               set(handles.nb_slice,'String',num2str(NbSlice))
852           end
853           slices_Callback(hObject, eventdata, handles)
854        end           
855    end
856end
857
858%update the data attached to the uvmat interface
859if ~isempty(TimeUnit)
860    set(handles.time_txt,'String',['time (' TimeUnit ')'])
861end
862UvData.TimeUnit=TimeUnit;
863UvData.XmlData=XmlData;
864UvData.NewSeries=1;
865
[231]866
[199]867%display warning message
868if ~isequal(warntext,'')
869    msgbox_uvmat('WARNING',warntext);
870end
871
872% set default options in menu 'Fields'
873
[227]874if ~testima
875    testcivx=0;
[231]876    if isfield(UvData,'FieldsString') && isequal(UvData.FieldsString,{'get_field...'})% field menu defined as input (from get_field)
877        set(handles.Fields,'Value',1)
878        set(handles.Fields,'String',{'get_field...'})
879        UvData=rmfield(UvData,'FieldsString');
880    else
[236]881        Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
882        if strcmp(Data.Conventions,'uvmat/civdata') ||( ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0))%if the new input is Civx
[227]883            FieldList=calc_field;
884            set(handles.Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
885            set(handles.Fields,'Value',2) % set menu to 'velocity'
886            col_vec=FieldList;
887            col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar)
888            testcivx=1;
889        end
[231]890        if ~testcivx
[227]891            set(handles.Fields,'Value',1) % set menu to 'get_field...
892            set(handles.Fields,'String',{'get_field...'})
[231]893            col_vec={'get_field...'};
894        end
895        set(handles.col_vec,'String',col_vec)
896    end
[227]897end
[231]898set(handles.uvmat,'UserData',UvData)
[199]899
900%% set index navigation options and refresh plots
901set(handles.RootPath,'BackgroundColor',[1 1 1])
902drawnow
903set_scan_options(hObject, eventdata, handles)
904
905%------------------------------------------------------------------------
906%--- Set index navigation options for new series input and refresh plot
907%------------------------------------------------------------------------
908function set_scan_options(hObject, eventdata, handles)
909
910%  set the corresponding index navigation options
911NomType=get(handles.FileIndex,'UserData');       
912NomType_1=get(handles.FileIndex_1,'UserData');
913last_i_str=get(handles.last_i,'String');
914nbfield=str2num(last_i_str{1});
915if numel(last_i_str)==2
916    nbfield=min(nbfield,str2num(last_i_str{2}));
917end 
918state_j='off'; %default
919scan_option='i';%default
920NomTypeRaw=regexprep(NomType(2:end), '-', '');
921if numel(regexp(NomTypeRaw,'\D'))>=1
922        state_j='on';
923        if isequal(nbfield,1)
924            scan_option='j'; %scan j index by default if nbfield=1               
925        end
926end
927if ~isempty(NomType_1)
928    NomTypeRaw=regexprep(NomType_1(2:end), '-', '');
929    if numel(regexp(NomTypeRaw,'\D'))>=1
930            state_j='on';
931            if isequal(nbfield,1)
932                scan_option='j';                 
933            end           
934    end
935end
936if isequal(scan_option,'i')
937     set(handles.scan_i,'Value',1)
938     scan_i_Callback(hObject, eventdata, handles);
939else
940     set(handles.scan_j,'Value',1)
941     scan_j_Callback(hObject, eventdata, handles);
942end
943set(handles.scan_j,'Visible',state_j)
944set(handles.j1,'Visible',state_j)
945set(handles.j2,'Visible',state_j)
946set(handles.last_j,'Visible',state_j);
947set(handles.frame_j,'Visible',state_j);
948set(handles.j_text,'Visible',state_j);
[221]949if strcmp(state_j,'on')
950    set(handles.fix_pair,'Visible','on')
951else
952    set(handles.fix_pair,'Visible','off')
953end
[199]954
955%% view the field 
956run0_Callback(hObject, eventdata, handles); %view field
957mask_test=get(handles.mask_test,'value');
958if mask_test
959    MaskData=get(handles.mask_test,'UserData');
960    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
961          delete(MaskData.maskhandle)    %delete old mask
962    end
963    mask_test_Callback(hObject, eventdata, handles)
964end
965
966%------------------------------------------------------------------------
967% --- Executes on the menu Open/Browse_1 for the second input field,
968%     search the files, recognize their type according to their name and fill the rootfile input windows
969function MenuBrowse_1_Callback(hObject, eventdata, handles)
970%------------------------------------------------------------------------
971% huvmat=get(handles.run0,'parent');
972UvData=get(handles.uvmat,'UserData');
973
974RootPath=get(handles.RootPath,'String');
975[FileName, PathName, filterindex] = uigetfile( ...
976       {'*.xml;*.xls;*.civ;*.jpg;*.png;*.avi;*.AVI;*.nc;*.cmx;*.fig;*.log;*.dat', ' (*.xml,*.xls,*.civ, *.jpg,*.png, *.avi,*.nc,*.cmx ,*.fig,*.log,*.dat)';
977       '*.xml',  '.xml files '; ...
978        '*.xls',  '.xls files '; ...
979        '*.civ',  '.civ files '; ...
980        '*.jpg','.jpg image files'; ...
981        '*.png','.png image files'; ...
982        '*.avi;*.AVI','.avi movie files'; ...
983        '*.nc','.netcdf files'; ...
984        '*.cdf','.netcdf files'; ...
985        '*.cmx','.cmx text files';...
986        '*.cmx2','.cmx2 text files';...
987        '*.fig','.fig files (matlab fig)';...
988        '*.log','.log text files ';...
989        '*.dat','.dat text files ';...
990        '*.*',  'All Files (*.*)'}, ...
[236]991        'Pick a second file for comparison',RootPath);
[199]992fileinput_1=[PathName FileName];%complete file name
993sizf=size(fileinput_1);
994if (~ischar(fileinput_1)||~isequal(sizf(1),1)),return;end
995
996% refresh the current displayed field
997display_file_name_1(hObject,eventdata,handles,fileinput_1)
998
999%update list of recent files in the menubar
1000MenuFile_1=fileinput_1;
1001MenuFile_2=get(handles.MenuFile_1,'Label');
1002MenuFile_3=get(handles.MenuFile_2,'Label');
1003MenuFile_4=get(handles.MenuFile_3,'Label');
1004MenuFile_5=get(handles.MenuFile_4,'Label');
1005set(handles.MenuFile_1,'Label',MenuFile_1)
1006set(handles.MenuFile_2,'Label',MenuFile_2)
1007set(handles.MenuFile_3,'Label',MenuFile_3)
1008set(handles.MenuFile_4,'Label',MenuFile_4)
1009set(handles.MenuFile_5,'Label',MenuFile_5)
1010set(handles.MenuFile_1_1,'Label',MenuFile_1)
1011set(handles.MenuFile_2_1,'Label',MenuFile_2)
1012set(handles.MenuFile_3_1,'Label',MenuFile_3)
1013set(handles.MenuFile_4_1,'Label',MenuFile_4)
1014set(handles.MenuFile_5_1,'Label',MenuFile_5)
1015dir_perso=prefdir;
1016profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1017if exist(profil_perso,'file')
1018    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1019else
1020    txt=ver('MATLAB');
1021    Release=txt.Release;
1022    relnumb=str2double(Release(3:4));
1023    if relnumb >= 14
1024        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1025    else
1026        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1027    end
1028end
1029
1030% -----------------------------------------------------------------------
1031% --- Open again as second field the file whose name has been recorded in MenuFile_1
1032function MenuFile_1_1_Callback(hObject, eventdata, handles)
1033% -----------------------------------------------------------------------
1034fileinput_1=get(handles.MenuFile_1_1,'Label');
1035display_file_name_1(hObject,eventdata,handles,fileinput_1)
1036
1037% -----------------------------------------------------------------------
1038% --- Open again as second field the file whose name has been recorded in MenuFile_2
1039function MenuFile_2_1_Callback(hObject, eventdata, handles)
1040% -----------------------------------------------------------------------
1041fileinput_1=get(handles.MenuFile_2_1,'Label');
1042display_file_name_1(hObject,eventdata,handles,fileinput_1)
1043
1044% -----------------------------------------------------------------------
1045% --- Open again as second field the file whose name has been recorded in MenuFile_3
1046function MenuFile_3_1_Callback(hObject, eventdata, handles)
1047% -----------------------------------------------------------------------
1048fileinput_1=get(handles.MenuFile_3_1,'Label');
1049display_file_name_1(hObject,eventdata,handles,fileinput_1)
1050
1051% -----------------------------------------------------------------------
1052% --- Open again as second field the file whose name has been recorded in MenuFile_4
1053function MenuFile_4_1_Callback(hObject, eventdata, handles)
1054% -----------------------------------------------------------------------
1055fileinput_1=get(handles.MenuFile_4_1,'Label');
1056display_file_name_1(hObject,eventdata,handles,fileinput_1)
1057
1058% -----------------------------------------------------------------------
1059% --- Open again as second field the file whose name has been recorded in MenuFile_5
1060function MenuFile_5_1_Callback(hObject, eventdata, handles)
1061% -----------------------------------------------------------------------
1062fileinput_1=get(handles.MenuFile_5_1,'Label');
1063display_file_name_1(hObject,eventdata,handles,fileinput_1)
1064
1065%------------------------------------------------------------------------
1066% fills the edit boxes RootPath_1, RootFile_1,NomType_1...from an input file name 'fileinput_1'
1067%------------------------------------------------------------------------
1068function display_file_name_1(hObject,eventdata,handles,fileinput_1)
1069
1070%[path,name,ext]=fileparts(fileinput_1);
1071[RootPath_1,RootFile_1,field_count,str2,str_a,str_b,FileExt_1,NomType_1,SubDir_1]=name2display(fileinput_1);
1072nbfield_1=1; %default
1073ext_test=FileExt_1;%default
1074form=imformats(FileExt_1(2:end));
1075if ~isempty(form) % if the extension corresponds to an image format recognized by Matlab
1076    imainfo=imfinfo(fileinput_1); 
1077    nbfield_1=length(imainfo);
1078    ext_test='.image';
1079elseif isequal(lower(FileExt_1),'.avi')
1080    info=aviinfo(fileinput_1);
1081    nbfield_1=info.NumFrames;
1082    ext_test='.image';
1083end
1084
1085%open directly fig or text files
1086switch ext_test
1087    case {'.civ','.log','.cmx','.cmx2','.txt'}  %display text file
1088        edit(fileinput) 
1089        return
1090    case '.fig'                           %display matlab figure
1091        hfig=open(fileinput);
1092        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
1093        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
1094        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
1095        return
1096    case {'.xml','.xls'}                % edit xml or Excel files
1097       heditxml=editxml(fileinput);
1098       return
1099    case {'.image','.nc','.cdf'}
1100%         set(handles.FileIndex,'UserData',NomType_1);
1101    otherwise
1102        msgbox_uvmat(['invalid input file extension ' FileExt_1 ' for uvmat'],'ERROR')
1103        return
1104end
1105
1106% test for image series in a single file and synchronise file indices of the two series
1107if nbfield_1 >1 %case of image with multiple frames
1108    if nbfield_1 < num_i1
1109        msgbox_uvmat('ERROR','current frame index beyond the input movie length')
1110        return
1111    else
1112        NomType_1='*'; %indicate a set of indexed frames within a single file
1113        filename_new=fileinput_1;
1114    end
1115else  % cases of data files   
1116    RootPath=get(handles.RootPath,'String');
1117    RootFile=get(handles.RootFile,'String');
1118    FileBase=fullfile(RootPath,RootFile);
1119    FileBase_1=fullfile(RootPath_1,RootFile_1);
1120    if isequal(FileBase,FileBase_1)
1121        filename_new=fileinput_1;
1122    else       
1123        num_i1=stra2num(get(handles.i1,'String'));%get the current file indices from counters
1124        num_j1=stra2num(get(handles.j1,'String'));
1125        num_i2=stra2num(get(handles.i2,'String'));
1126        num_j2=stra2num(get(handles.j2,'String'));
1127        [filename_new,idetect]=...
1128           name_generator(FileBase_1,num_i1,num_j1,FileExt_1,NomType_1,1,num_i2,num_j2,SubDir_1);%create name with indices synchronised with the first file
1129        indices=''; %default
1130        if ~idetect
1131            msgbox_uvmat('ERROR','second input file with indices corresponding to the first one does not exist')
1132            return
1133        end
1134    end
1135end
1136set(handles.FileIndex_1,'UserData',NomType_1);
1137
1138% make visible and fill the second raw of edit boxes
1139set(handles.RootPath_1,'Visible','on')
1140set(handles.RootFile_1,'Visible','on')
1141set(handles.SubDir_1,'Visible','on');
1142set(handles.FileIndex_1,'Visible','on');
1143set(handles.FileExt_1,'Visible','on');
1144[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
1145if isequal(FileBase,FileBase_1)
1146    set(handles.RootPath_1,'String','"')
1147    set(handles.RootFile_1,'String','"');
1148else
1149    set(handles.RootPath_1,'String',RootPath_1)
1150    set(handles.RootFile_1,'String',['/' RootFile_1]);
1151end
1152if  isequal(SubDir_1,'')
1153     set(handles.SubDir_1,'String','');
1154     FileBaseSub_1=FileBase_1;
1155else 
1156    set(handles.SubDir_1,'String',['/' SubDir_1]);
1157    FileBaseSub_1=fullfile(FileBase_1,SubDir_1);
1158end
1159indices=filename_new(length(FileBaseSub_1)+1:end);
1160indices(end-length(FileExt_1)+1:end)=[]; %remove extension
1161set(handles.FileIndex_1,'String',indices)
1162set(handles.FileIndex_1,'UserData',NomType_1)
1163set(handles.FileExt_1,'String',FileExt_1);
1164
1165% % default choice of fields
[236]1166%set(handles.SubField,'Visible','on')
[199]1167set(handles.SubField,'Value',1)
1168RootPath_1_Callback(hObject,eventdata,handles); 
1169
1170%-----------------------------------------------------------------------
1171% --- Called by action in RootPath_1 edit box
1172function RootPath_1_Callback(hObject,eventdata,handles)
1173% -----------------------------------------------------------------------
1174update_rootinfo_1(hObject,eventdata,handles)
1175
1176%-----------------------------------------------------------------------
1177% --- Called by action in RootFile_1 edit box
1178function RootFile_1_Callback(hObject, eventdata, handles)
1179% -----------------------------------------------------------------------
1180update_rootinfo_1(hObject,eventdata,handles)
1181
1182%------------------------------------------------------------------------
1183% --- Called by action in FileIndex_1 edit box
1184function FileIndex_1_Callback(hObject, eventdata, handles)
1185%------------------------------------------------------------------------
1186run0_Callback(hObject, eventdata, handles)
1187
1188%------------------------------------------------------------------------
1189% --- Update information about a new second field series (indices to scan, timing,
1190%     calibration from an xml file, then refresh current plots
1191function update_rootinfo_1(hObject,eventdata,handles) %A REVOIR
1192% -----------------------------------------------------------------------
1193set(handles.RootPath_1,'BackgroundColor',[1 1 0])% indicate active program by yellow color
1194drawnow
1195UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
1196UvData.NewSeries=1; %flag for run0: begin a new series
1197
1198[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes_1(handles);
1199if ~exist(FileName,'file')
1200    msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
1201end
[236]1202set(handles.FixVelType,'Value',0); %desactivate fixed veltype
[199]1203nbfield_1=[];%default
1204nburst_1=[];%default
1205XmlData.Time=[];
1206XmlData.GeometryCalib=[];%default
1207TimeUnit=[];
1208if isfield(UvData,'TimeUnit')
1209    TimeUnit=UvData.TimeUnit;
1210end
1211TimeUnit_1=[];
1212hhh='';%default, test for  movie reading with mmreader
1213imainfo=[];
1214if isequal(lower(FileExt),'.avi') %.avi file
1215    imainfo=aviinfo([FileBase FileIndices FileExt]);
1216    nbfield_1=imainfo.NumFrames;
1217    nburst_1=1;
1218    set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
1219    time=(0:1/imainfo.FramesPerSecond:(imainfo.NumFrames-1)/imainfo.FramesPerSecond)';
1220    ColorType=imainfo.ImageType;%='truecolor' for color images
1221    hhh=which('mmreader');
1222elseif ~isempty(imformats(FileExt(2:end)))|| isequal(FileExt,'.vol')
1223    if ~isequal(SubDir,'')
1224        RootFile=get(handles.RootFile,'String');
1225        imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
1226    else
1227        imainfo=imfinfo([FileBase FileIndices FileExt]);
1228    end
1229    ColorType=imainfo.ColorType;%='truecolor' for color images
1230    if length(imainfo) >1 %case of image with multiple frames
1231        nbfield_1=length(imainfo);
1232        nburst_1=1;
1233    end
1234end
1235if ~strcmp(hhh,'')&& mmreader.isPlatformSupported()% if the function is found (recent version of matlab)
1236    UvData.MovieObject_1=mmreader([FileBase FileIndices FileExt]);
1237elseif isfield(UvData,'MovieObject_1')
1238    UvData=rmfield(UvData,'MovieObject_1');
1239end
1240if ~isempty(imainfo)% (an image has been introduced as second fierld input)
1241    if strcmp(get(handles.npx,'String'),'') || strcmp(get(handles.npy,'String'),'')%update npx and npy if it is not already filled by the first input field
1242        if  isfield(imainfo,'Width') && isfield(imainfo,'Height')
1243            set(handles.npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box
1244            set(handles.npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box
1245        else
1246            set(handles.npx,'String','');%fills nbre of pixels x box
1247            set(handles.npy,'String','');%fills nbre of pixels x box
1248        end
1249        set(handles.BW,'Value',strcmp(ColorType,'grayscale'))% select handles.BW if grayscale image
1250    end
1251end
1252% find scaling parameters
1253filexml=[FileBase '.xml'];
1254fileciv=[FileBase '.civ'];
1255warntext='';%default warning text
1256if exist(filexml,'file')
1257    [XmlData,warntext]=imadoc2struct(filexml);
1258    if ~isempty(warntext)
1259        msgbox_uvmat('WARNING',warntext)
1260    end
1261    if isfield(XmlData,'Camera')
1262        if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
1263            TimeUnit=XmlData.Camera.TimeUnit;
1264        end
1265    end
1266elseif exist(fileciv,'file')% if .civ file found
1267    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
1268    GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
1269    GeometryCalib.Tx=0;
1270    GeometryCalib.Ty=0;
1271    GeometryCalib.Tz=1;
1272    GeometryCalib.dpx=1;
1273    GeometryCalib.dpy=1;
1274    GeometryCalib.sx=1;
1275    GeometryCalib.Cx=0;
1276    GeometryCalib.Cy=0;
1277    GeometryCalib.f=1;
1278    GeometryCalib.kappa1=0;
1279    GeometryCalib.CoordUnit='cm';
1280    XmlData.GeometryCalib=GeometryCalib;
1281    if error==2, warntext=['no file ' FileBase '.civ'];
1282    elseif error==1, warntext='inconsistent number of fields in the .civ file';
1283    end
1284   
1285    set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
1286    set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
1287    set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
1288    set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
1289    set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
1290    set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
1291end   
1292if ~isempty(TimeUnit_1) && ~isequal(TimeUnit_1,TimeUnit)
1293        msgbox_uvmat('WARNING','the time units for the second series differs from the first one')
1294end
1295       
1296% store last index in handles.lat_i and .last_j
1297if ~isempty(XmlData.Time)
1298    nbfield_1=size(XmlData.Time,1);
1299    nburst_1=size(XmlData.Time,2);   
1300end
1301last_i_cell=get(handles.last_i,'String');
1302if isempty(nbfield_1)
1303    last_i_cell{2}='';
1304else
1305    last_i_cell{2}=num2str(nbfield_1);
1306end
1307set(handles.last_i,'String',last_i_cell)
1308last_j_cell=get(handles.last_j,'String');
1309if isempty(nburst_1)
1310     last_j_cell{2}='';
1311else
1312     last_j_cell{2}=num2str(nburst_1);
1313end
1314set(handles.last_j,'String',last_j_cell);
1315if ~isequal(last_i_cell{1},last_i_cell{2}) || ~isequal(last_j_cell{1},last_j_cell{2})
1316        msgbox_uvmat('WARNING','the numbers of input file of the second series differs from the first one')
1317end
1318
1319% store calibration data
1320GeometryCalib=XmlData.GeometryCalib;
1321if isempty(GeometryCalib)
1322    if isfield(UvData, 'GeometryCalib_1')
1323        UvData=rmfield(UvData,'GeometryCalib_1');
1324    end
1325else
1326    UvData.GeometryCalib_1=GeometryCalib;
1327    if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||...
1328        (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0))
1329        set(handles.pxcm,'String','var')
1330        set(handles.pycm,'String','var')
1331    else
1332        if isfield(GeometryCalib,'fx_fy')
1333            pixcmx=GeometryCalib.fx_fy(1);
1334            pixcmy=GeometryCalib.fx_fy(2);
1335            set(handles.pxcm,'String',num2str(pixcmx))
1336            set(handles.pycm,'String',num2str(pixcmy))
1337        end
1338    end
1339end
1340UvData.XmlData_1=XmlData;
1341set(handles.uvmat,'UserData',UvData)%update the data attached to the uvmat interface
1342
1343if ~isequal(warntext,'')
1344    msgbox_uvmat('WARNING',warntext)
1345end
1346
1347set(handles.RootPath_1,'BackgroundColor',[1 1 1])% signa the end the input operation
1348drawnow
1349
1350set_scan_options(hObject, eventdata, handles)
1351
1352%---------------------------------------------------
1353% switch file index scanning options scan_i and scan_j in an exclusive way
1354function scan_i_Callback(hObject, eventdata, handles)
1355%---------------------------------------------------
1356if get(handles.scan_i,'Value')==1
1357    set(handles.scan_i,'BackgroundColor',[1 1 0])
1358    set(handles.scan_j,'Value',0)
1359%     set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1360else
1361    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1362    set(handles.scan_j,'Value',1)
1363%     set(handles.scan_j,'BackgroundColor',[1 1 0])
1364end
1365scan_j_Callback(hObject, eventdata, handles)
1366
1367%-------------------------------------------------------------------
1368% switch file index scanning options scan_i and scan_j in an exclusive way
1369function scan_j_Callback(hObject, eventdata, handles)
1370%-------------------------------------------------------------------
1371if get(handles.scan_j,'Value')==1
1372    set(handles.scan_j,'BackgroundColor',[1 1 0])
1373    set(handles.scan_i,'Value',0)
1374    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
[227]1375    NomType=get(handles.FileIndex,'UserData');
[199]1376    switch NomType
1377    case {'_i_j1-j2','#_ab','%3dab'},% pair with j index
1378        set(handles.fix_pair,'Visible','on')% option fixed pair on/off made visible (choice of avaible pair with buttons + and - if ='off')
1379    otherwise
1380        set(handles.fix_pair,'Visible','off')
1381    end
1382else
1383    set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1384    set(handles.scan_i,'Value',1)
1385    set(handles.scan_i,'BackgroundColor',[1 1 0])
1386    set(handles.fix_pair,'Visible','off')
1387end
1388
1389%-------------------------------------------------------------------
1390function i1_Callback(hObject, eventdata, handles)
1391%-------------------------------------------------------------------
1392set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])
1393NomType=get(handles.FileIndex,'UserData');
1394num1=stra2num(get(handles.i1,'String'));
1395num2=stra2num(get(handles.i2,'String'));
1396num_a=stra2num(get(handles.j1,'String'));
1397num_b=stra2num(get(handles.j2,'String'));
1398indices=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1399set(handles.FileIndex,'String',indices)
1400set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])
1401if get(handles.SubField,'Value')==1
1402    NomType_1=get(handles.FileIndex_1,'String');
1403     FileExt_1=get(handles.FileExt_1,'String');
1404    [P,F,str1,str2,str_a,str_b,Ext,NomType_1]=name2display(['xx' NomType_1 FileExt_1]);
1405     indices=name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
1406     set(handles.FileIndex_1,'String',indices)
1407     set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7])
1408end
1409%Run0_Callback(hObject, eventdata, handles)
1410
1411%-------------------------------------------------------------------
1412function i2_Callback(hObject, eventdata, handles)
1413set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])
1414i1_Callback(hObject, eventdata, handles)
1415%-------------------------------------------------------------------
1416
1417%-------------------------------------------------------------------
1418function j1_Callback(hObject, eventdata, handles)
1419set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])
1420i1_Callback(hObject, eventdata, handles)
1421%-------------------------------------------------------------------
1422
1423%-------------------------------------------------------------------
1424function j2_Callback(hObject, eventdata, handles)
1425set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])
1426i1_Callback(hObject, eventdata, handles)
1427%-------------------------------------------------------------------
1428
1429%-------------------------------------------------------------------
1430function slices_Callback(hObject, eventdata, handles)
1431%-------------------------------------------------------------------
1432if get(handles.slices,'Value')==1
1433    set(handles.slices,'BackgroundColor',[1 1 0])
1434    set(handles.nb_slice,'Visible','on')
1435    set(handles.z_text,'Visible','on')
1436    set(handles.z_index,'Visible','on')
1437    nb_slice_Callback(hObject, eventdata, handles)
1438else
1439    set(handles.nb_slice,'Visible','off')
1440    set(handles.slices,'BackgroundColor',[0.7 0.7 0.7])
1441    set(handles.z_text,'Visible','off')
1442    set(handles.z_index,'Visible','off')
1443    set(handles.masklevel,'Value',1)
1444    set(handles.masklevel,'String',{'1'})
1445end
1446
1447%-------------------------------------------------------------------
1448function nb_slice_Callback(hObject, eventdata, handles)
1449%-------------------------------------------------------------------
1450nb_slice_str=get(handles.nb_slice,'String');
1451if isequal(nb_slice_str,'volume')
1452    num=stra2num(get(handles.j1,'String'));
1453    last_j=get(handles.last_j,'String');
1454    nbslice=str2double(last_j{1});
1455else
1456    num=str2double(get(handles.i1,'String'));
1457    nbslice=str2double(get(handles.nb_slice,'String'));
1458end
1459z=mod(num-1,nbslice)+1;
1460set(handles.z_index,'String',num2str(z))
1461for ilist=1:nbslice
1462    list_index{ilist,1}=num2str(ilist);
1463end   
1464set(handles.masklevel,'String',list_index)
1465set(handles.masklevel,'Value',z)
1466
1467%------------------------------------------------------------------------
1468% --- Executes on button press in view_xml.
1469function view_xml_Callback(hObject, eventdata, handles)
1470%------------------------------------------------------------------------
1471[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
1472option=get(handles.view_xml,'String');
1473if isequal(option,'view .xml')
1474    FileXml=[FileBase '.xml'];
1475    heditxml=editxml(FileXml);
1476end
1477
1478%------------------------------------------------------------------------
1479% --- Executes on button press in mask_test.
1480function mask_test_Callback(hObject, eventdata, handles)
1481%------------------------------------------------------------------------
1482%case of view mask selection
1483if isequal(get(handles.mask_test,'Value'),1)
1484    [FF,RootPath,FileBase]=read_file_boxes(handles);
1485    num_i1=stra2num(get(handles.i1,'String'));
1486    num_j1=stra2num(get(handles.j1,'String'));
1487    currentdir=pwd; 
1488    cd(RootPath);
1489    maskfiles=dir('*_*mask_*.png');%look for a mask file
1490    cd(currentdir);%come back to the working directory
1491    mdetect=0;
1492    if ~isempty(maskfiles)
1493        for ilist=1:length(maskfiles)
1494            maskname=maskfiles(ilist).name;% take the first mask file in the list
1495            [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname);
1496            [Path2,Name,ext]=fileparts(maskname);
1497            Namedouble=double(Name);
1498            val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1499            ind_mask=findstr('mask',Name);
1500            i=ind_mask-1;
1501            while val(i)==0 && i>0
1502                i=i-1;
1503            end
1504            nbmask_str=str2num(Name(i+1:ind_mask-1));
1505            if ~isempty(nbmask_str)
1506                nbslice(ilist)=nbmask_str; % number of different masks (slices)
1507            end
1508        end
1509        if isequal(min(nbslice),max(nbslice))
1510            nbslice=nbslice(1);
1511        else
1512            msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory')
1513            return
1514        end
1515        if ~isempty(nbslice) && Name(i)=='_'
1516            Mask.Base=[FileBase Name(i:ind_mask+3)];
1517            Mask.NbSlice=nbslice;
1518            num_i1=mod(num_i1-1,nbslice)+1;
[248]1519            Mask.NomType=regexprep(Mask_NomType{1},'0','');%remove '0' in nom type for masks
[251]1520            maskname=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);%
[199]1521            mdetect=exist(maskname,'file');
1522            if mdetect
1523                set(handles.nb_slice,'String',Name(i+1:ind_mask-1));
1524                set(handles.nb_slice,'BackgroundColor',[1 1 0])
1525                set(handles.mask_test,'UserData',Mask);
1526                set(handles.mask_test,'BackgroundColor',[1 1 0])
1527                if nbslice > 1
1528                    set(handles.slices,'value',1)
1529                    slices_Callback(hObject, eventdata, handles)
1530                end
1531            end
1532        end
1533    end
1534    errormsg=[];%default
1535    if mdetect==0
1536        [FileName, PathName, filterindex] = uigetfile( ...
1537            {'*.png', ' (*.png)';
1538            '*.png',  '.png files '; ...
1539            '*.*', 'All Files (*.*)'}, ...
1540            'Pick a mask file *.png',FileBase);
1541        maskname=fullfile(PathName,FileName);
1542        if ~exist(maskname,'file')
1543            errormsg='no file browsed';
1544        end
1545        [RootDir,RootFile,x1,x2,xa,xb,xext,Mask.NomType]=name2display(maskname);
1546        Mask.Base=fullfile(RootDir,RootFile);
1547        Mask.NbSlice=1;
1548        set(handles.mask_test,'UserData',Mask);
1549        set(handles.mask_test,'BackgroundColor',[1 1 0])
1550    end
1551    if isempty(errormsg)
1552        errormsg=update_mask(handles,num_i1,num_j1);
1553    end
1554    if ~isempty(errormsg)
1555            set(handles.mask_test,'Value',0)
1556            set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1557     end
1558else
1559    MaskData=get(handles.mask_test,'UserData');
1560    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1561          delete(MaskData.maskhandle)   
1562    end
1563    set(handles.mask_test,'UserData',[])   
1564    %huvmat=get(handles.mask_test,'parent');
1565    UvData=get(handles.uvmat,'UserData');
1566    if isfield(UvData,'MaskName')
1567        UvData=rmfield(UvData,'MaskName');
1568        set(handles.uvmat,'UserData',UvData)
1569    end
1570    set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1571end
1572
1573%-------------------------------------------------------------------
1574function errormsg=update_mask(handles,num_i1,num_j1)
1575%-------------------------------------------------------------------
1576errormsg=[];%default
1577MaskData=get(handles.mask_test,'UserData');
1578if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1579    uistack(MaskData.maskhandle,'top');
1580end
1581num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
1582MaskName=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
1583huvmat=get(handles.mask_test,'parent');
1584UvData=get(huvmat,'UserData');
1585
1586%update mask image if the mask is new
1587if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
1588    UvData.MaskName=MaskName; %update the recorded name on UvData
1589    set(huvmat,'UserData',UvData);
1590    if ~exist(MaskName,'file')
1591        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1592            delete(MaskData.maskhandle)   
1593        end
1594    else
1595        %read mask image
1596        Mask.AName='image';
1597        Mask.A=imread(MaskName);
1598        npxy=size(Mask.A);
1599        test_error=0;
1600        if length(npxy)>2
1601            errormsg=[MaskName ' is not a grey scale image'];
1602            return
1603        elseif ~isa(Mask.A,'uint8')
1604            errormsg=[MaskName ' is not a 8 bit grey level image'];
1605            return
1606        end
1607        Mask.AX=[0.5 npxy(2)-0.5];
1608        Mask.AY=[npxy(1)-0.5 0.5 ];
1609        Mask.CoordUnit='pixel';
1610        if isequal(get(handles.slices,'Value'),1)
1611           NbSlice=str2num(get(handles.nb_slice,'String'));
1612           num_i1=str2num(get(handles.i1,'String'));
1613           Mask.ZIndex=mod(num_i1-1,NbSlice)+1;
1614        end
1615        %px to phys or other transform on field
1616         menu_transform=get(handles.transform_fct,'String');
1617        choice_value=get(handles.transform_fct,'Value');
1618        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1619        transform_list=get(handles.transform_fct,'UserData');
1620        transform=transform_list{choice_value};
1621        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1622            if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1623                Calib=UvData.XmlData.GeometryCalib;
1624                Mask=transform(Mask,UvData.XmlData);
1625            end
1626        end
1627        flagmask=Mask.A < 200;
1628       
1629        %make brown color image
1630        imflag(:,:,1)=0.9*flagmask;
1631        imflag(:,:,2)=0.7*flagmask;
1632        imflag(:,:,3)=zeros(size(flagmask));
1633       
1634        %update mask image
1635        hmask=[]; %default
1636        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1637            hmask=MaskData.maskhandle;
1638        end
1639        if ~isempty(hmask)
1640            set(hmask,'CData',imflag)   
1641            set(hmask,'AlphaData',flagmask*0.6)
1642            set(hmask,'XData',Mask.AX);
1643            set(hmask,'YData',Mask.AY);
1644%             uistack(hmask,'top')
1645        else
1646            axes(handles.axes3)
1647            hold on   
1648            MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
1649%             set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
1650            set(handles.mask_test,'UserData',MaskData)
1651        end
1652    end
1653end
1654
1655
1656%-------------------------------------------------------------------
1657function MenuExportFigure_Callback(hObject, eventdata, handles)
1658%-------------------------------------------------------------------
1659huvmat=get(handles.MenuExport,'parent');
1660%UvData=get(huvmat,'UserData');
1661hfig=figure;
1662copyobj(handles.axes3,hfig);
1663map=colormap(handles.axes3);
1664colormap(map);%transmit the current colormap to the zoom fig
1665colorbar
1666
1667%-------------------------------------------------------------------
1668%-------------------------------------------------------------------
1669% III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
1670%-------------------------------------------------------------------
1671
1672%-------------------------------------------------------------------
1673% --- Executes on button press in runplus: make one step forward and call
1674% --- run0. The step forward is along the fields series 1 or 2 depending on
1675% --- the scan_i and scan_j check box (exclusive each other)
1676function runplus_Callback(hObject, eventdata, handles)
1677%-------------------------------------------------------------------
1678set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow
1679drawnow
1680%TODO: introduce the option: increment ='*' to move to the next available view
1681increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
1682if isnan(increment)
1683    set(handles.increment_scan,'String','1')%default value
1684    increment=1;
1685end
1686errormsg=runpm(hObject,eventdata,handles,increment);
1687if ~isempty(errormsg)
1688    msgbox_uvmat('ERROR',errormsg);
1689end
1690set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back to red
1691
1692%-------------------------------------------------------------------
1693% --- Executes on button press in runmin: make one step backward and call
1694% --- run0. The step backward is along the fields series 1 or 2 depending on
1695% --- the scan_i and scan_j check box (exclusive each other)
1696function runmin_Callback(hObject, eventdata, handles)
1697%-------------------------------------------------------------------
1698set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
1699drawnow
1700increment=-str2double(get(handles.increment_scan,'String')); %get the field increment d
1701if isnan(increment)
1702    set(handles.increment_scan,'String','1')%default value
1703    increment=1;
1704end
1705errormsg=runpm(hObject,eventdata,handles,increment);
1706if ~isempty(errormsg)
1707    msgbox_uvmat('ERROR',errormsg);
1708end
1709set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back to red
1710
1711%-------------------------------------------------------------------
1712% -- Executes on button press in Movie: make a series of +> steps
1713function Movie_Callback(hObject, eventdata, handles)
1714%------------------------------------------------------------------
1715set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow
1716drawnow
1717increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
1718if isnan(increment)
1719    set(handles.increment_scan,'String','1')%default value
1720    increment=1;
1721end
1722set(handles.STOP,'Visible','on')
1723set(handles.speed,'Visible','on')
1724set(handles.speed_txt,'Visible','on')
1725set(handles.Movie,'BusyAction','queue')
1726UvData=get(handles.uvmat,'UserData');
1727
1728while get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command
1729        errormsg=runpm(hObject,eventdata,handles,increment);
1730        if ~isempty(errormsg)
1731            set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1732            return
1733        end
1734        pause(1.02-get(handles.speed,'Value'))% wait for next image
1735end
1736if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1737    UvData.aviobj=close(UvData.aviobj);
1738   set(handles.uvmat,'UserData',UvData);
1739end
1740set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1741
1742%-------------------------------------------------------------------
1743% -- Executes on button press in Movie: make a series of <- steps
1744function MovieBackward_Callback(hObject, eventdata, handles)
1745%------------------------------------------------------------------
1746set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow
1747drawnow
1748increment=-str2double(get(handles.increment_scan,'String')); %get the field increment d
1749if isnan(increment)
1750    set(handles.increment_scan,'String','1')%default value
1751    increment=1;
1752end
1753set(handles.STOP,'Visible','on')
1754set(handles.speed,'Visible','on')
1755set(handles.speed_txt,'Visible','on')
1756set(handles.MovieBackward,'BusyAction','queue')
1757UvData=get(handles.uvmat,'UserData');
1758
1759while get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command
1760        errormsg=runpm(hObject,eventdata,handles,increment);
1761        if ~isempty(errormsg)
1762            set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1763            return
1764        end
1765        pause(1.02-get(handles.speed,'Value'))% wait for next image
1766end
1767if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1768    UvData.aviobj=close(UvData.aviobj);
1769   set(handles.uvmat,'UserData',UvData);
1770end
1771set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1772
1773%-------------------------------------------------------------------
1774function STOP_Callback(hObject, eventdata, handles)
1775%-------------------------------------------------------------------
1776set(handles.movie_pair,'BusyAction','Cancel')
1777set(handles.movie_pair,'value',0)
1778set(handles.Movie,'BusyAction','Cancel')
1779set(handles.MovieBackward,'BusyAction','Cancel')
1780set(handles.MenuExportMovie,'BusyAction','Cancel')
1781set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1782set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1783set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1784
1785%------------------------------------------------------------------
1786function errormsg=runpm(hObject,eventdata,handles,increment)
1787%------------------------------------------------------------------
1788%check for mï¿œovie pair status
1789movie_status=get(handles.movie_pair,'Value');
1790if isequal(movie_status,1)
1791    STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
1792end
1793%read the data on the current input rootfile(s)
1794
1795[FileName,RootPath,filebase,FileIndices,FileExt,subdir]=read_file_boxes(handles);
1796NomType=get(handles.FileIndex,'UserData');
1797
1798num1=stra2num(get(handles.i1,'String'));
1799num2=stra2num(get(handles.i2,'String'));
1800num_a=stra2num(get(handles.j1,'String'));
1801num_b=stra2num(get(handles.j2,'String'));
1802
1803sub_value= get(handles.SubField,'Value');
1804if sub_value % a second input file has been entered
1805    [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
1806    [pp,ff,str1,str2,str_a,str_b]=name2display(FileIndices_1);
1807    num1_1=stra2num(str1);%current set of indices for the second field (may be set different than the main indices)
1808    num2_1=stra2num(str2);
1809    num_a_1=stra2num(str_a);
1810    num_b_1=stra2num(str_b);
1811    NomType_1=get(handles.FileIndex_1,'UserData');
1812else
1813    filename_1=[];
1814end   
1815
1816comp_input=get(handles.fix_pair,'Value');
1817
1818%case of scanning along the first direction (rootfile numbers)
1819if get(handles.scan_i,'Value')==1% case of scanning along index i   
1820     num1=num1+increment;
1821     num2=num2+increment;
1822     [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1823     if sub_value% set the second field name and indices
1824        num1_1=num1_1+increment;
1825        num2_1=num2_1+increment;
1826        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1827     end   
1828else % case of scanning along index j (burst numbers)
1829    num_a=num_a+increment;
1830    num_b=num_b+increment;
1831    [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1832    if sub_value
1833        num_a_1=num_a_1+increment;
1834        num_b_1=num_b_1+increment;
1835        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1836    end   
1837end
1838
1839% refresh plots
1840errormsg=refresh_field(handles,filename,filename_1,num1,num2,num_a,num_b);
1841if isempty(errormsg)  %update the index counters
1842    set(handles.i1,'String',num2stra(num1,NomType,1));
1843    if isequal(num2,num1)
1844         set(handles.i2,'String','');
1845    else
1846        set(handles.i2,'String',num2stra(num2,NomType,1));
1847    end
1848    set(handles.j1,'String',num2stra(num_a,NomType,2));
1849    if isequal(num_b,num_a)
1850         set(handles.j2,'String','');
1851    else
1852        set(handles.j2,'String',num2stra(num_b,NomType,2));
1853    end
1854    [indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1855    set(handles.FileIndex,'String',indices);
1856    if ~isempty(filename_1)
1857         indices_1=name_generator('',num1_1,num_a_1,'',NomType_1,1,num2_1,num_b_1,'');
1858         set(handles.FileIndex_1,'String',indices_1);
1859    end
1860    if isequal(movie_status,1)
1861        set(handles.movie_pair,'Value',1)
1862        movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
1863    end
1864end
1865
1866
1867%-------------------------------------------------------
1868% --- Executes on button press in movie_pair: create an alternating movie with two view
1869%-------------------------------------------------------
1870function movie_pair_Callback(hObject, eventdata, handles)
1871status=get(handles.movie_pair,'value');
1872if isequal(status,0)
1873    set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
1874    set(handles.i2,'String','')
1875    set(handles.j2,'String','')
1876    return
1877else
1878    set(handles.movie_pair,'BusyAction','queue')
1879end
1880%initialisation
1881set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
1882drawnow
1883list_fields=get(handles.Fields,'String');% list menu fields
1884index_fields=get(handles.Fields,'Value');% selected string index
1885FieldName=list_fields{index_fields}; % selected field
1886UvData=get(handles.uvmat,'UserData');
1887if isequal(FieldName,'image')
1888    test_1=0;
1889    [ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
1890    NomType=get(handles.FileIndex,'UserData');
1891else
1892    list_fields=get(handles.Fields_1,'String');% list menu fields
1893    index_fields=get(handles.Fields_1,'Value');% selected string index
1894    FieldName=list_fields{index_fields}; % selected field
1895    if isequal(FieldName,'image')
1896        test_1=1;
1897        [ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes_1(handles);
1898        NomType=get(handles.FileIndex_1,'UserData');
1899    else
1900        msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
1901        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1902        return
1903    end
1904end
1905
1906num_i1=str2double(get(handles.i1,'String'));
1907num_j1=stra2num(get(handles.j1,'String'));
1908num_i2=str2double(get(handles.i2,'String'));
1909num_j2=stra2num(get(handles.j2,'String'));
1910if isnan(num_j2)
1911    if isempty(num_i2)   
1912        msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
1913        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1914        return
1915    else
1916        num_j2=num_j1;%repeat the index i1 by default
1917    end
1918end
1919if isnan(num_i2)
1920    num_i2=num_i1;%repeat the index i1 by default
1921end
1922imaname_1=name_generator(filebase,num_i2,num_j2,Ext,NomType);
1923if ~exist(imaname_1,'file')
1924      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
1925      set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1926      return
1927end
1928
1929%read the second image
1930Field.AName='image';
1931if test_1
1932    Field_a=UvData.Field_1;
1933else
1934    Field_a=UvData.Field;
1935end
1936Field_b.AX=Field_a.AX;
1937Field_b.AY=Field_a.AY;
1938% z index
1939nbslice=str2double(get(handles.nb_slice,'String'));
1940if ~isempty(nbslice)
1941    Field_b.ZIndex=mod(num_i2-1,nbslice)+1;
1942end
1943Field_b.CoordUnit='pixel';
1944%determine the input file type
1945if (test_1 && isfield(UvData,'MovieObject_1'))||(~test_1 && isfield(UvData,'MovieObject'))
1946    FileType='movie';
1947elseif isequal(lower(Ext),'.avi')
1948    FileType='avi';
1949elseif isequal(lower(Ext),'.vol')
1950    FileType='vol';
1951else
1952   form=imformats(Ext(2:end));
1953   if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1954       if isequal(NomType,'*');
1955           FileType='multimage';
1956       else
1957           FileType='image';
1958       end
1959   end
1960end
1961switch FileType
1962        case 'movie'
1963            if test_1
1964                Field_b.A=read(UvData.MovieObject_1,num_i2);
1965            else
1966                Field_b.A=read(UvData.MovieObject,num_i2);
1967            end
1968        case 'avi'
1969            mov=aviread(imaname_1,num_i2);
1970            Field_b.A=frame2im(mov(1));
1971        case 'vol'
1972            Field_b.A=imread(imaname_1);
1973        case 'multimage'
1974            Field_b.A=imread(imaname_1,num_i2);
1975        case 'image'
1976            Field_b.A=imread(imaname_1);
1977end
1978if get(handles.slices,'Value')
1979    Field.ZIndex=str2double(get(handles.z_index,'String'));
1980end
1981
1982%px to phys or other transform on field
1983menu_transform=get(handles.transform_fct,'String');
1984choice_value=get(handles.transform_fct,'Value');
1985transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1986transform_list=get(handles.transform_fct,'UserData');
1987transform=transform_list{choice_value};
1988if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1989    if test_1 && isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1990        Field_a=transform(Field_a,UvData.XmlData_1);%the first field has been stored without transform
1991        Field_b=transform(Field_b,UvData.XmlData_1);
1992    elseif ~test_1 && isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib
1993        Field_b=transform(Field_b,UvData.XmlData);
1994    end
1995end
1996
1997 % make movie until movie speed is set to 0 or STOP is activated
1998hima=findobj(handles.axes3,'Tag','ima');% %handles.axes3 =main plotting window (A GENERALISER)
1999set(handles.STOP,'Visible','on')
2000set(handles.speed,'Visible','on')
2001set(handles.speed_txt,'Visible','on')
2002while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')%isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
2003    % read and plot the series of images in non erase mode
2004    set(hima,'CData',Field_b.A);
2005    pause(1.02-get(handles.speed,'Value'));% wait for next image
2006    set(hima,'CData',Field_a.A);
2007    pause(1.02-get(handles.speed,'Value'));% wait for next image
2008end
2009set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
2010
2011%------------------------------------------------------------------------
2012% --- Executes on button press in run0.
2013function run0_Callback(hObject, eventdata, handles)
2014%------------------------------------------------------------------------
2015set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
2016drawnow
2017filename=read_file_boxes(handles);
2018
2019filename_1=[];%default
2020if get(handles.SubField,'Value')
2021    filename_1=read_file_boxes_1(handles);
2022end
2023num_i1=stra2num(get(handles.i1,'String'));
2024num_i2=stra2num(get(handles.i2,'String'));
2025num_j1=stra2num(get(handles.j1,'String'));
2026num_j2=stra2num(get(handles.j2,'String'));
[227]2027
[199]2028errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
[227]2029
[199]2030if ~isempty(errormsg)
2031      msgbox_uvmat('ERROR',errormsg);
2032else
2033    set(handles.i1,'BackgroundColor',[1 1 1])
2034    set(handles.i2,'BackgroundColor',[1 1 1])
2035    set(handles.j1,'BackgroundColor',[1 1 1])
2036    set(handles.j2,'BackgroundColor',[1 1 1])
2037    set(handles.FileIndex,'BackgroundColor',[1 1 1])
2038    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
2039end   
2040set(handles.run0,'BackgroundColor',[1 0 0])
2041
2042
2043%------------------------------------------------------------------------
2044% --- read the input files and refresh all the plots, including projection.
2045% OUTPUT:
2046%  errormsg: error message char string  =[] by default
2047% INPUT:
2048% filename: first input file (=[] in the absence of input file)
2049% filename_1: second input file (=[] in the asbsenc of secodn input file)
2050% num_i1,num_i2,num_j1,num_j2; frame indices
2051% Field: structure describing an optional input field (then replace the input file)
2052function errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,Field)
2053%------------------------------------------------------------------------
2054
2055%% initialisation
2056abstime=[];
2057abstime_1=[];
2058dt=[];
2059if ~exist('Field','var')
2060    Field={};
2061end
2062UvData=get(handles.uvmat,'UserData');
2063if ishandle(handles.UVMAT_title) %remove title panel on uvmat
2064    delete(handles.UVMAT_title)
2065end
2066
2067%% determine the main input file information for action
2068FileType=[];%default
2069if ~exist(filename,'file')
2070    errormsg=['input file ' filename ' does not exist'];
2071    return
2072end
2073%Ext=get(handles.FileExt,'String');
2074NomType=get(handles.FileIndex,'UserData');
2075%update the z position index
2076nbslice_str=get(handles.nb_slice,'String');
2077if isequal(nbslice_str,'volume')%NOT USED
2078    z_index=num_j1;
2079    set(handles.z_index,'String',num2str(z_index))
2080else
2081    nbslice=str2num(nbslice_str);
2082    z_index=mod(num_i1-1,nbslice)+1;
2083    set(handles.z_index,'String',num2str(z_index))
2084end
2085% refresh menu for save_mask if relevant
2086masknumber=get(handles.masklevel,'String');
2087if length(masknumber)>=z_index
2088    set(handles.masklevel,'Value',z_index)
2089end
2090
2091%% read the first input field if a filename has been introduced
2092if ~isempty(filename)
2093    ObjectName=filename;
2094    FieldName=[];%default
2095    VelType=[];%default
2096    Ext=get(handles.FileExt,'String');
2097    if strcmp(Ext,'.nc')||strcmp(Ext,'.cdf')
2098        FileType='netcdf';
2099        list_fields=get(handles.Fields,'String');% list menu fields
2100        index_fields=get(handles.Fields,'Value');% selected string index
2101        FieldName= list_fields{index_fields}; % selected field
[221]2102        if ~strcmp(FieldName,'get_field...')
[236]2103           TestVelType=get(handles.FixVelType,'Value');
2104           if TestVelType
2105               VelType=setfield(handles);% read the velocity type.
2106           end
[199]2107        end
2108        if strcmp(FieldName,'velocity')
2109            list_code=get(handles.color_code,'String');% list menu fields
2110            index_code=get(handles.color_code,'Value');% selected string index
2111            if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
2112                list_code=get(handles.col_vec,'String');% list menu fields
2113                index_code=get(handles.col_vec,'Value');% selected string index
2114                ParamIn.ColorVar= list_code{index_code}; % selected field
2115            end
2116        end
2117    elseif isfield(UvData,'MovieObject')
2118        ObjectName=UvData.MovieObject;
2119        FileType='movie';
2120    elseif isequal(lower(Ext),'.avi')
2121        FileType='avi';
2122    elseif isequal(lower(Ext),'.vol')
2123        FileType='vol';
2124        if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
2125            ParamIn.Npy=UvData.XmlData.Npy;
2126            ParamIn.Npx=UvData.XmlData.Npx;
2127        else
2128            errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2129            return
2130        end
2131    else
2132       form=imformats(Ext(2:end));
2133       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2134           if isequal(NomType,'*');
2135               FileType='multimage';
2136           else
2137               FileType='image';
2138           end
2139       end
2140    end
2141    ParamIn.FieldName=FieldName;
2142    ParamIn.VelType=VelType;
2143    ParamIn.GUIName='get_field';
2144    [Field{1},ParamOut,errormsg] = read_field(ObjectName,FileType,ParamIn,num_i1);
2145    if ~isempty(errormsg)
2146        errormsg=['error in reading ' filename ': ' errormsg];
2147        return
[246]2148    end       
[199]2149    if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
2150        set(handles.npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2151        set(handles.npy,'String',num2str(ParamOut.Npy));
2152    end
[227]2153    if isfield(ParamOut,'TimeIndex')
2154        set(handles.i1,'String',num2str(ParamOut.TimeIndex))
2155    end
2156    if isfield(ParamOut,'TimeValue')
2157        Field{1}.Time=ParamOut.TimeValue;
2158    end
[199]2159end
2160
[236]2161%% choose a second field filename_1 if defined
[199]2162VelType_1=[];%default
2163FieldName_1=[];
2164ParamOut_1=[];
2165if ~isempty(filename_1)
2166    if ~exist(filename_1,'file')
2167        errormsg=['second file ' filename_1 ' does not exist'];
2168        return
2169    else
2170        Name=filename_1;
2171        FieldName_1=[];%default
2172        VelType_1=[];%default
[236]2173        if strcmp(get(handles.FileExt_1,'Visible'),'on')
2174            Ext_1=get(handles.FileExt_1,'String');
2175        else
2176            Ext_1=get(handles.FileExt,'String');%read the file extension for the first series (case of veltype comparison within a single file)
2177        end
[199]2178        NomType_1=get(handles.FileIndex_1,'UserData');
2179        if isequal(Ext_1,'.nc')||isequal(Ext_1,'.cdf')
2180            FileType_1='netcdf';
2181        elseif isfield(UvData,'MovieObject_1')
2182            Name=UvData.MovieObject_1;
2183            FileType_1='movie';
2184        elseif isequal(lower(Ext_1),'.avi')
2185            FileType_1='avi';
2186        elseif isequal(lower(Ext_1),'.vol')
2187            FileType_1='vol';
2188            if isfield(UvData.XmlData_1,'Npy') && isfield(UvData.XmlData_1,'Npx')
2189                ParamIn.Npy=UvData.XmlData_1.Npy;
2190                ParamIn.Npx=UvData.XmlData_1.Npx;
2191            else
2192                errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2193                return
2194            end
2195        else
[236]2196           if length(Ext_1)>=2
[199]2197           form=imformats(Ext_1(2:end));
2198           if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2199               if isequal(NomType_1,'*');
2200                   FileType_1='multimage';
2201               else
2202                   FileType_1='image';
2203               end
2204           end
[236]2205           end
[199]2206        end
2207        if strcmp(FileType_1,'netcdf')
2208            list_fields=get(handles.Fields_1,'String');% list menu fields
2209            index_fields=get(handles.Fields_1,'Value');% selected string index
2210            FieldName_1= list_fields{index_fields}; % selected field
2211            if ~isequal(FieldName_1,'get_field...')% read the field names on the interface get_field...
[236]2212                VelType_1='';
2213                if get(handles.FixVelType,'Value')
2214                    VelTypeList=get(handles.VelType_1,'String');
2215                    index=get(handles.VelType_1,'Value');
2216                    VelType_1=VelTypeList{index};
2217                end
[199]2218            end
2219            if strcmp(VelType_1,'*')% free veltype choice
2220                VelType_1=[];
2221            elseif strcmp(VelType_1,'"')% veltype the same as for the first field
2222                if isempty(VelType)
2223                    VelType_1=[];
2224                else
2225                    VelType_1=VelType;
2226                end
2227            end
2228            if strcmp(FieldName_1,'velocity')
2229                list_code=get(handles.color_code,'String');% list menu fields
2230                index_code=get(handles.color_code,'Value');% selected string index
2231                if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
2232                    list_code=get(handles.col_vec,'String');% list menu fields
2233                    index_code=get(handles.col_vec,'Value');% selected string index
2234                    ParamIn.ColorVar= list_code{index_code}; % selected field
2235                end
2236            end
2237        end
2238        test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
2239        if ~isequal(NomType_1,'*')%in case of a series of files (not avi movie)
2240            if isfield(UvData,'filename_1')&& isfield(UvData,'VelType_1') && isfield(UvData,'FieldName_1')
2241                test_keepdata_1= strcmp(filename_1,UvData.filename_1) && strcmp(VelType_1,UvData.VelType_1) && strcmp(FieldName_1,UvData.FieldName_1);
2242            end
2243        end
2244        if test_keepdata_1
2245            Field{2}=UvData.Field_1;
2246        else
2247            ParamIn.FieldName=FieldName_1;
2248            ParamIn.VelType=VelType_1;
2249            ParamIn.GUIName='get_field_1';
2250            [Field{2},ParamOut_1,errormsg] = read_field(Name,FileType_1,ParamIn,num_i1);
2251            if ~isempty(errormsg)
[236]2252                errormsg=['error in reading ' FieldName_1 ' in ' filename_1 ': ' errormsg];
[199]2253                return
2254            end
2255            UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
2256        end
2257    end
2258end
2259
2260%% update uvmat interface
2261if isfield(ParamOut,'Npx')
2262    set(handles.npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2263    set(handles.npy,'String',num2str(ParamOut.Npy));
2264elseif isfield(ParamOut_1,'Npx')
2265    set(handles.npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface
2266    set(handles.npy,'String',num2str(ParamOut_1.Npy));
2267end
2268
[236]2269%% update the display menu for the first velocity type (first menuline)
2270% veltype_handles=[handles.VelType handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2271% if ~isequal(FileType,'netcdf')|| isequal(FieldName,'get_field...')
2272%     set(veltype_handles,'Visible','off')
2273% else% if isempty(ParamOut.VelType) && ~isequal(FieldName,'get_field...')
2274%     set_veltype_display(veltype_handles,ParamOut.CivStage)%update the display of available velocity types for the first field
2275%     if isempty(ParamOut.VelType)
2276%         reset_vel_type(veltype_handles)
2277%     else
2278%         handle1=eval(['handles.' ParamOut.VelType]);
2279%         reset_vel_type(veltype_handles,handle1)
2280%     end
2281% end
2282test_veltype=0;
[199]2283if ~isequal(FileType,'netcdf')|| isequal(FieldName,'get_field...')
[236]2284    set(handles.VelType,'Visible','off')
2285else
2286    test_veltype=1;
2287    set(handles.VelType,'Visible','on')
2288    set(handles.VelType_1,'Visible','on')
2289    set(handles.FixVelType,'Visible','on')
2290    menu=set_veltype_display(ParamOut.CivStage);
2291    index_menu=strcmp(ParamOut.VelType,menu);
2292    set(handles.VelType,'Value',find(index_menu,1))
[246]2293    if ~get(handles.SubField,'value')
[236]2294    set(handles.VelType,'String',menu)
[246]2295     set(handles.VelType_1,'Value',1)
2296     set(handles.VelType_1,'String',[{''};menu])
2297    end
[199]2298end
2299field_index=strcmp(ParamOut.FieldName,ParamOut.FieldList);
2300set(handles.Fields,'String',ParamOut.FieldList); %update the field menu
2301set(handles.Fields,'Value',find(field_index,1))
2302
[236]2303%% update the display menu for the second velocity type (second menuline)
2304% if ~isempty(filename_1)
2305%     veltype_handles_1=[handles.VelType_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
2306%     if ~isequal(FileType_1,'netcdf')|| isequal(FieldName_1,'get_field...')
2307%         set(veltype_handles_1,'Visible','off')
2308%         %reset_vel_type(veltype_handles_1)
2309%     else %if isempty(VelType_1) && ~isequal(FieldName_1,'get_field...')
2310%         set_veltype_display(veltype_handles_1,ParamOut_1.CivStage)%update the display of available velocity types for the first field
2311%         if isempty(ParamOut_1.VelType)
2312%             reset_vel_type(veltype_handles_1)
2313%         else
2314%             handle1=eval(['handles.' ParamOut_1.VelType '_1']);
2315%             reset_vel_type(veltype_handles_1,handle1)
2316%         end
2317%     end
2318%     field_index=strcmp(ParamOut_1.FieldName,ParamOut_1.FieldList);
2319%     set(handles.Fields_1,'String',ParamOut_1.FieldList); %update the field menu
2320%     set(handles.Fields_1,'Value',find(field_index,1))
2321% end
2322test_veltype_1=0;
2323if isempty(filename_1)
2324    set(handles.Fields_1,'Value',1); %update the field menu
2325    set(handles.Fields_1,'String',[{''};ParamOut.FieldList]); %update the field menu
2326else
[199]2327    if ~isequal(FileType_1,'netcdf')|| isequal(FieldName_1,'get_field...')
[236]2328        set(handles.VelType_1,'Visible','off')
2329    else
2330        test_veltype_1=1;
2331        set(handles.VelType_1,'Visible','on')
2332        if ~get(handles.FixVelType,'Value')
2333            menu=set_veltype_display(ParamOut_1.CivStage);
2334            index_menu=strcmp(ParamOut_1.VelType,menu);
2335            set(handles.VelType_1,'Value',1+find(index_menu,1))
2336            set(handles.VelType_1,'String',[{''};menu])
[199]2337        end
2338    end
2339end
[236]2340if test_veltype||test_veltype_1
2341     set(handles.FixVelType,'Visible','on')
2342else
2343     set(handles.FixVelType,'Visible','off')
2344end
2345   
[199]2346%% introduce w as background image by default for a new series (only for nbdim=2)
2347if ~isfield(UvData,'NewSeries')
2348    UvData.NewSeries=1;
2349end
2350%put W as background image by default if NbDim=2:
2351if  UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3);
2352        set(handles.SubField,'Value',1);
2353        %menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
2354        set(handles.RootPath_1,'String','"')
2355        set(handles.RootFile_1,'String','"')
2356        set(handles.SubDir_1,'String','"');
2357        [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
2358        set(handles.FileIndex_1,'String',indices)
2359        set(handles.FileExt_1,'String','"');
2360        set(handles.Fields_1,'Visible','on');
2361        set(handles.Fields_1,'Visible','on');
2362        set(handles.RootPath_1,'Visible','on')
2363        set(handles.RootFile_1,'Visible','on')
2364        set(handles.SubDir_1,'Visible','on');
2365        set(handles.FileIndex_1,'Visible','on');
2366        set(handles.FileExt_1,'Visible','on');
2367        set(handles.Fields_1,'Visible','on');
2368        Field{1}.AName='w';
2369end           
2370
2371%% store the current open names, fields and vel types in uvmat interface
2372UvData.filename_1=filename_1;
2373UvData.VelType_1=[];%default
2374UvData.FieldName_1=[];
2375if isfield(ParamOut_1,VelType)
2376    UvData.VelType_1=ParamOut_1.VelType;
2377end
2378if isfield(ParamOut_1,FieldName)
2379    UvData.FieldName_1=ParamOut_1.FieldName;
2380end
2381
2382%% apply coordinate transform or other user fct
2383XmlData=[];%default
2384if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2385    XmlData=UvData.XmlData;
2386end
2387XmlData_1=[];%default
2388if isfield(UvData,'XmlData_1')
2389   XmlData_1=UvData.XmlData_1;
2390end
2391% menu_transform=get(handles.transform_fct,'String');
2392choice_value=get(handles.transform_fct,'Value');
2393transform_list=get(handles.transform_fct,'UserData');
2394transform=transform_list{choice_value};%selected function handles
2395% z index
2396if ~isempty(filename)
2397    Field{1}.ZIndex=z_index;
2398end
2399%px to phys or other transform on field
2400if ~isempty(transform)
2401    if length(Field)>=2
2402        Field{2}.ZIndex=z_index;
2403        [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
2404        if isempty(Field{2})
2405            Field(2)=[];
2406        end
2407    else
2408        Field{1}=transform(Field{1},XmlData);
2409    end
2410end
2411
2412%% calculate scalar
2413if isequal(FileType,'netcdf') && ~isequal(ParamOut.CivStage,0)%&&~isempty(FieldName)%
2414    Field{1}=calc_field([{ParamOut.FieldName} {ParamOut.ColorVar}],Field{1});
2415end
[246]2416if numel(Field)==2 && ~test_keepdata_1 && isequal(FileType_1,'netcdf') && ~isequal(ParamOut_1.FieldName,'get_field...')%&&~isempty(FieldName_1)
[199]2417    Field{2}=calc_field([{ParamOut_1.FieldName} {ParamOut_1.ColorVar}],Field{2});
2418end
2419
2420%% combine the two input fields (e.g. substract velocity fields)
2421if numel(Field)==2
2422   UvData.Field=sub_field(Field{1},Field{2}); 
2423else
2424   UvData.Field=Field{1};
2425end
[243]2426
[199]2427%% get bounds and mesh (needed for mouse action and to open set_object)
2428test_x=0;
2429test_z=0;% test for unstructured z coordinate
2430[UvData.Field,errormsg]=check_field_structure(UvData.Field);
2431if ~isempty(errormsg)
2432    errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];
2433    return
2434end
[210]2435[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(UvData.Field);
[199]2436if ~isempty(errormsg)
2437    errormsg=['error in uvmat/refresh_field/find_field_indices: ' errormsg];
2438    return
2439end
2440[NbDim,imax]=max(NbDim);
[210]2441if isfield(UvData.Field,'NbDim')
2442    NbDim=UvData.Field.NbDim;% deal with plane fields containing z coordinates
2443end
[199]2444if ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinates
2445    XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
2446    YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
2447    eval(['nbvec=length(UvData.Field.' XName ');'])%nbre of measurement points (e.g. vectors)
2448    test_x=1;%test for unstructured coordinates
[206]2449    if ~isempty(VarType{imax}.coord_z)
2450        ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
2451    else
2452       NbDim=2;
2453    end
[236]2454elseif numel(VarType)>=imax && numel(VarType{imax}.coord)>=NbDim && VarType{imax}.coord(NbDim)>0 %structured coordinate 
[199]2455    XName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim)};
2456    if NbDim>1
2457        YName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim-1)}; %structured coordinates
2458    end
[236]2459else
[247]2460%     errormsg='input field coordinates not defined';
2461%     return
[199]2462end
2463if NbDim==3
[206]2464    if ~test_x
2465        ZName=UvData.Field.ListVarName{VarType{imax}.coord(1)};%structured coordinates in 3D
2466    end
[199]2467    eval(['ZMax=max(UvData.Field.' ZName ');'])
2468    eval(['ZMin=min(UvData.Field.' ZName ');'])
[206]2469    UvData.Field.ZMax=ZMax;
2470    UvData.Field.ZMin=ZMin;
[199]2471    test_z=1;
2472    if isequal(ZMin,ZMax)%no z dependency
2473        NbDim=2;
2474        test_z=0;
2475    end
2476end
2477if exist('XName','var')
[227]2478    eval(['XMax=max(max(UvData.Field.' XName '));'])
2479    eval(['XMin=min(min(UvData.Field.' XName '));'])
[206]2480    UvData.Field.NbDim=NbDim;
2481    UvData.Field.XMax=XMax;
2482    UvData.Field.XMin=XMin;
[199]2483    if NbDim >1
[227]2484        eval(['YMax=max(max(UvData.Field.' YName '));'])
2485        eval(['YMin=min(min(UvData.Field.' YName '));'])
[206]2486        UvData.Field.YMax=YMax;
2487        UvData.Field.YMin=YMin;
[199]2488    end
[206]2489    eval(['nbvec=length(UvData.Field.' XName ');'])
2490    if test_x %unstructured coordinates
2491        if test_z
2492            UvData.Field.Mesh=((XMax-XMin)*(YMax-YMin)*(ZMax-ZMin))/nbvec;% volume per vector
2493            UvData.Field.Mesh=(UvData.Field.Mesh)^(1/3);
2494        else
2495            UvData.Field.Mesh=sqrt((XMax-XMin)*(YMax-YMin)/nbvec);%2D
2496        end
[199]2497    else
[206]2498        VarIndex=CellVarIndex{imax}; % list of variable indices
2499        DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
2500        nbpoints_x=UvData.Field.DimValue(DimIndex(NbDim));
2501        DX=(XMax-XMin)/(nbpoints_x-1);
2502        if NbDim >1
2503            nbpoints_y=UvData.Field.DimValue(DimIndex(NbDim-1));
2504            DY=(YMax-YMin)/(nbpoints_y-1);
2505        end
2506        if NbDim==3
2507            nbpoints_z=UvData.Field.DimValue(DimIndex(1));
2508            DZ=(ZMax-ZMin)/(nbpoints_z-1);
[246]2509            UvData.Field.Mesh=(DX*DY*DZ)^(1/3);
[206]2510            UvData.Field.ZMax=ZMax;
2511            UvData.Field.ZMin=ZMin;
2512        else
[221]2513            UvData.Field.Mesh=DX;%sqrt(DX*DY);
[206]2514        end
[199]2515    end
2516end
2517
2518%% 3D case (menuvolume)
2519if NbDim==3% && UvData.NewSeries
2520    test_set_object=1;
2521    hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
2522    ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
2523    ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
2524    if ~isempty(hset_object) %if set_object is detected
2525%         hhset_object=guidata(hset_object);
2526% %         ZBounds_old(1)=get(hhset_object.z_slider,'Min');
2527% %         ZBounds_old(2)=get(hhset_object.z_slider,'Max');
2528% %         if isequal(ZBounds_old,ZBounds)
2529%             test_set_object=0;% do not refresh the GUI set_object
2530%         else
2531            delete(hset_object);% delete the GUI set_object if it does not fit
2532%         end
2533    end
2534    if test_set_object% reinitiate the GUI set_object
2535        delete_object(1);% delete the current projection object in the list UvData.Object, delete its graphic representations and update the list displayed in handles.list_object_1 and 2
2536        UvData.Object{1}.Style='plane';%main plotting plane
2537        UvData.Object{1}.ProjMode='projection';%main plotting plane
2538        UvData.Object{1}.DisplayHandle_uvmat=[]; %plane not visible in uvmat
2539        UvData.Object{1}.NbDim=NbDim;%test for 3D objects
2540        UvData.Object{1}.RangeZ=UvData.Field.Mesh;%main plotting plane
2541        UvData.Object{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
[206]2542        UvData.Object{1}.Angle=[0 0 0];
2543%         UvData.Object{1}.Theta=0;
2544%         UvData.Object{1}.Psi=0;
[199]2545        UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
[206]2546%         PlotHandles=get_plot_handles(handles);
[199]2547        UvData.Object{1}.Name='1-PLANE';
2548        UvData.Object{1}.enable_plot=1;
[206]2549        set_object(UvData.Object{1},handles,ZBounds);
[199]2550        set(handles.list_object_1,'Value',1);
2551        set(handles.list_object_1,'String',{'1-PLANE'});
2552        set(handles.edit_object,'Value',1)% put the plane in edit mode to enable the z cursor
2553        edit_object_Callback([],[], handles)
2554    end
2555    %multilevel case (single menuplane in a 3D space)
2556elseif isfield(UvData,'Z')
2557    if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
2558        XmlData=UvData.XmlData;
2559        if isfield(XmlData,'PlanePos')
2560            UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
2561        end
2562        if isfield(XmlData,'PlaneAngle')
2563            siz=size(XmlData.PlaneAngle);
2564            indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
[206]2565            UvData.Object{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
[199]2566        end
2567    elseif isfield(UvData,'ZIndex')
2568        UvData.Object{1}.ZObject=UvData.ZIndex;
2569    end
2570else
[231]2571    % create a default projection
2572%     UvData.Object{1}.ProjMode='projection';%main plotting plane
2573%     UvData.Object{1}.DisplayHandle_uvmat=[]; %plane not visible in uvmat
2574%     set(handles.list_object_1,'Value',1);
2575%     set(handles.list_object_1,'String',{''});
[199]2576end
[215]2577% if ~isfield(UvData.Object{1},'plotaxes')
2578%     UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
2579% end
[199]2580testnewseries=UvData.NewSeries;
2581UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2582set(handles.uvmat,'UserData',UvData)
2583
2584%% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
2585if isfield(UvData,'Mask')&& ~isfield(UvData,'A')
2586    set(handles.MinA,'String','0')
2587    set(handles.MaxA,'String','255')
2588end
2589
2590%% Plot the projections on the selected  projection objects
[248]2591
[199]2592% main projection object (uvmat display)
[236]2593list_object=get(handles.list_object_1,'String');
2594if isequal(list_object,{''})%refresh list of objects if the menu is empty
2595    UvData.Object={[]};
2596    set(handles.list_object_1,'Value',1)
2597    set(handles.list_object_2,'Value',1)
2598    set(handles.list_object_2,'String',{''})
2599    set(handles.list_object_2,'Visible','off')
2600end
[199]2601IndexObj(1)=get(handles.list_object_1,'Value');%selected projection object for main view
2602if IndexObj(1)> numel(UvData.Object)
2603    IndexObj(1)=1;%select the first object if the selected one does not exist
2604    set(handles.list_object_1,'Value',1)
2605end
2606plot_handles{1}=handles;
[215]2607if isfield(UvData,'plotaxes')%case of movies
2608    haxes(1)=UvData.plotaxes;
2609else
2610    haxes(1)=handles.axes3;
2611end
[199]2612PlotParam{1}=read_plot_param(handles);%read plotting parameters on the uvmat interfac
2613keeplim(1)=get(handles.FixLimits,'Value');% test for fixed graph limits
2614PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
2615
2616% second projection object (view_field display)
2617IndexObj_2=get(handles.list_object_2,'Value');%selected projection object for the second view
[231]2618if IndexObj_2==0
2619    IndexObj_2=1;
2620end
[199]2621if isequal(get(handles.list_object_2,'Visible'),'on') && IndexObj_2 <= numel(UvData.Object)&& ~isempty(UvData.Object{IndexObj_2})
2622    IndexObj(2)=IndexObj_2;
2623    view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
2624    if ~isempty(view_field_handle)
2625        plot_handles{2}=guidata(view_field_handle);
2626        haxes(2)=plot_handles{2}.axes3;
2627        PlotParam{2}=read_plot_param(plot_handles{2});%read plotting parameters on the uvmat interface
2628        keeplim(2)=get(plot_handles{2}.FixLimits,'Value');
2629        PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
2630    end
2631end
2632
2633%loop on the projection objects: one or two
2634for imap=1:numel(IndexObj)
[206]2635    iobj=IndexObj(imap);
[199]2636    [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object
2637    if testnewseries && isfield(ObjectData,'CoordUnit')
2638        PlotParam{imap}=rmfield(PlotParam{imap},'FixEqual'); %set FixEqual to depend on the field (=1 if Data.CoordUnit=1 in plot_field)
2639    end
2640    if ~isempty(errormsg)
2641        return
2642    end
2643    %use of mask (TODO: check)
2644    if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
2645        flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2646        AX=ObjectData.AX;%x coordiantes for the scalar field
2647        AY=ObjectData.AY;%y coordinates for the scalar field
2648        MaskX=ObjectData.MaskX;%x coordiantes for the mask
2649        MaskY=ObjectData.MaskY;%y coordiantes for the mask
2650        if ~isequal(MaskX,AX)||~isequal(MaskY,AY)
2651            nxy=size(flag_mask);
2652            sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2653            sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2654            x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
2655            y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
2656            %project on the positions of the scalar
2657            npxy=size(ObjectData.A);
2658            dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2659            dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2660            xi=ObjectData.AX(1):dxy(2):ObjectData.AX(end);
2661            yi=ObjectData.AY(1):dxy(1):ObjectData.AY(end);
2662            [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2663            flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2664        end
2665        AClass=class(ObjectData.A);
2666        ObjectData.A=flag_mask.*double(ObjectData.A);
2667        ObjectData.A=feval(AClass,ObjectData.A);
2668        ind_off=[];
2669        if isfield(ObjectData,'ListVarName')
2670            for ilist=1:length(ObjectData.ListVarName)
2671                if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY')
2672                    ind_off=[ind_off ilist];
2673                end
2674            end
2675            ObjectData.ListVarName(ind_off)=[];
2676            ObjectData.VarDimIndex(ind_off)=[];
2677            ind_off=[];
2678            for ilist=1:length(ObjectData.ListDimName)
2679                if isequal(ObjectData.ListDimName{ilist},'MaskX') || isequal(ObjectData.ListDimName{ilist},'MaskY')
2680                    ind_off=[ind_off ilist];
2681                end
2682            end
2683            ObjectData.ListDimName(ind_off)=[];
2684            ObjectData.DimValue(ind_off)=[];
2685        end
2686    end   
2687    if ~isempty(ObjectData)
2688        PlotType='none'; %default
2689        if imap==2 && isempty(view_field_handle)
2690            view_field(ObjectData)
2691        else
2692            [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap},PosColorbar{imap});
2693            write_plot_param(plot_handles{imap},PlotParamOut) %update the auto plot parameters
2694            if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
2695                ObjectData.Mesh=Field.Mesh; % gives an estimated mesh size (useful for mouse action on the plot)
2696            end
2697        end
2698        if isequal(PlotType,'none')
2699            hget_field=findobj(allchild(0),'name','get_field');
2700            if isempty(hget_field)
2701                get_field(filename)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2702            end
2703            errormsg='The field defined by get_field cannot be plotted';
2704            return
2705        end
2706    end
2707end
2708
2709%% update the mask
2710if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
2711   update_mask(handles,num_i1,num_i2);
2712end
2713
2714%% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
2715menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
2716ind_bad=[];
2717nb_histo=1;
2718
2719% suppress coordinates from the histogram menu
2720for ivar=1:numel(menu_histo)%l loop on field variables:
2721    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2722        Role=UvData.Field.VarAttribute{ivar}.Role;
2723        switch Role
2724            case {'coord_x','coord_y','coord_z','dimvar'}
2725                ind_bad=[ind_bad ivar];
2726            case {'vector_y'}
2727                nb_histo=nb_histo+1;
2728        end
2729    end
2730    DimCell=UvData.Field.VarDimName{ivar};
2731    DimName='';
2732    if ischar(DimCell)
2733        DimName=DimCell;
2734    elseif iscell(DimCell)&& numel(DimCell)==1
2735        DimName=DimCell{1};
2736    end
2737    if strcmp(DimName,menu_histo{ivar})
2738        ind_bad=[ind_bad ivar];
2739    end
2740end
2741menu_histo(ind_bad)=[];
2742
2743%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2744% display menus and plot histograms
2745test_v=0;
2746if ~isempty(menu_histo)
2747    set(handles.histo1_menu,'Value',1)
2748    set(handles.histo1_menu,'String',menu_histo)
2749    histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
2750    % case of more than one variables (eg vector components)
2751    if nb_histo > 1
2752        test_v=1;
2753        set(handles.histo2_menu,'Visible','on')
2754        set(handles.histo_v,'Visible','on')
2755        set(handles.histo2_menu,'String',menu_histo)
2756        set(handles.histo2_menu,'Value',2)
2757        histo2_menu_Callback(handles.histo2_menu,[], handles)% plot second histogram
2758    end
2759end
2760if ~test_v
2761    set(handles.histo2_menu,'Visible','off')
2762    set(handles.histo_v,'Visible','off')
2763    cla(handles.histo_v)
2764    set(handles.histo2_menu,'Value',1)
2765end
2766%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2767
2768%% display time
2769testimedoc=0;
[221]2770TimeUnit='';
2771if isfield(UvData.Field,'Time')
2772    abstime=UvData.Field.Time;%time read from the netcdf input file
2773end
2774if isfield(UvData,'Field_1') && isfield(UvData.Field_1,'Time')
2775    abstime_1=UvData.Field_1.Time;%time read from the netcdf input file
2776end
2777if isfield(UvData.Field,'dt')
2778    dt=UvData.Field.dt;%dt read from the netcdf input file
2779    if isfield(UvData.Field,'TimeUnit')
2780       TimeUnit=UvData.Field.TimeUnit;
2781    end
2782elseif isfield(UvData,'Field_1') && isfield(UvData.Field_1,'dt')%dt obtained from the second field if not defined in the first
2783    dt=UvData.Field_1.dt;%dt read from the netcdf input file
2784    if isfield(UvData.Field_1,'TimeUnit')
2785       TimeUnit=UvData.Field_1.TimeUnit;
2786    end
2787end
2788% time from xml file overset previous result
[199]2789if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2790    if isempty(num_i2)||isnan(num_i2)
2791        num_i2=num_i1;
2792    end
2793    if isempty(num_j1)||isnan(num_j1)
2794        num_j1=1;
2795    end
2796    if isempty(num_j2)||isnan(num_j2)
2797        num_j2=num_j1;
2798    end
2799    siz=size(UvData.XmlData.Time);
2800    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2801        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2802        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2803        testimedoc=1;
[221]2804        if isfield(UvData.XmlData,'TimeUnit')
2805            TimeUnit=UvData.XmlData.TimeUnit;
2806        end
[199]2807    end
2808end
2809if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2810    [P,F,str1,str2,str_a,str_b,E]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2811    num_i2=str2double(str2);
2812    if isnan(num_i2)
2813        num_i2=num_i1;
2814    end
2815    num_j1=str2double(str_a);
2816    if isnan(num_j1)
2817        num_j1=1;
2818    end
2819    num_j2=str2double(str_b);
2820    if isnan(num_j2)
2821        num_j2=num_j1;
2822    end
2823    num_i1=str2double(str1);
2824    siz=size(UvData.XmlData_1.Time);
2825    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2826        abstime_1=(UvData.XmlData_1.Time(num_i1,num_j1)+UvData.XmlData_1.Time(num_i2,num_j2))/2;%overset the time read from files
2827    end
2828end
2829set(handles.abs_time,'String',num2str(abstime,4))
2830set(handles.abs_time_1,'String',num2str(abstime_1,4))
2831if testimedoc && isfield(UvData,'dt')
2832    dt=UvData.dt;
2833end
2834if isempty(dt)||isequal(dt,0)
2835    set(handles.Dt_txt,'String','')
2836else
[221]2837    if  isempty(TimeUnit)
[199]2838        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2839    else
[221]2840        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' TimeUnit] )
[199]2841    end
2842end
2843
2844
2845%-------------------------------------------------------------------
2846% --- translate coordinate to matrix index
2847%-------------------------------------------------------------------
2848function [indx,indy]=pos2ind(x0,rangx0,nxy)
2849indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2850indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2851
2852%-------------------------------------------------------------------
2853% --- Executes on button press in 'FixLimits'.
2854%-------------------------------------------------------------------
2855function FixLimits_Callback(hObject, eventdata, handles)
2856test=get(handles.FixLimits,'Value');
2857if test
2858    set(handles.FixLimits,'BackgroundColor',[1 1 0])
2859else
2860    set(handles.FixLimits,'BackgroundColor',[0.7 0.7 0.7])
2861    update_plot(handles);
2862end
2863
2864%-------------------------------------------------------------------
2865% --- Executes on button press in FixEqual.
2866function FixEqual_Callback(hObject, eventdata, handles)
2867test=get(handles.FixEqual,'Value');
2868if test
2869    set(handles.FixEqual,'BackgroundColor',[1 1 0])
2870    cla(handles.axes3)
2871    update_plot(handles);
2872else
2873    set(handles.FixEqual,'BackgroundColor',[0.7 0.7 0.7])
2874    update_plot(handles);
2875%     axis(handles.axes3,'image')
2876end
2877
2878
2879%-------------------------------------------------------------------
2880
2881%-------------------------------------------------------------------
2882% --- Executes on button press in 'zoom'.
2883%-------------------------------------------------------------------
2884function zoom_Callback(hObject, eventdata, handles)
2885
2886if (get(handles.zoom,'Value') == 1);
2887    set(handles.zoom,'BackgroundColor',[1 1 0])
2888    set(handles.FixLimits,'Value',1)% propose by default fixed limits for the plotting axes
2889    set(handles.FixLimits,'BackgroundColor',[1 1 0])
2890else
2891    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
2892end
2893
2894
2895%-------------------------------------------------------------------
2896%----Executes on button press in 'record': records the current flags of manual correction.
2897%-------------------------------------------------------------------
2898function record_Callback(hObject, eventdata, handles)
2899% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2900filename=read_file_boxes(handles);
2901[erread,message]=fileattrib(filename);
2902if ~isempty(message) && ~isequal(message.UserWrite,1)
2903     msgbox_uvmat('ERROR',['no writting access to ' filename])
2904     return
2905end
2906test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
[236]2907test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
[199]2908if ~test_civ2 && ~test_civ1
2909    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2910end
2911if test_civ2
2912    nbname='nb_vectors2';
2913   flagname='vec2_FixFlag';
2914   attrname='fix2';
2915end
2916if test_civ1
2917    nbname='nb_vectors';
2918   flagname='vec_FixFlag';
2919   attrname='fix';
2920end
2921%write fix flags in the netcdf file
2922UvData=get(handles.uvmat,'UserData');
2923hhh=which('netcdf.open');% look for built-in matlab netcdf library
2924if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
2925    nc=netcdf.open(filename,'NC_WRITE');
2926    netcdf.reDef(nc);
2927    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1);
2928    dimid = netcdf.inqDimID(nc,nbname);
2929    try
2930        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2931    catch
2932        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2933    end
2934    netcdf.endDef(nc);
2935    netcdf.putVar(nc,varid,UvData.axes3.FF);
2936    netcdf.close(nc); 
2937else %old netcdf library
2938    netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2939end
2940
2941%-------------------------------------------------------------------
2942%----Correct the netcdf file, using toolbox (old versions of Matlab).
2943%-------------------------------------------------------------------
2944function netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2945nc=netcdf(filename,'write'); %open netcdf file
2946result=redef(nc);
2947eval(['nc.' attrname '=1;']);
2948theDim=nc(nbname) ;% get the number of velocity vectors
2949nb_vectors=size(theDim);
2950var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2951var_FixFlag(1:nb_vectors)=AxeData.FF;%
2952fin=close(nc);
2953
2954
2955%-------------------------------------------------------------------
2956%determines the fields to read from the interface
2957%------------------------------------------------------------------
[236]2958function VelType=setfield(handles)
2959VelTypeList=get(handles.VelType,'String');
2960index=get(handles.VelType,'Value');
2961VelType=VelTypeList{index};
[199]2962
[236]2963% VelType=[]; %default
2964% if (get(handles.VelType,'Value') == 1);
2965%         VelType='civ1';
2966% % interp1   
2967% elseif (get(handles.interp1,'Value') == 1);
2968%     VelType='interp1';
2969% % filter1   
2970% elseif (get(handles.filter1,'Value') == 1);
2971%     VelType='filter1'; 
2972% % CIV2
2973% elseif (get(handles.civ2,'Value') == 1);
2974%     VelType='civ2';
2975% % interp2   
2976% elseif (get(handles.interp2,'Value') == 1);
2977%     VelType='interp2';
2978% % filter2   
2979% elseif (get(handles.filter2,'Value') == 1); 
2980%     VelType='filter2';
2981% end
2982%
2983% if isequal(get(handles.filter2,'Visible'),'on');
2984%     civ=6;
2985% % interp1   
2986% elseif isequal(get(handles.interp2,'Visible'),'on');
2987%     civ=5;
2988% % filter1   
2989% elseif isequal(get(handles.civ2,'Visible'),'on');
2990%     civ=4; 
2991% % CIV2
2992% elseif isequal(get(handles.filter1,'Visible'),'on');
2993%    civ=3;
2994% % interp2   
2995% elseif isequal(get(handles.interp1,'Visible'),'on');
2996%     civ=2;
2997% % filter2   
2998% elseif isequal(get(handles.VelType,'Visible'),'on'); 
2999%     civ=1;
3000% else
3001%     civ=0;
3002% end
[199]3003
3004%-------------------------------------------------------------------
3005%determines the veltype of the second field to read from the iinterface
3006%------------------------------------------------------------------
3007function VelType=setfield_1(handles)
[236]3008VelTypeList=get(handles.VelType_1,'String');
3009index=get(handles.VelType_1,'Value');
3010VelType=VelTypeList{index};
3011% VelType=[]; %default
3012% if (get(handles.VelType_1,'Value') == 1);
3013%     VelType='civ1';
3014% % interp1   
3015% elseif (get(handles.interp1_1,'Value') == 1);
3016%     VelType='interp1';
3017% % filter1   
3018% elseif (get(handles.filter1_1,'Value') == 1);
3019%     VelType='filter1'; 
3020% % CIV2
3021% elseif (get(handles.civ2_1,'Value') == 1);
3022%     VelType='civ2';
3023% % interp2   
3024% elseif (get(handles.interp2_1,'Value') == 1);
3025%     VelType='interp2';
3026% % filter2   
3027% elseif (get(handles.filter2_1,'Value') == 1); 
3028%     VelType='filter2';
3029% end
[199]3030
3031
3032%---------------------------------------------------
3033% --- Executes on button press in SubField
3034function SubField_Callback(hObject, eventdata, handles)
[236]3035% huvmat=get(handles.run0,'parent');
3036UvData=get(handles.uvmat,'UserData');
[199]3037if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
3038    set(handles.RootPath_1,'String','')
3039    set(handles.RootFile_1,'String','')
3040    set(handles.SubDir_1,'String','');
3041    set(handles.FileIndex_1,'String','');
3042    set(handles.FileExt_1,'String','');
3043    set(handles.RootPath_1,'Visible','off')
3044    set(handles.RootFile_1,'Visible','off')
3045    set(handles.SubDir_1,'Visible','off');
3046    set(handles.FileIndex_1,'Visible','off');
3047    set(handles.FileExt_1,'Visible','off');
3048    set(handles.Fields_1,'Value',1);%set to blank state
[236]3049    set(handles.VelType_1,'Value',1);%set to blank state
3050    if ~strcmp(get(handles.VelType,'Visible'),'on')
3051        set(handles.VelType_1,'Visible','off')
3052    end
3053%     set_veltype_display([handles.VelType_1 handles.interp1_1 handles.filter1_1 ...
3054%             handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
[199]3055    if isfield(UvData,'XmlData_1')
3056        UvData=rmfield(UvData,'XmlData_1');
3057    end
[236]3058    set(handles.uvmat,'UserData',UvData);
[199]3059    run0_Callback(hObject, eventdata, handles); %run
3060else
3061    MenuBrowse_1_Callback(hObject, eventdata, handles)
3062end
3063
3064%------------------------------------------------------------------------
3065% --- read the data displayed for the input rootfile windows (new)
3066function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
3067%------------------------------------------------------------------------
3068RootPath=get(handles.RootPath,'String');
3069FileName=RootPath; %default
3070SubDir=get(handles.SubDir,'String');
3071if ~isempty(SubDir) && ~isequal(SubDir,'')
3072    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
3073        SubDir(1)=[]; %suppress possible / or \ separator
3074    end
3075    FileName=fullfile(RootPath,SubDir);
3076end
3077RootFile=get(handles.RootFile,'String');
3078if ~isempty(RootFile) && ~isequal(RootFile,'')
3079    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3080        RootFile(1)=[]; %suppress possible / or \ separator
3081    end
3082    FileName=fullfile(FileName,RootFile);
3083end
3084FileBase=fullfile(RootPath,RootFile);
3085FileIndices=get(handles.FileIndex,'String');
3086FileExt=get(handles.FileExt,'String');
3087FileName=[FileName FileIndices FileExt];
3088
3089%------------------------------------------------------------------------
3090% ---- read the data displayed for the second input rootfile windows
3091function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
3092%------------------------------------------------------------------------
3093RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
3094if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
3095    RootPath_1=get(handles.RootPath,'String');
3096end;
3097FileName_1=RootPath_1; %default
3098SubDir_1=get(handles.SubDir_1,'String');
3099if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
3100    SubDir_1=get(handles.SubDir,'String');
3101end
3102if numel(SubDir_1)>=1
3103    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
3104        SubDir_1(1)=[]; %suppress possible / or \ separator
3105    end
3106    FileName_1=fullfile(RootPath_1,SubDir_1);
3107end
3108RootFile_1=get(handles.RootFile_1,'String');
3109if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
3110    RootFile_1=get(handles.RootFile,'String');
3111end
3112if numel(RootFile_1)>=1
[210]3113    if ~(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
[199]3114        RootFile_1(1)=[];%suppress possible / or \ separator
3115    end
3116    FileName_1=fullfile(FileName_1,RootFile_1);
3117end
3118FileBase_1=fullfile(RootPath_1,RootFile_1);
3119if isequal(get(handles.FileIndex_1,'Visible'),'off')
3120    FileIndices_1=get(handles.FileIndex,'String');
3121else
3122    FileIndices_1=get(handles.FileIndex_1,'String');
3123end
3124FileExt_1=get(handles.FileExt_1,'String');
[246]3125if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"')
3126    FileExt_1=get(handles.FileExt,'String');%read FileExt by default
3127end
[199]3128FileName_1=[FileName_1 FileIndices_1 FileExt_1];
3129
3130%------------------------------------------------------------------------
3131% --- Executes on menu selection Fields
3132function Fields_Callback(hObject, eventdata, handles)
3133%------------------------------------------------------------------------
3134list_fields=get(handles.Fields,'String');% list menu fields
3135index_fields=get(handles.Fields,'Value');% selected string index
3136field= list_fields{index_fields(1)}; % selected string
3137if isequal(field,'get_field...')
[236]3138     set(handles.FixVelType,'visible','off')
3139      set(handles.VelType,'visible','off')
3140       set(handles.VelType_1,'visible','off')
3141%      veltype_handles=[handles.VelType handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3142%      set_veltype_display(veltype_handles,0) % unvisible civ buttons
[199]3143     filename=read_file_boxes(handles);
3144     hget_field=findobj(allchild(0),'name','get_field');
3145     if ~isempty(hget_field)
3146         delete(hget_field)
3147     end
3148     hget_field=get_field(filename);
3149     set(hget_field,'Name','get_field')       
3150     hhget_field=guidata(hget_field);
3151     set(hhget_field.list_fig,'Value',1)
3152     set(hhget_field.list_fig,'String',{'uvmat'})
3153     set(handles.transform_fct,'Value',1)% no transform by default
3154     set(handles.path_transform,'String','')
3155    return %no action
3156end
3157list_fields=get(handles.Fields_1,'String');% list menu fields
3158index_fields=get(handles.Fields_1,'Value');% selected string index
3159field_1= list_fields{index_fields(1)}; % selected string
3160UvData=get(handles.uvmat,'UserData');
3161
3162%read the rootfile input display
3163[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
3164[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
3165NomTypeNew=NomType;%default
3166if isequal(field,'image')
3167    % transform netc type to the corresponding image type
3168%     if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
3169%         UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
3170%         if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')||isequal(UvData.SubDir(1),'/'))
3171%             UvData.SubDir(1)=[];
3172%         end
3173%         set(handles.SubDir,'String','')
3174%         set(handles.FileExt,'String','.png');
3175        if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
3176            NomTypeNew='_i_j';
3177        elseif isequal(NomType,'#_ab')
3178            NomTypeNew='#a';
3179        elseif isequal(NomType,'_i1-i2')
3180            NomTypeNew='_i';
3181        end 
3182        imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3183        if ~exist(imagename,'file')
3184                [FileName,PathName] = uigetfile( ...
3185           {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3186            '*.jpg',' jpeg image files'; ...
3187            '*.png','.png image files'; ...
3188            '*.tif','.tif image files'; ...
3189            '*.avi;*.AVI','.avi movie files'; ...
3190            '*.vol','.volume images (png)'; ...
3191            '*.*',  'All Files (*.*)'}, ...
3192            'Pick an image',imagename);           
3193            % display the selected field and related information
3194           imagename=[PathName FileName];
3195        end
3196        display_file_name(hObject, eventdata, handles,imagename)%display the image
3197        return
3198%     end
[236]3199%     veltype_handles=[handles.VelType handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
[199]3200%     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3201else
3202    ext=get(handles.FileExt,'String');
3203    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
3204                [FileName,PathName] = uigetfile( ...
3205           {'*.nc', ' (*.nc)';
3206            '*.nc',' netcdf files'; ...
3207            '*.*',  'All Files (*.*)'}, ...
3208            'Pick a netcdf file',FileBase);           
3209            % display the selected field and related information
3210           filename=[PathName FileName];
3211        display_file_name(hObject, eventdata, handles,filename)
3212        return
3213       %  MenuBrowse_Callback(hObject, eventdata, handles)
3214    end
[236]3215%     if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
3216% %         set(handles.VelType,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3217% %         set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3218% %         set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
3219% %         set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
3220%     elseif isequal(field,'more...');
3221%         set(handles.VelType,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3222%         set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3223%         str=calc_field;%get the list of available scalars by the function calc_scal
3224%         [ind_answer] = listdlg('PromptString','Select a file:',...
3225%                 'SelectionMode','single',...
3226%                 'ListString',str);
3227%        % edit the choice in the field and action menu
3228%         scalar=cell2mat(str(ind_answer));
3229%         menu=update_menu(handles.Fields,scalar);
3230%         menu=[{''};menu];
3231%         set(handles.Fields_1,'String',menu);% store the selected scalar type
3232%     end
[199]3233end
3234indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3235set(handles.FileIndex,'String',indices)
3236set(handles.FileIndex,'UserData',NomTypeNew)
3237%common to Fields_1_Callback
3238if isequal(field,'image')||isequal(field_1,'image')
3239    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3240    set(handles.npy_title,'Visible','on')
3241    set(handles.npx,'Visible','on')
3242    set(handles.npy,'Visible','on')
3243else
3244    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3245    set(handles.npy_title,'Visible','off')
3246    set(handles.npx,'Visible','off')
3247    set(handles.npy,'Visible','off')
3248end
3249setfield(handles);% update the field structure ('civ1'....)
3250
3251if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3252    run0_Callback(hObject, eventdata, handles)
3253end
3254
3255%---------------------------------------------------
3256% --- Executes on menu selection Fields
3257function Fields_1_Callback(hObject, eventdata, handles)
3258%-------------------------------------------------
3259list_fields=get(handles.Fields,'String');% list menu fields
3260index_fields=get(handles.Fields,'Value');% selected string index
3261field= list_fields{index_fields(1)}; % selected string
3262list_fields=get(handles.Fields_1,'String');% list menu fields
3263index_fields=get(handles.Fields_1,'Value');% selected string index
3264field_1= list_fields{index_fields(1)}; % selected string for the second field
3265if isequal(field_1,'') %remove second field if 'blank' field is selected
3266    set(handles.SubField,'Value',0)
3267    SubField_Callback(hObject, eventdata, handles)
3268    return
3269end
3270UvData=get(handles.uvmat,'UserData');
3271
3272%read the rootfile input display
[246]3273[FileName,RootPath,FileBase,FileIndices,FileExt_1]=read_file_boxes_1(handles);
3274[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_1]);
3275% if isempty(FileExt_prev)|| strcmp(FileExt_prev,'')
3276%     FileExt_1=get(handles.FileExt,'String');
3277% else
3278%     FileExt_1=FileExt_prev;
3279% end
[199]3280NomType_1=get(handles.FileIndex_1,'UserData');
[210]3281if isempty(NomType_1)|| strcmp(NomType_1,'')
[199]3282    NomType_1=get(handles.FileIndex,'UserData');
3283end
3284NomTypeNew=NomType_1;%default
3285
3286set(handles.SubField,'Value',1)%introduce second field
3287if isfield(UvData,'XmlData')
3288    UvData.XmlData_1=UvData.XmlData;
3289end
3290set(handles.FileIndex_1,'Visible','on')
3291set(handles.FileExt_1,'Visible','on')
3292RootPath_1=get(handles.RootPath_1,'String');
3293RootFile_1=get(handles.RootFile_1,'String');
3294if isempty(RootPath_1)||isequal(RootPath_1,'')
3295    set(handles.RootPath_1,'String','"')
3296end
3297if isempty(RootFile_1) || isequal(RootFile_1,'')
3298    set(handles.RootFile_1,'String','"')
3299end
3300if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
3301    RootFile_1(1)=[];
3302end
3303
3304if isequal(field_1,'get_field...')
[236]3305     veltype_handles=[handles.VelType handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
[199]3306     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3307     filename=read_file_boxes_1(handles);
3308     hget_field=findobj(allchild(0),'name','get_field_1');
3309     if ~isempty(hget_field)
3310         delete(hget_field)
3311     end
3312     hget_field=get_field(filename);
3313     set(hget_field,'name','get_field_1')
3314     hhget_field=guidata(hget_field);
3315     set(hhget_field.list_fig,'Value',1)
3316     set(hhget_field.list_fig,'String',{'uvmat'})
3317     set(handles.transform_fct,'Value',1)% no transform by default
3318     set(handles.path_transform,'String','')
3319    return %no action
3320end
3321if isequal(field_1,'image')
3322    % transform netc type to the corresponding image type
[227]3323    if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')|| isequal(NomType_1,'#_ab')|| isequal(NomType_1,'_i1-i2')
[236]3324        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory   
[227]3325        if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')
[199]3326            NomTypeNew='_i_j';
3327        elseif isequal(NomType_1,'#_ab')
3328            NomTypeNew='#a';
3329        elseif isequal(NomType_1,'_i1-i2')
3330            NomTypeNew='_i';
3331        end 
3332    end
3333    imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3334    if ~exist(imagename,'file')
3335        [FileName,PathName] = uigetfile( ...
3336            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3337            '*.jpg',' jpeg image files'; ...
3338            '*.png','.png image files'; ...
3339            '*.tif','.tif image files'; ...
3340            '*.avi;*.AVI','.avi movie files'; ...
3341            '*.vol','.volume images (png)'; ...
3342            '*.*',  'All Files (*.*)'}, ...
3343            'Pick an image',imagename);
3344        % display the selected field and related information
3345        imagename=[PathName FileName];
3346    end
3347    display_file_name_1(hObject, eventdata, handles,imagename)%display the image
3348    return
3349else
3350    set(handles.SubDir_1,'Visible','on')
[246]3351    if ~isequal(FileExt_1,'.nc') %find the new NomType if the previous display was not already a netcdf file
[236]3352%         veltype_handles=[handles.VelType_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3353%         set_veltype_display(veltype_handles,6); % make all civ buttons visible
[199]3354        RootPath_1=get(handles.RootPath_1,'String');
3355        RootFile_1=get(handles.RootFile_1,'String');
[236]3356        if isempty(RootPath_1)||isequal(RootPath_1,'')
[199]3357            set(handles.RootPath_1,'String','"')
3358        end
[236]3359        if isempty(RootFile_1) || isequal(RootFile_1,'')
[199]3360            set(handles.RootFile_1,'String','"')
3361        end
[236]3362        if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
[199]3363            RootFile_1(1)=[];
3364        end
3365        filebase_1=fullfile(RootPath_1,RootFile_1);
3366        SubDir_1=get(handles.SubDir,'String');
3367        if isempty(SubDir_1)||isequal(SubDir_1,'')
3368            if isfield(UvData,'SubDir_1')
3369                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3370            else
3371                SubDir_1='?';
3372            end
3373        end
3374        str1=get(handles.i1,'String');
3375        str_a=get(handles.j1,'String');
3376        if isequal(NomType_1,'#_ab')||isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')||isequal(NomType_1,'_i1-i2')
3377            NomTypeNew=NomType_1;
3378        elseif isequal(NomType_1,'#a')
3379             [filename, n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),stra2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3380             NomTypeNew='#_ab';
3381        elseif isequal(NomType_1,'_i_j')
3382             [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2_j',0,str2num(str1),[],SubDir_1);
3383            if idetect==1
3384                NomTypeNew='_i1-i2_j';
3385            else
3386                NomTypeNew='_i_j1-j2';
3387            end
3388        else %for instance avi files or any ima_num series
3389            [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
3390            NomTypeNew='_i1-i2';
3391        end           
3392        [Path,Name]=fileparts(filebase_1);
3393        set(handles.FileExt_1,'String','.nc');
3394        if ~isempty(SubDir_1) && ~strcmp(SubDir_1,'''')&& ~strcmp(SubDir_1,'"')&& ~strcmp(SubDir_1(1),'/')
3395            SubDir_1=['/' SubDir_1];
3396        end
3397        set(handles.SubDir_1,'String',SubDir_1);
3398    end
[236]3399    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
3400        set(handles.VelType_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
[199]3401        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3402        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3403        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3404    elseif isequal(field_1,'more...'); %add new item to the menu
[236]3405        set(handles.VelType_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
[199]3406        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3407        str=calc_field;%get the list of available scalars by the function calc_scal
3408        [ind_answer,v] = listdlg('PromptString','Select a file:',...
3409                'SelectionMode','single',...
3410                'ListString',str);
3411       % edit the choice in the field and action menu
3412        scalar=cell2mat(str(ind_answer));
3413        menu=update_menu(handles.Fields_1,scalar);
3414        set(handles.Fields_1,'String',menu);% store the selected scalar type
3415    end
3416end
3417str1=get(handles.i1,'String');
3418str2=get(handles.i2,'String');
3419str_a=get(handles.j1,'String');
3420str_b=get(handles.j2,'String');
3421indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3422set(handles.FileIndex_1,'String',indices)
3423set(handles.FileIndex_1,'UserData',NomTypeNew)
3424
3425%common to Fields_Callback
[236]3426if isequal(field,'image')||isequal(field_1,'image')
[199]3427    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3428    set(handles.npy_title,'Visible','on')
3429    set(handles.npx,'Visible','on')
3430    set(handles.npy,'Visible','on')
3431%     set(handles.fix_pair,'Value',0)
3432else
3433    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3434    set(handles.npy_title,'Visible','off')
3435    set(handles.npx,'Visible','off')
3436    set(handles.npy,'Visible','off')
3437%     set(handles.fix_pair,'Value',1)
3438end
[236]3439if isequal(field,'velocity')||isequal(field_1,'velocity');
[199]3440    state_vect='on';
3441else
3442    state_vect='off';
3443end
[236]3444if ~isequal(field,'velocity')||(~isequal(field_1,'velocity')&~isequal(field_1,''));
[199]3445    state_scal='on';
3446else
3447    state_scal='off';
3448end
3449set(handles.uvmat,'UserData',UvData)
3450setfield(handles);% update the field structure ('civ1'....)
3451if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3452    run0_Callback(hObject, eventdata, handles)
3453end
3454
3455%------------------------------------------------------------------------
3456% --- set the visibility of relevant velocity type menus:
[236]3457function menu=set_veltype_display(Civ)
[199]3458%------------------------------------------------------------------------
3459if isequal(Civ,0)
3460    imax=0;
3461elseif isequal(Civ,1) || isequal(Civ,2)
3462   imax=1;
3463elseif isequal(Civ,3)
3464    imax=3;
3465elseif isequal(Civ,4) || isequal(Civ,5)
3466    imax=4;
3467elseif isequal(Civ,6) %patch2
3468    imax=6;
3469end
[236]3470menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
3471menu=menu(1:imax);
3472% for ibutton=1:imax;
3473%     set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3474% end
3475% % for ibutton=max(imax+1,2):6;
3476% for ibutton=imax+1:6;
3477%     set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3478%     set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3479% end
[199]3480
3481%-------------------------------------------------------------------
[236]3482% --- Executes on button press in VelType.
3483function VelType_Callback(hObject, eventdata, handles)
[199]3484%-------------------------------------------------------------------
[236]3485% if get(handles.VelType,'Value')==1
3486%     reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.VelType)
3487% else
3488%     reset_vel_type([handles.VelType handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3489% end
3490set(handles.FixVelType,'Value',1)
[199]3491run0_Callback(hObject, eventdata, handles)
3492
3493%---------------------------------------------
[236]3494function VelType_1_Callback(hObject, eventdata, handles)
[199]3495%---------------------------------------------
[236]3496 
[246]3497set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic)
[236]3498%refresh field with a second filename=first fiel name
3499set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
[246]3500drawnow   
[236]3501filename=read_file_boxes(handles);
[246]3502
3503index=get(handles.VelType_1,'Value');
3504if index==1
3505        filename_1='';% we plot the current field without the second field
3506        set(handles.SubField,'Value',0)
3507        SubField_Callback(hObject, eventdata, handles)
3508elseif get(handles.SubField,'Value')% if subfield is already 'on'
3509    filename_1=read_file_boxes_1(handles); %read the current second field
[199]3510else
[246]3511     filename_1=filename;% we compare two fields in the same file
3512     set(handles.SubField,'Value',1)
[199]3513end
[246]3514
[236]3515num_i1=stra2num(get(handles.i1,'String'));
3516num_i2=stra2num(get(handles.i2,'String'));
3517num_j1=stra2num(get(handles.j1,'String'));
3518num_j2=stra2num(get(handles.j2,'String'));
[199]3519
[236]3520errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
[199]3521
[236]3522if ~isempty(errormsg)
3523    msgbox_uvmat('ERROR',errormsg);
[199]3524else
[236]3525    set(handles.i1,'BackgroundColor',[1 1 1])
3526    set(handles.i2,'BackgroundColor',[1 1 1])
3527    set(handles.j1,'BackgroundColor',[1 1 1])
3528    set(handles.j2,'BackgroundColor',[1 1 1])
3529    set(handles.FileIndex,'BackgroundColor',[1 1 1])
3530    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
[199]3531end
[236]3532set(handles.run0,'BackgroundColor',[1 0 0])
[199]3533
3534%-----------------------------------------------
3535% --- reset civ buttons
3536function reset_vel_type(handles_civ0,handle1)
3537for ibutton=1:length(handles_civ0)
3538    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3539    set(handles_civ0(ibutton),'Value',0)
3540end
3541if exist('handle1','var')%handles of selected button
3542        set(handle1,'BackgroundColor',[1 1 0]) 
3543end
3544
3545%-------------------------------------------------------
3546% --- Executes on button press in MENUVOLUME.
3547%-------------------------------------------------------
3548function VOLUME_Callback(hObject, eventdata, handles)
3549%errordlg('command VOL not implemented yet')
3550if ishandle(handles.UVMAT_title)
3551    delete(handles.UVMAT_title)
3552end
3553UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3554if isequal(get(handles.VOLUME,'Value'),1)
3555    set(handles.zoom,'Value',0)
3556    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3557    set(handles.edit_vect,'Value',0)
3558    edit_vect_Callback(hObject, eventdata, handles)
3559    set(handles.edit_object,'Value',0)
3560    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3561%     set(handles.cal,'Value',0)
3562%     set(handles.cal,'BackgroundColor',[0 1 0])
3563    set(handles.edit_vect,'Value',0)
3564    edit_vect_Callback(hObject, eventdata, handles)
3565    %initiate set_object GUI
3566    data.TITLE='VOLUME';
3567    if isfield(UvData,'CoordType')
3568        data.CoordType=UvData.CoordType;
3569    end
3570    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3571        data.RangeY=UvData.Mesh;
3572        data.RangeX=UvData.Mesh;
3573        data.DX=UvData.Mesh;
3574        data.DY=UvData.Mesh;
3575    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3576        np=size(UvData.Field.A);
3577        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3578        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3579        data.RangeY=max(meshx,meshy);
3580        data.RangeX=max(meshx,meshy);
3581        data.DX=max(meshx,meshy);
3582    end
3583    data.ParentButton=handles.VOLUME;
3584    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3585    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3586                                                      % associate the set_object interface handle to the plotting axes
3587    if isfield(UvData.OpenParam,'SetObjectOrigin')                                               
3588    pos_uvmat=get(huvmat,'Position');
3589    pos_set_object(1:2)=UvData.OpenParam.SetObjectOrigin + pos_uvmat(1:2);
3590    pos_set_object(3:4)=UvData.OpenParam.SetObjectSize .* pos_uvmat(3:4); 
3591    set(hset_object,'Position',pos_set_object)
3592    end
3593    UvData.MouseAction='create_object';
3594else
3595    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3596    UvData.MouseAction='none';
3597end
3598set(huvmat,'UserData',UvData)
3599
3600%-------------------------------------------------------
3601function edit_vect_Callback(hObject, eventdata, handles)
3602%-------------------------------------------------------
3603%
3604% UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3605if isequal(get(handles.edit_vect,'Value'),1)
3606    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
[236]3607    test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
[199]3608    if ~test_civ2 && ~test_civ1
3609        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3610    end
3611    set(handles.record,'Visible','on')
3612    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3613    set(handles.edit_object,'Value',0)
3614    set(handles.zoom,'Value',0)
3615    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3616%     set(handles.create,'Value',0)
3617%     set(handles.create,'BackgroundColor',[0 1 0])
3618    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3619    set(gcf,'Pointer','arrow')
3620%     UvData.MouseAction='edit_vect';
3621else
3622    set(handles.record,'Visible','off')
3623    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3624%     UvData.MouseAction='none';
3625end
3626% set(handles.uvmat,'UserData',UvData)
3627
3628%----------------------------------------------
3629function save_mask_Callback(hObject, eventdata, handles)
3630%-----------------------------------------------------------------------
3631UvData=get(handles.uvmat,'UserData');
3632
3633flag=1;
3634npx=size(UvData.Field.A,2);
3635npy=size(UvData.Field.A,1);
3636xi=0.5:npx-0.5;
3637yi=0.5:npy-0.5;
3638[Xi,Yi]=meshgrid(xi,yi);
3639if isfield(UvData,'Object')
3640    for iobj=1:length(UvData.Object)
3641        ObjectData=UvData.Object{iobj};
3642        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3643            flagobj=1;
3644            testphys=0; %coordinates in pixels by default
3645            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3646                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3647                    Calib=UvData.XmlData.GeometryCalib;
3648                    testphys=1;
3649                end
3650            end
3651            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3652                if isequal(ObjectData.Style,'polygon')
3653                    X=ObjectData.Coord(:,1);
3654                    Y=ObjectData.Coord(:,2);
3655                    if testphys
3656                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3657                    end
3658                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
3659                elseif isequal(ObjectData.Style,'ellipse')
3660                    if testphys
3661                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3662                    end
3663                    RangeX=max(ObjectData.RangeX);
3664                    RangeY=max(ObjectData.RangeY);
3665                    X2Max=RangeX*RangeX;
3666                    Y2Max=RangeY*RangeY;
3667                    distX=(Xi-ObjectData.Coord(1,1));
3668                    distY=(Yi-ObjectData.Coord(1,2));
3669                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3670                elseif isequal(ObjectData.Style,'rectangle')
3671                    if testphys
3672                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3673                    end
3674                    distX=abs(Xi-ObjectData.Coord(1,1));
3675                    distY=abs(Yi-ObjectData.Coord(1,2));
3676                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3677                end
3678                if isequal(ObjectData.ProjMode,'mask_outside')
3679                    flagobj=~flagobj;
3680                end
3681                flag=flag & flagobj;
3682            end
3683        end
3684    end
3685end
3686% flag=~flag;
3687%mask name
3688RootPath=get(handles.RootPath,'String');
3689RootFile=get(handles.RootFile,'String');
3690if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3691        RootFile(1)=[];
3692end
3693filebase=fullfile(RootPath,RootFile);
3694list=get(handles.masklevel,'String');
3695masknumber=num2str(length(list));
3696maskindex=get(handles.masklevel,'Value');
3697mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3698imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3699imflag=flipdim(imflag,1);
3700% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3701msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3702imwrite(imflag,mask_name,'BitDepth',8);
3703
3704%display the mask
3705%update_mask(handles,num_i1,num_j1)
3706figure;
3707vec=linspace(0,1,256);%define a linear greyscale colormap
3708map=[vec' vec' vec'];
3709colormap(map)
3710
3711image(imflag);
3712
3713%-------------------------------------------------------------------
3714%-------------------------------------------------------------------
3715%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3716
3717%------------------------------------------------------------------
3718
3719
3720
3721%------------------------------------------------------------------
3722% --- Executes on selection change in col_vec: choice of the color code.
3723%
3724function col_vec_Callback(hObject, eventdata, handles)
3725%------------------------------------------------------------------
3726% edit the choice for color code
3727list_code=get(handles.col_vec,'String');% list menu fields
3728index_code=get(handles.col_vec,'Value');% selected string index
3729col_code= list_code{index_code(1)}; % selected field
3730if isequal(col_code,'black') || isequal(col_code,'white')
3731   set(handles.slider1,'Visible','off')
3732   set(handles.slider2,'Visible','off')
3733   set(handles.colcode1,'Visible','off')
3734   set(handles.colcode2,'Visible','off')
3735   set(handles.AutoVecColor,'Visible','off')
3736   set_vec_col_bar(handles)
3737else
3738   set(handles.slider1,'Visible','on')
3739   set(handles.slider2,'Visible','on')
3740   set(handles.colcode1,'Visible','on')
3741   set(handles.colcode2,'Visible','on')
3742   set(handles.AutoVecColor,'Visible','on') 
3743   if isequal(col_code,'ima_cor')
3744       set(handles.AutoVecColor,'Value',0)%fixed scale by default
3745       set(handles.vec_col_bar,'Value',0)% 3 colors r,g,b by default
3746       set(handles.slider1,'Min',0);
3747       set(handles.slider1,'Max',1);
3748       set(handles.slider2,'Min',0);
3749       set(handles.slider2,'Max',1);
3750 %      set(handles.min_title_vec,'String','0')
3751       set(handles.max_vec,'String','1')
3752       set(handles.colcode1,'String','0.333')
3753       colcode1_Callback(hObject, eventdata, handles)
3754       set(handles.colcode2,'String','0.666')
3755       colcode2_Callback(hObject, eventdata, handles)
3756   else
3757       set(handles.AutoVecColor,'Value',1)%auto scale between min,max by default
3758       set(handles.vec_col_bar,'Value',1)% colormap 'jet' by default
3759       minval=get(handles.slider1,'Min');
3760       maxval=get(handles.slider1,'Max');
3761       set(handles.slider1,'Value',minval)
3762       set(handles.slider2,'Value',maxval)
3763       set_vec_col_bar(handles)
3764   end
3765%    slider_update(handles)
3766end
3767%replot the current graph
3768run0_Callback(hObject, eventdata, handles)
3769
3770
3771%----------------------------------------------------------------
3772% -- Executes on slider movement to set the color code
3773%
3774function slider1_Callback(hObject, eventdata, handles)
3775%------------------------------------------------------------------
3776slider1=get(handles.slider1,'Value');
3777min_val=str2num(get(handles.min_vec,'String'));
3778max_val=str2num(get(handles.max_vec,'String'));
3779col=min_val+(max_val-min_val)*slider1;
3780set(handles.colcode1,'String',num2str(col))
3781if(get(handles.slider2,'Value') < col)%move also the second slider at the same value if needed
3782    set(handles.slider2,'Value',col)
3783    set(handles.colcode2,'String',num2str(col))
3784end
3785colcode1_Callback(hObject, eventdata, handles)
3786
3787%----------------------------------------------------------------
3788% Executes on slider movement to set the color code
3789%----------------------------------------------------------------
3790function slider2_Callback(hObject, eventdata, handles)
3791slider2=get(handles.slider2,'Value');
3792min_val=str2num(get(handles.min_vec,'String'));
3793max_val=str2num(get(handles.max_vec,'String'));
3794col=min_val+(max_val-min_val)*slider2;
3795set(handles.colcode2,'String',num2str(col))
3796if(get(handles.slider1,'Value') > col)%move also the first slider at the same value if needed
3797    set(handles.slider1,'Value',col)
3798    set(handles.colcode1,'String',num2str(col))
3799end
3800colcode2_Callback(hObject, eventdata, handles)
3801
3802%----------------------------------------------------------------
3803%execute on return carriage on the edit box corresponding to slider 1
3804%----------------------------------------------------------------
3805function colcode1_Callback(hObject, eventdata, handles)
3806% col=str2num(get(handles.colcode1,'String'));
3807% set(handles.slider1,'Value',col)
3808set_vec_col_bar(handles)
3809update_plot(handles);
3810
3811%----------------------------------------------------------------
3812%execute on return carriage on the edit box corresponding to slider 2
3813%----------------------------------------------------------------
3814function colcode2_Callback(hObject, eventdata, handles)
3815% col=str2num(get(handles.colcode2,'String'));
3816% set(handles.slider2,'Value',col)
3817% slider2_Callback(hObject, eventdata, handles)
3818set_vec_col_bar(handles)
3819update_plot(handles);
3820%------------------------------------------------------------
3821%update the slider values after displaying vectors
3822%--------------------------------------------------------
3823% function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
3824% set(handles.slider1,'Min',minC)
3825% set(handles.slider1,'Max',maxC)
3826% set(handles.slider2,'Min',minC)
3827% set(handles.slider2,'Max',maxC)
3828% set(handles.min_title_vec,'String',num2str(minC))
3829% set(handles.max_vec,'String',num2str(maxC))
3830% if auto
3831%         set(handles.colcode1,'String',num2str(colcode1,3))%update display
3832%         set(handles.colcode2,'String',num2str(colcode2,3))
3833% end
3834% set(handles.slider1,'Value',colcode1)%update slider with constant display
3835% set(handles.slider2,'Value',colcode2)
3836% set_vec_col_bar(handles)
3837
3838
3839%-------------------------------------------------------
3840% --- Executes on button press in AutoVecColor.
3841%-------------------------------------------------------
3842function vec_col_bar_Callback(hObject, eventdata, handles)
3843set_vec_col_bar(handles)
3844
3845%-------------------------------------------------------------
3846% --- Executes on selection change in transform_fct.
3847function transform_fct_Callback(hObject, eventdata, handles)
3848%-------------------------------------------------------------
3849
3850UvData=get(handles.uvmat,'UserData');
3851menu=get(handles.transform_fct,'String');
3852ind_coord=get(handles.transform_fct,'Value');
3853coord_option=menu{ind_coord};
3854list_transform=get(handles.transform_fct,'UserData');
3855ff=functions(list_transform{end}); 
3856if isequal(coord_option,'more...');
3857    coord_fct='';
3858    prompt = {'Enter the name of the transform function'};
3859    dlg_title = 'user defined transform';
3860    num_lines= 1;
3861    [FileName, PathName] = uigetfile( ...
3862       {'*.m', ' (*.m)';
3863        '*.m',  '.m files '; ...
3864        '*.*', 'All Files (*.*)'}, ...
3865        'Pick a file', ff.file);
3866    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
3867        PathName(end)=[];
3868    end
3869    transform_selected =fullfile(PathName,FileName);
3870    if ~exist(transform_selected,'file')
3871           return
3872    end
3873   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
3874   if ~isequal(ext_fct,'.m')
3875        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
3876        return
3877   end
3878   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
3879   ind_coord=get(handles.transform_fct,'Value');
3880   addpath(PathName)
3881   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
3882   set(handles.transform_fct,'UserData',list_transform)
3883   rmpath(PathName)
3884   % save the new menu in the personal file 'uvmat_perso.mat'
3885   dir_perso=prefdir;%personal Matalb directory
3886   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3887   if exist(profil_perso,'file')
3888       nb_builtin=UvData.OpenParam.NbBuiltin;
3889       for ilist=nb_builtin+1:numel(list_transform)
3890           ff=functions(list_transform{ilist});
3891           transform_fct{ilist-nb_builtin}=ff.file;
3892       end
3893        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
3894   end   
3895end
3896
3897%check the current path to the selected function
3898if isa(list_transform{ind_coord},'function_handle')
3899    func=functions(list_transform{ind_coord});
3900    set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
3901else
3902    set(handles.path_transform,'String','')
3903end
3904
3905set(handles.FixLimits,'Value',0)
3906set(handles.FixLimits,'BackgroundColor',[0.7 0.7 0.7])
3907
3908%delete drawn objects
3909hother=findobj('Tag','proj_object');%find all the proj objects
3910for iobj=1:length(hother)
3911    delete_object(hother(iobj))
3912end
3913hother=findobj('Tag','DeformPoint');%find all the proj objects
3914for iobj=1:length(hother)
3915    delete_object(hother(iobj))
3916end
3917hh=findobj('Tag','calib_points');
3918if ~isempty(hh)
3919    delete(hh)
3920end
3921hhh=findobj('Tag','calib_marker');
3922if ~isempty(hhh)
3923    delete(hhh)
3924end
3925if isfield(UvData,'Object')
3926     UvData.Object=UvData.Object(1);
3927end
3928list_object=get(handles.list_object_1,'String');
3929set(handles.list_object_1,'Value',1)
[231]3930set(handles.list_object_1,'String',{''})
[238]3931set(handles.list_object_2,'Value',1)
[231]3932set(handles.list_object_2,'String',{''})
[199]3933list_object_2_Callback(hObject, eventdata, handles)
3934
3935%delete mask if it is displayed
3936if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
3937   UvData=rmfield(UvData,'MaskName'); %will impose mask refresh 
3938end
3939set(handles.uvmat,'UserData',UvData)
3940run0_Callback(hObject, eventdata, handles)
3941
3942%--------------------------------------------
3943function histo1_menu_Callback(hObject, eventdata, handles)
3944%--------------------------------------------
3945%plot first histo
3946huvmat=get(handles.histo1_menu,'parent');
3947histo_menu=get(handles.histo1_menu,'String');
3948histo_value=get(handles.histo1_menu,'Value');
3949FieldName=histo_menu{histo_value};
3950update_histo(handles.histo_u,huvmat,FieldName)
3951
3952%----------------------------------------------
3953function histo2_menu_Callback(hObject, eventdata, handles)
3954%----------------------------------------------
3955%plot second histo
3956huvmat=get(handles.histo2_menu,'parent');
3957histo_menu=get(handles.histo2_menu,'String');
3958histo_value=get(handles.histo2_menu,'Value');
3959FieldName=histo_menu{histo_value};
3960update_histo(handles.histo_v,huvmat,FieldName)
3961
3962
3963%--------------------------------------------
3964%read the field .Fieldname stored in UvData and plot its histogram
3965function update_histo(haxes,huvmat,FieldName)
3966UvData=get(huvmat,'UserData');
3967if ~isfield(UvData.Field,FieldName)
3968    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
3969    return
3970end
3971Field=UvData.Field;
3972FieldHisto=eval(['Field.' FieldName]);
3973if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto))
3974    indsel=find(Field.FF==0);%find values marked as false
3975    if ~isempty(indsel)
3976        FieldHisto=FieldHisto(indsel);
3977    end
3978end
3979if isempty(Field)
3980    msgbox_uvmat('ERROR',['empty field ' FieldName])
3981else
3982    nxy=size(FieldHisto);
3983    Amin=double(min(min(min(FieldHisto))));%min of image
3984    Amax=double(max(max(max(FieldHisto))));%max of image
3985    if isequal(Amin,Amax)
3986        msgbox_uvmat('WARNING',['uniform field =' num2str(Amin)]);
3987    else
3988        Histo.ListVarName={FieldName,'histo'};
3989        if isequal(Field.NbDim,3)
3990            Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
3991        else
3992            if numel(nxy)==2
3993                Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
3994            else
3995                Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
3996            end
3997        end
3998        %unit
3999        units=[]; %default
4000        for ivar=1:numel(Field.ListVarName)
4001            if strcmp(Field.ListVarName{ivar},FieldName)
4002                if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
4003                    units=Field.VarAttribute{ivar}.units;
4004                    break
4005                end
4006            end
4007        end
4008        if ~isempty(units)
4009            Histo.VarAttribute{1}.units=units;
4010        end
4011        eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
4012        if isequal(Field.NbDim,3)
4013            C=reshape(double(FieldHisto),1,[]);% reshape in a vector
4014            eval(['Histo.histo(:,1)=hist(C, Histo.' FieldName ');']);  %calculate histogram
4015        else
4016            for col=1:size(FieldHisto,3)
4017                B=FieldHisto(:,:,col);
4018                C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
4019                eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
4020            end
4021        end
4022%         set(haxes,'XLimMode','auto')%reset auto mode (after zoom effect)
4023%         set(haxes,'YLimMode','auto')
4024%         PlotParam.Auto_xy=1;
4025        plot_field(Histo,haxes);
4026    end
4027end
4028
4029%------------------------------------------------
4030%CALLBACKS FOR PLOTTING PARAMETERS
4031%-------------------------------------------------
4032
4033%------------------------------------------------------------------------
4034function MinX_Callback(hObject, eventdata, handles)
4035%------------------------------------------------------------------------
4036set(handles.FixLimits,'Value',1) %suppress auto mode
4037set(handles.FixLimits,'BackgroundColor',[1 1 0])
4038update_plot(handles);
4039
4040%------------------------------------------------------------------------
4041function MaxX_Callback(hObject, eventdata, handles)
4042%------------------------------------------------------------------------
4043set(handles.FixLimits,'Value',1) %suppress auto mode
4044set(handles.FixLimits,'BackgroundColor',[1 1 0])
4045update_plot(handles);
4046
4047%------------------------------------------------------------------------
4048function MinY_Callback(hObject, eventdata, handles)
4049%------------------------------------------
4050set(handles.FixLimits,'Value',1) %suppress auto mode
4051set(handles.FixLimits,'BackgroundColor',[1 1 0])
4052update_plot(handles);
4053
4054%------------------------------------------------------------------------
4055function MaxY_Callback(hObject, eventdata, handles)
4056%------------------------------------------------------------------------
4057set(handles.FixLimits,'Value',1) %suppress auto mode
4058set(handles.FixLimits,'BackgroundColor',[1 1 0])
4059update_plot(handles);
4060
4061%------------------------------------------------------------------------
4062function MinA_Callback(hObject, eventdata, handles)
4063%------------------------------------------
4064set(handles.FixScal,'Value',1) %suppress auto mode
4065set(handles.FixScal,'BackgroundColor',[1 1 0])
[227]4066MinA=str2double(get(handles.MinA,'String'));
4067MaxA=str2double(get(handles.MaxA,'String'));
4068if MinA>MaxA% switch minA and maxA in case of error
4069    MinA_old=MinA;
4070    MinA=MaxA;
4071    MaxA=MinA_old;
4072    set(handles.MinA,'String',num2str(MinA,5));
4073    set(handles.MaxA,'String',num2str(MaxA,5));
4074end
[199]4075update_plot(handles);
4076
4077%------------------------------------------------------------------------
4078function MaxA_Callback(hObject, eventdata, handles)
4079%------------------------------------------------------------------------
4080set(handles.FixScal,'Value',1) %suppress auto mode
4081set(handles.FixScal,'BackgroundColor',[1 1 0])
[227]4082MinA=str2double(get(handles.MinA,'String'));
4083MaxA=str2double(get(handles.MaxA,'String'));
4084if MinA>MaxA% switch minA and maxA in case of error
4085        MinA_old=MinA;
4086    MinA=MaxA;
4087    MaxA=MinA_old;
4088    set(handles.MinA,'String',num2str(MinA,5));
4089    set(handles.MaxA,'String',num2str(MaxA,5));
4090end
[199]4091update_plot(handles);
4092
4093%------------------------------------------------------------------------
4094function FixScal_Callback(hObject, eventdata, handles)
4095%------------------------------------------------------------------------
4096test=get(handles.FixScal,'Value');
4097if test
4098    set(handles.FixScal,'BackgroundColor',[1 1 0])
4099else
4100    set(handles.FixScal,'BackgroundColor',[0.7 0.7 0.7])
4101    update_plot(handles);
4102end
4103
4104%-------------------------------------------------------------------
4105function BW_Callback(hObject, eventdata, handles)
4106%-------------------------------------------------------------------
4107update_plot(handles);
4108
4109%-------------------------------------------------------------------
4110function Contours_Callback(hObject, eventdata, handles)
4111%-------------------------------------------------------------------
4112val=get(handles.Contours,'Value');
4113if val==2
4114    set(handles.interval_txt,'Visible','on')
4115    set(handles.IncrA,'Visible','on')
4116else
4117    set(handles.interval_txt,'Visible','off')
4118    set(handles.IncrA,'Visible','off')
4119end
4120update_plot(handles);
4121
4122%-------------------------------------------------------------------
4123function IncrA_Callback(hObject, eventdata, handles)
4124%-------------------------------------------------------------------
4125update_plot(handles);
4126
4127%-------------------------------------------------------------------
4128function HideWarning_Callback(hObject, eventdata, handles)
4129%-------------------------------------------------------------------
4130update_plot(handles);
4131
4132%-------------------------------------------------------------------
4133function HideFalse_Callback(hObject, eventdata, handles)
4134%-------------------------------------------------------------------
4135update_plot(handles);
4136
4137%-------------------------------------------------------------------
4138function VecScale_Callback(hObject, eventdata, handles)
4139%-------------------------------------------------------------------
4140set(handles.FixVec,'Value',1);
4141set(handles.FixVec,'BackgroundColor',[1 1 0])
4142update_plot(handles);
4143
4144%-------------------------------------------------------------------
4145function FixVec_Callback(hObject, eventdata, handles)
4146%-------------------------------------------------------------------
4147test=get(handles.FixVec,'Value');
4148if test
4149    set(handles.FixVec,'BackgroundColor',[1 1 0])
4150else
4151    update_plot(handles);
4152    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4153    set(handles.FixVec,'BackgroundColor',[0.7 0.7 0.7])
4154end
4155
4156%------------------------------------------------------------------------
4157% --- Executes on selection change in decimate4 (nb_vec/4).
4158function decimate4_Callback(hObject, eventdata, handles)
4159%------------------------------------------------------------------------
4160update_plot(handles);
4161
4162%------------------------------------------------------------------------
4163% --- Executes on selection change in color_code menu
4164function color_code_Callback(hObject, eventdata, handles)
4165%------------------------------------------------------------------------
4166set_vec_col_bar(handles)
4167update_plot(handles);
4168
4169%------------------------------------------------------------------------
4170% --- Executes on button press in AutoVecColor.
4171function AutoVecColor_Callback(hObject, eventdata, handles)
4172%------------------------------------------------------------------------
4173test=get(handles.AutoVecColor,'Value');
4174if test
4175    set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
4176else
4177    update_plot(handles);
4178    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4179    set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
4180end
4181
4182%------------------------------------------------------------------------
4183% --- Executes on selection change in max_vec.
4184function min_vec_Callback(hObject, eventdata, handles)
4185%------------------------------------------------------------------------
4186max_vec_Callback(hObject, eventdata, handles)
4187
4188%------------------------------------------------------------------------
4189% --- Executes on selection change in max_vec.
4190function max_vec_Callback(hObject, eventdata, handles)
4191%------------------------------------------------------------------------
4192set(handles.AutoVecColor,'Value',1)
4193AutoVecColor_Callback(hObject, eventdata, handles)
4194min_val=str2num(get(handles.min_vec,'String'));
4195max_val=str2num(get(handles.max_vec,'String'));
4196slider1=get(handles.slider1,'Value');
4197slider2=get(handles.slider2,'Value');
4198colcode1=min_val+(max_val-min_val)*slider1;
4199colcode2=min_val+(max_val-min_val)*slider2;
4200set(handles.colcode1,'String',num2str(colcode1))
4201set(handles.colcode2,'String',num2str(colcode2))
4202update_plot(handles);
4203
4204%------------------------------------------------------------------------
4205% --- update the display of color code for vectors
4206function set_vec_col_bar(handles)
4207%------------------------------------------------------------------------
4208%get the image of the color display button 'vec_col_bar' in pixels
4209set(handles.vec_col_bar,'Unit','pixel');
4210pos_vert=get(handles.vec_col_bar,'Position');
4211set(handles.vec_col_bar,'Unit','Normalized');
4212width=ceil(pos_vert(3));
4213height=ceil(pos_vert(4));
4214
4215%get slider indications
4216list=get(handles.color_code,'String');
4217ichoice=get(handles.color_code,'Value');
4218colcode.ColorCode=list{ichoice};
4219colcode.MinC=str2num(get(handles.min_vec,'String'));
4220colcode.MaxC=str2num(get(handles.max_vec,'String'));
4221test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
4222if test3color
4223    colcode.colcode1=str2num(get(handles.colcode1,'String'));
4224    colcode.colcode2=str2num(get(handles.colcode2,'String'));
4225end
4226colcode.FixedCbounds=0;
4227colcode.FixedCbounds=1;
4228vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*(0.5:width-0.5)/width;%sample of vec_C values from min to max
4229[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4230oneheight=ones(1,height);
4231A1=colorlist(col_vec,1)*oneheight;
4232A2=colorlist(col_vec,2)*oneheight;
4233A3=colorlist(col_vec,3)*oneheight;
4234A(:,:,1)=A1';
4235A(:,:,2)=A2';
4236A(:,:,3)=A3';
4237set(handles.vec_col_bar,'Cdata',A)
4238
4239
4240%-------------------------------------------------------------------
4241function update_plot(handles)
4242%-------------------------------------------------------------------
4243haxes= handles.axes3;
4244UvData=get(handles.uvmat,'UserData');
4245AxeData=UvData.axes3;
4246PlotParam=read_plot_param(handles);
4247[PP,PlotParamOut]= plot_field(AxeData,haxes,PlotParam);
4248write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4249
4250%-------------------------------------------------------------------
4251% --- Executes on button press in grid.
4252function grid_Callback(hObject, eventdata, handles)
4253
4254
4255%-------------------------------------------------------------------
4256% --- Executes on selection change in edit_object.
4257function edit_object_Callback(hObject, eventdata, handles)
4258%-------------------------------------------------------------------
4259UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4260test=get(handles.edit_object,'Value');
4261if test
4262    set(handles.edit_object,'BackgroundColor',[1,1,0]) 
4263    %suppress the other options
4264    set(handles.zoom,'Value',0)
4265    zoom_Callback(hObject, eventdata, handles)
4266    hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4267    if ishandle(hgeometry_calib)
4268        hhgeometry_calib=guidata(hgeometry_calib);
4269        set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib
4270        set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7])
4271    end
4272else
4273    UvData.MouseAction='none';
4274    set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7])   
4275    hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
4276    if ~isempty(hset_object)
4277        delete(hset_object)% delete the current GUI set_object
4278    end
4279end
4280set(handles.uvmat,'UserData',UvData);
4281hset_object=findobj(allchild(0),'Tag','set_object');
4282if ~isempty(hset_object)
4283    hhset_object=guidata(hset_object);
4284    if test
4285        set(hhset_object.PLOT,'enable','on');
4286    else
4287       set(hhset_object.PLOT,'enable','off');
4288    end
4289end
4290
4291%------------------------------------------------------------------------
4292% --- Executes on selection change in list_object_1.
4293function list_object_1_Callback(hObject, eventdata, handles)
4294%------------------------------------------------------------------------
4295list_str=get(handles.list_object_1,'String');
4296IndexObj=get(handles.list_object_1,'Value');
4297str_1=list_str{IndexObj};
[231]4298% val_2=get(handles.list_object_2,'Value');
4299% str_2=get(handles.list_object_2,'String');
4300% if isequal(val_2,IndexObj)% if the first selection is equal to the second, it will suppress the second
4301%     set(handles.list_object_2,'Value',numel(str_2))%select the end of the list ('...')
4302%     list_object_2_Callback(hObject, eventdata, handles)
4303% end
[199]4304update_object(handles,IndexObj,1,str_1)
4305
4306%------------------------------------------------------------------------
4307% --- Executes on selection change in list_object_1.
4308function list_object_2_Callback(hObject, eventdata, handles)
4309%------------------------------------------------------------------------
[242]4310list_str=get(handles.list_object_2,'String');
4311IndexObj=get(handles.list_object_2,'Value');
[231]4312if ischar(list_str) || isempty(list_str{IndexObj})% || strcmp(list_str{IndexObj},'...')
[199]4313    hview_field=findobj(allchild(0),'Tag','view_field');
4314    if ~isempty(hview_field)
4315        delete(hview_field)
4316    end
4317    hset_object=findobj(allchild(0),'Tag','set_object');
4318    if ~isempty(hset_object)
4319        delete(hset_object)
4320    end
4321else
4322    update_object(handles,IndexObj,2,list_str{IndexObj})
4323end
4324
4325%------------------------------------------------------------------------
4326function update_object(handles,IndexObj,option,ObjectName)
4327%------------------------------------------------------------------------
4328UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4329if numel(UvData.Object)<IndexObj;
4330    return
4331end
4332ObjectData=UvData.Object{IndexObj};
4333ObjectData.Name=ObjectName;
4334if isequal(get(handles.edit_object,'Value'),1)
4335    ObjectData.enable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4336end
4337ZBounds=0; % default
4338if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4339    ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4340    ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4341end
4342hset_object=findobj(allchild(0),'tag','set_object');
4343if ~isempty(hset_object)
4344    delete(hset_object)% delete existing version of set_object
4345end
4346edit_test=get(handles.edit_object,'Value');
4347if edit_test
4348    ObjectData.enable_plot=1;
4349else
[210]4350    if isfield(ObjectData,'enable_plot')
[199]4351        ObjectData=rmfield(ObjectData,'enable_plot');
4352    end
4353end
4354hset_object=set_object(ObjectData,[],ZBounds);% call the set_object interface,
4355
4356% %project the current field on the object and plot it
4357ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
4358if option==1%length(UvData.Object)>= IndexObj && isfield(UvData.Object{IndexObj},'plotaxes')&& ishandle(UvData.Object{IndexObj}.plotaxes)
4359    PlotHandles=handles;
4360else
4361    hview_field=findobj(allchild(0),'tag','view_field');
4362    if isempty(hview_field)
4363        hview_field=view_field;
4364    end
4365    PlotHandles=guidata(hview_field);
4366end
[231]4367%plot_field(ProjData,PlotHandles.axes3,PlotHandles);
[199]4368set(handles.uvmat,'UserData',UvData)
4369hother=findobj('Tag','proj_object');%find all the proj objects
4370for iobj=1:length(hother)
4371    if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
4372        set(hother(iobj),'EdgeColor','b')
4373        if isequal(get(hother(iobj),'FaceColor'),'m')
4374            set(hother(iobj),'FaceColor','b')
4375        end
4376    elseif isequal(get(hother(iobj),'Type'),'image')
4377        Acolor=get(hother(iobj),'CData');
4378        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4379        set(hother(iobj),'CData',Acolor);
4380    else
4381        set(hother(iobj),'Color','b')
4382    end
4383    set(hother(iobj),'Selected','off')
4384end
4385hother=findobj('Tag','DeformPoint');
4386set(hother,'Color','b');
4387set(hother,'Selected','off')
4388if isfield(ObjectData,'DisplayHandle_uvmat')
4389    if ishandle(ObjectData.DisplayHandle_uvmat)
4390        uistack(ObjectData.DisplayHandle_uvmat,'top')
4391        linetype=get(ObjectData.DisplayHandle_uvmat,'Type');
4392        if isequal(linetype,'line')
4393            set(ObjectData.DisplayHandle_uvmat,'Color','m'); %set the selected object to magenta color
4394        elseif isequal(linetype,'rectangle')
4395            set(ObjectData.DisplayHandle_uvmat,'EdgeColor','m'); %set the selected object to magenta color
4396        elseif isequal(linetype,'patch')
4397            set(ObjectData.DisplayHandle_uvmat,'FaceColor','m'); %set the selected object to magenta color
4398        end
4399        SubObjectData=get(ObjectData.DisplayHandle_uvmat,'UserData');
4400        if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
4401            uistack(SubObjectData.SubObject,'top')
4402            for iobj=1:length(SubObjectData.SubObject)
4403                hsub=SubObjectData.SubObject(iobj);
4404                if isequal(get(hsub,'Type'),'rectangle')
4405                    set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4406                elseif isequal(get(hsub,'Type'),'image')
4407                    Acolor=get(hsub,'CData');
4408                    Acolor(:,:,1)=Acolor(:,:,3);
4409                    set(hsub,'CData',Acolor);
4410                else
4411                    set(hsub,'Color','m')
4412                end
4413            end
4414        end
4415        if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
4416            set(SubObjectData.DeformPoint,'Color','m')
4417        end
4418    end
4419    %     end
4420end
4421% pause(0.1)
4422figure(hset_object)%put set_object in front
4423
4424%------------------------------------------------------
4425% --- Executes on button press in Menu/Export/field in workspace.
4426%------------------------------------------------------
4427function MenuExportField_Callback(hObject, eventdata, handles)
4428global Data_uvmat
4429Data_uvmat=get(handles.uvmat,'UserData');
4430evalin('base','global Data_uvmat')%make CurData global in the workspace
4431display('current field :')
4432evalin('base','Data_uvmat') %display CurData in the workspace
4433commandwindow; %brings the Matlab command window to the front
4434
4435%------------------------------------------------------
4436% --- Executes on button press in Menu/Export/extract figure.
4437%------------------------------------------------------
4438function MenuExport_plot_Callback(hObject, eventdata, handles)
4439huvmat=get(handles.MenuExport_plot,'parent');
4440UvData=get(huvmat,'UserData');
4441hfig=figure;
4442newaxes=copyobj(handles.axes3,hfig);
4443map=colormap(handles.axes3);
4444colormap(map);%transmit the current colormap to the zoom fig
4445colorbar
4446
4447
4448% --------------------------------------------------------------------
4449function Insert_Callback(hObject, eventdata, handles)
4450
4451
4452% --------------------------------------------------------------------
4453function MenuHelp_Callback(hObject, eventdata, handles)
4454% --------------------------------------------------------------------
4455path_to_uvmat=which ('uvmat');% check the path of uvmat
4456pathelp=fileparts(path_to_uvmat);
4457helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4458if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4459else
4460    addpath (fullfile(pathelp,'uvmat_doc'))
4461    web(helpfile);
4462end
4463
4464%------------------------------------------------------------------------
4465% --------------------------------------------------------------------
4466function MenuExportMovie_Callback(hObject, eventdata, handles)
4467% --------------------------------------------------------------------
4468set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4469huvmat=get(handles.run0,'parent');
4470UvData=get(huvmat,'UserData');
4471[xx,xx,FileBase]=read_file_boxes(handles);
4472 %read the current input file name
4473prompt = {'movie file name';'frames per second';'frame resolution (*[512x384] pixels)';'axis position relative to the frame';'total frame number (starting from the current uvmat display)'};
4474dlg_title = 'select properties of the output avi movie';
4475num_lines= 1;
4476% nbfield_cell=get(handles.last_i,'String');
4477def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4478answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4479aviname=answer{1};
4480fps=str2double(answer{2});
4481% check for existing file with output name aviname
4482if exist(aviname,'file')
4483    backup=aviname;
4484    testexist=2;
4485    while testexist==2
4486        backup=[backup '~'];
4487        testexist=exist(backup,'file');     
4488    end
4489    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4490    if isequal(success,1)
4491        delete(aviname)%delete existing file
4492    else
4493        msgbox_uvmat('ERROR',message)
4494        return
4495    end
4496end
4497%create avi open
4498aviobj=avifile(aviname,'Compression','None','fps',fps);
4499
4500%display first view for tests
4501newfig=figure;
4502newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
4503set(newaxes,'Tag','movieaxes')
4504nbpix=[512 384]*str2double(answer{3});
4505set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4506set(newaxes,'Position',eval(answer{4}));
4507map=colormap(handles.axes3);
4508colormap(map);%transmit the current colormap to the zoom fig
4509msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4510        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
[215]4511UvData.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
[199]4512set(huvmat,'UserData',UvData);
4513increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
4514if isnan(increment)
4515    set(handles.increment_scan,'String','1')%default value
4516    increment=1;
4517end
4518set(handles.STOP,'Visible','on')
4519set(handles.speed,'Visible','on')
4520set(handles.speed_txt,'Visible','on')
4521set(handles.Movie,'BusyAction','queue')
4522
4523%imin=str2double(get(handles.i1,'String'));
4524imax=str2double(answer{5});
4525% if isfield(UvData,'Time')
4526htitle=get(newaxes,'Title');
4527xlim=get(newaxes,'XLim');
4528ylim=get(newaxes,'YLim');
4529set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4530time_str=get(handles.abs_time,'String');
4531set(htitle,'String',['t=' time_str])
4532set(handles.speed,'Value',1)
4533for i=1:imax
4534    if get(handles.speed,'Value')~=0 && isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4535            runpm(hObject,eventdata,handles,increment)% run plus
4536            drawnow
4537            time_str=get(handles.abs_time,'String');
4538            if ishandle(htitle)
4539             set(htitle,'String',['t=' time_str])
4540            end
4541            mov=getframe(newfig);
4542            aviobj=addframe(aviobj,mov);
4543    end
4544end
[215]4545aviobj=close(aviobj);
4546UvData=rmfield(UvData,'plotaxes');
4547%UvData.Object{1}.plotaxes=handles.axes3;
[199]4548set(huvmat,'UserData',UvData);
4549msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4550
4551%------------------------------------------------------------------------
4552function MenuCalib_Callback(hObject, eventdata, handles)
4553%------------------------------------------------------------------------
4554
4555UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4556
4557%suppress competing options
4558set(handles.zoom,'Value',0)
4559set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4560set(handles.list_object_1,'Value',1)     
4561% initiate display of GUI geometry_calib
4562data=[]; %default
4563if isfield(UvData,'CoordType')
4564    data.CoordType=UvData.CoordType;
4565end
4566pos=get(handles.uvmat,'Position');
4567pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
4568pos(2)=pos(2)-0.02;
4569[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
4570set(handles.view_xml,'Backgroundcolor',[1 1 0])%indicate the reading of the current xml file by geometry_calib
4571if isfield(UvData.OpenParam,'CalOrigin')
4572    pos_uvmat=get(handles.uvmat,'Position');
4573    pos_cal(1)=pos_uvmat(1)+UvData.OpenParam.CalOrigin(1)*pos_uvmat(3);
4574    pos_cal(2)=pos_uvmat(2)+UvData.OpenParam.CalOrigin(2)*pos_uvmat(4);
4575    pos_cal(3:4)=UvData.OpenParam.CalSize .* pos_uvmat(3:4);
4576end
4577geometry_calib(FileName,pos_cal);% call the geometry_calib interface   
4578set(handles.view_xml,'Backgroundcolor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib
4579set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action
4580
4581%------------------------------------------------------------------------
4582function MenuMask_Callback(hObject, eventdata, handles)
4583%------------------------------------------------------------------------
4584UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4585ListObj=UvData.Object;
4586select=zeros(1,numel(ListObj));
4587for iobj=1:numel(ListObj);
4588    if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside')
4589        select(iobj)=1;
4590    end
4591end
4592val=find(select);
4593if isempty(val)
4594    msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar');
4595    return
4596else
4597    set(handles.list_object_1,'Max',2);%allow multiple selection
4598    set(handles.list_object_1,'Value',val);
4599    flag=1;
4600    npx=size(UvData.Field.A,2);
4601    npy=size(UvData.Field.A,1);
4602    xi=0.5:npx-0.5;
4603    yi=0.5:npy-0.5;
4604    [Xi,Yi]=meshgrid(xi,yi);
4605    if isfield(UvData,'Object')
4606        for iobj=1:length(UvData.Object)
4607            ObjectData=UvData.Object{iobj};
4608            if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
4609                flagobj=1;
4610                testphys=0; %coordinates in pixels by default
4611                if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel')
4612                    if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
4613                        Calib=UvData.XmlData.GeometryCalib;
4614                        testphys=1;
4615                    end
4616                end
4617                if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
4618                    if isequal(ObjectData.Style,'polygon')
4619                        X=ObjectData.Coord(:,1);
4620                        Y=ObjectData.Coord(:,2);
4621                        if testphys
4622                            [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
4623                        end
4624                        flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
4625                    elseif isequal(ObjectData.Style,'ellipse')
4626                        if testphys
4627                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4628                        end
4629                        RangeX=max(ObjectData.RangeX);
4630                        RangeY=max(ObjectData.RangeY);
4631                        X2Max=RangeX*RangeX;
4632                        Y2Max=RangeY*RangeY;
4633                        distX=(Xi-ObjectData.Coord(1,1));
4634                        distY=(Yi-ObjectData.Coord(1,2));
4635                        flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
4636                    elseif isequal(ObjectData.Style,'rectangle')
4637                        if testphys
4638                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4639                        end
4640                        distX=abs(Xi-ObjectData.Coord(1,1));
4641                        distY=abs(Yi-ObjectData.Coord(1,2));
4642                        flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
4643                    end
4644                    if isequal(ObjectData.ProjMode,'mask_outside')
4645                        flagobj=~flagobj;
4646                    end
4647                    flag=flag & flagobj;
4648                end
4649            end
4650        end
[231]4651    end
[199]4652    %mask name
4653    RootPath=get(handles.RootPath,'String');
4654    RootFile=get(handles.RootFile,'String');
4655    if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
4656        RootFile(1)=[];
4657    end
4658    filebase=fullfile(RootPath,RootFile);
4659    list=get(handles.masklevel,'String');
4660    masknumber=num2str(length(list));
4661    maskindex=get(handles.masklevel,'Value');
4662    mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
4663    imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
4664    imflag=flipdim(imflag,1);
4665
4666    %display the mask
[231]4667    hfigmask=figure;
4668    set(hfigmask,'Name','mask image')
[199]4669    vec=linspace(0,1,256);%define a linear greyscale colormap
4670    map=[vec' vec' vec'];
4671    colormap(map)
4672    image(imflag);
4673    answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name);
4674    if ~strcmp(answer,'Cancel')
4675        mask_dir=fileparts(answer);
4676        if ~exist(mask_dir,'dir')
4677            msgbox_uvmat('ERROR',['directory ' mask_dir ' does not exist'])
4678            return
4679        end
4680        imwrite(imflag,answer,'BitDepth',8);
4681    end
4682    set(handles.list_object_1,'Value',1)
4683    set(handles.list_object_1,'Max',1)
4684end
4685
4686%------------------------------------------------------------------------
4687%-- open the GUI set_grid.fig to create grid
4688function MenuGrid_Callback(hObject, eventdata, handles)
4689%------------------------------------------------------------------------
4690%UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4691
4692%suppress the other options if grid is chosen
4693set(handles.edit_vect,'Value',0)
4694edit_vect_Callback(hObject, eventdata, handles)
4695set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
4696set(handles.list_object_1,'Value',1)     
4697
4698%prepare display of the set_grid GUI
4699FileName=read_file_boxes(handles);
4700CoordList=get(handles.transform_fct,'String');
4701val=get(handles.transform_fct,'Value');
4702set_grid(FileName,CoordList{val});% call the set_object interface
4703%set(handles.uvmat,'UserData',UvData);
4704
4705%------------------------------------------------------------------------
4706% open the GUI 'series'
4707function MenuSeries_Callback(hObject, eventdata, handles)
4708%------------------------------------------------------------------------
4709series; %first display of the GUI to fill waiting time
4710[param.FileName]=read_file_boxes(handles);
4711if isequal(get(handles.SubField,'Value'),1)
4712    FileName_1=read_file_boxes_1(handles);%
4713    if ~isequal(FileName_1,param.FileName)
4714        param.FileName_1=FileName_1;
4715    end
4716end
4717param.NomType=get(handles.FileIndex,'UserData');
4718param.NomType_1=get(handles.FileIndex_1,'UserData');
4719param.comp_input=get(handles.fix_pair,'Value');
4720huvmat=get(handles.MenuSeries,'parent');
4721UvData=get(huvmat,'UserData');
4722if isfield(UvData,'Time')
4723    param.Time=UvData.XmlData.Time;
4724end
4725if isequal(get(handles.scan_i,'Value'),1)
4726    param.incr_i=str2double(get(handles.increment_scan,'String'));
4727elseif isequal(get(handles.scan_j,'Value'),1)
4728    param.incr_j=str2double(get(handles.increment_scan,'String'));
4729end
4730param.list_fields=get(handles.Fields,'String');% list menu fields
4731param.list_fields(1)=[]; %suppress  'image' option
4732param.index_fields=get(handles.Fields,'Value');% selected string index
4733if param.index_fields>1
4734    param.index_fields=param.index_fields-1;
4735end
4736param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
4737param.list_fields_1(1)=[]; %suppress  'image' option
4738param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
4739if param.index_fields_1>1
4740    param.index_fields_1=param.index_fields_1-1;
4741end
[238]4742% if isequal(get(handles.VelType,'Visible'),'on')
4743%     param.VelTypeMenu=get(handles.VelType,'String');
4744%     param.VelTypeIndex=get(handles.VelType,'Value');
4745% end
4746% param.civ1=get(handles.VelType,'Value');
4747% param.civ2=get(handles.civ2,'Value');
4748% param.interp1=get(handles.interp1,'Value');
4749% param.interp2=get(handles.interp2,'Value');
4750% param.filter1=get(handles.filter1,'Value');
4751% param.filter2=get(handles.filter2,'Value');
[199]4752param.menu_coord_str=get(handles.transform_fct,'String');
4753param.menu_coord_val=get(handles.transform_fct,'Value');
4754
4755series(param); %run the series interface
4756
4757%------------------------------------------------------------------------
4758% -- open the GUI civ.fig for civx (PIV)
4759function MenuPIV_Callback(hObject, eventdata, handles)
4760%------------------------------------------------------------------------
4761 
4762[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
4763num1=stra2num(get(handles.i1,'String'));
4764num2=stra2num(get(handles.i2,'String'));
4765num_a=stra2num(get(handles.j1,'String'));
4766num_b=stra2num(get(handles.j2,'String'));
4767NomType=get(handles.FileIndex,'UserData');
4768ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4769if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4770    ind_opening=2;% propose 'fix' as the default option
4771% +read the current netcdf rootfile
4772    Data=nc2struct(FileName,'ListGlobalAttribute','fix','patch','civ2','fix2');
4773    if isfield(Data,'fix') && isequal(Data.fix,1)
4774        ind_opening=3;
4775    end
4776    if isfield(Data,'patch') && isequal(Data.patch,1)
4777        ind_opening=4;
4778    end
4779    if isfield(Data,'civ2') && isequal(Data.civ2,1)
4780        ind_opening=5;
4781    end
4782    if isfield(Data,'fix2') && isequal(Data.fix2,1)
4783        ind_opening=6;
4784    end
4785end     
4786param.RootName=filebase;
4787param.NomType=NomType;
4788param.num1=num1;
4789param.num2=num2;
4790param.num_a=num_a;
4791param.num_b=num_b;
4792param.SubDir=SubDir;
4793param.IndOpening=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4794param.ImaExt=ext;
4795civ(param);% interface de civ(not in the uvmat file)
4796
4797%------------------------------------------------------------------------
4798function MenuTools_Callback(hObject, eventdata, handles)
4799%------------------------------------------------------------------------
4800
4801%------------------------------------------------------------------------
4802function MenuEditObject_Callback(hObject, eventdata, handles)
4803%------------------------------------------------------------------------
4804set(handles.edit_object,'Value',1)
4805edit_Callback(hObject, eventdata, handles)
4806
4807%------------------------------------------------------------------------
4808function enable_transform(handles,state)
4809%------------------------------------------------------------------------
4810set(handles.transform_fct,'Visible',state)
4811set(handles.TRANSFORM_txt,'Visible',state)   
4812set(handles.transform_fct,'Visible',state) 
4813set(handles.path_transform,'Visible',state)
4814set(handles.pxcmx_txt,'Visible',state)
4815set(handles.pxcmy_txt,'Visible',state)
4816set(handles.pxcm,'Visible',state)
4817set(handles.pycm,'Visible',state)
4818
4819%------------------------------------------------------------------------
4820function MenuEditVectors_Callback(hObject, eventdata, handles)
4821%------------------------------------------------------------------------
4822set(handles.edit_vect,'Visible','on')
4823set(handles.edit_vect,'Value',1)
4824edit_vect_Callback(hObject, eventdata, handles)
4825
4826% -----------------------------------------------------------------------
4827function Menupoints_Callback(hObject, eventdata, handles)
4828%------------------------------------------------------------------------
4829data.Style='points';
4830data.ProjMode='projection';%default
4831create_object(data,handles)
4832
4833% -----------------------------------------------------------------------
4834function Menuline_Callback(hObject, eventdata, handles)
4835%------------------------------------------------------------------------
4836data.Style='line';
4837data.ProjMode='projection';%default
4838create_object(data,handles)
4839
4840%------------------------------------------------------------------------
4841function Menupolyline_Callback(hObject, eventdata, handles)
4842%------------------------------------------------------------------------
4843data.Style='polyline';
4844data.ProjMode='projection';%default
4845create_object(data,handles)
4846
4847%------------------------------------------------------------------------
4848function Menupolygon_Callback(hObject, eventdata, handles)
4849%------------------------------------------------------------------------
4850data.Style='polygon';
4851data.ProjMode='inside';%default
4852create_object(data,handles)
4853
4854%------------------------------------------------------------------------
4855function Menurectangle_Callback(hObject, eventdata, handles)
4856%------------------------------------------------------------------------
4857data.Style='rectangle';
4858data.ProjMode='inside';%default
4859create_object(data,handles)
4860
4861%------------------------------------------------------------------------
4862function Menuellipse_Callback(hObject, eventdata, handles)
4863%------------------------------------------------------------------------
4864data.Style='ellipse';
4865data.ProjMode='inside';%default
4866create_object(data,handles)
4867
4868%------------------------------------------------------------------------
4869function MenuMaskObject_Callback(hObject, eventdata, handles)
4870%------------------------------------------------------------------------
4871data.Style='polygon';
4872data.StyleMenu={'polygon'};
4873data.ProjMode='mask_inside';%default
4874data.ProjMenu={'mask_inside';'mask_outside'};
4875create_object(data,handles)
4876
4877%------------------------------------------------------------------------
4878function Menuplane_Callback(hObject, eventdata, handles)
4879%------------------------------------------------------------------------
4880data.Style='plane';
4881data.ProjMode='projection';%default
4882
4883create_object(data,handles)
4884
4885%------------------------------------------------------------------------
4886function Menuvolume_Callback(hObject, eventdata, handles)
4887%------------------------------------------------------------------------
4888data.Style='volume';
4889data.ProjMode='interp';%default
4890% set(handles.create,'Visible','on')
4891% set(handles.create,'Value',1)
4892% VOLUME_Callback(hObject,eventdata,handles)
4893create_object(data,handles)
4894
4895%------------------------------------------------------------------------
4896function MenuBrowseObject_Callback(hObject, eventdata, handles)
4897%------------------------------------------------------------------------
4898%get the object file
4899[FileName, PathName, filterindex] = uigetfile( ...
4900       {'*.xml;*.mat', ' (*.xml,*.mat)';
4901       '*.xml',  '.xml files '; ...
4902        '*.mat',  '.mat matlab files '}, ...
4903        'Pick an xml Object file',get(handles.RootPath,'String'));
4904fileinput=[PathName FileName];%complete file name
4905% testblank=findstr(fileinput,' ');%look for blanks
4906% if ~isempty(testblank)
4907%     msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
4908%     return
4909% end
4910sizf=size(fileinput);
4911if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
4912
4913%read the file
4914t=xmltree(fileinput);
4915data=convert(t);
4916data.enable_plot=1;
4917[pp,data.Name]=fileparts(FileName);
4918%PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4919hset_object=findobj(allchild(0),'tag','set_object');
4920if ~isempty(hset_object)
4921    delete(hset_object)% delete existing version of set_object
4922end
4923% UvData=get(handles.uvmat,'UserData');
4924set_object(data);% call the set_object interface
4925% %position the set_object GUI with respect to uvmat
4926% pos_uvmat=get(handles.uvmat,'Position');
4927% if isfield(UvData,'SetObjectOrigin')
4928%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4929%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4930%     set(hset_object,'Position',pos_set_object)
4931% end
4932set(handles.edit_object,'Value',0); %suppress the object edit mode
4933set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
4934set(handles.MenuObject,'checked','on')
4935%UvData.MouseAction='create_object';
4936% set(handles.uvmat,'UserData',UvData)
4937set(handles.delete_object,'Visible','on')
4938set(handles.uvmat_title,'Visible','on')
4939set(handles.view_field_title,'Visible','on')
4940
4941%------------------------------------------------------------------------
4942% --- generic function used for the creation of a projection object
4943function create_object(data,handles)
4944%------------------------------------------------------------------------
4945hset_object=findobj(allchild(0),'tag','set_object');
4946if ~isempty(hset_object)
4947    delete(hset_object)% delete existing version of set_object
4948end
4949hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4950if ishandle(hgeometry_calib)
4951    hhgeometry_calib=guidata(hgeometry_calib);
4952    set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib
4953    set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7])
4954end
4955UvData=get(handles.uvmat,'UserData');
4956set(handles.edit_object,'Value',0); %suppress the object edit mode
4957set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
4958data.enable_plot=1;
4959transform_list=get(handles.transform_fct,'String');
4960val=get(handles.transform_fct,'Value');
4961%data.CoordType=transform_list{val};
4962if isfield(UvData,'Field')
4963    Field=UvData.Field;
4964    if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
4965        data.RangeX=Field.Mesh;
4966        data.RangeY=Field.Mesh;
4967        data.DX=Field.Mesh;
4968        data.DY=Field.Mesh;
4969    elseif isfield(Field,'AX')&& isfield(Field,'AY')&& isfield(Field,'A')%only image
4970        np=size(Field.A);
4971        meshx=(Field.AX(end)-Field.AX(1))/np(2);
4972        meshy=abs(Field.AY(end)-Field.AY(1))/np(1);
4973        data.RangeY=max(meshx,meshy);
4974        data.RangeX=max(meshx,meshy);
4975        data.DX=max(meshx,meshy);
4976    end
4977    if isfield(Field,'NbDim')
4978        data.NbDim=Field.NbDim;
4979    end
4980    if isfield(Field,'CoordUnit')
4981        data.CoordUnit=Field.CoordUnit;
4982    end
4983end
4984data.Coord=[0 0 0]; %default
4985if isfield(data,'Style') && isequal(data.Style,'line')
4986    if isfield(data,'DX')
4987        data.Coord=[[0 0 0];[data.DX 0 0]]; %default
4988    else
4989        data.Coord=[[0 0 0];[1 0 0]]; %default
4990    end
4991end
4992if ishandle(handles.UVMAT_title)
4993    delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered
4994end
4995%PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4996set_object(data,handles);% call the set_object interface
4997set(handles.MenuObject,'checked','on')
4998set(handles.uvmat,'UserData',UvData)
4999set(handles.zoom,'Value',0)
5000zoom_Callback(handles.uvmat, [], handles)
5001set(handles.delete_object,'Visible','on')
5002set(handles.uvmat_title,'Visible','on')
5003set(handles.view_field_title,'Visible','on')
5004
5005%------------------------------------------------------------------------
5006function MenuRuler_Callback(hObject, eventdata, handles)
5007%------------------------------------------------------------------------
5008set(handles.zoom,'Value',0)
5009zoom_Callback(handles.uvmat, [], handles)
5010set(handles.MenuRuler,'checked','on')
5011UvData=get(handles.uvmat,'UserData');
5012UvData.MouseAction='ruler';
5013set(handles.uvmat,'UserData',UvData);
5014
5015%------------------------------------------------------------------------
5016% --- executed when closing: set the parent interface button to value 0
5017function closefcn(gcbo,eventdata)
5018%------------------------------------------------------------------------
5019%delete all the associated figures if exist
5020hh=findobj(allchild(0),'tag','view_field');
5021if ~isempty(hh)
5022    delete(hh)
5023end
5024hh=findobj(allchild(0),'tag','geometry_calib');
5025if ~isempty(hh)
5026    delete(hh)
5027end
5028hh=findobj(allchild(0),'tag','set_object');
5029if ~isempty(hh)
5030    hhh=findobj(hh,'tag','PLOT');
5031    set(hhh,'enable','off')
5032end
5033
5034%------------------------------------------------------------------------
5035% --- Executes on button press in delete_object.
5036function delete_object_Callback(hObject, eventdata, handles)
5037%------------------------------------------------------------------------
5038IndexObj=get(handles.list_object_2,'Value');
5039if IndexObj>1
5040    delete_object(IndexObj)
5041end
5042
[236]5043% --- Executes on button press in FixVelType.
5044function FixVelType_Callback(hObject, eventdata, handles)
5045val=get(handles.FixVelType,'Value');
5046if ~val
5047    run0_Callback(hObject, eventdata, handles)
5048end
[199]5049
[236]5050
Note: See TracBrowser for help on using the repository browser.