Photon: Displaying Query Data - show_data

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

# 14.15. Photon: Displaying Query Data - `show_data`

The `show_data` function reads the `hsoutput.dat` file, which contains interpolated query output from the Cascade Historian, retrieved by the `InterpolatorSettings`.`get_data` method. This function modifies the data slightly as necessary, and puts it into the text widget.

       /*--------------------------------------------------------------------
        * Function:    show_data
        * Returns:     t or nil
        * Description: Shows interpolated query results from the Cascade Historian
        *              in the text widget and plots the results in the CwGraph widget.
        *------------------------------------------------------------------*/
       function show_data(txt_wgt, int_set, parent, button, datalist, minmaxlist)
       {
         local start_time, infile, line, string_list, line_ret;
         local x_is_time, x_min, x_max, y_min, y_max, x_list, y_list;
         local outstring = open_string ("");

         x_list = car(datalist);
         y_list = cadr(datalist);
         txt_wgt.text_string = "";
         start_time = find_midnite();

         if (int_set.fn == "NoInterpolator"  || int_set.fn == "Periodic")
           {
             x_is_time = t;
             txt_wgt.text_string = "Query results: \n     Time         Y History\n";
           }
         else
           {
             x_is_time = nil;
             txt_wgt.text_string = "Query results: \nX-hist / Y-hist\n";
           }

         infile = open("/tmp/cogentdemo/hsoutput.dat", "r");
         if (infile)
           {
             line = nil;
             while(line != _eof_)
               {
                 line = read_line(infile);
                 line_ret = "";
                 if (line != "Unexpected end of file")
                   {
                     if ((strstr(line,"#") != -1))
                       {
                         writec (outstring, line);
                         read_line(infile);
                         read_line(infile);
                       }

If the first character in the first line of output is "`#`", this means there was no data available. If this is the case, the `.get_data` method will have printed two dummy data lines into the `hsoutput.dat` file. These two lines must be read now, so that they will not get inserted into the text widget by the rest of this function. Hence we put in two extra Gamma `read_line` calls.

                     else
                       {
                         string_list = string_split(line, " ", 2);
                         if (x_is_time)
                           {
                             line_ret = string(number(car(string_list)) - start_time,
                                               " ", cadr(string_list),"\n");
                           }

Valid data in the `hsoutput.dat` file comes in two space-separated columns of numbers. If the numbers in the first column are time values (created using `NoInterpolator` or `Periodic` for the interpolator), this function recalculates each value to the number of seconds after midnight. This makes the data easier to read, and makes a better display in the plot.

                         else
                           {
                             line_ret = string(number(car(string_list)),
                                               "   ", cadr(string_list),"\n");
                           }
                         writec (outstring, line_ret);
                       }
                   }
               }

             txt_wgt.text_string = string(txt_wgt.text_string, string_file_buffer(outstring));

             if(x_list && y_list && minmaxlist != nil)
               {
                 if (x_is_time)
                   {
                     x_min = caar(minmaxlist);
                     x_max = cadar(minmaxlist);
                   }
                 else
                   {
                     x_min = floor(caar(minmaxlist));
                     x_max = ceil(cadar(minmaxlist));
                   }

                 y_min = floor(caadr(minmaxlist));
                 y_max = ceil(car(cdadr(minmaxlist))) + 1;

                 PtSetParentWidget(parent);

                 make_graph(x_min, x_max, y_min, y_max,
                                   x_list, y_list, int_set.dbflag);
               }
             close(infile);
           }
       }

After extracting the minimum and maximum values for the data from the `minmaxlist`, we call the `make_graph` function to plot the data.

Prev | Home | Next
Photon: Sending Queries - `send_query`, `.assign_values`, `.get_data` | Up | Photon: Setting Up Plots - `make_graph`, `make_CwGraph_points`

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