source: trunk/src/uvmat.m @ 98

Last change on this file since 98 was 98, checked in by gostiaux, 14 years ago

test commit from bigone

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