%% Demonstration: handling input and corresponding output in databases

%% Cleanup
% The database files are removed for a clean demonstration in the following
% sections.
myPath = fileparts(mfilename('fullpath'));
warning off MATLAB:DELETE:FileNotFound
delete([myPath filesep 'database' filesep 'fileList.matx']);
delete([myPath filesep 'data' filesep 'fileList.matx']);
delete([myPath filesep 'data' filesep '*.mat']);
warning on MATLAB:DELETE:FileNotFound

%% Initialize and view database
% In the first command, we initialize the database, while the available
% options are printed to screen as it is called without return arguments.
generateExampleData('init')

%%
% In the second command, the cases are returned in a struct array.
caseList = generateExampleData;
caseList(1),caseList(2)

%%
% To view possible options quickly, we can just call the function without
% arguments:
generateExampleData

%% Generate and load data
% The first call to both cases take some time to be calculated:
tic
data = generateExampleData('functionStruct');
data = generateExampleData('functionScript');
timeTaken = toc

%%
% But now, any subsequent calls are fast:
tic
data = generateExampleData('functionStruct');
data = generateExampleData('functionScript');
timeTaken = toc

%%
% And we still have the possibility to enforce the recalculation of the
% data. In this case, we have a field 'answer' filled with random data.
data=generateExampleData('functionStruct');
disp(data.answer);
%%
data=generateExampleData('functionStruct', 1);
disp(data.answer);
