Changeset 521 for trunk/src/read_field.m


Ignore:
Timestamp:
Aug 18, 2012, 11:17:48 PM (12 years ago)
Author:
sommeria
Message:

various bugs corrected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/read_field.m

    r520 r521  
    3939% end
    4040A=[];
     41if ischar(ParamIn.FieldName)
     42    ParamIn.FieldName={ParamIn.FieldName};
     43end
     44            if isfield(ParamIn,'ColorVar')
     45                InputField=[ParamIn.FieldName {ParamIn.ColorVar}];
     46                check_colorvar=1;
     47            else
     48                InputField= ParamIn.FieldName;
     49                check_colorvar=0;
     50            end
    4151%% distingush different input file types
    4252try
    4353    switch FileType
    4454        case 'civdata'
    45 %             ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
    46 %                         ParamOut.ColorVar='ima_cor';
    47                         if isfield(ParamIn,'ColorVar')
    48                         InputField=[{ParamIn.FieldName} {ParamIn.ColorVar}];
    49                         else
    50                            InputField= {ParamIn.FieldName};
    51                         end
    52                         [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType);
    53                         if ~isempty(errormsg),errormsg=['read_civdata:' errormsg];return,end
    54                         ParamOut.CivStage=Field.CivStage;
    55          case 'civx'
     55            [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType);
     56            if ~isempty(errormsg),errormsg=['read_civdata:' errormsg];return,end
     57            ParamOut.CivStage=Field.CivStage;
     58        case 'civx'
    5659            ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
    57                        % ParamOut.ColorVar='ima_cor';
    58                        if isfield(ParamIn,'ColorVar')
    59                         InputField=[{ParamIn.FieldName} {ParamIn.ColorVar}];
    60                         else
    61                            InputField= {ParamIn.FieldName};
    62                         end
    63                         [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType);
    64                         if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end
    65                         ParamOut.CivStage=Field.CivStage;
     60            [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType);
     61            if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end
     62            ParamOut.CivStage=Field.CivStage;
    6663        case 'netcdf'
    67             r=regexp(ParamIn.FieldName,'(^vec|^norm)\((?<UName>.+),(?<VName>.+)\)$','names');
    68             if isempty(r)
    69                 ListVar={ParamIn.FieldName};
    70                 input='scalar';
    71             else
    72                 ListVar={r.UName,r.VName};
    73                 input='vectors';
    74             end
    75             if ~isempty(ParamIn.ColorVar)
    76                 r=regexp(ParamIn.ColorVar,'(^vec|^norm)\((?<UName>.+),(?<VName>.+)\)$','names');
     64            ListVar={};
     65            for ilist=1:numel(InputField)
     66                r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
    7767                if isempty(r)
    78                     ListVar=[ListVar {ParamIn.ColorVar}];
     68                    ListVar=[ListVar InputField(ilist)];
     69                    Role{numel(ListVar)}='scalar';
     70%                     FieldRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot)
    7971                else
    8072                    ListVar=[ListVar {r.UName,r.VName}];
     73                    Role{numel(ListVar)}='vector_y';
     74                    Role{numel(ListVar)-1}='vector_x';
     75%                     switch r.Operator
     76%                         case 'norm'
     77%                             FieldRequest{numel(ListVar)-1}='interp_lin';%scalar field (requires interpolation for plot)
     78%                             FieldRequest{numel(ListVar)}='interp_lin';
     79%                         otherwise
     80%                            FieldRequest{numel(ListVar)-1}='';
     81%                     end
    8182                end
    8283            end
    83                 [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.CoordName ListVar]);
    84                 if strcmp(input,'vectors')
    85                     Field.VarAttribute{3}.Role='vector_x';
    86                     Field.VarAttribute{4}.Role='vector_y';
    87                 else
    88                     Field.VarAttribute{3}.Role='scalar';
    89                 end
    90 %             GUIName='get_field'; %default name of the GUI get_field
    91 %             if isfield(ParamIn,'GUIName')
    92 %                 GUIName=ParamIn.GUIName;
    93 %             end
    94 %             CivStage=0;
    95 % %             if ~strcmp(ParamIn.FieldName,'get_field...')% if get_field is not requested, look for Civx data
    96 %                 FieldList=calc_field;%list of possible fields for Civx data
    97 %                 ParamOut.ColorVar='';%default
    98 %                 if ischar(ParamIn.FieldName)
    99 %                     FieldName=ParamIn.FieldName;
    100 %                 else
    101 %                     FieldName=ParamIn.FieldName{1};
    102 %                 end
    103 %                 field_index=strcmp(FieldName,FieldList);%look for ParamIn.FieldName in the list of possible fields for Civx data
    104 %                 if isempty(find(field_index,1))% ParamIn.FieldName is not in the list, check whether Civx data exist
    105 %                     Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ','CivStage');
    106 %                     % case of new civdata conventions
    107 %                     if isequal(Data.Conventions,'uvmat/civdata')
    108 %                         
    109 %                         %case of old civx conventions
    110 %                     elseif ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)
    111 %                         ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
    112 %                         ParamOut.ColorVar='ima_cor';
    113 %                         InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}];
    114 %                         [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType);
    115 %                         if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end
    116 %                         CivStage=Field.CivStage;
    117 %                         ParamOut.CivStage=Field.CivStage;
    118 %                         % not cvix file, fields will be chosen through the GUI get_field
    119 %                     else
    120 %                         ParamOut.FieldName='get_field...';
    121 %                         hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
    122 %                         if ~isempty(hget_field)
    123 %                             delete(hget_field)%delete  get_field for reinitialisation
    124 %                         end
    125 %                     end
    126 %                 else             
    127 %                     InputField=ParamOut.FieldName;
    128 %                     if ischar(InputField)
    129 %                         InputField={InputField};
    130 %                     end
    131 %                     if isfield(ParamIn,'ColorVar')
    132 %                         ParamOut.ColorVar=ParamIn.ColorVar;
    133 %                         InputField=[InputField {ParamOut.ColorVar}];
    134 %                     end
    135 %                     [Field,ParamOut.VelType,errormsg]=read_civxdata(FileName,InputField,ParamIn.VelType);
    136 %                     if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end
    137 %                     CivStage=Field.CivStage;
    138 %                     ParamOut.CivStage=Field.CivStage;
    139 %                 end
    140 %                 ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}];
    141 %             end
    142 %             if CivStage==0% read the field names on the interface get_field.
    143 %                 hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
    144 %                 if isempty(hget_field)% open the GUI get_field if it is not found
    145 %                     hget_field= get_field(FileName);%open the get_field GUI
    146 %                     set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1)
    147 %                 end
    148 %                 hhget_field=guidata(hget_field);
    149 %                 %% update  the get_field GUI
    150 %                 set(hhget_field.inputfile,'String',FileName)
    151 %                 set(hhget_field.list_fig,'Value',1)
    152 %                 if exist('num','var')&&~isnan(num)
    153 %                     set(hhget_field.TimeIndexValue,'String',num2str(num))
    154 %                 end
    155 % %                 funct_list=get(hhget_field.ACTION,'UserData');
    156 % %                 funct_index=get(hhget_field.ACTION,'Value');
    157 % %                 funct=funct_list{funct_index};%select  the current action in get_field, e;g. PLOT
    158 % %                 Field=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot
    159 %                 [Field,errormsg]=read_get_field(hget_field);
    160 %                 Tabchar={''};%default
    161 %                 Tabcell=[];
    162 %                 set(hhget_field.inputfile,'String',FileName)
    163 %                 if isfield(Field,'ListGlobalAttribute')&& ~isempty(Field.ListGlobalAttribute)
    164 %                     for iline=1:length(Field.ListGlobalAttribute)
    165 %                         Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
    166 %                         if isfield(Field, Field.ListGlobalAttribute{iline})
    167 %                             val=Field.(Field.ListGlobalAttribute{iline});
    168 %                             if ischar(val);
    169 %                                 Tabcell{iline,2}=val;
    170 %                             else
    171 %                                 Tabcell{iline,2}=num2str(val);
    172 %                             end
    173 %                         end
    174 %                     end
    175 %                     if ~isempty(Tabcell)
    176 %                         Tabchar=cell2tab(Tabcell,'=');
    177 %                         Tabchar=[{''};Tabchar];
    178 %                     end
    179 %                 end
    180 %                 ParamOut.CivStage=0;
    181 %                 ParamOut.VelType=[];
    182 %                 if isfield(Field,'TimeIndex')
    183 %                     ParamOut.TimeIndex=Field.TimeIndex;
    184 %                 end
    185 %                 if isfield(Field,'TimeValue')
    186 %                     ParamOut.TimeValue=Field.TimeValue;
    187 %                 end
    188 %                 ParamOut.FieldList={'get_field...'};
    189 
     84            if check_colorvar
     85                Role{numel(ListVar)}='ancillary';% scalar used for color vector (not projected)
     86            end
     87            [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.CoordName ListVar]);
     88            for ivar=1:numel(ListVar)
     89                Field.VarAttribute{ivar+2}.Role=Role{ivar};
     90%                 Field.VarAttribute{ivar+2}.FieldRequest=FieldRequest{ivar};
     91            end
     92            %             GUIName='get_field'; %default name of the GUI get_field
     93            %             if isfield(ParamIn,'GUIName')
     94            %                 GUIName=ParamIn.GUIName;
     95            %             end
     96            %             CivStage=0;
     97            % %             if ~strcmp(ParamIn.FieldName,'get_field...')% if get_field is not requested, look for Civx data
     98            %                 FieldList=calc_field;%list of possible fields for Civx data
     99            %                 ParamOut.ColorVar='';%default
     100            %                 if ischar(ParamIn.FieldName)
     101            %                     FieldName=ParamIn.FieldName;
     102            %                 else
     103            %                     FieldName=ParamIn.FieldName{1};
     104            %                 end
     105            %                 field_index=strcmp(FieldName,FieldList);%look for ParamIn.FieldName in the list of possible fields for Civx data
     106            %                 if isempty(find(field_index,1))% ParamIn.FieldName is not in the list, check whether Civx data exist
     107            %                     Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ','CivStage');
     108            %                     % case of new civdata conventions
     109            %                     if isequal(Data.Conventions,'uvmat/civdata')
     110            %
     111            %                         %case of old civx conventions
     112            %                     elseif ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)
     113            %                         ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
     114            %                         ParamOut.ColorVar='ima_cor';
     115            %                         InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}];
     116            %                         [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType);
     117            %                         if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end
     118            %                         CivStage=Field.CivStage;
     119            %                         ParamOut.CivStage=Field.CivStage;
     120            %                         % not cvix file, fields will be chosen through the GUI get_field
     121            %                     else
     122            %                         ParamOut.FieldName='get_field...';
     123            %                         hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
     124            %                         if ~isempty(hget_field)
     125            %                             delete(hget_field)%delete  get_field for reinitialisation
     126            %                         end
     127            %                     end
     128            %                 else
     129            %                     InputField=ParamOut.FieldName;
     130            %                     if ischar(InputField)
     131            %                         InputField={InputField};
     132            %                     end
     133            %                     if isfield(ParamIn,'ColorVar')
     134            %                         ParamOut.ColorVar=ParamIn.ColorVar;
     135            %                         InputField=[InputField {ParamOut.ColorVar}];
     136            %                     end
     137            %                     [Field,ParamOut.VelType,errormsg]=read_civxdata(FileName,InputField,ParamIn.VelType);
     138            %                     if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end
     139            %                     CivStage=Field.CivStage;
     140            %                     ParamOut.CivStage=Field.CivStage;
     141            %                 end
     142            %                 ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}];
     143            %             end
     144            %             if CivStage==0% read the field names on the interface get_field.
     145            %                 hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
     146            %                 if isempty(hget_field)% open the GUI get_field if it is not found
     147            %                     hget_field= get_field(FileName);%open the get_field GUI
     148            %                     set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1)
     149            %                 end
     150            %                 hhget_field=guidata(hget_field);
     151            %                 %% update  the get_field GUI
     152            %                 set(hhget_field.inputfile,'String',FileName)
     153            %                 set(hhget_field.list_fig,'Value',1)
     154            %                 if exist('num','var')&&~isnan(num)
     155            %                     set(hhget_field.TimeIndexValue,'String',num2str(num))
     156            %                 end
     157            % %                 funct_list=get(hhget_field.ACTION,'UserData');
     158            % %                 funct_index=get(hhget_field.ACTION,'Value');
     159            % %                 funct=funct_list{funct_index};%select  the current action in get_field, e;g. PLOT
     160            % %                 Field=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot
     161            %                 [Field,errormsg]=read_get_field(hget_field);
     162            %                 Tabchar={''};%default
     163            %                 Tabcell=[];
     164            %                 set(hhget_field.inputfile,'String',FileName)
     165            %                 if isfield(Field,'ListGlobalAttribute')&& ~isempty(Field.ListGlobalAttribute)
     166            %                     for iline=1:length(Field.ListGlobalAttribute)
     167            %                         Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
     168            %                         if isfield(Field, Field.ListGlobalAttribute{iline})
     169            %                             val=Field.(Field.ListGlobalAttribute{iline});
     170            %                             if ischar(val);
     171            %                                 Tabcell{iline,2}=val;
     172            %                             else
     173            %                                 Tabcell{iline,2}=num2str(val);
     174            %                             end
     175            %                         end
     176            %                     end
     177            %                     if ~isempty(Tabcell)
     178            %                         Tabchar=cell2tab(Tabcell,'=');
     179            %                         Tabchar=[{''};Tabchar];
     180            %                     end
     181            %                 end
     182            %                 ParamOut.CivStage=0;
     183            %                 ParamOut.VelType=[];
     184            %                 if isfield(Field,'TimeIndex')
     185            %                     ParamOut.TimeIndex=Field.TimeIndex;
     186            %                 end
     187            %                 if isfield(Field,'TimeValue')
     188            %                     ParamOut.TimeValue=Field.TimeValue;
     189            %                 end
     190            %                 ParamOut.FieldList={'get_field...'};
     191           
    190192        case 'video'
    191193            if strcmp(class(ParamIn),'VideoReader')
Note: See TracChangeset for help on using the changeset viewer.