source: trunk/src/uvmat.m @ 67

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

civ: RUN civ lounched out of the Matlab work space. RUN and BATCH now runned by a unique sub-function lounch.m.
FiLE PARAM.xml modified to provide different paths for Batch and Run !!!!!
RUN_FIX: minor error message modif
geometry_calib: calib point editing by the mouse
improvement of the interactions between the different GUIs. Close function...

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