### Start Grace with Named Pipe Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/Tutorial.html Starts the xmgrace application and directs its input and output through a named pipe. This allows for external control of Grace by sending commands and data to the specified pipe. ```bash mkfifo pvc xmgrac`e` `_-_npipe``p``_v_c`& ``` -------------------------------- ### xmgrace Command Interpreter - Pattern Selections Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Details how to select patterns using the PATTERN expression, specifying the required ID type and providing an example. ```text PATTERN _id_: pattern with ID _id_ nexpr _id_ PATTERN 1 ``` -------------------------------- ### xmgrace Command Interpreter - Graph Selections Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Explains how to select sets within a graph using expressions like _graph_.SETS[_id_] and _graph_.S_nn_, specifying the types and examples for each selection method. ```text _graph_.SETS[_id_]: set _id_ in graph _graph_ indx _id_, graphsel _graph_ GRAPH[0].SETS[1] _graph_.S_nn_: set _nn_ in graph _graph_ _nn_: 0-99, graphsel _graph_ G0.S1 ``` -------------------------------- ### Compile and Load Custom C Function for Grace Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html This example demonstrates how to define a custom function in C, compile it into a shared library, and then load it into Grace. The C code defines `my_function` which takes an integer and a double, returning their product. Compilation involves creating a Position Independent Code (PIC) object file and then a shared library. ```c double my_function (int n, double x) { double retval; retval = (double) n * x; return (retval); } ``` ```bash $gcc -c -fPIC my_func.c $gcc -shared my_func.o -o /tmp/my_func.so $strip /tmp/my_func.so ``` ```grace USE "my_function" TYPE f_of_nd FROM "/tmp/my_func.so" ALIAS "myf" ``` -------------------------------- ### Grace USE Statement for OS/2 DLL Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Examples of how to use a custom DLL function within Grace. It shows two methods: placing the DLL in the LIBPATH for a short form or specifying the full path to the DLL. ```grace USE "my_function" TYPE f_of_nd FROM "my_func" ALIAS "myf" ``` ```grace USE "my_function" TYPE f_of_nd FROM "e:/foo/my_func.dll" ALIAS "myf" ``` -------------------------------- ### xmgrace Command Interpreter - Color Selections Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Explains the selection of mapped colors using COLOR expressions, differentiating between named colors and colors specified by an ID, with examples for each. ```text COLOR _"colorname"_: a mapped color _colorname_ - COLOR "red" COLOR _id_: a mapped color with ID _id_ nexpr _id_ COLOR 2 ``` -------------------------------- ### Grace Typesetting Control Codes Example Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html An example demonstrating the use of Grace's typesetting control codes to format a string, including subscripts, superscripts, font changes, and special character insertion. ```grace F\sX\N(\xe\f{}) = sin(\xe\f{})\#{b7}e\S-X\N\#{b7}cos(\xe\f{}) ``` -------------------------------- ### Real-time Plotting with grace_np Source: https://context7.com/fxcoudert/xmgrace/llms.txt Demonstrates how to initialize a Grace subprocess, register a custom error handler, and stream data points for real-time visualization. The example includes periodic display updates using GraceFlush and a manual wait mechanism. ```c #include #include #include #include "grace_np.h" /* Custom error handler */ void my_error_function(const char *msg) { fprintf(stderr, "Grace Error: %s\n", msg); } int main(int argc, char *argv[]) { int i; double x, y; /* Register custom error handler */ GraceRegisterErrorFunction(my_error_function); /* Open Grace with 2048 byte buffer */ if (GraceOpen(2048) == -1) { fprintf(stderr, "Can't open Grace\n"); exit(EXIT_FAILURE); } /* Send initialization commands */ GracePrintf("world 0, -1, 100, 1"); GracePrintf("xaxis tick major 20"); GracePrintf("yaxis tick major 0.5"); GracePrintf("s0 line color 2"); GracePrintf("s0 symbol 1"); GracePrintf("s0 symbol size 0.3"); /* Plot data points in real-time */ for (i = 0; i <= 100; i++) { x = (double) i; y = sin(x * 3.14159 / 50.0); /* Add point to set */ GracePrintf("g0.s0 point %g, %g", x, y); /* Update display every 10 points */ if (i % 10 == 0) { GracePrintf("redraw"); GraceFlush(); usleep(100000); /* 100ms delay */ } } /* Final update */ GracePrintf("autoscale"); GracePrintf("redraw"); GraceFlush(); /* Wait for user to close Grace */ printf("Press Enter to close Grace...\n"); getchar(); /* Close the Grace subprocess */ GraceClose(); return 0; } ``` -------------------------------- ### Customize File Dialog Patterns in X Resources Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html This snippet illustrates how to alter the default filename patterns for file selection dialogs in XMGrace. It provides an example for changing the pattern in the 'Open project' dialog to display all files. ```X Resources XMgrace*openProjectFSB.pattern: * ``` -------------------------------- ### Control XMGrace via C API Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Demonstrates initializing a Grace session, sending plotting commands, and streaming data points to the application. Requires the grace_np library and proper linking during compilation. ```c #include #include #include #include #ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 #endif #ifndef EXIT_FAILURE # define EXIT_FAILURE -1 #endif void my_error_function(const char *msg) { fprintf(stderr, "library message: \"%s\"\n", msg); } int main(int argc, char* argv[]) { int i; GraceRegisterErrorFunction(my_error_function); if (GraceOpen(2048) == -1) { fprintf(stderr, "Can't run Grace. \n"); exit(EXIT_FAILURE); } GracePrintf("world xmax 100"); GracePrintf("world ymax 10000"); GracePrintf("s0 on"); for (i = 1; i <= 100 && GraceIsOpen(); i++) { GracePrintf("g0.s0 point %d, %d", i, i); GracePrintf("g0.s1 point %d, %d", i, i * i); if (i % 10 == 0) { GracePrintf("redraw"); sleep(1); } } if (GraceIsOpen()) { GracePrintf("saveall \"sample.agr\""); GraceClose(); exit(EXIT_SUCCESS); } else { exit(EXIT_FAILURE); } } ``` -------------------------------- ### Initialize and Control Grace Subprocess Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Demonstrates the lifecycle of a Grace subprocess, including opening a connection, sending commands, and closing the pipe. The C interface supports formatted strings, while Fortran requires manual command formatting. ```c #include "grace_np.h" int main() { if (GraceOpen(2048) == 0) { GracePrintf("g0.s0 point %f, %f\n", 3.5, 4.2); GracePrintf("redraw\n"); GraceClose(); } return 0; } ``` ```fortran integer status status = GraceOpenF(2048) if (status .eq. 0) then call GraceCommandF("g0.s0 point 3.5, 4.2") call GraceCommandF("redraw") call GraceCloseF() endif ``` -------------------------------- ### OS/2 DLL Creation with GCC Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Steps to compile C source code into an object file, create a linker definition file, and link them to create a DLL on OS/2 using GCC and EMX. This process involves specific compiler and linker flags for DLL creation and export. ```bash gcc -Zomf -Zmt -c my_func.c -o my_func.obj ``` ```bash gcc my_func.obj my_func.def -o my_func.dll -Zdll -Zno-rte -Zmt -Zomf ``` -------------------------------- ### xmgrace Command Interpreter - Region Selections Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Describes how to select regions within a graph using the R_n_ expression, specifying the range for 'n' and providing an example. ```text R_n_: region _n_ _n_: 0-4 R0 ``` -------------------------------- ### Define Non-linear Fitting Function Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/Tutorial.html Example syntax for defining a custom non-linear function within the XMGrace non-linear fitting widget using parameters a0 through a9. ```Grace y = a0*sqrt(x) + a1*exp(x) + a2 ``` -------------------------------- ### OS/2 DLL Linker Definition File Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html A sample linker definition file ('my_func.def') for creating an OS/2 DLL. It specifies library information, load settings for code and data, a description, and lists the exported functions. ```linker_script * * * LIBRARY my_func INITINSTANCE TERMINSTANCE CODE LOADONCALL DATA LOADONCALL MULTIPLE NONSHARED DESCRIPTION 'This is a test DLL: my_func.dll' EXPORTS my_function * * * ``` -------------------------------- ### xmgrace Command Interpreter - Set Selections Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Illustrates methods for selecting sets in the current graph, including SET[_id_], S_nn_, S_, and S$, detailing their respective expression types and usage. ```text SET[_id_]: set _id_ in the current graph indx _id_ SET[1] S_nn_: set _nn_ in the current graph _nn_: 0-99 S1 S_: the last implicitly (i.e. as a result of a data transformation) allocated set in the current graph - S_ S$: the active set in the current graph - S$ ``` -------------------------------- ### xmgrace Command Interpreter - Expression Types Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Defines various expression types used in the xmgrace command interpreter, including numeric, integer, non-negative integer, string, and vector expressions, along with their characteristics and examples. ```text expr: Any numeric expression 1.5 + sin(2) iexpr: Any expression that evaluates to an integer 25, 0.1 + 1.9, PI/asin(1) nexpr: Non-negative iexpr 2 - 1 indx: Non-negative iexpr sexpr: String expression "a string", "a " . "string", "square root of 4 = " . sqrt(4) vexpr: Vector expression "2*x" ``` -------------------------------- ### Automate Plotting with XMGrace Batch Commands Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/Tutorial.html This snippet demonstrates how to create a batch command file to modify plot aesthetics and labels, followed by the command-line execution syntax for XMGrace. ```Grace #Obligatory descriptive comment s0.y = s0.y * 1000 s0 line color 3 s1 line color 4 title "A Gnasty Graph" xaxis label "Time ( s )" yaxis label "Gnats ( 1000's )" autoscale ``` ```bash xmgrace foo.dat bar.dat -batch bfile ``` -------------------------------- ### Customize Menu Accelerators in X Resources Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html This snippet demonstrates how to assign keyboard accelerators to menu items in XMGrace by modifying the .Xresources file. It shows the resource names derived from menu labels and their corresponding accelerator key combinations. ```X Resources XMgrace*transformationsMenu.nonLinearCurveFittingButton.acceleratorText: Ctrl+F XMgrace*transformationsMenu.nonLinearCurveFittingButton.accelerator: Ctrlf ``` -------------------------------- ### Grace Batch Processing Script Source: https://context7.com/fxcoudert/xmgrace/llms.txt A configuration file for Grace's batch mode, used for automated data processing and export. It handles page setup, file I/O, baseline shifting, and smoothing. ```text # batch_example.bat - Grace batch script # Run with: gracebat -batch batch_example.bat -nosafe -hardcopy # Page setup for publication quality page size 595 842 hardcopy device "EPS" device "EPS" op "level2" # Read input data cd "/path/to/data" read "experiment.dat" # Data preprocessing - shift baseline s0.y = s0.y - AVG(s0.y[0:10]) # Apply smoothing RUNAVG(s0, 5) # Create fitted curve in s1 s1 length 100 s1.x = mesh(MIN(s0.x), MAX(s0.x), 100) ``` -------------------------------- ### Configure XMGrace Axis and Viewport Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Commands to define world coordinate ranges, viewport boundaries, axis scaling modes, and inversion settings. ```XMGrace WORLD XMIN -10 WORLD YMAX 1e4 VIEW XMIN .2 VIEW 0.15, 0.15, 1.15, 0.85 XAXES SCALE LOGARITHMIC YAXES INVERT OFF AUTOSCALE ONREAD NONE ``` -------------------------------- ### Manipulate Data Points in XYDYDY Sets in xmgrace Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/FAQ.html This example shows how to assign values to individual data points within an XYDYDY set when the 'POINT' command does not directly support multiple Y-values. It involves accessing and modifying specific elements of the Y-arrays. ```xmgrace batch S0 POINT expr, expr S0.Y1[S0.LENGTH - 1] = expr S0.Y2[S0.LENGTH - 1] = expr ... ``` -------------------------------- ### xmgrace Command Interpreter - Arithmetic Operators Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Lists the supported arithmetic operators in the xmgrace command interpreter, including addition, subtraction, multiplication, division, modulus, and exponentiation. ```text Operator | Description + | addition - | substraction * | multiplication / | division % | modulus ^ | raising to power ``` -------------------------------- ### Specify Xmgr Version for File Compatibility Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/FAQ.html When dealing with older Xmgr project files, inserting a version line at the beginning can ensure compatibility. The format `@VERSION versionid` specifies the Xmgr version the file was created with. For example, `@VERSION 40102` corresponds to version 4.1.2. ```text @VERSION 40102 ``` -------------------------------- ### Evaluate Expression: Combining Data Sets Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Illustrates creating a new data set by combining coordinates from multiple existing sets using a mathematical formula. This example uses the y-coordinate from the source set, a sine function of the x-coordinate, and the y-coordinate from a second set (s2.y). It assumes all sets have the same number of points. ```grace y = y - 0.653 * sin (x deg) + s2.y ``` -------------------------------- ### Perform Data Transformations in XMGrace Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html Demonstrates how to manipulate data sets directly using the XMGrace command interpreter. These operations allow for scaling, running statistics, and interpolation on data sets. ```XMGrace Command S1.X = S1.X * 0.000256 RUNAVG(S0, 100) RUNMED(S0, 100) INTERPOLATE(S0, S1.X, ASPLINE, OFF) HISTOGRAM(S0, MESH(0, 1, 11), OFF, ON) INTEGRATE(S0) ``` -------------------------------- ### Feature Extraction: Y Maximum in XMGrace Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/Tutorial.html Extracts a specific feature (e.g., Y maximum) from a family of curves to create a new data set. The x-values of the new data set can be derived from the set number, original x or y values, or the legend entry of the source curves. This example demonstrates extracting the Y maximum and using the set index for the x-values. ```xmgrace commands # Example command sequence for Y maximum extraction (conceptual) # Assuming GUI actions are translated to commands or script # Set source graph and feature # Set x-value source to 'index' # Apply transformation ``` -------------------------------- ### Arranging Graphs in a Matrix in XMGrace Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html The ARRANGE command organizes existing graphs into a matrix format with specified rows, columns, and spacing. It supports various parameters to control the layout, including offsets, horizontal and vertical gaps, and flags for altering fill order and snake-like filling. ```xmgrace ARRANGE(2, 2, 0.1, 0.15, 0.2) ``` ```xmgrace ARRANGE(2, 2, 0.1, 0.15, 0.2, ON, OFF, ON) ``` ```xmgrace ARRANGE(2, 2, 0.1, 0.15, 0.2, ON, OFF, ON, ON) ``` -------------------------------- ### Registering Fortran Function in xmgrace Source: https://github.com/fxcoudert/xmgrace/blob/master/doc/UsersGuide.html This command informs xmgrace about the newly created Fortran function. It uses the 'USE' command to load the shared library and define the function's type, source, and an alias for use within xmgrace. ```grace USE "myfunc_wrapper" TYPE f_of_nd FROM "/tmp/myfunc.so" ALIAS "myfunc" ```