Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikPGJ committed Mar 12, 2024
1 parent db7c5b0 commit 4c7e5b4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
3 changes: 3 additions & 0 deletions irf.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
% version = IRF('version') return IRF version number
% [versionNumber, versionDate] = IRF('version') return also date
%
% [out] = IRF('path') returns the path to the current irfu-matlab root
% directory.
%
% IRF('demo') demonstration how to use IRF

%this is an edit to load BLAS
Expand Down
10 changes: 8 additions & 2 deletions irf/+irf/+cdf/datevec_to_TT2000.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
%
function tt2000 = datevec_to_TT2000(dateVecUtc)
% PROPOSAL: Separate wrapper function to handle spdfcomputett2000 special case.

% PROPOSAL: Make handle failed conversions when spdfcomputett2000 returns a too low value.
% ~CON: spdfcomputett2000 already returns special value.
%
% PROPOSAL: Refactor to take datetime as argument.
% PRO: More standard time format.
% PRO: The only (irfu-matlab) applications so far effectively use datetime as
% argument for this function. /2024-03-05
% PRO: Already easy to convert between datetime and date vector.
% NOTE: Might want to similarily convert irf.cdf.TT2000_to_datevec().

irf.assert.sizes(dateVecUtc, [NaN,6])
irf.assert.sizes(dateVecUtc, [NaN, 6])

