"Fossies" - the Fresh Open Source Software Archive

Member "dx-4.4.4/html/pages/progu087.htm" (12 Jul 2003, 11425 Bytes) of package /linux/misc/old/dx-4.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3//EN">
    2 <HTML><HEAD>
    3 <TITLE>IBM Visualization Data Explorer Programmer&#39;s Reference</TITLE>
    4 
    5 <META HTTP-EQUIV="abstract" CONTENT="IBM Visualization Data Explorer
    6 Programmer&#39;s Reference">
    7 <META HTTP-EQUIV="contact" CONTENT="IBM Visualization Data Explorer
    8 (ibmdx@watson.ibm.com)">
    9 <META HTTP-EQUIV="owner" CONTENT="IBM Visualization Data Explorer
   10 (ibmdx@watson.ibm.com)">
   11 <META HTTP-EQUIV="updated" CONTENT="Tue, 16 Sep 1997 ">
   12 <META HTTP-EQUIV="review" CONTENT="Fri, 14 Aug 1998 ">
   13 
   14 <META HTTP-EQUIV="keywords" CONTENT="GRAPHICS VISUALIZATION VISUAL PROGRAM DATA
   15 MINING">
   16 <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
   17 </HEAD><BODY BGCOLOR="#FFFFFF">
   18 
   19 <A NAME="Top_Of_Page"></A>
   20 <H1>IBM Visualization Data Explorer Programmer&#39;s Reference</H1>
   21 <B>&#91; <A HREF="#Bot_Of_Page">Bottom of Page</A> &#124; <A
   22 HREF="progu086.htm">Previous Page</A> &#124; <A HREF="progu088.htm">Next
   23 Page</A> &#124; <A HREF="../proguide.htm#ToC">Table of Contents</A> &#124; <A
   24 HREF="progu084.htm#PToC19">Partial Table of Contents</A> &#124; <A
   25 HREF="progu344.htm#HDRINDEX_START">Index</A> &#93;</B><HR><P>
   26 
   27 <HR>
   28 <H2><A NAME="Header_174" HREF="progu084.htm#PToC_174">17.4 Example 3:
   29 xapp.c</A></H2>
   30 <P>
   31 The third example which we will discuss is xapp.c. This sample
   32 program does not use the Data Explorer user interface at all;
   33 rather it creates its own (simple) user interface. The program
   34 communicates with Data Explorer entirely through the scripting
   35 language.
   36 <P>
   37 The interface
   38 presents the user with four buttons. Depending on which button
   39 is pressed, a different data file is imported. The maximum value
   40 in the data set is then computed and sent back to the DXLink
   41 application using a DXLOutput tool. The result is then displayed
   42 in a text widget created by the DXLink program.
   43 <P>
   44 <PRE>
   45 #include &lt;Xm/Xm.h&gt;
   46 #include &lt;Xm/Form.h&gt;
   47 #include &lt;Xm/Label.h&gt;
   48 #include &lt;Xm/PushB.h&gt;
   49 #include &lt;Xm/ToggleB.h&gt;
   50 #include &lt;Xm/Text.h&gt;
   51 #include "dx/dxl.h"
   52 void radio_cloudCB(Widget, XtPointer, XtPointer);
   53 void radio_rainCB(Widget, XtPointer, XtPointer);
   54 void radio_windCB(Widget, XtPointer, XtPointer);
   55 void radio_tempCB(Widget, XtPointer, XtPointer);
   56 void cloudhandler(DXLConnection *, const char *, const char *, void *);
   57 void rainhandler(DXLConnection *, const char *, const char *, void *);
   58 void windhandler(DXLConnection *, const char *, const char *, void *);
   59 void temphandler(DXLConnection *, const char *, const char *, void *);
   60 static String DefaultResources&#91;&#93; =
   61 {
   62     "*background:              #b4b4b4b4b4b4",
   63     "*foreground:              black",
   64 #ifdef sgi
   65     "*fontList:                 -adobe-helvetica*bold-r*14*=bold\n\
   66                                 -adobe-helvetica*medium-r*14*=normal\n\
   67                                 -adobe-helvetica*medium-o*14*=oblique",
   68 #else
   69     "*fontList:                 -adobe-helvetica*bold-r*14*=bold\
   70                                 -adobe-helvetica*medium-r*14*=normal\
   71                                 -adobe-helvetica*medium-o*14*=oblique",
   72 #endif
   73    "*XmToggleButton.selectColor:            CadetBlue",
   74     "*XmText.shadowThickness:                1",
   75     NULL
   76 };
   77 main(argc, argv)
   78 int argc;
   79 char *argv&#91;&#93;;
   80 {
   81    Widget          toplevel, main_w, label, textfield, radio_box;
   82    Widget          radio_cloud, radio_rain, radio_temp, radio_wind;
   83    XtAppContext    app;
   84    XmString        xms;
   85    DXLConnection   *conn;
   86    int             n;
   87    Arg             wargs&#91;50&#93;;
   88    /*
   89     *  Start the Data Explorer executive.
   90     */
   91    conn = DXLStartDX("dx -exonly",NULL);
   92    if (!conn)
   93     {
   94       printf("could not start dx");
   95       exit(0);
   96     }
   97    XtSetLanguageProc (NULL, NULL, NULL);
   98    toplevel = XtVaAppInitialize (&app, "Demos",
   99                                  NULL, 0, &argc, argv,
  100                                  DefaultResources, NULL);
  101    DXLInitializeXMainLoop(app, conn);
  102    /*
  103     * Create the user interface for this application
  104     */
  105    main_w = XtVaCreateManagedWidget("form",
  106                  xmFormWidgetClass, toplevel,
  107                  XmNwidth,    400,
  108                  XmNheight,   180,
  109                  XmNfractionBase, 5,
  110                  NULL);
  111    n = 0;
  112    XtSetArg(wargs&#91;n&#93;, XmNtopAttachment, XmATTACH_FORM); n++;
  113    XtSetArg(wargs&#91;n&#93;, XmNleftAttachment, XmATTACH_FORM); n++;
  114    XtSetArg(wargs&#91;n&#93;, XmNleftOffset, 30); n++;
  115    radio_box = (Widget)XmCreateRadioBox(main_w, "choice", wargs, n);
  116    XtManageChild(radio_box);
  117    xms = XmStringCreateSimple("cloudwater");
  118    radio_cloud = XtVaCreateManagedWidget("radio_cloud",
  119                       xmToggleButtonWidgetClass, radio_box,
  120                       XmNlabelString, xms,
  121                       NULL);
  122    XmStringFree(xms);
  123    XtAddCallback(radio_cloud, XmNvalueChangedCallback,
  124                  (XtCallbackProc)radio_cloudCB,
  125                  (XtPointer)conn);
  126    xms = XmStringCreateSimple("rainwater");
  127    radio_rain = XtVaCreateManagedWidget("radio_rain",
  128                       xmToggleButtonWidgetClass, radio_box,
  129                       XmNlabelString, xms,
  130                       NULL);
  131    XmStringFree(xms);
  132    XtAddCallback(radio_rain, XmNvalueChangedCallback,
  133                  (XtCallbackProc)radio_rainCB,
  134                  (XtPointer)conn);
  135    xms = XmStringCreateSimple("temperature");
  136    radio_temp = XtVaCreateManagedWidget("radio_temp",
  137                       xmToggleButtonWidgetClass, radio_box,
  138                       XmNlabelString, xms,
  139                       NULL);
  140    XmStringFree(xms);
  141    XtAddCallback(radio_temp, XmNvalueChangedCallback,
  142                  (XtCallbackProc)radio_tempCB,
  143                  (XtPointer)conn);
  144    xms = XmStringCreateSimple("wind");
  145    radio_wind = XtVaCreateManagedWidget("radio_wind",
  146                       xmToggleButtonWidgetClass, radio_box,
  147                       XmNlabelString, xms,
  148                       NULL);
  149    XmStringFree(xms);
  150    XtAddCallback(radio_wind, XmNvalueChangedCallback,
  151                  (XtCallbackProc)radio_windCB,
  152                  (XtPointer)conn);
  153    xms = XmStringCreateSimple("returned value:");
  154    label = XtVaCreateManagedWidget("label",
  155                  xmLabelWidgetClass,
  156                  main_w,
  157                  XmNtopAttachment,   XmATTACH_WIDGET,
  158                  XmNtopWidget,       radio_box,
  159                  XmNbottomAttachment,   XmATTACH_FORM,
  160                  XmNleftAttachment,  XmATTACH_FORM,
  161                  XmNlabelString, xms,
  162                  NULL);
  163    XmStringFree(xms);
  164    textfield = XtVaCreateManagedWidget("text",
  165                  xmTextWidgetClass,
  166                  main_w,
  167                  XmNtopAttachment,   XmATTACH_OPPOSITE_WIDGET,
  168                  XmNtopWidget,       label,
  169                  XmNleftAttachment,  XmATTACH_WIDGET,
  170                  XmNleftWidget,      label,
  171                  XmNrightAttachment,  XmATTACH_FORM,
  172                  XmNbottomAttachment,  XmATTACH_FORM,
  173                  NULL);
  174    /*
  175     * Set the handlers for the various parameters
  176     */
  177    DXLSetValueHandler(conn,"cloudmax", cloudhandler, textfield);
  178    DXLSetValueHandler(conn,"rainmax", rainhandler, textfield);
  179    DXLSetValueHandler(conn,"windmax", windhandler, textfield);
  180    DXLSetValueHandler(conn,"tempmax", temphandler, textfield);
  181    XtRealizeWidget (toplevel);
  182    XtAppMainLoop (app);
  183 }
  184 /*
  185  * The following are the handlers for data coming from DXLOutput. If
  186  * data is received by the handler, it is presented in a text widget.
  187  */
  188 void rainhandler(DXLConnection *conn, const char *name, const char *value,
  189              void *data)
  190 {
  191    char string&#91;100&#93;;
  192    Widget text_widget = (Widget)data;
  193    sprintf(string,"rainwater max value = %s", value);
  194    XmTextSetString(text_widget, string);
  195 }
  196 void cloudhandler(DXLConnection *conn, const char *name, const char *value,
  197              void *data)
  198 {
  199    char string&#91;100&#93;;
  200    Widget text_widget = (Widget)data;
  201    sprintf(string,"cloudwater max value = %s", value);
  202    XmTextSetString(text_widget, string);
  203 }
  204 void temphandler(DXLConnection *conn, const char *name, const char *value,
  205              void *data)
  206 {
  207    char string&#91;100&#93;;
  208    Widget text_widget = (Widget)data;
  209    sprintf(string,"temperature max value = %s", value);
  210    XmTextSetString(text_widget, string);
  211 }
  212 void windhandler(DXLConnection *conn, const char *name, const char *value,
  213              void *data)
  214 {
  215    char string&#91;100&#93;;
  216    Widget text_widget = (Widget)data;
  217    sprintf(string,"wind max value = %s", value);
  218    XmTextSetString(text_widget, string);
  219 }
  220 /*
  221  * The following are the callbacks for the buttons in the
  222  * user interface created above. In each case, some simple
  223  * script language commands are sent to the Data Explorer
  224  * executive. The maximum as computed by the Statistics
  225  * module is then input to the DXLOutput tool. The handlers
  226  * defined above wait for values to be received from
  227  * DXLOutput, and then present the result in the text widget.
  228  */
  229 void radio_cloudCB(Widget w, XtPointer xp1, XtPointer xp2)
  230 {
  231    DXLConnection *conn = (DXLConnection *)xp1;
  232    DXLSend(conn, "g = Import(\"/usr/local/dx/samples/data/cloudwater\");");
  233    DXLSend(conn, "mean,sd,var,min,max = Statistics(g);");
  234    DXLSend(conn, "DXLOutput(\"cloudmax\", max);");
  235 }
  236 void radio_rainCB(Widget w, XtPointer xp1, XtPointer xp2)
  237 {
  238    DXLConnection *conn = (DXLConnection *)xp1;
  239    DXLSend(conn, "g = Import(\"/usr/local/dx/samples/data/rainwater\");");
  240    DXLSend(conn, "mean,sd,var,min,max = Statistics(g);");
  241    DXLSend(conn, "DXLOutput(\"rainmax\", max);");
  242 }
  243 void radio_tempCB(Widget w, XtPointer xp1, XtPointer xp2)
  244 {
  245    DXLConnection *conn = (DXLConnection *)xp1;
  246    DXLSend(conn, "g = Import(\"/usr/local/dx/samples/data/temperature\");");
  247    DXLSend(conn, "mean,sd,var,min,max = Statistics(g);");
  248    DXLSend(conn, "DXLOutput(\"tempmax\", max);");
  249 }
  250 void radio_windCB(Widget w, XtPointer xp1, XtPointer xp2)
  251 {
  252    DXLConnection *conn = (DXLConnection *)xp1;
  253    DXLSend(conn, "g = Import(\"/usr/local/dx/samples/data/wind\");");
  254    DXLSend(conn, "mean,sd,var,min,max = Statistics(g);");
  255    DXLSend(conn, "DXLOutput(\"windmax\", max);");
  256 }
  257 </PRE>
  258 
  259 <P><HR><B>&#91; <A HREF="#Top_Of_Page">Top of Page</A> &#124; <A
  260 HREF="progu086.htm">Previous Page</A> &#124; <A HREF="progu088.htm">Next
  261 Page</A> &#124; <A HREF="../proguide.htm#ToC">Table of Contents</A> &#124; <A
  262 HREF="progu084.htm#PToC19">Partial Table of Contents</A> &#124; <A
  263 HREF="progu344.htm#HDRINDEX_START">Index</A> &#93;</B> <br><b>&#91;<a
  264 href="../allguide.htm">Data Explorer Documentation</a>&nbsp;&#124;&nbsp;<a
  265 href="../qikguide.htm">QuickStart Guide</a>&nbsp;&#124;&nbsp;<a
  266 href="../usrguide.htm">User&#39;s Guide</a>&nbsp;&#124;&nbsp;<a
  267 href="../refguide.htm">User&#39;s Reference</a>&nbsp;&#124;&nbsp;<a
  268 href="../proguide.htm">Programmer&#39;s Reference</a>&nbsp;&#124;&nbsp;<a
  269 href="../insguide.htm">Installation and Configuration
  270 Guide</a>&nbsp;&#93;</b><br><p><b>&#91;<a
  271 href="http://www.research.ibm.com/dx">Data Explorer Home
  272 Page</a>&#93;</b><p><HR ALIGN=LEFT WIDTH=600><b>&#91;<A
  273 HREF="http://www.ibm.com/">IBM Home Page</A>&nbsp;&#124;&nbsp;<A
  274 HREF="http://www.ibm.com/Orders/">Order</A>&nbsp;&#124;&nbsp;<A
  275 HREF="http://www.ibm.com/Search/">Search</A>&nbsp;&#124;&nbsp;<A
  276 HREF="http://www.ibm.com/Assist/">Contact IBM</A>&nbsp;&#124;&nbsp;<A
  277 HREF="http://www.ibm.com/Legal/">Legal</A>&nbsp;&#93;</b><hr><p>
  278 <A NAME="Bot_Of_Page"></A>
  279 </BODY></HTML>