source: trunk/src/uvmat.m @ 38

Last change on this file since 38 was 38, checked in by sommeria, 11 years ago

field transforms put in subdir transform_field. cleaning of obsolete functions

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