source: trunk/src/uvmat.m @ 59

Last change on this file since 59 was 59, checked in by sommeria, 11 years ago

upgrade and cleaning in uvmat: run min plus does not modify the field counters in case of error
nomtype2pair: comments added
get_field: minor cleaning

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