source: trunk/src/uvmat.m @ 356

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