import java.io.*;
import java.text.*;
import java.util.*;

public class SabocaPixel extends LabocaPixel {

	public SabocaPixel(int backendChannel) {
		super(backendChannel);
	}

	
	public static void markBads(LabocaPixel[] channel) {
		// 2, 10, 13, 25, 30, 40
		// 38, 39
		int[] bads = { 2, 10, 13, 25, 30 };
		for(int i=0; i<bads.length; i++) channel[bads[i]-1].flag = SabocaPixel.FLAG_DEAD;
		
	}
	
	public String gainString(DecimalFormat df) {
		String text = 
			df.format(gain) + "  " +
			"\t" + df.format(ampGain) + "  "; 

		return text;
	}
	
	@Override
	public void parseGains(StringTokenizer tokens) {
		gain = Double.parseDouble(tokens.nextToken());
		ampGain = Double.parseDouble(tokens.nextToken());
	}
	
	public String gainHeader() {
		return "gain\t\tGsquid";
	}

	static Vector2D[] pos; 
	
	public static void readWiring(String fileName) throws IOException {	
		int channels = 40;
		pos = new Vector2D[channels];

		ampForChannel = new int[channels];
		pinForChannel = new int[channels];
				
		BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
		String line;
		while((line = in.readLine()) != null) if(line.length() > 0) if(line.charAt(0) != '#') {
			StringTokenizer tokens = new StringTokenizer(line);
			int c = Integer.parseInt(tokens.nextToken()) - 1;

			ampForChannel[c] = 	Integer.parseInt(tokens.nextToken()) - 1;
			pinForChannel[c] = 	Integer.parseInt(tokens.nextToken()) - 1;
			
			try { pos[c] = new Vector2D(Double.parseDouble(tokens.nextToken()), Double.parseDouble(tokens.nextToken())); }
			catch(Exception e) { pos[c] = new Vector2D(); }
			pos[c].scale(Unit.arcsec);
		}
		
	}	
}
