2 % Copyright (C) 2009-2016 Peter Rakyta, Ph.D.
4 % This program is free software: you can redistribute it and/or modify
5 % it under the terms of the GNU General Public License as published by
6 % the Free Software Foundation, either version 3 of the License, or
7 % (at your option) any later version.
9 % This program is distributed in the hope that it will be useful,
10 % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 % GNU General Public License
for more details.
14 % You should have received a copy of the GNU General Public License
15 % along with
this program. If not, see http:
17 %> @addtogroup basic Basic Functionalities
20 %> @brief A
class providing interface to load variables from a file.
22 %> @brief A
class providing interface to load variables from a file.
26 properties ( Access =
protected )
27 %> structure containing the loaded data
35 %% constructorof the
class 36 %> @brief Constructor of the
class.
37 %> @
param filenev The
string of the absolute path to the file to open. (Matlab can operate with relative paths as well)
38 %> @
return An instance of the
class 41 if exist(filenev,
'file')
42 obj.LoadedVariable = load(filenev);
44 obj.LoadedVariable = [];
47 obj.filename = filenev;
52 %> @brief Loads a variable from the opened file.
53 %> @
param varname The
string containing the name of the variable.
54 %> @
param varargin Cell array of optional parameters (https:
55 %> @
param 'NoEmpty' Set 'On' for throw an error when the loaded variable is empty, or 'Off' (default) otherwise.
56 %> @
param 'StructName' String containing the name of a structure, when the wanted variable is a field of a structure.
57 function ret = LoadVariable(obj, varname, varargin)
60 p.addParameter('NoEmpty', 'Off');
61 p.addParameter('StructName', []);
64 NoEmpty = p.Results.NoEmpty;
65 StructName = p.Results.StructName;
67 if ~isempty(StructName)
68 dfieldnames = fieldnames(obj.LoadedVariable.(StructName));
69 if ismember(varname, dfieldnames)
70 ret = obj.LoadedVariable.(StructName).(varname);
75 if isempty(ret) && strcmp(NoEmpty,
'On')
76 error(['"', obj.filename, '" has no element called "',StructName,'.',varname,'", or it is empty.']);
84 if isfield(obj.LoadedVariable, varname)
85 ret = obj.LoadedVariable.(varname);
90 if isempty(ret) && strcmp(NoEmpty, 'On')
91 error(['"', obj.filename,'" has no element called "',varname,'", or it is empty.']);
98 %> @brief Sets a loaded variable.
99 %> @
param varname The
string containing the name of the variable.
100 %> @
param value The value to be set.
101 %> @
param varargin Cell array of optional parameters (https:
102 %> @
param 'NoEmpty' Set 'On' for throw an error when the loaded variable is empty, or 'Off' (default) otherwise.
103 %> @
param 'StructName' String containing the name of a structure, when the wanted variable is a field of a structure.
104 function ret = setLoadedVariable( obj, varname, value, varargin )
106 p.addParameter('NoEmpty', 'Off');
107 p.addParameter('StructName', []);
108 p.parse(varargin{:});
110 NoEmpty = p.Results.NoEmpty;
111 StructName = p.Results.StructName;
113 if ~isempty(StructName)
114 dfieldnames = fieldnames(obj.LoadedVariable.(StructName));
115 if ismember(varname, dfieldnames)
116 obj.LoadedVariable.(StructName).(varname) = value;
122 if ~ret && strcmp(NoEmpty,
'On')
123 error(['"',filenev,'" has no element called "',StructName,'.',varname,'", or it cannot be set.']);
131 if isfield(obj.LoadedVariable, varname)
132 obj.LoadedVariable.(varname) = value;
138 if ~ret && strcmp(NoEmpty, 'On')
139 error(['"',filenev,'" has no element called "',varname,'", or it cannot be set.']);
143 %% SaveLoadedVariables
144 %> @brief Save the loaded variables.
145 %> @
param varargin Cell array of optional parameters (https:
146 %> @
param 'filename' A
string containing the path to the new file to be created instead of the original one.
147 function SaveLoadedVariables( obj, varargin )
149 p.addParameter('filename', obj.filename);
150 p.parse(varargin{:});
152 filename = p.Results.filename;
153 LoadedVariable = obj.LoadedVariable;
154 save( filename,
'-struct',
'LoadedVariable' );
158 %% ClearLoadedVariables
159 %> @brief Disposes the loaded file.
160 function ClearLoadedVariables( obj )
161 obj.LoadedVariable = [];
function Transport(Energy, B)
Calculates the conductance at a given energy value.
Structure param contains data structures describing the physical parameters of the scattering center ...
A class providing interface to load variables from a file.