Skip to content

Commit

Permalink
Reduce MATLAB boilerplate: PART III
Browse files Browse the repository at this point in the history
Issue #2 touches MF scripts. (*)

Twin commit: beddalumia/QcmP-LAB@153e87a

--------
(*) This calls for some renaming, I'll think about it.
  • Loading branch information
beddalumia committed Jan 12, 2022
1 parent 108ae8b commit 280cc8e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 134 deletions.
23 changes: 1 addition & 22 deletions KMH-MF/KMH-MF_mat/MFenergies.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

cd(whichMF);

[SOI_list, SOI_names] = get_list('SOI');
[SOI_list, SOI_names] = postDMFT.get_list('SOI');
Nlines = length(SOI_list);
phaseVAR = cell(Nlines,1);
transLine = zeros(2,Nlines);
Expand Down Expand Up @@ -116,26 +116,5 @@
surf(X,Y,Z);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Subroutines
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function [flist, strlist] = get_list(VARNAME)
%% Getting a list of variable values, from directories.
% VARNAME: a string, identifying the listed variable (e.g. 'U')
% flist: an array of float_values (e.g. U=[:] )
% strlist: an array of dir_name strings (e.g. ['U=%f'] )
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subthings = dir('.'); % Retrieves every subdir and file inside pwd
subfolders = subthings([subthings(:).isdir]); % Keeps only subfolders
subfolders = subfolders(~ismember({subfolders(:).name},{'.','..'}));
N = length(subfolders); flist = zeros(N,1); strlist = strings(N,1);
for i = 1:N
DIR = subfolders(i).name; % Let's get the indexed string...
flist(i) = sscanf(DIR, [VARNAME,'=%f']); %...and extract the value!
strlist(i) = DIR;
end
% We need to sort the lists by floats (not strings, as it is now)
[flist, sortedIDX] = sort(flist); strlist = strlist(sortedIDX);
end
26 changes: 2 additions & 24 deletions KMH-MF/KMH-MF_mat/PlotMF.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function phase_line(varID)
% Select ordpmservable
iOBS = varID; % (iOBS==0 means everything)
% Get SOI value list
[SOI_list, SOI_names] = get_list('SOI');
[SOI_list, SOI_names] = postDMFT.get_list('SOI');
Nlines = length(SOI_list);
for iSOI = 1:Nlines
lineID = SOI_names(iSOI);
Expand All @@ -52,7 +52,7 @@ function phase_map(varID)
if varID == 0
error('All ordpmservables option not allowed for phase maps!')
end
[SOI_list, SOI_names] = get_list('SOI');
[SOI_list, SOI_names] = postDMFT.get_list('SOI');
Nlines = length(SOI_list);
phaseVAR = cell(Nlines,1);
transLine = zeros(2,Nlines);
Expand Down Expand Up @@ -96,27 +96,5 @@ function phase_map(varID)
%set(gca, 'ZScale', 'log');
clc
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Subroutines
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function [flist, strlist] = get_list(VARNAME)
%% Getting a list of variable values, from directories.
% VARNAME: a string, identifying the listed variable (e.g. 'U')
% flist: an array of float_values (e.g. U=[:] )
% strlist: an array of dir_name strings (e.g. ['U=%f'] )
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subthings = dir('.'); % Retrieves every subdir and file inside pwd
subfolders = subthings([subthings(:).isdir]); % Keeps only subfolders
subfolders = subfolders(~ismember({subfolders(:).name},{'.','..'}));
N = length(subfolders); flist = zeros(N,1); strlist = strings(N,1);
for i = 1:N
DIR = subfolders(i).name; % Let's get the indexed string...
flist(i) = sscanf(DIR, [VARNAME,'=%f']); %...and extract the value!
strlist(i) = DIR;
end
% We need to sort the lists by floats (not strings, as it is now)
[flist, sortedIDX] = sort(flist); strlist = strlist(sortedIDX);
end
90 changes: 2 additions & 88 deletions KMH-MF/KMH-MF_mat/PostMF.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

