Changeset 581 for trunk/src/get_field.m


Ignore:
Timestamp:
Mar 12, 2013, 12:52:13 PM (11 years ago)
Author:
sommeria
Message:

clean the transform field functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/get_field.m

    r538 r581  
    1 %'get_field': display variables and attributes from a Netcdf file, and RUN selected fields
     1%'get_field': display variables and attributes from a Netcdf file, and OK selected fields
    22%------------------------------------------------------------------------
    33%function varargout = get_field(varargin)
     
    2222function varargout = get_field(varargin)
    2323
    24 % Last Modified by GUIDE v2.5 26-Jul-2012 09:11:23
     24% Last Modified by GUIDE v2.5 10-Mar-2013 21:19:52
    2525
    2626% Begin initialization code - DO NOT EDIT
    27 gui_Singleton = 0;
     27gui_Singleton = 1;
    2828gui_State = struct('gui_Name',       mfilename, ...
    2929                   'gui_Singleton',  gui_Singleton, ...
     
    4545%------------------------------------------------------------------------
    4646% --- Executes just before get_field is made visible.
    47 function get_field_OpeningFcn(hObject, eventdata, handles,filename,multiple)
     47function get_field_OpeningFcn(hObject, eventdata, handles,filename,ParamIn)
    4848%------------------------------------------------------------------------
    4949global nb_builtin % nbre of functions to include by default in the menu of  functions called by RUN
    5050
    51 
    52 
    5351%% Choose default command line output for get_field
    54 handles.output = hObject;
     52handles.output = 'Cancel';
    5553
    5654%% Update handles structure
     
    5856set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
    5957
    60 %% prepare the list of RUN fcts and set their paths
    61 % functions included by default in 'get_field.m
    62 % menu_str={'PLOT';'FFT';'filter_band'};
    63 % nb_builtin=numel(menu_str);
    64 % path_uvmat=fileparts(which('uvmat'));%path of the function 'uvmat'
    65 % addpath(fullfile(path_uvmat,'get_field'))
    66 % testexist=zeros(size(menu_str'));%default
    67 % for ilist=1:length(menu_str)
    68 %     if exist(menu_str{ilist},'file')
    69 %         fct_handle{ilist,1}=str2func(menu_str{ilist});
    70 %         testexist(ilist)=1;
    71 %     else
    72 %         fct_handle{ilist,1}=[];
    73 %         testexist(ilist)=0;
    74 %     end
    75 % end
    76 % rmpath(fullfile(path_uvmat,'get_field'))
    77 % dir_perso=prefdir;
    78 
    79 % look for functions previously used (names and paths saved in the personal file uvmat_perso.mat):
    80 % profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    81 % if exist(profil_perso,'file')
    82 %       h=load (profil_perso);
    83 %      if isfield(h,'get_field_fct') && iscell(h.get_field_fct)
    84 %          for ilist=1:length(h.get_field_fct)
    85 %             [path,file]=fileparts(h.get_field_fct{ilist});
    86 %             addpath(path)       
    87 %             if exist(file,'file')
    88 %                 h_func=str2func(file);
    89 %                 testexist=[testexist 1];
    90 %              else
    91 %                 h_func=[];
    92 %                 testexist=[testexist 0];
    93 %              end
    94 %              fct_handle=[fct_handle; {h_func}]; %concatene the list of paths
    95 %              rmpath(path)
    96 %              menu_str=[menu_str; {file}];
    97 %          end
    98 %      end
    99 % end
    100 
    101 % menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
    102 % fct_handle=fct_handle(testexist==1);
    103 % menu_str=[menu_str;{'more...'}];
    104 % set(handles.ACTION,'String',menu_str)
    105 % set(handles.ACTION,'UserData',fct_handle)% store the list of path in UserData of ACTION
    106 % set(handles.path_action,'String',fullfile(path_uvmat,'get_field'))
    107 % set(handles.ACTION,'Value',1)% PLOT option selected
    108 
    109 %% settings for 'slave' mode, called by uvamt, or 'master' mode
     58%% settings for 'slave' mode, called by uvmat, or 'master' mode
    11059if exist('filename','var') && ischar(filename) %transfer input file name in slave mode
    11160    set(handles.inputfile,'String',filename)% prefill the input file name
    112     Field=nc2struct(filename,[]);% reads the  field structure, without variables
     61    Field=nc2struct(filename,[]);% reads the  field structure, without the variables
    11362    if isfield(Field,'Txt')
    114         msgbox_uvmat('ERROR',Field.Txt)
     63        msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])
    11564    else
    11665        set(handles.get_field,'UserData',Field);
    117         Field_input(handles,Field);
     66        if ~exist('ParamIn','var')
     67            ParamIn=[];
     68        end
     69        Field_input(handles,Field,ParamIn);
    11870    end
    11971else  %master mode
     
    12173end
    12274
    123 %% load the list of previously browsed files for the upper bar menu Open
    124 % dir_perso=prefdir;
    125 % profil_perso=fullfile(dir_perso,'uvmat_perso.mat');%
    126 % if exist(profil_perso,'file')
    127 %     h=load (profil_perso);
    128 %     if isfield(h,'MenuFile_1')
    129 %         set(handles.MenuFile_1,'Label',h.MenuFile_1);
    130 %     end
    131 %     if isfield(h,'MenuFile_1')
    132 %         set(handles.MenuFile_2,'Label',h.MenuFile_2);
    133 %     end
    134 %     if isfield(h,'MenuFile_1')
    135 %         set(handles.MenuFile_3,'Label',h.MenuFile_3);
    136 %     end
    137 %     if isfield(h,'MenuFile_1')
    138 %         set(handles.MenuFile_4,'Label',h.MenuFile_4);
    139 %     end
    140 %     if isfield(h,'MenuFile_1')
    141 %         set(handles.MenuFile_5,'Label',h.MenuFile_5);
    142 %     end
    143 % end
    144 
    14575%% put the GUI on the lower right of the sceen
     76set(hObject,'Unit','pixel')
    14677pos_view_field=get(hObject,'Position');
    14778ScreenSize=get(0,'ScreenSize');
     
    15081set(hObject,'Position',pos_view_field)
    15182
    152 %% remove already opened get_field GUI with name get_field
    153 if ~(exist('multiple','var') && isequal(multiple,1)) %set single occurrence
    154     hget_field=findobj(allchild(0),'Name','get_field'); %hget_field(1)= new GUI
    155     if length(hget_field)>1
    156         delete(hget_field(2))
    157     end
    158 else
    159     set(hObject,'name','get_field_1')
    160 end
    161 
     83% if ~(exist('multiple','var') && isequal(multiple,1)) %set single occurrence
     84%     hget_field=findobj(allchild(0),'Name','get_field'); %hget_field(1)= new GUI
     85%     if length(hget_field)>1
     86%         delete(hget_field(2))
     87%     end
     88% else
     89%     set(hObject,'name','get_field_1')
     90% end
     91set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
     92drawnow
     93 uiwait(handles.get_field);
    16294
    16395%------------------------------------------------------------------------
     
    16698%------------------------------------------------------------------------
    16799varargout{1} = handles.output;
     100delete(handles.get_field)
    168101
    169102%------------------------------------------------------------------------
     
    186119%------------------------------------------------------------------------
    187120% --- update the display when a new field is introduced.
    188 function Field_input(handles,Field)
     121function Field_input(handles,Field,ParamInput)
    189122%------------------------------------------------------------------------
    190123if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
     
    203136set(handles.variables,'String',[{'*'} Txt])
    204137variables_Callback(handles.variables,[], handles)
     138
     139if exist('ParamInput','var')
     140    fill_GUI(ParamInput,handles);
     141    return
     142else
    205143set(handles.abscissa,'String',[{''} Txt ])
    206144set(handles.ordinate,'String',Txt)
     
    209147set(handles.vector_z,'String',[{''} Txt ])
    210148set(handles.vec_color,'String',[{''} Txt ])
    211 set(handles.coord_x_scalar,'String',[{''} Txt ])
    212 set(handles.coord_y_scalar,'String',[{''} Txt ])
    213 set(handles.coord_x_vectors,'String',[{''} Txt ])
    214 set(handles.coord_y_vectors,'String',[{''} Txt ])
    215 set(handles.coord_z_scalar,'String',[{''} Txt ])
    216 set(handles.coord_z_vectors,'String',[{''} Txt ])
     149% set(handles.XVarName,'String',[{''} Txt ])
     150% set(handles.ZVarName,'String',[{''} Txt ])
     151% set(handles.coord_x_vectors,'String',[{''} Txt ])
     152% set(handles.coord_y_vectors,'String',[{''} Txt ])
     153% set(handles.YVarName,'String',[{''} Txt ])
     154% set(handles.TimeVarName,'String',[{''} Txt ])
    217155set(handles.scalar,'Value',1)
    218156
    219157set(handles.scalar,'String', Txt )
    220158[CellInfo,NbDim,errormsg]=find_field_cells(Field);
    221 % [CellVarIndex,NbDim,CoordType,VarRole,errormsg]=find_field_cells(Field);
    222159if ~isempty(errormsg) 
    223160    msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg])
    224161    return
    225162end 
    226 % for icell=1:numel(CellInfo)
    227 %     NbDim(icell)=max(NbDim(icell),numel(CellInfo{icell}.VarIndex));
    228 % end
    229163[maxdim,imax]=max(NbDim);
    230    
     164
     165%% set time mode
     166if maxdim>=4
     167    set(handles.SwitchVarIndexTime,'Value',4)
     168else
     169    time_index=[];
     170    if isfield(Field,'ListGlobalAttribute')
     171    time_index=find(~cellfun('isempty',regexp(Field.ListGlobalAttribute,'Time')));% index of the attributes containing the string 'Time'
     172    end
     173    if isempty(time_index)
     174        set(handles.SwitchVarIndexTime,'Value',1)
     175    else
     176        set(handles.SwitchVarIndexTime,'Value',2)
     177    end
     178end
     179SwitchVarIndexTime_Callback([],[], handles)
     180
    231181if maxdim>=3
    232182    set(handles.vector_z,'Visible','on')
    233183    set(handles.vector_z,'String',[{''} Txt ])
    234     set(handles.coord_z_vectors,'Visible','on')
    235     set(handles.coord_z_vectors,'String',[{''} Txt ])
    236     set(handles.coord_z_scalar,'Visible','on')
    237     set(handles.coord_z_scalar,'String',[{''} Txt ])
     184        set(handles.ZVarName,'Visible','on')
     185    set(handles.SwitchVarIndexZ,'Visible','on')
     186    set(handles.Z_title,'Visible','on')
     187%     set(handles.TimeVarName,'Visible','on')
     188%     set(handles.TimeVarName,'String',[{''} Txt ])
     189%     set(handles.YVarName,'Visible','on')
     190%     set(handles.YVarName,'String',[{''} Txt ])
    238191else
    239192    set(handles.vector_z,'Visible','off')
    240     set(handles.coord_z_vectors,'Visible','off')
    241     set(handles.coord_z_scalar,'Visible','off')
     193    set(handles.ZVarName,'Visible','off')
     194    set(handles.SwitchVarIndexZ,'Visible','off')
     195    set(handles.Z_title,'Visible','off')
    242196end
    243197if maxdim>=2
     
    248202        set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1))
    249203        set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1))
    250         if strcmp(CellInfo{imax}.CoordType,'scattered')
    251             set(handles.coord_x_vectors,'Value',CellInfo{imax}.CoordIndex(end))
    252             set(handles.coord_y_vectors,'Value',CellInfo{imax}.CoordIndex(end-1))
    253         elseif strcmp(CellInfo{imax}.CoordType,'grid')
    254             set(handles.coord_x_vectors,'Value',CellInfo{imax}.CoordIndex(end)+1)
    255             set(handles.coord_y_vectors,'Value',CellInfo{imax}.CoordIndex(end-1)+1)
    256         end
     204%         if strcmp(CellInfo{imax}.CoordType,'scattered')
     205%             set(handles.coord_x_vectors,'Value',CellInfo{imax}.CoordIndex(end))
     206%             set(handles.coord_y_vectors,'Value',CellInfo{imax}.CoordIndex(end-1))
     207%         elseif strcmp(CellInfo{imax}.CoordType,'grid')
     208%             set(handles.coord_x_vectors,'Value',CellInfo{imax}.CoordIndex(end)+1)
     209%             set(handles.coord_y_vectors,'Value',CellInfo{imax}.CoordIndex(end-1)+1)
     210%         end
    257211    else
    258212        set(handles.CheckScalar,'Value',1)
    259213        set(handles.CheckVector,'Value',0)
    260         if isfield(CellInfo{imax},'VarIndex_scalar')
    261             set(handles.scalar,'Value',CellInfo{imax}.VarIndex_scalar(1))
    262                 set(handles.coord_x_scalar,'Value',CellInfo{imax}.CoordIndex(end)+1)
    263                 set(handles.coord_y_scalar,'Value',CellInfo{imax}.CoordIndex(end-1)+1)
    264             if numel(CellInfo{imax}.CoordIndex)==3
    265                 set(handles.coord_z_scalar,'Value',CellInfo{imax}.CoordIndex(1)+1)
    266             end
    267         end
    268     end
    269     CheckPlot1D_Callback(handles.CheckPlot1D, [], handles)
    270     CheckScalar_Callback(handles.CheckScalar, [], handles)
    271     CheckVector_Callback(handles.CheckVector, [], handles)
    272 end
     214%         if isfield(CellInfo{imax},'VarIndex_scalar')
     215%             set(handles.scalar,'Value',CellInfo{imax}.VarIndex_scalar(1))
     216%                 set(handles.XVarName,'Value',CellInfo{imax}.CoordIndex(end)+1)
     217%                 set(handles.ZVarName,'Value',CellInfo{imax}.CoordIndex(end-1)+1)
     218%             if numel(CellInfo{imax}.CoordIndex)==3
     219%                 set(handles.YVarName,'Value',CellInfo{imax}.CoordIndex(1)+1)
     220%             end
     221%         end
     222    end
     223else
     224    set(handles.CheckPlot1D,'Value',1)
     225    set(handles.CheckScalar,'Value',0)
     226    set(handles.CheckVector,'Value',0)
     227end
     228end
     229CheckPlot1D_Callback(handles.CheckPlot1D, [], handles)
     230CheckScalar_Callback(handles.CheckScalar, [], handles)
     231CheckVector_Callback(handles.CheckVector, [], handles)
    273232
    274233%------------------------------------------------------------------------
     
    324283%     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
    325284%     variables_Callback(hObject, eventdata, handles)  %display properties of the TimeVariable (dim, attributes)
    326 %     if  ~test_2D &  ~test_scalar% look for possible varaibles to RUN in ordinate   
     285%     if  ~test_2D &  ~test_scalar% look for possible varaibles to OK in ordinate   
    327286%         index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa
    328287%         VarIndex=[];
     
    330289%             index_i=Field.VarDimIndex{ilist};
    331290%             if ~isempty(index_i)
    332 %                 if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, RUN is possible
     291%                 if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, OK is possible
    333292%                     VarIndex=[VarIndex ilist];
    334293%                 end
     
    378337
    379338string_coord=[{''};string(test_coord==1)];
    380 val=get(handles.coord_x_scalar,'Value');
     339val=get(handles.XVarName,'Value');
    381340if val>numel(string_coord)
    382     set(handles.coord_x_scalar,'Value',1)
    383 end
    384 set(handles.coord_x_scalar,'String',string_coord);
    385 val=get(handles.coord_y_scalar,'Value');
     341    set(handles.XVarName,'Value',1)
     342end
     343set(handles.XVarName,'String',string_coord);
     344val=get(handles.ZVarName,'Value');
    386345if val>numel(string_coord)
    387     set(handles.coord_y_scalar,'Value',1)
    388 end
    389 set(handles.coord_y_scalar,'String',string_coord);
    390 val=get(handles.coord_y_scalar,'Value');
     346    set(handles.ZVarName,'Value',1)
     347end
     348set(handles.ZVarName,'String',string_coord);
     349val=get(handles.ZVarName,'Value');
    391350if val>numel(string_coord)
    392     set(handles.coord_y_scalar,'Value',1)
    393 end
    394 set(handles.coord_z_scalar,'String',string_coord);
    395 
    396 
    397 %------------------------------------------------------------------------
    398 % --- Executes on selection change in coord_x_scalar.
    399 function coord_x_scalar_Callback(hObject, eventdata, handles)
    400 %------------------------------------------------------------------------
    401 index=get(handles.coord_x_scalar,'Value');
    402 string=get(handles.coord_x_scalar,'String');
     351    set(handles.ZVarName,'Value',1)
     352end
     353set(handles.YVarName,'String',string_coord);
     354
     355
     356%------------------------------------------------------------------------
     357% --- Executes on selection change in XVarName.
     358function XVarName_Callback(hObject, eventdata, handles)
     359%------------------------------------------------------------------------
     360index=get(handles.XVarName,'Value');
     361string=get(handles.XVarName,'String');
    403362VarName=string{index};
    404363update_field(hObject, eventdata, handles,VarName)
    405364
    406365%------------------------------------------------------------------------
    407 % --- Executes on selection change in coord_y_scalar.
    408 function coord_y_scalar_Callback(hObject, eventdata, handles)
    409 %------------------------------------------------------------------------
    410 index=get(handles.coord_y_scalar,'Value');
    411 string=get(handles.coord_y_scalar,'String');
     366% --- Executes on selection change in ZVarName.
     367function ZVarName_Callback(hObject, eventdata, handles)
     368%------------------------------------------------------------------------
     369index=get(handles.ZVarName,'Value');
     370string=get(handles.ZVarName,'String');
    412371VarName=string{index};
    413372update_field(hObject, eventdata, handles,VarName)
    414373
    415374%------------------------------------------------------------------------
    416 % --- Executes on selection change in coord_z_scalar.
    417 function coord_z_scalar_Callback(hObject, eventdata, handles)
    418 %------------------------------------------------------------------------
    419 index=get(handles.coord_z_scalar,'Value');
    420 string=get(handles.coord_z_scalar,'String');
     375% --- Executes on selection change in YVarName.
     376function YVarName_Callback(hObject, eventdata, handles)
     377%------------------------------------------------------------------------
     378index=get(handles.YVarName,'Value');
     379string=get(handles.YVarName,'String');
    421380VarName=string{index};
    422381update_field(hObject, eventdata, handles,VarName)
     
    480439end
    481440set(handles.coord_y_vectors,'String',string_coord);
    482 val=get(handles.coord_z_vectors,'Value');
     441val=get(handles.TimeVarName,'Value');
    483442if val>numel(string_coord)
    484     set(handles.coord_z_vectors,'Value',1)
    485 end
    486 set(handles.coord_z_vectors,'String',string_coord);
     443    set(handles.TimeVarName,'Value',1)
     444end
     445set(handles.TimeVarName,'String',string_coord);
    487446
    488447update_field(hObject, eventdata, handles,VarName)
     
    525484
    526485%------------------------------------------------------------------------
    527 % --- Executes on selection change in coord_z_scalar.
    528 function coord_z_vectors_Callback(hObject, eventdata, handles)
    529 %------------------------------------------------------------------------
    530 index=get(handles.coord_z_vectors,'Value');
    531 string=get(handles.coord_z_vectors,'String');
     486% --- Executes on selection change in YVarName.
     487function TimeVarName_Callback(hObject, eventdata, handles)
     488%------------------------------------------------------------------------
     489index=get(handles.TimeVarName,'Value');
     490string=get(handles.TimeVarName,'String');
    532491VarName=string{index};
    533492update_field(hObject, eventdata, handles,VarName)
     
    689648VarIndex.y=name2index(list_var,Field.ListVarName);
    690649if isequal(VarIndex.A,VarIndex.y)
    691     set(handles.coord_y_scalar,'Value',1)
     650    set(handles.ZVarName,'Value',1)
    692651elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
    693652   set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
     
    811770
    812771%---------------------------------------------------------
    813 % --- Executes on button press in RUN.
    814 
    815 function RUN_Callback(hObject, eventdata, handles)
     772% --- Executes on button press in OK.
     773
     774function OK_Callback(hObject, eventdata, handles)
    816775%---------------------------------------------------------
     776
     777handles.output=read_GUI(handles.get_field);
     778guidata(hObject, handles);% Update handles structure
     779uiresume(handles.get_field);
     780drawnow
     781return
     782
     783%%%% SKIPPED %%%%
    817784hfield=[];
    818785huvmat=findobj(allchild(0),'tag','uvmat');
     
    911878if strcmp(list_fig{val},'uvmat')
    912879    set(handles.inputfile,'Enable','off')% desactivate the input file edit box   
    913     set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt)
     880    set(handles.OK,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt)
    914881    set(handles.MenuOpen,'Visible','off')
    915882    set(handles.MenuExport,'Visible','off')
     
    933900% %------------------------------------------------
    934901% % --- Executes on button press in Plot_histo.
    935 % %RUN global histograms
     902% %OK global histograms
    936903% %-------------------------------------------------
    937904% function RUN_histo_Callback(hObject, eventdata, handles)
    938 % % hObject    handle to RUN (see GCBO)
     905% % hObject    handle to OK (see GCBO)
    939906% % eventdata  reserved - to be defined in a future version of MATLAB
    940907% % handles    structure with handles and user data (see GUIDATA)
     
    16721639    set(handles.TimeIndexValue,'Visible','off')
    16731640end
    1674 
    1675 %------------------------------------------------------------------------
    1676 % --- Executes on selection change in TimeDimensionMenu.
    1677 function TimeDimensionMenu_Callback(hObject, eventdata, handles)
    1678 %------------------------------------------------------------------------
    1679 index=get(handles.TimeDimensionMenu,'Value');
    1680 DimList=get(handles.TimeDimensionMenu,'String');
    1681 DimName=DimList{index};
    1682 Field=get(handles.get_field,'UserData');
    1683 DimIndex=find(strcmp(DimName,Field.ListDimName),1);
    1684 ref_index=round(Field.DimValue(DimIndex)/2);   
    1685 set(handles.TimeIndexValue,'String',num2str(ref_index))
    1686 scalar_Callback(hObject, eventdata, handles)
    1687 vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
    1688  % look for a corresponding time variable and value
    1689  time_test=zeros(size(Field.VarDimName));
    1690  for ilist=1:numel(Field.VarDimName)
    1691      if isequal(Field.VarDimName{ilist},{DimName})
    1692          time_test(ilist)=1;
    1693      end
    1694  end
    1695  ListVariable=Field.ListVarName(time_test==1);
    1696  set(handles.TimeVariableMenu,'Value',1)
    1697  if isempty(ListVariable)     
    1698      set(handles.TimeVariableMenu,'String',{''})
    1699      set(handles.TimeVarValue,'String','')
    1700  else
    1701     set(handles.TimeVariableMenu,'String',ListVariable)
    1702     TimeVarName=ListVariable{1};
    1703     VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
    1704     inputfile=get(handles.inputfile,'String');% read the input file
    1705     SubField=nc2struct(inputfile,{TimeVarName});
    1706     eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
    1707     set(handles.TimeVarValue,'Visible','on')
    1708     set(handles.TimeVariableMenu,'Visible','on')
    1709     set(handles.TimeVarValue,'String',num2str(TimeValue))
    1710  end
    1711 
    1712 
     1641%
     1642% %------------------------------------------------------------------------
     1643% % --- Executes on selection change in TimeDimensionMenu.
     1644% function TimeDimensionMenu_Callback(hObject, eventdata, handles)
     1645% %------------------------------------------------------------------------
     1646% index=get(handles.TimeDimensionMenu,'Value');
     1647% DimList=get(handles.TimeDimensionMenu,'String');
     1648% DimName=DimList{index};
     1649% Field=get(handles.get_field,'UserData');
     1650% DimIndex=find(strcmp(DimName,Field.ListDimName),1);
     1651% ref_index=round(Field.DimValue(DimIndex)/2);   
     1652% set(handles.TimeIndexValue,'String',num2str(ref_index))
     1653% scalar_Callback(hObject, eventdata, handles)
     1654% vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
     1655%  % look for a corresponding time variable and value
     1656%  time_test=zeros(size(Field.VarDimName));
     1657%  for ilist=1:numel(Field.VarDimName)
     1658%      if isequal(Field.VarDimName{ilist},{DimName})
     1659%          time_test(ilist)=1;
     1660%      end
     1661%  end
     1662%  ListVariable=Field.ListVarName(time_test==1);
     1663%  set(handles.TimeVariableMenu,'Value',1)
     1664%  if isempty(ListVariable)     
     1665%      set(handles.TimeVariableMenu,'String',{''})
     1666%      set(handles.TimeVarValue,'String','')
     1667%  else
     1668%     set(handles.TimeVariableMenu,'String',ListVariable)
     1669%     TimeVarName=ListVariable{1};
     1670%     VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
     1671%     inputfile=get(handles.inputfile,'String');% read the input file
     1672%     SubField=nc2struct(inputfile,{TimeVarName});
     1673%     eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
     1674%     set(handles.TimeVarValue,'Visible','on')
     1675%     set(handles.TimeVariableMenu,'Visible','on')
     1676%     set(handles.TimeVarValue,'String',num2str(TimeValue))
     1677%  end
     1678%
     1679%
     1680% % % -----------------------------------------------------------------------
     1681% % % --- Executes on button press in TimeVariable.
     1682% % function TimeVariable_Callback(hObject, eventdata, handles)
     1683% % % -----------------------------------------------------------------------
     1684% % val=get(handles.TimeVariable,'Value');
     1685% % if val
     1686% %     Field=get(handles.get_field,'UserData');
     1687% %     time_test=zeros(size(Field.VarDimName));
     1688% %     for ilist=1:numel(Field.VarDimName)
     1689% %         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
     1690% %             time_test(ilist)=1;
     1691% %         end
     1692% %     end
     1693% %     ind_test=find(time_test);
     1694% %     if isempty(time_test)
     1695% %         set(handles.TimeVariable,'Value',0)
     1696% %         set(handles.TimeVariableMenu,'Visible','off')
     1697% %         set(handles.TimeVarValue,'Visible','off')
     1698% %     else
     1699% %         set(handles.TimeVariableMenu,'Visible','on')
     1700% %         set(handles.TimeVarValue,'Visible','on')
     1701% %         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
     1702% %             set(handles.TimeVariableMenu,'Value',1)
     1703% %         end
     1704% %         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
     1705% %         TimeVariableMenu_Callback(hObject, eventdata, handles)
     1706% %         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
     1707% %         set(handles.TimeAttribute,'Value',0)
     1708% %         TimeAttribute_Callback(hObject, eventdata, handles)
     1709% %     end
     1710% % else
     1711% %     set(handles.TimeVariableMenu,'Visible','off')
     1712% %     set(handles.TimeVarValue,'Visible','off')
     1713% % end
     1714%
    17131715% % -----------------------------------------------------------------------
    1714 % % --- Executes on button press in TimeVariable.
    1715 % function TimeVariable_Callback(hObject, eventdata, handles)
     1716% % --- Executes on selection change in TimeVariableMenu.
     1717% function TimeVariableMenu_Callback(hObject, eventdata, handles)
    17161718% % -----------------------------------------------------------------------
    1717 % val=get(handles.TimeVariable,'Value');
    1718 % if val
    1719 %     Field=get(handles.get_field,'UserData');
    1720 %     time_test=zeros(size(Field.VarDimName));
    1721 %     for ilist=1:numel(Field.VarDimName)
    1722 %         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
    1723 %             time_test(ilist)=1;
    1724 %         end
    1725 %     end
    1726 %     ind_test=find(time_test);
    1727 %     if isempty(time_test)
    1728 %         set(handles.TimeVariable,'Value',0)
    1729 %         set(handles.TimeVariableMenu,'Visible','off')
    1730 %         set(handles.TimeVarValue,'Visible','off')
    1731 %     else
    1732 %         set(handles.TimeVariableMenu,'Visible','on')
    1733 %         set(handles.TimeVarValue,'Visible','on')
    1734 %         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
    1735 %             set(handles.TimeVariableMenu,'Value',1)
    1736 %         end
    1737 %         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
    1738 %         TimeVariableMenu_Callback(hObject, eventdata, handles)
    1739 %         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
    1740 %         set(handles.TimeAttribute,'Value',0)
    1741 %         TimeAttribute_Callback(hObject, eventdata, handles)
    1742 %     end
    1743 % else
    1744 %     set(handles.TimeVariableMenu,'Visible','off')
    1745 %     set(handles.TimeVarValue,'Visible','off')
     1719% ListVar=get(handles.TimeVariableMenu,'String');
     1720% index=get(handles.TimeVariableMenu,'Value');
     1721% TimeVariable=ListVar{index};% name of the selected variable
     1722% if isempty(TimeVariable)% case of blank selection
     1723%     return
    17461724% end
    1747 
    1748 % -----------------------------------------------------------------------
    1749 % --- Executes on selection change in TimeVariableMenu.
    1750 function TimeVariableMenu_Callback(hObject, eventdata, handles)
    1751 % -----------------------------------------------------------------------
    1752 ListVar=get(handles.TimeVariableMenu,'String');
    1753 index=get(handles.TimeVariableMenu,'Value');
    1754 TimeVariable=ListVar{index};% name of the selected variable
    1755 if isempty(TimeVariable)% case of blank selection
    1756     return
    1757 end
    1758 Field=get(handles.get_field,'UserData'); %index of
    1759 VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
    1760 DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
    1761 set(handles.TimeDimensionMenu,'Value',1)
    1762 set(handles.TimeDimensionMenu,'String',DimName)
    1763 inputfile=get(handles.inputfile,'String');% read the input file
    1764 SubField=nc2struct(inputfile,{TimeVariable});
    1765 eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
    1766 ref_index=round(TimeDimension/2);
    1767 eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
    1768 set(handles.TimeIndexValue,'String',num2str(ref_index))
    1769 set(handles.TimeVarValue,'String',num2str(TimeValue))
    1770 
    1771 
    1772 function TimeValue_Callback(hObject, eventdata, handles)
    1773 %TO suppress
    1774 
    1775 % -----------------------------------------------------------------------
    1776 function TimeIndexValue_Callback(hObject, eventdata, handles)
    1777 % -----------------------------------------------------------------------
    1778 TimeIndex=str2double(get(handles.TimeIndexValue,'String'));
    1779 TimeVarName=Field.ListVarName{time_index};
    1780 set(handles.TimeVariable,'Value',1)
    1781 set(handles.TimeName,'String',TimeVarName)
    1782 fileinput=get(handles.inputfile,'String');
    1783 SubField=nc2struct(fileinput,{TimeVarName});
    1784 eval(['TimeValue=SubField.' TimeVarName '(ref_index);']);
    1785 set(handles.TimeValue,'Visible','on')
    1786 set(handles.TimeValue,'String',num2str(TimeValue))
    1787 
    1788 % -----------------------------------------------------------------------
    1789 function SelectFigure_Callback(hObject, eventdata, handles)
    1790 % -----------------------------------------------------------------------
    1791 val=get(handles.SelectFigure,'Value');
    1792 if val
    1793     set(handles.list_fig,'Visible','on')
    1794     %% look at the existing figures in the work space
    1795     browse_fig(handles.list_fig)
    1796 else
    1797    set(handles.list_fig,'Visible','off')
    1798 end
    1799 
    1800 
    1801 function TimeVarValue_Callback(hObject, eventdata, handles)
    1802 
     1725% Field=get(handles.get_field,'UserData'); %index of
     1726% VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
     1727% DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
     1728% set(handles.TimeDimensionMenu,'Value',1)
     1729% set(handles.TimeDimensionMenu,'String',DimName)
     1730% inputfile=get(handles.inputfile,'String');% read the input file
     1731% SubField=nc2struct(inputfile,{TimeVariable});
     1732% eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
     1733% ref_index=round(TimeDimension/2);
     1734% eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
     1735% set(handles.TimeIndexValue,'String',num2str(ref_index))
     1736% set(handles.TimeVarValue,'String',num2str(TimeValue))
    18031737
    18041738
    18051739% --- Executes on button press in check_rgb.
    18061740function check_rgb_Callback(hObject, eventdata, handles)
     1741
     1742
     1743% --- Executes when user attempts to close get_field.
     1744function get_field_CloseRequestFcn(hObject, eventdata, handles)
     1745if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
     1746    % The GUI is still in UIWAIT, us UIRESUME
     1747    uiresume(handles.get_field);
     1748else
     1749    % The GUI is no longer waiting, just close it
     1750    delete(handles.get_field);
     1751end
     1752
     1753
     1754
     1755
     1756
     1757% --- Executes on selection change in listbox30.
     1758function listbox30_Callback(hObject, eventdata, handles)
     1759% hObject    handle to listbox30 (see GCBO)
     1760% eventdata  reserved - to be defined in a future version of MATLAB
     1761% handles    structure with handles and user data (see GUIDATA)
     1762
     1763% Hints: contents = cellstr(get(hObject,'String')) returns listbox30 contents as cell array
     1764%        contents{get(hObject,'Value')} returns selected item from listbox30
     1765
     1766
     1767% --- Executes on selection change in SwitchVarIndexX.
     1768function SwitchVarIndexX_Callback(hObject, eventdata, handles)
     1769% hObject    handle to SwitchVarIndexX (see GCBO)
     1770% eventdata  reserved - to be defined in a future version of MATLAB
     1771% handles    structure with handles and user data (see GUIDATA)
     1772
     1773% Hints: contents = cellstr(get(hObject,'String')) returns SwitchVarIndexX contents as cell array
     1774%        contents{get(hObject,'Value')} returns selected item from SwitchVarIndexX
     1775
     1776
     1777% --- Executes on selection change in SwitchVarIndexTime.
     1778function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
     1779menu=get(handles.SwitchVarIndexTime,'String');
     1780option=menu{get(handles.SwitchVarIndexTime,'Value')};
     1781switch option
     1782    case 'file index'
     1783        set(handles.TimeVarName, 'Visible','off')
     1784    case 'attribute'
     1785        set(handles.TimeVarName, 'Visible','on')
     1786        time_index=[];
     1787        ListAttributes=get(handles.attributes,'String');
     1788        if ~isempty(ListAttributes)
     1789            time_index=find(~cellfun('isempty',regexp(ListAttributes,'Time')));% index of the attributes containing the string 'Time'
     1790        end
     1791        if ~isempty(time_index)
     1792            set(handles.TimeVarName,'Value',time_index(1))
     1793        else
     1794            set(handles.TimeVarName,'Value',1)
     1795        end
     1796        set(handles.TimeVarName, 'String',ListAttributes)
     1797    case 'variable'
     1798        ListDim=get(handles.dimensions,'String');
     1799        Field=get(handles.get_field,'UserData');
     1800        for idim=1:numel(ListDim)
     1801            var_count=[];
     1802            for ilist=1:numel(Field.VarDimName)
     1803                DimName=Field.VarDimName{ilist};
     1804                if strcmp(DimName,ListDim{idim})||strcmp(DimName,{ListDim{idim}}) %if the variable has a single dim ( 1D array)
     1805                    var_count=[var_count ilist];
     1806                end
     1807            end
     1808            if numel(var_count)==1
     1809                TimeVarName=[TimeVarName;Field.ListVarName{var_count}];
     1810            end
     1811        end
     1812        set(handles.TimeVarName, 'Visible','on')
     1813        List=get(handles.TimeVarName,'String');
     1814        option=List{get(handles.TimeVarName,'Value')};
     1815        ind=find(strcmp(option,get(handles.dimensions,'String')));
     1816        if isempty(ind)
     1817            set(handles.TimeVarName, 'Value',1);
     1818        else
     1819            set(handles.TimeVarName, 'Value',ind);
     1820        end
     1821        set(handles.TimeVarName, 'String',TimeVarName)
     1822    case 'dim index'
     1823        set(handles.TimeVarName, 'Visible','on')
     1824        List=get(handles.TimeVarName,'String');
     1825        option=List{get(handles.TimeVarName,'Value')};
     1826        ind=find(strcmp(option,get(handles.dimensions,'String')));
     1827        if isempty(ind)
     1828            set(handles.TimeVarName, 'Value',1);
     1829        else
     1830            set(handles.TimeVarName, 'Value',ind);
     1831        end
     1832        set(handles.TimeVarName, 'String',get(handles.dimensions,'String'))
     1833end
     1834
     1835   
Note: See TracChangeset for help on using the changeset viewer.