package signals.mast;

import java.io.IOException;

import ncsa.hdf.hdf5lib.exceptions.*;
import signals.Signal;
import descriptors.JET.PPFDesc;
import descriptors.mast.IDAMDesc;

/**
 * A IDAM Signal - Specifically a dataType.
 * 
 * All IDAM Data should be stored and returned as floats.
 * 
 * 
 * @author oliford <codes@oliford.co.uk>
 */
public class IDAM extends Signal {
	
	/** Load a JPF Object from a HDF5 cache file */
	public IDAM(String cacheRoot, IDAMDesc desc) throws IOException {
		super(cacheRoot + desc.path() + ".hdf");
		this.desc = desc;
	}
	
	/** Load a JPF Object from a HDF5 cache file */
	public IDAM(String cacheRoot, IDAMDesc desc, int i) throws IOException {
		super(cacheRoot + desc.path() + "E.hdf");
		this.desc = desc;
	}
			
	/** Create a new 2D PPF directly from data*/
	public IDAM(IDAMDesc desc, Object data, Object xVec, Object tVec){
		super(data, new Object[]{ xVec, tVec });
		this.desc = desc;
	}
	
	/** Create a new 1D PPF (tVector) directly from data */
	public IDAM(IDAMDesc desc, Object data, Object tVec){
		super(data, new Object[]{ tVec });
		this.desc = desc;
	}
	
	/** PPF Location descriptor */
	private IDAMDesc desc;
	

	@Override
	public final IDAMDesc getDescriptor() { return desc; }
	
	/** Return vector of time coordinates */ 
	public final Object getTVector(){ return getCoords(getRank()-1); }
	
	/** Return vector of X coordinates */
	public final Object getXVector(){ return getCoords(0); }

	/** Return vector of time coordinates */ 
	public final Object getTVectorAsType(Class <?>type){ return getCoordsAsType(getRank()-1, type); }
	
	/** Return vector of X coordinates */
	public final Object getXVectorAsType(Class <?>type){ return getCoordsAsType(0, type); }

	/** Check this is a 1D PPF and get data */
	public final Object get1DData(){
		if(getRank() == 1)
			return getData();
		else
			throw new RuntimeException("Not a 1D PPF!");
	}
	
	/** Check this is a 2D PPF and get data */
	public final Object get2DData(){
		if(getRank() == 2)
			return getData();
		else
			throw new RuntimeException("Not a 2D PPF!");
	}
	
	@Override
	protected void writeExtraToHDF5(int file_id) throws IOException, HDF5Exception {
		super.writeExtraToHDF5(file_id);

	}

	@Override
	protected void readExtraFromHDF5 (int file_id) throws IOException, HDF5Exception {		
		super.readExtraFromHDF5(file_id);
	
		
	}
	
	@Override
	public String toString() {
		return "IDAM from '"+desc.toString()+"': " + super.toString();
	}

	
}
