Ignore:
Timestamp:
Dec 14, 2011, 1:33:18 PM (13 years ago)
Author:
sommeria
Message:

bugs corrected in fileparts_uvmat and find_file_series
name2dispaly replaced by fileparts_uvmat in uvmat, but not in other functions
bug corrected in plot_field, introduction of FileType? in read_field

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_file_series.m

    r332 r334  
    1 %'find_file_series': check the content onf an input fiel and find the corresponding file series
     1%'find_file_series': check the content onf an input field and find the corresponding file series
    22%--------------------------------------------------------------------------
    33% function [i1,i2,j1,j2,NomType,FileType,Object]=find_file_series(fileinput)
     
    3636function [i1,i2,j1,j2,NomType,FileType,Object]=find_file_series(fileinput)
    3737%------------------------------------------------------------------------
    38 i1=NaN;%default
    39 i2=NaN;%default
    40 j1=NaN;%default
    41 j2=NaN;%default
     38i1=[];%default
     39i2=[];%default
     40j1=[];%default
     41j2=[];%default
    4242
    4343%% get input root name and nomenclature type
    44 [RootPath,RootFile,~,~,~,~,FileExt,NomType,SubDir]=name2display(fileinput);
     44% [RootPath,RootFile,~,~,~,~,FileExt,NomType,SubDir]=name2display(fileinput);
     45[RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(fileinput);
    4546
    4647%% check for particular file types: images, movies, civ data
    4748FileType='';
    4849Object=[];
    49 if ~isempty(FileExt)&& ~isempty(imformats(FileExt(2:end)))
    50     imainfo=imfinfo(fileinput);
    51     FileType='image';
    52     if length(imainfo) >1 %case of image with multiple frames
    53         NomType='*';
    54         FileType='multimage';
    55         i1=1;
    56         i2=length(imainfo);
    57         [RootPath,RootFile]=fileparts(fileinput);
    58     end
     50switch FileExt
     51    % ancillary files, no field indexing
     52    case {'.civ','.log','.cmx','.cmx2','.txt','.bat'}
     53        FileType='txt';
     54        NomType='';
     55    case '.fig'
     56        FileType='figure';
     57        NomType='';
     58    case '.xml'
     59        FileType='xml';
     60        NomType='';
     61    case '.xls'
     62        FileType='xls';
     63        NomType='';
     64    otherwise
     65        if ~isempty(FileExt)&& ~isempty(imformats(FileExt(2:end)))
     66            imainfo=imfinfo(fileinput);
     67            FileType='image';
     68            if length(imainfo) >1 %case of image with multiple frames
     69                NomType='*';
     70                FileType='multimage';
     71                i1=1;
     72                i2=length(imainfo);
     73                [RootPath,RootFile]=fileparts(fileinput);
     74            end
     75        else
     76            try
     77                Data=nc2struct(fileinput,'ListGlobalAttribute','absolut_time_T0','Conventions');
     78                if ~isempty(Data.absolut_time_T0')
     79                    FileType='civx'; % test for civx velocity fields
     80                elseif strcmp(Data.Conventions','uvmat/civdata')
     81                    FileType='civdata'; % test for civx velocity fields
     82                else
     83                    FileType='netcdf';
     84                end
     85            end
     86            try
     87                Object=VideoReader(fileinput);
     88                NomType='*';
     89                FileType='video';
     90                i1=1;
     91                i2=get(Object,'NumberOfFrames');
     92                [RootPath,RootFile]=fileparts(fileinput);
     93            end
     94        end
     95end
     96if strcmp(NomType,'')||strcmp(NomType,'*')
     97    [RootPath,RootFile]=fileparts(fileinput);% case of constant name (no indexing)
     98%% get the list of existing files
    5999else
    60     try
    61         Data=nc2struct(fileinput,'ListGlobalAttribute',{'absolut_time_T0','Conventions'});
    62         if ~isempty(Data,'absolut_time_T0')
    63             FileType='civx'; % test for civx velocity fields
    64         elseif strcmp(Data.Conventions','uvmat/civdata')
    65             FileType='civdata'; % test for civx velocity fields
    66         else
    67             FileType='netcdf';
    68         end     
    69     end
    70     try
    71         Object=VideoReader(fileinput);
    72         NomType='*';
    73         FileType='video';
    74         i1=1;
    75         i2=get(Object,'NumberOfFrames');
    76         [RootPath,RootFile]=fileparts(fileinput);
    77     end
    78 end
    79 
    80 %% get the list of existing files
    81 if ~strcmp(NomType,'*')
    82100    if strcmp(SubDir,'')
    83101        filebasesub=fullfile(RootPath,RootFile);
     
    95113    end
    96114    dirpair=dir([filebasesub detect_string FileExt]);
    97     % switch NomType %TODO: complement for other cases
    98     %     case '_0001'
    99     %         dirpair=dir([filebasesub '_*' FileExt]);
    100     %     case '_1'
    101     %         dirpair=dir([filebasesub '_*' FileExt]);
    102     %     case '_1_1'
    103     %         dirpair=dir([filebasesub '_*_*' FileExt]);
    104     %     case '_i1-i2'
    105     %         dirpair=dir([filebasesub '_*-*' FileExt]);
    106     %     case '1_ab'
    107     %         dirpair=dir([filebasesub '*_*' FileExt]);
    108     %     case '_i_j1-j2'
    109     %         dirpair=dir([filebasesub '*_*-*' FileExt]);
    110     %     case '_i1-i2_j'
    111     %         dirpair=dir([filebasesub '*-*_*' FileExt]);
    112     % end
    113115    for ifile=1:length(dirpair)
    114         [~,~,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name);
    115         i1(ifile)=str2double(str_1);
    116         i2(ifile)=str2double(str_2);
    117         if isnan(i2(ifile))
     116       % [~,~,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name);
     117       dirpair(ifile).name
     118        [~,~,~,i1_ifile,i2_ifile,j1_ifile,j2_ifile]=fileparts_uvmat(dirpair(ifile).name); 
     119        if isempty(i1_ifile)
     120            i1(ifile)=1;
     121        else
     122            i1(ifile)=i1_ifile;
     123        end
     124        if isempty(i2_ifile)
    118125            i2(ifile)=i1(ifile);
     126        else
     127            i2(ifile)=i2_ifile;
    119128        end
    120         j1(ifile)=stra2num(str_a);
    121         if isnan(j1(ifile))
     129        end
     130        if isempty(j1_ifile)
    122131            j1(ifile)=1;
     132        else
     133            j1(ifile)=j1_ifile;
    123134        end
    124         j2(ifile)=stra2num(str_b);
    125         if isnan(j2(ifile))
     135        if isempty(j2_ifile)
    126136            j2(ifile)=j1(ifile);
     137        else
     138            j2(ifile)=j2_ifile;
    127139        end
    128     end
    129    
     140    end 
     141    % TODO : sort by reference index
    130142    % update the NomType from the minimal index detected (to deal with number strings beginning by 0)
    131143    [~,ifile]=min(i1);
    132     [~,~,~,~,~,~,~,NomType]=name2display(dirpair(ifile).name);
     144    %[~,~,~,~,~,~,~,NomType]=name2display(dirpair(ifile).name);
     145    if ~isempty(i1)
     146           [~,ifile]=min(i1);
     147    [~,~,~,~,~,~,~,~,NomType]=fileparts_uvmat(dirpair(ifile).name);
     148    end
    133149end
Note: See TracChangeset for help on using the changeset viewer.