source: trunk/src/uvmat.m @ 248

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

various modifications

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