source: trunk/src/uvmat.m @ 191

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

introduce edit boxes to set axis limits. rationalisation of names FixScal?, FixLimits?....
introduce volume scan in calibration procedures

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