% We don't have a SOI-values list, but we can obtain that by just
% inspecting the subdirectories...
[SOI_list, SOI_names] = get_list('SOI');
[SOI_list, SOI_names] = postDMFT.get_list('SOI');
Nlines = length(SOI_list);
for iSOI = 1:Nlines
SOIDIR = SOI_names(iSOI);
Expand All @@ -20,97 +20,11 @@
else
U_list = [];
end
[ids,ordpms,U_list] = extract_line(U_list); fprintf('..DONE\n');
[ids,ordpms,U_list] = postDMFT.order_parameter_line(U_list); fprintf('..DONE\n');
save('order_parameter_line.mat','ids','ordpms','U_list');
cd('..');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [flist, strlist] = get_list(VARNAME)
%% Getting a list of variable values, from directories.
% VARNAME: a string, identifying the listed variable (e.g. 'U')
% flist: an array of float_values (e.g. U=[:] )
% strlist: an array of dir_name strings (e.g. ['U=%f'] )
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subthings = dir('.'); % Retrieves every subdir and file inside pwd
subfolders = subthings([subthings(:).isdir]); % Keeps only subfolders
subfolders = subfolders(~ismember({subfolders(:).name},{'.','..'}));
N = length(subfolders); flist = zeros(N,1); strlist = strings(N,1);
for i = 1:N
DIR = subfolders(i).name; % Let's get the indexed string...
flist(i) = sscanf(DIR, [VARNAME,'=%f']); %...and extract the value!
strlist(i) = DIR;
end
% We need to sort the lists by floats (not strings, as it is now)
[flist, sortedIDX] = sort(flist); strlist = strlist(sortedIDX);
end

function [ids,ordpms,U_list] = extract_line(U_LIST)
%% Getting a list of variable values, from directories.
% U_LIST: an array of values for Hubbard interaction U (could be empty!)
% ids: a cell of strings, the names of the order parameters
% ordpms: a cell of arrays, corresponding to the names above, for all U
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
global ignUlist
if isempty(U_LIST) | ignUlist == true
[U_LIST, ~] = get_list('U');
else
U_LIST = sort(U_LIST);
end
% Then we can proceed spanning all the U-values
Nu = length(U_LIST);
cellordpms = cell(Nu,1);
for iU = 1:length(U_LIST)
U = U_LIST(iU);
UDIR= sprintf('U=%f',U);
if ~isfolder(UDIR)
errstr = 'U_list file appears to be inconsistent: ';
errstr = [errstr,UDIR];
errstr = [errstr,' folder has not been found.'];
error(errstr);
end
cd(UDIR);
[ids, cellordpms{iU}] = get_order_parameters();
cd('..');
end
% We need some proper reshaping
Nordpms = length(ids);
ordpms = cell(1,Nordpms);
for jORDPMS = 1:Nordpms
ordpms{jORDPMS} = zeros(Nu,1);
for iU = 1:Nu
ordpms{jORDPMS}(iU) = cellordpms{iU}(jORDPMS);
end
end
U_list = U_LIST;
end

function [names, order_parameters] = get_order_parameters()
%% Getting all information from order_parameters_[].dat
% names: a cell of strings, the names of the order parameters (from [])
% order_parameters: an array of floats, corresponding to the names above
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%names = readcell('order_parameters_info.ed','FileType','fixedwidth');
%names(strcmp(names,'#'))=[];
pattern = 'order_parameters_';
files = dir('.');
N = length(files);
for i = 1:N
temp_name = getfield(files,{i},'name');
found = strfind(temp_name,pattern);
if found
full_name = temp_name;
end
end
beheaded = erase(full_name,pattern); % Removes 'order_parameter_'
detailed = erase(beheaded,'.dat'); % Removes '.dat'
names = strsplit(detailed,'_'); % Reads the names separated by '_'
order_parameters = load(full_name);
if length(names) ~= length(order_parameters)
error('Something went wrong reading order parameters!');
end
end

0 comments on commit 280cc8e

Please sign in to comment.