14.21. Common: the InterpolatorSettings class and .set_defaults, .set_interpolator methods

Note

This class and two methods are located in the lib/common.g file.

   /*--------------------------------------------------------------------
    * Class:       InterpolatorSettings
    * Description: The instance variables of this class correspond to all
    *              the possible arguments to the Cascade Historian's
    *              "interpolate" command (plus a couple more for this
    *              program's use).  They are set by the radio buttons and
    *              entry values in the Interpolator options, and sent to
    *              the Cascade Historian when any query is made.
    *------------------------------------------------------------------*/
   class InterpolatorSettings
   {
     fn = "NoInterpolator";
     y_history = "MV_001";
     start = 20000;
     duration = RECORD_TIME + 1;
     x_history = "PV_001";
     interval = .3;
     max_gap = 100;
     dbflag = "NONE";
     misc_info = "";
   }
   
   /*--------------------------------------------------------------------
    * Method:      InterpolatorSettings.set_defaults
    * Returns:     t or nil
    * Description: Sets the default .start to correspond to the last time
    *              the "Record" button was toggled on and off, and resets
    *              the .dbflag.
    *------------------------------------------------------------------*/
   method InterpolatorSettings.set_defaults(button, entry)
   {
     if (button.switched_on())
       {
         .start = clock() - find_midnite();
         entry.set_text(string(.start));
         .dbflag = "NONE";
       }
   }
   

The .set_interpolator method has to take into account that each interpolator has a different group of parameters. We use the Gamma switch statement to allow for each possibility. The "TimeSetup" and "RelSetup" cases are used in the first call to this function by the GTK or Photon version of the send_query function. Those interpolation queries are used to find the minimum and maximum Y and X values for either a time-based or relative query. The values are then used in the creation of the Y and X axes of the plot. The other cases correspond to each of the four different types of interpolator.

   /*--------------------------------------------------------------------
    * Method:      InterpolatorSettings.set_interpolator
    * Returns:     a query buffer ID number
    * Description: Sends a query to the Cascade Historian (corresponding to
    *              the task parameter), based on the information in the
    *              InterpolatorSettings class.  
    *------------------------------------------------------------------*/
   method InterpolatorSettings.set_interpolator(task)
   {
     local tmp_history, tmp_history1, tmp_history2, intpl;
   
     switch (.fn)
       {
       case "TimeSetup":
         tmp_history = string(substr(.y_history, 0, 3), "001");
         intpl = send(task, `interpolate(@tmp_history, NoInterpolator,
                                         (@.start + midnite),
                                         @.duration));
       case "RelSetup":
         tmp_history1 = string(substr(.y_history, 0, 3), "001");
         tmp_history2 = string(substr(.x_history, 0, 3), "001");
         intpl = send(task, `interpolate(@tmp_history1, RelativeInterpolator,
                                         (@.start + midnite),
                                         @.duration, @tmp_history2));
       case "NoInterpolator":
         intpl = send(task, `interpolate(@.y_history, NoInterpolator,
                                         (@.start + find_midnite()),
                                         @.duration));
       case "Periodic":
           intpl = send(task, `interpolate(@.y_history, PeriodicInterpolator,
                                           (@.start + find_midnite()),
                                           @.duration, @.interval,
                                           @.max_gap));
       case "Relative":
         intpl = send(task, `interpolate(@.y_history, RelativeInterpolator,
                                         (@.start + find_midnite()),
                                         @.duration, @.x_history));
       case "FixedRelative":
         intpl = send(task, `interpolate(@.y_history,
                                         FixedRelativeInterpolator,
                                         (@.start + find_midnite()),
                                         @.duration, @.x_history,
                                         @.interval));
       }
     intpl;
   }
   

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