File: binaryIoTest.cpp

package info (click to toggle)
dmrgpp 6.06-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 113,900 kB
  • sloc: cpp: 80,986; perl: 14,772; ansic: 2,923; makefile: 83; sh: 17
file content (46 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "IoBinary.h"
#include "Vector.h"

void readMe(const String& myfile)
{
	PsimagLite::IoBinary::In fin(myfile);
	typename Vector<double>::Type v;
	fin.read(v, "MyVector");
	std::cout << "MyVector\n";
	std::cout << v;
	std::cout << "------------------\n";

	PsimagLite::Matrix<float> m;
	fin.read(m, "MyMatrix");
	std::cout << "MyMatrix";
	std::cout << m;
	std::cout << "------------------\n";
}

int main()
{
	SizeType rank = 0;
	String myfile = "myfile.txt";
	PsimagLite::IoBinary::Out fout(myfile, rank);
	String s = "Hello World!";
	fout.print(s);
	typename Vector<double>::Type m(10);

	srand48(3490201);
	for (SizeType i = 0; i < m.size(); i++)
		m[i] = drand48();
	fout.printVector(m, "MyVector");
	std::cout << "MyVector\n";
	std::cout << m;
	std::cout << "------------------\n";

	PsimagLite::Matrix<float> a(10, 20);
	for (SizeType i = 0; i < a.n_row(); i++)
		for (SizeType j = 0; j < a.n_col(); j++)
			a(i, j) = drand48();

	fout.write(a, "MyMatrix");
	fout.close();

	readMe(myfile);
}