Tennessee Leeuwenberg has pointed out that I can get the results that I want
using the netCDF implementation: This time I can
read as many times as I like.

This appears to have answered my question so there's no pressing need for
anybody to go looking through BinaryReader to see the cause of my initial
problem (unless they want to).



-----Original Message-----
[mailto:owner-visad@xxxxxxxxxxxxxxxx]On Behalf Of Rob Hackett
Sent: Tuesday, 3 February 2004 12:26

He everyone

  I am writing an application that uses point data from meteorological
observing stations. The data is extracted from a database using the
AddePointDataReader class before being converted into a visad FieldImpl of
the form:

(Time -> (IDN -> (Latitude, Longitude, Date, Time, Temperature, etc))

where IDN is the id number of the station from where the observation is
made. Essentially a field of times, where the range for each time, is a
field of station based observations.

  I would like to be able to write this field to a local file to allow it to
be archived seperately from ADDE database, along with any changes that a
user may have made to the field. I have chosen to do this using BinaryWriter
and reading the field back using BinaryReader, as they seem to offer a
simple, efficient means to do this.

  My code looks something like this:

         * Write field to file
        void write(FieldImpl field, String filename)
                File file = new File(filename);
                FileOutputStream oStream = new FileOutputStream(file);
                BinaryWriter writer = new BinaryWriter(oStream);

         * Read field from file
        FieldImpl read(String filename)
                File file = new File(filename);
                FileInputStream iStream = new FileInputStream(file);
                BinaryReader reader = new BinaryReader(iStream);
                field = (FieldImpl)reader.getData();

                return field;

        Initially this gets me exactly what I want, the field is written to 
and when read back in is exactly as it was before. The problem is I can only
read it once. If I attempt to read the file again (or any other file
containing this field structure) I get the following stack trace:

Error: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
        at java.util.ArrayList.RangeCheck(
        at java.util.ArrayList.get(
        at TestBinaryIO.main(

        I can't reproduce this error using a more simple gridded FlatField, and 
error also occurs if I have previously used a field of this form when
extracted directly from AddePointDataReader, without having made any
previous reference to BinaryWriter or BinaryReader. It seems to be specific
to the data field structure that I'm trying to store.

        Could anyone explain to me what might be happening? Or alternatively
suggest another, equally simple way of storing a field of this structure to
a local file.



  • 2004 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: