file: data_text.c
/*
* data_text.c - This file contains functions relating to the data values
* text list.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without fee
* is granted provided that the above copyright notice appears in all copies.
* It is provided "as is" without express or implied warranty.
*/
#include "XmdvTool.h"
#include "brush.h"
#include "brush_oper.h"
#include "util.h"
#include "average.h"
extern Widget appShell;
extern int dims, data_size;
extern char names[MAXDIM][MAXLABEL];
/* the operations */
extern Operation operations[MAXOPER];
extern int num_oper;
/* the names to put in the list widget */
char **data_names=NULL;
/* the number of names in the list */
int num_data_names = 0;
/*
* DataTextUpdateList() - Update the list of data points displayed by
* "view" operations.
*
* PARAMETERS
* void
*
* RETURNS
* void
*/
void DataTextUpdateList(void)
{
int op; /* the operation number */
int i,j, count = 0;
Widget scroll_w; /* the scrollable list widget */
Widget label_w; /* the label widget */
char buf[1024], name[1024]; /* temp string buffers */
double data[MAXDIM]; /* a data point */
int n;
Arg wargs[10]; /* for XtSetArg() */
int widths[MAXDIM]={0}; /* the field widths */
/* get the scrollabel list widget */
if(!(scroll_w = WcFullNameToWidget(appShell, "*data_text_list")))
{
fprintf(stderr, "Error finding *data_text_list\n");
return;
}
/* first delete any existing names */
for(i=0; i<num_data_names; i++)
if(data_names[i])
free(data_names[i]);
if(data_names) free(data_names);
num_data_names = 0;
/* initialize field widths */
for(i = 0;i < dims;i++)
widths[i] = strlen(names[i]) + 1;
/* update the key */
if(!(label_w = WcFullNameToWidget(appShell, "*data_text_label")))
{
fprintf(stderr, "Error finding *data_text_label\n");
return;
}
/* find the field width for each column */
for(op=0; op<num_oper; op++)
{
/* check if the operation has OPER_VALUES set */
if(!(operations[op].oper & OPER_VALUES))
continue;
for(i=0; i<data_size; i++)
{
get_data(data, i);
if(OperationPoint(data, op)) {
count++;
for(j=0; j<dims; j++)
{
sprintf(buf, "%f ", data[j]);
widths[j] = MAX(widths[j], strlen(buf));
/* cut off string if name field too long */
if(widths[j] >= MAXOPER)
widths[j] = MAXOPER-1;
}
}
}
}
/* allocate pointers to strings, adding one for labels, average, and line */
data_names = (char **)malloc((count+3) * sizeof(char *));
if(data_names == NULL) {
printf("failed to allocate space for string pointers in data_text.\n");
exit(-1);
}
sprintf(name, "Oper: ");
for(n=strlen(name), i=0; i<dims; i++)
{
for(j=0; j<widths[i]; j++)
{
if(j < strlen(names[i]))
name[n++] = names[i][j];
else
name[n++] = ' ';
}
name[n++] = ' ';
name[n] = '\0';
}
/*
n = 0;
XtSetArg(wargs[n], XtNlabel, name); n++;
XtSetValues(label_w, wargs, n);
*/
data_names[num_data_names++] = str_dup(name);
/* add a dashed line */
n = strlen(name);
for(i = 0;i < n;i++)
name[i] = '-';
name[i] = '\0';
data_names[num_data_names++] = str_dup(name);
/* add the new names */
for(op=0; op<num_oper; op++)
{
/* check if the operation has OPER_VALUES set */
if(!(operations[op].oper & OPER_VALUES))
continue;
for(i=0; i<data_size; i++)
{
get_data(data, i);
if(OperationPoint(data, op))
{
sprintf(name, "%4d: ", op+1);
for(j=0; j<dims; j++)
{
sprintf(buf, "%f", data[j]);
strcat(name, buf);
for(n=0; n<=widths[j]-strlen(buf); n++)
strcat(name, " ");
}
data_names[num_data_names++] = str_dup(name);
}
}
/* check if we should add an average too */
if(operations[op].oper & OPER_AVERAGE)
{
if(ComputeAverage(op, data))
continue;
sprintf(name, "Average %d: ", op+1);
for(j=0; j<dims; j++)
{
sprintf(buf, "%f ", data[j]);
strcat(name, buf);
}
data_names[num_data_names++] = str_dup(name);
}
}
/* unselect the itmes in the scrollable list first */
XukcScrListUnselectItems(scroll_w);
/* change the list */
/*
if(num_data_names == 0)
{
/* this is a hack to get around the broken Athena list
/* widget which can't have 0 items in it
data_names[0] = str_dup(" ");
XukcScrListChange(scroll_w, data_names, 1);
}
else
*/
XukcScrListChange(scroll_w, data_names, num_data_names);
}
C++ to HTML Conversion by ctoohtml