Ignore:
Timestamp:
Jan 17, 2012, 12:11:00 AM (12 years ago)
Author:
sommeria
Message:

introduce get_file_type to get easily the type of file (image, multimage, civdata...)
a few bugs corrected in series

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_file_series.m

    r372 r376  
    3737%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    3838
    39 function [RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object]=find_file_series(RootPath,fileinput,option)
     39function [RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object]=find_file_series(RootPath,fileinput)
    4040%------------------------------------------------------------------------
    4141if ~exist('option','var')
     
    4747
    4848%% check for particular file types: images, movies, civ data
    49 FileType='';
    50 Object=[];
    5149i1_series=zeros(1,1,1);
    5250i2_series=zeros(1,1,1);
    5351j1_series=zeros(1,1,1);
    5452j2_series=zeros(1,1,1);
    55 
    56 switch FileExt
    57     % ancillary files, no field indexing
    58     case {'.civ','.log','.cmx','.cmx2','.txt','.bat'}
    59         FileType='txt';
    60         NomType='';
    61     case '.fig'
    62         FileType='figure';
    63         NomType='';
    64     case '.xml'
    65         FileType='xml';
    66         NomType='';
    67     case '.xls'
    68         FileType='xls';
    69         NomType='';
    70     otherwise
    71      
    72         if ~isempty(FileExt)&& ~isempty(imformats(FileExt(2:end)))
    73             try
    74                 imainfo=imfinfo(fullfileinput);
    75                 FileType='image';
    76                 if length(imainfo) >1 %case of image with multiple frames
    77                     NomType='*';
    78                     FileType='multimage';
    79                     i1_series=(1:length(imainfo))';
    80                     [RootPath,RootFile]=fileparts(fullfileinput);
    81                 end
    82             end
    83         else
    84             try
    85                 Data=nc2struct(fullfileinput,'ListGlobalAttribute','absolut_time_T0','Conventions');
    86                 if ~isempty(Data.absolut_time_T0')
    87                     FileType='civx'; % test for civx velocity fields
    88                 elseif strcmp(Data.Conventions,'uvmat/civdata')
    89                     FileType='civdata'; % test for civx velocity fields
    90                 else
    91                     FileType='netcdf';
    92                 end
    93             end
    94             try
    95                 if exist('VideoReader','file')%recent version of Matlab
    96                     Object=VideoReader(fullfileinput);
    97                 else
    98                     Object=mmreader(fullfileinput);%older Matlab function for movies
    99                 end
    100                 NomType='*';
    101                 FileType='video';
    102                 i1_series=(1:get(Object,'NumberOfFrames'))';
    103             end
    104         end
     53[FileType,FileInfo,Object]=get_file_type(fullfileinput);
     54if strcmp( FileType,'multimage')||strcmp( FileType,'video')
     55        NomType='*';
     56        i1_series=(1:FileInfo.NbFrame)'
    10557end
    10658
     
    172124    star_string=[RootFile sep1 i1_star sep2 i2_star sep3 j1_star sep4 j2_star '*'];
    173125    wd=pwd;%current working directory
    174     %RR=fullfile(RootPath,SubDir);
    175126    cd (RootPath)% move to the local dir to save time in the operation dir.
    176127    dirpair=dir([star_string FileExt]);% look for relevant files in the file directory
     
    258209
    259210%% update the file type if the input file does not exist (pb of 0001)
    260 if strcmp(option,'filetype')
    261     return
    262 elseif isempty(FileType)
    263     [tild,tild, tild,tild,tild,tild,FileType,Object]=find_file_series(RootPath,dirpair(ifile_min).name,'filetype');
     211if isempty(FileType)
     212    [FileType,tild,Object]=get_file_type(dirpair(ifile_min).name);
    264213end
    265214
Note: See TracChangeset for help on using the changeset viewer.