source: trunk/src/uvmat.m @ 86

Last change on this file since 86 was 86, checked in by sommeria, 14 years ago

sub_field: bug corrected for comparing velocity and scalar (eg vort)
uvmat: bug corrected for comparing velocity and scalar
set_grid.fig: unused callbacks desactivated$
civ.m: bug correction for the new civx (civAll): no grid ='none' instead of 'n'

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