source: trunk/src/uvmat.m @ 62

Last change on this file since 62 was 62, checked in by sommeria, 14 years ago

minor improvements

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