source: trunk/src/uvmat.m @ 106

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

Bug fix

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