14.5. GTK: Setting Up Plots - reset_deadbands, plot_prep

   /*--------------------------------------------------------------------
    * Function:    reset_deadbands
    * Returns:     t or nil
    * Description: Clears all traces and sets the Full data set (no deadband)
    *              option.  Called when non-deadband buttons are activated.
    *------------------------------------------------------------------*/
   function reset_deadbands(button, iset, but1, but2, but3, text, e1, e2, 
                            e3, e4, e5, e6, e7, b1, b2, b3, b4, b5, b6)
   {
     but2.set_active(FALSE);
     but3.set_active(FALSE);
     but1.set_active(TRUE);
     if(is_file("/tmp/cogentdemo/hsoutput2.dat"))
         unlink("/tmp/cogentdemo/hsoutput2.dat");
     if(is_file("/tmp/cogentdemo/hsoutput3.dat"))
         unlink("/tmp/cogentdemo/hsoutput3.dat");
[Note]

All the data files in the demo are written to the /tmp/cogentdemo/ temporary directory, and deleted when the Controller exits.

We remove the hsoutput2.dat and hsoutput3.dat files so that gnuplot doesn't attempt to continue plotting them along with the new data set. Then we pass along the arguments to the plot_prep function (below).

     plot_prep(but1, iset, but1, but2, but3, text, e1, e2, 
               e3, e4, e5, e6, e7, b1, b2, b3, b4, b5, b6);
   }
   

The plot_prep function creates a setup file for gnuplot, called plhistsetup.dat Each time a query is sent, this file gets rewritten. Since the time values in the setup file are based on the time of midnight, this function uses the find_midnite function to calculate the time since midnight in seconds.

   /*--------------------------------------------------------------------
    * Function:    plot_prep
    * Returns:     t or nil
    * Description: Writes to the plhistsetup.dat file the relevant values
    *              for the time of midnight, x-axis label, and deadband
    *              status.
    *------------------------------------------------------------------*/
   function plot_prep (button, iset, but_db1, but_db2, but_db3, text,
                       e1, e2, e3, e4, e5, e6, e7, b1, b2, b3, b4, b5, b6)
   {
     local fp, histtime, line;
   
     /* Write the time. */
     fp = open("/tmp/cogentdemo/plhistsetup.dat", "w", nil);
     histtime = find_midnite();
     line = string("histtime = ", histtime, "\n");
     writec(fp, line);
   
     /* Set up the X-axis label. */
     if ((iset.fn == "NoInterpolator") || (iset.fn == "Periodic"))
       line = "xlab = 1\n";
     else line = "xlab = 2\n";
     writec(fp, line);
   
     /* Set the deadband flag in the InterpolatorSettings instance. */
     if(button.switched_on() && button == but_db1)
       iset.dbflag = "NONE";
     if(button.switched_on() && button == but_db2)
       iset.dbflag = "DB";
     if(button.switched_on() && button == but_db3)
       iset.dbflag = "DBP";
   
     /* Write the on or off value for each deadband. */
     if (but_db1.switched_on())
       line = "db1 = 1\n";
     else line = "db1 = 0\n";
     writec(fp, line);
   
     if (but_db2.switched_on())
       line = "db2 = 1\n";
     else line = "db2 = 0\n";
     writec(fp, line);
   
     if (but_db3.switched_on())
       line = "db3 = 1\n";
     else line = "db3 = 0\n";
     writec(fp, line);
   
     close(fp);
   
     send_query(button, iset, text, e1, e2, e3, e4,
                e5, e6, e7, b1, b2, b3, b4, b5, b6);
   }