NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: Units problem

Dear Eugene,

I am still having trouble figuring exactly what it is you
are doing, to reproduce your error.  For example, I don't
know how the 'RealTuple selectedTuple' argument to printTuple
relates to your FlatField.

Could you please put together a complete program that
illustrates the problem, and put it on a server for us.
If necessary, use our anonymous incoming ftp at:

  ftp://hyde.ssec.wisc.edu/pub/incoming

Then please send me an email telling me the names of the
files, and how to run them.  We should probably finish this
discussion off the list.

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


On Tue, 11 Jan 2000, Eugene Tan wrote:

> Dear Bill,
> 
> I tried updating the source but it hasn't done anything. We still have the
> same problem. This is how we're printing out what's in the field which has
> worked for us from beginning to now.
> 
> public static void printTuple(RealTuple selectedTuple)
>     throws VisADException, RemoteException {
> 
>     Unit[] unitArray = selectedTuple.getTupleUnits();
>     int dimension = selectedTuple.getDimension();
> 
>     for (int i=0; i < dimension; i++) {
>         Real data = (Real)selectedTuple.getComponent(i);
>       
>         double dataValue = data.getValue();
>         System.out.print("\tComponent: " + i + " ");
>         System.out.print("\tType: " + data.getType() + " ");
>         System.out.print("\tValue: " + data.getValue() + " ");
>         System.out.print("\tUnits: " + data.getUnit());
>         System.out.print("\n");
>     }
> }
> 
> After looking further, I've found another problem. I'm trying to convert
> 20 degrees celsius into kelvin and then changing it back to celsius. This
> is the output I'm getting:
> 
> >From Celsius to Kelvin (looks like it works):
> Component: 0    Type: MinTemp   Value: 293.1499938964844 Units: K
> Component: 1    Type: MaxTemp   Value: 293.1499938964844 Units: K
> 
> And then when I convert it back Celsius using the same code:
> Component: 0    Type: MinTemp   Value: -253.14999389648438 Units: Cel
> Component: 1    Type: MaxTemp   Value: -253.14999389648438 Units: Cel
> 
> It looks like the program has deducted 273.15K from 20 degrees celsius?
> 
> This is how our code does it:
> 
> //field is the flatfield containing the original data
> float[][] values = field.getFloats();
> values = Unit.convertTuple(values, oldUnits, newUnits);
> 
> //newField is the flatfield we're creating now - the code to do this is in
> //my previous mail
> newField.setSamples(values);
> 
> Please tell me what I'm doing wrong as I'm stuck again. Do you have any
> suggestion of a better way?
> 
> Thanks in advance.
> 
> Eug.
> 
>    _--_|\     Eugene Tan <E.Tan@xxxxxxxxxx>
>   /      \    AutoTAF Project Developer 
>   \_.--.*/    Bureau of Meteorology, Melbourne, VIC 3001, Australia
>         v     Telephone: +613 9669 4652
> 
> On Mon, 10 Jan 2000, From: Bill Hibbard <hibbard@xxxxxxxxxxxxxxxxx> wrote:
> 
> > I'm not sure how you're printing the FlatField, but I did
> > find a bug in FlatField.toString() that could cause your
> > problem.  I am at the AMS Conference in Long Beach this
> > week and cannot update our source server, but did put the
> > fix at:
> > 
> >   ftp://hyde.ssec.wisc.edu/pub/incoming/FlatField.java
> > 
> > On Mon, 10 Jan 2000, Eugene Tan wrote:
> > 
> > > We can't seem to convert some units properly. This is what we have:
> > > 
> > > (in a for loop to print out the original units)
> > > Units: 
> > > oldUnits: Cel
> > > oldUnits: Cel
> > > oldUnits: degrees_north
> > > 
> > > We then change all the Cel (celsius) units to Kelvin by doing this:
> > > 
> > > Unit[] newUnits = Unit.copyUnitsArray(oldUnits);
> > > Unit toUnit = SI.kelvin;
> > > 
> > > for (int i=0; i < oldUnits.length; i++) {
> > >     if (newUnits[i].toString().equals("Cel")) {
> > >         newUnits[i]=toUnit;
> > >     }
> > > }
> > > 
> > > Printing out the new units array:
> > > (in a for loop to print out the new units)
> > > Units: 
> > > newUnits: K
> > > newUnits: K
> > > newUnits: degrees_north
> > > 
> > > We then create a FlatField ie.
> > > 
> > > FlatField newField
> > >     new FlatField((FunctionType) field.getType(),
> > >             field.getDomainSet(),
> > >             null, 
> > >             null,
> > >                     field.getRangeSets(),
> > >             newUnits);
> > > 
> > > When I printed out the contents of newField, this is the output I get:
> > > Component: 0    Type: MinTemp   Value: NaN      Units: Cel
> > > Component: 1    Type: MaxTemp   Value: NaN      Units: Cel
> > > Component: 2    Type: WindDir   Value: NaN      Units: degrees_north
> > > 
> > > which is wrong. We want to convert the units for Component 0 & 1 to
> > > Kelvin but it keeps returning "Cel". Can anyone identify what we're doing
> > > wrong please?
> 
> 


  • 2000 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: