Ignore:
Timestamp:
Jan 29, 2012, 2:31:56 PM (12 years ago)
Author:
sommeria
Message:

reading of civ data, new format, improved: bugs for reading u and v repairedd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/read_civdata.m

    r379 r380  
    4747% 'nc2struct': reads a netcdf file
    4848
    49 function [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType,XI,YI)
     49function [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType,CivStage)
    5050errormsg='';
    5151VelTypeOut=VelType;%default
     
    6565
    6666%% reading data
    67 [varlist,role,units,vel_type_out_cell]=varcivx_generator(FieldNames,VelType);
    68 [Field,vardetect,ichoice]=nc2struct(filename,varlist);%read the variables in the netcdf file
     67[varlist,role,units,VelTypeOut]=varcivx_generator(FieldNames,VelType,CivStage);
     68[Field,vardetect]=nc2struct(filename,varlist);%read the variables in the netcdf file
    6969if isfield(Field,'Txt')
    7070    errormsg=Field.Txt;
     
    7575     return
    7676end
    77 switch vel_type_out_cell{ichoice}
    78     case{'civ1','fix1','patch1'}
    79         Field.dt=Field.Civ1_Dt;
    80     case{'civ2','fix2','patch2'}
    81         Field.dt=Field.Civ2_Dt;
     77switch VelTypeOut
     78    case{'civ1','civ-filter1','filter1'}
     79        Field.Dt=Field.Civ1_Dt;
     80    case{'civ2','civ-filter2','filter2'}
     81        Field.Dt=Field.Civ2_Dt;
    8282end
    83 Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'dt'}];
     83Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt'}];
    8484var_ind=find(vardetect);
    8585for ivar=1:min(numel(var_ind),numel(Field.VarAttribute))
     
    8888    Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel
    8989end
    90 if ~isempty(ichoice)
    91     VelTypeOut=vel_type_out_cell{ichoice};
    92 end
    9390
    94 
    95 %% renaming for standard conventions
    96 %Field.NbCoord=Field.nb_coord;
    97 %Field.NbDim=2;%Field.nb_dim;
    98 
    99 %% CivStage
    100 % if isfield(Field,'patch2')&& isequal(Field.patch2,1)
    101 %     Field.CivStage=6;
    102 % elseif isfield(Field,'fix2')&& isequal(Field.fix2,1)
    103 %     Field.CivStage=5;
    104 % elseif isfield(Field,'civ2')&& isequal(Field.civ2,1)
    105 %     Field.CivStage=4;
    106 % elseif isfield(Field,'patch')&& isequal(Field.patch,1)
    107 %     Field.CivStage=3;
    108 % elseif isfield(Field,'fix')&& isequal(Field.fix,1)
    109 %     Field.CivStage=2;
    110 % else
    111 %     Field.CivStage=1;
    112 % end
    11391Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
    114 % %determine the appropriate constant for time and dt for the PIV pair
    115 % test_civ1=isequal(VelTypeOut,'civ1')||isequal(VelTypeOut,'interp1')||isequal(VelTypeOut,'filter1');
    116 % test_civ2=isequal(VelTypeOut,'civ2')||isequal(VelTypeOut,'interp2')||isequal(VelTypeOut,'filter2');
    117 % Field.Time=0; %default
    118 % Field.TimeUnit='s';
    119 % if test_civ1
    120 %     if isfield(Field,'absolut_time_T0')
    121 %         Field.Time=double(Field.absolut_time_T0);
    122 %         Field.dt=double(Field.dt);
    123 %     else
    124 %        Field.Txt='the input file is not civx';
    125 %        Field.CivStage=0;
    126 %        Field.dt=0;
    127 %     end
    128 % elseif test_civ2
    129 %     Field.Time=double(Field.absolut_time_T0_2);
    130 %     Field.dt=double(Field.dt2);
    131 % else
    132 %     Field.Txt='the input file is not civx';
    133 %     Field.CivStage=0;
    134 %     Field.dt=0;
    135 % end
    136 %
    137 %
    138 %
    13992% %% update list of global attributes
    140 % List=Field.ListGlobalAttribute;
    141 % ind_remove=[];
    142 % for ilist=1:length(List)
    143 %     switch(List{ilist})
    144 %         case {'patch2','fix2','civ2','patch','fix','dt2','absolut_time_T0','absolut_time_T0_2','nb_coord','nb_dim','pixcmx','pixcmy'}
    145 %             ind_remove=[ind_remove ilist];
    146 %             Field=rmfield(Field,List{ilist});
    147 %     end
    148 % end
    149 % List(ind_remove)=[];
    150 % Field.ListGlobalAttribute=[{'NbCoord'},{'NbDim'} List {'Time','TimeUnit','CivStage','CoordUnit'}];
    15193Field.NbCoord=2;
    15294Field.NbDim=2;
     
    15799
    158100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    159 % TAKEN FROM read_civxdata NOT USED
    160101% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
    161102%INPUT:
     
    166107%             
    167108% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
    168 %            if vel_type=[] or'*', a  priority choice, given by vel_type_out{1,2}, is done depending
    169 %            if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
     109%            if vel_type=[] or'*', a  priority choice is done, civ2 considered better than civ1 )
    170110
    171 function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
     111function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type,CivStage)
    172112
    173113%% default input values
     
    187127        case {'vort','div','strain'}
    188128            testder=1;
     129           
    189130    end
    190131    end
    191132end   
     133
     134if isempty(vel_type)
     135    switch CivStage
     136        case {6} %filter2 available
     137            vel_type='civ2';
     138        case {4,5}% civ2 available but not filter2
     139            if testder% derivatives needed
     140                vel_type='civ1';
     141            else
     142                vel_type='civ2';
     143            end
     144        case {1,2,3}% civ1 available but not civ2
     145            vel_type='civ1';
     146    end
     147end
     148if strcmp(vel_type,'civ2') && testder
     149    vel_type='filter2';
     150elseif stcmp(vel_type,'civ1') && testder
     151    vel_type='filter1';
     152end
     153
    192154switch vel_type
    193     case 'civ1'
    194         var={'X','Y','Z','U','V','W','C','F','FF';...
    195             'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
    196         role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
    197         units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
    198     case 'interp1'
     155    case {'civ1'}
     156        var={'X','Y','Z','U','V','W','C','F','FF','X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
     157            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
     158            'Civ1_X_tps','Civ1_Y_tps','','Civ1_U_tps','Civ1_V_tps','','Civ1_X_SubRange','Civ1_Y_SubRange','Civ1_NbSites'};
     159        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','','','','','','','','',''};
     160        units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''};
     161    case 'civ-filter1'
    199162        var={'X','Y','Z','U','V','W','FF';...
    200163            'Civ1_X','Civ1_Y','','Civ1_U_Diff','Civ1_V_Diff','','Civ1_FF'};
     
    207170        units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''};
    208171    case 'civ2'
    209         var={'X','Y','Z','U','V','W','C','F','FF';...
    210             'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
    211         role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
    212         units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
    213     case 'interp2'
     172        var={'X','Y','Z','U','V','W','C','F','FF','X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
     173            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
     174            'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites'};
     175        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','','','','','','','','',''};
     176        units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''};
     177%         var={'X','Y','Z','U','V','W','C','F','FF';...
     178%             'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
     179%         role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
     180%         units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
     181    case 'civ-filter2'
    214182        var={'X','Y','Z','U','V','W','FF';...
    215183            'Civ2_X','Civ2_Y','','Civ2_U_Diff','Civ2_V_Diff','','Civ2_FF'};
     
    221189        role={'','','','','','','','',''};
    222190        units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel',''};
    223     otherwise % if VelType=[], choose the best field, civ in priority, or patch2 for derivatives
    224         if testpatch
    225             var={'X_tps','Y_tps','Z_tps','U_tps','V_tps','W_tps','X_SubRange','Y_SubRange','NbSites';...
    226                 'Civ2_X_tps','Civ2_Y_tps','','Civ2_U_tps','Civ2_V_tps','','Civ2_X_SubRange','Civ2_Y_SubRange','Civ2_NbSites';...
    227                 'Civ1_X_tps','Civ1_Y_tps','','Civ1_U_tps','Civ1_V_tps','','Civ1_X_SubRange','Civ1_Y_SubRange','Civ1_NbSites'};
    228             role={'','','','','','','',''};
    229             units={'pixel','pixel','pixel','pixel','pixel','pixel','pixel','pixel'};
    230         else
    231             var={'X','Y','Z','U','V','W','C','F','FF';...
    232                 'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF';...
    233                 'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
    234             role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
    235             units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
    236         end
    237191end
    238 if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
    239     if testder
    240          vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
    241         vel_type_out{2}='filter1';
    242     else
    243         vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority     
    244         vel_type_out{2}='civ1';
    245     end
    246 elseif isequal(vel_type,'filter')
    247         vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
    248         vel_type_out{2}='filter1';
    249         if ~testder
    250             vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed
    251         end
    252 elseif testder
    253     test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1');
    254     if test_civ1
    255         vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives
    256     else
    257         vel_type_out{1}='filter2';
    258     end
    259 else   
    260     vel_type_out{1}=vel_type;%imposed velocity field
    261 end
    262 vel_type_out=vel_type_out';
     192vel_type_out=vel_type;
    263193
    264194
     
    266196
    267197
    268 
Note: See TracChangeset for help on using the changeset viewer.