#include"Save_Array.h"
#include<iostream>
#include<fstream>
#include"io.h"

using namespace std;
typedef std::complex<double> Creal;

Save_Array::Save_Array() {

}
Save_Array::~Save_Array() {

}

void Save_Array::init(string path, string filename) {
	active = 1;
	string track = path;
	track.append(filename);
	ofs.open(track, ios::out | ios::binary);
}

void Save_Array::write_begin(int rows, int columns) {
	if (active == 1) {

		saveHeader(ofs, "1.0");

		saveInt(ofs, rows);
		saveInt(ofs, columns);

	}
}

void Save_Array::write(Cvec input) {
	if (active == 1) {
		for (int n = 0; n < input.get_size(); n++) {
			double r = input[n].real();
			double i = input[n].imag();
			saveDouble(ofs, r);
			saveDouble(ofs, i);
		}
	}
}

void Save_Array::write(Wavefunction input) {
	if (active == 1) {
		for (int n = 0; n < input.get_size(); n++) {
			double r = input[n].real();
			double i = input[n].imag();
			saveDouble(ofs, r);
			saveDouble(ofs, i);
		}
	}
}

void Save_Array::write(Creal input) {
	if (active == 1) {
			double r = input.real();
			double i = input.imag();
			saveDouble(ofs, r);
			saveDouble(ofs, i);
	}
}

void Save_Array::close() {
	if (active == 1) ofs.close();
}