package nxm.sys.test;

import nxm.sys.lib.BaseFile;
import nxm.sys.lib.Data;
import nxm.sys.lib.DataFile;
import nxm.sys.lib.Primitive;
import nxm.sys.lib.Time;

/** This class is a helper class for plotting xyz data.
 *  @author Kevin Esterheld
 *  @since  NeXtMidas 3.9.3
 */
public class plot3dgraphtester extends Primitive {
  private DataFile outFile;           // Output file/pipe
  private Data     outData;           // Output data table
  private double   size;              // Size of file
  private long     offset;            // current offset
  private long count = 0;
  private double x = 0;
  private double y = 0;
  private double z = 0;
  public int open() {
    size    = 50;
    xfer    = MA.getL("/TL",1);
    outFile = MA.getDataFile("OUT");
    outFile.setComponents("POS/VD/6/5,ELPS/VD/0/0,NAME/2A/0/0");
    outFile.setSize(size);
    outFile.open(BaseFile.OUTPUT);
    outData = outFile.getDataBuffer(1);

    return NORMAL;
  }

  /** default constructor */
  public plot3dgraphtester () {}

  public int process() {
    Time.sleep(.2);
    count++;
    if ((count % 3) == 1) x++;
    else if ((count % 3 ) == 2) y++;
    else z++;

    int    status = NORMAL;

        outData.packD( 0, z);
        outData.packD( 8, y);
        outData.packD(16, x);

        outFile.write(outData);
        offset++;

    return (offset < size)? status: FINISH;
  }

  public int close() {
    if (outFile != null) outFile.close();
    return NORMAL;
  }
}
