source: trunk/src/uvmat.m @ 72

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

ima2vol: write image volumes in 16 bits (test for civ_3D)
plot-text removed: put as a sub-function of plot_field
uvmat: movie stops in case of error in reding files
bug fixes for reading 3D vel fields

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