/* * TableUtil.java * * Created on November 14, 2003, 6:47 PM */ package org.das2.dataset; import org.das2.datum.LocationUnits; import org.das2.datum.Units; import org.das2.datum.DatumVector; import org.das2.datum.Datum; import org.das2.datum.UnitsUtil; import org.das2.datum.TimeUtil; import org.das2.stream.StreamProducer; import org.das2.stream.DataTransferType; import org.das2.stream.StreamYScanDescriptor; import org.das2.stream.StreamDescriptor; import org.das2.stream.StreamXDescriptor; import org.das2.stream.StreamException; import org.das2.stream.PacketDescriptor; import org.das2.util.FixedWidthFormatter; import java.io.*; import java.nio.channels.*; import java.text.*; import java.util.*; import java.util.Map.Entry; import org.das2.qds.QDataSet; import org.das2.qds.SemanticOps; import org.das2.qds.ops.Ops; /** * * @author Owner */ public class TableUtil { // maybe a cache to keep track of last finds public static double[] getYTagArrayDouble( TableDataSet table, int itable, Units units ) { double[] yy= new double[table.getYLength(itable)]; for ( int j=0; j 10. ) { return Units.log10Ratio.createDatum( Math.log10(y1/y0) ); } else { if ( (yn-y0)/n > (y1-y0) ) { return table.getYUnits().createDatum((yn-y0)/n); // the average is bigger than the first. maybe return the last. } else { return table.getYUnits().createDatum(y1-y0); } } } public static double tableMax( TableDataSet tds, Units units ) { double result= Double.NEGATIVE_INFINITY; for ( int itable=0; itable result ) { result= tds.getDouble(i,j,units); } } } } return result; } public static void checkForNaN( TableDataSet tds ) { for ( int i=0; i"); pout.println("Stream creation date: "+TimeUtil.now().toString()+""); pout.print(""); if ( tds.getXUnits() instanceof LocationUnits ) { base= xmin; offsetUnits= ((LocationUnits)base.getUnits()).getOffsetUnits(); if ( offsetUnits==Units.microseconds ) { offsetUnits= Units.seconds; } } pout.print("[01]\n"); pout.print(""); StringBuilder yTagsString= new StringBuilder( ); yTagsString.append( tds.getYTagDatum(0,0) ); for ( int j=1; j"); pout.print(""); NumberFormat xnf= new DecimalFormat("00000.000"); NumberFormat ynf= new DecimalFormat("0.00E00"); double dx= xmax.subtract(xmin).doubleValue(offsetUnits); for (int i=0; i=0 && x properties= tds.getProperties(); for ( Entry e: properties.entrySet() ) { String key= e.getKey(); sd.setProperty(key, e.getValue() ); } DataTransferType zTransferType; DataTransferType xTransferType; if ( asciiTransferTypes ) { if ( UnitsUtil.isTimeLocation(tds.getXUnits()) ) { xTransferType= DataTransferType.getByName("time24"); } else { xTransferType= DataTransferType.getByName("ascii24"); } zTransferType= DataTransferType.getByName("ascii10"); } else { zTransferType= DataTransferType.getByName("sun_real4"); xTransferType= DataTransferType.getByName("sun_real8"); } if ( sendStreamDescriptor ) producer.streamDescriptor(sd); DatumVector[] zValues = new DatumVector[1]; for (int table = 0; table < tds.tableCount(); table++) { StreamXDescriptor xDescriptor = new StreamXDescriptor(); xDescriptor.setUnits(tds.getXUnits()); xDescriptor.setDataTransferType(xTransferType); StreamYScanDescriptor yDescriptor = new StreamYScanDescriptor(); yDescriptor.setDataTransferType(zTransferType); yDescriptor.setZUnits(tds.getZUnits()); yDescriptor.setYCoordinates(tds.getYTags(table)); PacketDescriptor pd = new PacketDescriptor(); pd.setXDescriptor(xDescriptor); pd.addYDescriptor(yDescriptor); producer.packetDescriptor(pd); for (int i = tds.tableStart(table); i < tds.tableEnd(table); i++) { Datum xTag = tds.getXTagDatum(i); zValues[0] = tds.getScan(i); producer.packet(pd, xTag, zValues); } } if ( sendStreamDescriptor ) producer.streamClosed(sd); } catch (StreamException se) { throw new RuntimeException(se); } } /** * return the first row before the datum. Handles mono decreasing. * @return the row which is less than or equal to the datum */ public static int getPreviousRow( TableDataSet ds, int itable, Datum datum ) { int i= closestRow( ds, itable, datum ); Units units= ds.getYUnits(); double dir= ds.getYTagDouble(itable, 1, units ) - ds.getYTagDouble(itable, 0, units ); double dd= ds.getYTagDouble(itable,i,units) - datum.doubleValue(units); if ( i>0 && ( dir * dd > 0 ) ) { return i-1; } else { return i; } } /** * return the first row after the datum. Handles mono decreasing. * @return the row which is greater than or equal to the datum */ public static int getNextRow( TableDataSet ds, int itable, Datum datum ) { int i= closestRow( ds, itable, datum ); Units units= ds.getYUnits(); double dir= ds.getYTagDouble(itable, 1, units ) - ds.getYTagDouble(itable, 0, units ); double dd= ds.getYTagDouble(itable,i,units) - datum.doubleValue(units); if ( i