|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgsfc.nssdc.cdf.Variable
public class Variable
The Variable class defines a CDF variable.
Notes:
Since the CDF JavaAPI always uses zMODE = 2
, all variables
are by default, zVariables.
Attribute
,
Entry
Field Summary |
---|
Method Summary | |
---|---|
void |
allocateBlock(long firstRec,
long lastRec)
Allocates a range of records for this variable. |
void |
allocateRecords(long num0toRecords)
Allocates a number of records, starting from record number 0. |
boolean |
checkPadValueExistence()
Checks if the pad value has been defined for this variable. |
void |
concatenateDataRecords(Variable destVar)
Concatenates this variable's data records to the destination variable. |
long |
confirmCacheSize()
Gets the number of 512-byte cache buffers defined for this variable. |
long |
confirmPadValue()
Checks the existence of an explicitly specified pad value for the current z variable. |
long |
confirmReservePercent()
Gets the reserve percentage set for this variable. |
Variable |
copy(CDF destCDF,
java.lang.String varName)
Copies this variable into a new variable and puts it into the designated CDF file. |
Variable |
copy(java.lang.String varName)
Copies this variable to a new variable. |
void |
copyDataRecords(Variable destVar)
Copies this variable's data to the destination variable. |
static Variable |
create(CDF myCDF,
java.lang.String varName,
long dataType,
long numElements,
long numDims,
long[] dimSizes,
long recVary,
long[] dimVarys)
Creates a variable. |
void |
delete()
Deletes this variable. |
void |
deleteRecords(long firstRec,
long lastRec)
Deletes a range of records from this variable. |
Variable |
duplicate(CDF destCDF,
java.lang.String varName)
Duplicates this variable and put it into the designated CDF file. |
Variable |
duplicate(java.lang.String varName)
Duplicates this variable to a new variable. |
long |
getAllocatedFrom(long recNum)
Inquires the next allocated record at or after a given record for this variable. |
long |
getAllocatedTo(long firstRec)
Inquires the last allocated record (before the next unallocated record) at or after a given record for this variable. |
java.util.Vector |
getAttributes()
Returns the variable attributes that are associated with this variable. |
long |
getBlockingFactor()
Gets the blocking factor for this variable. |
java.lang.String |
getCompression()
Gets the string representation of the compression type and parameters set for this variable. |
long[] |
getCompressionParms()
Sets the compression parameters of this variable. |
long |
getCompressionPct()
Gets the compression percentage rate of this variable. |
long |
getCompressionType()
Gets the compression type of this variable. |
long |
getDataType()
Gets the CDF data type of this variable. |
long[] |
getDimSizes()
Gets the dimensions size of this variable. |
long[] |
getDimVariances()
Gets the dimension variances for this variable. |
java.lang.Object |
getEntryData(java.lang.String attrName)
Gets the attribute entry data for this variable. |
java.lang.Object |
getHyperData(long recNum,
long recCount,
long recInterval,
long[] dimIndices,
long[] dimCounts,
long[] dimIntervals)
Reads one or more values from the current z variable. |
CDFData |
getHyperDataObject(long recNum,
long recCount,
long recInterval,
long[] dimIndices,
long[] dimCounts,
long[] dimIntervals)
Reads one or more values from the current z variable. |
long |
getID()
Gets the ID of this variable. |
long |
getMaxAllocatedRecord()
Gets the maximum allocated record number for this variable. |
long |
getMaxWrittenRecord()
Gets the last written record number, beginning with 0. |
CDF |
getMyCDF()
Gets the CDF object to which this variable belongs. |
java.lang.String |
getName()
Gets the name of this variable. |
long |
getNumAllocatedRecords()
Gets the number of records allocated for this variable. |
long |
getNumDims()
Gets the number of dimensions for this variable. |
long |
getNumElements()
Gets the number of elements for this variable. |
long |
getNumWrittenRecords()
Gets the number of records physically written (not allocated) for this variable. |
java.lang.Object |
getPadValue()
Gets the pad value set for this variable. |
java.lang.Object |
getRecord(long recNum)
Gets a single record from this variable. |
CDFData |
getRecordObject(long recNum)
Get a single record of data from this variable. |
CDFData |
getRecordsObject(long recNum,
long numRecs)
Get a number of records of data from this variable. |
boolean |
getRecVariance()
Gets the value of record variance. |
java.lang.Object |
getScalarData()
Gets the scalar data from a non-record varying 0-dimensional variable. |
java.lang.Object |
getScalarData(long recNum)
Get the scalar data from a record varying 0-dimensional variable. |
CDFData |
getScalarDataObject()
Get the scalar data from a non-record varying 0-dimensional variable. |
CDFData |
getScalarDataObject(long recNum)
Get the scalar data from this record varying 0-dimensional variable. |
java.lang.Object |
getSingleData(long recNum,
long[] indices)
Gets a single data value. |
CDFData |
getSingleDataObject(long recNum,
long[] indices)
Gets a single data object from this variable. |
long |
getSparseRecords()
Gets the sparse record type for this variable. |
void |
putEntry(Attribute attr,
long dataType,
java.lang.Object data)
Creates an attribute entry for this variable. |
void |
putEntry(java.lang.String attrName,
long dataType,
java.lang.Object data)
Creates an attribute entry for this variable. |
CDFData |
putHyperData(long recNum,
long recCount,
long recInterval,
long[] dimIndices,
long[] dimCounts,
long[] dimIntervals,
java.lang.Object data)
Writes one or more values from the current z variable. |
CDFData |
putRecord(long recNum,
java.lang.Object data)
Adds a single record to a record-varying variable. |
CDFData |
putRecord(java.lang.Object data)
Adds a single record to a non-record-varying variable. |
CDFData |
putScalarData(long recNum,
java.lang.Object data)
Adds a scalar data to this variable (of 0 dimensional). |
CDFData |
putScalarData(java.lang.Object data)
Adds a scalar data to this variable (of 0 dimensional). |
CDFData |
putSingleData(long recNum,
long[] indices,
java.lang.Object data)
Adds a single data value to this variable. |
void |
rename(java.lang.String newName)
Renames the current variable. |
void |
selectCacheSize(long cacheSize)
Sets the number of 512-byte cache buffers to be used. |
void |
selectReservePercent(long reservePercent)
Sets the reserve percentage to be used for this variable. |
void |
setBlockingFactor(long blockingFactor)
Sets the blocking factor for this variable. |
void |
setCompression(long cType,
long[] cParms)
Sets the compression type and parameters for this variable. |
void |
setDimVariances(long[] dimVariances)
Sets the dimension variances for this variable. |
void |
setInitialRecords(long nRecords)
Sets the number of records to be written initially for this variable. |
void |
setPadValue(java.lang.Object padValue)
Sets the pad value for this variable. |
void |
setRecVariance(long recVariance)
Sets the record variance for this variable. |
void |
setSparseRecords(long sparseRecords)
Sets the sparse record type for this variable. |
java.lang.String |
toString()
Gets the name of this variable. |
void |
updateDataSpec(long dataType,
long numElements)
Update the data specification (data type and number of elements) of the variable. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static Variable create(CDF myCDF, java.lang.String varName, long dataType, long numElements, long numDims, long[] dimSizes, long recVary, long[] dimVarys) throws CDFException
The following example creates a variable called "Longitude" that is scalar (non-array) and record-varying:
longitude = Variable.create(cdf, "Longitude", CDF_INT2, 1L, 0L, new long [] {1}, VARY, new long [] {NOVARY});The following example creates a variable called "TestData" whose data is 2-dimensional (3 x 2), record variance is TURE, and dimension variances are TRUE.
data = Variable.create(cdf, "TestData", CDF_INT2, 1L, 2L, new long [] {3,2}, VARY, new long [] {VARY, VARY});
myCDF
- the CDF to which this variable belongs varName
- the name of the variable to create dataType
- the CDF data type for this variable that should be one
of the following:
numElements
- for CDF_CHAR and CDF_UCHAR this is the
string length, 1 otherwise numDims
- the dimensionality dimSizes
- The dimension sizes. An array of length numDims
indicating the size of each dimension recVary
- the record variance that should be either
VARY or NOVARY dimVarys
- The dimension variance(s). Each dimension variance
should be either VARY or NOVARY.
CDFException
- if there is a problem creating a variablepublic void delete() throws CDFException
delete
in interface CDFObject
CDFException
- if there was an error deleting this variablepublic void rename(java.lang.String newName) throws CDFException
rename
in interface CDFObject
newName
- the new variable name
CDFException
- if there was a problem renaming this variablepublic Variable copy(java.lang.String varName) throws CDFException
varName
- the name of the variable to copy this variable into
CDFException
- if there was a problem copying a variable public Variable copy(CDF destCDF, java.lang.String varName) throws CDFException
destCDF
- the destination CDF into which copy this variablevarName
- the new variable name
CDFException
- if there was a problem copying a variable public Variable duplicate(java.lang.String varName) throws CDFException
Note: This copies everything from the existing variable to a new variable. It includes the metadata associated with this variable, all data records as well as other information such as blocking factor/compression/sparseness/pad value.
varName
- the name of the variable to duplicate this
variable into
CDFException
- if there was a problem duplicating
a variable public Variable duplicate(CDF destCDF, java.lang.String varName) throws CDFException
Note: This copies everything from the current variable to a new variable. It includes the metadata associated with this variable, all data records as well as other information such as blocking factor/compression/sparseness/pad value.
destCDF
- the destination CDF to duplicate this variable into varName
- the name of the variable to duplicate this variable
into
CDFException
- if there was a problem duplicating a variablepublic void copyDataRecords(Variable destVar) throws CDFException
Note: This copies data records from the current variable to the destination variable. The metadata associated with the destination variable will be not changed.
The current CDF file MUST be saved first (by calling the save() method) before 'copying/duplicating data records' operation is performed. Otherwise the program will either fail or produce undesired results.
destVar
- the destination variable to copy data into
CDFException
- if there was a problem copying data recordspublic void concatenateDataRecords(Variable destVar) throws CDFException
Note: This copies only the data records from the current variable to the destination variable. The metadata associated with the destination variable will be not changed.
destVar
- the destination variable to copy data records into
CDFException
- if there was a problem copying data recordspublic java.lang.Object getEntryData(java.lang.String attrName) throws CDFException
The following examples retrieves the 'Longitude' variable entry for the attribute VALIDMIN:
Variable var = cdf.getVariable("Longitude"); float longitude = (float) var.getEntryData("VALIDMIN");
attrName
- the name of the attribute to get entry data from
CDFException
- if there was a problem getting entry datapublic java.lang.Object getSingleData(long recNum, long[] indices) throws CDFException
Let's assume that variable TestData is defined to be 1-dimensional array that has 3 elements in it. The following example extracts the last element from the second record:
Variable var = cdf.getVariable("TestData"); int data = (int) var.getSingleData(1L, new long [] {2});Let's assume that variable TestData is defined to be 2-dimensional (3x2 - 3 rows and 2 columns) array. The following example extracts the first element of the second row from the first record:
Variable var = cdf.getVariable("TestData"); int data = (int) var.getSingleData(0L, new long [] {1,0});
recNum
- the record number to retrieve data from indices
- the index, within a record, to extract data from
CDFException
- if there was a problem extracting datapublic CDFData getSingleDataObject(long recNum, long[] indices) throws CDFException
recNum
- the record number to retrieve data from indices
- the index, within a record, to extract data from
CDFException
- if there was a problem extracting datapublic java.lang.Object getRecord(long recNum) throws CDFException
Let's assume that variable TestData is defined to be 2-dimensional (3x2 - 3 rows and 2 columns). The following example extracts an entire record (containing 6 elements) from the first record from a variable of data type CDF_INT4:
Variable var = cdf.getVariable("TestData"); int[][] data = (int [][]) var.getRecord(0L);However, if a dimensional variable with all indices being invariant, e.g., 2-dimensional (1x1), the retrieved object will be different. (Since the variable has only one data value per record, it is preferred to be defined as an 0-dim, rather.). The object is not an array, instead, a single Java class item, e.g., Integer, Double, Short, etc. The following example extracts an record from the first record of a variable, 2-dim (1x1), with data type CDF_INT2:
Variable var = cdf.getVariable("TestVar"); short data = ((Short) var.getRecord(0L)).shortValue();
recNum
- the record number to retrieve data from
CDFException
- if there was a problem getting a recordpublic CDFData getRecordObject(long recNum) throws CDFException
recNum
- the record number to retrieve data from
CDFException
- if there was a problem getting a recordpublic CDFData getRecordsObject(long recNum, long numRecs) throws CDFException
recNum
- the record number to start to retrieve data from numRecs
- the number of records to retrieve
CDFException
- if there was a problem getting the record(s)public java.lang.Object getScalarData() throws CDFException
CDFException
- if there was a problem getting datapublic java.lang.Object getScalarData(long recNum) throws CDFException
recNum
- The record number to retrieve data from
CDFException
- if there was a problem getting datapublic CDFData getScalarDataObject() throws CDFException
CDFException
- if there was a problem getting datapublic CDFData getScalarDataObject(long recNum) throws CDFException
recNum
- the record number to retrieve data from
CDFException
- if there was a problem getting datapublic java.lang.Object getHyperData(long recNum, long recCount, long recInterval, long[] dimIndices, long[] dimCounts, long[] dimIntervals) throws CDFException
Let's assume that variable TestData is defined to be 2-dimensional (3x2 - 3 rows and 2 columns). The following example extracts the entire record (containing 6 elements) from the first, second, and third records:
Variable var = cdf.getVariable("TestData"); int[][][] data = (int [][][]) var.getHyperData (0L, 3L, 1L, new long[] {0, 0}, new long[] {3, 2}, new long[] {1, 1});The following example will extract the entire record from the first record:
Variable var = cdf.getVariable("TestData"); int[][] data = (int [][]) var.getHyperData (0L, 1L, 1L, new long[] {0, 0}, new long[] {3, 2}, new long[] {1, 1});Note: it returns a 2-dimensional object as only one record is involved. The following example will extract the second row from the first, and third records:
Variable var = cdf.getVariable("TestData"); int[][] data = (int [][]) var.getHyperData (0L, 3L, 2L, new long[] {1, 0}, new long[] {1, 2}, new long[] {1, 1});The following example will extract the first column from the first and second records:
Variable var = cdf.getVariable("TestData"); int[][] data = (int [][]) var.getHyperData (0L, 2L, 1L, new long[] {0, 0}, new long[] {3, 1}, new long[] {1, 1});
recNum
- the record number at which data search begins recCount
- the number of records to read recInterval
- the number of records to skip between reads dimIndices
- the dimension index within a record at which data
search begins dimCounts
- the number of elements to read from dimIndices dimIntervals
- the number of elements to skip between reads
CDFException
- if there was a problem getting datapublic CDFData getHyperDataObject(long recNum, long recCount, long recInterval, long[] dimIndices, long[] dimCounts, long[] dimIntervals) throws CDFException
recNum
- the record number at which data search beginsrecCount
- the number of records to readrecInterval
- the number of records to skip between readsdimIndices
- the dimension index within a record at which data
search beginsdimCounts
- the number of elements to read from dimIndicesdimIntervals
- the number of elements to skip between reads
CDFException
- if there was a problem getting datapublic void putEntry(java.lang.String attrName, long dataType, java.lang.Object data) throws CDFException
The following example creates a variable entry for the variable "Longitude" associated with the attribute "VALIDMIN":
Variable longitude = cdf.getVariable("Longitude"); longitude.putEntry("VALIDMIN", CDF_INT2, new Short((short)180));
attrName
- the attribute to which this attribute entry is attacheddataType
- the CDF data type of the entry data - see the
description of the create method in this class for
a list of the CDF data types supporteddata
- the attribute entry data to be added
CDFException
- if a problem occurs putting an entryAttribute
,
Entry
public void putEntry(Attribute attr, long dataType, java.lang.Object data) throws CDFException
Variable longitude = cdf.getVariable("Longitude"); Attribute validMin = Attribute.create(cdf, "VALIDMIN", VARIABLE_SCOPE); Entry.create(validMin, longitude.getID(), CDF_INT2, new Short((short)10));OR
longitude.putEntry(validMin, CDF_INT2, new Short((short)180));
attr
- the attribute to which this attribute entry is attached dataType
- the CDF data type of the entry data - see the
description of the create method in this class for
a list of the CDF data types supporteddata
- the attribute entry data to be added
CDFException
- if a problem occurs putting an entryAttribute
,
Entry
public CDFData putSingleData(long recNum, long[] indices, java.lang.Object data) throws CDFException
longitude = cdf.getVariable("Longitude"); longitude.putSingleData(0L, new long[] {1}, new Short((short)200)); or longitude.putSingleData(0L, new long[] {1}, longitudeData[1]);
recNum
- the record number to which this data belongs indices
- the index (location) in the specified record data
- the data to be added
CDFException
- if there was an error writing datapublic CDFData putScalarData(long recNum, java.lang.Object data) throws CDFException
longitude = cdf.getVariable("Longitude"); longitude.putScalarData(0L, new Short((short)200)); or longitude.putScalarData(0L, longitudeData[0]);
recNum
- the record number to which this data belongs data
- the data to be added
CDFException
- if there was an error writing datapublic CDFData putScalarData(java.lang.Object data) throws CDFException
longitude = cdf.getVariable("Longitude"); longitude.putScalarData(new Short((short)200)); or longitude.putScalarData(longitudeData[0]);
data
- the data to be added
CDFException
- if there was an error writing datapublic CDFData putRecord(long recNum, java.lang.Object data) throws CDFException
The following example adds a scalar data to record number 0:longitude = cdf.getVariable("Longitude"); longitude.putRecord(0L, new Short((short)200));
The following example adds multiple elements (array) to record number 0:
short [] longitudeData = {10, 20, 30}; longitude = cdf.getVariable("Longitude"); longitude.putRecord(0L, longitudeData);
recNum
- the record number to which this data belongs data
- the data to be added
CDFException
- if there was a problem writing datapublic CDFData putRecord(java.lang.Object data) throws CDFException
The following example adds a scalar data to record number 0:longitude = cdf.getVariable("Longitude"); longitude.putRecord(new Short((short)200));
The following example adds multiple elements (array) to record number 0:
short [] longitudeData = {10, 20, 30}; longitude = cdf.getVariable("Longitude"); longitude.putRecord(longitudeData);
data
- the data to be added
CDFException
- if there was a problem writing datapublic CDFData putHyperData(long recNum, long recCount, long recInterval, long[] dimIndices, long[] dimCounts, long[] dimIntervals, java.lang.Object data) throws CDFException
Let's assume that variable TestData is defined to be 2-dimensional (3x2 - 3 rows and 2 columns). The following example writes the entire record (containing 6 elements) to the first, second, and third records:
long [][][] testData = {{{10,20},{30,40},{50, 60}}, {{15,25},{45,55},{75, 85}} {{90,95},{96,97},{2147483648L,4294967295L}} }; testData.putHyperData (0L, 3L, 1L, new long[] {0, 0}, new long[] {3, 2}, new long[] {1, 1});The following example will write the first two rows of testData to the first, third, and fifth records:
testData.putHyperData (0L, 3L, 2L, new long[] {0, 0}, new long[] {2, 2}, new long[] {1, 1});
recNum
- the record number at which data write begins recCount
- the number of records to write recInterval
- the number of records to skip between writes dimIndices
- the dimension index within a record at which data
write begins dimCounts
- the number of elements to write from dimIndices dimIntervals
- the number of elements to skip between writes data
- the data to be written
CDFException
- if there was a problem writing datapublic CDF getMyCDF()
public long getCompressionType()
public long getCompressionPct()
public long[] getCompressionParms()
public void setCompression(long cType, long[] cParms) throws CDFException
cType
- the compression typecParms
- the compression parameters that go with cType
CDFException
- if a problem occurs setting compression
type and parameterspublic java.lang.String getCompression() throws CDFException
CDFException
- if a problem occurs getting the compression
type and parameterspublic long getNumDims()
public long[] getDimSizes()
public long getNumElements()
public java.lang.String getName()
getName
in interface CDFObject
public long getID()
public java.lang.String toString()
toString
in class java.lang.Object
public void setRecVariance(long recVariance) throws CDFException
recVariance
- the record variance that should be either
VARY or NOVARY.
CDFException
- if a problem occurs setting the record
variancepublic boolean getRecVariance()
public void setDimVariances(long[] dimVariances) throws CDFException
dimVariances
- the dimension variances for this variable
CDFException
- if a problem occurs setting the
dimension variancespublic long[] getDimVariances()
public long getDataType()
public void deleteRecords(long firstRec, long lastRec) throws CDFException
firstRec
- the first record to be deletedlastRec
- the last record to be deleted
CDFException
- if a problem occurs deleting recordspublic void allocateBlock(long firstRec, long lastRec) throws CDFException
firstRec
- the first record to be allocatedlastRec
- the last record to be allocated
CDFException
- if a problem occurs allocating recordspublic void allocateRecords(long num0toRecords) throws CDFException
num0toRecords
- the number of records to be allocated
CDFException
- if a problem occurs allocating recordspublic long getNumWrittenRecords() throws CDFException
CDFException
- if a problem occurs getting the number
of records written physicallypublic long getMaxWrittenRecord() throws CDFException
CDFException
- if a problem occurs getting the last
written record numberpublic long getNumAllocatedRecords() throws CDFException
CDFException
- if a problem occurs getting the
number of records allocatedpublic long getMaxAllocatedRecord() throws CDFException
CDFException
- if a problem occurs getting the
maximum allocated record numberpublic void setPadValue(java.lang.Object padValue) throws CDFException
padValue
- the pad value to be used for undefined values
CDFException
- if a problem occurs setting the pad valuepublic boolean checkPadValueExistence() throws CDFException
Note: The system default pad value is returned if getPadValue() is called.
CDFException
- if a problem occurs checking the existence of the
pad valuepublic java.lang.Object getPadValue()
public void setSparseRecords(long sparseRecords) throws CDFException
sparseRecords
- sparse record type that should be one of the
following types:
CDFException
- if a problem occurs setting the sparse
record typepublic long getSparseRecords()
public void setBlockingFactor(long blockingFactor) throws CDFException
blockingFactor
- the blocking factor - a value of zero (0)
indicates that the default blocking
factor should be used
CDFException
- if a problem occurs setting the blocking factorpublic long getBlockingFactor() throws CDFException
CDFException
- if a problem occurs getting the blocking
factor set for this variablepublic void setInitialRecords(long nRecords) throws CDFException
nRecords
- the number of records to be written initially
CDFException
- if a problem occurs writing initial recordspublic void selectCacheSize(long cacheSize) throws CDFException
cacheSize
- the number of 512-byte cache buffers
CDFException
- if a problem occurs allocating cache bufferspublic long confirmCacheSize() throws CDFException
CDFException
- if a problem occurs getting the number
of cache buffers set for this variablepublic void selectReservePercent(long reservePercent) throws CDFException
reservePercent
- the reserve percentage to be used
CDFException
- if a problem occurs setting a reserve
percentagepublic long confirmReservePercent() throws CDFException
CDFException
- if a problem occurs getting the reserve
percentagepublic long confirmPadValue() throws CDFException
CDFException
- if a problem occurs checking the
existence of pad value.public long getAllocatedFrom(long recNum) throws CDFException
recNum
- The record number at which to begin searching for the
next allocated record. If this record exists, it will
be considered the next allocated record.
CDFException
- if a problem occurs getting the number
of the next allocated recordpublic long getAllocatedTo(long firstRec) throws CDFException
firstRec
- the record number at which to begin searching for the
last allocated record
CDFException
- if a problem occurs getting the number
of the last allocated recordpublic void updateDataSpec(long dataType, long numElements) throws CDFException
CDFException
public java.util.Vector getAttributes()
The following example describes how to retrieve all the variable attributes that are associated with a particular variable. Variable v = cdf.getVariable("myVariable"); Vector attrs = v.getAttributes(); if (attrs.size() > 0) { for (Enumeration e=attrs.elements(); e.hasMoreElements();) { Attribute a = (Attribute) e.nextElement(); // manipulate the attribute } }
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |