Changeset 527 for trunk/src


Ignore:
Timestamp:
Aug 20, 2012, 11:12:46 PM (12 years ago)
Author:
sommeria
Message:

various bugs corrected

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_field_cells.m

    r525 r527  
    225225        % look for coordinates variables
    226226        coord=zeros(1,numel(DimCell));%default
    227         %     if NbDim(icell)==0 && ~isempty(VarDimName)% no unstructured coordinate found
    228227        if  ~test_coord && ~isempty(VarDimName)
    229228            for idim=1:numel(DimCell)   %loop on the dimensions of the variables in cell #icell
  • trunk/src/nc2struct.m

    r517 r527  
    9696   
    9797    %%  -------- read all global attributes (constants)-----------
    98     att_key={};%default
    99 %     iatt_g=0;
    10098    Data.ListGlobalAttribute={};%default
     99    att_key=cell(1,ngatts);%default
    101100    for iatt=1:ngatts
    102101        keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1);
     
    117116        catch ME
    118117            att_key{iatt}=['attr_' num2str(iatt)];
    119             eval(['Data.' att_key{iatt} '=[];'])
     118            Data.(att_key{iatt})=[];
    120119        end
    121120    end
     
    123122
    124123    %%  -------- read dimension names-----------
    125     ListDimNameNetcdf={};
    126     dim_value=[];
     124    ListDimNameNetcdf=cell(1,ndims);
     125    dim_value=zeros(1,ndims);
    127126    for idim=1:ndims %loop on the dimensions of the netcdf file
    128127        [ListDimNameNetcdf{idim},dim_value(idim)] = netcdf.inqDim(nc,idim-1);%get name and value of each dimension
     
    133132 
    134133    %%  -------- read names of variables -----------
    135     ListVarNameNetcdf={}; %default
    136     dimids={};
    137     nbatt=[];
     134    ListVarNameNetcdf=cell(1,nvars); %default
     135    dimids=cell(1,nvars);
     136    nbatt=zeros(1,nvars);
    138137    for ncvar=1:nvars %loop on the variables of the netcdf file
    139138        %get name, type, dimensions and attribute numbers of each variable
     
    146145    else   %select input variables, if requested by the input ListVarName
    147146        ind_remove=[];
    148         for ivar=1:numel(ListVarName) % check redondancy
    149             if ~isempty(find(strcmp(ListVarName{ivar},ListVarName(1:ivar-1))))
    150                 ind_remove=[ind_remove ivar];
    151             end
    152         end
    153         if ~isempty(ind_remove)
    154             ListVarName(ind_remove)=[];
    155         end           
     147        check_keep=ones(1,size(ListVarName,2));
     148        for ivar=1:size(ListVarName,2) % check redondancy of variable names
     149            if ~isempty(find(strcmp(ListVarName{1,ivar},ListVarName(1:ivar-1)), 1))
     150                check_keep(ivar)=0;% the variable #ivar is already in the list
     151            end
     152        end
     153        ListVarName=ListVarName(:,logical(check_keep));         
    156154        sizvar=size(ListVarName);
    157155        testmulti=(sizvar(1)>1);%test for multiple choice of variable ranked by order of priority
  • trunk/src/read_civxdata.m

    r498 r527  
    5353DataTest=nc2struct(filename,'ListGlobalAttribute','Conventions','CivStage');
    5454if isfield(DataTest,'Txt')
    55     errormsg=['nc2struct:' DataTest.Txt];
     55    errormsg=['nc2struct / ' DataTest.Txt];
    5656    return
    5757elseif isequal(DataTest.Conventions,'uvmat/civdata')%test for new civ format
    5858     [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType,DataTest.CivStage);
    59       if ~isempty(errormsg),errormsg=['read_civdata:' errormsg];end
     59      if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];end
    6060     return
    6161end
     
    7777[Field,vardetect,ichoice]=nc2struct(filename,var);%read the variables in the netcdf file
    7878if isfield(Field,'Txt')
    79     errormsg=['nc2struct:' Field.Txt];
     79    errormsg=['nc2struct / ' Field.Txt];
    8080    return
    8181end
     
    9797if isfield(Field,'DjUi')
    9898    Field.ListVarName{end-3}='DjUi';
    99     Field.VarDimName{end-3}=[Field.VarDimName{end-3} {'nb_coord'} {'nb-coord'}];
     99    Field.VarDimName{end-3}=[Field.VarDimName{end-3} {'nb_coord'} {'nb_coord'}];
    100100    Field.ListVarName(end-2:end)=[];
    101101    Field.VarDimName(end-2:end)=[];
     
    186186%INPUT:
    187187% FieldNames =cell of field names to get, which can contain the strings:
    188 %             'ima_cor': image correlation, vec_c or vec2_C
    189 %             'vort','div','strain': requires velocity derivatives DUDX...
     188%             'C': image correlation, vec_c or vec2_C
     189%             'curl','div','strain': requires velocity derivatives DUDX...
    190190%             'error': error estimate (vec_E or vec2_E)
    191191%             
     
    199199if ~exist('vel_type','var'),vel_type=[];end;
    200200if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
    201 if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
     201if ~exist('FieldNames','var'),FieldNames={'C'};end;%default scalar
    202202if ischar(FieldNames), FieldNames={FieldNames}; end;
    203203
     
    205205testder=0;
    206206for ilist=1:length(FieldNames)
    207     if ~isempty(FieldNames{ilist})
    208     switch FieldNames{ilist}
    209         case {'vort','div','strain'}
    210             testder=1;
    211     end
    212     end
     207        testder=~isempty(regexp(FieldNames{ilist},'(^curl|^div|strain)', 'once'));%test need for derivatives
     208        if testder, break;end
    213209end     
    214210if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
     
    261257    if ~isempty(FieldNames{ilist})
    262258    switch FieldNames{ilist}
    263         case 'ima_cor' %image correlation corresponding to a vel vector
     259        case 'C' %image correlation corresponding to a vel vector
    264260            C1='vec_C';
    265261            C2='vec2_C';
     
    267263            C1='vec_E';
    268264            C2='vec2_E';
    269         case {'vort','div','strain'}
    270             testder=1;
     265        otherwise
     266          testder=~isempty(regexp(FieldNames{ilist},'(^curl|^div|strain)', 'once'));%test need for derivatives
    271267    end
    272268    end
  • trunk/src/read_field.m

    r526 r527  
    3535ParamOut=ParamIn;%default
    3636errormsg='';
    37 % if isfield(ParamIn,'VelType')
    38 % VelType=ParamIn.VelType;
    39 % end
    4037A=[];
    4138if isstruct(ParamIn)
     
    5249end
    5350%% distingush different input file types
    54 try
    55     switch FileType
    56         case 'civdata'
    57             [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType);
    58             if ~isempty(errormsg),errormsg=['read_civdata:' errormsg];return,end
    59             ParamOut.CivStage=Field.CivStage;
    60         case 'civx'
    61             ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
    62             [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType);
    63             if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end
    64             ParamOut.CivStage=Field.CivStage;
    65         case 'netcdf'
    66             ListVar={};
    67             for ilist=1:numel(InputField)
    68                 r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
    69                 if isempty(r)
    70                     ListVar=[ListVar InputField(ilist)];
    71                     Role{numel(ListVar)}='scalar';
    72 %                     FieldRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot)
    73                 else
    74                     ListVar=[ListVar {r.UName,r.VName}];
    75                     Role{numel(ListVar)}='vector_y';
    76                     Role{numel(ListVar)-1}='vector_x';
    77 %                    TODO; introduce that for unstructured coordinates
    78 %                     switch r.Operator TODO; introduce that for unstructured coordinates
    79 %                         case 'norm'
    80 %                             FieldRequest{numel(ListVar)-1}='interp_lin';%scalar field (requires interpolation for plot)
    81 %                             FieldRequest{numel(ListVar)}='interp_lin';
    82 %                         otherwise
    83 %                            FieldRequest{numel(ListVar)-1}='';
    84 %                     end
    85                 end
     51switch FileType
     52    case 'civdata'
     53        [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType);
     54        if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];return,end
     55        ParamOut.CivStage=Field.CivStage;
     56    case 'civx'
     57        ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
     58        [Field,ParamOut.VelType,errormsg]=read_civxdata(FileName,InputField,ParamIn.VelType);
     59        if ~isempty(errormsg),errormsg=['read_civxdata / ' errormsg];return,end
     60        ParamOut.CivStage=Field.CivStage;
     61    case 'netcdf'
     62        ListVar={};
     63        for ilist=1:numel(InputField)
     64            r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
     65            if isempty(r)
     66                ListVar=[ListVar InputField(ilist)];
     67                Role{numel(ListVar)}='scalar';
     68                %                     FieldRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot)
     69            else
     70                ListVar=[ListVar {r.UName,r.VName}];
     71                Role{numel(ListVar)}='vector_y';
     72                Role{numel(ListVar)-1}='vector_x';
     73                %                    TODO; introduce that for unstructured coordinates
     74                %                     switch r.Operator TODO; introduce that for unstructured coordinates
     75                %                         case 'norm'
     76                %                             FieldRequest{numel(ListVar)-1}='interp_lin';%scalar field (requires interpolation for plot)
     77                %                             FieldRequest{numel(ListVar)}='interp_lin';
     78                %                         otherwise
     79                %                            FieldRequest{numel(ListVar)-1}='';
     80                %                     end
    8681            end
    87             if check_colorvar
    88                 Role{numel(ListVar)}='ancillary';% scalar used for color vector (not projected)
    89             end
    90             [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ListVar]);
    91             for ivar=1:numel(ListVar)
    92                 Field.VarAttribute{ivar+2}.Role=Role{ivar};
    93 %                 Field.VarAttribute{ivar+2}.FieldRequest=FieldRequest{ivar};
    94             end
    95            
    96         case 'video'
    97             if strcmp(class(ParamIn),'VideoReader')
    98                 A=read(ParamIn,num);
    99             else
    100                 ParamOut=VideoReader(FileName);
    101                 A=read(ParamOut,num);
    102             end
    103         case 'mmreader'
    104             if strcmp(class(ParamIn),'mmreader')
    105                 A=read(ParamIn,num);
    106             else
    107                 ParamOut=mmreader(FileName);
    108                 A=read(ParamOut,num);
    109             end
    110         case 'vol'
    111             A=imread(FileName);
    112             Npz=size(A,1)/ParamIn.Npy;
    113             A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz);
    114             A=permute(A,[3 2 1]);
    115         case 'multimage'
    116             warning 'off'
    117             A=imread(FileName,num);
    118         case 'image'
    119             A=imread(FileName);
    120     end
    121 catch ME
    122     errormsg=[FileType ' input: ' ME.message];
     82        end
     83        if check_colorvar
     84            Role{numel(ListVar)}='ancillary';% scalar used for color vector (not projected)
     85        end
     86        [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ListVar]);
     87        for ivar=1:numel(ListVar)
     88            Field.VarAttribute{ivar+2}.Role=Role{ivar};
     89            %                 Field.VarAttribute{ivar+2}.FieldRequest=FieldRequest{ivar};
     90        end
     91       
     92    case 'video'
     93        if strcmp(class(ParamIn),'VideoReader')
     94            A=read(ParamIn,num);
     95        else
     96            ParamOut=VideoReader(FileName);
     97            A=read(ParamOut,num);
     98        end
     99    case 'mmreader'
     100        if strcmp(class(ParamIn),'mmreader')
     101            A=read(ParamIn,num);
     102        else
     103            ParamOut=mmreader(FileName);
     104            A=read(ParamOut,num);
     105        end
     106    case 'vol'
     107        A=imread(FileName);
     108        Npz=size(A,1)/ParamIn.Npy;
     109        A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz);
     110        A=permute(A,[3 2 1]);
     111    case 'multimage'
     112        warning 'off'
     113        A=imread(FileName,num);
     114    case 'image'
     115        A=imread(FileName);
     116end
     117if ~isempty(errormsg)
     118    errormsg=[FileType ' input: ' errormsg];
    123119    return
    124120end
  • trunk/src/uvmat.m

    r526 r527  
    20632063[Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
    20642064if ~isempty(errormsg)
    2065     errormsg=['uvmat/refresh_field/read_field: ' FileName ': ' errormsg];
     2065    errormsg=['uvmat / refresh_field / read_field( ' FileName ') / ' errormsg];
    20662066    return
    20672067end 
     
    23962396[CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(UvData.Field);% analyse  the input field structure
    23972397if ~isempty(errormsg)
    2398     errormsg=['error in uvmat/refresh_field/find_field_cells: ' errormsg];% display error
     2398    errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error
    23992399    return
    24002400end
     
    24042404end
    24052405
    2406 %% get bounds and mesh (needed for mouse action and to open set_object)
     2406%% get bounds and mesh (needed  to propose default options for projection objects)
    24072407if NbDim>1
    24082408    XName=''; %default
     
    24122412        XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
    24132413        YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
    2414         %nbvec=length(UvData.Field.(XName));%nbre of measurement points (e.g. vectors)
    24152414        test_x=1;%test for unstructured coordinates
    24162415        if ~isempty(VarType{imax}.coord_z)
     
    24252424            YName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim-1)}; %structured coordinates
    24262425        end
    2427         % VarIndex=CellVarIndex{imax}; % list of variable indices
    24282426        DimIndex=VarDimIndex{CellVarIndex{imax}(1)}; %list of dim indices for the variable
    24292427        nbpoints_x=DimValue(DimIndex(NbDim));
Note: See TracChangeset for help on using the changeset viewer.