source: trunk/src/uvmat.m @ 60

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

-plot projections on a new specific GUI view_field, to avoid the multiplication of active figures
-introduce a ruler in uvmat (in menu/Tools), to measure distances and angles
-insert automatic detection of points for geometric calibration: tool 'detect_grid'. Four points, deliminating the grid to determine, must be marked with the mouse, as well as the physical grid. Then the points inside are automatically detected.
-reading plane positions in ImaDoc? improved to deal with volume scans

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