Changeset 646 for trunk/src/get_field.m


Ignore:
Timestamp:
Jun 2, 2013, 4:00:34 PM (8 years ago)
Author:
sommeria
Message:

various update, bugs to be expected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/get_field.m

    r644 r646  
    2222function varargout = get_field(varargin)
    2323
    24 % Last Modified by GUIDE v2.5 28-May-2013 01:55:25
     24% Last Modified by GUIDE v2.5 02-Jun-2013 14:00:39
    2525
    2626% Begin initialization code - DO NOT EDIT
     
    7575set(hObject,'Unit','pixel')
    7676pos_view_field=get(hObject,'Position');
     77set(0,'Unit','pixels')
    7778ScreenSize=get(0,'ScreenSize');
    7879pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
     
    106107set(handles.variables,'String',[{'*'} Txt])
    107108variables_Callback(handles.variables,[], handles)
    108 
    109 % set(handles.abscissa,'String',[{''} Txt ])
    110109set(handles.ordinate,'String',Txt)
    111 set(handles.vector_x,'String',[Txt ])
    112 set(handles.vector_y,'String',[Txt ])
     110set(handles.vector_x,'String',Txt)
     111set(handles.vector_y,'String',Txt )
    113112set(handles.vector_z,'String',[{''} Txt ])
    114113set(handles.vec_color,'String',[{''} Txt ])
    115 set(handles.XVarName,'String',[{''} Txt ])
    116 set(handles.YVarName,'String',[{''} Txt ])
    117 set(handles.ZVarName,'String',[{''} Txt ])
    118 % set(handles.coord_x_vectors,'String',[{''} Txt ])
    119 % set(handles.coord_y_vectors,'String',[{''} Txt ])
    120 % set(handles.YVarName,'String',[{''} Txt ])
    121 % set(handles.TimeVarName,'String',[{''} Txt ])
     114set(handles.XVarName,'String',Txt )
     115set(handles.YVarName,'String',Txt )
     116set(handles.ZVarName,'String',Txt )
    122117set(handles.scalar,'Value',1)
    123118set(handles.scalar,'String', Txt )
    124119
    125 %% ananlyse the input field cells
     120%% analyse the input field cells
    126121[CellInfo,NbDim,errormsg]=find_field_cells(Field);
    127122if ~isempty(errormsg) 
     
    162157
    163158%% set time mode
    164 ListSwitchVarIndexTime={'file index'};
     159ListSwitchVarIndexTime={'file index'};% default setting: the time is the file index
    165160% look at global attributes with numerical values
    166161check_numvalue=false;
    167162check_time=false;
    168     for ilist=1:numel(Field.ListGlobalAttribute)
    169         Value=Field.(Field.ListGlobalAttribute{ilist});
    170         check_numvalue(ilist)=isnumeric(Value);
    171         check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1));
    172     end 
     163for ilist=1:numel(Field.ListGlobalAttribute)
     164    Value=Field.(Field.ListGlobalAttribute{ilist});
     165    check_numvalue(ilist)=isnumeric(Value);
     166    check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1));
     167end
    173168Field.ListNumAttributes=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
    174169if ~isempty(Field.ListNumAttributes)
    175 ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];
     170    ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];% the time can be chosen as a global attribute
    176171end
    177172nboption=numel(ListSwitchVarIndexTime);
    178173if Field.MaxDim>=2
    179     ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];
    180 end
    181 if Field.MaxDim>=4
    182         option=nboption+1;
     174    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];% the time can be chosen as a dim index
     175end
     176if Field.MaxDim>=4% for dim >=4, one dim is proposed as time
     177    option=nboption+1;
    183178elseif ~isempty(find(check_time, 1))
    184179    option=2;
     
    186181    option=1;
    187182end
    188 %set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
    189 %set(handles.SwitchVarIndexTime,'Value',option)
     183set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
     184set(handles.SwitchVarIndexTime,'Value',option)
    190185set(handles.get_field,'UserData',Field);% record the finput field structure
    191 %SwitchVarIndexTime_Callback([],[], handles)
     186SwitchVarIndexTime_Callback([],[], handles)
    192187
    193188%% set z coordinate menu if relevant
     
    207202%% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields
    208203if Field.MaxDim>=2 % case of 2D (or 3D) fields
     204    if isfield(CellInfo{imax},'VarIndex_coord_x')&&  isfield(CellInfo{imax},'VarIndex_coord_y')
     205        set(handles.XVarName,'Value',CellInfo{imax}.VarIndex_coord_x(1))
     206        set(handles.YVarName,'Value',CellInfo{imax}.VarIndex_coord_y(1))
     207    end
    209208    if isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
    210         set(handles.CheckVector,'Value',1)
    211         set(handles.CheckScalar,'Value',0)
     209        set(handles.FieldOption,'Value',3)% set vector selection option
    212210        set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1))
    213211        set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1))
     
    354352    end
    355353end
    356 val=get(handles.abscissa,'Value');
    357 set(handles.abscissa,'Value',min(val,2));
     354%val=get(handles.abscissa,'Value');
     355%set(handles.abscissa,'Value',min(val,2));
    358356coord_x_index=CellInfo{cell_select}.VarIndex_coord_x;
    359357coord_x_index=coord_x_index(coord_x_index~=0);
    360 set(handles.XVarName,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
     358%set(handles.XVarName,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
     359set(handles.XVarName,'String',[(Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
    361360
    362361%------------------------------------------------------------------------
     
    395394%eliminate time
    396395TimeDimName='';%default
     396
    397397% SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
    398398% TimeVarOption=SwitchVarIndexTime{get(handles.SwitchVarIndexTime,'Value')};
    399 if strcmp(TimeVarOption,'variable')
    400     List=get(handles.TimeVarName,'String');
     399List=get(handles.TimeVarName,'String');
     400if get(handles.CheckDimensionTime)
     401         TimeDimName=List{get(handles.TimeVarName,'Value')};
     402elseif ~get(handles.CheckAttributeTime)
    401403    TimeVarName=List{get(handles.TimeVarName,'Value')};
    402 elseif  strcmp(TimeVarOption,'dim index')
    403     List=get(handles.TimeVarName,'String');
    404     TimeDimName=List{get(handles.TimeVarName,'Value')};
    405404end
    406405% A completer
     
    10381037end
    10391038
    1040 % --------------------------------------------------------------------
    1041 function MenuOpen_Callback(hObject, eventdata, handles)
    1042 % hObject    handle to MenuOpen (see GCBO)
    1043 % eventdata  reserved - to be defined in a future version of MATLAB
    1044 % handles    structure with handles and user data (see GUIDATA)
    1045 
    1046 
    1047 % --------------------------------------------------------------------
    1048 function MenuExport_Callback(hObject, eventdata, handles)
    1049 % hObject    handle to MenuExport (see GCBO)
    1050 % eventdata  reserved - to be defined in a future version of MATLAB
    1051 % handles    structure with handles and user data (see GUIDATA)
    1052 
    1053 
    1054 % --------------------------------------------------------------------
    1055 function MenuBrowse_Callback(hObject, eventdata, handles)
    1056 
    1057 oldfile=get(handles.inputfile,'String');
    1058 testrootfile=0;
    1059 testsubdir=0;
    1060 if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
    1061         oldfile='';
    1062         dir_perso=prefdir;
    1063          profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    1064          if exist(profil_perso,'file')
    1065               h=load (profil_perso);
    1066              if isfield(h,'RootPath')
    1067                   RootPath=h.RootPath;
    1068              end
    1069              if isfield(h,'SubDir')
    1070                   SubDir=h.SubDir;
    1071                   if ~isempty(SubDir)
    1072                     testsubdir=1;
    1073                   end
    1074              end
    1075              if isfield(h,'RootFile')
    1076                   RootFile=h.RootFile;
    1077                   if ~isempty(RootFile)
    1078                     testrootfile=1;
    1079                   end
    1080              end
    1081          end
    1082 end
    1083 if testrootfile
    1084     if ~testsubdir
    1085         oldfile=fullfile(RootPath,RootFile);
    1086     else
    1087         oldfile=fullfile(RootPath,SubDir,RootFile);
    1088     end
    1089 end
    1090 [FileName, PathName] = uigetfile( ...
    1091        {'*.nc', ' *.nc';...
    1092        '*.cdf', ' *.cdf';...
    1093         '*.*',  'All Files (*.*)'}, ...
    1094         'Pick a file',oldfile);
    1095 
    1096 %global inputfile
    1097 fileinput=[PathName FileName];%complete file name
    1098 sizf=size(fileinput);
    1099 if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
    1100 set(handles.inputfile,'String',fileinput)
    1101 inputfile_Callback(hObject, eventdata, handles)
    1102 
    1103 %update list of recent files in the menubar
    1104 MenuFile_1=fileinput;
    1105 MenuFile_2=get(handles.MenuFile_1,'Label');
    1106 MenuFile_3=get(handles.MenuFile_2,'Label');
    1107 MenuFile_4=get(handles.MenuFile_3,'Label');
    1108 MenuFile_5=get(handles.MenuFile_4,'Label');
    1109 set(handles.MenuFile_1,'Label',MenuFile_1)
    1110 set(handles.MenuFile_2,'Label',MenuFile_2)
    1111 set(handles.MenuFile_3,'Label',MenuFile_3)
    1112 set(handles.MenuFile_4,'Label',MenuFile_4)
    1113 set(handles.MenuFile_5,'Label',MenuFile_5)
    1114 dir_perso=prefdir;
    1115 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    1116 display(profil_perso)
    1117 if exist(profil_perso,'file')
    1118     save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
    1119 else
    1120     txt=ver('MATLAB');
    1121     Release=txt.Release;
    1122     relnumb=str2double(Release(3:4));
    1123     if relnumb >= 14
    1124         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
    1125     else
    1126         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
    1127     end
    1128 end
    1129 
    1130 % --------------------------------------------------------------------
    1131 function MenuFile_1_Callback(hObject, eventdata, handles)
    1132 fileinput=get(handles.MenuFile_1,'Label');
    1133 set(handles.inputfile,'String',fileinput)
    1134 inputfile_Callback(hObject, eventdata, handles)
    1135 
    1136 % --------------------------------------------------------------------
    1137 function MenuFile_2_Callback(hObject, eventdata, handles)
    1138 fileinput=get(handles.MenuFile_2,'Label');
    1139 set(handles.inputfile,'String',fileinput)
    1140 inputfile_Callback(hObject, eventdata, handles)
    1141 
    1142 % -----------------------------------------------------------------------
    1143 function MenuFile_3_Callback(hObject, eventdata, handles)
    1144 % -----------------------------------------------------------------------
    1145 fileinput=get(handles.MenuFile_3,'Label');
    1146 set(handles.inputfile,'String',fileinput)
    1147 inputfile_Callback(hObject, eventdata, handles)
    1148 
    1149 % -----------------------------------------------------------------------
    1150 function MenuFile_4_Callback(hObject, eventdata, handles)
    1151 % -----------------------------------------------------------------------
    1152 fileinput=get(handles.MenuFile_4,'Label');
    1153 set(handles.inputfile,'String',fileinput)
    1154 inputfile_Callback(hObject, eventdata, handles)
    1155 
    1156 % -----------------------------------------------------------------------
    1157 function MenuFile_5_Callback(hObject, eventdata, handles)
    1158 % -----------------------------------------------------------------------
    1159 fileinput=get(handles.MenuFile_5,'Label');
    1160 set(handles.inputfile,'String',fileinput)
    1161 inputfile_Callback(hObject, eventdata, handles)
    1162 
    1163 %------------------------------------------------------------------------
    1164 function MenuExportField_Callback(hObject, eventdata, handles)
    1165 %------------------------------------------------------------------------
    1166 global Data_get_field
    1167 % huvmat=findobj(allchild(0),'Name','uvmat');
    1168 inputfile=get(handles.inputfile,'String');
    1169 Data_get_field=nc2struct(inputfile);
    1170 % Data_view_field=UvData.ProjField_2;
    1171 evalin('base','global Data_get_field')%make CurData global in the workspace
    1172 display(['content of ' inputfile ':'])
    1173 evalin('base','Data_get_field') %display CurData in the workspace
    1174 commandwindow;
    1175 
    1176 %------------------------------------------------------------------------
    1177 function MenuHelp_Callback(hObject, eventdata, handles)
    1178 %------------------------------------------------------------------------
    1179 path_to_uvmat=which ('uvmat');% check the path of uvmat
    1180 pathelp=fileparts(path_to_uvmat);
    1181 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
    1182 if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
    1183 else
    1184 web([helpfile '#get_field'])   
    1185 end
    11861039
    11871040% -----------------------------------------------------------------------
     
    13841237
    13851238
    1386 
     1239%------------------------------------------------------------------------
    13871240% --- Executes on selection change in SwitchVarIndexX.
     1241%------------------------------------------------------------------------
    13881242function SwitchVarIndexX_Callback(hObject, eventdata, handles)
    1389 % hObject    handle to SwitchVarIndexX (see GCBO)
    1390 % eventdata  reserved - to be defined in a future version of MATLAB
    1391 % handles    structure with handles and user data (see GUIDATA)
    1392 
    1393 % Hints: contents = cellstr(get(hObject,'String')) returns SwitchVarIndexX contents as cell array
    1394 %        contents{get(hObject,'Value')} returns selected item from SwitchVarIndexX
    1395 
    1396 
     1243
     1244%------------------------------------------------------------------------
    13971245% --- Executes on selection change in SwitchVarIndexTime.
     1246%------------------------------------------------------------------------
    13981247function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
     1248
    13991249menu=get(handles.SwitchVarIndexTime,'String');
    14001250option=menu{get(handles.SwitchVarIndexTime,'Value')};
     
    14531303switch FieldOption
    14541304    case '1D plot'
    1455          set(handles.Panel1Dplot,'Visible','on')
    1456          pos=get(handles.Panel1Dplot,'Position');
    1457          pos(1)=2;
    1458          pos_coord=get(handles.Coordinates,'Position');
    1459          pos(2)=pos_coord(2)-pos(4)-2;
    1460          set(handles.Panel1Dplot,'Position',pos)
    1461     set(handles.PanelScalar,'Visible','off')
    1462     set(handles.PanelVectors,'Visible','off')
    1463     set(handles.YVarName,'Visible','off')
    1464 %    set(handles.SwitchVarIndexY,'Visible','off')
    1465     set(handles.Y_title,'Visible','off')
    1466     set(handles.ZVarName,'Visible','off')
    1467  %   set(handles.SwitchVarIndexZ,'Visible','off')
    1468     set(handles.Z_title,'Visible','off')
    1469 %    ordinate_Callback(hObject, eventdata, handles)
    1470 %         set(handles.get_field,'Units','pixels')
    1471 % size_fig=get(handles.get_field,'Position');
    1472 % Data=get(handles.view_field,'UserData');
    1473 % Data.GUISize=size_fig;
    1474 % set(handles.view_field,'UserData',Data)
    1475 %
    1476 % %% reset position of text_display or TableDisplay
    1477 % if strcmp(get(handles.TableDisplay,'Visible'),'off')
    1478 %     pos_1=get(handles.text_display,'Position');
    1479 %     pos_1(1)=size_fig(3)-pos_1(3);
    1480 %     pos_1(2)=size_fig(4)-pos_1(4);
    1481 %     set(handles.text_display,'Position',pos_1)
    1482 %     % reset position of TableDisplay
    1483 % else
    1484 %     pos_1=get(handles.TableDisplay,'Position');
    1485 %     pos_1(1)=size_fig(3)-pos_1(3);
    1486 %     pos_1(2)=size_fig(4)-pos_1(4);
    1487 %     set(handles.TableDisplay,'Position',pos_1)
    1488 % end
    1489 %
    1490 % %% reset position of Coordinates
    1491 % pos_2=get(handles.Coordinates,'Position');
    1492 % pos_2(1)=size_fig(3)-pos_1(3);
    1493 % pos_2(2)=pos_1(2)-pos_2(4);
    1494 % set(handles.Coordinates,'Position',pos_2)
     1305        set(handles.Panel1Dplot,'Visible','on')
     1306        pos=get(handles.Panel1Dplot,'Position');
     1307        pos(1)=2;
     1308        pos_coord=get(handles.Coordinates,'Position');
     1309        pos(2)=pos_coord(2)-pos(4)-2;
     1310        set(handles.Panel1Dplot,'Position',pos)
     1311        set(handles.PanelScalar,'Visible','off')
     1312        set(handles.PanelVectors,'Visible','off')
     1313        set(handles.YVarName,'Visible','off')
     1314        %    set(handles.SwitchVarIndexY,'Visible','off')
     1315        set(handles.Y_title,'Visible','off')
     1316        set(handles.ZVarName,'Visible','off')
     1317        %   set(handles.SwitchVarIndexZ,'Visible','off')
     1318        set(handles.Z_title,'Visible','off')
    14951319    case 'scalar'
    14961320        set(handles.Panel1Dplot,'Visible','off')
    1497     set(handles.PanelScalar,'Visible','on')
    1498     set(handles.PanelVectors,'Visible','off')
    1499          pos=get(handles.PanelScalar,'Position');
    1500          pos(1)=2;
    1501          pos_coord=get(handles.Coordinates,'Position');
    1502          pos(2)=pos_coord(2)-pos(4)-2;
    1503          set(handles.PanelScalar,'Position',pos)
    1504     set(handles.YVarName,'Visible','on')
    1505     set(handles.Y_title,'Visible','on')
     1321        set(handles.PanelScalar,'Visible','on')
     1322        set(handles.PanelVectors,'Visible','off')
     1323        pos=get(handles.PanelScalar,'Position');
     1324        pos(1)=2;
     1325        pos_coord=get(handles.Coordinates,'Position');
     1326        pos(2)=pos_coord(2)-pos(4)-2;
     1327        set(handles.PanelScalar,'Position',pos)
     1328        set(handles.YVarName,'Visible','on')
     1329        set(handles.Y_title,'Visible','on')
    15061330    case 'vectors'
    15071331        set(handles.Panel1Dplot,'Visible','off')
    1508     set(handles.PanelScalar,'Visible','off')
    1509     set(handles.PanelVectors,'Visible','on')
    1510     pos=get(handles.PanelVectors,'Position');
    1511          pos(1)=2;
    1512          pos_coord=get(handles.Coordinates,'Position');
    1513          pos(2)=pos_coord(2)-pos(4)-2;
    1514          set(handles.PanelVectors,'Position',pos)
    1515     set(handles.YVarName,'Visible','on')
    1516     set(handles.Y_title,'Visible','on')
    1517 end
    1518 % hObject    handle to FieldOption (see GCBO)
    1519 % eventdata  reserved - to be defined in a future version of MATLAB
    1520 % handles    structure with handles and user data (see GUIDATA)
    1521 
    1522 % Hints: contents = get(hObject,'String') returns FieldOption contents as cell array
    1523 %        contents{get(hObject,'Value')} returns selected item from FieldOption
    1524 
    1525 
    1526 % --- Executes on button press in CheckDimensionX.
    1527 function CheckDimensionX_Callback(hObject, eventdata, handles)
    1528 % hObject    handle to CheckDimensionX (see GCBO)
    1529 % eventdata  reserved - to be defined in a future version of MATLAB
    1530 % handles    structure with handles and user data (see GUIDATA)
    1531 
    1532 % Hint: get(hObject,'Value') returns toggle state of CheckDimensionX
    1533 
    1534 
    1535 % --- Executes on button press in checkbox25.
    1536 function checkbox25_Callback(hObject, eventdata, handles)
    1537 % hObject    handle to checkbox25 (see GCBO)
    1538 % eventdata  reserved - to be defined in a future version of MATLAB
    1539 % handles    structure with handles and user data (see GUIDATA)
    1540 
    1541 % Hint: get(hObject,'Value') returns toggle state of checkbox25
    1542 
    1543 
    1544 % --- Executes on button press in checkbox26.
    1545 function checkbox26_Callback(hObject, eventdata, handles)
    1546 % hObject    handle to checkbox26 (see GCBO)
    1547 % eventdata  reserved - to be defined in a future version of MATLAB
    1548 % handles    structure with handles and user data (see GUIDATA)
    1549 
    1550 % Hint: get(hObject,'Value') returns toggle state of checkbox26
    1551 
    1552 
    1553 % --- Executes on button press in checkbox27.
    1554 function checkbox27_Callback(hObject, eventdata, handles)
    1555 % hObject    handle to checkbox27 (see GCBO)
    1556 % eventdata  reserved - to be defined in a future version of MATLAB
    1557 % handles    structure with handles and user data (see GUIDATA)
    1558 
    1559 % Hint: get(hObject,'Value') returns toggle state of checkbox27
    1560 
    1561 
    1562 % --- Executes on button press in checkbox29.
    1563 function checkbox29_Callback(hObject, eventdata, handles)
    1564 % hObject    handle to checkbox29 (see GCBO)
    1565 % eventdata  reserved - to be defined in a future version of MATLAB
    1566 % handles    structure with handles and user data (see GUIDATA)
    1567 
    1568 % Hint: get(hObject,'Value') returns toggle state of checkbox29
     1332        set(handles.PanelScalar,'Visible','off')
     1333        set(handles.PanelVectors,'Visible','on')
     1334        pos=get(handles.PanelVectors,'Position');
     1335        pos(1)=2;
     1336        pos_coord=get(handles.Coordinates,'Position');
     1337        pos(2)=pos_coord(2)-pos(4)-2;
     1338        set(handles.PanelVectors,'Position',pos)
     1339        set(handles.YVarName,'Visible','on')
     1340        set(handles.Y_title,'Visible','on')
     1341end
Note: See TracChangeset for help on using the changeset viewer.