source: trunk/src/uvmat.m @ 159

Last change on this file since 159 was 159, checked in by sommeria, 13 years ago

bug in civ corrected: civ2 was not lauched for Windows system
various bugs corrections and cleaning

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