source: trunk/src/uvmat.m @ 40

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

-relabel_i_j added to the svn (relabel an image series with two indices)
-Menu projection Object added to uvmat, rationalizes the call of projection objects (to improve yet)
-get_plot_handles: modified in relationwith the Menu projection object
-mouse_down: corrected in relation with previous change in field transforms
-transform_field functions added to the svn
-set_object and keyboard_callback: cleaning

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