Add Datastorage

This commit is contained in:
Silas
2024-10-07 09:37:55 +02:00
parent f6fa1d5c46
commit c1c53ba7db
19 changed files with 2946 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
% Script, that shows the data management routine :-)
% 1) Define all your parameters, best practice directly constructs a
% structure
params = struct;
params.D =[0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 ];
params.a =[-2 -1.8 -1.6 -1.4 -1.2 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 ];
params.chirp =[-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 ];
params.rop =[-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 ];
%wh = warehouse :-)
wh = DataStorage(params);
wh.showInfo;
wh.addStorage("ber");
%2) Simulate a bunch of data - TO BE IMPLEMENTED HERE - for now use scripts
%from Sebastian
%3) Once the simulation folder is around, specifiy path and analyze dirs
path = uigetdir('C:\Users\Silas\Documents\MATLAB\move_it_model_collection\phase_predist_imdd\save2km');
allMat = getAllFilesInFolder(path,'.mat');
allErr = getAllFilesInFolder(path,'.err');
%allMat = dir([path filesep '*.mat']);
%allErr = dir([path filesep '*.err']);
if numel(allMat) == 0
warning('You defined an empty folder. Could not locate any .mat file.')
else
fprintf('%-20s', 'Err Files:'); fprintf('%-12s', num2str(numel(allErr))); fprintf('\n');
fprintf('%-20s', 'Mat Files:'); fprintf('%-12s', num2str(numel(allMat))); fprintf('\n');
fprintf('%-20s', 'Missing Mat Files:'); fprintf('%-12s', num2str(numel(allErr)-numel(allMat))); fprintf('\n');
end
%4) Now load that data
f = waitbar(0,'Please wait...');
cnt = 0;
for num = 1:numel(allMat)
fileName = allMat(num).name;
fileFolder = allMat(num).path;
fileExt = allMat(num).ext;
matFile = load([fileFolder filesep fileName fileExt]);
matFile = matFile.saveStructTemp;
% ____________________________________
% FIND THE DATAPOINT CURRENTLY LOADED
D =matFile.common.dispersion;
a1 =matFile.common.a1;
chirp =matFile.common.chirp_alpha;
rop =matFile.common.rec_opt_pow;
ber = mean(matFile.prms_compare_state.BER);
wh.addValueToStorage(ber,'ber',D,a1,chirp,rop);
waitbar(num/numel(allMat),f,'Loading your data');
end
close(f)
% 4) Hey! the warehouse is here and (hopefully) filled with data :-)
% Create a save dialog
defaultDir = 'C:\Users\Silas\Documents\MATLAB\move_it_model_collection\';
defaultExt = '*.mat';
[filename, pathname] = uiputfile(fullfile(defaultDir, defaultExt),'', 'wh.mat');
% Check if the user pressed Cancel
if isequal(filename, 0) || isequal(pathname, 0)
disp('Save operation canceled.');
else
% Save the variable to the selected file
save(fullfile(pathname, filename), 'wh');
disp(['Variable "wh" saved to: ', fullfile(pathname, filename)]);
end
function matFileStructArray = getAllFilesInFolder(folderPath,extension)
% Get a list of all files in the current folder
currentFolderFiles = dir(fullfile(folderPath, '*'));
% Exclude '.' and '..' directories
currentFolderFiles = currentFolderFiles(~ismember({currentFolderFiles.name}, {'.', '..'}));
% Initialize the structure array for .mat files
matFileStructArray = struct('path', {}, 'name', {}, 'ext', {});
% Loop over each file in the current folder
for i = 1:length(currentFolderFiles)
currentFile = currentFolderFiles(i);
% Check if the current item is a file and has a .mat extension
if ~currentFile.isdir && endsWith(currentFile.name, extension, 'IgnoreCase', true)
% If it's a .mat file, add it to the structure array
[matFileStructArray(end + 1).path,matFileStructArray(end+1).name, matFileStructArray(end+1).ext] = fileparts(fullfile(folderPath, currentFile.name));
elseif currentFile.isdir
% If it's a directory, recursively call the function
subfolderPath = fullfile(folderPath, currentFile.name);
subfolderMatFiles = getAllFilesInFolder(subfolderPath,extension);
% Add .mat files from the subfolder to the structure array
matFileStructArray = [matFileStructArray, subfolderMatFiles];
end
end
end