source: trunk/src/script_delete_rdvision.m @ 1165

Last change on this file since 1165 was 1162, checked in by sommeria, 2 months ago

further cleaning

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