Skip to content

Commit

Permalink
throw useful and timely errors when there is an I/O problem. (Old beh…
Browse files Browse the repository at this point in the history
…avior was to cause harder to decipher errors down the line).

Former-commit-id: e4bf079
  • Loading branch information
agbondy committed Oct 21, 2020
1 parent ec0377e commit 1d429f6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion preProcess/preprocessDataSub.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@
fprintf('Time %3.0fs. Loading raw data and applying filters... \n', toc);

fid = fopen(ops.fbinary, 'r'); % open for reading raw data
if fid<3
error('Could not open %s for reading.',ops.fbinary);
end
fidW = fopen(ops.fproc, 'w'); % open for writing processed data
if fidW<3
error('Could not open %s for writing.',ops.fproc);
end

for ibatch = 1:Nbatch
% we'll create a binary file of batches of NT samples, which overlap consecutively on ops.ntbuff samples
Expand Down Expand Up @@ -103,7 +109,10 @@
datr = datr * Wrot; % whiten the data and scale by 200 for int16 range

datcpu = gather(int16(datr)); % convert to int16, and gather on the CPU side
fwrite(fidW, datcpu, 'int16'); % write this batch to binary file
count = fwrite(fidW, datcpu, 'int16'); % write this batch to binary file
if count~=numel(datcpu)
error('Error writing batch %g to %s. Check available disk space.',ibatch,ops.fproc);
end
end

rez.Wrot = gather(Wrot); % gather the whitening matrix as a CPU variable
Expand Down

0 comments on commit 1d429f6

Please sign in to comment.