Dear Gitlab Users, for our upcoming upgrade to Gitlab v14, Gitlab will be unavailable on Thursday, 05.08.2021 from 5:00 pm to approximately 7:00 pm. Note that with v14, certain breaking changes will be introduced (https://about.gitlab.com/blog/2021/06/04/gitlab-moving-to-14-breaking-changes/).

Commit c9754628 authored by paulphilipp.meyer's avatar paulphilipp.meyer
Browse files

readSpec lists available scans and columns

parent 5dde03b4
......@@ -38,15 +38,16 @@ 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
error('Not enough input arguments: specify filepath, scan number and column');
end
if (nargin < 3)
numCols = 1;
end
if numCols > 1
numCols = numCols+1;
% this used to set the default: numCols = 1;
list_scan_variables(file, numScan)
return
end
lineStart = -1;
......@@ -92,3 +93,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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment