source: trunk/src/series.m @ 329

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

bugs repaired in series, default size of view_field changed. ';' added in proj_field

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