source: trunk/src/uvmat.m @ 75

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

plot_field: bug repaired for profiles
view_field: introduction of a edit uicontrol for text display (needs to be used)
rescaling of the figure to optimize space
uvmat: small bugs repaired, in particular for 3D fields
TODO: adapt proj_field for lines in 3D space

introduce volume objects and interpolate on 3D grid (griddata3)

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