diff --git a/+PlotID/@config/config.m b/+PlotID/@config/config.m new file mode 100644 index 0000000000000000000000000000000000000000..e3a5ed487d5b2e51af1de5c81fadb772a3e44bdf --- /dev/null +++ b/+PlotID/@config/config.m @@ -0,0 +1,70 @@ +classdef config < handle + %CONFIG class handles methoths and attributes related to the config + %file + % Detailed explanation goes here + % handle class used for dynamicy property updates + + properties (SetAccess = protected) + configData + configFileName + end + + methods + function obj = config(configFileName) + %CONFIG Construct an instance of this class + % Detailed explanation goes here + obj.configFileName = configFileName; + try + txt = fileread(obj.configFileName); + obj.configData = jsondecode(txt); + checkConfig(obj); + catch + msg = ['no valid config File with the filename ',... + obj.configFileName, ' found.' newline,... + 'Please enter the required information manually']; + disp(msg); + obj.configData = obj.wizard('initilise'); + m = input('Do you want to save the config, Y/N [Y]:','s'); + if ismember(m,{'Y','y'}) + obj.writeConfig(fullfile(pwd)); + end + end%try + + end + + function outputArg = checkConfig(obj) + %checkConfig validates the config file + % TODo; + outputArg = true; + end + + function writeConfig(obj,path) + %writeConfig writes the config file to path + % TODo; + fid = fopen(fullfile(path,obj.configFileName),'w'); + txt = jsonencode(obj.configData,'PrettyPrint',true); + %fprintf does not write paths correctly !!! + fwrite(fid,txt); + fclose(fid); + end + + function configData = addPublishOptions(obj,mode) + %writeConfig writes the config file to path + % TODo; + obj.configData.options = obj.plotID_options(mode); + end + + function outputArg = method1(obj,inputArg) + %METHOD1 Summary of this method goes here + % Detailed explanation goes here + outputArg = obj.Property1 + inputArg; + end + + end + + methods (Static) + configStruct = wizard(mode) + optionStruct = plotID_options(input) + end +end + diff --git a/+PlotID/@config/plotID_options.m b/+PlotID/@config/plotID_options.m new file mode 100644 index 0000000000000000000000000000000000000000..235f1cb791ef0484873d32a2883aae5daf387406 --- /dev/null +++ b/+PlotID/@config/plotID_options.m @@ -0,0 +1,28 @@ +function [options] = plotID_options(input) +%PLOTID_OPTIONS Summary of this function goes here +% Detailed explanation goes here + +options = struct(); +switch input + case 'default' %same as Arguments Block + options.Location = 'local'; % storage path + options.Method = 'individual'; + options.ParentFolder = 'export'; + options.ConfigFileName = 'config.json';%individual config names possible + options.CopyUserFCN = true; + options.CSV = false; + options.ShowMessages = true; + options.ForcePublish = false; %publish anyway + case 'debug' + options.Location = 'local'; % storage path + options.Method = 'individual'; + options.ParentFolder = 'export'; + options.ConfigFileName = 'config.json';%individual config names possible + options.CopyUserFCN = true; + options.CSV = true; + options.ShowMessages = true; + options.ForcePublish = true; %publish anyway +end + +end + diff --git a/+PlotID/@config/wizard.m b/+PlotID/@config/wizard.m new file mode 100644 index 0000000000000000000000000000000000000000..de66181d95c25c8d3efa4d06e2e693c28f8bdfbc --- /dev/null +++ b/+PlotID/@config/wizard.m @@ -0,0 +1,39 @@ +function config = wizard(mode) +%wizard creates config files depending on the selected mode +% initilise ask only for the input that is neccessary to run plotID + +config = struct(); +switch mode + case 'initilise' + config.Author = inputRequired('your Name'); + config.ProjectID = inputRequired('your Project Number'); + + msg = ['Do you want to add a remote path?' newline,... + 'Otherwise your files will be stored locally.' newline,... + 'You can add this later by rerunning the initilisation.']; + disp(msg); + m = input('Do you want add a remothe path, Y/N [Y]:','s'); + + if ismember(m,{'Y','y'}) + config.ServerPath = uigetdir(); + end + otherwise + error('wizard mode undefined in CLASS config'); +end %switch + +end + +function usrTxt = inputRequired(msg) +%Input Dialog that repeats if left empty +inputRequired = true; +while inputRequired + prompt = ['Please enter ', msg , ':']; + inpt = input(prompt,'s'); + if isempty(inpt) + disp('Input must not be empty!'); + else + usrTxt = inpt; + inputRequired = false; + end +end +end \ No newline at end of file diff --git a/+PlotID/Publish.m b/+PlotID/Publish.m index 6cf46238f927923222082a086d4c50fdcf3df9b5..02a1e36db925f7b284d2d283ac2d1fa13cb68df7 100644 --- a/+PlotID/Publish.m +++ b/+PlotID/Publish.m @@ -67,16 +67,24 @@ if isempty(ID) warning(msg); end +%% read config file +% there is only one config Object (handleClass) +configObj = PlotID.config(options.ConfigFileName); +if isfield(configObj.configData, 'options') + % is working but prune to user errors + options = configObj.configData.options; +end +% try +% txt = fileread('config.json'); +% config = jsondecode(txt); +% catch +% dlgObj.configError = true; +% end + + % Error and MSG handeling dlgObj = PlotID.userDLG(ID,options); -%% read config file -try - txt = fileread('config.json'); - config = jsondecode(txt); -catch - dlgObj.configError = true; -end %% storage location switch options.Location @@ -183,26 +191,38 @@ dlgObj.rdFilesPublished = status; dlgObj.userMSG(msg); %% Write Config File -if ~dlgObj.configError %config File must exist - % copy config file - configPath = PlotID.createFileCopy('config.json',folderName,... - storPath,ID, 'data'); -else - configPath = fullfile(storPath,folderName,'config.json'); - config = struct(); - if ispc - config.author = getenv('USERNAME'); - end -end +exportPath = fullfile(storPath,folderName); +configObj.writeConfig(exportPath); + +% if ~dlgObj.configError +% % copy config file +% configPath = PlotID.createFileCopy('config.json',folderName,... +% storPath,ID, 'data'); +% else +% %create config file +% configPath = fullfile(storPath,folderName,'config.json'); +% config = options; +% end +% %write config +% fid = fopen(char(configPath),'w'); +% txt = jsonencode(config,'PrettyPrint',true); +% fprintf(fid,txt); +% fclose(fid); + % add further Metadata -config.ProjectID = ID; -config.CreationDate = datestr(now); -config.MatlabVersion = version; -config.ToolboxVersions = pList; +meta =struct(); +if ispc + meta.author = getenv('USERNAME'); +end +meta.ProjectID = ID; +meta.CreationDate = datestr(now); +meta.MatlabVersion = version; +meta.ToolboxVersions = pList; -%write config -fid = fopen(char(configPath),'w'); -txt = jsonencode(config,'PrettyPrint',true); +% write meta +metaPath = fullfile(storPath,folderName,'plotID_data.json'); +fid = fopen(char(metaPath),'w'); +txt = jsonencode(meta,'PrettyPrint',true); fprintf(fid,txt); fclose(fid); diff --git a/+PlotID/TagPlot.m b/+PlotID/TagPlot.m index 439a20ec2b1a9a89648d85f760ca4e70a9cbae85..b925379f4a5a8a23f5b37d802d0edc61eda0bf4f 100644 --- a/+PlotID/TagPlot.m +++ b/+PlotID/TagPlot.m @@ -19,25 +19,14 @@ arguments options.Location (1,:) {mustBeText} = 'east' options.DistanceToAxis {mustBeReal} = .01 % relative distance options.Position (1,2) {mustBeVector} = [1,0.4] % default for east - options.Rotation (1,1) {mustBeReal} = NaN + options.Rotation (1,1) {mustBeReal} = NaN + options.ConfigFileName (1,:) {mustBeText} = 'config.json' end if isempty(options.ProjectID) - try - txt = fileread('config.json'); - config = jsondecode(txt); - catch - config =struct; - config.ProjectID = ''; - warning("No ProjectID was definded and no config.json could be found"); - - end - - if ~isempty(config.ProjectID) - options.ProjectID = config.ProjectID; - else - warning('no project options.ProjectID defined') - end + configObj = PlotID.config(options.ConfigFileName); + configData = configObj.configData; + options.ProjectID = configData.ProjectID; end switch options.Location diff --git a/+PlotID/initilise.m b/+PlotID/initilise.m new file mode 100644 index 0000000000000000000000000000000000000000..4f893441299d085fa8f5a06fbd4dc36b105df04c --- /dev/null +++ b/+PlotID/initilise.m @@ -0,0 +1,7 @@ +function [status] = initilise() +%INITILISE Initilisation for first time úsage + + + +end + diff --git a/+PlotID/removePltIdFiles.m b/+PlotID/removePltIdFiles.m index 942b216565c78516978c4dc507eed7e3e2d1c2c5..169990d0f7e6f6d99b73f1b5d91c8454b9cf9a65 100644 --- a/+PlotID/removePltIdFiles.m +++ b/+PlotID/removePltIdFiles.m @@ -8,8 +8,18 @@ names = strcat(names, ext); % add ext for comparison % Get a list of all .m files that are part of Plot id packageContent = what('PlotID'); % packageContent.classes has no extensions -PltID_flist = [packageContent.m; strcat(packageContent.classes,'.m')]; +PltID_classlist = packageContent.classes; +% Class Methods need to be listed in an additional function +Class_flist = cell(1,numel(packageContent.classes)); %preallocate +for i=1:numel(packageContent.classes) + temp = what(['PlotID',filesep,'@',PltID_classlist{i}]); + Class_flist{i} = temp.m; +end + +Class_flist = vertcat(Class_flist{:}); +% all plotID .m files: +PltID_flist = [packageContent.m; Class_flist]; % Comparison and filter fListClean = fList(~ismember(names,PltID_flist)); end diff --git a/Initialisation.m b/Initialisation.m new file mode 100644 index 0000000000000000000000000000000000000000..97835f3364ac842e857a021953fa2f2c632fd38e --- /dev/null +++ b/Initialisation.m @@ -0,0 +1,29 @@ +%% This is the PlotID Initialisation file +% Please run this script before using PlotID + +%% Step 1: Add plotID location to you MATLAB path +% This is necessary to use PlotID in your personal MATLAB Scripts +addpath(pwd); +savepath; + +%% Section 2 Config File +% To make things easy, you should use the config file. The following wizard +% will help you create one: +writeConfig = true; + +% Ask User if current config should be overwritten +if isfile('config.json') + m = input('Do you want to overwrite the current config file, Y/N [Y]:','s'); + writeConfig = ismember(m,{'Y','y'}); +end + +if writeConfig + config = PlotID.config.wizard('initilise'); + fid = fopen('config.json','w'); + txt = jsonencode(config,'PrettyPrint',true); + fwrite(fid,txt); + fclose(fid); +end + +%% +disp('Initialisition done.') diff --git a/PlotID_Demo.m b/PlotID_Demo.m deleted file mode 100644 index 766ad17cfb60feb31820c5382e61b6f3cc7d413b..0000000000000000000000000000000000000000 --- a/PlotID_Demo.m +++ /dev/null @@ -1,74 +0,0 @@ -%% Example Script -% This Script is meant to demonstrate the capabilities of the PlotID tool. - -%% Clear Environment -clear; clc; close all; -addpath('CI_files'); % Test scripts -try - delete testdata2.h5; -end - -%% Set ProjectID -% ProjectID can also be set in the config file -% Leave empty for using the ID from the config file -ProjectID = 'FST01'; - -%% Data -% Creating Random Data to use as data-file -x = linspace(0,7); -y = rand(1,100)+2; -dataset1 = 'test_data.mat'; -% use absolute paths for good practise -dataset1 = fullfile(pwd, dataset1); -save(dataset1,'x','y'); - -% some data as .h5 -x1 = linspace(0,2*pi); -y1 = sin(x1)+.5*sin(2*x1)+2; - -% define file path & name - -fpath = fullfile(pwd,"./testdata2.h5"); -dataset2 = fullfile(pwd,'testdata2.h5'); - -% create hdf5 file and dataset > write data to hdf5 file / dataset -h5create(fpath, "/x1", size(x1), "Datatype", class(x1)) -h5create(fpath, "/y1", size(y1), "Datatype", class(y1)) -h5write(fpath, "/x1", x1) -h5write(fpath, "/y1", y1) - -%% Plotting -% This is still part of a normal script to produce plots. -% Make sure to save each figure in a variable to pass to PlotID-functions. -fig(1) = figure; -set(gcf,'Units','centimeters','PaperUnits','centimeters','PaperSize',[9 7],... -'Position',[5 5 9 7]); -plot(x,y,'Color',0.5*[1 1 1]); -box off; hold on; -plot(x1,y1,'-k'); -set(gca, 'TickDir', 'out', 'YLim', [0,4],'YTick',[0:1:4],'XLim',[0,6]); -%fstplt.setfiguresize('1/2ppt16:9'); -%fstplt.pimpplot; - -%% Example 1: single plot based on two data-sets - -%% Tag the plot -% PlotID Implementation starts here. -% TagPlot adds a visible ID to the figure(s) and to the figures property -% 'Tag' -[fig, ID] = PlotID.TagPlot(fig, 'ProjectID', ProjectID); - -%% Publishing -% Second part of plotID -% The functions needs the file location, the location of the data and the -% figure and can take several options. -path.script = mfilename('fullpath'); % filename of the m.script -% file names of the datasets -path.rdata = {dataset1,dataset2} ; % don't forget the extension - -PlotID.Publish(path, ID, fig(1), 'Location', 'local' ,'Method','individual') - - - -%% End - diff --git a/example-config.json b/example-config.json deleted file mode 100644 index 92b8621a1d43e5fc26290fa6acce3be448471d3e..0000000000000000000000000000000000000000 --- a/example-config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Author": "Example Author", - "ProjectID": "AB01", - "ServerPath": "\\\\Server\\path\\folder" -} diff --git a/example.m b/example.m index 3f86ce5b8528dd67ac5fd78664ccd2a6265391e7..b64044db476204bb46edce6332f08ddb80be7573 100644 --- a/example.m +++ b/example.m @@ -62,8 +62,8 @@ set(gca, 'TickDir', 'out', 'YLim', [0,4]); % PlotID Implementation starts here. % TagPlot adds a visible ID to the figure(s) and to the figures property % 'Tag' -[fig, ID] = PlotID.TagPlot(fig, 'ProjectID', ProjectID); - +% [fig, ID] = PlotID.TagPlot(fig, 'ProjectID', ProjectID); +[fig, ID] = PlotID.TagPlot(fig); %% Publishing % Second part of plotID % The functions needs the file location of the script, the location of the @@ -76,7 +76,7 @@ scriptPath = [mfilename('fullpath'),'.m']; %(defined above:) dataset1 = 'test_data.mat'; dataset2 = 'testdata2.h5' locations = {dataset1,dataset2} ; % don't forget the extension -locations = {string(dataset1),dataset2} +locations = {string(dataset1),dataset2}; %call publishing PlotID.Publish(locations,scriptPath, fig(1), 'Location', 'local' ,'Method','individual')