KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FileData.m
Go to the documentation of this file.
1 namespace data{
2 
3 
4 /* (Autoinserted by mtoc++)
5  * This source code has been filtered by the mtoc++ executable,
6  * which generates code that can be processed by the doxygen documentation tool.
7  *
8  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
9  * Except for the comments, the function bodies of your M-file functions are untouched.
10  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
11  * attached source files that are highly readable by humans.
12  *
13  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
14  * the correct locations in the source code browser.
15  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
16  */
17 
18 class FileData
19  :public handle {
39  public:
40 
41  char Host = "";
54  public: /* ( Dependent ) */
55 
70  protected:
71 
72  logical isSaved = false;
88  private:
89 
90  fDataDir;
91 
92 
93  public:
94 
95  FileData(data_dir) {
96  if nargin == 1
97  this.DataDirectory= data_dir;
98  end
99  this.Host= KerMor.getHost;
100  }
101 
102 
103  function relocate(char new_root) {
104  this.DataDirectory= new_root;
105  this.Host= KerMor.getHost;
106  }
120  function delete() {
121  if ~isempty(this.fDataDir) && ~this.isSaved && exist(this.fDataDir," dir ") == 7
122  if length(dir(this.fDataDir)) ~= 2
123  warning(" KerMor:FileData ",...
124  " A FileData instance (%s) should be deleted but the DataDirectory '%s' is not empty. Not deleting. ",...
125  class(this),this.fDataDir);
126  else
127  rmdir(this.fDataDir);
128  end
129  end
130  }
131 
132 
133 
134 
135 #if 0 //mtoc++: 'set.DataDirectory'
136 function DataDirectory(value) {
137  if ~isempty(value)
138  if Utils.ensureDir(value);
139  this.fDataDir= value;
140  return;
141  else
142  warning(" KerMor:FileData "," Could not make sure that the directory '%s' exists.\nPlease ensure a correct path and try again. ",value);
143  end
144  end
145  this.fDataDir= ;
146  }
147 
148 #endif
149 
150 
151 
152 #if 0 //mtoc++: 'get.DataDirectory'
153 function dir = DataDirectory() {
154  dir = this.fDataDir;
155  }
156 
157 #endif
158 
159 
160  protected:
161 
162  function file = getfile(file) {
163  file = fullfile(this.fDataDir,file);
164  if exist(file," file ") ~= 2
165  if strcmp(this.Host,KerMor.getHost)
166  error(" File '%s' not found in folder '%s'. Have you deleted data files? ",...
167  file,this.fDataDir);
168  else
169  error([" File '%s' not found. This FileData instance was created on host '%s' "...
170  " and the DataDirectory cannot be found on the local machine '%s'.\n "...
171  " Copy the files to an accessible directory and use the 'relocate' method. "],...
172  file,this.Host,KerMor.getHost);
173  end
174  end
175  }
176 
177 
178  function this = saveobj() {
179  this.isSaved= true;
180  }
190  protected: /* ( Static ) */
191 
192  static function this = loadobj(this,initfrom) {
193 
194  created = false;
195  if ~isa(this, " data.FileData ")
196  initfrom = this;
197  if isfield(initfrom," fDataDir ")
198  this = data.FileData(initfrom.fDataDir);
199  else
200  this = data.FileData(initfrom.DataDirectory);
201  end
202  created = true;
203  end
204  if nargin == 2
205  if ~created
206  if isfield(initfrom," fDataDir ")
207  this.fDataDir= initfrom.fDataDir;
208  else
209  this.fDataDir= initfrom.DataDirectory;
210  end
211  end
212  this.Host= initfrom.Host;
213  this.isSaved= initfrom.isSaved;
214  end
215  if ~isempty(this.fDataDir) && exist(this.fDataDir," file ") == 0
216  str = " Directory '%s' not found. Loading files will not work until fixed.\n ";
217  if ~strcmp(this.Host,KerMor.getHost)
218  str = sprintf([" %sNote that this FileData has been created on machine %s. "...
219  " If you changed the computer (local: %s), use the 'relocate' method.\n "],str,this.Host,KerMor.getHost);
220  end
221  fprintf(2,str,this.fDataDir);
222  end
223  }
243 };
244 }
245 
static function host = getHost()
Returns the hostname of the current machine.
Definition: KerMor.m:1023
Collection of generally useful functions.
Definition: Utils.m:17
function file = getfile(file)
Definition: FileData.m:162
function this = saveobj()
Set saved flag so that the data files do not get deleted on the delete method.
Definition: FileData.m:178
Matlab's base handle class (documentation generation substitute)
function relocate(char new_root)
Relocates this FileData instance to a different folder.
Definition: FileData.m:103
FileData(data_dir)
Definition: FileData.m:95
A boolean value.
FileData: Base class for access of files stored in a specific folder in the local file system...
Definition: FileData.m:18
char DataDirectory
The root folder where the FileData's files are saved.
Definition: FileData.m:56
char Host
The host machine this file data is created on.
Definition: FileData.m:41
logical isSaved
This flag indicates that this FileData instance has been stored to disk via the save method somewhere...
Definition: FileData.m:72
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
A MatLab character array.
static function this = loadobj(this, initfrom)
Loads a FileData instance.
Definition: FileData.m:192