source: trunk/src/series/time_series.m @ 27

Last change on this file since 27 was 27, checked in by gostiaux, 11 years ago

files separated from series.m

File size: 30.0 KB
Line 
1function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series)
2%----------------------------------------------------------------------
3% --- make a time series analysis
4%----------------------------------------------------------------------
5%INPUT:
6%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
7%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
8%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
9%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
10%OTHER INPUTS given by the structure Series
11
12%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
13if ~exist('num_i1','var')
14    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
15        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
16        'RootFile';'on';... %root input file name ('on' by default)
17        'FileExt';'on';... %input file extension ('on' by default)
18        'NomType';'on';...%type of file indexing ('on' by default)
19        'NbSlice';'on'; ...%nbre of slices ('off' by default)
20        'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
21        'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
22        'CoordType';'on';...%can use a transform function 'off' by default
23        'GetObject';'on';...%can use projection object ,'off' by default
24        %'GetMask';'on'...%can use mask option   ,'off' by default
25        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
26               ''};
27    return %exit the function
28end
29
30%------------------------------------------------------
31hseries=guidata(Series.hseries);%handles in the GUI series
32WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame
33
34%projection object
35test_object=get(hseries.GetObject,'Value');
36if test_object%isfield(Series,'sethandles')
37    Series.ProjObject=read_set_object(Series.sethandles);
38    %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
39    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' Series.ProjObject.Style]);
40    if ~isequal(answeryes,'Yes')
41        return
42    end
43else
44    msgbox_uvmat('ERROR','a projection object is needed');
45    return
46end
47
48% root names
49if iscell(Series.RootPath)
50    RootPath=Series.RootPath;
51    RootFile=Series.RootFile;
52    SubDir=Series.SubDir;
53    FileExt=Series.FileExt;
54    NomType=Series.NomType;
55else
56    RootPath={Series.RootPath};
57    RootFile={Series.RootFile};
58    SubDir={Series.SubDir};
59    FileExt={Series.FileExt};
60    NomType={Series.NomType};
61    num_i1={num_i1};
62    num_i2={num_i2};
63    num_j1={num_j1};
64    num_j2={num_j2};
65end
66ext=FileExt{1};
67form=imformats(ext([2:end]));%test valid Matlab image formats
68testima=0;
69if ~isempty(form)||isequal(lower(ext),'.avi')
70    testima=1;
71end
72nbview=length(RootPath);%number of series (1 or 2)
73nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series
74
75%Number of input series: this function  accepts only a single input file series
76nbview=length(RootPath);
77if nbview==2
78    %TODO: choose between difference and two series
79elseif nbview>2  % TODO: make multiple series
80%     RootPath=RootPath(1:2);
81%     set(hseries.RootPath,'String',RootPath)
82%     SubDir=SubDir(1:2);
83%     set(hseries.SubDir,'String',SubDir)
84%     RootFile=RootFile(1:2);
85%     set(hseries.RootFile,'String',RootFile)
86%     NomType=NomType(1:2);
87%     %set(hseries.NomType,'String',NomType)
88%     FileExt=FileExt(1:2);
89%     set(hseries.FileExt,'String',FileExt)
90%     nbview=2;
91end
92hhh=which('mmreader');
93for iview=1:nbview
94    test_movie(iview)=0;
95    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
96        if isequal(lower(FileExt{iview}),'.avi')
97            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
98            test_movie(iview)=1;
99        end
100    end
101end
102filebase{1}=fullfile(RootPath{1},RootFile{1});
103
104% number of slices
105NbSlice=str2num(get(hseries.NbSlice,'String'));
106if isempty(NbSlice)
107    NbSlice=1;
108end
109NbSlice_name=num2str(NbSlice);
110
111% Field and velocity type (the same for the two views)
112if isfield(Series,'Field')
113    FieldName=Series.Field;%the same set of fields for all views
114else
115    FieldName={''};
116end
117if isequal(FieldName,{'get_field...'})
118    hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
119    if numel(hget_field)>1
120        delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld
121    elseif isempty(hget_field)
122       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
123       idetect(iview)=exist(filename,'file');
124       hget_field=get_field(filename);
125       return
126    end
127    %hhget_field=guidata(hget_field);%handles of GUI elements in get_field
128    SubField=read_get_field(hget_field) %read the names of the variables to plot in the get_field GUI
129    if isempty(SubField)
130        delete(hget_field)
131       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
132        hget_field=get_field(filename);
133        SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
134    end
135%     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
136%         list_transform=get(hhget_field.menu_coord,'String');
137%         val_list=get(hhget_field.menu_coord,'Value');
138%         transform=list_transform{val_list};
139%     end
140end
141
142%detect whether the two files are 'images' or 'netcdf'
143testima=0;
144testvol=0;
145testcivx=0;
146testnc=0;
147FileExt=get(hseries.FileExt,'String');
148for iview=1:nbview
149     ext=FileExt{iview};
150     form=imformats(ext([2:end]));
151     if isequal(lower(ext),'.vol')
152         testvol=testvol+1;
153     elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
154         testima=testima+1;
155     elseif isequal(ext,'.nc')
156         testnc=testnc+1;
157     end
158end
159if testvol
160    msgbox_uvmat('ERROR','volume images not implemented yet')
161    return
162end
163if testnc~=nbview && testima~=nbview && testvol~=nbview
164    msgbox_uvmat('need a set of images or a set of netcdf files with the same fields as input','ERROR')
165    return
166end
167if ~isequal(FieldName,{'get_field...'})
168    testcivx=testnc;
169end
170
171% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
172filebasesub=fullfile(RootPath{1},RootFile{1});
173if NbSlice==1
174    filebase_out=[filebasesub '_time'];
175else
176    filebase_out=[filebasesub '_' NbSlice_name 'mtim'];
177    increment=num_i1{1}(2)-num_i1{1}(1);
178    if ~isequal(increment,1) % if an increment is set
179        answeryes=msgbox_uvmat('INPUT_Y-N',['will take time series in ' num2str(NbSlice) 'slices with increment = ' num2str(increment) '!']);
180    else   
181        answeryes=msgbox_uvmat('INPUT_Y-N',{['will take time series in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
182    end
183    if ~isequal(answeryes,'Yes')
184        return
185    end
186end
187VelType_str=get(hseries.VelTypeMenu,'String');
188VelType_val=get(hseries.VelTypeMenu,'Value');
189VelType{1}=VelType_str{VelType_val};
190if nbview==2
191    VelType_str=get(hseries.VelTypeMenu_1,'String');
192    VelType_val=get(hseries.VelTypeMenu_1,'Value');
193    VelType{2}=VelType_str{VelType_val};
194end
195
196%Calibration data and timing: read the ImaDoc files
197mode=''; %default
198timecell={};
199XmlData={};
200itime=0;
201NbSlice_calib={};
202for iview=1:nbview%Loop on views
203    XmlData{iview}=[];%default
204    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
205    if exist([filebase{iview} '.xml'],'file')
206        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
207        if isfield(XmlData{iview},'Time')
208            itime=itime+1;
209            timecell{itime}=XmlData{iview}.Time;
210        end
211        if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
212            NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
213            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
214                msgbox_uvmat('WARNING','inconsistent number of Z indices for the field series');
215            end
216        end
217    elseif exist([filebase{iview} '.civ'],'file')
218        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
219        itime=itime+1;
220        timecell{itime}=time;
221        XmlData{iview}.Time=time;
222        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
223        GeometryCalib.Tx=0;
224        GeometryCalib.Ty=0;
225        GeometryCalib.Tz=1;
226        GeometryCalib.dpx=1;
227        GeometryCalib.dpy=1;
228        GeometryCalib.sx=1;
229        GeometryCalib.Cx=0;
230        GeometryCalib.Cy=0;
231        GeometryCalib.f=1;
232        GeometryCalib.kappa1=0;
233        GeometryCalib.CoordUnit='cm';
234        XmlData{iview}.GeometryCalib=GeometryCalib;
235        if error==1
236            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
237        end
238    end
239end
240
241%check coincidence in time
242multitime=0;
243if length(timecell)==0
244    time=[];
245elseif length(timecell)==1
246    time=timecell{1};
247elseif length(timecell)>1
248    multitime=1;
249    for icell=1:length(timecell)
250        if ~isequal(size(timecell{icell}),size(timecell{1}))
251            warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING')
252            time=timecell{1};
253            multitime=0;
254            break
255        end
256    end
257end
258if multitime
259    for icell=1:length(timecell)
260        time(icell,:,:)=timecell{icell};
261    end
262    diff_time=max(max(diff(time)));
263    if diff_time>0
264        warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING')
265    end   
266end
267if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
268    time=[];
269end
270
271% image or scalar processing programme set by user
272Coord_menu=get(hseries.CoordType,'String');
273menu_val=get(hseries.CoordType,'Value');
274usrfct=Coord_menu{menu_val};
275testfct=~isequal(usrfct,'');
276
277% to update:
278VelType_str=get(hseries.VelTypeMenu,'String');
279VelType_val=get(hseries.VelTypeMenu,'Value');
280VelType{1}=VelType_str{VelType_val};
281if nbview==2
282    VelType_str=get(hseries.VelTypeMenu_1,'String');
283    VelType_val=get(hseries.VelTypeMenu_1,'Value');
284    VelType{2}=VelType_str{VelType_val};
285end
286
287%LOOP ON SLICES
288for i_slice=1:NbSlice
289     dt=[];
290     nbmissing=0; %number of undetected files
291     nbfiles=0;
292    %%%%%%%%%%%%%%%%%%%%%%%%%%%%LOOP ON FIELDS IN  A SLICE
293    for ifile=i_slice:NbSlice:nbfield 
294        stopstate=get(hseries.RUN,'BusyAction');
295        if isequal(stopstate,'queue')% enable STOP command
296             update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
297             for iview=1:nbview
298                filename=...
299                           name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
300                idetect(iview)=exist(filename,'file');
301                Data{iview}=[]; %default     
302                if testima                 
303                    Data{iview}.ListVarName={'A'};
304                    Data{iview}.AName='image';
305                    if test_movie(iview)
306                        A=read(MovieObject{iview},num_i1{iview}(ifile));
307                    else
308                        A=double(read_image(filename,NomType{iview},num_i1{iview}(ifile)));% read the image, num2 is the counter for avi files
309                    end
310                    Data{iview}.ListVarName={'coord_y','coord_x','A'}; %
311                    npy=size(A,1);
312                    npx=size(A,2);
313                    nbcolor=size(A,3);
314                    if nbcolor==3
315                         Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x','rgb'}};
316                    else
317                         Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'}};
318                    end 
319                    Data{iview}.coord_y=[npy-0.5 0.5];
320                    Data{iview}.coord_x=[0.5 npx-0.5];
321                    Data{iview}.A=A;
322                    Data{iview}.CoordType='px';
323                elseif testcivx
324                    [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
325                else
326                    [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data               
327                    Data{iview}.VarAttribute=SubField.VarAttribute;
328                end
329                if ~isempty(NbSlice_calib)  % z index
330                    Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
331                end
332             end
333            % geometry transform or other user defined transform
334            if ~isequal(Series.CoordType,'')           
335                if nbview==2
336                    [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
337                    if isempty(Data{2})
338                        Data(2)=[];
339                    end
340                else
341                    Data{1}=feval(Series.CoordType,Data{1},XmlData{1});
342                end
343            end
344            if testcivx
345                    Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
346            end
347            if length(Data)==2
348                [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
349                if ~isempty(errormsg)
350                    msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg])
351                    return
352                end
353            else
354                Field=Data{1};
355            end
356            if isfield(Series,'ProjObject')
357                Series.ProjObject
358                [Field,errormsg]=proj_field(Field,Series.ProjObject);
359                if ~isempty(errormsg)
360                    msgbox_uvmat('ERROR',['error in time_series/proj_field:' errormsg])
361                    return
362                end
363            end
364            if min(idetect)>=1% the input file(s) have been detected         
365                nbfiles=nbfiles+1;
366                if nbfiles==1 %first field: initiate the time series
367                    RecordData=Field;%default
368                    RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots         
369                    nbvar=length(Field.ListVarName);
370                    if nbvar==0
371                        msgbox_uvmat('ERROR','no input variable selected in get_field')
372                        return
373                    end
374                    testsum=2*ones(1,nbvar);%initiate flag for action on each variable
375                    indexfalse=0;
376                    CoordName={};
377                    indexremove=[];
378                    if isfield(Field,'VarAttribute') % look for coordinate and flag variables   
379                        for ivar=1:nbvar
380                            if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
381                                var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
382                                if isequal(var_role,'errorflag')
383                                    msgbox_uvmat('ERROR','do not handle error flags in time series')
384                                    return                                               
385                                end
386                                if isequal(var_role,'warnflag')                       
387                                    testsum(ivar)=0;  % not recorded variable
388                                    eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable
389                                end                 
390                                if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
391                                    isequal(var_role,'coord_z')|isequal(var_role,'coord')
392                                    testsum(ivar)=1; %constant coordinates, record without time evolution
393                                end
394                                % check whether the variable ivar is a dimension variable
395                                %index=Field.VarDimIndex{ivar};%dimension indices of the variable #ivar
396                                DimCell=Field.VarDimName{ivar};
397                                if ischar(DimCell)
398                                    DimCell={DimCell};
399                                end
400                                if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
401                                   testsum(ivar)=1;
402                                end
403                            end
404                        end
405                    end
406                    for ivar=1:nbvar
407                        if testsum(ivar)==2                     
408                            eval(['RecordData.' Field.ListVarName{ivar} '=[];'])
409                        end
410                    end
411                    RecordData.ListVarName=[{'Time'} RecordData.ListVarName];
412                end
413                for ivar=1:length(Field.ListVarName)
414                    VarName=Field.ListVarName{ivar};
415                    eval(['VarVal=Field.' VarName ';']);
416                    if testsum(ivar)==2% test for recorded variable
417                        eval(['VarVal=Field.' VarName ';']);
418                        if isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
419                            if isempty(VarVal)
420                                msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
421                                return                             
422                            end
423                            VarVal=mean(VarVal,1);
424                        end
425                        VarVal=shiftdim(VarVal,-1); %shift dimension
426                        eval(['RecordData.' VarName '=cat(1,RecordData.' VarName ',VarVal);']);%concanete the current field to the time series   
427                    elseif testsum(ivar)==1% variable representing fixed coordinates
428                        eval(['VarInit=RecordData.' VarName ';']);
429                        if ~isequal(VarVal,VarInit)
430                            msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName])
431                            return
432                        end
433                    end                 
434                end
435                % time:
436                if isempty(time)% time read in ncfiles
437                   if isfield(Field,'Time')
438                       RecordData.Time(nbfiles,1)=Field.Time;
439                   else
440                       RecordData.Time(nbfiles,1)=nbfiles;%default
441                   end
442                else % time from ImaDoc prevails
443                    RecordData.Time(nbfiles,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
444                end
445            else
446                nbmissing=nbmissing+1;
447            end
448        end
449    end
450    %remove time for global attributes if exists
451    for iattr=1:numel(RecordData.ListGlobalAttribute)
452        if strcmp(RecordData.ListGlobalAttribute{iattr},'Time')
453            RecordData.ListGlobalAttribute(iattr)=[];
454            break
455        end
456    end
457    for ivar=1:numel(RecordData.ListVarName)
458        VarName=RecordData.ListVarName{ivar};
459        eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons
460    end
461        % add time dimension and update VarDimIndex:
462   %if ~isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
463        for ivar=1:length(Field.ListVarName)
464%              vardimindex=Field.VarDimIndex{ivar};% array of dimension indices for variable VarIndex(ivar)
465             DimCell=Field.VarDimName(ivar);
466             if testsum(ivar)==2%variable used as time series
467%                  RecordData.VarDimIndex{ivar}=[1 vardimindex+1];
468                  RecordData.VarDimName{ivar}=[{'Time'} DimCell];
469             elseif testsum(ivar)==1
470%                  RecordData.VarDimIndex{ivar}=[vardimindex+1];
471                 RecordData.VarDimName{ivar}=DimCell;
472             end
473        end
474   % end
475    indexremove=find(~testsum);
476    if ~isempty(indexremove)
477        RecordData.ListVarName(1+indexremove)=[];
478        RecordData.VarDimName(indexremove)=[];
479        if isfield(RecordData,'Role')&~isempty(RecordData.Role{1})%generaliser aus autres attributs
480            RecordData.Role(1+indexremove)=[];
481        end
482    end
483    %RecordData.VarDimIndex=[{[1]} RecordData.VarDimIndex]; %time dimension
484    %shift variable attributes
485    if isfield(RecordData,'VarAttribute')
486        RecordData.VarAttribute=[{[]} RecordData.VarAttribute];
487    end
488    RecordData.VarDimName=[{'Time'} RecordData.VarDimName];
489    RecordData.Action=Series.Action;%name of the processing programme
490    %name of result file
491    [filemean]=...
492               name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),SubDir{1});
493    errormsg=struct2nc(filemean,RecordData); %save result file
494    if isempty(errormsg)
495        display([filemean ' written'])
496    else
497        msgbox_uvmat('ERROR',['error in Series/struct2nc' errormsg])
498    end
499end
500figure
501haxes=axes;
502
503plot_field(RecordData,haxes)
504hget_field=findobj(allchild(0),'name','get_field');
505if ~isempty(hget_field)
506    delete(hget_field)
507end
508get_field(filemean,RecordData)
509   
510%-----------------------------------------------------------------------
511% --- Executes on selection change in CoordType.
512function CoordType_Callback(hObject, eventdata, handles)
513menu_str=get(handles.CoordType,'String');
514ind_coord=get(handles.CoordType,'Value');
515coord_option=menu_str{ind_coord};
516if isequal(coord_option,'more...');
517    fct_name='';
518    if exist('./TMP/current_usr_fct.mat','file')% if a file is found
519        h=load('./TMP/current_usr_fct.mat');
520        if isfield(h,'fct_name');
521            fct_name=h.fct_name;
522        end
523    end
524    prompt = {'Enter the name of the transform function'};
525    dlg_title = 'user defined transform';
526    num_lines= 1;
527    [FileName, PathName, filterindex] = uigetfile( ...
528       {'*.m', ' (*.m)';
529        '*.m',  '.m files '; ...
530        '*.*', 'All Files (*.*)'}, ...
531        'Pick a file', fct_name);
532    fct_name=fullfile(PathName,FileName);
533    addpath(PathName);%add the path to the selected fct
534    [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
535    if ~exist(fct_name,'file')
536           warndlg(['image procesing fct ' fct_name ' not found'])
537    else
538        transform=FileName(1:end-2);%
539        update_menu(handles.CoordType,transform)%add the selected fct to the menu
540  %      set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu
541      %save ('./TMP/current_usr_fct.mat','fct_name');
542    end   
543end
544ind_coord=get(handles.CoordType,'Value');   
545
546%---------------------------------------------------------------------
547% --- Executes on selection change in ProjObject.
548function ProjObject_Callback(hObject, eventdata, handles)
549
550list_object=get(handles.ProjObject,'String');
551index=get(handles.ProjObject,'Value');
552hseries=get(handles.ProjObject,'Parent');
553SeriesData=get(hseries,'UserData');
554Obj=SeriesData.ProjObject{index};
555[SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index});
556set(hseries,'UserData',SeriesData);
557
558%-------------------------------------------------------------
559%generates a series of file names with reference numbers between range1 and
560%range2 with increment incr. The reference number num_ref is the image number at the middle of the
561%image pair. The set of first numbers num1 of the image pairs is also
562%given as output
563%------------------------------------------------------
564function [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)
565[Path,Name]=fileparts(filebase);
566filebasesub=fullfile(Path,subdir,Name);
567filecell={};%default
568num_i1=[];
569num_i2=[];
570num_j1=[];
571num_j2=[];
572ind0_i=first_i:incr_i:last_i;
573nbcolumn=length(ind0_i);
574ind0_j=first_j:incr_j:last_j;
575nbline=length(ind0_j);
576if isequal(mode,'#_ab')
577    dirpair=dir([filebasesub '*_*.nc']);
578elseif isequal(mode,'bursts')|isequal(mode,'series(Dj)') 
579    dirpair=dir([filebasesub '_*_*-*.nc']);
580elseif isequal(mode,'series(Di)')
581    dirpair=dir([filebasesub '_*-*_*.nc']);
582else
583    errordlg('option *|* not yet implemented')
584    return
585end
586if isempty(dirpair)
587        errordlg('no pair detected in the selected range')
588        return
589end
590    %ind0_i=first_i:incr_i:last_i;
591    %nbcolumn=length(ind0_i);
592    %dirpair=dir([filebasesub '_*_*-*.nc']);
593if isequal(mode,'bursts')|isequal(mode,'#_ab')
594    icount=0;
595    for ifile=1:length(dirpair)
596        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
597       
598%         if isempty(str2num(str_1))
599%             dirpair(ifile).name
600%         end
601        num1_r=str2num(str_1);
602        if isequal(RootFile,Name) & ~isempty(num1_r)   
603            num_i1(ifile)=num1_r;
604            num_a(ifile)=stra2num(str_a);
605            num_b(ifile)=stra2num(str_b);
606%             icount=icount+1;
607        end     
608    end
609    length(dirpair)
610%     num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
611    test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
612    ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
613    select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
614    ind_i=ind_i(select);%set of selected indices ind_i
615    [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
616    select=select(indsort);
617    num_i1=num_i1(select);
618    num_a=num_a(select);
619    num_b=num_b(select);
620    dirpair=dirpair(select);
621    [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn);
622    ind_i(ind_remove)=[];
623    num_a(ind_remove)=[];
624    num_b(ind_remove)=[];
625    num_j1=zeros(1,nbcolumn);%default
626    num_j2=num_j1;
627    num_j1(ind_i)=num_a;
628    num_j2(ind_i)=num_b;
629    num_i1=first_i:incr_i:last_i;
630    num_i2=num_i1;
631    nbmissing=nbcolumn-length(ind_i);
632
633elseif isequal(mode,'series(Di)')
634    %ind0_i=first_i:incr_i:last_i;
635    %nbcolumn=length(ind0_i);
636    %ind0_j=first_j:incr_j:last_j;
637    %nbline=length(ind0_j);
638    %dirpair=dir([filebasesub '_*-*_*.nc']);
639    for ifile=1:length(dirpair)
640        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
641        num_i1_r(ifile)=str2num(str_1);
642        num_i2_r(ifile)=str2num(str_2);
643        num_j(ifile)=str2num(str_a);
644    end
645    num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
646    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
647    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
648    ind_j=((num_j-first_j)/incr_j)+1;
649    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
650    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
651    ind_ij=ind_ij(select);%set of selected indices ind_ij
652    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
653    select=select(indsort);
654    num_i1_r=num_i1_r(select);
655    num_i2_r=num_i2_r(select);
656%     num_j=num_j(select);
657    dirpair=dirpair(select);
658    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
659    ind_ij(ind_remove)=[];
660    num_i1_r(ind_remove)=[];
661    num_i2_r(ind_remove)=[];
662    num_i1=zeros(1,nbline*nbcolumn);%default
663    num_i2=num_i1;
664    num_i1(ind_ij)=num_i1_r;
665    num_j2(ind_ij)=num_i2_r;
666    num_i1=reshape(num_i1,nbline,nbcolumn);
667    num_i2=reshape(num_i2,nbline,nbcolumn);
668    num_j1=meshgrid(ind0_i,ind0_j);
669    num_j2=num_j1;
670    nbmissing=nbline*nbcolumn-length(ind_ij);
671elseif isequal(mode,'series(Dj)')
672 %   ind0_i=first_i:incr_i:last_i;
673 %   nbcolumn=length(ind0_i);
674 %   ind0_j=first_j:incr_j:last_j;
675  %  nbline=length(ind0_j);
676  %  dirpair=dir([filebasesub '_*_*-*.nc']);
677    for ifile=1:length(dirpair)
678        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
679        num_i(ifile)=str2num(str_1);
680        num_a(ifile)=str2num(str_a);
681        num_b(ifile)=str2num(str_b);
682    end
683    num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
684    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
685    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
686    ind_j=((num_j-first_j)/incr_j)+1;
687    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
688    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
689    ind_ij=ind_ij(select);%set of selected indices ind_ij
690    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
691    select=select(indsort);
692    num_i=num_i(select);
693    num_a=num_a(select);
694    num_b=num_b(select);
695    dirpair=dirpair(select);
696    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
697    ind_ij(ind_remove)=[];
698    num_a(ind_remove)=[];
699    num_b(ind_remove)=[];
700    num_j1=zeros(1,nbline*nbcolumn);%default
701    num_j2=num_j1;
702    num_j1(ind_ij)=num_a;
703    num_j2(ind_ij)=num_b;
704    num_j1=reshape(num_j1,nbline,nbcolumn);
705    num_j2=reshape(num_j2,nbline,nbcolumn);
706    num_i1=meshgrid(ind0_i,ind0_j);
707    num_i2=num_i1;
708    nbmissing=nbline*nbcolumn-length(ind_ij);
709%     for i=1:length(indsel);%A SUPPRIMER ULTERIEUREMENT
710%         if indsel(i)==0
711%             filecell{i}='';
712%         else
713%             Name=dirpair(indsel(i)).name;
714%             filecell{i}=fullfile(Path,subdir,Name);
715%         end
716%     end
717%else
718%    errordlg('option *|* not yet implemented')
719%    return
720end
Note: See TracBrowser for help on using the repository browser.