package org.das2.qds.buffer; import java.nio.ByteBuffer; import java.text.ParseException; import org.das2.datum.Units; import org.das2.qds.QDataSet; /** * Sometimes you might just have numbers encoded in ASCII within a binary stream, * or fixed-length fields allow such parsing. * @author jbf */ public class AsciiDataSet extends BufferDataSet { int lenBytes; double fill= -1e38; private final Units UNITS= Units.dimensionless; /** * 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 "asciiXX" where XX is number of bytes, between 1 and 24. */ public AsciiDataSet(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(5) ); if ( this.lenBytes<1 ) throw new IllegalArgumentException("ascii1 is the shortest field supported."); if ( this.lenBytes>32 ) throw new IllegalArgumentException("ascii24 is the longest field supported."); putProperty( QDataSet.FILL_VALUE, fill ); } public void setLengthBytes( int length ) { this.lenBytes= length; } private double parseDouble( ByteBuffer back, int offset ) { byte[] buff= new byte[lenBytes]; for ( int i=0; i