source: trunk/src/series.m @ 100

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

nc2struct.m: convert variables to double after reading (civ gives single)
series.m: prob of initialisation solved
civ.m: gestion of button 'experimental' for new patch

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