package ipp.imse.fusionOptics.mse;

import jafama.FastMath;

import java.util.ArrayList;
import java.util.HashMap;

import fusionOptics.MinervaOpticsSettings;

import oneLiners.OneLiners;

public class AugFaroNov2013 {
	//read the FARO data from the November AUG 2013 in-vessel work for MSE/IMSE
	public static final String fileName = MinervaOpticsSettings.getMinervaSourcePath() + "/minerva-aug/data/MSE-auswert-28112013.csv";
	
	public HashMap<String, double[]> pos = new HashMap<String, double[]>();
	public HashMap<String, double[]> uvec = new HashMap<String, double[]>();
	public HashMap<String, Double> diameter = new HashMap<String, Double>();

	//Rough read everything in that looks like a double
	public AugFaroNov2013() {
		
		String lines[] = OneLiners.linesFromFile(fileName);
		
		for(String line : lines){
			String tokens[] = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
			String name = tokens[0].substring(1, tokens[0].length()-1);
			
			name = name.replaceAll("^Hilfsebene - ", "");
			
			double xAUG = Double.parseDouble(tokens[1]);
			double yAUG = Double.parseDouble(tokens[2]);
			double zAUG = Double.parseDouble(tokens[3]);
			
			//convert aug general to 'x is north'
			double ang = 5 * 22.5 * Math.PI / 180; 
			double x = FastMath.cos(ang) * xAUG + FastMath.sin(ang) * yAUG; 
			double y = -FastMath.sin(ang) * xAUG + FastMath.cos(ang) * yAUG;
			double z = zAUG;
						
			
			if(tokens[4].equals("\"ijk\"")){
				uvec.put(name, new double[]{ x, y, z } );	
				
			}else{
				pos.put(name, new double[]{ x / 1000, y / 1000, z / 1000 } );				
			}
			
			try{
				double d = Double.parseDouble(tokens[5]);
				diameter.put(name, d / 1000);
			}catch(NumberFormatException err){ }
			
			
		}
		System.out.println();
		
	}
	
	public double[] getPos(String name){ return pos.get(name); }
	public double[] getUVec(String name){ return uvec.get(name); }
	public double getDiameter(String name){ Double d = diameter.get(name); return (d == null) ? Double.NaN : d; }

	public String[] getNames() { return pos.keySet().toArray(new String[0]); }
		
}
