36 static Treal
maxdiff(
const Treal* f1,
const Treal* f2,
int size) {
39 for(
int i = 0; i < size * size; i++) {
42 diff = (diff > tmpdiff ? diff : tmpdiff);
48 static Treal
maxdiff_tri(
const Treal* f1,
const Treal* f2,
int size) {
51 for (
int col = 0; col < size; col++)
52 for (
int row = 0; row < col + 1; row++) {
54 diff = (diff > tmpdiff ? diff : tmpdiff);
61 static Treal
frobdiff(
const Treal* f1,
const Treal* f2,
int size) {
64 for(
int i = 0; i < size * size; i++) {
73 static void fileread(T *ptr,
int size,FILE*) {
74 std::cout<<
"error reading file"<<std::endl;
78 fread(ptr,
sizeof(
double),size*size,file);
82 double* tmpptr=
new double [size*size];
83 fread(tmpptr,
sizeof(
double),size*size,file);
84 for (
int i=0;i<size*size;i++)
86 ptr[i]=(float)tmpptr[i];
91 template<
typename Treal,
typename Trealonfile>
92 static void fileread(Treal *ptr,
int size, FILE* file) {
93 if (
sizeof(Trealonfile) ==
sizeof(Treal))
94 fread(ptr,
sizeof(Treal),size,file);
96 Trealonfile* tmpptr=
new Trealonfile[size];
97 fread(tmpptr,
sizeof(Trealonfile),size,file);
98 for (
int i = 0; i < size; i++) {
99 ptr[i]=(Treal)tmpptr[i];
106 template<
typename Treal,
typename Tmatrix>
108 char const *
const matrixPath,
110 FILE* matrixfile=fopen(matrixPath,
"rb");
112 throw Failure(
"read_matrix: Cannot open inputfile");
114 Treal* matrixfull =
new Treal [size*size];
115 fileread<Treal, double>(matrixfull, size*size, matrixfile);
117 A.assign_from_full(matrixfull, size, size);
122 template<
typename Treal,
typename Trealonfile,
typename Tmatrix>
124 char const *
const rowPath,
125 char const *
const colPath,
126 char const *
const valPath,
128 FILE* rowfile=fopen(rowPath,
"rb");
130 throw Failure(
"read_matrix: Cannot open inputfile rowfile");
132 FILE* colfile=fopen(colPath,
"rb");
134 throw Failure(
"read_matrix: Cannot open inputfile colfile");
136 FILE* valfile=fopen(valPath,
"rb");
138 throw Failure(
"read_matrix: Cannot open inputfile valfile");
140 int* row =
new int[nval];
141 int* col =
new int[nval];
142 Treal* val =
new Treal[nval];
143 fileread<int, int>(row, nval, rowfile);
144 fileread<int, int>(col, nval, colfile);
145 fileread<Treal, Trealonfile>(val, nval, valfile);
148 A.assign_from_sparse(row, col, val, nval);
150 Treal* compval =
new Treal[nval];
151 A.get_values(row, col, compval, nval);
154 for (
int i = 0; i < nval; i++) {
156 maxdiff = diff > maxdiff ? diff :
maxdiff;
158 std::cout<<
"Maxdiff: "<<maxdiff<<std::endl;
166 template<
typename Treal>
171 char* atomfile(atomsPath);
172 std::ifstream
input(atomfile);
174 throw Failure(
"read_xyz: Cannot open inputfile");
176 input >> std::setprecision(10);
177 Treal* xtmp =
new Treal[natoms];
178 Treal* ytmp =
new Treal[natoms];
179 Treal* ztmp =
new Treal[natoms];
180 int* atomstart =
new int[natoms+1];
181 for(
int i = 0 ; i < natoms ; i++) {
185 input >> atomstart[i];
187 atomstart[natoms] = size;
188 for (
int atom = 0; atom < natoms; atom++)
189 for (
int bf = atomstart[atom]; bf < atomstart[atom + 1]; bf++) {