Ignore:
Timestamp:
Jun 25, 2013, 12:48:10 AM (11 years ago)
Author:
sommeria
Message:

various bugs corrected. Introduction of campaign lists in Open menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/browse_data.m

    r630 r651  
    121121    MirrorDir=get(handles.MirrorDir,'String');
    122122else
    123     MirrorRoot=uigetdir('','select the dir which must contain the mirror directory, then press OK'); %file browser
    124     if ~ischar(MirrorRoot)
     123    MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir');
     124%     MirrorRoot=uigetdir('','select the dir which must contain the mirror directory, then press OK'); %file browser
     125    if isempty(MirrorRoot)
    125126        return
    126127    else
     
    148149            if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
    149150                idir=idir+1;
    150                 ExpName{idir}=hdir(ilist).name;
    151 
    152                 mirror=fullfile(MirrorDir,ExpName{idir});
     151                mirror=fullfile(MirrorDir,hdir(ilist).name);
    153152                if ~exist(mirror,'dir')
    154153                   mkdir(mirror)
    155154                end
     155                ExpName{idir}=['+/' hdir(ilist).name];
    156156            end
    157157            % look for the list of 'devices'
     
    186186%SourceDir=get(handles.SourceDir,'String');
    187187%MirrorDir=get(handles.MirrorDir,'String');
    188 ExpName={''};
     188% ExpName={''};
    189189if exist(Campaign,'dir')
    190     hdir=dir(Campaign); %list files and dirs
    191     idir=0;
    192     for ilist=1:length(hdir)
    193         if hdir(ilist).isdir
    194             dirname=hdir(ilist).name;
    195             if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
    196                 idir=idir+1;
    197                 ExpName{idir}=hdir(ilist).name;
    198             end
    199         end
    200     end
    201     set(handles.ListExperiments,'String',[{'*'};ExpName'])
     190    ListStruct=dir(Campaign); %list files and dirs
     191    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
     192    ListFiles=ListCells(1,:);%list of dir and file  names
     193    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     194    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
     195    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
     196    check_keep=cellfun('isempty', cell_remove);
     197    ListFiles=sort((ListFiles(check_keep))');
     198    set(handles.ListExperiments,'String',[{'*'};ListFiles])
    202199    set(handles.ListExperiments,'Value',1)
    203200    ListExperiments_Callback([],[], handles)
     
    210207%------------------------------------------------------------------------
    211208% --- Executes on selection change in ListExperiments.
     209%------------------------------------------------------------------------
    212210 function ListExperiments_Callback(hObject, eventdata, handles)
    213 %------------------------------------------------------------------------
     211
    214212MirrorPath='';
    215213CampaignPath=get(handles.SourceDir,'String');
    216214if strcmp(get(handles.MirrorDir,'Visible'),'on')
    217 %     CampaignPath=get(handles.MirrorDir,'String');
    218215    MirrorPath=get(handles.MirrorDir,'String');
    219 else
    220 %     CampaignPath=get(handles.SourceDir,'String');
    221 end
    222 % MirrorPath=get(handles.MirrorDir,'String');
     216end
    223217ListExperiments=get(handles.ListExperiments,'String');
    224218list_val=get(handles.ListExperiments,'Value');
    225219if isequal(list_val(1),1)
    226220    ListExperiments=ListExperiments(2:end); %choose all experiments
    227     testList=1;
    228221    set(handles.ListExperiments,'Value',1)
    229222else
    230223    ListExperiments=ListExperiments(list_val);%choose selected experiments
    231     testList=0;
    232224end
    233225scan_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
     
    236228%------------------------------------------------------------------------
    237229% --- Executes on selection change in ListExperiments.
     230%------------------------------------------------------------------------
    238231 function scan_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
    239 %------------------------------------------------------------------------
     232
    240233ListDevices={};
    241234for iexp=1:numel(ListExperiments)
    242     hdir=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the experiment directory
    243     idir=0;
    244     for ilist=1:length(hdir)
    245         if ~isequal(hdir(ilist).name(1),'.')
    246             DataSeries=fullfile(CampaignPath,ListExperiments{iexp},hdir(ilist).name);
    247             if ~isempty(MirrorPath)
    248                 mirror=fullfile(MirrorPath,ListExperiments{iexp},hdir(ilist).name);
    249                 if ~exist(mirror)% create mirror if needed
    250                     system(['ln -s ' DataSeries ' ' mirror])
    251                 end
    252             end
    253             check_list=strcmp(hdir(ilist).name,ListDevices);
    254             if isempty(find(check_list, 1))
    255                 ListDevices=[ListDevices;hdir(ilist).name];
     235    if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
     236        ListExperiments{iexp}(1)=[];
     237        ListStruct=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the experiment directory
     238        ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
     239        ListFiles=ListCells(1,:);%list of dir and file  names
     240        cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
     241        check_keep=cellfun('isempty', cell_remove);
     242        check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     243        for ilist=1:numel(ListFiles)
     244            if check_keep(ilist)
     245                DataSeries=fullfile(CampaignPath,ListExperiments{iexp},ListFiles{ilist});
     246                if ~isempty(MirrorPath)
     247                    mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});
     248                    if ~exist(mirror)% create mirror if needed
     249                        system(['ln -s ' DataSeries ' ' mirror])
     250                    end
     251                end
     252                if isempty(find(strcmp(ListFiles{ilist},ListDevices), 1))% if the item is not already in ListDevices
     253                    if check_dir(ilist)
     254                        ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
     255                    end
     256                    ListDevices=[ListDevices;ListFiles{ilist}]; %append the item to the list
     257                end
    256258            end
    257259        end
    258260    end
    259261end
    260 set(handles.ListDevices,'String',ListDevices)
    261 
    262 %------------------------------------------------------------------------
    263 % --- Executes on button press in update_headings.
    264 function ListDevices_Callback(hObject, eventdata, handles)
    265 % CurrentPath=get(handles.SourceDir,'String');
    266 % ListExperiments=get(handles.ListExperiments,'String');
    267 % list_val=get(handles.ListExperiments,'Value');
    268 % if isequal(list_val,1)
    269 %     ListExperiments=ListExperiments(2:end);
    270 % else
    271 %     ListExperiments=ListExperiments(list_val);
    272 % end
    273 % set(handles.ListRecords,'Value',1)
    274 % set(handles.ListXml,'Value',1)
    275 % ListDevices=get(handles.ListDevices,'String');
    276 % list_val=get(handles.ListDevices,'Value');
    277 % if isequal(list_val,1)
    278 %     ListDevices=ListDevices(2:end);
    279 % else
    280 %     ListDevices=ListDevices(list_val);
    281 % end
    282 % [ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
    283 % set(handles.ListRecords,'String',[{'*'};ListRecords'])
    284 % set(handles.ListXml,'String',[{'*'};ListXml'])
    285 %
    286 %
    287 % if strcmp(get(handles.MirrorDir,'Visible'),'on')
    288 %     CurrentPath=get(handles.MirrorDir,'String');
    289 % else
    290 %     CurrentPath=get(handles.SourceDir,'String');
    291 % end
    292 % ListDevices=get(handles.ListDevices,'String');
    293 % Device=ListDevices(get(handles.ListDevices,'Value'));
    294 % % else
    295 % hdir=dir(fullfile(SourcePath,Device)); %list files and dirs
    296 
    297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    298 
    299 
    300 
    301 %------------------------------------------------------------------------
    302 % --- Executes on selection change in ListRecords.
    303 function ListRecords_Callback(hObject, eventdata, handles)
    304 Value=get(handles.ListRecords,'Value');
    305 if isequal(Value(1),1)
    306     set(handles.ListRecords,'Value',1);
    307 end
     262set(handles.ListDevices,'String',sort(ListDevices))
    308263
    309264%------------------------------------------------------------------------
     
    311266function CampaignDoc_Callback(hObject, eventdata, handles)
    312267%------------------------------------------------------------------------   
    313 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')
     268answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file');
    314269if ~isequal(answer{1},'OK')
    315270    return
     
    351306                    [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
    352307                    if test
    353                         [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
     308                        disp([List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated'])
    354309                    end
    355310                    if isequal(Title,'ImaDoc')
     
    369324                            [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
    370325                            if test
    371                                 [FileName ' , Heading updated']
     326                                disp([FileName ' , Heading updated'])
    372327                            end
    373328                            [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
     
    426381            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    427382                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
    428                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
     383                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
    429384                    if isequal(FileName,XmlName)
    430385                        editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
     
    556511
    557512%------------------------------------------------------------------------
    558 % --- Executes on button press in HELP.
    559 function HELP_Callback(hObject, eventdata, handles)
    560 path_to_uvmat=which ('uvmat')% check the path of uvmat
    561 pathelp=fileparts(path_to_uvmat);
    562 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
    563 if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
    564 else
    565 web([helpfile '#dataview'])   
    566 end
    567 
    568 
    569 
    570 % --- Executes on selection change in ListXml.
    571 function ListXml_Callback(hObject, eventdata, handles)
    572 Value=get(handles.ListXml,'Value');
    573 if isequal(Value(1),1)
    574     set(handles.ListXml,'Value',1);
    575 end
    576 
    577 
    578 % --- Executes on button press in clean_civ_cmx.
    579 function clean_civ_cmx_Callback(hObject, eventdata, handles)
    580 message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
    581 answer=msgbox_uvmat('INPUT_Y-N',message);
    582 if ~isequal(answer,'Yes')
    583     return
    584 end
    585 set(handles.ListExperiments,'Value',1)
    586 ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
    587 DataviewData=get(handles.browse_data,'UserData')
    588 List=DataviewData.List;
    589 Currentpath=get(handles.SourceDir,'String');
    590 [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
    591 Campaign=[Campaign DirExt];
    592 SubCampaignTest=get(handles.SubCampaignTest,'Value');
    593 nbdelete_tot=0;
    594 for iexp=1:length(List.Experiment)
    595     set(handles.ListExperiments,'Value',iexp+1)
    596     drawnow
    597     test_mod=0;
    598     ExpName=List.Experiment{iexp}.name; 
    599     nbdelete=0;
    600     if isfield(List.Experiment{iexp},'Device')
    601         for idevice=1:length(List.Experiment{iexp}.Device)
    602             DeviceName=List.Experiment{iexp}.Device{idevice}.name;     
    603             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    604                 currentdir=fullfile(Currentpath,Campaign,ExpName,DeviceName);
    605                 hdir=dir(currentdir); %list files and dirs
    606                 idir=0;
    607                 for ilist=1:length(hdir)
    608                     if hdir(ilist).isdir
    609                         dirname=hdir(ilist).name;
    610                         if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
    611                             CivDir=fullfile(currentdir,dirname)
    612                             hCivDir=dir(CivDir);
    613                             for ilist=1:length(hCivDir)
    614                                 FileName=hCivDir(ilist).name;
    615                                 [dd,ff,Ext]=fileparts(FileName);
    616                                 if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
    617                                     delete(fullfile(CivDir,FileName))
    618                                     nbdelete=nbdelete+1;
    619                                 end
    620                             end
    621                         end
    622                     end
    623                 end
    624              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    625                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    626                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
    627                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
    628                         'look at subdirectories'
    629                     end
    630                 end
    631             end
    632         end
    633     end
    634     display([num2str(nbdelete) ' files deleted'])
    635     nbdelete_tot=nbdelete_tot+nbdelete;
    636 end
    637 msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete_tot) ' files deleted by clean_civ_cmx'])
    638 set(handles.ListExperiments,'Value',1)
    639 
    640 
    641513% --- Executes on button press in OK.
     514%------------------------------------------------------------------------
    642515function OK_Callback(hObject, eventdata, handles)
    643 %------------------------------------------------------------------------
     516
    644517if strcmp(get(handles.MirrorDir,'Visible'),'on')
    645518    Campaign=get(handles.MirrorDir,'String');
     
    653526    Experiment=Experiment(IndicesExp);% use the selection of the list of experiments
    654527end
     528Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
    655529Device=get(handles.ListDevices,'String');
    656530Value=get(handles.ListDevices,'Value');
    657531Device=Device(Value);
     532Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir
    658533handles.output.Experiment=Experiment;
    659 handles.output.Device=Device;
     534handles.output.DataSeries=Device;
    660535guidata(hObject, handles);% Update handles structure
    661536uiresume(handles.browse_data);
    662537drawnow
    663 return
    664 
    665 
    666 % ListRecords=get(handles.ListRecords,'String');
    667 % Value=get(handles.ListRecords,'Value');
    668 % if ~isequal(Value,1)
    669 %     ListRecords=ListRecords(Value);
    670 % end
    671 
    672 %[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices);
    673 ListXml=get(handles.ListXml,'String');
    674 Value=get(handles.ListXml,'Value');
    675 if isequal(Value,1)
    676     msgbox_uvmat('ERROR','you need to select in the GUI browse_data the xml files to edit')
    677     return
    678 else
    679     ListXml=ListXml(Value);
    680 end
    681 
    682 %update all the selected xml files
    683 DataviewData=get(handles.browse_data,'UserData');
    684 % answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' ...
    685 %     DataviewData.GeometryCalib.CalibrationType ' calibration data'])
    686 % if ~isequal(answer,'Yes')
    687 %     return
    688 % end
    689 %List.Experiment{1}.Device{1}
    690 %List.Experiment{2}.Device{1}
    691 for iexp=1:length(List.Experiment)
    692     ExpName=List.Experiment{iexp}.name;
    693     set(handles.ListExperiments,'Value',IndicesExp(iexp));
    694     if isfield(List.Experiment{iexp},'Device')
    695         for idevice=1:length(List.Experiment{iexp}.Device)
    696             DeviceName=List.Experiment{iexp}.Device{idevice}.name;     
    697             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
    698                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
    699                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
    700                     for ilistxml=1:length(ListXml)
    701                         if isequal(FileName,ListXml{ilistxml})
    702                             set(handles.ListXml,'Value',Value(ilistxml))
    703                             drawnow
    704                             xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
    705                             update_imadoc(DataviewData.GeometryCalib,xmlfullname,'GeometryCalib')
    706                             display([xmlfullname ' updated'])
    707                             break
    708                         end
    709                     end
    710                 end
    711              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
    712                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
    713                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
    714                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
    715                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
    716                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
    717                             for ilistxml=1:length(ListXml)
    718                                 if isequal(FileName,ListXml{ilistxml})
    719                                     set(handles.ListXml,'Value',Value(ilistxml))
    720                                     drawnow
    721                                     xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
    722                                     update_imadoc(DataviewData.GeometryCalib,xmlfullname,'GeometryCalib')
    723                                     display([xmlfullname ' updated'])
    724                                     break
    725                                 end
    726                             end
    727                         end
    728                     end
    729                 end
    730             end
    731         end
    732     end
    733 end
    734 set(handles.ListXml,'Value',Value)   
    735 %     
    736 %     
    737 %     
    738 %     
    739 %     
    740 %     
    741 %     
    742 % CurrentPath=get(handles.SourceDir,'String');%= get(hObject,'String');
    743 % ListExperiments=get(handles.ListExperiments,'String');
    744 % Value=get(handles.ListExperiments,'Value');
    745 % if ~isequal(Value,1)
    746 %     ListExperiments=ListExperiments(Value);
    747 % end
    748 % ListDevices=get(handles.ListDevices,'String');
    749 % Value=get(handles.ListDevices,'Value');
    750 % if isequal(Value,1)
    751 %     msgbox_uvmat('ERROR','manually select in the GUI browse_data the device being calibrated')
    752 %     return
    753 % else
    754 %     ListDevices=ListDevices(Value);
    755 % end
    756 % ListRecords=get(handles.ListRecords,'String');
    757 % Value=get(handles.ListRecords,'Value');
    758 % if ~isequal(Value,1)
    759 %     ListRecords=ListRecords(Value);
    760 % end
    761 % [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
    762 % ListXml=get(handles.ListXml,'String');
    763 % Value=get(handles.ListXml,'Value');
    764 % if isequal(Value,1)
    765 %     msgbox_uvmat('ERROR','you need to select in the GUI browse_data the xml files to edit')
    766 %     return
    767 % else
    768 %     ListXml=ListXml(Value);
    769 % end
    770 % handles.output.CurrentPath=CurrentPath;
    771 % handles.output.ListExperiments=ListExperiments;
    772 % handles.output.ListDevices=ListDevices;
    773 % handles.output.ListRecords=ListRecords;
    774 % handles.output.ListXml=ListXml;
    775 % handles.output.List=List;
    776 % handles.output ='OK, Calibration replicated';
    777 % guidata(hObject, handles);% Update handles structure
    778 % uiresume(handles.browse_data);
    779 
     538
     539%------------------------------------------------------------------------
     540% --- Executes on button press in HELP.
     541function HELP_Callback(hObject, eventdata, handles)
     542path_to_uvmat=which ('uvmat');% check the path of uvmat
     543pathelp=fileparts(path_to_uvmat);
     544helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
     545if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
     546else
     547web([helpfile '#dataview'])   
     548end
     549
     550%------------------------------------------------------------------------
    780551% --- Executes on button press in Cancel.
     552%------------------------------------------------------------------------
    781553function Cancel_Callback(hObject, eventdata, handles)
     554   
    782555handles.output = get(hObject,'String');
    783556guidata(hObject, handles); % Update handles structure
     
    785558uiresume(handles.browse_data);
    786559
     560%------------------------------------------------------------------------
    787561% --- Executes when user attempts to close browse_data.
     562%------------------------------------------------------------------------
    788563function browse_data_CloseRequestFcn(hObject, eventdata, handles)
     564   
    789565if isequal(get(handles.browse_data, 'waitstatus'), 'waiting')
    790566    % The GUI is still in UIWAIT, us UIRESUME
     
    795571end
    796572
     573%------------------------------------------------------------------------
    797574% --- Executes on key press over figure1 with no controls selected.
     575%------------------------------------------------------------------------
    798576function browse_data_KeyPressFcn(hObject, eventdata, handles)
     577   
    799578% Check for "enter" or "escape"
    800579if isequal(get(hObject,'CurrentKey'),'escape')
Note: See TracChangeset for help on using the changeset viewer.