source: trunk/src/uvmat.m @ 316

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

a few more bugs corrected, now the new civ_matlab works for civ1,fix1, patch1

File size: 209.8 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);
[316]2554if ~isfield(PlotParam{1},'Vectors')
2555    PlotParam{1}.Vectors.MaxVec=1;
2556    PlotParam{1}.Vectors.MinVec=0;
2557    PlotParam{1}.Vectors.CheckFixVecColor=1;
2558    PlotParam{1}.Vectors.ColCode1=0.33;
2559    PlotParam{1}.Vectors.ColCode2=0.66;
2560     PlotParam{1}.Vectors.ListColorScalar={'ima_cor'};
2561     PlotParam{1}.Vectors.ListColorCode= {'rgb'};
2562end
[292]2563keeplim(1)=get(handles.CheckFixLimits,'Value');% test for fixed graph limits
[199]2564PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
2565
2566% second projection object (view_field display)
[315]2567if length( IndexObj)>=2
[199]2568    view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
2569    if ~isempty(view_field_handle)
2570        plot_handles{2}=guidata(view_field_handle);
2571        haxes(2)=plot_handles{2}.axes3;
[292]2572        %PlotParam{2}=read_plot_param(plot_handles{2});%read plotting parameters on the viewinterface
2573        PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
2574        keeplim(2)=get(plot_handles{2}.CheckFixLimits,'Value');
[199]2575        PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
2576    end
2577end
2578
2579%loop on the projection objects: one or two
2580for imap=1:numel(IndexObj)
[206]2581    iobj=IndexObj(imap);
[199]2582    [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object
[316]2583
[199]2584    if ~isempty(errormsg)
2585        return
2586    end
[316]2587    %     if testnewseries && isfield(ObjectData,'CoordUnit')&& isfield(PlotParam{imap},'Coordinates')
2588%         PlotParam{imap}.Coordinates=rmfield(PlotParam{imap}.Coordinates,'CheckFixEqual'); %set FixEqual to depend on the field (=1 if Data.CoordUnit=1 in plot_field)
2589%     end
2590    if testnewseries && isfield(ObjectData,'CoordUnit')
2591        PlotParam{imap}.Coordinates.CheckFixEqual=1;
2592    end
[199]2593    %use of mask (TODO: check)
2594    if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
2595        flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2596        AX=ObjectData.AX;%x coordiantes for the scalar field
2597        AY=ObjectData.AY;%y coordinates for the scalar field
2598        MaskX=ObjectData.MaskX;%x coordiantes for the mask
2599        MaskY=ObjectData.MaskY;%y coordiantes for the mask
2600        if ~isequal(MaskX,AX)||~isequal(MaskY,AY)
2601            nxy=size(flag_mask);
2602            sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2603            sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2604            x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
2605            y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
2606            %project on the positions of the scalar
2607            npxy=size(ObjectData.A);
2608            dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2609            dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2610            xi=ObjectData.AX(1):dxy(2):ObjectData.AX(end);
2611            yi=ObjectData.AY(1):dxy(1):ObjectData.AY(end);
2612            [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2613            flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2614        end
2615        AClass=class(ObjectData.A);
2616        ObjectData.A=flag_mask.*double(ObjectData.A);
2617        ObjectData.A=feval(AClass,ObjectData.A);
2618        ind_off=[];
2619        if isfield(ObjectData,'ListVarName')
2620            for ilist=1:length(ObjectData.ListVarName)
2621                if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY')
2622                    ind_off=[ind_off ilist];
2623                end
2624            end
2625            ObjectData.ListVarName(ind_off)=[];
2626            ObjectData.VarDimIndex(ind_off)=[];
2627            ind_off=[];
2628            for ilist=1:length(ObjectData.ListDimName)
2629                if isequal(ObjectData.ListDimName{ilist},'MaskX') || isequal(ObjectData.ListDimName{ilist},'MaskY')
2630                    ind_off=[ind_off ilist];
2631                end
2632            end
2633            ObjectData.ListDimName(ind_off)=[];
2634            ObjectData.DimValue(ind_off)=[];
2635        end
2636    end   
2637    if ~isempty(ObjectData)
2638        PlotType='none'; %default
2639        if imap==2 && isempty(view_field_handle)
2640            view_field(ObjectData)
2641        else
2642            [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap},PosColorbar{imap});
2643            write_plot_param(plot_handles{imap},PlotParamOut) %update the auto plot parameters
2644            if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
2645                ObjectData.Mesh=Field.Mesh; % gives an estimated mesh size (useful for mouse action on the plot)
2646            end
2647        end
2648        if isequal(PlotType,'none')
2649            hget_field=findobj(allchild(0),'name','get_field');
2650            if isempty(hget_field)
2651                get_field(filename)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2652            end
2653            errormsg='The field defined by get_field cannot be plotted';
2654            return
2655        end
2656    end
2657end
2658
2659%% update the mask
[315]2660if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
[199]2661   update_mask(handles,num_i1,num_i2);
2662end
2663
2664%% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
2665menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
2666ind_bad=[];
2667nb_histo=1;
2668
2669% suppress coordinates from the histogram menu
2670for ivar=1:numel(menu_histo)%l loop on field variables:
2671    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2672        Role=UvData.Field.VarAttribute{ivar}.Role;
2673        switch Role
2674            case {'coord_x','coord_y','coord_z','dimvar'}
2675                ind_bad=[ind_bad ivar];
2676            case {'vector_y'}
2677                nb_histo=nb_histo+1;
2678        end
2679    end
2680    DimCell=UvData.Field.VarDimName{ivar};
2681    DimName='';
2682    if ischar(DimCell)
2683        DimName=DimCell;
2684    elseif iscell(DimCell)&& numel(DimCell)==1
2685        DimName=DimCell{1};
2686    end
2687    if strcmp(DimName,menu_histo{ivar})
2688        ind_bad=[ind_bad ivar];
2689    end
2690end
2691menu_histo(ind_bad)=[];
2692
2693%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2694% display menus and plot histograms
2695test_v=0;
2696if ~isempty(menu_histo)
2697    set(handles.histo1_menu,'Value',1)
2698    set(handles.histo1_menu,'String',menu_histo)
2699    histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
2700    % case of more than one variables (eg vector components)
2701    if nb_histo > 1
2702        test_v=1;
2703        set(handles.histo2_menu,'Visible','on')
2704        set(handles.histo_v,'Visible','on')
2705        set(handles.histo2_menu,'String',menu_histo)
2706        set(handles.histo2_menu,'Value',2)
2707        histo2_menu_Callback(handles.histo2_menu,[], handles)% plot second histogram
2708    end
2709end
2710if ~test_v
2711    set(handles.histo2_menu,'Visible','off')
2712    set(handles.histo_v,'Visible','off')
2713    cla(handles.histo_v)
2714    set(handles.histo2_menu,'Value',1)
2715end
2716%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2717
2718%% display time
2719testimedoc=0;
[221]2720TimeUnit='';
2721if isfield(UvData.Field,'Time')
2722    abstime=UvData.Field.Time;%time read from the netcdf input file
2723end
2724if isfield(UvData,'Field_1') && isfield(UvData.Field_1,'Time')
2725    abstime_1=UvData.Field_1.Time;%time read from the netcdf input file
2726end
2727if isfield(UvData.Field,'dt')
2728    dt=UvData.Field.dt;%dt read from the netcdf input file
2729    if isfield(UvData.Field,'TimeUnit')
2730       TimeUnit=UvData.Field.TimeUnit;
2731    end
2732elseif isfield(UvData,'Field_1') && isfield(UvData.Field_1,'dt')%dt obtained from the second field if not defined in the first
2733    dt=UvData.Field_1.dt;%dt read from the netcdf input file
2734    if isfield(UvData.Field_1,'TimeUnit')
2735       TimeUnit=UvData.Field_1.TimeUnit;
2736    end
2737end
2738% time from xml file overset previous result
[199]2739if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2740    if isempty(num_i2)||isnan(num_i2)
2741        num_i2=num_i1;
2742    end
2743    if isempty(num_j1)||isnan(num_j1)
2744        num_j1=1;
2745    end
2746    if isempty(num_j2)||isnan(num_j2)
2747        num_j2=num_j1;
2748    end
2749    siz=size(UvData.XmlData.Time);
2750    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2751        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2752        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2753        testimedoc=1;
[221]2754        if isfield(UvData.XmlData,'TimeUnit')
2755            TimeUnit=UvData.XmlData.TimeUnit;
2756        end
[199]2757    end
2758end
2759if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2760    [P,F,str1,str2,str_a,str_b,E]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2761    num_i2=str2double(str2);
2762    if isnan(num_i2)
2763        num_i2=num_i1;
2764    end
2765    num_j1=str2double(str_a);
2766    if isnan(num_j1)
2767        num_j1=1;
2768    end
2769    num_j2=str2double(str_b);
2770    if isnan(num_j2)
2771        num_j2=num_j1;
2772    end
2773    num_i1=str2double(str1);
2774    siz=size(UvData.XmlData_1.Time);
2775    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2776        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
2777    end
2778end
[258]2779if ~isequal(numel(abstime),1)
2780    abstime=[];
2781end
2782if ~isequal(numel(abstime_1),1)
2783      abstime_1=[];
2784end 
[199]2785set(handles.abs_time,'String',num2str(abstime,4))
2786set(handles.abs_time_1,'String',num2str(abstime_1,4))
2787if testimedoc && isfield(UvData,'dt')
2788    dt=UvData.dt;
2789end
2790if isempty(dt)||isequal(dt,0)
2791    set(handles.Dt_txt,'String','')
2792else
[221]2793    if  isempty(TimeUnit)
[199]2794        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2795    else
[221]2796        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' TimeUnit] )
[199]2797    end
2798end
2799
2800
2801%-------------------------------------------------------------------
2802% --- translate coordinate to matrix index
2803%-------------------------------------------------------------------
2804function [indx,indy]=pos2ind(x0,rangx0,nxy)
2805indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2806indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2807
2808%-------------------------------------------------------------------
[292]2809% --- Executes on button press in 'CheckFixLimits'.
[199]2810%-------------------------------------------------------------------
[292]2811function CheckFixLimits_Callback(hObject, eventdata, handles)
2812test=get(handles.CheckFixLimits,'Value');
[199]2813if test
[292]2814    set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[199]2815else
[292]2816    set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
[199]2817    update_plot(handles);
2818end
2819
2820%-------------------------------------------------------------------
[292]2821% --- Executes on button press in CheckFixEqual.
2822function CheckFixEqual_Callback(hObject, eventdata, handles)
2823test=get(handles.CheckFixEqual,'Value');
[199]2824if test
[292]2825    set(handles.CheckFixEqual,'BackgroundColor',[1 1 0])
[199]2826    cla(handles.axes3)
2827    update_plot(handles);
2828else
[292]2829    set(handles.CheckFixEqual,'BackgroundColor',[0.7 0.7 0.7])
[199]2830    update_plot(handles);
2831%     axis(handles.axes3,'image')
2832end
2833
2834
2835%-------------------------------------------------------------------
2836
2837%-------------------------------------------------------------------
[292]2838% --- Executes on button press in 'CheckZoom'.
[199]2839%-------------------------------------------------------------------
[292]2840function CheckZoom_Callback(hObject, eventdata, handles)
[199]2841
[292]2842if (get(handles.CheckZoom,'Value') == 1);
2843    set(handles.CheckZoom,'BackgroundColor',[1 1 0])
2844    set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes
2845    set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[199]2846else
[292]2847    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
[199]2848end
2849
2850
2851%-------------------------------------------------------------------
2852%----Executes on button press in 'record': records the current flags of manual correction.
2853%-------------------------------------------------------------------
2854function record_Callback(hObject, eventdata, handles)
2855% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2856filename=read_file_boxes(handles);
2857[erread,message]=fileattrib(filename);
2858if ~isempty(message) && ~isequal(message.UserWrite,1)
2859     msgbox_uvmat('ERROR',['no writting access to ' filename])
2860     return
2861end
2862test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
[236]2863test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
[199]2864if ~test_civ2 && ~test_civ1
2865    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2866end
2867if test_civ2
2868    nbname='nb_vectors2';
2869   flagname='vec2_FixFlag';
2870   attrname='fix2';
2871end
2872if test_civ1
2873    nbname='nb_vectors';
2874   flagname='vec_FixFlag';
2875   attrname='fix';
2876end
2877%write fix flags in the netcdf file
2878UvData=get(handles.uvmat,'UserData');
2879hhh=which('netcdf.open');% look for built-in matlab netcdf library
2880if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
2881    nc=netcdf.open(filename,'NC_WRITE');
2882    netcdf.reDef(nc);
2883    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1);
2884    dimid = netcdf.inqDimID(nc,nbname);
2885    try
2886        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2887    catch
2888        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2889    end
2890    netcdf.endDef(nc);
2891    netcdf.putVar(nc,varid,UvData.axes3.FF);
2892    netcdf.close(nc); 
2893else %old netcdf library
2894    netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2895end
2896
2897%-------------------------------------------------------------------
2898%----Correct the netcdf file, using toolbox (old versions of Matlab).
2899%-------------------------------------------------------------------
2900function netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2901nc=netcdf(filename,'write'); %open netcdf file
2902result=redef(nc);
2903eval(['nc.' attrname '=1;']);
2904theDim=nc(nbname) ;% get the number of velocity vectors
2905nb_vectors=size(theDim);
2906var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2907var_FixFlag(1:nb_vectors)=AxeData.FF;%
2908fin=close(nc);
2909
2910
2911%-------------------------------------------------------------------
2912%determines the fields to read from the interface
2913%------------------------------------------------------------------
[236]2914function VelType=setfield(handles)
2915VelTypeList=get(handles.VelType,'String');
2916index=get(handles.VelType,'Value');
2917VelType=VelTypeList{index};
[199]2918
[236]2919% VelType=[]; %default
2920% if (get(handles.VelType,'Value') == 1);
2921%         VelType='civ1';
2922% % interp1   
2923% elseif (get(handles.interp1,'Value') == 1);
2924%     VelType='interp1';
2925% % filter1   
2926% elseif (get(handles.filter1,'Value') == 1);
2927%     VelType='filter1'; 
2928% % CIV2
2929% elseif (get(handles.civ2,'Value') == 1);
2930%     VelType='civ2';
2931% % interp2   
2932% elseif (get(handles.interp2,'Value') == 1);
2933%     VelType='interp2';
2934% % filter2   
2935% elseif (get(handles.filter2,'Value') == 1); 
2936%     VelType='filter2';
2937% end
2938%
2939% if isequal(get(handles.filter2,'Visible'),'on');
2940%     civ=6;
2941% % interp1   
2942% elseif isequal(get(handles.interp2,'Visible'),'on');
2943%     civ=5;
2944% % filter1   
2945% elseif isequal(get(handles.civ2,'Visible'),'on');
2946%     civ=4; 
2947% % CIV2
2948% elseif isequal(get(handles.filter1,'Visible'),'on');
2949%    civ=3;
2950% % interp2   
2951% elseif isequal(get(handles.interp1,'Visible'),'on');
2952%     civ=2;
2953% % filter2   
2954% elseif isequal(get(handles.VelType,'Visible'),'on'); 
2955%     civ=1;
2956% else
2957%     civ=0;
2958% end
[199]2959
2960%-------------------------------------------------------------------
2961%determines the veltype of the second field to read from the iinterface
2962%------------------------------------------------------------------
2963function VelType=setfield_1(handles)
[236]2964VelTypeList=get(handles.VelType_1,'String');
2965index=get(handles.VelType_1,'Value');
2966VelType=VelTypeList{index};
2967% VelType=[]; %default
2968% if (get(handles.VelType_1,'Value') == 1);
2969%     VelType='civ1';
2970% % interp1   
2971% elseif (get(handles.interp1_1,'Value') == 1);
2972%     VelType='interp1';
2973% % filter1   
2974% elseif (get(handles.filter1_1,'Value') == 1);
2975%     VelType='filter1'; 
2976% % CIV2
2977% elseif (get(handles.civ2_1,'Value') == 1);
2978%     VelType='civ2';
2979% % interp2   
2980% elseif (get(handles.interp2_1,'Value') == 1);
2981%     VelType='interp2';
2982% % filter2   
2983% elseif (get(handles.filter2_1,'Value') == 1); 
2984%     VelType='filter2';
2985% end
[199]2986
2987
2988%---------------------------------------------------
2989% --- Executes on button press in SubField
2990function SubField_Callback(hObject, eventdata, handles)
[236]2991% huvmat=get(handles.run0,'parent');
2992UvData=get(handles.uvmat,'UserData');
[199]2993if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
2994    set(handles.RootPath_1,'String','')
2995    set(handles.RootFile_1,'String','')
2996    set(handles.SubDir_1,'String','');
2997    set(handles.FileIndex_1,'String','');
2998    set(handles.FileExt_1,'String','');
2999    set(handles.RootPath_1,'Visible','off')
3000    set(handles.RootFile_1,'Visible','off')
3001    set(handles.SubDir_1,'Visible','off');
3002    set(handles.FileIndex_1,'Visible','off');
3003    set(handles.FileExt_1,'Visible','off');
3004    set(handles.Fields_1,'Value',1);%set to blank state
[236]3005    set(handles.VelType_1,'Value',1);%set to blank state
3006    if ~strcmp(get(handles.VelType,'Visible'),'on')
3007        set(handles.VelType_1,'Visible','off')
3008    end
3009%     set_veltype_display([handles.VelType_1 handles.interp1_1 handles.filter1_1 ...
3010%             handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
[199]3011    if isfield(UvData,'XmlData_1')
3012        UvData=rmfield(UvData,'XmlData_1');
3013    end
[236]3014    set(handles.uvmat,'UserData',UvData);
[199]3015    run0_Callback(hObject, eventdata, handles); %run
3016else
3017    MenuBrowse_1_Callback(hObject, eventdata, handles)
3018end
3019
3020%------------------------------------------------------------------------
3021% --- read the data displayed for the input rootfile windows (new)
3022function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
3023%------------------------------------------------------------------------
3024RootPath=get(handles.RootPath,'String');
3025FileName=RootPath; %default
3026SubDir=get(handles.SubDir,'String');
3027if ~isempty(SubDir) && ~isequal(SubDir,'')
3028    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
3029        SubDir(1)=[]; %suppress possible / or \ separator
3030    end
3031    FileName=fullfile(RootPath,SubDir);
3032end
3033RootFile=get(handles.RootFile,'String');
3034if ~isempty(RootFile) && ~isequal(RootFile,'')
3035    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3036        RootFile(1)=[]; %suppress possible / or \ separator
3037    end
3038    FileName=fullfile(FileName,RootFile);
3039end
3040FileBase=fullfile(RootPath,RootFile);
3041FileIndices=get(handles.FileIndex,'String');
3042FileExt=get(handles.FileExt,'String');
3043FileName=[FileName FileIndices FileExt];
3044
3045%------------------------------------------------------------------------
3046% ---- read the data displayed for the second input rootfile windows
3047function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
3048%------------------------------------------------------------------------
3049RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
3050if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
3051    RootPath_1=get(handles.RootPath,'String');
3052end;
3053FileName_1=RootPath_1; %default
3054SubDir_1=get(handles.SubDir_1,'String');
3055if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
3056    SubDir_1=get(handles.SubDir,'String');
3057end
3058if numel(SubDir_1)>=1
3059    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
3060        SubDir_1(1)=[]; %suppress possible / or \ separator
3061    end
3062    FileName_1=fullfile(RootPath_1,SubDir_1);
3063end
3064RootFile_1=get(handles.RootFile_1,'String');
3065if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
3066    RootFile_1=get(handles.RootFile,'String');
3067end
3068if numel(RootFile_1)>=1
[210]3069    if ~(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
[199]3070        RootFile_1(1)=[];%suppress possible / or \ separator
3071    end
3072    FileName_1=fullfile(FileName_1,RootFile_1);
3073end
3074FileBase_1=fullfile(RootPath_1,RootFile_1);
3075if isequal(get(handles.FileIndex_1,'Visible'),'off')
3076    FileIndices_1=get(handles.FileIndex,'String');
3077else
3078    FileIndices_1=get(handles.FileIndex_1,'String');
3079end
3080FileExt_1=get(handles.FileExt_1,'String');
[246]3081if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"')
3082    FileExt_1=get(handles.FileExt,'String');%read FileExt by default
3083end
[199]3084FileName_1=[FileName_1 FileIndices_1 FileExt_1];
3085
3086%------------------------------------------------------------------------
3087% --- Executes on menu selection Fields
3088function Fields_Callback(hObject, eventdata, handles)
3089%------------------------------------------------------------------------
3090list_fields=get(handles.Fields,'String');% list menu fields
3091index_fields=get(handles.Fields,'Value');% selected string index
3092field= list_fields{index_fields(1)}; % selected string
3093if isequal(field,'get_field...')
[295]3094    set(handles.FixVelType,'visible','off')
3095    set(handles.VelType,'visible','off')
3096    set(handles.VelType_1,'visible','off')
3097    filename=read_file_boxes(handles);
3098    hget_field=findobj(allchild(0),'name','get_field');
3099    if ~isempty(hget_field)
3100        delete(hget_field)
3101    end
3102    hget_field=get_field(filename);
3103    set(hget_field,'Name','get_field')
3104    hhget_field=guidata(hget_field);
3105    set(hhget_field.list_fig,'Value',1)
3106    set(hhget_field.list_fig,'String',{'uvmat'})
3107    set(handles.transform_fct,'Value',1)% no transform by default
3108    set(handles.path_transform,'String','')
[199]3109    return %no action
3110end
3111list_fields=get(handles.Fields_1,'String');% list menu fields
3112index_fields=get(handles.Fields_1,'Value');% selected string index
3113field_1= list_fields{index_fields(1)}; % selected string
3114UvData=get(handles.uvmat,'UserData');
3115
3116%read the rootfile input display
3117[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
3118[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
3119NomTypeNew=NomType;%default
[295]3120if isequal(field,'image')
3121    if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
3122        NomTypeNew='_i_j';
3123    elseif isequal(NomType,'#_ab')
3124        NomTypeNew='#a';
3125    elseif isequal(NomType,'_i1-i2')
3126        NomTypeNew='_i';
3127    end
3128    imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3129    if ~exist(imagename,'file')
3130        [FileName,PathName] = uigetfile( ...
3131            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
[199]3132            '*.jpg',' jpeg image files'; ...
3133            '*.png','.png image files'; ...
3134            '*.tif','.tif image files'; ...
3135            '*.avi;*.AVI','.avi movie files'; ...
3136            '*.vol','.volume images (png)'; ...
3137            '*.*',  'All Files (*.*)'}, ...
[295]3138            'Pick an image',imagename);   
3139        imagename=[PathName FileName];
3140    end
3141     % display the selected field and related information
3142    display_file_name(hObject, eventdata, handles,imagename)%display the image
3143    return
[199]3144else
3145    ext=get(handles.FileExt,'String');
3146    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
[295]3147        [FileName,PathName] = uigetfile( ...
3148            {'*.nc', ' (*.nc)';
[199]3149            '*.nc',' netcdf files'; ...
3150            '*.*',  'All Files (*.*)'}, ...
[295]3151            'Pick a netcdf file',FileBase);
3152        filename=[PathName FileName];
3153        % display the selected field and related information
[199]3154        display_file_name(hObject, eventdata, handles,filename)
3155        return
3156    end
3157end
3158indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3159set(handles.FileIndex,'String',indices)
3160set(handles.FileIndex,'UserData',NomTypeNew)
3161%common to Fields_1_Callback
3162if isequal(field,'image')||isequal(field_1,'image')
[292]3163    set(handles.TitleNpx,'Visible','on')% visible npx,pxcm... buttons
3164    set(handles.TitleNpy,'Visible','on')
3165    set(handles.num_Npx,'Visible','on')
3166    set(handles.num_Npy,'Visible','on')
[199]3167else
[292]3168    set(handles.TitleNpx,'Visible','off')% visible npx,pxcm... buttons
3169    set(handles.TitleNpy,'Visible','off')
3170    set(handles.num_Npx,'Visible','off')
3171    set(handles.num_Npy,'Visible','off')
[199]3172end
3173setfield(handles);% update the field structure ('civ1'....)
3174if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3175    run0_Callback(hObject, eventdata, handles)
3176end
3177
3178%---------------------------------------------------
3179% --- Executes on menu selection Fields
3180function Fields_1_Callback(hObject, eventdata, handles)
3181%-------------------------------------------------
3182list_fields=get(handles.Fields,'String');% list menu fields
3183index_fields=get(handles.Fields,'Value');% selected string index
3184field= list_fields{index_fields(1)}; % selected string
3185list_fields=get(handles.Fields_1,'String');% list menu fields
3186index_fields=get(handles.Fields_1,'Value');% selected string index
3187field_1= list_fields{index_fields(1)}; % selected string for the second field
3188if isequal(field_1,'') %remove second field if 'blank' field is selected
3189    set(handles.SubField,'Value',0)
3190    SubField_Callback(hObject, eventdata, handles)
3191    return
3192end
3193UvData=get(handles.uvmat,'UserData');
3194
3195%read the rootfile input display
[246]3196[FileName,RootPath,FileBase,FileIndices,FileExt_1]=read_file_boxes_1(handles);
[295]3197[P,F,str1,str2,str_a,str_b,E,NomType_1]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_1]);
[246]3198% if isempty(FileExt_prev)|| strcmp(FileExt_prev,'')
3199%     FileExt_1=get(handles.FileExt,'String');
3200% else
3201%     FileExt_1=FileExt_prev;
3202% end
[295]3203% NomType_1=get(handles.FileIndex_1,'UserData');
[210]3204if isempty(NomType_1)|| strcmp(NomType_1,'')
[295]3205    [FileName,RootPath,FileBase,FileIndices,FileExt_1]=read_file_boxes(handles);
3206    [P,F,str1,str2,str_a,str_b,E,NomType_1]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_1]);
3207%     NomType_1=get(handles.FileIndex,'UserData');
[199]3208end
3209NomTypeNew=NomType_1;%default
3210
3211set(handles.SubField,'Value',1)%introduce second field
3212if isfield(UvData,'XmlData')
3213    UvData.XmlData_1=UvData.XmlData;
3214end
3215set(handles.FileIndex_1,'Visible','on')
3216set(handles.FileExt_1,'Visible','on')
3217RootPath_1=get(handles.RootPath_1,'String');
3218RootFile_1=get(handles.RootFile_1,'String');
3219if isempty(RootPath_1)||isequal(RootPath_1,'')
3220    set(handles.RootPath_1,'String','"')
3221end
3222if isempty(RootFile_1) || isequal(RootFile_1,'')
3223    set(handles.RootFile_1,'String','"')
3224end
3225if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
3226    RootFile_1(1)=[];
3227end
3228
3229if isequal(field_1,'get_field...')
[236]3230     veltype_handles=[handles.VelType handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
[199]3231     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3232     filename=read_file_boxes_1(handles);
3233     hget_field=findobj(allchild(0),'name','get_field_1');
3234     if ~isempty(hget_field)
3235         delete(hget_field)
3236     end
3237     hget_field=get_field(filename);
3238     set(hget_field,'name','get_field_1')
3239     hhget_field=guidata(hget_field);
3240     set(hhget_field.list_fig,'Value',1)
3241     set(hhget_field.list_fig,'String',{'uvmat'})
3242     set(handles.transform_fct,'Value',1)% no transform by default
3243     set(handles.path_transform,'String','')
3244    return %no action
3245end
3246if isequal(field_1,'image')
3247    % transform netc type to the corresponding image type
[227]3248    if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')|| isequal(NomType_1,'#_ab')|| isequal(NomType_1,'_i1-i2')
[236]3249        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory   
[227]3250        if isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')
[199]3251            NomTypeNew='_i_j';
3252        elseif isequal(NomType_1,'#_ab')
3253            NomTypeNew='#a';
3254        elseif isequal(NomType_1,'_i1-i2')
3255            NomTypeNew='_i';
3256        end 
3257    end
3258    imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3259    if ~exist(imagename,'file')
3260        [FileName,PathName] = uigetfile( ...
3261            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3262            '*.jpg',' jpeg image files'; ...
3263            '*.png','.png image files'; ...
3264            '*.tif','.tif image files'; ...
3265            '*.avi;*.AVI','.avi movie files'; ...
3266            '*.vol','.volume images (png)'; ...
3267            '*.*',  'All Files (*.*)'}, ...
3268            'Pick an image',imagename);
3269        % display the selected field and related information
3270        imagename=[PathName FileName];
3271    end
3272    display_file_name_1(hObject, eventdata, handles,imagename)%display the image
3273    return
3274else
3275    set(handles.SubDir_1,'Visible','on')
[246]3276    if ~isequal(FileExt_1,'.nc') %find the new NomType if the previous display was not already a netcdf file
[199]3277        RootPath_1=get(handles.RootPath_1,'String');
3278        RootFile_1=get(handles.RootFile_1,'String');
[236]3279        if isempty(RootPath_1)||isequal(RootPath_1,'')
[199]3280            set(handles.RootPath_1,'String','"')
3281        end
[236]3282        if isempty(RootFile_1) || isequal(RootFile_1,'')
[199]3283            set(handles.RootFile_1,'String','"')
3284        end
[236]3285        if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
[199]3286            RootFile_1(1)=[];
3287        end
3288        filebase_1=fullfile(RootPath_1,RootFile_1);
3289        SubDir_1=get(handles.SubDir,'String');
3290        if isempty(SubDir_1)||isequal(SubDir_1,'')
3291            if isfield(UvData,'SubDir_1')
3292                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3293            else
3294                SubDir_1='?';
3295            end
3296        end
3297        str1=get(handles.i1,'String');
3298        str_a=get(handles.j1,'String');
3299        if isequal(NomType_1,'#_ab')||isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')||isequal(NomType_1,'_i1-i2')
3300            NomTypeNew=NomType_1;
3301        elseif isequal(NomType_1,'#a')
3302             [filename, n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),stra2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3303             NomTypeNew='#_ab';
3304        elseif isequal(NomType_1,'_i_j')
3305             [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);
3306            if idetect==1
3307                NomTypeNew='_i1-i2_j';
3308            else
3309                NomTypeNew='_i_j1-j2';
3310            end
3311        else %for instance avi files or any ima_num series
3312            [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
3313            NomTypeNew='_i1-i2';
3314        end           
3315        [Path,Name]=fileparts(filebase_1);
3316        set(handles.FileExt_1,'String','.nc');
3317        if ~isempty(SubDir_1) && ~strcmp(SubDir_1,'''')&& ~strcmp(SubDir_1,'"')&& ~strcmp(SubDir_1(1),'/')
3318            SubDir_1=['/' SubDir_1];
3319        end
3320        set(handles.SubDir_1,'String',SubDir_1);
3321    end
[236]3322    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
3323        set(handles.VelType_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
[199]3324        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3325        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3326        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3327    elseif isequal(field_1,'more...'); %add new item to the menu
[236]3328        set(handles.VelType_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
[199]3329        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3330        str=calc_field;%get the list of available scalars by the function calc_scal
3331        [ind_answer,v] = listdlg('PromptString','Select a file:',...
3332                'SelectionMode','single',...
3333                'ListString',str);
3334       % edit the choice in the field and action menu
3335        scalar=cell2mat(str(ind_answer));
3336        menu=update_menu(handles.Fields_1,scalar);
3337        set(handles.Fields_1,'String',menu);% store the selected scalar type
3338    end
3339end
3340str1=get(handles.i1,'String');
3341str2=get(handles.i2,'String');
3342str_a=get(handles.j1,'String');
3343str_b=get(handles.j2,'String');
3344indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3345set(handles.FileIndex_1,'String',indices)
3346set(handles.FileIndex_1,'UserData',NomTypeNew)
3347
3348%common to Fields_Callback
[236]3349if isequal(field,'image')||isequal(field_1,'image')
[292]3350    set(handles.TitleNpx,'Visible','on')% visible npx,pxcm... buttons
3351    set(handles.TitleNpy,'Visible','on')
3352    set(handles.num_Npx,'Visible','on')
3353    set(handles.num_Npy,'Visible','on')
[199]3354%     set(handles.fix_pair,'Value',0)
3355else
[292]3356    set(handles.TitleNpx,'Visible','off')% visible npx,pxcm... buttons
3357    set(handles.TitleNpy,'Visible','off')
3358    set(handles.num_Npx,'Visible','off')
3359    set(handles.num_Npy,'Visible','off')
[199]3360%     set(handles.fix_pair,'Value',1)
3361end
[236]3362if isequal(field,'velocity')||isequal(field_1,'velocity');
[199]3363    state_vect='on';
3364else
3365    state_vect='off';
3366end
[236]3367if ~isequal(field,'velocity')||(~isequal(field_1,'velocity')&~isequal(field_1,''));
[199]3368    state_scal='on';
3369else
3370    state_scal='off';
3371end
3372set(handles.uvmat,'UserData',UvData)
3373setfield(handles);% update the field structure ('civ1'....)
3374if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3375    run0_Callback(hObject, eventdata, handles)
3376end
3377
3378%------------------------------------------------------------------------
3379% --- set the visibility of relevant velocity type menus:
[236]3380function menu=set_veltype_display(Civ)
[199]3381%------------------------------------------------------------------------
3382if isequal(Civ,0)
3383    imax=0;
3384elseif isequal(Civ,1) || isequal(Civ,2)
3385   imax=1;
3386elseif isequal(Civ,3)
3387    imax=3;
3388elseif isequal(Civ,4) || isequal(Civ,5)
3389    imax=4;
3390elseif isequal(Civ,6) %patch2
3391    imax=6;
3392end
[236]3393menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
3394menu=menu(1:imax);
3395% for ibutton=1:imax;
3396%     set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3397% end
3398% % for ibutton=max(imax+1,2):6;
3399% for ibutton=imax+1:6;
3400%     set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3401%     set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3402% end
[199]3403
3404%-------------------------------------------------------------------
[236]3405% --- Executes on button press in VelType.
3406function VelType_Callback(hObject, eventdata, handles)
[199]3407%-------------------------------------------------------------------
[236]3408% if get(handles.VelType,'Value')==1
3409%     reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.VelType)
3410% else
3411%     reset_vel_type([handles.VelType handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3412% end
3413set(handles.FixVelType,'Value',1)
[199]3414run0_Callback(hObject, eventdata, handles)
3415
3416%---------------------------------------------
[236]3417function VelType_1_Callback(hObject, eventdata, handles)
[199]3418%---------------------------------------------
[236]3419 
[246]3420set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic)
[236]3421%refresh field with a second filename=first fiel name
3422set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
[246]3423drawnow   
[236]3424filename=read_file_boxes(handles);
[246]3425
3426index=get(handles.VelType_1,'Value');
3427if index==1
3428        filename_1='';% we plot the current field without the second field
3429        set(handles.SubField,'Value',0)
3430        SubField_Callback(hObject, eventdata, handles)
3431elseif get(handles.SubField,'Value')% if subfield is already 'on'
3432    filename_1=read_file_boxes_1(handles); %read the current second field
[199]3433else
[246]3434     filename_1=filename;% we compare two fields in the same file
3435     set(handles.SubField,'Value',1)
[199]3436end
[246]3437
[236]3438num_i1=stra2num(get(handles.i1,'String'));
3439num_i2=stra2num(get(handles.i2,'String'));
3440num_j1=stra2num(get(handles.j1,'String'));
3441num_j2=stra2num(get(handles.j2,'String'));
[199]3442
[236]3443errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
[199]3444
[236]3445if ~isempty(errormsg)
3446    msgbox_uvmat('ERROR',errormsg);
[199]3447else
[236]3448    set(handles.i1,'BackgroundColor',[1 1 1])
3449    set(handles.i2,'BackgroundColor',[1 1 1])
3450    set(handles.j1,'BackgroundColor',[1 1 1])
3451    set(handles.j2,'BackgroundColor',[1 1 1])
3452    set(handles.FileIndex,'BackgroundColor',[1 1 1])
3453    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
[199]3454end
[236]3455set(handles.run0,'BackgroundColor',[1 0 0])
[199]3456
3457%-----------------------------------------------
3458% --- reset civ buttons
3459function reset_vel_type(handles_civ0,handle1)
3460for ibutton=1:length(handles_civ0)
3461    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3462    set(handles_civ0(ibutton),'Value',0)
3463end
3464if exist('handle1','var')%handles of selected button
3465        set(handle1,'BackgroundColor',[1 1 0]) 
3466end
3467
3468%-------------------------------------------------------
3469% --- Executes on button press in MENUVOLUME.
3470%-------------------------------------------------------
3471function VOLUME_Callback(hObject, eventdata, handles)
3472%errordlg('command VOL not implemented yet')
3473if ishandle(handles.UVMAT_title)
3474    delete(handles.UVMAT_title)
3475end
3476UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3477if isequal(get(handles.VOLUME,'Value'),1)
[292]3478    set(handles.CheckZoom,'Value',0)
3479    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
[199]3480    set(handles.edit_vect,'Value',0)
3481    edit_vect_Callback(hObject, eventdata, handles)
3482    set(handles.edit_object,'Value',0)
3483    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3484%     set(handles.cal,'Value',0)
3485%     set(handles.cal,'BackgroundColor',[0 1 0])
3486    set(handles.edit_vect,'Value',0)
3487    edit_vect_Callback(hObject, eventdata, handles)
3488    %initiate set_object GUI
3489    data.TITLE='VOLUME';
3490    if isfield(UvData,'CoordType')
3491        data.CoordType=UvData.CoordType;
3492    end
3493    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3494        data.RangeY=UvData.Mesh;
3495        data.RangeX=UvData.Mesh;
3496        data.DX=UvData.Mesh;
3497        data.DY=UvData.Mesh;
3498    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3499        np=size(UvData.Field.A);
3500        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3501        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3502        data.RangeY=max(meshx,meshy);
3503        data.RangeX=max(meshx,meshy);
3504        data.DX=max(meshx,meshy);
3505    end
3506    data.ParentButton=handles.VOLUME;
3507    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3508    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3509                                                      % associate the set_object interface handle to the plotting axes
3510    if isfield(UvData.OpenParam,'SetObjectOrigin')                                               
3511    pos_uvmat=get(huvmat,'Position');
3512    pos_set_object(1:2)=UvData.OpenParam.SetObjectOrigin + pos_uvmat(1:2);
3513    pos_set_object(3:4)=UvData.OpenParam.SetObjectSize .* pos_uvmat(3:4); 
3514    set(hset_object,'Position',pos_set_object)
3515    end
3516    UvData.MouseAction='create_object';
3517else
3518    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3519    UvData.MouseAction='none';
3520end
3521set(huvmat,'UserData',UvData)
3522
3523%-------------------------------------------------------
3524function edit_vect_Callback(hObject, eventdata, handles)
3525%-------------------------------------------------------
3526%
3527% UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3528if isequal(get(handles.edit_vect,'Value'),1)
3529    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
[236]3530    test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
[199]3531    if ~test_civ2 && ~test_civ1
3532        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3533    end
3534    set(handles.record,'Visible','on')
3535    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3536    set(handles.edit_object,'Value',0)
[292]3537    set(handles.CheckZoom,'Value',0)
3538    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
[199]3539%     set(handles.create,'Value',0)
3540%     set(handles.create,'BackgroundColor',[0 1 0])
3541    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3542    set(gcf,'Pointer','arrow')
3543%     UvData.MouseAction='edit_vect';
3544else
3545    set(handles.record,'Visible','off')
3546    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3547%     UvData.MouseAction='none';
3548end
3549% set(handles.uvmat,'UserData',UvData)
3550
3551%----------------------------------------------
3552function save_mask_Callback(hObject, eventdata, handles)
3553%-----------------------------------------------------------------------
3554UvData=get(handles.uvmat,'UserData');
3555
3556flag=1;
3557npx=size(UvData.Field.A,2);
3558npy=size(UvData.Field.A,1);
3559xi=0.5:npx-0.5;
3560yi=0.5:npy-0.5;
3561[Xi,Yi]=meshgrid(xi,yi);
3562if isfield(UvData,'Object')
3563    for iobj=1:length(UvData.Object)
3564        ObjectData=UvData.Object{iobj};
3565        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3566            flagobj=1;
3567            testphys=0; %coordinates in pixels by default
3568            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3569                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3570                    Calib=UvData.XmlData.GeometryCalib;
3571                    testphys=1;
3572                end
3573            end
3574            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3575                if isequal(ObjectData.Style,'polygon')
3576                    X=ObjectData.Coord(:,1);
3577                    Y=ObjectData.Coord(:,2);
3578                    if testphys
3579                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3580                    end
3581                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
3582                elseif isequal(ObjectData.Style,'ellipse')
3583                    if testphys
3584                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3585                    end
3586                    RangeX=max(ObjectData.RangeX);
3587                    RangeY=max(ObjectData.RangeY);
3588                    X2Max=RangeX*RangeX;
3589                    Y2Max=RangeY*RangeY;
3590                    distX=(Xi-ObjectData.Coord(1,1));
3591                    distY=(Yi-ObjectData.Coord(1,2));
3592                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3593                elseif isequal(ObjectData.Style,'rectangle')
3594                    if testphys
3595                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3596                    end
3597                    distX=abs(Xi-ObjectData.Coord(1,1));
3598                    distY=abs(Yi-ObjectData.Coord(1,2));
3599                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3600                end
3601                if isequal(ObjectData.ProjMode,'mask_outside')
3602                    flagobj=~flagobj;
3603                end
3604                flag=flag & flagobj;
3605            end
3606        end
3607    end
3608end
3609% flag=~flag;
3610%mask name
3611RootPath=get(handles.RootPath,'String');
3612RootFile=get(handles.RootFile,'String');
3613if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3614        RootFile(1)=[];
3615end
3616filebase=fullfile(RootPath,RootFile);
3617list=get(handles.masklevel,'String');
3618masknumber=num2str(length(list));
3619maskindex=get(handles.masklevel,'Value');
3620mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3621imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3622imflag=flipdim(imflag,1);
3623% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3624msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3625imwrite(imflag,mask_name,'BitDepth',8);
3626
3627%display the mask
3628%update_mask(handles,num_i1,num_j1)
3629figure;
3630vec=linspace(0,1,256);%define a linear greyscale colormap
3631map=[vec' vec' vec'];
3632colormap(map)
3633
3634image(imflag);
3635
3636%-------------------------------------------------------------------
3637%-------------------------------------------------------------------
3638%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3639
3640%------------------------------------------------------------------
3641
3642
3643
3644%------------------------------------------------------------------
[292]3645% --- Executes on selection change in ListColorScalar: choice of the color code.
[199]3646%
[292]3647function ListColorScalar_Callback(hObject, eventdata, handles)
[199]3648%------------------------------------------------------------------
3649% edit the choice for color code
[292]3650list_code=get(handles.ListColorScalar,'String');% list menu fields
3651index_code=get(handles.ListColorScalar,'Value');% selected string index
[199]3652col_code= list_code{index_code(1)}; % selected field
3653if isequal(col_code,'black') || isequal(col_code,'white')
[292]3654   set(handles.Slider1,'Visible','off')
3655   set(handles.Slider2,'Visible','off')
3656   set(handles.num_ColCode1,'Visible','off')
3657   set(handles.num_ColCode2,'Visible','off')
3658   set(handles.CheckFixVecColor,'Visible','off')
[199]3659   set_vec_col_bar(handles)
3660else
[292]3661   set(handles.Slider1,'Visible','on')
3662   set(handles.Slider2,'Visible','on')
3663   set(handles.num_ColCode1,'Visible','on')
3664   set(handles.num_ColCode2,'Visible','on')
3665   set(handles.CheckFixVecColor,'Visible','on') 
[199]3666   if isequal(col_code,'ima_cor')
[292]3667       set(handles.CheckFixVecColor,'Value',0)%fixed scale by default
3668       set(handles.VecColBar,'Value',0)% 3 colors r,g,b by default
3669       set(handles.Slider1,'Min',0);
3670       set(handles.Slider1,'Max',1);
3671       set(handles.Slider2,'Min',0);
3672       set(handles.Slider2,'Max',1);
[199]3673 %      set(handles.min_title_vec,'String','0')
[292]3674       set(handles.num_MaxVec,'String','1')
3675       set(handles.num_ColCode1,'String','0.333')
[309]3676       num_ColCode1_Callback(hObject, eventdata, handles)
[292]3677       set(handles.num_ColCode2,'String','0.666')
[309]3678       num_ColCode2_Callback(hObject, eventdata, handles)
[199]3679   else
[292]3680       set(handles.CheckFixVecColor,'Value',1)%auto scale between min,max by default
3681       set(handles.VecColBar,'Value',1)% colormap 'jet' by default
3682       minval=get(handles.Slider1,'Min');
3683       maxval=get(handles.Slider1,'Max');
3684       set(handles.Slider1,'Value',minval)
3685       set(handles.Slider2,'Value',maxval)
[199]3686       set_vec_col_bar(handles)
3687   end
3688%    slider_update(handles)
3689end
3690%replot the current graph
3691run0_Callback(hObject, eventdata, handles)
3692
3693
3694%----------------------------------------------------------------
3695% -- Executes on slider movement to set the color code
3696%
[292]3697function Slider1_Callback(hObject, eventdata, handles)
[199]3698%------------------------------------------------------------------
[292]3699slider1=get(handles.Slider1,'Value');
3700min_val=str2num(get(handles.num_MinVec,'String'));
3701max_val=str2num(get(handles.num_MaxVec,'String'));
[199]3702col=min_val+(max_val-min_val)*slider1;
[292]3703set(handles.num_ColCode1,'String',num2str(col))
3704if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed
3705    set(handles.Slider2,'Value',col)
3706    set(handles.num_ColCode2,'String',num2str(col))
[199]3707end
[309]3708num_ColCode1_Callback(hObject, eventdata, handles)
[199]3709
3710%----------------------------------------------------------------
3711% Executes on slider movement to set the color code
3712%----------------------------------------------------------------
[292]3713function Slider2_Callback(hObject, eventdata, handles)
3714slider2=get(handles.Slider2,'Value');
3715min_val=str2num(get(handles.num_MinVec,'String'));
3716max_val=str2num(get(handles.num_MaxVec,'String'));
[199]3717col=min_val+(max_val-min_val)*slider2;
[292]3718set(handles.num_ColCode2,'String',num2str(col))
3719if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed
3720    set(handles.Slider1,'Value',col)
3721    set(handles.num_ColCode1,'String',num2str(col))
[199]3722end
[309]3723num_ColCode2_Callback(hObject, eventdata, handles)
[199]3724
3725%----------------------------------------------------------------
[309]3726% --- Execute on return carriage on the edit box corresponding to slider 1
[199]3727%----------------------------------------------------------------
[309]3728function num_ColCode1_Callback(hObject, eventdata, handles)
[199]3729set_vec_col_bar(handles)
3730update_plot(handles);
3731
3732%----------------------------------------------------------------
[309]3733% --- Execute on return carriage on the edit box corresponding to slider 2
[199]3734%----------------------------------------------------------------
[292]3735function num_ColCode2_Callback(hObject, eventdata, handles)
[199]3736set_vec_col_bar(handles)
3737update_plot(handles);
[309]3738%------------------------------------------------------------------------
[199]3739%-------------------------------------------------------
[292]3740% --- Executes on button press in CheckFixVecColor.
[199]3741%-------------------------------------------------------
[292]3742function VecColBar_Callback(hObject, eventdata, handles)
[199]3743set_vec_col_bar(handles)
3744
3745%-------------------------------------------------------------
3746% --- Executes on selection change in transform_fct.
3747function transform_fct_Callback(hObject, eventdata, handles)
3748%-------------------------------------------------------------
3749UvData=get(handles.uvmat,'UserData');
3750menu=get(handles.transform_fct,'String');
3751ind_coord=get(handles.transform_fct,'Value');
3752coord_option=menu{ind_coord};
3753list_transform=get(handles.transform_fct,'UserData');
3754ff=functions(list_transform{end}); 
3755if isequal(coord_option,'more...');
3756    coord_fct='';
3757    prompt = {'Enter the name of the transform function'};
3758    dlg_title = 'user defined transform';
3759    num_lines= 1;
3760    [FileName, PathName] = uigetfile( ...
3761       {'*.m', ' (*.m)';
3762        '*.m',  '.m files '; ...
3763        '*.*', 'All Files (*.*)'}, ...
3764        'Pick a file', ff.file);
3765    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
3766        PathName(end)=[];
3767    end
3768    transform_selected =fullfile(PathName,FileName);
3769    if ~exist(transform_selected,'file')
3770           return
3771    end
3772   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
3773   if ~isequal(ext_fct,'.m')
3774        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
3775        return
3776   end
3777   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
3778   ind_coord=get(handles.transform_fct,'Value');
3779   addpath(PathName)
3780   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
3781   set(handles.transform_fct,'UserData',list_transform)
3782   rmpath(PathName)
3783   % save the new menu in the personal file 'uvmat_perso.mat'
3784   dir_perso=prefdir;%personal Matalb directory
3785   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3786   if exist(profil_perso,'file')
3787       nb_builtin=UvData.OpenParam.NbBuiltin;
3788       for ilist=nb_builtin+1:numel(list_transform)
3789           ff=functions(list_transform{ilist});
3790           transform_fct{ilist-nb_builtin}=ff.file;
3791       end
3792        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
3793   end   
3794end
3795
3796%check the current path to the selected function
3797if isa(list_transform{ind_coord},'function_handle')
3798    func=functions(list_transform{ind_coord});
3799    set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
3800else
3801    set(handles.path_transform,'String','')
3802end
3803
[292]3804set(handles.CheckFixLimits,'Value',0)
3805set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
[199]3806
3807%delete drawn objects
3808hother=findobj('Tag','proj_object');%find all the proj objects
3809for iobj=1:length(hother)
3810    delete_object(hother(iobj))
3811end
3812hother=findobj('Tag','DeformPoint');%find all the proj objects
3813for iobj=1:length(hother)
3814    delete_object(hother(iobj))
3815end
3816hh=findobj('Tag','calib_points');
3817if ~isempty(hh)
3818    delete(hh)
3819end
3820hhh=findobj('Tag','calib_marker');
3821if ~isempty(hhh)
3822    delete(hhh)
3823end
3824if isfield(UvData,'Object')
3825     UvData.Object=UvData.Object(1);
3826end
[315]3827%list_object=get(handles.ListObject,'String');
[302]3828set(handles.ListObject,'Value',1)
3829set(handles.ListObject,'String',{''})
3830%set(handles.list_object_2,'Value',1)
3831%set(handles.list_object_2,'String',{''})
3832%list_object_2_Callback(hObject, eventdata, handles)
[199]3833
3834%delete mask if it is displayed
[315]3835if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
[199]3836   UvData=rmfield(UvData,'MaskName'); %will impose mask refresh 
3837end
3838set(handles.uvmat,'UserData',UvData)
3839run0_Callback(hObject, eventdata, handles)
3840
[315]3841%------------------------------------------------------------------------
[199]3842function histo1_menu_Callback(hObject, eventdata, handles)
3843%--------------------------------------------
3844%plot first histo
3845huvmat=get(handles.histo1_menu,'parent');
3846histo_menu=get(handles.histo1_menu,'String');
3847histo_value=get(handles.histo1_menu,'Value');
3848FieldName=histo_menu{histo_value};
3849update_histo(handles.histo_u,huvmat,FieldName)
3850
[315]3851%------------------------------------------------------------------------
[199]3852function histo2_menu_Callback(hObject, eventdata, handles)
[315]3853%------------------------------------------------------------------------
[199]3854%plot second histo
3855huvmat=get(handles.histo2_menu,'parent');
3856histo_menu=get(handles.histo2_menu,'String');
3857histo_value=get(handles.histo2_menu,'Value');
3858FieldName=histo_menu{histo_value};
3859update_histo(handles.histo_v,huvmat,FieldName)
3860
[315]3861%------------------------------------------------------------------------
[199]3862%read the field .Fieldname stored in UvData and plot its histogram
3863function update_histo(haxes,huvmat,FieldName)
[315]3864%------------------------------------------------------------------------
[199]3865UvData=get(huvmat,'UserData');
3866if ~isfield(UvData.Field,FieldName)
3867    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
3868    return
3869end
3870Field=UvData.Field;
3871FieldHisto=eval(['Field.' FieldName]);
3872if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto))
3873    indsel=find(Field.FF==0);%find values marked as false
3874    if ~isempty(indsel)
3875        FieldHisto=FieldHisto(indsel);
3876    end
3877end
3878if isempty(Field)
3879    msgbox_uvmat('ERROR',['empty field ' FieldName])
3880else
3881    nxy=size(FieldHisto);
3882    Amin=double(min(min(min(FieldHisto))));%min of image
3883    Amax=double(max(max(max(FieldHisto))));%max of image
3884    if isequal(Amin,Amax)
[316]3885        %msgbox_uvmat('WARNING',['uniform field =' num2str(Amin)]);
3886        cla(haxes)
[199]3887    else
3888        Histo.ListVarName={FieldName,'histo'};
[258]3889        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
[199]3890            Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
3891        else
3892            if numel(nxy)==2
3893                Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
3894            else
3895                Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
3896            end
3897        end
3898        %unit
3899        units=[]; %default
3900        for ivar=1:numel(Field.ListVarName)
3901            if strcmp(Field.ListVarName{ivar},FieldName)
3902                if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
3903                    units=Field.VarAttribute{ivar}.units;
3904                    break
3905                end
3906            end
3907        end
3908        if ~isempty(units)
3909            Histo.VarAttribute{1}.units=units;
3910        end
3911        eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
[258]3912        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
[199]3913            C=reshape(double(FieldHisto),1,[]);% reshape in a vector
3914            eval(['Histo.histo(:,1)=hist(C, Histo.' FieldName ');']);  %calculate histogram
3915        else
3916            for col=1:size(FieldHisto,3)
3917                B=FieldHisto(:,:,col);
3918                C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
3919                eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
3920            end
3921        end
[292]3922%         set(haxes,'XLimMode','auto')%reset auto mode (after CheckZoom effect)
[199]3923%         set(haxes,'YLimMode','auto')
3924%         PlotParam.Auto_xy=1;
3925        plot_field(Histo,haxes);
3926    end
3927end
3928
3929%------------------------------------------------
3930%CALLBACKS FOR PLOTTING PARAMETERS
3931%-------------------------------------------------
3932
3933%------------------------------------------------------------------------
[292]3934function num_MinX_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_MaxX_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_MinY_Callback(hObject, eventdata, handles)
[199]3949%------------------------------------------
[292]3950set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3951set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[199]3952update_plot(handles);
3953
3954%------------------------------------------------------------------------
[292]3955function num_MaxY_Callback(hObject, eventdata, handles)
[199]3956%------------------------------------------------------------------------
[292]3957set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3958set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[199]3959update_plot(handles);
3960
3961%------------------------------------------------------------------------
[292]3962function num_MinA_Callback(hObject, eventdata, handles)
[199]3963%------------------------------------------
[292]3964set(handles.CheckFixScalar,'Value',1) %suppress auto mode
3965set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
3966MinA=str2double(get(handles.num_MinA,'String'));
3967MaxA=str2double(get(handles.num_MaxA,'String'));
[227]3968if MinA>MaxA% switch minA and maxA in case of error
3969    MinA_old=MinA;
3970    MinA=MaxA;
3971    MaxA=MinA_old;
[292]3972    set(handles.num_MinA,'String',num2str(MinA,5));
3973    set(handles.num_MaxA,'String',num2str(MaxA,5));
[227]3974end
[199]3975update_plot(handles);
3976
3977%------------------------------------------------------------------------
[292]3978function num_MaxA_Callback(hObject, eventdata, handles)
[199]3979%------------------------------------------------------------------------
[292]3980set(handles.CheckFixScalar,'Value',1) %suppress auto mode
3981set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
3982MinA=str2double(get(handles.num_MinA,'String'));
3983MaxA=str2double(get(handles.num_MaxA,'String'));
[227]3984if MinA>MaxA% switch minA and maxA in case of error
3985        MinA_old=MinA;
3986    MinA=MaxA;
3987    MaxA=MinA_old;
[292]3988    set(handles.num_MinA,'String',num2str(MinA,5));
3989    set(handles.num_MaxA,'String',num2str(MaxA,5));
[227]3990end
[199]3991update_plot(handles);
3992
3993%------------------------------------------------------------------------
[292]3994function CheckFixScalar_Callback(hObject, eventdata, handles)
[199]3995%------------------------------------------------------------------------
[292]3996test=get(handles.CheckFixScalar,'Value');
[199]3997if test
[292]3998    set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
[199]3999else
[292]4000    set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7])
[199]4001    update_plot(handles);
4002end
4003
4004%-------------------------------------------------------------------
[292]4005function CheckBW_Callback(hObject, eventdata, handles)
[199]4006%-------------------------------------------------------------------
4007update_plot(handles);
4008
4009%-------------------------------------------------------------------
[292]4010function ListContour_Callback(hObject, eventdata, handles)
[199]4011%-------------------------------------------------------------------
[292]4012val=get(handles.ListContour,'Value');
[199]4013if val==2
4014    set(handles.interval_txt,'Visible','on')
[292]4015    set(handles.num_IncrA,'Visible','on')
[199]4016else
4017    set(handles.interval_txt,'Visible','off')
[292]4018    set(handles.num_IncrA,'Visible','off')
[199]4019end
4020update_plot(handles);
4021
4022%-------------------------------------------------------------------
[292]4023function num_IncrA_Callback(hObject, eventdata, handles)
[199]4024%-------------------------------------------------------------------
4025update_plot(handles);
4026
4027%-------------------------------------------------------------------
[292]4028function CheckHideWarning_Callback(hObject, eventdata, handles)
[199]4029%-------------------------------------------------------------------
4030update_plot(handles);
4031
4032%-------------------------------------------------------------------
[292]4033function CheckHideFalse_Callback(hObject, eventdata, handles)
[199]4034%-------------------------------------------------------------------
4035update_plot(handles);
4036
4037%-------------------------------------------------------------------
[292]4038function num_VecScale_Callback(hObject, eventdata, handles)
[199]4039%-------------------------------------------------------------------
[292]4040set(handles.CheckFixVectors,'Value',1);
4041set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
[199]4042update_plot(handles);
4043
4044%-------------------------------------------------------------------
[292]4045function CheckFixVectors_Callback(hObject, eventdata, handles)
[199]4046%-------------------------------------------------------------------
[292]4047test=get(handles.CheckFixVectors,'Value');
[199]4048if test
[292]4049    set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
[199]4050else
4051    update_plot(handles);
[292]4052    %set(handles.num_VecScale,'String',num2str(ScalOut.num_VecScale,3))
4053    set(handles.CheckFixVectors,'BackgroundColor',[0.7 0.7 0.7])
[199]4054end
4055
4056%------------------------------------------------------------------------
[292]4057% --- Executes on selection change in CheckDecimate4 (nb_vec/4).
4058function CheckDecimate4_Callback(hObject, eventdata, handles)
[199]4059%------------------------------------------------------------------------
4060update_plot(handles);
4061
4062%------------------------------------------------------------------------
[292]4063% --- Executes on selection change in ListColorCode menu
4064function ListColorCode_Callback(hObject, eventdata, handles)
[199]4065%------------------------------------------------------------------------
4066set_vec_col_bar(handles)
4067update_plot(handles);
4068
4069%------------------------------------------------------------------------
[292]4070% --- Executes on button press in CheckFixVecColor.
4071function CheckFixVecColor_Callback(hObject, eventdata, handles)
[199]4072%------------------------------------------------------------------------
[292]4073test=get(handles.CheckFixVecColor,'Value');
[199]4074if test
[292]4075    set(handles.CheckFixVecColor,'BackgroundColor',[1 1 0])
[199]4076else
4077    update_plot(handles);
[292]4078    %set(handles.num_VecScale,'String',num2str(ScalOut.num_VecScale,3))
4079    set(handles.CheckFixVecColor,'BackgroundColor',[0.7 0.7 0.7])
[199]4080end
4081
4082%------------------------------------------------------------------------
[292]4083% --- Executes on selection change in num_MaxVec.
4084function num_MinVec_Callback(hObject, eventdata, handles)
[199]4085%------------------------------------------------------------------------
4086max_vec_Callback(hObject, eventdata, handles)
4087
4088%------------------------------------------------------------------------
[292]4089% --- Executes on selection change in num_MaxVec.
4090function num_MaxVec_Callback(hObject, eventdata, handles)
[199]4091%------------------------------------------------------------------------
[292]4092set(handles.CheckFixVecColor,'Value',1)
[316]4093CheckFixVecColor_Callback(hObject, eventdata, handles)
[292]4094min_val=str2num(get(handles.num_MinVec,'String'));
4095max_val=str2num(get(handles.num_MaxVec,'String'));
4096slider1=get(handles.Slider1,'Value');
4097slider2=get(handles.Slider2,'Value');
[199]4098colcode1=min_val+(max_val-min_val)*slider1;
4099colcode2=min_val+(max_val-min_val)*slider2;
[292]4100set(handles.num_ColCode1,'String',num2str(colcode1))
4101set(handles.num_ColCode2,'String',num2str(colcode2))
[199]4102update_plot(handles);
4103
4104%------------------------------------------------------------------------
4105% --- update the display of color code for vectors
4106function set_vec_col_bar(handles)
4107%------------------------------------------------------------------------
[292]4108%get the image of the color display button 'VecColBar' in pixels
4109set(handles.VecColBar,'Unit','pixel');
4110pos_vert=get(handles.VecColBar,'Position');
4111set(handles.VecColBar,'Unit','Normalized');
[199]4112width=ceil(pos_vert(3));
4113height=ceil(pos_vert(4));
4114
4115%get slider indications
[292]4116list=get(handles.ListColorCode,'String');
4117ichoice=get(handles.ListColorCode,'Value');
[315]4118colcode.ListColorCode=list{ichoice};
4119colcode.MinVec=str2num(get(handles.num_MinVec,'String'));
4120colcode.MaxVec=str2num(get(handles.num_MaxVec,'String'));
4121test3color=strcmp(colcode.ListColorCode,'rgb') || strcmp(colcode.ListColorCode,'bgr');
[199]4122if test3color
[315]4123    colcode.ColCode1=str2num(get(handles.num_ColCode1,'String'));
4124    colcode.ColCode2=str2num(get(handles.num_ColCode2,'String'));
[199]4125end
[315]4126% colcode.FixedCbounds=0;
4127%colcode.CheckFixVecColor=1;
4128vec_C=colcode.MinVec+(colcode.MaxVec-colcode.MinVec)*(0.5:width-0.5)/width;%sample of vec_C values from min to max
[199]4129[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4130oneheight=ones(1,height);
4131A1=colorlist(col_vec,1)*oneheight;
4132A2=colorlist(col_vec,2)*oneheight;
4133A3=colorlist(col_vec,3)*oneheight;
4134A(:,:,1)=A1';
4135A(:,:,2)=A2';
4136A(:,:,3)=A3';
[292]4137set(handles.VecColBar,'Cdata',A)
[199]4138
4139%-------------------------------------------------------------------
4140function update_plot(handles)
4141%-------------------------------------------------------------------
4142UvData=get(handles.uvmat,'UserData');
[295]4143AxeData=UvData.axes3;% retrieve the current plotted data
[292]4144PlotParam=read_GUI(handles.uvmat);
[295]4145[PP,PlotParamOut]= plot_field(AxeData,handles.axes3,PlotParam);
[199]4146write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4147
[315]4148% %-------------------------------------------------------------------
4149% % --- Executes on button press in grid.
4150% function grid_Callback(hObject, eventdata, handles)
[199]4151
4152
4153%-------------------------------------------------------------------
4154% --- Executes on selection change in edit_object.
4155function edit_object_Callback(hObject, eventdata, handles)
4156%-------------------------------------------------------------------
4157UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4158test=get(handles.edit_object,'Value');
4159if test
4160    set(handles.edit_object,'BackgroundColor',[1,1,0]) 
4161    %suppress the other options
[292]4162    set(handles.CheckZoom,'Value',0)
[302]4163    CheckZoom_Callback(hObject, eventdata, handles)
[199]4164    hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4165    if ishandle(hgeometry_calib)
4166        hhgeometry_calib=guidata(hgeometry_calib);
4167        set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib
4168        set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7])
4169    end
4170else
4171    UvData.MouseAction='none';
4172    set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7])   
[302]4173%     hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
4174%     if ~isempty(hset_object)
4175%         delete(hset_object)% delete the current GUI set_object
4176%     end
[199]4177end
4178set(handles.uvmat,'UserData',UvData);
4179hset_object=findobj(allchild(0),'Tag','set_object');
4180if ~isempty(hset_object)
4181    hhset_object=guidata(hset_object);
4182    if test
4183        set(hhset_object.PLOT,'enable','on');
4184    else
4185       set(hhset_object.PLOT,'enable','off');
4186    end
4187end
4188
4189%------------------------------------------------------------------------
[302]4190% --- Executes on selection change in ListObject.
4191function ListObject_Callback(hObject, eventdata, handles)
[199]4192%------------------------------------------------------------------------
4193
[302]4194list_str=get(handles.ListObject,'String');
4195IndexObj_old=get(handles.ListObject,'UserData');%retrieve previous selection
4196IndexObj=get(handles.ListObject,'Value');
4197if length(IndexObj)>2
4198     IndexObj=[IndexObj(end-1) IndexObj(end)];%keeps only the last two selected items at most
4199end
4200if length(IndexObj)==1
4201    if length(IndexObj_old)>=2 && isequal(IndexObj_old(1),IndexObj)       
4202        IndexObj=IndexObj_old(2);
4203    elseif length(IndexObj_old)>=2 && isequal(IndexObj_old(2),IndexObj)
4204        IndexObj=IndexObj_old(1);
[252]4205    else
[302]4206        IndexObj=[IndexObj_old(1) IndexObj];
[252]4207    end
[199]4208end
[302]4209set(handles.ListObject,'Value',IndexObj); %keeps only the two first selected objects
4210set(handles.ListObject,'UserData',IndexObj)
4211 %desactivate the edit object mode
4212set(handles.edit_object,'Value',0)
4213edit_object_Callback(hObject, eventdata, handles)
4214UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4215if numel(UvData.Object)<max(IndexObj);
4216    msgbox_uvmat('ERROR','invalid object list')
4217    return
4218end
4219UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
4220set(handles.uvmat,'UserData',UvData)
[199]4221
[302]4222%project on the selected object and update the corresponding plot
4223hview_field=findobj(allchild(0),'tag','view_field');
4224ViewObjectAxes=[];%default
4225if ~isequal(IndexObj(1),IndexObj_old(1))
4226update_object(handles,IndexObj(1),handles.axes3,list_str{IndexObj(1)})%plot the projection in uvmat
4227end
4228if length(IndexObj)==2 && (length(IndexObj_old)==1 || ~isequal(IndexObj(2),IndexObj_old(2)))
4229    hview_field=findobj(allchild(0),'tag','view_field');
4230    if isempty(hview_field)
4231        hview_field=view_field;
4232    end
4233    PlotHandles=guidata(hview_field);
4234    update_object(handles,IndexObj(2),PlotHandles.axes3,list_str{IndexObj(2)})%plot the projection in view_field
4235end
4236update_object_color(handles.axes3,PlotHandles.axes3,UvData.Object{IndexObj(2)}.DisplayHandle_uvmat)
4237
[199]4238%------------------------------------------------------------------------
[302]4239function update_object(handles,IndexObj,ViewObjectAxes,ObjectName)
[199]4240%------------------------------------------------------------------------
4241UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4242ObjectData=UvData.Object{IndexObj};
4243ObjectData.Name=ObjectName;
4244if isequal(get(handles.edit_object,'Value'),1)
4245    ObjectData.enable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4246end
4247ZBounds=0; % default
4248if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4249    ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4250    ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4251end
4252hset_object=findobj(allchild(0),'tag','set_object');
4253if ~isempty(hset_object)
4254    delete(hset_object)% delete existing version of set_object
[302]4255    hset_object=set_object(ObjectData,[],ZBounds);
[199]4256end
4257edit_test=get(handles.edit_object,'Value');
4258if edit_test
4259    ObjectData.enable_plot=1;
4260else
[210]4261    if isfield(ObjectData,'enable_plot')
[199]4262        ObjectData=rmfield(ObjectData,'enable_plot');
4263    end
4264end
4265
[302]4266uistack(ViewObjectAxes,'top')% display the plotting axes at the top
4267ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
4268plot_field(ProjData,ViewObjectAxes,read_GUI(get(ViewObjectAxes,'Parent')));%read plotting parameters on the uvmat interfacPlotHandles);
4269%
4270% UvData.Object=update_obj(UvData,IndexObj(1),IndexObj(2));
4271% set(handles.uvmat,'UserData',UvData)
[252]4272
[302]4273%------------------------------------------------------------------------
4274%--- update the representation of objects
4275function update_object_color(axes_uvmat,axes_view_field,DisplayHandle)
4276%------------------------------------------------------------------------
4277hother=[findobj(axes_uvmat,'Tag','proj_object') ;findobj(axes_view_field,'Tag','proj_object')] ;%find all the proj objects
4278hother=[hother ;findobj(axes_uvmat,'Tag','DeformPoint'); findobj(axes_view_field,'Tag','DeformPoint')];
[199]4279for iobj=1:length(hother)
4280    if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
4281        set(hother(iobj),'EdgeColor','b')
4282        if isequal(get(hother(iobj),'FaceColor'),'m')
4283            set(hother(iobj),'FaceColor','b')
4284        end
4285    elseif isequal(get(hother(iobj),'Type'),'image')
4286        Acolor=get(hother(iobj),'CData');
4287        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4288        set(hother(iobj),'CData',Acolor);
4289    else
4290        set(hother(iobj),'Color','b')
4291    end
4292    set(hother(iobj),'Selected','off')
4293end
[302]4294linetype=get(DisplayHandle,'Type');
4295if isequal(linetype,'line')
4296    set(DisplayHandle,'Color','m'); %set the selected object to magenta color
4297elseif isequal(linetype,'rectangle')
4298    set(DisplayHandle,'EdgeColor','m'); %set the selected object to magenta color
4299elseif isequal(linetype,'patch')
4300    set(DisplayHandle,'FaceColor','m'); %set the selected object to magenta color
4301end
4302SubObjectData=get(DisplayHandle,'UserData');
4303if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
4304    for iobj=1:length(SubObjectData.SubObject)
4305        hsub=SubObjectData.SubObject(iobj);
4306        if isequal(get(hsub,'Type'),'rectangle')
4307            set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4308        elseif isequal(get(hsub,'Type'),'image')
4309            Acolor=get(hsub,'CData');
4310            Acolor(:,:,1)=Acolor(:,:,3);
4311            set(hsub,'CData',Acolor);
4312        else
4313            set(hsub,'Color','m')
[199]4314        end
4315    end
4316end
[302]4317if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
4318    set(SubObjectData.DeformPoint,'Color','m')
4319end
[199]4320
[302]4321%         SubObjectData=get(ObjectData.DisplayHandle_uvmat,'UserData');
4322
4323
4324
4325
4326
4327
4328
[199]4329%------------------------------------------------------
4330% --- Executes on button press in Menu/Export/field in workspace.
4331%------------------------------------------------------
4332function MenuExportField_Callback(hObject, eventdata, handles)
4333global Data_uvmat
4334Data_uvmat=get(handles.uvmat,'UserData');
4335evalin('base','global Data_uvmat')%make CurData global in the workspace
4336display('current field :')
4337evalin('base','Data_uvmat') %display CurData in the workspace
4338commandwindow; %brings the Matlab command window to the front
4339
4340%------------------------------------------------------
4341% --- Executes on button press in Menu/Export/extract figure.
4342%------------------------------------------------------
4343function MenuExport_plot_Callback(hObject, eventdata, handles)
4344huvmat=get(handles.MenuExport_plot,'parent');
4345UvData=get(huvmat,'UserData');
4346hfig=figure;
4347newaxes=copyobj(handles.axes3,hfig);
4348map=colormap(handles.axes3);
4349colormap(map);%transmit the current colormap to the zoom fig
4350colorbar
4351
4352
4353% --------------------------------------------------------------------
4354function Insert_Callback(hObject, eventdata, handles)
4355
4356
4357% --------------------------------------------------------------------
4358function MenuHelp_Callback(hObject, eventdata, handles)
4359% --------------------------------------------------------------------
4360path_to_uvmat=which ('uvmat');% check the path of uvmat
4361pathelp=fileparts(path_to_uvmat);
4362helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4363if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4364else
4365    addpath (fullfile(pathelp,'uvmat_doc'))
4366    web(helpfile);
4367end
4368
4369%------------------------------------------------------------------------
4370% --------------------------------------------------------------------
4371function MenuExportMovie_Callback(hObject, eventdata, handles)
4372% --------------------------------------------------------------------
4373set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4374huvmat=get(handles.run0,'parent');
4375UvData=get(huvmat,'UserData');
4376[xx,xx,FileBase]=read_file_boxes(handles);
4377 %read the current input file name
4378prompt = {'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)'};
4379dlg_title = 'select properties of the output avi movie';
4380num_lines= 1;
4381% nbfield_cell=get(handles.last_i,'String');
4382def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4383answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4384aviname=answer{1};
4385fps=str2double(answer{2});
4386% check for existing file with output name aviname
4387if exist(aviname,'file')
4388    backup=aviname;
4389    testexist=2;
4390    while testexist==2
4391        backup=[backup '~'];
4392        testexist=exist(backup,'file');     
4393    end
4394    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4395    if isequal(success,1)
4396        delete(aviname)%delete existing file
4397    else
4398        msgbox_uvmat('ERROR',message)
4399        return
4400    end
4401end
4402%create avi open
4403aviobj=avifile(aviname,'Compression','None','fps',fps);
4404
4405%display first view for tests
4406newfig=figure;
4407newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
4408set(newaxes,'Tag','movieaxes')
4409nbpix=[512 384]*str2double(answer{3});
4410set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4411set(newaxes,'Position',eval(answer{4}));
4412map=colormap(handles.axes3);
4413colormap(map);%transmit the current colormap to the zoom fig
4414msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4415        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
[215]4416UvData.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
[199]4417set(huvmat,'UserData',UvData);
4418increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
4419if isnan(increment)
4420    set(handles.increment_scan,'String','1')%default value
4421    increment=1;
4422end
4423set(handles.STOP,'Visible','on')
4424set(handles.speed,'Visible','on')
4425set(handles.speed_txt,'Visible','on')
4426set(handles.Movie,'BusyAction','queue')
4427
4428%imin=str2double(get(handles.i1,'String'));
4429imax=str2double(answer{5});
4430% if isfield(UvData,'Time')
4431htitle=get(newaxes,'Title');
4432xlim=get(newaxes,'XLim');
4433ylim=get(newaxes,'YLim');
4434set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4435time_str=get(handles.abs_time,'String');
4436set(htitle,'String',['t=' time_str])
4437set(handles.speed,'Value',1)
4438for i=1:imax
4439    if get(handles.speed,'Value')~=0 && isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4440            runpm(hObject,eventdata,handles,increment)% run plus
4441            drawnow
4442            time_str=get(handles.abs_time,'String');
4443            if ishandle(htitle)
4444             set(htitle,'String',['t=' time_str])
4445            end
4446            mov=getframe(newfig);
4447            aviobj=addframe(aviobj,mov);
4448    end
4449end
[215]4450aviobj=close(aviobj);
4451UvData=rmfield(UvData,'plotaxes');
4452%UvData.Object{1}.plotaxes=handles.axes3;
[199]4453set(huvmat,'UserData',UvData);
4454msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4455
4456%------------------------------------------------------------------------
4457function MenuCalib_Callback(hObject, eventdata, handles)
4458%------------------------------------------------------------------------
4459
4460UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4461
4462%suppress competing options
[292]4463set(handles.CheckZoom,'Value',0)
4464set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
[302]4465set(handles.ListObject,'Value',1)     
[199]4466% initiate display of GUI geometry_calib
4467data=[]; %default
4468if isfield(UvData,'CoordType')
4469    data.CoordType=UvData.CoordType;
4470end
4471pos=get(handles.uvmat,'Position');
4472pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
4473pos(2)=pos(2)-0.02;
4474[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
4475set(handles.view_xml,'Backgroundcolor',[1 1 0])%indicate the reading of the current xml file by geometry_calib
4476if isfield(UvData.OpenParam,'CalOrigin')
4477    pos_uvmat=get(handles.uvmat,'Position');
4478    pos_cal(1)=pos_uvmat(1)+UvData.OpenParam.CalOrigin(1)*pos_uvmat(3);
4479    pos_cal(2)=pos_uvmat(2)+UvData.OpenParam.CalOrigin(2)*pos_uvmat(4);
4480    pos_cal(3:4)=UvData.OpenParam.CalSize .* pos_uvmat(3:4);
4481end
4482geometry_calib(FileName,pos_cal);% call the geometry_calib interface   
4483set(handles.view_xml,'Backgroundcolor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib
4484set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action
4485
4486%------------------------------------------------------------------------
4487function MenuMask_Callback(hObject, eventdata, handles)
4488%------------------------------------------------------------------------
4489UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4490ListObj=UvData.Object;
4491select=zeros(1,numel(ListObj));
4492for iobj=1:numel(ListObj);
4493    if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside')
4494        select(iobj)=1;
4495    end
4496end
4497val=find(select);
4498if isempty(val)
4499    msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar');
4500    return
4501else
[302]4502    set(handles.ListObject,'Max',2);%allow multiple selection
4503    set(handles.ListObject,'Value',val);
[199]4504    flag=1;
4505    npx=size(UvData.Field.A,2);
4506    npy=size(UvData.Field.A,1);
4507    xi=0.5:npx-0.5;
4508    yi=0.5:npy-0.5;
4509    [Xi,Yi]=meshgrid(xi,yi);
4510    if isfield(UvData,'Object')
4511        for iobj=1:length(UvData.Object)
4512            ObjectData=UvData.Object{iobj};
4513            if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
4514                flagobj=1;
4515                testphys=0; %coordinates in pixels by default
4516                if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel')
4517                    if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
4518                        Calib=UvData.XmlData.GeometryCalib;
4519                        testphys=1;
4520                    end
4521                end
[295]4522                if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Style')
[199]4523                    if isequal(ObjectData.Style,'polygon')
4524                        X=ObjectData.Coord(:,1);
4525                        Y=ObjectData.Coord(:,2);
4526                        if testphys
4527                            [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
4528                        end
4529                        flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
4530                    elseif isequal(ObjectData.Style,'ellipse')
4531                        if testphys
4532                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4533                        end
4534                        RangeX=max(ObjectData.RangeX);
4535                        RangeY=max(ObjectData.RangeY);
4536                        X2Max=RangeX*RangeX;
4537                        Y2Max=RangeY*RangeY;
4538                        distX=(Xi-ObjectData.Coord(1,1));
4539                        distY=(Yi-ObjectData.Coord(1,2));
4540                        flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
4541                    elseif isequal(ObjectData.Style,'rectangle')
4542                        if testphys
4543                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4544                        end
4545                        distX=abs(Xi-ObjectData.Coord(1,1));
4546                        distY=abs(Yi-ObjectData.Coord(1,2));
4547                        flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
4548                    end
4549                    if isequal(ObjectData.ProjMode,'mask_outside')
4550                        flagobj=~flagobj;
4551                    end
4552                    flag=flag & flagobj;
4553                end
4554            end
4555        end
[231]4556    end
[199]4557    %mask name
4558    RootPath=get(handles.RootPath,'String');
4559    RootFile=get(handles.RootFile,'String');
4560    if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
4561        RootFile(1)=[];
4562    end
4563    filebase=fullfile(RootPath,RootFile);
4564    list=get(handles.masklevel,'String');
4565    masknumber=num2str(length(list));
4566    maskindex=get(handles.masklevel,'Value');
4567    mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
4568    imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
4569    imflag=flipdim(imflag,1);
4570
4571    %display the mask
[231]4572    hfigmask=figure;
4573    set(hfigmask,'Name','mask image')
[199]4574    vec=linspace(0,1,256);%define a linear greyscale colormap
4575    map=[vec' vec' vec'];
4576    colormap(map)
4577    image(imflag);
4578    answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name);
4579    if ~strcmp(answer,'Cancel')
4580        mask_dir=fileparts(answer);
4581        if ~exist(mask_dir,'dir')
4582            msgbox_uvmat('ERROR',['directory ' mask_dir ' does not exist'])
4583            return
4584        end
4585        imwrite(imflag,answer,'BitDepth',8);
4586    end
[302]4587    set(handles.ListObject,'Value',1)
4588    set(handles.ListObject,'Max',1)
[199]4589end
4590
4591%------------------------------------------------------------------------
4592%-- open the GUI set_grid.fig to create grid
4593function MenuGrid_Callback(hObject, eventdata, handles)
4594%------------------------------------------------------------------------
4595%suppress the other options if grid is chosen
4596set(handles.edit_vect,'Value',0)
4597edit_vect_Callback(hObject, eventdata, handles)
4598set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
[302]4599set(handles.ListObject,'Value',1)     
[199]4600
4601%prepare display of the set_grid GUI
4602FileName=read_file_boxes(handles);
4603CoordList=get(handles.transform_fct,'String');
4604val=get(handles.transform_fct,'Value');
4605set_grid(FileName,CoordList{val});% call the set_object interface
4606
4607%------------------------------------------------------------------------
4608% open the GUI 'series'
4609function MenuSeries_Callback(hObject, eventdata, handles)
4610%------------------------------------------------------------------------
4611series; %first display of the GUI to fill waiting time
4612[param.FileName]=read_file_boxes(handles);
4613if isequal(get(handles.SubField,'Value'),1)
4614    FileName_1=read_file_boxes_1(handles);%
4615    if ~isequal(FileName_1,param.FileName)
4616        param.FileName_1=FileName_1;
4617    end
4618end
4619param.NomType=get(handles.FileIndex,'UserData');
4620param.NomType_1=get(handles.FileIndex_1,'UserData');
4621param.comp_input=get(handles.fix_pair,'Value');
4622huvmat=get(handles.MenuSeries,'parent');
4623UvData=get(huvmat,'UserData');
4624if isfield(UvData,'Time')
4625    param.Time=UvData.XmlData.Time;
4626end
4627if isequal(get(handles.scan_i,'Value'),1)
4628    param.incr_i=str2double(get(handles.increment_scan,'String'));
4629elseif isequal(get(handles.scan_j,'Value'),1)
4630    param.incr_j=str2double(get(handles.increment_scan,'String'));
4631end
4632param.list_fields=get(handles.Fields,'String');% list menu fields
4633param.list_fields(1)=[]; %suppress  'image' option
4634param.index_fields=get(handles.Fields,'Value');% selected string index
4635if param.index_fields>1
4636    param.index_fields=param.index_fields-1;
4637end
4638param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
4639param.list_fields_1(1)=[]; %suppress  'image' option
4640param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
4641if param.index_fields_1>1
4642    param.index_fields_1=param.index_fields_1-1;
4643end
4644param.menu_coord_str=get(handles.transform_fct,'String');
4645param.menu_coord_val=get(handles.transform_fct,'Value');
4646series(param); %run the series interface
4647
4648%------------------------------------------------------------------------
4649% -- open the GUI civ.fig for civx (PIV)
4650function MenuPIV_Callback(hObject, eventdata, handles)
4651%------------------------------------------------------------------------
[298]4652 FileName=read_file_boxes(handles);
4653%[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles)
4654% num1=stra2num(get(handles.i1,'String'));
4655% num2=stra2num(get(handles.i2,'String'));
4656% num_a=stra2num(get(handles.j1,'String'));
4657% num_b=stra2num(get(handles.j2,'String'));
4658% NomType=get(handles.FileIndex,'UserData');
4659% ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4660% if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4661%     ind_opening=2;% propose 'fix' as the default option
4662% % +read the current netcdf rootfile
4663%     Data=nc2struct(FileName,'ListGlobalAttribute','fix','patch','civ2','fix2');
4664%     if isfield(Data,'fix') && isequal(Data.fix,1)
4665%         ind_opening=3;
4666%     end
4667%     if isfield(Data,'patch') && isequal(Data.patch,1)
4668%         ind_opening=4;
4669%     end
4670%     if isfield(Data,'civ2') && isequal(Data.civ2,1)
4671%         ind_opening=5;
4672%     end
4673%     if isfield(Data,'fix2') && isequal(Data.fix2,1)
4674%         ind_opening=6;
4675%     end
4676% end     
4677% param.RootName=filebase;
4678% param.NomType=NomType;
4679% param.num1=num1;
4680% param.num2=num2;
4681% param.num_a=num_a;
4682% param.num_b=num_b;
4683% param.SubDir=SubDir;
4684% param.IndOpening=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4685% param.ImaExt=ext;
4686civ(FileName);% interface de civ(not in the uvmat file)
[199]4687
4688%------------------------------------------------------------------------
4689function MenuTools_Callback(hObject, eventdata, handles)
4690%------------------------------------------------------------------------
4691
4692%------------------------------------------------------------------------
4693function MenuEditObject_Callback(hObject, eventdata, handles)
4694%------------------------------------------------------------------------
4695set(handles.edit_object,'Value',1)
4696edit_Callback(hObject, eventdata, handles)
4697
4698%------------------------------------------------------------------------
4699function enable_transform(handles,state)
4700%------------------------------------------------------------------------
4701set(handles.transform_fct,'Visible',state)
4702set(handles.TRANSFORM_txt,'Visible',state)   
4703set(handles.transform_fct,'Visible',state) 
4704set(handles.path_transform,'Visible',state)
4705set(handles.pxcmx_txt,'Visible',state)
4706set(handles.pxcmy_txt,'Visible',state)
4707set(handles.pxcm,'Visible',state)
4708set(handles.pycm,'Visible',state)
4709
4710%------------------------------------------------------------------------
4711function MenuEditVectors_Callback(hObject, eventdata, handles)
4712%------------------------------------------------------------------------
4713set(handles.edit_vect,'Visible','on')
4714set(handles.edit_vect,'Value',1)
4715edit_vect_Callback(hObject, eventdata, handles)
4716
4717% -----------------------------------------------------------------------
4718function Menupoints_Callback(hObject, eventdata, handles)
4719%------------------------------------------------------------------------
4720data.Style='points';
4721data.ProjMode='projection';%default
4722create_object(data,handles)
4723
4724% -----------------------------------------------------------------------
4725function Menuline_Callback(hObject, eventdata, handles)
4726%------------------------------------------------------------------------
4727data.Style='line';
4728data.ProjMode='projection';%default
4729create_object(data,handles)
4730
4731%------------------------------------------------------------------------
4732function Menupolyline_Callback(hObject, eventdata, handles)
4733%------------------------------------------------------------------------
4734data.Style='polyline';
4735data.ProjMode='projection';%default
4736create_object(data,handles)
4737
4738%------------------------------------------------------------------------
4739function Menupolygon_Callback(hObject, eventdata, handles)
4740%------------------------------------------------------------------------
4741data.Style='polygon';
4742data.ProjMode='inside';%default
4743create_object(data,handles)
4744
4745%------------------------------------------------------------------------
4746function Menurectangle_Callback(hObject, eventdata, handles)
4747%------------------------------------------------------------------------
4748data.Style='rectangle';
4749data.ProjMode='inside';%default
4750create_object(data,handles)
4751
4752%------------------------------------------------------------------------
4753function Menuellipse_Callback(hObject, eventdata, handles)
4754%------------------------------------------------------------------------
4755data.Style='ellipse';
4756data.ProjMode='inside';%default
4757create_object(data,handles)
4758
4759%------------------------------------------------------------------------
4760function MenuMaskObject_Callback(hObject, eventdata, handles)
4761%------------------------------------------------------------------------
4762data.Style='polygon';
4763data.StyleMenu={'polygon'};
4764data.ProjMode='mask_inside';%default
4765data.ProjMenu={'mask_inside';'mask_outside'};
4766create_object(data,handles)
4767
4768%------------------------------------------------------------------------
4769function Menuplane_Callback(hObject, eventdata, handles)
4770%------------------------------------------------------------------------
4771data.Style='plane';
4772data.ProjMode='projection';%default
4773
4774create_object(data,handles)
4775
4776%------------------------------------------------------------------------
4777function Menuvolume_Callback(hObject, eventdata, handles)
4778%------------------------------------------------------------------------
4779data.Style='volume';
4780data.ProjMode='interp';%default
4781% set(handles.create,'Visible','on')
4782% set(handles.create,'Value',1)
4783% VOLUME_Callback(hObject,eventdata,handles)
4784create_object(data,handles)
4785
4786%------------------------------------------------------------------------
4787function MenuBrowseObject_Callback(hObject, eventdata, handles)
4788%------------------------------------------------------------------------
4789%get the object file
4790[FileName, PathName, filterindex] = uigetfile( ...
4791       {'*.xml;*.mat', ' (*.xml,*.mat)';
4792       '*.xml',  '.xml files '; ...
4793        '*.mat',  '.mat matlab files '}, ...
4794        'Pick an xml Object file',get(handles.RootPath,'String'));
4795fileinput=[PathName FileName];%complete file name
4796% testblank=findstr(fileinput,' ');%look for blanks
4797% if ~isempty(testblank)
4798%     msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
4799%     return
4800% end
4801sizf=size(fileinput);
4802if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
4803
4804%read the file
4805t=xmltree(fileinput);
4806data=convert(t);
4807data.enable_plot=1;
4808[pp,data.Name]=fileparts(FileName);
4809%PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4810hset_object=findobj(allchild(0),'tag','set_object');
4811if ~isempty(hset_object)
4812    delete(hset_object)% delete existing version of set_object
4813end
4814% UvData=get(handles.uvmat,'UserData');
4815set_object(data);% call the set_object interface
4816% %position the set_object GUI with respect to uvmat
4817% pos_uvmat=get(handles.uvmat,'Position');
4818% if isfield(UvData,'SetObjectOrigin')
4819%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4820%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4821%     set(hset_object,'Position',pos_set_object)
4822% end
4823set(handles.edit_object,'Value',0); %suppress the object edit mode
4824set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
4825set(handles.MenuObject,'checked','on')
4826%UvData.MouseAction='create_object';
4827% set(handles.uvmat,'UserData',UvData)
4828set(handles.delete_object,'Visible','on')
[307]4829% set(handles.uvmat_title,'Visible','on')
4830% set(handles.view_field_title,'Visible','on')
[199]4831
4832%------------------------------------------------------------------------
4833% --- generic function used for the creation of a projection object
4834function create_object(data,handles)
4835%------------------------------------------------------------------------
4836hset_object=findobj(allchild(0),'tag','set_object');
4837if ~isempty(hset_object)
4838    delete(hset_object)% delete existing version of set_object
4839end
4840hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4841if ishandle(hgeometry_calib)
4842    hhgeometry_calib=guidata(hgeometry_calib);
4843    set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib
4844    set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7])
4845end
4846UvData=get(handles.uvmat,'UserData');
4847set(handles.edit_object,'Value',0); %suppress the object edit mode
4848set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
4849data.enable_plot=1;
4850transform_list=get(handles.transform_fct,'String');
4851val=get(handles.transform_fct,'Value');
4852%data.CoordType=transform_list{val};
4853if isfield(UvData,'Field')
4854    Field=UvData.Field;
4855    if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
4856        data.RangeX=Field.Mesh;
4857        data.RangeY=Field.Mesh;
4858        data.DX=Field.Mesh;
4859        data.DY=Field.Mesh;
4860    elseif isfield(Field,'AX')&& isfield(Field,'AY')&& isfield(Field,'A')%only image
4861        np=size(Field.A);
4862        meshx=(Field.AX(end)-Field.AX(1))/np(2);
4863        meshy=abs(Field.AY(end)-Field.AY(1))/np(1);
4864        data.RangeY=max(meshx,meshy);
4865        data.RangeX=max(meshx,meshy);
4866        data.DX=max(meshx,meshy);
4867    end
4868    if isfield(Field,'NbDim')
4869        data.NbDim=Field.NbDim;
4870    end
4871    if isfield(Field,'CoordUnit')
4872        data.CoordUnit=Field.CoordUnit;
4873    end
4874end
4875data.Coord=[0 0 0]; %default
4876if isfield(data,'Style') && isequal(data.Style,'line')
4877    if isfield(data,'DX')
4878        data.Coord=[[0 0 0];[data.DX 0 0]]; %default
4879    else
4880        data.Coord=[[0 0 0];[1 0 0]]; %default
4881    end
4882end
4883if ishandle(handles.UVMAT_title)
4884    delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered
4885end
4886%PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4887set_object(data,handles);% call the set_object interface
4888set(handles.MenuObject,'checked','on')
4889set(handles.uvmat,'UserData',UvData)
[292]4890set(handles.CheckZoom,'Value',0)
4891CheckZoom_Callback(handles.uvmat, [], handles)
[199]4892set(handles.delete_object,'Visible','on')
[302]4893% set(handles._title,'Visible','on')
4894% set(handles.view_field_title,'Visible','on')
[199]4895
4896%------------------------------------------------------------------------
4897function MenuRuler_Callback(hObject, eventdata, handles)
4898%------------------------------------------------------------------------
[292]4899set(handles.CheckZoom,'Value',0)
4900CheckZoom_Callback(handles.uvmat, [], handles)
[199]4901set(handles.MenuRuler,'checked','on')
4902UvData=get(handles.uvmat,'UserData');
4903UvData.MouseAction='ruler';
4904set(handles.uvmat,'UserData',UvData);
4905
4906%------------------------------------------------------------------------
4907% --- executed when closing: set the parent interface button to value 0
4908function closefcn(gcbo,eventdata)
4909%------------------------------------------------------------------------
4910%delete all the associated figures if exist
4911hh=findobj(allchild(0),'tag','view_field');
4912if ~isempty(hh)
4913    delete(hh)
4914end
4915hh=findobj(allchild(0),'tag','geometry_calib');
4916if ~isempty(hh)
4917    delete(hh)
4918end
4919hh=findobj(allchild(0),'tag','set_object');
4920if ~isempty(hh)
4921    hhh=findobj(hh,'tag','PLOT');
4922    set(hhh,'enable','off')
4923end
4924
4925%------------------------------------------------------------------------
4926% --- Executes on button press in delete_object.
4927function delete_object_Callback(hObject, eventdata, handles)
4928%------------------------------------------------------------------------
[302]4929IndexObj=get(handles.ListObject,'Value');
4930if IndexObj(end)>1
4931    delete_object(IndexObj(end))
[199]4932end
4933
[236]4934% --- Executes on button press in FixVelType.
4935function FixVelType_Callback(hObject, eventdata, handles)
4936val=get(handles.FixVelType,'Value');
4937if ~val
4938    run0_Callback(hObject, eventdata, handles)
4939end
[199]4940
[236]4941
[302]4942% --- Executes on button press in ViewObject.
4943function ViewObject_Callback(hObject, eventdata, handles)
4944IndexObj=get(handles.ListObject,'Value');
4945IndexObj=IndexObj(end); %keeps only the secodn value
4946UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4947if numel(UvData.Object)<IndexObj;% error in UvData
4948    msgbox_uvmat('ERROR','invalid object list')
4949    return
4950end
4951ObjectData=UvData.Object{IndexObj};
4952ZBounds=0; % default
4953if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4954    ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4955    ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4956end
4957hset_object=findobj(allchild(0),'tag','set_object');
4958if ~isempty(hset_object)
4959    delete(hset_object)% delete existing version of set_object
4960end
4961hset_object=set_object(ObjectData,[],ZBounds);
Note: See TracBrowser for help on using the repository browser.