source: trunk/src/uvmat.m @ 56

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

uvmat: edit vector button activated
debugging and cleaning after modifications made with the windows version

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