source: trunk/src/uvmat.m @ 27

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

possibilite de créer une grille physique dans geometry_calib (le faire apres avoir introduit les points sur l'image avec la souris)
petites corrections mineures sur les autres fichiers

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