Changeset 124


Ignore:
Timestamp:
Nov 18, 2010, 10:55:22 PM (10 years ago)
Author:
gostiaux
Message:

smart indent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/calc_field.m

    r123 r124  
    1 %'calc_field': defines fields (velocity, vort, div...) from civx data and calculate them 
     1%'calc_field': defines fields (velocity, vort, div...) from civx data and calculate them
    22%---------------------------------------------------------------------
    33% [DataOut,errormsg]=calc_field(FieldName,DataIn)
    44%
    5 % OUTPUT: 
    6 % Scal: matlab vector representing the scalar values (length nbvec defined by var_read) 
     5% OUTPUT:
     6% Scal: matlab vector representing the scalar values (length nbvec defined by var_read)
    77%      if no input, Scal=list of programmed scalar names (to put in menus)
    88%      if only the field name is put as input, vec_A=type of scalar, which can be:
    99%                   'discrete': related to the individual velocity vectors, not interpolated by patch
    1010%                   'vel': scalar calculated solely from velocity components
    11 %                   'der': needs spatial derivatives     
     11%                   'der': needs spatial derivatives
    1212%                   'var': the scalar name directly corresponds to a field name in the netcdf files
    1313% error: error flag
     
    2020%
    2121% FUNCTION related
    22 % varname_generator.m: determines the field names to read in the netcdf file, depending on the scalar
     22% varname_generator.m: determines the field names to read in the netcdf
     23% file, depending on the scalar
    2324
    2425function [DataOut,errormsg]=calc_field(FieldName,DataIn)
    2526
    2627%list of defined scalars to display in menus (in addition to 'ima_cor').
    27 % a type is associated to each scalar: 
     28% a type is associated to each scalar:
    2829%              'discrete': related to the individual velocity vectors, not interpolated by patch
    29 %              'vel': calculated from velocity components, continuous field (interpolated with velocity)             
    30 %              'der': needs spatial derivatives     
     30%              'vel': calculated from velocity components, continuous field (interpolated with velocity)
     31%              'der': needs spatial derivatives
    3132%              'var': the scalar name corresponds to a field name in the netcdf files
    3233% a specific variable name for civ1 and civ2 fields are also associated, if
     
    3536%list_scal={title, type, civ1 var name,civ2 var name}
    3637list_field={'velocity';...%image correlation corresponding to a vel vector
    37            'ima_cor';...%image correlation corresponding to a vel vector
    38            'norm_vel';...%norm of the velocity
    39            'vort';...%vorticity
    40            'div';...%divergence
    41            'strain';...%rate of strain
    42            'u';... %u velocity component
    43            'v';... %v velocity component
    44            'w';... %w velocity component
    45            'w_normal';... %w velocity component normal to the plane
    46           'error'}; %error associated to a vector (for stereo or patch)
     38    'ima_cor';...%image correlation corresponding to a vel vector
     39    'norm_vel';...%norm of the velocity
     40    'vort';...%vorticity
     41    'div';...%divergence
     42    'strain';...%rate of strain
     43    'u';... %u velocity component
     44    'v';... %v velocity component
     45    'w';... %w velocity component
     46    'w_normal';... %w velocity component normal to the plane
     47    'error'}; %error associated to a vector (for stereo or patch)
    4748errormsg=[]; %default error message
    48 if ~exist('FieldName','var') 
     49if ~exist('FieldName','var')
    4950    DataOut=list_field;% gives the list of possible fields in the absence of input
    5051else
     
    5960    else
    6061        nbcoord=2;
    61     end   
     62    end
    6263    DataOut=DataIn; %reproduce global attribute
    6364    ListVarName={};
     
    6566    RoleList={};
    6667    units_cell={};
    67     for ilist=1:length(FieldName) 
     68    for ilist=1:length(FieldName)
    6869        [VarName,Value,Role,units]=feval(FieldName{ilist},DataIn);%calculate field with appropriate function named FieldName{ilist}
    6970        ListVarName=[ListVarName VarName];
     
    7172        RoleList=[RoleList Role];
    7273        units_cell=[units_cell units];
    73    end   
    74        %erase previous data (except coordinates)
     74    end
     75    %erase previous data (except coordinates)
    7576    for ivar=nbcoord+1:length(DataOut.ListVarName)
    7677        VarName=DataOut.ListVarName{ivar};
    7778        DataOut=rmfield(DataOut,VarName);
    78     end 
     79    end
    7980    DataOut.ListVarName=DataOut.ListVarName(1:nbcoord);
    8081    if isfield(DataOut,'VarDimName')
     
    8889    DataOut.ListVarName=[DataOut.ListVarName ListVarName];
    8990    for ivar=1:length(ListVarName)
    90         DataOut.VarDimName{nbcoord+ivar}=DataOut.VarDimName{1};     
    91         DataOut.VarAttribute{nbcoord+ivar}.Role=RoleList{ivar}; 
     91        DataOut.VarDimName{nbcoord+ivar}=DataOut.VarDimName{1};
     92        DataOut.VarAttribute{nbcoord+ivar}.Role=RoleList{ivar};
    9293        DataOut.VarAttribute{nbcoord+ivar}.units=units_cell{ivar};
    9394        eval(['DataOut.' ListVarName{ivar} '=ValueList{ivar};'])
     
    115116    VarName=[VarName {'V'}];
    116117    ValCell=[ValCell {DataIn.V}];
    117     Role=[Role {'vector_y'}]; 
     118    Role=[Role {'vector_y'}];
    118119    units_cell=[units_cell {units}];
    119120end
     
    158159if isfield(DataIn,'U') && isfield(DataIn,'V')
    159160    VarName{1}='norm_vel';
    160      ValCell{1}=DataIn.U.*DataIn.U+ DataIn.V.*DataIn.V;
    161      if isfield(DataIn,'W') && isequal(size(DataIn.W),size(DataIn.U))
    162          ValCell{1}=ValCell{1}+DataIn.W.*DataIn.W;
    163      end
    164      ValCell{1}=sqrt(ValCell{1});
    165      Role{1}='scalar';
    166      if isfield(DataIn,'CoordUnit') && isfield(DataIn,'TimeUnit')
    167         units={[DataIn.CoordUnit '/' DataIn.TimeUnit]};
    168      else
    169         units={'pixel'};
    170      end
    171 end 
     161    ValCell{1}=DataIn.U.*DataIn.U+ DataIn.V.*DataIn.V;
     162    if isfield(DataIn,'W') && isequal(size(DataIn.W),size(DataIn.U))
     163        ValCell{1}=ValCell{1}+DataIn.W.*DataIn.W;
     164    end
     165    ValCell{1}=sqrt(ValCell{1});
     166    Role{1}='scalar';
     167    if isfield(DataIn,'CoordUnit') && isfield(DataIn,'TimeUnit')
     168        units={[DataIn.CoordUnit '/' DataIn.TimeUnit]};
     169    else
     170        units={'pixel'};
     171    end
     172end
    172173
    173174
     
    190191        units={[]};
    191192    end
    192 end 
     193end
    193194
    194195%%%%%%%%%%%%% divergence%%%%%%%%%%%%%%%%%%%%
     
    209210        units={[]};
    210211    end
    211 end 
     212end
    212213
    213214%%%%%%%%%%%%% strain %%%%%%%%%%%%%%%%%%%%
     
    218219units={};
    219220if isfield(DataIn,'DjUi')
    220    VarName{1}='strain';
    221    ValCell{1}=DataIn.DjUi(:,1,2)+DataIn.DjUi(:,2,1);%DVDX+DUDY
    222    siz=size(ValCell{1});   
    223    ValCell{1}=reshape(ValCell{1},siz(1),1);
    224    if isfield(DataIn,'TimeUnit')
     221    VarName{1}='strain';
     222    ValCell{1}=DataIn.DjUi(:,1,2)+DataIn.DjUi(:,2,1);%DVDX+DUDY
     223    siz=size(ValCell{1});
     224    ValCell{1}=reshape(ValCell{1},siz(1),1);
     225    if isfield(DataIn,'TimeUnit')
    225226        units={[DataIn.TimeUnit '-1']};
    226    else
     227    else
    227228        units={[]};
    228    end
    229 end 
     229    end
     230end
    230231
    231232%%%%%%%%%%%%% u %%%%%%%%%%%%%%%%%%%%
     
    289290    VarName{1}='W';
    290291    ValCell{1}=DataIn.W;
    291     Role{1}='vector_z';%will behave like a vector component  by projection 
     292    Role{1}='vector_z';%will behave like a vector component  by projection
    292293    if isfield(DataIn,'CoordUnit') && isfield(DataIn,'TimeUnit')
    293294        units={[DataIn.CoordUnit '/' DataIn.TimeUnit]};
Note: See TracChangeset for help on using the changeset viewer.