source: trunk/src/uvmat.m @ 65

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

name_generator: remove unneeded indices at output
civ.m: & introduced at the end of system command lines (beginning by !) to allow matlab operations during civ in run mode
uvmat.m: debugging in dealing with projections
prove image pair movies superposed to velocity vectors
mouse: put circles along detected vectors

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