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

improvement of calc-field and combination of two fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/read_civdata.m

    r497 r515  
    1010%                    .NbCoord: number of vector components
    1111%                    .NbDim: number of dimensions (=2 or 3)
    12 %                    .dt: time interval for the corresponding image pair
     12%                    .Dt: time interval for the corresponding image pair
    1313%                    .Time: absolute time (average of the initial image pair)
    1414%                    .CivStage: =0,
     
    6363end
    6464errormsg='';
     65if ischar(FieldNames), FieldNames={FieldNames}; end;
     66FieldRequest='vec';
     67for ilist=1:length(FieldNames)
     68    if ~isempty(FieldNames{ilist})
     69        switch FieldNames{ilist}
     70            case{'U','V','norm(U,V)'}
     71                FieldRequest='interp';
     72            case {'curl(U,V)','div(U,V)','strain(U,V)'}
     73                FieldRequest='derivatives';
     74        end
     75    end
     76end
    6577
    6678%% reading data
    67 [varlist,role,units,VelTypeOut]=varcivx_generator(FieldNames,VelType,CivStage);
     79[varlist,role,VelTypeOut]=varcivx_generator(FieldRequest,VelType,CivStage);
    6880if isempty(varlist)
    6981    erromsg=['error in read_civdata: unknow velocity type ' VelType];
     
    97109end
    98110Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
     111ivar_U_tps=[];
    99112var_ind=find(vardetect);
    100113for ivar=1:numel(var_ind)
    101114    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
    102     Field.VarAttribute{ivar}.Unit=units{var_ind(ivar)};
     115    Field.VarAttribute{ivar}.FieldRequest=FieldRequest;
     116    if strcmp(role{var_ind(ivar)},'vector_x')
     117        Field.VarAttribute{ivar}.Operation=FieldNames;
     118        ivar_U=ivar;
     119    end
     120    if strcmp(role{var_ind(ivar)},'vector_x_tps')
     121        Field.VarAttribute{ivar}.Operation=FieldNames;
     122        ivar_U_tps=ivar;
     123    end
     124%     Field.VarAttribute{ivar}.Unit=units{var_ind(ivar)};
    103125    Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel
    104126end
     127if ~isempty(ivar_U_tps)
     128    Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
     129end
     130% if strcmp(FieldRequest,'derivatives')% fields will be calculated from the tps
     131%     Field.VarAttribute{ivar_U_tps}.FieldRequest=FieldRequest;
     132%     Field.VarAttribute{ivar_U_tps}.Operation=FieldNames;
     133% else% fields will be calculated from the initial fields
     134%     Field.VarAttribute{ivar_U}.FieldRequest=FieldRequest;%
     135%     Field.VarAttribute{ivar_U}.Operation=FieldNames;
     136% end
     137
    105138Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
    106139% %% update list of global attributes
     
    121154%            if vel_type=[] or'*', a  priority choice is done, civ2 considered better than civ1 )
    122155
    123 function [var,role,units,vel_type_out,errormsg]=varcivx_generator(FieldNames,vel_type,CivStage)
     156function [var,role,vel_type_out,errormsg]=varcivx_generator(FieldRequest,vel_type,CivStage)
    124157
    125158%% default input values
    126159if ~exist('vel_type','var'),vel_type='';end;
    127160if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
    128 if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
    129 if ischar(FieldNames), FieldNames={FieldNames}; end;
    130161errormsg='';
    131162
    132163%% select the priority order for automatic vel_type selection
    133 testder=0;
    134 testpatch=0;
    135 for ilist=1:length(FieldNames)
    136     if ~isempty(FieldNames{ilist})
    137         switch FieldNames{ilist}
    138             case{'u','v'}
    139                 testpatch=1;
    140             case {'vort','div','strain'}
    141                 testder=1;
    142         end
    143     end
    144 end
    145 if strcmp(vel_type,'civ2') && testder
     164if strcmp(vel_type,'civ2') && strcmp(FieldRequest,'derivatives')
    146165    vel_type='filter2';
    147 elseif strcmp(vel_type,'civ1') && testder
     166elseif strcmp(vel_type,'civ1') && strcmp(FieldRequest,'derivatives')
    148167    vel_type='filter1';
    149168end
     
    153172            vel_type='filter2';
    154173        case {4,5}% civ2 available but not filter2
    155             if testder% derivatives needed
     174            if strcmp(FieldRequest,'derivatives')% derivatives needed
    156175                vel_type='filter1';
    157176            else
     
    171190            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
    172191        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
    173         units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
     192    %    units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
    174193    case 'filter1'
    175194        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
     
    178197        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
    179198            'vector_y_tps','vector_z_tps','ancillary','ancillary'};
    180         units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
     199     %   units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
    181200    case 'civ2'
    182201        var={'X','Y','Z','U','V','W','C','F','FF';...
    183202            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
    184203        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
    185         units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
     204      %  units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
    186205    case 'filter2'
    187206        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
     
    190209        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
    191210            'vector_y_tps','vector_z_tps','ancillary','ancillary'};
    192         units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
     211       % units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
     212end
     213if ~strcmp(FieldRequest,'derivatives')
     214    var=var(:,1:9);%suppress tps if not needed
    193215end
    194216vel_type_out=vel_type;
Note: See TracChangeset for help on using the changeset viewer.