swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Storing data in hdf format


From: Sven Thommesen
Subject: Re: Storing data in hdf format
Date: Tue, 26 Jun 2001 23:04:04 -0500

At 05:15 PM 6/26/01 -0500, Paul Johnson wrote:
"Marcus G. Daniels" wrote:
>
> >>>>> "PJ" == Paul E Johnson <address@hidden> writes:
>
> I'd suggest changing my previous example by moving the `DataRecord'
> class outside of the primary class InnerClassHDFDemo.
>
OK, I changed the code and the example works.  Now the example is still
archived under the same name, but that name is somewhat misleading
because it is a not an inner class anymore. Oh, well

http://lark.cc.ukans.edu/~pauljohn/Swarm/WorkingExampleCode/java/InnerClassHDFDemo.java

Paul,

I have appended below a re-named and spiffed-up version of the demo program, with a couple of extra comments added to it. Feel free to post on your web site, please.

The demo works fine for me, too. As it turns out, if the app you're working on is built in a directory tree using the Java 'package' concept, the DataRecord class not only cannot be an inner class, it needs to be defined as its very own public class, with the proper 'package' statement at the top or else the appArchiver won't be able to build your class instance from a hdf record.

Sven

/*
 * HDFAppArchiverDemo mgd/pj/snt 06-26-01
 */

/*
 * Rule 1: only data declared 'public' will be saved/restored
 *         by the hdfAppArchiver
 *
 * Rule 2: the 'putShallow$object' method cannot be used to save
 *         an array of primitive types. Use 'putDeep$object' instead.
 */

/*
 * Instead of using the hdfAppArchiver, which is 'built-in',
 * you can create your own archiver object:
 *
 *   String archiverPath = "/my_path/my_archiveName";
* HDF5Archiver dataArchiver = new HDF5ArchiverImpl(getZone(), archiverPath);
 *   ...
 *   dataArchiver.putDeep$object(dataKey, dataRecord);
 */

/*
 * If your application is built as a subtree using the java 'package'
 * concept, the DataRecord class needs to be defined in its own source
 * file as a public class, with the appropriate 'package' statement
 * at the top.
 */

/*
 * It appears that for the time being, even 'putDeep$object' can only handle
 * arrays of dimension 1; it seems to croak on higher-dimensional objects.
 */

import swarm.Globals;

class DeepDataRecord {

   public int count;
   public int step;
   public int valArray[];

   DeepDataRecord () {
   }

   DeepDataRecord (int count, int step) {

      this.count = count;
      this.step = step;

      valArray = new int[count];
      valArray[0] = 0;
      for (int i = 1; i < count; i++)
          valArray[i] = valArray[i - 1] + step;
   }

}

class ShallowDataRecord {

   public int count;
   public int step;
   int valArray[];

   ShallowDataRecord () {
   }

   ShallowDataRecord (int count, int step) {
      this.count = count;
      this.step = step;

      valArray = new int[count];
      valArray[0] = 0;
      for (int i = 1; i < count; i++)
         valArray[i] = valArray[i - 1] + step;
   }
}


public class HDFAppArchiverDemo {

   HDFAppArchiverDemo () {
   }

   void testDeep () {

      DeepDataRecord deepDataRecord;

      deepDataRecord =
         (DeepDataRecord) Globals.env.hdf5AppArchiver.getObject ("deepdata");

      if (deepDataRecord == null) {

            deepDataRecord = new DeepDataRecord (8, 2);
            Globals.env.hdf5AppArchiver.putDeep$object
                ("deepdata", deepDataRecord);

      } else {

            System.out.println ("Deep count: " + deepDataRecord.count);
            System.out.println ("Deep step:  " + deepDataRecord.step);

            if (deepDataRecord.valArray == null) {
                    System.out.println("Deep: array is null");
            } else {
                  int lastIndex = deepDataRecord.count - 1;
                  int lastVal = deepDataRecord.valArray[lastIndex];

                  System.out.println
                     ("Deep valArray[" + lastIndex + "]: " + lastVal);
            }
      }
   }


   void testShallow () {

      ShallowDataRecord shallowDataRecord;

      shallowDataRecord =
(ShallowDataRecord) Globals.env.hdf5AppArchiver.getObject ("shallowdata");

      if (shallowDataRecord == null) {

            shallowDataRecord = new ShallowDataRecord (6, 3);
            Globals.env.hdf5AppArchiver.putShallow$object
                ("shallowdata", shallowDataRecord);

      } else {

            System.out.println ("Shallow count: " + shallowDataRecord.count);
            System.out.println ("Shallow step: " + shallowDataRecord.step);

            if (shallowDataRecord.valArray == null) {
               System.out.println("Shallow: array pointer is null");
            } else {
               int lastIndex = shallowDataRecord.count - 1;
               int lastVal = shallowDataRecord.valArray[lastIndex];

               System.out.println
                 ("Shallow valArray[" + lastIndex + "]: " + lastVal);
            }
      }
   }


   static void main (String args[]) {

      Globals.env.initSwarm
         ("HDFAppArchiverDemo", "0.0", "address@hidden", args);

      HDFAppArchiverDemo demo = new HDFAppArchiverDemo ();

      demo.testDeep ();
      demo.testShallow ();
   }
}




                 ==================================
  Swarm-Support is for discussion of the technical details of the day
  to day usage of Swarm.  For list administration needs (esp.
  [un]subscribing), please send a message to <address@hidden>
  with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]