source: trunk/src/uvmat.m @ 29

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

read_imadoc suppressed (obsolete, replaced by imadoc2struct)
update_imadoc: bug repaired: existing xml file was erased
various cleaning (deals with non existing input file for series and uvmat)

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