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

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

-relabel_i_j: improve the question dlg box for image transform
-aver_stat,time_series,merge_proj: include modification of field transform and call of set_object.
-series: introduce a browser for set_object
-ima2vol: create volume images (png images of a slice concacened along y) for PIV 3D
-set_object: suppress TITLE, introduce Tooltip helps for parameters
-civ: fixed bug on BATCH sequences

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