Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Re: extracting data from a field

Hi Cameron,

> I am trying to traverse through the structure of a field and extract the data
> for verification purposes.
>
> Here is a snippet of code.
>
> DataImpl mofStructure = plain.open(args[0]); //open and load netcdf file
> FieldImpl mofField = (FieldImpl)mofStructure; //convert to fieldimpl
> Data mofData = mofField.getSample(0);  //get first sample
>
> The data object received from 'getSample()' is of type Real.
> It should be tuple however I cannot cast it to Tuple and therefore cannot
> access the data (through getData() from tuple).
> How do I access the data?

If mofData is Real, you can get its value by:

  double value = ((Real) mofData)).getValue();

In general, if the MathType of a Field is something like:

  ((x, y) -> z)

then the samples of the Field will be Real.  If the MathType
of the Field is something like:

  ((x, y) -> (z, w))

then the samples of the Field will be Tuple (actually RealTuple
which is a subclass of Tuple).

So it could be that the netCDF adapter is not reading your
file the way you think it should be.  I am not sure how it
will deal with Text values.

Perhaps Steve can tell us.

Cheers,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html

 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690