source: trunk/src/uvmat.m @ 30

Last change on this file since 30 was 30, checked in by gostiaux, 14 years ago

The version number is now read from the revision.log file that can be found in /raid/soft/UVMAT/src/
This revision.log file is generated by the bash script export.sh which exports the code from /raid/soft/UVMAT/SVN/trunk/src/ to /raid/soft/UVMAT/src/;
if revision.log is absent, nothing is written there.

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