-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectData.m
executable file
·55 lines (45 loc) · 1.44 KB
/
SelectData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function [ ] = SelectData( nrun )
% Select events from list and write corresponding data to new file
% OMH 27/12/2011
SharedGlobals;
dstname = [DST_PATH sprintf('R%d_sel.mat',nrun)];
dst = load(dstname);
sel = sortrows(dst.selection,2);
icoinc = sel(:,1);
idet = sel(:,2);
ievt = sel(:,3);
ic = sort(icoinc);
ncoinc = sum(diff(ic)>0)
nevents = length(icoinc)
pause
id = 0;
for i = 1:nevents
if id~=idet(i) % new detector
fclose all;
% Open datafile for reading
ft = OpenFileTime( nrun, idet(i) );
fd = OpenFileData( nrun, idet(i) );
if fd<0 | ft<0
disp(sprintf('Could not find data for detector %d.',idet(i)))
continue
end
id = idet(i);
j = 1;
% Open datafile for writing
filename = sprintf( 'S%06d_A%04d_time.bin', nrun, id );
ftw = fopen( [ SELDATA_PATH, filename ], 'w+' );
filename = sprintf( 'S%06d_A%04d_data.bin', nrun, id );
fdw = fopen( [ SELDATA_PATH, filename ], 'w+' );
end
fseek( ft, 4*ibufft*(ievt(i)-1),'bof');
fseek( fd, ibuff*(ievt(i)-1),'bof');
TimeEvt = double( fread( ft,ibufft,'*uint32' ) );
DataEvt = double( fread( fd, ibuff, '*uint8' ) );
fwrite(ftw,TimeEvt,'*uint32');
fwrite(fdw,DataEvt,'*uint8');
ipos(i) = j;
j = j+1;
end
fclose all;
selection = [icoinc idet ievt ipos'];
save(dstname,'selection')