source: trunk/src/uvmat.m @ 141

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

cleaning

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