source: trunk/src/uvmat.m @ 82

Last change on this file since 82 was 82, checked in by sommeria, 14 years ago

mouse_up: improve zoom : keep the selected point at the same place on the graph
plot_field: memorize the max coordiantes on the graph (AxeData?) for zoom out
set_object: input possibilities extende to restrict menu (for mask objects)
uvmat: improvement of mask creation
civ: select mask option for civ2 when select(ed for civ1

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