package walltest;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class FileHandling {

    public static float[][] readMapFileF(String filename) {
        ArrayList<float[]> al = new ArrayList<float[]>(1000);
        float[][] map = null;
        float[][] a = new float[1][];
        try {
            FileReader fr;
            fr = new FileReader(filename);
            BufferedReader br = new BufferedReader(fr);
            String s;
            while ((s = br.readLine()) != null) {
                StringTokenizer st = new StringTokenizer(s);
                float[] seg = new float[4];
                int count = 0;
                while (st.hasMoreTokens()) {
                    if (count > 3) {
                        throw (new Exception());
                    }
                    seg[count] = (new Float(st.nextToken())).floatValue();
                    count++;
                }
                if (count != 4) {
                    throw (new Exception());
                }
                al.add(seg);
            }
            map = al.toArray(a);
        } catch (Exception ex) {
            System.out.println("Could not read map-file '"+filename+"'");
            map = null;
        }
        return (map);
    }
}
