
ncsa.hdf.object.h4.H4Vdata Maven / Gradle / Ivy
/*****************************************************************************
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of the HDF Java Products distribution. *
* The full copyright notice, including terms governing use, modification, *
* and redistribution, is contained in the files COPYING and Copyright.html. *
* COPYING can be found at the root of the source code distribution tree. *
* Or, see http://hdfgroup.org/products/hdf-java/doc/Copyright.html. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
****************************************************************************/
package ncsa.hdf.object.h4;
import java.util.List;
import java.util.Vector;
import ncsa.hdf.hdflib.HDFConstants;
import ncsa.hdf.hdflib.HDFException;
import ncsa.hdf.hdflib.HDFLibrary;
import ncsa.hdf.object.Attribute;
import ncsa.hdf.object.CompoundDS;
import ncsa.hdf.object.Dataset;
import ncsa.hdf.object.Datatype;
import ncsa.hdf.object.FileFormat;
/**
* H4Vdata describes a multi-dimension array of HDF4 vdata, inheriting CompoundDS.
*
* A vdata is like a table that consists of a collection of records whose values
* are stored in fixed-length fields. All records have the same structure and
* all values in each field have the same data type. Vdatas are uniquely
* identified by a name, a class, and a series of individual field names.
*
* How to Select a Subset
*
* Dataset defines APIs for read, write and subet a dataset. No function is defined
* to select a subset of a data array. The selection is done in an implicit way.
* Function calls to dimension information such as getSelectedDims() return an array
* of dimension values, which is a reference to the array in the dataset object.
* Changes of the array outside the dataset object directly change the values of
* the array in the dataset object. It is like pointers in C.
*
*
* The following is an example of how to make a subset. In the example, the dataset
* is a 4-dimension with size of [200][100][50][10], i.e.
* dims[0]=200; dims[1]=100; dims[2]=50; dims[3]=10;
* We want to select every other data points in dims[1] and dims[2]
*
int rank = dataset.getRank(); // number of dimension of the dataset
long[] dims = dataset.getDims(); // the dimension sizes of the dataset
long[] selected = dataset.getSelectedDims(); // the selected size of the dataet
long[] start = dataset.getStartDims(); // the off set of the selection
long[] stride = dataset.getStride(); // the stride of the dataset
int[] selectedIndex = dataset.getSelectedIndex(); // the selected dimensions for display
// select dim1 and dim2 as 2D data for display,and slice through dim0
selectedIndex[0] = 1;
selectedIndex[1] = 2;
selectedIndex[1] = 0;
// reset the selection arrays
for (int i=0; i
*
*
* @version 1.1 9/4/2007
* @author Peter X. Cao
*/
public class H4Vdata extends CompoundDS
{
/**
*
*/
private static final long serialVersionUID = -5978700886955419959L;
/**
* The list of attributes of this data object. Members of the list are
* instance of Attribute.
*/
private List attributeList;
/**
* Number of records of this Vdata table.
*/
private int numberOfRecords;
/**
* The data types of the members of the compound dataset.
*/
private int[] memberTIDs;
private int nAttributes = -1;
public H4Vdata(FileFormat theFile, String name, String path)
{
this(theFile, name, path, null);
}
/**
* Creates an H4Vdata object with specific name and path.
*
* @param theFile the HDF file.
* @param name the name of this H4Vdata.
* @param path the full path of this H4Vdata.
* @param oid the unique identifier of this data object.
*/
public H4Vdata(
FileFormat theFile,
String name,
String path,
long[] oid)
{
super (theFile, name, path, oid);
numberOfRecords = 0;
numberOfMembers = 0;
memberOrders = null;
}
/*
* (non-Javadoc)
* @see ncsa.hdf.object.DataFormat#hasAttribute()
*/
public boolean hasAttribute ()
{
if (nAttributes < 0) {
int id = open();
try { nAttributes = HDFLibrary.VSnattrs(id); }
catch (Exception ex ) { nAttributes = 0;}
close(id);
}
return (nAttributes>0);
}
// implementing Dataset
@Override
public Datatype getDatatype()
{
if (datatype == null)
{
datatype = new H4Datatype(-1);
}
return datatype;
}
// Implementing Dataset
@Override
public byte[] readBytes() throws HDFException
{
byte[] theData = null;
if (rank <=0 ) {
init();
}
if (numberOfMembers <= 0) {
return null; // this Vdata does not have any filed
}
int id = open();
if (id < 0) {
return null;
}
String allNames = memberNames[0];
for (int i=0; i0) {
return; // already called. Initialize only once
}
int id = open();
if (id < 0) {
return;
}
try {
numberOfMembers = HDFLibrary.VFnfields(id);
numberOfRecords = HDFLibrary.VSelts(id);
} catch (HDFException ex) {
numberOfMembers = 0;
numberOfRecords = 0;
}
// Still need to get information if there is no record, see bug 1738
// if ((numberOfMembers <=0) || (numberOfRecords <= 0))
// {
// // no table field is defined or no records
// close(id);
// return;
// }
// a Vdata table is an one dimension array of records.
// each record has the same fields
rank = 1;
dims = new long[1];
dims[0] = numberOfRecords;
selectedDims = new long[1];
selectedDims[0] = numberOfRecords;
selectedIndex[0] = 0;
startDims = new long[1];
startDims[0] = 0;
memberNames = new String[numberOfMembers];
memberTIDs = new int[numberOfMembers];
memberTypes = new Datatype[numberOfMembers];
memberOrders = new int[numberOfMembers];
isMemberSelected = new boolean[numberOfMembers];
for (int i=0; i