Changeset 227 for trunk/src/get_field.m


Ignore:
Timestamp:
Mar 31, 2011, 1:42:51 PM (13 years ago)
Author:
sommeria
Message:

add function sub_field_series to apply the sub_field operation to a series of fileds (for instance subtracting a background to an image series)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/get_field.m

    r213 r227  
    2222function varargout = get_field(varargin)
    2323
    24 % Last Modified by GUIDE v2.5 06-Feb-2010 09:58:13
     24% Last Modified by GUIDE v2.5 27-Mar-2011 19:13:26
    2525
    2626% Begin initialization code - DO NOT EDIT
     
    4949global nb_builtin % nbre of functions to include by default in the menu of  functions called by RUN
    5050
    51 %% look at the existing figures in the work space
    52 browse_fig(handles.list_fig)
     51
    5352
    5453%% Choose default command line output for get_field
     
    5857guidata(hObject, handles);
    5958
    60 %% activate the mouse action function: visualise the current field on work space by right click action
    61 set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})
     59%%activate the mouse action function: visualise the current field on work space by right click action
     60%set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})
    6261
    6362%% prepare the list of RUN fcts and set their paths
     
    112111%% settings for 'slave' mode, called by uvamt, or 'master' mode
    113112if exist('filename','var') && ischar(filename) %transfer input file name in slave mode
    114     set(handles.inputfile,'String',filename)% prefill the input file name 
    115     Field=nc2struct(filename);% reads the whole field
     113    set(handles.inputfile,'String',filename)% prefill the input file name
     114    Field=nc2struct(filename,[]);% reads the whole field
    116115    if isfield(Field,'Txt')
    117116        msgbox_uvmat('ERROR',Field.Txt)
    118117    else
    119         set(handles.figure1,'UserData',Field);
     118        set(handles.get_field,'UserData',Field);
    120119        Field_input(eventdata,handles,Field);
    121120    end
    122121else  %master mode
    123     set(handles.inputfile,'String','')   
    124 %     set(handles.RUN,'String','RUN')%
    125     % load the list of previously browsed files for the upper bar menu Open
    126     dir_perso=prefdir;
    127     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');%
    128     if exist(profil_perso,'file')
    129         h=load (profil_perso);
    130         if isfield(h,'MenuFile_1')
    131             set(handles.MenuFile_1,'Label',h.MenuFile_1);
    132         end
    133         if isfield(h,'MenuFile_1')
    134             set(handles.MenuFile_2,'Label',h.MenuFile_2);
    135         end
    136         if isfield(h,'MenuFile_1')
    137             set(handles.MenuFile_3,'Label',h.MenuFile_3);
    138         end
    139         if isfield(h,'MenuFile_1')
    140             set(handles.MenuFile_4,'Label',h.MenuFile_4);
    141         end
    142         if isfield(h,'MenuFile_1')
    143             set(handles.MenuFile_5,'Label',h.MenuFile_5);
    144         end
     122    set(handles.inputfile,'String','')
     123end
     124
     125%% load the list of previously browsed files for the upper bar menu Open
     126dir_perso=prefdir;
     127profil_perso=fullfile(dir_perso,'uvmat_perso.mat');%
     128if exist(profil_perso,'file')
     129    h=load (profil_perso);
     130    if isfield(h,'MenuFile_1')
     131        set(handles.MenuFile_1,'Label',h.MenuFile_1);
     132    end
     133    if isfield(h,'MenuFile_1')
     134        set(handles.MenuFile_2,'Label',h.MenuFile_2);
     135    end
     136    if isfield(h,'MenuFile_1')
     137        set(handles.MenuFile_3,'Label',h.MenuFile_3);
     138    end
     139    if isfield(h,'MenuFile_1')
     140        set(handles.MenuFile_4,'Label',h.MenuFile_4);
     141    end
     142    if isfield(h,'MenuFile_1')
     143        set(handles.MenuFile_5,'Label',h.MenuFile_5);
    145144    end
    146145end
     
    168167%------------------------------------------------------------------------
    169168inputfile=get(handles.inputfile,'String');
    170 Field=nc2struct(inputfile);% reads the whole field
     169Field=nc2struct(inputfile,[]);% reads the  field description, without data
     170Field.ListGlobalAttribute
    171171if isfield(Field,'Txt')
    172172    msgbox_uvmat('ERROR',Field.Txt)
    173173else
    174 set(handles.figure1,'UserData',Field);
     174set(handles.get_field,'UserData',Field);
    175175Field_input(eventdata,handles,Field);
    176176end
     
    189189        Tabcell{iline,2}=num2str(Field.DimValue(iline));
    190190    end
    191     Tabchar=cell2tab(Tabcell,'=');
     191    Tabchar=cell2tab(Tabcell,' = ');
    192192    set(handles.dimensions,'String',Tabchar)
    193193end
     
    212212set(handles.coord_z_vectors,'String',[{''} Txt ])
    213213set(handles.scalar,'Value',1)
     214
    214215set(handles.scalar,'String', Txt )
    215216[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
     
    218219    return
    219220end 
     221for icell=1:numel(CellVarIndex)
     222    NbDim(icell)=max(NbDim(icell),numel(CellVarIndex{icell}));
     223end
    220224[maxdim,imax]=max(NbDim);
    221225   
     
    278282    check_vector_Callback(handles.check_vector, eventdata, handles)
    279283end
     284%scalar_Callback(handles.get_field, eventdata, handles)
     285%vector_x_Callback(handles.get_field, eventdata, handles)
    280286
    281287%------------------------------------------------------------------------
     
    315321% test_2D=get(handles.check_vector,'Value');% =1 for vector fields
    316322% test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields
    317 %if isequal(xdispindex,1)% blank selection, no selected variable for abscissa
     323%if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa
    318324%     Txt=Field.ListVarName;
    319325%     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
     
    329335%      end
    330336%     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
    331 %     variables_Callback(hObject, eventdata, handles)  %display properties of the variable (dim, attributes)
     337%     variables_Callback(hObject, eventdata, handles)  %display properties of the TimeVariable (dim, attributes)
    332338%     if  ~test_2D &  ~test_scalar% look for possible varaibles to RUN in ordinate   
    333 %         index=Field.VarDimIndex{xindex};%dimension indices of the variable selected for abscissa
     339%         index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa
    334340%         VarIndex=[];
    335341%         for ilist=1:length(Field.VarDimIndex)%detect
    336342%             index_i=Field.VarDimIndex{ilist};
    337343%             if ~isempty(index_i)
    338 %                 if isequal(index_i(1),index(1))%if the first dimension of the variable coincide with the selected one, RUN is possible
     344%                 if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, RUN is possible
    339345%                     VarIndex=[VarIndex ilist];
    340346%                 end
     
    352358function scalar_Callback(hObject, eventdata, handles)
    353359%------------------------------------------------------------------------
    354 Aindex=get(handles.scalar,'Value');
    355 Astring=get(handles.scalar,'String');
    356 VarName=Astring{Aindex};
     360index=get(handles.scalar,'Value');
     361string=get(handles.scalar,'String');
     362VarName=string{index};
    357363update_field(hObject, eventdata, handles,VarName)
     364
     365%eliminate time
     366TimeDimName='';%default
     367if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on')
     368    TimeDimList=get(handles.TimeDimensionMenu,'String');
     369    TimeDimIndex=get(handles.TimeDimensionMenu,'Value');
     370    TimeDimName=TimeDimList{TimeDimIndex};
     371end
     372
     373%check possible coordinates
     374Field=get(handles.get_field,'UserData');
     375dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar
     376test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
     377for ilist=1:numel(Field.VarDimName)
     378    dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
     379    if isequal(dimnames,{TimeDimName})
     380        test_coord(ilist)=0;%mark time variables fo elimination
     381    end
     382    for idim=1:numel(dimnames)
     383        if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable
     384            test_coord(ilist)=0;
     385            break
     386        end
     387    end
     388end
     389test_coord(index)=0;%the coordinate variable must be different from the scalar
     390
     391string_coord=[{''};string(test_coord==1)];
     392val=get(handles.coord_x_scalar,'Value');
     393if val>numel(string_coord)
     394    set(handles.coord_x_scalar,'Value',1)
     395end
     396set(handles.coord_x_scalar,'String',string_coord);
     397val=get(handles.coord_y_scalar,'Value');
     398if val>numel(string_coord)
     399    set(handles.coord_y_scalar,'Value',1)
     400end
     401set(handles.coord_y_scalar,'String',string_coord);
     402val=get(handles.coord_y_scalar,'Value');
     403if val>numel(string_coord)
     404    set(handles.coord_y_scalar,'Value',1)
     405end
     406set(handles.coord_z_scalar,'String',string_coord);
     407
    358408
    359409%------------------------------------------------------------------------
     
    391441string=get(handles.vector_x,'String');
    392442VarName=string{index};
     443
     444%check possible coordinates
     445Field=get(handles.get_field,'UserData');
     446dim_var=Field.VarDimName{index};%list of dimensions of the selected scalar
     447test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
     448test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component
     449for ilist=1:numel(Field.VarDimName)
     450    dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
     451    if ~isequal(dimnames,dim_var)
     452        test_component(ilist)=0;
     453    end
     454    for idim=1:numel(dimnames)
     455        if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable
     456            test_coord(ilist)=0;
     457            break
     458        end
     459    end
     460end
     461%eliminate time
     462if get(handles.TimeVariable,'Value')
     463    TimeName=get(handles.TimeName,'String');
     464    index_time=find(strcmp( TimeName,Field.ListVarName));
     465    test_coord(index_time)=0;
     466end
     467vlength=numel(string(test_component==1));
     468val=get(handles.vector_y,'Value');
     469if val>vlength
     470    set(handles.vector_y,'Value',1)
     471end
     472set(handles.vector_y,'String',[string(test_component==1)])
     473val=get(handles.vector_z,'Value');
     474if val>vlength+1
     475    set(handles.vector_z,'Value',1)
     476end
     477set(handles.vector_z,'String',[{''};string(test_component==1)])
     478val=get(handles.vec_color,'Value');
     479if val>vlength+1
     480    set(handles.vec_color,'Value',1)
     481end
     482set(handles.vec_color,'String',[{''};string(test_component==1)])
     483string_coord=[{''};string(test_coord==1)];
     484val=get(handles.coord_x_vectors,'Value');
     485if val>numel(string_coord)
     486    set(handles.coord_x_vectors,'Value',1)
     487end
     488set(handles.coord_x_vectors,'String',string_coord);
     489val=get(handles.coord_y_vectors,'Value');
     490if val>numel(string_coord)
     491    set(handles.coord_y_vectors,'Value',1)
     492end
     493set(handles.coord_y_vectors,'String',string_coord);
     494val=get(handles.coord_z_vectors,'Value');
     495if val>numel(string_coord)
     496    set(handles.coord_z_vectors,'Value',1)
     497end
     498set(handles.coord_z_vectors,'String',string_coord);
     499
    393500update_field(hObject, eventdata, handles,VarName)
    394501
     
    420527update_field(hObject, eventdata, handles,VarName)
    421528
    422 %-------------------------------------------------------
     529%------------------------------------------------------------------------
    423530% --- Executes on selection change in coord_y_vectors.
    424 %-------------------------------------------------------
    425531function coord_y_vectors_Callback(hObject, eventdata, handles)
     532%------------------------------------------------------------------------
    426533index=get(handles.coord_y_vectors,'Value');
    427534string=get(handles.coord_y_vectors,'String');
     
    429536update_field(hObject, eventdata, handles,VarName)
    430537
    431 %-------------------------------------------------------
     538%------------------------------------------------------------------------
    432539% --- Executes on selection change in coord_z_scalar.
    433540function coord_z_vectors_Callback(hObject, eventdata, handles)
    434 %-------------------------------------------------------
     541%------------------------------------------------------------------------
    435542index=get(handles.coord_z_vectors,'Value');
    436543string=get(handles.coord_z_vectors,'String');
     
    438545update_field(hObject, eventdata, handles,VarName)
    439546
    440 %-------------------------------------------------------
     547%------------------------------------------------------------------------
    441548% --- Executes on selection change in vec_color.
    442549function vec_color_Callback(hObject, eventdata, handles)
    443 %-------------------------------------------------------
     550%------------------------------------------------------------------------
    444551index=get(handles.vec_color,'Value');
    445552string=get(handles.vec_color,'String');
     
    447554update_field(hObject, eventdata, handles,VarName)
    448555
    449 %---------------------------------
     556%-----------------------------------------------------------------------
    450557function update_field(hObject, eventdata, handles,VarName)
    451 % VarName= input variable name for scalar or vector plots
    452 hselect_field=get(handles.inputfile,'parent');
    453 Field=get(hselect_field,'UserData');
     558%-----------------------------------------------------------------------
     559Field=get(handles.get_field,'UserData');
    454560index=name2index(VarName,Field.ListVarName);
    455561if ~isempty(index)
     
    457563    variables_Callback(hObject, eventdata, handles)
    458564end
    459 %
    460 %
    461 % hselect_field=get(handles.inputfile,'parent');
    462 % Field=get(hselect_field,'UserData');
    463 % ivar_sel=[];%default
    464 % for ivar=1:length(Field.ListVarName)%detect
    465 %     if isequal(Field.ListVarName{ivar},VarName)
    466 %         ivar_sel=ivar; %ivar_sel = index of the input variable in the list ListVarName
    467 %         break
    468 %     end
    469 % end
    470 % if isempty(ivar_sel)
    471 %     return
    472 % end
    473 % set(handles.variables,'Value',ivar_sel+1)%select the corresponding item in the displayed  list 'variables'
    474 % variables_Callback(hObject, eventdata, handles)%show the dimensions and attributes of the input variable
    475 %
    476 % index=Field.VarDimIndex{ivar_sel};%dimension indices of the input variable
    477 % DimValue=Field.DimValue(index);%dimension values of the input variable
    478 % ind_1=find(DimValue==1);
    479 % index(ind_1)=[];%Mremove singletons
    480 %
    481 %
    482 % % detect possible variables for abscissa and ordinate
    483 % VarIndex=[];%initiate list of selected variable indices
    484 % ind_coordvar=[]; %initiate list of coordinate variables
    485 % for ilist=1:length(Field.VarDimIndex)
    486 %     if ~isequal(ilist,ivar_sel)       
    487 %         index_i=Field.VarDimIndex{ilist};%indices of dimensions associated with variable #ilist
    488 %         if length(index_i)>1
    489 %             DimValue=Field.DimValue(index_i);
    490 %             ind_1=find(DimValue==1);
    491 %             index_i(ind_1)=[];%Mremove singletons
    492 %             if isequal(index,index_i)
    493 %                 VarIndex=[VarIndex ilist]; %selected variable withb the same dimensions of the input variable
    494 %             end
    495 %         else
    496 %             idim=find(index==index_i(1));
    497 %             if ~isempty(idim)
    498 %                  VarIndex=[VarIndex ilist]; %possible dimension variable
    499 %                  if isequal(Field.ListDimName{index_i(1)},Field.ListVarName{ilist})
    500 %                      ind_coordvar=[ind_coordvar length(VarIndex)];
    501 %                  end
    502 %             end
    503 %         end
    504 %     end
    505 % end
    506 % % val=get(handles.abscissa,'Value');
    507 % % if val>length(Field.ListVarName(VarIndex))+1
    508 % %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
    509 % % end
    510 % % val=get(handles.ordinate,'Value');
    511 % % if val>length(Field.ListVarName(VarIndex))+1
    512 % %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
    513 % % end
    514 % % val=get(handles.coord_z_vectors_scalar,'Value');
    515 % % if val>length(Field.ListVarName(VarIndex))+1
    516 % %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
    517 % % end
    518 % set(handles.abscissa,'Value',1)%default
    519 % set(handles.ordinate,'Value',1)%default
    520 % set(handles.coord_z_scalar,'Value',1)%default
    521 % set(handles.abscissa,'String',[{''} Field.ListVarName(VarIndex) ])
    522 % set(handles.ordinate,'String',[{''} Field.ListVarName(VarIndex) ])
    523 % set(handles.coord_z_scalar,'String',[{''} Field.ListVarName(VarIndex) ])
    524 % if length(ind_coordvar)>=1
    525 %     set(handles.abscissa,'Value',ind_coordvar(1)+1)
    526 % elseif length(index)==1 && length(VarIndex)>=1
    527 %     set(handles.abscissa,'Value',2)
    528 % end
    529 % if length(ind_coordvar)>=2
    530 %     set(handles.ordinate,'Value',ind_coordvar(2)+1)
    531 % elseif length(index)==1 && length(VarIndex)>=2
    532 %     set(handles.ordinate,'Value',3)
    533 % end
    534 % if length(ind_coordvar)>=3
    535 %     set(handles.coord_z_scalar,'Value',ind_coordvar(3)+1)
    536 % elseif length(index)==1 && length(VarIndex)>=3
    537 %     set(handles.coord_z_scalar,'Value',4)
    538 % end
    539 
    540 %---------------------------------------------------------
     565
     566%------------------------------------------------------------------------
    541567% update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
    542568function update_UserData(handles)
    543 %---------------------------------------------------------
     569%------------------------------------------------------------------------
    544570return
    545571% global SubField
     
    615641    end
    616642    DimIndex=DimIndex_u;
    617     %TODO possibility of selecting 3 times the same variable for u, v, w components
    618 end
    619 
    620 
    621 % select the variable  index (or indices) for z coordinates
     643    %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components
     644end
     645
     646
     647% select the TimeVariable  index (or indices) for z coordinates
    622648test_grid=0;
    623649if test_scalar | test_vector
     
    658684        end
    659685%         if ~isempty(VarIndex_z)
    660 %             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable   
    661 %             if length(DimIndex_z)==1 & nbdim==3 %dimension variable
     686%             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable   
     687%             if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable
    662688%                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
    663689%                 ind_z=find(DimIndex==DimIndex_z(1));
     
    669695end
    670696
    671 % select the variable  index (or indices) for ordinate
     697% select the TimeVariable  index (or indices) for ordinate
    672698ystring=get(handles.ordinate,'String');
    673699yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
     
    701727end
    702728
    703 %select the variable index for the abscissa
     729%select the TimeVariable index for the abscissa
    704730xstring=get(handles.abscissa,'String');
    705731xindex=get(handles.abscissa,'Value');
     
    801827function RUN_Callback(hObject, eventdata, handles)
    802828%---------------------------------------------------------
    803 figcell=get(handles.list_fig,'String');
    804 index=get(handles.list_fig,'value');
    805 figstring=figcell{index};
     829set(handles.RUN,'BackgroundColor',[1 1 0])% mark use of RUN action
     830test_fig=get(handles.SelectFigure,'Value');
    806831
    807832% plot requested in uvmat
    808 if isequal(figstring,'uvmat')
     833if ~test_fig
    809834    inputfile=get(handles.inputfile,'String');
    810835    huvmat=findobj(allchild(0),'tag','uvmat');
     
    814839        set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases)
    815840        hhuvmat=guidata(huvmat);
     841        set(hhuvmat.Fields,'Value',1)
     842        set(hhuvmat.Fields,'String',{'get_field...'})
    816843        uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat
    817844    end
    818845   
    819846% other kind of plot
    820 else
     847else  %TODO: check and update: add plot on an existing axes
     848    figcell=get(handles.list_fig,'String');
     849    index=get(handles.list_fig,'value');
     850    figstring=figcell{index};
    821851    index=get(handles.ACTION,'Value');
    822852    list_func=get(handles.ACTION,'UserData');
     
    824854    set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
    825855    drawnow
    826     SubField=h_fun(handles.figure1);%handles.figure1 =handles of the GUI get_field
     856    SubField=h_fun(handles.get_field);%handles.figure1 =handles of the GUI get_field
    827857    if ~isempty(SubField)
    828858        plot_get_field(SubField,handles)
     
    869899% % handles    structure with handles and user data (see GUIDATA)
    870900%
    871 % %time plots
     901% %timename plots
    872902% leg={};
    873903% n=0;
     
    10421072Tabcell=[];
    10431073hselect_field=get(handles.variables,'parent');
    1044 Field=get(hselect_field,'UserData');
     1074Field=get(handles.get_field,'UserData');
    10451075index=get(handles.variables,'Value');%index in the list 'variables'
    10461076if isequal(index,1)
    10471077    set(handles.attributes_txt,'String','global attributes')
    1048 % list global attribute names and values if index=1 (blank variable display) is selected
     1078% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
    10491079    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
    10501080        for iline=1:length(Field.ListGlobalAttribute)
     
    10621092    end
    10631093else
    1064 %list attribute names and values associated to the variable # injdex-1   
     1094%list TimeAttribute names and values associated to the TimeVariable # injdex-1   
    10651095    list_var=get(handles.variables,'String');
    10661096    var_select=list_var{index};
     
    11151145        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
    11161146    end
    1117     Tabchar=cell2tab(Tabdim,'=');
     1147    Tabchar=cell2tab(Tabdim,' = ');
    11181148    Tabchar=[{''} ;Tabchar];
     1149    set(handles.dimensions,'Value',1)
    11191150    set(handles.dimensions,'String',Tabchar) 
    11201151end 
     
    11531184end
    11541185
    1155 %------------------------------------------------------------------------
    1156 function mouse_up_gui(ggg,eventdata,handles)
    1157 %------------------------------------------------------------------------
    1158 if isequal(get(ggg,'SelectionType'),'alt')
    1159     message=''; 
    1160     global CurData
    1161     inputfield=get(handles.inputfile,'String');
    1162     if exist(inputfield,'file')
    1163         CurData=nc2struct(inputfield);
    1164     else
    1165         CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
    1166     end
    1167   %%%% TODO: put the matalb command window in front
    1168     evalin('base','global CurData')%make CurData global in the workspace
    1169     evalin('base','CurData') %display CurData in the workspace
    1170 end
     1186% %------------------------------------------------------------------------
     1187% function mouse_up_gui(ggg,eventdata,handles)
     1188% %------------------------------------------------------------------------
     1189% if isequal(get(ggg,'SelectionType'),'alt')
     1190%     message=''; 
     1191%     global CurData
     1192%     inputfield=get(handles.inputfile,'String');
     1193%     if exist(inputfield,'file')
     1194%         CurData=nc2struct(inputfield);
     1195%     else
     1196%         CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
     1197%     end
     1198%   %%%% TODO: put the matalb command window in front
     1199%     evalin('base','global CurData')%make CurData global in the workspace
     1200%     evalin('base','CurData') %display CurData in the workspace
     1201% end
    11711202
    11721203%------------------------------------------------------------------------
     
    14141445%global inputfile
    14151446fileinput=[PathName FileName];%complete file name
    1416 testblank=findstr(fileinput,' ');%look for blanks
    1417 if ~isempty(testblank)
    1418     msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
    1419     return
    1420 end
    14211447sizf=size(fileinput);
    1422 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
     1448if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
    14231449set(handles.inputfile,'String',fileinput)
    14241450inputfile_Callback(hObject, eventdata, handles)
    1425 
    14261451
    14271452%update list of recent files in the menubar
     
    14641489inputfile_Callback(hObject, eventdata, handles)
    14651490
    1466 % --------------------------------------------------------------------
     1491% -----------------------------------------------------------------------
    14671492function MenuFile_3_Callback(hObject, eventdata, handles)
     1493% -----------------------------------------------------------------------
    14681494fileinput=get(handles.MenuFile_3,'Label');
    14691495set(handles.inputfile,'String',fileinput)
    14701496inputfile_Callback(hObject, eventdata, handles)
    14711497
    1472 % --------------------------------------------------------------------
     1498% -----------------------------------------------------------------------
    14731499function MenuFile_4_Callback(hObject, eventdata, handles)
     1500% -----------------------------------------------------------------------
    14741501fileinput=get(handles.MenuFile_4,'Label');
    14751502set(handles.inputfile,'String',fileinput)
    14761503inputfile_Callback(hObject, eventdata, handles)
    14771504
    1478 % --------------------------------------------------------------------
     1505% -----------------------------------------------------------------------
    14791506function MenuFile_5_Callback(hObject, eventdata, handles)
     1507% -----------------------------------------------------------------------
    14801508fileinput=get(handles.MenuFile_5,'Label');
    14811509set(handles.inputfile,'String',fileinput)
    14821510inputfile_Callback(hObject, eventdata, handles)
    14831511
    1484 % --------------------------------------------------------------------
     1512%------------------------------------------------------------------------
    14851513function MenuExportField_Callback(hObject, eventdata, handles)
     1514%------------------------------------------------------------------------
    14861515global Data_get_field
    14871516% huvmat=findobj(allchild(0),'Name','uvmat');
     
    14941523commandwindow;
    14951524
    1496 % --------------------------------------------------------------------
     1525%------------------------------------------------------------------------
    14971526function MenuHelp_Callback(hObject, eventdata, handles)
    1498 % hObject    handle to MenuHelp (see GCBO)
    1499 % eventdata  reserved - to be defined in a future version of MATLAB
    1500 % handles    structure with handles and user data (see GUIDATA)
     1527%------------------------------------------------------------------------
    15011528path_to_uvmat=which ('uvmat');% check the path of uvmat
    15021529pathelp=fileparts(path_to_uvmat);
     
    15071534end
    15081535
     1536% -----------------------------------------------------------------------
     1537function TimeName_Callback(hObject, eventdata, handles)
     1538
     1539scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates
     1540vector_x_Callback(hObject, eventdata, handles)
     1541
     1542%------------------------------------------------------------------------
     1543% --- Executes on button press in TimeAttribute.
     1544function TimeAttribute_Callback(hObject, eventdata, handles)
     1545%------------------------------------------------------------------------
     1546val=get(handles.TimeAttribute,'Value');
     1547if val
     1548    set(handles.TimeAttributeMenu,'Visible','on')
     1549    Field=get(handles.get_field,'UserData');
     1550    time_value=zeros(size(Field.ListGlobalAttribute));
     1551    test_time=zeros(size(Field.ListGlobalAttribute));
     1552    for ilist=1:numel(Field.ListGlobalAttribute)
     1553        if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}]))
     1554            eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';'])
     1555            if ~isempty(time_val)
     1556                time_value(ilist)=time_val;
     1557                test_time(ilist)=1;
     1558            end
     1559        end
     1560    end
     1561    ListTimeAttribute=Field.ListGlobalAttribute(test_time==1);
     1562    attr_index=get(handles.TimeAttributeMenu,'Value');
     1563    if attr_index>numel(ListTimeAttribute)
     1564        attr_index=1;
     1565        set(handles.TimeAttributeMenu,'Value',1);
     1566    end
     1567    if isempty(ListTimeAttribute)
     1568        set(handles.TimeAttributeMenu,'String',{''})
     1569        set(handles.TimeValue,'Visible','off')
     1570    else
     1571        set(handles.TimeValue,'Visible','on')
     1572        set(handles.TimeAttributeMenu,'String',ListTimeAttribute)
     1573        set(handles.TimeValue,'String',num2str(time_value(attr_index)))
     1574    end
     1575    set(handles.TimeDimension,'Value',0)
     1576    TimeDimension_Callback(hObject, eventdata, handles)
     1577    set(handles.TimeVariable,'Value',0)
     1578    TimeVariable_Callback(hObject, eventdata, handles)
     1579else
     1580    set(handles.TimeAttributeMenu,'Visible','off')
     1581    set(handles.TimeValue,'Visible','off')
     1582end
     1583
     1584%------------------------------------------------------------------------
     1585% --- Executes on selection change in TimeAttributeMenu.
     1586function TimeAttributeMenu_Callback(hObject, eventdata, handles)
     1587 ListTimeAttribute=get(handles.TimeAttributeMenu,'String');
     1588 index=get(handles.TimeAttributeMenu,'Value');
     1589 AttrName=ListTimeAttribute{index};
     1590 Field=get(handles.get_field,'UserData');
     1591 eval(['time_val=Field.' AttrName ';'])
     1592 set(handles.TimeValue,'String',num2str(time_val))
     1593%------------------------------------------------------------------------
     1594
     1595%------------------------------------------------------------------------
     1596% --- Executes on button press in TimeVariable.
     1597function TimeDimension_Callback(hObject, eventdata, handles)
     1598%------------------------------------------------------------------------
     1599val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected
     1600if val  %if check box TimeDimension is selected
     1601    Field=get(handles.get_field,'UserData');% structure describing the currently opened field
     1602    previous_menu=get(handles.TimeDimensionMenu,'String');
     1603    if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu
     1604        ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time'
     1605        if isempty(ind_select)
     1606            ind_select=1;% select the first item in the list if 'time' is not found
     1607        end
     1608        set(handles.TimeDimensionMenu,'Value',ind_select);
     1609        set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu
     1610    end   
     1611    set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible
     1612    set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible
     1613    TimeDimensionMenu_Callback(hObject, eventdata, handles) 
     1614    set(handles.TimeAttribute,'Value',0) %deselect alternative options for time
     1615    set(handles.TimeVariable,'Value',0)
     1616    TimeAttribute_Callback(hObject, eventdata, handles)
     1617else
     1618    set(handles.TimeDimensionMenu,'Visible','off')
     1619    set(handles.TimeIndexValue,'Visible','off')
     1620end
     1621
     1622%------------------------------------------------------------------------
     1623% --- Executes on selection change in TimeDimensionMenu.
     1624function TimeDimensionMenu_Callback(hObject, eventdata, handles)
     1625%------------------------------------------------------------------------
     1626index=get(handles.TimeDimensionMenu,'Value');
     1627DimList=get(handles.TimeDimensionMenu,'String');
     1628DimName=DimList{index};
     1629Field=get(handles.get_field,'UserData');
     1630DimIndex=find(strcmp(DimName,Field.ListDimName),1);
     1631ref_index=round(Field.DimValue(DimIndex)/2);   
     1632set(handles.TimeIndexValue,'String',num2str(ref_index))
     1633scalar_Callback(hObject, eventdata, handles)
     1634vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
     1635 % look for a corresponding time variable and value
     1636 time_test=zeros(size(Field.VarDimName));
     1637 for ilist=1:numel(Field.VarDimName)
     1638     if isequal(Field.VarDimName{ilist},{DimName})
     1639         time_test(ilist)=1;
     1640     end
     1641 end
     1642 ListVariable=Field.ListVarName(time_test==1);
     1643 set(handles.TimeVariableMenu,'Value',1)
     1644 if isempty(ListVariable)     
     1645     set(handles.TimeVariableMenu,'String',{''})
     1646     set(handles.TimeVarValue,'String','')
     1647 else
     1648    set(handles.TimeVariableMenu,'String',ListVariable)
     1649    TimeVarName=ListVariable{1};
     1650    VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
     1651    inputfile=get(handles.inputfile,'String');% read the input file
     1652    SubField=nc2struct(inputfile,{TimeVarName});
     1653    eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
     1654    set(handles.TimeVarValue,'Visible','on')
     1655    set(handles.TimeVariableMenu,'Visible','on')
     1656    set(handles.TimeVarValue,'String',num2str(TimeValue))
     1657 end
     1658
     1659
     1660% % -----------------------------------------------------------------------
     1661% % --- Executes on button press in TimeVariable.
     1662% function TimeVariable_Callback(hObject, eventdata, handles)
     1663% % -----------------------------------------------------------------------
     1664% val=get(handles.TimeVariable,'Value');
     1665% if val
     1666%     Field=get(handles.get_field,'UserData');
     1667%     time_test=zeros(size(Field.VarDimName));
     1668%     for ilist=1:numel(Field.VarDimName)
     1669%         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
     1670%             time_test(ilist)=1;
     1671%         end
     1672%     end
     1673%     ind_test=find(time_test);
     1674%     if isempty(time_test)
     1675%         set(handles.TimeVariable,'Value',0)
     1676%         set(handles.TimeVariableMenu,'Visible','off')
     1677%         set(handles.TimeVarValue,'Visible','off')
     1678%     else
     1679%         set(handles.TimeVariableMenu,'Visible','on')
     1680%         set(handles.TimeVarValue,'Visible','on')
     1681%         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
     1682%             set(handles.TimeVariableMenu,'Value',1)
     1683%         end
     1684%         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
     1685%         TimeVariableMenu_Callback(hObject, eventdata, handles)
     1686%         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
     1687%         set(handles.TimeAttribute,'Value',0)
     1688%         TimeAttribute_Callback(hObject, eventdata, handles)
     1689%     end
     1690% else
     1691%     set(handles.TimeVariableMenu,'Visible','off')
     1692%     set(handles.TimeVarValue,'Visible','off')
     1693% end
     1694
     1695% -----------------------------------------------------------------------
     1696% --- Executes on selection change in TimeVariableMenu.
     1697function TimeVariableMenu_Callback(hObject, eventdata, handles)
     1698% -----------------------------------------------------------------------
     1699ListVar=get(handles.TimeVariableMenu,'String');
     1700index=get(handles.TimeVariableMenu,'Value');
     1701TimeVariable=ListVar{index};% name of the selected variable
     1702if isempty(TimeVariable)% case of blank selection
     1703    return
     1704end
     1705Field=get(handles.get_field,'UserData'); %index of
     1706VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
     1707DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
     1708set(handles.TimeDimensionMenu,'Value',1)
     1709set(handles.TimeDimensionMenu,'String',DimName)
     1710inputfile=get(handles.inputfile,'String');% read the input file
     1711SubField=nc2struct(inputfile,{TimeVariable});
     1712eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
     1713ref_index=round(TimeDimension/2);
     1714eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
     1715set(handles.TimeIndexValue,'String',num2str(ref_index))
     1716set(handles.TimeVarValue,'String',num2str(TimeValue))
     1717
     1718
     1719function TimeValue_Callback(hObject, eventdata, handles)
     1720%TO suppress
     1721
     1722% -----------------------------------------------------------------------
     1723function TimeIndexValue_Callback(hObject, eventdata, handles)
     1724% -----------------------------------------------------------------------
     1725TimeIndex=str2double(get(handles.TimeIndexValue,'String'));
     1726TimeVarName=Field.ListVarName{time_index};
     1727set(handles.TimeVariable,'Value',1)
     1728set(handles.TimeName,'String',TimeVarName)
     1729fileinput=get(handles.inputfile,'String');
     1730SubField=nc2struct(fileinput,{TimeVarName});
     1731eval(['TimeValue=SubField.' TimeVarName '(ref_index);']);
     1732set(handles.TimeValue,'Visible','on')
     1733set(handles.TimeValue,'String',num2str(TimeValue))
     1734
     1735% -----------------------------------------------------------------------
     1736function SelectFigure_Callback(hObject, eventdata, handles)
     1737% -----------------------------------------------------------------------
     1738val=get(handles.SelectFigure,'Value');
     1739if val
     1740    set(handles.list_fig,'Visible','on')
     1741    %% look at the existing figures in the work space
     1742    browse_fig(handles.list_fig)
     1743else
     1744   set(handles.list_fig,'Visible','off')
     1745end
     1746
     1747
     1748function TimeVarValue_Callback(hObject, eventdata, handles)
     1749
     1750
     1751
     1752% --- Executes on button press in check_rgb.
     1753function check_rgb_Callback(hObject, eventdata, handles)
     1754
     1755
     1756
Note: See TracChangeset for help on using the changeset viewer.