source: trunk/src/script_delete_rdvision.m @ 1129

Last change on this file since 1129 was 1123, checked in by sommeria, 16 months ago

various improvements

File size: 6.7 KB
Line 
1
2%%% extract a series of image folders from RDvision
3% to run on the cluster, edit the file extract.sh in the folder TOP_view or SCANSIDE,
4% Then oarsub -l "walltime=20:00:00" /fsnet/project/coriolis/2018/18ADDUCE/TOP_View/extract.sh
5%%%%%%%%%%%%%%  CHOOSE THE ROOT FOLDER %%%%%%%%%%
6
7RootDir='DATA'
8%RootFolder=fullfile('/fsnet/project/coriolis/2018/18JEVERB',RootDir);
9RootFolder=fullfile('/fsnet/project/edt/2021/21CORIOFARM',RootDir)
10%ParamFile=fullfile(RootFolder,'extract_param.xml');
11%Param=xml2struct(ParamFile);
12
13ListStruct=dir(RootFolder); % get structure of the Root directory
14index_dir=find(strcmp('isdir',fieldnames(ListStruct)));%detect folder info in structure ListStruct
15ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
16check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files
17ListCells=ListCells(:,check_dir);
18ListCells(:,1:2)=[];
19ListNames=ListCells(1,:);
20List2extract={};
21List2delete={};
22List2check={};
23
24%% loop on experiments
25for ilist=1:numel(ListNames)%loop on experiments
26    ListNames{ilist}
27    SubFolder=fullfile(RootFolder,ListNames{ilist});
28    ListStructSub=dir(SubFolder); % get structure of the Root directory
29    index_dir=find(strcmp('isdir',fieldnames(ListStructSub)));%detect folder info in structure ListStruct
30    ListCellsSub=struct2cell(ListStructSub);% transform dir struct to a cell arrray
31    check_dir=cell2mat(ListCellsSub(index_dir,:));% =1 for directories, =0 for files
32    ListCellsSub=ListCellsSub(:,check_dir);
33    ListCellsSub(:,1:2)=[];
34    ListNamesSub=ListCellsSub(1,:);
35    ind_rdvision=[];
36    for isub=1:numel(ListNamesSub)% loop on data folders of the current experiment
37        ListStructSubSub=dir(fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub})); % get structure of the Root directory
38        index_dir=find(strcmp('isdir',fieldnames(ListStructSubSub)));%detect folder info in structure ListStruct
39        ListCellsSubSub=struct2cell(ListStructSubSub);% transform dir struct to a cell arrray
40        check_dir=cell2mat(ListCellsSubSub(index_dir,:));% =1 for directories, =0 for files
41        ListCellsSubSub=ListCellsSubSub(:,check_dir);
42        ListCellsSubSub(:,1:2)=[];
43        ListNamesSubSub=ListCellsSubSub(1,:);
44        ind_rdvision=[];
45        for isubsub=1:numel(ListNamesSubSub)
46            if ~isempty(regexp(ListNamesSubSub{isubsub},'^2021-'))
47                ind_rdvision=[ind_rdvision isubsub];%detect rdvision folders
48            end
49        end
50
51        %% extract the rdvision image series if it was not done
52        if numel(ind_rdvision)==1%
53            DataFolder=fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub},ListNamesSubSub{ind_rdvision});
54            if isempty(regexp(DataFolder,'.extract$'))% if the detected folder is not .extract
55                %     ExtractFolder=fullfile(Param.InputTable{1},[Param.InputTable{2} '.extract']);
56                %     mkdir(ExtractFolder)
57                % %     if ~isempty(XmlFile)
58                % %     copyfile(fullfile(RootFolder,XmlFile),fullfile(DataFolder,[Param.OutputRootFile '.xml']));
59                % %     end
60                %     seqname=fullfile(DataFolder,[Param.InputTable{3} Param.InputTable{5}]);
61                %     [A,FileInfo,timestamps,errormsg]=read_rdvision(seqname,[]);
62                %     Param.IndexRange.last_i=str2num(FileInfo.numberoffiles);
63                %     Param.OutputSubDir=Param.InputTable{2};
64                %     Param.ActionInput.LogPath= DataFolder;
65                %     extract_rdvision(Param)% apply the function used in series
66                %     [ListNames{ilist} ' extracted']
67                List2extract=[List2extract;DataFolder];
68            end
69        end
70
71        %% delete the rdvision source if the extraction has been done
72        Checkdelete=0;
73        ExtractFolder=fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub});
74        status='';
75        if numel(ind_rdvision)==2
76            for irdvision=1:2
77                CheckExtract(irdvision)=isempty(regexp(fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub},ListNamesSubSub{irdvision}), '.extract$'));
78            end
79            status='extract missing';
80            if numel(find(CheckExtract))==1
81                ExtractFolder=fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub},ListNamesSubSub{find(CheckExtract)});
82                PngFolder=fullfile(RootFolder,ListNames{ilist},ListNamesSub{isub},'im');
83                status='image folder not created';
84                if exist(ExtractFolder,'dir') && exist(PngFolder,'dir')
85                    filename_seq=fullfile(ExtractFolder,'im.seq');
86                    s=ini2struct(filename_seq);
87                    FileInfo=s.sequenceSettings;
88                    if isfield(s.sequenceSettings,'numberoffiles')
89                        NumberOfFrames=str2double(s.sequenceSettings.numberoffiles);
90                    else
91                        status='bad seq file';
92                    end
93                    DirPng=dir(PngFolder);
94                    if numel(DirPng)==NumberOfFrames+2
95                        Checkdelete=1;
96                    else
97                        status=['extraction not finished,' num2str(numel(DirPng)-2) ' images extracted'];
98                    end
99                end
100            end
101            %
102            %
103            %     Param.InputTable{1}=fullfile(RootFolder,ListDir{ilist});%folder exp
104            %     ddd=dir(Param.InputTable{1});
105            %     Param.InputTable{2}=ddd(3).name;
106            %     DataFolder=fullfile(Param.InputTable{1},Param.InputTable{2});
107            %     ExtractFolder=fullfile(Param.InputTable{1},[Param.InputTable{2} '.extract']);
108            %     mkdir(ExtractFolder)
109            %     if ~isempty(XmlFile)
110            %     copyfile(fullfile(RootFolder,XmlFile),fullfile(DataFolder,[Param.OutputRootFile '.xml']));
111            %     end
112            %     seqname=fullfile(DataFolder,[Param.InputTable{3} Param.InputTable{5}]);
113            %     [A,FileInfo,timestamps,errormsg]=read_rdvision(seqname,[]);
114            %     Param.IndexRange.last_i=str2num(FileInfo.numberoffiles);
115            %     Param.OutputSubDir=Param.InputTable{2};
116            %     Param.ActionInput.LogPath= DataFolder;
117            %     extract_rdvision(Param)% apply the function used in series
118        end
119        if Checkdelete
120            List2delete=[List2delete;ExtractFolder];
121            %rmdir(ExtractFolder,'s')
122        elseif ~isempty(status)
123            List2check=[List2check;[ExtractFolder ' ' status]];
124        end
125    end
126end
127List2extract
128List2check
129List2delete
130if ~isempty(List2delete)
131    Answer = questdlg('delete listed folders(Y/N)');
132    if strcmp(Answer,'Yes')
133        for ifolder=1:numel(List2delete)
134            rmdir(List2delete{ifolder},'s')
135        end
136    end
137end
Note: See TracBrowser for help on using the repository browser.