source: trunk/src/uvmat.m @ 383

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

bugs corrected , new Matlab patch introduced for patch2

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