Common: Plot Setup - find_midnite, min_max

Cogent Tools Demo and Tutorials: Version 4.0
Prev | Chapter 14. History Functions | Next

# 14.24. Common: Plot Setup - `find_midnite`, `min_max`

| These functions are located in the `lib/common.g` file.

The Cascade Historian bases all of its historical calculations on system time, the number of seconds since 7:00 p.m. EST, December 31, 1969. The resulting 10-digit numbers are awkward to display and work with, so the History program converts times into seconds past midnight. Thus, for example, 9:00 a.m. on April 18, 2002 is displayed as `32400` instead of `1019134800`.

The `find_midnite` function uses the output from the Gamma `date` function applied to the Gamma `clock` function, which returns system times in the format `Wed Apr 18 09:25:21 2002`. We use the Gamma `string_split` function to separate the date from the time. Then we split the time up into hours, minutes, and seconds and calculate the total number of seconds that have transpired so far today. Subtracting that from the total number of seconds on the system clock gives us the time of midnight, in seconds.

       /*--------------------------------------------------------------------
        * Function:    find_midnite
        * Returns:     t or nil
        * Description: Finds the time of midnight in system time.  This is the
        *              basis for the History time axis values and plots.  It
        *              makes the times shorter and easier to read, because all
        *              times are in seconds.
        *------------------------------------------------------------------*/
       function find_midnite()
       {
         local midnite;

         midnite = cadr(cddr(string_split(date(clock()), " ", 4)));
         midnite = string_split(midnite, ":", 2);
         midnite = (number(car(midnite)) * 3600)
           + (number(cadr(midnite)) * 60)
             + number(caddr(midnite));
         midnite = floor((clock() - midnite)/100) * 100;
         midnite;
       }

This function is used by the GTK or Photon version of the `send_query` function to calculate the minimum and maximum values of a list of data returned from a query.

       /*--------------------------------------------------------------------
        * Function:    min_max
        * Returns:     t or nil
        * Description: Finds the minimum and maximum values in a
        *              list of numbers and returns them as a list.
        *------------------------------------------------------------------*/
       function min_max (numlist)
       {
         local max = car(numlist), min = car(numlist);
         with m in numlist do
           {
             if(min > m)
               min = m;
             if(max < m)
               max = m;
           }
         list(min, max);
       }

Prev | Home | Next
Common: the `DeadbandSettings` class and `.set_parms` method | Up | Index

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.