Skip to content

Commit

Permalink
work on build system
Browse files Browse the repository at this point in the history
  • Loading branch information
stestoll committed Mar 31, 2024
1 parent be04205 commit fc3bd91
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 389 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Propose and discuss any new functionality first in an [issue](https://github.com
Currently, there are no formal coding style guidelines. Check out the existing code base to get an idea of how to write code. A few principles are worth mentioning:

- The main criterion for code is readability. Don't sacrifice that for performance. Prefer simple over complicated data structures. Avoid crytpic code.
- Write code such that it runs in MATLAB R2017a. Don't use more recent MATLAB features.
- Write code such that it runs in MATLAB R2021b. Don't use more recent MATLAB features.
- Use 2-space indents, instead of 4-space indents. This is because some EasySpin functions are deeply nested.
- Use variable names that are explicit, but not too long. USe camelCase instead of snake_case.
- Add a judicious amount of white space and empty line to make the code readable.
Expand Down
2 changes: 1 addition & 1 deletion docsrc/installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div class="subtitle" style="margin-top:0ex;">Requirements</div>

<p>
<i>EasySpin</i> requires MATLAB 9.2 (R2017a) or later on either Windows, Linux or Mac. EasySpin is not guaranteed to run on MATLAB versions older than R2017a.
<i>EasySpin</i> requires MATLAB 9.11 (R2021b) or later on either Windows, Linux or Mac. EasySpin is not guaranteed to run on MATLAB versions older than R2021b.
Beyond a basic MATLAB installation, no additional MATLAB toolboxes are needed to run <i>EasySpin</i>. <i>EasySpin</i> does not run on Octave (a free MATLAB clone).
</p>

Expand Down
50 changes: 25 additions & 25 deletions easyspin/easyspinupdate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
% release branch (stable or development)
% easyspinupdate('5.2.22') downloads specific EasySpin version

function easyspinupdate(OnlineVersion)
function easyspinupdate(onlineVersion)

% ---------------------------------------------------------------
% If easyspinupdate is called without argument, a version check is run.
% If a newer version is available, easyspinupdate is called again with the
% newer version as argument.
if nargin == 0
[UpdateAvailable, OnlineVersion] = easyspinversioncheck;
[UpdateAvailable, onlineVersion] = easyspinversioncheck;
if UpdateAvailable
easyspinupdate(OnlineVersion);
easyspinupdate(onlineVersion);
end
return
end

if all(isstrprop(OnlineVersion,'alpha'))
InstalledVersion = easyspin('info');
UpdateOpt.Branch = OnlineVersion;
if all(isstrprop(onlineVersion,'alpha'))
installedVersion = easyspin('info');
UpdateOpt.Branch = onlineVersion;
UpdateOpt.Silent = true;
[~, OnlineVersion] = easyspinversioncheck(InstalledVersion,UpdateOpt);
if isempty(OnlineVersion)
[~, onlineVersion] = easyspinversioncheck(installedVersion,UpdateOpt);
if isempty(onlineVersion)
msg = [UpdateOpt.Branch ' is not a valid branch name.'];
disp(msg)
return
Expand Down Expand Up @@ -58,33 +58,33 @@ function easyspinupdate(OnlineVersion)
% ---------------------------------------------------------------
% Download and install

VersionToGet = OnlineVersion;
versionToGet = onlineVersion;

% Determine installation path of currently installed EasySpin
InstalledVersion = easyspin('info');
InstallationPath = InstalledVersion.Root;
installedVersion = easyspin('info');
installationPath = installedVersion.Root;

% The installation target is two directories above the easyspin functions:
Path = strsplit(InstallationPath,filesep);
InstallationPath = join(Path(1:end-2),filesep);
InstallationPath = InstallationPath{1};
Path = strsplit(installationPath,filesep);
installationPath = join(Path(1:end-2),filesep);
installationPath = installationPath{1};

% Before downloading, check if the previous installation is in a write
% protected directory
fileName = join([InstallationPath "easyspininstalltest.txt"],filesep);
fileName = join([installationPath "easyspininstalltest.txt"],filesep);
[fid,errmsg] = fopen(fileName, 'w');
if ~isempty(errmsg)
error(['The EasySpin installation directory (' InstallationPath ') appears to be write protected. Please move EasySpin to a different directory and retry update or manually install the new EasySpin version.']);
error(['The EasySpin installation directory (' installationPath ') appears to be write protected. Please move EasySpin to a different directory and retry update or manually install the new EasySpin version.']);
else
fclose(fid);
delete(fileName);
fclose(fid);
delete(fileName);
end

OldPath = join(Path(1:end-1),filesep);
OldPath = OldPath{1};
oldPath = join(Path(1:end-1),filesep);
oldPath = oldPath{1};

disp(['Downloading EasySpin version (' VersionToGet ')']);
zipName = ['easyspin-' VersionToGet '.zip'];
disp(['Downloading EasySpin version (' versionToGet ')']);
zipName = ['easyspin-' versionToGet '.zip'];

% set time out to 60 seconds
options = weboptions('Timeout',60);
Expand All @@ -107,21 +107,21 @@ function easyspinupdate(OnlineVersion)
disp('Installing...');

% unzip to destination
Destination = [InstallationPath filesep];
Destination = [installationPath filesep];
unzip(zipFile,Destination);

% remove downloaded zip
delete(zipFile);

% ---------------------------------------------------------------
% Add to Path and clean up
newESPath = [Destination 'easyspin-' VersionToGet filesep 'easyspin' filesep];
newESPath = [Destination 'easyspin-' versionToGet filesep 'easyspin' filesep];

if exist(newESPath,'dir')
addpath(newESPath);
savepath
msg = ['EasySpin was succesfully installed to ' newline newESPath newline 'and added to the MATLAB search paths.' newline];
msg = [msg 'For optimal perfomance, your should remove EasySpin installation (' OldPath ') from the MATLAB search paths and delete the folder from your system.'];
msg = [msg 'For optimal perfomance, your should remove EasySpin installation (' oldPath ') from the MATLAB search paths and delete the folder from your system.'];
disp(msg);
else
errMsg = ['EasySpin was succecsfully downloaded to ' newline newESPath newline];
Expand Down
32 changes: 16 additions & 16 deletions easyspin/easyspinversioncheck.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@

if nargin == 2 && isfield(Opt,'Branch')
ReleaseChannel = Opt.Branch;
InstalledVersion = '0.0.0';
installedVersion = '0.0.0';
else
ReleaseChannel = VersionInfo.ReleaseChannel;
InstalledVersion = VersionInfo.Version;
installedVersion = VersionInfo.Version;
end

% stop looking for an update if EasySpin is on source control
Expand All @@ -112,28 +112,28 @@

matchVersioning = '(\d+).(\d+).(\d+)-?([a-z]+)?.?(\d+)?';

VersionInfo = regexp(InstalledVersion,matchVersioning,'tokens');
VersionInfo = regexp(installedVersion,matchVersioning,'tokens');

if isempty(VersionInfo)
error('Error polling currently installed version')
error('Error determining currently installed EasySpin version.')
else
VersionInfo = VersionInfo{:};
end

InstalledVersion = convertVersionNumber(VersionInfo);
installedVersion = convertVersionNumber(VersionInfo);

% Get online versions and put them into a structure
%--------------------------------------------------------------
msg = 'Checking for a new version...';
if messages; disp(msg); end
if messages, disp(msg); end

if ~testing
VersionsFile = websave('versions.txt','http://easyspin.org/easyspin/versions.txt');
versionsInfoFile = websave('versions.txt','http://easyspin.org/versions.txt');
else
VersionsFile = './data/versions.txt';
versionsInfoFile = './data/versions.txt';
end

fileID = fopen(VersionsFile,'r');
fileID = fopen(versionsInfoFile,'r');

expression = ['([a-z]+):' matchVersioning];
tline = fgetl(fileID);
Expand All @@ -142,21 +142,21 @@
V = regexp(tline,expression,'tokens');
if ~isempty(V)
V = V{:};
[OnlineVersions.(V{1}).Numeric, OnlineVersions.(V{1}).String] = convertVersionNumber(V(2:end));
[onlineVersions.(V{1}).Numeric, onlineVersions.(V{1}).String] = convertVersionNumber(V(2:end));
end
tline = fgetl(fileID);
end

fclose(fileID);

if ~testing
delete(VersionsFile);
delete(versionsInfoFile);
end

% Check if the releasechannel of the currently installed version (or the
% requested releasechannel) are tracked on easyspin.org
%----------------------------------------------------------
if ~isfield(OnlineVersions,ReleaseChannel)
if ~isfield(onlineVersions,ReleaseChannel)
msg = ['The release channel you are currently on - "' ReleaseChannel '" - does not support automatic updates.'];
if messages; disp(msg); end
varargout = {false []};
Expand All @@ -165,13 +165,13 @@

% Compare versions if a new version is available
%----------------------------------------------------------
OnlineVersion = OnlineVersions.(ReleaseChannel).Numeric;
onlineVersion = onlineVersions.(ReleaseChannel).Numeric;

% Subtract local version from online version. Any version numbers of the
% local installation that are larger than the online versions, are
% negative. If online and local version are idential, Diffs is a vector of
% zeros.
Diffs = OnlineVersion - InstalledVersion;
Diffs = onlineVersion - installedVersion;

% if both versions arent identical, Diffs contains nonzero elements
if any(Diffs > 0) && any(Diffs < 0)
Expand All @@ -193,15 +193,15 @@
end

if UpdateAvailable
msg = ['A new EasySpin version (' OnlineVersions.(ReleaseChannel).String ') is available online.' newline];
msg = ['A new EasySpin version (' onlineVersions.(ReleaseChannel).String ') is available online.' newline];
msg = [msg 'Type and run "easyspinupdate" to update.'];
else
msg = 'You are using the most recent version of EasySpin.';
end
if messages; disp(msg); end

if nargout > 0
varargout = {UpdateAvailable OnlineVersions.(ReleaseChannel).String};
varargout = {UpdateAvailable onlineVersions.(ReleaseChannel).String};
end

function [VersionArray, VersionString] = convertVersionNumber(VersionInfo)
Expand Down
16 changes: 1 addition & 15 deletions easyspin/eprconvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
esguimain(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end

% --- Executes just before eprconvert is made visible.
function eprconvert_OpeningFcn(hObject, eventdata, handles, varargin)
Expand Down Expand Up @@ -59,7 +58,6 @@ function eprconvert_OpeningFcn(hObject, eventdata, handles, varargin)

% UIWAIT makes eprconvert wait for user response (see UIRESUME)
% uiwait(handles.eprconvert);
end

% --- Outputs from this function are returned to the command line.
function varargout = eprconvert_OutputFcn(hObject, eventdata, handles)
Expand Down Expand Up @@ -137,7 +135,6 @@ function ComputegButton_Callback(hObject, eventdata, handles)
handles.gVal = planck*handles.FreqSI/bmagn/handles.FieldSI;
guidata(handles.eprconvert,handles);
UpdateDisplay(handles);
end

function ComputeFreqButton_Callback(hObject, eventdata, handles)
if isempty(handles.FieldSI)
Expand All @@ -151,7 +148,6 @@ function ComputeFreqButton_Callback(hObject, eventdata, handles)
handles.FreqSI = bmagn*handles.gVal*handles.FieldSI/planck;
UpdateDisplay(handles);
guidata(handles.eprconvert,handles);
end

%function FieldList_CreateFcn(hObject, eventdata, handles)
%function FieldList_Callback(hObject, eventdata, handles)
Expand All @@ -168,7 +164,6 @@ function ComputeFreqButton_Callback(hObject, eventdata, handles)
case 'cm^-1', prefactor = 100*clight;
case 'eV', prefactor = planck/echarge;
end
end

function [Unit,prefactor] = GetFieldUnit(handles)
UnitStr = get(handles.FieldUnits,'String');
Expand All @@ -180,27 +175,22 @@ function ComputeFreqButton_Callback(hObject, eventdata, handles)
case 'G', prefactor = 1e-4;
case 'kG', prefactor = 1e-1;
end
end

function Freq = GetFreqInSIUnits(handles)
Freq = str2num(get(handles.FreqEdit,'String'));
[Unit,prefactor] = GetFreqUnit(handles);
Freq = prefactor*Freq;
end

function Field = GetFieldInSIUnits(handles)
Field = str2num(get(handles.FieldEdit,'String'));
[Unit,prefactor] = GetFieldUnit(handles);
Field = prefactor*Field;
end

function g = GetgValue(handles)
g = str2num(get(handles.gEdit,'String'));
end

function SetgVal(g,handles)
set(handles.gEdit,'String',sprintf('%g',g));
end

%---------------------------------------------------------------
function UpdateDisplay(handles)
Expand Down Expand Up @@ -234,7 +224,6 @@ function UpdateDisplay(handles)

g = handles.gVal;
set(handles.gEdit,'String',sprintf('%g',g));
end

% --- Executes on button press in ClearButton.
function ClearButton_Callback(hObject, eventdata, handles)
Expand All @@ -244,7 +233,6 @@ function ClearButton_Callback(hObject, eventdata, handles)
handles.gVal = [];
UpdateDisplay(handles);
guidata(handles.eprconvert,handles);
end

% --- Executes on button press in WbandButton.
function WbandButton_Callback(hObject, eventdata, handles)
Expand All @@ -255,7 +243,7 @@ function WbandButton_Callback(hObject, eventdata, handles)
handles.FreqSI = 94e9;
UpdateDisplay(handles);
guidata(handles.eprconvert,handles);
end

% --- Executes on button press in QbandButton.
function QbandButton_Callback(hObject, eventdata, handles)
% hObject handle to QbandButton (see GCBO)
Expand All @@ -265,7 +253,6 @@ function QbandButton_Callback(hObject, eventdata, handles)
handles.FreqSI = 34e9;
UpdateDisplay(handles);
guidata(handles.eprconvert,handles);
end

% --- Executes on button press in XbandButton.
function XbandButton_Callback(hObject, eventdata, handles)
Expand All @@ -276,4 +263,3 @@ function XbandButton_Callback(hObject, eventdata, handles)
handles.FreqSI = 9.8e9;
UpdateDisplay(handles);
guidata(handles.eprconvert,handles);
end
23 changes: 15 additions & 8 deletions easyspin/eschecker.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@
error('At most one output argument is possible.');
end

% Version and expiry date settings
esVersion = '$ReleaseID$';
expiryDate = '$ExpiryDate$'; % Installed version is not valid after ExpiryDate.

% Determine whether this function has been called by an EasySpin function
ESfilenames = {'cardamom','chili','curry','esfit','garlic','pepper','saffron','salt','spidyan'};
EasySpinFilenames = {'cardamom','chili','curry','esfit','garlic','pepper','saffron','salt','spidyan'};
db = dbstack;
internalCall = numel(db)>=2 && any(strcmp(db(2).name,ESfilenames));
internalCall = numel(db)>=2 && any(strcmp(db(2).name,EasySpinFilenames));


% Version and expiry date settings
%-------------------------------------------------------------------------------
persistent esVersion expiryDate
if isempty(esVersion)
info = easyspin_info;
esVersion = info.Version;
expiryDate = info.ExpiryDate;
end


% Don't check at every iteration
Expand All @@ -46,6 +52,7 @@
end
end


% Check for expiry
%-------------------------------------------------------------------------------
isUnpackaged = esVersion(1)=='$';
Expand Down Expand Up @@ -91,9 +98,9 @@
varargout = {err};
else
if isUnpackaged
fprintf('Your EasySpin installation is valid. It is unpackaged.');
fprintf('Your EasySpin installation is valid.\nIt is unpackaged.\n');
elseif versionOK
fprintf('Your EasySpin installation is valid. It will expire in %d days.\n',daysToExpiry);
fprintf('Your EasySpin installation is valid.\nIt expires in %d days.\n',daysToExpiry);
else
disp(err);
end
Expand Down
Loading

0 comments on commit fc3bd91

Please sign in to comment.