Ignore:
Timestamp:
Jul 20, 2024, 9:33:32 AM (2 months ago)
Author:
sommeria
Message:

further cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/read_field.m

    r1137 r1162  
    11%'read_field': read the fields from files in different formats (netcdf files, images, video)
    22%--------------------------------------------------------------------------
    3 %  function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,num)
     3%  function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,frame_index)
    44%
    55% OUTPUT:
     
    2020%     .ColorVar: variable used for vector color
    2121%     .Npx, .Npy: nbre of pixels along x and y (used for .vol input files)
    22 %     .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num'
    23 % num: frame number for movies
     22%     .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'frame_index'
     23% frame_index: frame number for movies or multidimensional netcdf files with dim >2
    2424%
    2525% see also read_image.m,read_civxdata.m,read_civdata.m,
     
    4343%=======================================================================
    4444
    45 function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,num)
     45function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,frame_index)
    4646%% default output and check input
    4747Field=[];
    48 if ~exist('num','var')
    49     num=1;
    50 end
    51 if isempty(num)
    52     num=1;
     48if ~exist('frame_index','var')
     49    frame_index=1;
     50end
     51if isempty(frame_index)
     52    frame_index=1;
    5353end
    5454if ~exist('ParamIn','var')
     
    5757ParamOut=ParamIn;%default
    5858errormsg='';
    59 if isempty(regexp(FileName,'^http://'))&& ~exist(FileName,'file')
     59if isempty(regexp(FileName,'^http://', 'once'))&& ~exist(FileName,'file')
    6060    errormsg=['input file ' FileName ' does not exist'];
    6161    return
     
    8181%% distingush different input file types
    8282switch FileType
    83     case 'civdata'% new format for civ results
    84         [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType);
     83    case {'civdata','civdata_3D'}% new format for civ results
     84        [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType,frame_index);
    8585        if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];return,end
    8686        ParamOut.CivStage=Field.CivStage;
     
    102102        % scan the list InputField
    103103        Operator=cell(1,numel(InputField));
    104         InputVar=cell(1,numel(InputField));
     104        %InputVar=cell(1,numel(InputField));
    105105        for ilist=1:numel(InputField)
    106106            % look for input variables to read
     
    145145        NbCoord=~isempty(ParamIn.Coord_x)+~isempty(ParamIn.Coord_y)+~isempty(ParamIn.Coord_z);
    146146        if isfield(ParamIn,'TimeDimName')% case of reading of a single time index in a multidimensional array
    147             [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);
     147            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,frame_index,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);
    148148        elseif isfield(ParamIn,'TimeVarName')% case of reading of a single time  in a multidimensional array
    149             [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);
    150             if numel(num)~=1
     149            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,frame_index,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);
     150            if numel(frame_index)~=1
    151151                NbCoord=NbCoord+1;% adds time coordinate, except if a single time has been selected
    152152            end
     
    157157            return
    158158        end
    159         CheckStructured=1;
     159       % CheckStructured=1;
    160160        %scan all the variables
    161161        NbCoord=0;
    162162        if ~isempty(ParamIn.Coord_x)
    163             index_Coord_x=find(strcmp(ParamIn.Coord_x,Field.ListVarName));
     163            index_Coord_x=strcmp(ParamIn.Coord_x,Field.ListVarName);
    164164            Field.VarAttribute{index_Coord_x}.Role='coord_x';%
    165165            NbCoord=NbCoord+1;
     
    167167        if ~isempty(ParamIn.Coord_y)
    168168            if ischar(ParamIn.Coord_y)
    169                 index_Coord_y=find(strcmp(ParamIn.Coord_y,Field.ListVarName));
     169                index_Coord_y=strcmp(ParamIn.Coord_y,Field.ListVarName);
    170170                Field.VarAttribute{index_Coord_y}.Role='coord_y';%
    171171                NbCoord=NbCoord+1;
    172172            else
    173173                for icoord_y=1:numel(ParamIn.Coord_y)
    174                     index_Coord_y=find(strcmp(ParamIn.Coord_y{icoord_y},Field.ListVarName));
     174                    index_Coord_y=strcmp(ParamIn.Coord_y{icoord_y},Field.ListVarName);
    175175                    Field.VarAttribute{index_Coord_y}.Role='coord_y';%
    176176                    NbCoord=NbCoord+1;
     
    180180        NbDim=1;
    181181        if ~isempty(ParamIn.Coord_z)
    182             index_Coord_z=find(strcmp(ParamIn.Coord_z,Field.ListVarName));
     182            index_Coord_z=strcmp(ParamIn.Coord_z,Field.ListVarName);
    183183            Field.VarAttribute{index_Coord_z}.Role='coord_z';%
    184184            NbCoord=NbCoord+1;
     
    187187            NbDim=2;
    188188        end
    189         NormName='';
    190         UName='';
    191         VName='';
    192189        if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (exclude 1 D plots)
    193190            VarAttribute=cell(1,numel(ListVarName));
     
    236233        end 
    237234    case 'video'
    238         if strcmp(class(ParamIn),'VideoReader')
    239             A=read(ParamIn,num);
     235        if isa(ParamIn,'VideoReader')
     236            A=read(ParamIn,frame_index);
    240237        else
    241238            ParamOut=VideoReader(FileName);
    242             A=read(ParamOut,num);
     239            A=read(ParamOut,frame_index);
    243240        end
    244241    case 'mmreader'
    245         if strcmp(class(ParamIn),'mmreader')
    246             A=read(ParamIn,num);
     242        if isa(ParamIn,'mmreader')
     243            A=read(ParamIn,frame_index);
    247244        else
    248245            ParamOut=mmreader(FileName);
    249             A=read(ParamOut,num);
     246            A=read(ParamOut,frame_index);
    250247        end
    251248    case 'vol'
     
    255252        A=permute(A,[3 2 1]);
    256253    case 'multimage'
    257         %  warning 'off'
    258         A=imread(FileName,num);
     254        A=imread(FileName,frame_index);
    259255    case 'image'
    260256        A=imread(FileName);
    261257    case 'rdvision'
    262         [A,FileInfo,timestamps,errormsg]=read_rdvision(FileName,num);
     258        [A,FileInfo,timestamps,errormsg]=read_rdvision(FileName,frame_index);
    263259    case 'image_DaVis'
    264260        Input=readimx(FileName);
    265261        if numel(Input.Frames)==1
    266             num=1;
    267         end
    268         A=Input.Frames{num}.Components{1}.Planes{1}';
     262            frame_index=1;
     263        end
     264        A=Input.Frames{frame_index}.Components{1}.Planes{1}';
    269265        for ilist=1:numel(Input.Frames{1}.Attributes)
    270266            if strcmp(Input.Frames{1}.Attributes{ilist}.Name,'AcqTimeSeries')
     
    274270        end
    275271    case 'cine_phantom'
    276         [A,FileInfo] = read_cine_phantom(FileName,num );
     272        [A,FileInfo] = read_cine_phantom(FileName,frame_index );
    277273    otherwise
    278274        errormsg=[ FileType ': invalid input file type for uvmat'];
     
    299295    Field.VarAttribute{3}.Role='scalar';
    300296    if ndims(A)==3
    301         if Npz==1;%color
     297        if Npz==1%color
    302298            Field.VarDimName={'Coord_y','Coord_x',{'Coord_y','Coord_x','rgb'}}; %
    303299            Field.Coord_y=[npxy(1)-0.5 0.5];
Note: See TracChangeset for help on using the changeset viewer.