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
Util.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
17 class Util {
36  public: /* ( Constant ) */
37 
38  static const MachineFormat = "ieee-be";
50  public: /* ( Static ) */ /* ( Constant ) */
51 
52  static function saveRealMatrix(mat,file,folder) {
53  if ~isreal(mat)/* || ~ismatrix(mat) */
54 
55  error(" Matrix must contain only real values ");
56  end
57  prec = class(mat);
58  /* single precision is encoded as float32 */
59  if strcmp(prec," single ")
60  prec = " float32 ";
61  end
62 
63  if nargin == 3
64  if exist(folder," dir ") ~= 7
65  error(" Directory '%s' does not exist. ", folder);
66  end
67  file = fullfile(folder,file);
68  end
69 
70  f = fopen(file," w+ ",Util.MachineFormat);
71  try
72  [n,m] = size(mat);
73  if n > intmax(" int32 ") || m > intmax(" int32 ")
74  error(" Cannot save matrix: Dimensions exceed max int32 value. ");
75  end
76  fwrite(f,n," int32 ");
77  fwrite(f,m," int32 ");
78  /* Matlab Rev. 2009a: entries are written in column order, which must be transposed
79  * in order to read them in row order (native storage format in java
80  * apache.commons.math */
81  fwrite(f,mat^t,prec);
82  catch ME
83  fclose(f);
84  rethrow(ME);
85  end
86  fclose(f);
87  }
99  static function saveRealVector(vec,file,folder) {
100  if ~isreal(vec) || ~isvector(vec)
101  error(" vec must be a vector with real values ");
102  end
103  prec = class(vec);
104  /* single precision is encoded as float32 */
105  if strcmp(prec," single ")
106  prec = " float32 ";
107  end
108 
109  if nargin == 3
110  if exist(folder," dir ") ~= 7
111  error(" Directory '%s' does not exist. ", folder);
112  end
113  file = fullfile(folder,file);
114  end
115 
116  f = fopen(file," w+ ",Util.MachineFormat);
117  try
118  s = length(vec);
119  if s > intmax(" int32 ")
120  error(" Cannot save vector: Dimension exceeds max int32 value. ");
121  end
122  fwrite(f,s," int32 ");
123  fwrite(f, vec, prec);
124  catch ME
125  fclose(f);
126  rethrow(ME);
127  end
128  fclose(f);
129  }
140  static function charjsonobj = matrixToJSON(double value) {
141  siz = sprintf(" %d, ",size(value));
142  vals = sprintf(" %.16e, ",value(:));
143  jsonobj = sprintf(" {'dim':[%s], 'values':[%s]} ",siz(1:end-2),vals(1:end-2));
144  }
163 };
164 
static const MachineFormat
The machine format (little/big endian, 32/64bit) to use upon export.
Definition: Util.m:38
static function saveRealVector(vec, file, folder)
Stores a real double vector in little endian format.
Definition: Util.m:99
static function char jsonobj = matrixToJSON(double value)
Takes a matrix and returns a JSON representation as JSONObject with the fields "dim" and "values"...
Definition: Util.m:140
Util: Utility functions for export of matrices and vectors to files.
Definition: Util.m:17
static function saveRealMatrix(mat, file, folder)
Stores a real double matrix in little endian format.
Definition: Util.m:52