Hi -

I've been trying to figure out how to read data using the hdf-java without
success.  All data values returned are zero.  Thinking the data was somehow
corrupted, I validated the file by writing an equivalent C program, and then
looked at the data using hdfview.

After validating, I decided to try the TestH4File.java example, running the
"testH4SDS" test, and --- got the same result.  All values output are zero
(and should not be).  

I've tried this on both my Mac (Lion) and on an Ubuntu 11 box.  I'm using
hdf-java 2.8 and java 1.6 (64b).

Any insights are appreciated.
Thanks,
Susan

=== output ===

Julian Date and Time
_FillValue
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
Longitude 
_FillValue
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 

(I modified line 205 to take the min of the array size of 10, vs. 1000 for
brevity.)

===== relevant code ====

    /**
     * Test H4SDS.
     */
    private static void testH4SDS(String fileName)
    {
        H4File h4file = new H4File(fileName, HDFConstants.DFACC_READ);

        try {
            h4file.open();
        } catch (Exception ex)
        {
            System.out.println(ex);
        }

        DefaultMutableTreeNode root =
(DefaultMutableTreeNode)h4file.getRootNode();
        H4SDS sds = null;
        DefaultMutableTreeNode node = null;
        if (root != null)
        {
            Enumeration nodes = root.depthFirstEnumeration();
            while (nodes.hasMoreElements())
            {
                node = (DefaultMutableTreeNode)nodes.nextElement();
                Object obj = node.getUserObject();
                if (obj instanceof H4SDS)
                {
                    sds = (H4SDS)obj;
                    System.out.println(sds);

                    // test H4CompoundDS attributes
                    Attribute attr = null;
                    List info = null;
                    try {
                        info = sds.getMetadata();
                    } catch (Exception ex)
                    { System.out.println(ex); }

                    int n = 0;
                    if (info != null)
                    {
                        n = info.size();
                        for (int i=0; i<n; i++)
                        {
                            attr = (Attribute)info.get(i);
                            System.out.println(attr);
                        }
                    }

                    // data
                    Object data = null;
                    try
                    {
                        data = sds.read();
                    } catch (Exception ex) {System.out.println(ex);}

                    if ((data != null) && data.getClass().isArray())
                    {
                        // print out the first 1000 data points
                        n = Math.min(Array.getLength(data), 10);
                        StringBuffer sb = new StringBuffer();
                        for (int j=0; j<n; j++)
                        {
                            sb.append(Array.get(data, j));
                            sb.append(" ");
                        }
                        System.out.println(sb.toString());
                    }
                } //if (obj instanceof H4Group
            } //while (nodes.hasMoreElements())
        } //if (root != null)

        try {
        h4file.close();
        } catch (Exception ex)
        {
            System.out.println(ex);
        }
    }

--
View this message in context: 
http://hdf-forum.184993.n3.nabble.com/Problems-reading-a-datatset-using-hdf-java-tp4015601.html
Sent from the hdf-forum mailing list archive at Nabble.com.

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to