//-----------------------------------------------------------------------------
// Copyright (c) 1994,1995 Southeastern Universities Research Association,
//                         Continuous Electron Beam Accelerator Facility
//
// This software was developed under a United States Government license
// described in the NOTICE file included as part of this distribution.
//
// Jefferson Lab HPC Group, 12000 Jefferson Ave., Newport News, VA 23606
//-----------------------------------------------------------------------------
//
// Description:
//      rsvcDataEntry Class Which is contained inside rsvcData
//
// Author:  
//      Jie Chen
//      Jefferson Lab HPC Group
//
// Revision History:
//   $Log: rsvcDataEntry.java,v $
//   Revision 1.1.1.1  2000/05/23 15:12:50  pal
//   cdev_psi_1.7.2
//
//   Revision 1.1  1999/10/18 17:12:40  chen
//   *** empty log message ***
//
//
//
//
import java.io.IOException;
import rsvcDataTypes;
import rsvcTimeStamp;
import rsvcDataOutputStream;

public final class rsvcDataEntry 
{
    private String tag_;   
    private short  type_;
    private short  ndims_;
    private int    nelems_;
    private Number []data_;
    private String []sdata_;

    /**
     * Construct an empty data entry
     */
    public rsvcDataEntry ()
    {
	tag_ = null;
	type_ = rsvcDataTypes.RSVC_INVALID;
	ndims_ = -1;
	nelems_ = 0;
    }

