source: trunk/src/uvmat.m @ 177

Last change on this file since 177 was 177, checked in by sommeria, 13 years ago

bug with mouse object editing resolved. Display feature 'satus' for PIV task advancement introduced. Various bug repair and cleaning

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