Changeset 507


Ignore:
Timestamp:
Jul 29, 2012, 11:18:31 PM (8 years ago)
Author:
sommeria
Message:

various improvments and corrections
dtatatree_browser tested

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/compile_functions.m

    r503 r507  
    11% check
    2 if isempty(which('mcc')
     2if isempty(which('mcc'))
    33    msgbox_uvmat('no Matlab compiler toolbox mcc installed')
    44    return
  • trunk/src/datatree_browser.m

    r503 r507  
    2222function varargout = datatree_browser(varargin)
    2323
    24 % Last Modified by GUIDE v2.5 26-Jul-2012 08:24:26
     24% Last Modified by GUIDE v2.5 29-Jul-2012 08:49:20
    2525
    2626% Begin initialization code - DO NOT EDIT
     
    4545%------------------------------------------------------------------------
    4646% --- Executes just before datatree_browser is made visible.
    47 function datatree_browser_OpeningFcn(hObject, eventdata, handles, projectxml)
     47function datatree_browser_OpeningFcn(hObject, eventdata, handles, InputName)
    4848%------------------------------------------------------------------------
    4949% Choose default command line output for datatree_browser
     
    7474set(hObject, 'Units', OldUnits);
    7575
    76 % % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
    77 % load dialogicons.mat
    78 % eval(['IconData=' icontype 'IconData;'])
    79 % eval(['IconCMap=' icontype 'IconMap;'])
    80 % questIconMap(256,:) = get(handles.figure1, 'Color');
    81 % Img=image(IconData, 'Parent', handles.axes1);
    82 % set(handles.figure1, 'Colormap', IconCMap);
    83 % set(handles.axes1, ...
    84 %     'Visible', 'off', ...
    85 %     'YDir'   , 'reverse'       , ...
    86 %     'XLim'   , get(Img,'XData'), ...
    87 %     'YLim'   , get(Img,'YData')  ...
    88 %     );
    89 % if exist('GeometryCalib','var')
    90 %     DataviewData.GeometryCalib=GeometryCalib;
    91 %     set(hObject,'UserData',DataviewData)
    92 % end
    93 % if exist('SubCampaignTst','var') && isequal(SubCampaignTst,'y')
    94 %    set(handles.SubCampaignTest,'Value',1);
    95 % end
    96 if ~isempty(regexp(projectxml,'.project.xml$'))
    97             if exist(regexprep(projectxml,'.project.xml$','.link'),'dir')
    98                
    99                 set(handles.LinkDir,'String',regexprep(projectxml,'.project.xml$','.link'))
    100                 XmlContent=xml2struct(projectxml);
    101                 set(handles.SourceDir,'String',XmlContent.SourceDir)
    102                 set(handles.UpdateLink,'String','UpdateLink')
    103 %                 datatree_browser(regexprep(fileinput,'.project.xml$','.link'))
    104 
    105         elseif exist(regexprep(projectxml,'.project.xml$',''),'dir')
    106                 set(handles.SourceDir,'String',regexprep(projectxml,'.project.xml$',''))
     76if exist('InputName','var')
     77    if isdir(InputName)% opening by uvmat/MenuSetProject
     78        set(handles.SourceDir,'String',InputName)% the input directory is considered as a project
     79        set(handles.LinkDir,'Visible','off')
     80        set(handles.UpdateLink,'String','create_link')
     81        set(handles.MarkupDir,'Visible','on')
     82
     83    else% opening by uvmat/Open
     84        InputDir=regexprep(InputName,'.xml$','');
     85        if exist(InputDir,'dir')
     86            s=xml2struct(InputName);
     87            if isfield(s,'SourceDir')
     88                set(handles.SourceDir,'String',s.SourceDir)
     89                set(handles.LinkDir,'String',InputDir)
     90                set(handles.LinkDir,'Visible','on')
     91            else
     92                set(handles.SourceDir,'String',InputDir)
    10793                set(handles.LinkDir,'Visible','off')
    108                 set(handles.UpdateLink,'String','CreateLink')
     94                set(handles.MarkupDir,'String','CreateLink')
     95            end
    10996        end
    110     set(handles.OK,'Visible','on')
    111     set(handles.Cancel,'Visible','on')
    112     set(handles.figure,'WindowStyle','modal')% Make% Make the GUI modal
    113     drawnow
    114  uiwait(handles.figure);
    115 end
    116 % if exist('RootDir','var')
    117 %    set(handles.SourceDir,'String',RootDir);
    118 % %    set(handles.clean_civ_cmx,'Visible','off')
    119 %    set(handles.edit_xml,'Visible','off')
    120 %    set(handles.HELP,'Visible','off')
    121 %    set(handles.OK,'Visible','on')
    122 %    set(handles.Cancel,'Visible','on')
    123 %    set(handles.figure,'WindowStyle','modal')% Make% Make the GUI modal
    124 %    set(hObject,'Visible','on')
    125 %    drawnow
    126 %    %RootDirectory_Callback(hObject, eventdata, handles)
    127 %    % UIWAIT makes translate_points wait for user response (see UIRESUME)
    128 %    uiwait(handles.figure);
    129 % end
     97                FillExperiments(handles)
     98        set(handles.OK,'Visible','on')
     99        drawnow
     100       
     101    end
     102end
     103
    130104
    131105%------------------------------------------------------------------------
     
    135109% Get default command line output from handles structure
    136110varargout{1} = handles.output;
    137 %delete(handles.figure)
    138 
    139 %------------------------------------------------------------------------
    140 % --- Executes on button press in UpdateLink.
     111%delete(handles.datatree_browser)
     112
     113%------------------------------------------------------------------------
     114% --- Executes on button press in MarkupDir: create a xml file to mark SourceDir as project source
     115function MarkupDir_Callback(hObject, eventdata, handles)
     116%------------------------------------------------------------------------
     117SourceDir=get(handles.SourceDir,'String');
     118t=xmltree;
     119t=set(t,1,'name','Project');
     120try
     121save(t,[SourceDir '.xml'])
     122catch ME
     123    msgbox_uvmat('ERROR',ME.message)
     124end
     125
     126%------------------------------------------------------------------------
     127% --- Executes on button press in UpdateLink: create a link dir or update it if it exists
    141128function UpdateLink_Callback(hObject, eventdata, handles)
    142129%------------------------------------------------------------------------
    143 InputString=get(handles.UpdateLink,'String')
    144 switch InputString
    145     case 'CreateLink'
    146         CurrentDir=fileparts(get(handles.SourceDir,'String'));
    147         if ~exist(CurrentDir,'dir')
    148             CurrentDir='';
    149         end
    150         SourceDir=uigetdir(CurrentDir,'pick up the source project directory'); %file browser
    151         if isequal(SourceDir,0)
    152             return
    153         else
    154             set(handles.SourceDir,'String',SourceDir)
    155         end
    156         drawnow
    157         [SourcePath,ProjectName]=fileparts(SourceDir);
    158         MirrorRoot=uigetdir(CurrentDir,'path to the link directory'); %file browser
    159         if isempty(MirrorRoot)
    160             return
    161         else
    162             MirrorDir=fullfile(MirrorRoot,[ProjectName '.link']);
    163         end
    164         if ~exist(MirrorDir,'dir')
    165             mkdir(MirrorDir)
    166         end
    167         MirrorDoc.SourceDir=SourceDir;
    168         t=struct2xml(MirrorDoc);
    169         set(t,1,'name','DataTree');
    170         save(t,fullfile(MirrorDir,[ProjectName '.xml']))
    171         set(handles.LinkDir,'String',MirrorDir)
    172        
    173         %update_link(SourceDir,LinkDir)
    174         SourceDir_Callback([],[], handles)
    175     case 'UpDateLink'
    176         %      MirrorDir=get(handles.LinkDir,'String');
    177         % menu={'*.xml', ' (*.xml)';
    178         %     '*.xml',  '.xml files '; ...
    179         %     '*.*',  'All Files (*.*)'};
    180         % [MirrorXml, PathName] = uigetfile( menu, 'Pick the head xml file in the link directory',MirrorDir);
    181         [MirrorXml, PathName]=fileparts(get(handles.LinkDir,'String'));
    182         %set(handles.LinkDir,'String',fullfile(PathName,regexprep(MirrorXml,'.xml$','.link')))
    183         LinkDir_Callback(hObject, eventdata, handles)
    184 end
    185 
    186 % RootDirectory_Callback(hObject, eventdata, handles)
    187 %------------------------------------------------------------------------
    188 % --- Executes on button press in open_SubCampaign.
    189 function UpdateMirror_Callback(hObject, eventdata, handles)
    190 %------------------------------------------------------------------------
    191 % MirrorDir=get(handles.LinkDir,'String');
    192 % menu={'*.xml', ' (*.xml)';
    193 %     '*.xml',  '.xml files '; ...
    194 %     '*.*',  'All Files (*.*)'};
    195 % [MirrorXml, PathName] = uigetfile( menu, 'Pick the head xml file in the link directory',MirrorDir);
    196 % set(handles.LinkDir,'String',fullfile(PathName,regexprep(MirrorXml,'.xml$','.link')))
    197 % MirrorDir_Callback(hObject, eventdata, handles)
    198 
    199 
    200 %------------------------------------------------------------------------
    201 function LinkDir_Callback(hObject, eventdata, handles)
    202 %------------------------------------------------------------------------   
    203 MirrorDir=get(handles.LinkDir,'String');
    204 [tild,MirrorName]=fileparts(MirrorDir);
    205 s=xml2struct(fullfile(MirrorDir,[MirrorName '.xml']));
    206 set(handles.SourceDir,'String',s.SourceDir)
    207 SourceDir_Callback([],[], handles)
    208 %update_link(s.SourceDir, LinkDir)
    209 
    210 
    211 % %------------------------------------------------------------------------
    212 % function update_link(SourceDir,LinkDir,handles)
    213 % %------------------------------------------------------------------------
    214 % SourceDir_Callback([],[], handles)
    215 
    216 %------------------------------------------------------------------------
    217 function SourceDir_Callback(hObject, eventdata, handles)
    218 %------------------------------------------------------------------------
    219 set(handles.SourceDir,'BackgroundColor',[1 1 0])
    220 drawnow
     130[SourcePath,ProjectName]=fileparts(get(handles.SourceDir,'String'));
     131LinkDir=get(handles.LinkDir,'String');
     132if isempty(LinkDir)||strcmp(get(handles.LinkDir,'Visible'),'off')
     133    LinkRoot=uigetdir(LinkDir,'pick up the path to the link directory'); %file browser
     134    if isempty(LinkRoot),return,end
     135    LinkDir=fullfile(LinkRoot,[ProjectName '.link']);
     136    set(handles.LinkDir,'Visible','on')
     137    set(handles.LinkDir,'String',LinkDir)
     138end
     139
     140if ~exist(LinkDir,'dir')
     141    try
     142        mkdir(LinkDir)
     143    catch ME
     144        msgbox_uvmat('ERROR',ME.message)
     145    end
     146end
     147LinkDirXml=fullfile(fileparts(LinkDir),[ProjectName '.link.xml']);
     148if ~exist(LinkDirXml,'file')
     149    LinkDoc.SourceDir=get(handles.SourceDir,'String');
     150    t=struct2xml(LinkDoc);
     151    t=set(t,1,'name','Project');
     152    save(t,LinkDirXml)
     153    set(handles.UpdateLink,'String','update_link')
     154end
     155
     156FillExperiments(handles)
     157
     158%------------------------------------------------------------------------
     159% --- Fill the column 'Experiments' with the list of detected directries
     160function FillExperiments(handles)
     161%------------------------------------------------------------------------   
    221162SourceDir=get(handles.SourceDir,'String');
    222 MirrorDir=get(handles.LinkDir,'String');
    223 ExpName={''};
    224 if exist(SourceDir,'dir')
    225     hdir=dir(SourceDir); %list files and dirs
    226     idir=0;
    227     for ilist=1:length(hdir)
    228         if hdir(ilist).isdir
    229             dirname=hdir(ilist).name;
    230             if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
    231                 idir=idir+1;
    232                 ExpName{idir}=hdir(ilist).name;
    233                 link=fullfile(MirrorDir,ExpName{idir})
     163LinkDir='';
     164if strcmp(get(handles.LinkDir,'Visible'),'on')
     165    LinkDir=get(handles.LinkDir,'String');
     166end
     167
     168hdir=dir(SourceDir); %list files and dirs
     169idir=0;
     170ExpName=cell(length(hdir),1);
     171for ilist=1:length(hdir)
     172    if hdir(ilist).isdir
     173        dirname=hdir(ilist).name;
     174        if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')% do not list directories beginning by '0'
     175            idir=idir+1;
     176            ExpName{idir}=hdir(ilist).name;
     177            if ~isempty(LinkDir)
     178                link=fullfile(LinkDir,ExpName{idir});
    234179                if ~exist(link,'dir')
    235                    mkdir(link)
    236                 end
    237             end
    238             % look for the list of 'devices'
    239         else
    240             %warning for isolated files
    241         end
    242     end
    243     set(handles.ListExperiments,'String',[{'*'};ExpName'])
    244     set(handles.ListExperiments,'Value',1)
    245     ListExperiments_Callback(hObject, eventdata, handles)
    246 else
    247     msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory'])
    248 end
    249 set(handles.SourceDir,'BackgroundColor',[1 1 1])
    250 
    251 
    252 %------------------------------------------------------------------------
    253 % --- Executes on selection change in ListExperiments.
    254  function ListExperiments_Callback(hObject, eventdata, handles)
    255 %------------------------------------------------------------------------
    256 SourcePath=get(handles.SourceDir,'String');
    257 MirrorPath=get(handles.LinkDir,'String');
    258 ListExperiments=get(handles.ListExperiments,'String');
    259 ListDevices={};
    260 list_val=get(handles.ListExperiments,'Value');
    261 if isequal(list_val(1),1)
    262     ListExperiments=ListExperiments(2:end); %choose all experiments
    263     testList=1;
    264     set(handles.ListExperiments,'Value',1)
    265 else
    266     ListExperiments=ListExperiments(list_val);%choose selected experiments
    267     testList=0;
    268 end
    269 for iexp=1:numel(ListExperiments)
    270     hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and dirs
    271     idir=0;
    272     for ilist=1:length(hdir)
    273          if ~isequal(hdir(ilist).name(1),'.')
    274         source=fullfile(SourcePath,ListExperiments{iexp},hdir(ilist).name);
    275         link=fullfile(MirrorPath,ListExperiments{iexp},hdir(ilist).name);
    276         if ~exist(link)
    277             system(['ln -s ' source ' ' link])
    278         end
    279         check_list=strcmp(hdir(ilist).name,ListDevices);
    280         if isempty(find(check_list))
    281             ListDevices=[ListDevices;hdir(ilist).name];
    282         end   
    283          end
    284     end
    285 end
    286 set(handles.ListDevices,'String',ListDevices)
    287 %         if hdir(ilist).isdir
    288 %             dirname=hdir(ilist).name;
    289 %             if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
    290 %                 idir=idir+1;
    291 %                 ExpName{idir}=hdir(ilist).name;
    292 %                 link=fullfile(LinkDir,ExpName{idir});
    293 %                 if ~exist(link,'dir')
    294 %                    mkdir(link)
    295 %                 end
    296 %             end
    297 %             % look for the list of 'devices'
    298 %         else
    299 %             %warning for isolated files
    300 %         end
    301 %     end
    302 %     set(handles.ListExperiments,'String',[{'*'};ExpName'])
    303 %     set(handles.ListExperiments,'Value',1)
    304 %     ListExperiments_Callback(hObject, eventdata, handles)
    305    
    306    
    307 % set(handles.ListDevices,'Value',1)
    308 % set(handles.ListRecords,'Value',1)
    309 % set(handles.ListXml,'Value',1)
    310 % [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,{},{});
    311 % set(handles.ListRecords,'String',[{'*'};ListRecords'])
    312 % set(handles.ListDevices,'String',[{'*'};ListDevices'])
    313 % set(handles.ListXml,'String',[{'*'};ListXml'])
    314 % if testList
    315 %     DataviewData=get(handles.figure,'UserData');
    316 %     DataviewData.List=List;
    317 %     set(handles.figure,'UserData',DataviewData)
    318 % end
    319 % set(handles.CampaignDoc,'Visible','on')
    320 % set(handles.edit_xml,'Visible','on')
    321 
    322 %------------------------------------------------------------------------
    323 % --- Executes on button press in update_headings.
    324 function ListDevices_Callback(hObject, eventdata, handles)
    325 CurrentPath=get(handles.SourceDir,'String');
    326 ListExperiments=get(handles.ListExperiments,'String');
    327 list_val=get(handles.ListExperiments,'Value');
    328 if isequal(list_val,1)
    329     ListExperiments=ListExperiments(2:end);
    330 else
    331     ListExperiments=ListExperiments(list_val);
    332 end
    333 set(handles.ListRecords,'Value',1)
    334 set(handles.ListXml,'Value',1)
    335 ListDevices=get(handles.ListDevices,'String');
    336 list_val=get(handles.ListDevices,'Value');
    337 if isequal(list_val,1)
    338     ListDevices=ListDevices(2:end);
    339 else
    340     ListDevices=ListDevices(list_val);
    341 end
    342 [ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
    343 set(handles.ListRecords,'String',[{'*'};ListRecords'])
    344 set(handles.ListXml,'String',[{'*'};ListXml'])
    345 
    346 
    347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    348 
    349 
    350 
    351 %------------------------------------------------------------------------
    352 % --- Executes on selection change in ListRecords.
    353 function ListRecords_Callback(hObject, eventdata, handles)
    354 Value=get(handles.ListRecords,'Value');
    355 if isequal(Value(1),1)
    356     set(handles.ListRecords,'Value',1);
    357 end
    358 
    359 %------------------------------------------------------------------------
    360 % --- Executes on button press in CampaignDoc.
    361 function CampaignDoc_Callback(hObject, eventdata, handles)
    362 %------------------------------------------------------------------------   
    363 answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file')
    364 if ~isequal(answer{1},'OK')
    365     return
    366 end
    367 set(handles.ListExperiments,'Value',1)
    368 ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
    369 DataviewData=get(handles.figure,'UserData');
    370 List=DataviewData.List;
    371 Currentpath=get(handles.SourceDir,'String');
    372 [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
    373 Campaign=[Campaign DirExt];
    374 t=xmltree;
    375 t=set(t,1,'name','CampaignDoc');
    376 t = attributes(t,'add',1,'source','directory');
    377 SubCampaignTest=get(handles.SubCampaignTest,'Value');
    378 root_uid=1;
    379 if SubCampaignTest
    380     %TO DO open an exoiting xml doc
    381     [t,root_uid]=add(t,1,'element','SubCampaign');
    382     t =attributes(t,'add',root_uid,'DirName',Campaign);
    383 end
    384 for iexp=1:length(List.Experiment)
    385     set(handles.ListExperiments,'Value',iexp+1)
    386     drawnow
    387     test_mod=0;
    388     [t,uid_exp]=add(t,root_uid,'element','Experiment');
    389     t = attributes(t,'add',uid_exp,'i',num2str(iexp));
    390     ExpName=List.Experiment{iexp}.name;
    391     t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
    392    
    393     if isfield(List.Experiment{iexp},'Device')
    394         for idevice=1:length(List.Experiment{iexp}.Device)
    395             [t,uid_device]=add(t,uid_exp,'element','Device');
    396             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
    397             t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
    398             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    399                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
    400                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
    401                     [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
    402                     if test
    403                         [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
    404                     end
    405                     if isequal(Title,'ImaDoc')
    406                         [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
    407                         t = attributes(t,'add',uid_xml,'source','file');
    408                         [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                   
    409                     end
    410                 end
    411              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    412                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    413                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
    414                     [t,uid_record]=add(t,uid_device,'element','Record');
    415                     t = attributes(t,'add',uid_record,'DirName',RecordName);
    416                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
    417                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
    418                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
    419                             [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
    420                             if test
    421                                 [FileName ' , Heading updated']
    422                             end
    423                             [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
    424                             t = attributes(t,'add',uid_xml,'source','file');
    425                             [t]=add(t,uid_xml,'chardata',FileName);
    426                         end
    427                     end
     180                    mkdir(link)% create the directory containing links
    428181                end
    429182            end
     
    431184    end
    432185end
     186set(handles.ListExperiments,'String',[{'*'};ExpName(1:idir)])
    433187set(handles.ListExperiments,'Value',1)
    434 outputdir=get(handles.SourceDir,'String');
    435 [path,dirname]=fileparts(outputdir);
    436 outputfile=fullfile(outputdir,[dirname '.xml']);
    437 %campaigndoc(t);
    438 save(t,outputfile)
    439 
    440 %------------------------------------------------------------------------
    441 % --- Executes on button press in CampaignDoc.
    442 function edit_xml_Callback(hObject, eventdata, handles)
    443 %------------------------------------------------------------------------
    444 CurrentPath=get(handles.SourceDir,'String');
    445 %[CurrentPath,Name,Ext]=fileparts(CurrentDir);
     188ListExperiments_Callback([],[], handles)
     189
     190
     191%------------------------------------------------------------------------
     192% --- Executes on selection change in ListExperiments.
     193 function ListExperiments_Callback(hObject,eventdata,handles)
     194%------------------------------------------------------------------------
     195SourcePath=get(handles.SourceDir,'String');
     196MirrorPath='';
     197if strcmp(get(handles.LinkDir,'Visible'),'on')
     198MirrorPath=get(handles.LinkDir,'String');
     199end
    446200ListExperiments=get(handles.ListExperiments,'String');
    447 Value=get(handles.ListExperiments,'Value');
    448 if ~isequal(Value,1)
    449     ListExperiments=ListExperiments(Value);
    450 end
    451 ListDevices=get(handles.ListDevices,'String');
    452 Value=get(handles.ListDevices,'Value');
    453 if ~isequal(Value,1)
    454     ListDevices=ListDevices(Value);
    455 end
    456 ListRecords=get(handles.ListRecords,'String');
    457 Value=get(handles.ListRecords,'Value');
    458 if ~isequal(Value,1)
    459     ListRecords=ListRecords(Value);
    460 end
    461 [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
    462 ListXml=get(handles.ListXml,'String');
    463 Value=get(handles.ListXml,'Value');
    464 set(handles.ListXml,'Value',Value(1));
    465 if isequal(Value(1),1)
    466     msgbox_uvmat('ERROR','an xml file needs to be selected')
    467    return
     201if isequal(get(handles.ListExperiments,'Value'),1)
     202    ListExperiments=ListExperiments(2:end); %choose all experiments
    468203else
    469     XmlName=ListXml{Value(1)};
    470 end
    471 for iexp=1:length(List.Experiment)
    472     ExpName=List.Experiment{iexp}.name;
    473     if isfield(List.Experiment{iexp},'Device')
    474         for idevice=1:length(List.Experiment{iexp}.Device)
    475             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
    476             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    477                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
    478                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
    479                     if isequal(FileName,XmlName)
    480                         editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
    481                         return
    482                     end
     204    ListExperiments=ListExperiments(get(handles.ListExperiments,'Value'));
     205end
     206ListDevices={};
     207
     208for iexp=1:numel(ListExperiments)
     209    hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and dirs
     210    for ilist=1:length(hdir)
     211        Device=hdir(ilist).name;
     212        if ~isequal(Device(1),'.')
     213            if ~isempty(MirrorPath)% we list the links to the data directories of files
     214                link=fullfile(MirrorPath,ListExperiments{iexp},Device);
     215                if ~exist(link)
     216                    source=fullfile(SourcePath,ListExperiments{iexp},Device);
     217                    system(['ln -s ' source ' ' link])%TODO translate for DOS
    483218                end
    484              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    485                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    486                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
    487                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
    488                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
    489                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
    490                             if isequal(FileName,XmlName)
    491                                 editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
    492                                 return
    493                             end                         
    494                         end
    495                     end
    496                 end
     219                Device=['@' Device];
     220            end
     221            if hdir(ilist).isdir
     222                Device=[Device '/'];
     223            end
     224            check_list=strcmp(Device,ListDevices);
     225            if isempty(find(check_list))
     226                ListDevices=[ListDevices;Device];
    497227            end
    498228        end
    499229    end
    500230end
    501 
    502 
    503 
    504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    505 % CurrentPath/Campaign: root directory
    506 function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
    507 
    508  %Shema for Heading:
    509 %  Campaign             
    510 %  (SubCampaign)
    511 % Experiment
    512 %  Device
    513 %  (Record)
    514 %  ImageName
    515 %  DateExp
    516 %                 old: %Project: suppressed ( changed to Campaign)
    517                        %Exp: suppressed (changed to experiment)
    518                        %ImaNames: changed to ImageName
    519 if exist('Record','var') && ~isempty(Record)
    520     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname); 
    521     testrecord=1;
    522 else
    523     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname);
    524     testrecord=0;
    525 end
    526 if ~exist('testSubCampaign','var')
    527     testSubCampaign=0;
    528 end
    529 if testSubCampaign
    530    SubCampaign=Campaign;
    531    [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
    532    Campaign=[Campaign DirExt];
    533 end
    534 test_mod=0; %test for the modification of the xml file
    535 t_device=xmltree(xmlfullname);
    536 Title=get(t_device,1,'name');
    537 uid_child=children(t_device,1);
    538 Heading_old=[];
    539 uidheading=0;
    540 for ilist=1:length(uid_child)
    541     name=get(t_device,uid_child(ilist),'name');
    542     if isequal(name,'Heading')
    543         uidheading=uid_child(ilist);
     231set(handles.ListDevices,'String',ListDevices)
     232
     233
     234%------------------------------------------------------------------------
     235% --- Executes on selection in column ListDevices
     236function ListDevices_Callback(hObject, eventdata, handles)
     237%------------------------------------------------------------------------   
     238list_val=get(handles.ListExperiments,'Value');
     239if numel(list_val)~=1
     240    msgbox_uvmat('ERROR','select a single experiment')
     241    return
     242end
     243ListExperiments=get(handles.ListExperiments,'String');
     244Experiment=ListExperiments{list_val};
     245RootPath='';
     246if strcmp(get(handles.LinkDir,'Visible'),'on')
     247    RootPath=get(handles.LinkDir,'String');
     248end
     249if isempty(RootPath)
     250RootPath=get(handles.SourceDir,'String');
     251end
     252ListDevices=get(handles.ListDevices,'String');
     253Device=ListDevices{get(handles.ListDevices,'Value')};
     254Device=regexprep(Device,'^@','');
     255if strcmp(Device(end),'/')
     256    DataDir=fullfile(RootPath,Experiment,Device(1:end-1));
     257    DirList=dir(DataDir);
     258    for ilist=1:numel(DirList)
     259        [tild,tild,FileExt]=fileparts(DirList(ilist).name);
     260        FileExt=regexprep(FileExt,'^.','');
     261        if ~isempty(FileExt) && (~isempty(imformats(FileExt))||strcmp(lower(FileExt),'avi')||strcmp(lower(FileExt),'nc'))
     262            uvmat(fullfile(DataDir,DirList(ilist).name))
     263            return
     264        end
    544265    end
    545266end
    546 if uidheading
    547     subt=branch(t_device,uidheading);
    548     Heading_old=convert(subt);
    549 else
    550    return % do not edit xml files without element 'Heading'
    551 end
    552 if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
    553     test_mod=1;
    554 end
    555 Heading.Campaign=Campaign;
    556 if testSubCampaign
    557     if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
    558         test_mod=1;
    559     end
    560     Heading.SubCampaign=SubCampaign;
    561 end
    562 if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
    563     test_mod=1;
    564 end
    565 Heading.Experiment=Experiment;
    566 if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
    567     test_mod=1;
    568 end
    569 Heading.Device=Device;
    570 if testrecord
    571     if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
    572         test_mod=1;
    573     end
    574     Heading.Record=Record;
    575 end
    576 if isfield(Heading_old,'ImaNames')
    577     test_mod=1;
    578     if  ~isempty(Heading_old.ImaNames)
    579         Heading.ImageName=Heading_old.ImaNames;
    580     end
    581 end
    582 if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
    583     Heading.ImageName=Heading_old.ImageName;
    584 end
    585 if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
    586     Heading.DateExp=Heading_old.DateExp;
    587 end
    588 if test_mod && uidheading
    589      uid_child=children(t_device,uidheading);
    590      t_device=delete(t_device,uid_child);
    591     t_device=struct2xml(Heading,t_device,uidheading);
    592     backupfile=xmlfullname;
    593     testexist=2;
    594     while testexist==2
    595        backupfile=[backupfile '~'];
    596        testexist=exist(backupfile,'file');
    597     end
    598     [success,message]=copyfile(xmlfullname,backupfile);%make backup
    599     if isequal(success,1)
    600         delete(xmlfullname)
    601     else
    602         return
    603     end
    604     save(t_device,xmlfullname)
    605 end
     267%
     268% set(handles.ListRecords,'Value',1)
     269% set(handles.ListXml,'Value',1)
     270% ListDevices=get(handles.ListDevices,'String');
     271% list_val=get(handles.ListDevices,'Value');
     272% if isequal(list_val,1)
     273%     ListDevices=ListDevices(2:end);
     274% else
     275%     ListDevices=ListDevices(list_val);
     276% end
     277% [ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
     278% set(handles.ListRecords,'String',[{'*'};ListRecords'])
     279% set(handles.ListXml,'String',[{'*'};ListXml'])
     280
     281
     282%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     283
     284
     285
     286% %------------------------------------------------------------------------
     287% % --- Executes on selection change in ListRecords.
     288% function ListRecords_Callback(hObject, eventdata, handles)
     289% Value=get(handles.ListRecords,'Value');
     290% if isequal(Value(1),1)
     291%     set(handles.ListRecords,'Value',1);
     292% end
     293
     294% %------------------------------------------------------------------------
     295% % --- Executes on button press in CampaignDoc.
     296% function CampaignDoc_Callback(hObject, eventdata, handles)
     297% %------------------------------------------------------------------------   
     298% answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file')
     299% if ~isequal(answer{1},'OK')
     300%     return
     301% end
     302% set(handles.ListExperiments,'Value',1)
     303% ListExperiments_Callback(handles)%update the overview of the experiment directories
     304% DataviewData=get(handles.datatree_browser,'UserData');
     305% List=DataviewData.List;
     306% Currentpath=get(handles.SourceDir,'String');
     307% [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
     308% Campaign=[Campaign DirExt];
     309% t=xmltree;
     310% t=set(t,1,'name','CampaignDoc');
     311% t = attributes(t,'add',1,'source','directory');
     312% SubCampaignTest=get(handles.SubCampaignTest,'Value');
     313% root_uid=1;
     314% if SubCampaignTest
     315%     %TO DO open an exoiting xml doc
     316%     [t,root_uid]=add(t,1,'element','SubCampaign');
     317%     t =attributes(t,'add',root_uid,'DirName',Campaign);
     318% end
     319% for iexp=1:length(List.Experiment)
     320%     set(handles.ListExperiments,'Value',iexp+1)
     321%     drawnow
     322%     test_mod=0;
     323%     [t,uid_exp]=add(t,root_uid,'element','Experiment');
     324%     t = attributes(t,'add',uid_exp,'i',num2str(iexp));
     325%     ExpName=List.Experiment{iexp}.name;
     326%     t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
     327%   
     328%     if isfield(List.Experiment{iexp},'Device')
     329%         for idevice=1:length(List.Experiment{iexp}.Device)
     330%             [t,uid_device]=add(t,uid_exp,'element','Device');
     331%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
     332%             t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
     333%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
     334%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
     335%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
     336%                     [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
     337%                     if test
     338%                         [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
     339%                     end
     340%                     if isequal(Title,'ImaDoc')
     341%                         [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
     342%                         t = attributes(t,'add',uid_xml,'source','file');
     343%                         [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                   
     344%                     end
     345%                 end
     346%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
     347%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
     348%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
     349%                     [t,uid_record]=add(t,uid_device,'element','Record');
     350%                     t = attributes(t,'add',uid_record,'DirName',RecordName);
     351%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
     352%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
     353%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
     354%                             [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
     355%                             if test
     356%                                 [FileName ' , Heading updated']
     357%                             end
     358%                             [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
     359%                             t = attributes(t,'add',uid_xml,'source','file');
     360%                             [t]=add(t,uid_xml,'chardata',FileName);
     361%                         end
     362%                     end
     363%                 end
     364%             end
     365%         end
     366%     end
     367% end
     368% set(handles.ListExperiments,'Value',1)
     369% outputdir=get(handles.SourceDir,'String');
     370% [path,dirname]=fileparts(outputdir);
     371% outputfile=fullfile(outputdir,[dirname '.xml']);
     372% %campaigndoc(t);
     373% save(t,outputfile)
     374%
     375% %------------------------------------------------------------------------
     376% % --- Executes on button press in CampaignDoc.
     377% function edit_xml_Callback(hObject, eventdata, handles)
     378% %------------------------------------------------------------------------
     379% CurrentPath=get(handles.SourceDir,'String');
     380% %[CurrentPath,Name,Ext]=fileparts(CurrentDir);
     381% ListExperiments=get(handles.ListExperiments,'String');
     382% Value=get(handles.ListExperiments,'Value');
     383% if ~isequal(Value,1)
     384%     ListExperiments=ListExperiments(Value);
     385% end
     386% ListDevices=get(handles.ListDevices,'String');
     387% Value=get(handles.ListDevices,'Value');
     388% if ~isequal(Value,1)
     389%     ListDevices=ListDevices(Value);
     390% end
     391% ListRecords=get(handles.ListRecords,'String');
     392% Value=get(handles.ListRecords,'Value');
     393% if ~isequal(Value,1)
     394%     ListRecords=ListRecords(Value);
     395% end
     396% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
     397% ListXml=get(handles.ListXml,'String');
     398% Value=get(handles.ListXml,'Value');
     399% set(handles.ListXml,'Value',Value(1));
     400% if isequal(Value(1),1)
     401%     msgbox_uvmat('ERROR','an xml file needs to be selected')
     402%    return
     403% else
     404%     XmlName=ListXml{Value(1)};
     405% end
     406% for iexp=1:length(List.Experiment)
     407%     ExpName=List.Experiment{iexp}.name;
     408%     if isfield(List.Experiment{iexp},'Device')
     409%         for idevice=1:length(List.Experiment{iexp}.Device)
     410%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
     411%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
     412%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
     413%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
     414%                     if isequal(FileName,XmlName)
     415%                         editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
     416%                         return
     417%                     end
     418%                 end
     419%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
     420%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
     421%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
     422%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
     423%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
     424%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
     425%                             if isequal(FileName,XmlName)
     426%                                 editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
     427%                                 return
     428%                             end                         
     429%                         end
     430%                     end
     431%                 end
     432%             end
     433%         end
     434%     end
     435% end
     436
     437
     438%
     439% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     440% % CurrentPath/Campaign: root directory
     441% function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
     442%
     443%  %Shema for Heading:
     444% %  Campaign             
     445% %  (SubCampaign)
     446% % Experiment
     447% %  Device
     448% %  (Record)
     449% %  ImageName
     450% %  DateExp
     451% %                 old: %Project: suppressed ( changed to Campaign)
     452%                        %Exp: suppressed (changed to experiment)
     453%                        %ImaNames: changed to ImageName
     454% if exist('Record','var') && ~isempty(Record)
     455%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname); 
     456%     testrecord=1;
     457% else
     458%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname);
     459%     testrecord=0;
     460% end
     461% if ~exist('testSubCampaign','var')
     462%     testSubCampaign=0;
     463% end
     464% if testSubCampaign
     465%    SubCampaign=Campaign;
     466%    [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
     467%    Campaign=[Campaign DirExt];
     468% end
     469% test_mod=0; %test for the modification of the xml file
     470% t_device=xmltree(xmlfullname);
     471% Title=get(t_device,1,'name');
     472% uid_child=children(t_device,1);
     473% Heading_old=[];
     474% uidheading=0;
     475% for ilist=1:length(uid_child)
     476%     name=get(t_device,uid_child(ilist),'name');
     477%     if isequal(name,'Heading')
     478%         uidheading=uid_child(ilist);
     479%     end
     480% end
     481% if uidheading
     482%     subt=branch(t_device,uidheading);
     483%     Heading_old=convert(subt);
     484% else
     485%    return % do not edit xml files without element 'Heading'
     486% end
     487% if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
     488%     test_mod=1;
     489% end
     490% Heading.Campaign=Campaign;
     491% if testSubCampaign
     492%     if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
     493%         test_mod=1;
     494%     end
     495%     Heading.SubCampaign=SubCampaign;
     496% end
     497% if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
     498%     test_mod=1;
     499% end
     500% Heading.Experiment=Experiment;
     501% if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
     502%     test_mod=1;
     503% end
     504% Heading.Device=Device;
     505% if testrecord
     506%     if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
     507%         test_mod=1;
     508%     end
     509%     Heading.Record=Record;
     510% end
     511% if isfield(Heading_old,'ImaNames')
     512%     test_mod=1;
     513%     if  ~isempty(Heading_old.ImaNames)
     514%         Heading.ImageName=Heading_old.ImaNames;
     515%     end
     516% end
     517% if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
     518%     Heading.ImageName=Heading_old.ImageName;
     519% end
     520% if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
     521%     Heading.DateExp=Heading_old.DateExp;
     522% end
     523% if test_mod && uidheading
     524%      uid_child=children(t_device,uidheading);
     525%      t_device=delete(t_device,uid_child);
     526%     t_device=struct2xml(Heading,t_device,uidheading);
     527%     backupfile=xmlfullname;
     528%     testexist=2;
     529%     while testexist==2
     530%        backupfile=[backupfile '~'];
     531%        testexist=exist(backupfile,'file');
     532%     end
     533%     [success,message]=copyfile(xmlfullname,backupfile);%make backup
     534%     if isequal(success,1)
     535%         delete(xmlfullname)
     536%     else
     537%         return
     538%     end
     539%     save(t_device,xmlfullname)
     540% end
    606541
    607542%------------------------------------------------------------------------
     
    616551end
    617552
    618 
    619 
    620 % --- Executes on selection change in ListXml.
    621 function ListXml_Callback(hObject, eventdata, handles)
    622 Value=get(handles.ListXml,'Value');
    623 if isequal(Value(1),1)
    624     set(handles.ListXml,'Value',1);
    625 end
     553%
     554%
     555% % --- Executes on selection change in ListXml.
     556% function ListXml_Callback(hObject, eventdata, handles)
     557% Value=get(handles.ListXml,'Value');
     558% if isequal(Value(1),1)
     559%     set(handles.ListXml,'Value',1);
     560% end
    626561
    627562
     
    634569end
    635570set(handles.ListExperiments,'Value',1)
    636 ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
    637 DataviewData=get(handles.figure,'UserData')
     571ListDataDir(hObject, eventdata, handles)%update the overview of the experiment directories
     572DataviewData=get(handles.datatree_browser,'UserData')
    638573List=DataviewData.List;
    639574Currentpath=get(handles.SourceDir,'String');
     
    688623set(handles.ListExperiments,'Value',1)
    689624
    690 
    691 % --- Executes on button press in OK.
    692 function OK_Callback(hObject, eventdata, handles)
    693 %------------------------------------------------------------------------
    694 CurrentPath=get(handles.SourceDir,'String');
    695 ListExperiments=get(handles.ListExperiments,'String');
    696 IndicesExp=get(handles.ListExperiments,'Value');
    697 if ~isequal(IndicesExp,1)
    698     ListExperiments=ListExperiments(IndicesExp);
    699 end
    700 ListDevices=get(handles.ListDevices,'String');
    701 Value=get(handles.ListDevices,'Value');
    702 if isequal(Value,1)
    703     msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated')
    704     return
    705 else
    706     ListDevices=ListDevices(Value);
    707 end
    708 ListRecords=get(handles.ListRecords,'String');
    709 Value=get(handles.ListRecords,'Value');
    710 if ~isequal(Value,1)
    711     ListRecords=ListRecords(Value);
    712 end
    713 [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
    714 ListXml=get(handles.ListXml,'String');
    715 Value=get(handles.ListXml,'Value');
    716 if isequal(Value,1)
    717     msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit')
    718     return
    719 else
    720     ListXml=ListXml(Value);
    721 end
    722 
    723 %update all the selected xml files
    724 DataviewData=get(handles.figure,'UserData');
    725 % answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' ...
    726 %     DataviewData.GeometryCalib.CalibrationType ' calibration data'])
    727 % if ~isequal(answer,'Yes')
     625%
     626% % --- Executes on button press in OK.
     627% function OK_Callback(hObject, eventdata, handles)
     628% %------------------------------------------------------------------------
     629% CurrentPath=get(handles.SourceDir,'String');
     630% ListExperiments=get(handles.ListExperiments,'String');
     631% IndicesExp=get(handles.ListExperiments,'Value');
     632% if ~isequal(IndicesExp,1)
     633%     ListExperiments=ListExperiments(IndicesExp);
     634% end
     635% ListDevices=get(handles.ListDevices,'String');
     636% Value=get(handles.ListDevices,'Value');
     637% if isequal(Value,1)
     638%     msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated')
    728639%     return
    729 % end
    730 %List.Experiment{1}.Device{1}
    731 %List.Experiment{2}.Device{1}
    732 for iexp=1:length(List.Experiment)
    733     ExpName=List.Experiment{iexp}.name;
    734     set(handles.ListExperiments,'Value',IndicesExp(iexp));
    735     if isfield(List.Experiment{iexp},'Device')
    736         for idevice=1:length(List.Experiment{iexp}.Device)
    737             DeviceName=List.Experiment{iexp}.Device{idevice}.name;     
    738             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    739                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
    740                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
    741                     for ilistxml=1:length(ListXml)
    742                         if isequal(FileName,ListXml{ilistxml})
    743                             set(handles.ListXml,'Value',Value(ilistxml))
    744                             drawnow
    745                             xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
    746                             update_imadoc(DataviewData.GeometryCalib,xmlfullname)
    747                             display([xmlfullname ' updated'])
    748                             break
    749                         end
    750                     end
    751                 end
    752              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    753                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    754                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
    755                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
    756                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
    757                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
    758                             for ilistxml=1:length(ListXml)
    759                                 if isequal(FileName,ListXml{ilistxml})
    760                                     set(handles.ListXml,'Value',Value(ilistxml))
    761                                     drawnow
    762                                     xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
    763                                     update_imadoc(DataviewData.GeometryCalib,xmlfullname)
    764                                     display([xmlfullname ' updated'])
    765                                     break
    766                                 end
    767                             end
    768                         end
    769                     end
    770                 end
    771             end
    772         end
    773     end
    774 end
    775 set(handles.ListXml,'Value',Value)   
     640% else
     641%     ListDevices=ListDevices(Value);
     642% end
     643% ListRecords=get(handles.ListRecords,'String');
     644% Value=get(handles.ListRecords,'Value');
     645% if ~isequal(Value,1)
     646%     ListRecords=ListRecords(Value);
     647% end
     648% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
     649% ListXml=get(handles.ListXml,'String');
     650% Value=get(handles.ListXml,'Value');
     651% if isequal(Value,1)
     652%     msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit')
     653%     return
     654% else
     655%     ListXml=ListXml(Value);
     656% end
     657%
     658% %update all the selected xml files
     659% DataviewData=get(handles.datatree_browser,'UserData');
     660% % answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' ...
     661% %     DataviewData.GeometryCalib.CalibrationType ' calibration data'])
     662% % if ~isequal(answer,'Yes')
     663% %     return
     664% % end
     665% %List.Experiment{1}.Device{1}
     666% %List.Experiment{2}.Device{1}
     667% for iexp=1:length(List.Experiment)
     668%     ExpName=List.Experiment{iexp}.name;
     669%     set(handles.ListExperiments,'Value',IndicesExp(iexp));
     670%     if isfield(List.Experiment{iexp},'Device')
     671%         for idevice=1:length(List.Experiment{iexp}.Device)
     672%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;     
     673%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
     674%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
     675%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
     676%                     for ilistxml=1:length(ListXml)
     677%                         if isequal(FileName,ListXml{ilistxml})
     678%                             set(handles.ListXml,'Value',Value(ilistxml))
     679%                             drawnow
     680%                             xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
     681%                             update_imadoc(DataviewData.GeometryCalib,xmlfullname)
     682%                             display([xmlfullname ' updated'])
     683%                             break
     684%                         end
     685%                     end
     686%                 end
     687%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
     688%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
     689%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
     690%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
     691%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
     692%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
     693%                             for ilistxml=1:length(ListXml)
     694%                                 if isequal(FileName,ListXml{ilistxml})
     695%                                     set(handles.ListXml,'Value',Value(ilistxml))
     696%                                     drawnow
     697%                                     xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
     698%                                     update_imadoc(DataviewData.GeometryCalib,xmlfullname)
     699%                                     display([xmlfullname ' updated'])
     700%                                     break
     701%                                 end
     702%                             end
     703%                         end
     704%                     end
     705%                 end
     706%             end
     707%         end
     708%     end
     709% end
     710% set(handles.ListXml,'Value',Value)   
    776711%     
    777712%     
     
    817752handles.output ='OK, Calibration replicated';
    818753guidata(hObject, handles);% Update handles structure
    819 uiresume(handles.figure);
    820 
    821 % --- Executes on button press in Cancel.
    822 function Cancel_Callback(hObject, eventdata, handles)
    823 handles.output = get(hObject,'String');
    824 guidata(hObject, handles); % Update handles structure
    825 % Use UIRESUME instead of delete because the OutputFcn needs
    826 uiresume(handles.figure);
    827 
    828 % --- Executes when user attempts to close figure.
    829 function figure_CloseRequestFcn(hObject, eventdata, handles)
    830 % if isequal(get(handles.figure, 'waitstatus'), 'waiting')
     754uiresume(handles.datatree_browser);
     755%
     756% % --- Executes on button press in Cancel.
     757% function Cancel_Callback(hObject, eventdata, handles)
     758% handles.output = get(hObject,'String');
     759% guidata(hObject, handles); % Update handles structure
     760% % Use UIRESUME instead of delete because the OutputFcn needs
     761% uiresume(handles.datatree_browser);
     762
     763% --- Executes when user attempts to close datatree_browser.
     764function datatree_browser_CloseRequestFcn(hObject, eventdata, handles)
     765% if isequal(get(handles.datatree_browser, 'waitstatus'), 'waiting')
    831766%     % The GUI is still in UIWAIT, us UIRESUME
    832 %     uiresume(handles.figure);
     767%     uiresume(handles.datatree_browser);
    833768% else
    834769%     % The GUI is no longer waiting, just close it
    835 %     delete(handles.figure);
    836 % end
    837 
    838 % --- Executes on key press over figure1 with no controls selected.
    839 function figure_KeyPressFcn(hObject, eventdata, handles)
    840 % Check for "enter" or "escape"
    841 if isequal(get(hObject,'CurrentKey'),'escape')
    842     % User said no by hitting escape
    843     handles.output = 'Cancel';
    844    
    845     % Update handles structure
    846     guidata(hObject, handles);
    847    
    848     uiresume(handles.figure);
    849 end
    850 if isequal(get(hObject,'CurrentKey'),'return')
    851     uiresume(handles.figure);
    852 end
     770%     delete(handles.datatree_browser);
     771% end
     772delete(hObject)
  • trunk/src/find_imadoc.m

    r469 r507  
    1313XmlFileName=[fullfile(RootPath,SubDirBase) '.xml'];%new convention: xml at the level of the image folder
    1414if ~exist(XmlFileName,'file')
    15     if strcmp(FileExt,'.nc')
    16         basexml=fullfile(RootPath,RootFile) ; % old convention: xml inside the image folder, case of civ files
    17     else
    18         basexml=fullfile(RootPath,SubDir,RootFile) ; % old convention: xml inside the image folder, case of images
    19     end
    20     XmlFileName=[basexml '.xml'];
     15    XmlFileName=[fullfile(RootPath,SubDirBase,RootFile) '.xml']; % old convention: xml inside the image folder, case of images or new civ files
    2116    if ~exist(XmlFileName,'file')
    22         XmlFileName=[basexml '.civ']; % very old convention: .civ file
    23         if ~exist(XmlFileName,'file')
    24             XmlFileName='';
     17        XmlFileName=[fullfile(RootPath,SubDirBase,RootFile) '.civ']; % very old convention: .civ file
     18        if ~exist(XmlFileName,'file') && strcmp(FileExt,'.nc')
     19            XmlFileName=[fullfile(RootPath,RootFile) '.xml'] ; % old convention: xml inside the image folder, old civ file opened
     20            if ~exist(XmlFileName,'file')
     21                XmlFileName=[fullfile(RootPath,RootFile) '.civ']; % very old convention: .civ file
     22            end
    2523        end
    2624    end
    2725end
     26if ~exist(XmlFileName,'file')
     27    XmlFileName='';
     28end
  • trunk/src/geometry_calib.m

    r502 r507  
    5050% Edit the above text to modify the response to help geometry_calib
    5151
    52 % Last Modified by GUIDE v2.5 05-Oct-2010 13:47:00
     52% Last Modified by GUIDE v2.5 29-Jul-2012 08:46:09
    5353
    5454% Begin initialization code - DO NOT edit
     
    14501450
    14511451
     1452% --- Executes when user attempts to close geometry_calib.
     1453function geometry_calib_CloseRequestFcn(hObject, eventdata, handles)
     1454% hObject    handle to geometry_calib (see GCBO)
     1455% eventdata  reserved - to be defined in a future version of MATLAB
     1456% handles    structure with handles and user data (see GUIDATA)
     1457
     1458% Hint: delete(hObject) closes the figure
     1459delete(hObject);
  • trunk/src/msgbox_uvmat.m

    r497 r507  
    112112    if exist('Position','var')
    113113    if iscell(default_answer)
    114         widthstring=max(cellfun('length',default_answer),length(display_str));
    115         heightstring=size(default_answer,1);
     114        widthstring=max(max(cellfun('length',default_answer)),length(display_str));
     115        heightstring=size(default_answer,1);%nbre of expected lines
    116116        set(handles.edit_box,'Max',2);
    117117    else
  • trunk/src/transform_field/phys.m

    r494 r507  
    1616% Data_1, CalibData_1: same as Data, CalibData for the second field.
    1717
    18 function [DataOut,DataOut_1]=phys(varargin)
     18function [DataOut,DataOut_1]=phys(DataIn,XmlData,DataIn_1,XmlData_1)
    1919% A FAIRE: 1- verifier si DataIn est une 'field structure'(.ListVarName'):
    2020% chercher ListVarAttribute, for each field (cell of variables):
     
    2525%            'D_i' if '.Role='vector_x,...',
    2626%              'scalar', else (thenno change except scale factor)
     27%% set GUI config
     28DataOut=[];
     29DataOut_1=[]; %default second  output field
     30if strcmp(DataIn,'*')
     31    if isfield(XmlData,'GeometryCalib')&& isfield(XmlData.GeometryCalib,'CoordUnit')
     32        DataOut.CoordUnit=XmlData.GeometryCalib.CoordUnit;
     33    end
     34    return
     35end
     36
    2737%% analyse input and set default output
    28 DataOut=varargin{1};%default first output field
    29 DataOut_1=[]; %default second  output field
     38DataOut=DataIn;%default first output field
    3039if nargin>=2 % nargin =nbre of input variables
    31     if isfield(varargin{2},'GeometryCalib')
    32         Calib{1}=varargin{2}.GeometryCalib;
     40    if isfield(XmlData,'GeometryCalib')
     41        Calib{1}=XmlData.GeometryCalib;
    3342    else
    3443        Calib{1}=[];
    3544    end
    3645    if nargin>=3  %two input fields
    37         DataOut_1=varargin{3};%default second output field
    38         if nargin>=4 && isfield(varargin{4},'GeometryCalib')
    39             Calib{2}=varargin{4}.GeometryCalib;
     46        DataOut_1=DataIn_1;%default second output field
     47        if nargin>=4 && isfield(XmlData_1,'GeometryCalib')
     48            Calib{2}=XmlData_1.GeometryCalib;
    4049        else
    4150            Calib{2}=Calib{1};
     
    4554
    4655%% get the z index defining the section plane
    47 if isfield(varargin{1},'ZIndex')&&~isempty(varargin{1}.ZIndex)&&~isnan(varargin{1}.ZIndex)
    48     ZIndex=varargin{1}.ZIndex;
     56if isfield(DataIn,'ZIndex')&&~isempty(DataIn.ZIndex)&&~isnan(DataIn.ZIndex)
     57    ZIndex=DataIn.ZIndex;
    4958else
    5059    ZIndex=1;
     
    5766        return %bad calib parameter input
    5867    end
    59     if ~(isfield(varargin{1},'CoordUnit')&& strcmp(varargin{1}.CoordUnit,'pixel'))
     68    if ~(isfield(DataIn,'CoordUnit')&& strcmp(DataIn.CoordUnit,'pixel'))
    6069        return % transform only fields in pixel coordinates
    6170    end
    62     DataOut=phys_1(varargin{1},Calib{1},ZIndex);% transform coordiantes and velocity components
     71    DataOut=phys_1(DataIn,Calib{1},ZIndex);% transform coordiantes and velocity components
    6372    %case of images or scalar: in case of two input fields, we need to project the transform  on the same regular grid
    64     if isfield(varargin{1},'A') && isfield(varargin{1},'AX') && ~isempty(varargin{1}.AX) && isfield(varargin{1},'AY')&&...
    65                                            ~isempty(varargin{1}.AY) && length(varargin{1}.A)>1
     73    if isfield(DataIn,'A') && isfield(DataIn,'AX') && ~isempty(DataIn.AX) && isfield(DataIn,'AY')&&...
     74                                           ~isempty(DataIn.AY) && length(DataIn.A)>1
    6675        iscalar=1;
    67         A{1}=varargin{1}.A;
     76        A{1}=DataIn.A;
    6877    end
    6978end
     
    8392%% transform second field if relevant
    8493if ~isempty(DataOut_1)
    85     if isfield(varargin{3},'ZIndex') && ~isequal(varargin{3}.ZIndex,ZIndex)
     94    if isfield(DataIn_1,'ZIndex') && ~isequal(DataIn_1.ZIndex,ZIndex)
    8695        DataOut_1.Txt='different plane indices for the two input fields';
    8796        return
     
    9099        return %bad calib parameter input
    91100    end
    92     if ~(isfield(varargin{3},'CoordUnit')&& strcmp(varargin{3}.CoordUnit,'pixel'))
     101    if ~(isfield(DataIn_1,'CoordUnit')&& strcmp(DataIn_1.CoordUnit,'pixel'))
    93102        return % transform only fields in pixel coordinates
    94103    end
     
    108117        end
    109118    end
    110     if isfield(varargin{3},'A')&&isfield(varargin{3},'AX')&&~isempty(varargin{3}.AX) && isfield(varargin{3},'AY')&&...
    111             ~isempty(varargin{3}.AY)&&length(varargin{3}.A)>1
     119    if isfield(DataIn_1,'A')&&isfield(DataIn_1,'AX')&&~isempty(DataIn_1.AX) && isfield(DataIn_1,'AY')&&...
     120            ~isempty(DataIn_1.AY)&&length(DataIn_1.A)>1
    112121        iscalar=iscalar+1;
    113122        Calib{iscalar}=Calib{2};
    114         A{iscalar}=varargin{3}.A;
     123        A{iscalar}=DataIn_1.A;
    115124    end
    116125end
  • trunk/src/update_menu.m

    r236 r507  
    1212function menu_str=update_menu(handle,strinput)
    1313menu_str=get(handle,'String');
    14 nbmenu=length(menu_str);
    1514ichoice=find(strcmp(strinput,menu_str),1);
    1615if isempty(ichoice)%the input string does not exist in the menu
    17     menu_str{nbmenu+1}=menu_str{nbmenu};%shift  the last item ('more...')
    18     menu_str{nbmenu}=strinput;
     16    ichoice= length(menu_str);
     17    menu_str=[menu_str(1:end-1);{strinput};menu_str(end)];
    1918    set(handle,'String',menu_str)
    20     ichoice=nbmenu;
    2119end
    2220set(handle,'Value',ichoice)
  • trunk/src/uvmat.m

    r503 r507  
    207207guidata(hObject, handles);
    208208
     209%% add the path to uvmat (useful if uvmat has been opened in the working directory and a working directory change occured)
     210path_uvmat=fileparts(which('uvmat'));
     211
    209212%% set the position of colorbar and ancillary GUIs:
    210213set(hObject,'Units','Normalized')
     
    237240
    238241%% TRANSFORM menu: builtin fcts
    239 menu_str={'';'phys';'px';'phys_polar'};
    240 UvData.OpenParam.NbBuiltin=numel(menu_str); %number of functions
    241 path_uvmat=fileparts(which('uvmat'));
    242 addpath (path_uvmat) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
    243 addpath(fullfile(path_uvmat,'transform_field'))%add the path to transform functions,
    244 fct_handle{1,1}=[];
    245 testexist=zeros(size(menu_str'));%default
    246 testexist(1)=1;
    247 for ilist=2:length(menu_str)
    248     if exist(menu_str{ilist},'file')
    249         fct_handle{ilist,1}=str2func(menu_str{ilist});
    250         testexist(ilist)=1;
    251     else
    252         testexist(ilist)=0;
    253     end
    254 end
    255 rmpath(fullfile(path_uvmat,'transform_field'))
    256 
    257 %% load the list of previously browsed files in menus Open and Open_1
     242transform_menu={'';'phys';'px';'phys_polar'};
     243UvData.OpenParam.NbBuiltin=numel(transform_menu); %number of functions
     244path_list=(num2cell(blanks(UvData.OpenParam.NbBuiltin)))';%initialize a cell array of nbvar blanks
     245transform_path=fullfile(path_uvmat,'transform_field');
     246path_list{1}='';
     247path_list(2:end)=regexprep(path_list(2:end),' ',transform_path); % set transform_path to the path_list
     248
     249%% load the list of previously browsed files in menus Open, Open_1 and transform_fct
    258250 dir_perso=prefdir; % path to the directory .matlab for personal data
    259251 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab
    260252 if exist(profil_perso,'file')
    261       h=load (profil_perso);
    262       if isfield(h,'MenuFile')
    263           for ifile=1:min(length(h.MenuFile),5)
    264               eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
    265                eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
    266           end
    267       end
    268       if isfield(h,'transform_fct') && iscell(h.transform_fct)
     253     h=load (profil_perso);
     254     if isfield(h,'MenuFile')
     255         for ifile=1:min(length(h.MenuFile),5)
     256             eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
     257             eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
     258         end
     259     end
     260     if isfield(h,'transform_fct') && iscell(h.transform_fct)
    269261         for ilist=1:length(h.transform_fct);
    270262             if exist(h.transform_fct{ilist},'file')
    271                 [path,file]=fileparts(h.transform_fct{ilist});
    272                 addpath(path)
    273                 h_func=str2func(file);
    274                 rmpath(path)
    275                 testexist=[testexist 1];
    276              else
    277                 file='';
    278                 h_func=[];
    279                 testexist=[testexist 0];
     263                 [path,file]=fileparts(h.transform_fct{ilist});
     264                 transform_menu=[transform_menu; {file}];
     265                 path_list=[path_list; {path}];
    280266             end
    281              fct_handle=[fct_handle; {h_func}]; %concatene the list of paths
    282              menu_str=[menu_str; {file}];
    283267         end
    284       end
     268     end
    285269 end
    286 menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
    287 fct_handle=fct_handle(testexist==1);
    288 menu_str=[menu_str;{'more...'}];
    289 set(handles.transform_fct,'String',menu_str)
    290 set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
     270transform_menu=[transform_menu;{'more...'}];
     271set(handles.transform_fct,'String',transform_menu)
     272set(handles.transform_fct,'UserData',path_list)% store the list of path in UserData of ACTION
     273set(handles.path_transform,'String','')
     274set(handles.path_transform,'UserData',[])
    291275
    292276%% case of an input argument for uvmat
     
    700684        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
    701685    case 'xml'                % edit xml files
    702         if ~isempty(regexp(fileinput,'.project.xml$'))
     686        t=xmltree(fileinput);
     687        if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir')
    703688            datatree_browser(fileinput)
    704689        else
     
    19771962end
    19781963
    1979 %% read the first input field if a filename has been introduced
     1964%% read the first input field
    19801965ParamIn.ColorVar='';%default variable name for vector color
    19811966frame_index=1;%default
    1982 if ~isempty(FileName)
    1983     FieldName='';%default
    1984     VelType='';%default
     1967% if ~isempty(FileName)
     1968FieldName='';%default
     1969VelType='';%default
    19851970%     FileType=UvData.FileType{1};
    1986     switch UvData.FileType{1}
    1987         case {'civx','civdata','netcdf'};
    1988             list_fields=get(handles.Fields,'String');% list menu fields
    1989   %          index_fields=get(handles.Fields,'Value');% selected string index
    1990             FieldName= list_fields{get(handles.Fields,'Value')}; % selected field
    1991             if ~strcmp(FieldName,'get_field...')
    1992                 if get(handles.FixVelType,'Value')
    1993                     VelTypeList=get(handles.VelType,'String');
    1994                     VelType=VelTypeList{get(handles.VelType,'Value')};
    1995                 end
     1971switch UvData.FileType{1}
     1972    case {'civx','civdata','netcdf'};
     1973        list_fields=get(handles.Fields,'String');% list menu fields
     1974%          index_fields=get(handles.Fields,'Value');% selected string index
     1975        FieldName= list_fields{get(handles.Fields,'Value')}; % selected field
     1976        if ~strcmp(FieldName,'get_field...')
     1977            if get(handles.FixVelType,'Value')
     1978                VelTypeList=get(handles.VelType,'String');
     1979                VelType=VelTypeList{get(handles.VelType,'Value')};
    19961980            end
    1997             if strcmp(FieldName,'velocity')
    1998                 list_code=get(handles.ColorCode,'String');% list menu fields
    1999                 index_code=get(handles.ColorCode,'Value');% selected string index
    2000                 if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
    2001                     list_code=get(handles.ColorScalar,'String');% list menu fields
    2002                     index_code=get(handles.ColorScalar,'Value');% selected string index
    2003                     ParamIn.ColorVar= list_code{index_code}; % selected field
    2004                 end
     1981        end
     1982        if strcmp(FieldName,'velocity')
     1983            list_code=get(handles.ColorCode,'String');% list menu fields
     1984            index_code=get(handles.ColorCode,'Value');% selected string index
     1985            if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
     1986                list_code=get(handles.ColorScalar,'String');% list menu fields
     1987                index_code=get(handles.ColorScalar,'Value');% selected string index
     1988                ParamIn.ColorVar= list_code{index_code}; % selected field
    20051989            end
    2006         case {'video','mmreader'}
    2007             ParamIn=UvData.MovieObject{1};     
    2008             if ~strcmp(NomType,'*')
    2009                 frame_index=num_j1;%frame index for movies or multimage
    2010             else
    2011                 frame_index=num_i1;
    2012             end
    2013         case 'multimage'
    2014             if ~strcmp(NomType,'*')
    2015                 frame_index=num_j1;%frame index for movies or multimage
    2016             else
    2017                 frame_index=num_i1;
    2018             end
    2019         case 'vol' %TODO: update
    2020             if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
    2021                 ParamIn.Npy=UvData.XmlData.Npy;
    2022                 ParamIn.Npx=UvData.XmlData.Npx;
    2023             else           
    2024                 errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
    2025                 return
    2026             end
    2027     end
    2028     if isstruct (ParamIn)
    2029     ParamIn.FieldName=FieldName;
    2030     ParamIn.VelType=VelType;
    2031     ParamIn.GUIName='get_field';
    2032     end
    2033     [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
    2034     if ~isempty(errormsg)
    2035         errormsg=['error in reading ' FileName ': ' errormsg];
    2036         return
    2037     end 
    2038     if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
    2039         set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
    2040         set(handles.num_Npy,'String',num2str(ParamOut.Npy));
    2041     end
    2042     if isfield(ParamOut,'TimeIndex')% case of time obtained from get_field
    2043         set(handles.i1,'String',num2str(ParamOut.TimeIndex))
    2044     end
    2045     if isfield(ParamOut,'TimeValue')
    2046         Field{1}.Time=ParamOut.TimeValue;% case of time obtained from get_field
    2047     end
    2048 end
     1990        end
     1991    case {'video','mmreader'}
     1992        ParamIn=UvData.MovieObject{1};     
     1993        if ~strcmp(NomType,'*')
     1994            frame_index=num_j1;%frame index for movies or multimage
     1995        else
     1996            frame_index=num_i1;
     1997        end
     1998    case 'multimage'
     1999        if ~strcmp(NomType,'*')
     2000            frame_index=num_j1;%frame index for movies or multimage
     2001        else
     2002            frame_index=num_i1;
     2003        end
     2004    case 'vol' %TODO: update
     2005        if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
     2006            ParamIn.Npy=UvData.XmlData.Npy;
     2007            ParamIn.Npx=UvData.XmlData.Npx;
     2008        else           
     2009            errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
     2010            return
     2011        end
     2012end
     2013if isstruct (ParamIn)
     2014ParamIn.FieldName=FieldName;
     2015ParamIn.VelType=VelType;
     2016ParamIn.GUIName='get_field';
     2017end
     2018[Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
     2019if ~isempty(errormsg)
     2020    errormsg=['error in reading ' FileName ': ' errormsg];
     2021    return
     2022end 
     2023if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
     2024    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
     2025    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
     2026end
     2027if isfield(ParamOut,'TimeIndex')% case of time obtained from get_field
     2028    set(handles.i1,'String',num2str(ParamOut.TimeIndex))
     2029end
     2030if isfield(ParamOut,'TimeValue')
     2031    Field{1}.Time=ParamOut.TimeValue;% case of time obtained from get_field
     2032end
     2033Field{1}.ZIndex=z_index; %used for multiplane 3D calibration
     2034% end
    20492035
    20502036%% choose and read a second field FileName_1 if defined
     
    21272113        end
    21282114    end
     2115    Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration
    21292116end
    21302117
     
    23132300
    23142301%% apply coordinate transform or other user fct
    2315 XmlData=[];%default
    2316 XmlData_1=[];%default
    2317 if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
    2318     XmlData=UvData.XmlData{1};
    2319     if numel(UvData.XmlData)==2
    2320         XmlData_1=UvData.XmlData{2};
    2321     end
    2322 end
    2323 choice_value=get(handles.transform_fct,'Value');
    2324 transform_list=get(handles.transform_fct,'UserData');
    2325 transform=transform_list{choice_value};%selected function handles
    2326 % z index
    2327 if ~isempty(FileName)
    2328     Field{1}.ZIndex=z_index;
    2329 end
     2302transform=get(handles.path_transform,'UserData');
    23302303if ~isempty(transform)
    2331     if length(Field)>=2
    2332         Field{2}.ZIndex=z_index;
    2333         [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
    2334         if isempty(Field{2})
     2304    XmlData=[];%default
     2305    XmlData_1=[];%default
     2306    if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
     2307        XmlData=UvData.XmlData{1};
     2308        if numel(UvData.XmlData)==2
     2309            XmlData_1=UvData.XmlData{2};
     2310        end
     2311    end
     2312    transform=get(handles.path_transform,'UserData');
     2313    nbre_arg=nargin(transform);
     2314    if length(Field)==2
     2315        if nbre_arg==4
     2316            [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
     2317        else
     2318            Field{1}=transform(Field{1},XmlData);
    23352319            Field(2)=[];
    23362320        end
    23372321    else
    2338         Field{1}=transform(Field{1},XmlData);
    2339     end
    2340 end   
     2322        if nbre_arg==1
     2323            Field{1}=transform(Field{1});%transform which does not need input parameter
     2324        else
     2325            Field{1}=transform(Field{1},XmlData);
     2326        end
     2327    end
     2328end
    23412329    %% check whether tps is needed, then calculate tps coefficients if needed
    23422330check_proj_tps=0;
     
    31003088    set(hhget_field.list_fig,'Value',1)
    31013089    set(hhget_field.list_fig,'String',{'uvmat'})
    3102     set(handles.transform_fct,'Value',1)% no transform by default
    3103     set(handles.path_transform,'String','')
     3090  %  set(handles.transform_fct,'Value',1)% no transform by default
     3091  %  set(handles.path_transform,'String','')
    31043092    return %no action
    31053093end
     
    32153203        set(hhget_field.list_fig,'Value',1)
    32163204        set(hhget_field.list_fig,'String',{'uvmat'})
    3217         set(handles.transform_fct,'Value',1)% no transform by default
    3218         set(handles.path_transform,'String','')
     3205%         set(handles.transform_fct,'Value',1)% no transform by default
     3206%         set(handles.path_transform,'String','')
    32193207        if check_new
    32203208            UvData.FileType{2}=UvData.FileType{1};
     
    35623550UvData=get(handles.uvmat,'UserData');
    35633551menu=get(handles.transform_fct,'String');
    3564 ind_coord=get(handles.transform_fct,'Value');
    3565 coord_option=menu{ind_coord};
    3566 list_transform=get(handles.transform_fct,'UserData');
    3567 ff=functions(list_transform{end}); 
    3568 if isequal(coord_option,'more...');
    3569     coord_fct='';
    3570     prompt = {'Enter the name of the transform function'};
    3571     dlg_title = 'user defined transform';
    3572     num_lines= 1;
     3552ichoice=get(handles.transform_fct,'Value');%item number in the menu
     3553transform_name=menu{ichoice};% choice of the transform fct
     3554list_path=get(handles.transform_fct,'UserData');
     3555
     3556%% add a new item to the menu if the option 'more...' has been selected
     3557if strcmp(transform_name,'more...');
    35733558    [FileName, PathName] = uigetfile( ...
    3574        {'*.m', ' (*.m)';
     3559        {'*.m', ' (*.m)';
    35753560        '*.m',  '.m files '; ...
    35763561        '*.*', 'All Files (*.*)'}, ...
    3577         'Pick a file', ff.file);
    3578     if isequal(PathName(end),'/')||isequal(PathName(end),'\')
    3579         PathName(end)=[];
    3580     end
    3581     transform_selected =fullfile(PathName,FileName);
    3582     if ~exist(transform_selected,'file')
    3583            return
    3584     end
    3585    [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
    3586    if ~isequal(ext_fct,'.m')
     3562        'Pick the transform function', get(handles.path_transform,'String'));
     3563    path_transform_fct =fullfile(PathName,FileName);
     3564    if ~exist(path_transform_fct,'file')% cancel has been activated
     3565        return
     3566    end
     3567    if isempty(regexp(FileName,'.m$'))% detect file extension .m
    35873568        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
    35883569        return
    3589    end
    3590    menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
    3591    ind_coord=get(handles.transform_fct,'Value');
    3592    addpath(PathName)
    3593    list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
    3594    set(handles.transform_fct,'UserData',list_transform)
    3595    rmpath(PathName)
    3596    % save the new menu in the personal file 'uvmat_perso.mat'
    3597    dir_perso=prefdir;%personal Matalb directory
    3598    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    3599    if exist(profil_perso,'file')
    3600        nb_builtin=UvData.OpenParam.NbBuiltin;
    3601        for ilist=nb_builtin+1:numel(list_transform)
    3602            ff=functions(list_transform{ilist});
    3603            transform_fct{ilist-nb_builtin}=ff.file;
    3604        end
     3570    else
     3571        transform_name=regexprep(FileName,'.m','');
     3572    end
     3573    ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu
     3574    if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it)
     3575        menu=[menu(1:end-1);{transform_name};{'more...'}];
     3576        ichoice=numel(menu)-1;   
     3577    end
     3578    list_path{ichoice}=PathName;%update the list fo fct paths
     3579   
     3580    % save the new menu in the personal file 'uvmat_perso.mat'
     3581    dir_perso=prefdir;%personal Matalb directory
     3582    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     3583    if exist(profil_perso,'file')
     3584        nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat
     3585        for ilist=nb_builtin+1:numel(list_path)
     3586            transform_fct{ilist-nb_builtin}=fullfile(list_path{ilist},menu{ilist});
     3587        end
    36053588        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
    3606    end   
    3607 end
    3608 
    3609 %% check the current path to the selected function
    3610 if isa(list_transform{ind_coord},'function_handle')
    3611     func=functions(list_transform{ind_coord});
    3612     set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
    3613 else
    3614     set(handles.path_transform,'String','')
     3589    end
     3590end
     3591
     3592%% create the function handle of the selected fct
     3593if isempty(list_path{ichoice})% case of no selected fct
     3594    transform_handle=[];
     3595else
     3596    if ~exist(list_path{ichoice},'dir')
     3597        msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...')
     3598        return
     3599    end
     3600    current_dir=pwd;%current working dir
     3601    cd(list_path{ichoice})
     3602    transform_handle=str2func(transform_name);
     3603    cd(current_dir)
     3604end
     3605set(handles.path_transform,'UserData',transform_handle)
     3606
     3607%% update the ToolTip string of the menu transform_fct with the first line of the selected fct file
     3608if isempty(list_path{ichoice})% case of no selected fct
     3609    set(handles.transform_fct,'ToolTipString','transform_fct:choose a transform function')
     3610else
     3611    try
     3612        [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']);
     3613        InputText=textscan(fid,'%s',1,'delimiter','\n');
     3614        fclose(fid)
     3615        set(handles.transform_fct,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help
     3616    end
     3617end
     3618
     3619%% adapt the GUI to the input/output conditions of the selected transform fct
     3620if isempty(list_path{ichoice})% case of no selected fct
     3621    DataOut=[];
     3622else
     3623    if nargin(transform_handle)>1
     3624        if isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
     3625            XmlData=UvData.XmlData{1};
     3626            DataOut=feval(transform_handle,'*',XmlData);
     3627        end
     3628    end
    36153629end
    36163630
    36173631set(handles.CheckFixLimits,'Value',0)
    36183632set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
     3633
     3634%% execute the function to set input an output conditions
     3635
    36193636
    36203637%% delete drawn objects
     
    48564873end
    48574874
     4875
     4876% --------------------------------------------------------------------
     4877function MenuSetProject_Callback(hObject, eventdata, handles)
     4878RootPath=get(handles.RootPath,'String');
     4879ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project source directory');
     4880datatree_browser(ProjectDir)
Note: See TracChangeset for help on using the changeset viewer.