Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.

Re: Question about units package...

> > Digging around in the various examples and docs, I have not been able
> > to figure out how to do the equivalent using the Java units package.
> > Can somebody please provide me with a pointer a specific example or
> > tutorial that covers this?
> 
> Regretably, the VisAD units subsystem does not yet contain an equivalent
> of the "valtocal" function.  At the moment, the best advice I can give
> is to use the standard Java date and time-handling classes to do what
> you want (e.g. the "Data" and "Calendar" classes in the "java.util"
> package).

i haven't contributed too many answers to the VisAD mailing list. But i do
know how to use a (simple) timer in Java.  Here's a simple timer class:

public class QuestionTimer {

    private float beginSecond;
    private float endSecond;
    private Calendar timer;

    /**
     * constructor
     */
    public QuestionTimer() {

        setTimer(Calendar.getInstance());
    }
    /**
     * @return the Calendar timer object
     */
    private Calendar getTimer() {
        return Calendar.getInstance();  
    }
    /**
     * @param a timer object
     * @return TRUE if the set was successful
     */
    private boolean setTimer(Calendar calendar) {
        timer = calendar;
        return true;
    }

    /**
     * @return the second when the timer started
     */
    private float getBeginSecond() { return beginSecond; }

    /**
     * @param the second when the timer started
     */
    private void setBeginSecond(float minute,
                                float second,
                                float millisecond)  {

        beginSecond = (60 * minute) + (second) + (millisecond/1000);
    }

    /**
     * @return the second when the timer ended
     */
    private float getEndSecond() { return endSecond; }
    /**
     * @param the second when the timer ended
     */
    private void setEndSecond(float minute,
                              float second,
                              float millisecond) {

        endSecond = (60 * minute) + (second) + (millisecond/1000);
    }

    /**
     * Starts the timer running
     * <P>
     * @return TRUE if it's started
     */
    public boolean beginTimer() {

        setBeginSecond(getTimer().get(Calendar.MINUTE),
                       getTimer().get(Calendar.SECOND),
                       getTimer().get(Calendar.MILLISECOND));
        return true;
    }

    /**
     * Ends the timer
     * <P>
     * @return TRUE if it's ended
     */
    public boolean endTimer() {

        setEndSecond(getTimer().get(Calendar.MINUTE),
                     getTimer().get(Calendar.SECOND),
                     getTimer().get(Calendar.MILLISECOND));

        computeTotalTime();
        return true;
    }
    /**
     * @return TRUE if the total time was computed
     */
    private boolean computeTotalTime() {

        System.out.println("QuestionTimer.computeTotalTime(), TOTAL TIME is: "
                           + (getEndSecond() - getBeginSecond()) +
                           " seconds.");
        return true;
    }
}

-cheers, bob

-
Robert S Laramee        tel:    (603) 868-1361
9 Woodman Road, #314    office: (603) 862-0350
Durham, NH 03824        URL:   http://www.cs.unh.edu/~rlaramee


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