Changeset 1080 for trunk/src/get_field.m


Ignore:
Timestamp:
Apr 17, 2020, 5:58:49 PM (4 years ago)
Author:
sommeria
Message:

ima2temperature.m added and various bug repairs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/get_field.m

    r1072 r1080  
    136136end
    137137if isempty(CellInfo)
    138     Field.MaxDim=max(cellfun(@numel,Field.Display.VarDimName));
     138    [Field.MaxDim,imax]=max(cellfun(@numel,Field.Display.VarDimName));% maximum number of dimensions for the input fields
     139    ListDim=Field.Display.VarDimName{imax};
    139140    check_cellinfo=false;
    140141else
    141     [Field.MaxDim,imax]=max(NbDim);
     142    [Field.MaxDim,imax]=max(NbDim);% maximum number of dimensions for the input fields identified by attributes
    142143    check_cellinfo=true;
    143144end
     
    171172
    172173%% select the Time attribute from input
    173 if isfield(ParamIn,'TimeAttrName')
    174     time_index=find(strcmp(ParamIn.TimeAttrName,Field.Display.ListGlobalAttribute),1);
     174if Field.MaxDim >=2
     175    variable_index=find(strcmp('variable',ListSwitchVarIndexTime),1);
     176    set(handles.SwitchVarIndexTime,'Value',variable_index);
    175177else
    176     time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% look for global attribute containing name 'Time'
    177 end
    178 if isempty(time_index)
    179     set(handles.SwitchVarIndexTime,'Value',1);
    180 else
    181     set(handles.SwitchVarIndexTime,'Value',2);
    182     set(handles.TimeName,'UserData',time_index)
     178    if isfield(ParamIn,'TimeAttrName')
     179        time_index=find(strcmp(ParamIn.TimeAttrName,Field.Display.ListGlobalAttribute),1);
     180    else
     181        time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% look for global attribute containing name 'Time'
     182    end
     183    if isempty(time_index)
     184        set(handles.SwitchVarIndexTime,'Value',1);
     185    else
     186        set(handles.SwitchVarIndexTime,'Value',2);
     187        set(handles.TimeName,'UserData',time_index)
     188    end
    183189end
    184190set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
     
    258264%% fill menus for coordinates and time
    259265FieldOption_Callback(handles.variables,[], handles)% list the global attributes
    260 
    261 %% Make choices of coordinates from input
    262 %     check_menu=false(1,numel(Data.ListVarName));
    263 %     ListCoordMenu=1:numel(Data.ListVarName);
    264 %     CoordIndex=CellInfo{icell}.CoordIndex(CellInfo{icell}.CoordIndex~=0);
    265 %
    266 %             for ivar=find(check_coord_names)
    267 %                 check_dim=strcmp(Data.VarDimName{ivar},DimCell_var);
    268 %                 if ~isempty(find(check_dim))
    269 %                     check_menu(ivar)=true;
    270 %                 end
    271 %             end
    272 %             CellInfo{icell}.CoordMenu=[CoordIndex find(check_menu)];
    273 %             ListCoordMenu(CoordIndex)=[];
    274 %             for ivar=ListCoordMenu
    275 %                 DimCell=Data.VarDimName{ivar};
    276 %                 if isequal(DimCell,DimCell_var)
    277 %                     check_menu(ivar)=true;
    278 %                 end
    279 %             end
    280 %             CellInfo{icell}.CoordMenu=[CellInfo{icell}.CoordMenu find(check_menu)];
    281 %
    282 % if isfield(CellInfo{imax},'CoordIndex')
    283 %     CoordIndex=CellInfo{imax}.CoordIndex;
    284 %     if numel(CoordIndex)==2
    285 %         if isfield(ParamIn,'Coord_x')&& isfield(ParamIn,'Coord_y')
    286 %             YName=ParamIn.Coord_y;
    287 %             XName=ParamIn.Coord_x;
    288 %         else
    289 %         YName=Field.ListVarName{CoordIndex(1)};
    290 %         XName=Field.ListVarName{CoordIndex(2)};
    291 %         end
    292 %         ListCoord=get(handles.Coord_x,'String');
    293 %         XIndex=find(strcmp(XName,ListCoord));
    294 %         if ~isempty(XIndex)
    295 %             set(handles.Coord_x,'Value',XIndex)
    296 %         end
    297 %         YIndex=find(strcmp(YName,ListCoord));
    298 %         if ~isempty(YIndex)
    299 %             set(handles.Coord_y,'Value',YIndex)
    300 %         end
    301 %     end
    302 % end
    303266
    304267%% put the GUI on the lower right of the sceen
     
    663626var_component(var_component==scalar_index)=[];
    664627ListCoord=Field.Display.ListVarName([var_coord var_component]);
    665 
    666 %% set default coord selection
     628coord_val=zeros(size(ListCoord));
     629
     630%% set default selection for grid coordinates
     631coord_val(1)=var_coord(end);
     632coord_val(2)=var_coord(end-1);
     633if numel(var_coord)>=3
     634    coord_val(3)=var_coord(end-2);
     635end
    667636% if numel(find(test_coord))>3
    668637%     SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
     
    675644% end
    676645
    677 coord_val=[0 0];
    678 % look for labelled unstructured coordinates
     646%% default selection for labelled unstructured coordinates
    679647for ilist=1:numel(var_component)
    680648    ivar=var_component(ilist);
     
    696664    coord_val([1 2])=[1 2];
    697665end
     666
     667%% set menu and default selection for coordinates
    698668set(handles.Coord_x,'Value',coord_val(1))
    699669set(handles.Coord_x,'String',ListCoord)
    700 
    701670set(handles.Coord_y,'Value',coord_val(2))
    702671set(handles.Coord_y,'String',ListCoord)
    703 
    704672if numel(coord_val)>=3
    705673    set(handles.Coord_z,'Value',coord_val(3))
     
    956924            if ~isempty(PreviousList)
    957925                PreviousAttr=PreviousList{get(handles.TimeName, 'Value')};
    958                 index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttributes),1);
     926                index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttribute),1);
    959927            end
    960928        end
     
    1011979VarIndex_y=[];
    1012980if ischar(cell_str)
    1013     for ivar=1:length(ListVarName)
    1014         varlist=ListVarName{ivar};
    1015         if isequal(varlist,cell_str)
    1016             VarIndex_y= ivar;
    1017             break
    1018         end
    1019     end
     981    VarIndex_y=find(strcmp(cell_str,ListVarName),1);
    1020982elseif iscell(cell_str)
    1021983    for isel=1:length(cell_str)
     
    1030992end
    1031993
    1032 % --- Executes on button press in CheckDimensionY.
    1033 % function CheckDimensionX_Callback(hObject, eventdata, handles)
    1034 % CheckDimensionX=get(handles.CheckDimensionX,'value')
    1035 % if CheckDimensionX
    1036 %     set(handles.Coordinates,'visible','off')
    1037 % else
    1038 %     set(handles.Coordinates,'visible','on')
    1039 % end
    1040 % FieldList=get(handles.FieldOption,'String');
    1041 % FieldOption=FieldList{get(handles.FieldOption,'Value')};
    1042 % switch FieldOption
    1043 %     case '1D plot'
    1044 %         
    1045 %     case {'scalar'}
    1046 %        scalar_Callback(hObject, eventdata, handles)
    1047 %     case 'vectors'
    1048 % end
     994
    1049995
    1050996% % --- Executes on button press in CheckDimensionY.
     
    11181064end
    11191065
    1120 
     1066%-----------------------------------------------------------------------
    11211067% --- Executes on button press in Check3D.
     1068%-----------------------------------------------------------------------
    11221069function Check3D_Callback(hObject, eventdata, handles)
    11231070if get(handles.Check3D,'Value')% 3D fields
     
    11321079set(handles.vector_z,'Visible',status)
    11331080set(handles.W_title,'Visible',status)
    1134 if strcmp(status,'on')% ask for 3D input   
    1135     Field=get(handles.get_field,'UserData');
     1081Field=get(handles.get_field,'UserData');
     1082if strcmp(status,'on')% ask for 3D input       
    11361083    if Field.MaxDim>3% for 4D fields, propose to use the fourth variable as time
    11371084        %set(handles.Time,'Visible','on')
     
    11431090    else
    11441091        set(handles.SwitchVarIndexTime,'Value',1)
    1145         set(handles.SwitchVarIndexTime,'String',{'file index'})
    1146     end
    1147 else
     1092        set(handles.SwitchVarIndexTime,'String',{'file index';'attribute'})
     1093    end
     1094else 
    11481095   set(handles.SwitchVarIndexTime,'String',get(handles.SwitchVarIndexTime,'UserData'))
     1096   if Field.MaxDim >=3
     1097       var_index=find(strcmp('variable',get(handles.SwitchVarIndexTime,'UserData')));
     1098       set(handles.SwitchVarIndexTime,'Value',var_index)
     1099   end
    11491100end
    11501101SwitchVarIndexTime_Callback(handles.SwitchVarIndexTime,[], handles)
Note: See TracChangeset for help on using the changeset viewer.