Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/matrixIO/matrixIO.h

raw symbols SCIP
1 /*************************************************************************
2 * *
3 * Vega FEM Simulation Library Version 3.1 *
4 * *
5 * "matrix" library , Copyright (C) 2007 CMU, 2009 MIT *
6 * All rights reserved. *
7 * *
8 * Code author: Jernej Barbic *
9 * http://www.jernejbarbic.com/code *
10 * Research: Jernej Barbic, Doug L. James, Jovan Popovic *
11 * Funding: NSF, Link Foundation, Singapore-MIT GAMBIT Game Lab *
12 * *
13 * This library is free software; you can redistribute it and/or *
14 * modify it under the terms of the BSD-style license that is *
15 * included with this library in the file LICENSE.txt *
16 * *
17 * This library is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *
20 * LICENSE.TXT for more details. *
21 * *
22 *************************************************************************/
23
24 /*
25 These routines allow you to read/write a dense matrix from/to a file,
26 using a special simple binary format. LAPACK-style column-major
27 format is used. The code is templated for "float" and "double" datatypes.
28
29 See also matrix.h.
30
31 Binary file format, for a m x n matrix, is:
32 <m> <n> <data>
33 where: m is an integer (of type "int")
34 n is an integer (of type "int")
35 data is a sequence of m*n real numbers (of type either "float" or "double")
36
37 All quantities are stored in binary format.
38 Data is stored in column-major format (as in LAPACK):
39 first column first, then second column, and so on.
40 Total file size is 2 * sizeof(int) + m * n * sizeof(real),
41 where real is either "float" or "double".
42
43 Underscored routines will perform error checking and cause the program to abort
44 in case of error when accessing the file.
45 */
46
47 #ifndef _MATRIXIO_H_
48 #define _MATRIXIO_H_
49
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include "matrixMacros.h"
53
54 // === matrix input/output routines ===
55
56 template <class real>
57 int ReadMatrixFromDisk(const char * filename, int * m, int * n, real ** matrix);
58 template <class real>
59 int ReadMatrixFromDisk_(const char * filename, int * m, int * n, real ** matrix);
60
61 int ReadMatrixSizeFromDisk(const char * filename, int * m, int * n);
62 void ReadMatrixSizeFromDisk_(const char * filename, int * m, int * n);
63 void ChangeMatrixHeader(const char * filename, int numRows, int numColumns); // overwrites any previous header; keeps data intact
64
65 template <class real>
66 int WriteMatrixToDisk(const char * filename, int m, int n, const real * matrix);
67 template <class real>
68 int WriteMatrixToDisk_(const char * filename, int m, int n, const real * matrix);
69
70 template <class real>
71 int AppendMatrixToDisk(const char * filename, int m, int n, const real * matrix);
72 template <class real>
73 int AppendMatrixToDisk_(const char * filename, int m, int n, const real * matrix);
74
75 template <class real>
76 int ReadMatrixFromDiskTextFile(const char * filename, int * m, int * n, real ** matrix);
77
78 template <class real>
79 int WriteMatrixToDiskTextFile(const char * filename, int m, int n, const real * matrix);
80
81 // "fileList" is a filename of a text file that contains the matrices to be loaded (concatenated column-wise) into the matrix, one text entry per line of "fileList"
82 template <class real>
83 int ReadMatrixFromDiskListOfFiles(const char * fileList, int * m, int * n, real ** matrix);
84
85 // prints the matrix to standard output in Mathematica format
86 template <class real>
87 void PrintMatrixInMathematicaFormat(int n, int r, real * U);
88
89 // === assert and abort ===
90
91 // if (a!=b) exit program (and print the integer "assertionIdentifier" to stdout)
92 int Assert_(int a, int b, int assertionIdentifier);
93 int Assert_(bool cond, int assertionIdentifier);
94
95 // exit the program, by first printing the "reason" text message
96 void Abort_(const char * reason);
97 void Abort_(const char * reason, int exitCode);
98
99 // === stream routines (they operate on a file that is already open, in binary mode) ===
100
101 int OpenFile_(const char * filename, FILE ** fin, const char * mode);
102
103 template <class real>
104 int WriteMatrixToStream(FILE * file, int m, int n, const real * matrix);
105
106 int WriteMatrixHeaderToStream(FILE * file, int m, int n);
107
108 template <class real>
109 int ReadMatrixFromStream(FILE * file, int m, int n, real * matrix);
110
111 int ReadMatrixSizeFromStream(FILE * file, int * m, int * n);
112
113 // === helper routines ===
114
115 template<class T>
116 int ReadBinary(FILE * fin, T * data);
117 template<class T>
118 void ReadBinary_(FILE * fin, T * data);
119
120 template<class T>
121 int ReadBinaryBuffer(FILE * fin, int size, T * data);
122 template<class T>
123 void ReadBinaryBuffer_(FILE * fin, int size, T * data);
124
125 // === specific research routines for linear modal analysis (rarely used) ===
126
127 template <class real>
128 int ReadModesFromDisk(const char * filename, int * n, int * r, real ** frequencies, real ** modes);
129
130 int ReadModeInfoFromDisk(const char * filename, int * n, int * r);
131
132 template <class real>
133 int WriteModesToDisk(const char * filename, int n, int r, real * frequencies, real * modes);
134
135 #endif
136