% IMPLEMENTATION NOTE: Using integer precision is good for automatic testing
% (empirically it is needed for predictable, reversible results).
Expand Down
2 changes: 1 addition & 1 deletion irf/+irf/+cdf/write_dataobj.m
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function write_dataobj(filePath, ...

%============================================================================
% Convert specific VariableAttributes values
%
% ------------------------------------------
% Case 1: tt2000 values as UTC strings : Convert to tt2000.
% Case 2: All other : Convert to the zVariable data type.
% --------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion irf/+irf/+utils/mixed_radix.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
% Ex: Can interpret [seconds, milliseconds, microseconds, nanoseconds] as used
% by the spdf* TT2000 functions.
%
% See e.g. https://en.wikipedia.org/wiki/Mixed_radix .
%
%
% NOTES
% =====
Expand All @@ -21,7 +23,7 @@
%
% CONVENTIONS
% ===========
% MRD = Mixed Radix Digits, i.e. the digits in mixed radix number.
% MRD = Mixed Radix Digits, i.e. the digits in a mixed radix number.
% --
% iDigit=1 <==> Least significant digit.
% NOTE: This means that digits are in the opposite order to what is
Expand Down
37 changes: 22 additions & 15 deletions mission/solar_orbiter/solo_local_file_db.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ function list_sci_tint()
t.min = str2double(utc(15:16));
t.sec = str2double(utc(18:end-1));
end

function limited_sci_list()
listingD = dir([fullfile(curDir, dPref) '*.cdf']); % SolO have only latest file of each type.
listingD = dir([fullfile(curDir, dPref) '*.cdf']); % SolO directories only have the latest version datasets (files).

if isempty(listingD), return, end
if isempty(dateFormat)
% Are we looking for files with 8 or the full 14 digits
Expand Down Expand Up @@ -190,13 +192,14 @@ function list_sci()
end
end
end % LIST_SCI

%% ADD2LIST_SCI
function add2list_sci(name,curDir)
Entry = struct('name', name, 'ver', str2double(name(end-5:end-4)), ...
'start',[], 'stop',[],...
'path', curDir, 'dbId', obj.id);
Entry = add_ss(Entry);
% Check time limits of the file
% Check if time range in file is within specified time limits.
if isempty(Entry) || ~isempty(tint) && ...
(Entry.start>tint.stop || Entry.stop<tint.start)
return
Expand All @@ -211,6 +214,7 @@ function add2list_sci(name,curDir)
if is_version_larger(str2double(name(end-5:end-4)), fileList(iSame).ver)
fileList(iSame) = add_ss(Entry); % replace file
end

function entry = add_ss(entry)
entryTmp = obj.cache.get_by_key(entry.name);
if ~isempty(entryTmp)
Expand All @@ -230,25 +234,28 @@ function add2list_sci(name,curDir)
errS = ['Cannot read: ' entry.path filesep entry.name];
irf.log('critical',errS), error(errS)
end

% Search for TT2000-typed zVariables in CDF.
isCdfEpochTT2000VariableArray=cellfun(@(x) strcmpi(x,'tt2000'), info.Variables(:,4));
if ~any(isCdfEpochTT2000VariableArray)
errS = ['no TT2000 vars in:' entry.path filesep entry.name];
irf.log('critical',errS), error(errS)
end
iVar = find(isCdfEpochTT2000VariableArray,1);
data = spdfcdfread([entry.path filesep entry.name], ...
'Variables', info.Variables(iVar,1), 'CombineRecords', true, ...

iTt2000Var = find(isCdfEpochTT2000VariableArray,1);
varData = spdfcdfread([entry.path filesep entry.name], ...
'Variables', info.Variables(iTt2000Var,1), 'CombineRecords', true, ...
'KeepEpochAsIs', true, 'DataOnly', true);
if ispc
% Add a very short delay to ensure consecutive files are not
% accessed TOO quickly as this may cause Matlab to experince a
% hard crash on Win10 regardless of the try&catch.
pause(0.0001);
end
if isempty(data), entry = []; return, end
entry.start = EpochTT(data(1));
entry.stop = EpochTT(data(end));
% add to cache
if isempty(varData), entry = []; return, end
entry.start = EpochTT(varData(1));
entry.stop = EpochTT(varData(end));
% Add to cache
entryTmp.start = entry.start; entryTmp.stop = entry.stop;
entryTmp.vars = info.Variables;
obj.cache.add_entry(entry.name, entryTmp);
Expand Down Expand Up @@ -306,33 +313,33 @@ function add2list_sci(name,curDir)

temp = strsplit(C{3}, '-');
instrument = temp{1};
dbRoot = obj.dbRoot;
dbRootDir = obj.dbRoot;

if strcmp(instrument, 'rpw')
%==============================
% CASE: Searching for RPW data
%==============================
if exist(fullfile(dbRoot, 'latest'), 'dir')
if exist(fullfile(dbRootDir, 'latest'), 'dir')
% CASE: obj.dbRoot has subdirectory "latest/".
% ==> Use RPW BIAS data (L2, L3) processed at IRFU.
%
% Ex: obj.dbRoot == /data/solo/data_irfu/
% ==> /data/solo/data_irfu/latest/rpw/

rDir = fullfile(dbRoot, 'latest', 'rpw');
rDir = fullfile(dbRootDir, 'latest', 'rpw');
else
% CASE: obj.dbRoot DOES NOT have subdirectory "latest/".
% ==> Use RPW data (all subsystems) mirrored from ROC/LESIA.
%
% Ex: obj.dbRoot == /data/solo/
% ==> /data/solo/remote/data/
rDir = fullfile(dbRoot, 'remote', 'data');
rDir = fullfile(dbRootDir, 'remote', 'data');
end
else
%==================================
% CASE: Searching for non-RPW data
%==================================
rDir = fullfile(dbRoot, 'soar', instrument);
rDir = fullfile(dbRootDir, 'soar', instrument);
if exist(rDir, 'dir')
% CASE: obj.dbRoot has subdirectory "soar".
% ==> Use (presumed) SOAR mirror.
Expand All @@ -342,7 +349,7 @@ function add2list_sci(name,curDir)
return
end

rDir = fullfile(dbRoot, instrument);
rDir = fullfile(dbRootDir, instrument);
if exist(rDir, 'dir')
% CASE: obj.dbRoot has subdirectory named after instrument.
% ==> obj.dbRoot is a general folder for (multiple) non-RPW
Expand Down

0 comments on commit 4c7e5b4

Please sign in to comment.