source: trunk/src/uvmat.m @ 57

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

small bug repaired in civ (spurious call to first_i)
image pair movie improved in uvmat

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