#!F-adobe-helvetica-medium-r-normal--18*
#!N 
#!CNavyBlue #!N  #!Rall1144 Example 3: xapp.c #!N #!EC #!N 
#!N The third example which we will discuss is xapp.c. This 
sample program does not use the Data Explorer user interface at 
all; rather it creates its own (simple) user interface. The program 
communicates with Data Explorer entirely through the scripting language. #!N #!N 
The interface presents the user with four buttons. Depending on which 
button is pressed, a different data file is imported. The maximum 
value in the data set is then computed and sent back 
to the DXLink application using a DXLOutput tool. The result is 
then displayed in a text widget created by the DXLink program. 
#!N #!N #!CForestGreen #!N  #!F-adobe-courier-bold-r-normal--18*   #!N #include <Xm/Xm.h> #!N #include <Xm/Form.h> 
#!N #include <Xm/Label.h> #!N #include <Xm/PushB.h> #!N #include <Xm/ToggleB.h> #!N #include 
<Xm/Text.h> #!N #include "dx/dxl.h" #!N #!N #!N void radio_cloudCB(Widget, XtPointer, XtPointer); 
#!N void radio_rainCB(Widget, XtPointer, XtPointer); #!N void radio_windCB(Widget, XtPointer, XtPointer); #!N 
void radio_tempCB(Widget, XtPointer, XtPointer); #!N void cloudhandler(DXLConnection *, const char *, 
const char *, void *); #!N void rainhandler(DXLConnection *, const char 
*, const char *, void *); #!N void windhandler(DXLConnection *, const 
char *, const char *, void *); #!N void temphandler(DXLConnection *, 
const char *, const char *, void *); #!N #!N static 
String DefaultResources[] = #!N { #!N "*background: #b4b4b4b4b4b4", #!N "*foreground: black", 
#!N #ifdef sgi #!N "*fontList: -adobe-helvetica*bold-r*14*=bold\n\ #!N -adobe-helvetica*medium-r*14*=normal\n\ #!N -adobe-helvetica*medium-o*14*=oblique", #!N 
#else #!N "*fontList: -adobe-helvetica*bold-r*14*=bold\ #!N -adobe-helvetica*medium-r*14*=normal\ #!N -adobe-helvetica*medium-o*14*=oblique", #!N #endif #!N 
"*XmToggleButton.selectColor: CadetBlue", #!N "*XmText.shadowThickness: 1", #!N NULL #!N }; #!N #!N 
#!N main(argc, argv) #!N int argc; #!N char *argv[]; #!N { 
#!N Widget toplevel, main_w, label, textfield, radio_box; #!N Widget radio_cloud, radio_rain, 
radio_temp, radio_wind; #!N XtAppContext app; #!N XmString xms; #!N DXLConnection *conn; 
#!N int n; #!N Arg wargs[50]; #!N #!N #!N /* #!N 
* Start the Data Explorer executive. #!N */ #!N conn = 
DXLStartDX("dx -exonly",NULL); #!N if (!conn) #!N { #!N printf("could not start 
dx"); #!N exit(0); #!N } #!N #!N #!N XtSetLanguageProc (NULL, NULL, 
NULL); #!N #!N toplevel = XtVaAppInitialize (&app, "Demos", #!N NULL, 0, 
&argc, argv, #!N DefaultResources, NULL); #!N #!N DXLInitializeXMainLoop(app, conn); #!N #!N 
#!N /* #!N * Create the user interface for this application 
#!N */ #!N main_w = XtVaCreateManagedWidget("form", #!N xmFormWidgetClass, toplevel, #!N XmNwidth, 
400, #!N XmNheight, 180, #!N XmNfractionBase, 5, #!N NULL); #!N #!N 
n = 0; #!N XtSetArg(wargs[n], XmNtopAttachment, XmATTACH_FORM); n++; #!N XtSetArg(wargs[n], XmNleftAttachment, 
XmATTACH_FORM); n++; #!N XtSetArg(wargs[n], XmNleftOffset, 30); n++; #!N radio_box = (Widget)XmCreateRadioBox(main_w, 
"choice", wargs, n); #!N XtManageChild(radio_box); #!N #!N xms = XmStringCreateSimple("cloudwater"); #!N 
radio_cloud = XtVaCreateManagedWidget("radio_cloud", #!N xmToggleButtonWidgetClass, radio_box, #!N XmNlabelString, xms, #!N NULL); 
#!N XmStringFree(xms); #!N XtAddCallback(radio_cloud, XmNvalueChangedCallback, #!N (XtCallbackProc)radio_cloudCB, #!N (XtPointer)conn); #!N #!N 
xms = XmStringCreateSimple("rainwater"); #!N radio_rain = XtVaCreateManagedWidget("radio_rain", #!N xmToggleButtonWidgetClass, radio_box, #!N 
XmNlabelString, xms, #!N NULL); #!N XmStringFree(xms); #!N XtAddCallback(radio_rain, XmNvalueChangedCallback, #!N (XtCallbackProc)radio_rainCB, 
#!N (XtPointer)conn); #!N #!N xms = XmStringCreateSimple("temperature"); #!N radio_temp = XtVaCreateManagedWidget("radio_temp", 
#!N xmToggleButtonWidgetClass, radio_box, #!N XmNlabelString, xms, #!N NULL); #!N XmStringFree(xms); #!N 
XtAddCallback(radio_temp, XmNvalueChangedCallback, #!N (XtCallbackProc)radio_tempCB, #!N (XtPointer)conn); #!N #!N xms = XmStringCreateSimple("wind"); 
#!N radio_wind = XtVaCreateManagedWidget("radio_wind", #!N xmToggleButtonWidgetClass, radio_box, #!N XmNlabelString, xms, #!N 
NULL); #!N XmStringFree(xms); #!N XtAddCallback(radio_wind, XmNvalueChangedCallback, #!N (XtCallbackProc)radio_windCB, #!N (XtPointer)conn); #!N 
#!N #!N #!N #!N xms = XmStringCreateSimple("returned value:"); #!N label = 
XtVaCreateManagedWidget("label", #!N xmLabelWidgetClass, #!N main_w, #!N XmNtopAttachment, XmATTACH_WIDGET, #!N XmNtopWidget, radio_box, 
#!N XmNbottomAttachment, XmATTACH_FORM, #!N XmNleftAttachment, XmATTACH_FORM, #!N XmNlabelString, xms, #!N NULL); 
#!N XmStringFree(xms); #!N #!N textfield = XtVaCreateManagedWidget("text", #!N xmTextWidgetClass, #!N main_w, 
#!N XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET, #!N XmNtopWidget, label, #!N XmNleftAttachment, XmATTACH_WIDGET, #!N XmNleftWidget, 
label, #!N XmNrightAttachment, XmATTACH_FORM, #!N XmNbottomAttachment, XmATTACH_FORM, #!N NULL); #!N #!N 
#!N /* #!N * Set the handlers for the various parameters 
#!N */ #!N DXLSetValueHandler(conn,"cloudmax", cloudhandler, textfield); #!N DXLSetValueHandler(conn,"rainmax", rainhandler, textfield); #!N 
DXLSetValueHandler(conn,"windmax", windhandler, textfield); #!N DXLSetValueHandler(conn,"tempmax", temphandler, textfield); #!N #!N #!N XtRealizeWidget 
(toplevel); #!N XtAppMainLoop (app); #!N } #!N #!N #!N /* #!N 
* The following are the handlers for data coming from DXLOutput. 
If #!N * data is received by the handler, it is 
presented in a text widget. #!N */ #!N void rainhandler(DXLConnection *conn, 
const char *name, const char *value, #!N void *data) #!N { 
#!N char string[100]; #!N Widget text_widget = (Widget)data; #!N #!N sprintf(string,"rainwater 
max value = %s", value); #!N XmTextSetString(text_widget, string); #!N } #!N 
void cloudhandler(DXLConnection *conn, const char *name, const char *value, #!N void 
*data) #!N { #!N char string[100]; #!N Widget text_widget = (Widget)data; 
#!N #!N sprintf(string,"cloudwater max value = %s", value); #!N XmTextSetString(text_widget, string); 
#!N } #!N void temphandler(DXLConnection *conn, const char *name, const char 
*value, #!N void *data) #!N { #!N char string[100]; #!N Widget 
text_widget = (Widget)data; #!N #!N sprintf(string,"temperature max value = %s", value); 
#!N XmTextSetString(text_widget, string); #!N } #!N void windhandler(DXLConnection *conn, const char 
*name, const char *value, #!N void *data) #!N { #!N char 
string[100]; #!N Widget text_widget = (Widget)data; #!N #!N sprintf(string,"wind max value 
= %s", value); #!N XmTextSetString(text_widget, string); #!N } #!N #!N #!N 
/* #!N * The following are the callbacks for the buttons 
in the #!N * user interface created above. In each case, 
some simple #!N * script language commands are sent to the 
Data Explorer #!N * executive. The maximum as computed by the 
Statistics #!N * module is then input to the DXLOutput tool. 
The handlers #!N * defined above wait for values to be 
received from #!N * DXLOutput, and then present the result in 
the text widget. #!N */ #!N void radio_cloudCB(Widget w, XtPointer xp1, 
XtPointer xp2) #!N { #!N DXLConnection *conn = (DXLConnection *)xp1; #!N 
DXLSend(conn, "g = Import(\"/opt/local/dx/samples/data/cloudwater\");"); #!N DXLSend(conn, "mean,sd,var,min,max = Statistics(g);"); #!N DXLSend(conn, 
"DXLOutput(\"cloudmax\", max);"); #!N } #!N void radio_rainCB(Widget w, XtPointer xp1, XtPointer 
xp2) #!N { #!N DXLConnection *conn = (DXLConnection *)xp1; #!N DXLSend(conn, 
"g = Import(\"/opt/local/dx/samples/data/rainwater\");"); #!N DXLSend(conn, "mean,sd,var,min,max = Statistics(g);"); #!N DXLSend(conn, "DXLOutput(\"rainmax\", 
max);"); #!N } #!N void radio_tempCB(Widget w, XtPointer xp1, XtPointer xp2) 
#!N { #!N DXLConnection *conn = (DXLConnection *)xp1; #!N DXLSend(conn, "g 
= Import(\"/opt/local/dx/samples/data/temperature\");"); #!N DXLSend(conn, "mean,sd,var,min,max = Statistics(g);"); #!N DXLSend(conn, "DXLOutput(\"tempmax\", max);"); 
#!N } #!N void radio_windCB(Widget w, XtPointer xp1, XtPointer xp2) #!N 
{ #!N DXLConnection *conn = (DXLConnection *)xp1; #!N DXLSend(conn, "g = 
Import(\"/opt/local/dx/samples/data/wind\");"); #!N DXLSend(conn, "mean,sd,var,min,max = Statistics(g);"); #!N DXLSend(conn, "DXLOutput(\"windmax\", max);"); #!N 
} #!EF #!N #!N #!EC #!N #!N #!N  #!F-adobe-times-medium-i-normal--18*   Next Topic 
#!EF #!N #!N  #!Linitex,dxall1146 h Initialization and Exit  #!EL  #!N  #!F-adobe-times-medium-i-normal--18*   #!N 
