This project is read-only.

How-To ...

Add new variable.
  • Methods DataSet.AddVariable create a new storage variable, i.e. a variable that stores data somehow.
  • Methods DataSet.AddVariableByReference(Variable, params String[]) create a reference variable that does not store anything but refers to a variable of another DataSet.
  • Methods DataSet.AddVariableByValue(Variable, String, params String[]) create a new storage variable as a copy of another variable.
Put data into a variable.
  • Methods Variable.PutData(Array) and Variable.PutData(Int32[], Array) put an array into a variable.
  • Methods Variable.Append(Array), Variable.Append(Array, Int32) and Variable.Append(Array, String) put an array at the end of the variable by a certain dimension.
Get data from a variable.
  • Method Variable.GetData() returns the entire array of the variable.
  • Methods Variable.GetData(Int32[], Int32[]) and Variable.GetData(Int32[], Int32[], Int32[]) return a subset of the data.
  • Generic class Variable<DataType> also has an indexer that returns a single value for specified indices:
Variable<int> v = (Variable<int>)dataSet["var"];
int i = v[new int[] { 0 }]; // gets the value at the index { 0 }
Work with metadata.
  • Use a MetadataDictionary class instance available through the Variable.Metadata or DataSet.Metadata properties.
Variable v = dataSet["var"];
v.Metadata["Units"] = "m/s";
. . .
string units = (string)v.Metadata["Units"];
Create, modify, and get data from a scalar variable
Zero-rank variables (also called scalar variables) have Variable.Rank equal to zero and contain a single value.
  • To create a scalar variable, use common methods such as AddVariable<DataType>().
  • To put data or get data from such variable, use methods such asGetData() and PutData(Array).
The value is represented as a one-dimensional array with a single element.
Note that the Append(Array) method does not support scalars and throws an exception if is invoked for a scalar variable. Another way to put data or get data from scalar variable is to use a typed indexer from the Variable<DataType> class, as in the example below. In all these methods, an origin parameter (if it is required) must be either null, an array of Int32, or a special constant Variable.DefaultIndices.
Variable<double> scalarDbl = ds.AddVariable<double>("scalarDbl");
Assert.IsTrue(scalarDbl.Rank == 0);

// Using PutData and GetData methods:
scalarDbl.PutData(new double[] { Math.PI });
Assert.AreEqual(1, scalarDbl.GetData().Length); // contains only one element
Assert.AreEqual(Math.PI, ((double[])scalarDbl.GetData())[0]); // true

// Using indexer:
scalarDbl[Variable.DefaultIndices] = 2*Math.PI;
Assert.AreEqual(2*Math.PI, scalarDbl[Variable.DefaultIndices]); // true


An alternative way to work with DataSet is described in the topic Imperative API.

Last edited Apr 20, 2010 at 9:25 PM by pennyo, version 8

Comments

No comments yet.