import nom.tam.fits.*;

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

public class SabocaScan extends LabocaScan {

	public SabocaScan() {
		instrumentName = "saboca";
		rcpFile = instrumentName + File.separator + "master.rcp";
		pixelDataFile = instrumentName + File.separator + "pixel.dat";
		channelTemplate = new SabocaPixel(-1);
	}
	
	
	public void getChannelGroups() throws Exception {
		ampChannels = LabocaPixel.getChannelGroups(channel, LabocaPixel.class.getField("amp"), LabocaPixel.FLAG_DEAD); 
		pinOrder(ampChannels);
	}
	
	public void readPar(BinaryTableHDU hdu) throws IOException, FitsException, HeaderCardException {
		super.readPar(hdu);
		instrumentGain = 1000.0;
	}
	
	public SabocaScan[] readScanDirectory(LabocaScan common, String dir, String ext) throws IOException, FitsException, HeaderCardException {
		int subscans = common.readScanInfo(dir + File.separator + "SCAN" + ext);
		common.readPar(dir + File.separator + "SABOCA-ABBA-FEBEPAR" + ext);

		Vector<SabocaScan> buffer = new Vector<SabocaScan>();

		for(int i=0; i<subscans; i++) {
			try {
				SabocaScan subscan = (SabocaScan) common.copy();

				System.err.println(" Subscan {" + (i+1) + "}:");
				subscan.subscanNo = i;
				subscan.readDataPar(dir + File.separator + (i+1) + File.separator + "SABOCA-ABBA-DATAPAR" + ext);
				subscan.readData(dir + File.separator + (i+1) + File.separator + "SABOCA-ABBA-ARRAYDATA-1" + ext);
				subscan.readMonitor(dir + File.separator + (i+1) + File.separator + "MONITOR" + ext);
				subscan.validate();

				buffer.add(subscan);
			}
			catch(Exception e) {
				System.err.println(" ERROR: " + e.getMessage());
				e.printStackTrace();
			}
		}

		SabocaScan[] set = new SabocaScan[buffer.size()];
		for(int i=0; i<buffer.size(); i++) {
			set[i] = buffer.get(i);
			set[i].scanPath = dir;
		}
		
		return set;
	}
	
}
