Saving VisAD Data objects

I'm gonna try to get FitsForm.save() implemented in the next week or so,
in the hope that the Big Release won't be read-only.

I'm assuming that I want to use DataVisitor to suss out exactly what
the Data object holds.  Is this correct?

My first whack at this was to create a simple FitsVisitor class which
just prints the Tuple/FlatField's class and returns true.

After hooking this into a DataNode, it only seems to descend to the
FlatField level.  Does this mean I need to write the code to pick apart
the FlatField and turn it into a FITS object?

I was hoping things were automated enough that I could use some class
which would parse things for me.  I didn't turn up anything like that,
so I'm kinda mulling over what something like that would look like.

Just to check my assumptions, VisAD Data objects eventually boil down
into some sort of array, possibly sparsely filled, and possibly having
names associated with either the vertices or individual columns (or both?).
Is this a reasonable summary?

I'm thinking of writing something like the following.  Would this work
and be generally useful?  (This is the product of roughly ten minutes'
reflection, so there's probably a better way to do it all...)

        public class FieldArray {
          int getDimension();
          String[] getColumnNames();
          String[] getVertexNames();
          ??? getBaseType();    // returns Double, Float or Mixed?
          Enumeration getRows();
        }

        public class FieldArrayObject {
          boolean isBaseObject();
          Enumeration getRows();
          ?? getBaseType();     // this again
          double getColumnIndex();
          double getRowIndex();
          Scalar getScalarObject();
        }

The above seem to be general enough that I could do something like this:

        public void recurse(Enumeration arrayEnum, Object storageArray)
        {
          while (enum.hasMoreElements()) {
            FieldArrayObject obj = (FieldArrayObject )enum.nextElement();
            if (!obj.isBaseObject()) {
              recurse(obj.getRows(), storageArray);
              continue;
            }

            // at this point, you know you can safely fetch a Scalar object
            // which you can use to:
            // * write directly to a file
            // * save in row-major form
            // * save in column-major form
            // * something else my tiny mind can't imagine...
            //
            Real real = (Real )obj.getScalarObject()
            double[][] d = (double[][] )storageArray;

            d[obj.getColumnIndex()][obj.getRowIndex()] = real.getValue();
          }
        }

Another way to do the following might be to hand back a 1D array containing
a column of data, but the above seems like it'd be more general.

The classes should also probably support column-wise traversal as well,
I suppose.

There's also probably a design pattern which would better express this, but
I still haven't gotten around to picking up a book on that yet.  (I'm
planning on hitting Computer Literacy the weekend after JavaOne ... between
there and Fry's I should be able to blow a couple hundred bucks :-)

Is there a better way to do all this?  Does any of the above sound workable?

(At this point, Bill slaps his forehead, realizes just how clueless I
am, and rushes down to yank my Ethernet connection out of the wall
before I can do any more damage to his software :-)


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