...
 
Commits (2)
......@@ -38,11 +38,15 @@ function result = readSpec(file, numScan, numCols)
% along with this program. If not, see <http://www.gnu.org/licenses/>.
if(nargin < 2)
error('Not enough input arguments: specify filepath, filename and scan number');
% find available scans in specified file
list_scans(file)
return
end
if (nargin < 3)
numCols = 1;
% this used to set the default: numCols = 1;
list_scan_variables(file, numScan)
return
end
lineStart = -1;
......@@ -88,3 +92,53 @@ end
result = dlmread(file,' ',[lineStart numCols-1 lineEnd numCols-1]);
end
function list_scans(file)
scansFound = {};
fid = fopen(file,'r');
scanString = '#S';
while ~feof(fid)
tline = fgetl(fid);
if (startsWith(tline, scanString))
scansFound = [scansFound, tline]; %#ok<AGROW>
end
end
fclose(fid);
if numel(scansFound) > 0
fprintf('scans found in file "%s":\n', file)
fprintf(' %s\n', scansFound{:});
else
fprintf('no scans found\n')
end
end
function list_scan_variables(file, numScan)
fid = fopen(file,'r');
scanString = sprintf('#S %01i',numScan);
% find scan
while ~feof(fid)
tline = fgetl(fid);
if (startsWith(tline, scanString))
break
end
end
while ~feof(fid)
tline = fgetl(fid);
if (startsWith(tline, '#S'))
break % no variable found
elseif (startsWith(tline, '#L'))
disp('available columns:')
vars = split(tline);
for i=2:numel(vars)
fprintf('%02d %s\n', i-1, vars{i})
end
return
end
end
error('no variables found for scan %01i in file "%s"', numScan, file)
end