package analyzer;

import java.io.File;
import java.io.FileWriter;

public class StructureWriter {

	float[][] mWeightO;
	float[][] mWeightH;
	String mFilename;

	public StructureWriter(float[][] weightH, float[][] weightO, String filename) {
		mWeightO = weightO;
		mWeightH = weightH;
		mFilename = filename;
	}

	public boolean write() {
		FileWriter fileWriter = null;
		try {
			fileWriter = new FileWriter(new File(mFilename));
			// fileWriter.write("NN" + " ");
			fileWriter.write(mWeightH[0].length + " ");
			fileWriter.write(mWeightH.length + " ");
			fileWriter.write(mWeightO.length + System.getProperty("line.separator"));

			for (int i = 0; i < mWeightH.length; i++)
				for (int j = 0; j < mWeightH[i].length; j++) {
					fileWriter.write(mWeightH[i][j] + "");
					if (mWeightH[i].length - j == 1)
						fileWriter.write(System.getProperty("line.separator"));
					else
						fileWriter.write(" ");
				}

			for (int i = 0; i < mWeightO.length; i++)
				for (int j = 0; j < mWeightO[i].length; j++) {
					fileWriter.write(mWeightO[i][j] + "");
					if (mWeightO[i].length - j == 1)
						fileWriter.write(System.getProperty("line.separator"));
					else
						fileWriter.write(" ");
				}

			fileWriter.close();
		} catch (Exception e) {
			e.printStackTrace();

			return false;
		}

		return true;
	}
}