    /**
     * Construct a tagged data entry from a double value
     */
    public rsvcDataEntry (String tag, double d)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_DOUBLE;
	data_ = new Double[1];
	data_[0] = new Double (d);
    }

    /**
     * Construct a tagged data entry from a float value
     */
    public rsvcDataEntry (String tag, float f)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_FLOAT;
	data_ = new Float[1];
	data_[0] = new Float(f);
    }


    /**
     * Construct a tagged data entry from a long value
     */
    public rsvcDataEntry (String tag, long l)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_LONG;
	data_ = new Long[1];
	data_[0] = new Long(l);
    }

    /**
     * Construct a tagged data entry from an integer value
     */
    public rsvcDataEntry (String tag, int i)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_INT32;
	data_ = new Integer[1];
	data_[0] = new Integer(i);
    }    

    /**
     * Construct a tagged data entry from a short value
     */
    public rsvcDataEntry (String tag, short s)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_INT16;
	data_ = new Short[1];
	data_[0] = new Short(s);
    }

    /**
     * Construct a tagged data entry from a byte value
     */
    public rsvcDataEntry (String tag, byte b)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_BYTE;
	data_ = new Byte[1];
	data_[0] = new Byte(b);
    }

    /**
     * Construct a tagged data entry from a string
     */
    public rsvcDataEntry (String tag, String str)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_STRING;
	sdata_ = new String[1];
	sdata_[0] = str;
    }

    /**
     * Construct a tagged data entry from a time stamp
     */
    public rsvcDataEntry (String tag, rsvcTimeStamp ts)
    {
	tag_ = tag;
	ndims_ = 0;
	nelems_ = 1;
	type_ = rsvcDataTypes.RSVC_TIMESTAMP;
	data_ = new rsvcTimeStamp[1];
	data_[0] = ts;
    }

    /**
     * Construct a tagged data entry from an array of byte
     */
    public rsvcDataEntry (String tag, byte[] barray)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = barray.length;
	type_ = rsvcDataTypes.RSVC_BYTE;
	data_ = new Byte[nelems_];
	for (int i = 0; i < nelems_; i++)
	    data_[i] = new Byte(barray[i]);
    }

    /**
     * Construct a tagged data entry from an array of short
     */
    public rsvcDataEntry (String tag, short[] sarray)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = sarray.length;
	type_ = rsvcDataTypes.RSVC_INT16;
	data_ = new Short[nelems_];
	for (int i = 0; i < nelems_; i++)
	    data_[i] = new Short(sarray[i]);
    }
    
    /**
     * Construct a tagged data entry from an array of integer
     */
    public rsvcDataEntry (String tag, int[] iarray)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = iarray.length;
	type_ = rsvcDataTypes.RSVC_INT32;
	data_ = new Integer[nelems_];
	for (int i = 0; i < nelems_; i++)
	    data_[i] = new Integer(iarray[i]);
    }

    /**
     * Construct a tagged data entry from an array of long
     */
    public rsvcDataEntry (String tag, long[] larray)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = larray.length;
	type_ = rsvcDataTypes.RSVC_LONG;
	data_ = new Long[nelems_];
	for (int i = 0; i < nelems_; i++)
	    data_[i] = new Long(larray[i]);
    }

    /**
     * Construct a tagged data entry from an array of float
     */
    public rsvcDataEntry (String tag, float[] farray)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = farray.length;
	type_ = rsvcDataTypes.RSVC_FLOAT;
	data_ = new Float[nelems_];
	for (int i = 0; i < nelems_; i++)
	    data_[i] = new Float (farray[i]);	
    }

    /**
     * Construct a tagged data entry from an array of double
     */
    public rsvcDataEntry (String tag, double[] darray)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = darray.length;
	type_ = rsvcDataTypes.RSVC_DOUBLE;
	data_ = new Double[nelems_];
	for (int i = 0; i < nelems_; i++)
	    data_[i] = new Double(darray[i]);	
    }

    /**
     * Construct a tagged data entry from an array of strings
     */
    public rsvcDataEntry (String tag, String[] strs)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = strs.length;
	type_ = rsvcDataTypes.RSVC_STRING;
	sdata_ = new String[nelems_];
	for (int i = 0; i < nelems_; i++)
	    sdata_[i] = strs[i];
    }

    /**
     * Construct a tagged data entry from an array of time stamps
     */
    public rsvcDataEntry (String tag, rsvcTimeStamp[] tsarray)
    {
	tag_ = tag;
	ndims_ = 1;
	nelems_ = tsarray.length;
	type_ = rsvcDataTypes.RSVC_TIMESTAMP;
	data_ = new rsvcTimeStamp[nelems_];
	for (int i = 0; i < nelems_; i++)
	    data_[i] = tsarray[i];
    }

    /**
     * Hash code for this data entry
     */
    public int hashCode()
    {
	return tag_.hashCode();
    }

    /**
     * Compare two data entries
     */
    public boolean equals(rsvcDataEntry dobj)
    {
	if (dobj.type_ != type_ ||
	    dobj.nelems_ != nelems_ ||
	    dobj.ndims_ != ndims_ ||
	    dobj.tag_.equals(tag_) == false)
	    return false;

	int i, j;
	if (type_ != rsvcDataTypes.RSVC_INVALID) {
	    if (type_ == rsvcDataTypes.RSVC_STRING) {
		for (i = 0; i < nelems_; i++) {
		    if (sdata_[i].equals (dobj.sdata_[i]) == false)
			return false;
		}
	    }
	    else {
		for (i = 0; i < nelems_; i++) {
		    if (data_[i].equals (dobj.data_[i]) == false)
			return false;
		}
	    }
	}
	return true;
    }
	

    /**
     * Retrieve internal data as a byte value
     */
    public byte byteValue ()
    {
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING)
	    return data_[0].byteValue();
	else if (type_ == rsvcDataTypes.RSVC_STRING)
	    return Byte.valueOf(sdata_[0]).byteValue();
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as a short value
     */
    public short shortValue ()
    {
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING)
	    return data_[0].shortValue();
	else if (type_ == rsvcDataTypes.RSVC_STRING)
	    return Short.valueOf(sdata_[0]).shortValue();
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an integer value
     */
    public int intValue ()
    {
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING)
	    return data_[0].intValue();
	else if (type_ == rsvcDataTypes.RSVC_STRING)
	    return Integer.valueOf(sdata_[0]).intValue();
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as a long value
     */
    public long longValue ()
    {
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING)
	    return data_[0].longValue();
	else if (type_ == rsvcDataTypes.RSVC_STRING)
	    return Long.valueOf(sdata_[0]).longValue();
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as a float value
     */
    public float floatValue ()
    {
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING)
	    return data_[0].floatValue();
	else if (type_ == rsvcDataTypes.RSVC_STRING)
	    return Float.valueOf(sdata_[0]).floatValue();
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as a double value
     */    
    public double doubleValue ()
    {
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING)
	    return data_[0].doubleValue();
	else if (type_ == rsvcDataTypes.RSVC_STRING)
	    return Double.valueOf(sdata_[0]).doubleValue();
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as a string
     */
    public String stringValue ()
    {
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING)
	    return String.valueOf (data_[0]);
	else if (type_ == rsvcDataTypes.RSVC_STRING)	
	    return sdata_[0];
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an array of byte
     */
    public byte[] byteArray ()
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING) {
	    byte[] barray = new byte[nelems_];
	    for (i = 0; i < nelems_; i++)
		barray[i] = data_[i].byteValue();
	    return barray;
	}
	else if (type_ == rsvcDataTypes.RSVC_STRING) {
	    byte[] barray = new byte[nelems_];
	    for (i = 0; i < nelems_; i++)
		barray[i] = Byte.valueOf(sdata_[i]).byteValue();
	    return barray;
	}
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an array of short
     */
    public short[] shortArray ()
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING) {
	    short[] sarray = new short[nelems_];
	    for (i = 0; i < nelems_; i++)
		sarray[i] = data_[i].shortValue();
	    return sarray;
	}
	else if (type_ == rsvcDataTypes.RSVC_STRING) {
	    short[] sarray = new short[nelems_];
	    for (i = 0; i < nelems_; i++)
		sarray[i] = Short.valueOf(sdata_[i]).shortValue();
	    return sarray;
	}
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an array of integer
     */
    public int[] intArray ()
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING) {
	    int[] iarray = new int[nelems_];
	    for (i = 0; i < nelems_; i++)
		iarray[i] = data_[i].intValue();
	    return iarray;
	}
	else if (type_ == rsvcDataTypes.RSVC_STRING) {
	    int[] iarray = new int[nelems_];
	    for (i = 0; i < nelems_; i++)
		iarray[i] = Integer.valueOf(sdata_[i]).intValue();
	    return iarray;
	}
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an array of float
     */
    public float[] floatArray ()
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING) {
	    float[] farray = new float[nelems_];
	    for (i = 0; i < nelems_; i++)
		farray[i] = data_[i].floatValue();
	    return farray;
	}
	else if (type_ == rsvcDataTypes.RSVC_STRING) {
	    float[] farray = new float[nelems_];
	    for (i = 0; i < nelems_; i++)
		farray[i] = Float.valueOf(sdata_[i]).floatValue();
	    return farray;
	}
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an array of double
     */
    public double[] doubleArray ()
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING) {
	    double[] darray = new double[nelems_];
	    for (i = 0; i < nelems_; i++)
		darray[i] = data_[i].doubleValue();
	    return darray;
	}
	else if (type_ == rsvcDataTypes.RSVC_STRING) {
	    double[] darray = new double[nelems_];
	    for (i = 0; i < nelems_; i++)
		darray[i] = Double.valueOf(sdata_[i]).doubleValue();
	    return darray;
	}
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an array of long
     */
    public long[] longArray ()
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING) {
	    long[] larray = new long[nelems_];
	    for (i = 0; i < nelems_; i++)
		larray[i] = data_[i].longValue();
	    return larray;
	}
	else if (type_ == rsvcDataTypes.RSVC_STRING) {
	    long[] larray = new long[nelems_];
	    for (i = 0; i < nelems_; i++)
		larray[i] = Long.valueOf(sdata_[i]).longValue();
	    return larray;
	}
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     * Retrieve internal data as an array of strings
     */
    public String[] stringArray ()
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID &&
	    type_ != rsvcDataTypes.RSVC_STRING) {
	    String[] sarray = new String[nelems_];
	    for (i = 0; i < nelems_; i++) 
		sarray[i] = String.valueOf (data_[i]);
	    return sarray;
	}
	else if (type_ == rsvcDataTypes.RSVC_STRING) {
	    String[] sarray = new String[nelems_];	
	    for (i = 0; i < nelems_; i++) 
		sarray[i] = sdata_[i];
	    return sarray;
	}
	else throw new NumberFormatException("Uninitialize rsvcDataEntry Object");
    }

    /**
     *convert the data entry into a string representation
     */
    public String toString ()
    {
	StringBuffer result = new StringBuffer();
	int i, j;

	if (type_ == rsvcDataTypes.RSVC_INVALID)
	    result.append ("Invalid DataEntry Object");
	else {
	    result.append ("Key:       ").append (tag_).append ("\n");
	    result.append ("Type:      ").append (rsvcDataTypes.types[type_]).append("\n");
	    result.append ("NElems:     ").append(nelems_).append("\n");
	    result.append ("Values:     \n");
	    
	    j = 0;
	    String[] sarray = stringArray();
	    for (i = 0; i < nelems_; i++) {
		if (j == 0)
		    result.append ("\t");
		result.append(sarray[i]).append(" ");
		j++;
		if (j >= 8) {
		    result.append ("\n");
		    j = 0;
		}
	    }
	}
	return result.toString();
    }

    /**
     * Provide an exact deep copy of this data entry 
     */
    public rsvcDataEntry copy ()
    {
	int i;
	rsvcDataEntry de = new rsvcDataEntry();
	
	de.type_ = type_;
	de.nelems_ = nelems_;
	de.ndims_ = ndims_;
	if (tag_ != null)
	    de.tag_ = new String (tag_);
	else
	    de.tag_ = null;

	if (type_ != rsvcDataTypes.RSVC_INVALID) {
	    switch (type_) {
	    case rsvcDataTypes.RSVC_STRING:
		de.sdata_ = new String[nelems_];
		for (i = 0; i < nelems_; i++)
		    de.sdata_[i] = new String(sdata_[i]);
		break;
	    case rsvcDataTypes.RSVC_BYTE:
		de.data_ = new Byte[nelems_];
		for (i = 0; i < nelems_; i++)
		    de.data_[i] = new Byte(data_[i].byteValue());
		break;
	    case rsvcDataTypes.RSVC_INT16:
		de.data_ = new Short[nelems_];
		for (i = 0; i < nelems_; i++)
		    de.data_[i] = new Short(data_[i].shortValue());
		break;
	    case rsvcDataTypes.RSVC_INT32:
		de.data_ = new Integer[nelems_];
		for (i = 0; i < nelems_; i++)
		    de.data_[i] = new Integer(data_[i].intValue());
		break;
	    case rsvcDataTypes.RSVC_FLOAT:
		de.data_ = new Float[nelems_];
		for (i = 0; i < nelems_; i++)
		    de.data_[i] = new Float(data_[i].floatValue());
		break;
	    case rsvcDataTypes.RSVC_DOUBLE:
		de.data_ = new Double[nelems_];
		for (i = 0; i < nelems_; i++)
		    de.data_[i] = new Double(data_[i].doubleValue());
		break;
	    case rsvcDataTypes.RSVC_LONG:
		de.data_ = new Long[nelems_];
		for (i = 0; i < nelems_; i++)
		    de.data_[i] = new Long(data_[i].longValue());
		break;
	    }
	}
	return de;
    }

    /**
     * Return tag of this data entry
     */
    public String getTag ()
    {
	return tag_;
    }

    /**
     * Set tag to new tag
     */
    public void setTag (String tag)
    {
	tag_ = tag;
    }

    /**
     * Return data type in numeric value
     */
    public short getType ()
    {
	return type_;
    }

    /**
     * Return data type in Class
     */
    public Class getClassType () throws ClassNotFoundException
    {
	if (type_ == rsvcDataTypes.RSVC_INVALID)
	    throw new ClassNotFoundException ("Invalid data entry object");
	else {
	    if (type_ == rsvcDataTypes.RSVC_STRING)
		return sdata_.getClass();
	    else
		return data_.getClass();
	}
    }

    /**
     * Return dimensionality information
     */
    public short getDimension ()
    {
	return ndims_;
    }

    /**
     * Return number of elements
     */
    public int getNumElements ()
    {
	return nelems_;
    }

    /**
     * Return streamed data size for this data entry
     */
    public int streamSize ()
    {
	int datasize = 0;
	int i;
	
	if (type_ == rsvcDataTypes.RSVC_INVALID)
	    return datasize;

	 // size of tag is fixed
	datasize += rsvcDataOutputStream.streamSize (tag_,
				rsvcDataTypes.RSVC_TAG_MAX_LEN);
	// data type, dim, nelems
	datasize += 3*rsvcDataOutputStream.streamSize ((int)1);
	
	if (type_ == rsvcDataTypes.RSVC_STRING) {
	    if (nelems_ == 1) 
		datasize += rsvcDataOutputStream.streamSize (sdata_[0]);
	    else {
		for (i = 0; i < nelems_; i++)
		    datasize += rsvcDataOutputStream.streamSize (sdata_[i]);
	    }
	}
	else if(type_ == rsvcDataTypes.RSVC_BYTE) 
	    datasize += nelems_*rsvcDataOutputStream.streamSize ((byte)1);
	else if(type_ == rsvcDataTypes.RSVC_INT16)
	    datasize += nelems_*rsvcDataOutputStream.streamSize ((short)1);
	else if(type_ == rsvcDataTypes.RSVC_INT32)
	    datasize += nelems_*rsvcDataOutputStream.streamSize ((int)1);
	else if(type_ == rsvcDataTypes.RSVC_FLOAT)
	    datasize += nelems_*rsvcDataOutputStream.streamSize ((float)1.0);
	else if(type_ == rsvcDataTypes.RSVC_DOUBLE)
	    datasize += nelems_*rsvcDataOutputStream.streamSize ((double)1.0);
	else if(type_ == rsvcDataTypes.RSVC_TIMESTAMP){
	    rsvcTimeStamp ts = new rsvcTimeStamp();
	    datasize += nelems_*rsvcDataOutputStream.streamSize (ts);
	}
	else if(type_ == rsvcDataTypes.RSVC_LONG)
	    datasize += nelems_*rsvcDataOutputStream.streamSize ((long)1);
	
	return datasize;
    }

    /**
     * Convert this data entry into a byte stream
     */
    public void streamOut (rsvcDataOutputStream output) throws IOException
    {
	int i;
	if (type_ != rsvcDataTypes.RSVC_INVALID) {
	    try {
		output.write (tag_, rsvcDataTypes.RSVC_TAG_MAX_LEN);
	    }catch (IOException e) {
		throw e;
	    }

	    try {
		output.write (type_);
	    }catch (IOException e) {
		throw e;
	    }

	    try {
		output.write (ndims_);
	    }catch (IOException e) {
		throw e;
	    }
	    
	    // to make stream data compatible to output generated
	    // by C++ code
	    int numelems;
	    if (type_ == rsvcDataTypes.RSVC_STRING) {
		if (ndims_ == 0)
		    numelems = sdata_[0].length() + 1;
		else
		    numelems = nelems_;
	    }
	    else {
		if (ndims_ == 0)
		    numelems = 0;
		else
		    numelems = nelems_;
	    }
	    
	    try {
		output.write (numelems);
	    }catch (IOException e) {
		throw e;
	    }
	    
	    if (type_ == rsvcDataTypes.RSVC_STRING) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write (sdata_[i]);
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	    else if (type_ == rsvcDataTypes.RSVC_BYTE) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write (data_[i].byteValue());
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	    else if (type_ == rsvcDataTypes.RSVC_INT16) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write (data_[i].shortValue());
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	    else if (type_ == rsvcDataTypes.RSVC_INT32) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write (data_[i].intValue());
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	    else if (type_ == rsvcDataTypes.RSVC_LONG) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write (data_[i].longValue());
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	    else if (type_ == rsvcDataTypes.RSVC_FLOAT) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write (data_[i].floatValue());
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	    else if (type_ == rsvcDataTypes.RSVC_DOUBLE) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write (data_[i].doubleValue());
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	    else if (type_ == rsvcDataTypes.RSVC_TIMESTAMP) {
		for (i = 0; i < nelems_; i++) {
		    try {
			output.write ((rsvcTimeStamp)data_[i]);
		    }catch (IOException e) {
			throw e;
		    }
		}
	    }
	}

    }
    
}

    

