source: trunk/src/uvmat.m @ 353

Last change on this file since 353 was 353, checked in by sommeria, 12 years ago

functions adapted to Matlab version 2009 (~ replaced by 'tild' in function output)
svn test put under 'try' (error observed)
fullfile_uvmat introduced, aimed at replacing name_generator

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