Jim LaGrone <[email protected]> wrote on 08/12/2009 05:43:42 PM:
> On Aug 12, 2009, at 10:23 AM, Igor Peshansky wrote:
>
> > But you could provide your own implementation of Marshal[Double]
> > that reads bytes in whatever order you wish. For example:
> >
> > class LSB {
> > public static class MyDoubleMarshal implements Marshal[Double] {
> > public def read(r: Reader): Double throws IOException {
> > var l: Long = 0l;
> > for (var shift: Int = 0; shift < 64; shift+=8) {
> > val b : Long = r.read();
> > l |= (b & 0xff) << shift;
> > }
> > return Double.fromLongBits(l);
> > }
> >
> > public def write(w: Writer, d: Double): Void throws
> > IOException {
> > val l: Long = d.toLongBits();
> > for (var shift: Int = 0; shift < 64; shift+=8) {
> > val b = ((l >>> shift) & 0xffL) as Byte;
> > w.write(b);
> > }
> > }
> > }
> > const DOUBLE = new MyDoubleMarshal();
> > }
> >
> > You can then use the above as follows:
> >
> > val r: Reader = ...;
> > val d: Double = r.read(LSB.DOUBLE);
> >
> > or even
> >
> > val da = Rail.makeVar[Double](100);
> > r.read(LSB.DOUBLE, da);
> >
> > to read an array of 100 doubles in LSB format.
>
> This array is really a Rail (local). Given no apparent method for
> reading an Array[Double], can I read multiple Rail[Double] multiple
> time and assign each to a row in the Array[Double]? Otherwise it
> appears I would have to read each byte individually.
Right, sorry, I meant a Rail (a Java-style array). There is no easy
way to read an Array[T] in one go. You can at least provide a Marshal
and read the array T by T, rather than byte by byte.
Beware that to read a distributed array, you would need to either
implement distributed file handles, or read in one place and transfer
the data to another. It's not as easy as it seems initially.
Igor
--
Igor Peshansky (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users