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: Marcus G. Daniels
Subject: Re: Storing data in hdf format
Date: 26 Jun 2001 10:26:26 -0600
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.7

>>>>> "ST" == Sven N Thommesen <address@hidden> writes:

ST> I have defined an inner class 'DataRecord' which contains a bunch
ST> of integers and arrays of integers. During the program run I
ST> collect statistics and fill in this record. Then I try to write
ST> the record to a hdf file, and this is where the problems crop up.

First off, you can't put arrays in objects that are stored `shallow'.
The other thing is that any ivars you want picked up should be tagged public.

Here's an example.  The first time it is run it will write the HDF5 file,
and the second time it will print out what it finds.

import swarm.Globals;

public class InnerClassHDFDemo {
    class DataRecord {
        public int count;
        public int step;
        // remove "public" below if you want to serialize this `shallow'
        int valArray[];

        DataRecord (int count, int step) {
            valArray = new int[count];

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

    InnerClassHDFDemo () {
    }

    void test () {
        DataRecord dataRecord;

        dataRecord =
            (DataRecord) Globals.env.hdf5AppArchiver.getObject ("data");

        if (dataRecord == null)
            {
                dataRecord = new DataRecord (10, 2);
                // "Deep" or "Shallow"
                Globals.env.hdf5AppArchiver.putShallow$object ("data",
                                                               dataRecord);
            }
        else
            {

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

                // valArray will be null in case of shallow serialization
                if (dataRecord.valArray != null)
                    {
                        int lastIndex = dataRecord.count - 1;
                        int lastVal = dataRecord.valArray[lastIndex];
                        
                        System.out.println ("valArray[9]: " + lastVal);
                    }
            }
    }

    static void main (String args[]) {
        Globals.env.initSwarm ("InnerClassHDFDemo", "0.0",
                               "address@hidden",
                               args);
        
        InnerClassHDFDemo demo = new InnerClassHDFDemo ();
        demo.test ();
    }
}

                  ==================================
   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]