source: trunk/src/uvmat.m @ 102

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

bugs corrected for projection objects

File size: 211.3 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');
2593haxes_1=handles.axes3;
2594if IndexObj(1)> numel(UvData.Object)
2595    IndexObj(1)=1;
2596    haxes_1=handles.axes3;
2597end
2598view_field_handle=[];
2599IndexObj_2=get(handles.list_object_2,'Value');
2600if isequal(get(handles.list_object_2,'Visible'),'on') && IndexObj_2 <= numel(UvData.Object)
2601    IndexObj(2)=IndexObj_2;
2602    view_field_handle=findobj(allchild(0),'tag','view_field');
2603end
2604for imap=1:numel(IndexObj)
2605    iobj=IndexObj(imap);
2606    if ~isempty(UvData.Object{iobj})%& isfield(Object{iobj},'plotaxes')& ishandle(Object{iobj}.plotaxes)
2607        %Projeter les champs sur l'objet:*
2608        ObjectData=proj_field(UvData.Field,UvData.Object{iobj},iobj);
2609        %use of mask
2610        if isfield(ObjectData,'NbDim')&isequal(ObjectData.NbDim,2)
2611            if isfield(ObjectData,'Mask') & isfield(ObjectData,'A')
2612                 flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2613                 AX=ObjectData.AX;
2614                 AY=ObjectData.AY;
2615                 MaskX=ObjectData.MaskX;
2616                 MaskY=ObjectData.MaskY;
2617                 if ~isequal(MaskX,AX)|~isequal(MaskY,AY)
2618                     nxy=size(flag_mask);
2619                     sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2620                     sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2621                     x_mask=[ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end)]; % pixel x coordinates for image display
2622                     y_mask=[ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end)];% pixel x coordinates for image display
2623                     %project on the positions of the scalar
2624                     npxy=size(ObjectData.A);
2625                     dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2626                     dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2627                     xi=[ObjectData.AX(1):dxy(2):ObjectData.AX(end)];
2628                     yi=[ObjectData.AY(1):dxy(1):ObjectData.AY(end)];     
2629                     [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2630                    flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2631                 end
2632                 AClass=class(ObjectData.A);
2633                 ObjectData.A=flag_mask.*double(ObjectData.A);
2634                 ObjectData.A=feval(AClass,ObjectData.A);
2635                 ind_off=[];
2636                 if isfield(ObjectData,'ListVarName')
2637                      for ilist=1:length(ObjectData.ListVarName)
2638                           if isequal(ObjectData.ListVarName{ilist},'Mask')|isequal(ObjectData.ListVarName{ilist},'MaskX')|isequal(ObjectData.ListVarName{ilist},'MaskY')
2639                               ind_off=[ind_off ilist];
2640                           end
2641                      end
2642                      ObjectData.ListVarName(ind_off)=[];
2643                      ObjectData.VarDimIndex(ind_off)=[];
2644                      ind_off=[];       
2645                      for ilist=1:length(ObjectData.ListDimName)       
2646                           if isequal(ObjectData.ListDimName{ilist},'MaskX')|isequal(ObjectData.ListDimName{ilist},'MaskY')
2647                               ind_off=[ind_off ilist];
2648                           end
2649                      end
2650                      ObjectData.ListDimName(ind_off)=[];
2651                      ObjectData.DimValue(ind_off)=[];
2652                 end
2653            end 
2654        end
2655        if ~isempty(ObjectData)
2656%             haxes=[];%default
2657%             if isfield(UvData.Object{iobj},'plotaxes')
2658%                 haxes=UvData.Object{iobj}.plotaxes;%axes used for representing the projection on the object
2659%             end
2660            PosColorbar=[];%default: no colorbar
2661            if ishandle(haxes_1) & isequal(get(haxes_1,'Tag'),'axes3')& isfield(UvData,'PosColorbar')
2662                PosColorbar=UvData.PosColorbar;%prescribe the colorbar position on the uvmat interface
2663            else
2664                PosColorbar='*';%default position
2665            end
2666            if imap==1 %plot on uvmat
2667                PlotParam=read_plot_param(handles);%read plotting parameters on the uvmat interface
2668                [PlotType,ScalOut,UvData.Object{iobj}.plotaxes]=plot_field(ObjectData,haxes_1,PlotParam,keeplim,PosColorbar);
2669            elseif ~isempty(view_field_handle)
2670                view_field_hh=guidata(view_field_handle);
2671                PlotParam=read_plot_param(view_field_hh);%read plotting parameters on the uvmat interface
2672                [PlotType,ScalOut,UvData.Object{iobj}.plotaxes]=plot_field(ObjectData,view_field_hh.axes3,PlotParam,keeplim,PosColorbar);
2673            else
2674                [pt,so,UvData.Object{iobj}.plotaxes]=view_field(ObjectData);
2675            end
2676           
2677            if isequal(PlotType,'none')
2678                hget_field=findobj(allchild(0),'name','get_field');
2679                if isempty(hget_field)
2680                    get_field([],ObjectData)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2681                else
2682                    errormsg='The field defined by get_field cannot be plotted';
2683                    return
2684                end
2685            end 
2686            UvData.Object{iobj}.PlotParam=ScalOut; %record the plotting parameters
2687        end       
2688    end
2689end
2690
2691%display the updated plotting parameters for the base menuplane
2692write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
2693UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2694set(handles.uvmat,'UserData',UvData)
2695
2696%update the mask
2697if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
2698   update_mask(handles,num_i1,num_i2);
2699end
2700
2701%prepare the menus of histograms (for the whole menuvolume in 3D case)
2702menu_histo=(UvData.Field.ListVarName)';
2703ind_bad=[];
2704nb_histo=1;
2705for ivar=1:numel(menu_histo)
2706    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2707        Role=UvData.Field.VarAttribute{ivar}.Role;
2708        switch Role
2709            case {'coord_x','coord_y','coord_z','dimvar'}
2710                ind_bad=[ind_bad ivar];
2711            case {'vector_y'}
2712                nb_histo=nb_histo+1;
2713        end
2714    end
2715    DimCell=UvData.Field.VarDimName{ivar};
2716    DimName='';
2717    if ischar(DimCell)
2718        DimName=DimCell;
2719    elseif iscell(DimCell)&& numel(DimCell)==1
2720        DimName=DimCell{1};
2721    end
2722    if strcmp(DimName,menu_histo{ivar})
2723        ind_bad=[ind_bad ivar];
2724    end
2725end
2726menu_histo(ind_bad)=[];
2727test_v=0;
2728if ~isempty(menu_histo)
2729    set(handles.histo1_menu,'Value',1)
2730    set(handles.histo1_menu,'String',menu_histo)
2731    histo1_menu_Callback(handles.histo1_menu, [], handles)
2732    if nb_histo > 1
2733        test_v=1;
2734        set(handles.histo2_menu,'Visible','on')
2735        set(handles.histo_v,'Visible','on')
2736        set(handles.histo2_menu,'String',menu_histo)
2737        set(handles.histo2_menu,'Value',2)
2738        histo2_menu_Callback(handles.histo2_menu,[], handles)
2739    end
2740end
2741if ~test_v
2742    set(handles.histo2_menu,'Visible','off')
2743    set(handles.histo_v,'Visible','off')
2744    cla(handles.histo_v)
2745    set(handles.histo2_menu,'Value',1)
2746end
2747
2748%display time
2749testimedoc=0;
2750if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2751    if isempty(num_i2)||isnan(num_i2)
2752        num_i2=num_i1;
2753    end
2754    if isempty(num_j1)||isnan(num_j1)
2755        num_j1=1;
2756    end
2757    if isempty(num_j2)||isnan(num_j2)
2758        num_j2=num_j1;
2759    end
2760    siz=size(UvData.XmlData.Time);
2761    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2762        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2763        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2764        testimedoc=1;
2765    end
2766end
2767if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2768    [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2769    num_i2=str2num(str2);
2770    if isempty(num_i2)
2771        num_i2=num_i1;
2772    end
2773    num_j1=str2num(str_a);
2774    if isempty(num_j1)
2775        num_j1=1;
2776    end
2777    num_j2=str2num(str_b);
2778    if isempty(num_j2)
2779        num_j2=num_j1;
2780    end
2781    num_i1=str2num(str1);
2782    siz=size(UvData.XmlData_1.Time);
2783    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2784        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
2785    end
2786end
2787set(handles.abs_time,'String',num2str(abstime,4))
2788set(handles.abs_time_1,'String',num2str(abstime_1,4))
2789if testimedoc && isfield(UvData,'dt')
2790    dt=UvData.dt;
2791end
2792if isequal(dt,0)
2793    set(handles.Dt_txt,'String','')
2794else
2795    if ~(isfield(UvData,'TimeUnit') && ~isempty(UvData.TimeUnit))
2796        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2797    else
2798        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
2799    end
2800end
2801%update the input file name in the get_field GUI
2802if isequal(FieldName,'get_field...')
2803    set(hhget_field.inputfile,'String',filename)
2804    Tabchar={''};%default
2805    Tabcell=[];
2806    if isfield(Field{1},'ListGlobalAttribute')& ~isempty(Field{1}.ListGlobalAttribute)
2807        for iline=1:length(Field{1}.ListGlobalAttribute)
2808            Tabcell{iline,1}=Field{1}.ListGlobalAttribute{iline};
2809            if isfield(Field{1}, Field{1}.ListGlobalAttribute{iline})
2810                eval(['val=Field{1}.' Field{1}.ListGlobalAttribute{iline} ';'])
2811                if ischar(val);
2812                    Tabcell{iline,2}=val;
2813                else
2814                    Tabcell{iline,2}=num2str(val);
2815                end
2816            end
2817        end
2818        if ~isempty(Tabcell)
2819            Tabchar=cell2tab(Tabcell,'=');
2820            Tabchar=[{''};Tabchar];
2821        end
2822    end
2823    set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
2824end
2825if isequal(FieldName_1,'get_field...')
2826    set(hhget_field_1.inputfile,'String',filename_1)
2827    Tabchar={''};%default
2828    Tabcell=[];
2829    if isfield(Field{2},'ListGlobalAttribute')& ~isempty(Field{2}.ListGlobalAttribute)
2830        for iline=1:length(Field{2}.ListGlobalAttribute)
2831            Tabcell{iline,1}=Field{2}.ListGlobalAttribute{iline};
2832            if isfield(Field{2}, Field{2}.ListGlobalAttribute{iline})
2833                eval(['val=Field{2}.' Field{2}.ListGlobalAttribute{iline} ';'])
2834                if ischar(val);
2835                    Tabcell{iline,2}=val;
2836                else
2837                    Tabcell{iline,2}=num2str(val);
2838                end
2839            end
2840        end
2841        if ~isempty(Tabcell)
2842            Tabchar=cell2tab(Tabcell,'=');
2843            Tabchar=[{''};Tabchar];
2844        end
2845    end
2846    set(hhget_field_1.attributes,'String',Tabchar);%update list of global attributes in get_field
2847end
2848
2849
2850
2851%-------------------------------------------------------------------
2852% --- translate coordinate to matrix index
2853%-------------------------------------------------------------------
2854function [indx,indy]=pos2ind(x0,rangx0,nxy)
2855indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2856indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2857
2858%-------------------------------------------------------------------
2859% --- Executes on button press in 'FixedLimits'.
2860%-------------------------------------------------------------------
2861function FixedLimits_Callback(hObject, eventdata, handles)
2862test=get(handles.FixedLimits,'Value');
2863if test
2864    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2865else
2866    set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
2867    update_plot(handles);
2868end
2869
2870%-------------------------------------------------------------------
2871% --- Executes on button press in auto_xy.
2872function auto_xy_Callback(hObject, eventdata, handles)
2873test=get(handles.auto_xy,'Value');
2874if test
2875    set(handles.auto_xy,'BackgroundColor',[1 1 0])
2876    cla(handles.axes3)
2877    update_plot(handles);
2878else
2879    set(handles.auto_xy,'BackgroundColor',[0.7 0.7 0.7])
2880    update_plot(handles);
2881%     axis(handles.axes3,'image')
2882end
2883
2884
2885%-------------------------------------------------------------------
2886
2887%-------------------------------------------------------------------
2888% --- Executes on button press in 'zoom'.
2889%-------------------------------------------------------------------
2890function zoom_Callback(hObject, eventdata, handles)
2891
2892if (get(handles.zoom,'Value') == 1);
2893    set(handles.zoom,'BackgroundColor',[1 1 0])
2894    set(handles.FixedLimits,'Value',1)% propose by default fixed limits for the plotting axes
2895    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2896else
2897    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
2898end
2899
2900
2901%-------------------------------------------------------------------
2902%----Executes on button press in 'record': records the current flags of manual correction.
2903%-------------------------------------------------------------------
2904function record_Callback(hObject, eventdata, handles)
2905% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2906filename=read_file_boxes(handles);
2907AxeData=get(gca,'UserData');
2908[erread,message]=fileattrib(filename);
2909if ~isempty(message) && ~isequal(message.UserWrite,1)
2910     msgbox_uvmat('ERROR',['no writting access to ' filename])
2911     return
2912end
2913test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
2914test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
2915if ~test_civ2 && ~test_civ1
2916    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2917end
2918if test_civ2
2919    nbname='nb_vectors2';
2920   flagname='vec2_FixFlag';
2921   attrname='fix2';
2922end
2923if test_civ1
2924    nbname='nb_vectors';
2925   flagname='vec_FixFlag';
2926   attrname='fix';
2927end
2928%write fix flags in the netcdf file
2929hhh=which('netcdf.open');% look for built-in matlab netcdf library
2930if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
2931    nc=netcdf.open(filename,'NC_WRITE');
2932    netcdf.reDef(nc)
2933    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1)
2934    dimid = netcdf.inqDimID(nc,nbname);
2935    try
2936        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2937    catch
2938        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2939    end
2940    netcdf.endDef(nc)
2941    netcdf.putVar(nc,varid,AxeData.FF);
2942    netcdf.close(nc) 
2943else %old netcdf library
2944    netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2945end
2946
2947function netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2948nc=netcdf(filename,'write'); %open netcdf file
2949result=redef(nc);
2950eval(['nc.' attrname '=1;']);
2951theDim=nc(nbname) ;% get the number of velocity vectors
2952nb_vectors=size(theDim);
2953var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2954var_FixFlag(1:nb_vectors)=AxeData.FF;%
2955fin=close(nc);
2956
2957
2958%-------------------------------------------------------------------
2959%determines the fields to read from the interface
2960%------------------------------------------------------------------
2961function [VelType,civ]=setfield(handles)
2962
2963VelType=[]; %default
2964if (get(handles.civ1,'Value') == 1);
2965        VelType='civ1';
2966% interp1   
2967elseif (get(handles.interp1,'Value') == 1);
2968    VelType='interp1';
2969% filter1   
2970elseif (get(handles.filter1,'Value') == 1);
2971    VelType='filter1'; 
2972% CIV2
2973elseif (get(handles.civ2,'Value') == 1);
2974    VelType='civ2';
2975% interp2   
2976elseif (get(handles.interp2,'Value') == 1);
2977    VelType='interp2';
2978% filter2   
2979elseif (get(handles.filter2,'Value') == 1); 
2980    VelType='filter2';
2981end
2982
2983if isequal(get(handles.filter2,'Visible'),'on');
2984    civ=6;
2985% interp1   
2986elseif isequal(get(handles.interp2,'Visible'),'on');
2987    civ=5;
2988% filter1   
2989elseif isequal(get(handles.civ2,'Visible'),'on');
2990    civ=4; 
2991% CIV2
2992elseif isequal(get(handles.filter1,'Visible'),'on');
2993   civ=3;
2994% interp2   
2995elseif isequal(get(handles.interp1,'Visible'),'on');
2996    civ=2;
2997% filter2   
2998elseif isequal(get(handles.civ1,'Visible'),'on'); 
2999    civ=1;
3000else
3001    civ=0;
3002end
3003
3004%-------------------------------------------------------------------
3005%determines the veltype of the second field to read from the iinterface
3006%------------------------------------------------------------------
3007function VelType=setfield_1(handles)
3008
3009VelType=[]; %default
3010if (get(handles.civ1_1,'Value') == 1);
3011    VelType='civ1';
3012% interp1   
3013elseif (get(handles.interp1_1,'Value') == 1);
3014    VelType='interp1';
3015% filter1   
3016elseif (get(handles.filter1_1,'Value') == 1);
3017    VelType='filter1'; 
3018% CIV2
3019elseif (get(handles.civ2_1,'Value') == 1);
3020    VelType='civ2';
3021% interp2   
3022elseif (get(handles.interp2_1,'Value') == 1);
3023    VelType='interp2';
3024% filter2   
3025elseif (get(handles.filter2_1,'Value') == 1); 
3026    VelType='filter2';
3027end
3028
3029
3030%---------------------------------------------------
3031% --- Executes on button press in SubField
3032function SubField_Callback(hObject, eventdata, handles)
3033huvmat=get(handles.run0,'parent');
3034UvData=get(huvmat,'UserData');
3035if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
3036    set(handles.RootPath_1,'String','')
3037    set(handles.RootFile_1,'String','')
3038    set(handles.SubDir_1,'String','');
3039    set(handles.FileIndex_1,'String','');
3040    set(handles.FileExt_1,'String','');
3041    set(handles.RootPath_1,'Visible','off')
3042    set(handles.RootFile_1,'Visible','off')
3043    set(handles.SubDir_1,'Visible','off');
3044    set(handles.FileIndex_1,'Visible','off');
3045    set(handles.FileExt_1,'Visible','off');
3046    set(handles.Fields_1,'Value',1);%set to blank state
3047    set_veltype_display([handles.civ1_1 handles.interp1_1 handles.filter1_1 ...
3048            handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
3049    if isfield(UvData,'XmlData_1')
3050        UvData=rmfield(UvData,'XmlData_1');
3051    end
3052    set(huvmat,'UserData',UvData);
3053    run0_Callback(hObject, eventdata, handles); %run
3054else
3055    MenuBrowse_1_Callback(hObject, eventdata, handles)
3056end
3057
3058%------------------------------------------------------------------------
3059% --- read the data displayed for the input rootfile windows (new)
3060function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
3061%------------------------------------------------------------------------
3062RootPath=get(handles.RootPath,'String');
3063FileName=RootPath; %default
3064SubDir=get(handles.SubDir,'String');
3065if ~isempty(SubDir) && ~isequal(SubDir,'')
3066    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
3067        SubDir(1)=[]; %suppress possible / or \ separator
3068    end
3069    FileName=fullfile(RootPath,SubDir);
3070end
3071RootFile=get(handles.RootFile,'String');
3072if ~isempty(RootFile) && ~isequal(RootFile,'')
3073    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3074        RootFile(1)=[]; %suppress possible / or \ separator
3075    end
3076    FileName=fullfile(FileName,RootFile);
3077end
3078FileBase=fullfile(RootPath,RootFile);
3079FileIndices=get(handles.FileIndex,'String');
3080FileExt=get(handles.FileExt,'String');
3081FileName=[FileName FileIndices FileExt];
3082
3083%------------------------------------------------------------------------
3084% ---- read the data displayed for the second input rootfile windows
3085function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
3086%------------------------------------------------------------------------
3087RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
3088if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
3089    RootPath_1=get(handles.RootPath,'String');
3090end;
3091FileName_1=RootPath_1; %default
3092SubDir_1=get(handles.SubDir_1,'String');
3093if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
3094    SubDir_1=get(handles.SubDir,'String');
3095end
3096if numel(SubDir_1)>=1
3097    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
3098        SubDir_1(1)=[]; %suppress possible / or \ separator
3099    end
3100    FileName_1=fullfile(RootPath_1,SubDir_1);
3101end
3102RootFile_1=get(handles.RootFile_1,'String');
3103if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
3104    RootFile_1=get(handles.RootFile,'String');
3105end
3106if numel(RootFile_1)>=1
3107    if ~(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3108        RootFile_1(1)=[];%suppress possible / or \ separator
3109    end
3110    FileName_1=fullfile(FileName_1,RootFile_1);
3111end
3112FileBase_1=fullfile(RootPath_1,RootFile_1);
3113if isequal(get(handles.FileIndex_1,'Visible'),'off')
3114    FileIndices_1=get(handles.FileIndex,'String');
3115else
3116    FileIndices_1=get(handles.FileIndex_1,'String');
3117end
3118FileExt_1=get(handles.FileExt_1,'String');
3119if isequal(FileExt_1,'"'),FileExt_1=get(handles.FileExt,'String'); end;
3120FileName_1=[FileName_1 FileIndices_1 FileExt_1];
3121
3122%------------------------------------------------------------------------
3123% --- Executes on menu selection Fields
3124function Fields_Callback(hObject, eventdata, handles)
3125%------------------------------------------------------------------------
3126list_fields=get(handles.Fields,'String');% list menu fields
3127index_fields=get(handles.Fields,'Value');% selected string index
3128field= list_fields{index_fields(1)}; % selected string
3129if isequal(field,'get_field...')
3130     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3131     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3132     filename=read_file_boxes(handles);
3133     hget_field=findobj(allchild(0),'name','uvmat_field');
3134     if isempty(hget_field)
3135         hget_field=get_field(filename);
3136         set(hget_field,'Name','uvmat_field')       
3137     end
3138    return %no action
3139end
3140list_fields=get(handles.Fields_1,'String');% list menu fields
3141index_fields=get(handles.Fields_1,'Value');% selected string index
3142field_1= list_fields{index_fields(1)}; % selected string
3143UvData=get(handles.uvmat,'UserData');
3144
3145%read the rootfile input display
3146[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
3147[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
3148NomTypeNew=NomType;%default
3149if isequal(field,'image')
3150    % transform netc type to the corresponding image type
3151%     if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
3152%         UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
3153%         if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')||isequal(UvData.SubDir(1),'/'))
3154%             UvData.SubDir(1)=[];
3155%         end
3156%         set(handles.SubDir,'String','')
3157%         set(handles.FileExt,'String','.png');
3158        if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
3159            NomTypeNew='_i_j';
3160        elseif isequal(NomType,'#_ab')
3161            NomTypeNew='#a';
3162        elseif isequal(NomType,'_i1-i2')
3163            NomTypeNew='_i';
3164        end 
3165        imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3166        if ~exist(imagename,'file')
3167                [FileName,PathName] = uigetfile( ...
3168           {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3169            '*.jpg',' jpeg image files'; ...
3170            '*.png','.png image files'; ...
3171            '*.tif','.tif image files'; ...
3172            '*.avi;*.AVI','.avi movie files'; ...
3173            '*.vol','.volume images (png)'; ...
3174            '*.*',  'All Files (*.*)'}, ...
3175            'Pick an image',imagename);           
3176            % display the selected field and related information
3177           imagename=[PathName FileName];
3178        end
3179        display_file_name(hObject, eventdata, handles,imagename)%display the image
3180        return
3181%     end
3182%     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3183%     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3184else
3185    ext=get(handles.FileExt,'String');
3186    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
3187                [FileName,PathName] = uigetfile( ...
3188           {'*.nc', ' (*.nc)';
3189            '*.nc',' netcdf files'; ...
3190            '*.*',  'All Files (*.*)'}, ...
3191            'Pick a netcdf file',FileBase);           
3192            % display the selected field and related information
3193           filename=[PathName FileName];
3194        display_file_name(hObject, eventdata, handles,filename)
3195        return
3196       %  MenuBrowse_Callback(hObject, eventdata, handles)
3197    end
3198    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
3199        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3200        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3201        set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
3202        set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
3203    elseif isequal(field,'more...');
3204        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3205        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3206        str=calc_field;%get the list of available scalars by the function calc_scal
3207        [ind_answer] = listdlg('PromptString','Select a file:',...
3208                'SelectionMode','single',...
3209                'ListString',str);
3210       % edit the choice in the field and action menu
3211        scalar=cell2mat(str(ind_answer));
3212        menu=update_menu(handles.Fields,scalar);
3213        menu=[{''};menu];
3214        set(handles.Fields_1,'String',menu);% store the selected scalar type
3215    end
3216end
3217indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3218set(handles.FileIndex,'String',indices)
3219set(handles.FileIndex,'UserData',NomTypeNew)
3220%common to Fields_1_Callback
3221if isequal(field,'image')||isequal(field_1,'image')
3222    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3223    set(handles.npy_title,'Visible','on')
3224    set(handles.npx,'Visible','on')
3225    set(handles.npy,'Visible','on')
3226else
3227    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3228    set(handles.npy_title,'Visible','off')
3229    set(handles.npx,'Visible','off')
3230    set(handles.npy,'Visible','off')
3231end
3232setfield(handles);% update the field structure ('civ1'....)
3233
3234if ~isfield(UvData,'NewSeries')||isequal(UvData.NewSeries,0)
3235    run0_Callback(hObject, eventdata, handles)
3236end
3237
3238%---------------------------------------------------
3239% --- Executes on menu selection Fields
3240function Fields_1_Callback(hObject, eventdata, handles)
3241%-------------------------------------------------
3242list_fields=get(handles.Fields,'String');% list menu fields
3243index_fields=get(handles.Fields,'Value');% selected string index
3244field= list_fields{index_fields(1)}; % selected string
3245list_fields=get(handles.Fields_1,'String');% list menu fields
3246index_fields=get(handles.Fields_1,'Value');% selected string index
3247field_1= list_fields{index_fields(1)}; % selected string for the second field
3248if isequal(field_1,'') %remove second field if 'blank' field is selected
3249    set(handles.SubField,'Value',0)
3250    SubField_Callback(hObject, eventdata, handles)
3251    return
3252end
3253UvData=get(handles.uvmat,'UserData');
3254
3255%read the rootfile input display
3256[FileName,RootPath,FileBase,FileIndices,FileExt_prev]=read_file_boxes_1(handles);
3257[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_prev]);
3258if isempty(FileExt_prev)|isequal(FileExt_prev,'')
3259    FileExt_1=get(handles.FileExt,'String');
3260else
3261    FileExt_1=FileExt_prev;
3262end
3263NomType_1=get(handles.FileIndex_1,'UserData');
3264if isempty(NomType_1)|isequal(NomType_1,'')
3265    NomType_1=get(handles.FileIndex,'UserData');
3266end
3267NomTypeNew=NomType_1;%default
3268
3269set(handles.SubField,'Value',1)%introduce second field
3270if isfield(UvData,'XmlData')
3271    UvData.XmlData_1=UvData.XmlData;
3272end
3273set(handles.FileIndex_1,'Visible','on')
3274set(handles.FileExt_1,'Visible','on')
3275RootPath_1=get(handles.RootPath_1,'String');
3276RootFile_1=get(handles.RootFile_1,'String');
3277if isempty(RootPath_1)||isequal(RootPath_1,'')
3278    set(handles.RootPath_1,'String','"')
3279end
3280if isempty(RootFile_1) || isequal(RootFile_1,'')
3281    set(handles.RootFile_1,'String','"')
3282end
3283if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
3284    RootFile_1(1)=[];
3285end
3286
3287if isequal(field_1,'get_field...')
3288     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3289     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3290     filename=read_file_boxes_1(handles);
3291     hget_field=findobj(allchild(0),'name','get_field_1');
3292     if ~isempty(hget_field)
3293         delete(hget_field)
3294     end
3295     hget_field=get_field(filename);
3296     set(hget_field,'name','get_field_1')
3297    return %no action
3298end
3299if isequal(field_1,'image')
3300    % transform netc type to the corresponding image type
3301%     set(handles.FileExt_1,'String','.png');
3302    if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')
3303        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
3304%         set(handles.SubDir_1,'String','')
3305%         set(handles.FileExt_1,'String','.png');       
3306        if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')
3307            NomTypeNew='_i_j';
3308        elseif isequal(NomType_1,'#_ab')
3309            NomTypeNew='#a';
3310        elseif isequal(NomType_1,'_i1-i2')
3311            NomTypeNew='_i';
3312        end 
3313    end
3314    imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3315    if ~exist(imagename,'file')
3316        [FileName,PathName] = uigetfile( ...
3317            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3318            '*.jpg',' jpeg image files'; ...
3319            '*.png','.png image files'; ...
3320            '*.tif','.tif image files'; ...
3321            '*.avi;*.AVI','.avi movie files'; ...
3322            '*.vol','.volume images (png)'; ...
3323            '*.*',  'All Files (*.*)'}, ...
3324            'Pick an image',imagename);
3325        % display the selected field and related information
3326        imagename=[PathName FileName];
3327    end
3328    display_file_name_1(hObject, eventdata, handles,imagename)%display the image
3329    return
3330%     veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3331%     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3332else
3333    set(handles.SubDir_1,'Visible','on')
3334    if ~isequal(FileExt_prev,'.nc') %find the new NomType if the previous display was not already a netcdf file
3335        veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3336        set_veltype_display(veltype_handles,6); % make all civ buttons visible
3337        RootPath_1=get(handles.RootPath_1,'String');
3338        RootFile_1=get(handles.RootFile_1,'String');
3339        if isempty(RootPath_1)|isequal(RootPath_1,'')
3340            set(handles.RootPath_1,'String','"')
3341        end
3342        if isempty(RootFile_1) | isequal(RootFile_1,'')
3343            set(handles.RootFile_1,'String','"')
3344        end
3345        if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3346            RootFile_1(1)=[];
3347        end
3348        filebase_1=fullfile(RootPath_1,RootFile_1);
3349        SubDir_1=get(handles.SubDir,'String');
3350        if isempty(SubDir_1)||isequal(SubDir_1,'')
3351            if isfield(UvData,'SubDir_1')
3352                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3353            else
3354                SubDir_1='?';
3355            end
3356        end
3357        str1=get(handles.i1,'String');
3358        str_a=get(handles.j1,'String');
3359        if isequal(NomType_1,'#_ab')||isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')||isequal(NomType_1,'_i1-i2')
3360            NomTypeNew=NomType_1;
3361        elseif isequal(NomType_1,'#a')
3362             [filename, n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),stra2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3363             NomTypeNew='#_ab';
3364        elseif isequal(NomType_1,'_i_j')
3365             [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);
3366            if idetect==1
3367                NomTypeNew='_i1-i2_j';
3368            else
3369                NomTypeNew='_i_j1-j2';
3370            end
3371        else %for instance avi files or any ima_num series
3372            [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
3373            NomTypeNew='_i1-i2';
3374        end           
3375        [Path,Name]=fileparts(filebase_1);
3376        set(handles.FileExt_1,'String','.nc');
3377        if ~isempty(SubDir_1) && ~strcmp(SubDir_1,'''')&& ~strcmp(SubDir_1,'"')&& ~strcmp(SubDir_1(1),'/')
3378            SubDir_1=['/' SubDir_1];
3379        end
3380        set(handles.SubDir_1,'String',SubDir_1);
3381    end
3382    if isequal(field,'vort') | isequal(field,'div') | isequal(field,'strain')
3383        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3384        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3385        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3386        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3387    elseif isequal(field_1,'more...'); %add new item to the menu
3388        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3389        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3390        str=calc_field;%get the list of available scalars by the function calc_scal
3391        [ind_answer,v] = listdlg('PromptString','Select a file:',...
3392                'SelectionMode','single',...
3393                'ListString',str);
3394       % edit the choice in the field and action menu
3395        scalar=cell2mat(str(ind_answer));
3396        menu=update_menu(handles.Fields_1,scalar);
3397        set(handles.Fields_1,'String',menu);% store the selected scalar type
3398    end
3399end
3400str1=get(handles.i1,'String');
3401str2=get(handles.i2,'String');
3402str_a=get(handles.j1,'String');
3403str_b=get(handles.j2,'String');
3404indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3405set(handles.FileIndex_1,'String',indices)
3406set(handles.FileIndex_1,'UserData',NomTypeNew)
3407
3408%common to Fields_Callback
3409if isequal(field,'image')|isequal(field_1,'image')
3410    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3411    set(handles.npy_title,'Visible','on')
3412    set(handles.npx,'Visible','on')
3413    set(handles.npy,'Visible','on')
3414%     set(handles.fix_pair,'Value',0)
3415else
3416    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3417    set(handles.npy_title,'Visible','off')
3418    set(handles.npx,'Visible','off')
3419    set(handles.npy,'Visible','off')
3420%     set(handles.fix_pair,'Value',1)
3421end
3422if isequal(field,'velocity')|isequal(field_1,'velocity');
3423    state_vect='on';
3424else
3425    state_vect='off';
3426end
3427if ~isequal(field,'velocity')|(~isequal(field_1,'velocity')&~isequal(field_1,''));
3428    state_scal='on';
3429else
3430    state_scal='off';
3431end
3432set(handles.uvmat,'UserData',UvData)
3433setfield(handles);% update the field structure ('civ1'....)
3434if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
3435    run0_Callback(hObject, eventdata, handles)
3436end
3437
3438%------------------------------------------------------------------------
3439% --- set the visibility of relevant velocity type menus:
3440function set_veltype_display(handles,Civ)
3441%------------------------------------------------------------------------
3442%Civ=0; all states 'off'
3443%Civ=6; all states 'on'
3444if isequal(Civ,0)
3445    imax=0;
3446%    set(handles(1),'Visible','on')  % unvisible civ buttons
3447% else
3448%    set(handles(1),'String','civ1')
3449% end
3450elseif isequal(Civ,1) || isequal(Civ,2)
3451   imax=1;
3452elseif isequal(Civ,3)
3453    imax=3;
3454elseif isequal(Civ,4) || isequal(Civ,5)
3455    imax=4;
3456elseif isequal(Civ,6) %patch2
3457    imax=6;
3458end
3459for ibutton=1:imax;
3460    set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3461end
3462% for ibutton=max(imax+1,2):6;
3463for ibutton=imax+1:6;
3464    set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3465    set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3466end
3467
3468%-------------------------------------------------------------------
3469% --- Executes on button press in civ1.
3470function civ1_Callback(hObject, eventdata, handles)
3471%-------------------------------------------------------------------
3472if get(handles.civ1,'Value')==1
3473    reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ1)
3474else
3475    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3476end
3477run0_Callback(hObject, eventdata, handles)
3478
3479%-------------------------------------------------------------------
3480% --- Executes on button press in interp1.
3481function interp1_Callback(hObject, eventdata, handles)
3482%-------------------------------------------------------------------
3483if get(handles.interp1,'Value')==1
3484    reset_vel_type([handles.civ1 handles.civ2 handles.filter1 handles.interp2 handles.filter2],handles.interp1)
3485else
3486     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3487end
3488run0_Callback(hObject, eventdata, handles)
3489
3490%-------------------------------------------------------------------
3491% --- Executes on button press in filter1.
3492function filter1_Callback(hObject, eventdata, handles)
3493%-------------------------------------------------------------------
3494if get(handles.filter1,'Value')==1
3495    reset_vel_type([handles.civ1 handles.civ2 handles.interp1 handles.interp2 handles.filter2],handles.filter1)
3496else
3497     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3498end
3499run0_Callback(hObject, eventdata, handles)
3500
3501%-------------------------------------------------------------------
3502% --- Executes on button press in civ2.
3503function civ2_Callback(hObject, eventdata, handles)
3504%-------------------------------------------------------------------
3505if get(handles.civ2,'Value')==1
3506    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ2)
3507else
3508     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3509end
3510run0_Callback(hObject, eventdata, handles)
3511
3512%-----------------------------------------
3513% --- Executes on button press in interp2.
3514%-------------------------------------------
3515function interp2_Callback(hObject, eventdata, handles)
3516if get(handles.interp2,'Value')==1
3517    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.filter2],handles.interp2)
3518else
3519     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3520end
3521run0_Callback(hObject, eventdata, handles)
3522%---------------------------------------------
3523% --- Executes on button press in filter2.
3524%-------------------------------------------
3525function filter2_Callback(hObject, eventdata, handles)
3526if get(handles.filter2,'Value')==1
3527    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2],handles.filter2)
3528else
3529     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3530end
3531run0_Callback(hObject, eventdata, handles)
3532
3533%---------------------------------------------
3534function civ1_1_Callback(hObject, eventdata, handles)
3535%---------------------------------------------
3536if get(handles.civ1_1,'Value')==1
3537    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.civ1_1)
3538else
3539     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3540end
3541run0_Callback(hObject, eventdata, handles)
3542
3543%--------------------------------------------
3544function interp1_1_Callback(hObject, eventdata, handles)
3545%--------------------------------------------
3546if get(handles.interp1_1,'Value')==1
3547    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.interp1_1)
3548else
3549    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3550end
3551run0_Callback(hObject, eventdata, handles)
3552
3553%--------------------------------------------
3554function filter1_1_Callback(hObject, eventdata, handles)
3555%--------------------------------------------
3556if get(handles.filter1_1,'Value')==1
3557    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.filter1_1)
3558else
3559    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3560end
3561run0_Callback(hObject, eventdata, handles)
3562
3563%--------------------------------------------
3564function civ2_1_Callback(hObject, eventdata, handles)
3565%--------------------------------------------
3566if get(handles.civ2_1,'Value')==1
3567    reset_vel_type([handles.civ1_1 handles.interp1_1  handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.civ2_1)
3568else
3569    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3570end
3571run0_Callback(hObject, eventdata, handles)
3572
3573%--------------------------------------------
3574function interp2_1_Callback(hObject, eventdata, handles)
3575%--------------------------------------------
3576if get(handles.interp2_1,'Value')==1
3577    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.filter2_1],handles.interp2_1)
3578else
3579    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3580end
3581run0_Callback(hObject, eventdata, handles)
3582
3583%--------------------------------------------
3584function filter2_1_Callback(hObject, eventdata, handles)
3585%--------------------------------------------
3586if get(handles.filter2_1,'Value')==1
3587    reset_vel_type([handles.civ1_1 handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1],handles.filter2_1)
3588else
3589    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3590end
3591run0_Callback(hObject, eventdata, handles)
3592
3593%-----------------------------------------------
3594% --- reset civ buttons
3595function reset_vel_type(handles_civ0,handle1)
3596for ibutton=1:length(handles_civ0)
3597    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3598    set(handles_civ0(ibutton),'Value',0)
3599end
3600if exist('handle1','var')%handles of selected button
3601        set(handle1,'BackgroundColor',[1 1 0]) 
3602end
3603
3604%-------------------------------------------------------
3605% --- Executes on button press in MENUVOLUME.
3606%-------------------------------------------------------
3607function VOLUME_Callback(hObject, eventdata, handles)
3608%errordlg('command VOL not implemented yet')
3609if ishandle(handles.UVMAT_title)
3610    delete(handles.UVMAT_title)
3611end
3612UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3613if isequal(get(handles.VOLUME,'Value'),1)
3614    set(handles.zoom,'Value',0)
3615    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3616    set(handles.edit_vect,'Value',0)
3617    edit_vect_Callback(hObject, eventdata, handles)
3618    set(handles.edit,'Value',0)
3619    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3620%     set(handles.cal,'Value',0)
3621%     set(handles.cal,'BackgroundColor',[0 1 0])
3622    set(handles.edit_vect,'Value',0)
3623    edit_vect_Callback(hObject, eventdata, handles)
3624    %initiate set_object GUI
3625    data.TITLE='VOLUME';
3626    if isfield(UvData,'CoordType')
3627        data.CoordType=UvData.CoordType;
3628    end
3629    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3630        data.RangeY=UvData.Mesh;
3631        data.RangeX=UvData.Mesh;
3632        data.DX=UvData.Mesh;
3633        data.DY=UvData.Mesh;
3634    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3635        np=size(UvData.Field.A);
3636        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3637        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3638        data.RangeY=max(meshx,meshy);
3639        data.RangeX=max(meshx,meshy);
3640        data.DX=max(meshx,meshy);
3641    end
3642    data.ParentButton=handles.VOLUME;
3643    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3644    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3645                                                      % associate the set_edit interface handle to the plotting axes
3646    if isfield(UvData,'SetObjectOrigin')                                               
3647    pos_uvmat=get(huvmat,'Position');
3648    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3649    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3650    set(hset_object,'Position',pos_set_object)
3651    end
3652    UvData.MouseAction='create_object';
3653else
3654    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3655    UvData.MouseAction='none';
3656end
3657set(huvmat,'UserData',UvData)
3658
3659%-------------------------------------------------------
3660function edit_vect_Callback(hObject, eventdata, handles)
3661%-------------------------------------------------------
3662
3663UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3664if isequal(get(handles.edit_vect,'Value'),1)
3665    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
3666    test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
3667    if ~test_civ2 && ~test_civ1
3668        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3669    end
3670    set(handles.record,'Visible','on')
3671    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3672    set(handles.edit,'Value',0)
3673    set(handles.zoom,'Value',0)
3674    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3675%     set(handles.create,'Value',0)
3676%     set(handles.create,'BackgroundColor',[0 1 0])
3677    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3678    set(gcf,'Pointer','arrow')
3679    UvData.MouseAction='edit_vect';
3680else
3681    set(handles.record,'Visible','off')
3682    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3683    UvData.MouseAction='none';
3684end
3685set(handles.uvmat,'UserData',UvData)
3686
3687%----------------------------------------------
3688function save_mask_Callback(hObject, eventdata, handles)
3689%-----------------------------------------------------------------------
3690UvData=get(handles.uvmat,'UserData');
3691
3692flag=1;
3693npx=size(UvData.Field.A,2);
3694npy=size(UvData.Field.A,1);
3695xi=[0.5:npx-0.5];
3696yi=[0.5:npy-0.5];
3697[Xi,Yi]=meshgrid(xi,yi);
3698if isfield(UvData,'Object')
3699    for iobj=1:length(UvData.Object)
3700        ObjectData=UvData.Object{iobj};
3701        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3702            flagobj=1;
3703            testphys=0; %coordinates in pixels by default
3704            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3705                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3706                    Calib=UvData.XmlData.GeometryCalib;
3707                    testphys=1;
3708                end
3709            end
3710            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3711                if isequal(ObjectData.Style,'polygon')
3712                    X=ObjectData.Coord(:,1);
3713                    Y=ObjectData.Coord(:,2);
3714                    if testphys
3715                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3716                    end
3717                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
3718                elseif isequal(ObjectData.Style,'ellipse')
3719                    if testphys
3720                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3721                    end
3722                    RangeX=max(ObjectData.RangeX);
3723                    RangeY=max(ObjectData.RangeY);
3724                    X2Max=RangeX*RangeX;
3725                    Y2Max=RangeY*RangeY;
3726                    distX=(Xi-ObjectData.Coord(1,1));
3727                    distY=(Yi-ObjectData.Coord(1,2));
3728                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3729                elseif isequal(ObjectData.Style,'rectangle')
3730                    if testphys
3731                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3732                    end
3733                    distX=abs(Xi-ObjectData.Coord(1,1));
3734                    distY=abs(Yi-ObjectData.Coord(1,2));
3735                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3736                end
3737                if isequal(ObjectData.ProjMode,'mask_outside')
3738                    flagobj=~flagobj;
3739                end
3740                flag=flag & flagobj;
3741            end
3742        end
3743    end
3744end
3745% flag=~flag;
3746%mask name
3747RootPath=get(handles.RootPath,'String');
3748RootFile=get(handles.RootFile,'String');
3749if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
3750        RootFile(1)=[];
3751end
3752filebase=fullfile(RootPath,RootFile);
3753list=get(handles.masklevel,'String');
3754masknumber=num2str(length(list));
3755maskindex=get(handles.masklevel,'Value');
3756mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3757imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3758imflag=flipdim(imflag,1);
3759% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3760msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3761imwrite(imflag,mask_name,'BitDepth',8);
3762
3763%display the mask
3764%update_mask(handles,num_i1,num_j1)
3765figure;
3766vec=linspace(0,1,256);%define a linear greyscale colormap
3767map=[vec' vec' vec'];
3768colormap(map)
3769
3770image(imflag);
3771
3772%-------------------------------------------------------------------
3773%-------------------------------------------------------------------
3774%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3775
3776%------------------------------------------------------------------
3777
3778
3779
3780%------------------------------------------------------------------
3781% --- Executes on selection change in col_vec: choice of the color code.
3782%
3783function col_vec_Callback(hObject, eventdata, handles)
3784%------------------------------------------------------------------
3785% edit the choice for color code
3786list_code=get(handles.col_vec,'String');% list menu fields
3787index_code=get(handles.col_vec,'Value');% selected string index
3788col_code= list_code{index_code(1)}; % selected field
3789if isequal(col_code,'black') | isequal(col_code,'white')
3790   set(handles.slider1,'Visible','off')
3791   set(handles.slider2,'Visible','off')
3792   set(handles.colcode1,'Visible','off')
3793   set(handles.colcode2,'Visible','off')
3794   set(handles.AutoVecColor,'Visible','off')
3795   set_vec_col_bar(handles)
3796else
3797   set(handles.slider1,'Visible','on')
3798   set(handles.slider2,'Visible','on')
3799   set(handles.colcode1,'Visible','on')
3800   set(handles.colcode2,'Visible','on')
3801   set(handles.AutoVecColor,'Visible','on') 
3802   if isequal(col_code,'ima_cor')
3803       set(handles.AutoVecColor,'Value',0)%fixed scale by default
3804       set(handles.vec_col_bar,'Value',0)% 3 colors r,g,b by default
3805       set(handles.slider1,'Min',0);
3806       set(handles.slider1,'Max',1);
3807       set(handles.slider2,'Min',0);
3808       set(handles.slider2,'Max',1);
3809 %      set(handles.min_title_vec,'String','0')
3810       set(handles.max_vec,'String','1')
3811       set(handles.colcode1,'String','0.333')
3812       colcode1_Callback(hObject, eventdata, handles)
3813       set(handles.colcode2,'String','0.666')
3814       colcode2_Callback(hObject, eventdata, handles)
3815   else
3816       set(handles.AutoVecColor,'Value',1)%auto scale between min,max by default
3817       set(handles.vec_col_bar,'Value',1)% colormap 'jet' by default
3818       minval=get(handles.slider1,'Min');
3819       maxval=get(handles.slider1,'Max');
3820       set(handles.slider1,'Value',minval)
3821       set(handles.slider2,'Value',maxval)
3822       set_vec_col_bar(handles)
3823   end
3824%    slider_update(handles)
3825end
3826%replot the current graph
3827run0_Callback(hObject, eventdata, handles)
3828
3829
3830%----------------------------------------------------------------
3831% -- Executes on slider movement to set the color code
3832%
3833function slider1_Callback(hObject, eventdata, handles)
3834%------------------------------------------------------------------
3835slider1=get(handles.slider1,'Value');
3836min_val=str2num(get(handles.min_vec,'String'));
3837max_val=str2num(get(handles.max_vec,'String'));
3838col=min_val+(max_val-min_val)*slider1;
3839set(handles.colcode1,'String',num2str(col))
3840if(get(handles.slider2,'Value') < col)%move also the second slider at the same value if needed
3841    set(handles.slider2,'Value',col)
3842    set(handles.colcode2,'String',num2str(col))
3843end
3844colcode1_Callback(hObject, eventdata, handles)
3845
3846%----------------------------------------------------------------
3847% Executes on slider movement to set the color code
3848%----------------------------------------------------------------
3849function slider2_Callback(hObject, eventdata, handles)
3850slider2=get(handles.slider2,'Value');
3851min_val=str2num(get(handles.min_vec,'String'));
3852max_val=str2num(get(handles.max_vec,'String'));
3853col=min_val+(max_val-min_val)*slider2;
3854set(handles.colcode2,'String',num2str(col))
3855if(get(handles.slider1,'Value') > col)%move also the first slider at the same value if needed
3856    set(handles.slider1,'Value',col)
3857    set(handles.colcode1,'String',num2str(col))
3858end
3859colcode2_Callback(hObject, eventdata, handles)
3860
3861%----------------------------------------------------------------
3862%execute on return carriage on the edit box corresponding to slider 1
3863%----------------------------------------------------------------
3864function colcode1_Callback(hObject, eventdata, handles)
3865% col=str2num(get(handles.colcode1,'String'));
3866% set(handles.slider1,'Value',col)
3867set_vec_col_bar(handles)
3868update_plot(handles);
3869
3870%----------------------------------------------------------------
3871%execute on return carriage on the edit box corresponding to slider 2
3872%----------------------------------------------------------------
3873function colcode2_Callback(hObject, eventdata, handles)
3874% col=str2num(get(handles.colcode2,'String'));
3875% set(handles.slider2,'Value',col)
3876% slider2_Callback(hObject, eventdata, handles)
3877set_vec_col_bar(handles)
3878update_plot(handles);
3879%------------------------------------------------------------
3880%update the slider values after displaying vectors
3881%--------------------------------------------------------
3882% function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
3883% set(handles.slider1,'Min',minC)
3884% set(handles.slider1,'Max',maxC)
3885% set(handles.slider2,'Min',minC)
3886% set(handles.slider2,'Max',maxC)
3887% set(handles.min_title_vec,'String',num2str(minC))
3888% set(handles.max_vec,'String',num2str(maxC))
3889% if auto
3890%         set(handles.colcode1,'String',num2str(colcode1,3))%update display
3891%         set(handles.colcode2,'String',num2str(colcode2,3))
3892% end
3893% set(handles.slider1,'Value',colcode1)%update slider with constant display
3894% set(handles.slider2,'Value',colcode2)
3895% set_vec_col_bar(handles)
3896
3897
3898%-------------------------------------------------------
3899% --- Executes on button press in AutoVecColor.
3900%-------------------------------------------------------
3901function vec_col_bar_Callback(hObject, eventdata, handles)
3902set_vec_col_bar(handles)
3903
3904%-------------------------------------------------------------
3905% --- Executes on selection change in transform_fct.
3906function transform_fct_Callback(hObject, eventdata, handles)
3907%-------------------------------------------------------------
3908global nb_builtin
3909
3910huvmat=get(handles.transform_fct,'parent');
3911menu=get(handles.transform_fct,'String');
3912ind_coord=get(handles.transform_fct,'Value');
3913coord_option=menu{ind_coord};
3914list_transform=get(handles.transform_fct,'UserData');
3915ff=functions(list_transform{end}); 
3916if isequal(coord_option,'more...');
3917    coord_fct='';
3918    prompt = {'Enter the name of the transform function'};
3919    dlg_title = 'user defined transform';
3920    num_lines= 1;
3921    [FileName, PathName] = uigetfile( ...
3922       {'*.m', ' (*.m)';
3923        '*.m',  '.m files '; ...
3924        '*.*', 'All Files (*.*)'}, ...
3925        'Pick a file', ff.file);
3926    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
3927        PathName(end)=[];
3928    end
3929    transform_selected =fullfile(PathName,FileName);
3930    if ~exist(transform_selected,'file')
3931           return
3932    end
3933   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
3934   if ~isequal(ext_fct,'.m')
3935        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
3936        return
3937   end
3938   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
3939   ind_coord=get(handles.transform_fct,'Value');
3940   addpath(PathName)
3941   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
3942   set(handles.transform_fct,'UserData',list_transform)
3943   rmpath(PathName)
3944   % save the new menu in the personal file 'uvmat_perso.mat'
3945   dir_perso=prefdir;%personal Matalb directory
3946   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3947   if exist(profil_perso,'file')
3948       for ilist=nb_builtin+1:numel(list_transform)
3949           ff=functions(list_transform{ilist});
3950           transform_fct{ilist-nb_builtin}=ff.file;
3951       end
3952        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
3953   end   
3954end
3955
3956%check the current path to the selected function
3957if isa(list_transform{ind_coord},'function_handle')
3958    func=functions(list_transform{ind_coord});
3959    set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
3960else
3961    set(handles.path_transform,'String','')
3962end
3963
3964set(handles.FixedLimits,'Value',0)
3965set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
3966
3967UvData=get(huvmat,'UserData');
3968
3969%delete drawn objects
3970hother=findobj('Tag','proj_object');%find all the proj objects
3971for iobj=1:length(hother)
3972    delete_object(hother(iobj))
3973end
3974hother=findobj('Tag','DeformPoint');%find all the proj objects
3975for iobj=1:length(hother)
3976    delete_object(hother(iobj))
3977end
3978hh=findobj('Tag','calib_points');
3979if ~isempty(hh)
3980    delete(hh)
3981end
3982hhh=findobj('Tag','calib_marker');
3983if ~isempty(hhh)
3984    delete(hhh)
3985end
3986if isfield(UvData,'Object')
3987     UvData.Object=UvData.Object(1);
3988end
3989list_object=get(handles.list_object_1,'String');
3990set(handles.list_object_1,'Value',1)
3991set(handles.list_object_1,'String',list_object(1))
3992set(handles.list_object_2,'Value',2)
3993set(handles.list_object_2,'String',[list_object(1);{'...'}])
3994list_object_2_Callback(hObject, eventdata, handles)
3995
3996%delete mask if it is displayed
3997if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
3998   UvData=rmfield(UvData,'MaskName'); %will impose mask refresh 
3999end
4000set(huvmat,'UserData',UvData)
4001run0_Callback(hObject, eventdata, handles)
4002
4003%--------------------------------------------
4004function histo1_menu_Callback(hObject, eventdata, handles)
4005%--------------------------------------------
4006%plot first histo
4007huvmat=get(handles.histo1_menu,'parent');
4008histo_menu=get(handles.histo1_menu,'String');
4009histo_value=get(handles.histo1_menu,'Value');
4010FieldName=histo_menu{histo_value};
4011UvData=get(huvmat,'UserData');
4012update_histo(handles.histo_u,huvmat,FieldName)
4013
4014%----------------------------------------------
4015function histo2_menu_Callback(hObject, eventdata, handles)
4016%----------------------------------------------
4017%plot second histo
4018huvmat=get(handles.histo2_menu,'parent');
4019histo_menu=get(handles.histo2_menu,'String');
4020histo_value=get(handles.histo2_menu,'Value');
4021FieldName=histo_menu{histo_value};
4022UvData=get(huvmat,'UserData');
4023update_histo(handles.histo_v,huvmat,FieldName)
4024
4025
4026%--------------------------------------------
4027%read the field .Fieldname stored in UvData and plot its histogram
4028function update_histo(haxes,huvmat,FieldName)
4029UvData=get(huvmat,'UserData');
4030
4031if ~isfield(UvData.Field,FieldName)
4032    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
4033    return
4034end
4035Field=UvData.Field;
4036FieldHisto=eval(['Field.' FieldName]);
4037if isfield(Field,'FF') & ~isempty(Field.FF) & isequal(size(Field.FF),size(FieldHisto))
4038    indsel=find(Field.FF==0);%find values marked as false
4039    if ~isempty(indsel)
4040        FieldHisto=FieldHisto(indsel);
4041    end
4042end
4043if isempty(Field)
4044    msgbox_uvmat('ERROR',['empty field ' FieldName])
4045else
4046    nxy=size(FieldHisto);
4047    Amin=double(min(min(min(FieldHisto))));%min of image
4048    Amax=double(max(max(max(FieldHisto))));%max of image
4049    if isequal(Amin,Amax)
4050       Histo.Txt=['uniform field =' num2str(Amin)];
4051    else
4052    Histo.ListVarName={FieldName,'histo'};
4053    if numel(nxy)==2
4054        Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
4055    else %color images
4056        Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
4057    end
4058    %unit
4059    units=[]; %default
4060    for ivar=1:numel(Field.ListVarName)   
4061        if strcmp(Field.ListVarName{ivar},FieldName)
4062            if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
4063                units=Field.VarAttribute{ivar}.units;
4064                break
4065            end
4066        end
4067    end
4068    if ~isempty(units)
4069        Histo.VarAttribute{1}.units=units;
4070    end
4071    eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
4072    for col=1:size(FieldHisto,3)
4073        B=FieldHisto(:,:,col);
4074        C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
4075       eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
4076    end
4077    set(haxes,'XLimMode','auto')%reset auto mode (after zoom effect)
4078    set(haxes,'YLimMode','auto')
4079    plot_field(Histo,haxes);
4080    end
4081end
4082
4083
4084
4085%------------------------------------------------
4086%CALLBACKS FOR PLOTTING PARAMETERS
4087%-------------------------------------------------
4088
4089%-----------------------------------------------------------------
4090function MinA_Callback(hObject, eventdata, handles)
4091%------------------------------------------
4092set(handles.AutoScal,'Value',1) %suppress auto mode
4093set(handles.AutoScal,'BackgroundColor',[1 1 0])
4094update_plot(handles);
4095
4096%-----------------------------------------------------------------
4097function MaxA_Callback(hObject, eventdata, handles)
4098%--------------------------------------------
4099set(handles.AutoScal,'Value',1) %suppress auto mode
4100set(handles.AutoScal,'BackgroundColor',[1 1 0])
4101update_plot(handles);
4102
4103%-----------------------------------------------
4104function AutoScal_Callback(hObject, eventdata, handles)
4105%--------------------------------------------
4106test=get(handles.AutoScal,'Value');
4107if test
4108    set(handles.AutoScal,'BackgroundColor',[1 1 0])
4109else
4110    set(handles.AutoScal,'BackgroundColor',[0.7 0.7 0.7])
4111    update_plot(handles);
4112end
4113
4114%-------------------------------------------------------------------
4115function BW_Callback(hObject, eventdata, handles)
4116%-------------------------------------------------------------------
4117update_plot(handles);
4118
4119%-------------------------------------------------------------------
4120function Contours_Callback(hObject, eventdata, handles)
4121%-------------------------------------------------------------------
4122val=get(handles.Contours,'Value');
4123if val==2
4124    set(handles.interval_txt,'Visible','on')
4125    set(handles.IncrA,'Visible','on')
4126else
4127    set(handles.interval_txt,'Visible','off')
4128    set(handles.IncrA,'Visible','off')
4129end
4130update_plot(handles);
4131
4132%-------------------------------------------------------------------
4133function IncrA_Callback(hObject, eventdata, handles)
4134%-------------------------------------------------------------------
4135update_plot(handles);
4136
4137%-------------------------------------------------------------------
4138function HideWarning_Callback(hObject, eventdata, handles)
4139%-------------------------------------------------------------------
4140update_plot(handles);
4141
4142%-------------------------------------------------------------------
4143function HideFalse_Callback(hObject, eventdata, handles)
4144%-------------------------------------------------------------------
4145update_plot(handles);
4146
4147%-------------------------------------------------------------------
4148function VecScale_Callback(hObject, eventdata, handles)
4149%-------------------------------------------------------------------
4150set(handles.AutoVec,'Value',1);
4151set(handles.AutoVec,'BackgroundColor',[1 1 0])
4152update_plot(handles);
4153
4154%-------------------------------------------------------------------
4155function AutoVec_Callback(hObject, eventdata, handles)
4156%-------------------------------------------------------------------
4157test=get(handles.AutoVec,'Value');
4158if test
4159    set(handles.AutoVec,'BackgroundColor',[1 1 0])
4160else
4161    update_plot(handles);
4162    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4163    set(handles.AutoVec,'BackgroundColor',[0.7 0.7 0.7])
4164end
4165
4166%------------------------------------------------------------------------
4167% --- Executes on selection change in decimate4 (nb_vec/4).
4168function decimate4_Callback(hObject, eventdata, handles)
4169%------------------------------------------------------------------------
4170update_plot(handles);
4171
4172%------------------------------------------------------------------------
4173% --- Executes on selection change in color_code menu
4174function color_code_Callback(hObject, eventdata, handles)
4175%------------------------------------------------------------------------
4176set_vec_col_bar(handles)
4177update_plot(handles);
4178
4179%------------------------------------------------------------------------
4180% --- Executes on button press in AutoVecColor.
4181function AutoVecColor_Callback(hObject, eventdata, handles)
4182%------------------------------------------------------------------------
4183test=get(handles.AutoVecColor,'Value');
4184if test
4185    set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
4186else
4187    update_plot(handles);
4188    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4189    set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
4190end
4191
4192%------------------------------------------------------------------------
4193% --- Executes on selection change in max_vec.
4194function min_vec_Callback(hObject, eventdata, handles)
4195%------------------------------------------------------------------------
4196max_vec_Callback(hObject, eventdata, handles)
4197
4198%------------------------------------------------------------------------
4199% --- Executes on selection change in max_vec.
4200function max_vec_Callback(hObject, eventdata, handles)
4201%------------------------------------------------------------------------
4202set(handles.AutoVecColor,'Value',1)
4203AutoVecColor_Callback(hObject, eventdata, handles)
4204min_val=str2num(get(handles.min_vec,'String'));
4205max_val=str2num(get(handles.max_vec,'String'));
4206slider1=get(handles.slider1,'Value');
4207slider2=get(handles.slider2,'Value');
4208colcode1=min_val+(max_val-min_val)*slider1;
4209colcode2=min_val+(max_val-min_val)*slider2;
4210set(handles.colcode1,'String',num2str(colcode1))
4211set(handles.colcode2,'String',num2str(colcode2))
4212update_plot(handles);
4213
4214%------------------------------------------------------------------------
4215% --- update the display of color code for vectors
4216function set_vec_col_bar(handles)
4217%------------------------------------------------------------------------
4218%get the image of the color display button 'vec_col_bar' in pixels
4219set(handles.vec_col_bar,'Unit','pixel');
4220pos_vert=get(handles.vec_col_bar,'Position');
4221set(handles.vec_col_bar,'Unit','Normalized');
4222width=ceil(pos_vert(3));
4223height=ceil(pos_vert(4));
4224
4225%get slider indications
4226list=get(handles.color_code,'String');
4227ichoice=get(handles.color_code,'Value');
4228colcode.ColorCode=list{ichoice};
4229colcode.MinC=str2num(get(handles.min_vec,'String'));
4230colcode.MaxC=str2num(get(handles.max_vec,'String'));
4231test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
4232if test3color
4233    colcode.colcode1=str2num(get(handles.colcode1,'String'));
4234    colcode.colcode2=str2num(get(handles.colcode2,'String'));
4235end
4236% colcode.option=get(handles.vec_col_bar,'Value');
4237colcode.FixedCbounds=0;
4238% list_code=get(handles.col_vec,'String');% list menu fields
4239% index_code=get(handles.col_vec,'Value');% selected string index
4240% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
4241colcode.FixedCbounds=1;
4242vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
4243[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4244oneheight=ones(1,height);
4245A1=colorlist(col_vec,1)*oneheight;
4246A2=colorlist(col_vec,2)*oneheight;
4247A3=colorlist(col_vec,3)*oneheight;
4248A(:,:,1)=A1';
4249A(:,:,2)=A2';
4250A(:,:,3)=A3';
4251set(handles.vec_col_bar,'Cdata',A)
4252
4253
4254%-------------------------------------------------------------------
4255function [PlotType,ScalOut]=update_plot(handles)
4256%-------------------------------------------------------------------
4257haxes= handles.axes3;
4258AxeData=get(haxes,'UserData');
4259PlotParam=read_plot_param(handles);
4260PlotParam.Scalar
4261[PlotType,PlotParamOut]= plot_field(AxeData,haxes,PlotParam,1);
4262write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4263
4264%-------------------------------------------------------------------
4265% --- Executes on button press in grid.
4266function grid_Callback(hObject, eventdata, handles)
4267
4268
4269
4270%-------------------------------------------------------------------
4271% --- Executes on selection change in edit.
4272function edit_Callback(hObject, eventdata, handles)
4273%-------------------------------------------------------------------
4274UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4275test=get(handles.edit,'Value');
4276if test
4277    UvData.MouseAction='edit_object';
4278    set(handles.edit,'BackgroundColor',[1,1,0]) 
4279    %suppress the other options
4280    set(handles.zoom,'Value',0)
4281    zoom_Callback(hObject, eventdata, handles)
4282    set(handles.edit_vect,'Value',0)
4283    edit_vect_Callback(hObject, eventdata, handles) 
4284    %list_object_Callback(hObject, eventdata, handles)
4285else
4286    UvData.MouseAction='none';
4287    set(handles.edit,'BackgroundColor',[0.7,0.7,0.7])   
4288end
4289set(handles.uvmat,'UserData',UvData);
4290hset_object=findobj(allchild(0),'Tag','set_object');
4291if ~isempty(hset_object)
4292    hhset_object=guidata(hset_object);
4293    if test
4294        set(hhset_object.PLOT,'enable','on');
4295    else
4296       set(hhset_object.PLOT,'enable','off');
4297    end
4298end
4299
4300%------------------------------------------------------------------------
4301% --- Executes on selection change in list_object_1.
4302function list_object_1_Callback(hObject, eventdata, handles)
4303%------------------------------------------------------------------------
4304list_str=get(handles.list_object_1,'String');
4305IndexObj=get(handles.list_object_1,'Value');
4306str_1=list_str{IndexObj};
4307val_2=get(handles.list_object_2,'Value');
4308str_2=get(handles.list_object_2,'String');
4309if isequal(val_2,IndexObj)% if the first selection is equal to the second, it will suppress the second
4310    set(handles.list_object_2,'Value',numel(str_2))%select the end of the list ('...')
4311    list_object_2_Callback(hObject, eventdata, handles)
4312end
4313update_object(handles,IndexObj,1,str_1)
4314
4315%------------------------------------------------------------------------
4316% --- Executes on selection change in list_object_1.
4317function list_object_2_Callback(hObject, eventdata, handles)
4318%------------------------------------------------------------------------
4319list_str=get(handles.list_object_2,'String');
4320IndexObj=get(handles.list_object_2,'Value');
4321if isequal(list_str{IndexObj},'...')
4322    hview_field=findobj(allchild(0),'Tag','view_field');
4323    if ~isempty(hview_field)
4324        delete(hview_field)
4325    end
4326else
4327    update_object(handles,IndexObj,2,list_str{IndexObj})
4328end
4329
4330%------------------------------------------------------------------------
4331function update_object(handles,IndexObj,option,ObjectName)
4332%------------------------------------------------------------------------
4333UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4334if ~(length(UvData.Object)>=IndexObj);
4335    return
4336end
4337ObjectData=UvData.Object{IndexObj};
4338ObjectData.Name=ObjectName;
4339if isequal(get(handles.edit,'Value'),1)
4340    ObjectData.enable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4341end
4342PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4343ZBounds=0; % default
4344    if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
4345        ZBounds(1)=UvData.ZMin; %minimum for the Z slider
4346        ZBounds(2)=UvData.ZMax;%maximum for the Z slider
4347    end
4348hset_object=findobj(allchild(0),'tag','set_object');
4349if ~isempty(hset_object)
4350    delete(hset_object)% delete existing version of set_object
4351end
4352hset_object=set_object(ObjectData,PlotHandles,ZBounds);% call the set_object interface,
4353%set(hset_object,'name',ObjectName)
4354
4355% %project the current field on the object and plot it
4356% ProjData= proj_field(UvData.Field,ObjectData,IndexObj);%project the current interface field on ObjectData
4357% if option==1%length(UvData.Object)>= IndexObj && isfield(UvData.Object{IndexObj},'plotaxes')&& ishandle(UvData.Object{IndexObj}.plotaxes)
4358%     plot_field(ProjData,handles.axes3,PlotHandles);
4359%     UvData.Object{IndexObj}.plotaxes=handles.axes3;
4360% else
4361%     UvData.Object{IndexObj}.plotaxes=view_field(ProjData);
4362% end
4363% set(handles.uvmat,'UserData',UvData)
4364hother=findobj('Tag','proj_object');%find all the proj objects
4365for iobj=1:length(hother)
4366    if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
4367        set(hother(iobj),'EdgeColor','b')
4368        if isequal(get(hother(iobj),'FaceColor'),'m')
4369            set(hother(iobj),'FaceColor','b')
4370        end
4371    elseif isequal(get(hother(iobj),'Type'),'image')
4372           Acolor=get(hother(iobj),'CData');
4373           Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4374           set(hother(iobj),'CData',Acolor);
4375    else
4376         set(hother(iobj),'Color','b')
4377    end
4378    set(hother(iobj),'Selected','off')
4379end
4380hother=findobj('Tag','DeformPoint');
4381set(hother,'Color','b');
4382set(hother,'Selected','off')   
4383if isfield(ObjectData,'HandlesDisplay')
4384    for iview=1:length(ObjectData.HandlesDisplay)
4385        if ishandle(ObjectData.HandlesDisplay(iview))
4386            uistack(ObjectData.HandlesDisplay(iview),'top')
4387            linetype=get(ObjectData.HandlesDisplay(iview),'Type');
4388            if isequal(linetype,'line')
4389                set(ObjectData.HandlesDisplay(iview),'Color','m'); %set the selected object to magenta color
4390            elseif isequal(linetype,'rectangle')
4391                set(ObjectData.HandlesDisplay(iview),'EdgeColor','m'); %set the selected object to magenta color
4392            elseif isequal(linetype,'patch')
4393                set(ObjectData.HandlesDisplay(iview),'FaceColor','m'); %set the selected object to magenta color
4394            end
4395            SubObjectData=get(ObjectData.HandlesDisplay(iview),'UserData');
4396            if isfield(SubObjectData,'SubObject')& ishandle(SubObjectData.SubObject)
4397                uistack(SubObjectData.SubObject,'top')
4398                for iobj=1:length(SubObjectData.SubObject)
4399                    hsub=SubObjectData.SubObject(iobj);
4400                    if isequal(get(hsub,'Type'),'rectangle')
4401                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4402                    elseif isequal(get(hsub,'Type'),'image')
4403                       Acolor=get(hsub,'CData');
4404                       Acolor(:,:,1)=Acolor(:,:,3);
4405                       set(hsub,'CData',Acolor);
4406                    else
4407                        set(hsub,'Color','m')
4408                    end
4409                end
4410            end
4411            if isfield(SubObjectData,'DeformPoint')& ishandle(SubObjectData.DeformPoint)
4412                set(SubObjectData.DeformPoint,'Color','m')
4413            end
4414        end
4415    end
4416end
4417pause(0.1)
4418figure(hset_object)%put set_object in front
4419
4420%------------------------------------------------------
4421% --- Executes on button press in Menu/Export/field in workspace.
4422%------------------------------------------------------
4423function MenuExportField_Callback(hObject, eventdata, handles)
4424global Data_uvmat
4425Data_uvmat=get(handles.uvmat,'UserData');
4426evalin('base','global Data_uvmat')%make CurData global in the workspace
4427display(['current field :'])
4428evalin('base','Data_uvmat') %display CurData in the workspace
4429commandwindow; %brings the Matlab command window to the front
4430
4431%------------------------------------------------------
4432% --- Executes on button press in Menu/Export/extract figure.
4433%------------------------------------------------------
4434function MenuExport_plot_Callback(hObject, eventdata, handles)
4435huvmat=get(handles.MenuExport_plot,'parent');
4436UvData=get(huvmat,'UserData');
4437hfig=figure;
4438newaxes=copyobj(handles.axes3,hfig);
4439map=colormap(handles.axes3);
4440colormap(map);%transmit the current colormap to the zoom fig
4441colorbar
4442
4443
4444% --------------------------------------------------------------------
4445function Insert_Callback(hObject, eventdata, handles)
4446
4447
4448% --------------------------------------------------------------------
4449function MenuHelp_Callback(hObject, eventdata, handles)
4450% --------------------------------------------------------------------
4451path_to_uvmat=which ('uvmat');% check the path of uvmat
4452pathelp=fileparts(path_to_uvmat);
4453helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4454if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4455else
4456    addpath (fullfile(pathelp,'uvmat_doc'))
4457    web(helpfile);
4458end
4459
4460
4461% --------------------------------------------------------------------
4462function MenuExportMovie_Callback(hObject, eventdata, handles)
4463% --------------------------------------------------------------------
4464set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4465huvmat=get(handles.run0,'parent');
4466UvData=get(huvmat,'UserData');
4467[xx,xx,FileBase]=read_file_boxes(handles);
4468 %read the current input file name
4469prompt = {'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)'};
4470dlg_title = 'select properties of the output avi movie';
4471num_lines= 1;
4472nbfield_cell=get(handles.last_i,'String');
4473def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4474answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4475aviname=answer{1};
4476fps=str2num(answer{2});
4477% check for existing file with output name aviname
4478if exist(aviname,'file')
4479    backup=aviname;
4480    testexist=2;
4481    while testexist==2
4482        backup=[backup '~'];
4483        testexist=exist(backup,'file');     
4484    end
4485    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4486    if isequal(success,1)
4487        delete(aviname)%delete existing file
4488    else
4489        msgbox_uvmat('ERROR',message)
4490        return
4491    end
4492end
4493%create avi open
4494aviobj=avifile(aviname,'Compression','None','fps',fps);
4495
4496%display first view for tests
4497newfig=figure;
4498newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
4499set(newaxes,'Tag','movieaxes')
4500nbpix=[512 384]*str2num(answer{3});
4501set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4502set(newaxes,'Position',eval(answer{4}));
4503map=colormap(handles.axes3);
4504colormap(map);%transmit the current colormap to the zoom fig
4505msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4506        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
4507UvData.Object{1}.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
4508set(huvmat,'UserData',UvData);
4509increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
4510set(handles.STOP,'Visible','on')
4511set(handles.speed,'Visible','on')
4512set(handles.speed_txt,'Visible','on')
4513set(handles.Movie,'BusyAction','queue')
4514
4515imin=str2num(get(handles.i1,'String'));
4516imax=str2num(answer{5});
4517% if isfield(UvData,'Time')
4518htitle=get(newaxes,'Title');
4519xlim=get(newaxes,'XLim');
4520ylim=get(newaxes,'YLim');
4521set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4522time_str=get(handles.abs_time,'String');
4523set(htitle,'String',['t=' time_str])
4524set(handles.speed,'Value',1)
4525for i=1:imax
4526    if get(handles.speed,'Value')~=0 & isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4527            runpm(hObject,eventdata,handles,increment)
4528            drawnow
4529            time_str=get(handles.abs_time,'String');
4530            if ishandle(htitle)
4531             set(htitle,'String',['t=' time_str])
4532            end
4533            mov=getframe(newfig);
4534            aviobj=addframe(aviobj,mov);
4535    end
4536end
4537aviobj=close(aviobj);
4538UvData.Object{1}.plotaxes=handles.axes3;
4539set(huvmat,'UserData',UvData);
4540msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4541
4542
4543% ------------------------------------------------------------------
4544function MenuCalib_Callback(hObject, eventdata, handles)
4545
4546UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4547
4548%suppress competing options
4549set(handles.zoom,'Value',0)
4550set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4551set(handles.MenuMask,'enable','off')
4552set(handles.MenuGrid,'enable','off')
4553set(handles.MenuObject,'enable','off')
4554set(handles.MenuEdit,'enable','off')
4555set(handles.list_object_1,'Value',1)     
4556% initiate display of GUI geometry_calib
4557data=[]; %default
4558if isfield(UvData,'CoordType')
4559    data.CoordType=UvData.CoordType;
4560end
4561pos=get(handles.uvmat,'Position');
4562pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
4563pos(2)=pos(2)-0.02;
4564[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
4565[UvData.hset_object,UvData.sethandles]=geometry_calib(handles,pos,FileName);% call the set_object interface     
4566pos_uvmat=get(handles.uvmat,'Position');
4567
4568if isfield(UvData,'CalOrigin')
4569    pos_cal(1)=pos_uvmat(1)+UvData.CalOrigin(1)*pos_uvmat(3);
4570    pos_cal(2)=pos_uvmat(2)+UvData.CalOrigin(2)*pos_uvmat(4);
4571    pos_cal(3:4)=UvData.CalSize .* pos_uvmat(3:4);
4572    set(UvData.hset_object,'Position',pos_cal)
4573end
4574UvData.MouseAction='calib';
4575set(handles.uvmat,'UserData',UvData);
4576
4577
4578% ------------------------------------------------------------------
4579function MenuMask_Callback(hObject, eventdata, handles)
4580% set(handles.TOOLS_txt,'Visible','on')
4581% set(handles.frame_tools,'Visible','on')
4582% % set(handles.create,'Visible','on')
4583% % set(handles.create,'Value',1)
4584% % set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
4585% set(handles.save_mask,'Visible','on')
4586% set(handles.masklevel,'Visible','on')
4587% if isequal(get(handles.z_index,'Visible'),'on')
4588%     nb_slice=str2num(get(handles.nb_slice,'String'));
4589%     for ilist=1:nb_slice
4590%         list_index{ilist,1}=num2str(ilist);
4591%     end   
4592%     set(handles.masklevel,'String',list_index)
4593%     val=str2num(get(handles.z_index,'String'));
4594%     if val<=nb_slice
4595%         set(handles.masklevel,'Value',val)
4596%     end
4597% else
4598%     set(handles.masklevel,'String',{'1'})
4599%     set(handles.masklevel,'Value',1)
4600% end
4601% if ishandle(handles.UVMAT_title)
4602%     delete(handles.UVMAT_title)
4603% end
4604UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4605% set(handles.zoom,'Value',0)
4606% set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4607% set(handles.edit_vect,'Value',0)
4608% edit_vect_Callback(hObject, eventdata, handles)
4609% set(handles.edit,'Value',0)
4610% set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4611% set(handles.edit_vect,'Value',0) 
4612% edit_vect_Callback(hObject, eventdata, handles)
4613% set(handles.cal,'Value',0)
4614% set(handles.cal,'BackgroundColor',[0 1 0])
4615
4616%initiate the GUI set_object
4617% data.TITLE='MASK';
4618% if isfield(UvData,'CoordType')
4619%     data.CoordType=UvData.CoordType;
4620% end
4621% if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
4622%     data.YMax=UvData.Mesh;
4623% elseif isfield(UvData.Field,'AX')&&isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
4624%     np=size(UvData.Field.A);
4625%     meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
4626%     meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
4627%     data.YMax=max(meshx,meshy);
4628%     data.DX=max(meshx,meshy);
4629% end
4630% data.Coord=[0 0 0]; %default
4631% PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
4632% [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
4633% pos_uvmat=get(handles.uvmat,'Position');
4634% if isfield(UvData,'SetObjectOrigin')
4635%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4636%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4637%     set(hset_object,'Position',pos_set_object)
4638% end
4639ListObj=UvData.Object;
4640select=zeros(1,numel(ListObj));
4641for iobj=1:numel(ListObj);
4642    if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside')
4643        select(iobj)=1;
4644    end
4645end
4646val=find(select);
4647if isempty(val)
4648    msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar');
4649    return
4650else
4651    set(handles.list_object_1,'Max',2);%allow multiple selection
4652    set(handles.list_object_1,'Value',val);
4653%     answer=msgbox_uvmat('INPUT_Y-N',['make the mask image from ' num2str(numel(val)) ' polygons']);
4654%     if ~isempty(answer)
4655        flag=1;
4656        npx=size(UvData.Field.A,2);
4657        npy=size(UvData.Field.A,1);
4658        xi=[0.5:npx-0.5];
4659        yi=[0.5:npy-0.5];
4660        [Xi,Yi]=meshgrid(xi,yi);
4661        if isfield(UvData,'Object')
4662            for iobj=1:length(UvData.Object)
4663                ObjectData=UvData.Object{iobj};
4664                if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
4665                    flagobj=1;
4666                    testphys=0; %coordinates in pixels by default
4667                    if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
4668                        if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
4669                            Calib=UvData.XmlData.GeometryCalib;
4670                            testphys=1;
4671                        end
4672                    end
4673                    if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
4674                        if isequal(ObjectData.Style,'polygon')
4675                            X=ObjectData.Coord(:,1);
4676                            Y=ObjectData.Coord(:,2);
4677                            if testphys
4678                                [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
4679                            end
4680                            flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
4681                        elseif isequal(ObjectData.Style,'ellipse')
4682                            if testphys
4683                                %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4684                            end
4685                            RangeX=max(ObjectData.RangeX);
4686                            RangeY=max(ObjectData.RangeY);
4687                            X2Max=RangeX*RangeX;
4688                            Y2Max=RangeY*RangeY;
4689                            distX=(Xi-ObjectData.Coord(1,1));
4690                            distY=(Yi-ObjectData.Coord(1,2));
4691                            flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
4692                        elseif isequal(ObjectData.Style,'rectangle')
4693                            if testphys
4694                                %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4695                            end
4696                            distX=abs(Xi-ObjectData.Coord(1,1));
4697                            distY=abs(Yi-ObjectData.Coord(1,2));
4698                            flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
4699                        end
4700                        if isequal(ObjectData.ProjMode,'mask_outside')
4701                            flagobj=~flagobj;
4702                        end
4703                        flag=flag & flagobj;
4704                    end
4705                end
4706            end
4707        end
4708        % flag=~flag;
4709        %mask name
4710        RootPath=get(handles.RootPath,'String');
4711        RootFile=get(handles.RootFile,'String');
4712        if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
4713            RootFile(1)=[];
4714        end
4715        filebase=fullfile(RootPath,RootFile);
4716        list=get(handles.masklevel,'String');
4717        masknumber=num2str(length(list));
4718        maskindex=get(handles.masklevel,'Value');
4719        mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
4720        imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
4721        imflag=flipdim(imflag,1);
4722        % imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when
4723        % 20<imflag<200)
4724
4725        %display the mask
4726        %update_mask(handles,num_i1,num_j1)
4727        figure;
4728        vec=linspace(0,1,256);%define a linear greyscale colormap
4729        map=[vec' vec' vec'];
4730        colormap(map)
4731        image(imflag);
4732        answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name);
4733        if ~strcmp(answer,'Cancel')
4734            imwrite(imflag,answer,'BitDepth',8);
4735        end
4736        set(list_object_1,'Value',1)
4737        set(list_object_1,'Max',1)
4738%     end
4739end       
4740     
4741
4742% UvData.MouseAction='create_object';
4743set(handles.uvmat,'UserData',UvData);
4744
4745% ------------------------------------------------------------------
4746%-- open the GUI set_grid.fig to create grid
4747function MenuGrid_Callback(hObject, eventdata, handles)
4748%UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4749
4750%suppress the other options if grid is chosen
4751set(handles.edit_vect,'Value',0)
4752edit_vect_Callback(hObject, eventdata, handles)
4753set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4754set(handles.list_object_1,'Value',1)     
4755
4756%prepare display of the set_grid GUI
4757FileName=read_file_boxes(handles);
4758CoordList=get(handles.transform_fct,'String');
4759val=get(handles.transform_fct,'Value');
4760set_grid(FileName,CoordList{val});% call the set_object interface
4761%set(handles.uvmat,'UserData',UvData);
4762
4763%----------------------------------------------------------------
4764% open the GUI 'series'
4765%----------------------------------------------------------------
4766function MenuSeries_Callback(hObject, eventdata, handles)
4767%-------------------------------------------------------------------
4768
4769[param.FileName]=read_file_boxes(handles);
4770if isequal(get(handles.SubField,'Value'),1)
4771    FileName_1=read_file_boxes_1(handles);%
4772    if ~isequal(FileName_1,param.FileName)
4773        param.FileName_1=FileName_1;
4774    end
4775end
4776param.NomType=get(handles.FileIndex,'UserData');
4777param.NomType_1=get(handles.FileIndex_1,'UserData');
4778param.comp_input=get(handles.fix_pair,'Value');
4779huvmat=get(handles.MenuSeries,'parent');
4780UvData=get(huvmat,'UserData');
4781if isfield(UvData,'Time')
4782    param.Time=UvData.XmlData.Time;
4783end
4784if isequal(get(handles.scan_i,'Value'),1)
4785    param.incr_i=str2num(get(handles.increment_scan,'String'));
4786elseif isequal(get(handles.scan_j,'Value'),1)
4787    param.incr_j=str2num(get(handles.increment_scan,'String'));
4788end
4789param.list_fields=get(handles.Fields,'String');% list menu fields
4790param.list_fields(1)=[]; %suppress  'image' option
4791param.index_fields=get(handles.Fields,'Value');% selected string index
4792if param.index_fields>1
4793    param.index_fields=param.index_fields-1;
4794end
4795param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
4796param.list_fields_1(1)=[]; %suppress  'image' option
4797param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
4798if param.index_fields_1>1
4799    param.index_fields_1=param.index_fields_1-1;
4800end
4801param.civ1=get(handles.civ1,'Value');
4802param.civ2=get(handles.civ2,'Value');
4803param.interp1=get(handles.interp1,'Value');
4804param.interp2=get(handles.interp2,'Value');
4805param.filter1=get(handles.filter1,'Value');
4806param.filter2=get(handles.filter2,'Value');
4807param.menu_coord_str=get(handles.transform_fct,'String');
4808param.menu_coord_val=get(handles.transform_fct,'Value');
4809
4810series(param); %run the series interface
4811
4812% ------------------------------------------------------------------
4813% -- open the GUI civ.fig for civx (PIV)
4814% ------------------------------------------------------------------
4815function MenuPIV_Callback(hObject, eventdata, handles)
4816 
4817[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
4818num1=stra2num(get(handles.i1,'String'));
4819num2=stra2num(get(handles.i2,'String'));
4820num_a=stra2num(get(handles.j1,'String'));
4821num_b=stra2num(get(handles.j2,'String'));
4822NomType=get(handles.FileIndex,'UserData');
4823ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4824if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4825    ind_opening=2;% propose 'fix' as the default option
4826% +read the current netcdf rootfile
4827    Data=nc2struct(FileName,[]);
4828    if isfield(Data,'fix') & isequal(Data.fix,1)
4829        ind_opening=3;
4830    end
4831    if isfield(Data,'patch') & isequal(Data.patch,1)
4832        ind_opening=4;
4833    end
4834    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4835        ind_opening=5;
4836    end
4837    if isfield(Data,'fix2') & isequal(Data.fix2,1)
4838        ind_opening=6;
4839    end
4840end     
4841param.RootName=filebase;
4842param.NomType=NomType;
4843param.num1=num1;
4844param.num2=num2;
4845param.num_a=num_a;
4846param.num_b=num_b;
4847param.SubDir=SubDir;
4848param.IndOpening=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4849param.ImaExt=ext;
4850civ(param);% interface de civ(not in the uvmat file)
4851
4852% ------------------------------------------------------------------
4853function MenuTools_Callback(hObject, eventdata, handles)
4854
4855% ------------------------------------------------------------------
4856function MenuEditObject_Callback(hObject, eventdata, handles)
4857set(handles.edit,'Value',1)
4858edit_Callback(hObject, eventdata, handles)
4859
4860%--------------------------------------------------------------------------
4861function enable_transform(handles,state)
4862set(handles.transform_fct,'Visible',state)
4863set(handles.TRANSFORM_txt,'Visible',state)   
4864set(handles.transform_fct,'Visible',state) 
4865set(handles.path_transform,'Visible',state)
4866set(handles.pxcmx_txt,'Visible',state)
4867set(handles.pxcmy_txt,'Visible',state)
4868set(handles.pxcm,'Visible',state)
4869set(handles.pycm,'Visible',state)
4870
4871%------------------------------------------------------------------------
4872function MenuEditVectors_Callback(hObject, eventdata, handles)
4873%------------------------------------------------------------------------
4874set(handles.edit_vect,'Visible','on')
4875set(handles.edit_vect,'Value',1)
4876edit_vect_Callback(hObject, eventdata, handles)
4877
4878% --------------------------------------------------------------------
4879function Menupoints_Callback(hObject, eventdata, handles)
4880data.Style='points';
4881data.ProjMode='projection';%default
4882create_object(data,handles)
4883
4884% --------------------------------------------------------------------
4885function Menuline_Callback(hObject, eventdata, handles)
4886% set(handles.create,'Visible','on')
4887% set(handles.create,'Value',1)
4888% LINE_Callback(hObject,eventdata,handles)
4889data.Style='line';
4890data.ProjMode='projection';%default
4891create_object(data,handles)
4892
4893%------------------------------------------------------------------------
4894function Menupolyline_Callback(hObject, eventdata, handles)
4895%------------------------------------------------------------------------
4896data.Style='polyline';
4897data.ProjMode='projection';%default
4898create_object(data,handles)
4899
4900%------------------------------------------------------------------------
4901function Menupolygon_Callback(hObject, eventdata, handles)
4902%------------------------------------------------------------------------
4903data.Style='polygon';
4904data.ProjMode='inside';%default
4905create_object(data,handles)
4906
4907%------------------------------------------------------------------------
4908function Menurectangle_Callback(hObject, eventdata, handles)
4909%------------------------------------------------------------------------
4910data.Style='rectangle';
4911data.ProjMode='inside';%default
4912create_object(data,handles)
4913
4914%------------------------------------------------------------------------
4915function Menuellipse_Callback(hObject, eventdata, handles)
4916%------------------------------------------------------------------------
4917data.Style='ellipse';
4918data.ProjMode='inside';%default
4919create_object(data,handles)
4920
4921%------------------------------------------------------------------------
4922function MenuMaskObject_Callback(hObject, eventdata, handles)
4923%------------------------------------------------------------------------
4924data.Style='polygon';
4925data.StyleMenu={'polygon'};
4926data.ProjMode='mask_inside';%default
4927data.ProjMenu={'mask_inside';'mask_outside'};
4928create_object(data,handles)
4929
4930% ------------------------------------------------------------------
4931function Menuplane_Callback(hObject, eventdata, handles)
4932data.Style='plane';
4933data.ProjMode='projection';%default
4934
4935create_object(data,handles)
4936
4937% ------------------------------------------------------------------
4938function Menuvolume_Callback(hObject, eventdata, handles)
4939data.Style='volume';
4940data.ProjMode='interp';%default
4941% set(handles.create,'Visible','on')
4942% set(handles.create,'Value',1)
4943% VOLUME_Callback(hObject,eventdata,handles)
4944create_object(data,handles)
4945
4946%------------------------------------------------------------------------
4947function MenuBrowseObject_Callback(hObject, eventdata, handles)
4948%------------------------------------------------------------------------
4949%get the object file
4950[FileName, PathName, filterindex] = uigetfile( ...
4951       {'*.xml;*.mat', ' (*.xml,*.mat)';
4952       '*.xml',  '.xml files '; ...
4953        '*.mat',  '.mat matlab files '}, ...
4954        'Pick an xml Object file',get(handles.RootPath,'String'));
4955fileinput=[PathName FileName];%complete file name
4956testblank=findstr(fileinput,' ');%look for blanks
4957if ~isempty(testblank)
4958    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
4959    return
4960end
4961sizf=size(fileinput);
4962if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
4963
4964%read the file
4965t=xmltree(fileinput);
4966data=convert(t);
4967data.enable_plot=1;
4968[pp,data.Name]=fileparts(FileName);
4969%PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4970hset_object=findobj(allchild(0),'tag','set_object');
4971if ~isempty(hset_object)
4972    delete(hset_object)% delete existing version of set_object
4973end
4974UvData=get(handles.uvmat,'UserData');
4975[hset_object,UvData.sethandles]=set_object(data);% call the set_object interface
4976% %position the set_object GUI with respect to uvmat
4977% pos_uvmat=get(handles.uvmat,'Position');
4978% if isfield(UvData,'SetObjectOrigin')
4979%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4980%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4981%     set(hset_object,'Position',pos_set_object)
4982% end
4983set(handles.edit,'Value',0); %suppress the object edit mode
4984set(handles.edit,'BackgroundColor',[0.7,0.7,0.7]) 
4985UvData.MouseAction='create_object';
4986set(handles.uvmat,'UserData',UvData)
4987set(handles.delete_object,'Visible','on')
4988set(handles.uvmat_title,'Visible','on')
4989set(handles.view_field_title,'Visible','on')
4990
4991%------------------------------------------------------------------------
4992% --- generic function used for the creation of a projection object
4993function create_object(data,handles)
4994%------------------------------------------------------------------------
4995hset_object=findobj(allchild(0),'tag','set_object');
4996if ~isempty(hset_object)
4997    delete(hset_object)% delete existing version of set_object
4998end
4999UvData=get(handles.uvmat,'UserData');
5000set(handles.edit,'Value',0); %suppress the object edit mode
5001set(handles.edit,'BackgroundColor',[0.7,0.7,0.7]) 
5002data.enable_plot=1;
5003transform_list=get(handles.transform_fct,'String');
5004val=get(handles.transform_fct,'Value');
5005data.CoordType=transform_list{val};
5006% if isfield(UvData,'CoordType')
5007%     data.CoordType=UvData.CoordType;
5008% end
5009if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
5010    data.RangeX=UvData.Mesh;
5011    data.RangeY=UvData.Mesh;
5012    data.DX=UvData.Mesh;
5013    data.DY=UvData.Mesh;
5014elseif isfield(UvData.Field,'AX')&& isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
5015    np=size(UvData.Field.A);
5016    meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
5017    meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
5018    data.RangeY=max(meshx,meshy);
5019    data.RangeX=max(meshx,meshy);
5020    data.DX=max(meshx,meshy);
5021end
5022if isfield(UvData,'NbDim')
5023    data.NbDim=UvData.NbDim;
5024end
5025data.Coord=[0 0 0]; %default
5026if isfield(data,'Style') && isequal(data.Style,'line')
5027    if isfield(data,'DX')
5028        data.Coord=[[0 0 0];[data.DX 0 0]]; %default
5029    else
5030        data.Coord=[[0 0 0];[1 0 0]]; %default
5031    end
5032end
5033%data.ParentButton=handles.create;
5034if ishandle(handles.UVMAT_title)
5035    delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered
5036end
5037PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
5038[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
5039
5040UvData.MouseAction='create_object';
5041set(handles.uvmat,'UserData',UvData)
5042set(handles.zoom,'Value',0)
5043zoom_Callback(handles.uvmat, [], handles)
5044set(handles.delete_object,'Visible','on')
5045set(handles.uvmat_title,'Visible','on')
5046set(handles.view_field_title,'Visible','on')
5047
5048%------------------------------------------------------------------------
5049function MenuRuler_Callback(hObject, eventdata, handles)
5050%------------------------------------------------------------------------
5051set(handles.zoom,'Value',0)
5052zoom_Callback(handles.uvmat, [], handles)
5053UvData=get(handles.uvmat,'UserData');
5054UvData.MouseAction='ruler';
5055set(handles.uvmat,'UserData',UvData);
5056
5057%------------------------------------------------------------------------
5058% --- executed when closing: set the parent interface button to value 0
5059function closefcn(gcbo,eventdata)
5060%------------------------------------------------------------------------
5061%delete all the associated figures if exist
5062hh=findobj(allchild(0),'tag','view_field');
5063if ~isempty(hh)
5064    delete(hh)
5065end
5066hh=findobj(allchild(0),'tag','geometry_calib');
5067if ~isempty(hh)
5068    delete(hh)
5069end
5070hh=findobj(allchild(0),'tag','set_object');
5071if ~isempty(hh)
5072    hhh=findobj(hh,'tag','PLOT');
5073    set(hhh,'enable','off')
5074end
5075
5076
5077% --- Executes on button press in delete_object.
5078function delete_object_Callback(hObject, eventdata, handles)
5079IndexObj=get(handles.list_object_2,'Value');
5080    if IndexObj>1
5081        delete_object(IndexObj)
5082    end
5083   
5084
5085
5086
5087
Note: See TracBrowser for help on using the repository browser.