source: trunk/src/uvmat.m @ 88

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

plot_field: test for multicomponent image (-> errormsg)
creat_grid: possibility of changing the figure name (for detect_grid)
geometry_calib: detect_grid improved (range of search adjusted from grid mesh)

bug repaired in translate points

uvmat: bug repair: dela with the case with several get_field GUI opened

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