Changeset 251 for trunk/src/civ_uvmat.m


Ignore:
Timestamp:
May 13, 2011, 11:05:49 AM (14 years ago)
Author:
sommeria
Message:

bug corrected in mouse_motion (display of z)
civ_uvmat corrected to use mask in fix (not implemented in civx fortran programmes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ_uvmat.m

    r248 r251  
    1010mask='';
    1111maskname='';%default
     12test_civx=0;%default
    1213
    1314%% Civ1
     
    7475    Data.CivStage=1;
    7576else
    76     if isfield(Param,'Fix1')
    77         Data=nc2struct(ncfile,ListVarCiv1);%read civ1 data in the existing netcdf file
     77    Data=nc2struct(ncfile,'ListGlobalAttribute','absolut_time_T0');
     78   
     79    % read Civx data
     80    if ~isempty(Data.absolut_time_T0')%read civx file
     81%         var={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F','Civ1_FF';...
     82%             'vec_X','vec_Y','vec_U','vec_V','vec_C','vec_F','vec_FixFlag'};
     83
     84        %var=varcivx_generator('velocity','Civ1');%determine the names of constants and variables to read
     85        test_civx=1;
     86        [Data,vardetect,ichoice]=nc2struct(ncfile);%read the variables in the netcdf file
     87%         Data.ListGlobalAttribute=[{'Conventions','Program','CivStage'} Data.ListGlobalAttribute {'Civ1_Time','Civ1_Dt'}];
     88%         Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
     89%         Data.Program='civ_uvmat';
     90%         Data.Civ1_Time=double(Data.absolut_time_T0);
     91%         Data.Civ1_Dt=double(Data.dt);
     92%         Data.VarDimName={'nbvec1','nbvec1','nbvec1','nbvec1','nbvec1','nbvec1','nbvec1'};
     93%         Data.VarAttribute{1}.Role='coord_x';
     94%         Data.VarAttribute{2}.Role='coord_y';
     95%         Data.VarAttribute{3}.Role='vector_x';
     96%         Data.VarAttribute{4}.Role='vector_y';
     97%         Data.VarAttribute{5}.Role='ancillary';
     98%         Data.VarAttribute{6}.Role='warnflag';
     99%         Data.VarAttribute{7}.Role='errorflag';
     100%         Data.CivStage=1;
    78101    else
    79         Data=nc2struct(ncfile,ListVarFix1);%read civ1 and fix1 data in the existing netcdf file
     102
     103        if isfield(Param,'Fix1')
     104            Data=nc2struct(ncfile,ListVarCiv1);%read civ1 data in the existing netcdf file
     105        else
     106            Data=nc2struct(ncfile,ListVarFix1);%read civ1 and fix1 data in the existing netcdf file
     107        end
    80108    end
    81109    if isfield(Data,'Txt')
     
    83111        return
    84112    end
    85     % read Civx data
    86     if isfield(Data,'absolut_time_T0')%read civx file
    87         var={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F','Civ1_FF';'vec_X','vec_Y','vec_U','vec_V','vec_C','vec_F','vec_FixFlag'};
    88         %var=varcivx_generator('velocity','Civ1');%determine the names of constants and variables to read
    89         [Data,vardetect,ichoice]=nc2struct(ncfile,var);%read the variables in the netcdf file
    90         Data.ListGlobalAttribute=[{'Conventions','Program','CivStage'} Data.ListGlobalAttribute {'Civ1_Time','Civ1_Dt'}];
    91         Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
    92         Data.Program='civ_uvmat';
    93         Data.Civ1_Time=double(Data.absolut_time_T0);
    94         Data.Civ1_Dt=double(Data.dt);
    95         Data.VarDimName={'nbvec1','nbvec1','nbvec1','nbvec1','nbvec1','nbvec1','nbvec1'};
    96         Data.VarAttribute{1}.Role='coord_x';
    97         Data.VarAttribute{2}.Role='coord_y';
    98         Data.VarAttribute{3}.Role='vector_x';
    99         Data.VarAttribute{4}.Role='vector_y';
    100         Data.VarAttribute{5}.Role='ancillary';
    101         Data.VarAttribute{6}.Role='warnflag';
    102         Data.VarAttribute{7}.Role='errorflag';
    103         Data.CivStage=1;
    104     end
    105113end
    106114
     
    119127%     Data.Fix1_ThreshVel=Param.Fix1.ThreshVel;
    120128%     Data.Fix1_UpperBoundTest=Param.Fix1.UpperBoundTest;
    121     Data.ListVarName=[Data.ListVarName {'Civ1_FF'}];
    122     Data.VarDimName=[Data.VarDimName {'nbvec1'}];
    123     nbvar=length(Data.ListVarName);
    124     Data.VarAttribute{nbvar}.Role='errorflag';   
    125     Data.Civ1_FF=fix_uvmat(Param.Fix1,Data.Civ1_F,Data.Civ1_C,Data.Civ1_U,Data.Civ1_V);
    126     Data.CivStage=2;                               
     129
     130    if test_civx
     131        if ~isfield(Data,'fix')
     132            Data.ListGlobalAttribute=[Data.ListGlobalAttribute 'fix'];
     133            Data.fix=1;
     134            Data.ListVarName=[Data.ListVarName {'vec_FixFlag'}];
     135            Data.VarDimName=[Data.VardimName {'nb_vectors'}];
     136        end
     137        Data.vec_FixFlag=fix_uvmat(Param.Fix1,Data.vec_F,Data.vec_C,Data.vec_U,Data.vec_V,Data.vec_X,Data.vec_Y);
     138    else
     139        Data.ListVarName=[Data.ListVarName {'Civ1_FF'}];
     140        Data.VarDimName=[Data.VarDimName {'nbvec1'}];
     141        nbvar=length(Data.ListVarName);
     142        Data.VarAttribute{nbvar}.Role='errorflag';   
     143        Data.Civ1_FF=fix_uvmat(Param.Fix1,Data.Civ1_F,Data.Civ1_C,Data.Civ1_U,Data.Civ1_V);
     144        Data.CivStage=2;   
     145    end
    127146end   
    128147%% Patch1
     
    246265%fieldref: 'civ1','filter1'...feld used in fileref
    247266
    248 function FF=fix_uvmat(Param,F,C,U,V)
     267function FF=fix_uvmat(Param,F,C,U,V,X,Y)
    249268%error=[]; %default
     269Param
    250270FF=zeros(size(F));%default
    251271
     
    270290    FF=FF==1 | (U.*U+V.*V)>thresh;
    271291end
     292if isfield(Param,'MaskName')
     293   M=imread(Param.MaskName);
     294   nxy=size(M);
     295   M=reshape(M,1,[]);
     296   rangx0=[0.5 nxy(2)-0.5];
     297   rangy0=[0.5 nxy(1)-0.5];
     298   vec_x1=X-U/2;%beginning points
     299   vec_x2=X+U/2;%end points of vectors
     300   vec_y1=Y-V/2;%beginning points
     301   vec_y2=Y+V/2;%end points of vectors
     302   indx=1+round((nxy(2)-1)*(vec_x1-rangx0(1))/(rangx0(2)-rangx0(1)));% image index x at abcissa vec_x1
     303   indy=1+round((nxy(1)-1)*(vec_y1-rangy0(1))/(rangy0(2)-rangy0(1)));% image index y at ordinate vec_y1   
     304   test_in=~(indx < 1 |indy < 1 | indx > nxy(2) |indy > nxy(1)); %=0 out of the mask image, 1 inside
     305   indx=indx.*test_in+(1-test_in); %replace indx by 1 out of the mask range
     306   indy=indy.*test_in+(1-test_in); %replace indy by 1 out of the mask range
     307   ICOMB=((indx-1)*nxy(1)+(nxy(1)+1-indy));%determine the indices in the image reshaped in a Matlab vector
     308   Mvalues=M(ICOMB);
     309   flag7b=((20 < Mvalues) & (Mvalues < 200))| ~test_in';
     310   indx=1+round((nxy(2)-1)*(vec_x2-rangx0(1))/(rangx0(2)-rangx0(1)));% image index x at abcissa vec_x2
     311   indy=1+round((nxy(1)-1)*(vec_y2-rangy0(1))/(rangy0(2)-rangy0(1)));% image index y at ordinate vec_y2
     312   test_in=~(indx < 1 |indy < 1 | indx > nxy(2) |indy > nxy(1)); %=0 out of the mask image, 1 inside
     313   indx=indx.*test_in+(1-test_in); %replace indx by 1 out of the mask range
     314   indy=indy.*test_in+(1-test_in); %replace indy by 1 out of the mask range
     315   ICOMB=((indx-1)*nxy(1)+(nxy(1)+1-indy));%determine the indices in the image reshaped in a Matlab vector
     316   Mvalues=M(ICOMB);
     317   flag7e=((Mvalues > 20) & (Mvalues < 200))| ~test_in';
     318   FF=FF==1 |(flag7b|flag7e)';
     319end
     320%    flag7=0;
     321% end   
     322
     323
    272324FF=double(FF);
    273325%
     
    311363%
    312364%             % flag7 introduce a grey mask, matrix M
    313 % if isequal (flag_mask,1)
    314 %    M=imread(maskname);
    315 %    nxy=size(M);
    316 %    M=reshape(M,1,nxy(1)*nxy(2));
    317 %    rangx0=[0.5 nxy(2)-0.5];
    318 %    rangy0=[0.5 nxy(1)-0.5];
    319 %    vec_x1=Field.X-Field.U/2;%beginning points
    320 %    vec_x2=Field.X+Field.U/2;%end points of vectors
    321 %    vec_y1=Field.Y-Field.V/2;%beginning points
    322 %    vec_y2=Field.Y+Field.V/2;%end points of vectors
    323 %    indx=1+round((nxy(2)-1)*(vec_x1-rangx0(1))/(rangx0(2)-rangx0(1)));% image index x at abcissa vec_x
    324 %    indy=1+round((nxy(1)-1)*(vec_y1-rangy0(1))/(rangy0(2)-rangy0(1)));% image index y at ordinate vec_y   
    325 %    test_in=~(indx < 1 |indy < 1 | indx > nxy(2) |indy > nxy(1)); %=0 out of the mask image, 1 inside
    326 %    indx=indx.*test_in+(1-test_in); %replace indx by 1 out of the mask range
    327 %    indy=indy.*test_in+(1-test_in); %replace indy by 1 out of the mask range
    328 %    ICOMB=((indx-1)*nxy(1)+(nxy(1)+1-indy));%determine the indices in the image reshaped in a Matlab vector
    329 %    Mvalues=M(ICOMB);
    330 %    flag7b=((20 < Mvalues) & (Mvalues < 200))| ~test_in';
    331 %    indx=1+round((nxy(2)-1)*(vec_x2-rangx0(1))/(rangx0(2)-rangx0(1)));% image index x at abcissa Field.X
    332 %    indy=1+round((nxy(1)-1)*(vec_y2-rangy0(1))/(rangy0(2)-rangy0(1)));% image index y at ordinate vec_y
    333 %    test_in=~(indx < 1 |indy < 1 | indx > nxy(2) |indy > nxy(1)); %=0 out of the mask image, 1 inside
    334 %    indx=indx.*test_in+(1-test_in); %replace indx by 1 out of the mask range
    335 %    indy=indy.*test_in+(1-test_in); %replace indy by 1 out of the mask range
    336 %    ICOMB=((indx-1)*nxy(1)+(nxy(1)+1-indy));%determine the indices in the image reshaped in a Matlab vector
    337 %    Mvalues=M(ICOMB);
    338 %    flag7e=((Mvalues > 20) & (Mvalues < 200))| ~test_in';
    339 %    flag7=(flag7b|flag7e)';
    340 % else
    341 %    flag7=0;
    342 % end   
     365
    343366% flagmagenta=flag1|flag2|flag3|flag4|flag5|flag7;
    344367% fixflag_unit=Field.FF-10*floor(Field.FF/10); %unity term of fix_flag
Note: See TracChangeset for help on using the changeset viewer.