package org.das2.qds.buffer; import java.nio.ByteBuffer; import java.text.ParseException; import org.das2.datum.TimeUtil; import org.das2.datum.Units; import org.das2.qds.QDataSet; /** * Often we see where time is left decoded in binary streams, occupying ~21 * bytes (ASCII characters) instead of 8 bytes to represent them as a double. This extension * allows this sort of data to be read in as well, making the data available * as Units.us2000. * * @author jbf */ public class TimeDataSet extends BufferDataSet { int lenBytes; double fill= -1e38; private final Units UNITS= Units.us2000; /** * Like the other constructors, but the type is needed as well to get the * number of bytes. * @param rank * @param reclen * @param recoffs * @param len0 * @param len1 * @param len2 * @param len3 * @param back * @param type string "timeXX" where XX is number of bytes, between 20 and 24. */ public TimeDataSet(int rank, int reclen, int recoffs, int len0, int len1, int len2, int len3, ByteBuffer back, Object type ) { super(rank, reclen, recoffs, len0, len1, len2, len3, type, back ); this.lenBytes= Integer.parseInt( type.toString().substring(4) ); if ( this.lenBytes<16 ) throw new IllegalArgumentException("time16 is the shortest time supported."); if ( this.lenBytes>24 ) throw new IllegalArgumentException("time24 is the longest time supported."); putProperty( QDataSet.UNITS, UNITS ); putProperty( QDataSet.FILL_VALUE, fill ); } public void setLengthBytes( int length ) { this.lenBytes= length; } private double parseTime( ByteBuffer back, int offset ) { byte[] buff= new byte[lenBytes]; for ( int i=0; i