source: trunk/src/uvmat.m @ 315

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

many corrections, use of the new GUI civ with mask, grid and the new matlab civ1 and fix
pivlab now included in civ_matlab which contains all matlab subfunctions for civ.

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