Changeset 492 for trunk/src/proj_field.m


Ignore:
Timestamp:
Jul 15, 2012, 10:30:28 AM (12 years ago)
Author:
sommeria
Message:

civ corrected to deal with windows system
proj_field improved to provject tps fields on lines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/proj_field.m

    r491 r492  
    536536%project on a line
    537537% AJOUTER flux,circul,error
     538% OUTPUT:
     539% ProjData: projected field
     540%
    538541function  [ProjData,errormsg] = proj_line(FieldData, ObjectData)
    539542%-----------------------------------------------------------------
     
    547550if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
    548551% ProjAngle=90; %90 degrees projection by default
    549 % if isfield(FieldData,'ProjAngle'),ProjAngle=ObjectData.ProjAngle; end;
     552
    550553width=0;%default width of the projection band
    551554if isfield(ObjectData,'Range')&&size(ObjectData.Range,2)>=2
     
    569572ListIndex={};
    570573
    571 %angles of the polyline and boundaries of action
     574%% angles of the polyline and boundaries of action
    572575dlinx=diff(ObjectData.Coord(:,1));
    573576dliny=diff(ObjectData.Coord(:,2));
    574 theta=angle(dlinx+i*dliny);%angle of each segment
     577theta=angle(dlinx+1i*dliny);%angle of each segment
    575578theta(siz_line(1))=theta(siz_line(1)-1);
    576579% determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
     580xsup=zeros(1,siz_line(1)); xinf=zeros(1,siz_line(1)); ysup=zeros(1,siz_line(1)); yinf=zeros(1,siz_line(1));
    577581if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
    578582    xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
     
    588592end
    589593
    590 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
     594%% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
    591595[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
    592596if ~isempty(errormsg)
     
    595599end
    596600
    597 % loop on variable cells with the same space dimension
     601%% loop on variable cells with the same space dimension
    598602ProjData.ListVarName={};
    599603ProjData.VarDimName={};
     604testproj=zeros(size(FieldData.ListVarName));
    600605for icell=1:length(CellVarIndex)
    601606    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
     
    605610    end
    606611    testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates
     612    test_tps=~isempty(VarType.coord_tps);
    607613    testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors
    608614    testfalse=~isempty(VarType.errorflag);% test for error flag
    609615    testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0
    610616                                             %=0 for vector components, treated separately
    611     testproj(VarType.scalar)=1;
    612     testproj(VarType.image)=1;
    613     testproj(VarType.color)=1;
     617    testproj([VarType.scalar VarType.image VarType.color VarType.vector_x VarType.vector_y])=1;
    614618    VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
    615     if testU
    616          VarIndex=[VarIndex VarType.vector_x VarType.vector_y];%append u and v at the end of the list of variables
    617     end
     619
    618620    %identify vector components   
    619621    if testU
    620622        UName=FieldData.ListVarName{VarType.vector_x};
    621623        VName=FieldData.ListVarName{VarType.vector_y};
    622         eval(['vector_x=FieldData.' UName ';'])
    623         eval(['vector_y=FieldData.' VName ';'])
     624        vector_x=FieldData.(UName);
     625        vector_y=FieldData.(VName);
    624626    end 
    625627    %identify error flag
    626628    if testfalse
    627629        FFName=FieldData.ListVarName{VarType.errorflag};
    628         eval(['errorflag=FieldData.' FFName ';'])
     630        errorflag=FieldData.(FFName);
    629631    end   
    630632    % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
     
    648650        XName= FieldData.ListVarName{VarType.coord_x};
    649651        YName= FieldData.ListVarName{VarType.coord_y};
    650         eval(['coord_x=FieldData.' XName ';'])   
    651         eval(['coord_y=FieldData.' YName ';'])
     652        coord_x=FieldData.(XName);   
     653        coord_y=FieldData.(YName);
    652654    end   
    653655    %initiate projection
     
    737739        end
    738740        ProjData.X=XLine';
    739         cur_index=1;
    740741        ProjData.ListVarName=[ProjData.ListVarName {XName}];
    741742        ProjData.VarDimName=[ProjData.VarDimName {XName}];
     
    871872                ProjData.VarDimName{end}={AXName,'rgb'};
    872873            end
    873         end     
     874        end
     875    elseif test_tps
     876         if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
     877                DX=abs(ObjectData.DX);%mesh of interpolation points along the line
     878                Xproj=linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint);
     879                xreg=cos(theta(ip))*Xproj+ObjectData.Coord(ip,1)
     880                yreg=sin(theta(ip))*Xproj+ObjectData.Coord(ip,2)
     881%                 coord_x_proj=XMin:DX:XMax;
     882%                 coord_y_proj=YMin:DY:YMax;
     883                DataOut=calc_field(FieldData.FieldList,FieldData,cat(3,xreg,yreg));
     884                ProjData.ListVarName=[ProjData.ListVarName DataOut.ListVarName];
     885                ProjData.VarDimName=[ProjData.VarDimName DataOut.VarDimName];
     886                ProjData.VarAttribute=[ProjData.VarAttribute DataOut.VarAttribute];   
     887                DataOut.ListVarName(1)=[];
     888                DataOut.VarDimName(1)=[];
     889                DataOut.VarAttribute(1)=[];
     890                for ilist=2:length(DataOut.ListVarName)% reshape data, excluding coordinates (ilist=1-2), TODO: rationalise
     891                    VarName=DataOut.ListVarName{ilist};
     892                     ProjData.(VarName)=DataOut.(VarName);
     893                end
     894                ProjData.coord_x=Xproj;
     895         end
    874896    end
    875897end
Note: See TracChangeset for help on using the changeset viewer.