//
// RealTuple.java
//
/*
VisAD system for interactive analysis and visualization of numerical
data. Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
package visad;
import java.rmi.*;
/**
RealTuple is the VisAD data class for vectors in R^n for n>0.
RealTuple objects are immutable.
*/
public class RealTuple
extends Tuple
implements RealTupleIface
{
private CoordinateSystem TupleCoordinateSystem;
private boolean checkRealUnits;
/*
* Simply copies of Unit-s from Real tupleComponents.
* Will be null if RealTuple(RealTupleType) constructor is used.
*/
private Unit[] TupleUnits = null;
/**
* construct a RealTuple object with the missing value
* @param type RealTupleType of this RealTuple
*/
public RealTuple(RealTupleType type) {
super(type);
TupleCoordinateSystem = type.getCoordinateSystem();
if (tupleComponents != null) {
int n = tupleComponents.length;
TupleUnits = new Unit[n];
for (int i=0; iNB: setting this to false
* can cause problems if the units are not convertible.
* Only do this if you know what you are doing.
*/
public RealTuple(RealTupleType type, Real[] reals, CoordinateSystem coord_sys,
Unit[] units, boolean checkUnits)
throws VisADException, RemoteException {
super(type, reals, false); // copy == false because Reals are immutable
TupleUnits = units;
checkRealUnits = checkUnits;
init_coord_sys(coord_sys);
}
/**
* construct a RealTuple according to an array of Real objects
* @param reals array of reals
*/
public RealTuple(Real[] reals)
throws VisADException, RemoteException {
this((RealTupleType)buildTupleType(reals), reals, null,
buildTupleUnits(reals), false);
}
/**
* Construct a RealTuple according to a RealTupleType and a double array
* @param type RealTupleType of this RealTuple
* @param values values for each component. Units are the default units
* of the RealTupleType components.
*/
public RealTuple(RealTupleType type, double[] values)
throws VisADException, RemoteException {
this(type, buildRealArray(type, values), null, type.getDefaultUnits(), false);
}
/** initialize TupleCoordinateSystem and TupleUnits */
private void init_coord_sys(CoordinateSystem coord_sys)
throws VisADException {
CoordinateSystem cs = ((RealTupleType) Type).getCoordinateSystem();
if (coord_sys == null) {
TupleCoordinateSystem = cs;
}
else {
if (cs == null || !cs.getReference().equals(coord_sys.getReference())) {
throw new CoordinateSystemException("RealTuple: coord_sys " +
coord_sys.getReference() +
" must match" +
" Type.DefaultCoordinateSystem " +
(cs == null ? null :
cs.getReference()));
}
TupleCoordinateSystem = coord_sys;
}
if (TupleCoordinateSystem != null &&
!Unit.canConvertArray(TupleCoordinateSystem.getCoordinateSystemUnits(),
((RealTupleType) Type).getDefaultUnits())) {
throw new UnitException("RealTuple: CoordinateSystem Units must be " +
"convertable with Type default Units");
}
if (TupleUnits == null) {
int n = tupleComponents.length;
TupleUnits = new Unit[n];
for (int i=0; i
Ads help maintain this website.