source: trunk/src/uvmat.m @ 45

Last change on this file since 45 was 45, checked in by gostiaux, 11 years ago

adaptation for movies

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