source: trunk/src/uvmat.m @ 100

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

plot_field.m, update_obj.m do not change figure names
view_field.m,uvmat.m cleaning code

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