source: trunk/src/uvmat.m @ 307

Last change on this file since 307 was 307, checked in by sommeria, 12 years ago

bug fixed in the browser of civ + bug fix for the plot of objects

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