source: trunk/src/uvmat.m @ 55

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

-use of a single parameter file PARAM.xml (instead of PARAM_WIN and PARAM_LINUX).
-correction of a bug for opening an existing projection object
-manual editing of vectors made available with the builtin netcdf tool.
-bug fix for reading netcdf files with the builtin netcdf tool.

File size: 207.7 KB
Line 
1%'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
2%------------------------------------------------------------------------
3% function huvmat=uvmat(input)
4%
5%OUTPUT
6% huvmat=current handles of the GUI uvmat.fig
7%%
8%
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,[]);
825   col_vec=get(handles.col_vec,'String');
826   if isfield(Data,'absolut_time_T0')%&& (isfield(Data,'civ1')||isfield(Data,'civ'))
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
1988if ~isfield(UvData,'Txt')&& ~isempty(filename_1) && isequal(FieldName_1,'image')
1989    switch FileType_1
1990        case 'movie'
1991            A=read(UvData.MovieObject_1,num_i1);
1992        case 'avi'
1993            mov=aviread(filename,num_i1);
1994            A=frame2im(mov(1));
1995        case 'vol'
1996            A=imread(filename);
1997        case 'multimage'
1998            A=imread(filename,num_i1);
1999        case 'image'
2000            A=imread(filename);
2001    end
2002    npxy=size(A);
2003    set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
2004    set(handles.npy,'String',num2str(npxy(1)));
2005    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
2006    Rangy=[npxy(1)-0.5 0.5]; %
2007%     npx=str2num(get(handles.npx,'String'));
2008%     npy=str2num(get(handles.npy,'String'));
2009%     if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2010%         abs_time=UvData.XmlData_1.Time;
2011%     end
2012    Field{2}.AName='image';
2013    Field{2}.ListVarName={'AY','AX','A'}; %
2014    if size(A,3)==3;%color
2015        Field{2}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
2016    else
2017        Field{2}.VarDimName={'AY','AX',{'AY','AX'}}; %
2018    end
2019    Field{2}.AY=Rangy;
2020    Field{2}.AX=Rangx;
2021    Field{2}.A=A;
2022    Field{2}.CoordType='px'; %used for mouse_motion
2023    Field{2}.CoordUnit='px'; %used for move_mou
2024end
2025
2026%read ncfile(s)
2027CivStage_1=0;%default
2028VelType_out_1=[];
2029InputField={FieldName};
2030InputField_1={FieldName_1};
2031if ~isfield(UvData,'Txt') && ((~isempty(filename)&& isequal(FileType,'netcdf')) || (~isempty(filename_1)&& isequal(FileType,'netcdf'))) ;
2032    %read the velocity field(s) from netcdf rootfile(s)
2033    list_code=get(handles.col_vec,'String');% list menu fields
2034    index_code=get(handles.col_vec,'Value');% selected string index
2035    scal_color= list_code{index_code(1)}; % selected field
2036    if isequal(FieldName,'velocity')&& ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
2037        InputField=[InputField scal_color];
2038    end
2039    if isequal(FieldName_1,'velocity') && ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
2040        InputField_1=[InputField_1 scal_color];
2041    end
2042    if isequal(FileType,'netcdf')  %read the first nc field
2043        if isequal(FieldName,'get_field...')% read the field names on the interface get_field.
2044%             test_detect=0;%default
2045            VelType=get(handles.Fields,'UserData');
2046            hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
2047            if isempty(hget_field)
2048                hget_field= get_field(filename);%open the get_field GUI   
2049            end
2050%             test_detect=1;
2051            hhget_field=guidata(hget_field);
2052            set(hhget_field.inputfile,'String',filename)% update the list of input fields in get_field
2053            set(hhget_field.ACTION,'Value',1)% PLOT option selected
2054            set(hhget_field.list_fig,'Value',2)% plotting axes =uvmat selected
2055            [Field{1},errormsg]=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
2056            if ~isempty(errormsg)
2057                msgbox_uvmat('ERROR',['error in uvmat/run0_Callback/read_get_field: ' errormsg])
2058                return
2059            end
2060            CivStage=0;
2061            VelType_out=[];         
2062        else
2063            [Field{1},VelType_out]=read_civxdata(filename,InputField,VelType);
2064            if isfield(Field{1},'Txt')
2065                msgbox_uvmat('ERROR',Field{1}.Txt)
2066                return
2067            end
2068            CivStage=Field{1}.CivStage;
2069            UvData.NbDim=Field{1}.nb_dim;
2070        end
2071    end
2072    if ~isempty(filename_1) && isequal(FileType_1,'netcdf') %read the second file
2073        if isequal(FieldName_1,'get_field...')% read the field names on the interface get_field.
2074%             test_detect=0;%default
2075            hget_field=findobj(allchild(0),'Name','get_field_1');%find the get_field... GUI
2076             if isempty(hget_field)
2077                 hget_field= get_field(filename_1);%open the get_field GUI
2078                 set(hget_field,'name','get_field_1')
2079%                 enable_transform(handles,'off')% no field transform (possible transform in the GUI get_field)
2080             end
2081%             test_detect=1;
2082            hhget_field=guidata(hget_field);%handles of GUI elements in get_field
2083            SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
2084            [Field{2},var_detect]=nc2struct(filename_1,SubField.ListVarName); %read the corresponding input data               
2085            Field{2}.VarAttribute=SubField.VarAttribute;
2086%             if isequal(get(hhget_field.transform_fct,'Visible'),'on')
2087%                 list_transform=get(hhget_field.transform_fct,'String');
2088%                 val_list=get(hhget_field.transform_fct,'Value');
2089%                 transf=list_transform{val_list};
2090%                 if ~isempty(transf)
2091%                     Field{2}=feval(transf,Field{2});
2092%                 end
2093%             end
2094            %update the display on get_field
2095            set(hhget_field.inputfile,'String',filename_1)
2096            set(hhget_field.variables,'Value',1)
2097            Tabchar={''};%default
2098            Tabcell=[];
2099            if isfield(Field{2},'ListGlobalAttribute')& ~isempty(Field{2}.ListGlobalAttribute)
2100                for iline=1:length(Field{2}.ListGlobalAttribute)
2101                    Tabcell{iline,1}=Field{2}.ListGlobalAttribute{iline};
2102                    if isfield(Field{2}, Field{2}.ListGlobalAttribute{iline})
2103                        eval(['val=Field{2}.' Field{2}.ListGlobalAttribute{iline} ';'])
2104                        if ischar(val);
2105                            Tabcell{iline,2}=val;
2106                        else
2107                            Tabcell{iline,2}=num2str(val);
2108                        end
2109                    end
2110                end
2111                if ~isempty(Tabcell)
2112                    Tabchar=cell2tab(Tabcell,'=');
2113                    Tabchar=[{''};Tabchar];
2114                end
2115            end
2116            set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
2117        else
2118            [Field{2},VelType_out_1]=read_civxdata(filename_1,[],VelType_1);
2119            CivStage_1=Field{2}.CivStage;
2120        end
2121        if ~isequal(FileType,'netcdf')
2122            VelType_out=VelType_out_1;
2123        end
2124    end
2125end
2126
2127%update the display buttons for the first velocity type (first menuline)
2128veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2129if ~isequal(FileType,'netcdf')
2130    reset_vel_type(veltype_handles)
2131elseif isempty(VelType)
2132    set_veltype_display(veltype_handles,CivStage)%update the display of available velocity types for the first field
2133    if isempty(VelType_out)
2134        reset_vel_type(veltype_handles)
2135    else
2136        handle1=eval(['handles.' VelType_out]);
2137        reset_vel_type(veltype_handles,handle1)
2138    end
2139end
2140
2141%update the display buttons for the second velocity type (second menuline)
2142veltype_handles_1=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
2143if ~isequal(FileType_1,'netcdf')
2144    reset_vel_type(veltype_handles_1)
2145elseif isempty(VelType_1)
2146    set_veltype_display(veltype_handles_1,CivStage_1)%update the display of available velocity types for the first field
2147    if isempty(VelType_out_1)
2148        reset_vel_type(veltype_handles_1)
2149    else
2150        handle1=eval(['handles.' VelType_out_1 '_1']);
2151        reset_vel_type(veltype_handles_1,handle1)
2152    end
2153end
2154
2155%introduce w as background image by default for a new series (only for nbdim=2)
2156if ~isfield(UvData,'NewSeries')
2157    UvData.NewSeries=1;
2158end
2159%put W as background image by default if NbDim=2:
2160if ~isfield(UvData,'NbDim')||isempty(UvData.NbDim)||~isequal(UvData.NbDim,3)
2161    if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W);
2162        set(handles.SubField,'Value',1);
2163        %menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
2164        set(handles.RootPath_1,'String','"')
2165        set(handles.RootFile_1,'String','"')
2166        set(handles.SubDir_1,'String','"');
2167        [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
2168        set(handles.FileIndex_1,'String',indices)
2169        set(handles.FileExt_1,'String','"');
2170        set(handles.Fields_1,'Visible','on');
2171        set(handles.Fields_1,'Visible','on');
2172        set(handles.RootPath_1,'Visible','on')
2173        set(handles.RootFile_1,'Visible','on')
2174        set(handles.SubDir_1,'Visible','on');
2175        set(handles.FileIndex_1,'Visible','on');
2176        set(handles.FileExt_1,'Visible','on');
2177        set(handles.Fields_1,'Visible','on');
2178        Field{1}.AName='w';
2179        testscal=1;
2180    end
2181end           
2182
2183%multislice case
2184if TestInputFile &&(~isfield(UvData,'NbDim') || isequal(UvData.NbDim,2))&&...%2D case
2185      isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')&& isfield(UvData.XmlData.GeometryCalib,'SliceCoord')
2186%     nbfield2=str2num(get(handles.last_j,'String'));
2187       siz=size(UvData.XmlData.GeometryCalib.SliceCoord);
2188       if siz(1)>1
2189           NbSlice=siz(1);
2190           set(handles.slices,'Visible','on')
2191           set(handles.slices,'Value',1)
2192       else
2193           NbSlice=1;
2194       end
2195       set(handles.nb_slice,'String',num2str(NbSlice))
2196       slices_Callback(hObject, eventdata, handles)
2197%        Coord=UvData.XmlData.GeometryCalib.SliceCoord;
2198%        ZIndex=num_i1-NbSlice*(floor((num_i1-1)/NbSlice));
2199%        Field{1}.Z=ZIndex;
2200end
2201
2202%store the current open names, fields and vel types in uvmat interface
2203UvData.filename=filename;
2204UvData.filename_1=filename_1;
2205UvData.VelType=VelType;
2206UvData.VelType_1=VelType_1;
2207UvData.FieldName=FieldName;
2208UvData.FieldName_1=FieldName_1;
2209if ~isempty(scal_color)
2210    UvData.CName=scal_color;
2211end
2212
2213%coordinate transform or user fct
2214XmlData=[];%default
2215if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2216    XmlData=UvData.XmlData;
2217end
2218XmlData_1=[];%default
2219if isfield(UvData,'XmlData_1')
2220   XmlData_1=UvData.XmlData_1;
2221end
2222menu_transform=get(handles.transform_fct,'String');
2223choice_value=get(handles.transform_fct,'Value');
2224%transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
2225transform_list=get(handles.transform_fct,'UserData');
2226transform=transform_list{choice_value};%selected function handles
2227
2228% z index
2229if TestInputFile
2230    Field{1}.ZIndex=mod(num_i1-1,nbslice)+1;
2231end
2232%px to phys or other transform on field
2233if  ~isempty(transform)
2234    if length(Field)>=2
2235        Field{2}.ZIndex=mod(num_i1-1,nbslice)+1;
2236        [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
2237        if isempty(Field{2})
2238            Field(2)=[];
2239        end
2240    else
2241        Field{1}=transform(Field{1},XmlData);
2242    end
2243end
2244
2245%calculate scalar
2246if isequal(FileType,'netcdf') && ~isequal(FieldName,'get_field...')%
2247    Field{1}=calc_field(InputField,Field{1});
2248end
2249if length(Field)==2 && isequal(FileType_1,'netcdf') && ~isequal(FieldName_1,'get_field...')
2250    Field{2}=calc_field(InputField_1,Field{2});
2251end
2252
2253% combine the two input fields (e.g. substract velocity fields)
2254if numel(Field)==2
2255    if ~(isequal(get(handles.movie_pair,'Value'),1) && isequal(FieldName,'image') && isequal(FieldName_1,'image')) %combine fields if not viewing image pairs
2256        UvData.Field=sub_field(Field{1},Field{2}); %TO UPDATE FOR MORE GENERAL INPUT
2257    end
2258else
2259   UvData.Field=Field{1};
2260end
2261UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2262% test 3D , default projection menuplane and typical mesh (needed to menuopen set_object)
2263test_x=0;
2264test_z=0;% test for unstructured z coordinate
2265UvData.ZMax=0;
2266UvData.ZMin=0;%default
2267UvData.Mesh=1; %default
2268[UvData.Field,errormsg]=check_field_structure(UvData.Field);
2269if ~isempty(errormsg)
2270    msgbox_uvmat('ERROR',['error in uvmat/run0_Callback/check_field_structure: ' errormsg])
2271    return
2272end
2273[CellVarIndex,NbDim,VarType]=find_field_indices(UvData.Field);
2274[NbDim,imax]=max(NbDim);
2275if isempty(imax)
2276%    DimVarIndex=0;   
2277    coord_x=[];
2278else
2279%     VarIndex=CellVarIndex{imax};
2280    coord_x=VarType{imax}.coord_x;
2281end
2282if isfield(UvData,'NbDim') && ~isempty(UvData.NbDim)
2283    NbDim=UvData.NbDim;
2284else 
2285    UvData.NbDim=NbDim;
2286end
2287if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
2288    XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
2289    YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
2290    test_x=1;
2291elseif isfield(UvData.Field,'X') && isfield(UvData.Field,'Y')
2292    XName='X';
2293    YName='Y';
2294    test_x=1;
2295end
2296if test_x
2297    eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2298    eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2299    eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2300    eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2301    eval(['nbvec=length(UvData.Field.' XName ');'])
2302    if NbDim==3%
2303        if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
2304            ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
2305            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2306            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2307            test_z=1;   
2308        elseif isfield(UvData,'Z')% usual civ data
2309            UvData.ZMax=max(UvData.Z);
2310            UvData.ZMin=min(UvData.Z);
2311            test_z=1;
2312        end
2313    end
2314    if isequal(UvData.ZMin,UvData.ZMax)%no z dependency
2315        NbDim=2;
2316        test_z=0;
2317    end   
2318    if test_z
2319         UvData.Mesh=((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)*(UvData.ZMax-UvData.ZMin))/nbvec;% volume per vector
2320         UvData.Mesh=(UvData.Mesh)^(1/3);
2321    else
2322        UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/nbvec);%2D
2323    end
2324end
2325%case of structured coordinates
2326if isfield(UvData.Field,'AX') & isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')
2327    UvData.XMax=max(UvData.Field.AX);
2328    UvData.XMin=min(UvData.Field.AX);
2329    UvData.YMax=max(UvData.Field.AY);
2330    UvData.YMin=min(UvData.Field.AY);
2331    np_A=size(UvData.Field.A);
2332    UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/((np_A(1)-1) * (np_A(2)-1))) ;
2333end
2334if  isempty(coord_x)&~isempty(CellVarIndex)
2335    VarIndex=CellVarIndex{imax}; % list of variable indices
2336    DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
2337    if NbDim==3
2338        nbpoints=UvData.Field.DimValue(DimIndex(1));
2339        %Zvar=DimVarIndex(DimIndex(1));
2340         %Zvar=DimVarIndex(1);
2341         Zvar=VarType{imax}.coord_3;
2342        if Zvar~=0 % z is a dimension variable
2343            ZName=UvData.Field.ListVarName{Zvar};
2344            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2345            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2346        else
2347            testcoord_z=0;
2348            if length(UvData.Field.VarAttribute)>=VarIndex(1)
2349                if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid
2350                    Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
2351                    UvData.ZMax=max(Coord_z);
2352                    UvData.ZMin=min(Coord_z);
2353                    testcoord_z=1;
2354                end
2355            end
2356            if ~testcoord_z
2357                  UvData.ZMin=1;
2358                  UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
2359            end
2360        end
2361        UvData.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1);
2362    elseif NbDim==2
2363        nbpoints_y=UvData.Field.DimValue(DimIndex(1));       
2364        Yvar=VarType{imax}.coord_y;
2365        if Yvar~=0  % x is a dimension variable
2366            YName=UvData.Field.ListVarName{Yvar};
2367            eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2368            eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2369        else
2370            testcoord_y=0;
2371            if ~testcoord_y
2372                  UvData.YMin=1;
2373                  UvData.YMax=UvData.Field.DimValue(DimIndex(1));
2374            end
2375        end
2376        DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
2377        nbpoints_x=UvData.Field.DimValue(DimIndex(2));
2378        Xvar=VarType{imax}.coord_x;
2379        if Xvar~=0  % x is a dimension variable
2380            XName=UvData.Field.ListVarName{Xvar};
2381            eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2382            eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2383        else
2384            testcoord_x=0;
2385            if ~testcoord_x
2386                  UvData.XMin=1;
2387                  UvData.XMax=UvData.Field.DimValue(DimIndex(2));
2388            end
2389        end
2390        DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
2391        UvData.Mesh= sqrt(DX*DY);
2392    end
2393end
2394
2395%create a default projection menuplane
2396UvData.Object{1}.Style='plane';%main plotting plane
2397UvData.Object{1}.ProjMode='projection';%main plotting plane
2398if ~isfield(UvData.Object{1},'plotaxes')
2399    UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
2400    set(handles.list_object,'String',{'1-PLANE';'...'});
2401    set(handles.list_object,'Value',1);
2402end
2403
2404%3D case (menuvolume)
2405if NbDim==3
2406    UvData.Object{1}.NbDim=UvData.NbDim;%test for 3D objects
2407    UvData.Object{1}.RangeZ=UvData.Mesh;%main plotting plane
2408    UvData.Object{1}.Coord(1,3)=(UvData.ZMin+UvData.ZMax)/2;%section at a middle plane chosen
2409    UvData.Object{1}.Phi=0;
2410    UvData.Object{1}.Theta=0;
2411    UvData.Object{1}.Psi=0;
2412    UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR 
2413    PlotHandles=get_plot_handles(handles);
2414    ZBounds(1)=UvData.ZMin; %minimum for the Z slider
2415    ZBounds(2)=UvData.ZMax;%maximum for the Z slider
2416    set_object(UvData.Object{1},PlotHandles,ZBounds);
2417    set(handles.list_object,'Value',1);
2418%multilevel case (single menuplane in a 3D space)
2419elseif isfield(UvData,'Z')
2420    if isfield(UvData,'CoordType')& isequal(UvData.CoordType,'phys') & isfield(UvData,'XmlData')
2421        XmlData=UvData.XmlData;
2422        if isfield(XmlData,'PlanePos')
2423             UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
2424        end
2425        if isfield(XmlData,'PlaneAngle')
2426            siz=size(XmlData.PlaneAngle);
2427            indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)             
2428            UvData.Object{1}.Phi=XmlData.PlaneAngle(indangle,1);
2429            UvData.Object{1}.Theta=XmlData.PlaneAngle(indangle,2);
2430            UvData.Object{1}.Psi=XmlData.PlaneAngle(indangle,3);
2431        end
2432    elseif isfield(UvData,'ZIndex')
2433        UvData.Object{1}.ZObject=UvData.ZIndex;
2434    end
2435end
2436
2437%Plot the projections on all existing  projection objects
2438keeplim=get(handles.FixedLimits,'Value');
2439%reset the min and max of scalar if only the mask is displayed
2440if isfield(UvData,'Mask')&~isfield(UvData,'A')
2441    set(handles.MinA,'String','0')
2442    set(handles.MaxA,'String','255')
2443end
2444
2445Object=UvData.Object;
2446for iobj=1:length(Object)
2447    if ~isempty(Object{iobj})%& isfield(Object{iobj},'plotaxes')& ishandle(Object{iobj}.plotaxes)
2448        %Projeter les champs sur l'objet:*
2449        ObjectData=proj_field(UvData.Field,Object{iobj},iobj);
2450   
2451        %use of mask
2452        if isfield(ObjectData,'NbDim')&isequal(ObjectData.NbDim,2)
2453            if isfield(ObjectData,'Mask') & isfield(ObjectData,'A')
2454                 flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2455                 AX=ObjectData.AX;
2456                 AY=ObjectData.AY;
2457                 MaskX=ObjectData.MaskX;
2458                 MaskY=ObjectData.MaskY;
2459                 if ~isequal(MaskX,AX)|~isequal(MaskY,AY)
2460                     nxy=size(flag_mask);
2461                     sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2462                     sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2463                     x_mask=[ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end)]; % pixel x coordinates for image display
2464                     y_mask=[ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end)];% pixel x coordinates for image display
2465                     %project on the positions of the scalar
2466                     npxy=size(ObjectData.A);
2467                     dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2468                     dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2469                     xi=[ObjectData.AX(1):dxy(2):ObjectData.AX(end)];
2470                     yi=[ObjectData.AY(1):dxy(1):ObjectData.AY(end)];     
2471                     [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2472                    flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2473                 end
2474                 AClass=class(ObjectData.A);
2475                 ObjectData.A=flag_mask.*double(ObjectData.A);
2476                 ObjectData.A=feval(AClass,ObjectData.A);
2477                 ind_off=[];
2478                 if isfield(ObjectData,'ListVarName')
2479                      for ilist=1:length(ObjectData.ListVarName)
2480                           if isequal(ObjectData.ListVarName{ilist},'Mask')|isequal(ObjectData.ListVarName{ilist},'MaskX')|isequal(ObjectData.ListVarName{ilist},'MaskY')
2481                               ind_off=[ind_off ilist];
2482                           end
2483                      end
2484                      ObjectData.ListVarName(ind_off)=[];
2485                      ObjectData.VarDimIndex(ind_off)=[];
2486                      ind_off=[];       
2487                      for ilist=1:length(ObjectData.ListDimName)       
2488                           if isequal(ObjectData.ListDimName{ilist},'MaskX')|isequal(ObjectData.ListDimName{ilist},'MaskY')
2489                               ind_off=[ind_off ilist];
2490                           end
2491                      end
2492                      ObjectData.ListDimName(ind_off)=[];
2493                      ObjectData.DimValue(ind_off)=[];
2494                 end
2495            end 
2496        end
2497        if ~isempty(ObjectData)
2498            haxes=[];%default
2499            if isfield(Object{iobj},'plotaxes')
2500                haxes=Object{iobj}.plotaxes;%axes used for representing the projection on the object
2501            end
2502            PosColorbar=[];%default: no colorbar
2503            if ishandle(haxes) & isequal(get(haxes,'Tag'),'axes3')& isfield(UvData,'PosColorbar')
2504                PosColorbar=UvData.PosColorbar;%prescribe the colorbar position on the uvmat interface
2505            else
2506                PosColorbar='*';%default position
2507            end
2508            PlotParam=read_plot_param(handles);%read plotting parameters on the uvmat interface
2509            [PlotType,ScalOut,UvData.Object{iobj}.plotaxes]=plot_field(ObjectData,haxes,PlotParam,keeplim,PosColorbar);
2510            if isequal(PlotType,'none')
2511                hget_field=findobj(allchild(0),'name','get_field');
2512                if isempty(hget_field)
2513                    get_field([],ObjectData)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2514                else
2515                    msgbox_uvmat('ERROR','The field defined by get_field cannot be plotted')
2516                end
2517            end 
2518            UvData.Object{iobj}.PlotParam=ScalOut; %record the plotting parameters
2519        end
2520       
2521    end
2522end
2523
2524%display the updated plotting parameters for the base menuplane
2525write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
2526set(handles.uvmat,'UserData',UvData)
2527
2528%update the mask
2529if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
2530   update_mask(handles,num_i1,num_i2);
2531end
2532
2533%prepare the menus of histograms (for the whole menuvolume in 3D case)
2534menu_histo=(UvData.Field.ListVarName)';
2535ind_bad=[];
2536nb_histo=1;
2537for ivar=1:numel(menu_histo)
2538    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2539        Role=UvData.Field.VarAttribute{ivar}.Role;
2540        switch Role
2541            case {'coord_x','coord_y','coord_z','dimvar'}
2542                ind_bad=[ind_bad ivar];
2543            case {'vector_y'}
2544                nb_histo=nb_histo+1;
2545        end
2546    end
2547    DimCell=UvData.Field.VarDimName{ivar};
2548    DimName='';
2549    if ischar(DimCell)
2550        DimName=DimCell;
2551    elseif iscell(DimCell)&& numel(DimCell)==1
2552        DimName=DimCell{1};
2553    end
2554    if strcmp(DimName,menu_histo{ivar})
2555        ind_bad=[ind_bad ivar];
2556    end
2557end
2558menu_histo(ind_bad)=[];
2559test_v=0;
2560if ~isempty(menu_histo)
2561    set(handles.histo1_menu,'Value',1)
2562    set(handles.histo1_menu,'String',menu_histo)
2563    histo1_menu_Callback(hObject, eventdata, handles)
2564    if nb_histo > 1
2565        test_v=1;
2566        set(handles.histo2_menu,'Visible','on')
2567        set(handles.histo_v,'Visible','on')
2568        set(handles.histo2_menu,'String',menu_histo)
2569        set(handles.histo2_menu,'Value',2)
2570        histo2_menu_Callback(hObject, eventdata, handles)
2571    end
2572end
2573if ~test_v
2574    set(handles.histo2_menu,'Visible','off')
2575    set(handles.histo_v,'Visible','off')
2576    cla(handles.histo_v)
2577    set(handles.histo2_menu,'Value',1)
2578end
2579
2580%display time
2581testimedoc=0;
2582if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2583    if isempty(num_i2)
2584        num_i2=num_i1;
2585    end
2586    if isempty(num_j1)
2587        num_j1=1;
2588    end
2589    if isempty(num_j2)
2590        num_j2=num_j1;
2591    end
2592    siz=size(UvData.XmlData.Time);
2593    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2594        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2595        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2596        testimedoc=1;
2597    end
2598end
2599if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2600    [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2601    num_i2=str2num(str2);
2602    if isempty(num_i2)
2603        num_i2=num_i1;
2604    end
2605    num_j1=str2num(str_a);
2606    if isempty(num_j1)
2607        num_j1=1;
2608    end
2609    num_j2=str2num(str_b);
2610    if isempty(num_j2)
2611        num_j2=num_j1;
2612    end
2613    num_i1=str2num(str1);
2614    siz=size(UvData.XmlData_1.Time);
2615    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2616        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
2617    end
2618end
2619set(handles.abs_time,'String',num2str(abstime,4))
2620set(handles.abs_time_1,'String',num2str(abstime_1,4))
2621if testimedoc && isfield(UvData,'dt')
2622    dt=UvData.dt;
2623end
2624if isequal(dt,0)
2625    set(handles.Dt_txt,'String','')
2626else
2627    if ~(isfield(UvData,'TimeUnit') && ~isempty(UvData.TimeUnit))
2628        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2629    else
2630        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
2631    end
2632end
2633set(handles.run0,'BackgroundColor',[1 0 0])
2634
2635
2636
2637%-------------------------------------------------------------------
2638% --- translate coordinate to matrix index
2639%-------------------------------------------------------------------
2640function [indx,indy]=pos2ind(x0,rangx0,nxy)
2641indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2642indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2643
2644%-------------------------------------------------------------------
2645% --- Executes on button press in 'FixedLimits'.
2646%-------------------------------------------------------------------
2647function FixedLimits_Callback(hObject, eventdata, handles)
2648test=get(handles.FixedLimits,'Value');
2649if test
2650    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2651else
2652    set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
2653end
2654
2655%-------------------------------------------------------------------
2656% --- Executes on button press in auto_xy.
2657function auto_xy_Callback(hObject, eventdata, handles)
2658test=get(handles.auto_xy,'Value');
2659if test
2660    set(handles.auto_xy,'BackgroundColor',[1 1 0])
2661    cla(handles.axes3)
2662    update_plot(handles)
2663else
2664    set(handles.auto_xy,'BackgroundColor',[0.7 0.7 0.7])
2665    update_plot(handles)
2666%     axis(handles.axes3,'image')
2667end
2668
2669
2670%-------------------------------------------------------------------
2671
2672%-------------------------------------------------------------------
2673% --- Executes on button press in 'zoom'.
2674%-------------------------------------------------------------------
2675function zoom_Callback(hObject, eventdata, handles)
2676%huvmat=get(handles.zoom,'parent');%general input
2677UvData=get(handles.uvmat,'UserData');
2678if (get(handles.zoom,'Value') == 1);
2679    set(handles.zoom,'BackgroundColor',[1 1 0])
2680    set(handles.FixedLimits,'Value',1)% propose by default fixed limits for the plotting axes
2681    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2682    %UvData.ZoomOn=1;   %test for mouse action   
2683else
2684    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
2685    %UvData.ZoomOn=0;  %test for mouse action
2686end
2687set(handles.uvmat,'UserData',UvData);
2688
2689%-------------------------------------------------------------------
2690%----Executes on button press in 'record': records the current flags of manual correction.
2691%-------------------------------------------------------------------
2692function record_Callback(hObject, eventdata, handles)
2693% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2694filename=read_file_boxes(handles);
2695AxeData=get(gca,'UserData');
2696[erread,message]=fileattrib(filename);
2697if ~isempty(message) && ~isequal(message.UserWrite,1)
2698     msgbox_uvmat('ERROR',['no writting access to ' filename])
2699     return
2700end
2701test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
2702test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
2703if ~test_civ2 && ~test_civ1
2704    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2705end
2706if test_civ2
2707    nbname='nb_vectors2';
2708   flagname='vec2_FixFlag';
2709   attrname='fix2';
2710end
2711if test_civ1
2712    nbname='nb_vectors';
2713   flagname='vec_FixFlag';
2714   attrname='fix';
2715end
2716%write fix flags in the netcdf file
2717hhh=which('netcdf.open');% look for built-in matlab netcdf library
2718if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
2719    nc=netcdf.open(filename,'NC_WRITE');
2720    netcdf.reDef(nc)
2721    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1)
2722    dimid = netcdf.inqDimID(nc,nbname);
2723    try
2724        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2725    catch
2726        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2727    end
2728    netcdf.endDef(nc)
2729    netcdf.putVar(nc,varid,AxeData.FF);
2730    netcdf.close(nc) 
2731else %old netcdf library
2732    nc=netcdf(filename,'write'); %open netcdf file
2733    result=redef(nc);
2734    eval(['nc.' attrname '=1;']);
2735    theDim=nc(nbname) ;% get the number of velocity vectors
2736    nb_vectors=size(theDim);
2737    var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2738    var_FixFlag(1:nb_vectors)=AxeData.FF;%
2739    fin=close(nc);
2740end
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750%-------------------------------------------------------------------
2751%determines the fields to read from the interface
2752%------------------------------------------------------------------
2753function [VelType,civ]=setfield(handles)
2754
2755VelType=[]; %default
2756if (get(handles.civ1,'Value') == 1);
2757        VelType='civ1';
2758% interp1   
2759elseif (get(handles.interp1,'Value') == 1);
2760    VelType='interp1';
2761% filter1   
2762elseif (get(handles.filter1,'Value') == 1);
2763    VelType='filter1'; 
2764% CIV2
2765elseif (get(handles.civ2,'Value') == 1);
2766    VelType='civ2';
2767% interp2   
2768elseif (get(handles.interp2,'Value') == 1);
2769    VelType='interp2';
2770% filter2   
2771elseif (get(handles.filter2,'Value') == 1); 
2772    VelType='filter2';
2773end
2774
2775if isequal(get(handles.filter2,'Visible'),'on');
2776    civ=6;
2777% interp1   
2778elseif isequal(get(handles.interp2,'Visible'),'on');
2779    civ=5;
2780% filter1   
2781elseif isequal(get(handles.civ2,'Visible'),'on');
2782    civ=4; 
2783% CIV2
2784elseif isequal(get(handles.filter1,'Visible'),'on');
2785   civ=3;
2786% interp2   
2787elseif isequal(get(handles.interp1,'Visible'),'on');
2788    civ=2;
2789% filter2   
2790elseif isequal(get(handles.civ1,'Visible'),'on'); 
2791    civ=1;
2792else
2793    civ=0;
2794end
2795
2796%-------------------------------------------------------------------
2797%determines the veltype of the second field to read from the iinterface
2798%------------------------------------------------------------------
2799function VelType=setfield_1(handles)
2800
2801VelType=[]; %default
2802if (get(handles.civ1_1,'Value') == 1);
2803    VelType='civ1';
2804% interp1   
2805elseif (get(handles.interp1_1,'Value') == 1);
2806    VelType='interp1';
2807% filter1   
2808elseif (get(handles.filter1_1,'Value') == 1);
2809    VelType='filter1'; 
2810% CIV2
2811elseif (get(handles.civ2_1,'Value') == 1);
2812    VelType='civ2';
2813% interp2   
2814elseif (get(handles.interp2_1,'Value') == 1);
2815    VelType='interp2';
2816% filter2   
2817elseif (get(handles.filter2_1,'Value') == 1); 
2818    VelType='filter2';
2819end
2820
2821
2822%---------------------------------------------------
2823% --- Executes on button press in SubField
2824function SubField_Callback(hObject, eventdata, handles)
2825huvmat=get(handles.run0,'parent');
2826UvData=get(huvmat,'UserData');
2827if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
2828    set(handles.RootPath_1,'String','')
2829    set(handles.RootFile_1,'String','')
2830    set(handles.SubDir_1,'String','');
2831    set(handles.FileIndex_1,'String','');
2832    set(handles.FileExt_1,'String','');
2833    set(handles.RootPath_1,'Visible','off')
2834    set(handles.RootFile_1,'Visible','off')
2835    set(handles.SubDir_1,'Visible','off');
2836    set(handles.FileIndex_1,'Visible','off');
2837    set(handles.FileExt_1,'Visible','off');
2838    set(handles.Fields_1,'Value',1);%set to blank state
2839    set_veltype_display([handles.civ1_1 handles.interp1_1 handles.filter1_1 ...
2840            handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
2841    if isfield(UvData,'XmlData_1')
2842        UvData=rmfield(UvData,'XmlData_1');
2843    end
2844    set(huvmat,'UserData',UvData);
2845    run0_Callback(hObject, eventdata, handles); %run
2846else
2847    MenuBrowse_1_Callback(hObject, eventdata, handles)
2848end
2849
2850% %----------------------------------------------
2851% %read the data displayed for the input rootfile windows (new)
2852% %-------------------------------------------------
2853function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
2854RootPath=get(handles.RootPath,'String');
2855FileName=RootPath; %default
2856SubDir=get(handles.SubDir,'String');
2857if ~isempty(SubDir) && ~isequal(SubDir,'')
2858    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
2859        SubDir(1)=[]; %suppress possible / or \ separator
2860    end
2861    FileName=fullfile(RootPath,SubDir);
2862end
2863RootFile=get(handles.RootFile,'String');
2864if ~isempty(RootFile) && ~isequal(RootFile,'')
2865    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
2866        RootFile(1)=[]; %suppress possible / or \ separator
2867    end
2868    FileName=fullfile(FileName,RootFile);
2869end
2870FileBase=fullfile(RootPath,RootFile);
2871FileIndices=get(handles.FileIndex,'String');
2872FileExt=get(handles.FileExt,'String');
2873FileName=[FileName FileIndices FileExt];
2874
2875%----------------------------------------------
2876%read the data displayed for the second input rootfile windows
2877%-------------------------------------------------
2878function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
2879RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
2880if isequal(RootPath_1,'"'),RootPath_1=get(handles.RootPath,'String'); end;
2881FileName_1=RootPath_1; %default
2882SubDir_1=get(handles.SubDir_1,'String');
2883if isequal(SubDir_1,'"')
2884    SubDir_1=get(handles.SubDir,'String');
2885end
2886if ~isempty(SubDir_1) && ~isequal(SubDir_1,'')
2887    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
2888        SubDir_1(1)=[]; %suppress possible / or \ separator
2889    end
2890    FileName_1=fullfile(RootPath_1,SubDir_1);
2891end
2892RootFile_1=get(handles.RootFile_1,'String');
2893if isequal(RootFile_1,'"'),RootFile_1=get(handles.RootFile,'String'); end;
2894if ~isempty(RootFile_1) && ~isequal(RootFile_1,'')
2895    if ~(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
2896        RootFile_1(1)=[];%suppress possible / or \ separator
2897    end
2898    FileName_1=fullfile(FileName_1,RootFile_1);
2899end
2900FileBase_1=fullfile(RootPath_1,RootFile_1);
2901FileIndices_1=get(handles.FileIndex_1,'String');
2902FileExt_1=get(handles.FileExt_1,'String');
2903if isequal(FileExt_1,'"'),FileExt_1=get(handles.FileExt,'String'); end;
2904FileName_1=[FileName_1 FileIndices_1 FileExt_1];
2905
2906%---------------------------------------------------
2907% --- Executes on menu selection Fields
2908function Fields_Callback(hObject, eventdata, handles)
2909%-------------------------------------------------
2910huvmat=get(handles.Fields,'parent');
2911list_fields=get(handles.Fields,'String');% list menu fields
2912index_fields=get(handles.Fields,'Value');% selected string index
2913field= list_fields{index_fields(1)}; % selected string
2914if isequal(field,'get_field...')
2915     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2916     set_veltype_display(veltype_handles,0) % unvisible civ buttons
2917     filename=read_file_boxes(handles);
2918     hget_field=findobj(allchild(0),'name','get_field');
2919     if ~isempty(hget_field)
2920         delete(hget_field)
2921     end
2922     get_field(filename)
2923    return %no action
2924end
2925list_fields=get(handles.Fields_1,'String');% list menu fields
2926index_fields=get(handles.Fields_1,'Value');% selected string index
2927field_1= list_fields{index_fields(1)}; % selected string
2928UvData=get(huvmat,'UserData');
2929
2930%read the rootfile input display
2931FileExt=get(handles.FileExt,'String');
2932[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
2933NomTypeNew=NomType;%default
2934if isequal(field,'image')
2935    % transform netc type to the corresponding image type
2936    if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
2937        UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
2938        if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')||isequal(UvData.SubDir(1),'/'))
2939            UvData.SubDir(1)=[];
2940        end
2941        set(handles.SubDir,'String','')
2942        set(handles.FileExt,'String','.png');
2943        if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
2944            NomTypeNew='_i_j';
2945        elseif isequal(NomType,'#_ab')
2946            NomTypeNew='#a';
2947        elseif isequal(NomType,'_i1-i2')
2948            NomTypeNew='_i';
2949        end 
2950    end
2951    veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2952    set_veltype_display(veltype_handles,0) % unvisible civ buttons
2953else
2954    ext=get(handles.FileExt,'String');
2955    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
2956         MenuBrowse_Callback(hObject, eventdata, handles)
2957    end
2958    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
2959        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
2960        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
2961        set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
2962        set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
2963    elseif isequal(field,'more...');
2964        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
2965        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
2966        str=calc_field;%get the list of available scalars by the function calc_scal
2967        [ind_answer] = listdlg('PromptString','Select a file:',...
2968                'SelectionMode','single',...
2969                'ListString',str);
2970       % edit the choice in the field and action menu
2971        scalar=cell2mat(str(ind_answer));
2972        menu=update_menu(handles.Fields,scalar);
2973        menu=[{''};menu];
2974        set(handles.Fields_1,'String',menu);% store the selected scalar type
2975    end
2976end
2977indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
2978set(handles.FileIndex,'String',indices)
2979set(handles.FileIndex,'UserData',NomTypeNew)
2980%common to Fields_1_Callback
2981if isequal(field,'image')||isequal(field_1,'image')
2982    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
2983    set(handles.npy_title,'Visible','on')
2984    set(handles.npx,'Visible','on')
2985    set(handles.npy,'Visible','on')
2986    set(handles.fix_pair,'Value',0)
2987else
2988    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
2989    set(handles.npy_title,'Visible','off')
2990    set(handles.npx,'Visible','off')
2991    set(handles.npy,'Visible','off')
2992    set(handles.fix_pair,'Value',1)
2993end
2994% if isequal(field,'velocity')|isequal(field_1,'velocity');
2995%     state_vect='on';
2996% else
2997%     state_vect='off';
2998% end
2999% if ~isequal(field,'velocity')|(~isequal(field_1,'velocity'));
3000%     state_scal='on';
3001% else
3002%     state_scal='off';
3003% end
3004setfield(handles);% update the field structure ('civ1'....)
3005
3006if ~isfield(UvData,'NewSeries')||isequal(UvData.NewSeries,0)
3007    run0_Callback(hObject, eventdata, handles)
3008end
3009
3010%---------------------------------------------------
3011% --- Executes on menu selection Fields
3012function Fields_1_Callback(hObject, eventdata, handles)
3013%-------------------------------------------------
3014huvmat=get(handles.Fields_1,'parent');
3015list_fields=get(handles.Fields,'String');% list menu fields
3016index_fields=get(handles.Fields,'Value');% selected string index
3017field= list_fields{index_fields(1)}; % selected string
3018list_fields=get(handles.Fields_1,'String');% list menu fields
3019index_fields=get(handles.Fields_1,'Value');% selected string index
3020field_1= list_fields{index_fields(1)}; % selected string for the second field
3021if isequal(field_1,'') %remove second field if 'blank' field is selected
3022    set(handles.SubField,'Value',0)
3023    SubField_Callback(hObject, eventdata, handles)
3024    return
3025end
3026UvData=get(huvmat,'UserData');
3027
3028%read the rootfile input display
3029FileExt_prev=get(handles.FileExt_1,'String');
3030if isempty(FileExt_prev)|isequal(FileExt_prev,'')
3031    FileExt_1=get(handles.FileExt,'String');
3032else
3033    FileExt_1=FileExt_prev;
3034end
3035NomType_1=get(handles.FileIndex_1,'UserData');
3036if isempty(NomType_1)|isequal(NomType_1,'')
3037    NomType_1=get(handles.FileIndex,'UserData');
3038end
3039NomTypeNew=NomType_1;%default
3040
3041set(handles.SubField,'Value',1)%introduce second field
3042if isfield(UvData,'XmlData')
3043    UvData.XmlData_1=UvData.XmlData;
3044end
3045set(handles.FileIndex_1,'Visible','on')
3046set(handles.FileExt_1,'Visible','on')
3047RootPath_1=get(handles.RootPath_1,'String');
3048RootFile_1=get(handles.RootFile_1,'String');
3049if isempty(RootPath_1)|isequal(RootPath_1,'')
3050    set(handles.RootPath_1,'String','"')
3051end
3052if isempty(RootFile_1) | isequal(RootFile_1,'')
3053    set(handles.RootFile_1,'String','"')
3054end
3055if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3056    RootFile_1(1)=[];
3057end
3058
3059if isequal(field_1,'get_field...')
3060     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3061     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3062     filename=read_file_boxes_1(handles);
3063     hget_field=findobj(allchild(0),'name','get_field_1');
3064     if ~isempty(hget_field)
3065         delete(hget_field)
3066     end
3067     hget_field=get_field(filename);
3068     set(hget_field,'name','get_field_1')
3069    return %no action
3070end
3071if isequal(field_1,'image')
3072    % transform netc type to the corresponding image type
3073    set(handles.FileExt_1,'String','.png');
3074    if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')
3075        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
3076        set(handles.SubDir_1,'String','')
3077%         set(handles.FileExt_1,'String','.png');       
3078        if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')
3079            NomTypeNew='_i_j';
3080        elseif isequal(NomType_1,'#_ab')
3081            NomTypeNew='#a';
3082        elseif isequal(NomType_1,'_i1-i2')
3083            NomTypeNew='_i';
3084        end 
3085    end
3086    veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3087    set_veltype_display(veltype_handles,0) % unvisible civ buttons
3088else
3089    set(handles.SubDir_1,'Visible','on')
3090    if ~isequal(FileExt_prev,'.nc') %find the new NomType if the previous display was not already a netcdf file
3091        veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3092        set_veltype_display(veltype_handles,6); % make all civ buttons visible
3093        RootPath_1=get(handles.RootPath_1,'String');
3094        RootFile_1=get(handles.RootFile_1,'String');
3095        if isempty(RootPath_1)|isequal(RootPath_1,'')
3096            set(handles.RootPath_1,'String','"')
3097        end
3098        if isempty(RootFile_1) | isequal(RootFile_1,'')
3099            set(handles.RootFile_1,'String','"')
3100        end
3101        if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3102            RootFile_1(1)=[];
3103        end
3104        filebase_1=fullfile(RootPath_1,RootFile_1);
3105        SubDir_1=get(handles.SubDir,'String');
3106        if isempty(SubDir_1)|isequal(SubDir_1,'')
3107            if isfield(UvData,'SubDir_1')
3108                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3109            else
3110                SubDir_1='?';
3111            end
3112        end
3113        if isequal(NomType_1,'#_ab')|isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')|isequal(NomType_1,'_i1-i2')
3114            NomTypeNew=NomType_1;
3115        elseif isequal(NomType_1,'#a')
3116             [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),str2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3117             NomTypeNew='#_ab';
3118        elseif isequal(NomType_1,'_i_j')
3119             [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);
3120            if idetect==1
3121                NomTypeNew='_i1-i2_j';
3122            else
3123                NomTypeNew='_i_j1-j2';
3124            end
3125        else %for instance avi files or any ima_num series
3126            [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);
3127            NomTypeNew='_i1-i2';
3128        end           
3129        [Path,Name]=fileparts(filebase_1);
3130        set(handles.FileExt_1,'String','.nc');
3131        if ~isempty(SubDir_1) & ~isequal(SubDir_1,'''')& ~isequal(SubDir_1,'"')
3132            SubDir_1=['/' SubDir_1];
3133        end
3134        set(handles.SubDir_1,'String',SubDir_1);
3135    end
3136    if isequal(field,'vort') | isequal(field,'div') | isequal(field,'strain')
3137        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3138        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3139        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3140        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3141    elseif isequal(field_1,'more...'); %add new item to the menu
3142        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3143        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3144        str=calc_field;%get the list of available scalars by the function calc_scal
3145        [ind_answer,v] = listdlg('PromptString','Select a file:',...
3146                'SelectionMode','single',...
3147                'ListString',str);
3148       % edit the choice in the field and action menu
3149        scalar=cell2mat(str(ind_answer));
3150        menu=update_menu(handles.Fields_1,scalar);
3151        set(handles.Fields_1,'String',menu);% store the selected scalar type
3152    end
3153end
3154str1=get(handles.i1,'String');
3155str2=get(handles.i2,'String');
3156str_a=get(handles.j1,'String');
3157str_b=get(handles.j2,'String');
3158indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3159set(handles.FileIndex_1,'String',indices)
3160set(handles.FileIndex_1,'UserData',NomTypeNew)
3161
3162%common to Fields_Callback
3163if isequal(field,'image')|isequal(field_1,'image')
3164    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3165    set(handles.npy_title,'Visible','on')
3166    set(handles.npx,'Visible','on')
3167    set(handles.npy,'Visible','on')
3168    set(handles.fix_pair,'Value',0)
3169else
3170    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3171    set(handles.npy_title,'Visible','off')
3172    set(handles.npx,'Visible','off')
3173    set(handles.npy,'Visible','off')
3174    set(handles.fix_pair,'Value',1)
3175end
3176if isequal(field,'velocity')|isequal(field_1,'velocity');
3177    state_vect='on';
3178else
3179    state_vect='off';
3180end
3181if ~isequal(field,'velocity')|(~isequal(field_1,'velocity')&~isequal(field_1,''));
3182    state_scal='on';
3183else
3184    state_scal='off';
3185end
3186set(huvmat,'UserData',UvData)
3187setfield(handles);% update the field structure ('civ1'....)
3188if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
3189    run0_Callback(hObject, eventdata, handles)
3190end
3191
3192
3193%-----------------------------------
3194%set the visibility of relevant velocity type menus:
3195%-----------------------------------
3196%Civ=0; all states 'off'
3197%Civ=6; all states 'on'
3198function set_veltype_display(handles,Civ)
3199if isequal(Civ,0)
3200    imax=0;
3201%    set(handles(1),'Visible','on')  % unvisible civ buttons
3202% else
3203%    set(handles(1),'String','civ1')
3204% end
3205elseif isequal(Civ,1)
3206   imax=1;
3207elseif isequal(Civ,2) | isequal(Civ,3)
3208    imax=3;
3209elseif isequal(Civ,4) | isequal(Civ,5)
3210    imax=4;
3211elseif isequal(Civ,6)
3212    imax=6;
3213end
3214for ibutton=1:imax;
3215    set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3216end
3217% for ibutton=max(imax+1,2):6;
3218for ibutton=imax+1:6;
3219    set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3220    set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3221end
3222
3223%-------------------------------------------------------------------
3224% --- Executes on button press in civ1.
3225function civ1_Callback(hObject, eventdata, handles)
3226%-------------------------------------------------------------------
3227if get(handles.civ1,'Value')==1
3228    reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ1)
3229else
3230    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3231end
3232run0_Callback(hObject, eventdata, handles)
3233
3234%-------------------------------------------------------------------
3235% --- Executes on button press in interp1.
3236function interp1_Callback(hObject, eventdata, handles)
3237%-------------------------------------------------------------------
3238if get(handles.interp1,'Value')==1
3239    reset_vel_type([handles.civ1 handles.civ2 handles.filter1 handles.interp2 handles.filter2],handles.interp1)
3240else
3241     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3242end
3243run0_Callback(hObject, eventdata, handles)
3244
3245%-------------------------------------------------------------------
3246% --- Executes on button press in filter1.
3247function filter1_Callback(hObject, eventdata, handles)
3248%-------------------------------------------------------------------
3249if get(handles.filter1,'Value')==1
3250    reset_vel_type([handles.civ1 handles.civ2 handles.interp1 handles.interp2 handles.filter2],handles.filter1)
3251else
3252     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3253end
3254run0_Callback(hObject, eventdata, handles)
3255
3256%-------------------------------------------------------------------
3257% --- Executes on button press in civ2.
3258function civ2_Callback(hObject, eventdata, handles)
3259%-------------------------------------------------------------------
3260if get(handles.civ2,'Value')==1
3261    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ2)
3262else
3263     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3264end
3265run0_Callback(hObject, eventdata, handles)
3266
3267%-----------------------------------------
3268% --- Executes on button press in interp2.
3269%-------------------------------------------
3270function interp2_Callback(hObject, eventdata, handles)
3271if get(handles.interp2,'Value')==1
3272    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.filter2],handles.interp2)
3273else
3274     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3275end
3276run0_Callback(hObject, eventdata, handles)
3277%---------------------------------------------
3278% --- Executes on button press in filter2.
3279%-------------------------------------------
3280function filter2_Callback(hObject, eventdata, handles)
3281if get(handles.filter2,'Value')==1
3282    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2],handles.filter2)
3283else
3284     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3285end
3286run0_Callback(hObject, eventdata, handles)
3287
3288%---------------------------------------------
3289function civ1_1_Callback(hObject, eventdata, handles)
3290%---------------------------------------------
3291if get(handles.civ1_1,'Value')==1
3292    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.civ1_1)
3293else
3294     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3295end
3296run0_Callback(hObject, eventdata, handles)
3297
3298%--------------------------------------------
3299function interp1_1_Callback(hObject, eventdata, handles)
3300%--------------------------------------------
3301if get(handles.interp1_1,'Value')==1
3302    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.interp1_1)
3303else
3304    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3305end
3306run0_Callback(hObject, eventdata, handles)
3307
3308%--------------------------------------------
3309function filter1_1_Callback(hObject, eventdata, handles)
3310%--------------------------------------------
3311if get(handles.filter1_1,'Value')==1
3312    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.filter1_1)
3313else
3314    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3315end
3316run0_Callback(hObject, eventdata, handles)
3317
3318%--------------------------------------------
3319function civ2_1_Callback(hObject, eventdata, handles)
3320%--------------------------------------------
3321if get(handles.civ2_1,'Value')==1
3322    reset_vel_type([handles.civ1_1 handles.interp1_1  handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.civ2_1)
3323else
3324    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3325end
3326run0_Callback(hObject, eventdata, handles)
3327
3328%--------------------------------------------
3329function interp2_1_Callback(hObject, eventdata, handles)
3330%--------------------------------------------
3331if get(handles.interp2_1,'Value')==1
3332    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.filter2_1],handles.interp2_1)
3333else
3334    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3335end
3336run0_Callback(hObject, eventdata, handles)
3337
3338%--------------------------------------------
3339function filter2_1_Callback(hObject, eventdata, handles)
3340%--------------------------------------------
3341if get(handles.filter2_1,'Value')==1
3342    reset_vel_type([handles.civ1_1 handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1],handles.filter2_1)
3343else
3344    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3345end
3346run0_Callback(hObject, eventdata, handles)
3347
3348%-----------------------------------------------
3349% --- reset civ buttons
3350function reset_vel_type(handles_civ0,handle1)
3351for ibutton=1:length(handles_civ0)
3352    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3353    set(handles_civ0(ibutton),'Value',0)
3354end
3355if exist('handle1','var')%handles of selected button
3356        set(handle1,'BackgroundColor',[1 1 0]) 
3357end
3358
3359%------------------------------------------------
3360function create_Callback(hObject,eventdata,handles)
3361%------------------------------------------------
3362if ishandle(handles.UVMAT_title)
3363    delete(handles.UVMAT_title)
3364end
3365huvmat=get(handles.create,'parent');
3366UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
3367if isequal(get(handles.create,'Value'),1)
3368    set(handles.zoom,'Value',0)
3369    zoom_Callback(hObject, eventdata, handles)
3370     set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
3371    set(handles.edit_vect,'Value',0) 
3372    edit_vect_Callback(hObject, eventdata, handles)
3373    set(handles.edit,'Value',0)
3374    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3375    list_object=get(handles.list_object,'String');
3376    if ~isempty(list_object)
3377        set(handles.list_object,'Value',length(list_object))
3378    end
3379    MouseAction='create_object';
3380    hset_object=findobj(allchild(0),'Name','set_object');
3381    uistack(hset_object,'top')
3382else
3383    set(handles.create,'BackgroundColor',[0 1 0])
3384    set(handles.edit,'Value',1)
3385    set(handles.edit,'BackgroundColor',[1 1 0])
3386    MouseAction='none';
3387end
3388
3389UvData.MouseAction=MouseAction;
3390set(huvmat,'UserData',UvData);
3391
3392%------------------------------------------------
3393function POINTS_Callback(hObject,eventdata,handles)
3394%------------------------------------------------
3395if ishandle(handles.UVMAT_title)
3396    delete(handles.UVMAT_title)
3397end
3398huvmat=get(handles.create,'parent');
3399UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
3400if isequal(get(handles.create,'Value'),1)
3401    set(handles.zoom,'Value',0)
3402    zoom_Callback(hObject, eventdata, handles)
3403    set(handles.edit_vect,'Value',0) 
3404    edit_vect_Callback(hObject, eventdata, handles)
3405    set(handles.edit,'Value',0)
3406    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3407    %set(handles.grid,'Value',0)
3408    %set(handles.grid,'BackgroundColor',[0 1 0])
3409    % initiate set_object GUI
3410     data.TITLE='POINTS';
3411    if isfield(UvData,'CoordType')
3412        data.CoordType=UvData.CoordType;
3413    end
3414    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3415        data.RangeY=UvData.Mesh;
3416    elseif isfield(UvData,'AX')&isfield(UvData,'AY')& isfield(UvData,'A')%only image
3417        np=size(UvData.Field.A);
3418        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3419        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3420        data.RangeY=max(meshx,meshy);
3421        data.DX=max(meshx,meshy);
3422    end
3423    data.Coord=[0 0 0]; %default
3424    data.ParentButton=handles.create;
3425    PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3426    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
3427    if isfield(UvData,'SetObjectOrigin')
3428    pos_uvmat=get(huvmat,'Position');
3429    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3430    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
3431    set(hset_object,'Position',pos_set_object)
3432    end
3433    %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)]);
3434    list_object=get(handles.list_object,'String');
3435    if ~isempty(list_object)
3436        set(handles.list_object,'Value',length(list_object))
3437    end
3438    MouseAction='create_object';
3439    %UvData.ZoomOn=0;
3440else
3441    set(handles.create,'BackgroundColor',[0 1 0])
3442    set(handles.edit,'Value',1)
3443    set(handles.edit,'BackgroundColor',[1 1 0])
3444    MouseAction='none';
3445end
3446
3447UvData.MouseAction=MouseAction;
3448set(huvmat,'UserData',UvData);
3449
3450%-----------------------------------------------------------
3451function LINE_Callback(hObject, eventdata, handles)
3452%-------------------------------------------------
3453if ishandle(handles.UVMAT_title)
3454    delete(handles.UVMAT_title)
3455end
3456% handles.uvmat
3457huvmat=get(handles.create,'parent');
3458UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3459set(handles.zoom,'Value',0)
3460zoom_Callback(hObject, eventdata, handles)
3461set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3462set(handles.edit_vect,'Value',0)
3463edit_vect_Callback(hObject, eventdata, handles)
3464set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3465set(handles.edit,'Value',0)
3466set(handles.list_object,'Value',1);
3467edit_vect_Callback(hObject, eventdata, handles)
3468set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3469set(handles.cal,'Value',0)
3470set(handles.cal,'BackgroundColor',[0 1 0])
3471%  initiate the set_object GUI
3472data.TITLE='LINE';
3473if isfield(UvData,'CoordType')
3474    data.CoordType=UvData.CoordType;
3475end
3476if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3477    data.RangeX=UvData.Mesh;
3478    data.RangeY=UvData.Mesh;
3479    data.DX=UvData.Mesh;
3480    data.DY=UvData.Mesh;
3481elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3482    np=size(UvData.Field.A);
3483    meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3484    meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3485    data.RangeY=max(meshx,meshy);
3486    data.RangeX=max(meshx,meshy);
3487    data.DX=max(meshx,meshy);
3488end
3489if isfield(data,'DX')
3490    data.Coord=[[0 0 0];[data.DX 0 0]]; %default
3491else
3492    data.Coord=[[0 0 0];[1 0 0]]; %default
3493end
3494data.ParentButton=handles.create;
3495PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3496[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3497                                                  % associate the set_edit interface handle to the plotting axes
3498pos_uvmat=get(huvmat,'Position');
3499if isfield(UvData,'SetObjectOrigin')
3500    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3501    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3502    set(hset_object,'Position',pos_set_object)
3503end
3504list_object=get(handles.list_object,'String');
3505if ~isempty(list_object)
3506    set(handles.list_object,'Value',length(list_object))
3507end
3508MouseAction='create_object';
3509UvData.MouseAction=MouseAction;
3510set(huvmat,'UserData',UvData)
3511
3512%-----------------------------------------------------------
3513function PATCH_Callback(hObject, eventdata, handles)
3514%-----------------------------------------------------------
3515if ishandle(handles.UVMAT_title)
3516    delete(handles.UVMAT_title)
3517end
3518huvmat=get(handles.create,'parent');
3519UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3520% if isequal(get(handles.PATCH,'Value'),1)
3521    set(handles.zoom,'Value',0)
3522    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3523%     set(handles.create,'Value',0)%suppress the other options if LINE is chosen
3524%     set(handles.create,'BackgroundColor',[0 1 0])
3525%     set(handles.LINE,'Value',0)
3526%     set(handles.LINE,'BackgroundColor',[0 1 0])
3527%     set(handles.PATCH,'Value',1)
3528%     set(handles.PATCH,'BackgroundColor',[1 1 0])
3529%     set(handles.PLANE,'Value',0)
3530%     set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
3531%     set(handles.VOLUME,'Value',0)
3532%     set(handles.VOLUME,'BackgroundColor',[0 1 0])
3533    %set(handles.makemask,'Value',0)
3534    %makemask_Callback(hObject, eventdata, handles)
3535    set(handles.edit_vect,'Value',0)
3536    edit_vect_Callback(hObject, eventdata, handles)
3537    set(handles.edit,'Value',0)
3538    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3539    set(handles.edit_vect,'Value',0) 
3540    edit_vect_Callback(hObject, eventdata, handles)
3541    set(handles.cal,'Value',0)
3542    set(handles.cal,'BackgroundColor',[0 1 0])
3543    %set(handles.grid,'Value',0)
3544    %set(handles.grid,'BackgroundColor',[0 1 0])
3545    %initiate set_object GUI
3546    data.TITLE='PATCH';
3547    if isfield(UvData,'CoordType')
3548        data.CoordType=UvData.CoordType;
3549    end
3550    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3551        data.YMax=UvData.Mesh;
3552    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3553        np=size(UvData.Field.A);
3554        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
3555        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
3556        data.YMax=max(meshx,meshy);
3557        data.DX=max(meshx,meshy);
3558    end
3559    data.Coord=[0 0 0]; %default
3560    data.ParentButton=handles.create;
3561    PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3562    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
3563    pos_uvmat=get(huvmat,'Position');
3564    if isfield(UvData,'SetObjectOrigin')
3565        pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3566        pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
3567        set(hset_object,'Position',pos_set_object)
3568    end
3569    list_object=get(handles.list_object,'String');
3570    if ~isempty(list_object)
3571        set(handles.list_object,'Value',length(list_object))
3572    end
3573    UvData.MouseAction='create_object';
3574    set(huvmat,'UserData',UvData);
3575%-------------------------------------------------------
3576function PLANE_Callback(hObject, eventdata, handles)
3577%-------------------------------------------------------
3578if ishandle(handles.UVMAT_title)
3579    delete(handles.UVMAT_title)
3580end
3581huvmat=get(handles.create,'parent');
3582UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3583set(handles.zoom,'Value',0)
3584set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3585set(handles.edit_vect,'Value',0)
3586edit_vect_Callback(hObject, eventdata, handles)
3587set(handles.edit,'Value',0)
3588set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3589set(handles.cal,'Value',0)
3590set(handles.cal,'BackgroundColor',[0 1 0])
3591%set(handles.grid,'Value',0)
3592%set(handles.grid,'BackgroundColor',[0 1 0])
3593%initiate set_object GUI
3594data.TITLE='PLANE';
3595if isfield(UvData,'CoordType')
3596    data.CoordType=UvData.CoordType;
3597end
3598%Si 3D data.nbdim=3;
3599%Si 2D
3600if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3601    data.ZMax=UvData.Mesh;
3602    data.DX=UvData.Mesh;
3603    data.DY=UvData.Mesh;
3604elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3605    np=size(UvData.Field.A);
3606    meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
3607    meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
3608    data.DX=max(meshx,meshy);
3609end
3610if isfield(UvData,'DX')
3611    data.DX=UvData.DX;
3612end
3613if isfield(UvData,'DY')
3614    data.DY=UvData.DY;
3615elseif isfield(UvData,'Mesh')
3616    data.DY=UvData.Mesh;
3617end
3618if isfield(UvData.Field,'X')& isfield(UvData.Field,'Y')
3619    data.Coord=[0 0 0];
3620    data.Style='plane';
3621    data.Phi=0;
3622    data.IndexObj=1; %act on the first reference plane by default
3623    haxes= handles.axes3;%GENERALISER
3624    plot_object(data,[],haxes,'m'); %plot the axes of the default plane 
3625end
3626data.ParentButton=handles.create;
3627PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3628ZBounds=0; % default
3629if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
3630    ZBounds(1)=UvData.ZMin; %minimum for the Z slider
3631    ZBounds(2)=UvData.ZMax;%maximum for the Z slider
3632end
3633[hset_object,UvData.sethandles]=set_object(data,PlotHandles,ZBounds);% call the set_object interface with action on haxes,
3634if isfield(UvData,'SetObjectOrigin')
3635pos_uvmat=get(huvmat,'Position');
3636pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3637pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3638set(hset_object,'Position',pos_set_object)
3639end
3640list_object=get(handles.list_object,'String');
3641nbobject=length(list_object);
3642set(handles.list_object,'Value',nbobject)
3643UvData.MouseAction='create_object';
3644set(huvmat,'UserData',UvData)
3645
3646%-------------------------------------------------------
3647% --- Executes on button press in MENUVOLUME.
3648%-------------------------------------------------------
3649function VOLUME_Callback(hObject, eventdata, handles)
3650%errordlg('command VOL not implemented yet')
3651if ishandle(handles.UVMAT_title)
3652    delete(handles.UVMAT_title)
3653end
3654huvmat=get(handles.create,'parent');
3655UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3656if isequal(get(handles.VOLUME,'Value'),1)
3657    set(handles.zoom,'Value',0)
3658    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3659    set(handles.edit_vect,'Value',0)
3660    edit_vect_Callback(hObject, eventdata, handles)
3661    set(handles.edit,'Value',0)
3662    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3663    set(handles.cal,'Value',0)
3664    set(handles.cal,'BackgroundColor',[0 1 0])
3665    set(handles.edit_vect,'Value',0)
3666    edit_vect_Callback(hObject, eventdata, handles)
3667    %initiate set_object GUI
3668    data.TITLE='VOLUME';
3669    if isfield(UvData,'CoordType')
3670        data.CoordType=UvData.CoordType;
3671    end
3672    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3673        data.RangeY=UvData.Mesh;
3674        data.RangeX=UvData.Mesh;
3675        data.DX=UvData.Mesh;
3676        data.DY=UvData.Mesh;
3677    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3678        np=size(UvData.Field.A);
3679        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3680        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3681        data.RangeY=max(meshx,meshy);
3682        data.RangeX=max(meshx,meshy);
3683        data.DX=max(meshx,meshy);
3684    end
3685    data.ParentButton=handles.VOLUME;
3686    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3687    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3688                                                      % associate the set_edit interface handle to the plotting axes
3689    if isfield(UvData,'SetObjectOrigin')                                               
3690    pos_uvmat=get(huvmat,'Position');
3691    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3692    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3693    set(hset_object,'Position',pos_set_object)
3694    end
3695    UvData.MouseAction='create_object';
3696else
3697    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3698    UvData.MouseAction='none';
3699end
3700set(huvmat,'UserData',UvData)
3701
3702%-------------------------------------------------------
3703function edit_vect_Callback(hObject, eventdata, handles)
3704%-------------------------------------------------------
3705
3706UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3707if isequal(get(handles.edit_vect,'Value'),1)
3708    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
3709    test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
3710    if ~test_civ2 && ~test_civ1
3711        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3712    end
3713    set(handles.record,'Visible','on')
3714    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3715    set(handles.edit,'Value',0)
3716    set(handles.create,'Value',0)
3717    set(handles.create,'BackgroundColor',[0 1 0])
3718    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3719    set(gcf,'Pointer','arrow')
3720    UvData.MouseAction='edit_vect';
3721else
3722    set(handles.record,'Visible','off')
3723    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3724    UvData.MouseAction='none';
3725end
3726set(handles.uvmat,'UserData',UvData)
3727
3728%----------------------------------------------
3729function save_mask_Callback(hObject, eventdata, handles)
3730%-----------------------------------------------------------------------
3731huvmat=get(handles.save_mask,'parent');
3732UvData=get(huvmat,'UserData');
3733
3734hpatch=findobj(huvmat,'Type','patch');
3735flag=1;
3736npx=size(UvData.Field.A,2);
3737npy=size(UvData.Field.A,1);
3738xi=[0.5:npx-0.5];
3739yi=[0.5:npy-0.5];
3740[Xi,Yi]=meshgrid(xi,yi);
3741if isfield(UvData,'Object')
3742    for iobj=1:length(UvData.Object)
3743        ObjectData=UvData.Object{iobj};
3744        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3745            flagobj=1;
3746            testphys=0; %coordinates in pixels by default
3747            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3748                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3749                    Calib=UvData.XmlData.GeometryCalib;
3750                    testphys=1;
3751                end
3752            end
3753            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3754                if isequal(ObjectData.Style,'polygon')
3755                    X=ObjectData.Coord(:,1);
3756                    Y=ObjectData.Coord(:,2);
3757                    if testphys
3758                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3759                    end
3760                    flagobj=~inpolygon(Xi,Yi,X,Y);%=0 inside the polygon, 1 outside                 
3761                elseif isequal(ObjectData.Style,'ellipse')
3762                    if testphys
3763                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3764                    end
3765                    RangeX=max(ObjectData.RangeX);
3766                    RangeY=max(ObjectData.RangeY);
3767                    X2Max=RangeX*RangeX;
3768                    Y2Max=RangeY*RangeY;
3769                    distX=(Xi-ObjectData.Coord(1,1));
3770                    distY=(Yi-ObjectData.Coord(1,2));
3771                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3772                elseif isequal(ObjectData.Style,'rectangle')
3773                    if testphys
3774                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3775                    end
3776                    distX=abs(Xi-ObjectData.Coord(1,1));
3777                    distY=abs(Yi-ObjectData.Coord(1,2));
3778                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3779                end
3780                if isequal(ObjectData.ProjMode,'mask_outside')
3781                    flagobj=~flagobj;
3782                end
3783                flag=flag & flagobj;
3784            end
3785        end
3786    end
3787end
3788% flag=~flag;
3789%mask name
3790RootPath=get(handles.RootPath,'String');
3791RootFile=get(handles.RootFile,'String');
3792if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
3793        RootFile(1)=[];
3794end
3795filebase=fullfile(RootPath,RootFile);
3796list=get(handles.masklevel,'String');
3797masknumber=num2str(length(list));
3798maskindex=get(handles.masklevel,'Value');
3799mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3800imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3801imflag=flipdim(imflag,1);
3802% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3803msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3804imwrite(imflag,mask_name,'BitDepth',8);
3805
3806%display the mask
3807%update_mask(handles,num_i1,num_j1)
3808figure;
3809vec=linspace(0,1,256);%define a linear greyscale colormap
3810map=[vec' vec' vec'];
3811colormap(map)
3812
3813image(imflag);
3814
3815%-------------------------------------------------------------------
3816%-------------------------------------------------------------------
3817%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3818
3819%------------------------------------------------------------------
3820
3821
3822
3823%------------------------------------------------------------------
3824% --- Executes on selection change in col_vec: choice of the color code.
3825%
3826function col_vec_Callback(hObject, eventdata, handles)
3827%------------------------------------------------------------------
3828% edit the choice for color code
3829list_code=get(handles.col_vec,'String');% list menu fields
3830index_code=get(handles.col_vec,'Value');% selected string index
3831col_code= list_code{index_code(1)}; % selected field
3832if isequal(col_code,'black') | isequal(col_code,'white')
3833   set(handles.slider1,'Visible','off')
3834   set(handles.slider2,'Visible','off')
3835   set(handles.colcode1,'Visible','off')
3836   set(handles.colcode2,'Visible','off')
3837   set(handles.AutoVecColor,'Visible','off')
3838   set_vec_col_bar(handles)
3839else
3840   set(handles.slider1,'Visible','on')
3841   set(handles.slider2,'Visible','on')
3842   set(handles.colcode1,'Visible','on')
3843   set(handles.colcode2,'Visible','on')
3844   set(handles.AutoVecColor,'Visible','on') 
3845   if isequal(col_code,'ima_cor')
3846       set(handles.AutoVecColor,'Value',0)%fixed scale by default
3847       set(handles.vec_col_bar,'Value',0)% 3 colors r,g,b by default
3848       set(handles.slider1,'Min',0);
3849       set(handles.slider1,'Max',1);
3850       set(handles.slider2,'Min',0);
3851       set(handles.slider2,'Max',1);
3852 %      set(handles.min_title_vec,'String','0')
3853       set(handles.max_vec,'String','1')
3854       set(handles.colcode1,'String','0.333')
3855       colcode1_Callback(hObject, eventdata, handles)
3856       set(handles.colcode2,'String','0.666')
3857       colcode2_Callback(hObject, eventdata, handles)
3858   else
3859       set(handles.AutoVecColor,'Value',1)%auto scale between min,max by default
3860       set(handles.vec_col_bar,'Value',1)% colormap 'jet' by default
3861       minval=get(handles.slider1,'Min');
3862       maxval=get(handles.slider1,'Max');
3863       set(handles.slider1,'Value',minval)
3864       set(handles.slider2,'Value',maxval)
3865       set_vec_col_bar(handles)
3866   end
3867%    slider_update(handles)
3868end
3869%replot the current graph
3870run0_Callback(hObject, eventdata, handles)
3871
3872
3873%----------------------------------------------------------------
3874% -- Executes on slider movement to set the color code
3875%
3876function slider1_Callback(hObject, eventdata, handles)
3877%------------------------------------------------------------------
3878slider1=get(handles.slider1,'Value');
3879min_val=str2num(get(handles.min_vec,'String'));
3880max_val=str2num(get(handles.max_vec,'String'));
3881col=min_val+(max_val-min_val)*slider1;
3882set(handles.colcode1,'String',num2str(col))
3883if(get(handles.slider2,'Value') < col)%move also the second slider at the same value if needed
3884    set(handles.slider2,'Value',col)
3885    set(handles.colcode2,'String',num2str(col))
3886end
3887colcode1_Callback(hObject, eventdata, handles)
3888
3889%----------------------------------------------------------------
3890% Executes on slider movement to set the color code
3891%----------------------------------------------------------------
3892function slider2_Callback(hObject, eventdata, handles)
3893slider2=get(handles.slider2,'Value');
3894min_val=str2num(get(handles.min_vec,'String'));
3895max_val=str2num(get(handles.max_vec,'String'));
3896col=min_val+(max_val-min_val)*slider2;
3897set(handles.colcode2,'String',num2str(col))
3898if(get(handles.slider1,'Value') > col)%move also the first slider at the same value if needed
3899    set(handles.slider1,'Value',col)
3900    set(handles.colcode1,'String',num2str(col))
3901end
3902colcode2_Callback(hObject, eventdata, handles)
3903
3904%----------------------------------------------------------------
3905%execute on return carriage on the edit box corresponding to slider 1
3906%----------------------------------------------------------------
3907function colcode1_Callback(hObject, eventdata, handles)
3908% col=str2num(get(handles.colcode1,'String'));
3909% set(handles.slider1,'Value',col)
3910set_vec_col_bar(handles)
3911update_plot(handles)
3912
3913%----------------------------------------------------------------
3914%execute on return carriage on the edit box corresponding to slider 2
3915%----------------------------------------------------------------
3916function colcode2_Callback(hObject, eventdata, handles)
3917% col=str2num(get(handles.colcode2,'String'));
3918% set(handles.slider2,'Value',col)
3919% slider2_Callback(hObject, eventdata, handles)
3920set_vec_col_bar(handles)
3921update_plot(handles)
3922%------------------------------------------------------------
3923%update the slider values after displaying vectors
3924%--------------------------------------------------------
3925% function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
3926% set(handles.slider1,'Min',minC)
3927% set(handles.slider1,'Max',maxC)
3928% set(handles.slider2,'Min',minC)
3929% set(handles.slider2,'Max',maxC)
3930% set(handles.min_title_vec,'String',num2str(minC))
3931% set(handles.max_vec,'String',num2str(maxC))
3932% if auto
3933%         set(handles.colcode1,'String',num2str(colcode1,3))%update display
3934%         set(handles.colcode2,'String',num2str(colcode2,3))
3935% end
3936% set(handles.slider1,'Value',colcode1)%update slider with constant display
3937% set(handles.slider2,'Value',colcode2)
3938% set_vec_col_bar(handles)
3939
3940
3941%-------------------------------------------------------
3942% --- Executes on button press in AutoVecColor.
3943%-------------------------------------------------------
3944function vec_col_bar_Callback(hObject, eventdata, handles)
3945set_vec_col_bar(handles)
3946
3947% %--------------------------------------------
3948% %update the display of color code for vectors
3949% %--------------------------------------------
3950% function set_vec_col_bar(handles)
3951% %get the image of the color display button 'vec_col_bar' in pixels
3952% uni=get(handles.vec_col_bar,'Unit');
3953% set(handles.vec_col_bar,'Unit','pixel')
3954% pos_vert=get(handles.vec_col_bar,'Position');
3955% set(handles.vec_col_bar,'Unit','Normalized')
3956% width=ceil(pos_vert(3));
3957% height=ceil(pos_vert(4));
3958% %get slider indications
3959% colcode.min=get(handles.slider1,'Min');
3960% colcode.max=get(handles.slider1,'Max');
3961% colcode.colcode1=get(handles.slider1,'Value');
3962% colcode.colcode2=get(handles.slider2,'Value');
3963% colcode.option=get(handles.vec_col_bar,'Value');
3964% colcode.auto=1;
3965% list_code=get(handles.col_vec,'String');% list menu fields
3966% index_code=get(handles.col_vec,'Value');% selected string index
3967% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
3968% vec_C=colcode.min+(colcode.max-colcode.min)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
3969% [colorlist,col_vec]=set_col_vec(colcode,vec_C);
3970% oneheight=ones(1,height);
3971% A1=colorlist(col_vec,1)*oneheight;
3972% A2=colorlist(col_vec,2)*oneheight;
3973% A3=colorlist(col_vec,3)*oneheight;
3974% A(:,:,1)=A1';
3975% A(:,:,2)=A2';
3976% A(:,:,3)=A3';
3977% set(handles.vec_col_bar,'Cdata',A)
3978
3979%--------------------------------------------------------
3980% --- Executes on button press in cal.
3981function cal_Callback(hObject, eventdata, handles)
3982
3983huvmat=get(handles.cal,'parent');%handles of the uvmat interface
3984UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3985%reinitialize the edit interface associated with uvmat
3986value=get(handles.cal,'Value');
3987if value
3988        set(handles.cal,'BackgroundColor',[1 1 0])
3989        %suppress the other options if MENULINE is chosen
3990        set(handles.zoom,'Value',0)
3991        set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3992        set(handles.create,'Value',0)
3993        set(handles.create,'BackgroundColor',[0 1 0])
3994        set(handles.create,'enable','off')     
3995        set(handles.edit_vect,'Value',0)
3996        set(handles.edit_vect,'enable','off')
3997        edit_vect_Callback(hObject, eventdata, handles)
3998        set(handles.edit,'Value',0)
3999        set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4000        set(handles.edit,'enable','off')
4001        set(handles.list_object,'Value',1)     
4002        % initiate display of GUI geometry_calib
4003        data=[]; %default
4004                if isfield(UvData,'CoordType')
4005            data.CoordType=UvData.CoordType;
4006        end
4007        %data.ParentButton=handles.cal; % transmit the handles of the calling button to the GUI geometry_calib
4008                pos=get(huvmat,'Position');
4009                pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
4010                pos(2)=pos(2)-0.02;
4011        [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
4012%         [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
4013%         [inputfile,idetect]=name_generator(filebase,num_i1,num_j1,Ext,NomType,1,num_i2,num_j2,SubDir);
4014                [UvData.hset_object,UvData.sethandles]=geometry_calib(handles,pos,FileName);% call the set_object interface     
4015        pos_uvmat=get(huvmat,'Position');
4016        %pos_cal(1:2)=UvData.CalOrigin + pos_uvmat(1:2);
4017        if isfield(UvData,'CalOrigin')
4018            pos_cal(1)=pos_uvmat(1)+UvData.CalOrigin(1)*pos_uvmat(3);
4019            pos_cal(2)=pos_uvmat(2)+UvData.CalOrigin(2)*pos_uvmat(4);
4020            pos_cal(3:4)=UvData.CalSize .* pos_uvmat(3:4);
4021            set(UvData.hset_object,'Position',pos_cal)
4022        end
4023        UvData.MouseAction='calib';
4024else
4025     UvData.MouseAction='none';     
4026     hgeometry_calib=findobj(allchild(0),'Name','geometry_calib');
4027%      if ~isempty(hgeometry_calib)
4028%          answer=questdlg('close the GUI geometry-calib?');
4029%          if isequal(answer,'Yes')
4030%              delete(hgeometry_calib)
4031%              set(handles.cal,'BackgroundColor',[0 1 0])
4032%          else
4033%              set(handles.cal,'Value',1)% keep the calibration function active
4034%          end
4035%      end
4036     set(handles.edit_vect,'enable','on')
4037     set(handles.edit,'enable','on')
4038     set(handles.create,'enable','on')
4039%      set(handles.LINE,'enable','on')
4040%      set(handles.PATCH,'enable','on')
4041%      set(handles.PLANE,'enable','on')
4042%      set(handles.VOLUME,'enable','on')
4043     %set(handles.makemask,'enable','on')
4044     hh=findobj(handles.axes3,'Tag','calib_points');
4045     if ~isempty(hh)
4046         delete(hh)
4047     end
4048     hhh=findobj(handles.axes3,'Tag','calib_marker');
4049     if ~isempty(hhh)
4050         delete(hhh)
4051     end   
4052end
4053set(huvmat,'UserData',UvData);
4054
4055%-------------------------------------------------------------
4056% --- Executes on selection change in transform_fct.
4057function transform_fct_Callback(hObject, eventdata, handles)
4058%-------------------------------------------------------------
4059global nb_builtin
4060
4061huvmat=get(handles.transform_fct,'parent');
4062menu=get(handles.transform_fct,'String');
4063ind_coord=get(handles.transform_fct,'Value');
4064coord_option=menu{ind_coord};
4065list_transform=get(handles.transform_fct,'UserData');
4066ff=functions(list_transform{end}); 
4067if isequal(coord_option,'more...');
4068    coord_fct='';
4069
4070%     if exist(profil_perso,'file')
4071%           h=load (profil_perso);
4072%          if isfield(h,'transform_fct')
4073%                 transform_fct=h.transform_fct;
4074%          end
4075%     end
4076    prompt = {'Enter the name of the transform function'};
4077    dlg_title = 'user defined transform';
4078    num_lines= 1;
4079    [FileName, PathName, filterindex] = uigetfile( ...
4080       {'*.m', ' (*.m)';
4081        '*.m',  '.m files '; ...
4082        '*.*', 'All Files (*.*)'}, ...
4083        'Pick a file', ff.file);
4084    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
4085        PathName(end)=[];
4086    end
4087    transform_selected =fullfile(PathName,FileName);
4088    if ~exist(transform_selected,'file')
4089%            msgbox_uvmat('ERROR',['procesing fct ' transform_selected ' not found'])
4090           return
4091    end
4092   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
4093   if ~isequal(ext_fct,'.m')
4094        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
4095        return
4096   end
4097   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
4098   ind_coord=get(handles.transform_fct,'Value');
4099   addpath(PathName)
4100   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
4101   set(handles.transform_fct,'UserData',list_transform)
4102   rmpath(PathName)
4103   % save the new menu in the personal file 'uvmat_perso.mat'
4104   dir_perso=prefdir;%personal Matalb directory
4105   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
4106   if exist(profil_perso,'file')
4107       for ilist=nb_builtin+1:numel(list_transform)
4108           ff=functions(list_transform{ilist});
4109           transform_fct{ilist-nb_builtin}=ff.file;
4110       end
4111        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
4112   end   
4113end
4114
4115%check the current path to the selected function
4116if isa(list_transform{ind_coord},'function_handle')
4117    func=functions(list_transform{ind_coord});
4118    set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
4119else
4120    set(handles.path_transform,'String','')
4121end
4122%CurrentPath=fileparts(which(coord_option));
4123% if ~isequal(PathName,CurrentPath)
4124%     addpath(PathName)
4125%     errormsg=check_functions;
4126%     msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
4127% end
4128%set(handles.path_transform,'String',fullfile(PathName,' ')); %show the path to the senlected function
4129set(handles.FixedLimits,'Value',0)
4130set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
4131
4132UvData=get(huvmat,'UserData');
4133
4134%delete drawn objects
4135hother=findobj('Tag','proj_object');%find all the proj objects
4136for iobj=1:length(hother)
4137    delete_object(hother(iobj))
4138end
4139hother=findobj('Tag','DeformPoint');%find all the proj objects
4140for iobj=1:length(hother)
4141    delete_object(hother(iobj))
4142end
4143hh=findobj('Tag','calib_points');
4144if ~isempty(hh)
4145    delete(hh)
4146end
4147hhh=findobj('Tag','calib_marker');
4148if ~isempty(hhh)
4149    delete(hhh)
4150end
4151if isfield(UvData,'Object')
4152    nbobject=length(UvData.Object);
4153    UvData.Object([2:nbobject])=[];
4154end
4155
4156%delete mask if it is displayed
4157if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
4158   UvData=rmfield(UvData,'MaskName'); %will impose mask refresh 
4159end
4160set(huvmat,'UserData',UvData)
4161run0_Callback(hObject, eventdata, handles)
4162
4163%--------------------------------------------
4164function histo1_menu_Callback(hObject, eventdata, handles)
4165%--------------------------------------------
4166%plot first histo
4167huvmat=get(handles.histo1_menu,'parent');
4168histo_menu=get(handles.histo1_menu,'String');
4169histo_value=get(handles.histo1_menu,'Value');
4170FieldName=histo_menu{histo_value};
4171UvData=get(huvmat,'UserData');
4172update_histo(handles.histo_u,huvmat,FieldName)
4173
4174%----------------------------------------------
4175function histo2_menu_Callback(hObject, eventdata, handles)
4176%----------------------------------------------
4177%plot second histo
4178huvmat=get(handles.histo2_menu,'parent');
4179histo_menu=get(handles.histo2_menu,'String');
4180histo_value=get(handles.histo2_menu,'Value');
4181FieldName=histo_menu{histo_value};
4182UvData=get(huvmat,'UserData');
4183update_histo(handles.histo_v,huvmat,FieldName)
4184
4185
4186%--------------------------------------------
4187%read the field .Fieldname stored in UvData and plot its histogram
4188function update_histo(haxes,huvmat,FieldName)
4189UvData=get(huvmat,'UserData');
4190
4191if ~isfield(UvData.Field,FieldName)
4192    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
4193    return
4194end
4195Field=UvData.Field;
4196FieldHisto=eval(['Field.' FieldName]);
4197if isfield(Field,'FF') & ~isempty(Field.FF) & isequal(size(Field.FF),size(FieldHisto))
4198    indsel=find(Field.FF==0);%find values marked as false
4199    if ~isempty(indsel)
4200        FieldHisto=FieldHisto(indsel);
4201    end
4202end
4203if isempty(Field)
4204    msgbox_uvmat('ERROR',['empty field ' FieldName])
4205else
4206    nxy=size(FieldHisto);
4207    Amin=double(min(min(min(FieldHisto))));%min of image
4208    Amax=double(max(max(max(FieldHisto))));%max of image
4209    if isequal(Amin,Amax)
4210       Histo.Txt=['uniform field =' num2str(Amin)];
4211    else
4212    Histo.ListVarName={FieldName,'histo'};
4213    if numel(nxy)==2
4214        Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
4215    else %color images
4216        Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
4217    end
4218    %unit
4219    units=[]; %default
4220    for ivar=1:numel(Field.ListVarName)   
4221        if strcmp(Field.ListVarName{ivar},FieldName)
4222            if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
4223                units=Field.VarAttribute{ivar}.units;
4224                break
4225            end
4226        end
4227    end
4228    if ~isempty(units)
4229        Histo.VarAttribute{1}.units=units;
4230    end
4231    eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
4232    for col=1:size(FieldHisto,3)
4233        B=FieldHisto(:,:,col);
4234        C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
4235       eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
4236    end
4237    set(haxes,'XLimMode','auto')%reset auto mode (after zoom effect)
4238    set(haxes,'YLimMode','auto')
4239    plot_field(Histo,haxes);
4240    end
4241end
4242
4243
4244
4245%------------------------------------------------
4246%CALLBACKS FOR PLOTTING PARAMETERS
4247%-------------------------------------------------
4248
4249%-----------------------------------------------------------------
4250function MinA_Callback(hObject, eventdata, handles)
4251%------------------------------------------
4252set(handles.AutoScal,'Value',1) %suppress auto mode
4253set(handles.AutoScal,'BackgroundColor',[1 1 0])
4254update_plot(handles)
4255
4256%-----------------------------------------------------------------
4257function MaxA_Callback(hObject, eventdata, handles)
4258%--------------------------------------------
4259set(handles.AutoScal,'Value',1) %suppress auto mode
4260set(handles.AutoScal,'BackgroundColor',[1 1 0])
4261update_plot(handles)
4262
4263%-----------------------------------------------
4264function AutoScal_Callback(hObject, eventdata, handles)
4265%--------------------------------------------
4266test=get(handles.AutoScal,'Value');
4267if test
4268    set(handles.AutoScal,'BackgroundColor',[1 1 0])
4269else
4270    set(handles.AutoScal,'BackgroundColor',[0.7 0.7 0.7])
4271    update_plot(handles);
4272%     set(handles.MinA,'String',num2str(ScalOut.MinA,3))
4273%     set(handles.MaxA,'String',num2str(ScalOut.MaxA,3))
4274end
4275
4276%-------------------------------------------------------------------
4277function BW_Callback(hObject, eventdata, handles)
4278%-------------------------------------------------------------------
4279update_plot(handles)
4280
4281%-------------------------------------------------------------------
4282function Contours_Callback(hObject, eventdata, handles)
4283%-------------------------------------------------------------------
4284val=get(handles.Contours,'Value');
4285if val==2
4286    set(handles.interval_txt,'Visible','on')
4287    set(handles.IncrA,'Visible','on')
4288else
4289    set(handles.interval_txt,'Visible','off')
4290    set(handles.IncrA,'Visible','off')
4291end
4292update_plot(handles)
4293
4294%-------------------------------------------------------------------
4295function IncrA_Callback(hObject, eventdata, handles)
4296%-------------------------------------------------------------------
4297update_plot(handles)
4298
4299%-------------------------------------------------------------------
4300function HideWarning_Callback(hObject, eventdata, handles)
4301%-------------------------------------------------------------------
4302update_plot(handles)
4303
4304%-------------------------------------------------------------------
4305function HideFalse_Callback(hObject, eventdata, handles)
4306%-------------------------------------------------------------------
4307update_plot(handles)
4308
4309%-------------------------------------------------------------------
4310function VecScale_Callback(hObject, eventdata, handles)
4311%-------------------------------------------------------------------
4312set(handles.AutoVec,'Value',1);
4313set(handles.AutoVec,'BackgroundColor',[1 1 0])
4314update_plot(handles)
4315
4316%-------------------------------------------------------------------
4317function AutoVec_Callback(hObject, eventdata, handles)
4318%-------------------------------------------------------------------
4319test=get(handles.AutoVec,'Value');
4320if test
4321    set(handles.AutoVec,'BackgroundColor',[1 1 0])
4322else
4323    update_plot(handles);
4324    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4325    set(handles.AutoVec,'BackgroundColor',[0.7 0.7 0.7])
4326end
4327
4328%-------------------------------------------------------
4329% --- Executes on selection change in decimate4 (nb_vec/4).
4330%-------------------------------------------------------
4331function decimate4_Callback(hObject, eventdata, handles)
4332update_plot(handles)
4333
4334
4335%-------------------------------------------------------
4336% --- Executes on selection change in color_code menu
4337%-------------------------------------------------------
4338function color_code_Callback(hObject, eventdata, handles)
4339set_vec_col_bar(handles)
4340update_plot(handles);
4341
4342%-------------------------------------------------------
4343% --- Executes on button press in AutoVecColor.
4344%-------------------------------------------------------
4345function AutoVecColor_Callback(hObject, eventdata, handles)
4346test=get(handles.AutoVecColor,'Value');
4347if test
4348    set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
4349else
4350    update_plot(handles);
4351    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4352    set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
4353end
4354%set_vec_col_bar(handles)
4355
4356%-------------------------------------------------------
4357% --- Executes on selection change in max_vec.
4358%-------------------------------------------------------
4359function min_vec_Callback(hObject, eventdata, handles)
4360max_vec_Callback(hObject, eventdata, handles)
4361
4362% --- Executes on selection change in max_vec.
4363function max_vec_Callback(hObject, eventdata, handles)
4364set(handles.AutoVecColor,'Value',1)
4365AutoVecColor_Callback(hObject, eventdata, handles)
4366min_val=str2num(get(handles.min_vec,'String'));
4367max_val=str2num(get(handles.max_vec,'String'));
4368slider1=get(handles.slider1,'Value');
4369slider2=get(handles.slider2,'Value');
4370colcode1=min_val+(max_val-min_val)*slider1;
4371colcode2=min_val+(max_val-min_val)*slider2;
4372set(handles.colcode1,'String',num2str(colcode1))
4373set(handles.colcode2,'String',num2str(colcode2))
4374update_plot(handles);
4375
4376%-------------------------------------------------------------------
4377%update the display of color code for vectors
4378function set_vec_col_bar(handles)
4379%-------------------------------------------------------------------
4380%get the image of the color display button 'vec_col_bar' in pixels
4381set(handles.vec_col_bar,'Unit','pixel');
4382pos_vert=get(handles.vec_col_bar,'Position');
4383set(handles.vec_col_bar,'Unit','Normalized');
4384width=ceil(pos_vert(3));
4385height=ceil(pos_vert(4));
4386
4387%get slider indications
4388list=get(handles.color_code,'String');
4389ichoice=get(handles.color_code,'Value');
4390colcode.ColorCode=list{ichoice};
4391colcode.MinC=str2num(get(handles.min_vec,'String'));
4392colcode.MaxC=str2num(get(handles.max_vec,'String'));
4393test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
4394if test3color
4395    colcode.colcode1=str2num(get(handles.colcode1,'String'));
4396    colcode.colcode2=str2num(get(handles.colcode2,'String'));
4397end
4398% colcode.option=get(handles.vec_col_bar,'Value');
4399colcode.FixedCbounds=0;
4400% list_code=get(handles.col_vec,'String');% list menu fields
4401% index_code=get(handles.col_vec,'Value');% selected string index
4402% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
4403colcode.FixedCbounds=1;
4404vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
4405[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4406oneheight=ones(1,height);
4407A1=colorlist(col_vec,1)*oneheight;
4408A2=colorlist(col_vec,2)*oneheight;
4409A3=colorlist(col_vec,3)*oneheight;
4410A(:,:,1)=A1';
4411A(:,:,2)=A2';
4412A(:,:,3)=A3';
4413set(handles.vec_col_bar,'Cdata',A)
4414
4415
4416%-------------------------------------------------------------------
4417function [PlotType,ScalOut]=update_plot(handles)
4418%-------------------------------------------------------------------
4419haxes= handles.axes3;
4420AxeData=get(haxes,'UserData');
4421PlotParam=read_plot_param(handles);
4422[PlotType,PlotParamOut]= plot_field(AxeData,haxes,PlotParam,1);
4423write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4424
4425%-------------------------------------------------------------------
4426% --- Executes on button press in grid.
4427function grid_Callback(hObject, eventdata, handles)
4428%-------------------------------------------------------------------
4429huvmat=get(handles.create,'parent');
4430UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4431
4432%suppress the other options if grid is chosen
4433set(handles.create,'Value',0)
4434set(handles.create,'BackgroundColor',[0 1 0])
4435set(handles.edit_vect,'Value',0)
4436edit_vect_Callback(hObject, eventdata, handles)
4437set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4438set(handles.edit_vect,'Value',0) 
4439edit_vect_Callback(hObject, eventdata, handles)
4440set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4441set(handles.list_object,'Value',1)     
4442set(handles.cal,'Value',0)
4443set(handles.cal,'BackgroundColor',[0 1 0])   
4444
4445%prepare display of the set_grid GUI
4446data.fixedtitle=1;
4447FileName=read_file_boxes(handles);
4448[hset_object,UvData.sethandles]=set_grid(FileName);% call the set_object interface
4449set(huvmat,'UserData',UvData);
4450
4451
4452%-------------------------------------------------------------------
4453% --- Executes on selection change in edit.
4454function edit_Callback(hObject, eventdata, handles)
4455%-------------------------------------------------------------------
4456huvmat=get(handles.list_object,'parent');
4457UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4458test=get(handles.edit,'Value');
4459if test
4460    UvData.MouseAction='edit_object';
4461    set(handles.edit,'BackgroundColor',[1,1,0]) 
4462    %suppress the other options
4463    set(handles.zoom,'Value',0)
4464    zoom_Callback(hObject, eventdata, handles)
4465    set(handles.create,'Value',0)
4466    set(handles.create,'BackgroundColor',[0 1 0])
4467%     set(handles.LINE,'Value',0)
4468%     set(handles.LINE,'BackgroundColor',[0 1 0])
4469%     set(handles.PATCH,'Value',0)
4470%     set(handles.PATCH,'BackgroundColor',[0 1 0])
4471%     set(handles.PLANE,'Value',0)
4472%     set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
4473%     set(handles.VOLUME,'Value',0)
4474%     set(handles.VOLUME,'BackgroundColor',[0 1 0])
4475    set(handles.edit_vect,'Value',0)
4476    edit_vect_Callback(hObject, eventdata, handles) 
4477    set(handles.cal,'Value',0)
4478    set(handles.cal,'BackgroundColor',[0 1 0])   
4479    %set(handles.grid,'Value',0)
4480    %set(handles.grid,'BackgroundColor',[0 1 0])
4481    list_object_Callback(hObject, eventdata, handles)
4482else
4483    UvData.MouseAction='none';
4484    set(handles.edit,'BackgroundColor',[0.7,0.7,0.7])   
4485end
4486set(huvmat,'UserData',UvData);
4487
4488%--------------------------------------------------------
4489% --- Executes on selection change in list_object.
4490%--------------------------------------------------------
4491function list_object_Callback(hObject, eventdata, handles)
4492huvmat=get(handles.list_object,'parent');
4493UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4494list_str=get(handles.list_object,'String');
4495IndexObj=get(handles.list_object,'Value');
4496
4497if ~(length(UvData.Object)>=IndexObj);
4498    return
4499end
4500ObjectData=UvData.Object{IndexObj};
4501ObjectData.desable_open=1; % desable the OPEN option in the set_object GUI (editing mode)
4502if isequal(get(handles.edit,'Value'),0)
4503    ObjectData.desable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4504end
4505PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4506ZBounds=0; % default
4507    if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
4508        ZBounds(1)=UvData.ZMin; %minimum for the Z slider
4509        ZBounds(2)=UvData.ZMax;%maximum for the Z slider
4510    end
4511AxeData.hset_object=set_object(ObjectData,PlotHandles,ZBounds);% call the set_object interface,
4512pos_uvmat=get(huvmat,'Position');
4513if isfield(UvData,'SetObjectOrigin')
4514pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4515pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4516set(AxeData.hset_object,'Position',pos_set_object)
4517end
4518hother=findobj('Tag','proj_object');%find all the proj objects
4519for iobj=1:length(hother)
4520    if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
4521        set(hother(iobj),'EdgeColor','b')
4522        if isequal(get(hother(iobj),'FaceColor'),'m')
4523            set(hother(iobj),'FaceColor','b')
4524        end
4525    elseif isequal(get(hother(iobj),'Type'),'image')
4526           Acolor=get(hother(iobj),'CData');
4527           Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4528           set(hother(iobj),'CData',Acolor);
4529    else
4530         set(hother(iobj),'Color','b')
4531    end
4532    set(hother(iobj),'Selected','off')
4533end
4534hother=findobj('Tag','DeformPoint');
4535set(hother,'Color','b');
4536set(hother,'Selected','off')   
4537if isfield(ObjectData,'HandlesDisplay')
4538    for iview=1:length(ObjectData.HandlesDisplay)
4539        if ishandle(ObjectData.HandlesDisplay(iview))
4540            uistack(ObjectData.HandlesDisplay(iview),'top')
4541            linetype=get(ObjectData.HandlesDisplay(iview),'Type');
4542            if isequal(linetype,'line')
4543                set(ObjectData.HandlesDisplay(iview),'Color','m'); %set the selected object to magenta color
4544            elseif isequal(linetype,'rectangle')
4545                set(ObjectData.HandlesDisplay(iview),'EdgeColor','m'); %set the selected object to magenta color
4546            elseif isequal(linetype,'patch')
4547                set(ObjectData.HandlesDisplay(iview),'FaceColor','m'); %set the selected object to magenta color
4548            end
4549            SubObjectData=get(ObjectData.HandlesDisplay(iview),'UserData');
4550            if isfield(SubObjectData,'SubObject')& ishandle(SubObjectData.SubObject)
4551                uistack(SubObjectData.SubObject,'top')
4552                for iobj=1:length(SubObjectData.SubObject)
4553                    hsub=SubObjectData.SubObject(iobj);
4554                    if isequal(get(hsub,'Type'),'rectangle')
4555                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4556                    elseif isequal(get(hsub,'Type'),'image')
4557                       Acolor=get(hsub,'CData');
4558                       Acolor(:,:,1)=Acolor(:,:,3);
4559                       set(hsub,'CData',Acolor);
4560                    else
4561                        set(hsub,'Color','m')
4562                    end
4563                end
4564            end
4565            if isfield(SubObjectData,'DeformPoint')& ishandle(SubObjectData.DeformPoint)
4566                set(SubObjectData.DeformPoint,'Color','m')
4567            end
4568        end
4569    end
4570end
4571
4572%------------------------------------------------------
4573% --- Executes on button press in Menu/Export/field in workspace.
4574%------------------------------------------------------
4575function MenuExportField_Callback(hObject, eventdata, handles)
4576
4577global CurData
4578huvmat=get(handles.RootPath,'parent');
4579CurData=get(huvmat,'UserData');
4580evalin('base','global CurData')%make CurData global in the workspace
4581display(['UserData of uvmat :'])
4582evalin('base','CurData') %display CurData in the workspace
4583commandwindow;
4584
4585%------------------------------------------------------
4586% --- Executes on button press in Menu/Export/extract figure.
4587%------------------------------------------------------
4588function MenuExport_plot_Callback(hObject, eventdata, handles)
4589huvmat=get(handles.MenuExport_plot,'parent');
4590UvData=get(huvmat,'UserData');
4591hfig=figure;
4592newaxes=copyobj(handles.axes3,hfig);
4593map=colormap(handles.axes3);
4594colormap(map);%transmit the current colormap to the zoom fig
4595colorbar
4596
4597
4598% --------------------------------------------------------------------
4599function Insert_Callback(hObject, eventdata, handles)
4600
4601
4602% --------------------------------------------------------------------
4603function MenuRun_Callback(hObject, eventdata, handles)
4604% --------------------------------------------------------------------
4605
4606% --------------------------------------------------------------------
4607function MenuHelp_Callback(hObject, eventdata, handles)
4608% --------------------------------------------------------------------
4609path_to_uvmat=which ('uvmat');% check the path of uvmat
4610pathelp=fileparts(path_to_uvmat);
4611helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4612if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4613else
4614    addpath (fullfile(pathelp,'uvmat_doc'))
4615    web(helpfile);
4616end
4617
4618% --------------------------------------------------------------------
4619function MenuOpen_Callback(hObject, eventdata, handles)
4620% --------------------------------------------------------------------
4621% --------------------------------------------------------------------
4622function MenuOpen_1_Callback(hObject, eventdata, handles)
4623% --------------------------------------------------------------------
4624% --------------------------------------------------------------------
4625function MenuExport_Callback(hObject, eventdata, handles)
4626% --------------------------------------------------------------------
4627
4628% --------------------------------------------------------------------
4629function MenuExportMovie_Callback(hObject, eventdata, handles)
4630% --------------------------------------------------------------------
4631set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4632huvmat=get(handles.run0,'parent');
4633UvData=get(huvmat,'UserData');
4634[xx,xx,FileBase]=read_file_boxes(handles);
4635 %read the current input file name
4636prompt = {'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)'};
4637dlg_title = 'select properties of the output avi movie';
4638num_lines= 1;
4639nbfield_cell=get(handles.last_i,'String');
4640def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4641answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4642aviname=answer{1};
4643fps=str2num(answer{2});
4644% check for existing file with output name aviname
4645if exist(aviname,'file')
4646    backup=aviname;
4647    testexist=2;
4648    while testexist==2
4649        backup=[backup '~'];
4650        testexist=exist(backup,'file');     
4651    end
4652    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4653    if isequal(success,1)
4654        delete(aviname)%delete existing file
4655    else
4656        msgbox_uvmat('ERROR',message)
4657        return
4658    end
4659end
4660%create avi open
4661aviobj=avifile(aviname,'Compression','None','fps',fps);
4662
4663%display first view for tests
4664newfig=figure;
4665newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
4666set(newaxes,'Tag','movieaxes')
4667nbpix=[512 384]*str2num(answer{3});
4668set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4669set(newaxes,'Position',eval(answer{4}));
4670map=colormap(handles.axes3);
4671colormap(map);%transmit the current colormap to the zoom fig
4672msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4673        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
4674UvData.Object{1}.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
4675set(huvmat,'UserData',UvData);
4676increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
4677set(handles.STOP,'Visible','on')
4678set(handles.speed,'Visible','on')
4679set(handles.speed_txt,'Visible','on')
4680set(handles.RunMovie,'BusyAction','queue')
4681
4682imin=str2num(get(handles.i1,'String'));
4683imax=str2num(answer{5});
4684% if isfield(UvData,'Time')
4685htitle=get(newaxes,'Title');
4686xlim=get(newaxes,'XLim');
4687ylim=get(newaxes,'YLim');
4688set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4689time_str=get(handles.abs_time,'String');
4690set(htitle,'String',['t=' time_str])
4691set(handles.speed,'Value',1)
4692for i=1:imax
4693    if get(handles.speed,'Value')~=0 & isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4694            runpm(hObject,eventdata,handles,increment)
4695            drawnow
4696            time_str=get(handles.abs_time,'String');
4697            if ishandle(htitle)
4698             set(htitle,'String',['t=' time_str])
4699            end
4700            mov=getframe(newfig);
4701            aviobj=addframe(aviobj,mov);
4702    end
4703end
4704aviobj=close(aviobj);
4705UvData.Object{1}.plotaxes=handles.axes3;
4706set(huvmat,'UserData',UvData);
4707msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4708
4709
4710% ------------------------------------------------------------------
4711function MenuCalib_Callback(hObject, eventdata, handles)
4712set(handles.TOOLS_txt,'Visible','on')
4713set(handles.frame_tools,'Visible','on')
4714set(handles.cal,'Visible','on')
4715set(handles.cal,'Value',1)
4716cal_Callback(hObject,eventdata,handles)
4717
4718% ------------------------------------------------------------------
4719function MenuMask_Callback(hObject, eventdata, handles)
4720set(handles.TOOLS_txt,'Visible','on')
4721set(handles.frame_tools,'Visible','on')
4722set(handles.create,'Visible','on')
4723set(handles.create,'Value',1)
4724set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
4725set(handles.save_mask,'Visible','on')
4726set(handles.masklevel,'Visible','on')
4727if isequal(get(handles.z_index,'Visible'),'on')
4728    nb_slice=str2num(get(handles.nb_slice,'String'));
4729    for ilist=1:nb_slice
4730        list_index{ilist,1}=num2str(ilist);
4731    end   
4732    set(handles.masklevel,'String',list_index)
4733    val=str2num(get(handles.z_index,'String'));
4734    if val<=nb_slice
4735        set(handles.masklevel,'Value',val)
4736    end
4737else
4738    set(handles.masklevel,'String',{'1'})
4739    set(handles.masklevel,'Value',1)
4740end
4741if ishandle(handles.UVMAT_title)
4742    delete(handles.UVMAT_title)
4743end
4744huvmat=get(handles.create,'parent');
4745UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4746set(handles.zoom,'Value',0)
4747set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4748set(handles.edit_vect,'Value',0)
4749edit_vect_Callback(hObject, eventdata, handles)
4750set(handles.edit,'Value',0)
4751set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4752set(handles.edit_vect,'Value',0) 
4753edit_vect_Callback(hObject, eventdata, handles)
4754set(handles.cal,'Value',0)
4755set(handles.cal,'BackgroundColor',[0 1 0])
4756
4757%initiate the GUI set_object
4758data.TITLE='MASK';
4759if isfield(UvData,'CoordType')
4760    data.CoordType=UvData.CoordType;
4761end
4762if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
4763    data.YMax=UvData.Mesh;
4764elseif isfield(UvData.Field,'AX')&&isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
4765    np=size(UvData.Field.A);
4766    meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
4767    meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
4768    data.YMax=max(meshx,meshy);
4769    data.DX=max(meshx,meshy);
4770end
4771data.Coord=[0 0 0]; %default
4772PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
4773[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
4774pos_uvmat=get(huvmat,'Position');
4775if isfield(UvData,'SetObjectOrigin')
4776    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4777    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4778    set(hset_object,'Position',pos_set_object)
4779end
4780list_object=get(handles.list_object,'String');
4781if ~isempty(list_object)
4782    set(handles.list_object,'Value',length(list_object))
4783end
4784UvData.MouseAction='create_object';
4785set(huvmat,'UserData',UvData);
4786
4787% ------------------------------------------------------------------
4788%-- open the GUI set_grid.fig to create grid
4789function MenuGrid_Callback(hObject, eventdata, handles)
4790set(handles.TOOLS_txt,'Visible','on')
4791set(handles.frame_tools,'Visible','on')
4792grid_Callback(hObject,eventdata,handles)
4793
4794%----------------------------------------------------------------
4795% open the GUI 'series'
4796%----------------------------------------------------------------
4797function MenuSeries_Callback(hObject, eventdata, handles)
4798%-------------------------------------------------------------------
4799
4800[param.FileName]=read_file_boxes(handles);
4801if isequal(get(handles.SubField,'Value'),1)
4802    FileName_1=read_file_boxes_1(handles);%
4803    if ~isequal(FileName_1,param.FileName)
4804        param.FileName_1=FileName_1;
4805    end
4806end
4807param.NomType=get(handles.FileIndex,'UserData');
4808param.NomType_1=get(handles.FileIndex_1,'UserData');
4809param.comp_input=get(handles.fix_pair,'Value');
4810huvmat=get(handles.MenuSeries,'parent');
4811UvData=get(huvmat,'UserData');
4812if isfield(UvData,'Time')
4813    param.Time=UvData.XmlData.Time;
4814end
4815if isequal(get(handles.scan_i,'Value'),1)
4816    param.incr_i=str2num(get(handles.increment_scan,'String'));
4817elseif isequal(get(handles.scan_j,'Value'),1)
4818    param.incr_j=str2num(get(handles.increment_scan,'String'));
4819end
4820param.list_fields=get(handles.Fields,'String');% list menu fields
4821param.list_fields(1)=[]; %suppress  'image' option
4822param.index_fields=get(handles.Fields,'Value');% selected string index
4823if param.index_fields>1
4824    param.index_fields=param.index_fields-1;
4825end
4826param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
4827param.list_fields_1(1)=[]; %suppress  'image' option
4828param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
4829if param.index_fields_1>1
4830    param.index_fields_1=param.index_fields_1-1;
4831end
4832param.civ1=get(handles.civ1,'Value');
4833param.civ2=get(handles.civ2,'Value');
4834param.interp1=get(handles.interp1,'Value');
4835param.interp2=get(handles.interp2,'Value');
4836param.filter1=get(handles.filter1,'Value');
4837param.filter2=get(handles.filter2,'Value');
4838param.menu_coord_str=get(handles.transform_fct,'String');
4839param.menu_coord_val=get(handles.transform_fct,'Value');
4840
4841series(param); %run the series interface
4842
4843% ------------------------------------------------------------------
4844% -- open the GUI civ.fig for civx (PIV)
4845% ------------------------------------------------------------------
4846function MenuPIV_Callback(hObject, eventdata, handles)
4847 
4848[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
4849num1=stra2num(get(handles.i1,'String'));
4850num2=stra2num(get(handles.i2,'String'));
4851num_a=stra2num(get(handles.j1,'String'));
4852num_b=stra2num(get(handles.j2,'String'));
4853NomType=get(handles.FileIndex,'UserData');
4854ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4855if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4856    ind_opening=2;% propose 'fix' as the default option
4857% +read the current netcdf rootfile
4858    Data=nc2struct(FileName,[]);
4859    if isfield(Data,'fix') & isequal(Data.fix,1)
4860        ind_opening=3;
4861    end
4862    if isfield(Data,'patch') & isequal(Data.patch,1)
4863        ind_opening=4;
4864    end
4865    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4866        ind_opening=5;
4867    end
4868    if isfield(Data,'fix2') & isequal(Data.fix2,1)
4869        ind_opening=6;
4870    end
4871end     
4872varargin{1}=filebase;
4873varargin{2}=NomType;
4874varargin{3}=num1;
4875varargin{4}=num2;
4876varargin{5}=num_a;
4877varargin{6}=num_b;
4878varargin{7}=SubDir;
4879varargin{8}=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4880varargin{11}=ext;
4881civ(varargin);% interface de civ(not in the uvmat file)
4882
4883% ------------------------------------------------------------------
4884function MenuTools_Callback(hObject, eventdata, handles)
4885
4886% ------------------------------------------------------------------
4887function MenuEdit_Callback(hObject, eventdata, handles)
4888
4889%--------------------------------------------------------------------------
4890function enable_transform(handles,state)
4891set(handles.transform_fct,'Visible',state)
4892set(handles.TRANSFORM_txt,'Visible',state)   
4893set(handles.transform_fct,'Visible',state) 
4894set(handles.path_transform,'Visible',state)
4895set(handles.pxcmx_txt,'Visible',state)
4896set(handles.pxcmy_txt,'Visible',state)
4897set(handles.pxcm,'Visible',state)
4898set(handles.pycm,'Visible',state)
4899
4900%------------------------------------------------------------------------
4901function MenuEditVectors_Callback(hObject, eventdata, handles)
4902%------------------------------------------------------------------------
4903set(handles.edit_vect,'Visible','on')
4904set(handles.edit_vect,'Value',1)
4905edit_vect_Callback(hObject, eventdata, handles)
4906
4907% --------------------------------------------------------------------
4908function Menupoints_Callback(hObject, eventdata, handles)
4909data.Style='points';
4910data.ProjMode='projection';%default
4911create_object(data,handles)
4912
4913% --------------------------------------------------------------------
4914function Menuline_Callback(hObject, eventdata, handles)
4915% set(handles.create,'Visible','on')
4916% set(handles.create,'Value',1)
4917% LINE_Callback(hObject,eventdata,handles)
4918data.Style='line';
4919data.ProjMode='projection';%default
4920create_object(data,handles)
4921
4922%------------------------------------------------------------------------
4923function Menupolyline_Callback(hObject, eventdata, handles)
4924%------------------------------------------------------------------------
4925data.Style='polyline';
4926data.ProjMode='projection';%default
4927create_object(data,handles)
4928
4929%------------------------------------------------------------------------
4930function Menupolygon_Callback(hObject, eventdata, handles)
4931%------------------------------------------------------------------------
4932data.Style='polygon';
4933data.ProjMode='inside';%default
4934create_object(data,handles)
4935
4936%------------------------------------------------------------------------
4937function Menurectangle_Callback(hObject, eventdata, handles)
4938%------------------------------------------------------------------------
4939data.Style='rectangle';
4940data.ProjMode='inside';%default
4941create_object(data,handles)
4942
4943%------------------------------------------------------------------------
4944function Menuellipse_Callback(hObject, eventdata, handles)
4945%------------------------------------------------------------------------
4946data.Style='ellipse';
4947data.ProjMode='inside';%default
4948create_object(data,handles)
4949
4950% ------------------------------------------------------------------
4951function Menuplane_Callback(hObject, eventdata, handles)
4952% set(handles.create,'Visible','on')
4953% set(handles.create,'Value',1)
4954% PLANE_Callback(hObject,eventdata,handles)
4955data.Style='plane';
4956data.ProjMode='projection';%default
4957
4958create_object(data,handles)
4959
4960% ------------------------------------------------------------------
4961function Menuvolume_Callback(hObject, eventdata, handles)
4962set(handles.create,'Visible','on')
4963set(handles.create,'Value',1)
4964VOLUME_Callback(hObject,eventdata,handles)
4965
4966%------------------------------------------------------------------------
4967function MenuBrowseObject_Callback(hObject, eventdata, handles)
4968%------------------------------------------------------------------------
4969%get the object file
4970[FileName, PathName, filterindex] = uigetfile( ...
4971       {'*.xml;*.mat', ' (*.xml,*.mat)';
4972       '*.xml',  '.xml files '; ...
4973        '*.mat',  '.mat matlab files '}, ...
4974        'Pick a file',get(handles.RootPath,'String'));
4975fileinput=[PathName FileName];%complete file name
4976testblank=findstr(fileinput,' ');%look for blanks
4977if ~isempty(testblank)
4978    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
4979    return
4980end
4981sizf=size(fileinput);
4982if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
4983
4984%read the file
4985t=xmltree(fileinput);
4986data=convert(t);
4987PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4988hset_object=findobj(allchild(0),'Name','set_object');
4989if ~isempty(hset_object)
4990    delete(hset_object)% delete existing version of set_object
4991end
4992[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
4993UvData.MouseAction='create_object';
4994set(handles.uvmat,'UserData',UvData)
4995
4996%------------------------------------------------------------------------
4997function create_object(data,handles)
4998%------------------------------------------------------------------------
4999hset_object=findobj(allchild(0),'Name','set_object');
5000if ~isempty(hset_object)
5001    delete(hset_object)% delete existing version of set_object
5002end
5003UvData=get(handles.uvmat,'UserData');
5004if isfield(UvData,'CoordType')
5005    data.CoordType=UvData.CoordType;
5006end
5007if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
5008    data.RangeX=UvData.Mesh;
5009    data.RangeY=UvData.Mesh;
5010    data.DX=UvData.Mesh;
5011    data.DY=UvData.Mesh;
5012elseif isfield(UvData.Field,'AX')&& isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
5013    np=size(UvData.Field.A);
5014    meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
5015    meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
5016    data.RangeY=max(meshx,meshy);
5017    data.RangeX=max(meshx,meshy);
5018    data.DX=max(meshx,meshy);
5019end
5020data.Coord=[0 0 0]; %default
5021if isfield(data,'Style') && isequal(data.Style,'line')
5022    if isfield(data,'DX')
5023        data.Coord=[[0 0 0];[data.DX 0 0]]; %default
5024    else
5025        data.Coord=[[0 0 0];[1 0 0]]; %default
5026    end
5027end
5028%data.ParentButton=handles.create;
5029if ishandle(handles.UVMAT_title)
5030    delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered
5031end
5032PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
5033[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
5034UvData.MouseAction='create_object';
5035set(handles.uvmat,'UserData',UvData)
5036set(handles.zoom,'Value',0)
5037zoom_Callback(handles.uvmat, [], handles)
5038
Note: See TracBrowser for help on using the repository browser.