source: trunk/src/uvmat.m @ 118

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

geometry_calib is now updated when a new image is viewed by uvmat
imadoc2struct corrected for time reading

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