Changeset 674 for trunk/src/get_field.m
- Timestamp:
- Aug 23, 2013, 2:56:17 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/get_field.m
r672 r674 1 1 %'get_field': display variables and attributes from a Netcdf file, and OK selected fields 2 2 %------------------------------------------------------------------------ 3 % function varargout = get_field(varargin)3 % GetFieldData=get_field(FileName,ParamIn) 4 4 % associated with the GUI get_field.fig 5 % 6 % OUPUT: 7 % GetFieldData: structure containing the information on the selected 8 % fields, obtained by applying the fct red_GUI to the GUI get_field 9 % .FieldOption='vectors': variables are used for vector plot 10 % 'scalar': variables are used for scalar plot, 11 % '1Dplot': variables are used for usual x-y plot, 12 % 'civdata...': go back to automatic reading of civ data 13 % .PanelVectors: sub-structure variables used as vector components 14 % .PanelScalar: 15 % INPUT: 16 % FileName: name (including path) of the netcdf file to open 5 17 % 6 18 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA … … 42 54 end 43 55 % End initialization code - DO NOT EDIT 44 56 45 57 %------------------------------------------------------------------------ 46 58 % --- Executes just before get_field is made visible. … … 54 66 55 67 %% enter input data 56 set(handles.inputfile,'String',filename)% fill the input file name 57 Field=nc2struct(filename,[]);% reads the field structure, without the variables 68 if ischar(filename)% input file name 69 set(handles.inputfile,'String',filename)% fill the input file name 70 Field=nc2struct(filename,[]);% reads the field structure, without the variables 71 else 72 'bad input to get_field' 73 end 74 if ~exist('ParamIn','var') 75 ParamIn=[]; 76 end 58 77 if isfield(Field,'Txt') 59 msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])% display error message for input fi elreading78 msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])% display error message for input file reading 60 79 return 61 80 end 62 81 if ~isfield(Field,'ListVarName') 63 82 return 64 end65 if ~exist('ParamIn','var')66 ParamIn=[];67 83 end 68 84 … … 111 127 ListSwitchVarIndexTime={'file index'};% default setting: the time is the file index 112 128 % look at global attributes with numerical values 113 check_numvalue=false; 114 check_time=false; 129 check_numvalue=false(1,numel(Field.ListGlobalAttribute)); 115 130 for ilist=1:numel(Field.ListGlobalAttribute) 116 131 Value=Field.(Field.ListGlobalAttribute{ilist}); 117 132 check_numvalue(ilist)=isnumeric(Value); 118 check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1));119 133 end 120 134 Field.Display.ListGlobalAttribute=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value … … 122 136 ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];% the time can be chosen as a global attribute 123 137 end 124 nboption=numel(ListSwitchVarIndexTime);125 138 if Field.MaxDim>=2 126 139 ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];% the time can be chosen as a dim index 127 140 end 128 if ~isempty(find(check_time, 1)) 141 142 %% select the Time attribute from input 143 if isfield(ParamIn,'TimeAttrName') 144 time_index=find(strcmp(ParamIn.TimeAttrName,Field.Display.ListGlobalAttribute),1); 145 else 146 time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1); 147 end 148 if ~isempty(time_index) 129 149 set(handles.SwitchVarIndexTime,'Value',2); 150 set(handles.TimeName,'UserData',time_index) 130 151 else 131 152 set(handles.SwitchVarIndexTime,'Value',1); … … 150 171 end 151 172 if Field.MaxDim>=2 % case of 2D (or 3D) fields 152 if isfield(CellInfo{imax},'VarIndex_vector_x') && isfield(CellInfo{imax},'VarIndex_vector_y') 173 check_vec_input=0; 174 if isfield(ParamIn,'vector_x')&& isfield(ParamIn,'vector_y') 175 ichoice_x=find(strcmp(ParamIn.vector_x,Field.Display.ListVarName),1); 176 ichoice_y=find(strcmp(ParamIn.vector_y,Field.Display.ListVarName),1); 177 if ~isempty(ichoice_x)&&~isempty(ichoice_y) 178 set(handles.vector_x,'UserData',ichoice_x) 179 set(handles.vector_y,'UserData',ichoice_y) 180 check_vec_input=1; 181 end 182 end 183 if ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') && isfield(CellInfo{imax},'VarIndex_vector_y') 184 set(handles.vector_x,'UserData',CellInfo{imax}.VarIndex_vector_x(1)) 185 set(handles.vector_y,'UserData',CellInfo{imax}.VarIndex_vector_y(1)) 186 check_vec_input=1; 187 end 188 if check_vec_input 153 189 set(handles.FieldOption,'Value',3)% set vector selection option 154 set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1))155 set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1))156 set(handles.FieldOption,'Value',3)157 190 else 158 set(handles.FieldOption,'Value',2) 191 set(handles.FieldOption,'Value',2)% set scalar selection option 159 192 end 160 193 else % case of 1D fields … … 177 210 %% fill menus for coordinates and time 178 211 FieldOption_Callback(handles.variables,[], handles)% list the global attributes 179 % if isfield(CellInfo{imax},'VarIndex_coord_x')&& isfield(CellInfo{imax},'VarIndex_coord_y')180 % set(handles.Coord_x,'Value',CellInfo{imax}.VarIndex_coord_x(1))181 % set(handles.Coord_y,'Value',CellInfo{imax}.VarIndex_coord_y(1))182 % end183 212 184 213 %% Make choices of coordinates from input … … 214 243 return 215 244 216 SwitchVarIndexTime_Callback([],[], handles)217 218 245 %% set z coordinate menu if relevant 219 246 if Field.MaxDim>=3 … … 227 254 set(handles.Coord_z,'Visible','off') 228 255 set(handles.Z_title,'Visible','off') 256 end 257 258 %% make selections according to ParamIn 259 if isfield(ParamIn,'vector_x') && isfield(ParamIn,'vector_y') 260 229 261 end 230 262 … … 300 332 for iline=1:length(attr_list) 301 333 Tabcell{iline,1}=attr_list{iline}; 302 eval(['val=VarAttr.' attr_list{iline} ';'])334 val=VarAttr.(attr_list{iline}) ; 303 335 if ischar(val); 304 336 Tabcell{iline,2}=val; … … 406 438 end 407 439 scalar_Callback(hObject, eventdata, handles) 408 440 409 441 case 'vectors' 442 set(handles.PanelVectors,'Visible','on') 410 443 set(handles.Coordinates,'Visible','on') 411 444 set(handles.PanelOrdinate,'Visible','off') 412 445 set(handles.PanelScalar,'Visible','off') 413 set(handles.PanelVectors,'Visible','on')414 446 pos=get(handles.PanelVectors,'Position'); 415 447 pos(1)=2; … … 420 452 set(handles.Y_title,'Visible','on') 421 453 %default vector selection 422 test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante 423 for ilist=1:numel(Field.Display.VarDimName) 424 if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') 425 Role=Field.Display.VarAttribute{ilist}.Role; 426 if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') 454 vector_x_value=get(handles.vector_x,'UserData'); 455 vector_y_value=get(handles.vector_y,'UserData'); 456 if ~isempty(vector_x_value)&&~isempty(vector_y_value) 457 set(handles.vector_x,'Value',vector_x_value) 458 set(handles.vector_y,'Value',vector_y_value) 459 else 460 test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate 461 for ilist=1:numel(Field.Display.VarDimName) 462 if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') 463 Role=Field.Display.VarAttribute{ilist}.Role; 464 if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') 465 test_coord(ilist)=1; 466 end 467 end 468 dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist 469 if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable 427 470 test_coord(ilist)=1; 428 471 end 429 472 end 430 dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist 431 if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable 432 test_coord(ilist)=1; 473 vector_index=find(~test_coord,2);%get the two first variables not a coordinate 474 if isempty(vector_index) 475 set(handles.vector_x,'Value',1) 476 set(handles.vector_y,'Value',2) 477 else 478 set(handles.vector_x,'Value',vector_index(1)) 479 set(handles.vector_y,'Value',vector_index(2)) 433 480 end 434 481 end 435 vector_index=find(~test_coord,2);%get the first variable not a coordiante436 if isempty(vector_index)437 set(handles.vector_x,'Value',1)438 set(handles.vector_y,'Value',2)439 else440 set(handles.vector_x,'Value',vector_index(1))441 set(handles.vector_y,'Value',vector_index(2))442 end443 482 vector_Callback(handles) 444 483 … … 525 564 end 526 565 update_field(handles,YName) 527 566 528 567 %------------------------------------------------------------------------ 529 568 % --- Executes on selection change in scalar menu. … … 801 840 case 'attribute' 802 841 set(handles.TimeName, 'Visible','on')% timeName menu represents the available attributes 803 time_index=[]; 804 PreviousList=get(handles.TimeName, 'String'); 805 index=[]; 806 if ~isempty(PreviousList) 807 PreviousAttr=PreviousList{get(handles.TimeName, 'Value')}; 808 index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttributes)); 809 end 810 if isempty(index) 811 time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')));% index of the attributes containing the string 'Time' 812 end 842 time_index=get(handles.TimeName,'UserData'); %select the input data 843 if isempty(time_index) 844 PreviousList=get(handles.TimeName, 'String'); 845 if ~isempty(PreviousList) 846 PreviousAttr=PreviousList{get(handles.TimeName, 'Value')}; 847 index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttributes),1); 848 end 849 end 850 if isempty(time_index) 851 time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% index of the attributes containing the string 'Time' 852 end 813 853 if ~isempty(time_index) 814 set(handles.TimeName,'Value',time_index (1))854 set(handles.TimeName,'Value',time_index) 815 855 else 816 856 set(handles.TimeName,'Value',1) 817 857 end 818 858 set(handles.TimeName, 'String',Field.Display.ListGlobalAttribute) 859 819 860 case 'variable'% TimeName menu represents the available variables 820 861 set(handles.TimeName, 'Visible','on')
Note: See TracChangeset
for help on using the changeset viewer.