source: trunk/src/uvmat.m @ 714

Last change on this file since 714 was 714, checked in by sommeria, 10 years ago

various improvements

File size: 234.5 KB
RevLine 
[387]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
[526]11% visualize, or Matlab structure representing  netcdf fieldname (with fieldname
[387]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%
[511]30% Information stored on the interface:(use 'Export/field in workspace' in
31% the menu bar of uvmat to retrieve it)
32%          .OpenParam: structure containing parameters defined when uvmat is opened
33%                       .PosColorbar: position (1x4 vector)of the colorbar (relative to the fig uvmat)
34%                       .PosGeometryCalib: size of set_object
[591]35%                       .NbBuiltin: nbre of functions always displayed in TransformName menu
[622]36%          .ProjObject: cell array of structures representing the current projection objects, as produced by 'set_object.m'={[]} by default
[511]37%          .NewSeries: =0/1 flag telling whether a new field series has been opened
38%          .FileName_1: name of the current second field (used to detect a  constant field during file scanning)
39%          .FileType: current file type, as defined by the fct  get_file_type.m)
40%          .i1_series,.i2_series,.j1_series,.j1_series: series of i1,i2,j1,j2 indices detected in the input dir,set by  the fct find_file_series
41%          .MovieObject: current movie object
42%          .TimeUnit: unit for time
[526]43%          .XmlData: cell array of 1 or 2 structures representing the xml files associated with the input fieldname (containing timing  and geometry calibration)
[511]44%          .Field: cell array of 1 or 2 structures representing the current  input field(s)
45%          .PlotAxes: field structure representing the current field plotted  on the main axes  (used for mouse operations)
46%          .HistoAxes: idem for histogram axes
[387]47
[713]48% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   DATA FLOW  (for REFRESH_Callback) %%%%%%%%%%%%%%%%%%%%:
[387]49%
[406]50%
[651]51% 1) Input filenames are determined by MenuBrowse (first field), MenuBrowseCampaign
[512]52% (second field), or by the stored file name .FileName_1, or as an input of uvmat.
53% 2) These functions call 'uvmat/display_file_name.m' which detects the file series, and fills the file index boxes
54% 3) Then 'uvmat/update_rootinfo.m' Updates information about a new field series (indices to scan, timing, calibration from an xml file)
[526]55% 4) Then fieldname are opened and visualised by the main sub-function 'uvmat/refresh_field.m'
[512]56% The function first reads the name of the input file(s) (one or two) from the edit boxes  of the GUI
57% It then reads the input file(s) with the function read_field.m and perform the following list of operations:
[387]58%
[512]59%    %%%%%%%%  structure of uvmat/refresh_field.m %%%%%%%%
[387]60%
[512]61%           Main input open       second input open_1       
62%                    |                   | 
63%             read_field.m            read_field.m
64%                    |                   |
65%                 Field{1}            Field{2}               
66%                    |                   |                                 
[526]67%                    --->transform fct<---             transform (e.g. phys.m) and combine input fieldname 
[512]68%                            |                                   
[581]69%                        (tps_coeff_field.m)               calculate tps coefficients (for filter projection or spatial derivatives).
[512]70%                            |
71%                       UvData.Field-------------->histogram
72%               _____________|____________
73%              |                          |                   
[595]74%        proj_field.m               proj_field.m       project the field on the projection objects (use set_field_list.m)           
[512]75%              |                          |
76%         UvData.PlotAxes          ViewData.PlotAxes (on view_field)
77%              |                          |
[526]78%       plot_field.m (uvmat)       plot_field.m (view_field)      plot the projected fieldname
[512]79%
80%
[387]81%%%%%%%%%%%%%%    SCALARS: %%%%%%%%%%%%??%%%
82% scalars are displayed either as an image or countour plot, either as a color of
83% velocity vectors. The scalar values in the first case is represented by
84% UvData.Field.A, and by UvData.Field.C in the second case. The corresponding set of X
85% and Y coordinates are represented by UvData.Field.AX and UvData.Field.AY, and .X and
86% .Y for C (the same as velocity vectors). If A is a nxxny matrix (scalar
87% on a regtular grid), then .AX andf.AY contains only two elements, represneting the
88% coordinates of the four image corners. The scalar name is represented by
89% the strings .AName and/or .CName.
90% If the scalar exists in an input open (image or scalar stored under its
91% name in a netcdf open), it is directly read at the level of Field{1}or Field{2}.
92% Else only its name AName is recorded in Field{i}, and its field is then calculated
[650]93%by the fuction calc_scal after the coordinate transform or after projection on an CheckEditObject
[387]94     
95% Properties attached to plotting figures (standard Matlab properties):
96%    'CurrentAxes'= gca or get(gcf,'CurrentAxes');
97%    'CurrentPoint'=get(gcf,'CurrentPoint'): figure coordinates of the point over which the mouse is positioned
98%    'CurrentCharacter'=get(gcf,'CurrentCharacter'): last character typed  over the figure where the mouse is positioned
99%    'WindowButtonMotionFcn': function permanently called by mouse motion over the figure
100%    'KeyPressFcn': function called by pressing a key on the key board
101%    'WindowButtonDownFcn':  function called by pressing the mouse over the  figure
102%    'WindowButtonUpFcn': function called by releasing  the mouse pressure over the  figure
103
104% Properties attached to plotting axes:
105%    'CurrentPoint'=get(gca,'CurrentPoint'); (standard Matlab) same as for the figure, but position in plot coordinates.
106%     AxeData:=get(gca,'UserData');
107%     AxeData.Drawing  = create: create a new object
108%                       = deform: modify an existing object by moving its defining create
109%                      = off: no current drawing action
110%                     = translate: translate an existing object
111%                    = calibration: move a calibration point
112%                    = CheckZoom: isolate a subregion for CheckZoom in=1 if an object is being currently drawn, 0 else (set to 0 by releasing mouse button)
[650]113%            .CurrentOrigin: Origin of a curently drawn CheckEditObject
[387]114%            .CurrentLine: currently drawn menuline (A REVOIR)
[650]115%            .CurrentObject: handle of the currently drawn CheckEditObject
[387]116%            .CurrentRectZoom: current rectangle used for CheckZoom
117
118% Properties attached to projection objects (create, menuline, menuplane...):
119%    'Tag'='proj_object': for all projection objects
120%    ObjectData.Type=...: style of projection object:
121%              .ProjMode
122%              .Coord: defines the position of the object
123%              .XMin,YMin....
124%              .XMax,YMax....
125%              .DX,DY,DZ
126%              .Phi, .Theta, .Psi : Euler angles
127%              .X,.Y,.U,.V.... : field data projected on the object
[622]128%              .IndexObj: index in the list of UvData.ProjObject
[387]129           %during plotting
130%               .plotaxes: handles of the current axes used to plot the  result of field projection on the object
131%               .plothandle: vector of handle(s) of the object graphic represnetation in all the opened plotting axes
132% To each projection object #iobj, corresponds an axis
133% Object{iobj}.plotaxes and nbobj representation graphs  Object{iobj}.plothandles(:) (where nbobj is the
134% nbre of current objects opened in uvmat. Note that Object{iobj}.plothandles(iobj)=[] : an object is not represented in its own projection field;
135
136%------------------------------------------------------------------------
137%------------------------------------------------------------------------
[406]138%  I - MAIN FUNCTION uvmat
[387]139%------------------------------------------------------------------------
140%------------------------------------------------------------------------
141function varargout = uvmat(varargin)
142
143% Begin initialization code - DO NOT EDIT
144gui_Singleton = 1;
145gui_State = struct('gui_Name',          mfilename, ...
146                   'gui_Singleton',     gui_Singleton, ...
147                   'gui_OpeningFcn',    @uvmat_OpeningFcn, ...
148                   'gui_OutputFcn',     @uvmat_OutputFcn, ...
149                   'gui_LayoutFcn',     [], ...
150                   'gui_Callback',      []);
151if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
152    gui_State.gui_Callback = str2func(varargin{1});
153end
154
155if nargout
156    varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:});
157else
158    gui_mainfcn(gui_State, varargin{:});
159end
160% End initialization code - DO NOT EDIT
161
162%------------------------------------------------------------------------
163% --- Executes just before the GUI uvmat is made visible.
164function uvmat_OpeningFcn(hObject, eventdata, handles, input )
165%------------------------------------------------------------------------
166
167%% Choose default command menuline output for uvmat (standard GUI)
168handles.output = hObject;
169
170%% Update handles structure (standard GUI)
171guidata(hObject, handles);
172
[507]173%% add the path to uvmat (useful if uvmat has been opened in the working directory and a working directory change occured)
174path_uvmat=fileparts(which('uvmat'));
175
[609]176%% set the position of the GUI, colorbar and ancillary GUIs:
177set(hObject,'Units','pixels')%
178set(0,'Units','pixels');
179ScreenSize=get(0,'ScreenSize');%size of the current screen
180Width=1050;
181Height=700;
182%adjust to screen size (reduced by a min margin)
183RescaleFactor=min((ScreenSize(3)-80)/Width,(ScreenSize(4)-80)/Height);
184if RescaleFactor>1
185    RescaleFactor=RescaleFactor/2+1/2; %reduce the rescale factor to provide an increased margin for a big screen
186end
187Width=Width*RescaleFactor;
188Height=Height*RescaleFactor;
189LeftX=80*RescaleFactor;%position of the left fig side, in pixels (put to the left side, with some margin)
190LowY=round(ScreenSize(4)/2-Height/2); % put at the middle height on the screen
191set(hObject,'Position',[LeftX LowY Width Height])
[644]192UvData.OpenParam.PosColorbar=[0.80 0.02 0.018 0.445];
[672]193% UvData.OpenParam.PosGeometryCalib=[0.95 -0.03 0.28 1 ];%position for geometry_calib
[387]194AxeData.LimEditBox=1; %initialise AxeData
[511]195set(handles.PlotAxes,'UserData',AxeData)
[646]196% position of table Coord_y
197set(handles.Coord_y,'Unit','pixel')
198Pos=get(handles.Coord_y,'Position');
199set(handles.Coord_y,'Unit','normalized')
200set(handles.Coord_y,'ColumnWidth',{Pos(3)})
201set(handles.Coord_y,'ColumnFormat',{'char'})
202set(handles.Coord_y,'ColumnEditable',false)
203set(handles.Coord_y,'ColumnName',{''})
[387]204
205%% set functions for the mouse and keyboard
[681]206set(hObject,'WindowKeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
[387]207set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio
208set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
209set(hObject,'WindowButtonUpFcn',{'mouse_up',handles})
210set(hObject,'DeleteFcn',{@closefcn})%
[644]211set(hObject,'ResizeFcn',{@ResizeFcn,handles})%
[710]212% set(handles.RootPath,'ButtonDownFcn',{'@mouse_down_control'})%set mouse click action function
[387]213
[511]214%% initialisation
[526]215set(handles.FieldName,'Value',1)
216set(handles.FieldName,'string',{''})
[622]217UvData.ProjObject={[]};
[387]218
219%% TRANSFORM menu: builtin fcts
[515]220transform_menu={'';'sub_field';'phys';'phys_polar'};
[507]221UvData.OpenParam.NbBuiltin=numel(transform_menu); %number of functions
222transform_path=fullfile(path_uvmat,'transform_field');
[528]223path_list=cell(UvData.OpenParam.NbBuiltin,1);
[507]224path_list{1}='';
[523]225for ilist=2:UvData.OpenParam.NbBuiltin
226path_list{ilist}=transform_path; % set transform_path to the path_list
227end
[387]228
[591]229%% load the list of previously browsed files in menus Open, Open_1 and TransformName
[671]230dir_perso=prefdir; % path to the directory .matlab containing the personal data of the current user
231profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmat_perso.mat' in .matlab
232if exist(profil_perso,'file')% if the file exists
233    h=load (profil_perso); % open the personal file
234    if isfield(h,'MenuFile')% load the saved menu of previously opened files
235        for ifile=1:min(length(h.MenuFile),5)
236            set(handles.(['MenuFile_' num2str(ifile)]),'Label',h.MenuFile{ifile});
237        end
238    end
239    if isfield(h,'MenuCampaign')% load the saved menu of previously opened campaigns
240        for ifile=1:min(length(h.MenuCampaign),5)
241            set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile});
242        end
243    end
244    if isfield(h,'RootPath')
245        set(handles.RootPath,'UserData',h.RootPath); %store the previous campaign in the UserData of RootPath
246    end
247    if isfield(h,'transform_fct') && iscell(h.transform_fct) % load the menu of transform fct set by user
248        for ilist=1:length(h.transform_fct);
249            if exist(h.transform_fct{ilist},'file')
250                [path,file]=fileparts(h.transform_fct{ilist});
251                transform_menu=[transform_menu; {file}];
252                path_list=[path_list; {path}];
253            end
254        end
255    end
256end
[523]257transform_menu=[transform_menu;{'more...'}];%append the option more.. to the menu
[591]258set(handles.TransformName,'String',transform_menu)% display the menu of transform fcts
259set(handles.TransformName,'UserData',path_list)% store the corresponding list of path in UserData of uicontrol transform_fct
260set(handles.TransformPath,'String','')
261set(handles.TransformPath,'UserData',[])
[387]262
263%% case of an input argument for uvmat
264testinputfield=0;
265inputfile=[];
266Field=[];
267if exist('input','var')
268    if ishandle(handles.UVMAT_title)
269        delete(handles.UVMAT_title)
270    end   
271    if isstruct(input)
272        if isfield(input,'InputFile')
273            inputfile=input.InputFile;
274        end
275        if isfield(input,'TimeIndex')
276            set(handles.i1,num2str(input.TimeIndex))
277        end
278        if isfield(input,'FieldsString')
279            UvData.FieldsString=input.FieldsString;
280        end
281    elseif ischar(input)% file name introduced as input
282           inputfile=input;
283    elseif isnumeric(input)%simple matrix introduced as input
284        sizinput=size(input);
285        if sizinput(1)<=1 || sizinput(2)<=1
286            msgbox_uvmat('ERROR','bad input for uvmat: file name, structure or numerical matrix accepted')
287            return
288        end
289        UvData.Field.ListVarName={'A','coord_y','coord_x'};
290        UvData.Field.VarDimName={{'coord_y','coord_x'},'cord_y','coord_x'};
291        UvData.Field.A=input;
292        UvData.Field.coord_x=[0.5 size(input,2)-0.5];
293        UvData.Field.coord_y=[size(input,1)-0.5 0.5];
294        testinputfield=1;
295    end
296else
[476]297    %% check the path and date of modification of all functions in uvmat
298    path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat
299    [infomsg,date_str,svn_info]=check_files;%check the path of the functions called by uvmat.m   
300    date_str=['last modification: ' date_str];
301    if ishandle(handles.UVMAT_title)
302        set(handles.UVMAT_title,'String',...
303            [{'Copyright  LEGI UMR 5519 /CNRS-UJF-Grenoble INP, 2010'};...
304            {'GNU General Public License'};...
305            {path_to_uvmat};...
306            {date_str};...
307            infomsg]);
308    end
[387]309end
310set(handles.uvmat,'UserData',UvData)
311if ~isempty(inputfile)
312    %%%%% display the input field %%%%%%%
[406]313    display_file_name(handles,inputfile)
[387]314    %%%%%%%
315end
316
317set_vec_col_bar(handles) %update the display of color code for vectors
318
319%------------------------------------------------------------------------
320% --- Outputs from this function are returned to the command menuline.
321function varargout = uvmat_OutputFcn(hObject, eventdata, handles)
[710]322%------------------------------------------------------------------------   
[387]323varargout{1} = handles.output;% the only output argument is the handle to the GUI figure
324
325%------------------------------------------------------------------------
[402]326% --- executed when closing uvmat: delete or desactivate the associated figures if exist
327function closefcn(gcbo,eventdata)
[387]328%------------------------------------------------------------------------
[710]329% delete GUI 'view_field' if detected
[402]330hh=findobj(allchild(0),'tag','view_field');
331if ~isempty(hh)
332    delete(hh)
333end
[710]334% delete GUI 'geometry_calib' if detected
[402]335hh=findobj(allchild(0),'tag','geometry_calib');
336if ~isempty(hh)
337    delete(hh)
338end
[710]339% desable set_object editing action if detected
[402]340hh=findobj(allchild(0),'tag','set_object');
341if ~isempty(hh)
342    hhh=findobj(hh,'tag','PLOT');
343    set(hhh,'enable','off')
344end
[710]345%delete the bowser if detected
346hh=findobj(allchild(0),'tag','browser');
347if ~isempty(hh)
348    delete(hh)
349end
[402]350
351%------------------------------------------------------------------------
[644]352%--- activated when resizing the GUI view_field
353 function ResizeFcn(gcbo,eventdata,handles)
354%------------------------------------------------------------------------     
355set(handles.uvmat,'Units','pixels')
356size_fig=get(handles.uvmat,'Position');
357ColumnWidth=max(150,0.18*size_fig(3));
358ColumnWidth=min(ColumnWidth,250); % width of the right side display column, between 150 and 250, depending on the fig width
359
360%% position of panel InputFile
[646]361set(handles.InputFile,'Units','pixels')
[644]362pos_InputFile=get(handles.InputFile,'Position');% [lower x lower y width height] for text_display
363pos_InputFile(1)=0;
364pos_InputFile(2)=size_fig(4)-pos_InputFile(4);             % set frame InputFile to the top of the fig
365pos_InputFile(3)=size_fig(3);
366set(handles.InputFile,'Position',pos_InputFile);% [lower x lower y width height] for text_display
367
[690]368%% reset position of text_display and TableDisplay
369% if strcmp(get(handles.TableDisplay,'Visible'),'off')
[646]370    set(handles.text_display,'Units','pixels')
[644]371    pos_1=get(handles.text_display,'Position');% [lower x lower y width height] for text_display
372        pos_1(3)=1.2*ColumnWidth;
373    pos_1(1)=size_fig(3)-pos_1(3);             % set text display to the right of the fig
374    pos_1(2)=size_fig(4)-pos_InputFile(4)-pos_1(4);             % set text display to the top of the fig
375    set(handles.text_display,'Position',pos_1)
376    % reset position of TableDisplay
[690]377% else
378%     set(handles.TableDisplay,'Units','pixels')
379%     pos_1=get(handles.TableDisplay,'Position');
380%     pos_1(3)=1.2*ColumnWidth;
381%     pos_1(1)=size_fig(3)-pos_1(3);
382%     pos_1(2)=size_fig(4)-pos_InputFile(4)-pos_1(4);
[644]383    set(handles.TableDisplay,'Position',pos_1)
[690]384    % reset position of CheckTable
385    set(handles.CheckTable,'Unit','pixels')
386pos_CheckTable=get(handles.CheckTable,'Position');% [lower x lower y width height] for CheckHold
387pos_CheckTable(1)=pos_1(1)-pos_CheckTable(3);       % set 'CheckHold' to the right of the fig
388pos_CheckTable(2)=pos_InputFile(2)-pos_CheckTable(4);          % set 'CheckHold' to the lower edge of text display
389set(handles.CheckTable,'Position',pos_CheckTable)
390% end
[644]391
392%% reset position of CheckHold
393% pos_CheckHold=get(handles.CheckHold,'Position');% [lower x lower y width height] for CheckHold
394% pos_CheckHold(1)=size_fig(3)-pos_CheckHold(3);       % set 'CheckHold' to the right of the fig
395% pos_CheckHold(2)=pos_1(2)-pos_CheckHold(4);          % set 'CheckHold' to the lower edge of text display
396% set(handles.CheckHold,'Position',pos_CheckHold)
397
398%% reset position of Coordinates
[646]399set(handles.Coordinates,'Units','pixels')
[644]400pos_2=get(handles.Coordinates,'Position');% [lower x lower y width height] for frame 'Coordinates'
401pos_2(3)=ColumnWidth;
402pos_2(1)=size_fig(3)-pos_2(3);       % set 'Coordinates' to the right of the fig
403pos_2(2)=pos_1(2)-pos_2(4);          % set 'Coordinates' to the lower edge of text display, allowing a margin for CheckHold
404set(handles.Coordinates,'Position',pos_2)
405
406%% reset position of  Scalar
[646]407set(handles.Scalar,'Units','pixels')
[644]408pos_3=get(handles.Scalar,'Position'); % [lower x lower y width height] for frame 'Scalar'
409pos_3(3)=ColumnWidth;
410pos_3(1)=size_fig(3)-pos_3(3);         % set 'Scalar' to the right of the fig
411if strcmp(get(handles.Scalar,'Visible'),'on')
412    pos_3(2)=pos_2(2)-pos_3(4); % set 'Scalar' to the lower edge of frame 'Coordinates' if visible
413else
414    pos_3(2)=pos_2(2);% set 'Scalar' to the lower edge of frame 'text display' if  unvisible
415end
416set(handles.Scalar,'Position',pos_3)
417
418%% reset position of  Vectors
419set(handles.Vectors,'Units','pixels')
420pos_4=get(handles.Vectors,'Position');
421pos_4(3)=ColumnWidth;
422pos_4(1)=size_fig(3)-pos_4(3);
423if strcmp(get(handles.Vectors,'visible'),'on')
424    pos_4(2)=pos_3(2)-pos_4(4);
425else
426    pos_4(2)=pos_3(2);
427end
428set(handles.Vectors,'Position',pos_4)
429
430%% reset position and scale of axis
431pos(1)=0.2*size_fig(3)+35;
432pos(2)=35;
433pos(3)=0.77*size_fig(3)-1.2*ColumnWidth;
434pos(4)=size_fig(4)-60;
[646]435set(handles.PlotAxes,'Units','pixels')
[644]436set(handles.PlotAxes,'Position',pos)
[713]437set(handles.PlotAxes,'Units','normalized')
[644]438
439
[402]440%------------------------------------------------------------------------
[644]441%------------------------------------------------------------------------
[387]442%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
443% automatically sets the global properties when the rootfile name is introduced
444% then activate the view-field action if selected
445% it is activated either by clicking on the RootPath window or by the
446% browser
447%------------------------------------------------------------------------
448%------------------------------------------------------------------------
449% --- Executes on the menu Open/Browse...
450% search the files, recognize their type according to their name and fill the rootfile input windows
451function MenuBrowse_Callback(hObject, eventdata, handles)
452[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
[609]453oldfile=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
[576]454if isempty(oldfile) %loads the previously stored file name and set it as default in the file_input box
455    oldfile=get(handles.RootPath,'UserData');
[387]456end
[651]457fileinput=uigetfile_uvmat('pick an input file',oldfile);
[704]458hh=dir(fileinput);
459if numel(hh)>1
460    msgbox_uvmat('ERROR','invalid input, probably a broken link');
461else
[611]462
[710]463    %% display the selected field and related information
464    if ~isempty(fileinput)
465        set(handles.SubField,'Value',0)
466        desable_subfield(handles)
467        display_file_name(handles,fileinput)
468    end
[606]469end
[387]470
471% -----------------------------------------------------------------------
[651]472% --- Open again the file whose name has been recorded in MenuFile_1
473function MenuFile_Callback(hObject, eventdata, handles)
474%------------------------------------------------------------------------
475fileinput=get(hObject,'Label');
[714]476set(handles.SubField,'Value',0)
477desable_subfield(handles)
478errormsg=display_file_name( handles,fileinput);
479if ~isempty(errormsg)
480    set(hObject,'Label','')
481    MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
482        {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
483    str_find=strcmp(get(hObject,'Label'),MenuFile);
484    MenuFile(str_find)=[];% suppress the input file to the list
485    for ifile=1:numel(MenuFile)
486        set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile});
487    end
488end
[651]489
490% -----------------------------------------------------------------------
[569]491% --- Executes on the menu Open/Browse campaign...
[651]492% --- search the file inside a campaign, using the GUI browse_data
493% -----------------------------------------------------------------------
[569]494function MenuBrowseCampaign_Callback(hObject, eventdata, handles)
[651]495set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
496drawnow
[576]497RootPath=get(handles.RootPath,'String');
498if isempty(RootPath)
499    RootPath=get(handles.RootPath,'UserData');%use Rootpath recored from the personal file at uvmat opening
500end
501CampaignPath=fileparts(fileparts(RootPath));
[651]502DirFull=uigetfile_uvmat('define this path as the Campaign folder:',CampaignPath,'uigetdir');
503%DirFull = uigetdir(CampaignPath,'Select a Campaign dir, then press OK');
504if isempty(DirFull)
[569]505    return
506end
507OutPut=browse_data(DirFull);% open the GUI browse_data to get select a campaign dir, experiment and device
508if ~isfield(OutPut,'Campaign')
509    return
510end
[651]511DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
512ListStruct=dir(DirName); %list files and the dir DataSeries
513% select the first appropriate file in the dir
514FileName='';
515for ilist=1:numel(ListStruct)
516    if ~isequal(ListStruct(ilist).isdir,1)%look for files, not dir
517        FileName=ListStruct(ilist).name;
[569]518        FileType=get_file_type(fullfile(DirName,FileName));
519        switch FileType
520            case {'image','multimage','civx','civdata','netcdf'}
[651]521                break
[569]522        end
523    end
524end
[651]525if isempty(FileName)
526    msgbox_uvmat('ERROR',['no appropriate input file in the DataSeries folder ' fullfile(DirName)])
527    return
528end
[569]529
[651]530%% update the list of campaigns in the menubar
531MenuCampaign=[{get(handles.MenuCampaign_1,'Label')};{get(handles.MenuCampaign_2,'Label')};...
532    {get(handles.MenuCampaign_3,'Label')};{get(handles.MenuCampaign_4,'Label')};{get(handles.MenuCampaign_5,'Label')}];
533check_dir=isempty(find(strcmp(DirFull,MenuCampaign)));
534if check_dir %insert the new campaign in the list if it is not found
535    MenuCampaign(end)=[]; %suppress the last item
536    MenuCampaign=[{DirFull};MenuCampaign];%insert the new campaign
537    for ilist=1:numel(MenuCampaign)
538        set(handles.(['MenuCampaign_' num2str(ilist)]),'Label',MenuCampaign{ilist})
539    end
540    % save the list for future opening:
541    dir_perso=prefdir;
542    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
543    if exist(profil_perso,'file')
544        save (profil_perso,'MenuCampaign','RootPath','-append'); %store the file names for future opening of uvmat
545    else
546        save (profil_perso,'MenuCampaign','RootPath','-V6'); %store the file names for future opening of uvmat
547    end
548end
549
[569]550%% display the selected field and related information
551display_file_name( handles,fullfile(DirName,FileName))
552
[651]553set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
[387]554
555% -----------------------------------------------------------------------
[651]556% --- Open again as second field the file whose name has been recorded in MenuFile_1
[387]557% -----------------------------------------------------------------------
[651]558function MenuCampaign_Callback(hObject, eventdata, handles)
[387]559
[651]560set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
561OutPut=browse_data(get(hObject,'Label'));% open the GUI browse_data to get select a campaign dir, experiment and device
[569]562if ~isfield(OutPut,'Campaign')
563    return
564end
[651]565DirName=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
[569]566hdir=dir(DirName); %list files and dirs
[672]567FileName='';
[569]568for ilist=1:numel(hdir)
569    if ~isequal(hdir(ilist).isdir,1)%look for files, not dir
570        FileName=hdir(ilist).name;
571        FileType=get_file_type(fullfile(DirName,FileName));
572        switch FileType
573            case {'image','multimage','civx','civdata','netcdf'}
574            break
575        end
576    end
577end
[672]578if isempty(FileName)
579    msgbox_uvmat('ERROR','no valid input file in the selected directory')
580else
[651]581display_file_name(handles,fullfile(DirName,FileName))
[672]582end
[651]583set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
[569]584
[402]585%------------------------------------------------------------------------
586% --- Called by action in FileIndex edit box
587function FileIndex_Callback(hObject, eventdata, handles)
588%------------------------------------------------------------------------
589[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
590set(handles.i1,'String',num2str(i1));
591set(handles.i2,'String',num2str(i2));
592set(handles.j1,'String',num2str(j1));
593set(handles.j2,'String',num2str(j2));
594
595
596%------------------------------------------------------------------------
597% --- Called by action in NomType edit box
598function NomType_Callback(hObject, eventdata, handles)
599%------------------------------------------------------------------------
600i1=str2num(get(handles.i1,'String'));
601i2=str2num(get(handles.i2,'String'));
602j1=str2num(get(handles.j1,'String'));
603j2=str2num(get(handles.j2,'String'));
604FileIndex=fullfile_uvmat('','','','',get(handles.NomType,'String'),i1,i2,j1,j2);
605set(handles.FileIndex,'String',FileIndex)
[713]606% inputfilerefresh the current settings and inputfilerefresh the field view
[402]607RootPath_Callback(hObject,eventdata,handles)
608
609%------------------------------------------------------------------------
610% --- Called by action in NomType edit box
611function NomType_1_Callback(hObject, eventdata, handles)
612%------------------------------------------------------------------------
613i1=str2num(get(handles.i1,'String'));
614i2=str2num(get(handles.i2,'String'));
615j1=str2num(get(handles.j1,'String'));
616j2=str2num(get(handles.j2,'String'));
617FileIndex=fullfile_uvmat('','','','',get(handles.NomType_1,'String'),i1,i2,j1,j2);
618set(handles.FileIndex_1,'String',FileIndex)
[713]619% inputfilerefresh the current settings and inputfilerefresh the field view
[402]620RootPath_1_Callback(hObject,eventdata,handles)
621
[710]622%------------------------------------------------------------------------
[713]623% --- Executes on button press in InputFileREFRESH.
624function InputFileREFRESH_Callback(hObject, eventdata, handles)
[710]625%------------------------------------------------------------------------   
[713]626set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% set button color to yellow to indicate that refresh is under action
[714]627set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
628drawnow
[710]629% read the current input file name:
630[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
631% if ~exist(fullfile(RootPath,SubDir),'dir')
632%     msgbox_uvmat('ERROR',['directory ' fullfile(RootPath,SubDir) ' does not exist'])
633%     return
634% end
635% detect the file type, get the movie object if relevant, and look for the corresponding file series:
636[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
[713]637% initiate the input file series and inputfilerefresh the current field view:
[710]638errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,1);
[713]639% inputfilerefresh the second series if selected
[710]640if get(handles.SubField,'Value')
641    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
642    if ~exist(fullfile(RootPath,SubDir),'dir')
643        msgbox_uvmat('ERROR',['directory ' fullfile(RootPath,SubDir) ' does not exist'])
644        return
645    end
646    % detect the file type, get the movie object if relevant, and look for the corresponding file series:
647    [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
[713]648    % initiate the input file series and inputfilerefresh the current field view:
[710]649    errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,2);
650end
651
652if isempty(errormsg)
[714]653% set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% set button color to red to indicate that refresh has been updated
[710]654else
[713]655    set(handles.InputFileREFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
[710]656end
[714]657set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow
[710]658
[387]659%------------------------------------------------------------------------
660% --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
[714]661function errormsg=display_file_name(handles,fileinput,index)
[387]662%------------------------------------------------------------------------
663%% look for the input file existence
[714]664errormsg='';%default
[387]665if ~exist(fileinput,'file')
[714]666    errormsg=['input file ' fileinput  ' does not exist'];
667    msgbox_uvmat('ERROR',errormsg)
[387]668    return
669end
670
[406]671%% define the relevant handles for the first field series (index=1) or the second file series (index=2)
[387]672if ~exist('index','var')
673    index=1;
674end
675if index==1
676    handles_RootPath=handles.RootPath;
677    handles_SubDir=handles.SubDir;
678    handles_RootFile=handles.RootFile;
679    handles_FileIndex=handles.FileIndex;
680    handles_NomType=handles.NomType;
681    handles_FileExt=handles.FileExt;
682elseif index==2
683    handles_RootPath=handles.RootPath_1;
684    handles_SubDir=handles.SubDir_1;
685    handles_RootFile=handles.RootFile_1;
686    handles_FileIndex=handles.FileIndex_1;
687    handles_NomType=handles.NomType_1;
688    handles_FileExt=handles.FileExt_1;
689    set(handles.RootPath_1,'Visible','on')
690    set(handles.RootFile_1,'Visible','on')
691    set(handles.SubDir_1,'Visible','on');
692    set(handles.FileIndex_1,'Visible','on');
693    set(handles.FileExt_1,'Visible','on');
694    set(handles.NomType_1,'Visible','on');
[674]695    set(handles.TimeName_1,'Visible','on')
696    set(handles.TimeValue_1,'Visible','on')
[387]697end
[713]698set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])% paint REFRESH button to yellow to visualise root file input
[674]699set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
700drawnow
[387]701
[674]702%% detect root name, nomenclature and indices in the input file name:
703[FilePath,FileName,FileExt]=fileparts(fileinput);
704% detect the file type, get the movie object if relevant, and look for the corresponding file series:
705% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
706[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
707
708if strcmp(FileType,'txt')
[688]709    try
710        edit(fileinput)
711    catch ME
712        msgbox_uvmat('ERROR','invalid intput file')
713    end
[674]714    return
715elseif strcmp(FileType,'xml')
716    editxml(fileinput)
717     return
718elseif strcmp(FileType,'figure')
719    open(fileinput)
720     return
721end
722
[387]723%% open the file or fill the GUI uvmat according to the detected file type
724switch FileType
725    case ''
726        msgbox_uvmat('ERROR','invalid input file type')
727    case 'txt'
728        edit(fileinput)
729    case 'figure'                           %display matlab figure
730        hfig=open(fileinput);
731        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
732        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
733        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
[503]734    case 'xml'                % edit xml files
[507]735        t=xmltree(fileinput);
[508]736        % the xml file marks a project or project link, open datatree_browser
[507]737        if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir')
[503]738            datatree_browser(fileinput)
[508]739        else % other xml file, open the xml editor
[503]740            editxml(fileinput);
741        end
[508]742    case 'xls'% Excel file opended by editxml
[387]743        editxml(fileinput);
744    otherwise
745        set(handles_RootPath,'String',RootPath);
746        rootname=fullfile(RootPath,SubDir,RootFile);
747        set(handles_SubDir,'String',['/' SubDir]);
748        set(handles_RootFile,'String',['/' RootFile]); %display the separator
749        indices=fileinput(length(rootname)+1:end);
750        indices(end-length(FileExt)+1:end)=[]; %remove extension
751        set(handles_FileIndex,'String',indices);
752        set(handles_NomType,'String',NomType);
753        set(handles_FileExt,'String',FileExt);
754        if index==1
755            % fill file index counters if the first file series is opened
756            set(handles.i1,'String',num2str(i1));
757            set(handles.i2,'String',num2str(i2));
758            set(handles.j1,'String',num2stra(j1,NomType));
759            set(handles.j2,'String',num2stra(j2,NomType));
[515]760        else %read the current field index to synchronise with the first series
761            i1_s=str2num(get(handles.i1,'String'));
762            i2_0=str2num(get(handles.i2,'String'));
763            if ~isempty(i2_0)
764                i2_s=i2_0;
765            else
766               i2_s=i2;
767            end
768            j1_0=stra2num(get(handles.j1,'String'));
769            if ~isempty(j1_0)
770                j1_s=j1_0;
771            else
772                j1_s=j1;
773            end
774            j2_0=stra2num(get(handles.j2,'String'));
775            if ~isempty(j2_0)
776                j2_s=j2_0;
777            else
778                j2_s=j2;
779            end
[387]780        end
781       
782        % synchronise indices of the second  input file if it exists
783        if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
784            Input=read_GUI(handles.InputFile);
785            if ~isfield(Input,'RootPath_1')||strcmp(Input.RootPath_1,'"')
786                Input.RootPath_1=Input.RootPath;
787            end
788            if ~isfield(Input,'SubDir_1')||strcmp(Input.SubDir_1,'"')
789                Input.SubDir_1=Input.SubDir;
790            end
791            if ~isfield(Input,'RootFile_1')||strcmp(Input.RootFile_1,'"')
792                Input.RootFile_1=Input.RootFile;
793            end
[405]794            if ~isfield(Input,'FileExt_1')||strcmp(Input.FileExt_1,'"')
795                Input.FileExt_1=Input.FileExt;
796            end
797            if ~isfield(Input,'NomType_1')||strcmp(Input.NomType_1,'"')
798                Input.NomType_1=Input.NomType;
799            end
[387]800            %updtate the indices of the second field series to correspond to the newly opened one
[515]801            FileName_1=fullfile_uvmat(Input.RootPath_1,Input.SubDir_1,Input.RootFile_1,Input.FileExt_1,Input.NomType_1,i1_s,i2_s,j1_s,j2_s);
[387]802            if exist(FileName_1,'file')
[515]803                FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1_s,i2_s,j1_s,j2_s);
804            else
[387]805                FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1,i2,j1,j2);
[408]806                msgbox_uvmat('WARNING','unable to synchronise the indices of the two series')
[387]807            end
[515]808            set(handles.FileIndex_1,'String',FileIndex_1)
[387]809        end
810       
811        %enable other menus
[651]812        set(handles.MenuOpenCampaign,'Enable','on')
[387]813        set(handles.MenuExport,'Enable','on')
814        set(handles.MenuExportFigure,'Enable','on')
815        set(handles.MenuExportMovie,'Enable','on')
816        set(handles.MenuTools,'Enable','on')
[503]817
[713]818        % initiate input file series and inputfilerefresh the current field view:     
[387]819        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,index);
820
821end
822
[503]823%% update list of recent files in the menubar and save it for future opening
824MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
825    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
826str_find=strcmp(fileinput,MenuFile);
827if isempty(find(str_find,1))
828    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
829end
830for ifile=1:min(length(MenuFile),5)
[576]831    set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile});
[651]832    %set(handles.(['MenuFile_' num2str(ifile) '_1']),'Label',MenuFile{ifile});
[503]833end
834dir_perso=prefdir;
835profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
836if exist(profil_perso,'file')
[576]837    save (profil_perso,'MenuFile','RootPath','-append'); %store the file names for future opening of uvmat
[503]838else
[576]839    save (profil_perso,'MenuFile','RootPath','-V6'); %store the file names for future opening of uvmat
[503]840end
841
[713]842set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% paint back button to red to indicate update is finished
[674]843set(handles.uvmat,'Pointer','arrow')% set back the mouse pointer to arrow
[387]844
845
846%------------------------------------------------------------------------
847% --- Update information about a new field series (indices to scan, timing,
[713]848%     calibration from an xml file, then inputfilerefresh current plots
[710]849function errormsg=update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,index)
[387]850%------------------------------------------------------------------------
[710]851errormsg=''; %default error msg
[387]852%% define the relevant handles depending on the index (1=first file series, 2= second file series)
853if ~exist('index','var')
854    index=1;
855end
856if index==1
[526]857    handles_Fields=handles.FieldName;
[387]858elseif index==2
[526]859    handles_Fields=handles.FieldName_1;
[387]860end
861
[526]862set(handles.FieldName,'UserData',[])% reinialize data from uvmat opening
[387]863UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
[713]864UvData.NewSeries=1; %flag for REFRESH: begin a new series
[511]865UvData.FileName_1='';% name of the current second field (used to detect a  constant field during file scanning)
[387]866UvData.FileType{index}=FileType;
867UvData.i1_series{index}=i1_series;
868UvData.i2_series{index}=i2_series;
869UvData.j1_series{index}=j1_series;
870UvData.j2_series{index}=j2_series;
871set(handles.FixVelType,'Value',0); %desactivate fixed veltype
872if index==1
873    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
874else
875    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
876end
877FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
878FileBase=fullfile(RootPath,RootFile);
879if ~exist(FileName,'file')
[710]880    errormsg=['input file ' FileName ' not found'];
881   msgbox_uvmat('ERROR',errormsg);   
[387]882    return
883end
884
885%% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
[674]886TimeUnit='';%default
887TimeName='';%default
[387]888XmlData.Time=[];%default
889imainfo=[];
890ColorType='falsecolor'; %default
[397]891UvData.MovieObject{index}=VideoObject;
[675]892if ~isempty(VideoObject)% case of video data
[397]893    imainfo=get(VideoObject);
[387]894    TimeUnit='s';
[494]895    if isempty(j1_series); %frame index along i
[674]896        XmlData.Time=zeros(imainfo.NumberOfFrames+1,2);
897        XmlData.Time(:,2)=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)';
[494]898    else
[674]899        XmlData.Time=[0;ones(size(i1_series,3)-1,1)]*(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate);
[494]900    end
[675]901    %set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
[674]902    TimeName='video';
[397]903    ColorType='truecolor';
[387]904elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image
905    if ~isequal(SubDir,'')
906        imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
907    else
908        imainfo=imfinfo([FileBase FileIndices FileExt]);
909    end
910    ColorType=imainfo.ColorType;%='truecolor' for color images
911end
912if isfield(imainfo,'Width') && isfield(imainfo,'Height')
913    if length(imainfo)>1
914        set(handles.num_Npx,'String',num2str(imainfo(1).Width));%fills nbre of pixels x box
915        set(handles.num_Npy,'String',num2str(imainfo(1).Height));%fills nbre of pixels x box
916    else
917        set(handles.num_Npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box
918        set(handles.num_Npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box
919    end
920else
921    set(handles.num_Npx,'String','');%fills nbre of pixels x box
922    set(handles.num_Npy,'String','');%fills nbre of pixels x box
923end
924set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image
925
926%% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
[674]927XmlData.GeometryCalib=[];%default
[469]928XmlFileName=find_imadoc(RootPath,SubDir,RootFile,FileExt);
929[tild,tild,DocExt]=fileparts(XmlFileName);
[387]930warntext='';%default warning message
931NbSlice=1;%default
[611]932ImaDoc_str='';
[469]933if ~isempty(XmlFileName)
[387]934    set(handles.view_xml,'Visible','on')
[611]935    set(handles.view_xml,'BackgroundColor',[1 1 0])% paint  to yellow color to indicate reading of the xml file
[387]936    set(handles.view_xml,'String','view .xml')
937    drawnow
[469]938    [XmlDataRead,warntext]=imadoc2struct(XmlFileName);
[688]939    if ~isempty(warntext)
940        msgbox_uvmat('WARNING',warntext)
941    end
[611]942    if ~isempty(XmlDataRead)
[688]943        ImaDoc_str=['view ' DocExt];  % DocExt= '.xml' or .civ (obsolete case)
944        %XmlData=XmlDataRead;
945        if isfield(XmlDataRead,'TimeUnit')&& ~isempty(XmlDataRead.TimeUnit)
946            TimeUnit=XmlDataRead.TimeUnit;
947        end
948        if isfield(XmlDataRead,'Time')&& ~isempty(XmlDataRead.Time)
949            XmlData.Time=XmlDataRead.Time;
950        end
[683]951        set(handles.view_xml,'BackgroundColor',[1 1 1])% paint back to white
[456]952        drawnow
[683]953        if isfield(XmlDataRead, 'GeometryCalib') && ~isempty(XmlDataRead.GeometryCalib)
954            XmlData.GeometryCalib=XmlDataRead.GeometryCalib;
[456]955            if isfield(XmlData.GeometryCalib,'VolumeScan') && isequal(XmlData.GeometryCalib.VolumeScan,'y')
[589]956                set (handles.slices,'String','volume')
[456]957            end
[688]958            % check whether the GUI geometry_calib is opened
[456]959            hgeometry_calib=findobj('tag','geometry_calib');
[683]960            if ~isempty(hgeometry_calib) % check whether the display of the GUI geometry_calib is consistent with the current calib param
[456]961                GUserData=get(hgeometry_calib,'UserData');
[469]962                if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,XmlFileName))
[683]963                    answer=msgbox_uvmat('INPUT_Y-N','refresh the display of the GUI geometry_calib with the new input data?');
[456]964                    if strcmp(answer,'Yes')
[469]965                        geometry_calib(XmlFileName);%diplay the new calibration points and parameters in geometry_calib
[456]966                    end
[387]967                end
968            end
969        end
[441]970    end
[387]971end
[674]972if isempty(ImaDoc_str)
973    set(handles.view_xml,'Visible','off') % no .xml (or .civ) file detected
[648]974else
[674]975    set(handles.view_xml,'String',ImaDoc_str)% indicate that a xml file has been detected
[494]976end
[674]977
978%% Define timing
979% time not set by the input file: images or civ data: indicate that time is read from the xml file
980if isfield(XmlData,'Time')&& ~isempty(XmlData.Time) && ...
981        (strcmp(FileType,'image')|| strcmp(FileType,'multimage')||strcmp(FileType,'civdata')||strcmp(FileType,'civx'))
982    TimeName='xml';
[675]983elseif strcmp(FileType,'civdata')
984    TimeName='civdata';
985elseif strcmp(FileType,'civx')
986    TimeName='civx';
[674]987end
988if index==1
989    set(handles.TimeName,'String',TimeName)
[611]990else
[674]991    set(handles.TimeName_1,'String',TimeName)
992    set(handles.TimeName_1,'Visible','on')
[611]993end
[387]994
[648]995%% store last index in handles.MaxIndex_i and .MaxIndex_j
[496]996nbfield=max(max(max(i2_series)));
[387]997if isempty(nbfield)
[496]998    nbfield=max(max(max(i1_series)));
[387]999end
[496]1000nbfield_j=max(max(max(j2_series)));
[387]1001if isempty(nbfield_j)
[552]1002    nbfield_j=max(max(max(j1_series)));
[387]1003end
[674]1004if isfield(XmlData,'Time')&& ~isempty(XmlData.Time)
[387]1005    %transform .Time to a column vector if it is a line vector the nomenclature uses a single index
[441]1006    if isequal(size(XmlData.Time,1),1)
[456]1007        XmlData.Time=(XmlData.Time)';
[387]1008    end
1009end
[648]1010last_i_cell=get(handles.MaxIndex_i,'String');
[387]1011if isempty(nbfield)
[552]1012    last_i_cell{index}='';
[387]1013else
[552]1014    last_i_cell{index}=num2str(nbfield);
[387]1015end
[648]1016set(handles.MaxIndex_i,'String',last_i_cell)
1017last_j_cell=get(handles.MaxIndex_j,'String');
[387]1018if isempty(nbfield_j)
[552]1019     last_j_cell{index}='';
[387]1020else
[552]1021     last_j_cell{index}=num2str(nbfield_j);
[387]1022end
[648]1023set(handles.MaxIndex_j,'String',last_j_cell);
[387]1024
1025%% store geometric calibration in UvData
1026if isfield(XmlData,'GeometryCalib')
1027    GeometryCalib=XmlData.GeometryCalib;
1028    if isempty(GeometryCalib)
[689]1029        set(handles.pxcmx,'String','')
1030        set(handles.pxcmy,'String','')
1031        set(handles.pxcmx,'Visible','off')
1032        set(handles.pxcmy,'Visible','off')
[591]1033        set(handles.TransformName,'Value',1); %  no transform by default
[387]1034    else
[689]1035        set(handles.pxcmx,'Visible','on')
1036        set(handles.pxcmy,'Visible','on')
[387]1037        if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||...
1038            (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0))
[689]1039            set(handles.pxcmx,'String','var')
1040            set(handles.pxcmy,'String','var')
[387]1041        elseif isfield(GeometryCalib,'fx_fy')
1042            pixcmx=GeometryCalib.fx_fy(1);%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
1043            pixcmy=GeometryCalib.fx_fy(2);%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
[689]1044            set(handles.pxcmx,'String',num2str(pixcmx))
1045            set(handles.pxcmy,'String',num2str(pixcmy))
[387]1046        end
1047        if ~get(handles.CheckFixLimits,'Value')
[591]1048            set(handles.TransformName,'Value',3); % phys transform by default if fixedLimits is off
[387]1049        end
[508]1050        if isfield(GeometryCalib,'SliceCoord')           
[387]1051           siz=size(GeometryCalib.SliceCoord);
1052           if siz(1)>1
1053               NbSlice=siz(1);
1054               set(handles.slices,'Visible','on')
1055               set(handles.slices,'Value',1)
1056           end
1057           if isfield(GeometryCalib,'VolumeScan') && isequal(GeometryCalib.VolumeScan,'y')
[589]1058               set(handles.num_NbSlice,'Visible','off')
[387]1059           else
[589]1060               set(handles.num_NbSlice,'Visible','on')
[497]1061               set(handles.num_NbSlice,'String',num2str(NbSlice))
[387]1062           end
1063           slices_Callback([],[], handles)
1064        end           
1065    end
1066end
1067
1068%% update the data attached to the uvmat interface
[675]1069if ~isempty(TimeUnit)
1070    if index==2 && isfield(UvData,'TimeUnit') && ~strcmp(UvData.TimeUnit,TimeUnit)
[688]1071        msgbox_uvmat('WARNING',['time unit for second file series ' TimeUnit ' inconsistent with first series'])
[675]1072    else
1073        UvData.TimeUnit=TimeUnit;
1074    end
1075end
[387]1076UvData.XmlData{index}=XmlData;
1077UvData.NewSeries=1;
1078
1079%display warning message
[688]1080if ~isequal(warntext,'')
[387]1081    msgbox_uvmat('WARNING',warntext);
1082end
1083
[526]1084%% set default options in menu 'FieldName'
[517]1085switch FileType
1086    case {'civx','civdata'}
[581]1087        [FieldList,ColorList]=set_field_list('U','V','C');
[525]1088        set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
1089        set(handles_Fields,'Value',2) % set menu to 'velocity
[580]1090        if index==1
1091            set(handles.FieldName_1,'Value',1);
1092            set(handles.FieldName_1,'String',[{''};{'image'};FieldList;{'get_field...'}]);%standard menu for civx data reproduced for the second field
1093        end
[525]1094        set(handles.ColorScalar,'Value',1)
1095        set(handles.ColorScalar,'String',ColorList)
1096        set(handles.Vectors,'Visible','on')
1097        set(handles.Coord_x,'Value',1);
[646]1098        set(handles.Coord_x,'String','X');
1099%         set(handles.Coord_y,'Value',1);
1100        set(handles.Coord_y,'Data',{'Y'});
[517]1101    case 'netcdf'
[387]1102        set(handles_Fields,'Value',1)
1103        set(handles_Fields,'String',{'get_field...'})
[713]1104        if index==1
1105            FieldName_Callback([],[], handles)
1106        else
1107            FieldName_1_Callback([],[], handles)
1108        end
[517]1109    otherwise
1110        set(handles_Fields,'Value',1) % set menu to 'image'
1111        set(handles_Fields,'String',{'image'})
[525]1112        set(handles.Coord_x,'Value',1);
[646]1113        set(handles.Coord_x,'String','AX');
1114    set(handles.Coord_y,'Data',{'AY'});
[387]1115end
1116set(handles.uvmat,'UserData',UvData)
1117
[713]1118%% set index navigation options and inputfilerefresh plots
[387]1119scan_option='i';%default
1120state_j='off'; %default
1121if index==2
1122    if get(handles.scan_j,'Value')
[494]1123        scan_option='j'; %keep the scan option for the second file series
[387]1124    end
1125    if strcmp(get(handles.j1,'Visible'),'on')
1126        state_j='on';
1127    end
1128end
[515]1129[ref_j,ref_i]=find(squeeze(i1_series(1,:,:)));
[387]1130if ~isempty(j1_series)
1131        state_j='on';
[494]1132        if index==1
[515]1133            if isequal(ref_i,ref_i(1)*ones(size(ref_j)))% if ref_i is always equal to its first value
[494]1134                scan_option='j'; %scan j indext               
1135            end
1136        end
[387]1137end
1138if isequal(scan_option,'i')
[494]1139    diff_ref_i=diff(ref_i,1);
1140    if isempty(diff_ref_i)
1141        diff_ref_i=1;
1142    end
1143    if isequal (diff_ref_i,diff_ref_i(1)*ones(size(diff_ref_i)))
[511]1144        set(handles.num_IndexIncrement,'String',num2str(diff_ref_i(1)))
[494]1145    end
[387]1146     set(handles.scan_i,'Value',1)
1147     scan_i_Callback([],[], handles);
1148else
[494]1149    diff_ref_j=diff(ref_j);
1150    if isempty(diff_ref_j)
1151        diff_ref_j=1;
1152    end
1153    if isequal (diff_ref_j,diff_ref_j(1)*ones(size(diff_ref_j)))
[511]1154        set(handles.num_IndexIncrement,'String',num2str(diff_ref_j(1)))
[494]1155    end
[387]1156     set(handles.scan_j,'Value',1)
1157     scan_j_Callback([],[], handles);
1158end
1159set(handles.scan_j,'Visible',state_j)
1160set(handles.j1,'Visible',state_j)
1161set(handles.j2,'Visible',state_j)
[648]1162set(handles.MaxIndex_j,'Visible',state_j);
[387]1163set(handles.j_text,'Visible',state_j);
1164if ~isempty(i2_series)||~isempty(j2_series)
1165    set(handles.CheckFixPair,'Visible','on')
1166elseif index==1
1167    set(handles.CheckFixPair,'Visible','off')
1168end
1169
[508]1170%% apply the effect of the transform fct and view the field 
[591]1171transform=get(handles.TransformPath,'UserData');
[515]1172if index==2 && (~isa(transform,'function_handle')||nargin(transform)<3)
[591]1173    set(handles.TransformName,'value',2); % set transform to sub_field if the current fct doe not accept two input fields
[515]1174end
[714]1175set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])% set button color to red to indicate that refresh has been updated
1176TransformName_Callback([],[],handles)% callback for the selection of transform function, then refresh the current plot
[387]1177mask_test=get(handles.CheckMask,'value');
1178if mask_test
1179    MaskData=get(handles.CheckMask,'UserData');
1180    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1181          delete(MaskData.maskhandle)    %delete old mask
1182    end
1183    CheckMask_Callback([],[],handles)
1184end
1185
1186%------------------------------------------------------------------------
1187% --- switch file index scanning options scan_i and scan_j in an exclusive way
[667]1188%------------------------------------------------------------------------
[387]1189function scan_i_Callback(hObject, eventdata, handles)
[667]1190
[387]1191if get(handles.scan_i,'Value')==1
1192    set(handles.scan_j,'Value',0)
1193else
1194    set(handles.scan_j,'Value',1)
1195end
1196scan_j_Callback(hObject, eventdata, handles)
1197
1198%------------------------------------------------------------------------
1199% --- switch file index scanning options scan_i and scan_j in an exclusive way
[667]1200%------------------------------------------------------------------------
[387]1201function scan_j_Callback(hObject, eventdata, handles)
[667]1202
[387]1203if get(handles.scan_j,'Value')==1
1204    set(handles.scan_i,'Value',0)
1205else
1206    set(handles.scan_i,'Value',1)
1207    set(handles.CheckFixPair,'Visible','off')
1208end
1209
1210%------------------------------------------------------------------------
1211function i1_Callback(hObject, eventdata, handles)
1212%------------------------------------------------------------------------
[515]1213update_ij(handles,1)
[387]1214
1215%------------------------------------------------------------------------
1216function i2_Callback(hObject, eventdata, handles)
1217%------------------------------------------------------------------------
[515]1218update_ij(handles,2)
[387]1219
1220%------------------------------------------------------------------------
1221function j1_Callback(hObject, eventdata, handles)
1222%------------------------------------------------------------------------
[515]1223update_ij(handles,3)
[387]1224
1225%------------------------------------------------------------------------
1226function j2_Callback(hObject, eventdata, handles)
1227%------------------------------------------------------------------------
[515]1228update_ij(handles,4)
[387]1229
1230%------------------------------------------------------------------------
[515]1231%--- update the index display after action on edit boxes i1, i2, j1 or j2
[675]1232%------------------------------------------------------------------------
[515]1233function update_ij(handles,index_rank)
[675]1234   
[515]1235NomType=get(handles.NomType,'String');
1236indices=get(handles.FileIndex,'String');
1237[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex
1238switch index_rank
1239    case 1
1240        indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2);
1241        set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
1242    case 2
1243        indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2);
1244        set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
1245    case 3
1246        indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2);
1247        set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
1248    case 4
1249        indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String')));
1250        set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
1251end
1252set(handles.FileIndex,'String',indices)
1253set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
1254% update the second index if relevant
1255if strcmp(get(handles.FileIndex_1,'Visible'),'on')
1256    NomType_1=get(handles.NomType_1,'String');
1257    indices_1=get(handles.FileIndex_1,'String');
1258    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(indices_1);% the indices for the second series taken from FileIndex_1
1259    switch index_rank
1260        case 1
1261            indices_1=fullfile_uvmat('','','','',NomType_1,stra2num(get(handles.i1,'String')),i2_1,j1_1,j2_1);
1262        case 2
1263            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,stra2num(get(handles.i2,'String')),j1_1,j2_1);
1264        case 3
1265            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,stra2num(get(handles.j1,'String')),j2_1);
1266        case 4
1267            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,j1_1,stra2num(get(handles.j2,'String')));
1268    end
1269    set(handles.FileIndex_1,'String',indices_1)
1270    set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
1271end
1272   
1273%------------------------------------------------------------------------
1274
1275%------------------------------------------------------------------------
[387]1276function slices_Callback(hObject, eventdata, handles)
1277%------------------------------------------------------------------------
[589]1278if strcmp(get(handles.slices,'String'),'slices')
1279    if get(handles.slices,'Value')==1
1280        set(handles.num_NbSlice,'Visible','on')
1281        set(handles.z_text,'Visible','on')
1282        set(handles.z_index,'Visible','on')
1283        num_NbSlice_Callback(hObject, eventdata, handles)
1284    else
1285        set(handles.num_NbSlice,'Visible','off')
1286        set(handles.z_text,'Visible','off')
1287        set(handles.z_index,'Visible','off')
1288        set(handles.masklevel,'Value',1)
1289        set(handles.masklevel,'String',{'1'})
1290    end
[387]1291end
1292
1293%------------------------------------------------------------------------
[497]1294function num_NbSlice_Callback(hObject, eventdata, handles)
[387]1295%------------------------------------------------------------------------
[589]1296mode=get(handles.slices,'String');
[497]1297nb_slice_str=get(handles.num_NbSlice,'String');
[589]1298if strcmp(mode,'volume')
1299    z=stra2num(get(handles.j1,'String'));
[387]1300else
1301    num=str2double(get(handles.i1,'String'));
[497]1302    nbslice=str2double(get(handles.num_NbSlice,'String'));
[589]1303    z=mod(num-1,nbslice)+1;
[387]1304end
1305set(handles.z_index,'String',num2str(z))
1306for ilist=1:nbslice
1307    list_index{ilist,1}=num2str(ilist);
1308end   
1309set(handles.masklevel,'String',list_index)
1310set(handles.masklevel,'Value',z)
1311
1312%------------------------------------------------------------------------
1313% --- Executes on button press in view_xml.
[674]1314%------------------------------------------------------------------------
[387]1315function view_xml_Callback(hObject, eventdata, handles)
[674]1316
1317% if TimeName defined, open the xml file corresponding to the first file
1318% series, else open the xml file corresponding to the second series
1319if isempty(get(handles.TimeName,'String'))% open the xml file corresponding to the secodn file series
1320    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
1321else
1322   [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
1323end
[387]1324option=get(handles.view_xml,'String');
[674]1325if isequal(option,'view .xml')     
[494]1326    FileXml=fullfile(RootPath,[SubDir '.xml']);
1327    if ~exist(FileXml,'file')% case of civ files , removes the extension for subdir
1328        FileXml=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']);
1329    end
[387]1330    heditxml=editxml(FileXml);
1331end
1332
1333%------------------------------------------------------------------------
1334% --- Executes on button press in CheckMask.
1335function CheckMask_Callback(hObject, eventdata, handles)
1336%------------------------------------------------------------------------
1337%case of view mask selection
1338if isequal(get(handles.CheckMask,'Value'),1)
[641]1339    [RootPath,SubDir]=read_file_boxes(handles);
1340    MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
1341    MaskPath=fullfile(RootPath,[MaskSubDir '.mask']);
[387]1342    mdetect=0;
[641]1343    if exist(MaskPath,'dir')
1344        ListStruct=dir(MaskPath);%look for a mask file
1345        ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
1346        check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
[667]1347        ListFiles=ListCells(1,:);%list of file and dri names
1348        ListFiles=ListFiles(~check_dir);%list of file names (excluding dir)
[641]1349        if ~isempty(ListFiles)
[675]1350            for ifile=1:numel(ListFiles)
1351                [tild,tild,MaskExt]=fileparts(ListFiles{1});
1352                [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileType]=find_file_series(MaskPath,ListFiles{ifile},0);
1353                if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series)
1354                    mdetect=1;
1355                end
1356                if ~strcmp(MaskFile{ifile},MaskFile{1})
1357                    mdetect=0;% cancel detection test in case of multiple masks, use the brower for selection
1358                    break
1359                end
[387]1360            end
1361        end
[675]1362        RootPath=MaskPath;
[648]1363    end
1364    if mdetect==0
[667]1365        MaskFullName=uigetfile_uvmat('pick a mask image file:',RootPath,'image');
[648]1366        if isempty(MaskFullName)
1367            set(handles.CheckMask,'Value',0)
[387]1368        end
[648]1369        [MaskPath,MaskName,MaskExt]=fileparts(MaskFullName);
[667]1370        [tild,tild,MaskFile,i1_series,i2_series,j1_series,j2_series,MaskNomType]=find_file_series(MaskPath,[MaskName MaskExt],0);
[648]1371        if ~(isempty(i2_series) && isempty(j2_series))
1372            MaskNomType='*';
1373        end
[387]1374    end
[648]1375    Mask.Path=MaskPath;
[710]1376    if isempty(MaskFile)
1377        Mask.File='';
1378    else
1379        Mask.File=MaskFile{1};
1380    end
[648]1381    Mask.Ext=MaskExt;
1382    Mask.NomType=MaskNomType;
1383    set(handles.CheckMask,'UserData',Mask);
1384    errormsg=update_mask(handles);
[387]1385else % desactivate mask display
1386    MaskData=get(handles.CheckMask,'UserData');
1387    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
[641]1388        delete(MaskData.maskhandle)
[387]1389    end
[641]1390    set(handles.CheckMask,'UserData',[])
[387]1391    UvData=get(handles.uvmat,'UserData');
1392    if isfield(UvData,'MaskName')
1393        UvData=rmfield(UvData,'MaskName');
1394        set(handles.uvmat,'UserData',UvData)
1395    end
1396    set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7])
1397end
1398
1399%------------------------------------------------------------------------
[641]1400function errormsg=update_mask(handles)
[387]1401%------------------------------------------------------------------------
1402errormsg=[];%default
[641]1403Mask=get(handles.CheckMask,'UserData');
1404MaskIndex=1;
1405if strcmp(get(handles.z_index,'Visible'),'on')
1406    MaskIndex=str2num(get(handles.z_index,'String'));
[387]1407end
[641]1408if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
1409    uistack(Mask.maskhandle,'top');
1410end
1411MaskName=fullfile_uvmat(Mask.Path,'',Mask.File,Mask.Ext,Mask.NomType,MaskIndex);
[387]1412UvData=get(handles.uvmat,'UserData');
[641]1413
1414%% update mask image if the mask is new
[387]1415if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
1416    UvData.MaskName=MaskName; %update the recorded name on UvData
1417    set(handles.uvmat,'UserData',UvData);
1418    if ~exist(MaskName,'file')
[641]1419        if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
1420            delete(Mask.maskhandle)   
[387]1421        end
1422    else
1423        %read mask image
[641]1424        [MaskField,tild,errormsg] = read_field(MaskName,'image');
[542]1425        if ~isempty(errormsg)
1426            return
1427        end
[641]1428        npxy=size(MaskField.A);
[387]1429        if length(npxy)>2
1430            errormsg=[MaskName ' is not a grey scale image'];
1431            return
[641]1432        elseif ~isa(MaskField.A,'uint8')
[387]1433            errormsg=[MaskName ' is not a 8 bit grey level image'];
1434            return
1435        end
[641]1436        MaskField.ZIndex=MaskIndex;
[387]1437        %px to phys or other transform on field
[591]1438         menu_transform=get(handles.TransformName,'String');
1439        choice_value=get(handles.TransformName,'Value');
[387]1440        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
[591]1441        transform=get(handles.TransformPath,'UserData');
[387]1442        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1443            if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1444                Calib=UvData.XmlData{1}.GeometryCalib;
[641]1445                MaskField=transform(MaskField,UvData.XmlData{1});
[387]1446            end
1447        end
[641]1448        flagmask=MaskField.A < 200;
[387]1449       
1450        %make brown color image
1451        imflag(:,:,1)=0.9*flagmask;
1452        imflag(:,:,2)=0.7*flagmask;
1453        imflag(:,:,3)=zeros(size(flagmask));
1454       
1455        %update mask image
1456        hmask=[]; %default
[641]1457        if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
1458            hmask=Mask.maskhandle;
[387]1459        end
1460        if ~isempty(hmask)
1461            set(hmask,'CData',imflag)   
1462            set(hmask,'AlphaData',flagmask*0.6)
[641]1463            set(hmask,'XData',MaskField.AX);
1464            set(hmask,'YData',MaskField.AY);
[387]1465%             uistack(hmask,'top')
1466        else
[511]1467            axes(handles.PlotAxes)
[387]1468            hold on   
[641]1469            Mask.maskhandle=image(MaskField.AX,MaskField.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
1470            set(handles.CheckMask,'UserData',Mask)
[387]1471        end
1472    end
1473end
1474
1475%------------------------------------------------------------------------
1476%------------------------------------------------------------------------
[713]1477% III - MAIN InputFileREFRESH FUNCTIONS : 'FRAME PLOT'
[387]1478%------------------------------------------------------------------------
1479
1480%------------------------------------------------------------------------
1481% --- Executes on button press in runplus: make one step forward and call
[713]1482% --- InputFileREFRESH. The step forward is along the fieldname series 1 or 2 depending on
[387]1483% --- the scan_i and scan_j check box (exclusive each other)
1484function runplus_Callback(hObject, eventdata, handles)
1485%------------------------------------------------------------------------
[635]1486
[387]1487set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow
1488drawnow
[635]1489increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
1490if isnan(increment)% case of free increment: move to next available field index
1491    increment='+';
1492end
[387]1493errormsg=runpm(hObject,eventdata,handles,increment);
1494if ~isempty(errormsg)
1495    msgbox_uvmat('ERROR',errormsg);
1496end
1497set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back to red
1498
1499%------------------------------------------------------------------------
1500% --- Executes on button press in runmin: make one step backward and call
[713]1501% --- InputFileREFRESH. The step backward is along the fieldname series 1 or 2 depending on
[387]1502% --- the scan_i and scan_j check box (exclusive each other)
1503function runmin_Callback(hObject, eventdata, handles)
1504%------------------------------------------------------------------------
[635]1505
[387]1506set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
1507drawnow
[635]1508increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
1509if isnan(increment)% case of free increment: move to previous available field index
1510    increment='-';
1511end
[387]1512errormsg=runpm(hObject,eventdata,handles,increment);
1513if ~isempty(errormsg)
1514    msgbox_uvmat('ERROR',errormsg);
1515end
1516set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back to red
1517
1518%------------------------------------------------------------------------
1519% -- Executes on button press in Movie: make a series of +> steps
1520function Movie_Callback(hObject, eventdata, handles)
1521%------------------------------------------------------------------------
[635]1522
[387]1523set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow
1524drawnow
[635]1525increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
1526if isnan(increment)% case of free increment: move to next available field index
1527    increment='+';
1528end
[387]1529set(handles.STOP,'Visible','on')
1530set(handles.speed,'Visible','on')
1531set(handles.speed_txt,'Visible','on')
1532set(handles.Movie,'BusyAction','queue')
1533UvData=get(handles.uvmat,'UserData');
1534
[435]1535while get(handles.Movie,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command
[387]1536        errormsg=runpm(hObject,eventdata,handles,increment);
1537        if ~isempty(errormsg)
1538            set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1539            return
1540        end
1541        pause(1.02-get(handles.speed,'Value'))% wait for next image
1542end
1543if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1544    UvData.aviobj=close(UvData.aviobj);
1545   set(handles.uvmat,'UserData',UvData);
1546end
1547set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1548
1549%------------------------------------------------------------------------
1550% -- Executes on button press in Movie: make a series of <- steps
1551function MovieBackward_Callback(hObject, eventdata, handles)
1552%------------------------------------------------------------------------
1553set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow
1554drawnow
[635]1555increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
1556if isnan(increment)% case of free increment: move to next available field index
1557    increment='-';
1558end
[387]1559set(handles.STOP,'Visible','on')
1560set(handles.speed,'Visible','on')
1561set(handles.speed_txt,'Visible','on')
1562set(handles.MovieBackward,'BusyAction','queue')
1563UvData=get(handles.uvmat,'UserData');
1564
[435]1565while get(handles.MovieBackward,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command
[387]1566        errormsg=runpm(hObject,eventdata,handles,increment);
1567        if ~isempty(errormsg)
1568            set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1569            return
1570        end
1571        pause(1.02-get(handles.speed,'Value'))% wait for next image
1572end
1573if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1574    UvData.aviobj=close(UvData.aviobj);
1575   set(handles.uvmat,'UserData',UvData);
1576end
1577set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1578
1579%------------------------------------------------------------------------
1580function STOP_Callback(hObject, eventdata, handles)
1581%------------------------------------------------------------------------
1582set(handles.movie_pair,'BusyAction','Cancel')
1583set(handles.movie_pair,'value',0)
1584set(handles.Movie,'BusyAction','Cancel')
1585set(handles.MovieBackward,'BusyAction','Cancel')
1586set(handles.MenuExportMovie,'BusyAction','Cancel')
[675]1587%set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
[387]1588set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1589set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1590
1591%------------------------------------------------------------------------
1592% --- function activated by runplus and run minus
1593function errormsg=runpm(hObject,eventdata,handles,increment)
1594%------------------------------------------------------------------------
1595errormsg='';%default
1596%% check for movie pair status
1597movie_status=get(handles.movie_pair,'Value');
1598if isequal(movie_status,1)
1599    STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
1600end
1601
1602%% read the current input file name(s) and field indices
1603InputFile=read_GUI(handles.InputFile);
1604InputFile.RootFile=regexprep(InputFile.RootFile,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
1605InputFile.SubDir=regexprep(InputFile.SubDir,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
1606FileExt=InputFile.FileExt;
[675]1607NomType=InputFile.NomType;
1608% i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
1609% i2=[];%default
1610% if strcmp(get(handles.i2,'Visible'),'on')
1611%     i2=str2num(get(handles.i2,'String'));
1612% end
1613% j1=[];
1614% if strcmp(get(handles.j1,'Visible'),'on')
1615%     j1=stra2num(get(handles.j1,'String'));
1616% end
1617% j2=j1;
1618% if strcmp(get(handles.j2,'Visible'),'on')
1619%     j2=stra2num(get(handles.j2,'String'));
1620% end
1621[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(InputFile.FileIndex);% check back the indices used
[683]1622if isempty(i1)
1623    i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
1624elseif isempty(j1) && strcmp(get(handles.j1,'Visible'),'on')
1625    j1=str2num(get(handles.j1,'String'));%case of indexed movie
1626end
[387]1627sub_value= get(handles.SubField,'Value');
[683]1628if sub_value % a second input file has been entered
1629    [InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileIndex_1,InputFile.FileExt_1,InputFile.NomType_1]=read_file_boxes_1(handles);
[515]1630    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(InputFile.FileIndex_1);% the indices for the second series taken from FileIndex_1
[683]1631    if isempty(i1_1)
1632        i1_1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
1633    elseif isempty(j1_1) && strcmp(get(handles.j1,'Visible'),'on')
1634        j1_1=str2num(get(handles.j1,'String'));%case of indexed movie
1635    end
[387]1636else
1637    filename_1=[];
[683]1638end
[387]1639
1640%% increment (or decrement) the field indices and update the input filename(s)
[635]1641if ~isnumeric(increment)% undefined increment value
[387]1642    set(handles.CheckFixPair,'Value',0)
1643end
1644CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&&isempty(j2));
[427]1645
1646% the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected)
[635]1647if CheckFixPair && isnumeric(increment)
[387]1648    if get(handles.scan_i,'Value')==1% case of scanning along index i
1649        i1=i1+increment;
1650        i2=i2+increment;
1651        if sub_value
1652            i1_1=i1_1+increment;
1653            i2_1=i2_1+increment;
[675]1654        end
[387]1655    else % case of scanning along index j (burst numbers)
1656        j1=j1+increment;
1657        j2=j2+increment;
1658        if sub_value
1659            j1_1=j1_1+increment;
1660            j2_1=j2_1+increment;
1661        end
1662    end
[427]1663   
[675]1664    % the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used
[387]1665else
1666    UvData=get(handles.uvmat,'UserData');
1667    ref_i=i1;
1668    if ~isempty(i2)
[427]1669        ref_i=floor((i1+i2)/2);% current reference index i
[387]1670    end
1671    ref_j=1;
1672    if ~isempty(j1)
1673        ref_j=j1;
1674        if ~isempty(j2)
[427]1675            ref_j=floor((j1+j2)/2);% current reference index j
[387]1676        end
1677    end
[635]1678    if isnumeric(increment)
[387]1679        if get(handles.scan_i,'Value')==1% case of scanning along index i
[427]1680            ref_i=ref_i+increment;% increment the current reference index i
[387]1681        else % case of scanning along index j (burst numbers)
[427]1682            ref_j=ref_j+increment;% increment the current reference index j if scan_j option is used
[387]1683        end
[388]1684    else % free increment
[511]1685        runaction=get(gcbo,'tag');
[635]1686        if strcmp(increment,'+')% if runplus or movie is activated
[387]1687            step=1;
1688        else
1689            step=-1;
1690        end
1691        if get(handles.scan_i,'Value')==1% case of scanning along index i
1692            ref_i=ref_i+step;
[512]1693            while ref_i>=0  && size(UvData.i1_series{1},3)>=ref_i+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
[387]1694                ref_i=ref_i+step;
1695            end
1696        else % case of scanning along index j (burst numbers)
1697            ref_j=ref_j+step;
[512]1698            while ref_j>=0  && size(UvData.i1_series{1},2)>=ref_j+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0
[387]1699                ref_j=ref_j+step;
1700            end
1701        end
1702    end
1703    if ref_i<0
1704        errormsg='minimum i index reached';
1705    elseif ref_j<0
1706        errormsg='minimum j index reached';
[512]1707    elseif ref_i+1>size(UvData.i1_series{1},3)
[511]1708        errormsg='maximum i index reached (reload the input file to update the index bound)';
[387]1709    elseif ref_j+1>size(UvData.i1_series{1},2)
[511]1710        errormsg='maximum j index reached (reload the input file to update the index bound)';
[387]1711    end
[511]1712    if ~isempty(errormsg),return,end
[512]1713    siz=size(UvData.i1_series{1});
[515]1714    ref_indices=ref_i*siz(1)*siz(2)+ref_j*siz(1)+1:ref_i*siz(1)*siz(2)+(ref_j+1)*siz(1);
[512]1715    i1_subseries=UvData.i1_series{1}(ref_indices);
1716    ref_indices=ref_indices(i1_subseries>0);
1717    if isempty(ref_indices)% case of pairs (free index i)
[515]1718        ref_indices=ref_i*siz(1)*siz(2)+1:(ref_i+1)*siz(1)*siz(2);
[512]1719        i1_subseries=UvData.i1_series{1}(ref_indices);
1720        ref_indices=ref_indices(i1_subseries>0);
[511]1721    end
[512]1722    if isempty(ref_indices),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return
[387]1723    end
[512]1724    i1=UvData.i1_series{1}(ref_indices(end));
[387]1725    if ~isempty(UvData.i2_series{1})
[512]1726        i2=UvData.i2_series{1}(ref_indices(end));
[387]1727    end
1728    if ~isempty(UvData.j1_series{1})
[512]1729        j1=UvData.j1_series{1}(ref_indices(end));
[387]1730    end
1731    if ~isempty(UvData.j2_series{1})
[512]1732        j2=UvData.j2_series{1}(ref_indices(end));
[515]1733    end
1734   
[675]1735    % case of a second file series
[515]1736    if sub_value
1737        ref_i_1=i1_1;
1738        if ~isempty(i2_1)
1739            ref_i_1=floor((i1_1+i2_1)/2);% current reference index i
1740        end
1741        ref_j_1=1;
1742        if ~isempty(j1_1)
1743            ref_j_1=j1_1;
1744            if ~isempty(j2_1)
1745                ref_j_1=floor((j1_1+j2_1)/2);% current reference index j
1746            end
1747        end
[635]1748        if isnumeric(increment)
[515]1749            if get(handles.scan_i,'Value')==1% case of scanning along index i
1750                ref_i_1=ref_i_1+increment;% increment the current reference index i
1751            else % case of scanning along index j (burst numbers)
1752                ref_j_1=ref_j_1+increment;% increment the current reference index j if scan_j option is used
1753            end
1754        else % free increment, synchronise the ref indices with the first series
1755            ref_i_1=ref_i;
[675]1756            ref_j_1=ref_j;
[515]1757        end
1758        if numel(UvData.i1_series)==1
1759            UvData.i1_series{2}=UvData.i1_series{1};
1760            UvData.j1_series{2}=UvData.j1_series{1};
1761            UvData.i2_series{2}=UvData.i2_series{1};
1762            UvData.j2_series{2}=UvData.j2_series{1};
1763        end
1764        if ref_i_1<0
1765            errormsg='minimum i index reached';
1766        elseif ref_j_1<0
1767            errormsg='minimum j index reached';
1768        elseif ref_i_1+1>size(UvData.i1_series{2},3)
1769            errormsg='maximum i index reached for the second series (reload the input file to update the index bound)';
1770        elseif ref_j_1+1>size(UvData.i1_series{2},2)
1771            errormsg='maximum j index reached for the second series(reload the input file to update the index bound)';
1772        end
1773        if ~isempty(errormsg),return,end
1774        siz=size(UvData.i1_series{2});
1775        ref_indices=ref_i_1*siz(1)*siz(2)+ref_j_1*siz(1)+1:ref_i_1*siz(1)*siz(2)+(ref_j_1+1)*siz(1);
1776        i1_subseries=UvData.i1_series{2}(ref_indices);
1777        ref_indices=ref_indices(i1_subseries>0);
1778        if isempty(ref_indices)% case of pairs (free index i)
1779            ref_indices=ref_i_1*siz(1)*siz(2)+1:(ref_i_1+1)*siz(1)*siz(2);
1780            i1_subseries=UvData.i1_series{2}(ref_indices);
1781            ref_indices=ref_indices(i1_subseries>0);
1782        end
1783        i1_1=UvData.i1_series{2}(ref_indices(end));
[427]1784        if ~isempty(UvData.i2_series{2})
[515]1785            i2_1=UvData.i2_series{2}(ref_indices(end));
[427]1786        end
1787        if ~isempty(UvData.j1_series{2})
[515]1788            j1_1=UvData.j1_series{2}(ref_indices(end));
[427]1789        end
1790        if ~isempty(UvData.j2_series{2})
[515]1791            j2_1=UvData.j2_series{1}(ref_indices(end));
[675]1792        end
[515]1793    else% the second series (if needed) is the same file as the first
1794        i1_1=i1;
1795        i2_1=i2;
1796        j1_1=j1;
1797        j2_1=j2;
[387]1798    end
1799end
1800filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2);
[675]1801
[713]1802%% inputfilerefresh plots
[387]1803if sub_value
[428]1804    filename_1=fullfile_uvmat(InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileExt_1,InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
[675]1805    errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2,i1_1,i2_1,j1_1,j2_1);
1806else
1807    errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2);
[387]1808end
[713]1809set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])
[387]1810
1811%% update the index counters if the index move is successfull
1812if isempty(errormsg)
1813    set(handles.i1,'String',num2stra(i1,NomType,1));
1814    if isequal(i2,i1)
1815        set(handles.i2,'String','');
1816    else
1817        set(handles.i2,'String',num2stra(i2,NomType,1));
1818    end
1819    set(handles.j1,'String',num2stra(j1,NomType,2));
1820    if isequal(j2,j1)
1821        set(handles.j2,'String','');
1822    else
1823        set(handles.j2,'String',num2stra(j2,NomType,2));
1824    end
1825    indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
1826    set(handles.FileIndex,'String',indices);
1827    if ~isempty(filename_1)
[428]1828        indices_1=fullfile_uvmat('','','','',InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
[387]1829        set(handles.FileIndex_1,'String',indices_1);
1830    end
1831    if isequal(movie_status,1)
1832        set(handles.movie_pair,'Value',1)
1833        movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
[675]1834    else
1835        if isempty(i2), set(handles.i2,'String',''); end % suppress the second index display if not used
1836        if isempty(j2), set(handles.j2,'String',''); end
[387]1837    end
[675]1838    set(handles.i1,'BackgroundColor',[1 1 1])
1839    set(handles.i2,'BackgroundColor',[1 1 1])
1840    set(handles.j1,'BackgroundColor',[1 1 1])
1841    set(handles.j2,'BackgroundColor',[1 1 1])
1842    set(handles.FileIndex,'BackgroundColor',[1 1 1])
1843    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
[387]1844end
1845
1846%------------------------------------------------------------------------
1847% --- Executes on button press in movie_pair: create an alternating movie with two view
1848function movie_pair_Callback(hObject, eventdata, handles)
1849%------------------------------------------------------------------------
[622]1850
[387]1851%% stop movie action if the movie_pair button is off
1852if ~get(handles.movie_pair,'value')
1853    set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
1854    set(handles.i2,'String','')
1855    set(handles.j2,'String','')
[675]1856    set(handles.Dt_txt,'String','')
[387]1857    return
1858else
1859    set(handles.movie_pair,'BusyAction','queue')
[713]1860    set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])
[387]1861end
1862
1863%% initialisation
1864set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
1865drawnow
[526]1866list_fields=get(handles.FieldName,'String');% list menu fields
1867index_fields=get(handles.FieldName,'Value');% selected string index
[387]1868FieldName=list_fields{index_fields}; % selected field
1869UvData=get(handles.uvmat,'UserData');
1870if isequal(FieldName,'image')
[512]1871    index=1;
[387]1872    [RootPath,SubDir,RootFile,FileIndices,Ext]=read_file_boxes(handles);
1873    NomType=get(handles.NomType,'String');
1874else
[526]1875    list_fields=get(handles.FieldName_1,'String');% list menu fields
1876    index_fields=get(handles.FieldName_1,'Value');% selected string index
[387]1877    FieldName=list_fields{index_fields}; % selected field
1878    if isequal(FieldName,'image')
[512]1879        index=2;
[709]1880        [RootPath,SubDir,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles);% get info from the second input line
[387]1881    else
1882        msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
1883        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1884        set(handles.movie_pair,'Value',0)
1885        return
1886    end
1887end
1888num_i1=str2num(get(handles.i1,'String'));
1889num_j1=stra2num(get(handles.j1,'String'));
1890num_i2=str2num(get(handles.i2,'String'));
1891num_j2=stra2num(get(handles.j2,'String'));
[582]1892imaname_1='';
[387]1893if isempty(num_j2)
[582]1894    if isempty(num_i2)
1895        if strcmp(get(handles.j2,'Visible'),'on') %if the j box is visible
1896            imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,Ext,NomType,num_i1,[],num_j1+1);
1897        end
1898        if exist(imaname_1,'file')
[598]1899            num_j2=num_j1+1;% look by default for the next j index as the second file
1900            set(handles.j2,'String',num2stra(num_j2,NomType));
[582]1901        else
1902            imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,Ext,NomType,num_i1+1,[],num_j1);
1903            if exist(imaname_1,'file')
1904                num_i2=num_i1+1;
1905                set(handles.i2,'String',num2str(num_i2));
1906            else
1907                msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
1908                set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1909                set(handles.movie_pair,'Value',0)
1910                return
1911            end
1912        end
[387]1913    else
1914        num_j2=num_j1;%repeat the index i1 by default
1915    end
1916end
1917if isempty(num_i2)
1918    num_i2=num_i1;%repeat the index i1 by default
1919end
[709]1920if isempty(num_j1)
1921    num_j1=1;
1922end
1923if isempty(num_j2)
1924    num_j2=num_j1;%repeat the index i1 by default
1925end
[439]1926imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,Ext,NomType,num_i2,[],num_j2);
[512]1927if strcmp(NomType,'*')
1928    num_frame=num_i2;
1929else
1930    num_frame=num_j2;
1931end
[387]1932if ~exist(imaname_1,'file')
1933      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
1934      set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1935       set(handles.movie_pair,'Value',0)
1936      return
1937end
1938
[675]1939%% display time interval for the image pair
[684]1940if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'Time')...
1941        && size(UvData.XmlData{1}.Time,1)>=num_i2+1 && size(UvData.XmlData{1}.Time,2)>=num_j2+1
[675]1942    dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
1943    if  isfield(UvData,'TimeUnit')
1944        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
1945    else
1946        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
1947    end
1948else
1949    set(handles.Dt_txt,'String','')
1950end
1951
[512]1952%% get the first image
1953%Field.AName='image';
1954if index==1
1955    Field_a=UvData.Field;% movie on the second field
[387]1956else
[512]1957    Field_a=UvData.Field_1;% movie on the first field
[387]1958end
1959
[512]1960%% read the second image
1961MovieObject=[];
1962if numel(UvData.MovieObject)>=index
1963    MovieObject=UvData.MovieObject{index};
[387]1964end
[549]1965[Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{index},MovieObject,num_frame);
[387]1966
1967%px to phys or other transform on field
[591]1968transform=get(handles.TransformPath,'UserData');
[512]1969if  ~isempty(transform)
1970    if isfield(UvData,'XmlData') && numel(UvData.XmlData)>=index %use geometry calib recorded from the ImaDoc xml file as first priority
1971        if index==2
1972        Field_a=transform(Field_a,UvData.XmlData{index});%the first field has been stored without transform
1973        end
[701]1974        if nargin(transform)>=2
[512]1975        Field_b=transform(Field_b,UvData.XmlData{index});
[701]1976        else
1977          Field_b=transform(Field_b);
1978        end
[387]1979    end
1980end
1981
[675]1982% make movie until movie speed is set to 0 or STOP is activated
[511]1983hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER)
[387]1984set(handles.STOP,'Visible','on')
1985set(handles.speed,'Visible','on')
1986set(handles.speed_txt,'Visible','on')
[675]1987set(handles.i2,'BackgroundColor',[1 1 1])% mark the edit box in white to indicate its use as input
1988set(handles.j2,'BackgroundColor',[1 1 1])% mark the edit box in white to indicate its use as input
1989set(handles.FileIndex,'BackgroundColor',[1 1 1])% mark the edit box in white to indicate its use as input
[710]1990while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue') % enable STOP command
[387]1991    % read and plot the series of images in non erase mode
1992    set(hima,'CData',Field_b.A);
1993    pause(1.02-get(handles.speed,'Value'));% wait for next image
1994    set(hima,'CData',Field_a.A);
1995    pause(1.02-get(handles.speed,'Value'));% wait for next image
1996end
1997set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
[675]1998set(handles.movie_pair,'Value',0)
1999set(handles.Dt_txt,'String','')
[387]2000
2001%------------------------------------------------------------------------
[713]2002% --- Executes on button press in InputFileREFRESH.
2003function REFRESH_Callback(hObject, eventdata, handles)
[387]2004%------------------------------------------------------------------------
[713]2005set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the command button in yellow
[387]2006drawnow
[515]2007[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
[675]2008[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(FileIndex);% check back the indices used
2009if isempty(i2), set(handles.i2,'String',''); end % suppress the second index display if not used
2010if isempty(j2), set(handles.j2,'String',''); end
[515]2011filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
2012filename_1='';%default
2013FileIndex_1='';
[387]2014if get(handles.SubField,'Value')
[515]2015    [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
2016    filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
[387]2017end
2018num_i1=stra2num(get(handles.i1,'String'));
2019num_i2=stra2num(get(handles.i2,'String'));
2020num_j1=stra2num(get(handles.j1,'String'));
2021num_j2=stra2num(get(handles.j2,'String'));
[609]2022[tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
2023if isempty(j1_1)% case of movies, the index is not given by file index
2024    j1_1=num_j1;
2025end
[387]2026
[515]2027errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
[387]2028
2029if ~isempty(errormsg)
2030      msgbox_uvmat('ERROR',errormsg);
[714]2031      set(handles.InputFileREFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
[387]2032else
2033    set(handles.i1,'BackgroundColor',[1 1 1])
2034    set(handles.i2,'BackgroundColor',[1 1 1])
2035    set(handles.j1,'BackgroundColor',[1 1 1])
2036    set(handles.j2,'BackgroundColor',[1 1 1])
2037    set(handles.FileIndex,'BackgroundColor',[1 1 1])
[681]2038    set(handles.FileIndex_1,'BackgroundColor',[1 1 1]) 
[714]2039    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
[387]2040end   
2041
2042%------------------------------------------------------------------------
[713]2043% --- read the input files and inputfilerefresh all the plots, including projection.
[387]2044% OUTPUT:
2045%  errormsg: error message char string  =[] by default
2046% INPUT:
[675]2047% FileName: first input file (=[] in the absence of input file)
2048% FileName_1: second input file (=[] in the asbsence of second input file)
[387]2049% num_i1,num_i2,num_j1,num_j2; frame indices
[675]2050% i1_1,i2_1,j1_1,j2_1: frame indices for the second input file  (needed if FileName_1 is not empty)
2051%------------------------------------------------------------------------
[515]2052function errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1)
[387]2053%------------------------------------------------------------------------
2054
2055%% initialisation
[714]2056pointer=get(handles.uvmat,'Pointer');
2057set(handles.uvmat,'Pointer','watch')
2058drawnow
[387]2059if ~exist('Field','var')
2060    Field={};
2061end
2062UvData=get(handles.uvmat,'UserData');
2063if ishandle(handles.UVMAT_title) %remove title panel on uvmat
2064    delete(handles.UVMAT_title)
2065end
2066
2067%% determine the main input file information for action
[450]2068if ~exist(FileName,'file')
2069    errormsg=['input file ' FileName ' does not exist'];
[387]2070    return
2071end
2072NomType=get(handles.NomType,'String');
[494]2073NomType_1='';
2074if strcmp(get(handles.NomType_1,'Visible'),'on')
2075    NomType_1=get(handles.NomType_1,'String');
2076end
[387]2077%update the z position index
[589]2078mode_slice=get(handles.slices,'String');
2079if strcmp(mode_slice,'volume')
[387]2080    z_index=num_j1;
2081    set(handles.z_index,'String',num2str(z_index))
2082else
[589]2083    nbslice=str2num(get(handles.num_NbSlice,'String'));
[387]2084    z_index=mod(num_i1-1,nbslice)+1;
2085    set(handles.z_index,'String',num2str(z_index))
2086end
[713]2087% inputfilerefresh menu for save_mask if relevant
[387]2088masknumber=get(handles.masklevel,'String');
2089if length(masknumber)>=z_index
2090    set(handles.masklevel,'Value',z_index)
2091end
2092
[515]2093%% test for need of tps
2094check_proj_tps=0;
2095if  (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx'))
[622]2096    for iobj=1:numel(UvData.ProjObject)
2097        if isfield(UvData.ProjObject{iobj},'ProjMode')&& strcmp(UvData.ProjObject{iobj}.ProjMode,'interp_tps')
[515]2098            check_proj_tps=1;
2099            break
2100        end
2101    end
2102end
2103
[507]2104%% read the first input field
[421]2105ParamIn.ColorVar='';%default variable name for vector color
[445]2106frame_index=1;%default
[507]2107FieldName='';%default
2108VelType='';%default
2109switch UvData.FileType{1}
2110    case {'civx','civdata','netcdf'};
[526]2111        list_fields=get(handles.FieldName,'String');% list menu fields
2112        FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field
[507]2113        if ~strcmp(FieldName,'get_field...')
2114            if get(handles.FixVelType,'Value')
2115                VelTypeList=get(handles.VelType,'String');
2116                VelType=VelTypeList{get(handles.VelType,'Value')};
[387]2117            end
[507]2118        end
[576]2119        % case of input vector field, get the scalar used for vector color
[517]2120        if ~isempty(regexp(FieldName,'^vec('))
[507]2121            list_code=get(handles.ColorCode,'String');% list menu fields
2122            index_code=get(handles.ColorCode,'Value');% selected string index
2123            if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
2124                list_code=get(handles.ColorScalar,'String');% list menu fields
2125                index_code=get(handles.ColorScalar,'Value');% selected string index
2126                ParamIn.ColorVar= list_code{index_code}; % selected field
[387]2127            end
[507]2128        end
2129    case {'video','mmreader'}
2130        ParamIn=UvData.MovieObject{1};     
[683]2131        if strcmp(NomType,'*')
2132            frame_index=num_i1;%frame index from a single movies or multimage
[507]2133        else
[683]2134            frame_index=num_j1;% frame index from a set of indexed movies
[507]2135        end
2136    case 'multimage'
2137        if ~strcmp(NomType,'*')
2138            frame_index=num_j1;%frame index for movies or multimage
2139        else
2140            frame_index=num_i1;
2141        end
2142    case 'vol' %TODO: update
2143        if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
2144            ParamIn.Npy=UvData.XmlData.Npy;
2145            ParamIn.Npx=UvData.XmlData.Npx;
2146        else           
2147            errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2148            return
2149        end
[387]2150end
[507]2151if isstruct (ParamIn)
[517]2152    ParamIn.FieldName=FieldName;
2153    ParamIn.VelType=VelType;
[648]2154    ParamIn.Coord_x=get(handles.Coord_x,'String');
[646]2155    ParamIn.Coord_y=get(handles.Coord_y,'Data');
[507]2156end
[517]2157check_tps = 0;         
[515]2158if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...')
2159       check_tps=1;%tps needed to get the requested field
2160end
[507]2161[Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
2162if ~isempty(errormsg)
[527]2163    errormsg=['uvmat / refresh_field / read_field( ' FileName ') / ' errormsg];
[507]2164    return
2165end 
2166if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
2167    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2168    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
2169end
2170Field{1}.ZIndex=z_index; %used for multiplane 3D calibration
[387]2171
[450]2172%% choose and read a second field FileName_1 if defined
[387]2173VelType_1=[];%default
2174FieldName_1=[];
[496]2175ParamIn_1=[];
[387]2176ParamOut_1=[];
[445]2177frame_index_1=1;
[450]2178if ~isempty(FileName_1)
2179    if ~exist(FileName_1,'file')
2180        errormsg=['second file ' FileName_1 ' does not exist'];
[387]2181        return
2182    end
[404]2183    switch UvData.FileType{2}
[387]2184        case {'civx','civdata','netcdf'};
[526]2185            list_fields=get(handles.FieldName_1,'String');% list menu fields
[520]2186            if ischar(list_fields),list_fields={list_fields};end
[526]2187            FieldName_1= list_fields{get(handles.FieldName_1,'Value')}; % selected field
[387]2188            if ~strcmp(FieldName,'get_field...')
[389]2189                if get(handles.FixVelType,'Value')
2190                    VelTypeList=get(handles.VelType_1,'String');
2191                    VelType_1=VelTypeList{get(handles.VelType_1,'Value')};% read the velocity type.
[387]2192                end
2193            end
[405]2194            if strcmp(FieldName_1,'velocity')&& strcmp(get(handles.ColorCode,'Visible'),'on')
2195                list_code=get(handles.ColorCode,'String');% list menu fields
2196                index_code=get(handles.ColorCode,'Value');% selected string index
[387]2197                if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
[405]2198                    list_code=get(handles.ColorScalar,'String');% list menu fields
2199                    index_code=get(handles.ColorScalar,'Value');% selected string index
2200                    ParamIn_1.ColorVar= list_code{index_code}; % selected field for vector color display                 
[387]2201                end
2202            end
[435]2203        case {'video','mmreader'}
[450]2204            ParamIn_1=UvData.MovieObject{2};
[445]2205                        if ~strcmp(NomType_1,'*')
[515]2206                frame_index_1=j1_1;%frame index for movies or multimage
[445]2207            else
[515]2208                frame_index_1=i1_1;
[445]2209            end 
2210         case 'multimage'
[609]2211            if strcmp(NomType_1,'*')%frame index for movies or multimage
2212                frame_index_1=i1_1;
[445]2213            else
[609]2214                frame_index_1=j1_1;
[445]2215            end   
[387]2216        case 'vol' %TODO: update
2217            if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
[405]2218                ParamIn_1.Npy=UvData.XmlData.Npy;
2219                ParamIn_1.Npx=UvData.XmlData.Npx;
[387]2220            else
2221                errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2222                return
2223            end
2224    end
[428]2225    if isequal(get(handles.NomType_1,'Visible'),'on')
[387]2226    NomType_1=get(handles.NomType_1,'String');
[428]2227    else
2228        NomType_1=get(handles.NomType,'String');
2229    end
[387]2230    test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
[515]2231    if ~isequal(NomType_1,'*')&& isfield(UvData,'FileName_1')
[580]2232           test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ;
[387]2233    end
2234    if test_keepdata_1
[389]2235        Field{2}=UvData.Field_1;% keep the stored field
[427]2236        ParamOut_1=UvData.ParamOut_1;
[387]2237    else
[496]2238        if isempty(ParamIn_1) || isstruct(ParamIn_1)
[405]2239        ParamIn_1.FieldName=FieldName_1;
2240        ParamIn_1.VelType=VelType_1;
[713]2241        ParamIn_1.Coord_x=get(handles.Coord_x,'String');
2242        ParamIn_1.Coord_y=get(handles.Coord_y,'Data');
[515]2243        end 
[580]2244        [Field{2},ParamOut_1,errormsg] = read_field(FileName_1,UvData.FileType{2},ParamIn_1,frame_index_1);
[387]2245        if ~isempty(errormsg)
[450]2246            errormsg=['error in reading ' FieldName_1 ' in ' FileName_1 ': ' errormsg];
[387]2247            return
2248        end
[515]2249        if isstruct(ParamOut_1)&&~strcmp(ParamOut_1.FieldName,'get_field...')&& (strcmp(UvData.FileType{2},'civdata')||strcmp(UvData.FileType{2},'civx'))...
2250                &&~strcmp(ParamOut_1.FieldName,'velocity') && ~strcmp(ParamOut_1.FieldName,'get_field...')
2251            if ~check_proj_tps
2252            end
2253        end
[387]2254    end
[507]2255    Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration
[387]2256end
2257
2258%% update uvmat interface
2259if isfield(ParamOut,'Npx')
2260    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2261    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
2262elseif isfield(ParamOut_1,'Npx')
2263    set(handles.num_Npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface
2264    set(handles.num_Npy,'String',num2str(ParamOut_1.Npy));
2265end
2266
2267%% update the display menu for the first velocity type (first menuline)
2268test_veltype=0;
[404]2269if (strcmp(UvData.FileType{1},'civx')||strcmp(UvData.FileType{1},'civdata'))&& ~strcmp(FieldName,'get_field...')
[387]2270    test_veltype=1;
2271    set(handles.VelType,'Visible','on')
2272    set(handles.VelType_1,'Visible','on')
2273    set(handles.FixVelType,'Visible','on')
[404]2274    menu=set_veltype_display(ParamOut.CivStage,UvData.FileType{1});
[387]2275    index_menu=strcmp(ParamOut.VelType,menu);%look for VelType in  the menu
2276    index_val=find(index_menu,1);
2277    if isempty(index_val)
2278        index_val=1;
2279    end
2280    set(handles.VelType,'Value',index_val)
2281    if ~get(handles.SubField,'value')
2282        set(handles.VelType,'String',menu)
2283        set(handles.VelType_1,'Value',1)
2284        set(handles.VelType_1,'String',[{''};menu])
2285    end
2286else
2287    set(handles.VelType,'Visible','off')
2288end
2289
2290%% update the display menu for the second velocity type (second menuline)
2291test_veltype_1=0;
[450]2292if isempty(FileName_1)
[580]2293    %     set(handles.FieldName_1,'Value',1); %update the field menu
2294    %     if isstruct(ParamOut)
2295    %     set(handles.FieldName_1,'String',[{''};ParamOut.FieldList]); %update the field menu
2296    %     end
[405]2297elseif ~test_keepdata_1
[713]2298    if (strcmp(UvData.FileType{2},'civx')||strcmp(UvData.FileType{2},'civdata'))&& ~strcmp(FieldName_1,'get_field...')
2299%     if (~strcmp(UvData.FileType{2},'netcdf')&&~strcmp(UvData.FileType{2},'civdata')&&~strcmp(UvData.FileType{2},'civx'))|| isequal(FieldName_1,'get_field...')
[387]2300        test_veltype_1=1;
2301        set(handles.VelType_1,'Visible','on')
[515]2302        menu=set_veltype_display(ParamOut_1.CivStage,UvData.FileType{2});
[494]2303        index_menu=strcmp(ParamOut_1.VelType,menu);
2304        set(handles.VelType_1,'Value',1+find(index_menu,1))
2305        set(handles.VelType_1,'String',[{''};menu])
[713]2306    else
2307         set(handles.VelType_1,'Visible','off')
[387]2308    end
[405]2309    % update the second field menu: the same quantity
[494]2310    if isstruct(ParamOut_1)
[580]2311        % display the FieldName menu from the input file and pick the selected one:
2312        FieldList=get(handles.FieldName_1,'String');
2313        field_index=strcmp(ParamOut_1.FieldName,FieldList);
2314        if ~isempty(field_index)
2315            set(handles.FieldName_1,'Value',find(field_index,1))
2316        end
[494]2317    end
[387]2318end
2319if test_veltype||test_veltype_1
[580]2320    set(handles.FixVelType,'Visible','on')
[387]2321else
[580]2322    set(handles.FixVelType,'Visible','off')
[387]2323end
2324   
2325%% introduce w as background image by default for a new series (only for nbdim=2)
2326if ~isfield(UvData,'NewSeries')
2327    UvData.NewSeries=1;
2328end
2329%put W as background image by default if NbDim=2:
2330if  UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3);
2331        set(handles.SubField,'Value',1);
2332        set(handles.RootPath_1,'String','"')
2333        set(handles.RootFile_1,'String','"')
2334        set(handles.SubDir_1,'String','"');
2335         indices=fullfile_uvmat('','','','',NomType,num_i1,num_i2,num_j1,num_j2);
2336        set(handles.FileIndex_1,'String',indices)
2337        set(handles.FileExt_1,'String','"');
[526]2338        set(handles.FieldName_1,'Visible','on');
2339        set(handles.FieldName_1,'Visible','on');
[387]2340        set(handles.RootPath_1,'Visible','on')
2341        set(handles.RootFile_1,'Visible','on')
2342        set(handles.SubDir_1,'Visible','on');
2343        set(handles.FileIndex_1,'Visible','on');
2344        set(handles.FileExt_1,'Visible','on');
[526]2345        set(handles.FieldName_1,'Visible','on');
[387]2346        Field{1}.AName='w';
2347end           
2348
[674]2349%% display time value of the current file
[615]2350abstime=[];%default inputs
2351dt=[];
[415]2352TimeUnit='';
[674]2353if isfield(UvData,'TimeUnit')
2354TimeUnit=UvData.TimeUnit;%retrieve info from update_rootinfo
2355end
[615]2356% time from xml file or video movie
[674]2357TimeName=get(handles.TimeName,'String');% indicate that time is from xml
2358if strcmp(TimeName,'xml')||strcmp(TimeName,'video')
[415]2359    if isempty(num_i2)||isnan(num_i2)
2360        num_i2=num_i1;
2361    end
2362    if isempty(num_j1)||isnan(num_j1)
2363        num_j1=1;
2364    end
2365    if isempty(num_j2)||isnan(num_j2)
2366        num_j2=num_j1;
2367    end
2368    siz=size(UvData.XmlData{1}.Time);
[615]2369    if ~isempty(num_i1)&& ~isempty(num_i2) && num_i1>=0 &&siz(1)>=max(num_i1+1,num_i2+1) && siz(2)>=max(num_j1+1,num_j2+1)
[611]2370        abstime=(UvData.XmlData{1}.Time(num_i1+1,num_j1+1)+UvData.XmlData{1}.Time(num_i2+1,num_j2+1))/2;%overset the time read from files
2371        dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
[415]2372        Field{1}.Dt=dt;
2373        if isfield(UvData.XmlData{1},'TimeUnit')
2374            TimeUnit=UvData.XmlData{1}.TimeUnit;
2375        end
2376    end
2377end
[615]2378
[674]2379% get time in the input file, not defined in a xml file or movie
[615]2380if isempty(abstime)
[675]2381    if strcmp(TimeName,'civdata')||strcmp(TimeName,'civx')
2382        abstime=Field{1}.Time;
[693]2383    elseif ~isempty(regexp(TimeName,'^att:'))||~isempty(regexp(TimeName,'^var:'))
[648]2384        abstime=Field{1}.(TimeName(5:end));%the time is an attribute or variale selected by get_file
[693]2385    elseif ~isempty(regexp(TimeName,'^dim:'))
2386        abstime=str2num(get(handles.i1,'String'));
[615]2387    end
[648]2388    if isfield(Field{1},'Dt')
2389        dt=Field{1}.Dt;%dt read from the netcdf input file
2390        if isfield(Field{1},'TimeUnit')
2391            TimeUnit=Field{1}.TimeUnit;
2392        end
2393    elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first
2394        dt=Field{2}.Dt;%dt read from the netcdf input file
2395        if isfield(Field{2},'TimeUnit')
2396            TimeUnit=Field{2}.TimeUnit;
2397        end
[615]2398    end
[667]2399end
[654]2400set(handles.TimeValue,'String',num2str(abstime))
[674]2401
2402%% display time value of the second current file if relevant
[648]2403abstime_1=[];
[674]2404if ~isempty(FileName_1)
2405    TimeName_1=get(handles.TimeName_1,'String');% indicate whether time is from xml or video
2406    % time from xml file or video movie as a second file series
2407    if strcmp(TimeName_1,'xml')||strcmp(TimeName_1,'video')
2408        if numel(UvData.XmlData)==2
2409            if isempty(i2_1)
2410                i2_1=num_i1;
2411            end
2412            if isempty(j1_1)
2413                j1_1=1;
2414            end
2415            if isempty(j2_1)
2416                j2_1=j1_1;
2417            end
2418            siz=size(UvData.XmlData{2}.Time);
2419            if ~isempty(i1_1) && siz(1)>=max(i1_1+1,i2_1+1) && siz(2)>=max(j1_1+1,j2_1+1)
2420                abstime_1=(UvData.XmlData{2}.Time(i1_1+1,j1_1+1)+UvData.XmlData{2}.Time(i2_1+1,j2_1+1))/2;%overset the time read from files
2421                Field{2}.Dt=(UvData.XmlData{2}.Time(i2_1+1,j2_1+1)-UvData.XmlData{2}.Time(i1_1+1,j1_1+1));
2422            end
2423        end
2424    end
2425   
2426    % get time in the input file of the second series, not defined in a xml file or movie
[675]2427    if isempty(abstime_1) && numel(Field)==2
2428         if strcmp(TimeName_1,'civdata')||strcmp(TimeName_1,'civx')
2429        abstime_1=Field{2}.Time;
2430         elseif  ~isempty(regexp(TimeName_1,'^att:')) ||~isempty(regexp(TimeName_1,'^dim:'))||~isempty(regexp(TimeName_1,'^var:'))
[648]2431        abstime_1=Field{2}.(TimeName_1(5:end));%the time is an attribute or variale selected by get_file
[675]2432         end
[674]2433    end
2434    set(handles.TimeValue_1,'String',num2str(abstime_1,5))
[648]2435end
[674]2436
[415]2437if isempty(dt)||isequal(dt,0)
2438    set(handles.Dt_txt,'String','')
2439else
2440    if  isempty(TimeUnit)
2441        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2442    else
2443        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' TimeUnit] )
2444    end
2445end
2446
[674]2447%% Time title with unit
2448if isempty(abstime)&&isempty(abstime_1)
2449    Time_title='';
2450else
2451    Time_title='Time';
2452    if ~isempty(TimeUnit)
2453        Time_title=['Time (' TimeUnit ')'];
2454    end
2455end
2456set(handles.Time_title,'String',Time_title)
2457
[526]2458%% store the current open names, fieldname and vel types in uvmat interface
[450]2459UvData.FileName_1=FileName_1;
[512]2460UvData.ParamOut_1=ParamOut_1;
2461if numel(Field)==2
[713]2462    UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
[512]2463end
[387]2464
2465%% apply coordinate transform or other user fct
[591]2466transform=get(handles.TransformPath,'UserData');
[515]2467if isempty(transform)
2468    UvData.Field=Field{1};
2469else
[507]2470    XmlData=[];%default
2471    XmlData_1=[];%default
2472    if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2473        XmlData=UvData.XmlData{1};
2474        if numel(UvData.XmlData)==2
2475            XmlData_1=UvData.XmlData{2};
2476        end
[387]2477    end
[512]2478    switch nargin(transform)
2479        case 4
2480            if length(Field)==2
2481                UvData.Field=transform(Field{1},XmlData,Field{2},XmlData_1);
2482            else
2483                UvData.Field=transform(Field{1},XmlData);
2484            end
2485        case 3
2486            if length(Field)==2
2487                UvData.Field=transform(Field{1},XmlData,Field{2});
2488            else
2489                UvData.Field=transform(Field{1},XmlData);
2490            end
2491        case 2
2492            UvData.Field=transform(Field{1},XmlData);
2493        case 1
2494            UvData.Field=transform(Field{1});
[387]2495    end
[507]2496end
[508]2497
[515]2498%% calculate tps coefficients if needed
[581]2499UvData.Field=tps_coeff_field(UvData.Field,check_proj_tps);
[387]2500
[667]2501%% get bounds and dimensions of the input field
2502UvData.Field=find_field_bounds(UvData.Field);
2503
[654]2504if UvData.Field.NbDim>1
[491]2505    % default projection plane
[622]2506    if isempty(UvData.ProjObject{1})
2507        UvData.ProjObject{1}.Type='plane';%main plotting plane
2508        UvData.ProjObject{1}.ProjMode='projection';%main plotting plane
[627]2509       % UvData.ProjObject{1}.Coord=[0 0 0];
[622]2510        UvData.ProjObject{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
2511        UvData.ProjObject{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
[491]2512    end
[435]2513    %% 3D case (menuvolume)
[654]2514    if UvData.Field.NbDim==3% && UvData.NewSeries
[435]2515        test_set_object=1;
2516        hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
2517        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
2518        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
2519        if ~isempty(hset_object) %if set_object is detected
2520            delete(hset_object);% delete the GUI set_object if it does not fit
[387]2521        end
[435]2522        if test_set_object% reinitiate the GUI set_object
[622]2523            delete_object(1);% delete the current projection object in the list UvData.ProjObject, delete its graphic representations and update the list displayed in handles.ListObject and 2
2524            UvData.ProjObject{1}.NbDim=NbDim;%test for 3D objects
2525            UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
2526            UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
2527            UvData.ProjObject{1}.Angle=[0 0 0];
2528            UvData.ProjObject{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
2529            UvData.ProjObject{1}.Name='1-PLANE';
2530            UvData.ProjObject{1}.enable_plot=1;
2531            set_object(UvData.ProjObject{1},handles,ZBounds);
[435]2532            set(handles.ListObject,'Value',1);
2533            set(handles.ListObject,'String',{'1-PLANE'});
[650]2534            set(handles.CheckEditObject,'Value',1)% put the plane in edit mode to enable the z cursor
2535            CheckEditObject_Callback([],[], handles)
[387]2536        end
[435]2537        %multilevel case (single menuplane in a 3D space)
2538    elseif isfield(UvData,'Z')
2539        if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
2540            XmlData=UvData.XmlData{1};
2541            if isfield(XmlData,'PlanePos')
[622]2542                UvData.ProjObject{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
[435]2543            end
2544            if isfield(XmlData,'PlaneAngle')
2545                siz=size(XmlData.PlaneAngle);
2546                indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
[622]2547                UvData.ProjObject{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
[435]2548            end
2549        elseif isfield(UvData,'ZIndex')
[622]2550            UvData.ProjObject{1}.ZObject=UvData.ZIndex;
[435]2551        end
[387]2552    end
2553end
[435]2554
[387]2555testnewseries=UvData.NewSeries;
2556UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2557set(handles.uvmat,'UserData',UvData)
2558
2559%% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
[405]2560% if isfield(UvData,'Mask')&& ~isfield(UvData,'A')
2561%     set(handles.num_MinA,'String','0')
2562%     set(handles.num_MaxA,'String','255')
2563% end
[387]2564
[434]2565%% usual 1D (x,y) plots
[654]2566if UvData.Field.NbDim<=1
[434]2567    set(handles.Objects,'Visible','off')
[689]2568%     set(handles.ListObject_1_title,'Visible','off')
2569%     set(handles.ListObject_1,'Visible','off')
[511]2570    [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.PlotAxes,read_GUI(handles.uvmat));
[598]2571    errormsg=fill_GUI(PlotParamOut,handles.uvmat);
2572    for list={'Scalar','Vectors'}
2573        if ~isfield(PlotParamOut,list{1})
2574            set(handles.(list{1}),'Visible','off')
2575        end
2576    end
[434]2577   
[526]2578%% 2D or 3D fieldname are generally projected
[387]2579else
[434]2580    set(handles.Objects,'Visible','on')
[689]2581%     set(handles.ListObject_1_title,'Visible','on')
2582%     set(handles.ListObject_1,'Visible','on')
[434]2583   
2584    %% Plot the projections on the selected  projection objects
2585    % main projection object (uvmat display)
2586    list_object=get(handles.ListObject_1,'String');
[535]2587    if isequal(list_object,{''})||isequal(list_object,' ')%refresh list of objects if the menu is empty
[508]2588        set(handles.ListObject,'Value',1)
2589        set(handles.ListObject,'String',{'plane'})
[622]2590        UvData.ProjObject{1}.Type='plane';%main plotting plane
2591        UvData.ProjObject{1}.ProjMode='projection';%main plotting plane
2592        UvData.ProjObject{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
2593        UvData.ProjObject{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
[434]2594        set(handles.ListObject_1,'Value',1)
[508]2595        set(handles.ListObject_1,'String',{'plane'})
[387]2596    end
[674]2597    IndexObj=get(handles.ListObject_1,'Value');%selected projection object for main view
2598    if IndexObj> numel(UvData.ProjObject)
2599        IndexObj=1;%select the first object if the selected one does not exist
[434]2600        set(handles.ListObject_1,'Value',1)
[387]2601    end
[674]2602    if get(handles.CheckViewField,'Value')
2603        IndexObj_2=get(handles.ListObject,'Value');%selected projection object for view_field
2604        if ~isequal(IndexObj_2,IndexObj(1))
2605            IndexObj(2)=IndexObj_2;
2606        end
[434]2607    end
2608    plot_handles{1}=handles;
2609    if isfield(UvData,'plotaxes')%case of movies
2610        haxes(1)=UvData.plotaxes;
2611    else
[511]2612        haxes(1)=handles.PlotAxes;
[434]2613    end
2614    PlotParam{1}=read_GUI(handles.uvmat);
2615    %default settings if vectors not visible
2616    if ~isfield(PlotParam{1},'Vectors')
2617        PlotParam{1}.Vectors.MaxVec=1;
2618        PlotParam{1}.Vectors.MinVec=0;
2619        PlotParam{1}.Vectors.CheckFixVecColor=1;
2620        PlotParam{1}.Vectors.ColCode1=0.33;
2621        PlotParam{1}.Vectors.ColCode2=0.66;
[517]2622        PlotParam{1}.Vectors.ColorScalar={''};
[434]2623        PlotParam{1}.Vectors.ColorCode= {'rgb'};
2624    end
2625    PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
2626   
2627    %% second projection object (view_field display)
2628    if length( IndexObj)>=2
2629        view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
2630        if ~isempty(view_field_handle)
2631            plot_handles{2}=guidata(view_field_handle);
[511]2632            haxes(2)=plot_handles{2}.PlotAxes;
[599]2633            PlotParam{2}=read_GUI(view_field_handle);
2634           % PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
[434]2635            PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
[421]2636        end
[387]2637    end
[434]2638   
2639    %% loop on the projection objects: one or two
2640   
2641    for imap=1:numel(IndexObj)
2642        iobj=IndexObj(imap);
[622]2643        if numel(UvData.ProjObject)<iobj
[606]2644            break
2645        end
[622]2646        [ObjectData,errormsg]=proj_field(UvData.Field,UvData.ProjObject{iobj});% project field on the object
[434]2647        if ~isempty(errormsg)
2648            return
[387]2649        end
[434]2650        if testnewseries
2651            PlotParam{imap}.Scalar.CheckBW=[]; %B/W option depends on the input field (image or scalar)
2652            if isfield(ObjectData,'CoordUnit')
2653                PlotParam{imap}.Coordinates.CheckFixAspectRatio=1;% set x and y scaling equal if CoordUnit is defined (common unit for x and y)
2654                PlotParam{imap}.Coordinates.AspectRatio=1; %set aspect ratio to 1
[387]2655            end
[434]2656        end
2657        %use of mask (TODO: check)
2658        if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
2659            flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2660            AX=ObjectData.AX;%x coordiantes for the scalar field
2661            AY=ObjectData.AY;%y coordinates for the scalar field
2662            MaskX=ObjectData.MaskX;%x coordiantes for the mask
2663            MaskY=ObjectData.MaskY;%y coordiantes for the mask
2664            if ~isequal(MaskX,AX)||~isequal(MaskY,AY)
2665                nxy=size(flag_mask);
2666                sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2667                sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2668                x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
2669                y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
2670                %project on the positions of the scalar
2671                npxy=size(ObjectData.A);
2672                dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2673                dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2674                xi=ObjectData.AX(1):dxy(2):ObjectData.AX(end);
2675                yi=ObjectData.AY(1):dxy(1):ObjectData.AY(end);
2676                [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2677                flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2678            end
2679            AClass=class(ObjectData.A);
2680            ObjectData.A=flag_mask.*double(ObjectData.A);
2681            ObjectData.A=feval(AClass,ObjectData.A);
[387]2682        end
[434]2683        if ~isempty(ObjectData)
[569]2684            %PlotType='none'; %default
[434]2685            if imap==2 && isempty(view_field_handle)
2686                view_field(ObjectData)
2687            else
[654]2688              %  ObjectData.VarAttribute{5}.Role='scalar';TODO    CORRECT
[434]2689                [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap},PosColorbar{imap});
[595]2690                if imap==1
[598]2691                    errormsg=fill_GUI(PlotParamOut,handles.uvmat);
[595]2692                else
[596]2693                    errormsg=fill_GUI(PlotParamOut,view_field_handle);
[595]2694                end
[598]2695                for list={'Scalar','Vectors'}
2696                    if ~isfield(PlotParamOut,list{1})
2697                        set(plot_handles{imap}.(list{1}),'Visible','off')
2698                    end
2699                end
[575]2700                if isfield(Field,'CoordMesh')&&~isempty(Field.CoordMesh)
2701                    ObjectData.CoordMesh=Field.CoordMesh; % gives an estimated mesh size (useful for mouse action on the plot)
[434]2702                end
[387]2703            end
2704        end
2705    end
[434]2706   
2707    %% update the mask
2708    if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
[641]2709        update_mask(handles);
[434]2710    end
2711   
2712    %% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
2713    menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
2714    ind_skip=[];
2715    % nb_histo=1;
2716    Ustring='';
2717    Vstring='';
2718    % suppress coordinates from the histogram menu
2719    for ivar=1:numel(menu_histo)%l loop on field variables:
2720        if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2721            Role=UvData.Field.VarAttribute{ivar}.Role;
2722            switch Role
2723                case {'coord_x','coord_y','coord_z','dimvar'}
2724                    ind_skip=[ind_skip ivar];
2725                case {'vector_x'}
2726                    Ustring=UvData.Field.ListVarName{ivar};
2727                    ind_skip=[ind_skip ivar];
2728                case {'vector_y'}
2729                    Vstring=UvData.Field.ListVarName{ivar};
2730                    ind_skip=[ind_skip ivar];
2731            end
[387]2732        end
[434]2733        DimCell=UvData.Field.VarDimName{ivar};
2734        DimName='';
2735        if ischar(DimCell)
2736            DimName=DimCell;
2737        elseif iscell(DimCell)&& numel(DimCell)==1
2738            DimName=DimCell{1};
2739        end
2740        if strcmp(DimName,menu_histo{ivar})
2741            ind_skip=[ind_skip ivar];
2742        end
[387]2743    end
[434]2744    menu_histo(ind_skip)=[];% remove skipped items
2745    if ~isempty(Ustring)
2746        menu_histo=[{[Ustring ',' Vstring]};menu_histo];% add U, V at the beginning if they exist
[387]2747    end
[434]2748   
2749    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2750    % display menus and plot histograms
2751    test_v=0;
2752    if ~isempty(menu_histo)
2753        set(handles.histo1_menu,'Value',1)
2754        set(handles.histo1_menu,'String',menu_histo)
2755        histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
[387]2756    end
2757end
[644]2758ResizeFcn(handles.uvmat,[],handles)
[714]2759set(handles.uvmat,'Pointer',pointer)
[387]2760
[424]2761%------------------------------------------------------------------------
2762function histo1_menu_Callback(hObject, eventdata, handles)
2763%--------------------------------------------
2764histo_menu=get(handles.histo1_menu,'String');
2765histo_value=get(handles.histo1_menu,'Value');
2766FieldName=histo_menu{histo_value};
[530]2767
[424]2768UvData=get(handles.uvmat,'UserData');
2769Field=UvData.Field;
2770r=regexp(FieldName,'(?<var1>.*)(?<sep>,)(?<var2>.*)','names');
2771FieldName_2='';
2772if ~isempty(r)
2773    FieldName=r.var1;
2774    FieldName_2=r.var2;
2775end
2776if ~isfield(UvData.Field,FieldName)
2777    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
2778    return
2779end
2780FieldHisto=Field.(FieldName);
2781if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto))
2782    indsel=find(Field.FF==0);%find values marked as false
2783    if ~isempty(indsel)
2784        FieldHisto=FieldHisto(indsel);
2785        if ~isempty(FieldName_2)
2786            FieldHisto(:,:,2)=Field.(FieldName_2)(indsel);
2787        end
[387]2788    end
[682]2789elseif ~isempty(FieldName_2)
2790    FieldHisto(:,:,2)=Field.(FieldName_2);
[387]2791end
[424]2792if isempty(Field)
2793    msgbox_uvmat('ERROR',['empty field ' FieldName])
2794else
2795    nxy=size(FieldHisto);
2796    Amin=double(min(min(min(FieldHisto))));%min of field value
2797    Amax=double(max(max(max(FieldHisto))));%max of field value
2798    if isequal(Amin,Amax)
[511]2799        cla(handles.HistoAxes)
[424]2800    else
2801        Histo.ListVarName={FieldName,'histo'};
2802        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
2803            Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
2804        else
2805            if numel(nxy)==2
2806                Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
2807            else
2808                Histo.VarDimName={FieldName,{FieldName,'component'}}; %dimensions for the histogram
2809            end
2810        end
2811        %unit
2812        units=[]; %default
2813        for ivar=1:numel(Field.ListVarName)
2814            if strcmp(Field.ListVarName{ivar},FieldName)
2815                if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
2816                    units=Field.VarAttribute{ivar}.units;
2817                    break
2818                end
2819            end
2820        end
2821        if ~isempty(units)
2822            Histo.VarAttribute{1}.units=units;
2823        end
2824        eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
2825        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
2826            C=reshape(double(FieldHisto),1,[]);% reshape in a vector
2827            Histo.histo(:,1)=hist(C, Histo.(FieldName));  %calculate histogram
2828        else
2829            for col=1:size(FieldHisto,3)
2830                B=FieldHisto(:,:,col);
2831                C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
2832                Histo.histo(:,col)=hist(C, Histo.(FieldName));  %calculate histogram
2833            end
2834        end
[511]2835        plot_field(Histo,handles.HistoAxes);
[426]2836        hlegend=legend;
2837        if isempty(FieldName_2)
2838        set(hlegend,'String',FieldName)
2839        else
2840            set(hlegend,'String',{FieldName;FieldName_2})
2841        end
[424]2842    end
[387]2843end
2844
[622]2845%------------------------------------------------------------------------
[387]2846% --- translate coordinate to matrix index
[622]2847%------------------------------------------------------------------------
[387]2848function [indx,indy]=pos2ind(x0,rangx0,nxy)
2849indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2850indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2851
[622]2852%------------------------------------------------------------------------
[428]2853% --- Executes on button press in 'CheckZoom'.
[622]2854%------------------------------------------------------------------------
[428]2855function CheckZoom_Callback(hObject, eventdata, handles)
2856
[699]2857    if get(handles.CheckZoom,'Value')
2858        set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes
2859        set(handles.CheckZoomFig,'Value',0)%desactivate zoom fig
2860    end
[428]2861
[699]2862
[622]2863%------------------------------------------------------------------------
2864% --- Executes on button press in CheckZoomFig.
2865%------------------------------------------------------------------------
2866function CheckZoomFig_Callback(hObject, eventdata, handles)
2867
2868if get(handles.CheckZoomFig,'Value')
2869    set(handles.CheckZoom,'value',0)
2870end
2871
2872%------------------------------------------------------------------------
[387]2873% --- Executes on button press in 'CheckFixLimits'.
[622]2874%------------------------------------------------------------------------
[387]2875function CheckFixLimits_Callback(hObject, eventdata, handles)
[622]2876
2877if ~get(handles.CheckFixLimits,'Value')
[675]2878    update_plot(handles)
2879    set(handles.CheckZoom,'Value',0)
[387]2880end
2881
[622]2882%------------------------------------------------------------------------
[428]2883% --- Executes on button press in CheckFixAspectRatio.
2884function CheckFixAspectRatio_Callback(hObject, eventdata, handles)
[622]2885%------------------------------------------------------------------------
2886
[690]2887% if get(handles.CheckFixAspectRatio,'Value')
[387]2888    update_plot(handles);
[690]2889% else
2890%     update_plot(handles);
2891% end
[387]2892
[622]2893%------------------------------------------------------------------------
[428]2894function num_AspectRatio_Callback(hObject, eventdata, handles)
[622]2895%------------------------------------------------------------------------
[428]2896set(handles.CheckFixAspectRatio,'Value',1)% select the fixed aspect ratio button
2897update_plot(handles);
[387]2898
[622]2899%------------------------------------------------------------------------
[387]2900%----Executes on button press in 'record': records the current flags of manual correction.
[622]2901%------------------------------------------------------------------------
[387]2902function record_Callback(hObject, eventdata, handles)
[622]2903
[387]2904[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
[450]2905FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
2906[erread,message]=fileattrib(FileName);
[387]2907if ~isempty(message) && ~isequal(message.UserWrite,1)
[450]2908     msgbox_uvmat('ERROR',['no writting access to ' FileName])
[387]2909     return
2910end
[627]2911MenuVelType=get(handles.VelType,'String');
2912test_civ2=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ2');
2913test_civ1=strcmp(MenuVelType{get(handles.VelType,'Value')},'civ1');
[387]2914if ~test_civ2 && ~test_civ1
2915    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2916end
2917if test_civ2
[627]2918    nbname='nb_vec_2';
2919   flagname='Civ2_FF';
2920   CivStage=5;
[387]2921end
2922if test_civ1
[627]2923    nbname='nb_vec_1';
2924   flagname='Civ1_FF';
2925    CivStage=2;
[387]2926end
2927%write fix flags in the netcdf file
2928UvData=get(handles.uvmat,'UserData');
2929hhh=which('netcdf.open');% look for built-in matlab netcdf library
[627]2930if ~isequal(hhh,'')% case of  builtin Matlab netcdf library
[450]2931    nc=netcdf.open(FileName,'NC_WRITE');
[387]2932    netcdf.reDef(nc);
[627]2933    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'CivStage',CivStage);
[387]2934    dimid = netcdf.inqDimID(nc,nbname);
2935    try
2936        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2937    catch
2938        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2939    end
2940    netcdf.endDef(nc);
[511]2941    netcdf.putVar(nc,varid,UvData.PlotAxes.FF);
[387]2942    netcdf.close(nc); 
2943else %old netcdf library
[450]2944    netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
[387]2945end
2946
2947%-------------------------------------------------------------------
2948%----Correct the netcdf file, using toolbox (old versions of Matlab).
2949%-------------------------------------------------------------------
[450]2950function netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
2951nc=netcdf(FileName,'write'); %open netcdf file
[387]2952result=redef(nc);
2953eval(['nc.' attrname '=1;']);
2954theDim=nc(nbname) ;% get the number of velocity vectors
2955nb_vectors=size(theDim);
2956var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2957var_FixFlag(1:nb_vectors)=AxeData.FF;%
2958fin=close(nc);
2959
[674]2960%-----------------------------------------------------------------------
[387]2961% --- Executes on button press in SubField
[674]2962%-----------------------------------------------------------------------
[387]2963function SubField_Callback(hObject, eventdata, handles)
[674]2964
2965if get(handles.SubField,'Value')==0% if the subfield button is desactivated 
2966    desable_subfield(handles)
[591]2967    transform_fct_list=get(handles.TransformName,'String');
2968    transform_fct=transform_fct_list(get(handles.TransformName,'Value'));
[515]2969    if strcmp(transform_fct,'sub_field')
[591]2970        set(handles.TransformName,'Value',1)%suppress the sub_field transform
[651]2971        TransformName_Callback(hObject, eventdata, handles);
[515]2972    else
[713]2973        REFRESH_Callback(hObject, eventdata, handles)
[515]2974    end 
[387]2975else
[651]2976    fileinput_1=uigetfile_uvmat('select a second input file:',get(handles.RootPath,'String'));
2977    if isempty(fileinput_1)
2978        set(handles.SubField,'Value',0)
[674]2979    else       
[651]2980        % refresh the current displayed field
2981        display_file_name(handles,fileinput_1,2)
2982       
2983        %update list of recent files in the menubar
2984        MenuFile_1=fileinput_1;
2985        MenuFile_2=get(handles.MenuFile_1,'Label');
2986        MenuFile_3=get(handles.MenuFile_2,'Label');
2987        MenuFile_4=get(handles.MenuFile_3,'Label');
2988        MenuFile_5=get(handles.MenuFile_4,'Label');
2989        set(handles.MenuFile_1,'Label',MenuFile_1)
2990        set(handles.MenuFile_2,'Label',MenuFile_2)
2991        set(handles.MenuFile_3,'Label',MenuFile_3)
2992        set(handles.MenuFile_4,'Label',MenuFile_4)
2993        set(handles.MenuFile_5,'Label',MenuFile_5)
2994    end
[387]2995end
2996
[674]2997%-----------------------------------------------------------------------
2998% --- desactivate display used for a second file series
2999%-----------------------------------------------------------------------
3000function desable_subfield(handles)
3001   
3002set(handles.RootPath_1,'String','')
3003set(handles.RootFile_1,'String','')
3004set(handles.SubDir_1,'String','');
3005set(handles.FileIndex_1,'String','');
3006set(handles.FileExt_1,'String','');
3007set(handles.RootPath_1,'Visible','off')
3008set(handles.RootFile_1,'Visible','off')
3009set(handles.SubDir_1,'Visible','off');
3010set(handles.NomType_1,'Visible','off');
3011set(handles.FileIndex_1,'Visible','off');
3012set(handles.FileExt_1,'Visible','off');
3013set(handles.TimeName_1,'String','');
3014set(handles.TimeName_1,'Visible','off');
3015set(handles.TimeValue_1,'String','');
3016set(handles.TimeValue_1,'Visible','off');
3017set(handles.FieldName_1,'Value',1);%set to blank state
3018set(handles.VelType_1,'Value',1);%set to blank state
3019set(handles.num_Opacity,'String','')% desactivate opacity setting
3020FieldList=get(handles.FieldName,'String');
3021if numel(FieldList)>1   % if a choice of fields exists
3022    set(handles.FieldName_1,'Value',1)% set second field choice to blank
3023    set(handles.FieldName_1,'String',[{''};FieldList])% reproduce the menu FieldName plus a blank option
3024else
3025    set(handles.FieldName_1,'String',{''})% set second field choice to blank
3026end
3027if ~strcmp(get(handles.VelType,'Visible'),'on')
3028    set(handles.VelType_1,'Visible','off')
3029end
3030UvData=get(handles.uvmat,'UserData');
3031if isfield(UvData,'XmlData_1')
3032    UvData=rmfield(UvData,'XmlData_1');
3033end
3034set(handles.uvmat,'UserData',UvData);
3035
[387]3036%------------------------------------------------------------------------
3037% --- read the data displayed for the input rootfile windows (new): TODO use read_GUI
[674]3038%------------------------------------------------------------------------
3039function [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles)
[387]3040
3041InputFile=read_GUI(handles.InputFile);
3042RootPath=InputFile.RootPath;
3043SubDir=regexprep(InputFile.SubDir,'/|\','');
3044RootFile=regexprep(InputFile.RootFile,'/|\','');
3045FileIndices=InputFile.FileIndex;
3046FileExt=InputFile.FileExt;
3047
3048
3049%------------------------------------------------------------------------
3050% ---- read the data displayed for the second input rootfile windows
[674]3051%------------------------------------------------------------------------
[387]3052function [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1,NomType_1]=read_file_boxes_1(handles)
[674]3053
[387]3054RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
3055if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
3056    RootPath_1=get(handles.RootPath,'String');
3057end;
3058SubDir_1=get(handles.SubDir_1,'String');
3059if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
3060    SubDir_1=get(handles.SubDir,'String');
3061end
3062SubDir_1=regexprep(SubDir_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
3063RootFile_1=get(handles.RootFile_1,'String');
3064if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
3065    RootFile_1=get(handles.RootFile,'String');
3066end
3067RootFile_1=regexprep(RootFile_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
3068FileIndex_1=get(handles.FileIndex_1,'String');
3069if isequal(get(handles.FileIndex_1,'Visible'),'off')|| isequal(FileIndex_1,'"')
3070    FileIndex_1=get(handles.FileIndex,'String');
3071end
3072FileExt_1=get(handles.FileExt_1,'String');
3073if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"')
3074    FileExt_1=get(handles.FileExt,'String');%read FileExt by default
3075end
3076NomType_1=get(handles.NomType_1,'String');
3077if isequal(get(handles.NomType_1,'Visible'),'off') || isequal(NomType_1,'"')
3078    NomType_1=get(handles.NomType,'String');%read FileExt by default
3079end
3080%------------------------------------------------------------------------
[526]3081% --- Executes on menu selection FieldName
3082function FieldName_Callback(hObject, eventdata, handles)
[387]3083%------------------------------------------------------------------------
[648]3084
3085%% read data from uvmat
[581]3086UvData=get(handles.uvmat,'UserData');
[526]3087list_fields=get(handles.FieldName,'String');% list menu fields
3088index_fields=get(handles.FieldName,'Value');% selected string index
[387]3089field= list_fields{index_fields(1)}; % selected string
3090[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
3091FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
3092[tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
[648]3093
[674]3094switch field
[648]3095   
3096    case 'get_field...'
[674]3097        %% fill the coordinates and variables from selections in get_field
[648]3098        ParamIn=[];
3099        % in case of civ data, we use the civ choice as default input for the GUI get_field
3100        if strcmp(get(handles.VelType,'Visible'),'on')
3101            ParamIn.SwitchVarIndexTime='attribute';
3102            ListVelType=get(handles.VelType,'String');
3103            VelType=ListVelType{get(handles.VelType,'Value')};
3104            switch VelType
3105                case 'civ1'
[674]3106                    ParamIn.TimeAttrName='Civ1_Time';
[648]3107                    ParamIn.vector_x='Civ1_U';
3108                    ParamIn.vector_y='Civ1_V';
3109                    ParamIn.vec_color='Civ1_C';
3110                case 'filter1'
[674]3111                    ParamIn.TimeAttrName='Civ1_Time';
[648]3112                    ParamIn.vector_x='Civ1_U_smooth';
3113                    ParamIn.vector_y='Civ1_V_smooth';
3114                case 'civ2'
[674]3115                    ParamIn.TimeAttrName='Civ2_Time';
[648]3116                    ParamIn.vector_x='Civ2_U';
3117                    ParamIn.vector_y='Civ2_V';
3118                case 'filter2'
[674]3119                    ParamIn.TimeAttrName='Civ2_Time';
[648]3120                    ParamIn.vector_x='Civ2_U_smooth';
3121                    ParamIn.vector_y='Civ2_V_smooth';
3122                    ParamIn.vec_color='Civ2_C';
3123            end
3124        end
3125       
3126        % VelType menu desactivated
3127        set(handles.FixVelType,'visible','off')
3128        set(handles.VelType,'Visible','off')
3129       
3130        %read selection from get_field
3131        [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
3132        FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
3133        GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field
3134        FieldList={};
3135        VecColorList={};
3136        switch GetFieldData.FieldOption
3137            case 'vectors'
3138                UName=GetFieldData.PanelVectors.vector_x;
3139                VName=GetFieldData.PanelVectors.vector_y;
3140                YName={GetFieldData.Coordinates.Coord_y};
3141                CName=GetFieldData.PanelVectors.vec_color;
[675]3142                FieldList={['vec(' UName ',' VName ')'];...
3143                    ['norm(' UName ',' VName ')'];...
3144                    UName;VName};
3145                VecColorList={['norm(' UName ',' VName ')'];...
3146                    UName;VName};
3147                if ~isempty(CName)
3148                    VecColorList=[{CName};VecColorList];
3149                end
[648]3150            case 'scalar'
3151                AName=GetFieldData.PanelScalar.scalar;
3152                YName={GetFieldData.Coordinates.Coord_y};
3153                FieldList={AName};
3154            case '1D plot'
3155                YName=GetFieldData.PanelOrdinate.ordinate;
[674]3156            case 'civdata...'%reinitiate input, return to automatic civ data reading
3157                display_file_name(handles,FileName,1)
[648]3158        end
[654]3159        if ~strcmp(GetFieldData.FieldOption,'civdata...')
3160            XName=GetFieldData.Coordinates.Coord_x;
[674]3161            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
[693]3162            switch TimeNameStr
3163                case 'file index'
3164                    set(handles.TimeName,'String','');
3165                case 'attribute'
3166                    set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]);
3167                case 'variable'
3168                    set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
3169                    set(handles.NomType,'String','*')
3170                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
3171                    set(handles.FileIndex,'String','')
3172                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
3173                case 'matrix_index'
3174                    set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
3175                    set(handles.NomType,'String','*')
3176                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
3177                    set(handles.FileIndex,'String','')
3178                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
[674]3179            end
3180            set(handles.Coord_x,'String',XName)
3181            if ischar(YName)
3182                YName={YName};
3183            end
3184            set(handles.Coord_y,'Data',YName)
3185            set(handles.FieldName,'Value',1)
3186            set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
3187            set(handles.ColorScalar,'Value',1)
3188            set(handles.ColorScalar,'String',VecColorList);
3189            UvData.FileType{1}='netcdf';
3190            set(handles.uvmat,'UserData',UvData)
[713]3191            REFRESH_Callback(hObject, eventdata, handles)
[648]3192        end
[674]3193       
[648]3194    case 'image'
[674]3195        %% look for image corresponding to civ data
[648]3196        if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
3197            imagename=UvData.Field.Civ2_ImageA;
3198        elseif isfield(UvData.Field,'Civ1_ImageA')%
3199            imagename=UvData.Field.Civ1_ImageA;
3200        else
3201            SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
3202            imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]);
3203        end
3204        if ~exist(imagename,'file')
3205            imagename=uigetfile_uvmat('Pick an image file',imagename,'image');
3206            if isempty(imagename)
3207                return
3208            end
3209        end
[387]3210        % display the selected field and related information
[648]3211        display_file_name(handles,imagename)%display the image
[674]3212    otherwise
[713]3213        REFRESH_Callback(hObject, eventdata, handles)
[387]3214end
3215
[622]3216%----------------------------------------------------------------
[526]3217% --- Executes on menu selection FieldName
3218function FieldName_1_Callback(hObject, eventdata, handles)
[387]3219%-------------------------------------------------
[648]3220
3221%%%%%% TODO: modify like FieldName_Callback
[387]3222%% read input data
3223check_new=~get(handles.SubField,'Value'); %check_new=1 if a second field was not previously entered
3224UvData=get(handles.uvmat,'UserData');
3225if check_new && isfield(UvData,'XmlData')
3226    UvData.XmlData{2}=UvData.XmlData{1};
3227end
[389]3228if isfield(UvData,'Field_1')
3229    UvData=rmfield(UvData,'Field_1');% remove the stored second field (a new one needs to be read)
3230end
[450]3231UvData.FileName_1='';% desactivate the use of a constant second file
[526]3232list_fields=get(handles.FieldName,'String');% list menu fields
3233field= list_fields{get(handles.FieldName,'Value')}; % selected string
3234list_fields=get(handles.FieldName_1,'String');% list menu fields
3235field_1= list_fields{get(handles.FieldName_1,'Value')}; % selected string for the second field
[405]3236if isempty(field_1)%||(numel(UvData.FileType)>=2 && strcmp(UvData.FileType{2},'image'))
[387]3237    set(handles.SubField,'Value',0)
3238    SubField_Callback(hObject, eventdata, handles)
[428]3239    return
[405]3240else
3241    set(handles.SubField,'Value',1)%state that a second field is now entered
[387]3242end
3243
3244%% read the rootfile input display
[405]3245[RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
[450]3246FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
[387]3247[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
3248switch field_1
3249    case 'get_field...'
[713]3250         %% fill the coordinates and variables from selections in get_field
3251        ParamIn=[];
3252        % in case of civ data, we use the civ choice as default input for the GUI get_field
3253        if strcmp(get(handles.VelType_1,'Visible'),'on')
3254            ParamIn.SwitchVarIndexTime='attribute';
3255            ListVelType=get(handles.VelType_1,'String');
3256            VelType=ListVelType{get(handles.VelType_1,'Value')};
3257            switch VelType
3258                case 'civ1'
3259                    ParamIn.TimeAttrName='Civ1_Time';
3260                    ParamIn.vector_x='Civ1_U';
3261                    ParamIn.vector_y='Civ1_V';
3262                    ParamIn.vec_color='Civ1_C';
3263                case 'filter1'
3264                    ParamIn.TimeAttrName='Civ1_Time';
3265                    ParamIn.vector_x='Civ1_U_smooth';
3266                    ParamIn.vector_y='Civ1_V_smooth';
3267                case 'civ2'
3268                    ParamIn.TimeAttrName='Civ2_Time';
3269                    ParamIn.vector_x='Civ2_U';
3270                    ParamIn.vector_y='Civ2_V';
3271                case 'filter2'
3272                    ParamIn.TimeAttrName='Civ2_Time';
3273                    ParamIn.vector_x='Civ2_U_smooth';
3274                    ParamIn.vector_y='Civ2_V_smooth';
3275                    ParamIn.vec_color='Civ2_C';
3276            end
[387]3277        end
[713]3278       
3279        % VelType menu desactivated
3280        set(handles.FixVelType,'visible','off')
3281        set(handles.VelType,'Visible','off')
3282       
3283        %read selection from get_field
3284        [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
3285        FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
3286        GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field
3287        FieldList={};
3288        VecColorList={};
3289        switch GetFieldData.FieldOption
3290            case 'vectors'
3291                UName=GetFieldData.PanelVectors.vector_x;
3292                VName=GetFieldData.PanelVectors.vector_y;
3293                YName={GetFieldData.Coordinates.Coord_y};
3294                CName=GetFieldData.PanelVectors.vec_color;
3295                FieldList={['vec(' UName ',' VName ')'];...
3296                    ['norm(' UName ',' VName ')'];...
3297                    UName;VName};
3298                VecColorList={['norm(' UName ',' VName ')'];...
3299                    UName;VName};
3300                if ~isempty(CName)
3301                    VecColorList=[{CName};VecColorList];
3302                end
3303            case 'scalar'
3304                AName=GetFieldData.PanelScalar.scalar;
3305                YName={GetFieldData.Coordinates.Coord_y};
3306                FieldList={AName};
3307            case '1D plot'
3308                YName=GetFieldData.PanelOrdinate.ordinate;
3309            case 'civdata...'%reinitiate input, return to automatic civ data reading
3310                display_file_name(handles,FileName,1)
[428]3311        end
[713]3312        if ~strcmp(GetFieldData.FieldOption,'civdata...')
3313            XName=GetFieldData.Coordinates.Coord_x;
3314            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
3315            switch TimeNameStr
3316                case 'file index'
3317                    set(handles.TimeName_1,'String','');
3318                case 'attribute'
3319                    set(handles.TimeName_1,'String',['att:' GetFieldData.Time.TimeName]);
3320                case 'variable'
3321                    set(handles.TimeName_1,'String',['var:' GetFieldData.Time.TimeName])
3322                    set(handles.NomType_1,'String','*')
3323                    set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
3324                    set(handles.FileIndex_1,'String','')
3325                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
3326                case 'matrix_index'
3327                    set(handles.TimeName_1,'String',['dim:' GetFieldData.Time.TimeName]);
3328                    set(handles.NomType_1,'String','*')
3329                    set(handles.RootFile_1,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
3330                    set(handles.FileIndex_1,'String','')
3331                    ParamIn.TimeDimName_1=GetFieldData.Time.TimeName;
3332            end
3333            set(handles.Coord_x,'String',XName)
3334            if ischar(YName)
3335                YName={YName};
3336            end
3337            set(handles.Coord_y,'Data',YName)
3338            set(handles.FieldName_1,'Value',1)
3339            set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]);
3340            set(handles.ColorScalar,'Value',1)
3341            set(handles.ColorScalar,'String',VecColorList);
3342            UvData.FileType{2}='netcdf';
3343            set(handles.uvmat,'UserData',UvData)
3344            REFRESH_Callback(hObject, eventdata, handles)
3345        end
3346         
3347%         set_veltype_display(0) % no veltype display
3348%         hget_field=findobj(allchild(0),'name','get_field_1');
3349%         if ~isempty(hget_field)
3350%             delete(hget_field)
3351%         end
3352%         hget_field=get_field(FileName_1);
3353%         set(hget_field,'name','get_field_1')
3354%         hhget_field=guidata(hget_field);
3355%         set(hhget_field.list_fig,'Value',1)
3356%         set(hhget_field.list_fig,'String',{'uvmat'})
3357%         if check_new
3358%             UvData.FileType{2}=UvData.FileType{1};
3359%             set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
3360%               set(handles.uvmat,'UserData',UvData)
3361%         end
[387]3362    case 'image'
[674]3363        %% look for image corresponding to civ data
3364        imagename='';
[494]3365        if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
3366            imagename=UvData.Field.Civ2_ImageA;
3367        elseif isfield(UvData.Field,'Civ1_ImageA')%
3368            imagename=UvData.Field.Civ1_ImageA;
3369        else
[674]3370            SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
3371            imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]);
[494]3372        end
[674]3373        if ~exist(imagename,'file')
3374            imagename=uigetfile_uvmat('Pick an image file',imagename,'image');
3375           
[387]3376        end
[674]3377        if isempty(imagename)
[405]3378            set(handles.SubField,'Value',0)
[674]3379            return
3380        else
3381            display_file_name(handles,imagename,2)%display the image as second field
[405]3382        end
[387]3383    otherwise
[580]3384        check_refresh=1;
3385        if check_new% if a second field was not previously entered, we just read another field in the first input file
[387]3386            set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
3387            set(handles.FileExt_1,'String',get(handles.FileExt,'String'))
[580]3388           
3389            UvData.FileType{2}=UvData.FileType{1};
3390            UvData.XmlData{2}= UvData.XmlData{1};
[591]3391            transform=get(handles.TransformPath,'UserData');
[580]3392             if (~isa(transform,'function_handle')||nargin(transform)<3)
3393                set(handles.uvmat,'UserData',UvData)
[591]3394                set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
[674]3395                TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
[580]3396                 check_refresh=0;
3397             end             
[387]3398        end
3399        if ~isequal(field,'image')
[546]3400            set(handles.TitleNpxy,'Visible','off')% visible npx,pxcm... buttons
[387]3401            set(handles.num_Npx,'Visible','off')
3402            set(handles.num_Npy,'Visible','off')
3403        end
3404        set(handles.uvmat,'UserData',UvData)
[580]3405 
3406        if check_refresh && ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
[713]3407            REFRESH_Callback(hObject, eventdata, handles)
[387]3408        end
3409end
3410
3411%------------------------------------------------------------------------
3412% --- set the visibility of relevant velocity type menus:
3413function menu=set_veltype_display(Civ,FileType)
3414%------------------------------------------------------------------------
3415if ~exist('FileType','var')
3416    FileType='civx';
3417end
3418switch FileType
3419    case 'civx'
[389]3420        menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
3421        if isequal(Civ,0)
3422            imax=0;
3423        elseif isequal(Civ,1) || isequal(Civ,2)
3424            imax=1;
3425        elseif isequal(Civ,3)
3426            imax=3;
3427        elseif isequal(Civ,4) || isequal(Civ,5)
3428            imax=4;
3429        elseif isequal(Civ,6) %patch2
3430            imax=6;
3431        end
[387]3432    case 'civdata'
[389]3433        menu={'civ1';'filter1';'civ2';'filter2'};
3434        if isequal(Civ,0)
3435            imax=0;
3436        elseif isequal(Civ,1) || isequal(Civ,2)
3437            imax=1;
3438        elseif isequal(Civ,3)
3439            imax=2;
3440        elseif isequal(Civ,4) || isequal(Civ,5)
3441            imax=3;
3442        elseif isequal(Civ,6) %patch2
3443            imax=4;
3444        end
[387]3445end
3446menu=menu(1:imax);
3447
3448%------------------------------------------------------------------------
[402]3449% --- Executes on button press in FixVelType.
3450function FixVelType_Callback(hObject, eventdata, handles)
3451%------------------------------------------------------------------------
[713]3452% inputfilerefresh the current plot if the fixed  veltype is unselected
[405]3453if ~get(handles.FixVelType,'Value')
[713]3454    REFRESH_Callback(hObject, eventdata, handles)
[402]3455end
3456
3457%------------------------------------------------------------------------
[387]3458% --- Executes on button press in VelType.
3459function VelType_Callback(hObject, eventdata, handles)
3460%------------------------------------------------------------------------
3461set(handles.FixVelType,'Value',1)
[713]3462REFRESH_Callback(hObject, eventdata, handles)
[387]3463
3464%------------------------------------------------------------------------
[515]3465% --- Executes on choice selection in VelType_1.
[387]3466function VelType_1_Callback(hObject, eventdata, handles)
3467%------------------------------------------------------------------------
3468set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic)
[389]3469UvData=get(handles.uvmat,'UserData');
[713]3470set(handles.InputFileREFRESH,'BackgroundColor',[1 1 0])%paint REFRESH button in yellow to indicate its activation
[387]3471drawnow   
[515]3472InputFile=read_GUI(handles.InputFile);% read the input file parameters
3473[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
3474[RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
3475FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% name of the first input file
[405]3476
[515]3477check_refresh=0;
[389]3478if isempty(InputFile.VelType_1)
[515]3479        FileName_1='';% we plot the first input field without the second field
[387]3480        set(handles.SubField,'Value',0)
[580]3481        SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current plot, removing the second field
[387]3482elseif get(handles.SubField,'Value')% if subfield is already 'on'
[515]3483     FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];% name of the second input file
[580]3484     check_refresh=1;%will refresh the current plot
[515]3485else% we introduce the same file (with a different field) for the second series
3486     FileName_1=FileName;% we compare two fields in the same file
[389]3487     UvData.FileType{2}=UvData.FileType{1};
[515]3488     UvData.XmlData{2}= UvData.XmlData{1};
[387]3489     set(handles.SubField,'Value',1)
[591]3490     transform=get(handles.TransformPath,'UserData');
[515]3491     if (~isa(transform,'function_handle')||nargin(transform)<3)
[580]3492        set(handles.uvmat,'UserData',UvData)
[591]3493        set(handles.TransformName,'value',2); % set transform fct to 'sub_field' if the current fct does not accept two input fields
[669]3494        TransformName_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current plot
[515]3495     else
3496         check_refresh=1;
3497     end 
[387]3498end
3499
[713]3500% inputfilerefresh the current plot if it has not been done previously
[515]3501if check_refresh
3502    UvData.FileName_1='';% desactivate the use of a constant second file
3503    set(handles.uvmat,'UserData',UvData)
3504    num_i1=stra2num(get(handles.i1,'String'));
3505    num_i2=stra2num(get(handles.i2,'String'));
3506    num_j1=stra2num(get(handles.j1,'String'));
3507    num_j2=stra2num(get(handles.j2,'String'));
3508    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(['xx' FileIndex_1]);
3509    errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
3510    if ~isempty(errormsg)
3511        msgbox_uvmat('ERROR',errormsg);
3512    else
3513        set(handles.i1,'BackgroundColor',[1 1 1])
3514        set(handles.i2,'BackgroundColor',[1 1 1])
3515        set(handles.j1,'BackgroundColor',[1 1 1])
3516        set(handles.j2,'BackgroundColor',[1 1 1])
3517        set(handles.FileIndex,'BackgroundColor',[1 1 1])
3518        set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
3519    end
[713]3520    set(handles.InputFileREFRESH,'BackgroundColor',[1 0 0])
[387]3521end
3522
[580]3523
[622]3524%------------------------------------------------------------------------
[387]3525% --- reset civ buttons
3526function reset_vel_type(handles_civ0,handle1)
[622]3527%------------------------------------------------------------------------
[387]3528for ibutton=1:length(handles_civ0)
3529    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3530    set(handles_civ0(ibutton),'Value',0)
3531end
3532if exist('handle1','var')%handles of selected button
3533        set(handle1,'BackgroundColor',[1 1 0]) 
3534end
3535
[580]3536%-----------------------------------------------------------------------
[387]3537% --- Executes on button press in MENUVOLUME.
3538function VOLUME_Callback(hObject, eventdata, handles)
[580]3539%-----------------------------------------------------------------------
[387]3540%errordlg('command VOL not implemented yet')
3541if ishandle(handles.UVMAT_title)
3542    delete(handles.UVMAT_title)
3543end
3544UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3545if isequal(get(handles.VOLUME,'Value'),1)
3546    set(handles.CheckZoom,'Value',0)
[623]3547%     set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
[387]3548    set(handles.edit_vect,'Value',0)
3549    edit_vect_Callback(hObject, eventdata, handles)
[650]3550    set(handles.CheckEditObject,'Value',0)
3551%     set(handles.CheckEditObject,'BackgroundColor',[0.7 0.7 0.7])
[387]3552%     set(handles.cal,'Value',0)
3553%     set(handles.cal,'BackgroundColor',[0 1 0])
3554    set(handles.edit_vect,'Value',0)
3555    edit_vect_Callback(hObject, eventdata, handles)
3556    %initiate set_object GUI
3557    data.Name='VOLUME';
3558    if isfield(UvData,'CoordType')
3559        data.CoordType=UvData.CoordType;
3560    end
[575]3561    if isfield(UvData.Field,'CoordMesh')&~isempty(UvData.Field.CoordMesh)
[404]3562        data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
3563        data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
[575]3564        data.DX=UvData.Field.CoordMesh;
3565        data.DY=UvData.Field.CoordMesh;
[387]3566    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3567        np=size(UvData.Field.A);
3568        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3569        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3570        data.RangeY=max(meshx,meshy);
3571        data.RangeX=max(meshx,meshy);
3572        data.DX=max(meshx,meshy);
3573    end
3574    data.ParentButton=handles.VOLUME;
3575    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3576    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3577                                                      % associate the set_object interface handle to the plotting axes
[609]3578    %set(hset_object,'Position',get(handles.uvmat,'Position')+UvData.OpenParam.PosSetObject)
[387]3579    UvData.MouseAction='create_object';
3580else
3581    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3582end
3583set(handles.uvmat,'UserData',UvData)
3584
3585%-------------------------------------------------------
3586function edit_vect_Callback(hObject, eventdata, handles)
3587%-------------------------------------------------------
3588%
3589if isequal(get(handles.edit_vect,'Value'),1)
[581]3590    VelTypeMenu=get(handles.VelType,'String');
3591    VelType=VelTypeMenu{get(handles.VelType,'Value')};
3592    if ~strcmp(VelType,'civ2') && ~strcmp(VelType,'civ1')
[387]3593        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3594    end
3595    set(handles.record,'Visible','on')
3596    set(handles.edit_vect,'BackgroundColor',[1 1 0])
[650]3597    set(handles.CheckEditObject,'Value',0)
[387]3598    set(handles.CheckZoom,'Value',0)
3599    set(gcf,'Pointer','arrow')
3600else
3601    set(handles.record,'Visible','off')
3602    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3603end
3604
3605%----------------------------------------------
3606function save_mask_Callback(hObject, eventdata, handles)
3607%-----------------------------------------------------------------------
3608UvData=get(handles.uvmat,'UserData');
3609
3610flag=1;
3611npx=size(UvData.Field.A,2);
3612npy=size(UvData.Field.A,1);
3613xi=0.5:npx-0.5;
3614yi=0.5:npy-0.5;
3615[Xi,Yi]=meshgrid(xi,yi);
[622]3616if isfield(UvData,'ProjObject')
3617    for iobj=1:length(UvData.ProjObject)
3618        ObjectData=UvData.ProjObject{iobj};
[387]3619        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3620            flagobj=1;
3621            testphys=0; %coordinates in pixels by default
3622            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3623                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
3624                    Calib=UvData.XmlData{1}.GeometryCalib;
3625                    testphys=1;
3626                end
3627            end
3628            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3629                if isequal(ObjectData.Type,'polygon')
3630                    X=ObjectData.Coord(:,1);
3631                    Y=ObjectData.Coord(:,2);
3632                    if testphys
3633                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3634                    end
3635                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
3636                elseif isequal(ObjectData.Type,'ellipse')
3637                    if testphys
3638                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3639                    end
3640                    RangeX=max(ObjectData.RangeX);
3641                    RangeY=max(ObjectData.RangeY);
3642                    X2Max=RangeX*RangeX;
3643                    Y2Max=RangeY*RangeY;
3644                    distX=(Xi-ObjectData.Coord(1,1));
3645                    distY=(Yi-ObjectData.Coord(1,2));
3646                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3647                elseif isequal(ObjectData.Type,'rectangle')
3648                    if testphys
3649                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3650                    end
3651                    distX=abs(Xi-ObjectData.Coord(1,1));
3652                    distY=abs(Yi-ObjectData.Coord(1,2));
3653                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3654                end
3655                if isequal(ObjectData.ProjMode,'mask_outside')
3656                    flagobj=~flagobj;
3657                end
3658                flag=flag & flagobj;
3659            end
3660        end
3661    end
3662end
3663% flag=~flag;
3664%mask name
3665RootPath=get(handles.RootPath,'String');
3666RootFile=get(handles.RootFile,'String');
3667RootFile=regexprep(RootFile,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
3668filebase=fullfile(RootPath,RootFile);
3669list=get(handles.masklevel,'String');
3670masknumber=num2str(length(list));
3671maskindex=get(handles.masklevel,'Value');
3672mask_name=fullfile_uvmat(RootPath,SubDir,[RootFile '_' masknumber 'mask'],'.png','_1',maskindex);
3673%mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3674imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3675imflag=flipdim(imflag,1);
3676% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3677msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3678imwrite(imflag,mask_name,'BitDepth',8);
3679
3680%display the mask
3681figure;
3682vec=linspace(0,1,256);%define a linear greyscale colormap
3683map=[vec' vec' vec'];
3684colormap(map)
3685
3686image(imflag);
3687
[622]3688%------------------------------------------------------------------------
3689%------------------------------------------------------------------------
[387]3690%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3691
[622]3692%------------------------------------------------------------------------
3693%------------------------------------------------------------------------
[591]3694% --- Executes on selection change in TransformName.
[508]3695
[591]3696function TransformName_Callback(hObject, eventdata, handles)
[622]3697%------------------------------------------------------------------------
[714]3698set(handles.TransformName,'backgroundColor',[1 1 0])% indicate activation  of the menu
3699drawnow
[387]3700UvData=get(handles.uvmat,'UserData');
[671]3701menu=get(handles.TransformName,'String');%refresh
[591]3702ichoice=get(handles.TransformName,'Value');%item number in the menu
[507]3703transform_name=menu{ichoice};% choice of the transform fct
[591]3704list_path=get(handles.TransformName,'UserData');
[507]3705
[689]3706%% handles uicontrol visibility
3707if isempty(transform_name)
3708    set(handles.TransformPath,'Visible','off')
3709else
3710    set(handles.TransformPath,'Visible','on')
3711end
3712
3713
[507]3714%% add a new item to the menu if the option 'more...' has been selected
[591]3715prev_path=fullfile(get(handles.TransformPath,'String'));
[508]3716if ~exist(prev_path,'dir')
3717    prev_path=fullfile(fileparts(which('uvmat')),'transform_field');
3718end
[507]3719if strcmp(transform_name,'more...');
[671]3720    transform_fct_chosen=uigetfile_uvmat('Pick the transform function',prev_path,'.m');
3721    if ~isempty(transform_fct_chosen)
3722        [PathName,transform_name]=fileparts(transform_fct_chosen);
[648]3723        ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu
3724        if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it)
3725            menu=[menu(1:end-1);{transform_name};{'more...'}];
3726            ichoice=numel(menu)-1;
[507]3727        end
[648]3728        list_path{ichoice}=PathName;%update the list fo fct paths
3729        set(handles.TransformName,'String',menu)
3730        set(handles.TransformName,'Value',ichoice)
3731       
3732        % save the new menu in the personal file 'uvmat_perso.mat'
3733        dir_perso=prefdir;%personal Matalb directory
3734        profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3735        if exist(profil_perso,'file')
3736            nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat
3737            if nb_builtin<numel(list_path)
3738                for ilist=nb_builtin+1:numel(list_path)
3739                    transform_fct{ilist-nb_builtin}=[fullfile(list_path{ilist},menu{ilist}) '.m'];
3740                end
3741                save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
3742            end
[523]3743        end
[507]3744    end
[387]3745end
3746
[507]3747%% create the function handle of the selected fct
3748if isempty(list_path{ichoice})% case of no selected fct
3749    transform_handle=[];
[387]3750else
[507]3751    if ~exist(list_path{ichoice},'dir')
3752        msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...')
3753        return
3754    end
3755    current_dir=pwd;%current working dir
3756    cd(list_path{ichoice})
3757    transform_handle=str2func(transform_name);
3758    cd(current_dir)
[387]3759end
[591]3760set(handles.TransformPath,'String',list_path{ichoice})
3761set(handles.TransformPath,'UserData',transform_handle)
3762set(handles.TransformName,'UserData',list_path)
[387]3763
[591]3764%% update the ToolTip string of the menu TransformName with the first line of the selected fct file
[507]3765if isempty(list_path{ichoice})% case of no selected fct
[591]3766    set(handles.TransformName,'ToolTipString','transform_fct:choose a transform function')
[507]3767else
3768    try
3769        [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']);
3770        InputText=textscan(fid,'%s',1,'delimiter','\n');
[714]3771        fclose(fid);
[591]3772        set(handles.TransformName,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help
[507]3773    end
3774end
3775
3776%% adapt the GUI to the input/output conditions of the selected transform fct
[508]3777DataOut=[];
3778CoordUnit='';
3779CoordUnitPrev='';
3780if isfield(UvData,'Field')&&isfield(UvData.Field,'CoordUnit')
3781    CoordUnitPrev=UvData.Field.CoordUnit;
3782end
3783if ~isempty(list_path{ichoice})
3784    if nargin(transform_handle)>1 && isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
3785        XmlData=UvData.XmlData{1};
3786        DataOut=feval(transform_handle,'*',XmlData);
[641]3787        if isfield(DataOut,'CoordUnit')% set the requested coord unit (info used to possibly delete the current projection objects)
[508]3788            CoordUnit=DataOut.CoordUnit;
[507]3789        end
[641]3790        if isfield(DataOut,'InputFieldType')% to be used to impose a type of input file (eg. for image transform)
[508]3791            UvData.InputFieldType=DataOut.InputFieldType;
3792        end
[641]3793        if isfield(DataOut,'XmlData')%  used to add transform parameters at selection of the transform fct
3794            ListFields=fieldnames(DataOut.XmlData);
3795            for ilist=1:numel(ListFields)
3796            UvData.XmlData{1}.(ListFields{ilist})=DataOut.XmlData.(ListFields{ilist});
3797            end
3798        end
[508]3799    else
3800        DataOut=feval(transform_handle,'*');
[507]3801    end
3802end
3803
[387]3804
[508]3805%% delete drawn objects if the output CooordUnit is different from the previous one
3806if ~strcmp(CoordUnit,CoordUnitPrev)
[541]3807    set(handles.CheckFixLimits,'Value',0)
[627]3808% set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
[508]3809    hother=findobj('Tag','proj_object');%find all the proj objects
3810    for iobj=1:length(hother)
3811        delete_object(hother(iobj))
3812    end
3813    hother=findobj('Tag','DeformPoint');%find all the proj objects
3814    for iobj=1:length(hother)
3815        delete_object(hother(iobj))
3816    end
3817    hh=findobj('Tag','calib_points');
3818    if ~isempty(hh)
3819        delete(hh)
3820    end
3821    hhh=findobj('Tag','calib_marker');
3822    if ~isempty(hhh)
3823        delete(hhh)
3824    end
3825    set(handles.ListObject,'Value',1)
3826    set(handles.ListObject,'String',{''})
3827    set(handles.ListObject_1,'Value',1)
3828    set(handles.ListObject_1,'String',{''})
[650]3829    set(handles.CheckViewObject,'value',0)
3830    CheckViewObject_Callback(hObject, eventdata, handles)
3831    set(handles.CheckViewField,'value',0)
3832    CheckViewField_Callback(hObject, eventdata, handles)
3833    set(handles.CheckEditObject,'Value',0)
3834    CheckEditObject_Callback(hObject, eventdata, handles)
[622]3835    UvData.ProjObject={[]};
[387]3836end
[508]3837set(handles.uvmat,'UserData',UvData)
[714]3838set(handles.TransformName,'backgroundColor',[1 1 1])% indicate desactivation  of the menu
3839drawnow
[387]3840
[713]3841%% inputfilerefresh the current plot
[515]3842if isempty(list_path{ichoice}) || nargin(transform_handle)<3
3843    set(handles.SubField,'Value',0)
3844    SubField_Callback(hObject, eventdata, handles)
3845else
[713]3846    REFRESH_Callback(hObject, eventdata, handles)
[515]3847end
[387]3848
3849%------------------------------------------------
3850%CALLBACKS FOR PLOTTING PARAMETERS
3851%-------------------------------------------------
[405]3852%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3853% Plot coordinates
3854%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[387]3855%------------------------------------------------------------------------
3856function num_MinX_Callback(hObject, eventdata, handles)
3857%------------------------------------------------------------------------
3858set(handles.CheckFixLimits,'Value',1) %suppress auto mode
[627]3859% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[387]3860update_plot(handles);
3861
3862%------------------------------------------------------------------------
3863function num_MaxX_Callback(hObject, eventdata, handles)
3864%------------------------------------------------------------------------
3865set(handles.CheckFixLimits,'Value',1) %suppress auto mode
[627]3866% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[387]3867update_plot(handles);
3868
3869%------------------------------------------------------------------------
3870function num_MinY_Callback(hObject, eventdata, handles)
3871%------------------------------------------
3872set(handles.CheckFixLimits,'Value',1) %suppress auto mode
[627]3873% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[387]3874update_plot(handles);
3875
3876%------------------------------------------------------------------------
3877function num_MaxY_Callback(hObject, eventdata, handles)
3878%------------------------------------------------------------------------
3879set(handles.CheckFixLimits,'Value',1) %suppress auto mode
[627]3880% set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
[387]3881update_plot(handles);
3882
[405]3883%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3884% Scalar or image representation
3885%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[387]3886%------------------------------------------------------------------------
3887function num_MinA_Callback(hObject, eventdata, handles)
3888%------------------------------------------
3889set(handles.CheckFixScalar,'Value',1) %suppress auto mode
[627]3890% set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
[387]3891MinA=str2double(get(handles.num_MinA,'String'));
3892MaxA=str2double(get(handles.num_MaxA,'String'));
3893if MinA>MaxA% switch minA and maxA in case of error
3894    MinA_old=MinA;
3895    MinA=MaxA;
3896    MaxA=MinA_old;
3897    set(handles.num_MinA,'String',num2str(MinA,5));
3898    set(handles.num_MaxA,'String',num2str(MaxA,5));
3899end
3900update_plot(handles);
3901
3902%------------------------------------------------------------------------
3903function num_MaxA_Callback(hObject, eventdata, handles)
3904%------------------------------------------------------------------------
3905set(handles.CheckFixScalar,'Value',1) %suppress auto mode
[627]3906% set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
[387]3907MinA=str2double(get(handles.num_MinA,'String'));
3908MaxA=str2double(get(handles.num_MaxA,'String'));
3909if MinA>MaxA% switch minA and maxA in case of error
3910        MinA_old=MinA;
3911    MinA=MaxA;
3912    MaxA=MinA_old;
3913    set(handles.num_MinA,'String',num2str(MinA,5));
3914    set(handles.num_MaxA,'String',num2str(MaxA,5));
3915end
3916update_plot(handles);
3917
3918%------------------------------------------------------------------------
3919function CheckFixScalar_Callback(hObject, eventdata, handles)
3920%------------------------------------------------------------------------
3921test=get(handles.CheckFixScalar,'Value');
3922if test
[627]3923%     set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
[387]3924else
[627]3925%     set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7])
[387]3926    update_plot(handles);
3927end
3928
3929%-------------------------------------------------------------------
3930function CheckBW_Callback(hObject, eventdata, handles)
3931%-------------------------------------------------------------------
3932update_plot(handles);
3933
3934%-------------------------------------------------------------------
[428]3935function num_Opacity_Callback(hObject, eventdata, handles)
3936update_plot(handles);
3937%-------------------------------------------------------------------
3938
3939%-------------------------------------------------------------------
[387]3940function ListContour_Callback(hObject, eventdata, handles)
3941%-------------------------------------------------------------------
3942val=get(handles.ListContour,'Value');
[688]3943if val==2% option 'contours'
[387]3944    set(handles.interval_txt,'Visible','on')
3945    set(handles.num_IncrA,'Visible','on')
[688]3946    set(handles.num_IncrA,'String','')% refresh contour interval
3947%     set(handles.opacity_txt,'Visible','off')
3948%     set(handles.num_Opacity,'Visible','off')
3949else % option 'image'
[387]3950    set(handles.interval_txt,'Visible','off')
3951    set(handles.num_IncrA,'Visible','off')
[688]3952%     set(handles.opacity_txt,'Visible','on')
3953%     set(handles.num_Opacity,'Visible','on')
[387]3954end
3955update_plot(handles);
3956
3957%-------------------------------------------------------------------
3958function num_IncrA_Callback(hObject, eventdata, handles)
3959%-------------------------------------------------------------------
3960update_plot(handles);
3961
[405]3962
3963%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3964% Vector representation
3965%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[387]3966%-------------------------------------------------------------------
3967function CheckHideWarning_Callback(hObject, eventdata, handles)
3968%-------------------------------------------------------------------
3969update_plot(handles);
3970
3971%-------------------------------------------------------------------
3972function CheckHideFalse_Callback(hObject, eventdata, handles)
3973%-------------------------------------------------------------------
3974update_plot(handles);
3975
3976%-------------------------------------------------------------------
3977function num_VecScale_Callback(hObject, eventdata, handles)
3978%-------------------------------------------------------------------
3979set(handles.CheckFixVectors,'Value',1);
3980set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
3981update_plot(handles);
3982
3983%-------------------------------------------------------------------
3984function CheckFixVectors_Callback(hObject, eventdata, handles)
3985%-------------------------------------------------------------------
[688]3986if ~get(handles.CheckFixVectors,'Value')
[387]3987    update_plot(handles);
3988end
3989
3990%------------------------------------------------------------------------
3991% --- Executes on selection change in CheckDecimate4 (nb_vec/4).
[622]3992%------------------------------------------------------------------------
[387]3993function CheckDecimate4_Callback(hObject, eventdata, handles)
[622]3994
[581]3995if isequal(get(handles.CheckDecimate4,'Value'),1)
3996    set(handles.CheckDecimate16,'Value',0)
3997end
[387]3998update_plot(handles);
3999
4000%------------------------------------------------------------------------
[581]4001% --- Executes on selection change in CheckDecimate16 (nb_vec/16).
[622]4002%------------------------------------------------------------------------
[581]4003function CheckDecimate16_Callback(hObject, eventdata, handles)
[622]4004
[581]4005if isequal(get(handles.CheckDecimate16,'Value'),1)
4006    set(handles.CheckDecimate4,'Value',0)
4007end
4008update_plot(handles);
4009
4010%------------------------------------------------------------------------
[405]4011% --- Executes on selection change in ColorCode menu
4012function ColorCode_Callback(hObject, eventdata, handles)
[387]4013%------------------------------------------------------------------------
[405]4014% edit the choice for color code
4015update_color_code_boxes(handles);
4016update_plot(handles);
4017
4018%------------------------------------------------------------------------
4019function update_color_code_boxes(handles)
4020%------------------------------------------------------------------------
4021list_code=get(handles.ColorCode,'String');% list menu fields
4022colcode= list_code{get(handles.ColorCode,'Value')}; % selected field
4023enable_slider='off';%default
4024enable_bounds='off';%default
4025enable_scalar='off';%default
4026switch colcode
4027    case {'rgb','bgr'}
4028        enable_slider='on';
4029        enable_bounds='on';
4030        enable_scalar='on';
4031    case '64 colors'
4032        enable_bounds='on';
4033        enable_scalar='on';
4034end
4035set(handles.Slider1,'Visible',enable_slider)
4036set(handles.Slider2,'Visible', enable_slider)
4037set(handles.num_ColCode1,'Visible',enable_slider)
4038set(handles.num_ColCode2,'Visible',enable_slider)
4039set(handles.TitleColCode1,'Visible',enable_slider)
4040set(handles.TitleColCode2,'Visible',enable_slider)
4041set(handles.CheckFixVecColor,'Visible',enable_bounds)
4042set(handles.num_MinVec,'Visible',enable_bounds)
4043set(handles.num_MaxVec,'Visible',enable_bounds)
4044set(handles.ColorScalar,'Visible',enable_scalar)
[387]4045set_vec_col_bar(handles)
[405]4046
4047%------------------------------------------------------------------
4048% --- Executes on selection change in ColorScalar: choice of the color code.
4049function ColorScalar_Callback(hObject, eventdata, handles)
4050%------------------------------------------------------------------
4051% edit the choice for color code
4052list_scalar=get(handles.ColorScalar,'String');% list menu fields
4053col_scalar= list_scalar{get(handles.ColorScalar,'Value')}; % selected field
4054if isequal(col_scalar,'ima_cor')
4055    set(handles.CheckFixVecColor,'Value',1)%fixed scale by default
4056    ColorCode='rgb';
4057    set(handles.num_MinVec,'String','0')
4058    set(handles.num_MaxVec,'String','1')
4059    set(handles.num_ColCode1,'String','0.333')
4060    set(handles.num_ColCode2,'String','0.666')
4061else
4062    set(handles.CheckFixVecColor,'Value',0)%auto scale between min,max by default
4063    ColorCode='64 colors';
4064end
4065ColorCodeList=get(handles.ColorCode,'String');
4066ichoice=find(strcmp(ColorCode,ColorCodeList),1);
4067set(handles.ColorCode,'Value',ichoice)% set color code in the menu
4068
4069update_color_code_boxes(handles);
4070%replot the current graph
[713]4071REFRESH_Callback(hObject, eventdata, handles)
[405]4072
4073%----------------------------------------------------------------
4074% -- Executes on slider movement to set the color code
4075%
4076function Slider1_Callback(hObject, eventdata, handles)
4077%------------------------------------------------------------------
4078slider1=get(handles.Slider1,'Value');
4079min_val=str2num(get(handles.num_MinVec,'String'));
4080max_val=str2num(get(handles.num_MaxVec,'String'));
4081col=min_val+(max_val-min_val)*slider1;
4082set(handles.num_ColCode1,'String',num2str(col))
4083if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed
4084    set(handles.Slider2,'Value',col)
4085    set(handles.num_ColCode2,'String',num2str(col))
4086end
4087set_vec_col_bar(handles)
[387]4088update_plot(handles);
4089
[405]4090%----------------------------------------------------------------
4091% Executes on slider movement to set the color code
4092%----------------------------------------------------------------
4093function Slider2_Callback(hObject, eventdata, handles)
4094slider2=get(handles.Slider2,'Value');
4095min_val=str2num(get(handles.num_MinVec,'String'));
4096max_val=str2num(get(handles.num_MaxVec,'String'));
4097col=min_val+(max_val-min_val)*slider2;
4098set(handles.num_ColCode2,'String',num2str(col))
4099if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed
4100    set(handles.Slider1,'Value',col)
4101    set(handles.num_ColCode1,'String',num2str(col))
4102end
4103set_vec_col_bar(handles)
4104update_plot(handles);
4105
4106%----------------------------------------------------------------
4107% --- Execute on return carriage on the edit box corresponding to slider 1
4108%----------------------------------------------------------------
4109function num_ColCode1_Callback(hObject, eventdata, handles)
4110set_vec_col_bar(handles)
4111update_plot(handles);
4112
4113%----------------------------------------------------------------
4114% --- Execute on return carriage on the edit box corresponding to slider 2
4115%----------------------------------------------------------------
4116function num_ColCode2_Callback(hObject, eventdata, handles)
4117set_vec_col_bar(handles)
4118update_plot(handles);
[387]4119%------------------------------------------------------------------------
[405]4120%-------------------------------------------------------
[387]4121% --- Executes on button press in CheckFixVecColor.
[405]4122%-------------------------------------------------------
4123function VecColBar_Callback(hObject, eventdata, handles)
4124set_vec_col_bar(handles)
4125
4126%------------------------------------------------------------------------
4127% --- Executes on button press in CheckFixVecColor.
[387]4128function CheckFixVecColor_Callback(hObject, eventdata, handles)
4129%------------------------------------------------------------------------
[405]4130if ~get(handles.CheckFixVecColor,'Value')
[387]4131    update_plot(handles);
4132end
4133
4134%------------------------------------------------------------------------
4135% --- Executes on selection change in num_MaxVec.
4136function num_MinVec_Callback(hObject, eventdata, handles)
4137%------------------------------------------------------------------------
[654]4138num_MaxVec_Callback(hObject, eventdata, handles)
[387]4139
4140%------------------------------------------------------------------------
4141% --- Executes on selection change in num_MaxVec.
4142function num_MaxVec_Callback(hObject, eventdata, handles)
4143%------------------------------------------------------------------------
4144set(handles.CheckFixVecColor,'Value',1)
4145CheckFixVecColor_Callback(hObject, eventdata, handles)
4146min_val=str2num(get(handles.num_MinVec,'String'));
4147max_val=str2num(get(handles.num_MaxVec,'String'));
4148slider1=get(handles.Slider1,'Value');
4149slider2=get(handles.Slider2,'Value');
4150colcode1=min_val+(max_val-min_val)*slider1;
4151colcode2=min_val+(max_val-min_val)*slider2;
4152set(handles.num_ColCode1,'String',num2str(colcode1))
4153set(handles.num_ColCode2,'String',num2str(colcode2))
4154update_plot(handles);
4155
4156%------------------------------------------------------------------------
[405]4157% --- update the display of color code for vectors (on vecColBar)
[387]4158function set_vec_col_bar(handles)
4159%------------------------------------------------------------------------
4160%get the image of the color display button 'VecColBar' in pixels
4161set(handles.VecColBar,'Unit','pixel');
4162pos_vert=get(handles.VecColBar,'Position');
4163set(handles.VecColBar,'Unit','Normalized');
4164width=ceil(pos_vert(3));
4165height=ceil(pos_vert(4));
4166
4167%get slider indications
[405]4168list=get(handles.ColorCode,'String');
4169ichoice=get(handles.ColorCode,'Value');
4170colcode.ColorCode=list{ichoice};
[387]4171colcode.MinVec=str2num(get(handles.num_MinVec,'String'));
4172colcode.MaxVec=str2num(get(handles.num_MaxVec,'String'));
[405]4173test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
[387]4174if test3color
4175    colcode.ColCode1=str2num(get(handles.num_ColCode1,'String'));
4176    colcode.ColCode2=str2num(get(handles.num_ColCode2,'String'));
4177end
4178vec_C=colcode.MinVec+(colcode.MaxVec-colcode.MinVec)*(0.5:width-0.5)/width;%sample of vec_C values from min to max
4179[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4180oneheight=ones(1,height);
4181A1=colorlist(col_vec,1)*oneheight;
4182A2=colorlist(col_vec,2)*oneheight;
4183A3=colorlist(col_vec,3)*oneheight;
4184A(:,:,1)=A1';
4185A(:,:,2)=A2';
4186A(:,:,3)=A3';
4187set(handles.VecColBar,'Cdata',A)
4188
4189%-------------------------------------------------------------------
4190function update_plot(handles)
4191%-------------------------------------------------------------------
[713]4192set(handles.REFRESH,'BackgroundColor',[1 1 0]);% display plot activity by yellow color
[688]4193drawnow
[387]4194UvData=get(handles.uvmat,'UserData');
[511]4195AxeData=UvData.PlotAxes;% retrieve the current plotted data
[387]4196PlotParam=read_GUI(handles.uvmat);
[511]4197[tild,PlotParamOut]= plot_field(AxeData,handles.PlotAxes,PlotParam);
[595]4198errormsg=fill_GUI(PlotParamOut,handles.uvmat);
[688]4199if ~isempty(errormsg)
4200    msgbox_uvmat('ERROR',errormsg)
4201    return
[681]4202end
[713]4203set(handles.REFRESH,'BackgroundColor',[1 0 0]);
[387]4204
[402]4205%------------------------------------------------------------------------
4206%------------------------------------------------------------------------
4207%   SELECTION AND EDITION OF PROJECTION OBJECTS
4208%------------------------------------------------------------------------
4209%------------------------------------------------------------------------
[387]4210
[410]4211% --- Executes on selection change in ListObject_1.
4212function ListObject_1_Callback(hObject, eventdata, handles)
[432]4213list_str=get(handles.ListObject,'String');
[410]4214UvData=get(handles.uvmat,'UserData');
[622]4215ObjectData=UvData.ProjObject{get(handles.ListObject_1,'Value')};
[410]4216
4217%% update the projection plot on uvmat
[432]4218ProjData= proj_field(UvData.Field,ObjectData);%project the current input field on object ObjectData
[511]4219plot_field(ProjData,handles.PlotAxes,read_GUI(handles.uvmat));% plot the projected field;
[432]4220%replot all the objects within the new projected field
4221for IndexObj=1:numel(list_str)
[622]4222        hobject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
[432]4223        if isempty(hobject) || ~ishandle(hobject)
[515]4224            hobject=handles.PlotAxes;
[432]4225        end
4226        if isequal(IndexObj,get(handles.ListObject,'Value'))
4227            objectcolor='m'; %paint in magenta the currently selected object in ListObject
4228        else
4229            objectcolor='b';
4230        end
[622]4231        UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=plot_object(UvData.ProjObject{IndexObj},ObjectData,hobject,objectcolor);%draw the object in uvmat     
[432]4232end
4233set(handles.uvmat,'UserData',UvData)
[410]4234
4235%% display the object parameters if the GUI set_object is already opened
[650]4236if ~get(handles.CheckViewObject,'Value')
[410]4237    ZBounds=0; % default
4238    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4239        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4240        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4241    end
[425]4242    ObjectData.Name=list_str{get(handles.ListObject_1,'Value')};
[410]4243    set_object(ObjectData,[],ZBounds);
[650]4244    set(handles.CheckViewObject,'Value',1)% show that the selected object in ListObject_1 is currently visualised
[410]4245end
[432]4246
[410]4247%  desactivate the edit object mode
[650]4248set(handles.CheckEditObject,'Value',0)
4249% set(handles.CheckEditObject,'BackgroundColor',[0.7,0.7,0.7])
[410]4250
[387]4251%------------------------------------------------------------------------
4252% --- Executes on selection change in ListObject.
4253function ListObject_Callback(hObject, eventdata, handles)
4254%------------------------------------------------------------------------
4255list_str=get(handles.ListObject,'String');
4256IndexObj=get(handles.ListObject,'Value');%present object selection
[402]4257UvData=get(handles.uvmat,'UserData');
[622]4258ObjectData=UvData.ProjObject{IndexObj};
[402]4259    ZBounds=0; % default
4260    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4261        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4262        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4263    end
[625]4264
4265%% show object features if view_object isselected
[650]4266if get(handles.CheckViewObject,'value')
[402]4267    set_object(ObjectData,[],ZBounds);
4268end
[429]4269
[625]4270%% The object  is displayed in set_object if this GUI is already opened
4271%
4272% hset_object=findobj(allchild(0),'tag','set_object');
4273% if ~isempty(hset_object)
4274%
4275%     ObjectData.Name=list_str{IndexObj};
4276%     set_object(ObjectData,[],ZBounds);
[650]4277%     set(handles.CheckViewField,'Value',1)% show that the selected object in ListObject is currently visualised
[625]4278% end
4279
4280%%  desactivate the edit object mode for security
[650]4281set(handles.CheckEditObject,'Value',0)
[625]4282
[650]4283% set(handles.CheckEditObject,'BackgroundColor',[0.7,0.7,0.7])
[402]4284
[429]4285%% update the  plot on view_field if view_field is already openened
4286hview_field=findobj(allchild(0),'tag','view_field');
4287if isempty(hview_field)
[511]4288    hhview_field.PlotAxes=[];
[429]4289else
4290    Data=get(hview_field,'UserData');
4291    hhview_field=guidata(hview_field);
4292    ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
[595]4293    [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the uvmat interface
4294   
4295    %write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
[429]4296    haxes=findobj(hview_field,'tag','axes3');
4297    pos=get(hview_field,'Position'); 
4298    if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
4299        h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
4300        pos_table=get(h_TableDisplay,'Position');
4301        set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
4302        drawnow% needed to change position before the next command
4303        set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
4304    else
[644]4305%         set(hview_field,'Position',Data.GUISize)% return to the previously stored GUI position and size
[387]4306    end
4307end
4308
[402]4309%% update the color of the graphic object representation: the selected object in magenta, others in blue
[622]4310update_object_color(handles.PlotAxes,hhview_field.PlotAxes,UvData.ProjObject{IndexObj}.DisplayHandle.uvmat)
[387]4311
4312%------------------------------------------------------------------------
[402]4313%--- update the color representation of objects (indicating the selected ones)
4314function update_object_color(axes_uvmat,axes_view_field,DisplayHandle)
[387]4315%------------------------------------------------------------------------
[402]4316if isempty(axes_view_field)% case with no view_field plot
4317hother=[findobj(axes_uvmat,'Tag','proj_object');findobj(axes_uvmat,'Tag','DeformPoint')];%find all the proj object and deform point representations
[387]4318else
[402]4319hother=[findobj(axes_uvmat,'Tag','proj_object') ;findobj(axes_view_field,'Tag','proj_object');... %find all the proj object representations
4320findobj(axes_uvmat,'Tag','DeformPoint'); findobj(axes_view_field,'Tag','DeformPoint')];%find all the deform point representations
[387]4321end
4322for iobj=1:length(hother)
4323    if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
4324        set(hother(iobj),'EdgeColor','b')
4325        if isequal(get(hother(iobj),'FaceColor'),'m')
4326            set(hother(iobj),'FaceColor','b')
4327        end
4328    elseif isequal(get(hother(iobj),'Type'),'image')
4329        Acolor=get(hother(iobj),'CData');
4330        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4331        set(hother(iobj),'CData',Acolor);
4332    else
4333        set(hother(iobj),'Color','b')
4334    end
4335    set(hother(iobj),'Selected','off')
4336end
[432]4337if ishandle(DisplayHandle)
[402]4338    linetype=get(DisplayHandle,'Type');
4339    if isequal(linetype,'line')
4340        set(DisplayHandle,'Color','m'); %set the selected object to magenta color
4341    elseif isequal(linetype,'rectangle')
4342        set(DisplayHandle,'EdgeColor','m'); %set the selected object to magenta color
4343    elseif isequal(linetype,'patch')
4344        set(DisplayHandle,'FaceColor','m'); %set the selected object to magenta color
4345    end
4346    SubObjectData=get(DisplayHandle,'UserData');
4347    if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
4348        for iobj=1:length(SubObjectData.SubObject)
4349            hsub=SubObjectData.SubObject(iobj);
4350            if isequal(get(hsub,'Type'),'rectangle')
4351                set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4352            elseif isequal(get(hsub,'Type'),'image')
4353                Acolor=get(hsub,'CData');
4354                Acolor(:,:,1)=Acolor(:,:,3);
4355                set(hsub,'CData',Acolor);
4356            else
4357                set(hsub,'Color','m')
4358            end
[387]4359        end
4360    end
[402]4361    if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
4362        set(SubObjectData.DeformPoint,'Color','m')
4363    end
[387]4364end
[402]4365
[427]4366%-------------------------------------------------------------------
[650]4367% --- Executes on selection change in CheckEditObject.
4368function CheckEditObject_Callback(hObject, eventdata, handles)
[427]4369%-------------------------------------------------------------------
4370hset_object=findobj(allchild(0),'Tag','set_object');
[650]4371if get(handles.CheckEditObject,'Value')
[427]4372    %suppress the other options
[701]4373    set(handles.MenuObject,'checked','off')
[427]4374    set(handles.CheckZoom,'Value',0)
4375    CheckZoom_Callback(hObject, eventdata, handles)
4376    hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4377    if ishandle(hgeometry_calib)
4378        hhgeometry_calib=guidata(hgeometry_calib);
[660]4379        set(hhgeometry_calib.CheckEnableMouse,'Value',0)% desactivate mouse action in geometry_calib
[682]4380        set(hhgeometry_calib.CheckEnableMouse,'BackgroundColor',[0.7 0.7 0.7])
[427]4381    end
[650]4382    set(handles.CheckViewObject,'value',1)
4383    CheckViewObject_Callback(hObject, eventdata, handles)
[625]4384else % desactivate object edit mode
[427]4385    if ~isempty(hset_object)% open the
[625]4386        set(get(hset_object,'children'),'Enable','off')
4387        hSAVE=findobj(hset_object,'Tag','SAVE');
4388        set(hSAVE,'Enable','on')
[427]4389    end
4390end
4391
4392
[402]4393%------------------------------------------------------------------------
[650]4394% --- Executes on button press in CheckViewObject.
4395function CheckViewObject_Callback(hObject, eventdata, handles)
[410]4396%------------------------------------------------------------------------
[650]4397check_view=get(handles.CheckViewObject,'Value');
[410]4398
4399if check_view %activate set_object   
[424]4400    IndexObj=get(handles.ListObject,'Value');
4401    list_object=get(handles.ListObject,'String');
[410]4402    UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
[622]4403    UvData.ProjObject{IndexObj}.Name=list_object{IndexObj};
4404    if numel(UvData.ProjObject)<IndexObj;% error in UvData
[410]4405        msgbox_uvmat('ERROR','invalid object list')
4406        return
4407    end
4408    ZBounds=0; % default
4409    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4410        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4411        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4412    end
[622]4413    data=UvData.ProjObject{IndexObj};
[410]4414    if ~isfield(data,'Type')% default plane
4415        data.Type='plane';
4416    end
4417    hset_object=set_object(data,[],ZBounds);
4418    hhset_object=guidata(hset_object);
[650]4419    if get(handles.CheckEditObject,'Value')% edit mode
[625]4420        set(get(hset_object,'children'),'Enable','on')
[410]4421    else
[625]4422        set(get(hset_object,'children'),'Enable','off')% deactivate the GUI except SAVE
[427]4423        set(hhset_object.SAVE,'Enable','on')
[410]4424    end
4425else
4426    hset_object=findobj(allchild(0),'tag','set_object');
4427    if ~isempty(hset_object)
4428        delete(hset_object)% delete existing version of set_object
4429    end
4430end
4431 
[424]4432
[410]4433%------------------------------------------------------------------------
[650]4434% --- Executes on button press in CheckViewField.
4435function CheckViewField_Callback(hObject, eventdata, handles)
[402]4436%------------------------------------------------------------------------
[650]4437check_view=get(handles.CheckViewField,'Value');
[387]4438
[410]4439if check_view
4440    IndexObj=get(handles.ListObject,'Value');
4441    UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
[622]4442    if numel(UvData.ProjObject)<IndexObj(end);% error in UvData
[410]4443        msgbox_uvmat('ERROR','invalid object list')
4444        return
4445    end
4446    ZBounds=0; % default
4447    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4448        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4449        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4450    end
4451    set(handles.ListObject,'Value',IndexObj);%restore ListObject selection after set_object deletion
[622]4452    if ~isfield(UvData.ProjObject{IndexObj(1)},'Type')% default plane
4453        UvData.ProjObject{IndexObj(1)}.Type='plane';
[410]4454    end
4455    list_object=get(handles.ListObject,'String');
[622]4456    UvData.ProjObject{IndexObj(end)}.Name=list_object{IndexObj(end)};
[410]4457   
[429]4458    %% show the projection of the selected object on view_field
[622]4459    ProjData= proj_field(UvData.Field,UvData.ProjObject{IndexObj});%project the current field on ObjectData
[402]4460    hview_field=findobj(allchild(0),'tag','view_field');
4461    if isempty(hview_field)
4462        hview_field=view_field;
4463    end
[429]4464    hhview_field=guidata(hview_field);
[511]4465    [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the GUI view_field);
[595]4466    errormsg=fill_GUI(PlotParam,hview_field);
[609]4467    for list={'Scalar','Vectors'}
4468        if ~isfield(PlotParam,list{1})
4469            set(hhview_field.(list{1}),'Visible','off')
4470        end
4471    end
[595]4472    %write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
[429]4473    haxes=findobj(hview_field,'tag','axes3');
4474    pos=get(hview_field,'Position');
4475    if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
4476        h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
4477        pos_table=get(h_TableDisplay,'Position');
4478        set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
4479    else
4480        Data=get(hview_field,'UserData');
[644]4481%         set(hview_field,'Position',Data.GUISize)% restore the size of view_field for plots
[429]4482    end
[410]4483else
[424]4484    hview_field=findobj(allchild(0),'tag','view_field');
4485    if ~isempty(hview_field)
4486        delete(hview_field)% delete existing version of set_object
[410]4487    end
[402]4488end
4489
[424]4490
[402]4491%------------------------------------------------------------------------
[650]4492% --- Executes on button press in DeleteObject.
[622]4493%------------------------------------------------------------------------
[650]4494function DeleteObject_Callback(hObject, eventdata, handles)
[622]4495
[499]4496IndexObj=get(handles.ListObject,'Value');%projection object selected for view_field
4497IndexObj_1=get(handles.ListObject_1,'Value');%projection object selected for uvmat plot
4498if IndexObj>1 && ~isequal(IndexObj,IndexObj_1) % do not delete the object used for the uvmat plot
[410]4499    delete_object(IndexObj)
[402]4500end
4501
[650]4502%'DeleteObject': delete a projection object, defined by its index in the Uvmat list or by its graphic handle
[402]4503%------------------------------------------------------------------------
[650]4504% function DeleteObject(hObject)
[622]4505%
4506% INPUT:
4507% hObject: object index (if integer) or handle of the graphic object. If
4508%          hObject is a subobject, the parent object is detected and deleted.
4509
4510function delete_object(IndexObj)
4511
4512huvmat=findobj('tag','uvmat');%handles of the uvmat interface
4513UvData=get(huvmat,'UserData');
4514hlist_object=findobj(huvmat,'Tag','ListObject');%handles of the object list in the uvmat interface
4515list_str=get(hlist_object,'String');%objet list
[648]4516if  ~isempty(UvData) && isfield(UvData, 'ProjObject') && length(UvData.ProjObject)>=IndexObj
4517    if isfield(UvData.ProjObject{IndexObj},'DisplayHandle') && isfield(UvData.ProjObject{IndexObj}.DisplayHandle,'uvmat')
[681]4518        hdisplay=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;%handle of the object graphic representation in uvmat
[648]4519        for iview=1:length(hdisplay)
4520            if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0)
4521                ObjectData=get(hdisplay(iview),'UserData');
[701]4522                if isfield(ObjectData,'SubObject') && ~isempty(ObjectData.SubObject)
4523                    delete(ObjectData.SubObject(ishandle(ObjectData.SubObject)));% delete the graphic 'sub-objects (e.g. projection bounds)
[648]4524                end
[701]4525                if isfield(ObjectData,'DeformPoint')&& ~isempty(ObjectData.DeformPoint)
4526                    delete(ObjectData.DeformPoint(ishandle(ObjectData.DeformPoint)));% delete the graphic deformation points
4527                    delete(hdisplay(iview))% delete the main graphic representation of the object
4528                end
[648]4529            end
4530            ishandle(hdisplay(iview))
4531        end
4532        for iobj=IndexObj+1:length(UvData.ProjObject)
4533            hdisplay=UvData.ProjObject{iobj}.DisplayHandle.uvmat;
[622]4534            for iview=1:length(hdisplay)
4535                if ishandle(hdisplay(iview)) && ~isequal(hdisplay(iview),0)
[648]4536                    PlotData=get(hdisplay(iview),'UserData');
4537                    PlotData.IndexObj=iobj-1;
4538                    set(hdisplay(iview),'UserData',PlotData);
[622]4539                end
4540            end
4541        end
4542    end
[648]4543    UvData.ProjObject(IndexObj)=[];
4544    if ~isempty(list_str)
4545        list_str(IndexObj)=[];
4546    end
4547end
[622]4548set(huvmat,'UserData',UvData);
4549set(hlist_object,'String',list_str)
4550set(hlist_object,'Value',length(list_str))
4551hlist_object_1=findobj(huvmat,'Tag','ListObject_1');%handles of the first object list in the uvmat interface
4552old_index=get(hlist_object_1,'Value');
4553set(hlist_object_1,'String',list_str)
4554if IndexObj<=old_index
4555    set(hlist_object_1,'Value',old_index-1)
4556end
4557
[402]4558%------------------------------------------------------------------------
[622]4559%------------------------------------------------------------------------
[402]4560%  II - TOOLS FROM THE UPPER MENU BAR
4561%------------------------------------------------------------------------
4562%------------------------------------------------------------------------
4563
4564%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4565% Export  Menu Callbacks
4566%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4567%------------------------------------------------------------------------
[387]4568% --- Executes on button press in Menu/Export/field in workspace.
4569function MenuExportField_Callback(hObject, eventdata, handles)
[402]4570%------------------------------------------------------------------------
[387]4571global Data_uvmat
4572Data_uvmat=get(handles.uvmat,'UserData');
4573evalin('base','global Data_uvmat')%make CurData global in the workspace
4574display('current field :')
4575evalin('base','Data_uvmat') %display CurData in the workspace
4576commandwindow; %brings the Matlab command window to the front
4577
[402]4578%------------------------------------------------------------------------
[387]4579% --- Executes on button press in Menu/Export/extract figure.
[402]4580function MenuExportFigure_Callback(hObject, eventdata, handles)
4581%------------------------------------------------------------------------
[387]4582hfig=figure;
[511]4583copyobj(handles.PlotAxes,hfig);
[713]4584h=findobj(handles.PlotAxes,'tag','ima'); %look for image in the plot
4585if ~isempty(h)
[511]4586map=colormap(handles.PlotAxes);
[387]4587colormap(map);%transmit the current colormap to the zoom fig
4588colorbar
[713]4589end
[387]4590
[508]4591% --------------------------------------------------------------------
4592function MenuExportAxis_Callback(hObject, eventdata, handles)
[581]4593ListFig=findobj(allchild(0),'Type','figure');
4594nb_option=0;
4595menu={};
4596for ilist=1:numel(ListFig)
4597    FigName=get(ListFig(ilist),'name');
4598    if isempty(FigName)
4599        FigName=['figure ' num2str(ListFig(ilist))];
4600    end
4601    if ~strcmp(FigName,'uvmat')
4602        ListAxes=findobj(ListFig(ilist),'Type','axes');
4603        ListTags=get(ListAxes,'Tag');
4604        if ~isempty(ListTags) && ~isempty(find(~strcmp('Colorbar',ListTags), 1))
4605            ListAxes=ListAxes(~strcmp('Colorbar',ListTags));
4606            if numel(ListAxes)==1
4607                nb_option=nb_option+1;
4608                menu{nb_option}=FigName ;
4609                AxesHandle(nb_option)=ListAxes;
4610            else
4611                nb_axis=0;
4612                for iaxes=1:numel(ListAxes)
4613                    nb_axis=nb_axis+1;
4614                    nb_option=nb_option+1;
4615                    menu{nb_option}=[FigName '_' num2str(nb_axis)];
4616                    AxesHandle(nb_option)=ListAxes(nb_axis);
4617                end
4618            end
4619        end
4620    end
[508]4621end
[581]4622if isempty(menu)
4623    answer=msgbox_uvmat('INPUT_Y-N','no existing plotting axes available, create new figure?');
4624    if strcmp(answer,'Yes')
4625        hfig=figure;
4626        copyobj(handles.PlotAxes,hfig);
4627    else
4628        return
4629    end
4630    map=colormap(handles.PlotAxes);
4631    colormap(map);%transmit the current colormap to the zoom fig
4632    colorbar
4633else
4634    answer=msgbox_uvmat('INPUT_MENU','select a figure/axis on which the current uvmat plot will be exported',menu);
4635    if isempty(answer)
4636        return
4637    else
4638        axes(AxesHandle(answer))
4639        hold on
4640        hchild=get(handles.PlotAxes,'children');
4641        copyobj(hchild,gca);
4642    end
4643end
[387]4644
[581]4645
[387]4646%------------------------------------------------------------------------
4647% --------------------------------------------------------------------
4648function MenuExportMovie_Callback(hObject, eventdata, handles)
4649% --------------------------------------------------------------------
4650set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
[713]4651huvmat=get(handles.InputFileREFRESH,'parent');
[387]4652UvData=get(huvmat,'UserData');
4653%[xx,xx,FileBase]=read_file_boxes(handles);
[515]4654[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
[387]4655FileBase=fullfile(RootPath,RootFile);
4656 %read the current input file name
4657prompt = {'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)'};
4658dlg_title = 'select properties of the output avi movie';
4659num_lines= 1;
4660def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4661answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4662aviname=answer{1};
4663fps=str2double(answer{2});
4664% check for existing file with output name aviname
4665if exist(aviname,'file')
4666    backup=aviname;
4667    testexist=2;
4668    while testexist==2
4669        backup=[backup '~'];
4670        testexist=exist(backup,'file');     
4671    end
4672    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4673    if isequal(success,1)
4674        delete(aviname)%delete existing file
4675    else
4676        msgbox_uvmat('ERROR',message)
4677        return
4678    end
4679end
4680%create avi open
4681aviobj=avifile(aviname,'Compression','None','fps',fps);
4682
4683%display first view for tests
4684newfig=figure;
[511]4685newaxes=copyobj(handles.PlotAxes,newfig);%new plotting axes in the new figure
[387]4686set(newaxes,'Tag','movieaxes')
4687nbpix=[512 384]*str2double(answer{3});
4688set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4689set(newaxes,'Position',eval(answer{4}));
[511]4690map=colormap(handles.PlotAxes);
[387]4691colormap(map);%transmit the current colormap to the zoom fig
4692msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4693        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
4694UvData.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
4695set(huvmat,'UserData',UvData);
[511]4696increment=str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d
[387]4697set(handles.STOP,'Visible','on')
4698set(handles.speed,'Visible','on')
4699set(handles.speed_txt,'Visible','on')
4700set(handles.Movie,'BusyAction','queue')
4701
4702%imin=str2double(get(handles.i1,'String'));
4703imax=str2double(answer{5});
4704% if isfield(UvData,'Time')
4705htitle=get(newaxes,'Title');
4706xlim=get(newaxes,'XLim');
4707ylim=get(newaxes,'YLim');
4708set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
[648]4709time_str=get(handles.TimeValue,'String');
[387]4710set(htitle,'String',['t=' time_str])
4711set(handles.speed,'Value',1)
4712for i=1:imax
4713    if get(handles.speed,'Value')~=0 && isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4714            runpm(hObject,eventdata,handles,increment)% run plus
4715            drawnow
[648]4716            time_str=get(handles.TimeValue,'String');
[387]4717            if ishandle(htitle)
4718             set(htitle,'String',['t=' time_str])
4719            end
4720            mov=getframe(newfig);
4721            aviobj=addframe(aviobj,mov);
4722    end
4723end
4724aviobj=close(aviobj);
4725UvData=rmfield(UvData,'plotaxes');
4726set(huvmat,'UserData',UvData);
4727msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4728
[402]4729
4730%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4731% Projection Objects Menu Callbacks
4732%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4733
4734% -----------------------------------------------------------------------
4735function Menupoints_Callback(hObject, eventdata, handles)
[387]4736%------------------------------------------------------------------------
[402]4737data.Type='points';
4738data.ProjMode='projection';%default
[410]4739data.ProjModeMenu={};% do not restrict ProjMode menus
[402]4740create_object(data,handles)
4741
4742% -----------------------------------------------------------------------
[650]4743% --- Callback of the Menu command line
4744%------------------------------------------------------------------------
[402]4745function Menuline_Callback(hObject, eventdata, handles)
4746%------------------------------------------------------------------------
4747data.Type='line';
4748data.ProjMode='projection';%default
[410]4749data.ProjModeMenu={};% do not restrict ProjMode menus
[402]4750create_object(data,handles)
4751
[650]4752% -----------------------------------------------------------------------
4753% --- Callback of the Menu command line_x
[402]4754%------------------------------------------------------------------------
[650]4755function Menuline_x_Callback(hObject, eventdata, handles)
[674]4756
[650]4757data.Type='line_x';
4758data.ProjMode='projection';%default
4759data.ProjModeMenu={};% do not restrict ProjMode menus
4760create_object(data,handles)
4761
4762% -----------------------------------------------------------------------
4763% --- Callback of the Menu command line_y
4764% -----------------------------------------------------------------------
4765function Menuline_y_Callback(hObject, eventdata, handles)
[674]4766
[650]4767data.Type='line_y';
4768data.ProjMode='projection';%default
4769data.ProjModeMenu={};% do not restrict ProjMode menus
4770create_object(data,handles)
4771
4772%------------------------------------------------------------------------
[402]4773function Menupolyline_Callback(hObject, eventdata, handles)
4774%------------------------------------------------------------------------
4775data.Type='polyline';
4776data.ProjMode='projection';%default
[410]4777data.ProjModeMenu={};% do not restrict ProjMode menus
[402]4778create_object(data,handles)
4779
4780%------------------------------------------------------------------------
4781function Menupolygon_Callback(hObject, eventdata, handles)
4782%------------------------------------------------------------------------
4783data.Type='polygon';
4784data.ProjMode='inside';%default
[410]4785data.ProjModeMenu={};% do not restrict ProjMode menus
[402]4786create_object(data,handles)
4787
4788%------------------------------------------------------------------------
4789function Menurectangle_Callback(hObject, eventdata, handles)
4790%------------------------------------------------------------------------
4791data.Type='rectangle';
4792data.ProjMode='inside';%default
[410]4793data.ProjModeMenu={};% do not restrict ProjMode menus
[402]4794create_object(data,handles)
4795
4796%------------------------------------------------------------------------
4797function Menuellipse_Callback(hObject, eventdata, handles)
4798%------------------------------------------------------------------------
4799data.Type='ellipse';
4800data.ProjMode='inside';%default
[410]4801data.ProjModeMenu={};% do not restrict ProjMode menus
[402]4802create_object(data,handles)
4803
4804%------------------------------------------------------------------------
4805function MenuMaskObject_Callback(hObject, eventdata, handles)
4806%------------------------------------------------------------------------
4807data.Type='polygon';
4808data.TypeMenu={'polygon'};
4809data.ProjMode='mask_inside';%default
4810data.ProjModeMenu={'mask_inside';'mask_outside'};
4811create_object(data,handles)
4812
4813%------------------------------------------------------------------------
4814function Menuplane_Callback(hObject, eventdata, handles)
4815%------------------------------------------------------------------------
4816data.Type='plane';
4817data.ProjMode='projection';%default
[410]4818data.ProjModeMenu={};% do not restrict ProjMode menus
[402]4819create_object(data,handles)
4820
4821%------------------------------------------------------------------------
4822function Menuvolume_Callback(hObject, eventdata, handles)
4823%------------------------------------------------------------------------
4824data.Type='volume';
[581]4825data.ProjMode='interp_lin';%default
[410]4826data.ProjModeMenu={};
[402]4827% set(handles.create,'Visible','on')
4828% set(handles.create,'Value',1)
[410]4829% VOLUME_Callback(hObject,eventdata,handles)data.ProjModeMenu={};
[402]4830create_object(data,handles)
4831
4832%------------------------------------------------------------------------
4833% --- generic function used for the creation of a projection object
4834function create_object(data,handles)
4835%------------------------------------------------------------------------
[622]4836%% desactivate concurrent tools
4837hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');% search the GUI geometric calibration
[402]4838if ishandle(hgeometry_calib)
4839    hhgeometry_calib=guidata(hgeometry_calib);
[660]4840    set(hhgeometry_calib.CheckEnableMouse,'Value',0)% desactivate mouse action in geometry_calib
[682]4841    set(hhgeometry_calib.CheckEnableMouse,'BackgroundColor',[0.7 0.7 0.7])
[402]4842end
[650]4843set(handles.CheckEditObject,'Value',0)  %desactivate the object edit mode
4844CheckEditObject_Callback([],[],handles)
4845set(handles.CheckViewObject,'Value',0) % desactivate view_object (new object created)
[622]4846set(handles.CheckZoomFig,'Value',0) %desactivate zoom sub fig
4847set(handles.CheckZoom,'Value',0)    %desactivate the zoom action
[701]4848set(handles.MenuObject,'checked','on')% indicate object creation for mouse pointer display
[622]4849if ishandle(handles.UVMAT_title)
4850    delete(handles.UVMAT_title)     %delete the initial display of uvmat if no field has been entered yet
4851end
4852
[648]4853%% initiate the new projection object
[410]4854UvData=get(handles.uvmat,'UserData');
4855data.Name=data.Type;% default name=type
[402]4856data.Coord=[0 0]; %default
[674]4857check_plot=0;
[402]4858if isfield(UvData,'Field')
4859    Field=UvData.Field;
[674]4860    if isfield(Field,'NbDim')&& isequal(Field.NbDim,3)
4861         data.Coord=[0 0 0]; %default
4862    end
4863    if isfield(Field,'CoordUnit')
4864        data.CoordUnit=Field.CoordUnit;
4865    end
[575]4866    if isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh)
[404]4867        data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
[650]4868        switch data.Type
4869            case {'line','polyline','points'}
4870                data.RangeY=UvData.Field.CoordMesh;
4871            case 'line_x'
[674]4872                check_plot=1; %plot the line directly when set_object is opened
4873                data.Type='line';
4874                data.RangeX=UvData.Field.XMin ;
[650]4875                data.RangeY=UvData.Field.CoordMesh;
[674]4876                data.Coord=[UvData.Field.XMin (UvData.Field.YMin +UvData.Field.YMax)/2;...
4877                           UvData.Field.XMax (UvData.Field.YMin +UvData.Field.YMax)/2];% put line at the middle of the y axis
[650]4878            case 'line_y'
[674]4879                check_plot=1; %plot the line directly when set_object is opened
4880                data.Type='line';
4881                data.RangeX=UvData.Field.YMin ;
[650]4882                data.RangeY=UvData.Field.CoordMesh;
[674]4883                data.Coord=[(UvData.Field.XMin+UvData.Field.XMax)/2 UvData.Field.YMin;...
4884                            (UvData.Field.XMin +UvData.Field.XMax)/2 UvData.Field.YMax];% put line at the middle of the y axis
[650]4885            case {'rectangle','ellipse'}
4886                data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
4887                data.RangeX=UvData.Field.CoordMesh;
4888                data.RangeY=UvData.Field.CoordMesh;
4889            otherwise
4890                data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
[406]4891        end
[575]4892        data.DX=UvData.Field.CoordMesh;
4893        data.DY=UvData.Field.CoordMesh;
[402]4894    end
4895end
[674]4896
[622]4897hset_object=set_object(data,handles);% call the GUI set_object
[421]4898hchild=get(hset_object,'children');
4899set(hchild,'enable','on')
[650]4900set(handles.DeleteObject,'Visible','on')% make the object delete button visible
[674]4901if check_plot
4902    hhset_object=guidata(hset_object);
[680]4903    set_object('REFRESH_Callback',1,[],hhset_object);% call the GUI set_object
[674]4904end
[689]4905set(handles.CheckViewField,'Visible','on')
4906set(handles.DeleteObject,'Visible','on')
4907set(handles.ListObject_1,'Visible','on')
4908set(handles.ListObject_1_title,'Visible','on')
[622]4909
[402]4910%------------------------------------------------------------------------
4911function MenuBrowseObject_Callback(hObject, eventdata, handles)
4912%------------------------------------------------------------------------
[680]4913%get the object file
[667]4914fileinput=uigetfile_uvmat('pick an xml object file:',get(handles.RootPath,'String'),'.xml');
4915if ~isempty(fileinput)
4916    %read the file
4917    [data,heading]=xml2struct(fileinput);
4918    if ~strcmp(heading,'ProjObject')
4919        msgbox_uvmat('WARNING','The xml file does not have the heading ProjObject for projection objects')
4920    end
4921    ListObject=get(handles.ListObject,'String');
[680]4922    ListObject=[ListObject;{data.Name}];
4923    IndexObj=length(ListObject);
[667]4924    UvData=get(handles.uvmat,'UserData');
4925    UvData.ProjObject{IndexObj}=[]; %create a new empty object
4926    UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=[]; %no plot handle before plot_field operation
4927    UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
4928    set(handles.uvmat,'UserData',UvData)
4929    set(handles.CheckViewObject,'Value',1)
4930    set(handles.CheckViewField,'Value',1)
4931    hset_object=set_object(data);% call the set_object interface
4932    hhset_object=guidata(hset_object);
[680]4933    set_object('REFRESH_Callback',hObject,eventdata,hhset_object);% plot projection
[667]4934    set(handles.CheckEditObject,'Value',0); %suppress the object edit mode
4935    CheckEditObject_Callback([],[],handles)
4936    set(handles.DeleteObject,'Visible','on')
[477]4937end
[445]4938
[402]4939%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4940% MenuTools Callbacks
4941%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4942%------------------------------------------------------------------------
[387]4943function MenuCalib_Callback(hObject, eventdata, handles)
4944%------------------------------------------------------------------------
4945
4946UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4947
4948%suppress competing options
4949set(handles.CheckZoom,'Value',0)
4950set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
4951set(handles.ListObject,'Value',1)     
4952% initiate display of GUI geometry_calib
4953data=[]; %default
4954if isfield(UvData,'CoordType')
4955    data.CoordType=UvData.CoordType;
4956end
[515]4957[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
4958FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
[710]4959set(handles.view_xml,'BackgroundColor',[1 1 0])%indicate the reading of the current xml file by geometry_calib
[657]4960geometry_calib(FileName);% call the geometry_calib interface   
[710]4961set(handles.view_xml,'BackgroundColor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib
[387]4962set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action
4963
[566]4964
4965%-----------------------------------------------------------------------
4966function MenuLIFCalib_Callback(hObject, eventdata, handles)
[387]4967%------------------------------------------------------------------------
[567]4968%% read UvData properties stored on the uvmat interface
4969UvData=get(handles.uvmat,'UserData');
4970if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
4971    XmlData=UvData.XmlData{1};
4972else
4973    msgbox_uvmat('ERROR','geometric calibration needed: use Tools/geometric calibration in the menu bar');
4974    return
4975end
4976
4977%% read lines currently drawn
[622]4978ListObj=UvData.ProjObject;
[566]4979select=zeros(1,numel(ListObj));
4980for iobj=1:numel(ListObj);
[567]4981    if isfield(ListObj{iobj},'Type') && strcmp(ListObj{iobj}.Type,'line')
[566]4982        select(iobj)=1;
4983    end
4984end
4985val=find(select);
4986if numel(val)<2
4987    msgbox_uvmat('ERROR','light rays must be defined by at least two lines created by Projection object/line in the menu bar');
4988    return
4989else
[567]4990    set(handles.ListObject,'Value',val);% show the selected lines on the list
[622]4991    ObjectData=UvData.ProjObject(val);
[566]4992    for iobj=1:length(ObjectData)
[567]4993            xA(iobj)=ObjectData{iobj}.Coord(1,1);
4994            yA(iobj)=ObjectData{iobj}.Coord(1,2);
4995            xB(iobj)=ObjectData{iobj}.Coord(2,1);
4996            yB(iobj)=ObjectData{iobj}.Coord(2,2);
[566]4997    end
4998end
4999
[567]5000%% find the origin as intersection of the two first lines (see http://www.ahristov.com/tutorial/geometry-games/intersection-lines.html )
5001x1=xA(1);x2=xB(1);
5002x3=xA(2);x4=xB(2);
5003y1=yA(1);y2=yB(1);
5004y3=yA(2);y4=yB(2);
5005D = (x1-x2)*(y3-y4) -(y1-y2)*(x3-x4);
5006if D==0
5007    msgbox_uvmat('ERROR','the two lines are parallel');
5008    return
5009end
5010x0=((x3-x4)*(x1*y2-y1*x2)-(x1-x2)*(x3*y4-y3*x4))/D;
5011y0=((y3-y4)*(x1*y2-y1*x2)-(y1-y2)*(x3*y4-y3*x4))/D;
5012XmlData.Illumination.Origin=[x0 y0];
5013XmlData.PolarCentre=[x0 y0];
[566]5014
[567]5015%% display the current image in polar coordinates with origin at the  illumination source
5016currentdir=pwd; 
5017uvmatpath=fileparts(which('uvmat'));
5018cd(fullfile(uvmatpath,'transform_field'));
5019phys_polar=str2func('phys_polar');
5020cd(currentdir)
5021DataOut=phys_polar(UvData.Field,XmlData);
5022view_field(DataOut);
[566]5023
[567]5024%% use the third line for reference luminosity
5025if numel(val)==3
5026    x_ref=linspace(ObjectData{3}.Coord(1,1),ObjectData{3}.Coord(2,1),10);
5027    y_ref=linspace(ObjectData{3}.Coord(1,2),ObjectData{3}.Coord(2,2),10);
5028    x_ref=x_ref-x0;
5029    y_ref=y_ref-y0;
5030    [theta_ref,r_ref] = cart2pol(x_ref,y_ref);%theta_ref  and r_ref are the polar coordinates of the points on the line
5031    theta_ref=theta_ref*180/pi;
5032    figure
5033    plot(theta_ref,r_ref)
5034    azimuth_ima=linspace(DataOut.AY(1),DataOut.AY(2),size(DataOut.A,1));%profile of x index on the transformed image
5035    dist_source = interp1(theta_ref,r_ref,azimuth_ima);
5036    dist_source_pixel=round(size(DataOut.A,2)*(dist_source-DataOut.AX(1))/(DataOut.AX(2)-DataOut.AX(1)));
5037    line_nan= isnan(dist_source_pixel);
5038    dist_source_pixel(line_nan)=1;
5039    width=20; %number of pixels used for reference
5040    DataOut.A=double(DataOut.A);
5041    Anorm=zeros(size(DataOut.A));
5042    Aval=mean(mean(DataOut.A));
5043    for iline=1:size(DataOut.A,1)
5044        lum(iline)=mean(DataOut.A(iline,dist_source_pixel(iline):dist_source_pixel(iline)+width));
5045        Anorm(iline,:)=uint16(Aval*DataOut.A(iline,:)/lum(iline));
5046    end
5047    lum(line_nan)=NaN;
5048    figure
5049    plot(1:size(DataOut.A,1),lum)
5050end
5051ImaName=regexprep([get(handles.RootFile,'String') get(handles.FileIndex,'String')],'//','');
5052NewImageName=fullfile(get(handles.RootPath,'String'),'polar',[ImaName get(handles.FileExt,'String')]);
5053imwrite(Anorm,NewImageName,'BitDepth',16)
5054
5055%% record the origin in the xml file
5056XmlFileName=find_imadoc(get(handles.RootPath,'String'),get(handles.SubDir,'String'),get(handles.RootFile,'String'),get(handles.FileExt,'String'));
5057answer=msgbox_uvmat('INPUT_Y-N','save the illumination origin in the current xml file?');
5058if strcmp(answer,'Yes')
5059    t=xmltree(XmlFileName); %read the file
5060    title=get(t,1,'name');
5061    if ~strcmp(title,'ImaDoc')
5062        msgbox_uvmat('ERROR','wrong xml file');
5063        return
5064    end
5065    % backup the output file if it already exist, and read it
5066    backupfile=XmlFileName;
5067    testexist=2;
5068    while testexist==2
5069        backupfile=[backupfile '~'];
5070        testexist=exist(backupfile,'file');
5071    end
5072    [success,message]=copyfile(XmlFileName,backupfile);%make backup
5073    if success~=1
5074        errormsg=['errror in xml file backup: ' message];
5075        return
5076    end
5077    uid_illumination=find(t,'ImaDoc/Illumination');
5078    if isempty(uid_illumination)  %if GeometryCalib does not already exists, create it
5079        [t,uid_illumination]=add(t,1,'element','Illumination');
5080    end
5081    uid_origin=find(t,'ImaDoc/Illumination/Origin');
5082    if ~isempty(uid_origin)  %if GeometryCalib does not already exists, create it
5083         t=delete(t,uid_origin);
5084    end
5085    % save the illumination origin
5086    t=struct2xml(XmlData.Illumination,t,uid_illumination);
5087    save(t,XmlFileName);
5088end
5089   
5090
5091
[566]5092%------------------------------------------------------------------------
[387]5093function MenuMask_Callback(hObject, eventdata, handles)
5094%------------------------------------------------------------------------
5095UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
[622]5096ListObj=UvData.ProjObject;
[387]5097select=zeros(1,numel(ListObj));
5098for iobj=1:numel(ListObj);
5099    if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside')
5100        select(iobj)=1;
5101    end
5102end
5103val=find(select);
5104if isempty(val)
5105    msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar');
5106    return
5107else
5108    set(handles.ListObject,'Value',val);
5109    flag=1;
[627]5110    if ~isfield(UvData.Field,'A')
5111            msgbox_uvmat('ERROR','an image needs to be opened to set the mask size');
5112    return
5113    end
[387]5114    npx=size(UvData.Field.A,2);
5115    npy=size(UvData.Field.A,1);
5116    xi=0.5:npx-0.5;
5117    yi=0.5:npy-0.5;
5118    [Xi,Yi]=meshgrid(xi,yi);
[622]5119        for iobj=1:length(UvData.ProjObject)
5120            ObjectData=UvData.ProjObject{iobj};
[387]5121            if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
5122                flagobj=1;
5123                testphys=0; %coordinates in pixels by default
5124                if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel')
5125                    if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
5126                        Calib=UvData.XmlData{1}.GeometryCalib;
5127                        testphys=1;
5128                    end
5129                end
5130                if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Type')
5131                    if isequal(ObjectData.Type,'polygon')
5132                        X=ObjectData.Coord(:,1);
5133                        Y=ObjectData.Coord(:,2);
5134                        if testphys
[542]5135                            pos=[X Y zeros(size(X))];
5136                            if isfield(Calib,'SliceCoord') && length(Calib.SliceCoord)>=3
5137                                if isfield(Calib,'SliceAngle')&&~isequal(Calib.SliceAngle,[0 0 0])
5138                                    om=norm(Calib.SliceAngle);%norm of rotation angle in radians
5139                                    OmAxis=Calib.SliceAngle/om; %unit vector marking the rotation axis
5140                                    cos_om=cos(pi*om/180);
5141                                    sin_om=sin(pi*om/180);
5142                                    pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis;
5143                                end
5144                                pos(:,1)=pos(:,1)+Calib.SliceCoord(1);
5145                                pos(:,2)=pos(:,2)+Calib.SliceCoord(2);
5146                                pos(:,3)=pos(:,3)+Calib.SliceCoord(3);
5147                            end                           
5148                            [X,Y]=px_XYZ(Calib,pos(:,1),pos(:,2),pos(:,3));
[387]5149                        end
5150                        flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
5151                    elseif isequal(ObjectData.Type,'ellipse')
5152                        if testphys
5153                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
5154                        end
5155                        RangeX=max(ObjectData.RangeX);
5156                        RangeY=max(ObjectData.RangeY);
5157                        X2Max=RangeX*RangeX;
5158                        Y2Max=RangeY*RangeY;
5159                        distX=(Xi-ObjectData.Coord(1,1));
5160                        distY=(Yi-ObjectData.Coord(1,2));
5161                        flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
5162                    elseif isequal(ObjectData.Type,'rectangle')
5163                        if testphys
5164                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
5165                        end
5166                        distX=abs(Xi-ObjectData.Coord(1,1));
5167                        distY=abs(Yi-ObjectData.Coord(1,2));
5168                        flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
5169                    end
5170                    if isequal(ObjectData.ProjMode,'mask_outside')
5171                        flagobj=~flagobj;
5172                    end
5173                    flag=flag & flagobj;
5174                end
5175            end
5176        end
5177    %mask name
5178    RootPath=get(handles.RootPath,'String');
[444]5179    SubDir=get(handles.SubDir,'String');
[387]5180    RootFile=get(handles.RootFile,'String');
5181    if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
5182        RootFile(1)=[];
5183    end
5184    list=get(handles.masklevel,'String');
5185    masknumber=num2str(length(list));
5186    maskindex=get(handles.masklevel,'Value');
[444]5187    mask_name=fullfile_uvmat(RootPath,[SubDir '.mask'],'mask','.png','_1',maskindex);
[387]5188    imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
5189    imflag=flipdim(imflag,1);
5190
5191    %display the mask
5192    hfigmask=figure;
5193    set(hfigmask,'Name','mask image')
5194    vec=linspace(0,1,256);%define a linear greyscale colormap
5195    map=[vec' vec' vec'];
5196    colormap(map)
5197    image(imflag);
5198    answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name);
5199    if ~strcmp(answer,'Cancel')
5200        mask_dir=fileparts(answer);
5201        if ~exist(mask_dir,'dir')
[444]5202            [xx,msg1]=mkdir(mask_dir);
5203            if ~strcmp(msg1,'')
5204                errormsg=['cannot create ' mask_dir ': ' msg1];%error message for directory creation
5205                return
5206            end
[387]5207        end
5208        imwrite(imflag,answer,'BitDepth',8);
5209    end
5210    set(handles.ListObject,'Value',1)
5211end
5212
5213%------------------------------------------------------------------------
5214%-- open the GUI set_grid.fig to create grid
5215function MenuGrid_Callback(hObject, eventdata, handles)
5216%------------------------------------------------------------------------
5217%suppress the other options if grid is chosen
5218set(handles.edit_vect,'Value',0)
5219edit_vect_Callback(hObject, eventdata, handles)
5220set(handles.ListObject,'Value',1)     
5221
5222%prepare display of the set_grid GUI
[515]5223[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
5224FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
[576]5225UvData=get(handles.uvmat,'UserData');
[591]5226% CoordList=get(handles.TransformName,'String');
5227% val=get(handles.TransformName,'Value');
[576]5228set_grid(FileName,UvData.Field);% call the set_object interface
[387]5229
[402]5230
[387]5231%------------------------------------------------------------------------
[402]5232function MenuRuler_Callback(hObject, eventdata, handles)
5233%------------------------------------------------------------------------
5234set(handles.CheckZoom,'Value',0)
5235CheckZoom_Callback(handles.uvmat, [], handles)
5236set(handles.MenuRuler,'checked','on')
5237UvData=get(handles.uvmat,'UserData');
5238UvData.MouseAction='ruler';
5239set(handles.uvmat,'UserData',UvData);
5240
5241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5242% MenuRun Callbacks
5243%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5244
5245%------------------------------------------------------------------------
[387]5246% open the GUI 'series'
5247function MenuSeries_Callback(hObject, eventdata, handles)
5248%------------------------------------------------------------------------
[651]5249Param=read_param(handles);
5250series(Param); %run the series interface
5251
5252% --------------------------------------------------------------------
5253function MenuPIV_Callback(hObject, eventdata, handles)
5254    Param=read_param(handles);
[654]5255%     Param.ActionName='civ_series';
5256hseries=series(Param);
5257hhseries=guidata(hseries);
5258ActionMenu=get(hhseries.ActionName,'String');
5259index_action=find(strcmp('civ_series',ActionMenu));
5260set(hhseries.ActionName,'Value',index_action);
5261series('ActionName_Callback',hObject,eventdata,hhseries); %file input with xml reading  in uvmat, show the image in phys coordinates
[651]5262
[654]5263
[651]5264%------------------------------------------------------------------------
5265% -- open the GUI civ.fig for PIV
5266function MenuCIVx_Callback(hObject, eventdata, handles)
5267%------------------------------------------------------------------------
5268 [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
5269 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
5270civ(FileName);% interface de civ(not in the uvmat file)
5271
5272function Param=read_param(handles)
5273   
[515]5274[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
[526]5275Param.FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];%first input file name
[387]5276if isequal(get(handles.SubField,'Value'),1)
[515]5277    [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
5278    FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
[526]5279    if ~isequal(FileName_1,Param.FileName)
5280        Param.FileName_1=FileName_1;%second input file name if relevant
[387]5281    end
5282end
[526]5283Param.NomType=get(handles.NomType,'String');
5284Param.NomType_1=get(handles.NomType_1,'String');
5285Param.CheckFixPair=get(handles.CheckFixPair,'Value');
5286UvData=get(handles.uvmat,'UserData');
[387]5287if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'Time')
[526]5288    Param.Time=UvData.XmlData{1}.Time;
[387]5289end
5290if isequal(get(handles.scan_i,'Value'),1)
[526]5291    Param.incr_i=str2num(get(handles.num_IndexIncrement,'String'));
[387]5292elseif isequal(get(handles.scan_j,'Value'),1)
[526]5293    Param.incr_j=str2num(get(handles.num_IndexIncrement,'String'));
[387]5294end
[526]5295
5296%% transfer fields and coordinate names
5297Param.list_fields=get(handles.FieldName,'String');% list menu fields
5298FieldName=Param.list_fields{get(handles.FieldName,'Value')};
5299ind_image=find(strcmp('image',Param.list_fields));
5300if ~isempty(ind_image) && numel(Param.list_fields)>1
5301    Param.list_fields(ind_image)=[]; %suppress  'image' option
[387]5302end
[526]5303Param.index_fields=find(strcmp(FieldName,Param.list_fields));% selected string index
5304Param.list_fields_1=get(handles.FieldName_1,'String');% list menu fields
5305if ischar(Param.list_fields_1),Param.list_fields_1={Param.list_fields_1};end
5306FieldName_1=Param.list_fields_1{get(handles.FieldName_1,'Value')};
5307ind_image=find(strcmp('image',Param.list_fields_1));
5308if ~isempty(ind_image) && numel(Param.list_fields_1)>1
5309    Param.list_fields_1(ind_image)=[]; %suppress  'image' option
[387]5310end
[526]5311Param.index_fields_1=find(strcmp(FieldName_1,Param.list_fields_1));% selected string index
[591]5312TransformList=get(handles.TransformName,'String');
5313Param.TransformName=TransformList{get(handles.TransformName,'Value')};
[526]5314Param.Coord_x_str=get(handles.Coord_x,'String');
5315Param.Coord_x_val=get(handles.Coord_x,'Value');
[646]5316Param.Coord_y_str=get(handles.Coord_y,'Data');
[387]5317
[402]5318% --------------------------------------------------------------------
5319function MenuHelp_Callback(hObject, eventdata, handles)
5320% --------------------------------------------------------------------
[646]5321web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp')
[497]5322
[646]5323% path_to_uvmat=which ('uvmat');% check the path of uvmat
5324% pathelp=fileparts(path_to_uvmat);
5325% helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
5326% if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
5327% else
5328%     addpath (fullfile(pathelp,'uvmat_doc'))
5329%     web(helpfile);
5330% end
5331
[517]5332% --- Executes on selection change in Coord_y.
5333function Coord_y_Callback(hObject, eventdata, handles)
5334
5335% --- Executes on selection change in Coord_x.
5336function Coord_x_Callback(hObject, eventdata, handles)
[546]5337
5338
5339% --- Executes on button press in CheckColorBar.
5340function CheckColorBar_Callback(hObject, eventdata, handles)
[591]5341
5342
5343
5344function TransformPath_Callback(hObject, eventdata, handles)
5345% hObject    handle to TransformPath (see GCBO)
5346% eventdata  reserved - to be defined in a future version of MATLAB
5347% handles    structure with handles and user data (see GUIDATA)
5348
5349% Hints: get(hObject,'String') returns contents of TransformPath as text
5350%        str2double(get(hObject,'String')) returns contents of TransformPath as a double
[598]5351
5352
5353%TODO: use to modify fill_GUI
5354%'write_plot_param': update the plotting parameters on the uvmat or view_field interface after a plotting operation
5355function write_plot_param(handles,PlotParam)
5356%% coordinates
5357if isempty(PlotParam.Coordinates)
5358    set(handles.Coordinates,'Visible','off')
5359    set(handles.PlotAxes,'Visible','off')
5360    set(handles.text_display,'Visible','off')
5361    set(handles.TableDisplay,'Visible','on')
5362else
5363    set(handles.Coordinates,'Visible','on')
5364    set(handles.PlotAxes,'Visible','on')
5365    set(handles.text_display,'Visible','on')
5366    if isfield(handles,'TableDisplay')
5367    set(handles.TableDisplay,'Visible','off')
5368    end
5369    Coordinates=PlotParam.Coordinates;
5370    if isfield(Coordinates,'CheckFixAspectRatio')
5371        if Coordinates.CheckFixAspectRatio
5372            set(handles.CheckFixAspectRatio,'Value',1)
5373        else
5374            set(handles.CheckFixAspectRatio,'Value',0)
5375 
5376        end
5377    end
5378    if isfield(Coordinates,'AspectRatio')
5379        set(handles.num_AspectRatio,'String',num2str(Coordinates.AspectRatio))
5380    end
5381    if isfield(Coordinates,'MinX')
5382        set(handles.num_MinX,'String',num2str(Coordinates.MinX,4));
5383        set(handles.num_MaxX,'String',num2str(Coordinates.MaxX,4));
5384        set(handles.num_MinY,'String',num2str(Coordinates.MinY,4));
5385        set(handles.num_MaxY,'String',num2str(Coordinates.MaxY,4));
5386    else
5387        set(handles.num_MinX,'String','');
5388        set(handles.num_MaxX,'String','');
5389        set(handles.num_MinY,'String','');
5390        set(handles.num_MaxY,'String','');
5391    end
5392end
5393
5394%% scalar or image parameters
5395if isfield(PlotParam,'Scalar')
5396    set(handles.Scalar,'Visible','on')
5397    if isfield(PlotParam.Scalar,'MaxA')
5398        set(handles.num_MaxA,'String',num2str(PlotParam.Scalar.MaxA,3));
5399    end
5400    if isfield(PlotParam.Scalar,'MinA')
5401        set(handles.num_MinA,'String',num2str(PlotParam.Scalar.MinA,3));
5402    end   
5403    if isfield(PlotParam.Scalar,'IncrA')
5404        set(handles.num_IncrA,'String',num2str(PlotParam.Scalar.IncrA,3))
5405    end
5406    set(handles.CheckBW,'Value',PlotParam.Scalar.CheckBW)
5407    if isfield(PlotParam.Scalar,'Opacity')&&isfield(handles,'num_Opacity')
5408        set(handles.num_Opacity,'String',num2str(PlotParam.Scalar.Opacity))
5409    end
5410else
5411    set(handles.Scalar,'Visible','off')
5412end
5413
5414%% parameter for vector field
5415if isfield(PlotParam,'Vectors')
5416    set(handles.Vectors,'Visible','on')
5417    if isfield(PlotParam.Vectors,'VecScale')
5418        set(handles.num_VecScale,'String',num2str(PlotParam.Vectors.VecScale,3))
5419    end
5420    if isfield(PlotParam.Vectors,'MinC')&& isfield(PlotParam.Vectors,'MaxC')
5421        MinC=PlotParam.Vectors.MinC;
5422        MaxC=PlotParam.Vectors.MaxC;
5423        set(handles.num_MinVec,'String', num2str(MinC,3));
5424        set(handles.num_MaxVec,'String',num2str(MaxC,3));
5425        list=get(handles.ColorCode,'String');
5426        ichoice=get(handles.ColorCode,'Value');
5427        color_option=list{ichoice};
5428        test3color=strcmp(color_option,'rgb')||strcmp(color_option,'bgr');
5429        if test3color% need to update color thresholds
5430            set(handles.num_ColCode1,'Visible','on')
5431            set(handles.num_ColCode2,'Visible','on')
5432            set(handles.Slider1,'Visible','on')
5433            set(handles.Slider2,'Visible','on')
5434            set(handles.num_ColCode1,'String',num2str(PlotParam.Vectors.ColCode1,3))
5435            set(handles.num_ColCode2,'String',num2str(PlotParam.Vectors.ColCode2,3))
5436            set(handles.Slider1,'Value',(PlotParam.Vectors.ColCode1-MinC)/(MaxC-MinC))
5437            set(handles.Slider2,'Value',(PlotParam.Vectors.ColCode2-MinC)/(MaxC-MinC))
5438        else
5439            set(handles.num_ColCode1,'Visible','off')
5440            set(handles.num_ColCode2,'Visible','off')
5441            set(handles.Slider1,'Visible','off')
5442            set(handles.Slider2,'Visible','off')
5443        end
5444    end
5445else
5446    set(handles.Vectors,'Visible','off')
5447    if isfield(handles,'edit_vect')
5448        set(handles.edit_vect,'Visible','off')
5449        set(handles.record,'Visible','off')
5450    end
5451end
[690]5452
5453
5454% --- Executes on button press in CheckTable.
5455function CheckTable_Callback(hObject, eventdata, handles)
5456if get(handles.CheckTable,'Value')
5457    set(handles.TableDisplay,'Visible','on')
5458else
5459    set(handles.TableDisplay,'Visible','off')
5460end
Note: See TracBrowser for help on using the repository browser.