source: trunk/src/uvmat.m @ 297

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

various

File size: 209.6 KB
Line 
1%'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
2%------------------------------------------------------------------------
3% function huvmat=uvmat(input)
4%
5%OUTPUT
6% huvmat=current handles of the GUI uvmat.fig
7%%
8%
9%INPUT:
10% input: input file name (if character chain), or input image matrix to
11% visualize, or Matlab structure representing  netcdf fields (with fields
12% ListVarName....)
13%
14%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
15%  Copyright Joel Sommeria,  2008, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr.
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%     This open is part of the toolbox UVMAT.
18%
19%     UVMAT is free software; you can redistribute it and/or modify
20%     it under the terms of the GNU General Public License as published by
21%     the Free Software Foundation; either version 2 of the License, or
22%     (at your option) any later version.
23%
24%     UVMAT is distributed in the hope that it will be useful,
25%     but WITHOUT ANY WARRANTY; without even the implied warranty of
26%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27%     GNU General Public License (open UVMAT/COPYING.txt) for more details.
28%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
29%
30% Information stored on the interface:
31%    'Strings' of all edit boxes and menus: get(handles.Tag,'String')
32%    'Values' of all menus and toggle buttons: get(handles.Tag,'Value')
33%     Matlab structure 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)
52%          .VelType_1: last velocity type (VelType, civ2...) for the second input series
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
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)
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
153%            .CurrentRectZoom: current rectangle used for CheckZoom
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
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
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})%
238set(handles.list_object_1,'ButtonDownFcn',{@list_object_1_Callback,handles})% allows activation of lis_object_1_callback with right mouse click
239set(handles.list_object_2,'ButtonDownFcn',{@list_object_2_Callback,handles})
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'));
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,
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);
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
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')
305    if ~isempty(errormsg)
306        msgbox_uvmat('WARNING',errormsg)
307    end
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
315        if isfield(input,'TimeIndex')
316            set(handles.i1,num2str(input.TimeIndex))
317        end
318        if isfield(input,'FieldsString')
319%             set(handles.Fields,'Value',1)
320            UvData.FieldsString=input.FieldsString;
321        end
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
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];
335        testinputfield=1;
336    end
337else
338   if ishandle(handles.UVMAT_title)
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};...
344           {['SVN revision : ' num2str(svn_info.cur_rev)]};...
345           errormsg]);
346   end
347end
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
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')
368        set(handles.list_object_1,'Visible','on')
369        set(handles.frame_object,'Visible','on')
370        if ~isempty(errormsg)
371            msgbox_uvmat('ERROR',errormsg)
372        end
373    end
374end
375
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)
436%------------------------------------------------------------------------
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)
443%------------------------------------------------------------------------
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)
450%------------------------------------------------------------------------
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)
457%------------------------------------------------------------------------
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)
464%------------------------------------------------------------------------
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)
471%------------------------------------------------------------------------
472if ~exist(fileinput,'file')
473    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
474    return
475end
476[RootPath,RootFile,i1,i2,str_a,str_b,ext,NomType,SubDir]=name2display(fileinput);%extract information from the file name
477ext_test=''; %default
478if ~isempty(ext) % if a file extension is detected
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
491    elseif isequal(lower(ext),'.avi')%case of avi movie file
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')
561        set(handles.list_object_1,'Visible','on')
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
621set(handles.FixVelType,'Value',0); %desactivate fixed veltype
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')
668    if length(imainfo)>1
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
671    else
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
674    end
675else
676    set(handles.num_Npx,'String','');%fills nbre of pixels x box
677    set(handles.num_Npy,'String','');%fills nbre of pixels x box
678end
679set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image
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 
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
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
797        if ~get(handles.CheckFixLimits,'Value')
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
826
827%display warning message
828if ~isequal(warntext,'')
829    msgbox_uvmat('WARNING',warntext);
830end
831
832% set default options in menu 'Fields'
833
834if ~testima
835    testcivx=0;
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
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
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
850        if ~testcivx
851            set(handles.Fields,'Value',1) % set menu to 'get_field...
852            set(handles.Fields,'String',{'get_field...'})
853            col_vec={'get_field...'};
854        end
855        set(handles.ListColorScalar,'String',col_vec)
856    end
857end
858set(handles.uvmat,'UserData',UvData)
859
860%% set index navigation options and refresh plots
861set(handles.RootPath,'BackgroundColor',[1 1 1])
862drawnow
863set_scan_options(hObject, eventdata, handles)
864
865%% update list of recent files in the menubar
866MenuFile=[{FileName};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')];
868   
869for ifile=1:length(MenuFile)
870    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
871    eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',MenuFile{ifile});'])
872end
873dir_perso=prefdir;
874profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
875if exist(profil_perso,'file')
876    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
877else
878    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
879end
880
881%------------------------------------------------------------------------
882%--- Set index navigation options for new series input and refresh plot
883%------------------------------------------------------------------------
884function set_scan_options(hObject, eventdata, handles)
885
886%  set the corresponding index navigation options
887NomType=get(handles.FileIndex,'UserData');       
888NomType_1=get(handles.FileIndex_1,'UserData');
889last_i_str=get(handles.last_i,'String');
890nbfield=str2num(last_i_str{1});
891if numel(last_i_str)==2
892    nbfield=min(nbfield,str2num(last_i_str{2}));
893end 
894state_j='off'; %default
895scan_option='i';%default
896NomTypeRaw=regexprep(NomType(2:end), '-', '');
897if numel(regexp(NomTypeRaw,'\D'))>=1
898        state_j='on';
899        if isequal(nbfield,1)
900            scan_option='j'; %scan j index by default if nbfield=1               
901        end
902end
903if ~isempty(NomType_1)
904    NomTypeRaw=regexprep(NomType_1(2:end), '-', '');
905    if numel(regexp(NomTypeRaw,'\D'))>=1
906            state_j='on';
907            if isequal(nbfield,1)
908                scan_option='j';                 
909            end           
910    end
911end
912if isequal(scan_option,'i')
913     set(handles.scan_i,'Value',1)
914     scan_i_Callback(hObject, eventdata, handles);
915else
916     set(handles.scan_j,'Value',1)
917     scan_j_Callback(hObject, eventdata, handles);
918end
919set(handles.scan_j,'Visible',state_j)
920set(handles.j1,'Visible',state_j)
921set(handles.j2,'Visible',state_j)
922set(handles.last_j,'Visible',state_j);
923set(handles.frame_j,'Visible',state_j);
924set(handles.j_text,'Visible',state_j);
925if strcmp(state_j,'on')
926    set(handles.fix_pair,'Visible','on')
927else
928    set(handles.fix_pair,'Visible','off')
929end
930
931%% view the field 
932run0_Callback(hObject, eventdata, handles); %view field
933mask_test=get(handles.mask_test,'value');
934if mask_test
935    MaskData=get(handles.mask_test,'UserData');
936    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
937          delete(MaskData.maskhandle)    %delete old mask
938    end
939    mask_test_Callback(hObject, eventdata, handles)
940end
941
942%------------------------------------------------------------------------
943% --- Executes on the menu Open/Browse_1 for the second input field,
944%     search the files, recognize their type according to their name and fill the rootfile input windows
945function MenuBrowse_1_Callback(hObject, eventdata, handles)
946%------------------------------------------------------------------------
947% huvmat=get(handles.run0,'parent');
948UvData=get(handles.uvmat,'UserData');
949
950RootPath=get(handles.RootPath,'String');
951[FileName, PathName, filterindex] = uigetfile( ...
952       {'*.xml;*.xls;*.civ;*.jpg;*.png;*.avi;*.AVI;*.nc;*.cmx;*.fig;*.log;*.dat', ' (*.xml,*.xls,*.civ, *.jpg,*.png, *.avi,*.nc,*.cmx ,*.fig,*.log,*.dat)';
953       '*.xml',  '.xml files '; ...
954        '*.xls',  '.xls files '; ...
955        '*.civ',  '.civ files '; ...
956        '*.jpg','.jpg image files'; ...
957        '*.png','.png image files'; ...
958        '*.avi;*.AVI','.avi movie files'; ...
959        '*.nc','.netcdf files'; ...
960        '*.cdf','.netcdf files'; ...
961        '*.cmx','.cmx text files';...
962        '*.cmx2','.cmx2 text files';...
963        '*.fig','.fig files (matlab fig)';...
964        '*.log','.log text files ';...
965        '*.dat','.dat text files ';...
966        '*.*',  'All Files (*.*)'}, ...
967        'Pick a second file for comparison',RootPath);
968fileinput_1=[PathName FileName];%complete file name
969sizf=size(fileinput_1);
970if (~ischar(fileinput_1)||~isequal(sizf(1),1)),return;end
971
972% refresh the current displayed field
973display_file_name_1(hObject,eventdata,handles,fileinput_1)
974
975%update list of recent files in the menubar
976MenuFile_1=fileinput_1;
977MenuFile_2=get(handles.MenuFile_1,'Label');
978MenuFile_3=get(handles.MenuFile_2,'Label');
979MenuFile_4=get(handles.MenuFile_3,'Label');
980MenuFile_5=get(handles.MenuFile_4,'Label');
981set(handles.MenuFile_1,'Label',MenuFile_1)
982set(handles.MenuFile_2,'Label',MenuFile_2)
983set(handles.MenuFile_3,'Label',MenuFile_3)
984set(handles.MenuFile_4,'Label',MenuFile_4)
985set(handles.MenuFile_5,'Label',MenuFile_5)
986set(handles.MenuFile_1_1,'Label',MenuFile_1)
987set(handles.MenuFile_2_1,'Label',MenuFile_2)
988set(handles.MenuFile_3_1,'Label',MenuFile_3)
989set(handles.MenuFile_4_1,'Label',MenuFile_4)
990set(handles.MenuFile_5_1,'Label',MenuFile_5)
991dir_perso=prefdir;
992profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
993if exist(profil_perso,'file')
994    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
995else
996    txt=ver('MATLAB');
997    Release=txt.Release;
998    relnumb=str2double(Release(3:4));
999    if relnumb >= 14
1000        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1001    else
1002        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1003    end
1004end
1005
1006% -----------------------------------------------------------------------
1007% --- Open again as second field the file whose name has been recorded in MenuFile_1
1008function MenuFile_1_1_Callback(hObject, eventdata, handles)
1009% -----------------------------------------------------------------------
1010fileinput_1=get(handles.MenuFile_1_1,'Label');
1011display_file_name_1(hObject,eventdata,handles,fileinput_1)
1012
1013% -----------------------------------------------------------------------
1014% --- Open again as second field the file whose name has been recorded in MenuFile_2
1015function MenuFile_2_1_Callback(hObject, eventdata, handles)
1016% -----------------------------------------------------------------------
1017fileinput_1=get(handles.MenuFile_2_1,'Label');
1018display_file_name_1(hObject,eventdata,handles,fileinput_1)
1019
1020% -----------------------------------------------------------------------
1021% --- Open again as second field the file whose name has been recorded in MenuFile_3
1022function MenuFile_3_1_Callback(hObject, eventdata, handles)
1023% -----------------------------------------------------------------------
1024fileinput_1=get(handles.MenuFile_3_1,'Label');
1025display_file_name_1(hObject,eventdata,handles,fileinput_1)
1026
1027% -----------------------------------------------------------------------
1028% --- Open again as second field the file whose name has been recorded in MenuFile_4
1029function MenuFile_4_1_Callback(hObject, eventdata, handles)
1030% -----------------------------------------------------------------------
1031fileinput_1=get(handles.MenuFile_4_1,'Label');
1032display_file_name_1(hObject,eventdata,handles,fileinput_1)
1033
1034% -----------------------------------------------------------------------
1035% --- Open again as second field the file whose name has been recorded in MenuFile_5
1036function MenuFile_5_1_Callback(hObject, eventdata, handles)
1037% -----------------------------------------------------------------------
1038fileinput_1=get(handles.MenuFile_5_1,'Label');
1039display_file_name_1(hObject,eventdata,handles,fileinput_1)
1040
1041%------------------------------------------------------------------------
1042% fills the edit boxes RootPath_1, RootFile_1,NomType_1...from an input file name 'fileinput_1'
1043%------------------------------------------------------------------------
1044function display_file_name_1(hObject,eventdata,handles,fileinput_1)
1045
1046%[path,name,ext]=fileparts(fileinput_1);
1047[RootPath_1,RootFile_1,field_count,str2,str_a,str_b,FileExt_1,NomType_1,SubDir_1]=name2display(fileinput_1);
1048nbfield_1=1; %default
1049ext_test=FileExt_1;%default
1050form=imformats(FileExt_1(2:end));
1051if ~isempty(form) % if the extension corresponds to an image format recognized by Matlab
1052    imainfo=imfinfo(fileinput_1); 
1053    nbfield_1=length(imainfo);
1054    ext_test='.image';
1055elseif isequal(lower(FileExt_1),'.avi')
1056    info=aviinfo(fileinput_1);
1057    nbfield_1=info.NumFrames;
1058    ext_test='.image';
1059end
1060
1061%open directly fig or text files
1062switch ext_test
1063    case {'.civ','.log','.cmx','.cmx2','.txt'}  %display text file
1064        edit(fileinput) 
1065        return
1066    case '.fig'                           %display matlab figure
1067        hfig=open(fileinput);
1068        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
1069        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
1070        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
1071        return
1072    case {'.xml','.xls'}                % edit xml or Excel files
1073       heditxml=editxml(fileinput);
1074       return
1075    case {'.image','.nc','.cdf'}
1076%         set(handles.FileIndex,'UserData',NomType_1);
1077    otherwise
1078        msgbox_uvmat(['invalid input file extension ' FileExt_1 ' for uvmat'],'ERROR')
1079        return
1080end
1081
1082% test for image series in a single file and synchronise file indices of the two series
1083if nbfield_1 >1 %case of image with multiple frames
1084    if nbfield_1 < num_i1
1085        msgbox_uvmat('ERROR','current frame index beyond the input movie length')
1086        return
1087    else
1088        NomType_1='*'; %indicate a set of indexed frames within a single file
1089        filename_new=fileinput_1;
1090    end
1091else  % cases of data files   
1092    RootPath=get(handles.RootPath,'String');
1093    RootFile=get(handles.RootFile,'String');
1094    FileBase=fullfile(RootPath,RootFile);
1095    FileBase_1=fullfile(RootPath_1,RootFile_1);
1096    if isequal(FileBase,FileBase_1)
1097        filename_new=fileinput_1;
1098    else       
1099        num_i1=stra2num(get(handles.i1,'String'));%get the current file indices from counters
1100        num_j1=stra2num(get(handles.j1,'String'));
1101        num_i2=stra2num(get(handles.i2,'String'));
1102        num_j2=stra2num(get(handles.j2,'String'));
1103        [filename_new,idetect]=...
1104           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
1105        indices=''; %default
1106        if ~idetect
1107            msgbox_uvmat('ERROR','second input file with indices corresponding to the first one does not exist')
1108            return
1109        end
1110    end
1111end
1112set(handles.FileIndex_1,'UserData',NomType_1);
1113
1114% make visible and fill the second raw of edit boxes
1115set(handles.RootPath_1,'Visible','on')
1116set(handles.RootFile_1,'Visible','on')
1117set(handles.SubDir_1,'Visible','on');
1118set(handles.FileIndex_1,'Visible','on');
1119set(handles.FileExt_1,'Visible','on');
1120[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
1121if isequal(FileBase,FileBase_1)
1122    set(handles.RootPath_1,'String','"')
1123    set(handles.RootFile_1,'String','"');
1124else
1125    set(handles.RootPath_1,'String',RootPath_1)
1126    set(handles.RootFile_1,'String',['/' RootFile_1]);
1127end
1128if  isequal(SubDir_1,'')
1129     set(handles.SubDir_1,'String','');
1130     FileBaseSub_1=FileBase_1;
1131else 
1132    set(handles.SubDir_1,'String',['/' SubDir_1]);
1133    FileBaseSub_1=fullfile(FileBase_1,SubDir_1);
1134end
1135indices=filename_new(length(FileBaseSub_1)+1:end);
1136indices(end-length(FileExt_1)+1:end)=[]; %remove extension
1137set(handles.FileIndex_1,'String',indices)
1138set(handles.FileIndex_1,'UserData',NomType_1)
1139set(handles.FileExt_1,'String',FileExt_1);
1140
1141% % default choice of fields
1142%set(handles.SubField,'Visible','on')
1143set(handles.SubField,'Value',1)
1144RootPath_1_Callback(hObject,eventdata,handles); 
1145
1146%-----------------------------------------------------------------------
1147% --- Called by action in RootPath_1 edit box
1148function RootPath_1_Callback(hObject,eventdata,handles)
1149% -----------------------------------------------------------------------
1150update_rootinfo_1(hObject,eventdata,handles)
1151
1152%-----------------------------------------------------------------------
1153% --- Called by action in RootFile_1 edit box
1154function RootFile_1_Callback(hObject, eventdata, handles)
1155% -----------------------------------------------------------------------
1156update_rootinfo_1(hObject,eventdata,handles)
1157
1158%------------------------------------------------------------------------
1159% --- Called by action in FileIndex_1 edit box
1160function FileIndex_1_Callback(hObject, eventdata, handles)
1161%------------------------------------------------------------------------
1162run0_Callback(hObject, eventdata, handles)
1163
1164%------------------------------------------------------------------------
1165% --- Update information about a new second field series (indices to scan, timing,
1166%     calibration from an xml file, then refresh current plots
1167function update_rootinfo_1(hObject,eventdata,handles) %A REVOIR
1168% -----------------------------------------------------------------------
1169set(handles.RootPath_1,'BackgroundColor',[1 1 0])% indicate active program by yellow color
1170drawnow
1171UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
1172UvData.NewSeries=1; %flag for run0: begin a new series
1173
1174[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes_1(handles);
1175if ~exist(FileName,'file')
1176    msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
1177end
1178set(handles.FixVelType,'Value',0); %desactivate fixed veltype
1179nbfield_1=[];%default
1180nburst_1=[];%default
1181XmlData.Time=[];
1182XmlData.GeometryCalib=[];%default
1183TimeUnit=[];
1184if isfield(UvData,'TimeUnit')
1185    TimeUnit=UvData.TimeUnit;
1186end
1187TimeUnit_1=[];
1188hhh='';%default, test for  movie reading with mmreader
1189imainfo=[];
1190if isequal(lower(FileExt),'.avi') %.avi file
1191    imainfo=aviinfo([FileBase FileIndices FileExt]);
1192    nbfield_1=imainfo.NumFrames;
1193    nburst_1=1;
1194    set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
1195    time=(0:1/imainfo.FramesPerSecond:(imainfo.NumFrames-1)/imainfo.FramesPerSecond)';
1196    ColorType=imainfo.ImageType;%='truecolor' for color images
1197    hhh=which('mmreader');
1198elseif ~isempty(imformats(FileExt(2:end)))|| isequal(FileExt,'.vol')
1199    if ~isequal(SubDir,'')
1200        RootFile=get(handles.RootFile,'String');
1201        imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
1202    else
1203        imainfo=imfinfo([FileBase FileIndices FileExt]);
1204    end
1205    ColorType=imainfo.ColorType;%='truecolor' for color images
1206    if length(imainfo) >1 %case of image with multiple frames
1207        nbfield_1=length(imainfo);
1208        nburst_1=1;
1209    end
1210end
1211if ~strcmp(hhh,'')&& mmreader.isPlatformSupported()% if the function is found (recent version of matlab)
1212    UvData.MovieObject_1=mmreader([FileBase FileIndices FileExt]);
1213elseif isfield(UvData,'MovieObject_1')
1214    UvData=rmfield(UvData,'MovieObject_1');
1215end
1216if ~isempty(imainfo)% (an image has been introduced as second fierld input)
1217    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
1218        if  isfield(imainfo,'Width') && isfield(imainfo,'Height')
1219            set(handles.num_Npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box
1220            set(handles.num_Npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box
1221        else
1222            set(handles.num_Npx,'String','');%fills nbre of pixels x box
1223            set(handles.num_Npy,'String','');%fills nbre of pixels x box
1224        end
1225        set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image
1226    end
1227end
1228% find scaling parameters
1229filexml=[FileBase '.xml'];
1230fileciv=[FileBase '.civ'];
1231warntext='';%default warning text
1232if exist(filexml,'file')
1233    [XmlData,warntext]=imadoc2struct(filexml);
1234    if ~isempty(warntext)
1235        msgbox_uvmat('WARNING',warntext)
1236    end
1237    if isfield(XmlData,'Camera')
1238        if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
1239            TimeUnit=XmlData.Camera.TimeUnit;
1240        end
1241    end
1242elseif exist(fileciv,'file')% if .civ file found
1243    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
1244    GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
1245    GeometryCalib.Tx=0;
1246    GeometryCalib.Ty=0;
1247    GeometryCalib.Tz=1;
1248    GeometryCalib.dpx=1;
1249    GeometryCalib.dpy=1;
1250    GeometryCalib.sx=1;
1251    GeometryCalib.Cx=0;
1252    GeometryCalib.Cy=0;
1253    GeometryCalib.f=1;
1254    GeometryCalib.kappa1=0;
1255    GeometryCalib.CoordUnit='cm';
1256    XmlData.GeometryCalib=GeometryCalib;
1257    if error==2, warntext=['no file ' FileBase '.civ'];
1258    elseif error==1, warntext='inconsistent number of fields in the .civ file';
1259    end
1260   
1261    set(handles.num_Npx,'String',num2str(npx));%fills nbre of pixels x box
1262    set(handles.num_Npy,'String',num2str(npy));%fills nbre of pixels y box
1263    set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
1264    set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
1265    set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
1266    set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
1267end   
1268if ~isempty(TimeUnit_1) && ~isequal(TimeUnit_1,TimeUnit)
1269        msgbox_uvmat('WARNING','the time units for the second series differs from the first one')
1270end
1271       
1272% store last index in handles.lat_i and .last_j
1273if ~isempty(XmlData.Time)
1274    nbfield_1=size(XmlData.Time,1);
1275    nburst_1=size(XmlData.Time,2);   
1276end
1277last_i_cell=get(handles.last_i,'String');
1278if isempty(nbfield_1)
1279    last_i_cell{2}='';
1280else
1281    last_i_cell{2}=num2str(nbfield_1);
1282end
1283set(handles.last_i,'String',last_i_cell)
1284last_j_cell=get(handles.last_j,'String');
1285if isempty(nburst_1)
1286     last_j_cell{2}='';
1287else
1288     last_j_cell{2}=num2str(nburst_1);
1289end
1290set(handles.last_j,'String',last_j_cell);
1291if ~isequal(last_i_cell{1},last_i_cell{2}) || ~isequal(last_j_cell{1},last_j_cell{2})
1292        msgbox_uvmat('WARNING','the numbers of input file of the second series differs from the first one')
1293end
1294
1295% store calibration data
1296GeometryCalib=XmlData.GeometryCalib;
1297if isempty(GeometryCalib)
1298    if isfield(UvData, 'GeometryCalib_1')
1299        UvData=rmfield(UvData,'GeometryCalib_1');
1300    end
1301else
1302    UvData.GeometryCalib_1=GeometryCalib;
1303    if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||...
1304        (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0))
1305        set(handles.pxcm,'String','var')
1306        set(handles.pycm,'String','var')
1307    else
1308        if isfield(GeometryCalib,'fx_fy')
1309            pixcmx=GeometryCalib.fx_fy(1);
1310            pixcmy=GeometryCalib.fx_fy(2);
1311            set(handles.pxcm,'String',num2str(pixcmx))
1312            set(handles.pycm,'String',num2str(pixcmy))
1313        end
1314    end
1315end
1316UvData.XmlData_1=XmlData;
1317set(handles.uvmat,'UserData',UvData)%update the data attached to the uvmat interface
1318
1319if ~isequal(warntext,'')
1320    msgbox_uvmat('WARNING',warntext)
1321end
1322
1323set(handles.RootPath_1,'BackgroundColor',[1 1 1])% signa the end the input operation
1324drawnow
1325
1326set_scan_options(hObject, eventdata, handles)
1327
1328%---------------------------------------------------
1329% switch file index scanning options scan_i and scan_j in an exclusive way
1330function scan_i_Callback(hObject, eventdata, handles)
1331%---------------------------------------------------
1332if get(handles.scan_i,'Value')==1
1333    set(handles.scan_i,'BackgroundColor',[1 1 0])
1334    set(handles.scan_j,'Value',0)
1335%     set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1336else
1337    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1338    set(handles.scan_j,'Value',1)
1339%     set(handles.scan_j,'BackgroundColor',[1 1 0])
1340end
1341scan_j_Callback(hObject, eventdata, handles)
1342
1343%-------------------------------------------------------------------
1344% switch file index scanning options scan_i and scan_j in an exclusive way
1345function scan_j_Callback(hObject, eventdata, handles)
1346%-------------------------------------------------------------------
1347if get(handles.scan_j,'Value')==1
1348    set(handles.scan_j,'BackgroundColor',[1 1 0])
1349    set(handles.scan_i,'Value',0)
1350    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1351    NomType=get(handles.FileIndex,'UserData');
1352    switch NomType
1353    case {'_i_j1-j2','#_ab','%3dab'},% pair with j index
1354        set(handles.fix_pair,'Visible','on')% option fixed pair on/off made visible (choice of avaible pair with buttons + and - if ='off')
1355    otherwise
1356        set(handles.fix_pair,'Visible','off')
1357    end
1358else
1359    set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1360    set(handles.scan_i,'Value',1)
1361    set(handles.scan_i,'BackgroundColor',[1 1 0])
1362    set(handles.fix_pair,'Visible','off')
1363end
1364
1365%-------------------------------------------------------------------
1366function i1_Callback(hObject, eventdata, handles)
1367%-------------------------------------------------------------------
1368set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])
1369NomType=get(handles.FileIndex,'UserData');
1370num1=stra2num(get(handles.i1,'String'));
1371num2=stra2num(get(handles.i2,'String'));
1372num_a=stra2num(get(handles.j1,'String'));
1373num_b=stra2num(get(handles.j2,'String'));
1374indices=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1375set(handles.FileIndex,'String',indices)
1376set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])
1377if get(handles.SubField,'Value')==1
1378    NomType_1=get(handles.FileIndex_1,'String');
1379     FileExt_1=get(handles.FileExt_1,'String');
1380    [P,F,str1,str2,str_a,str_b,Ext,NomType_1]=name2display(['xx' NomType_1 FileExt_1]);
1381     indices=name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
1382     set(handles.FileIndex_1,'String',indices)
1383     set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7])
1384end
1385%Run0_Callback(hObject, eventdata, handles)
1386
1387%-------------------------------------------------------------------
1388function i2_Callback(hObject, eventdata, handles)
1389set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])
1390i1_Callback(hObject, eventdata, handles)
1391%-------------------------------------------------------------------
1392
1393%-------------------------------------------------------------------
1394function j1_Callback(hObject, eventdata, handles)
1395set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])
1396i1_Callback(hObject, eventdata, handles)
1397%-------------------------------------------------------------------
1398
1399%-------------------------------------------------------------------
1400function j2_Callback(hObject, eventdata, handles)
1401set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])
1402i1_Callback(hObject, eventdata, handles)
1403%-------------------------------------------------------------------
1404
1405%-------------------------------------------------------------------
1406function slices_Callback(hObject, eventdata, handles)
1407%-------------------------------------------------------------------
1408if get(handles.slices,'Value')==1
1409    set(handles.slices,'BackgroundColor',[1 1 0])
1410    set(handles.nb_slice,'Visible','on')
1411    set(handles.z_text,'Visible','on')
1412    set(handles.z_index,'Visible','on')
1413    nb_slice_Callback(hObject, eventdata, handles)
1414else
1415    set(handles.nb_slice,'Visible','off')
1416    set(handles.slices,'BackgroundColor',[0.7 0.7 0.7])
1417    set(handles.z_text,'Visible','off')
1418    set(handles.z_index,'Visible','off')
1419    set(handles.masklevel,'Value',1)
1420    set(handles.masklevel,'String',{'1'})
1421end
1422
1423%-------------------------------------------------------------------
1424function nb_slice_Callback(hObject, eventdata, handles)
1425%-------------------------------------------------------------------
1426nb_slice_str=get(handles.nb_slice,'String');
1427if isequal(nb_slice_str,'volume')
1428    num=stra2num(get(handles.j1,'String'));
1429    last_j=get(handles.last_j,'String');
1430    nbslice=str2double(last_j{1});
1431else
1432    num=str2double(get(handles.i1,'String'));
1433    nbslice=str2double(get(handles.nb_slice,'String'));
1434end
1435z=mod(num-1,nbslice)+1;
1436set(handles.z_index,'String',num2str(z))
1437for ilist=1:nbslice
1438    list_index{ilist,1}=num2str(ilist);
1439end   
1440set(handles.masklevel,'String',list_index)
1441set(handles.masklevel,'Value',z)
1442
1443%------------------------------------------------------------------------
1444% --- Executes on button press in view_xml.
1445function view_xml_Callback(hObject, eventdata, handles)
1446%------------------------------------------------------------------------
1447[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
1448option=get(handles.view_xml,'String');
1449if isequal(option,'view .xml')
1450    FileXml=[FileBase '.xml'];
1451    heditxml=editxml(FileXml);
1452end
1453
1454%------------------------------------------------------------------------
1455% --- Executes on button press in mask_test.
1456function mask_test_Callback(hObject, eventdata, handles)
1457%------------------------------------------------------------------------
1458%case of view mask selection
1459if isequal(get(handles.mask_test,'Value'),1)
1460    [FF,RootPath,FileBase]=read_file_boxes(handles);
1461    num_i1=stra2num(get(handles.i1,'String'));
1462    num_j1=stra2num(get(handles.j1,'String'));
1463    currentdir=pwd; 
1464    cd(RootPath);
1465    maskfiles=dir('*_*mask_*.png');%look for a mask file
1466    cd(currentdir);%come back to the working directory
1467    mdetect=0;
1468    if ~isempty(maskfiles)
1469        for ilist=1:length(maskfiles)
1470            maskname=maskfiles(ilist).name;% take the first mask file in the list
1471            [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname);
1472            [Path2,Name,ext]=fileparts(maskname);
1473            Namedouble=double(Name);
1474            val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1475            ind_mask=findstr('mask',Name);
1476            i=ind_mask-1;
1477            while val(i)==0 && i>0
1478                i=i-1;
1479            end
1480            nbmask_str=str2num(Name(i+1:ind_mask-1));
1481            if ~isempty(nbmask_str)
1482                nbslice(ilist)=nbmask_str; % number of different masks (slices)
1483            end
1484        end
1485        if isequal(min(nbslice),max(nbslice))
1486            nbslice=nbslice(1);
1487        else
1488            msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory')
1489            return
1490        end
1491        if ~isempty(nbslice) && Name(i)=='_'
1492            Mask.Base=[FileBase Name(i:ind_mask+3)];
1493            Mask.NbSlice=nbslice;
1494            num_i1=mod(num_i1-1,nbslice)+1;
1495            Mask.NomType=regexprep(Mask_NomType{1},'0','');%remove '0' in nom type for masks
1496            maskname=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);%
1497            mdetect=exist(maskname,'file');
1498            if mdetect
1499                set(handles.nb_slice,'String',Name(i+1:ind_mask-1));
1500                set(handles.nb_slice,'BackgroundColor',[1 1 0])
1501                set(handles.mask_test,'UserData',Mask);
1502                set(handles.mask_test,'BackgroundColor',[1 1 0])
1503                if nbslice > 1
1504                    set(handles.slices,'value',1)
1505                    slices_Callback(hObject, eventdata, handles)
1506                end
1507            end
1508        end
1509    end
1510    errormsg=[];%default
1511    if mdetect==0
1512        [FileName, PathName, filterindex] = uigetfile( ...
1513            {'*.png', ' (*.png)';
1514            '*.png',  '.png files '; ...
1515            '*.*', 'All Files (*.*)'}, ...
1516            'Pick a mask file *.png',FileBase);
1517        maskname=fullfile(PathName,FileName);
1518        if ~exist(maskname,'file')
1519            errormsg='no file browsed';
1520        end
1521        [RootDir,RootFile,x1,x2,xa,xb,xext,Mask.NomType]=name2display(maskname);
1522        Mask.Base=fullfile(RootDir,RootFile);
1523        Mask.NbSlice=1;
1524        set(handles.mask_test,'UserData',Mask);
1525        set(handles.mask_test,'BackgroundColor',[1 1 0])
1526    end
1527    if isempty(errormsg)
1528        errormsg=update_mask(handles,num_i1,num_j1);
1529    end
1530    if ~isempty(errormsg)
1531            set(handles.mask_test,'Value',0)
1532            set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1533     end
1534else
1535    MaskData=get(handles.mask_test,'UserData');
1536    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1537          delete(MaskData.maskhandle)   
1538    end
1539    set(handles.mask_test,'UserData',[])   
1540    %huvmat=get(handles.mask_test,'parent');
1541    UvData=get(handles.uvmat,'UserData');
1542    if isfield(UvData,'MaskName')
1543        UvData=rmfield(UvData,'MaskName');
1544        set(handles.uvmat,'UserData',UvData)
1545    end
1546    set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1547end
1548
1549%-------------------------------------------------------------------
1550function errormsg=update_mask(handles,num_i1,num_j1)
1551%-------------------------------------------------------------------
1552errormsg=[];%default
1553MaskData=get(handles.mask_test,'UserData');
1554if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1555    uistack(MaskData.maskhandle,'top');
1556end
1557num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
1558MaskName=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
1559huvmat=get(handles.mask_test,'parent');
1560UvData=get(huvmat,'UserData');
1561
1562%update mask image if the mask is new
1563if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
1564    UvData.MaskName=MaskName; %update the recorded name on UvData
1565    set(huvmat,'UserData',UvData);
1566    if ~exist(MaskName,'file')
1567        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1568            delete(MaskData.maskhandle)   
1569        end
1570    else
1571        %read mask image
1572        Mask.AName='image';
1573        Mask.A=imread(MaskName);
1574        npxy=size(Mask.A);
1575        test_error=0;
1576        if length(npxy)>2
1577            errormsg=[MaskName ' is not a grey scale image'];
1578            return
1579        elseif ~isa(Mask.A,'uint8')
1580            errormsg=[MaskName ' is not a 8 bit grey level image'];
1581            return
1582        end
1583        Mask.AX=[0.5 npxy(2)-0.5];
1584        Mask.AY=[npxy(1)-0.5 0.5 ];
1585        Mask.CoordUnit='pixel';
1586        if isequal(get(handles.slices,'Value'),1)
1587           NbSlice=str2num(get(handles.nb_slice,'String'));
1588           num_i1=str2num(get(handles.i1,'String'));
1589           Mask.ZIndex=mod(num_i1-1,NbSlice)+1;
1590        end
1591        %px to phys or other transform on field
1592         menu_transform=get(handles.transform_fct,'String');
1593        choice_value=get(handles.transform_fct,'Value');
1594        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1595        transform_list=get(handles.transform_fct,'UserData');
1596        transform=transform_list{choice_value};
1597        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1598            if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1599                Calib=UvData.XmlData.GeometryCalib;
1600                Mask=transform(Mask,UvData.XmlData);
1601            end
1602        end
1603        flagmask=Mask.A < 200;
1604       
1605        %make brown color image
1606        imflag(:,:,1)=0.9*flagmask;
1607        imflag(:,:,2)=0.7*flagmask;
1608        imflag(:,:,3)=zeros(size(flagmask));
1609       
1610        %update mask image
1611        hmask=[]; %default
1612        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1613            hmask=MaskData.maskhandle;
1614        end
1615        if ~isempty(hmask)
1616            set(hmask,'CData',imflag)   
1617            set(hmask,'AlphaData',flagmask*0.6)
1618            set(hmask,'XData',Mask.AX);
1619            set(hmask,'YData',Mask.AY);
1620%             uistack(hmask,'top')
1621        else
1622            axes(handles.axes3)
1623            hold on   
1624            MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
1625%             set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
1626            set(handles.mask_test,'UserData',MaskData)
1627        end
1628    end
1629end
1630
1631
1632%-------------------------------------------------------------------
1633function MenuExportFigure_Callback(hObject, eventdata, handles)
1634%-------------------------------------------------------------------
1635huvmat=get(handles.MenuExport,'parent');
1636%UvData=get(huvmat,'UserData');
1637hfig=figure;
1638copyobj(handles.axes3,hfig);
1639map=colormap(handles.axes3);
1640colormap(map);%transmit the current colormap to the zoom fig
1641colorbar
1642
1643%-------------------------------------------------------------------
1644%-------------------------------------------------------------------
1645% III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
1646%-------------------------------------------------------------------
1647
1648%-------------------------------------------------------------------
1649% --- Executes on button press in runplus: make one step forward and call
1650% --- run0. The step forward is along the fields series 1 or 2 depending on
1651% --- the scan_i and scan_j check box (exclusive each other)
1652function runplus_Callback(hObject, eventdata, handles)
1653%-------------------------------------------------------------------
1654set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow
1655drawnow
1656%TODO: introduce the option: increment ='*' to move to the next available view
1657increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
1658if isnan(increment)
1659    set(handles.increment_scan,'String','1')%default value
1660    increment=1;
1661end
1662errormsg=runpm(hObject,eventdata,handles,increment);
1663if ~isempty(errormsg)
1664    msgbox_uvmat('ERROR',errormsg);
1665end
1666set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back to red
1667
1668%-------------------------------------------------------------------
1669% --- Executes on button press in runmin: make one step backward and call
1670% --- run0. The step backward is along the fields series 1 or 2 depending on
1671% --- the scan_i and scan_j check box (exclusive each other)
1672function runmin_Callback(hObject, eventdata, handles)
1673%-------------------------------------------------------------------
1674set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
1675drawnow
1676increment=-str2double(get(handles.increment_scan,'String')); %get the field increment d
1677if isnan(increment)
1678    set(handles.increment_scan,'String','1')%default value
1679    increment=1;
1680end
1681errormsg=runpm(hObject,eventdata,handles,increment);
1682if ~isempty(errormsg)
1683    msgbox_uvmat('ERROR',errormsg);
1684end
1685set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back to red
1686
1687%-------------------------------------------------------------------
1688% -- Executes on button press in Movie: make a series of +> steps
1689function Movie_Callback(hObject, eventdata, handles)
1690%------------------------------------------------------------------
1691set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow
1692drawnow
1693increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
1694if isnan(increment)
1695    set(handles.increment_scan,'String','1')%default value
1696    increment=1;
1697end
1698set(handles.STOP,'Visible','on')
1699set(handles.speed,'Visible','on')
1700set(handles.speed_txt,'Visible','on')
1701set(handles.Movie,'BusyAction','queue')
1702UvData=get(handles.uvmat,'UserData');
1703
1704while get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command
1705        errormsg=runpm(hObject,eventdata,handles,increment);
1706        if ~isempty(errormsg)
1707            set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1708            return
1709        end
1710        pause(1.02-get(handles.speed,'Value'))% wait for next image
1711end
1712if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1713    UvData.aviobj=close(UvData.aviobj);
1714   set(handles.uvmat,'UserData',UvData);
1715end
1716set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1717
1718%-------------------------------------------------------------------
1719% -- Executes on button press in Movie: make a series of <- steps
1720function MovieBackward_Callback(hObject, eventdata, handles)
1721%------------------------------------------------------------------
1722set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow
1723drawnow
1724increment=-str2double(get(handles.increment_scan,'String')); %get the field increment d
1725if isnan(increment)
1726    set(handles.increment_scan,'String','1')%default value
1727    increment=1;
1728end
1729set(handles.STOP,'Visible','on')
1730set(handles.speed,'Visible','on')
1731set(handles.speed_txt,'Visible','on')
1732set(handles.MovieBackward,'BusyAction','queue')
1733UvData=get(handles.uvmat,'UserData');
1734
1735while get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command
1736        errormsg=runpm(hObject,eventdata,handles,increment);
1737        if ~isempty(errormsg)
1738            set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1739            return
1740        end
1741        pause(1.02-get(handles.speed,'Value'))% wait for next image
1742end
1743if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1744    UvData.aviobj=close(UvData.aviobj);
1745   set(handles.uvmat,'UserData',UvData);
1746end
1747set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1748
1749%-------------------------------------------------------------------
1750function STOP_Callback(hObject, eventdata, handles)
1751%-------------------------------------------------------------------
1752set(handles.movie_pair,'BusyAction','Cancel')
1753set(handles.movie_pair,'value',0)
1754set(handles.Movie,'BusyAction','Cancel')
1755set(handles.MovieBackward,'BusyAction','Cancel')
1756set(handles.MenuExportMovie,'BusyAction','Cancel')
1757set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1758set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1759set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1760
1761%------------------------------------------------------------------
1762function errormsg=runpm(hObject,eventdata,handles,increment)
1763%------------------------------------------------------------------
1764%check for mï¿œovie pair status
1765movie_status=get(handles.movie_pair,'Value');
1766if isequal(movie_status,1)
1767    STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
1768end
1769%read the data on the current input rootfile(s)
1770
1771[FileName,RootPath,filebase,FileIndices,FileExt,subdir]=read_file_boxes(handles);
1772NomType=get(handles.FileIndex,'UserData');
1773
1774num1=stra2num(get(handles.i1,'String'));
1775num2=stra2num(get(handles.i2,'String'));
1776num_a=stra2num(get(handles.j1,'String'));
1777num_b=stra2num(get(handles.j2,'String'));
1778
1779sub_value= get(handles.SubField,'Value');
1780if sub_value % a second input file has been entered
1781    [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
1782    [pp,ff,str1,str2,str_a,str_b]=name2display(FileIndices_1);
1783    num1_1=stra2num(str1);%current set of indices for the second field (may be set different than the main indices)
1784    num2_1=stra2num(str2);
1785    num_a_1=stra2num(str_a);
1786    num_b_1=stra2num(str_b);
1787    NomType_1=get(handles.FileIndex_1,'UserData');
1788else
1789    filename_1=[];
1790end   
1791
1792comp_input=get(handles.fix_pair,'Value');
1793
1794%case of scanning along the first direction (rootfile numbers)
1795if get(handles.scan_i,'Value')==1% case of scanning along index i   
1796     num1=num1+increment;
1797     num2=num2+increment;
1798     [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1799     if sub_value% set the second field name and indices
1800        num1_1=num1_1+increment;
1801        num2_1=num2_1+increment;
1802        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1803     end   
1804else % case of scanning along index j (burst numbers)
1805    num_a=num_a+increment;
1806    num_b=num_b+increment;
1807    [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1808    if sub_value
1809        num_a_1=num_a_1+increment;
1810        num_b_1=num_b_1+increment;
1811        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1812    end   
1813end
1814
1815% refresh plots
1816errormsg=refresh_field(handles,filename,filename_1,num1,num2,num_a,num_b);
1817if isempty(errormsg)  %update the index counters
1818    set(handles.i1,'String',num2stra(num1,NomType,1));
1819    if isequal(num2,num1)
1820         set(handles.i2,'String','');
1821    else
1822        set(handles.i2,'String',num2stra(num2,NomType,1));
1823    end
1824    set(handles.j1,'String',num2stra(num_a,NomType,2));
1825    if isequal(num_b,num_a)
1826         set(handles.j2,'String','');
1827    else
1828        set(handles.j2,'String',num2stra(num_b,NomType,2));
1829    end
1830    [indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1831    set(handles.FileIndex,'String',indices);
1832    if ~isempty(filename_1)
1833         indices_1=name_generator('',num1_1,num_a_1,'',NomType_1,1,num2_1,num_b_1,'');
1834         set(handles.FileIndex_1,'String',indices_1);
1835    end
1836    if isequal(movie_status,1)
1837        set(handles.movie_pair,'Value',1)
1838        movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
1839    end
1840end
1841
1842
1843%-------------------------------------------------------
1844% --- Executes on button press in movie_pair: create an alternating movie with two view
1845%-------------------------------------------------------
1846function movie_pair_Callback(hObject, eventdata, handles)
1847status=get(handles.movie_pair,'value');
1848if isequal(status,0)
1849    set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
1850    set(handles.i2,'String','')
1851    set(handles.j2,'String','')
1852    return
1853else
1854    set(handles.movie_pair,'BusyAction','queue')
1855end
1856%initialisation
1857set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
1858drawnow
1859list_fields=get(handles.Fields,'String');% list menu fields
1860index_fields=get(handles.Fields,'Value');% selected string index
1861FieldName=list_fields{index_fields}; % selected field
1862UvData=get(handles.uvmat,'UserData');
1863if isequal(FieldName,'image')
1864    test_1=0;
1865    [ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
1866    NomType=get(handles.FileIndex,'UserData');
1867else
1868    list_fields=get(handles.Fields_1,'String');% list menu fields
1869    index_fields=get(handles.Fields_1,'Value');% selected string index
1870    FieldName=list_fields{index_fields}; % selected field
1871    if isequal(FieldName,'image')
1872        test_1=1;
1873        [ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes_1(handles);
1874        NomType=get(handles.FileIndex_1,'UserData');
1875    else
1876        msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
1877        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1878        return
1879    end
1880end
1881
1882num_i1=str2double(get(handles.i1,'String'));
1883num_j1=stra2num(get(handles.j1,'String'));
1884num_i2=str2double(get(handles.i2,'String'));
1885num_j2=stra2num(get(handles.j2,'String'));
1886if isnan(num_j2)
1887    if isempty(num_i2)   
1888        msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
1889        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1890        return
1891    else
1892        num_j2=num_j1;%repeat the index i1 by default
1893    end
1894end
1895if isnan(num_i2)
1896    num_i2=num_i1;%repeat the index i1 by default
1897end
1898imaname_1=name_generator(filebase,num_i2,num_j2,Ext,NomType);
1899if ~exist(imaname_1,'file')
1900      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
1901      set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1902      return
1903end
1904
1905%read the second image
1906Field.AName='image';
1907if test_1
1908    Field_a=UvData.Field_1;
1909else
1910    Field_a=UvData.Field;
1911end
1912Field_b.AX=Field_a.AX;
1913Field_b.AY=Field_a.AY;
1914% z index
1915nbslice=str2double(get(handles.nb_slice,'String'));
1916if ~isempty(nbslice)
1917    Field_b.ZIndex=mod(num_i2-1,nbslice)+1;
1918end
1919Field_b.CoordUnit='pixel';
1920%determine the input file type
1921if (test_1 && isfield(UvData,'MovieObject_1'))||(~test_1 && isfield(UvData,'MovieObject'))
1922    FileType='movie';
1923elseif isequal(lower(Ext),'.avi')
1924    FileType='avi';
1925elseif isequal(lower(Ext),'.vol')
1926    FileType='vol';
1927else
1928   form=imformats(Ext(2:end));
1929   if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1930       if isequal(NomType,'*');
1931           FileType='multimage';
1932       else
1933           FileType='image';
1934       end
1935   end
1936end
1937switch FileType
1938        case 'movie'
1939            if test_1
1940                Field_b.A=read(UvData.MovieObject_1,num_i2);
1941            else
1942                Field_b.A=read(UvData.MovieObject,num_i2);
1943            end
1944        case 'avi'
1945            mov=aviread(imaname_1,num_i2);
1946            Field_b.A=frame2im(mov(1));
1947        case 'vol'
1948            Field_b.A=imread(imaname_1);
1949        case 'multimage'
1950            Field_b.A=imread(imaname_1,num_i2);
1951        case 'image'
1952            Field_b.A=imread(imaname_1);
1953end
1954if get(handles.slices,'Value')
1955    Field.ZIndex=str2double(get(handles.z_index,'String'));
1956end
1957
1958%px to phys or other transform on field
1959menu_transform=get(handles.transform_fct,'String');
1960choice_value=get(handles.transform_fct,'Value');
1961transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1962transform_list=get(handles.transform_fct,'UserData');
1963transform=transform_list{choice_value};
1964if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1965    if test_1 && isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1966        Field_a=transform(Field_a,UvData.XmlData_1);%the first field has been stored without transform
1967        Field_b=transform(Field_b,UvData.XmlData_1);
1968    elseif ~test_1 && isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib
1969        Field_b=transform(Field_b,UvData.XmlData);
1970    end
1971end
1972
1973 % make movie until movie speed is set to 0 or STOP is activated
1974hima=findobj(handles.axes3,'Tag','ima');% %handles.axes3 =main plotting window (A GENERALISER)
1975set(handles.STOP,'Visible','on')
1976set(handles.speed,'Visible','on')
1977set(handles.speed_txt,'Visible','on')
1978while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')%isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
1979    % read and plot the series of images in non erase mode
1980    set(hima,'CData',Field_b.A);
1981    pause(1.02-get(handles.speed,'Value'));% wait for next image
1982    set(hima,'CData',Field_a.A);
1983    pause(1.02-get(handles.speed,'Value'));% wait for next image
1984end
1985set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1986
1987%------------------------------------------------------------------------
1988% --- Executes on button press in run0.
1989function run0_Callback(hObject, eventdata, handles)
1990%------------------------------------------------------------------------
1991set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
1992drawnow
1993filename=read_file_boxes(handles);
1994
1995filename_1=[];%default
1996if get(handles.SubField,'Value')
1997    filename_1=read_file_boxes_1(handles);
1998end
1999num_i1=stra2num(get(handles.i1,'String'));
2000num_i2=stra2num(get(handles.i2,'String'));
2001num_j1=stra2num(get(handles.j1,'String'));
2002num_j2=stra2num(get(handles.j2,'String'));
2003
2004errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
2005
2006if ~isempty(errormsg)
2007      msgbox_uvmat('ERROR',errormsg);
2008else
2009    set(handles.i1,'BackgroundColor',[1 1 1])
2010    set(handles.i2,'BackgroundColor',[1 1 1])
2011    set(handles.j1,'BackgroundColor',[1 1 1])
2012    set(handles.j2,'BackgroundColor',[1 1 1])
2013    set(handles.FileIndex,'BackgroundColor',[1 1 1])
2014    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
2015end   
2016set(handles.run0,'BackgroundColor',[1 0 0])
2017
2018
2019%------------------------------------------------------------------------
2020% --- read the input files and refresh all the plots, including projection.
2021% OUTPUT:
2022%  errormsg: error message char string  =[] by default
2023% INPUT:
2024% filename: first input file (=[] in the absence of input file)
2025% filename_1: second input file (=[] in the asbsenc of secodn input file)
2026% num_i1,num_i2,num_j1,num_j2; frame indices
2027% Field: structure describing an optional input field (then replace the input file)
2028function errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,Field)
2029%------------------------------------------------------------------------
2030
2031%% initialisation
2032abstime=[];
2033abstime_1=[];
2034dt=[];
2035if ~exist('Field','var')
2036    Field={};
2037end
2038UvData=get(handles.uvmat,'UserData');
2039if ishandle(handles.UVMAT_title) %remove title panel on uvmat
2040    delete(handles.UVMAT_title)
2041end
2042
2043%% determine the main input file information for action
2044FileType=[];%default
2045if ~exist(filename,'file')
2046    errormsg=['input file ' filename ' does not exist'];
2047    return
2048end
2049NomType=get(handles.FileIndex,'UserData');
2050%update the z position index
2051nbslice_str=get(handles.nb_slice,'String');
2052if isequal(nbslice_str,'volume')%NOT USED
2053    z_index=num_j1;
2054    set(handles.z_index,'String',num2str(z_index))
2055else
2056    nbslice=str2num(nbslice_str);
2057    z_index=mod(num_i1-1,nbslice)+1;
2058    set(handles.z_index,'String',num2str(z_index))
2059end
2060% refresh menu for save_mask if relevant
2061masknumber=get(handles.masklevel,'String');
2062if length(masknumber)>=z_index
2063    set(handles.masklevel,'Value',z_index)
2064end
2065
2066%% read the first input field if a filename has been introduced
2067if ~isempty(filename)
2068    ObjectName=filename;
2069    FieldName=[];%default
2070    VelType=[];%default
2071    Ext=get(handles.FileExt,'String');
2072    if strcmp(Ext,'.nc')||strcmp(Ext,'.cdf')
2073        FileType='netcdf';
2074        list_fields=get(handles.Fields,'String');% list menu fields
2075        index_fields=get(handles.Fields,'Value');% selected string index
2076        FieldName= list_fields{index_fields}; % selected field
2077        if ~strcmp(FieldName,'get_field...')
2078           TestVelType=get(handles.FixVelType,'Value');
2079           if TestVelType
2080               VelType=setfield(handles);% read the velocity type.
2081           end
2082        end
2083        if strcmp(FieldName,'velocity')
2084            list_code=get(handles.ListColorCode,'String');% list menu fields
2085            index_code=get(handles.ListColorCode,'Value');% selected string index
2086            if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
2087                list_code=get(handles.ListColorScalar,'String');% list menu fields
2088                index_code=get(handles.ListColorScalar,'Value');% selected string index
2089                ParamIn.ColorVar= list_code{index_code}; % selected field
2090            end
2091        end
2092    elseif isfield(UvData,'MovieObject')
2093        ObjectName=UvData.MovieObject;
2094        FileType='movie';
2095    elseif isequal(lower(Ext),'.avi')
2096        FileType='avi';
2097    elseif isequal(lower(Ext),'.vol')
2098        FileType='vol';
2099        if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
2100            ParamIn.Npy=UvData.XmlData.Npy;
2101            ParamIn.Npx=UvData.XmlData.Npx;
2102        else
2103            errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2104            return
2105        end
2106    else
2107       form=imformats(Ext(2:end));
2108       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2109           if isequal(NomType,'*');
2110               FileType='multimage';
2111           else
2112               FileType='image';
2113           end
2114       end
2115    end
2116    ParamIn.FieldName=FieldName;
2117    ParamIn.VelType=VelType;
2118    ParamIn.GUIName='get_field';
2119    [Field{1},ParamOut,errormsg] = read_field(ObjectName,FileType,ParamIn,num_i1);
2120    if ~isempty(errormsg)
2121        errormsg=['error in reading ' filename ': ' errormsg];
2122        return
2123    end       
2124    if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
2125        set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2126        set(handles.num_Npy,'String',num2str(ParamOut.Npy));
2127    end
2128    if isfield(ParamOut,'TimeIndex')
2129        set(handles.i1,'String',num2str(ParamOut.TimeIndex))
2130    end
2131    if isfield(ParamOut,'TimeValue')
2132        Field{1}.Time=ParamOut.TimeValue;
2133    end
2134end
2135
2136%% choose a second field filename_1 if defined
2137VelType_1=[];%default
2138FieldName_1=[];
2139ParamOut_1=[];
2140if ~isempty(filename_1)
2141    if ~exist(filename_1,'file')
2142        errormsg=['second file ' filename_1 ' does not exist'];
2143        return
2144    else
2145        Name=filename_1;
2146        FieldName_1=[];%default
2147        VelType_1=[];%default
2148        if strcmp(get(handles.FileExt_1,'Visible'),'on')
2149            Ext_1=get(handles.FileExt_1,'String');
2150        else
2151            Ext_1=get(handles.FileExt,'String');%read the file extension for the first series (case of veltype comparison within a single file)
2152        end
2153        NomType_1=get(handles.FileIndex_1,'UserData');
2154        if isequal(Ext_1,'.nc')||isequal(Ext_1,'.cdf')
2155            FileType_1='netcdf';
2156        elseif isfield(UvData,'MovieObject_1')
2157            Name=UvData.MovieObject_1;
2158            FileType_1='movie';
2159        elseif isequal(lower(Ext_1),'.avi')
2160            FileType_1='avi';
2161        elseif isequal(lower(Ext_1),'.vol')
2162            FileType_1='vol';
2163            if isfield(UvData.XmlData_1,'Npy') && isfield(UvData.XmlData_1,'Npx')
2164                ParamIn.Npy=UvData.XmlData_1.Npy;
2165                ParamIn.Npx=UvData.XmlData_1.Npx;
2166            else
2167                errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2168                return
2169            end
2170        else
2171           if length(Ext_1)>=2
2172           form=imformats(Ext_1(2:end));
2173           if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2174               if isequal(NomType_1,'*');
2175                   FileType_1='multimage';
2176               else
2177                   FileType_1='image';
2178               end
2179           end
2180           end
2181        end
2182        if strcmp(FileType_1,'netcdf')
2183            list_fields=get(handles.Fields_1,'String');% list menu fields
2184            index_fields=get(handles.Fields_1,'Value');% selected string index
2185            FieldName_1= list_fields{index_fields}; % selected field
2186            if ~isequal(FieldName_1,'get_field...')% read the field names on the interface get_field...
2187                VelType_1='';
2188                if get(handles.FixVelType,'Value')
2189                    VelTypeList=get(handles.VelType_1,'String');
2190                    index=get(handles.VelType_1,'Value');
2191                    VelType_1=VelTypeList{index};
2192                end
2193            end
2194            if strcmp(VelType_1,'*')% free veltype choice
2195                VelType_1=[];
2196            elseif strcmp(VelType_1,'"')% veltype the same as for the first field
2197                if isempty(VelType)
2198                    VelType_1=[];
2199                else
2200                    VelType_1=VelType;
2201                end
2202            end
2203            if strcmp(FieldName_1,'velocity')
2204                list_code=get(handles.ListColorCode,'String');% list menu fields
2205                index_code=get(handles.ListColorCode,'Value');% selected string index
2206                if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
2207                    list_code=get(handles.ListColorScalar,'String');% list menu fields
2208                    index_code=get(handles.ListColorScalar,'Value');% selected string index
2209                    ParamIn.ColorVar= list_code{index_code}; % selected field
2210                end
2211            end
2212        end
2213        test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
2214        if ~isequal(NomType_1,'*')%in case of a series of files (not avi movie)
2215            if isfield(UvData,'filename_1')&& isfield(UvData,'VelType_1') && isfield(UvData,'FieldName_1')
2216                test_keepdata_1= strcmp(filename_1,UvData.filename_1) && strcmp(VelType_1,UvData.VelType_1) && strcmp(FieldName_1,UvData.FieldName_1);
2217            end
2218        end
2219        if test_keepdata_1
2220            Field{2}=UvData.Field_1;
2221        else
2222            ParamIn.FieldName=FieldName_1;
2223            ParamIn.VelType=VelType_1;
2224            ParamIn.GUIName='get_field_1';
2225            [Field{2},ParamOut_1,errormsg] = read_field(Name,FileType_1,ParamIn,num_i1);
2226            if ~isempty(errormsg)
2227                errormsg=['error in reading ' FieldName_1 ' in ' filename_1 ': ' errormsg];
2228                return
2229            end
2230            UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
2231        end
2232    end
2233end
2234
2235%% update uvmat interface
2236if isfield(ParamOut,'Npx')
2237    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2238    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
2239elseif isfield(ParamOut_1,'Npx')
2240    set(handles.num_Npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface
2241    set(handles.num_Npy,'String',num2str(ParamOut_1.Npy));
2242end
2243
2244%% update the display menu for the first velocity type (first menuline)
2245test_veltype=0;
2246if ~isequal(FileType,'netcdf')|| isequal(FieldName,'get_field...')
2247    set(handles.VelType,'Visible','off')
2248else
2249    test_veltype=1;
2250    set(handles.VelType,'Visible','on')
2251    set(handles.VelType_1,'Visible','on')
2252    set(handles.FixVelType,'Visible','on')
2253    menu=set_veltype_display(ParamOut.CivStage);
2254    index_menu=strcmp(ParamOut.VelType,menu);
2255    set(handles.VelType,'Value',find(index_menu,1))
2256    if ~get(handles.SubField,'value')
2257    set(handles.VelType,'String',menu)
2258     set(handles.VelType_1,'Value',1)
2259     set(handles.VelType_1,'String',[{''};menu])
2260    end
2261end
2262field_index=strcmp(ParamOut.FieldName,ParamOut.FieldList);
2263set(handles.Fields,'String',ParamOut.FieldList); %update the field menu
2264set(handles.Fields,'Value',find(field_index,1))
2265
2266%% update the display menu for the second velocity type (second menuline)
2267test_veltype_1=0;
2268if isempty(filename_1)
2269    set(handles.Fields_1,'Value',1); %update the field menu
2270    set(handles.Fields_1,'String',[{''};ParamOut.FieldList]); %update the field menu
2271else
2272    if ~isequal(FileType_1,'netcdf')|| isequal(FieldName_1,'get_field...')
2273        set(handles.VelType_1,'Visible','off')
2274    else
2275        test_veltype_1=1;
2276        set(handles.VelType_1,'Visible','on')
2277        if ~get(handles.FixVelType,'Value')
2278            menu=set_veltype_display(ParamOut_1.CivStage);
2279            index_menu=strcmp(ParamOut_1.VelType,menu);
2280            set(handles.VelType_1,'Value',1+find(index_menu,1))
2281            set(handles.VelType_1,'String',[{''};menu])
2282        end
2283    end
2284end
2285if test_veltype||test_veltype_1
2286     set(handles.FixVelType,'Visible','on')
2287else
2288     set(handles.FixVelType,'Visible','off')
2289end
2290   
2291%% introduce w as background image by default for a new series (only for nbdim=2)
2292if ~isfield(UvData,'NewSeries')
2293    UvData.NewSeries=1;
2294end
2295%put W as background image by default if NbDim=2:
2296if  UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3);
2297        set(handles.SubField,'Value',1);
2298        %menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
2299        set(handles.RootPath_1,'String','"')
2300        set(handles.RootFile_1,'String','"')
2301        set(handles.SubDir_1,'String','"');
2302        [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
2303        set(handles.FileIndex_1,'String',indices)
2304        set(handles.FileExt_1,'String','"');
2305        set(handles.Fields_1,'Visible','on');
2306        set(handles.Fields_1,'Visible','on');
2307        set(handles.RootPath_1,'Visible','on')
2308        set(handles.RootFile_1,'Visible','on')
2309        set(handles.SubDir_1,'Visible','on');
2310        set(handles.FileIndex_1,'Visible','on');
2311        set(handles.FileExt_1,'Visible','on');
2312        set(handles.Fields_1,'Visible','on');
2313        Field{1}.AName='w';
2314end           
2315
2316%% store the current open names, fields and vel types in uvmat interface
2317UvData.filename_1=filename_1;
2318UvData.VelType_1=[];%default
2319UvData.FieldName_1=[];
2320if isfield(ParamOut_1,VelType)
2321    UvData.VelType_1=ParamOut_1.VelType;
2322end
2323if isfield(ParamOut_1,FieldName)
2324    UvData.FieldName_1=ParamOut_1.FieldName;
2325end
2326
2327%% apply coordinate transform or other user fct
2328XmlData=[];%default
2329if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2330    XmlData=UvData.XmlData;
2331end
2332XmlData_1=[];%default
2333if isfield(UvData,'XmlData_1')
2334   XmlData_1=UvData.XmlData_1;
2335end
2336% menu_transform=get(handles.transform_fct,'String');
2337choice_value=get(handles.transform_fct,'Value');
2338transform_list=get(handles.transform_fct,'UserData');
2339transform=transform_list{choice_value};%selected function handles
2340% z index
2341if ~isempty(filename)
2342    Field{1}.ZIndex=z_index;
2343end
2344%px to phys or other transform on field
2345if ~isempty(transform)
2346    if length(Field)>=2
2347        Field{2}.ZIndex=z_index;
2348        [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
2349        if isempty(Field{2})
2350            Field(2)=[];
2351        end
2352    else
2353        Field{1}=transform(Field{1},XmlData);
2354    end
2355end
2356
2357%% calculate scalar
2358if isequal(FileType,'netcdf') && ~isequal(ParamOut.CivStage,0)%&&~isempty(FieldName)%
2359    Field{1}=calc_field([{ParamOut.FieldName} {ParamOut.ColorVar}],Field{1});
2360end
2361if numel(Field)==2 && ~test_keepdata_1 && isequal(FileType_1,'netcdf') && ~isequal(ParamOut_1.FieldName,'get_field...')%&&~isempty(FieldName_1)
2362    Field{2}=calc_field([{ParamOut_1.FieldName} {ParamOut_1.ColorVar}],Field{2});
2363end
2364
2365%% combine the two input fields (e.g. substract velocity fields)
2366if numel(Field)==2
2367   UvData.Field=sub_field(Field{1},Field{2}); 
2368else
2369   UvData.Field=Field{1};
2370end
2371
2372%% get bounds and mesh (needed for mouse action and to open set_object)
2373test_x=0;
2374test_z=0;% test for unstructured z coordinate
2375[UvData.Field,errormsg]=check_field_structure(UvData.Field);
2376if ~isempty(errormsg)
2377    errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];
2378    return
2379end
2380[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(UvData.Field);
2381if ~isempty(errormsg)
2382    errormsg=['error in uvmat/refresh_field/find_field_indices: ' errormsg];
2383    return
2384end
2385[NbDim,imax]=max(NbDim);
2386if isfield(UvData.Field,'NbDim')
2387    NbDim=UvData.Field.NbDim;% deal with plane fields containing z coordinates
2388end
2389if ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinates
2390    XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
2391    YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
2392    eval(['nbvec=length(UvData.Field.' XName ');'])%nbre of measurement points (e.g. vectors)
2393    test_x=1;%test for unstructured coordinates
2394    if ~isempty(VarType{imax}.coord_z)
2395        ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
2396    else
2397        NbDim=2;
2398    end
2399elseif numel(VarType)>=imax && numel(VarType{imax}.coord)>=NbDim && VarType{imax}.coord(NbDim)>0 %structured coordinate
2400    XName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim)};
2401    if NbDim>1
2402        YName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim-1)}; %structured coordinates
2403    end
2404end
2405if NbDim==3
2406    if ~test_x
2407        ZName=UvData.Field.ListVarName{VarType{imax}.coord(1)};%structured coordinates in 3D
2408    end
2409    eval(['ZMax=max(UvData.Field.' ZName ');'])
2410    eval(['ZMin=min(UvData.Field.' ZName ');'])
2411    UvData.Field.ZMax=ZMax;
2412    UvData.Field.ZMin=ZMin;
2413    test_z=1;
2414    if isequal(ZMin,ZMax)%no z dependency
2415        NbDim=2;
2416        test_z=0;
2417    end
2418end
2419if exist('XName','var')
2420    eval(['XMax=max(max(UvData.Field.' XName '));'])
2421    eval(['XMin=min(min(UvData.Field.' XName '));'])
2422    UvData.Field.NbDim=NbDim;
2423    UvData.Field.XMax=XMax;
2424    UvData.Field.XMin=XMin;
2425    if NbDim >1
2426        eval(['YMax=max(max(UvData.Field.' YName '));'])
2427        eval(['YMin=min(min(UvData.Field.' YName '));'])
2428        UvData.Field.YMax=YMax;
2429        UvData.Field.YMin=YMin;
2430    end
2431    eval(['nbvec=length(UvData.Field.' XName ');'])
2432    if test_x %unstructured coordinates
2433        if test_z
2434            UvData.Field.Mesh=((XMax-XMin)*(YMax-YMin)*(ZMax-ZMin))/nbvec;% volume per vector
2435            UvData.Field.Mesh=(UvData.Field.Mesh)^(1/3);
2436        else
2437            UvData.Field.Mesh=sqrt((XMax-XMin)*(YMax-YMin)/nbvec);%2D
2438        end
2439    else
2440        VarIndex=CellVarIndex{imax}; % list of variable indices
2441        DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
2442        nbpoints_x=UvData.Field.DimValue(DimIndex(NbDim));
2443        DX=(XMax-XMin)/(nbpoints_x-1);
2444        if NbDim >1
2445            nbpoints_y=UvData.Field.DimValue(DimIndex(NbDim-1));
2446            DY=(YMax-YMin)/(nbpoints_y-1);
2447        end
2448        if NbDim==3
2449            nbpoints_z=UvData.Field.DimValue(DimIndex(1));
2450            DZ=(ZMax-ZMin)/(nbpoints_z-1);
2451            UvData.Field.Mesh=(DX*DY*DZ)^(1/3);
2452            UvData.Field.ZMax=ZMax;
2453            UvData.Field.ZMin=ZMin;
2454        else
2455            UvData.Field.Mesh=DX;%sqrt(DX*DY);
2456        end
2457    end
2458end
2459
2460%% 3D case (menuvolume)
2461if NbDim==3% && UvData.NewSeries
2462    test_set_object=1;
2463    hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
2464    ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
2465    ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
2466    if ~isempty(hset_object) %if set_object is detected
2467%         hhset_object=guidata(hset_object);
2468% %         ZBounds_old(1)=get(hhset_object.z_slider,'Min');
2469% %         ZBounds_old(2)=get(hhset_object.z_slider,'Max');
2470% %         if isequal(ZBounds_old,ZBounds)
2471%             test_set_object=0;% do not refresh the GUI set_object
2472%         else
2473            delete(hset_object);% delete the GUI set_object if it does not fit
2474%         end
2475    end
2476    if test_set_object% reinitiate the GUI set_object
2477        delete_object(1);% delete the current projection object in the list UvData.Object, delete its graphic representations and update the list displayed in handles.list_object_1 and 2
2478        UvData.Object{1}.Style='plane';%main plotting plane
2479        UvData.Object{1}.ProjMode='projection';%main plotting plane
2480        UvData.Object{1}.DisplayHandle_uvmat=[]; %plane not visible in uvmat
2481        UvData.Object{1}.NbDim=NbDim;%test for 3D objects
2482        UvData.Object{1}.RangeZ=UvData.Field.Mesh;%main plotting plane
2483        UvData.Object{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
2484        UvData.Object{1}.Angle=[0 0 0];
2485%         UvData.Object{1}.Theta=0;
2486%         UvData.Object{1}.Psi=0;
2487        UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
2488%         PlotHandles=get_plot_handles(handles);
2489        UvData.Object{1}.Name='1-PLANE';
2490        UvData.Object{1}.enable_plot=1;
2491        set_object(UvData.Object{1},handles,ZBounds);
2492        set(handles.list_object_1,'Value',1);
2493        set(handles.list_object_1,'String',{'1-PLANE'});
2494        set(handles.edit_object,'Value',1)% put the plane in edit mode to enable the z cursor
2495        edit_object_Callback([],[], handles)
2496    end
2497    %multilevel case (single menuplane in a 3D space)
2498elseif isfield(UvData,'Z')
2499    if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
2500        XmlData=UvData.XmlData;
2501        if isfield(XmlData,'PlanePos')
2502            UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
2503        end
2504        if isfield(XmlData,'PlaneAngle')
2505            siz=size(XmlData.PlaneAngle);
2506            indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
2507            UvData.Object{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
2508        end
2509    elseif isfield(UvData,'ZIndex')
2510        UvData.Object{1}.ZObject=UvData.ZIndex;
2511    end
2512else
2513    % create a default projection
2514    UvData.Object{1}.ProjMode='projection';%main plotting plane
2515    UvData.Object{1}.DisplayHandle_uvmat=[]; %plane not visible in uvmat
2516    set(handles.list_object_1,'Value',1);
2517    list_object=get(handles.list_object_1,'String');
2518    if isempty(list_object)
2519        list_object={''};
2520    elseif ~isempty(list_object{1})
2521        list_object=[{''};list_object];
2522    end
2523    set(handles.list_object_1,'String',list_object);
2524    set(handles.list_object_2,'String',list_object);
2525end
2526testnewseries=UvData.NewSeries;
2527UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2528set(handles.uvmat,'UserData',UvData)
2529
2530%% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
2531if isfield(UvData,'Mask')&& ~isfield(UvData,'A')
2532    set(handles.num_MinA,'String','0')
2533    set(handles.num_MaxA,'String','255')
2534end
2535
2536%% Plot the projections on the selected  projection objects
2537% main projection object (uvmat display)
2538list_object=get(handles.list_object_1,'String');
2539if isequal(list_object,{''})%refresh list of objects if the menu is empty
2540    UvData.Object={[]};
2541    set(handles.list_object_1,'Value',1)
2542    set(handles.list_object_2,'Value',1)
2543    set(handles.list_object_2,'String',{''})
2544    set(handles.list_object_2,'Visible','off')
2545end
2546IndexObj(1)=get(handles.list_object_1,'Value');%selected projection object for main view
2547if IndexObj(1)> numel(UvData.Object)
2548    IndexObj(1)=1;%select the first object if the selected one does not exist
2549    set(handles.list_object_1,'Value',1)
2550end
2551plot_handles{1}=handles;
2552if isfield(UvData,'plotaxes')%case of movies
2553    haxes(1)=UvData.plotaxes;
2554else
2555    haxes(1)=handles.axes3;
2556end
2557%PlotParam{1}=read_plot_param(handles);%read plotting parameters on the uvmat interfac
2558PlotParam{1}=read_GUI(handles.uvmat);
2559keeplim(1)=get(handles.CheckFixLimits,'Value');% test for fixed graph limits
2560PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
2561
2562% second projection object (view_field display)
2563IndexObj_2=get(handles.list_object_2,'Value');%selected projection object for the second view
2564if IndexObj_2==0
2565    IndexObj_2=1;
2566end
2567if isequal(get(handles.list_object_2,'Visible'),'on') && IndexObj_2 <= numel(UvData.Object)&& ~isempty(UvData.Object{IndexObj_2})
2568    IndexObj(2)=IndexObj_2;
2569    view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
2570    if ~isempty(view_field_handle)
2571        plot_handles{2}=guidata(view_field_handle);
2572        haxes(2)=plot_handles{2}.axes3;
2573        %PlotParam{2}=read_plot_param(plot_handles{2});%read plotting parameters on the viewinterface
2574        PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
2575        keeplim(2)=get(plot_handles{2}.CheckFixLimits,'Value');
2576        PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
2577    end
2578end
2579
2580%loop on the projection objects: one or two
2581for imap=1:numel(IndexObj)
2582    iobj=IndexObj(imap);
2583    [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object
2584    if testnewseries && isfield(ObjectData,'CoordUnit')&& isfield(PlotParam{imap},'Coordinates')
2585        PlotParam{imap}=rmfield(PlotParam{imap}.Coordinates,'CheckFixEqual'); %set FixEqual to depend on the field (=1 if Data.CoordUnit=1 in plot_field)
2586    end
2587    if ~isempty(errormsg)
2588        return
2589    end
2590    %use of mask (TODO: check)
2591    if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
2592        flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2593        AX=ObjectData.AX;%x coordiantes for the scalar field
2594        AY=ObjectData.AY;%y coordinates for the scalar field
2595        MaskX=ObjectData.MaskX;%x coordiantes for the mask
2596        MaskY=ObjectData.MaskY;%y coordiantes for the mask
2597        if ~isequal(MaskX,AX)||~isequal(MaskY,AY)
2598            nxy=size(flag_mask);
2599            sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2600            sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2601            x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
2602            y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
2603            %project on the positions of the scalar
2604            npxy=size(ObjectData.A);
2605            dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2606            dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2607            xi=ObjectData.AX(1):dxy(2):ObjectData.AX(end);
2608            yi=ObjectData.AY(1):dxy(1):ObjectData.AY(end);
2609            [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2610            flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2611        end
2612        AClass=class(ObjectData.A);
2613        ObjectData.A=flag_mask.*double(ObjectData.A);
2614        ObjectData.A=feval(AClass,ObjectData.A);
2615        ind_off=[];
2616        if isfield(ObjectData,'ListVarName')
2617            for ilist=1:length(ObjectData.ListVarName)
2618                if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY')
2619                    ind_off=[ind_off ilist];
2620                end
2621            end
2622            ObjectData.ListVarName(ind_off)=[];
2623            ObjectData.VarDimIndex(ind_off)=[];
2624            ind_off=[];
2625            for ilist=1:length(ObjectData.ListDimName)
2626                if isequal(ObjectData.ListDimName{ilist},'MaskX') || isequal(ObjectData.ListDimName{ilist},'MaskY')
2627                    ind_off=[ind_off ilist];
2628                end
2629            end
2630            ObjectData.ListDimName(ind_off)=[];
2631            ObjectData.DimValue(ind_off)=[];
2632        end
2633    end   
2634    if ~isempty(ObjectData)
2635        PlotType='none'; %default
2636        if imap==2 && isempty(view_field_handle)
2637            view_field(ObjectData)
2638        else
2639            [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap},PosColorbar{imap});
2640            write_plot_param(plot_handles{imap},PlotParamOut) %update the auto plot parameters
2641            if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
2642                ObjectData.Mesh=Field.Mesh; % gives an estimated mesh size (useful for mouse action on the plot)
2643            end
2644        end
2645        if isequal(PlotType,'none')
2646            hget_field=findobj(allchild(0),'name','get_field');
2647            if isempty(hget_field)
2648                get_field(filename)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2649            end
2650            errormsg='The field defined by get_field cannot be plotted';
2651            return
2652        end
2653    end
2654end
2655
2656%% update the mask
2657if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
2658   update_mask(handles,num_i1,num_i2);
2659end
2660
2661%% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
2662menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
2663ind_bad=[];
2664nb_histo=1;
2665
2666% suppress coordinates from the histogram menu
2667for ivar=1:numel(menu_histo)%l loop on field variables:
2668    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2669        Role=UvData.Field.VarAttribute{ivar}.Role;
2670        switch Role
2671            case {'coord_x','coord_y','coord_z','dimvar'}
2672                ind_bad=[ind_bad ivar];
2673            case {'vector_y'}
2674                nb_histo=nb_histo+1;
2675        end
2676    end
2677    DimCell=UvData.Field.VarDimName{ivar};
2678    DimName='';
2679    if ischar(DimCell)
2680        DimName=DimCell;
2681    elseif iscell(DimCell)&& numel(DimCell)==1
2682        DimName=DimCell{1};
2683    end
2684    if strcmp(DimName,menu_histo{ivar})
2685        ind_bad=[ind_bad ivar];
2686    end
2687end
2688menu_histo(ind_bad)=[];
2689
2690%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2691% display menus and plot histograms
2692test_v=0;
2693if ~isempty(menu_histo)
2694    set(handles.histo1_menu,'Value',1)
2695    set(handles.histo1_menu,'String',menu_histo)
2696    histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
2697    % case of more than one variables (eg vector components)
2698    if nb_histo > 1
2699        test_v=1;
2700        set(handles.histo2_menu,'Visible','on')
2701        set(handles.histo_v,'Visible','on')
2702        set(handles.histo2_menu,'String',menu_histo)
2703        set(handles.histo2_menu,'Value',2)
2704        histo2_menu_Callback(handles.histo2_menu,[], handles)% plot second histogram
2705    end
2706end
2707if ~test_v
2708    set(handles.histo2_menu,'Visible','off')
2709    set(handles.histo_v,'Visible','off')
2710    cla(handles.histo_v)
2711    set(handles.histo2_menu,'Value',1)
2712end
2713%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2714
2715%% display time
2716testimedoc=0;
2717TimeUnit='';
2718if isfield(UvData.Field,'Time')
2719    abstime=UvData.Field.Time;%time read from the netcdf input file
2720end
2721if isfield(UvData,'Field_1') && isfield(UvData.Field_1,'Time')
2722    abstime_1=UvData.Field_1.Time;%time read from the netcdf input file
2723end
2724if isfield(UvData.Field,'dt')
2725    dt=UvData.Field.dt;%dt read from the netcdf input file
2726    if isfield(UvData.Field,'TimeUnit')
2727       TimeUnit=UvData.Field.TimeUnit;
2728    end
2729elseif isfield(UvData,'Field_1') && isfield(UvData.Field_1,'dt')%dt obtained from the second field if not defined in the first
2730    dt=UvData.Field_1.dt;%dt read from the netcdf input file
2731    if isfield(UvData.Field_1,'TimeUnit')
2732       TimeUnit=UvData.Field_1.TimeUnit;
2733    end
2734end
2735% time from xml file overset previous result
2736if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2737    if isempty(num_i2)||isnan(num_i2)
2738        num_i2=num_i1;
2739    end
2740    if isempty(num_j1)||isnan(num_j1)
2741        num_j1=1;
2742    end
2743    if isempty(num_j2)||isnan(num_j2)
2744        num_j2=num_j1;
2745    end
2746    siz=size(UvData.XmlData.Time);
2747    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2748        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2749        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2750        testimedoc=1;
2751        if isfield(UvData.XmlData,'TimeUnit')
2752            TimeUnit=UvData.XmlData.TimeUnit;
2753        end
2754    end
2755end
2756if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2757    [P,F,str1,str2,str_a,str_b,E]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2758    num_i2=str2double(str2);
2759    if isnan(num_i2)
2760        num_i2=num_i1;
2761    end
2762    num_j1=str2double(str_a);
2763    if isnan(num_j1)
2764        num_j1=1;
2765    end
2766    num_j2=str2double(str_b);
2767    if isnan(num_j2)
2768        num_j2=num_j1;
2769    end
2770    num_i1=str2double(str1);
2771    siz=size(UvData.XmlData_1.Time);
2772    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2773        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
2774    end
2775end
2776if ~isequal(numel(abstime),1)
2777    abstime=[];
2778end
2779if ~isequal(numel(abstime_1),1)
2780      abstime_1=[];
2781end 
2782set(handles.abs_time,'String',num2str(abstime,4))
2783set(handles.abs_time_1,'String',num2str(abstime_1,4))
2784if testimedoc && isfield(UvData,'dt')
2785    dt=UvData.dt;
2786end
2787if isempty(dt)||isequal(dt,0)
2788    set(handles.Dt_txt,'String','')
2789else
2790    if  isempty(TimeUnit)
2791        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2792    else
2793        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' TimeUnit] )
2794    end
2795end
2796
2797
2798%-------------------------------------------------------------------
2799% --- translate coordinate to matrix index
2800%-------------------------------------------------------------------
2801function [indx,indy]=pos2ind(x0,rangx0,nxy)
2802indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2803indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2804
2805%-------------------------------------------------------------------
2806% --- Executes on button press in 'CheckFixLimits'.
2807%-------------------------------------------------------------------
2808function CheckFixLimits_Callback(hObject, eventdata, handles)
2809test=get(handles.CheckFixLimits,'Value');
2810if test
2811    set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
2812else
2813    set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
2814    update_plot(handles);
2815end
2816
2817%-------------------------------------------------------------------
2818% --- Executes on button press in CheckFixEqual.
2819function CheckFixEqual_Callback(hObject, eventdata, handles)
2820test=get(handles.CheckFixEqual,'Value');
2821if test
2822    set(handles.CheckFixEqual,'BackgroundColor',[1 1 0])
2823    cla(handles.axes3)
2824    update_plot(handles);
2825else
2826    set(handles.CheckFixEqual,'BackgroundColor',[0.7 0.7 0.7])
2827    update_plot(handles);
2828%     axis(handles.axes3,'image')
2829end
2830
2831
2832%-------------------------------------------------------------------
2833
2834%-------------------------------------------------------------------
2835% --- Executes on button press in 'CheckZoom'.
2836%-------------------------------------------------------------------
2837function CheckZoom_Callback(hObject, eventdata, handles)
2838
2839if (get(handles.CheckZoom,'Value') == 1);
2840    set(handles.CheckZoom,'BackgroundColor',[1 1 0])
2841    set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes
2842    set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
2843else
2844    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
2845end
2846
2847
2848%-------------------------------------------------------------------
2849%----Executes on button press in 'record': records the current flags of manual correction.
2850%-------------------------------------------------------------------
2851function record_Callback(hObject, eventdata, handles)
2852% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2853filename=read_file_boxes(handles);
2854[erread,message]=fileattrib(filename);
2855if ~isempty(message) && ~isequal(message.UserWrite,1)
2856     msgbox_uvmat('ERROR',['no writting access to ' filename])
2857     return
2858end
2859test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
2860test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
2861if ~test_civ2 && ~test_civ1
2862    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2863end
2864if test_civ2
2865    nbname='nb_vectors2';
2866   flagname='vec2_FixFlag';
2867   attrname='fix2';
2868end
2869if test_civ1
2870    nbname='nb_vectors';
2871   flagname='vec_FixFlag';
2872   attrname='fix';
2873end
2874%write fix flags in the netcdf file
2875UvData=get(handles.uvmat,'UserData');
2876hhh=which('netcdf.open');% look for built-in matlab netcdf library
2877if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
2878    nc=netcdf.open(filename,'NC_WRITE');
2879    netcdf.reDef(nc);
2880    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1);
2881    dimid = netcdf.inqDimID(nc,nbname);
2882    try
2883        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2884    catch
2885        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2886    end
2887    netcdf.endDef(nc);
2888    netcdf.putVar(nc,varid,UvData.axes3.FF);
2889    netcdf.close(nc); 
2890else %old netcdf library
2891    netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2892end
2893
2894%-------------------------------------------------------------------
2895%----Correct the netcdf file, using toolbox (old versions of Matlab).
2896%-------------------------------------------------------------------
2897function netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2898nc=netcdf(filename,'write'); %open netcdf file
2899result=redef(nc);
2900eval(['nc.' attrname '=1;']);
2901theDim=nc(nbname) ;% get the number of velocity vectors
2902nb_vectors=size(theDim);
2903var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2904var_FixFlag(1:nb_vectors)=AxeData.FF;%
2905fin=close(nc);
2906
2907
2908%-------------------------------------------------------------------
2909%determines the fields to read from the interface
2910%------------------------------------------------------------------
2911function VelType=setfield(handles)
2912VelTypeList=get(handles.VelType,'String');
2913index=get(handles.VelType,'Value');
2914VelType=VelTypeList{index};
2915
2916% VelType=[]; %default
2917% if (get(handles.VelType,'Value') == 1);
2918%         VelType='civ1';
2919% % interp1   
2920% elseif (get(handles.interp1,'Value') == 1);
2921%     VelType='interp1';
2922% % filter1   
2923% elseif (get(handles.filter1,'Value') == 1);
2924%     VelType='filter1'; 
2925% % CIV2
2926% elseif (get(handles.civ2,'Value') == 1);
2927%     VelType='civ2';
2928% % interp2   
2929% elseif (get(handles.interp2,'Value') == 1);
2930%     VelType='interp2';
2931% % filter2   
2932% elseif (get(handles.filter2,'Value') == 1); 
2933%     VelType='filter2';
2934% end
2935%
2936% if isequal(get(handles.filter2,'Visible'),'on');
2937%     civ=6;
2938% % interp1   
2939% elseif isequal(get(handles.interp2,'Visible'),'on');
2940%     civ=5;
2941% % filter1   
2942% elseif isequal(get(handles.civ2,'Visible'),'on');
2943%     civ=4; 
2944% % CIV2
2945% elseif isequal(get(handles.filter1,'Visible'),'on');
2946%    civ=3;
2947% % interp2   
2948% elseif isequal(get(handles.interp1,'Visible'),'on');
2949%     civ=2;
2950% % filter2   
2951% elseif isequal(get(handles.VelType,'Visible'),'on'); 
2952%     civ=1;
2953% else
2954%     civ=0;
2955% end
2956
2957%-------------------------------------------------------------------
2958%determines the veltype of the second field to read from the iinterface
2959%------------------------------------------------------------------
2960function VelType=setfield_1(handles)
2961VelTypeList=get(handles.VelType_1,'String');
2962index=get(handles.VelType_1,'Value');
2963VelType=VelTypeList{index};
2964% VelType=[]; %default
2965% if (get(handles.VelType_1,'Value') == 1);
2966%     VelType='civ1';
2967% % interp1   
2968% elseif (get(handles.interp1_1,'Value') == 1);
2969%     VelType='interp1';
2970% % filter1   
2971% elseif (get(handles.filter1_1,'Value') == 1);
2972%     VelType='filter1'; 
2973% % CIV2
2974% elseif (get(handles.civ2_1,'Value') == 1);
2975%     VelType='civ2';
2976% % interp2   
2977% elseif (get(handles.interp2_1,'Value') == 1);
2978%     VelType='interp2';
2979% % filter2   
2980% elseif (get(handles.filter2_1,'Value') == 1); 
2981%     VelType='filter2';
2982% end
2983
2984
2985%---------------------------------------------------
2986% --- Executes on button press in SubField
2987function SubField_Callback(hObject, eventdata, handles)
2988% huvmat=get(handles.run0,'parent');
2989UvData=get(handles.uvmat,'UserData');
2990if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
2991    set(handles.RootPath_1,'String','')
2992    set(handles.RootFile_1,'String','')
2993    set(handles.SubDir_1,'String','');
2994    set(handles.FileIndex_1,'String','');
2995    set(handles.FileExt_1,'String','');
2996    set(handles.RootPath_1,'Visible','off')
2997    set(handles.RootFile_1,'Visible','off')
2998    set(handles.SubDir_1,'Visible','off');
2999    set(handles.FileIndex_1,'Visible','off');
3000    set(handles.FileExt_1,'Visible','off');
3001    set(handles.Fields_1,'Value',1);%set to blank state
3002    set(handles.VelType_1,'Value',1);%set to blank state
3003    if ~strcmp(get(handles.VelType,'Visible'),'on')
3004        set(handles.VelType_1,'Visible','off')
3005    end
3006%     set_veltype_display([handles.VelType_1 handles.interp1_1 handles.filter1_1 ...
3007%             handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
3008    if isfield(UvData,'XmlData_1')
3009        UvData=rmfield(UvData,'XmlData_1');
3010    end
3011    set(handles.uvmat,'UserData',UvData);
3012    run0_Callback(hObject, eventdata, handles); %run
3013else
3014    MenuBrowse_1_Callback(hObject, eventdata, handles)
3015end
3016
3017%------------------------------------------------------------------------
3018% --- read the data displayed for the input rootfile windows (new)
3019function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
3020%------------------------------------------------------------------------
3021RootPath=get(handles.RootPath,'String');
3022FileName=RootPath; %default
3023SubDir=get(handles.SubDir,'String');
3024if ~isempty(SubDir) && ~isequal(SubDir,'')
3025    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
3026        SubDir(1)=[]; %suppress possible / or \ separator
3027    end
3028    FileName=fullfile(RootPath,SubDir);
3029end
3030RootFile=get(handles.RootFile,'String');
3031if ~isempty(RootFile) && ~isequal(RootFile,'')
3032    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3033        RootFile(1)=[]; %suppress possible / or \ separator
3034    end
3035    FileName=fullfile(FileName,RootFile);
3036end
3037FileBase=fullfile(RootPath,RootFile);
3038FileIndices=get(handles.FileIndex,'String');
3039FileExt=get(handles.FileExt,'String');
3040FileName=[FileName FileIndices FileExt];
3041
3042%------------------------------------------------------------------------
3043% ---- read the data displayed for the second input rootfile windows
3044function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
3045%------------------------------------------------------------------------
3046RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
3047if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
3048    RootPath_1=get(handles.RootPath,'String');
3049end;
3050FileName_1=RootPath_1; %default
3051SubDir_1=get(handles.SubDir_1,'String');
3052if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
3053    SubDir_1=get(handles.SubDir,'String');
3054end
3055if numel(SubDir_1)>=1
3056    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
3057        SubDir_1(1)=[]; %suppress possible / or \ separator
3058    end
3059    FileName_1=fullfile(RootPath_1,SubDir_1);
3060end
3061RootFile_1=get(handles.RootFile_1,'String');
3062if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
3063    RootFile_1=get(handles.RootFile,'String');
3064end
3065if numel(RootFile_1)>=1
3066    if ~(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
3067        RootFile_1(1)=[];%suppress possible / or \ separator
3068    end
3069    FileName_1=fullfile(FileName_1,RootFile_1);
3070end
3071FileBase_1=fullfile(RootPath_1,RootFile_1);
3072if isequal(get(handles.FileIndex_1,'Visible'),'off')
3073    FileIndices_1=get(handles.FileIndex,'String');
3074else
3075    FileIndices_1=get(handles.FileIndex_1,'String');
3076end
3077FileExt_1=get(handles.FileExt_1,'String');
3078if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"')
3079    FileExt_1=get(handles.FileExt,'String');%read FileExt by default
3080end
3081FileName_1=[FileName_1 FileIndices_1 FileExt_1];
3082
3083%------------------------------------------------------------------------
3084% --- Executes on menu selection Fields
3085function Fields_Callback(hObject, eventdata, handles)
3086%------------------------------------------------------------------------
3087list_fields=get(handles.Fields,'String');% list menu fields
3088index_fields=get(handles.Fields,'Value');% selected string index
3089field= list_fields{index_fields(1)}; % selected string
3090if isequal(field,'get_field...')
3091    set(handles.FixVelType,'visible','off')
3092    set(handles.VelType,'visible','off')
3093    set(handles.VelType_1,'visible','off')
3094    filename=read_file_boxes(handles);
3095    hget_field=findobj(allchild(0),'name','get_field');
3096    if ~isempty(hget_field)
3097        delete(hget_field)
3098    end
3099    hget_field=get_field(filename);
3100    set(hget_field,'Name','get_field')
3101    hhget_field=guidata(hget_field);
3102    set(hhget_field.list_fig,'Value',1)
3103    set(hhget_field.list_fig,'String',{'uvmat'})
3104    set(handles.transform_fct,'Value',1)% no transform by default
3105    set(handles.path_transform,'String','')
3106    return %no action
3107end
3108list_fields=get(handles.Fields_1,'String');% list menu fields
3109index_fields=get(handles.Fields_1,'Value');% selected string index
3110field_1= list_fields{index_fields(1)}; % selected string
3111UvData=get(handles.uvmat,'UserData');
3112
3113%read the rootfile input display
3114[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
3115[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
3116NomTypeNew=NomType;%default
3117if isequal(field,'image')
3118    if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
3119        NomTypeNew='_i_j';
3120    elseif isequal(NomType,'#_ab')
3121        NomTypeNew='#a';
3122    elseif isequal(NomType,'_i1-i2')
3123        NomTypeNew='_i';
3124    end
3125    imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3126    if ~exist(imagename,'file')
3127        [FileName,PathName] = uigetfile( ...
3128            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3129            '*.jpg',' jpeg image files'; ...
3130            '*.png','.png image files'; ...
3131            '*.tif','.tif image files'; ...
3132            '*.avi;*.AVI','.avi movie files'; ...
3133            '*.vol','.volume images (png)'; ...
3134            '*.*',  'All Files (*.*)'}, ...
3135            'Pick an image',imagename);   
3136        imagename=[PathName FileName];
3137    end
3138     % display the selected field and related information
3139    display_file_name(hObject, eventdata, handles,imagename)%display the image
3140    return
3141else
3142    ext=get(handles.FileExt,'String');
3143    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
3144        [FileName,PathName] = uigetfile( ...
3145            {'*.nc', ' (*.nc)';
3146            '*.nc',' netcdf files'; ...
3147            '*.*',  'All Files (*.*)'}, ...
3148            'Pick a netcdf file',FileBase);
3149        filename=[PathName FileName];
3150        % display the selected field and related information
3151        display_file_name(hObject, eventdata, handles,filename)
3152        return
3153    end
3154end
3155indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3156set(handles.FileIndex,'String',indices)
3157set(handles.FileIndex,'UserData',NomTypeNew)
3158%common to Fields_1_Callback
3159if isequal(field,'image')||isequal(field_1,'image')
3160    set(handles.TitleNpx,'Visible','on')% visible npx,pxcm... buttons
3161    set(handles.TitleNpy,'Visible','on')
3162    set(handles.num_Npx,'Visible','on')
3163    set(handles.num_Npy,'Visible','on')
3164else
3165    set(handles.TitleNpx,'Visible','off')% visible npx,pxcm... buttons
3166    set(handles.TitleNpy,'Visible','off')
3167    set(handles.num_Npx,'Visible','off')
3168    set(handles.num_Npy,'Visible','off')
3169end
3170setfield(handles);% update the field structure ('civ1'....)
3171if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3172    run0_Callback(hObject, eventdata, handles)
3173end
3174
3175%---------------------------------------------------
3176% --- Executes on menu selection Fields
3177function Fields_1_Callback(hObject, eventdata, handles)
3178%-------------------------------------------------
3179list_fields=get(handles.Fields,'String');% list menu fields
3180index_fields=get(handles.Fields,'Value');% selected string index
3181field= list_fields{index_fields(1)}; % selected string
3182list_fields=get(handles.Fields_1,'String');% list menu fields
3183index_fields=get(handles.Fields_1,'Value');% selected string index
3184field_1= list_fields{index_fields(1)}; % selected string for the second field
3185if isequal(field_1,'') %remove second field if 'blank' field is selected
3186    set(handles.SubField,'Value',0)
3187    SubField_Callback(hObject, eventdata, handles)
3188    return
3189end
3190UvData=get(handles.uvmat,'UserData');
3191
3192%read the rootfile input display
3193[FileName,RootPath,FileBase,FileIndices,FileExt_1]=read_file_boxes_1(handles);
3194[P,F,str1,str2,str_a,str_b,E,NomType_1]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_1]);
3195% if isempty(FileExt_prev)|| strcmp(FileExt_prev,'')
3196%     FileExt_1=get(handles.FileExt,'String');
3197% else
3198%     FileExt_1=FileExt_prev;
3199% end
3200% NomType_1=get(handles.FileIndex_1,'UserData');
3201if isempty(NomType_1)|| strcmp(NomType_1,'')
3202    [FileName,RootPath,FileBase,FileIndices,FileExt_1]=read_file_boxes(handles);
3203    [P,F,str1,str2,str_a,str_b,E,NomType_1]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_1]);
3204%     NomType_1=get(handles.FileIndex,'UserData');
3205end
3206NomTypeNew=NomType_1;%default
3207
3208set(handles.SubField,'Value',1)%introduce second field
3209if isfield(UvData,'XmlData')
3210    UvData.XmlData_1=UvData.XmlData;
3211end
3212set(handles.FileIndex_1,'Visible','on')
3213set(handles.FileExt_1,'Visible','on')
3214RootPath_1=get(handles.RootPath_1,'String');
3215RootFile_1=get(handles.RootFile_1,'String');
3216if isempty(RootPath_1)||isequal(RootPath_1,'')
3217    set(handles.RootPath_1,'String','"')
3218end
3219if isempty(RootFile_1) || isequal(RootFile_1,'')
3220    set(handles.RootFile_1,'String','"')
3221end
3222if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
3223    RootFile_1(1)=[];
3224end
3225
3226if isequal(field_1,'get_field...')
3227     veltype_handles=[handles.VelType handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3228     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3229     filename=read_file_boxes_1(handles);
3230     hget_field=findobj(allchild(0),'name','get_field_1');
3231     if ~isempty(hget_field)
3232         delete(hget_field)
3233     end
3234     hget_field=get_field(filename);
3235     set(hget_field,'name','get_field_1')
3236     hhget_field=guidata(hget_field);
3237     set(hhget_field.list_fig,'Value',1)
3238     set(hhget_field.list_fig,'String',{'uvmat'})
3239     set(handles.transform_fct,'Value',1)% no transform by default
3240     set(handles.path_transform,'String','')
3241    return %no action
3242end
3243if isequal(field_1,'image')
3244    % transform netc type to the corresponding image type
3245    if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')|| isequal(NomType_1,'#_ab')|| isequal(NomType_1,'_i1-i2')
3246        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory   
3247        if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')
3248            NomTypeNew='_i_j';
3249        elseif isequal(NomType_1,'#_ab')
3250            NomTypeNew='#a';
3251        elseif isequal(NomType_1,'_i1-i2')
3252            NomTypeNew='_i';
3253        end 
3254    end
3255    imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3256    if ~exist(imagename,'file')
3257        [FileName,PathName] = uigetfile( ...
3258            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3259            '*.jpg',' jpeg image files'; ...
3260            '*.png','.png image files'; ...
3261            '*.tif','.tif image files'; ...
3262            '*.avi;*.AVI','.avi movie files'; ...
3263            '*.vol','.volume images (png)'; ...
3264            '*.*',  'All Files (*.*)'}, ...
3265            'Pick an image',imagename);
3266        % display the selected field and related information
3267        imagename=[PathName FileName];
3268    end
3269    display_file_name_1(hObject, eventdata, handles,imagename)%display the image
3270    return
3271else
3272    set(handles.SubDir_1,'Visible','on')
3273    if ~isequal(FileExt_1,'.nc') %find the new NomType if the previous display was not already a netcdf file
3274        RootPath_1=get(handles.RootPath_1,'String');
3275        RootFile_1=get(handles.RootFile_1,'String');
3276        if isempty(RootPath_1)||isequal(RootPath_1,'')
3277            set(handles.RootPath_1,'String','"')
3278        end
3279        if isempty(RootFile_1) || isequal(RootFile_1,'')
3280            set(handles.RootFile_1,'String','"')
3281        end
3282        if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
3283            RootFile_1(1)=[];
3284        end
3285        filebase_1=fullfile(RootPath_1,RootFile_1);
3286        SubDir_1=get(handles.SubDir,'String');
3287        if isempty(SubDir_1)||isequal(SubDir_1,'')
3288            if isfield(UvData,'SubDir_1')
3289                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3290            else
3291                SubDir_1='?';
3292            end
3293        end
3294        str1=get(handles.i1,'String');
3295        str_a=get(handles.j1,'String');
3296        if isequal(NomType_1,'#_ab')||isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')||isequal(NomType_1,'_i1-i2')
3297            NomTypeNew=NomType_1;
3298        elseif isequal(NomType_1,'#a')
3299             [filename, n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),stra2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3300             NomTypeNew='#_ab';
3301        elseif isequal(NomType_1,'_i_j')
3302             [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);
3303            if idetect==1
3304                NomTypeNew='_i1-i2_j';
3305            else
3306                NomTypeNew='_i_j1-j2';
3307            end
3308        else %for instance avi files or any ima_num series
3309            [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
3310            NomTypeNew='_i1-i2';
3311        end           
3312        [Path,Name]=fileparts(filebase_1);
3313        set(handles.FileExt_1,'String','.nc');
3314        if ~isempty(SubDir_1) && ~strcmp(SubDir_1,'''')&& ~strcmp(SubDir_1,'"')&& ~strcmp(SubDir_1(1),'/')
3315            SubDir_1=['/' SubDir_1];
3316        end
3317        set(handles.SubDir_1,'String',SubDir_1);
3318    end
3319    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
3320        set(handles.VelType_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3321        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3322        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3323        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3324    elseif isequal(field_1,'more...'); %add new item to the menu
3325        set(handles.VelType_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3326        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3327        str=calc_field;%get the list of available scalars by the function calc_scal
3328        [ind_answer,v] = listdlg('PromptString','Select a file:',...
3329                'SelectionMode','single',...
3330                'ListString',str);
3331       % edit the choice in the field and action menu
3332        scalar=cell2mat(str(ind_answer));
3333        menu=update_menu(handles.Fields_1,scalar);
3334        set(handles.Fields_1,'String',menu);% store the selected scalar type
3335    end
3336end
3337str1=get(handles.i1,'String');
3338str2=get(handles.i2,'String');
3339str_a=get(handles.j1,'String');
3340str_b=get(handles.j2,'String');
3341indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3342set(handles.FileIndex_1,'String',indices)
3343set(handles.FileIndex_1,'UserData',NomTypeNew)
3344
3345%common to Fields_Callback
3346if isequal(field,'image')||isequal(field_1,'image')
3347    set(handles.TitleNpx,'Visible','on')% visible npx,pxcm... buttons
3348    set(handles.TitleNpy,'Visible','on')
3349    set(handles.num_Npx,'Visible','on')
3350    set(handles.num_Npy,'Visible','on')
3351%     set(handles.fix_pair,'Value',0)
3352else
3353    set(handles.TitleNpx,'Visible','off')% visible npx,pxcm... buttons
3354    set(handles.TitleNpy,'Visible','off')
3355    set(handles.num_Npx,'Visible','off')
3356    set(handles.num_Npy,'Visible','off')
3357%     set(handles.fix_pair,'Value',1)
3358end
3359if isequal(field,'velocity')||isequal(field_1,'velocity');
3360    state_vect='on';
3361else
3362    state_vect='off';
3363end
3364if ~isequal(field,'velocity')||(~isequal(field_1,'velocity')&~isequal(field_1,''));
3365    state_scal='on';
3366else
3367    state_scal='off';
3368end
3369set(handles.uvmat,'UserData',UvData)
3370setfield(handles);% update the field structure ('civ1'....)
3371if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3372    run0_Callback(hObject, eventdata, handles)
3373end
3374
3375%------------------------------------------------------------------------
3376% --- set the visibility of relevant velocity type menus:
3377function menu=set_veltype_display(Civ)
3378%------------------------------------------------------------------------
3379if isequal(Civ,0)
3380    imax=0;
3381elseif isequal(Civ,1) || isequal(Civ,2)
3382   imax=1;
3383elseif isequal(Civ,3)
3384    imax=3;
3385elseif isequal(Civ,4) || isequal(Civ,5)
3386    imax=4;
3387elseif isequal(Civ,6) %patch2
3388    imax=6;
3389end
3390menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
3391menu=menu(1:imax);
3392% for ibutton=1:imax;
3393%     set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3394% end
3395% % for ibutton=max(imax+1,2):6;
3396% for ibutton=imax+1:6;
3397%     set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3398%     set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3399% end
3400
3401%-------------------------------------------------------------------
3402% --- Executes on button press in VelType.
3403function VelType_Callback(hObject, eventdata, handles)
3404%-------------------------------------------------------------------
3405% if get(handles.VelType,'Value')==1
3406%     reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.VelType)
3407% else
3408%     reset_vel_type([handles.VelType handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3409% end
3410set(handles.FixVelType,'Value',1)
3411run0_Callback(hObject, eventdata, handles)
3412
3413%---------------------------------------------
3414function VelType_1_Callback(hObject, eventdata, handles)
3415%---------------------------------------------
3416 
3417set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic)
3418%refresh field with a second filename=first fiel name
3419set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
3420drawnow   
3421filename=read_file_boxes(handles);
3422
3423index=get(handles.VelType_1,'Value');
3424if index==1
3425        filename_1='';% we plot the current field without the second field
3426        set(handles.SubField,'Value',0)
3427        SubField_Callback(hObject, eventdata, handles)
3428elseif get(handles.SubField,'Value')% if subfield is already 'on'
3429    filename_1=read_file_boxes_1(handles); %read the current second field
3430else
3431     filename_1=filename;% we compare two fields in the same file
3432     set(handles.SubField,'Value',1)
3433end
3434
3435num_i1=stra2num(get(handles.i1,'String'));
3436num_i2=stra2num(get(handles.i2,'String'));
3437num_j1=stra2num(get(handles.j1,'String'));
3438num_j2=stra2num(get(handles.j2,'String'));
3439
3440errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
3441
3442if ~isempty(errormsg)
3443    msgbox_uvmat('ERROR',errormsg);
3444else
3445    set(handles.i1,'BackgroundColor',[1 1 1])
3446    set(handles.i2,'BackgroundColor',[1 1 1])
3447    set(handles.j1,'BackgroundColor',[1 1 1])
3448    set(handles.j2,'BackgroundColor',[1 1 1])
3449    set(handles.FileIndex,'BackgroundColor',[1 1 1])
3450    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
3451end
3452set(handles.run0,'BackgroundColor',[1 0 0])
3453
3454%-----------------------------------------------
3455% --- reset civ buttons
3456function reset_vel_type(handles_civ0,handle1)
3457for ibutton=1:length(handles_civ0)
3458    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3459    set(handles_civ0(ibutton),'Value',0)
3460end
3461if exist('handle1','var')%handles of selected button
3462        set(handle1,'BackgroundColor',[1 1 0]) 
3463end
3464
3465%-------------------------------------------------------
3466% --- Executes on button press in MENUVOLUME.
3467%-------------------------------------------------------
3468function VOLUME_Callback(hObject, eventdata, handles)
3469%errordlg('command VOL not implemented yet')
3470if ishandle(handles.UVMAT_title)
3471    delete(handles.UVMAT_title)
3472end
3473UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3474if isequal(get(handles.VOLUME,'Value'),1)
3475    set(handles.CheckZoom,'Value',0)
3476    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
3477    set(handles.edit_vect,'Value',0)
3478    edit_vect_Callback(hObject, eventdata, handles)
3479    set(handles.edit_object,'Value',0)
3480    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3481%     set(handles.cal,'Value',0)
3482%     set(handles.cal,'BackgroundColor',[0 1 0])
3483    set(handles.edit_vect,'Value',0)
3484    edit_vect_Callback(hObject, eventdata, handles)
3485    %initiate set_object GUI
3486    data.TITLE='VOLUME';
3487    if isfield(UvData,'CoordType')
3488        data.CoordType=UvData.CoordType;
3489    end
3490    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3491        data.RangeY=UvData.Mesh;
3492        data.RangeX=UvData.Mesh;
3493        data.DX=UvData.Mesh;
3494        data.DY=UvData.Mesh;
3495    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3496        np=size(UvData.Field.A);
3497        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3498        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3499        data.RangeY=max(meshx,meshy);
3500        data.RangeX=max(meshx,meshy);
3501        data.DX=max(meshx,meshy);
3502    end
3503    data.ParentButton=handles.VOLUME;
3504    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3505    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3506                                                      % associate the set_object interface handle to the plotting axes
3507    if isfield(UvData.OpenParam,'SetObjectOrigin')                                               
3508    pos_uvmat=get(huvmat,'Position');
3509    pos_set_object(1:2)=UvData.OpenParam.SetObjectOrigin + pos_uvmat(1:2);
3510    pos_set_object(3:4)=UvData.OpenParam.SetObjectSize .* pos_uvmat(3:4); 
3511    set(hset_object,'Position',pos_set_object)
3512    end
3513    UvData.MouseAction='create_object';
3514else
3515    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3516    UvData.MouseAction='none';
3517end
3518set(huvmat,'UserData',UvData)
3519
3520%-------------------------------------------------------
3521function edit_vect_Callback(hObject, eventdata, handles)
3522%-------------------------------------------------------
3523%
3524% UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3525if isequal(get(handles.edit_vect,'Value'),1)
3526    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
3527    test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
3528    if ~test_civ2 && ~test_civ1
3529        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3530    end
3531    set(handles.record,'Visible','on')
3532    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3533    set(handles.edit_object,'Value',0)
3534    set(handles.CheckZoom,'Value',0)
3535    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
3536%     set(handles.create,'Value',0)
3537%     set(handles.create,'BackgroundColor',[0 1 0])
3538    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3539    set(gcf,'Pointer','arrow')
3540%     UvData.MouseAction='edit_vect';
3541else
3542    set(handles.record,'Visible','off')
3543    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3544%     UvData.MouseAction='none';
3545end
3546% set(handles.uvmat,'UserData',UvData)
3547
3548%----------------------------------------------
3549function save_mask_Callback(hObject, eventdata, handles)
3550%-----------------------------------------------------------------------
3551UvData=get(handles.uvmat,'UserData');
3552
3553flag=1;
3554npx=size(UvData.Field.A,2);
3555npy=size(UvData.Field.A,1);
3556xi=0.5:npx-0.5;
3557yi=0.5:npy-0.5;
3558[Xi,Yi]=meshgrid(xi,yi);
3559if isfield(UvData,'Object')
3560    for iobj=1:length(UvData.Object)
3561        ObjectData=UvData.Object{iobj};
3562        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3563            flagobj=1;
3564            testphys=0; %coordinates in pixels by default
3565            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3566                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3567                    Calib=UvData.XmlData.GeometryCalib;
3568                    testphys=1;
3569                end
3570            end
3571            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3572                if isequal(ObjectData.Style,'polygon')
3573                    X=ObjectData.Coord(:,1);
3574                    Y=ObjectData.Coord(:,2);
3575                    if testphys
3576                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3577                    end
3578                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
3579                elseif isequal(ObjectData.Style,'ellipse')
3580                    if testphys
3581                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3582                    end
3583                    RangeX=max(ObjectData.RangeX);
3584                    RangeY=max(ObjectData.RangeY);
3585                    X2Max=RangeX*RangeX;
3586                    Y2Max=RangeY*RangeY;
3587                    distX=(Xi-ObjectData.Coord(1,1));
3588                    distY=(Yi-ObjectData.Coord(1,2));
3589                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3590                elseif isequal(ObjectData.Style,'rectangle')
3591                    if testphys
3592                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3593                    end
3594                    distX=abs(Xi-ObjectData.Coord(1,1));
3595                    distY=abs(Yi-ObjectData.Coord(1,2));
3596                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3597                end
3598                if isequal(ObjectData.ProjMode,'mask_outside')
3599                    flagobj=~flagobj;
3600                end
3601                flag=flag & flagobj;
3602            end
3603        end
3604    end
3605end
3606% flag=~flag;
3607%mask name
3608RootPath=get(handles.RootPath,'String');
3609RootFile=get(handles.RootFile,'String');
3610if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3611        RootFile(1)=[];
3612end
3613filebase=fullfile(RootPath,RootFile);
3614list=get(handles.masklevel,'String');
3615masknumber=num2str(length(list));
3616maskindex=get(handles.masklevel,'Value');
3617mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3618imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3619imflag=flipdim(imflag,1);
3620% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3621msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3622imwrite(imflag,mask_name,'BitDepth',8);
3623
3624%display the mask
3625%update_mask(handles,num_i1,num_j1)
3626figure;
3627vec=linspace(0,1,256);%define a linear greyscale colormap
3628map=[vec' vec' vec'];
3629colormap(map)
3630
3631image(imflag);
3632
3633%-------------------------------------------------------------------
3634%-------------------------------------------------------------------
3635%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3636
3637%------------------------------------------------------------------
3638
3639
3640
3641%------------------------------------------------------------------
3642% --- Executes on selection change in ListColorScalar: choice of the color code.
3643%
3644function ListColorScalar_Callback(hObject, eventdata, handles)
3645%------------------------------------------------------------------
3646% edit the choice for color code
3647list_code=get(handles.ListColorScalar,'String');% list menu fields
3648index_code=get(handles.ListColorScalar,'Value');% selected string index
3649col_code= list_code{index_code(1)}; % selected field
3650if isequal(col_code,'black') || isequal(col_code,'white')
3651   set(handles.Slider1,'Visible','off')
3652   set(handles.Slider2,'Visible','off')
3653   set(handles.num_ColCode1,'Visible','off')
3654   set(handles.num_ColCode2,'Visible','off')
3655   set(handles.CheckFixVecColor,'Visible','off')
3656   set_vec_col_bar(handles)
3657else
3658   set(handles.Slider1,'Visible','on')
3659   set(handles.Slider2,'Visible','on')
3660   set(handles.num_ColCode1,'Visible','on')
3661   set(handles.num_ColCode2,'Visible','on')
3662   set(handles.CheckFixVecColor,'Visible','on') 
3663   if isequal(col_code,'ima_cor')
3664       set(handles.CheckFixVecColor,'Value',0)%fixed scale by default
3665       set(handles.VecColBar,'Value',0)% 3 colors r,g,b by default
3666       set(handles.Slider1,'Min',0);
3667       set(handles.Slider1,'Max',1);
3668       set(handles.Slider2,'Min',0);
3669       set(handles.Slider2,'Max',1);
3670 %      set(handles.min_title_vec,'String','0')
3671       set(handles.num_MaxVec,'String','1')
3672       set(handles.num_ColCode1,'String','0.333')
3673       colcode1_Callback(hObject, eventdata, handles)
3674       set(handles.num_ColCode2,'String','0.666')
3675       colcode2_Callback(hObject, eventdata, handles)
3676   else
3677       set(handles.CheckFixVecColor,'Value',1)%auto scale between min,max by default
3678       set(handles.VecColBar,'Value',1)% colormap 'jet' by default
3679       minval=get(handles.Slider1,'Min');
3680       maxval=get(handles.Slider1,'Max');
3681       set(handles.Slider1,'Value',minval)
3682       set(handles.Slider2,'Value',maxval)
3683       set_vec_col_bar(handles)
3684   end
3685%    slider_update(handles)
3686end
3687%replot the current graph
3688run0_Callback(hObject, eventdata, handles)
3689
3690
3691%----------------------------------------------------------------
3692% -- Executes on slider movement to set the color code
3693%
3694function Slider1_Callback(hObject, eventdata, handles)
3695%------------------------------------------------------------------
3696slider1=get(handles.Slider1,'Value');
3697min_val=str2num(get(handles.num_MinVec,'String'));
3698max_val=str2num(get(handles.num_MaxVec,'String'));
3699col=min_val+(max_val-min_val)*slider1;
3700set(handles.num_ColCode1,'String',num2str(col))
3701if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed
3702    set(handles.Slider2,'Value',col)
3703    set(handles.num_ColCode2,'String',num2str(col))
3704end
3705colcode1_Callback(hObject, eventdata, handles)
3706
3707%----------------------------------------------------------------
3708% Executes on slider movement to set the color code
3709%----------------------------------------------------------------
3710function Slider2_Callback(hObject, eventdata, handles)
3711slider2=get(handles.Slider2,'Value');
3712min_val=str2num(get(handles.num_MinVec,'String'));
3713max_val=str2num(get(handles.num_MaxVec,'String'));
3714col=min_val+(max_val-min_val)*slider2;
3715set(handles.num_ColCode2,'String',num2str(col))
3716if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed
3717    set(handles.Slider1,'Value',col)
3718    set(handles.num_ColCode1,'String',num2str(col))
3719end
3720colcode2_Callback(hObject, eventdata, handles)
3721
3722%----------------------------------------------------------------
3723%execute on return carriage on the edit box corresponding to slider 1
3724%----------------------------------------------------------------
3725function num_ColCode1_Callback(hObject, eventdata, handles)
3726% col=str2num(get(handles.num_ColCode1,'String'));
3727% set(handles.Slider1,'Value',col)
3728set_vec_col_bar(handles)
3729update_plot(handles);
3730
3731%----------------------------------------------------------------
3732%execute on return carriage on the edit box corresponding to slider 2
3733%----------------------------------------------------------------
3734function num_ColCode2_Callback(hObject, eventdata, handles)
3735% col=str2num(get(handles.num_ColCode2,'String'));
3736% set(handles.Slider2,'Value',col)
3737% slider2_Callback(hObject, eventdata, handles)
3738set_vec_col_bar(handles)
3739update_plot(handles);
3740%------------------------------------------------------------
3741%update the slider values after displaying vectors
3742%--------------------------------------------------------
3743% function slider_update(handles,auto,minC,num_ColCode1,num_ColCode2,maxC)
3744% set(handles.Slider1,'Min',minC)
3745% set(handles.Slider1,'Max',maxC)
3746% set(handles.Slider2,'Min',minC)
3747% set(handles.Slider2,'Max',maxC)
3748% set(handles.min_title_vec,'String',num2str(minC))
3749% set(handles.num_MaxVec,'String',num2str(maxC))
3750% if auto
3751%         set(handles.num_ColCode1,'String',num2str(num_ColCode1,3))%update display
3752%         set(handles.num_ColCode2,'String',num2str(num_ColCode2,3))
3753% end
3754% set(handles.Slider1,'Value',num_ColCode1)%update slider with constant display
3755% set(handles.Slider2,'Value',num_ColCode2)
3756% set_vec_col_bar(handles)
3757
3758
3759%-------------------------------------------------------
3760% --- Executes on button press in CheckFixVecColor.
3761%-------------------------------------------------------
3762function VecColBar_Callback(hObject, eventdata, handles)
3763set_vec_col_bar(handles)
3764
3765%-------------------------------------------------------------
3766% --- Executes on selection change in transform_fct.
3767function transform_fct_Callback(hObject, eventdata, handles)
3768%-------------------------------------------------------------
3769
3770UvData=get(handles.uvmat,'UserData');
3771menu=get(handles.transform_fct,'String');
3772ind_coord=get(handles.transform_fct,'Value');
3773coord_option=menu{ind_coord};
3774list_transform=get(handles.transform_fct,'UserData');
3775ff=functions(list_transform{end}); 
3776if isequal(coord_option,'more...');
3777    coord_fct='';
3778    prompt = {'Enter the name of the transform function'};
3779    dlg_title = 'user defined transform';
3780    num_lines= 1;
3781    [FileName, PathName] = uigetfile( ...
3782       {'*.m', ' (*.m)';
3783        '*.m',  '.m files '; ...
3784        '*.*', 'All Files (*.*)'}, ...
3785        'Pick a file', ff.file);
3786    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
3787        PathName(end)=[];
3788    end
3789    transform_selected =fullfile(PathName,FileName);
3790    if ~exist(transform_selected,'file')
3791           return
3792    end
3793   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
3794   if ~isequal(ext_fct,'.m')
3795        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
3796        return
3797   end
3798   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
3799   ind_coord=get(handles.transform_fct,'Value');
3800   addpath(PathName)
3801   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
3802   set(handles.transform_fct,'UserData',list_transform)
3803   rmpath(PathName)
3804   % save the new menu in the personal file 'uvmat_perso.mat'
3805   dir_perso=prefdir;%personal Matalb directory
3806   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3807   if exist(profil_perso,'file')
3808       nb_builtin=UvData.OpenParam.NbBuiltin;
3809       for ilist=nb_builtin+1:numel(list_transform)
3810           ff=functions(list_transform{ilist});
3811           transform_fct{ilist-nb_builtin}=ff.file;
3812       end
3813        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
3814   end   
3815end
3816
3817%check the current path to the selected function
3818if isa(list_transform{ind_coord},'function_handle')
3819    func=functions(list_transform{ind_coord});
3820    set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
3821else
3822    set(handles.path_transform,'String','')
3823end
3824
3825set(handles.CheckFixLimits,'Value',0)
3826set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
3827
3828%delete drawn objects
3829hother=findobj('Tag','proj_object');%find all the proj objects
3830for iobj=1:length(hother)
3831    delete_object(hother(iobj))
3832end
3833hother=findobj('Tag','DeformPoint');%find all the proj objects
3834for iobj=1:length(hother)
3835    delete_object(hother(iobj))
3836end
3837hh=findobj('Tag','calib_points');
3838if ~isempty(hh)
3839    delete(hh)
3840end
3841hhh=findobj('Tag','calib_marker');
3842if ~isempty(hhh)
3843    delete(hhh)
3844end
3845if isfield(UvData,'Object')
3846     UvData.Object=UvData.Object(1);
3847end
3848list_object=get(handles.list_object_1,'String');
3849set(handles.list_object_1,'Value',1)
3850set(handles.list_object_1,'String',{''})
3851set(handles.list_object_2,'Value',1)
3852set(handles.list_object_2,'String',{''})
3853list_object_2_Callback(hObject, eventdata, handles)
3854
3855%delete mask if it is displayed
3856if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
3857   UvData=rmfield(UvData,'MaskName'); %will impose mask refresh 
3858end
3859set(handles.uvmat,'UserData',UvData)
3860run0_Callback(hObject, eventdata, handles)
3861
3862%--------------------------------------------
3863function histo1_menu_Callback(hObject, eventdata, handles)
3864%--------------------------------------------
3865%plot first histo
3866huvmat=get(handles.histo1_menu,'parent');
3867histo_menu=get(handles.histo1_menu,'String');
3868histo_value=get(handles.histo1_menu,'Value');
3869FieldName=histo_menu{histo_value};
3870update_histo(handles.histo_u,huvmat,FieldName)
3871
3872%----------------------------------------------
3873function histo2_menu_Callback(hObject, eventdata, handles)
3874%----------------------------------------------
3875%plot second histo
3876huvmat=get(handles.histo2_menu,'parent');
3877histo_menu=get(handles.histo2_menu,'String');
3878histo_value=get(handles.histo2_menu,'Value');
3879FieldName=histo_menu{histo_value};
3880update_histo(handles.histo_v,huvmat,FieldName)
3881
3882
3883%--------------------------------------------
3884%read the field .Fieldname stored in UvData and plot its histogram
3885function update_histo(haxes,huvmat,FieldName)
3886UvData=get(huvmat,'UserData');
3887if ~isfield(UvData.Field,FieldName)
3888    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
3889    return
3890end
3891Field=UvData.Field;
3892FieldHisto=eval(['Field.' FieldName]);
3893if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto))
3894    indsel=find(Field.FF==0);%find values marked as false
3895    if ~isempty(indsel)
3896        FieldHisto=FieldHisto(indsel);
3897    end
3898end
3899if isempty(Field)
3900    msgbox_uvmat('ERROR',['empty field ' FieldName])
3901else
3902    nxy=size(FieldHisto);
3903    Amin=double(min(min(min(FieldHisto))));%min of image
3904    Amax=double(max(max(max(FieldHisto))));%max of image
3905    if isequal(Amin,Amax)
3906        msgbox_uvmat('WARNING',['uniform field =' num2str(Amin)]);
3907    else
3908        Histo.ListVarName={FieldName,'histo'};
3909        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
3910            Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
3911        else
3912            if numel(nxy)==2
3913                Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
3914            else
3915                Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
3916            end
3917        end
3918        %unit
3919        units=[]; %default
3920        for ivar=1:numel(Field.ListVarName)
3921            if strcmp(Field.ListVarName{ivar},FieldName)
3922                if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
3923                    units=Field.VarAttribute{ivar}.units;
3924                    break
3925                end
3926            end
3927        end
3928        if ~isempty(units)
3929            Histo.VarAttribute{1}.units=units;
3930        end
3931        eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
3932        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
3933            C=reshape(double(FieldHisto),1,[]);% reshape in a vector
3934            eval(['Histo.histo(:,1)=hist(C, Histo.' FieldName ');']);  %calculate histogram
3935        else
3936            for col=1:size(FieldHisto,3)
3937                B=FieldHisto(:,:,col);
3938                C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
3939                eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
3940            end
3941        end
3942%         set(haxes,'XLimMode','auto')%reset auto mode (after CheckZoom effect)
3943%         set(haxes,'YLimMode','auto')
3944%         PlotParam.Auto_xy=1;
3945        plot_field(Histo,haxes);
3946    end
3947end
3948
3949%------------------------------------------------
3950%CALLBACKS FOR PLOTTING PARAMETERS
3951%-------------------------------------------------
3952
3953%------------------------------------------------------------------------
3954function num_MinX_Callback(hObject, eventdata, handles)
3955%------------------------------------------------------------------------
3956set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3957set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3958update_plot(handles);
3959
3960%------------------------------------------------------------------------
3961function num_MaxX_Callback(hObject, eventdata, handles)
3962%------------------------------------------------------------------------
3963set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3964set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3965update_plot(handles);
3966
3967%------------------------------------------------------------------------
3968function num_MinY_Callback(hObject, eventdata, handles)
3969%------------------------------------------
3970set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3971set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3972update_plot(handles);
3973
3974%------------------------------------------------------------------------
3975function num_MaxY_Callback(hObject, eventdata, handles)
3976%------------------------------------------------------------------------
3977set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3978set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3979update_plot(handles);
3980
3981%------------------------------------------------------------------------
3982function num_MinA_Callback(hObject, eventdata, handles)
3983%------------------------------------------
3984set(handles.CheckFixScalar,'Value',1) %suppress auto mode
3985set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
3986MinA=str2double(get(handles.num_MinA,'String'));
3987MaxA=str2double(get(handles.num_MaxA,'String'));
3988if MinA>MaxA% switch minA and maxA in case of error
3989    MinA_old=MinA;
3990    MinA=MaxA;
3991    MaxA=MinA_old;
3992    set(handles.num_MinA,'String',num2str(MinA,5));
3993    set(handles.num_MaxA,'String',num2str(MaxA,5));
3994end
3995update_plot(handles);
3996
3997%------------------------------------------------------------------------
3998function num_MaxA_Callback(hObject, eventdata, handles)
3999%------------------------------------------------------------------------
4000set(handles.CheckFixScalar,'Value',1) %suppress auto mode
4001set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
4002MinA=str2double(get(handles.num_MinA,'String'));
4003MaxA=str2double(get(handles.num_MaxA,'String'));
4004if MinA>MaxA% switch minA and maxA in case of error
4005        MinA_old=MinA;
4006    MinA=MaxA;
4007    MaxA=MinA_old;
4008    set(handles.num_MinA,'String',num2str(MinA,5));
4009    set(handles.num_MaxA,'String',num2str(MaxA,5));
4010end
4011update_plot(handles);
4012
4013%------------------------------------------------------------------------
4014function CheckFixScalar_Callback(hObject, eventdata, handles)
4015%------------------------------------------------------------------------
4016test=get(handles.CheckFixScalar,'Value');
4017if test
4018    set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
4019else
4020    set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7])
4021    update_plot(handles);
4022end
4023
4024%-------------------------------------------------------------------
4025function CheckBW_Callback(hObject, eventdata, handles)
4026%-------------------------------------------------------------------
4027update_plot(handles);
4028
4029%-------------------------------------------------------------------
4030function ListContour_Callback(hObject, eventdata, handles)
4031%-------------------------------------------------------------------
4032val=get(handles.ListContour,'Value');
4033if val==2
4034    set(handles.interval_txt,'Visible','on')
4035    set(handles.num_IncrA,'Visible','on')
4036else
4037    set(handles.interval_txt,'Visible','off')
4038    set(handles.num_IncrA,'Visible','off')
4039end
4040update_plot(handles);
4041
4042%-------------------------------------------------------------------
4043function num_IncrA_Callback(hObject, eventdata, handles)
4044%-------------------------------------------------------------------
4045update_plot(handles);
4046
4047%-------------------------------------------------------------------
4048function CheckHideWarning_Callback(hObject, eventdata, handles)
4049%-------------------------------------------------------------------
4050update_plot(handles);
4051
4052%-------------------------------------------------------------------
4053function CheckHideFalse_Callback(hObject, eventdata, handles)
4054%-------------------------------------------------------------------
4055update_plot(handles);
4056
4057%-------------------------------------------------------------------
4058function num_VecScale_Callback(hObject, eventdata, handles)
4059%-------------------------------------------------------------------
4060set(handles.CheckFixVectors,'Value',1);
4061set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
4062update_plot(handles);
4063
4064%-------------------------------------------------------------------
4065function CheckFixVectors_Callback(hObject, eventdata, handles)
4066%-------------------------------------------------------------------
4067test=get(handles.CheckFixVectors,'Value');
4068if test
4069    set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
4070else
4071    update_plot(handles);
4072    %set(handles.num_VecScale,'String',num2str(ScalOut.num_VecScale,3))
4073    set(handles.CheckFixVectors,'BackgroundColor',[0.7 0.7 0.7])
4074end
4075
4076%------------------------------------------------------------------------
4077% --- Executes on selection change in CheckDecimate4 (nb_vec/4).
4078function CheckDecimate4_Callback(hObject, eventdata, handles)
4079%------------------------------------------------------------------------
4080update_plot(handles);
4081
4082%------------------------------------------------------------------------
4083% --- Executes on selection change in ListColorCode menu
4084function ListColorCode_Callback(hObject, eventdata, handles)
4085%------------------------------------------------------------------------
4086set_vec_col_bar(handles)
4087update_plot(handles);
4088
4089%------------------------------------------------------------------------
4090% --- Executes on button press in CheckFixVecColor.
4091function CheckFixVecColor_Callback(hObject, eventdata, handles)
4092%------------------------------------------------------------------------
4093test=get(handles.CheckFixVecColor,'Value');
4094if test
4095    set(handles.CheckFixVecColor,'BackgroundColor',[1 1 0])
4096else
4097    update_plot(handles);
4098    %set(handles.num_VecScale,'String',num2str(ScalOut.num_VecScale,3))
4099    set(handles.CheckFixVecColor,'BackgroundColor',[0.7 0.7 0.7])
4100end
4101
4102%------------------------------------------------------------------------
4103% --- Executes on selection change in num_MaxVec.
4104function num_MinVec_Callback(hObject, eventdata, handles)
4105%------------------------------------------------------------------------
4106max_vec_Callback(hObject, eventdata, handles)
4107
4108%------------------------------------------------------------------------
4109% --- Executes on selection change in num_MaxVec.
4110function num_MaxVec_Callback(hObject, eventdata, handles)
4111%------------------------------------------------------------------------
4112set(handles.CheckFixVecColor,'Value',1)
4113AutoVecColor_Callback(hObject, eventdata, handles)
4114min_val=str2num(get(handles.num_MinVec,'String'));
4115max_val=str2num(get(handles.num_MaxVec,'String'));
4116slider1=get(handles.Slider1,'Value');
4117slider2=get(handles.Slider2,'Value');
4118colcode1=min_val+(max_val-min_val)*slider1;
4119colcode2=min_val+(max_val-min_val)*slider2;
4120set(handles.num_ColCode1,'String',num2str(colcode1))
4121set(handles.num_ColCode2,'String',num2str(colcode2))
4122update_plot(handles);
4123
4124%------------------------------------------------------------------------
4125% --- update the display of color code for vectors
4126function set_vec_col_bar(handles)
4127%------------------------------------------------------------------------
4128%get the image of the color display button 'VecColBar' in pixels
4129set(handles.VecColBar,'Unit','pixel');
4130pos_vert=get(handles.VecColBar,'Position');
4131set(handles.VecColBar,'Unit','Normalized');
4132width=ceil(pos_vert(3));
4133height=ceil(pos_vert(4));
4134
4135%get slider indications
4136list=get(handles.ListColorCode,'String');
4137ichoice=get(handles.ListColorCode,'Value');
4138colcode.ColorCode=list{ichoice};
4139colcode.MinC=str2num(get(handles.num_MinVec,'String'));
4140colcode.MaxC=str2num(get(handles.num_MaxVec,'String'));
4141test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
4142if test3color
4143    colcode.colcode1=str2num(get(handles.num_ColCode1,'String'));
4144    colcode.colcode2=str2num(get(handles.num_ColCode2,'String'));
4145end
4146colcode.FixedCbounds=0;
4147colcode.FixedCbounds=1;
4148vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*(0.5:width-0.5)/width;%sample of vec_C values from min to max
4149[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4150oneheight=ones(1,height);
4151A1=colorlist(col_vec,1)*oneheight;
4152A2=colorlist(col_vec,2)*oneheight;
4153A3=colorlist(col_vec,3)*oneheight;
4154A(:,:,1)=A1';
4155A(:,:,2)=A2';
4156A(:,:,3)=A3';
4157set(handles.VecColBar,'Cdata',A)
4158
4159%-------------------------------------------------------------------
4160function update_plot(handles)
4161%-------------------------------------------------------------------
4162UvData=get(handles.uvmat,'UserData');
4163AxeData=UvData.axes3;% retrieve the current plotted data
4164PlotParam=read_GUI(handles.uvmat);
4165[PP,PlotParamOut]= plot_field(AxeData,handles.axes3,PlotParam);
4166write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4167
4168%-------------------------------------------------------------------
4169% --- Executes on button press in grid.
4170function grid_Callback(hObject, eventdata, handles)
4171
4172
4173%-------------------------------------------------------------------
4174% --- Executes on selection change in edit_object.
4175function edit_object_Callback(hObject, eventdata, handles)
4176%-------------------------------------------------------------------
4177UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4178test=get(handles.edit_object,'Value');
4179if test
4180    set(handles.edit_object,'BackgroundColor',[1,1,0]) 
4181    %suppress the other options
4182    set(handles.CheckZoom,'Value',0)
4183    zoom_Callback(hObject, eventdata, handles)
4184    hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4185    if ishandle(hgeometry_calib)
4186        hhgeometry_calib=guidata(hgeometry_calib);
4187        set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib
4188        set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7])
4189    end
4190else
4191    UvData.MouseAction='none';
4192    set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7])   
4193    hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
4194    if ~isempty(hset_object)
4195        delete(hset_object)% delete the current GUI set_object
4196    end
4197end
4198set(handles.uvmat,'UserData',UvData);
4199hset_object=findobj(allchild(0),'Tag','set_object');
4200if ~isempty(hset_object)
4201    hhset_object=guidata(hset_object);
4202    if test
4203        set(hhset_object.PLOT,'enable','on');
4204    else
4205       set(hhset_object.PLOT,'enable','off');
4206    end
4207end
4208
4209%------------------------------------------------------------------------
4210% --- Executes on selection change in list_object_1.
4211function list_object_1_Callback(hObject, eventdata, handles)
4212%------------------------------------------------------------------------
4213list_str=get(handles.list_object_1,'String');
4214IndexObj=get(handles.list_object_1,'Value');
4215%IndexObj(2)=get(handles.list_object_2,'Value');
4216update_object(handles,IndexObj,1,list_str{IndexObj})
4217
4218%------------------------------------------------------------------------
4219% --- Executes on selection change in list_object_1.
4220function list_object_2_Callback(hObject, eventdata, handles)
4221%------------------------------------------------------------------------
4222list_str=get(handles.list_object_2,'String');
4223IndexObj=get(handles.list_object_2,'Value');
4224%IndexObj(2)=get(handles.list_object_2,'Value')-1;
4225% if no projection object is selected, close view_field
4226if ischar(list_str) || isempty(list_str{IndexObj})
4227    hview_field=findobj(allchild(0),'Tag','view_field');
4228    if ~isempty(hview_field)
4229        delete(hview_field)
4230    end
4231    hset_object=findobj(allchild(0),'Tag','set_object');
4232    if ~isempty(hset_object)
4233        delete(hset_object)
4234    end
4235else
4236    if isequal(get(handles.uvmat,'SelectionType'),'alt')
4237        option=4;%will show object properties on the GUI set_object
4238    else
4239        option=2; % just update the projection
4240    end
4241    update_object(handles,IndexObj,option,list_str{IndexObj})   
4242end
4243
4244%------------------------------------------------------------------------
4245function update_object(handles,IndexObj,option,ObjectName)
4246%------------------------------------------------------------------------
4247UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4248if numel(UvData.Object)<max(IndexObj);
4249    return
4250end
4251% if option==1 ||option==3
4252ObjectData=UvData.Object{IndexObj};
4253% else
4254%    ObjectData=UvData.Object{IndexObj};
4255% end
4256ObjectData.Name=ObjectName;
4257if isequal(get(handles.edit_object,'Value'),1)
4258    ObjectData.enable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4259end
4260ZBounds=0; % default
4261if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4262    ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4263    ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4264end
4265hset_object=findobj(allchild(0),'tag','set_object');
4266if ~isempty(hset_object)
4267    delete(hset_object)% delete existing version of set_object
4268end
4269edit_test=get(handles.edit_object,'Value');
4270if edit_test
4271    ObjectData.enable_plot=1;
4272else
4273    if isfield(ObjectData,'enable_plot')
4274        ObjectData=rmfield(ObjectData,'enable_plot');
4275    end
4276end
4277
4278if option==3 ||option==4% right mouse selection, show the GUI set_object:
4279    hset_object=set_object(ObjectData,[],ZBounds);
4280end
4281
4282%project on the selected object and update the corresponding plot
4283hview_field=findobj(allchild(0),'tag','view_field');
4284% PlotHandles=guidata(hview_field);
4285if option==1 ||  option==3%length(UvData.Object)>= IndexObj && isfield(UvData.Object{IndexObj},'plotaxes')&& ishandle(UvData.Object{IndexObj}.plotaxes)
4286    PlotHandles=handles;
4287else
4288    if isempty(hview_field)
4289        hview_field=view_field;
4290    end
4291    PlotHandles=guidata(hview_field);
4292end
4293if option==1 ||option==2% lefet mouse selection, peroject the field:
4294    ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
4295    %plot_field(ProjData,PlotHandles.axes3,read_plot_param(PlotHandles));%read plotting parameters on the uvmat interfacPlotHandles);
4296    plot_field(ProjData,PlotHandles.axes3,read_GUI(get(PlotHandles.axes3,'Parent')));%read plotting parameters on the uvmat interfacPlotHandles);
4297    UvData.Object=update_obj(UvData,IndexObj,[]);
4298    set(handles.uvmat,'UserData',UvData)
4299end
4300
4301
4302% set(handles.uvmat,'UserData',UvData)
4303hother=[findobj(handles.axes3,'Tag','proj_object') ;findobj(PlotHandles.axes3,'Tag','proj_object')] ;%find all the proj objects
4304hother=[hother ;findobj(handles.axes3,'Tag','DeformPoint'); findobj(PlotHandles.axes3,'Tag','DeformPoint')];
4305for iobj=1:length(hother)
4306    if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
4307        set(hother(iobj),'EdgeColor','b')
4308        if isequal(get(hother(iobj),'FaceColor'),'m')
4309            set(hother(iobj),'FaceColor','b')
4310        end
4311    elseif isequal(get(hother(iobj),'Type'),'image')
4312        Acolor=get(hother(iobj),'CData');
4313        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4314        set(hother(iobj),'CData',Acolor);
4315    else
4316        set(hother(iobj),'Color','b')
4317    end
4318    set(hother(iobj),'Selected','off')
4319end
4320if isfield(ObjectData,'DisplayHandle_uvmat')
4321    if ishandle(ObjectData.DisplayHandle_uvmat)
4322        uistack(ObjectData.DisplayHandle_uvmat,'top')
4323        linetype=get(ObjectData.DisplayHandle_uvmat,'Type');
4324        if isequal(linetype,'line')
4325            set(ObjectData.DisplayHandle_uvmat,'Color','m'); %set the selected object to magenta color
4326        elseif isequal(linetype,'rectangle')
4327            set(ObjectData.DisplayHandle_uvmat,'EdgeColor','m'); %set the selected object to magenta color
4328        elseif isequal(linetype,'patch')
4329            set(ObjectData.DisplayHandle_uvmat,'FaceColor','m'); %set the selected object to magenta color
4330        end
4331        SubObjectData=get(ObjectData.DisplayHandle_uvmat,'UserData');
4332        if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
4333            uistack(SubObjectData.SubObject,'top')
4334            for iobj=1:length(SubObjectData.SubObject)
4335                hsub=SubObjectData.SubObject(iobj);
4336                if isequal(get(hsub,'Type'),'rectangle')
4337                    set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4338                elseif isequal(get(hsub,'Type'),'image')
4339                    Acolor=get(hsub,'CData');
4340                    Acolor(:,:,1)=Acolor(:,:,3);
4341                    set(hsub,'CData',Acolor);
4342                else
4343                    set(hsub,'Color','m')
4344                end
4345            end
4346        end
4347        if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
4348            set(SubObjectData.DeformPoint,'Color','m')
4349        end
4350    end
4351end
4352
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']});
4440UvData.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
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
4474aviobj=close(aviobj);
4475UvData=rmfield(UvData,'plotaxes');
4476%UvData.Object{1}.plotaxes=handles.axes3;
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
4487set(handles.CheckZoom,'Value',0)
4488set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
4489set(handles.list_object_1,'Value',1)     
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
4526    set(handles.list_object_1,'Max',2);%allow multiple selection
4527    set(handles.list_object_1,'Value',val);
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
4546                if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Style')
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
4580    end
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
4596    hfigmask=figure;
4597    set(hfigmask,'Name','mask image')
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
4611    set(handles.list_object_1,'Value',1)
4612    set(handles.list_object_1,'Max',1)
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])
4623set(handles.list_object_1,'Value',1)     
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%------------------------------------------------------------------------
4676 
4677[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
4678num1=stra2num(get(handles.i1,'String'));
4679num2=stra2num(get(handles.i2,'String'));
4680num_a=stra2num(get(handles.j1,'String'));
4681num_b=stra2num(get(handles.j2,'String'));
4682NomType=get(handles.FileIndex,'UserData');
4683ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4684if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4685    ind_opening=2;% propose 'fix' as the default option
4686% +read the current netcdf rootfile
4687    Data=nc2struct(FileName,'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
4700end     
4701param.RootName=filebase;
4702param.NomType=NomType;
4703param.num1=num1;
4704param.num2=num2;
4705param.num_a=num_a;
4706param.num_b=num_b;
4707param.SubDir=SubDir;
4708param.IndOpening=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4709param.ImaExt=ext;
4710civ(param);% interface de civ(not in the uvmat file)
4711
4712%------------------------------------------------------------------------
4713function MenuTools_Callback(hObject, eventdata, handles)
4714%------------------------------------------------------------------------
4715
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')
4853set(handles.uvmat_title,'Visible','on')
4854set(handles.view_field_title,'Visible','on')
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)
4914set(handles.CheckZoom,'Value',0)
4915CheckZoom_Callback(handles.uvmat, [], handles)
4916set(handles.delete_object,'Visible','on')
4917set(handles.uvmat_title,'Visible','on')
4918set(handles.view_field_title,'Visible','on')
4919
4920%------------------------------------------------------------------------
4921function MenuRuler_Callback(hObject, eventdata, handles)
4922%------------------------------------------------------------------------
4923set(handles.CheckZoom,'Value',0)
4924CheckZoom_Callback(handles.uvmat, [], handles)
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%------------------------------------------------------------------------
4953IndexObj=get(handles.list_object_2,'Value');
4954if IndexObj>1
4955    delete_object(IndexObj)
4956end
4957
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
4964
4965
Note: See TracBrowser for help on using the repository browser.