Skip to content

Commit

Permalink
BICAS: findread: Reorder functions/mv. read_BRVF()
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikPGJ committed Sep 5, 2024
1 parent c887303 commit 343402b
Showing 1 changed file with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,55 +65,6 @@



% Read the BRVF file and return the content.
function [biasRctPath, DtValidityBegin, DtValidityEnd] = ...
read_BRVF(rctDir, L)

rctJsonPath = fullfile(rctDir, bicas.const.BRVF_FILENAME);
irf.assert.file_exists(rctJsonPath)

L.logf('info', 'Reading "%s".', rctJsonPath)
jsonStr = fileread(rctJsonPath);
JsonStruct = jsondecode(jsonStr);

fnCa = fieldnames(JsonStruct);
assert(length(fnCa) == 1, ...
'File "%s" does not reference exactly one BIAS RCT as expected.', ...
rctJsonPath)

rctFilename = fnCa{1};
% NOTE: Renaming "start"-->"begin" since "begin" is more conventional.
validityBegin = JsonStruct.(fnCa{1}).validity_start;
validityEnd = JsonStruct.(fnCa{1}).validity_end;

%=====================================================
% Correct the RCT filename returned from jsondecode()
%=====================================================
% IMPLEMENTATION NOTE: jsondecode() stores the filename in a struct field
% name, but struct field names do not permit all characters (such as dash
% and period) and replaces them with underscore instead. Must therefore
% correct the filename string using knowledge of legal RCT filenames
% (sigh...).
%
% Ex: solo_CAL_rpw-bias_20200210-20991231_V01.cdf
% ^ ^ ^
rctFilename(end-3) = '.';
%
iDsiDash = strfind(bicas.const.RCT_DSI, '-');
assert(isscalar(iDsiDash))
rctFilename(iDsiDash) = '-';
%
assert(strcmp(rctFilename(27), '_'))
rctFilename(27) = '-';

% Construct return values.
biasRctPath = fullfile(rctDir, rctFilename);
DtValidityBegin = datetime(validityBegin, 'TimeZone', 'UTCLeapSeconds');
DtValidityEnd = datetime(validityEnd, 'TimeZone', 'UTCLeapSeconds');
end



% (1) Load one BIAS RCT using the BRVF, and
% (2) load one non-BIAS RCT by only using assumptions on filenames (and
% directory).
Expand Down Expand Up @@ -233,6 +184,55 @@



% Read the BRVF file and return the content.
function [biasRctPath, DtValidityBegin, DtValidityEnd] = ...
read_BRVF(rctDir, L)

rctJsonPath = fullfile(rctDir, bicas.const.BRVF_FILENAME);
irf.assert.file_exists(rctJsonPath)

L.logf('info', 'Reading "%s".', rctJsonPath)
jsonStr = fileread(rctJsonPath);
JsonStruct = jsondecode(jsonStr);

fnCa = fieldnames(JsonStruct);
assert(length(fnCa) == 1, ...
'File "%s" does not reference exactly one BIAS RCT as expected.', ...
rctJsonPath)

rctFilename = fnCa{1};
% NOTE: Renaming "start"-->"begin" since "begin" is more conventional.
validityBegin = JsonStruct.(fnCa{1}).validity_start;
validityEnd = JsonStruct.(fnCa{1}).validity_end;

%=====================================================
% Correct the RCT filename returned from jsondecode()
%=====================================================
% IMPLEMENTATION NOTE: jsondecode() stores the filename in a struct field
% name, but struct field names do not permit all characters (such as dash
% and period) and replaces them with underscore instead. Must therefore
% correct the filename string using knowledge of legal RCT filenames
% (sigh...).
%
% Ex: solo_CAL_rpw-bias_20200210-20991231_V01.cdf
% ^ ^ ^
rctFilename(end-3) = '.';
%
iDsiDash = strfind(bicas.const.RCT_DSI, '-');
assert(isscalar(iDsiDash))
rctFilename(iDsiDash) = '-';
%
assert(strcmp(rctFilename(27), '_'))
rctFilename(27) = '-';

% Construct return values.
biasRctPath = fullfile(rctDir, rctFilename);
DtValidityBegin = datetime(validityBegin, 'TimeZone', 'UTCLeapSeconds');
DtValidityEnd = datetime(validityEnd, 'TimeZone', 'UTCLeapSeconds');
end



% Determine the path to the RCT that should be used according to
% algorithm specified in the documentation(?). If there are multiple
% matching candidates, choose the latest one as indicated by the
Expand Down

0 comments on commit 343402b

Please sign in to comment.