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

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?

Eug.

   _--_|\     Eugene Tan <E.Tan@xxxxxxxxxx>
  /      \    AutoTAF Project Developer 
  \_.--.*/    Bureau of Meteorology, Melbourne, VIC 3001, Australia
        v     Telephone: +613 9669 4652



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