/********************************************************* xlinear, the X11 linear equation solver Brett van de Sande bvds@geneva.edu This is my first attempt at an X-windows application. I learned how to do this by looking at: http://www.kerguelen.org/x/index.html http://www.cs.uregina.ca/~cdshaw/X11/x11notes.html compiling command: gcc -o xlinear xlinear.c -lXaw3d -L/usr/X11R6/lib\ -llapack -lblas -lg2c This uses the Athena widget set for the interface and LAPACK and BLAS to solve the system of linear equations. I compiled it on LINUX using the standard GNU Fortran to C interface This program is free for non-commercial use. Please send me any corrections/improvements! **********************************************************/ #include #include #include #include #include #include #include #include #include #include #define DEBUG 0 /* debug print messages */ #define FLOAT_DIGITS "%g" /* print format for numbers */ XtAppContext app_context; void quit_app(Widget,XtPointer,XtPointer); void solve(Widget w, XtPointer client, XtPointer call); Widget *a_input,*b_input,*x_output,message; long int n; /**********************************************************/ /* The following is taken from xfig source file e_edit.c, see /usr/src/redhat/SOURCES/xfig.3.2.3d */ /* don't do anything when return is hit */ static String edit_text_translations ="Return: no-op()\n"; void text_transl(Widget w){ /* modify default text parsing rules for a given widget */ XtOverrideTranslations(w, XtParseTranslationTable(edit_text_translations)); } /**********************************************************/ int main(int argc, char **argv){ Widget temp; Widget toplevel; Widget quit, math,form,equation,a_matrix,x_vector,b_vector; int i,j,width=90; char xin[20]; char intromessage[]="Input matrix A and vector b\n" "choose \"Find solution\""; XFontStruct *font; int textheight; #if 0 /* attempt to draw brackets */ Widget line; Display *display; Window window; Pixmap p; GC gc; #endif /* Initialize Widgets and parse input parameters. */ toplevel = XtOpenApplication(&app_context, "linear", NULL, 0, &argc,argv, NULL, applicationShellWidgetClass, NULL,0); if(argc!=2||sscanf(argv[--argc],"%li",&n)!=1||n<1){ fprintf(stderr,"\nUsage: xlinear [X options] n\n"); fprintf(stderr," The positive integer n is the number of equations be solved.\n"); fprintf(stderr," See \"man X\" for a list of possible X options.\n"); exit(1); } a_input=malloc(n*n*sizeof(Widget)); b_input=malloc(n*sizeof(Widget)); x_output=malloc(n*sizeof(Widget)); form = XtVaCreateManagedWidget("form", boxWidgetClass, toplevel, XtNorientation,XtorientVertical, NULL); XtVaCreateManagedWidget("Solve a sytem of liner equations A x = b", labelWidgetClass,form, XtNborderWidth,0, NULL); equation = XtVaCreateManagedWidget("equation", boxWidgetClass, form, XtNorientation,XtorientHorizontal, XtNborderWidth,0, NULL); message=XtVaCreateManagedWidget("message",asciiTextWidgetClass,form, XtNeditType,XawtextRead, XtNstring,intromessage, XtNborderWidth,3, XtNdisplayCaret,False, NULL); /* Find appropriate window sizes based on the font size of the message window. */ XtVaGetValues(message,XtNfont,&font,NULL); textheight=font->ascent+font->descent; sprintf(xin,FLOAT_DIGITS,-8.0e-11/9.0); width=XTextWidth(font,xin,strlen(xin))+ XTextWidth(font,"8",1); /* extra padding */ #if DEBUG printf("Font sizes ht=%i hw=%i width=%i\n",ht,hw,width); #endif /* Use the part of intromessage to estimate width XTextWidth does not handle \n well. */ XtVaSetValues(message,XtNheight,2*textheight+6, XtNwidth,XTextWidth(font,intromessage,30), NULL); #if 0 /* attempt to draw brackets */ line = XtVaCreateManagedWidget("line",coreWidgetClass,equation, XtNwidth,20+100, XtNheight,n*24+100, NULL); #endif a_matrix= XtVaCreateManagedWidget("a", formWidgetClass, equation, XtNborderWidth,0, NULL); x_vector = XtVaCreateManagedWidget("x", boxWidgetClass, equation, XtNborderWidth,0, NULL); XtVaCreateManagedWidget("=",labelWidgetClass,equation, XtNborderWidth,0, XtNinternalHeight,(n*(textheight+10)-14)/2, NULL); b_vector = XtVaCreateManagedWidget ("b", boxWidgetClass, equation, XtNborderWidth,0, NULL); math = XtVaCreateManagedWidget("Find solution", commandWidgetClass, form, NULL, 0); quit = XtVaCreateManagedWidget("Quit", commandWidgetClass, form, NULL, 0); for(i=0; i /* This is for interfacing with LAPACK routine */ /* Subroutine */ int sgesv_(integer *n, integer *nrhs, real *a, integer *lda, integer *ipiv, real *b, integer *ldb, integer *info); void solve(Widget w, XtPointer client, XtPointer call){ integer nrhs=1,*ipiv,info; int i,j; float *a,*b; String aa; char bb[128]; a=malloc(n*n*sizeof(float)); b=malloc(n*sizeof(float)); ipiv=malloc(n*sizeof(integer)); for(i=0; i