source: trunk/src/uvmat.m @ 192

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

civ: version working for all systems: windows, linux, mac
plots: introduction of axes limits , bug repairs (still further work needed)

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