
/**
 * SpectraData.java
 * This is stores the data and file information from a spectra data file.
 * Created: Dec 27, 2003
 *
 * @author Nathan Stevens
 * @version 0.1 1/29/04 
 */
import java.io.*;

public class SpectraData implements Serializable {
  private String name = null; // The name of the spectroscopy data
  private String type = null;  // The experiement type
  private String[] header = null; // The header information
  private float[][] data = null;  // The data in the file
  private float[][] rdata = null; // The reference data, if any.
  private String units = "nm"; // The units of data within
  private String xlabel, ylabel; // The x and y column labels
  private String delay = "0"; // Used to pump-probe and frgs data
  private String dname = null; // the name that is returned by the toString method
  private boolean exportX = true; // Export X data or not.
  public boolean hasref = false; // whether this has reference data or not
  public boolean is3D = false; // is this 3D data or 2D data?
  public int direction = 0; // 0 is horizontal, and 1 is vertical
  public boolean isSlice = false; // is this data slice data. used for Streak Camera data
  
  // default constructor
  public SpectraData() { }
  
  // The main constructor
  public SpectraData(String name, String type, String[] header, float[][] data, float[][] rdata) {
    this.name = name;
    this.type = type;
    this.header = header;
    this.data = data;
    this.rdata = rdata;
    
    // set the x and y labels based on the name
    xlabel = name + "-wl";
    ylabel = name + "-int";
    
    if(type.equals("macro") || type.equals("micro") || type.equals("FT")) {
      units = "cm-1";
    }
    
    // set has reference
    if(rdata != null) {
      hasref = true;
    }
    
    // set the display name variable
    dname = name + " (" + header[0] + "-" + header[1] + units + ")";
  }
  
  // Method to get the data header
  public String[] getHeader() {
    return header;
  }
  
  // Method to set the header informations
  public void setHeader(String[] header) {
    this.header = header;
  }
  
  // Method to set the data
  public void setData(float[][] data) {
    this.data = data;
    header[0] = "" + data[0][0];
    header[1] = "" + data[data.length-1][0];
    header[2] = "" + data.length;
  }
  
  // Method to get the data from the file
  public float[][] getData() {
    return data;
  }
  
  // Method set the reference data
  public void setReferenceData(float[][] rdata) {
    this.rdata = rdata;
    if(rdata != null) {
      hasref = true;
    }
  }
  
  // Method to get the data from the file
  public float[][] getReferenceData() {
    return rdata;
  }
  
  // Method to set the type
  public void setType(String type) {
    this.type = type;
  }
  
  // Method to return the type of this data object
  public String getType() {
    return type;
  }
  
  // Method to set the Column labels
  public void setColumnLabels(String xlabel, String ylabel) {
    this.xlabel = xlabel;
    this.ylabel = ylabel;
  }
  
  // Method to get the column labels
  public String[] getColumnLabels() {
    String[] xylabel = {xlabel, ylabel};
    return xylabel;
  }
  
  // Method to set whether or not to export the xlabel, and column.
  // used when generating work sheets containing multiple data
  public void setExportX(boolean b) {
    exportX = b;
  }
  
  //Method to return whether to export x or not
  public boolean exportX() {
    return exportX;
  }
  
  // Method to set whether the data is 2D or 3D
  public void set3D(boolean b) {
    is3D = b;
  }
  
  // Method to set whether the data is 2D or 3D
  public void setSlice(boolean b) {
    isSlice = b;
  }
  
  // Method to set the direction of the data vertical or horizontal
  public void setDirection(int d) {
    direction = d;
  }
  
  // Method to set the delay string and hence the name
  public void setDelay(String delay) {
    this.delay = delay;
    dname = name + "-" + delay + " (" + header[0] + "-" + header[1] + units + ")";
  }
  
  // Method to return the delay
  public String getDelay() {
    return delay;
  }
  
  // Method to return the size of the data array
  public int size() {
    if(data != null) {
      return data.length;
    }
    else {
      return 0;
    }
  }
  
  // Method to set the name
  public void setName(String name) {
    this.name = name;
    
    xlabel = name + "-wl";
    ylabel = name + "-int";
  }
  
  // Method to get the name of the data object
  public String getName() {
    return name;
  }
  
  // Method to return the name of this object
  public String toString() {
    return dname;
  }
} // --SpectraData
