source: trunk/src/series.m @ 458

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

bugs corrected in series

File size: 88.7 KB
RevLine 
[2]1%'series': master function associated to the GUI series.m for analysis field series 
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI series.fig
5%
6%INPUT
7% param: structure with input parameters (link with the GUI uvmat)
[446]8%      .menu_coord_str: string for the TransformName (menu for coordinate transforms)
9%      .menu_coord_val: value for TransformName (menu for coordinate transforms)
[2]10%      .FileName: input file name
11%      .FileName_1: second input file name
12%      .list_field: menu of input fields
13%      .index_fields: chosen index
14%      .civ1=0 or 1, .interp1,  ... : input civ field type
15%
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
[408]32%------------------------------------------------------------------------
33%------------------------------------------------------------------------
34%  I - MAIN FUNCTION series
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
[2]37function varargout = series(varargin)
38
39% Begin initialization code - DO NOT EDIT
40gui_Singleton = 1;
41gui_State = struct('gui_Name',       mfilename, ...
42                   'gui_Singleton',  gui_Singleton, ...
43                   'gui_OpeningFcn', @series_OpeningFcn, ...
44                   'gui_OutputFcn',  @series_OutputFcn, ...
45                   'gui_LayoutFcn',  [] , ...
46                   'gui_Callback',   []);
47if nargin && ischar(varargin{1})
48    gui_State.gui_Callback = str2func(varargin{1});
49end
50
51if nargout
52    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
53else
54    gui_mainfcn(gui_State, varargin{:});
55end
56% End initialization code - DO NOT EDIT
57
58%--------------------------------------------------------------------------
59% --- Executes just before series is made visible.
60%--------------------------------------------------------------------------
61function series_OpeningFcn(hObject, eventdata, handles,param)
[205]62global nb_builtin_ACTION nb_builtin_transform
[2]63% Choose default command line output for series
64handles.output = hObject;
65% Update handles structure
66guidata(hObject, handles);
67%default initial parameters
[156]68drawnow
[244]69set(hObject,'Units','pixels')
[408]70set(handles.PairString,'ColumnEditable',logical(0))
71set(handles.PairString,'ColumnFormat',{'char'})
72set(handles.PairString,'ColumnWidth',{60})
73set(handles.PairString,'Data',{''})
[244]74% set(0,'Units','pixels')
75% screensize=get(0,'ScreenSize'); %screen size in pixels
[332]76set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
77%set(hObject,'Position',[150 100 1000 600] );%position and size in pixels (get adjusted to the screen size in case of excess)
[2]78%load the list of previously browsed files in menus Open and Open_1
79dir_perso=prefdir;
[205]80test_profil_perso=0;
[2]81profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
82if exist(profil_perso,'file')
83     h=load (profil_perso);
[205]84     test_profil_perso=1;
[446]85     if isfield(h,'MenuFile_1') && exist(h.MenuFile_1,'file')
[2]86          set(handles.MenuFile_1,'Label',h.MenuFile_1);
87          set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
88     end
[446]89     if isfield(h,'MenuFile_2')&& exist(h.MenuFile_2,'file')
[2]90          set(handles.MenuFile_2,'Label',h.MenuFile_2);
91          set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
92     end
[446]93     if isfield(h,'MenuFile_3')&& exist(h.MenuFile_3,'file')
[2]94          set(handles.MenuFile_3,'Label',h.MenuFile_3);
95          set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
96     end
[446]97     if isfield(h,'MenuFile_4')&& exist(h.MenuFile_4,'file')
[2]98          set(handles.MenuFile_4,'Label',h.MenuFile_4);
99          set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
100     end
[446]101     if isfield(h,'MenuFile_5')&& exist(h.MenuFile_5,'file')
[2]102          set(handles.MenuFile_5,'Label',h.MenuFile_5);
103          set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
104     end
105end
106
107%check default input data
108if ~exist('param','var')
109    param=[]; %default
110end
111
[376]112%% file name and browser initialisation
[2]113if isfield(param,'menu_coord_str')
[446]114    set(handles.TransformName,'String',param.menu_coord_str)
[2]115end
116if isfield(param,'menu_coord_val')
[446]117    set(handles.TransformName,'Value',param.menu_coord_val);
[2]118else
[446]119     set(handles.TransformName,'Value',1);%default
[2]120end
121if isfield(param,'FileName')
122    if isfield(param,'FileName_1')
[408]123        display_file_name(handles,param.FileName_1,0)
124        display_file_name(handles,param.FileName,1)
[2]125    else
[408]126        display_file_name(handles,param.FileName,0)
[2]127    end
128end 
129
[376]130%% fields input initialisation
[2]131if isfield(param,'list_fields')&& isfield(param,'index_fields') &&~isempty(param.list_fields) &&~isempty(param.index_fields)
[446]132    set(handles.FieldName,'String',param.list_fields);% list menu fields
133    set(handles.FieldName,'Value',param.index_fields);% selected string index
[2]134    FieldCell{1}=param.list_fields{param.index_fields};
135end
[376]136
[446]137%loads the information stored in prefdir to initiate  the list of ActionName functions
[329]138fct_menu={'check_data_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
[38]139transform_menu={'';'phys';'px';'phys_polar'};
[205]140nb_builtin_ACTION=numel(fct_menu); %number of functions
[38]141nb_transform=numel(transform_menu);
[26]142[path_series,name,ext]=fileparts(which('series'));
[34]143path_series=fullfile(path_series,'series');%path of the function 'series'
[332]144addpath (path_series) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
[276]145path_transform=fullfile(path_series,'transform_field');%path to the field transform functions
[38]146for ilist=1:length(fct_menu)
[2]147    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
148end
[39]149
[376]150%% TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
[39]151menu_str={'';'phys';'px';'phys_polar'};
[205]152nb_builtin_transform=numel(menu_str); %number of functions
[39]153[path_uvmat,name,ext]=fileparts(which('uvmat'));
154addpath(fullfile(path_uvmat,'transform_field'))
155fct_handle{1,1}=[];
156testexist(1)=1;
157for ilist=2:length(menu_str)
158    if exist(menu_str{ilist},'file')
159        fct_handle{ilist,1}=str2func(menu_str{ilist});
160        testexist(ilist)=1;
161    else
162        testexist(ilist)=0;
163    end
[38]164end
[39]165rmpath(fullfile(path_uvmat,'transform_field'))
166
[376]167%% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
[205]168if test_profil_perso
[2]169    if isfield(h,'series_fct') && iscell(h.series_fct)
170         for ilist=1:length(h.series_fct)
171             [path,file]=fileparts(h.series_fct{ilist});
172             fct_path=[fct_path; {path}];%concatene the list of paths
[205]173             fct_menu=[fct_menu; {file}];
[2]174         end
175    end
[38]176    if isfield(h,'transform_fct') && iscell(h.transform_fct)
[39]177        for ilist=1:length(h.transform_fct);
[38]178             [path,file]=fileparts(h.transform_fct{ilist});
[39]179             addpath(path)
180             if exist(file,'file')
181                h_func=str2func(file);
182                testexist=[testexist 1];
183             else
184                h_func=[];
185                testexist=[testexist 0];
186             end
187             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
188             rmpath(path)
189             menu_str=[menu_str; {file}];
190        end
[38]191    end
[2]192end
[38]193fct_menu=[fct_menu;{'more...'}];
[446]194set(handles.ActionName,'String',fct_menu)
195set(handles.ActionName,'UserData',fct_path)% store the list of path in UserData of ACTION
[39]196menu_str=menu_str(find(testexist));
197fct_handle=fct_handle(find(testexist));
198menu_str=[menu_str;{'more...'}];
[446]199set(handles.TransformName,'String',menu_str)
200set(handles.TransformName,'UserData',fct_handle)% store the list of path in UserData of ACTION
[39]201
[446]202% display the GUI for the default actionname 'check_data_files'
203ActionName_Callback(hObject, eventdata, handles)
[2]204
[408]205%------------------------------------------------------------------------
[2]206% --- Outputs from this function are returned to the command line.
207function varargout = series_OutputFcn(hObject, eventdata, handles)
[408]208%------------------------------------------------------------------------
[2]209% varargout  cell array for returning output args (see VARARGOUT);
210% hObject    handle to figure
211% eventdata  reserved - to be defined in a future version of MATLAB
212% handles    structure with handles and user data (see GUIDATA)
213% Get default command line output from handles structure
214varargout{1} = handles.output;
215
[408]216%------------------------------------------------------------------------
217%------------------------------------------------------------------------
218%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
219% automatically sets the global properties when the rootfile name is introduced
[446]220% then activate the view-field actionname if selected
[408]221% it is activated either by clicking on the RootPath window or by the
222% browser
223%------------------------------------------------------------------------
224%------------------------------------------------------------------------
[2]225function MenuBrowse_Callback(hObject, eventdata, handles)
[408]226%------------------------------------------------------------------------   
[350]227InputTable=get(handles.InputTable,'Data');
228RootPathCell=InputTable(:,1);
[358]229SubDirCell=InputTable(:,2);
230RootFileCell=InputTable(:,3);
[2]231oldfile=''; %default
[329]232if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
[2]233     dir_perso=prefdir;
234     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
235     if exist(profil_perso,'file')
236          h=load (profil_perso);
[329]237         if isfield(h,'filebase')&&ischar(h.filebase)
[2]238                 oldfile=h.filebase;
239         end
[329]240         if isfield(h,'RootPath')&&ischar(h.RootPath)
[2]241                 oldfile=h.RootPath;
242         end
243     end
244 else
245     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
246 end
247[FileName, PathName, filterindex] = uigetfile( ...
248       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
249       '*.xml',  '.xml files '; ...
250        '*.xls',  '.xls files '; ...
251        '*.png','.png image files'; ...
252        '*.tif','.tif image files'; ...
253        '*.avi;*.AVI','.avi movie files'; ...
254        '*.nc','.netcdf files'; ...
255        '*.*',  'All Files (*.*)'}, ...
256        'Pick a file',oldfile);
257fileinput=[PathName FileName];%complete file name
258sizf=size(fileinput);
259if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
260[path,name,ext]=fileparts(fileinput);
261SeriesData=[];%dfault
262if isequal(ext,'.xml')
[408]263    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]264elseif isequal(ext,'.xls')
[408]265    msg_box_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]266else
[408]267    display_file_name(handles,fileinput,0)
[2]268     %update list of recent files in the menubar
[446]269%     MenuFile_1=fileinput;
270%     MenuFile_2=get(handles.MenuFile_1,'Label');
271%     MenuFile_3=get(handles.MenuFile_2,'Label');
272%     MenuFile_4=get(handles.MenuFile_3,'Label');
273%     MenuFile_5=get(handles.MenuFile_4,'Label');
274%     set(handles.MenuFile_1,'Label',MenuFile_1)
275%     set(handles.MenuFile_2,'Label',MenuFile_2)
276%     set(handles.MenuFile_3,'Label',MenuFile_3)
277%     set(handles.MenuFile_4,'Label',MenuFile_4)
278%     set(handles.MenuFile_5,'Label',MenuFile_5)
279%     set(handles.MenuFile_insert_1,'Label',MenuFile_1)
280%     set(handles.MenuFile_insert_2,'Label',MenuFile_2)
281%     set(handles.MenuFile_insert_3,'Label',MenuFile_3)
282%     set(handles.MenuFile_insert_4,'Label',MenuFile_4)
283%     set(handles.MenuFile_insert_5,'Label',MenuFile_5)
284%     dir_perso=prefdir;
285%     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
286%     if exist(profil_perso,'file')
287%         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
288%     else
289%     txt=ver('MATLAB');
290%     Release=txt.Release;
291%         relnumb=str2num(Release(3:4));
292%         if relnumb >= 14
293%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
294%         else
295%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
296%         end
297%     end
[2]298end
299
300% --------------------------------------------------------------------
301function MenuFile_1_Callback(hObject, eventdata, handles)
302fileinput=get(handles.MenuFile_1,'Label');
[408]303display_file_name(handles,fileinput,0)
[2]304
305% --------------------------------------------------------------------
306function MenuFile_2_Callback(hObject, eventdata, handles)
307fileinput=get(handles.MenuFile_2,'Label');
[408]308display_file_name(handles,fileinput,0)
[2]309
310% --------------------------------------------------------------------
311function MenuFile_3_Callback(hObject, eventdata, handles)
312fileinput=get(handles.MenuFile_3,'Label');
[408]313display_file_name( handles,fileinput,0)
[2]314
315% --------------------------------------------------------------------
316function MenuFile_4_Callback(hObject, eventdata, handles)
317fileinput=get(handles.MenuFile_4,'Label');
[408]318display_file_name(handles,fileinput,0)
[2]319
320% --------------------------------------------------------------------
321function MenuFile_5_Callback(hObject, eventdata, handles)
322fileinput=get(handles.MenuFile_5,'Label');
[408]323display_file_name(handles,fileinput,0)
[2]324
325% --------------------------------------------------------------------
326function MenuBrowse_insert_Callback(hObject, eventdata, handles)
[350]327InputTable=get(handles.InputTable,'Data');
328RootPathCell=InputTable(:,1);
329SubDirCell=InputTable(:,3);
330RootFileCell=InputTable(:,2);
[2]331oldfile=''; %default
[206]332if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
[2]333     dir_perso=prefdir;
334     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
335     if exist(profil_perso,'file')
336          h=load (profil_perso);
337         if isfield(h,'filebase')&ischar(h.filebase)
338                 oldfile=h.filebase;
339         end
340         if isfield(h,'RootPath')&ischar(h.RootPath)
341                 oldfile=h.RootPath;
342         end
343     end
344 else
345     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
346 end
347[FileName, PathName, filterindex] = uigetfile( ...
348       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
349       '*.xml',  '.xml files '; ...
350        '*.xls',  '.xls files '; ...
351        '*.png','.png image files'; ...
352        '*.avi;*.AVI','.avi movie files'; ...
353        '*.nc','.netcdf files'; ...
354        '*.*',  'All Files (*.*)'}, ...
355        'Pick a file',oldfile);
356fileinput=[PathName FileName];%complete file name
357sizf=size(fileinput);
358if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
359[path,name,ext]=fileparts(fileinput);
360if isequal(ext,'.xml')
[206]361    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]362elseif isequal(ext,'.xls')
[206]363    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
[2]364else
[408]365    display_file_name(handles,fileinput,1)
[2]366end
367
368% --------------------------------------------------------------------
369function MenuFile_insert_1_Callback(hObject, eventdata, handles)
[408]370% --------------------------------------------------------------------   
[2]371fileinput=get(handles.MenuFile_insert_1,'Label');
[408]372display_file_name(handles,fileinput,1)
[2]373
374% --------------------------------------------------------------------
375function MenuFile_insert_2_Callback(hObject, eventdata, handles)
[408]376% --------------------------------------------------------------------   
[2]377fileinput=get(handles.MenuFile_insert_2,'Label');
[408]378display_file_name(handles,fileinput,1)
[2]379
380% --------------------------------------------------------------------
381function MenuFile_insert_3_Callback(hObject, eventdata, handles)
[408]382% --------------------------------------------------------------------   
[2]383fileinput=get(handles.MenuFile_insert_3,'Label');
[408]384display_file_name( handles,fileinput,1)
[2]385
386% --------------------------------------------------------------------
387function MenuFile_insert_4_Callback(hObject, eventdata, handles)
[408]388% --------------------------------------------------------------------   
[2]389fileinput=get(handles.MenuFile_insert_4,'Label');
[408]390display_file_name( handles,fileinput,1)
[2]391
392% --------------------------------------------------------------------
393function MenuFile_insert_5_Callback(hObject, eventdata, handles)
[408]394% --------------------------------------------------------------------   
[2]395fileinput=get(handles.MenuFile_insert_5,'Label');
[408]396display_file_name(handles,fileinput,1)
[2]397
[89]398%------------------------------------------------------------------------
[408]399% --- Executes when entered data in editable cell(s) in InputTable.
400function InputTable_CellEditCallback(hObject, eventdata, handles)
401%------------------------------------------------------------------------
402iview=eventdata.Indices(1);
403InputTable=get(handles.InputTable,'Data');
[446]404fileinput=fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
[408]405display_file_name(handles,fileinput,0)
[446]406%update the output dir
407SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
408SubDirOut=SubDir{1};
409if numel(SubDir)>1
410    for ilist=2:numel(SubDir)
411        SubDirOut=[SubDirOut '-' SubDir{ilist}];
412    end
413end
414set(handles.OutputSubDir,'String',SubDirOut)
[408]415
416%------------------------------------------------------------------------
417% ---  refresh the GUI data after introduction of a new file
[332]418% INPUT:
[408]419% handles: handles of the elements in the GUI series
[332]420% fileinput: name of the input file
[408]421% append: =0 to refresh the list of file series, =1 to append a new series to the list (from the menu bar option 'Open_insert')
422function display_file_name(handles,fileinput,append)
[89]423%------------------------------------------------------------------------ 
[332]424
[408]425%% get the input root name, indices, file extension and nomenclature NomType
426if ~exist(fileinput,'file')
427    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
428    return
429end
430
[332]431%% enable other menus and uicontrols
432set(handles.MenuOpen_insert,'Enable','on')
433set(handles.MenuFile_insert_1,'Enable','on')
434set(handles.MenuFile_insert_2,'Enable','on')
435set(handles.MenuFile_insert_3,'Enable','on')
436set(handles.MenuFile_insert_4,'Enable','on')
437set(handles.MenuFile_insert_5,'Enable','on')
438set(handles.RUN, 'Enable','On')
439set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
[350]440set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
[332]441drawnow
442
[408]443%% detect root name, nomenclature and indices in the input file name:
444[FilePath,FileName,FileExt]=fileparts(fileinput);
445% detect the file type, get the movie object if relevant, and look for the corresponding file series:
446% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
447[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
448if isempty(RootFile)&&isempty(i1_series)
449    errormsg='no input file in the series';
[29]450    return
451end
[89]452
[376]453%% fill the list of file series
454InputTable=get(handles.InputTable,'Data');
[408]455if append % display the input data as a new line in the table
456     lastview=size(InputTable,1)+1;
457     InputTable(lastview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
458    set(handles.ListView,'String',[get(handles.ListView,'String');{num2str(lastview)}])
459    set(handles.ListView,'Value',lastview)
[446]460
[376]461else % or re-initialise the list of  input  file series
[408]462    lastview=1;
[376]463    InputTable=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
464    set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}])
465    set(handles.MinIndex,'Data',[{[]},{[]}])
466    set(handles.MaxIndex,'Data',[{[]},{[]}])
[408]467    set(handles.ListView,'Value',1)
468    set(handles.ListView,'String',{'1'})
[376]469end
470set(handles.InputTable,'Data',InputTable)
471
[446]472%update the output dir
473SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
474SubDirOut=SubDir{1};
475if numel(SubDir)>1
476    for ilist=2:numel(SubDir)
477        SubDirOut=[SubDirOut '-' SubDir{ilist}];
478    end
479end
480set(handles.OutputSubDir,'String',SubDirOut)
[376]481
[408]482%% determine the selected reference field indices for pair display
[2]483ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
[339]484if ~isempty(i1)
485    ref_i=i1;
486    if ~isempty(i2)
487        ref_i=floor((ref_i+i2)/2);% reference image number corresponding to the file
[2]488    end
489end
[408]490set(handles.num_ref_i,'String',num2str(ref_i));
[2]491ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
[339]492if ~isempty(j1)
493    ref_j=j1;
494    if ~isempty(j2)
495        ref_j=floor((j1+j2)/2);
[2]496    end         
497end
[408]498set(handles.num_ref_j,'String',num2str(ref_j));
[372]499
[446]500%% update the list of recent files in the menubar and save it for future opening
[408]501MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
502    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
[446]503str_find=strcmp(fileinput,MenuFile);
[408]504if isempty(find(str_find,1))
[446]505    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
[372]506end
[408]507for ifile=1:min(length(MenuFile),5)
508    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
509    eval(['set(handles.MenuFile_insert_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
510end
[2]511dir_perso=prefdir;
512profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
513if exist(profil_perso,'file')
[408]514    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
[2]515else
[408]516    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
[2]517end
[408]518
[350]519set(handles.InputTable,'BackgroundColor',[1 1 1])
[2]520
[408]521%% initiate input file series and refresh the current field view:     
522update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,lastview);
[2]523
[408]524%------------------------------------------------------------------------
525% --- Update information about a new field series (indices to scan, timing,
526%     calibration from an xml file, then refresh current plots
527function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,iview)
528%------------------------------------------------------------------------
529
530%% enable j index visibility
531if isempty(j1_series)
532    state='off';
533else
534    state='on';
535end
536enable_j(handles,state)
537
538%% display the min and max indices for all the file series
539MinIndex=get(handles.MinIndex,'Data');%retrieve the min indices in the table MinIndex
540MaxIndex=get(handles.MaxIndex,'Data');%retrieve the max indices in the table MaxIndex
[456]541i_sum=sum(sum(i1_series,2),3);%sum of i1_series on the last index
[408]542MaxIndex_i=max(find(i_sum>0))-1;
[456]543if isequal(i1_series(1),0)
544    MinIndex_i=0;
545else
546    MinIndex_i=min(find(i_sum>0))-1;
547end
548j_sum=sum(sum(j1_series,1),3);
[408]549MaxIndex_j=max(find(j_sum>0))-1;
550MinIndex_j=min(find(j_sum>0))-1;
551MinIndex{iview,1}=MinIndex_i;
552MinIndex{iview,2}=MinIndex_j;
553MaxIndex{iview,1}=MaxIndex_i;
554MaxIndex{iview,2}=MaxIndex_j;
555set(handles.MinIndex,'Data',MinIndex)%display the min indices in the table MinIndex
556set(handles.MaxIndex,'Data',MaxIndex)%display the max indices in the table MaxIndex
557
558%% adjust the first and last indices if requested by the bounds
559first_i=str2num(get(handles.num_first_i,'String'));
560ref_i=str2num(get(handles.num_ref_i,'String'));
561ref_j=str2num(get(handles.num_ref_j,'String'));
562if isempty(first_i)
563    first_i=ref_i;
564elseif first_i < MinIndex_i
565    first_i=MinIndex_i;
566end
567first_j=str2num(get(handles.num_first_j,'String'));
568if isempty(first_j)
569    first_j=ref_j;
570elseif first_j<MinIndex_j
571    first_j=MinIndex_j;
572end
573last_i=str2num(get(handles.num_last_i,'String'));
574if isempty(last_i)
575    last_i=ref_i;
576elseif last_i > MaxIndex_i
577    last_i=MaxIndex_i;
578end
579last_j=str2num(get(handles.num_first_j,'String'));
580if isempty(last_j)
581    last_j=ref_j;
582elseif last_j>MaxIndex_j
583    last_j=MaxIndex_j;
584end
585set(handles.num_first_i,'String',num2str(first_i));
586set(handles.num_first_j,'String',num2str(first_j));
587set(handles.num_last_i,'String',num2str(last_i));
588set(handles.num_last_j,'String',num2str(last_j));
589
590%% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
591InputTable=get(handles.InputTable,'Data');
592FileBase=fullfile(InputTable{iview,1},InputTable{iview,3});
593time=[];%default
594% case of movies
595if strcmp(InputTable{iview,4},'*')
596    if ~isempty(VideoObject)
597        imainfo=get(VideoObject);
598        time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames-1)/imainfo.FrameRate)';
599        set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
600        ColorType='truecolor';
601    elseif ~isempty(imformats(regexprep(InputTable{iview,5},'^.',''))) || isequal(InputTable{iview,5},'.vol')%&& isequal(NomType,'*')% multi-frame image
602        if ~isempty(InputTable{iview,2})
603            imainfo=imfinfo(fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,5}]));
604        else
605            imainfo=imfinfo([FileBase InputTable{iview,5}]);
606        end
607        ColorType=imainfo.ColorType;%='truecolor' for color images
608        if length(imainfo) >1 %case of image with multiple frames
609            nbfield=length(imainfo);
610            nbfield_j=1;
611        end
612    end
613end
614
615%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
616ext_imadoc='';
617if exist([FileBase '.xml'],'file')
618    ext_imadoc='.xml';
619elseif exist([FileBase '.civ'],'file')
620    ext_imadoc='.civ';
621end
622%read the ImaDoc file
623XmlData=[];
624NbSlice_calib={};
625if isequal(ext_imadoc,'.xml')
626        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
627        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
628            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
629        end
630        if isfield(XmlData,'Time')
631            time=XmlData.Time;
632        end
633        if isfield(XmlData,'Camera')
634            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
635                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
636                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
637                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
638                end
639            end
640            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
641                TimeUnit=XmlData.Camera.TimeUnit;
642            end
643        end
644        if ~isempty(warntext)
645            msgbox_uvmat('WARNING',warntext)
646        end 
647elseif isequal(ext_imadoc,'.civ')
648    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
649    time=XmlData.Time;
650    if error==2, warntext=['no file ' FileBase '.civ'];
651    elseif error==1, warntext='inconsistent number of fields in the .civ file';
652    end 
653end
654
655%% update time table
[456]656if ~isempty(time)
[408]657TimeTable=get(handles.TimeTable,'Data');
658if isempty(MinIndex_j)
[456]659    if MinIndex_i>0
[408]660    TimeTable{iview,1}=time(MinIndex_i);
[456]661    end
[408]662    TimeTable{iview,2}=time(first_i);
663    TimeTable{iview,3}=time(last_i);
664    TimeTable{iview,4}=time(MaxIndex_i);
[419]665elseif ~isempty(time)
[456]666    if MinIndex_i>0
[408]667    TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
[456]668    end
[408]669    TimeTable{iview,2}=time(first_i,first_j);
670    TimeTable{iview,3}=time(last_i,last_j);
671    TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
672end
673set(handles.TimeTable,'Data',TimeTable)
[456]674end
[408]675
676%% number of slices
[450]677NbSlice=MaxIndex_j-MinIndex_j+1;%default
[408]678if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
679    siz=size(XmlData.GeometryCalib.SliceCoord);
680    if siz(1)>1
681        NbSlice=siz(1);
682    end
683end
[450]684set(handles.num_NbSlice,'String',num2str(NbSlice))
685   
[408]686%% update pair menus
[441]687set(handles.Pairs,'Visible','on')
688set(handles.PairString,'Visible','on')
[408]689ListView=get(handles.ListView,'String');
690ListView{iview}=num2str(iview);
691set(handles.ListView,'String');
692set(handles.ListView,'Value',iview)
693update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
694
[441]695
[408]696%% display the set of existing files as an image
697set(handles.waitbar_frame,'Units','pixels')
698pos=get(handles.waitbar_frame,'Position');
699xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
700yima=0.5:pos(4)-0.5;
701[XIma,YIma]=meshgrid(xima,yima);
702nb_i=size(i1_series,1);
703nb_j=size(i1_series,2);
704ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
705ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
706[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
707CData=zeros([size(XIma) 3]);
708file_ima=double((i1_series(:,:,1)>0)');
709if numel(file_ima)>=2
710if size(file_ima,1)==1
711    CLine=interp1(ind_i,file_ima,xima,'nearest');
712    CData(:,:,2)=ones(size(yima'))*CLine;
713else
714    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
715end
716set(handles.waitbar_frame,'CData',CData)
717end
718set(handles.waitbar_frame,'Units','normalized')
719
720%% enable field and veltype menus
721SeriesData=get(handles.series,'UserData');
722SeriesData.FileType{iview}=FileType;
723check_civ=0;
724check_netcdf=0;
725for iview=1:length(SeriesData.FileType)
726    switch SeriesData.FileType{iview}
727        case {'civx','civdata'}
728            check_civ=check_civ+1;
729        case 'netcdf'
730            check_netcdf=check_netcdf+1;
731    end
732end
733if check_civ
734    enable='on';
735else
736    enable='off';
737end
[446]738set(handles.VelType,'Visible',enable)
[408]739set(handles.VelType_text,'Visible',enable)
740if check_civ>=2
741    enable='on';
742else
743    enable='off';
744end
[446]745set(handles.VelType_1,'Visible',enable)
[408]746set(handles.VelType_text_1,'Visible',enable)
747if check_civ || check_netcdf
748    enable='on';
749else
750    enable='off';
751end
[446]752set(handles.FieldName,'Visible',enable)
[408]753set(handles.Field_text,'Visible',enable)
754if check_civ+ check_netcdf>=2
755    enable='on';
756else
757    enable='off';
758end
[446]759set(handles.FieldName_1,'Visible',enable)
[408]760set(handles.Field_text_1,'Visible',enable)
761FieldString={''};
762if check_civ
763    FieldString=[calc_field;{'get_field...'}];
764elseif check_netcdf
765    FieldString={'get_field...'};
766end
[446]767set(handles.FieldName,'String',FieldString)
[408]768FieldString={''};
769if check_civ>=2
770    FieldString=[calc_field;{'get_field...'}];
771elseif check_civ+check_netcdf>=2
772    FieldString={'get_field...'};
773end
[446]774set(handles.FieldName_1,'String',{'get_field...'})
[408]775
776
777%% store the series info in 'UserData'
778SeriesData.i1_series{iview}=i1_series;
779SeriesData.i2_series{iview}=i2_series;
780SeriesData.j1_series{iview}=j1_series;
781SeriesData.j2_series{iview}=j2_series;
782SeriesData.FileType{iview}=FileType;
783SeriesData.Time{iview}=time;
784set(handles.series,'UserData',SeriesData)
785
[441]786%% check for pair display
787check_pairs=0;
788for iview=1:numel(SeriesData.i2_series)
789    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
790        check_pairs=1;
791    end
792end
793if check_pairs
794    set(handles.Pairs,'Visible','on')
795    set(handles.PairString,'Visible','on')
796else
797    set(handles.Pairs,'Visible','off')
798    set(handles.PairString,'Visible','off')
799end
[408]800
801return
802
803%% set default options in menu 'Fields'%% TODO: check VelType
804if ~testima
805    testcivx=0;
806    if isfield(UvData,'FieldsString') && isequal(UvData.FieldsString,{'get_field...'})% field menu defined as input (from get_field)
807        set(handles_Fields,'Value',1)
808        set(handles_Fields,'String',{'get_field...'})
809        UvData=rmfield(UvData,'FieldsString');
810    else
811        Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
812        if strcmp(Data.Conventions,'uvmat/civdata') ||( ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0))%if the new input is Civx
813            FieldList=calc_field;
814            set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
815            set(handles_Fields,'Value',2) % set menu to 'velocity'
816            col_vec=FieldList;
817            col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar)
818            testcivx=1;
819        end
820        if ~testcivx
821            set(handles_Fields,'Value',1) % set menu to 'get_field...
822            set(handles_Fields,'String',{'get_field...'})
823            col_vec={'get_field...'};
824        end
825        set(handles.ColorScalar,'String',col_vec)
826    end
827end
828set(handles.uvmat,'UserData',UvData)
829
830%% set index navigation options and refresh plots
831scan_option='i';%default
832state_j='off'; %default
833if index==2
834    if get(handles.scan_j,'Value')
835        scan_option='j'; %keep the scan option for the second fiel series
836    end
837    if strcmp(get(handles.j1,'Visible'),'on')
838        state_j='on';
839    end
840end
841if ~isempty(j1_series)
842        state_j='on';
843        if isequal(nbfield,1) &&index==1
844            scan_option='j'; %scan j index by default if nbfield=1               
845        end
846end
847if isequal(scan_option,'i')
848     set(handles.scan_i,'Value',1)
849     scan_i_Callback([],[], handles);
850else
851     set(handles.scan_j,'Value',1)
852     scan_j_Callback([],[], handles);
853end
854set(handles.scan_j,'Visible',state_j)
855set(handles.j1,'Visible',state_j)
856set(handles.j2,'Visible',state_j)
857set(handles.last_j,'Visible',state_j);
858set(handles.frame_j,'Visible',state_j);
859set(handles.j_text,'Visible',state_j);
860if ~isempty(i2_series)||~isempty(j2_series)
861    set(handles.CheckFixPair,'Visible','on')
862elseif index==1
863    set(handles.CheckFixPair,'Visible','off')
864end
865
866
867mode_Callback(hObject, eventdata, handles)
868
869set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
870InputTable=get(handles.InputTable,'Data');
[358]871check_lines=get(handles.REFRESH_INDICES,'UserData');
[2]872
[408]873%% check the indices and FileTypes for each series (limited to the new ones to save time)
874for ind_list=1:length(check_lines)
875    if  check_lines(ind_list)
876        InputLine=InputTable(ind_list,:);
877        detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
878        detect_idem=detect_idem(detect_idem>0);
879        if ~isempty (detect_idem)
880            InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
881            set(handles.InputTable,'Data',InputTable)
882        end
883        fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
884        %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
885        %update file series defined by the selected line
886        [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
887        if ~isempty(errormsg)
888                msgbox_uvmat('ERROR',errormsg)
889                return
890        end
891    end
892end
893set(handles.InputTable,'Data',InputTable)
894SeriesData=get(handles.series,'UserData');
[339]895
[408]896state_j='off';
897state_Pairs='off';
898state_InputFields='off';
899val=get(handles.ListView,'Value');
900ListViewString={''};
901if ~isempty(SeriesData)
902%     ListViewString={};
903    for iview=1:size(InputTable,1)
904        if ~isempty(SeriesData.j1_series{iview})
905            state_j='on';
906        end
907        if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
908            state_Pairs='on';
909            ListViewString{iview}=num2str(iview);
910            if check_lines(iview)
911                val=iview;%select the last pair if it is a new entry
912            end
913        end
914        if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
915            state_InputFields='on';
916        end
917    end
918end
919set(handles.ListView,'Value',val)
920set(handles.ListView,'String',ListViewString)
921if strcmp(state_Pairs,'on')
922    ListView_Callback(hObject,eventdata,handles)
923end
924set(handles.PairString,'Visible',state_Pairs)
925enable_j(handles,state_j)
926
[446]927%------------------------------------------------------------------------
928function num_first_i_Callback(hObject, eventdata, handles)
929%------------------------------------------------------------------------
930num_last_i_Callback(hObject, eventdata, handles)
[408]931
932%------------------------------------------------------------------------
[446]933function num_last_i_Callback(hObject, eventdata, handles)
934%------------------------------------------------------------------------
935SeriesData=get(handles.series,'UserData');
936if ~isfield(SeriesData,'Time')
937    SeriesData.Time{1}=[];
938end
939displ_time(handles);
940
941%------------------------------------------------------------------------
942function num_first_j_Callback(hObject, eventdata, handles)
943%------------------------------------------------------------------------
944 num_last_j_Callback(hObject, eventdata, handles)
945
946%------------------------------------------------------------------------
947function num_last_j_Callback(hObject, eventdata, handles)
948%------------------------------------------------------------------------
949first_j=str2num(get(handles.num_first_j,'String'));
950last_j=str2num(get(handles.num_last_j,'String'));
951ref_j=ceil((first_j+last_j)/2);
952set(handles.num_ref_j,'String', num2str(ref_j))
953num_ref_j_Callback(hObject, eventdata, handles)
954SeriesData=get(handles.series,'UserData');
955if ~isfield(SeriesData,'Time')
956    SeriesData.Time{1}=[];
957end
958displ_time(handles);
959
960%------------------------------------------------------------------------
961% ---- find the times corresponding to the first and last indices of a series
962function displ_time(handles)
963%------------------------------------------------------------------------
964SeriesData=get(handles.series,'UserData');%
965ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
966ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
967% last_i=str2num(get(handles.num_last_i,'String'));
968% last_j=str2num(get(handles.num_last_j,'String'));
969TimeTable=get(handles.TimeTable,'Data');
970Pairs=get(handles.PairString,'Data');
971for iview=1:size(TimeTable,1)
972    if size(SeriesData.Time,1)<iview
973        break
974    end
975    i1=ref_i;
976    j1=ref_j;
977    i2=ref_i;
978    j2=ref_j;
979    % case of pairs
980    if ~isempty(Pairs{iview,1})
981        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
982        if isempty(r)
983            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
984        end
985        switch r.mode
986            case 'Di='  %  case 'series(Di)')
987                i1=ref_i-str2num(r.num1);
988                i2=ref_i+str2num(r.num2);
989            case 'Dj='  %  case 'series(Dj)'
990                j1=ref_j-str2num(r.num1);
991                j2=ref_j+str2num(r.num2);
992            case '-'  % case 'bursts'
993                j1=str2num(r.num1)*ones(size(ref_i));
994                j2=str2num(r.num2)*ones(size(ref_i));
995        end
996    end
997    TimeTable{iview,2}=[];
998    TimeTable{iview,3}=[];
999    if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2)
1000        if isempty(ref_j)
1001            time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
1002            time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
1003        else
1004            time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
1005            time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
1006        end
1007        TimeTable{iview,2}=time_first; %TODO: take into account pairs
1008        TimeTable{iview,3}=time_last; %TODO: take into account pairs
1009    end
1010end
1011set(handles.TimeTable,'Data',TimeTable)
1012
1013%------------------------------------------------------------------------
[408]1014% --- Executes when selected cell(s) is changed in PairString.
1015function PairString_CellSelectionCallback(hObject, eventdata, handles)
1016%------------------------------------------------------------------------   
1017set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1018ListView_Callback ([],[],handles) % update the list of available pairs
1019
1020%------------------------------------------------------------------------
1021%------------------------------------------------------------------------
1022%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1023%------------------------------------------------------------------------
1024%------------------------------------------------------------------------
1025% --- Executes on selection change in ListView.
1026function ListView_Callback(hObject, eventdata, handles)
1027%------------------------------------------------------------------------   
1028SeriesData=get(handles.series,'UserData');
1029i2_series=[];
1030j2_series=[];
1031iview=get(handles.ListView,'Value');
1032if ~isempty(SeriesData.i2_series{iview})
1033    i2_series=SeriesData.i2_series{iview};
1034end
1035if ~isempty(SeriesData.j2_series{iview})
1036    j2_series=SeriesData.j2_series{iview};
1037end
1038update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1039    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1040
1041%------------------------------------------------------------------------
[2]1042% --- Executes on button press in mode.
[376]1043function mode_Callback(hObject, eventdata, handles)
[408]1044%------------------------------------------------------------------------       
[376]1045SeriesData=get(handles.series,'UserData');
[408]1046iview=get(handles.ListView,'Value');
[376]1047mode_list=get(handles.mode,'String');
[408]1048mode=mode_list{get(handles.mode,'Value')};
[376]1049if isequal(mode,'bursts')
1050    enable_i(handles,'On')
1051    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1052else
1053    enable_i(handles,'On')
1054    enable_j(handles,'Off')
1055end
[408]1056fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1057    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1058ListPairs_Callback([],[],handles)
[339]1059
[408]1060%-------------------------------------------------------------
1061% --- Executes on selection in ListPairs.
1062function ListPairs_Callback(hObject,eventdata,handles)
1063%------------------------------------------------------------
1064list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
[441]1065if isempty(list_pair)
1066    string='';
1067else
1068    string=list_pair{get(handles.ListPairs,'Value')};
1069    string=regexprep(string,',.*','');%removes time indication (after ',')
1070end
[408]1071PairString=get(handles.PairString,'Data');
1072iview=get(handles.ListView,'Value');
1073PairString{iview,1}=string;
1074% report the selected pair string to the table PairString
1075set(handles.PairString,'Data',PairString)
[2]1076
[408]1077%------------------------------------------------------------------------
1078function num_ref_i_Callback(hObject, eventdata, handles)
1079%------------------------------------------------------------------------
1080mode_list=get(handles.mode,'String');
1081mode=mode_list{get(handles.mode,'Value')};
1082SeriesData=get(handles.series,'UserData');
1083iview=get(handles.ListView,'Value');
1084fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
[446]1085    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
[408]1086ListPairs_Callback([],[],handles)
[2]1087
[408]1088%------------------------------------------------------------------------
1089function num_ref_j_Callback(hObject, eventdata, handles)
1090%------------------------------------------------------------------------
1091num_ref_i_Callback(hObject, eventdata, handles)
[2]1092
[408]1093%------------------------------------------------------------------------
1094function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1095%------------------------------------------------------------------------   
[440]1096check_burst=0;
[408]1097if isempty(j2_series)% no pair menu to display
1098    if isempty(i2_series)
1099        set(handles.mode,'String',{''})
1100    else
1101        set(handles.mode,'Value',1)
1102        set(handles.mode,'String',{'series(Di)'})
1103    end
1104else
[419]1105    nbfield=size(j2_series,1);
1106    nbfield2=size(j2_series,2);
[408]1107    set(handles.mode,'String',{'bursts';'series(Dj)'})
1108    if nbfield2>10 || nbfield==1
[440]1109        set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values
[408]1110    else
1111        set(handles.mode,'Value',1);
1112        check_burst=1;
1113    end
1114end
1115if check_burst
1116    enable_i(handles,'On')
1117    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1118else
1119    enable_i(handles,'On')
[456]1120    if isempty(j1_series)
1121         enable_j(handles,'Off')
1122    else
1123        enable_j(handles,'On')
1124    end
[408]1125end
1126fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1127ListPairs_Callback([],[],handles)
[2]1128
1129%--------------------------------------------------------------
[408]1130% determine the menu for civ1 pairstring depending on existing netcdf files
1131% with the reference indices num_ref_i and num_ref_j
[2]1132%----------------------------------------------------------------
[408]1133function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1134
[2]1135mode_list=get(handles.mode,'String');
[408]1136mode=mode_list{get(handles.mode,'Value')};
1137ref_i=str2num(get(handles.num_ref_i,'String'));
1138ref_j=str2num(get(handles.num_ref_j,'String'));
1139if isempty(ref_i)
1140    ref_i=1;
1141end
1142if isempty(ref_j)
1143    ref_j=1;
1144end
[2]1145TimeUnit=get(handles.TimeUnit,'String');
1146if length(TimeUnit)>=1
1147    dtunit=['m' TimeUnit];
1148else
1149    dtunit='e-03';
1150end
[339]1151
1152displ_pair={};
[118]1153if strcmp(mode,'series(Di)')
[339]1154    if isempty(i2_series)
1155        msgbox_uvmat('ERROR','no i1-i2 pair available')
1156        return
1157    end
1158    diff_i=i2_series-i1_series;
1159    min_diff=min(diff_i(diff_i>0));
1160    max_diff=max(diff_i(diff_i>0));
1161    for ipair=min_diff:max_diff
1162        if numel(diff_i(diff_i==ipair))>0
[408]1163            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1164            if ~isempty(time)
1165                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1166                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1167            end
1168            displ_pair=[displ_pair;{pair_string}];
[339]1169        end
1170    end
1171    if ~isempty(displ_pair)
1172        displ_pair=[displ_pair;{'Di=*|*'}];
1173    end
1174elseif strcmp(mode,'series(Dj)')
1175    if isempty(j2_series)
1176        msgbox_uvmat('ERROR','no j1-j2 pair available')
1177        return
1178    end
1179    diff_j=j2_series-j1_series;
1180    min_diff=min(diff_j(diff_j>0));
1181    max_diff=max(diff_j(diff_j>0));
1182    for ipair=min_diff:max_diff
1183        if numel(diff_j(diff_j==ipair))>0
[408]1184            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1185            if ~isempty(time)
1186                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1187                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1188            end
1189            displ_pair=[displ_pair;{pair_string}];
[339]1190        end
1191    end
1192    if ~isempty(displ_pair)
1193        displ_pair=[displ_pair;{'Dj=*|*'}];
1194    end
1195elseif strcmp(mode,'bursts')
1196    if isempty(j2_series)
1197        msgbox_uvmat('ERROR','no j1-j2 pair available')
1198        return
1199    end
1200    diff_j=j2_series-j1_series;
1201    min_j1=min(j1_series(j1_series>0));
1202    max_j1=max(j1_series(j1_series>0));
1203    min_j2=min(j2_series(j2_series>0));
1204    max_j2=max(j2_series(j2_series>0));
1205    for pair1=min_j1:min(max_j1,min_j1+20)
1206        for pair2=min_j2:min(max_j2,min_j2+20)
1207        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1208            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1209        end
1210        end
1211    end
1212    if ~isempty(displ_pair)
1213        displ_pair=[displ_pair;{'j=*-*'}];
1214    end
1215end
[408]1216
1217%% display list of pairstring
1218displ_pair_list=get(handles.ListPairs,'String');
[339]1219NewVal=[];
1220if ~isempty(displ_pair_list)
[408]1221Val=get(handles.ListPairs,'Value');
[419]1222NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
[339]1223end
1224if ~isempty(NewVal)
[408]1225    set(handles.ListPairs,'Value',NewVal)
[339]1226else
[408]1227    set(handles.ListPairs,'Value',1)
[339]1228end
[408]1229set(handles.ListPairs,'String',displ_pair)
[339]1230
[408]1231%-------------------------------------
1232function enable_i(handles,state)
1233set(handles.i_txt,'Visible',state)
1234set(handles.num_first_i,'Visible',state)
1235set(handles.num_last_i,'Visible',state)
1236set(handles.num_incr_i,'Visible',state)
1237% set(handles.num_MaxIndex_i,'Visible',state)
1238set(handles.num_ref_i,'Visible',state)
1239set(handles.ref_i_text,'Visible',state)
[2]1240
[408]1241%-----------------------------------
1242function enable_j(handles,state)
1243set(handles.j_txt,'Visible',state)
1244% set(handles.num_MinIndex_j,'Visible',state)
1245set(handles.num_first_j,'Visible',state)
1246set(handles.num_last_j,'Visible',state)
1247set(handles.num_incr_j,'Visible',state)
1248% set(handles.num_MaxIndex_j,'Visible',state)
1249set(handles.num_ref_j,'Visible',state)
1250set(handles.ref_j_text,'Visible',state)
[41]1251
[408]1252%-----------------------------------
1253function view_FieldMenu(handles,state)
[446]1254% set(handles.FieldName,'Visible',state)
[408]1255% set(handles.Field_text,'Visible',state)
1256set(handles.InputFields,'Visible',state)
1257
1258%-----------------------------------
1259function view_FieldMenu_1(handles,state)
[446]1260set(handles.FieldName_1,'Visible',state)
[408]1261set(handles.Field_text_1,'Visible',state)
1262
1263
[446]1264%%%%%%%%%%%%%%%%%%%%
1265%%  MAIN ActionName FUNCTIONS
1266%%%%%%%%%%%%%%%%%%%%
[41]1267%------------------------------------------------------------------------
[2]1268% --- Executes on button press in RUN.
1269function RUN_Callback(hObject, eventdata, handles)
[41]1270%------------------------------------------------------------------------
[2]1271set(handles.RUN,'BusyAction','queue');
[332]1272set(0,'CurrentFigure',handles.series)
[446]1273set(handles.RUN, 'Enable','Off')
1274set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[456]1275drawnow
[453]1276[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
[446]1277if ~isempty(errormsg)
1278    msgbox_uvmat('ERROR',errormsg)
[2]1279else
[456]1280  %Series.Specific=h_fun(Series);   
1281   Series=h_fun(Series); 
[453]1282   t=struct2xml(Series);
1283    t=set(t,1,'name','Series');
1284    save(t,filexml);
[456]1285%     h_fun(Series);
[2]1286end
[446]1287set(handles.RUN, 'Enable','On')
1288set(handles.RUN,'BackgroundColor',[1 0 0])
[2]1289
[446]1290%------------------------------------------------------------------------
1291function STOP_Callback(hObject, eventdata, handles)
1292%------------------------------------------------------------------------
1293set(handles.RUN, 'BusyAction','cancel')
1294set(handles.RUN,'BackgroundColor',[1 0 0])
1295set(handles.RUN,'enable','on')
[448]1296set(handles.BATCH,'BackgroundColor',[1 0 0])
1297set(handles.BATCH,'enable','on')
[446]1298
1299%------------------------------------------------------------------------
1300% --- Executes on button press in BATCH.
1301function BATCH_Callback(hObject, eventdata, handles)
1302%------------------------------------------------------------------------   
1303set(handles.BATCH, 'Enable','Off')
1304set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
[453]1305[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
[448]1306if ~isempty(errormsg)
1307    msgbox_uvmat('ERROR',errormsg)
1308    return
1309end
[453]1310% update the xml file after interactive input with the function
[456]1311Series.Specific=h_fun('input?');   
[453]1312t=struct2xml(Series);
1313t=set(t,1,'name','Series');
1314save(t,filexml);
[448]1315path_series=fileparts(which('series'));
1316filename_xml=fullfile(Series.OutputDir,[Series.OutputRootFile '.xml']);
1317filename_bat=fullfile(Series.OutputDir,[Series.OutputRootFile '.bat']);
[446]1318[fid,message]=fopen(filename_bat,'w');
1319if isequal(fid,-1)
[448]1320    msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
[446]1321    return
1322end
[456]1323path_fct=get(handles.ActionPath,'String');
[446]1324text_matlabscript=[...
1325    '#!/bin/bash \n'...
1326    '. /etc/sysprofile \n'...
1327    'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
[448]1328    'cd(''' path_series '''); \n'...
[456]1329    'addpath(''' path_fct '''); \n'...
[448]1330    '' Series.Action  '( ''' filename_xml '''); \n'...
[446]1331    'exit \n'...
1332    'END_MATLAB \n'];
1333fprintf(fid,text_matlabscript);
1334fclose(fid);
1335if isunix
[456]1336    system(['chmod +x ' filename_bat]);% set the file to executable
1337    system(['. ' filename_bat]);%execute fct
[446]1338end
[448]1339set(handles.BATCH, 'Enable','On')
1340set(handles.BATCH,'BackgroundColor',[1 0 0])
[456]1341
[446]1342%------------------------------------------------------------------------
1343% --- Executes on button press in BIN.
1344function BIN_Callback(hObject, eventdata, handles)
1345%------------------------------------------------------------------------
1346    cmd=['#!/bin/bash \n '...
1347        '#$ -cwd \n '...
1348        'hostname && date \n '...
1349        'umask 002 \n'...
1350        Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1351   
1352%------------------------------------------------------------------------
[456]1353% --- Main launch command, called by RUN and BATCH
[453]1354function [h_fun,Series,filexml,errormsg]=prepare_jobs(handles)
[446]1355%------------------------------------------------------------------------
[456]1356filexml='';
[446]1357errormsg='';
1358%% Read parameters from series
1359Series=read_GUI(handles.series);
1360if isfield(Series,'Pairs')
1361Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1362end
1363
[456]1364%% read index ranges
[446]1365first_i=1;
1366last_i=1;
1367incr_i=1;
1368first_j=1;
1369last_j=1;
1370incr_j=1;
[339]1371if isfield(Series.IndexRange,'first_i')
1372    first_i=Series.IndexRange.first_i;
1373    incr_i=Series.IndexRange.incr_i;
1374    last_i=Series.IndexRange.last_i;
1375end
1376if isfield(Series.IndexRange,'first_j')
1377    first_j=Series.IndexRange.first_j;
1378    incr_j=Series.IndexRange.incr_j;
1379    last_j=Series.IndexRange.last_j;
1380end
1381
1382%% read input file parameters and set menus
[446]1383menu_coord_state=get(handles.TransformName,'Visible');
[2]1384if isequal(menu_coord_state,'on')
[446]1385    menu_index=get(handles.TransformName,'Value');
1386    transform_list=get(handles.TransformName,'UserData');
1387    Series.FieldTransform.TransformHandle=transform_list{menu_index};% transform function handles
[2]1388end
1389
1390if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1391    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1392
[446]1393%% projection object
1394if isfield(Series,'CheckObject')
1395    if Series.CheckObject
1396        hset_object=findobj(allchild(0),'tag','set_object');
1397        Series.ProjObject=read_GUI(hset_object);
[458]1398        CheckObject_Callback([], [], handles)
[446]1399    end
1400else
1401    Series.CheckObject=0;
1402end
[2]1403
[446]1404%% get_field GUI
1405if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1406    if strcmp(Series.InputFields.Field,'get_field...')
1407        hget_field=findobj(allchild(0),'name','get_field');
1408        Series.GetField=read_GUI(hget_field);
1409    end
1410end
[2]1411
[446]1412%% defining the ActionName function handle
1413list_action=get(handles.ActionName,'String');% list menu action
1414index=get(handles.ActionName,'Value');
1415action= list_action{index}; % selected string
1416Series.Action=action;%name of the processing programme
1417Series.hseries=handles.series; % handles to the series GUI
[2]1418path_series=which('series');
[446]1419list_path=get(handles.ActionName,'UserData');
[2]1420fct_path=list_path{index}; %path stored for the function ACTION
1421if ~isequal(fct_path,path_series)
1422    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
[41]1423    if ~exist(fct_path,'dir')
[446]1424        errormsg=['The prescibed function path ' fct_path ' does not exist'];
[41]1425        return
1426    end
1427    if ~isequal(spath,fct_path)
[2]1428        addpath(fct_path)% add the prescribed path if not the current one
1429    end
1430end
[41]1431eval(['h_fun=@' action ';'])%create a function handle for ACTION
[26]1432if ~isequal(fct_path,path_series)
1433        rmpath(fct_path)% add the prescribed path if not the current one   
1434end
1435
[446]1436%% create the output data directory and write in it the xml file from the GUI config
1437%determine the root file corresponding to the first sub dir
1438if isfield(Series,'OutputSubDir')
1439    SubDirOut=[Series.OutputSubDir Series.OutputDirExt];
1440    SubDirOutNew=SubDirOut;
1441    iview=1;
1442    SeriesData=get(handles.series,'UserData');
1443    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && isfield(SeriesData.AllowInputSort)
1444        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1445        Series.InputTable=Series.InputTable(iview,:);
[421]1446    end
[448]1447    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
[450]1448    check_create=1; %need to create the result directory by default
[446]1449    while detect
[448]1450        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1451        if isequal(answer,'Yes')
1452            detect=0;
1453            check_create=0;
1454        else
1455            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1456            if isempty(r)
1457                r(1).root=[SubDirOutNew '_'];
1458                r(1).num1='0';
1459            end
1460            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1461            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1462            check_create=1;
[408]1463        end
1464    end
[448]1465    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
[446]1466    Series.OutputSubDir=SubDirOutNew;
1467    Series.OutputDir=fullfile(Series.InputTable{1,1},Series.OutputSubDir);%directory set for output results
1468    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
[448]1469    set(handles.OutputDirExt,'String',Series.OutputDirExt)
[450]1470    %removes redondant information
1471    Series=rmfield(Series,'OutputDirExt');
1472    Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
1473    Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1474    Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
[446]1475    % create output directory
[448]1476    if check_create
[446]1477        [tild,msg1]=mkdir(Series.OutputDir);
1478        if ~strcmp(msg1,'')
1479            errormsg=['cannot create ' Series.OutputDir ': ' msg1];%error message for directory creation
1480            return
[421]1481        end
[408]1482    end
[446]1483    filexml=fullfile(Series.OutputDir,[Series.InputTable{1,3} '.xml']);% name of the parameter xml file set in this directory
[456]1484%     t=struct2xml(Series);
1485%     t=set(t,1,'name','Series');
1486%     save(t,filexml);
[408]1487end
1488
[41]1489%------------------------------------------------------------------------
[446]1490% --- Executes on selection change in ActionName.
1491function ActionName_Callback(hObject, eventdata, handles)
[41]1492%------------------------------------------------------------------------
[205]1493global nb_builtin_ACTION
[446]1494list_ACTION=get(handles.ActionName,'String');% list menu fields
1495index_ACTION=get(handles.ActionName,'Value');% selected string index
[2]1496ACTION= list_ACTION{index_ACTION}; % selected function name
1497path_series=which('series');%path to series.m
[446]1498list_path=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ACTION
[39]1499default_file=fullfile(list_path{end},ACTION);
[29]1500% add a new function to the menu if the selected item is 'more...'
[2]1501if isequal(ACTION,'more...')
1502    pathfct=fileparts(path_series);
1503    [FileName, PathName, filterindex] = uigetfile( ...
1504       {'*.m', ' (*.m)';
1505        '*.m',  '.m files '; ...
1506        '*.*', 'All Files (*.*)'}, ...
[39]1507        'Pick a file',default_file);
[2]1508    if length(FileName)<2
1509        return
[29]1510    end
1511    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
[2]1512    if ~isequal(ext_fct,'.m')
1513        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1514        return
1515    end
1516   
[446]1517   % insert the choice in the actionname menu
1518   menu_str=update_menu(handles.ActionName,ACTION);%new action menu in which the new item has been appended if needed
1519   index_ACTION=get(handles.ActionName,'Value');% currently selected index in the list
[2]1520   list_path{index_ACTION}=PathName;
[205]1521   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1522       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1523       menu_str(nb_builtin_ACTION+1:end-5)=[];
1524       list_path(nb_builtin_ACTION+1:end-4)=[];
[2]1525       index_ACTION=index_ACTION-nbremove;
[446]1526       set(handles.ActionName,'Value',index_ACTION)
1527       set(handles.ActionName,'String',menu_str)
[2]1528   end
1529   list_path{index_ACTION}=PathName;
[446]1530   set(handles.ActionName,'UserData',list_path);
1531   set(handles.ActionPath,'enable','inactive')% indicate that the current path is accessible (not 'off')
[2]1532   
1533   %record the current menu in personal file profil_perso
1534   dir_perso=prefdir;
1535   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
[205]1536   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1537       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
[2]1538   end
[206]1539   if nb_builtin_ACTION+1<=length(menu_str)-1
1540       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1541           save(profil_perso,'series_fct','-append')
1542       else
1543           txt=ver('MATLAB');
1544           Release=txt.Release;
1545           relnumb=str2num(Release(3:4));
1546           if relnumb >= 14%recent relaese of Matlab
1547               save(profil_perso,'series_fct','-V6')
1548           else
1549               save(profil_perso, 'series_fct')
1550           end
1551       end
[2]1552   end
1553end
1554
[446]1555%check the current ActionPath to the selected function
[2]1556PathName=list_path{index_ACTION};%current recorded path
[446]1557set(handles.ActionPath,'String',PathName); %show the path to the senlected function
[2]1558
1559%default setting for the visibility of the GUI elements
[339]1560set(handles.num_NbSlice,'Visible','off')
[2]1561set(handles.NbSlice_title,'Visible','off')
[446]1562set(handles.VelType,'Visible','off');
[2]1563set(handles.VelType_text,'Visible','off');
[446]1564set(handles.VelType_1,'Visible','off');
[2]1565set(handles.VelType_text_1,'Visible','off');
1566view_FieldMenu(handles,'off')
1567view_FieldMenu_1(handles,'off')
[339]1568set(handles.FieldTransform,'Visible','off')
[446]1569set(handles.CheckObject,'Visible','off');
1570set(handles.ProjObject,'Visible','off');
1571set(handles.CheckMask,'Visible','off')
[2]1572set(handles.Mask,'Visible','off')
[446]1573% set(handles.OutputDirExt,'Visible','off');
[2]1574set(handles.ParamKey,'Visible','off')
1575set(handles.ParamVal,'Visible','off')
1576ParamKey={};
[446]1577set(handles.FieldName,'Enable','off')
1578set(handles.VelType,'Enable','off')
1579set(handles.FieldName_1,'Enable','off')
1580set(handles.VelType_1,'Enable','off')
1581set(handles.TransformName,'Enable','off')
1582set(handles.OutputDirExt,'Visible','off')
1583set(handles.OutputSubDir,'Visible','off')
1584set(handles.OutputDir_title,'Visible','off')
[2]1585%set the displayed GUI item needed for input parameters
[29]1586if ~isequal(path_series,PathName)
1587    addpath(PathName)
1588end
1589eval(['h_function=@' ACTION ';']);
[244]1590try
1591    [fid,errormsg] =fopen([ACTION '.m']);
1592    InputText=textscan(fid,'%s',1,'delimiter','\n');
1593    fclose(fid)
[456]1594    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
[244]1595end
[29]1596if ~isequal(path_series,PathName)
1597    rmpath(PathName)
1598end
1599varargout=h_function();
[2]1600Param_list={};
1601
[372]1602InputTable=get(handles.InputTable,'Data');
1603nb_series=size(InputTable,1);
[2]1604testima_series=1; %test for a list of images only
1605testima=1;
1606testima_1=1;
1607testciv_series=1;
1608for iview=1:nb_series
[372]1609     ext=InputTable{iview,5};
[2]1610    if length(ext)<2
1611        ext='.none';
1612    end
1613    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1614    if ~testimaview
1615        if iview==1
1616            testima=0;
1617        end
1618        if iview==2
1619            testima_1=0;
1620        end
1621        testima_series=0;
1622    end
1623end
1624for ilist=1:length(varargout)-1
1625    switch varargout{ilist}
[446]1626        case 'NbViewMax'
1627            if ~isempty (varargout{ilist+1})
1628                if size(InputTable,1)>varargout{ilist+1}
1629                InputTable=InputTable(1:varargout{ilist+1},:);
1630                set(handles.InputTable,'Data',InputTable)
1631                end
1632            end
1633        case 'AllowInputSort'
1634            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1635                SeriesData=get(handles.series,'UserData');
1636                SeriesData.AllowInputSort=1;
1637                set(handles.series,'UserData',SeriesData)
[456]1638            end                     
1639        case 'WholeIndexRange'
1640            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1641                MinIndex=get(handles.MinIndex,'Data');
1642                MaxIndex=get(handles.MaxIndex,'Data');
1643                if ~isempty(MinIndex)
1644                    set(handles.num_first_i,'String',num2str(MinIndex{1}))
1645                    set(handles.num_last_i,'String',num2str(MaxIndex{1}))
1646                    set(handles.num_incr_i,'String','1')
1647                    if size(MinIndex,2)>=2
1648                        set(handles.num_first_j,'String',num2str(MinIndex{1,2}))
1649                        set(handles.num_last_j,'String',num2str(MaxIndex{1,2}))
1650                        set(handles.num_incr_j,'String','1')
1651                    end
1652                end
1653            end           
[2]1654        case 'NbSlice'   %hidden by default
1655            if isequal(lower(varargout{ilist+1}),'on')
[339]1656                set(handles.num_NbSlice,'Visible','on')
[2]1657                set(handles.NbSlice_title,'Visible','on')
1658            end
[446]1659        case 'VelType'   %hidden by default
[372]1660             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
[446]1661                set(handles.VelType,'Enable','on')
[2]1662                if nb_series >=1 && ~testima_series
[446]1663                    set(handles.VelType,'Visible','on')
[2]1664                    set(handles.VelType_text,'Visible','on');
1665                end
[372]1666             end
[2]1667            if isequal(lower(varargout{ilist+1}),'two')
[446]1668                set(handles.VelType_1,'Enable','on')
[2]1669                if nb_series >=2 && ~testima_series
[446]1670                    set(handles.VelType_1,'Visible','on')
[2]1671                    set(handles.VelType_text_1,'Visible','on');
1672                end
1673            end
[446]1674        case 'FieldName'   %hidden by default
[2]1675            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
[446]1676                set(handles.FieldName,'Enable','on') % test for MenuBorser
[2]1677                if nb_series >=1 && ~testima_series
1678                    view_FieldMenu(handles,'on')
1679                end
1680            end
1681            if isequal(lower(varargout{ilist+1}),'two')
[446]1682                set(handles.FieldName_1,'Enable','on')
[2]1683                if nb_series >=2 && ~testima_1
1684                    view_FieldMenu_1(handles,'on')
1685                end
1686            end
[446]1687        case 'FieldTransform'   %hidden by default
[2]1688            if isequal(lower(varargout{ilist+1}),'on')
[446]1689                set(handles.TransformName,'Enable','on')
[339]1690                set(handles.FieldTransform,'Visible','on')
[2]1691            end
[446]1692        case 'ProjObject'   %hidden by default
[2]1693            if isequal(lower(varargout{ilist+1}),'on')   
[446]1694                set(handles.CheckObject,'Visible','on')
1695                set(handles.ProjObject,'Visible','on')
[2]1696            end
1697        case 'Mask'   %hidden by default
1698            if isequal(lower(varargout{ilist+1}),'on')   
[446]1699                set(handles.Mask,'Visible','on')
1700                 set(handles.CheckMask,'Visible','on');
[2]1701            end
[446]1702        case 'PARAMETER'  % NOT USED
[2]1703            set(handles.PARAMETERS_frame,'Visible','on')
1704            set(handles.PARAMETERS_title,'Visible','on')
1705            set(handles.ParamKey,'Visible','on')
1706            %set(handles.ParamVal,'Visible','on')
1707            Param_str=varargout{ilist+1};
[446]1708            Param_list=[Param_list; {Param_str}];   
1709        case 'OutputDirExt'
1710            if ~isempty(varargout{ilist+1})
1711            set(handles.OutputDirExt,'String',varargout{ilist+1})
1712            set(handles.OutputDirExt,'Visible','on')
1713            set(handles.OutputSubDir,'Visible','on')
1714            set(handles.OutputDir_title,'Visible','on') 
1715            end
[2]1716    end
1717end
1718if ~isempty(Param_list)
1719    set(handles.ParamKey,'String',Param_list)
1720    set(handles.ParamVal,'Visible','on')
1721end
1722
[41]1723%------------------------------------------------------------------------
[446]1724% --- Executes on selection change in FieldName.
1725function FieldName_Callback(hObject, eventdata, handles)
[41]1726%------------------------------------------------------------------------
[446]1727field_str=get(handles.FieldName,'String');
1728field_index=get(handles.FieldName,'Value');
[2]1729field=field_str{field_index(1)};
1730if isequal(field,'get_field...')   
1731     hget_field=findobj(allchild(0),'name','get_field');
1732     if ~isempty(hget_field)
1733         delete(hget_field)%delete opened versions of get_field
1734     end
[453]1735     filecell=get_file_series(read_GUI(handles.series));
[428]1736     if exist(filecell{1,1},'file')
1737        get_field(filecell{1,1})
[2]1738     end
1739elseif isequal(field,'more...')
1740    str=calc_field;
1741    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1742                'SelectionMode','single',...
1743                'ListString',str);
[446]1744       % edit the choice in the fields and actionname menu
[2]1745     scalar=cell2mat(str(ind_answer));
[446]1746     update_menu(handles.FieldName,scalar)
[2]1747end
1748
[41]1749%------------------------------------------------------------------------
[446]1750% --- Executes on selection change in FieldName_1.
1751function FieldName_1_Callback(hObject, eventdata, handles)
[41]1752%------------------------------------------------------------------------
[446]1753field_str=get(handles.FieldName_1,'String');
1754field_index=get(handles.FieldName_1,'Value');
[2]1755field=field_str{field_index};
1756if isequal(field,'get_field...')   
1757     hget_field=findobj(allchild(0),'name','get_field_1');
1758     if ~isempty(hget_field)
1759         delete(hget_field)
1760     end
[332]1761     SeriesData=get(handles.series,'UserData');
[2]1762     filename=SeriesData.CurrentInputFile_1;
1763     if exist(filename,'file')
1764        hget_field=get_field(filename);
1765        set(hget_field,'name','get_field_1')
1766     end
1767elseif isequal(field,'more...')
1768    str=calc_field;
1769    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1770                'SelectionMode','single',...
1771                'ListString',str);
[446]1772       % edit the choice in the fields and actionname menu
[2]1773     scalar=cell2mat(str(ind_answer));
[446]1774     update_menu(handles.FieldName_1,scalar)
[2]1775end   
[29]1776
[244]1777
[2]1778%%%%%%%%%%%%%
1779function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
[339]1780indsel=ind_i;
1781indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1782indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1783if ~isempty(indiff)
1784    indiff2=diff(indiff);
1785    indiffp=[indiff2 1];
1786    indiffm=[1 indiff2];
1787    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1788    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1789    %for each multiplet, select the most recent file
1790    ind_remove=[];
1791    for i=1:length(ind_multi_m)
1792        ind_pairs=ind_multi_m(i):ind_multi_p(i);
1793        for imulti=1:length(ind_pairs)
1794            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
[2]1795        end
[339]1796        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1797        ind_s=indsort2(1:end-1);%
1798        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1799    end
1800end
[2]1801
[89]1802%------------------------------------------------------------------------
[408]1803% --- determine the list of index pairstring of processing file
[32]1804function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
[89]1805%------------------------------------------------------------------------
[32]1806num_i1=num_i;% set of first image numbers by default
1807num_i2=num_i;
1808num_j1=num_j;
1809num_j2=num_j;
1810num_i_out=num_i;
1811num_j_out=num_j;
[339]1812% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1813if isequal(mode,'series(Di)')
[32]1814    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1815    num_i2_line=num_i+ind_shift(4);
1816    % adjust the first and last field number
1817        indsel=find(num_i1_line >= 1);
1818    num_i_out=num_i(indsel);
1819    num_i1_line=num_i1_line(indsel);
1820    num_i2_line=num_i2_line(indsel);
1821    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1822    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1823    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1824    [xx,num_i2]=meshgrid(num_j,num_i2_line);
[339]1825elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
[32]1826    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1827        num_j1=ind_shift(1)*ones(size(num_i));
1828        num_j2=ind_shift(2)*ones(size(num_i));
1829    else
1830        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1831        num_j2_col=num_j+ind_shift(2);
1832        % adjust the first field number
1833        indsel=find((num_j1_col >= 1));   
1834        num_j_out=num_j(indsel);
1835        num_j1_col=num_j1_col(indsel);
1836        num_j2_col=num_j2_col(indsel);
1837        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1838        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1839    end   
1840end
[2]1841
[41]1842%------------------------------------------------------------------------
[446]1843% --- Executes on button press in CheckObject.
1844function CheckObject_Callback(hObject, eventdata, handles)
[41]1845%------------------------------------------------------------------------
[446]1846% SeriesData=get(handles.series,'UserData');
1847value=get(handles.CheckObject,'Value');
[2]1848if value
[446]1849     set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
[76]1850     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
[2]1851     if ishandle(hset_object)
[421]1852         uistack(hset_object,'top')% show the GUI set_object if opened
[2]1853     else
[41]1854         %get the object file
[376]1855         InputTable=get(handles.InputTable,'Data');
1856         defaultname=InputTable{1,1};
[106]1857         if isempty(defaultname)
1858            defaultname={''};
1859         end
[41]1860        [FileName, PathName, filterindex] = uigetfile( ...
1861       {'*.xml;*.mat', ' (*.xml,*.mat)';
1862       '*.xml',  '.xml files '; ...
1863        '*.mat',  '.mat matlab files '}, ...
[427]1864        'Pick an xml object file (or use uvmat to create it)',defaultname);
[41]1865        fileinput=[PathName FileName];%complete file name
1866        sizf=size(fileinput);
1867        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1868        %read the file
[427]1869        data=xml2struct(fileinput);
[446]1870        if ~isfield(data,'Type')
1871             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
1872             return
[41]1873        end
1874        if ~isfield(data,'ProjMode')
[446]1875             data.ProjMode='none';
[41]1876        end
[446]1877        hset_object=set_object(data);% call the set_object interface
[2]1878     end
[446]1879     Object=read_GUI(hset_object);
1880     set(handles.ProjObject,'String',Object.Name);%display the object name
[2]1881else
[446]1882    set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
[2]1883end
[446]1884%set(handles.series,'UserData',SeriesData)
[2]1885
1886%--------------------------------------------------------------
[446]1887function CheckMask_Callback(hObject, eventdata, handles)
1888value=get(handles.CheckMask,'Value');
[2]1889if value
[41]1890    msgbox_uvmat('ERROR','not implemented yet')
[2]1891end
1892%--------------------------------------------------------------
1893
[41]1894%-------------------------------------------------------------------
[2]1895%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
1896function ncbrowser_uvmat(hObject, eventdata)
[41]1897%-------------------------------------------------------------------
[2]1898     bla=get(gcbo,'String');
1899     ind=get(gcbo,'Value');
1900     filename=cell2mat(bla(ind));
1901      blank=find(filename==' ');
1902      filename=filename(1:blank-1);
1903     get_field(filename)
1904
[41]1905% ------------------------------------------------------------------
[2]1906function MenuHelp_Callback(hObject, eventdata, handles)
[41]1907%-------------------------------------------------------------------
[2]1908path_to_uvmat=which ('uvmat');% check the path of uvmat
1909pathelp=fileparts(path_to_uvmat);
[36]1910helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
1911if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
[2]1912else
[36]1913    addpath (fullfile(pathelp,'uvmat_doc'))
1914    web([helpfile '#series'])
[2]1915end
1916
[41]1917%-------------------------------------------------------------------
[446]1918% --- Executes on selection change in TransformName.
1919function TransformName_Callback(hObject, eventdata, handles)
[41]1920%-------------------------------------------------------------------
[39]1921global nb_transform
[2]1922
[446]1923menu=get(handles.TransformName,'String');
1924ind_coord=get(handles.TransformName,'Value');
[39]1925coord_option=menu{ind_coord};
[446]1926list_transform=get(handles.TransformName,'UserData');
[39]1927ff=functions(list_transform{end});
1928if isequal(coord_option,'more...');
1929    coord_fct='';
1930    prompt = {'Enter the name of the transform function'};
1931    dlg_title = 'user defined transform';
1932    num_lines= 1;
1933    [FileName, PathName, filterindex] = uigetfile( ...
1934       {'*.m', ' (*.m)';
1935        '*.m',  '.m files '; ...
1936        '*.*', 'All Files (*.*)'}, ...
1937        'Pick a file', ff.file);
1938    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
1939        PathName(end)=[];
1940    end
1941    transform_selected =fullfile(PathName,FileName);
1942    if ~exist(transform_selected,'file')
1943          return
1944    end
1945    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
1946    if ~isequal(ext_fct,'.m')
1947        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1948        return
1949    end
[446]1950   menu=update_menu(handles.TransformName,transform);%add the selected fct to the menu
1951   ind_coord=get(handles.TransformName,'Value');
[39]1952   addpath(PathName)
1953   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
[446]1954   set(handles.TransformName,'UserData',list_transform)
[39]1955   rmpath(PathName)
1956   % save the new menu in the personal file 'uvmat_perso.mat'
1957   dir_perso=prefdir;%personal Matalb directory
1958   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1959   if exist(profil_perso,'file')
1960       for ilist=nb_transform+1:numel(list_transform)
[55]1961           ff=functions(list_transform{ilist});
[39]1962           transform_fct{ilist-nb_transform}=ff.file;
1963       end
1964        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
1965   end
1966end
[2]1967
[446]1968%check the current ActionPath to the selected function
[248]1969if ~isempty(list_transform{ind_coord})
[39]1970func=functions(list_transform{ind_coord});
[446]1971set(handles.TransformPath,'String',fileparts(func.file)); %show the path to the senlected function
[248]1972else
[446]1973   set(handles.TransformPath,'String',''); %show the path to the senlected function
[248]1974end
[350]1975
[446]1976% %------------------------------------------------------------------------
1977% % --- Executes on button press in REFRESH_INDICES.
1978%     function REFRESH_INDICES_Callback(hObject, eventdata, handles)
1979% %------------------------------------------------------------------------       
1980% % hObject    handle to REFRESH_INDICES (see GCBO)
1981% % eventdata  reserved - to be defined in a future version of MATLAB
1982% % handles    structure with handles and user data (see GUIDATA)
1983% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
1984% InputTable=get(handles.InputTable,'Data');
1985% check_lines=get(handles.REFRESH_INDICES,'UserData');
1986%
1987% %% check the indices and FileTypes for each series (limited to the new ones to save time)
1988% for ind_list=1:length(check_lines)
1989%     if  check_lines(ind_list)
1990%         InputLine=InputTable(ind_list,:);
1991%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
1992%         detect_idem=detect_idem(detect_idem>0);
1993%         if ~isempty (detect_idem)
1994%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
1995%             set(handles.InputTable,'Data',InputTable)
1996%         end
1997%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
1998%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
1999%         %update file series defined by the selected line
2000%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
2001%         if ~isempty(errormsg)
2002%                 msgbox_uvmat('ERROR',errormsg)
2003%                 return
2004%         end
2005%     end
2006% end
2007% set(handles.InputTable,'Data',InputTable)
2008% SeriesData=get(handles.series,'UserData');
2009%
2010% state_j='off';
2011% state_Pairs='off';
2012% state_InputFields='off';
2013% val=get(handles.ListView,'Value');
2014% ListViewString={''};
2015% if ~isempty(SeriesData)
2016% %     ListViewString={};
2017%     for iview=1:size(InputTable,1)
2018%         if ~isempty(SeriesData.j1_series{iview})
2019%             state_j='on';
2020%         end
2021%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
2022%             state_Pairs='on';
2023%             ListViewString{iview}=num2str(iview);
2024%             if check_lines(iview)
2025%                 val=iview;%select the last pair if it is a new entry
2026%             end
2027%         end
2028%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
2029%             state_InputFields='on';
2030%         end
2031%     end
2032% end
2033% set(handles.ListView,'Value',val)
2034% set(handles.ListView,'String',ListViewString)
2035% if strcmp(state_Pairs,'on')
2036%     ListView_Callback(hObject,eventdata,handles)
2037% end
2038% set(handles.PairString,'Visible',state_Pairs)
2039% enable_j(handles,state_j)
2040% set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
2041% set(handles.REFRESH_INDICES,'visible','off')
[350]2042
[372]2043% -----------------------------------------------------------------------
2044% --- Update min and max indices of a file series by scanning with find_file_series
2045% --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
2046% --- 1 or 001 by the function find_file_series
2047% --- This function also dispaly the set of availbale files in the series
2048% --- and the menus appropriate to the file type as well as timing possibly set
2049% --- by an xml image documentation file
2050function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
2051% -----------------------------------------------------------------------
[350]2052%% look for min and max indices existing in the file series and update SeriesData
2053errormsg='';
[398]2054[FilePath,FileName,FileExt]=fileparts(fileinput);
2055% detect the file type, get the movie object if relevant, and look for the corresponding file series:
2056% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
2057[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
[350]2058if isempty(RootFile)&&isempty(i1_series)
[358]2059    errormsg='no input file in the series';
[350]2060    return
2061end
2062
[408]2063%% adjust the min and max indices common to all the file series
[350]2064MinIndex=get(handles.MinIndex,'Data');
2065MaxIndex=get(handles.MaxIndex,'Data');
2066MinIndex_i=min(i1_series(i1_series>0));
2067if ~isempty(i2_series)
2068    MaxIndex_i=max(i2_series(i2_series>0));
2069else
2070    MaxIndex_i=max(i1_series(i1_series>0));
2071end
2072MinIndex_j=min(j1_series(j1_series>0));
2073if ~isempty(j2_series)
2074    MaxIndex_j=max(j2_series(j2_series>0));
2075else
2076    MaxIndex_j=max(j1_series(j1_series>0));
2077end
[358]2078MinIndex{iview,1}=MinIndex_i;
2079MinIndex{iview,2}=MinIndex_j;
2080MaxIndex{iview,1}=MaxIndex_i;
2081MaxIndex{iview,2}=MaxIndex_j;
[350]2082set(handles.MinIndex,'Data',MinIndex)
2083set(handles.MaxIndex,'Data',MaxIndex)
2084SeriesData=get(handles.series,'UserData');
[358]2085SeriesData.i1_series{iview}=i1_series;
2086SeriesData.i2_series{iview}=i2_series;
2087SeriesData.j1_series{iview}=j1_series;
2088SeriesData.j2_series{iview}=j2_series;
2089SeriesData.FileType{iview}=FileType;
[350]2090
[372]2091%% display the set of existing files as an image
[350]2092set(handles.waitbar_frame,'Units','pixels')
2093pos=get(handles.waitbar_frame,'Position');
2094xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2095yima=0.5:pos(4)-0.5;
2096[XIma,YIma]=meshgrid(xima,yima);
2097nb_i=size(i1_series,1);
2098nb_j=size(i1_series,2);
2099ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2100ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2101[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2102CData=zeros([size(XIma) 3]);
2103file_ima=double((i1_series(:,:,1)>0)');
2104if numel(file_ima)>=2
2105if size(file_ima,1)==1
2106    CLine=interp1(ind_i,file_ima,xima,'nearest');
2107    CData(:,:,2)=ones(size(yima'))*CLine;
2108else
2109    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2110end
2111set(handles.waitbar_frame,'CData',CData)
2112end
2113set(handles.waitbar_frame,'Units','normalized')
2114
2115%% enable field and veltype menus
[446]2116testfield=isequal(get(handles.FieldName,'enable'),'on');
2117testfield_1=isequal(get(handles.FieldName_1,'enable'),'on');
2118testveltype=isequal(get(handles.VelType,'enable'),'on');
2119testveltype_1=isequal(get(handles.VelType_1,'enable'),'on');
2120testtransform=isequal(get(handles.TransformName,'Enable'),'on');
[372]2121% testnc=0;
2122% testnc_1=0;
2123% testcivx=0;
2124% testcivx_1=0;
2125% testima=0; %test for image input
2126% if isequal(lower(FileExt),'.avi') %.avi file
2127%     testima=1;
2128% elseif ~isempty(imformats(FileExt(2:end)))
2129%     testima=1;
2130% elseif isequal(FileExt,'.vol')
2131%      testima=1;
2132% end
[350]2133%TODO: update
2134% if length(FileExtCell)==1 || length(FileExtCell)>2
2135%     for iview=1:length(FileExtCell)
2136%         if isequal(FileExtCell{iview},'.nc')
2137%             testnc=1;
2138%         end
2139%         if isequal(FileTypeCell{iview},'civx')
2140%             testcivx=1;
2141%         end
2142%     end
2143% elseif length(FileExtCell)==2
2144%     testnc=isequal(FileExtCell{1},'.nc');
2145%     testnc_1=isequal(FileExtCell{2},'.nc');
2146%     testcivx=isequal(FileTypeCell{1},'civx');
2147%     testcivx_1=isequal(FileTypeCell{2},'civx');
2148% end
[372]2149switch FileType
2150    case {'civx','civdata'}
[350]2151    view_FieldMenu(handles,'on')
[446]2152    menustr=get(handles.FieldName,'String');
[372]2153    if isequal(menustr,{'get_field...'})
[446]2154        set(handles.FieldName,'String',{'get_field...';'velocity';'vort';'div';'more...'})
[350]2155    end
[446]2156    set(handles.VelType,'Visible','on')
[372]2157    set(handles.FieldTransform,'Visible','on')
2158    %      view_TRANSFORM(handles,'on')
2159    %     TODO: second menu
2160    %           view_FieldMenu_1(handles,'on')
2161    %     if testcivx_1
[446]2162    %         menustr=get(handles.FieldName_1,'String');
[372]2163    %         if isequal(menustr,{'get_field...'})
[446]2164    %             set(handles.FieldName_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
[372]2165    %         end
2166    %     else
[446]2167    %         set(handles.FieldName_1,'Value',1)
2168    %         set(handles.FieldName_1,'String',{'get_field...'})
2169    %     set(handles.VelType_1,'Visible','on')
[372]2170    %     set(handles.VelType_text_1,'Visible','on');
2171    %     end
2172    %     view_FieldMenu_1(handles,'off')
2173    case 'netcdf'
2174    view_FieldMenu(handles,'on')
[446]2175    set(handles.FieldName,'Value',1)
2176    set(handles.FieldName,'String',{'get_field...'})
[372]2177    set(handles.FieldTransform,'Visible','off')
2178    %     view_TRANSFORM(handles,'off')
2179    case {'image','multimage','video'}
[350]2180    view_FieldMenu(handles,'off')
2181    view_FieldMenu_1(handles,'off')
[446]2182    set(handles.VelType,'Visible','off')
[350]2183    set(handles.VelType_text,'Visible','off');
2184end
[372]2185
2186
[350]2187%TODO:update
2188% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2189%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2190%     return
2191% end 
2192
2193%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2194ext_imadoc='';
[398]2195FileBase=fullfile(RootPath,RootFile);
[350]2196if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2197    ext_imadoc=FileExt;
2198elseif exist([FileBase '.xml'],'file')
2199    ext_imadoc='.xml';
2200elseif exist([FileBase '.civ'],'file')
2201    ext_imadoc='.civ';
2202end
2203%read the ImaDoc file
2204XmlData=[];
2205NbSlice_calib={};
2206if isequal(ext_imadoc,'.xml')
2207        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2208        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2209            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2210        end
2211        if isfield(XmlData,'Time')
[408]2212            time{iview}=XmlData.Time;
[350]2213        end
2214        if isfield(XmlData,'Camera')
2215            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2216                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2217                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2218                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2219                end
2220            end
2221            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2222                TimeUnit=XmlData.Camera.TimeUnit;
2223            end
2224        end
2225        if ~isempty(warntext)
2226            msgbox_uvmat('WARNING',warntext)
2227        end 
2228elseif isequal(ext_imadoc,'.civ')
2229    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
[408]2230    time{iview}=XmlData.Time;
[350]2231    if error==2, warntext=['no file ' FileBase '.civ'];
2232    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2233    end 
[408]2234end
[350]2235
[408]2236%% update time table
[446]2237TimeTable=get(handles.TimeTable,'Data');
[408]2238TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
2239TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
2240set(handles.TimeTable,'Data',TimeTable)
[350]2241
2242%% number of slices
2243if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2244       siz=size(XmlData.GeometryCalib.SliceCoord);
2245       if siz(1)>1
2246           NbSlice=siz(1);
2247       else
2248           NbSlice=1;
2249       end
2250       set(handles.num_NbSlice,'String',num2str(NbSlice))
2251end
[408]2252% set(handles.mode,'Visible','off') % do not show index pairstring by default
2253set(handles.PairString,'Visible','off')
2254% set(handles.num_ref_i,'Visible','off')
[350]2255% set(handles.ref_i_text,'Visible','off')
2256testpair=0;
[408]2257%set the menus of image pairstring and default selection for series
2258%list pairstring if relevant
[350]2259% Val=get(handles.NomType,'Value');
2260% synchronise_view(handles,Val)
2261
2262% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2263%     state_j='off'; %no need for j index
2264% else
2265%     state_j='on'; %case of j index
2266% end
[408]2267% show index pairstring if files exist
[350]2268set(handles.series,'UserData',SeriesData)
2269
[351]2270
[446]2271% --------------------------------------------------------------------
2272function MenuExportConfig_Callback(hObject, eventdata, handles)
2273global Series
2274[tild,Series,errormsg]=prepare_jobs(handles);
2275% Series=read_GUI(handles.series);
[358]2276
[446]2277evalin('base','global Series')%make CurData global in the workspace
2278display('current series config :')
2279evalin('base','Series') %display CurData in the workspace
2280commandwindow; %brings the Matlab command window to the front
Note: See TracBrowser for help on using the repository browser.