source: trunk/src/uvmat.m @ 39

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

civ: bug corrected for civ in batch
series and uvmat: further improvement and debugging for the menu of field transforms

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