source: trunk/src/series.m @ 295

Last change on this file since 295 was 276, checked in by sommeria, 9 years ago

further cleaning after new GUI civ: rationalisation of check_Grid and txt_gridName
records the path of uvmat, series, civ, by addpath

File size: 91.9 KB
Line 
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)
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)
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)
57global nb_builtin_ACTION nb_builtin_transform
58% Choose default command line output for series
59handles.output = hObject;
60% Update handles structure
61guidata(hObject, handles);
62%default initial parameters
63drawnow
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)
68%load the list of previously browsed files in menus Open and Open_1
69dir_perso=prefdir;
70test_profil_perso=0;
71profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
72if exist(profil_perso,'file')
73     h=load (profil_perso);
74     test_profil_perso=1;
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')
104    set(handles.transform_fct,'String',param.menu_coord_str)
105end
106if isfield(param,'menu_coord_val')
107    set(handles.transform_fct,'Value',param.menu_coord_val);
108else
109     set(handles.transform_fct,'Value',1);%default
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
127set(hObject,'WindowButtonDownFcn',{'mouse_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display)
128NomType_Callback(hObject, eventdata, handles)
129
130%loads the information stored in prefdir to initiate  the list of ACTION functions
131fct_menu={'check_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
132transform_menu={'';'phys';'px';'phys_polar'};
133nb_builtin_ACTION=numel(fct_menu); %number of functions
134nb_transform=numel(transform_menu);
135[path_series,name,ext]=fileparts(which('series'));
136path_series=fullfile(path_series,'series');%path of the function 'series'
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
139for ilist=1:length(fct_menu)
140    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
141end
142
143%TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
144menu_str={'';'phys';'px';'phys_polar'};
145nb_builtin_transform=numel(menu_str); %number of functions
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
157end
158rmpath(fullfile(path_uvmat,'transform_field'))
159
160% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
161if test_profil_perso
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
166             fct_menu=[fct_menu; {file}];
167         end
168    end
169    if isfield(h,'transform_fct') && iscell(h.transform_fct)
170        for ilist=1:length(h.transform_fct);
171             [path,file]=fileparts(h.transform_fct{ilist});
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
184    end
185end
186fct_menu=[fct_menu;{'more...'}];
187set(handles.ACTION,'String',fct_menu)
188set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
189
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
196% display the GUI for the default action 'check_files'
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
218if isempty(RootPathCell)|isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
219     dir_perso=prefdir;
220     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
221     if exist(profil_perso,'file')
222          h=load (profil_perso);
223         if isfield(h,'filebase')&ischar(h.filebase)
224                 oldfile=h.filebase;
225         end
226         if isfield(h,'RootPath')&ischar(h.RootPath)
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
244%testblank=findstr(fileinput,' ');%look for blanks
245% if ~isempty(testblank)
246%     errordlg('forbidden input file name: contain blanks')
247%     return
248% end
249sizf=size(fileinput);
250if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
251[path,name,ext]=fileparts(fileinput);
252SeriesData=[];%dfault
253if isequal(ext,'.xml')
254    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
255elseif isequal(ext,'.xls')
256    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
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
280    txt=ver('MATLAB');
281    Release=txt.Release;
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
320RootPathCell=get(handles.RootPath,'String');
321RootFileCell=get(handles.RootFile,'String');
322oldfile=''; %default
323if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
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
348% testblank=findstr(fileinput,' ');%look for blanks
349% if ~isempty(testblank)
350%     errordlg('forbidden input file name: contain blanks')
351%     return
352% end
353sizf=size(fileinput);
354if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
355[path,name,ext]=fileparts(fileinput);
356SeriesData=[];%dfault
357if isequal(ext,'.xml')
358    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
359elseif isequal(ext,'.xls')
360    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
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
384    txt=ver('MATLAB');
385    Release=txt.Release;
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
421%------------------------------------------------------------------------
422% ---  refresh the GUI data after introduction of a new file series
423function update_file(hObject, eventdata, handles,fileinput,addtest)
424%------------------------------------------------------------------------ 
425if ~exist(fileinput,'file')
426    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
427    return
428end
429
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);
432
433%check for movie image files
434if ~isempty(FileExt)
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
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
459    SeriesData=get(handles.figure1,'UserData');
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
528nb_field=NaN;%default
529nb_field2=NaN;%default
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]);
539    time=(0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond)';
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');
560testtransform=isequal(get(handles.transform_fct,'Enable'),'on');
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']);
647        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
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
680
681% if ~isempty(time)
682%     siztime=size(time);
683%     nb_field=siztime(1);
684%     nb_field2=siztime(2);
685% end   
686set(handles.TimeUnit,'String',TimeUnit)
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
693if isnan(nb_field)
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);
709set(handles.figure1,'UserData',SeriesData);
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
725%store the root name for future opening of uvmat
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
731    txt=ver('MATLAB');
732    Release=txt.Release;
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
745%------------------------------------------------------------
746function RootPath_Callback(hObject, eventdata, handles)
747Val=get(handles.RootPath,'Value');
748synchronise_view(handles,Val)
749NomType_Callback(hObject, eventdata, handles)
750%------------------------------------------------------------
751
752function synchronise_view(handles,Val)
753set(handles.RootPath,'Value',Val)
754set(handles.SubDir,'Value',Val)
755set(handles.RootFile,'Value',Val)
756set(handles.NomType,'Value',Val)
757set(handles.FileExt,'Value',Val)
758set(handles.nb_field,'Value',Val)
759set(handles.nb_field2,'Value',Val)
760set(handles.time_first,'Value',Val)
761set(handles.time_last,'Value',Val)
762
763
764%---------------------------------------------------------
765% Executes on carriage return on the subdir civ1 edit window
766%--------------------------------------------------------
767function SubDir_Callback(hObject, eventdata, handles)
768
769Val=get(handles.SubDir,'Value');
770synchronise_view(handles,Val)
771NomType_Callback(hObject, eventdata, handles)
772
773%--------------------------------------------------------------
774%function activated when a new filebase (image series) is introduced
775%------------------------------------------------------------
776function RootFile_Callback(hObject, eventdata, handles)
777Val=get(handles.RootFile,'Value');
778synchronise_view(handles,Val)
779NomType_Callback(hObject, eventdata, handles)
780
781%--------------------------------------------------------------
782%function activated when a new filebase (image series) is introduced
783%------------------------------------------------------------
784function FileExt_Callback(hObject, eventdata, handles)
785Val=get(handles.FileExt,'Value');
786synchronise_view(handles,Val)
787
788%--------------------------------------------------------------
789%function activated when a new filebase (image series) is introduced
790%------------------------------------------------------------
791function nb_field_Callback(hObject, eventdata, handles)
792Val=get(handles.nb_field,'Value');
793synchronise_view(handles,Val)
794
795%--------------------------------------------------------------
796%function activated when a new filebase (image series) is introduced
797%------------------------------------------------------------
798function nb_field2_Callback(hObject, eventdata, handles)
799Val=get(handles.nb_field2,'Value');
800synchronise_view(handles,Val)
801
802%--------------------------------------------------------------
803%function activated when a new filebase (image series) is introduced
804%------------------------------------------------------------
805function time_first_Callback(hObject, eventdata, handles)
806Val=get(handles.time_first,'Value');
807synchronise_view(handles,Val)
808
809%--------------------------------------------------------------
810%function activated when a new filebase (image series) is introduced
811%------------------------------------------------------------
812function time_last_Callback(hObject, eventdata, handles)
813Val=get(handles.time_last,'Value');
814synchronise_view(handles,Val)
815
816%--------------------------------------------------------------
817%function activated by NomType
818%------------------------------------------------------------
819NomType_Callback(hObject, eventdata, handles)
820
821%------------------------------------------------------------------------
822function NomType_Callback(hObject, eventdata, handles)
823%------------------------------------------------------------------------
824hseries=get(handles.ProjObject,'Parent');
825SeriesData=get(hseries,'UserData');
826if isfield(SeriesData,'NomType')
827    NomTypeCell=SeriesData.NomType;
828else
829    NomTypeCell={};
830end
831nbfield2_cell=get(handles.nb_field2,'String');
832val=get(handles.nb_field2,'Value');
833if iscell(nbfield2_cell)
834    nbfield2=str2num(nbfield2_cell{val});
835else
836    nbfield2=str2num(nbfield2_cell);
837end
838nbfield_cell=get(handles.nb_field,'String');
839if iscell(nbfield_cell)
840    nbfield=str2num(nbfield_cell{val});
841else
842   nbfield=str2num(nbfield_cell);
843end
844
845set(handles.mode,'Visible','off') % do not show index pairs by default
846set(handles.list_pair_civ,'Visible','off')
847set(handles.ref_i,'Visible','off')
848set(handles.ref_i_text,'Visible','off')
849testpair=0;
850state_j='off';
851%set the menus of image pairs and default selection for series
852%list pairs if relevant
853Val=get(handles.NomType,'Value');
854synchronise_view(handles,Val)
855if ~isempty(NomTypeCell)
856    NomType=NomTypeCell{Val};
857    switch NomType 
858            case {'_i1-i2_j', '_i1-i2'}
859                set(handles.mode,'String',{'series(Di)'})
860                set(handles.mode,'Value',1);
861                set(handles.mode,'Visible','on')
862                testpair=1;
863            case {'#_ab'}
864                set(handles.mode,'String',{'bursts'})
865                set(handles.mode,'Value',1);
866                testpair=1;
867            case '_i_j1-j2'
868                set(handles.mode,'String',{'bursts';'series(Dj)'})%multiple choice
869                if ~isempty(nbfield) && ~isempty(nbfield2) && ((nbfield2>10) || (nbfield==1))
870                    set(handles.mode,'Value',2);
871                else
872                    set(handles.mode,'Value',1);% advice 'bursts' for small bursts
873                end
874                set(handles.mode,'Visible','on')
875                testpair=1;
876    end
877    switch NomType   
878            case {'_1_1','_i_j1-j2','_i1-i2_j','1_ab','01_ab'},% two navigation indices
879                state_j='on';
880    end
881end
882if testpair
883    mode_Callback(hObject, eventdata, handles) 
884else
885    set(handles.NomType,'String',NomTypeCell)
886    set(handles.first_j,'Visible',state_j)
887    set(handles.incr_j,'Visible',state_j)
888    set(handles.last_j,'Visible',state_j)
889    set(handles.nb_field2,'Visible',state_j)
890end
891
892
893%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
894% --- Executes on button press in mode.
895%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896function mode_Callback(hObject, eventdata, handles)
897%hseries=get(handles.mode,'parent');
898hseries=handles.figure1;
899SeriesData=get(hseries,'UserData');
900mode_list=get(handles.mode,'String');
901mode_value=get(handles.mode,'Value');
902mode=mode_list{mode_value};
903NomType=[];
904test_find_pair=0;
905if isfield(SeriesData,'NomType')
906    NomTypeCell=SeriesData.NomType;
907    Val=get(handles.NomType,'Value');
908    NomType=NomTypeCell{Val};
909    test_find_pair=isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')|| isequal(NomType,'#_ab');
910end
911time=[];
912if isfield(SeriesData,'Time')
913time=SeriesData.Time{1}; %get the set of times
914end
915siztime=size(time);
916nbfield=siztime(1);
917nbfield2=siztime(2);
918indchosen=1;  %%first pair selected by default
919if isequal(mode,'bursts')
920    enable_i(handles,'On')
921    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice) 
922elseif  isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')
923    enable_i(handles,'On')
924    enable_j(handles,'On') % allow both i and j index scanning
925else
926    enable_i(handles,'On')
927    enable_j(handles,'Off')
928end   
929set(handles.list_pair_civ,'Value',indchosen);%set the default choice of image pairs for civ1
930set(hseries,'UserData',SeriesData)
931
932%list pairs if relevant
933if test_find_pair
934     find_netcpair_civ(hObject, eventdata, handles,Val)
935end
936
937%-------------------------------------
938function enable_i(handles,state)
939set(handles.i_txt,'Visible',state)
940set(handles.first_i,'Visible',state)
941set(handles.last_i,'Visible',state)
942set(handles.incr_i,'Visible',state)
943set(handles.nb_field,'Visible',state)
944set(handles.ref_i,'Visible',state)
945set(handles.ref_i_text,'Visible',state)
946
947%-----------------------------------
948function enable_j(handles,state)
949set(handles.j_txt,'Visible',state)
950set(handles.first_j,'Visible',state)
951set(handles.last_j,'Visible',state)
952set(handles.incr_j,'Visible',state)
953set(handles.nb_field2,'Visible',state)
954set(handles.ref_j,'Visible',state)
955set(handles.ref_j_text,'Visible',state)
956
957%-----------------------------------
958function view_FieldMenu(handles,state)
959set(handles.FieldMenu,'Visible',state)
960set(handles.Field_text,'Visible',state)
961set(handles.Field_frame,'Visible',state)
962
963%-----------------------------------
964function view_FieldMenu_1(handles,state)
965set(handles.FieldMenu_1,'Visible',state)
966set(handles.Field_text_1,'Visible',state)
967
968%-----------------------------------
969function view_TRANSFORM(handles,state)
970set(handles.TRANSFORM_frame,'Visible',state)
971set(handles.transform_fct,'Visible',state);
972set(handles.TRANSFORM_title,'Visible',state)
973
974%--------------------------------------------------------------
975% determine the menu for civ1 pairs depending on existing netcdf files
976% with the reference indices ref_i and ref_j
977%----------------------------------------------------------------
978function find_netcpair_civ(hObject, eventdata, handles,Val)
979%hseries=get(handles.list_pair_civ,'parent');
980SeriesData=get(handles.figure1,'UserData');
981% NomTypeCell=get(handles.NomType,'String');
982NomTypeCell=SeriesData.NomType;
983NomType=NomTypeCell{Val};
984  set(handles.list_pair_civ,'Visible','on')
985%nomenclature types
986RootPathCell=get(handles.RootPath,'String');
987filepath=RootPathCell{Val};
988RootFileCell=get(handles.RootFile,'String');
989filename=RootFileCell{Val};
990filebase=fullfile(filepath,filename);
991SubDirCell=get(handles.SubDir,'String');
992subdir=SubDirCell{Val};
993if ~exist(fullfile(filepath,subdir),'dir')
994         msgbox_uvmat('ERROR',['no civ file available: subdirectory ' subdir ' does not exist'])
995         set(handles.list_pair_civ,'String',{''});
996         return
997end
998mode_list=get(handles.mode,'String');
999mode_value=get(handles.mode,'Value');
1000mode=mode_list{mode_value};
1001
1002%reads image numbers from the interface
1003ref_i=str2num(get(handles.ref_i,'String'));
1004ref_j=str2num(get(handles.ref_j,'String'));
1005ref_time=0;
1006nbfield=50;
1007nbfield2=50;%default max number of pairs
1008
1009%look for existing processed pairs involving the field at the middle of the series if civ1 will not
1010% be performed, while the result is needed for next steps.
1011displ_pair={''};
1012displ_num=[];
1013ind_exist=0;
1014TimeUnit=get(handles.TimeUnit,'String');
1015if length(TimeUnit)>=1
1016    dtunit=['m' TimeUnit];
1017else
1018    dtunit='e-03';
1019end
1020if strcmp(mode,'series(Di)')
1021     for index=1:min(nbfield-1,50)
1022         filename=name_generator(filebase,ref_i-floor(index/2),ref_j,'.nc',NomType,1,ref_i+ceil(index/2),ref_j,subdir);
1023         select=(exist(filename,'file')==2);
1024         if select==1
1025               ind_exist=ind_exist+1;
1026                displ_num(1,ind_exist)=0;
1027                displ_num(2,ind_exist)=0;
1028                displ_num(3,ind_exist)=-floor(index/2);
1029                displ_num(4,ind_exist)=ceil(index/2);
1030                %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
1031                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1032                if isfield(Cte,'dt2')
1033                    dt=Cte.dt2;
1034                elseif isfield(Cte,'dt')
1035                    dt=Cte.dt;
1036                end
1037                if isfield(Cte,'absolut_time_TO_2')
1038                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1039                elseif isfield(Cte,'absolut_time_TO')
1040                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1041                elseif isfield(Cte,'Time')
1042                    ref_time(ind_exist)=Cte.Time;
1043                end
1044                displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1045         end
1046     end
1047     set(handles.list_pair_civ,'String',[displ_pair';{'Di=*|*'}]);   
1048elseif isequal(mode,'series(Dj)')% series on the j index
1049       for index=1:min(nbfield2-1,50)
1050           filename=name_generator(filebase,ref_i,ref_j-floor(index/2),'.nc',NomType,1,ref_i,ref_j+ceil(index/2),subdir);
1051           select=(exist(filename,'file')==2);
1052           if select==1
1053               ind_exist=ind_exist+1;
1054                displ_num(1,ind_exist)=-floor(index/2);
1055                displ_num(2,ind_exist)=ceil(index/2);
1056                displ_num(3,ind_exist)=0;
1057                displ_num(4,ind_exist)=0;
1058                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1059                if isfield(Cte,'dt2')
1060                    dt=Cte.dt2;
1061                elseif isfield(Cte,'dt')
1062                    dt=Cte.dt;
1063                end
1064                if isfield(Cte,'absolut_time_TO_2')
1065                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1066                elseif isfield(Cte,'absolut_time_TO')
1067                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1068                elseif isfield(Cte,'Time')
1069                    ref_time(ind_exist)=Cte.Time;
1070                end
1071%                 if cte_detect(2)==1;
1072%                     dt=cte_read(2);
1073%                     ref_time(ind_exist)=cte_read(4);%civ2 data used in priority
1074%                 else
1075%                     dt=cte_read(1);
1076%                     ref_time(ind_exist)=cte_read(3);
1077%                 end
1078                displ_pair{ind_exist}=['Dj= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1079           end
1080       end
1081       set(handles.list_pair_civ,'String',[displ_pair';{'Dj=*|*'}]);
1082elseif isequal(mode,'bursts') %case of bursts
1083    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'bursts' mode
1084        for numod_b=(numod_a+1):nbfield2
1085            [filename]=name_generator(filebase,ref_i,numod_a,'.nc',NomType,1,ref_i,numod_b,subdir);
1086            select=(exist(filename,'file')==2);
1087            if select==1
1088                ind_exist=ind_exist+1;
1089                numlist_a(ind_exist)=numod_a;
1090                numlist_b(ind_exist)=numod_b;
1091                Attr=nc2struct(filename,[]);
1092                isfield(Attr,'absolut_time_T0_2')
1093                if isfield(Attr,'dt2')
1094                   dt(ind_exist)=Attr.dt2;
1095                   ref_time(ind_exist)=Attr.absolut_time_T0_2;
1096                elseif isfield(Attr,'dt')& isfield(Attr,'absolut_time_T0')
1097                   dt(ind_exist)=Attr.dt;
1098                   ref_time(ind_exist)=Attr.absolut_time_T0;
1099                else
1100                   dt(ind_exist)=NaN;%no information on dt
1101                end
1102                %determine nom_type_ima for pair display (used in num2stra.m)
1103                switch NomType
1104                    case {'#ab'}
1105                        nom_type_ima='#a';
1106                    case {'#AB'}
1107                        nom_type_ima='#A';
1108                    otherwise
1109                         nom_type_ima='_i_j';
1110                end
1111               displ_pair{ind_exist}=['j= ' num2stra(numod_a,nom_type_ima,2) '-' num2stra(numod_b,nom_type_ima,2) ...
1112                        ' :dt= ' num2str(dt(ind_exist)*1000)];
1113            end
1114         end
1115         set(handles.list_pair_civ,'String',[displ_pair';{'j=*-*'}]);
1116     end
1117     if exist('dt','var') & ~isempty(dt)
1118         [dtsort,indsort]=sort(dt);
1119         displ_num(1,:)=numlist_a(indsort);
1120         displ_num(2,:)=numlist_b(indsort);
1121         displ_num(3,:)=0;
1122         displ_num(4,:)=0;
1123         displ_pair=displ_pair(indsort);
1124         ref_time=ref_time(indsort);
1125     end
1126end
1127if ind_exist==0
1128         if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
1129            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir])
1130        else
1131            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir])
1132        end
1133        if isequal(mode,'bursts') %case of bursts
1134            set(handles.list_pair_civ,'String',{'j=*-*'});
1135        elseif isequal(mode,'series(Di)') %case of bursts
1136            set(handles.list_pair_civ,'String',{'Di=*|*'});
1137        elseif isequal(mode,'series(Dj)') %case of bursts
1138            set(handles.list_pair_civ,'String',{'Dj=*|*'});
1139        end
1140end
1141
1142val=get(handles.list_pair_civ,'Value');
1143if val > length(displ_pair)
1144    set(handles.list_pair_civ,'Value',1);% first pair proposed by default in the menu
1145    val=1;
1146end
1147iview=get(handles.NomType,'Value');
1148SeriesData.displ_num(iview,:)=(displ_num(:,val))';
1149SeriesData.ref_time=ref_time;
1150set(handles.figure1,'UserData',SeriesData)
1151list_pair_civ_Callback(hObject, eventdata, handles)
1152
1153%-------------------------------------------------------------
1154% --- Executes on selection in list_pair_civ.
1155function list_pair_civ_Callback(hObject, eventdata, handles)
1156%------------------------------------------------------------
1157
1158%update first_i and last_i according to the chosen image pairs
1159testupdate=0;
1160Val=get(handles.RootPath,'Value');
1161IndexCell=get(handles.NomType,'String');
1162%hseries=get(handles.list_pair_civ,'parent');
1163SeriesData=get(handles.figure1,'UserData');
1164NomType=SeriesData.NomType{Val};
1165list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
1166index_pair=get(handles.list_pair_civ,'Value');
1167str_pair=list_pair{index_pair};
1168ind_equ=strfind(str_pair,'=');%find '='
1169ind_sep=strfind(str_pair,'|');%find pair separator '|'
1170ind_com=strfind(str_pair,':');%find ':'
1171test_bursts=0;
1172if isempty(ind_sep)
1173    ind_sep=strfind(str_pair,'-');%find pair separator if it is not '|'
1174    test_bursts=1;% we are in the case of bursts
1175end
1176displ_num=[0 0 0 0]; %default
1177if ~isempty(ind_sep)&& ~strcmp(str_pair(ind_sep-1),'*')% if there is a pair separator ('|' or '-')
1178    num1_str=str_pair(ind_equ(1)+1:ind_sep-1);
1179    num2_str=str_pair(ind_sep+1:ind_com-1);
1180    num1=str2double(num1_str);
1181    num2=str2double(num2_str);
1182    if isequal(num1_str(1),' ')
1183        num1_str(1)=[];
1184    end   
1185    if isequal(num2_str(end),' ')
1186        num2_str(end)=[];
1187    end
1188    switch NomType
1189       case {'_i1-i2_j'}
1190           if isequal(num1_str(1),'0')
1191               IndexCell{Val}=['_(i-(i+' num2_str ')_j'];
1192           else
1193               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')_j'];
1194           end
1195           displ_num(3)=num1;
1196           displ_num(4)=num2;
1197       case {'_i1-i2'}
1198           if isequal(num1_str(1),'0')
1199               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1200           else
1201               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1202           end
1203           displ_num(3)=num1;
1204           displ_num(4)=num2;
1205       case '_i_j1-j2'
1206          if test_bursts
1207              IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1208          else
1209              if isequal(num1_str(1),'0')
1210                 IndexCell{Val}=['_i_j-(j+' num2_str ')'];
1211              else
1212                 IndexCell{Val}=['_i_(j' num1_str ')-(j+' num2_str ')'];
1213              end
1214          end
1215          displ_num(1)=num1;
1216          displ_num(2)=num2;
1217       case {'#_ab'} %TO COMPLETE
1218           IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1219
1220    end
1221end
1222set(handles.NomType,'String',IndexCell)
1223SeriesData.displ_num(Val,:)=displ_num;
1224set(handles.figure1,'UserData',SeriesData)
1225% set(handles.NomType,'Value',Val)
1226
1227if ~isequal(str_pair,'Dj=*|*')&~isequal(str_pair,'Di=*|*')
1228        mode_list=get(handles.mode,'String');
1229    mode_value=get(handles.mode,'Value');
1230    mode=mode_list{mode_value};
1231        if isequal(mode,'series(Di)')
1232        first_i=str2num(get(handles.first_i,'String'));
1233        last_i=str2num(get(handles.last_i,'String'));
1234        incr_i=str2num(get(handles.incr_i,'String'));
1235        num1=first_i:incr_i:last_i;
1236        lastfieldCell=get(handles.nb_field,'String');
1237        lastfield=str2num(lastfieldCell{1});
1238        if ~isempty(lastfield)
1239            ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1240            num1=num1(ind);       
1241        end
1242        if ~isempty(num1)
1243            set(handles.first_i,'String',num2str(num1(1)));
1244            set(handles.last_i,'String',num2str(num1(end)));
1245        end
1246        testupdate=1;
1247        elseif isequal(mode,'series(Dj)')
1248        first_j=str2num(get(handles.first_j,'String'));
1249        last_j=str2num(get(handles.last_j,'String'));
1250        incr_j=str2num(get(handles.incr_j,'String'));
1251        num_j=first_j:incr_j:last_j;
1252        lastfieldCell=get(handles.nb_field2,'String');
1253        if ~isempty(lastfieldCell)
1254            lastfield2=lastfieldCell{1};
1255            ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1256                 (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1257        end
1258        testupdate=1;
1259        end
1260       
1261        %update the first and last times of the series
1262        if testupdate && isfield(SeriesData,'Time')
1263        if ~isempty(SeriesData.Time{1})
1264            displ_time(handles,SeriesData.Time{1});
1265        end
1266        end
1267end
1268
1269%------------------------------------------------------------------------
1270% --- Executes on button press in RUN.
1271function RUN_Callback(hObject, eventdata, handles)
1272%------------------------------------------------------------------------
1273%read root name and field type
1274set(handles.RUN,'BusyAction','queue');
1275%hseries=get(handles.RUN,'parent');
1276set(0,'CurrentFigure',handles.figure1)
1277if isequal(get(handles.GetObject,'Visible'),'on') && isequal(get(handles.GetObject,'Value'),1)
1278    Series.GetObject=1;
1279    GetObject_Callback(hObject, eventdata, handles)
1280else
1281    Series.GetObject=0;
1282end
1283SeriesData=get(handles.figure1,'UserData');
1284
1285%reinitiate waitbar position
1286Series.WaitbarPos=get(handles.waitbar_frame,'Position');%TO SUPPRESS
1287waitbarpos=Series.WaitbarPos;
1288waitbarpos(4)=0.005;%reinitialize waitbar to zero height
1289waitbarpos(2)=Series.WaitbarPos(2)+Series.WaitbarPos(4)-0.005;
1290set(handles.waitbar,'Position',waitbarpos)
1291
1292% read input file parameters and set menus
1293Series.PathProject=get(handles.PathCampaign,'String');
1294RootPath=get(handles.RootPath,'String');% path of the root name of the first field series
1295RootFile=get(handles.RootFile,'String');% root name of the first field series
1296SubDir=get(handles.SubDir,'String');% subdirectory for netcdf files
1297FileExt=get(handles.FileExt,'String');%file extension
1298if isempty(SeriesData)
1299    msgbox_uvmat('ERROR','no input file series')
1300    return
1301end
1302NomType=SeriesData.NomType;
1303if length(RootPath)==1 %string character input for user fct
1304    Series.RootPath=RootPath{1};
1305    Series.RootFile=RootFile{1};
1306    Series.SubDir=SubDir{1};
1307    Series.FileExt=FileExt{1};
1308    Series.NomType=NomType{1};
1309else %cell input for user fct
1310    Series.RootPath=RootPath;
1311    Series.RootFile=RootFile;
1312    Series.SubDir=SubDir;
1313    Series.FileExt=FileExt;
1314    Series.NomType=NomType;
1315end
1316if isequal(get(handles.FieldMenu,'Visible'),'on')
1317    FieldMenu=get(handles.FieldMenu,'String');
1318    FieldValue=get(handles.FieldMenu,'Value');
1319    Series.Field=FieldMenu(FieldValue);
1320end
1321menu_coord_state=get(handles.transform_fct,'Visible');
1322Series.CoordType='';%default
1323if isequal(menu_coord_state,'on')
1324%     menu_coord=get(handles.transform_fct,'String');
1325    menu_index=get(handles.transform_fct,'Value');
1326    transform_list=get(handles.transform_fct,'UserData');
1327    Series.transform_fct=transform_list{menu_index};% transform function handles
1328end
1329Series.hseries=handles.figure1; % handles to the series GUI
1330
1331%read the set of field numbers
1332first_i=str2num(get(handles.first_i,'String'));
1333last_i=str2num(get(handles.last_i,'String'));
1334incr_i=str2num(get(handles.incr_i,'String'));
1335first_j=str2num(get(handles.first_j,'String'));
1336last_j=str2num(get(handles.last_j,'String'));
1337incr_j=str2num(get(handles.incr_j,'String'));
1338if ~isequal(get(handles.first_i,'Visible'),'on')
1339   first_i=1;
1340   last_i=1;
1341   incr_i=1;
1342end
1343if ~isequal(get(handles.first_j,'Visible'),'on')
1344    first_j=1;
1345    last_j=1;
1346    incr_j=1;
1347end
1348Series.NbSlice=str2num(get(handles.NbSlice,'String'));
1349if isequal(first_i,[])|isequal(first_j,[]), msgbox_uvmat('ERROR','first field number not defined'),...
1350    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1351if isequal(last_i,[])| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
1352    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1353if isequal(incr_i,[])| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
1354    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1355if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1356    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1357num_i=first_i:incr_i:last_i;
1358num_j=first_j:incr_j:last_j;
1359nbfield_cell=get(handles.nb_field,'String');
1360nbfield=[]; %default
1361for iview=1:length(nbfield_cell)
1362    nb=str2num(nbfield_cell{iview});
1363    if ~isempty(nb)
1364        nbfield=[nbfield nb];
1365    end
1366end
1367nbfield=min(nbfield);
1368nbfield2_cell=get(handles.nb_field2,'String');
1369nbfield2=[]; %default
1370for iview=1:length(nbfield2_cell)
1371    nb=str2num(nbfield2_cell{iview});
1372    if ~isempty(nb)
1373        nbfield2=[nbfield2 nb];
1374    end
1375end
1376nbfield2=min(nbfield2);
1377
1378%get complementary information from the 'series' interface
1379list_action=get(handles.ACTION,'String');% list menu action
1380index_action=get(handles.ACTION,'Value');% selected string index
1381action= list_action{index_action}; % selected string
1382mode_list=get(handles.mode,'String');
1383index_mode=get(handles.mode,'Value');
1384mode=mode_list{index_mode};
1385ind_shift=0;%default
1386
1387%determine the list of input file names
1388nbmissing=0;
1389for iview=1:length(RootPath)
1390    %case of pairs (.nc files)
1391   
1392    if isequal(NomType{iview},'_i_j1-j2')|| isequal(NomType{iview},'_i1-i2_j')|| isequal(NomType{iview},'_i1-i2')|| isequal(NomType{iview},'#_ab')
1393        ind_shift=SeriesData.displ_num(iview,:);
1394        if isequal(ind_shift,[0 0 0 0]) % undefined pairs
1395            if isequal(NomType{iview},'#_ab')
1396                mode='#_ab';
1397            end
1398            [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);
1399        else   
1400            [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1401            if isempty(num_i)
1402                msgbox_uvmat('ERROR','ERROR: empty set of input files chosen')
1403                return
1404            end
1405            if num_i(1)>first_i
1406               set(handles.first_i,'String',num2str(num_i(1)))%update the display of first field
1407               last_i_Callback(hObject, eventdata, handles)
1408            end
1409            if num_i(end)<last_i
1410               set(handles.last_i,'String',num2str(num_i(end)))%update the display of last field
1411               last_i_Callback(hObject, eventdata, handles)
1412            end
1413            if num_j(1)>first_j
1414               set(handles.first_j,'String',num2str(num_j(1)))%update the display of first field
1415               last_j_Callback(hObject, eventdata, handles)
1416            end
1417            if num_j(end)<last_j
1418               set(handles.last_j,'String',num2str(num_j(end)))%update the display of last field
1419               last_j_Callback(hObject, eventdata, handles)
1420            end
1421        end
1422    else%case of images
1423        [num_i1,num_j1]=meshgrid(num_i,num_j);
1424        num_i2=num_i1;
1425        num_j2=num_j1;
1426    end
1427    if length(RootPath)>1
1428        num_i1_cell{iview}=num_i1;
1429        num_i2_cell{iview}=num_i2;
1430        num_j1_cell{iview}=num_j1;
1431        num_j2_cell{iview}=num_j2;
1432    end
1433end
1434
1435% defining the ACTION function handle
1436path_series=which('series');
1437list_path=get(handles.ACTION,'UserData');
1438index=get(handles.ACTION,'Value');
1439fct_path=list_path{index}; %path stored for the function ACTION
1440if ~isequal(fct_path,path_series)
1441    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1442    if ~exist(fct_path,'dir')
1443        msgbox_uvmat('ERROR',['The prescibed function path ' fct_path ' does not exist'])
1444        return
1445    end
1446    if ~isequal(spath,fct_path)
1447        addpath(fct_path)% add the prescribed path if not the current one
1448    end
1449end
1450eval(['h_fun=@' action ';'])%create a function handle for ACTION
1451if ~isequal(fct_path,path_series)
1452        rmpath(fct_path)% add the prescribed path if not the current one   
1453end
1454
1455% RUN ACTION
1456Series.Action=action;%name of the processing programme
1457set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1458
1459if length(RootPath)>1
1460    h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
1461else
1462    h_fun(num_i1,num_i2,num_j1,num_j2,Series);
1463end
1464set(handles.RUN,'BackgroundColor',[1 0 0])
1465
1466% %save the current interface setting as figure namefig, append .0 to the name if it already exists
1467% detect=1;
1468% while detect==1
1469%     namefigfull=[namedoc '.fig'];
1470%     hh=dir(namefigfull);
1471%     if ~isempty(hh)
1472%         detect=1;
1473%         namedoc=[namedoc '.0'];
1474%     else
1475%         detect=0;
1476%     end
1477% end
1478% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1479
1480%------------------------------------------------------------------------
1481function STOP_Callback(hObject, eventdata, handles)
1482%------------------------------------------------------------------------
1483set(handles.RUN, 'BusyAction','cancel')
1484set(handles.RUN,'BackgroundColor',[1 0 0])
1485
1486
1487%------------------------------------------------------------------------
1488function first_i_Callback(hObject, eventdata, handles)
1489%------------------------------------------------------------------------
1490last_i_Callback(hObject, eventdata, handles)
1491
1492%------------------------------------------------------------------------
1493function last_i_Callback(hObject, eventdata, handles)
1494%------------------------------------------------------------------------
1495%     hseries=get(handles.last_i,'parent');
1496% first_i=str2num(get(handles.first_i,'String'));
1497% last_i=str2num(get(handles.last_i,'String'));
1498% ref_i=ceil((first_i+last_i)/2);
1499% set(handles.ref_i,'String', num2str(ref_i))
1500% ref_i_Callback(hObject, eventdata, handles)
1501SeriesData=get(handles.figure1,'UserData');
1502if ~isfield(SeriesData,'Time')
1503    SeriesData.Time{1}=[];
1504end
1505displ_time(handles,SeriesData.Time{1});
1506
1507%------------------------------------------------------------------------
1508function first_j_Callback(hObject, eventdata, handles)
1509%------------------------------------------------------------------------
1510 last_j_Callback(hObject, eventdata, handles)
1511
1512%------------------------------------------------------------------------
1513function last_j_Callback(hObject, eventdata, handles)
1514%------------------------------------------------------------------------
1515first_j=str2num(get(handles.first_j,'String'));
1516last_j=str2num(get(handles.last_j,'String'));
1517ref_j=ceil((first_j+last_j)/2);
1518set(handles.ref_j,'String', num2str(ref_j))
1519ref_j_Callback(hObject, eventdata, handles)
1520SeriesData=get(handles.figure1,'UserData');
1521if ~isfield(SeriesData,'Time')
1522    SeriesData.Time{1}=[];
1523end
1524displ_time(handles,SeriesData.Time{1});
1525
1526
1527%------------------------------------------------------------------------
1528function ref_i_Callback(hObject, eventdata, handles)
1529%------------------------------------------------------------------------
1530mode_list=get(handles.mode,'String');
1531mode_value=get(handles.mode,'Value');
1532mode=mode_list{mode_value};
1533%hseries=get(handles.ref_i,'parent');
1534SeriesData=get(handles.figure1,'UserData');
1535%NomTypeCell=get(handles.NomType,'String');
1536NomTypeCell=SeriesData.NomType;
1537if ~isempty(NomTypeCell)
1538Val=get(handles.NomType,'Value');
1539NomType=NomTypeCell{Val};
1540% for ilist=1:length(NomType)
1541    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1542        if isequal(mode,'series(Di)')
1543            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1544%             break
1545        end
1546    end
1547end
1548
1549%------------------------------------------------------------------------
1550function ref_j_Callback(hObject, eventdata, handles)
1551%------------------------------------------------------------------------
1552mode_list=get(handles.mode,'String');
1553mode_value=get(handles.mode,'Value');
1554mode=mode_list{mode_value};
1555%hseries=get(handles.ref_i,'parent');
1556SeriesData=get(handles.figure1,'UserData');
1557NomTypeCell=SeriesData.NomType;
1558if ~isempty(NomTypeCell)
1559    Val=get(handles.NomType,'Value');
1560    NomType=NomTypeCell{Val};
1561    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1562        if isequal(mode,'series(Dj)')
1563            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1564        end
1565    end
1566end
1567
1568%------------------------------------------------------------------------
1569% --- Executes on selection change in ACTION.
1570function ACTION_Callback(hObject, eventdata, handles)
1571%------------------------------------------------------------------------
1572global nb_builtin_ACTION
1573list_ACTION=get(handles.ACTION,'String');% list menu fields
1574index_ACTION=get(handles.ACTION,'Value');% selected string index
1575ACTION= list_ACTION{index_ACTION}; % selected function name
1576path_series=which('series');%path to series.m
1577list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1578default_file=fullfile(list_path{end},ACTION);
1579% add a new function to the menu if the selected item is 'more...'
1580if isequal(ACTION,'more...')
1581    pathfct=fileparts(path_series);
1582    [FileName, PathName, filterindex] = uigetfile( ...
1583       {'*.m', ' (*.m)';
1584        '*.m',  '.m files '; ...
1585        '*.*', 'All Files (*.*)'}, ...
1586        'Pick a file',default_file);
1587    if length(FileName)<2
1588        return
1589    end
1590    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1591    if ~isequal(ext_fct,'.m')
1592        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1593        return
1594    end
1595   
1596   % insert the choice in the action menu
1597   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1598   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1599   list_path{index_ACTION}=PathName;
1600   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1601       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1602       menu_str(nb_builtin_ACTION+1:end-5)=[];
1603       list_path(nb_builtin_ACTION+1:end-4)=[];
1604       index_ACTION=index_ACTION-nbremove;
1605       set(handles.ACTION,'Value',index_ACTION)
1606       set(handles.ACTION,'String',menu_str)
1607   end
1608   list_path{index_ACTION}=PathName;
1609   set(handles.ACTION,'UserData',list_path);
1610   set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1611   
1612   %record the current menu in personal file profil_perso
1613   dir_perso=prefdir;
1614   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1615   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1616       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1617   end
1618   if nb_builtin_ACTION+1<=length(menu_str)-1
1619       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1620           save(profil_perso,'series_fct','-append')
1621       else
1622           txt=ver('MATLAB');
1623           Release=txt.Release;
1624           relnumb=str2num(Release(3:4));
1625           if relnumb >= 14%recent relaese of Matlab
1626               save(profil_perso,'series_fct','-V6')
1627           else
1628               save(profil_perso, 'series_fct')
1629           end
1630       end
1631   end
1632end
1633
1634%check the current path to the selected function
1635PathName=list_path{index_ACTION};%current recorded path
1636set(handles.path,'String',PathName); %show the path to the senlected function
1637
1638%default setting for the visibility of the GUI elements
1639set(handles.RootPath,'UserData','many')
1640set(handles.SubDir,'Visible','on')
1641set(handles.RootFile,'Visible','on')
1642set(handles.NomType,'Visible','on')
1643set(handles.FileExt,'Visible','on')
1644set(handles.NbSlice,'Visible','off')
1645set(handles.NbSlice_title,'Visible','off')
1646set(handles.VelTypeMenu,'Visible','off');
1647set(handles.VelType_text,'Visible','off');
1648set(handles.VelTypeMenu_1,'Visible','off');
1649set(handles.VelType_text_1,'Visible','off');
1650view_FieldMenu(handles,'off')
1651view_FieldMenu_1(handles,'off')
1652view_TRANSFORM(handles,'off')
1653set(handles.ProjObject_frame,'Visible','off');
1654set(handles.GetMask,'Visible','off')
1655set(handles.Mask,'Visible','off')
1656set(handles.GetObject,'Visible','off');
1657set(handles.ProjObject,'Visible','off');
1658set(handles.OutputDir,'Visible','off');
1659set(handles.PARAMETERS_frame,'Visible','off');
1660set(handles.PARAMETERS_title,'Visible','off');
1661set(handles.ParamKey,'Visible','off')
1662set(handles.ParamVal,'Visible','off')
1663ParamKey={};
1664set(handles.FieldMenu,'Enable','off')
1665set(handles.VelTypeMenu,'Enable','off')
1666set(handles.FieldMenu_1,'Enable','off')
1667set(handles.VelTypeMenu_1,'Enable','off')
1668set(handles.transform_fct,'Enable','off')
1669%set the displayed GUI item needed for input parameters
1670if ~isequal(path_series,PathName)
1671    addpath(PathName)
1672end
1673eval(['h_function=@' ACTION ';']);
1674try
1675    [fid,errormsg] =fopen([ACTION '.m']);
1676    InputText=textscan(fid,'%s',1,'delimiter','\n');
1677    fclose(fid)
1678    set(handles.ACTION,'ToolTipString',InputText{1}{1})
1679end
1680if ~isequal(path_series,PathName)
1681    rmpath(PathName)
1682end
1683varargout=h_function();
1684Param_list={};
1685
1686%nb_series=length(RootFile);
1687FileExt=get(handles.FileExt,'String');
1688nb_series=length(FileExt);
1689testima_series=1; %test for a list of images only
1690testima=1;
1691testima_1=1;
1692testciv_series=1;
1693for iview=1:nb_series
1694    ext=FileExt{iview};
1695    if length(ext)<2
1696        ext='.none';
1697    end
1698    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1699    if ~testimaview
1700        if iview==1
1701            testima=0;
1702        end
1703        if iview==2
1704            testima_1=0;
1705        end
1706        testima_series=0;
1707    end
1708end
1709for ilist=1:length(varargout)-1
1710    switch varargout{ilist}
1711                       %RootFile always visible
1712         case 'RootPath'   %visible by default
1713            value=lower(varargout{ilist+1});
1714            if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1715                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1716            end
1717        case 'SubDir' %visible by default
1718            if isequal(lower(varargout{ilist+1}),'off')
1719                set(handles.SubDir,'Visible','off')
1720            end
1721        case 'RootFile'   %visible by default
1722            value=lower(varargout{ilist+1});
1723            if isequal(value,'off')
1724                set(handles.RootFile,'Visible','off')
1725            elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1726                set(handles.RootFile,'Visible','on')
1727                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1728            end
1729        case 'NomType'   %visible by default
1730            if isequal(lower(varargout{ilist+1}),'off')
1731                set(handles.NomType,'Visible','off')
1732            end
1733        case 'FileExt'   %visible by default
1734            if isequal(lower(varargout{ilist+1}),'off')
1735                set(handles.FileExt,'Visible','off')
1736            end
1737        case 'NbSlice'   %hidden by default
1738            if isequal(lower(varargout{ilist+1}),'on')
1739                set(handles.NbSlice,'Visible','on')
1740                set(handles.NbSlice_title,'Visible','on')
1741            end
1742        case 'VelTypeMenu'   %hidden by default
1743            if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1744                set(handles.VelTypeMenu,'Enable','on')
1745                if nb_series >=1 && ~testima_series
1746                    set(handles.VelTypeMenu,'Visible','on')
1747                    set(handles.VelType_text,'Visible','on');
1748                    set(handles.Field_frame,'Visible','on')
1749                end
1750            end
1751            if isequal(lower(varargout{ilist+1}),'two')
1752                set(handles.VelTypeMenu_1,'Enable','on')
1753                if nb_series >=2 && ~testima_series
1754                    set(handles.VelTypeMenu_1,'Visible','on')
1755                    set(handles.VelType_text_1,'Visible','on');
1756                end
1757            end
1758        case 'FieldMenu'   %hidden by default
1759            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1760                set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1761                if nb_series >=1 && ~testima_series
1762                    view_FieldMenu(handles,'on')
1763                end
1764            end
1765            if isequal(lower(varargout{ilist+1}),'two')
1766                set(handles.FieldMenu_1,'Enable','on')
1767                if nb_series >=2 && ~testima_1
1768                    view_FieldMenu_1(handles,'on')
1769                end
1770            end
1771        case 'CoordType'   %hidden by default
1772            if isequal(lower(varargout{ilist+1}),'on')
1773                set(handles.transform_fct,'Enable','on')
1774                view_TRANSFORM(handles,'on')
1775            end
1776        case 'GetObject'   %hidden by default
1777            if isequal(lower(varargout{ilist+1}),'on')   
1778                set(handles.ProjObject_frame,'Visible','on')
1779                set(handles.GetObject,'Visible','on');
1780            end
1781        case 'Mask'   %hidden by default
1782            if isequal(lower(varargout{ilist+1}),'on')   
1783                set(handles.ProjObject_frame,'Visible','on')
1784                set(handles.GetMask,'Visible','on');
1785            end
1786        case 'PARAMETER' 
1787            set(handles.PARAMETERS_frame,'Visible','on')
1788            set(handles.PARAMETERS_title,'Visible','on')
1789            set(handles.ParamKey,'Visible','on')
1790            %set(handles.ParamVal,'Visible','on')
1791            Param_str=varargout{ilist+1};
1792            Param_list=[Param_list; {Param_str}];         
1793    end
1794end
1795if ~isempty(Param_list)
1796    set(handles.ParamKey,'String',Param_list)
1797    set(handles.ParamVal,'Visible','on')
1798end
1799
1800%------------------------------------------------------------------------
1801% --- Executes on selection change in FieldMenu.
1802function FieldMenu_Callback(hObject, eventdata, handles)
1803%------------------------------------------------------------------------
1804field_str=get(handles.FieldMenu,'String');
1805field_index=get(handles.FieldMenu,'Value');
1806field=field_str{field_index(1)};
1807if isequal(field,'get_field...')   
1808     hget_field=findobj(allchild(0),'name','get_field');
1809     if ~isempty(hget_field)
1810         delete(hget_field)%delete opened versions of get_field
1811     end
1812     %hseries=get(handles.FieldMenu,'parent');
1813     SeriesData=get(handles.figure1,'UserData');
1814     filename=SeriesData.CurrentInputFile;
1815     if exist(filename,'file')
1816        get_field(filename)
1817     end
1818elseif isequal(field,'more...')
1819    str=calc_field;
1820    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1821                'SelectionMode','single',...
1822                'ListString',str);
1823       % edit the choice in the fields and action menu
1824     scalar=cell2mat(str(ind_answer));
1825     update_menu(handles.FieldMenu,scalar)
1826end
1827
1828%------------------------------------------------------------------------
1829% --- Executes on selection change in FieldMenu_1.
1830function FieldMenu_1_Callback(hObject, eventdata, handles)
1831%------------------------------------------------------------------------
1832field_str=get(handles.FieldMenu_1,'String');
1833field_index=get(handles.FieldMenu_1,'Value');
1834field=field_str{field_index};
1835if isequal(field,'get_field...')   
1836     hget_field=findobj(allchild(0),'name','get_field_1');
1837     if ~isempty(hget_field)
1838         delete(hget_field)
1839     end
1840     %hseries=get(handles.FieldMenu,'parent');
1841     SeriesData=get(handles.figure1,'UserData');
1842     filename=SeriesData.CurrentInputFile_1;
1843     if exist(filename,'file')
1844        hget_field=get_field(filename);
1845        set(hget_field,'name','get_field_1')
1846     end
1847elseif isequal(field,'more...')
1848    str=calc_field;
1849    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1850                'SelectionMode','single',...
1851                'ListString',str);
1852       % edit the choice in the fields and action menu
1853     scalar=cell2mat(str(ind_answer));
1854     update_menu(handles.FieldMenu_1,scalar)
1855end   
1856
1857
1858%%%%%%%%%%%%%
1859function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1860
1861        indsel=ind_i;
1862        indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1863        indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1864        if ~isempty(indiff)
1865            indiff2=diff(indiff);
1866            indiffp=[indiff2 1];
1867            indiffm=[1 indiff2];
1868            ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1869            ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1870                %for each multiplet, select the most recent file
1871            ind_remove=[];
1872            for i=1:length(ind_multi_m)
1873                ind_pairs=ind_multi_m(i):ind_multi_p(i);
1874                for imulti=1:length(ind_pairs)
1875                    datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1876                end
1877                [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1878                ind_s=indsort2(1:end-1);%
1879                ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1880            end
1881        end
1882
1883%------------------------------------------------------------------------
1884% --- determine the list of index pairs of processing file
1885function [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)
1886%------------------------------------------------------------------------
1887num_i1=num_i;% set of first image numbers by default
1888num_i2=num_i;
1889num_j1=num_j;
1890num_j2=num_j;
1891num_i_out=num_i;
1892num_j_out=num_j;
1893if isequal (NomType,'_i1-i2_j') || isequal (NomType,'_i1-i2')
1894    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1895    num_i2_line=num_i+ind_shift(4);
1896    % adjust the first and last field number
1897        indsel=find(num_i1_line >= 1);
1898    num_i_out=num_i(indsel);
1899    num_i1_line=num_i1_line(indsel);
1900    num_i2_line=num_i2_line(indsel);
1901    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1902    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1903    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1904    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1905elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
1906    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1907        num_j1=ind_shift(1)*ones(size(num_i));
1908        num_j2=ind_shift(2)*ones(size(num_i));
1909    else
1910        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1911        num_j2_col=num_j+ind_shift(2);
1912        % adjust the first field number
1913        indsel=find((num_j1_col >= 1));   
1914        num_j_out=num_j(indsel);
1915        num_j1_col=num_j1_col(indsel);
1916        num_j2_col=num_j2_col(indsel);
1917        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1918        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1919    end   
1920end
1921
1922%------------------------------------------------------------------------
1923% ---- find the times corresponding to the first and last indices of a series
1924function displ_time(handles,times)
1925%------------------------------------------------------------------------
1926hseries=get(handles.last_i,'parent');
1927SeriesData=get(hseries,'UserData');%
1928first_i=str2num(get(handles.first_i,'String'));
1929first_j=str2num(get(handles.first_j,'String'));
1930last_i=str2num(get(handles.last_i,'String'));
1931last_j=str2num(get(handles.last_j,'String'));
1932% index_civ=get(handles.list_pair_civ,'Value');
1933% NomType=get(handles.NomType,'String');
1934NomType=SeriesData.NomType;
1935mode_list=get(handles.mode,'String');
1936index_mode=get(handles.mode,'Value');
1937mode=mode_list{index_mode};
1938% ind_shift=0;%default
1939
1940time_first=[];
1941time_last=[];
1942if ~isfield(SeriesData,'Time')
1943    SeriesData.Time{1}=[];
1944end
1945for iview=1:length(NomType)
1946    time_first_cell{iview}='?';
1947    time_last_cell{iview}='?';%default
1948    time=SeriesData.Time{iview};
1949    if isequal(NomType{iview},'_i1-i2_j')|isequal(NomType{iview},'_i_j1-j2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_i1-i2')
1950        if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
1951            ind_shift=SeriesData.displ_num(iview,:);
1952            if isequal(mode,'bursts')
1953                first_j=0;
1954                last_j=0;
1955            end
1956            first_i1=first_i +ind_shift(3);
1957            first_i2 =first_i +ind_shift(4);
1958            first_j1 =first_j +ind_shift(1);
1959            first_j2 =first_j +ind_shift(2);
1960            last_i1=last_i +ind_shift(3);
1961            last_i2 =last_i +ind_shift(4);   
1962            last_j1 =last_j +ind_shift(1);
1963            last_j2 =last_j +ind_shift(2);
1964            siz=size(SeriesData.Time{1});
1965            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
1966                time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
1967                time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
1968            else%read the time in the nc files
1969                RootPath=get(handles.RootPath,'String');
1970                RootFile=get(handles.RootFile,'String');
1971                SubDir=get(handles.SubDir,'String');
1972                %VelType=get(handles.VelType,'String');
1973                VelType_str=get(handles.VelTypeMenu,'String');
1974                VelType_val=get(handles.VelTypeMenu,'Value');
1975                VelType=VelType_str{VelType_val};
1976                filebase=fullfile(RootPath{1},RootFile{1});
1977                [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
1978                if  exist(filefirst,'file')
1979                    Attrib=nc2struct(filefirst,[]);
1980                    if isfield(Attrib,'Time')
1981                        time_first=Attrib.Time;
1982                    else
1983                        if isfield(Attrib,'absolut_time_T0')
1984                            time_first=Attrib.absolut_time_T0;
1985                        end
1986                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1987                            time_first=Attrib.absolut_time_T0_2;
1988                        end
1989                    end
1990                end
1991                [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
1992                if exist(filelast,'file')
1993                   Attrib=nc2struct(filelast,[]);
1994                    if isfield(Attrib,'Time')
1995                        time_last=Attrib.Time;
1996                    else
1997                        if isfield(Attrib,'absolut_time_T0')
1998                            time_last=Attrib.absolut_time_T0;
1999                        end
2000                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
2001                            time_last=Attrib.absolut_time_T0_2;
2002                        end
2003                    end
2004                end
2005            end
2006        end
2007    else
2008        siz=size(times);
2009        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
2010            time_first=times(first_i,first_j);
2011            time_last=times(last_i,last_j);
2012        end
2013    end
2014    time_first_cell{iview}=num2str(time_first,4);
2015    time_last_cell{iview}=num2str(time_last,4);
2016end
2017set(handles.time_first,'Value',1)
2018set(handles.time_last,'Value',1)
2019set(handles.time_first,'String',time_first_cell);
2020set(handles.time_last,'String',time_last_cell);
2021
2022%------------------------------------------------------------------------
2023% --- Executes on button press in GetObject.
2024function GetObject_Callback(hObject, eventdata, handles)
2025%------------------------------------------------------------------------
2026hseries=get(handles.GetObject,'parent');
2027SeriesData=get(hseries,'UserData');
2028value=get(handles.GetObject,'Value');
2029if value
2030     set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2031%      DataInit.ParentButton=handles.GetObject;
2032     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2033     if ishandle(hset_object)
2034         uistack(hset_object,'top')
2035        %[SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
2036     else
2037         %get the object file
2038         defaultname=get(handles.RootPath,'String');
2039         if isempty(defaultname)
2040            defaultname={''};
2041         end
2042        [FileName, PathName, filterindex] = uigetfile( ...
2043       {'*.xml;*.mat', ' (*.xml,*.mat)';
2044       '*.xml',  '.xml files '; ...
2045        '*.mat',  '.mat matlab files '}, ...
2046        'Pick an xml object file (or use uvmat to create it)',defaultname{1});
2047        fileinput=[PathName FileName];%complete file name
2048        testblank=findstr(fileinput,' ');%look for blanks
2049        if ~isempty(testblank)
2050            msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
2051            return
2052        end
2053        sizf=size(fileinput);
2054        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2055        %read the file
2056        t=xmltree(fileinput);
2057        data=convert(t);
2058        if ~isfield(data,'Style')
2059             data.Style='points';
2060        end
2061        if ~isfield(data,'ProjMode')
2062             data.ProjMode='projection';
2063        end
2064        transform_menu=get(handles.transform_fct,'String');
2065        ichoice=get(handles.transform_fct,'Value');
2066%         if isequal(transform_menu{ichoice},'px');
2067%             data.CoordType='px';
2068%         else
2069%             data.CoordType='phys';
2070%         end
2071        data.desable_plot=1;
2072        [SeriesData.hset_object,SeriesData.sethandles]=set_object(data);% call the set_object interface
2073     end
2074else
2075    set(handles.GetObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2076%     if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
2077%         close(SeriesData.hset_object)
2078%     end
2079end
2080set(hseries,'UserData',SeriesData)
2081
2082%--------------------------------------------------------------
2083function GetMask_Callback(hObject, eventdata, handles)
2084value=get(handles.GetMask,'Value');
2085if value
2086    msgbox_uvmat('ERROR','not implemented yet')
2087end
2088%--------------------------------------------------------------
2089
2090%-------------------------------------------------------------------
2091%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2092function ncbrowser_uvmat(hObject, eventdata)
2093%-------------------------------------------------------------------
2094     bla=get(gcbo,'String');
2095     ind=get(gcbo,'Value');
2096     filename=cell2mat(bla(ind));
2097      blank=find(filename==' ');
2098      filename=filename(1:blank-1);
2099     get_field(filename)
2100
2101% ------------------------------------------------------------------
2102function MenuHelp_Callback(hObject, eventdata, handles)
2103%-------------------------------------------------------------------
2104path_to_uvmat=which ('uvmat');% check the path of uvmat
2105pathelp=fileparts(path_to_uvmat);
2106helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2107if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2108else
2109    addpath (fullfile(pathelp,'uvmat_doc'))
2110    web([helpfile '#series'])
2111end
2112
2113%-------------------------------------------------------------------
2114% --- Executes on selection change in transform_fct.
2115function transform_fct_Callback(hObject, eventdata, handles)
2116%-------------------------------------------------------------------
2117global nb_transform
2118
2119% huvmat=get(handles.transform_fct,'parent');
2120menu=get(handles.transform_fct,'String');
2121ind_coord=get(handles.transform_fct,'Value');
2122coord_option=menu{ind_coord};
2123list_transform=get(handles.transform_fct,'UserData');
2124ff=functions(list_transform{end});
2125if isequal(coord_option,'more...');
2126    coord_fct='';
2127    prompt = {'Enter the name of the transform function'};
2128    dlg_title = 'user defined transform';
2129    num_lines= 1;
2130    [FileName, PathName, filterindex] = uigetfile( ...
2131       {'*.m', ' (*.m)';
2132        '*.m',  '.m files '; ...
2133        '*.*', 'All Files (*.*)'}, ...
2134        'Pick a file', ff.file);
2135    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2136        PathName(end)=[];
2137    end
2138    transform_selected =fullfile(PathName,FileName);
2139    if ~exist(transform_selected,'file')
2140          return
2141    end
2142    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
2143    if ~isequal(ext_fct,'.m')
2144        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2145        return
2146    end
2147   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
2148   ind_coord=get(handles.transform_fct,'Value');
2149   addpath(PathName)
2150   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2151   set(handles.transform_fct,'UserData',list_transform)
2152   rmpath(PathName)
2153   % save the new menu in the personal file 'uvmat_perso.mat'
2154   dir_perso=prefdir;%personal Matalb directory
2155   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2156   if exist(profil_perso,'file')
2157       for ilist=nb_transform+1:numel(list_transform)
2158           ff=functions(list_transform{ilist});
2159           transform_fct{ilist-nb_transform}=ff.file;
2160       end
2161        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2162   end
2163end
2164
2165%check the current path to the selected function
2166if ~isempty(list_transform{ind_coord})
2167func=functions(list_transform{ind_coord});
2168set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
2169else
2170   set(handles.path_transform,'String',''); %show the path to the senlected function
2171end
2172%------------------------------------------------------------------------
2173% --- generates a series of file names with reference numbers between range1 and
2174% --- range2 with increment incr. The reference number num_ref is the image number at the middle of the
2175% --- image pair. The set of first numbers num1 of the image pairs is also
2176% --- given as output
2177function [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)
2178%------------------------------------------------------------------------
2179[Path,Name]=fileparts(filebase);
2180filebasesub=fullfile(Path,subdir,Name);
2181filecell={};%default
2182num_i1=[];
2183num_i2=[];
2184num_j1=[];
2185num_j2=[];
2186ind0_i=first_i:incr_i:last_i;
2187nbcolumn=length(ind0_i);
2188ind0_j=first_j:incr_j:last_j;
2189nbline=length(ind0_j);
2190if isequal(mode,'#_ab')
2191    dirpair=dir([filebasesub '*_*.nc']);
2192elseif isequal(mode,'bursts')||isequal(mode,'series(Dj)') 
2193    dirpair=dir([filebasesub '_*_*-*.nc']);
2194elseif isequal(mode,'series(Di)')
2195    dirpair=dir([filebasesub '_*-*_*.nc']);
2196else
2197    msgbox_uvmat('ERROR','option *|* not yet implemented')
2198    return
2199end
2200if isempty(dirpair)
2201        msgbox_uvmat('ERROR','no pair detected in the selected range')
2202        return
2203end
2204
2205if isequal(mode,'bursts')||isequal(mode,'#_ab')
2206    icount=0;
2207    for ifile=1:length(dirpair)
2208        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2209        num1_r=str2num(str_1);
2210        if isequal(RootFile,Name) & ~isempty(num1_r)   
2211            num_i1(ifile)=num1_r;
2212            num_a(ifile)=stra2num(str_a);
2213            num_b(ifile)=stra2num(str_b);
2214        end     
2215    end
2216    test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
2217    ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
2218    select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
2219    ind_i=ind_i(select);%set of selected indices ind_i
2220    [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
2221    select=select(indsort);
2222    num_i1=num_i1(select);
2223    num_a=num_a(select);
2224    num_b=num_b(select);
2225    dirpair=dirpair(select);
2226    [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn);
2227    ind_i(ind_remove)=[];
2228    num_a(ind_remove)=[];
2229    num_b(ind_remove)=[];
2230    num_j1=zeros(1,nbcolumn);%default
2231    num_j2=num_j1;
2232    num_j1(ind_i)=num_a;
2233    num_j2(ind_i)=num_b;
2234    num_i1=first_i:incr_i:last_i;
2235    num_i2=num_i1;
2236    nbmissing=nbcolumn-length(ind_i);
2237
2238elseif isequal(mode,'series(Di)')
2239    %ind0_i=first_i:incr_i:last_i;
2240    %nbcolumn=length(ind0_i);
2241    %ind0_j=first_j:incr_j:last_j;
2242    %nbline=length(ind0_j);
2243    %dirpair=dir([filebasesub '_*-*_*.nc']);
2244    for ifile=1:length(dirpair)
2245        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2246        num_i1_r(ifile)=str2num(str_1);
2247        num_i2_r(ifile)=str2num(str_2);
2248        num_j(ifile)=str2num(str_a);
2249    end
2250    num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
2251    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
2252    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2253    ind_j=((num_j-first_j)/incr_j)+1;
2254    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2255    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2256    ind_ij=ind_ij(select);%set of selected indices ind_ij
2257    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2258    select=select(indsort);
2259    num_i1_r=num_i1_r(select);
2260    num_i2_r=num_i2_r(select);
2261    dirpair=dirpair(select);
2262    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2263    ind_ij(ind_remove)=[];
2264    num_i1_r(ind_remove)=[];
2265    num_i2_r(ind_remove)=[];
2266    num_i1=zeros(1,nbline*nbcolumn);%default
2267    num_i2=num_i1;
2268    num_i1(ind_ij)=num_i1_r;
2269    num_j2(ind_ij)=num_i2_r;
2270    num_i1=reshape(num_i1,nbline,nbcolumn);
2271    num_i2=reshape(num_i2,nbline,nbcolumn);
2272    num_j1=meshgrid(ind0_i,ind0_j);
2273    num_j2=num_j1;
2274    nbmissing=nbline*nbcolumn-length(ind_ij);
2275elseif isequal(mode,'series(Dj)')
2276    for ifile=1:length(dirpair)
2277        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2278        num_i(ifile)=str2num(str_1);
2279        num_a(ifile)=str2num(str_a);
2280        num_b(ifile)=str2num(str_b);
2281    end
2282    num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
2283    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
2284    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2285    ind_j=((num_j-first_j)/incr_j)+1;
2286    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2287    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2288    ind_ij=ind_ij(select);%set of selected indices ind_ij
2289    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2290    select=select(indsort);
2291    num_i=num_i(select);
2292    num_a=num_a(select);
2293    num_b=num_b(select);
2294    dirpair=dirpair(select);
2295    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2296    ind_ij(ind_remove)=[];
2297    num_a(ind_remove)=[];
2298    num_b(ind_remove)=[];
2299    num_j1=zeros(1,nbline*nbcolumn);%default
2300    num_j2=num_j1;
2301    num_j1(ind_ij)=num_a;
2302    num_j2(ind_ij)=num_b;
2303    num_j1=reshape(num_j1,nbline,nbcolumn);
2304    num_j2=reshape(num_j2,nbline,nbcolumn);
2305    num_i1=meshgrid(ind0_i,ind0_j);
2306    num_i2=num_i1;
2307    nbmissing=nbline*nbcolumn-length(ind_ij);
2308end
2309
2310%------------------------------------------------------------------------
2311% --- generates series of file indices corresponding to a file fileinput
2312function [num_i1,num_i2,num_j1,num_j2]=find_indexseries(fileinput)
2313%------------------------------------------------------------------------
2314num_i1=NaN;%default
2315num_i2=NaN;%default
2316num_j1=NaN;%default
2317num_j2=NaN;%default
2318% refresh input root name, indices, file extension and nomenclature
2319[RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
2320if strcmp(SubDir,'')
2321    filebasesub=fullfile(RootPath,RootFile);
2322else
2323    filebasesub=fullfile(RootPath,SubDir,RootFile);
2324end
2325dirpair=[]; %default
2326switch NomType
2327    case '_1'
2328        dirpair=dir([filebasesub '_*' FileExt]);
2329    case '_1_1'
2330        dirpair=dir([filebasesub '_*_*' FileExt]);
2331    case '_i1-i2'
2332        dirpair=dir([filebasesub '_*-*' FileExt]);
2333    case '1_ab'
2334        dirpair=dir([filebasesub '*_*' FileExt]);
2335    case '_i_j1-j2'
2336        dirpair=dir([filebasesub '*_*-*' FileExt]);   
2337    case '_i1-i2_j'
2338        dirpair=dir([filebasesub '*-*_*' FileExt]);   
2339end
2340for ifile=1:length(dirpair)
2341    [RootPath,RF,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name);
2342    num_i1(ifile)=str2double(str_1);
2343    num_i2(ifile)=str2double(str_2);
2344    if isnan(num_i2(ifile))
2345        num_i2(ifile)=num_i1(ifile);
2346    end
2347    num_j1(ifile)=stra2num(str_a);
2348    if isnan(num_j1(ifile))
2349        num_j1(ifile)=1;
2350    end
2351    num_j2(ifile)=stra2num(str_b);
2352    if isnan(num_j2(ifile))
2353        num_j2(ifile)=num_j1(ifile);
2354    end
2355end
2356
Note: See TracBrowser for help on using the repository browser.