source: trunk/src/uvmat.m @ 81

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

several bug repairs:
option movie backward introduced for uvmat

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