~ubuntu-branches/ubuntu/karmic/grace/karmic

« back to all changes in this revision

Viewing changes to doc/Tutorial.sgml

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-19 14:19:58 UTC
  • Revision ID: james.westby@ubuntu.com-20020319141958-5gxna6vo1ek3zjml
Tags: upstream-5.1.7
ImportĀ upstreamĀ versionĀ 5.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!doctype linuxdoc system>
 
2
 
 
3
<!-- LyX 1.1 created this file. For more info see http://www.lyx.org/ -->
 
4
<article>
 
5
<title>
 
6
Grace Tutorials
 
7
</title>
 
8
<author>
 
9
Edward Vigmond
 
10
<tt>evigmon@tulane.edu</tt>
 
11
</author>
 
12
<date>
 
13
for Grace-5.1.4
 
14
</date>
 
15
<toc>
 
16
<sect>
 
17
Introduction
 
18
<p>
 
19
These tutorials assumes that you are a new user to Grace but are somewhat
 
20
 familiar with a windowing system. They are designed to show you some of the
 
21
 basic operation of Grace as well as a few of its less intuitive features. Please
 
22
 feel free to go beyond the bounds of the actions described herein and explore
 
23
 the possibilities of using Grace. After all, you will be the one who benefits.<tt>
 
24
 </tt>
 
25
</p>
 
26
<sect1>
 
27
Purpose
 
28
<p>
 
29
The purpose of these tutorials are to give brief examples to show you the
 
30
 basics of how to do something. Essentials and some of the more esoteric features
 
31
 of Grace will be demonstrated to give the user an idea of the capabilities
 
32
 of this program. It is not possible to show everything that Grace is capable
 
33
 of doing. That knowledge only comes with use and experimentation. I recommend
 
34
 that you do the tutorial and then by playing around with things, you will begin
 
35
 to understand them. Finally, when you get stuck, read the user guide to help
 
36
 you.
 
37
</p>
 
38
<sect1>
 
39
Nomenclature
 
40
<p>
 
41
In referring to what item to select, the tutorial will use something of
 
42
 the form <sf>snaf:/foo/bar/bell </sf>which means that on the snaf popup, select from
 
43
 the foo menu the submenu bar and from the bar menu, the entry bell. The popup
 
44
 main is the large one with the graph that pops up when you run xmgrace. If
 
45
 there is a space in the menu item, it will be replaced by an underscore. So
 
46
 , if the menu item was actually "Bell jar" instead of bell in the last example,
 
47
 it would be <sf>snaf:/foo/bar/Bell_jar.</sf>
 
48
</p>
 
49
<p>
 
50
Things that are to be typed in will be presented in a typewriter font,
 
51
 eg, type <tt>y = 3*sin(x)</tt>. 
 
52
</p>
 
53
<p>
 
54
Some of examples require you to input a data file or graph. In such instances,
 
55
 there should be a file in the tutorial directory named data.N or N.agr where
 
56
 N is the tutorial number. For example, when doing tutorial 7.1.3, you should
 
57
 look for a file 7.1.3.agr. It is assumed that each major tutorial section starts
 
58
 with a clean graph.
 
59
</p>
 
60
<sect1>
 
61
Computer System
 
62
<p>
 
63
Some of the following examples require that system commands be run. The
 
64
 commands may be different on your machine or require a slightly different syntax.
 
65
 In this tutorial, an attempt will be made to use the most commonly available
 
66
 UNIX commands. This tutorial was prepared on a Linux machine with kernel 2.0.32.
 
67
</p>
 
68
<sect1>
 
69
Generalities
 
70
<p>
 
71
A couple of points should be made about the GUI before we begin to make
 
72
 life easier.
 
73
</p>
 
74
<p>
 
75
<enum>
 
76
 <item>
 
77
It is often possible to select more than one item from a list at a time
 
78
 (some lists may prevent it when it makes no sense.). Clicking on a list entry
 
79
 without any keyboard modifier pressed will deselect all other entries and select
 
80
 only that one. Depressing shift while clicking an entry selects all entries
 
81
 from a previously selected entry to the currently selected one. Finally, depressing
 
82
 control allows one to individually toggle the selection of an entry.
 
83
 <item>
 
84
There are often two buttons on a pop up: Apply and Accept. Changes are
 
85
 not registered until either of these buttons is pressed. The difference between
 
86
 them is that Accept also closes the window.
 
87
</enum>
 
88
</p><sect1>
 
89
Disclaimer
 
90
<p>
 
91
Even though I do my best to keep this up to date with the latest release,
 
92
 I cannot guarantee it. Think of this a perpetual work in progress. Therefore,
 
93
 if something is wrong, you can notify me and I'll fix it but keep in mind that
 
94
 I am doing it in my spare time for no money.
 
95
</p>
 
96
<sect>
 
97
Making a Simple Graph
 
98
<p>
 
99
The object of this tutorial is to do the most basic function of Grace:
 
100
 read in some data into a graph and then label the graph. Along the way, a few
 
101
 of the basic Grace commands and widgets will be introduced.
 
102
</p>
 
103
<sect1>
 
104
Reading the data from a file
 
105
<p>
 
106
Start by bringing up the set reading widget <em>Main:Data/Import/ASCII</em>. Select
 
107
 the file 2.1.dat (both double clicking and hitting return work). You should
 
108
 see a black curve drawn on a graph.
 
109
</p>
 
110
<p>
 
111
Now we would like to add some more sets to the graph, but this time the
 
112
 data file will be in a slightly different format. Looking at the file "2.1.dat"
 
113
 (with the program of your choice), you can see that its several columns of
 
114
 numbers. One way to interpret this file is the first column gives the x-values
 
115
 and the rest of the columns are y-values. From Grace, again open the "Read Sets"
 
116
 widget. This time, check the "NXY" button. Now select the file "2.1.dat". At this
 
117
 point you will have several differently coloured curves.
 
118
</p>
 
119
<p>
 
120
You should now have 2 copies of the first set since you've read the file
 
121
 twice. It would be nice to eliminate one copy. This is most easily accomplished
 
122
 by bringing up a popup which lists all the sets. Selecting <em>Main:Edit/Data_sets...</em>bring up the Data set props popup. It lists all the sets and for the selected
 
123
 set, its type and a few statistics. To eliminate a set, select it and then
 
124
 press the right mouse button. A menu should appear from which you can select
 
125
 kill. You'll note that there is a kill and kill data. The former totally eliminates
 
126
 everything associated with a set while the latter eliminates the data but keeps
 
127
 the settings for it so that if new data is read into the set, it will have
 
128
 the same properties like colouring and line width, etc. Kill set 0 for now.
 
129
</p>
 
130
<sect1>
 
131
Set appearance
 
132
<p>
 
133
We would now like style the sets. Practically all aspects of the curves
 
134
 are configurable including colour, line thickness, symbols, drop lines, fills,
 
135
 etc. These operations are available under the "Set appearance" widget which is
 
136
 invoked by selecting <em>Main:Plot/Set appearance...</em> or by double clicking near
 
137
 the target set within the graph frame.
 
138
</p>
 
139
<p>
 
140
When the widget comes up, there will be a list of the sets with their number
 
141
 (eg. G0.S1 refers to set 1 in graph 0). Later operations will require you to
 
142
 know the number. Like the data sets pop up, clicking on mouse button 3 in the
 
143
 set list will bring up the menu of set operations.
 
144
</p>
 
145
<sect2>
 
146
Colouring all sets differently
 
147
<p>
 
148
The simplest way to colour all sets differently is from Set_Appearance:Data/All
 
149
 colors. First select the sets which you wish to recolour and then select Set_Appearance:Data/All
 
150
 colors. Do this now to your graph.
 
151
</p>
 
152
<sect2>
 
153
Customizing each set
 
154
<p>
 
155
When a set in the list is highlighted, the widgets change to reflect the
 
156
 settings. Practically all aspects are configurable. Experiment by changing
 
157
 the line colours and widths, placing a symbol at each data point, not connecting
 
158
 data points and fill the space between the x-axis and the curve. Don't forget
 
159
 to try out what is available under the other tabs besides Main. To see the
 
160
 effect of a change, you have to hit the "Apply" button. <bf>N.B</bf>.: Things are drawn
 
161
 in numerical order so if there is overlap, the highest numbered item will be
 
162
 on top. This applies to graphs and sets within each graph.
 
163
</p>
 
164
<sect1>
 
165
Labelling the axes using the font tool
 
166
<p>
 
167
Aspects of the axes are controlled by the axes popup which is called from
 
168
 <em>Main:Plot/Axis properties</em> or by double clicking the graph frame. All aspects
 
169
 of the axes can be changed like the title, the font, colour, whether or not
 
170
 to draw grid lines, or user defined tick marks and labels. There are many settings
 
171
 and the best thing to do is to experiment to see what each setting does.
 
172
</p>
 
173
<p>
 
174
For now, let's start by labelling the axes. Suppose these curves represent
 
175
 the number of tasks a processor runs as the function of the number of users.
 
176
 To make it more interesting, assume we are doing this in Quebec. That means
 
177
 we want to plot "Nombre de tļæ½ches vs. nombre d'usagers". Note the importance
 
178
 of having the accent over the a in tļæ½ches or we would end up plotting the number
 
179
 of stains which is entirely another case. Bring up the Axes pop up, select
 
180
 the Y axis, and click in the space to enter the label string of the axis label.
 
181
 Start typing Nombre de t. At this point we need to enter a accented letter,
 
182
 so we bring up the font tool by pressing <tt>Control-E. </tt>You will now see what we
 
183
 have typed in the Cstring widget. Move the cursor to where you want to place
 
184
 the accented letter and click on the letter. It should now appear in the string.
 
185
 You can either finish the string here or hit accept and keep editing. Label
 
186
 the x axis as well. This font tool is available wherever text needs to be entered.
 
187
</p>
 
188
<p>
 
189
All the attributes regarding the axis labels like size, colour, font, position
 
190
 are changeable. 
 
191
</p>
 
192
<sect1>
 
193
Graph titles
 
194
<p>
 
195
Our next exercise will be to title the graph so other. Operation pertaining
 
196
 to this are found in the "Graph appearance" widget which we open by selecting
 
197
 <em>Main:Plot/Graph appearance</em> or by double clicking just above the graph frame.
 
198
</p>
 
199
<p>
 
200
We can now fill in the title of the graph and by clicking on the "Titles"
 
201
 tab, the font and size and colour can be chosen. The Viewport box under the
 
202
 "Main" tab defines the 4 corners of the graph frame. You can type them in or
 
203
 use the mouse to move them by first double clicking on them.
 
204
</p>
 
205
<p>
 
206
Other things which can be controlled in this widget are the frame drawn
 
207
 around the graph, whether or not the graph background is coloured and the legends.
 
208
 Legends will be dealt with a little later. 
 
209
</p>
 
210
<sect1>
 
211
Legends
 
212
<p>
 
213
Since we have several lines in our graph, it makes sense that we label
 
214
 them with a legend so that other people can figure out what they mean. The
 
215
 first thing to do is to give each set a label. This is done by entering a legend
 
216
 string for each set in the Set appearance popup. Now, from the Main form in
 
217
 the Graph appearance popup, click on "Display legend" to see the legend box.
 
218
 The location and appearance of the box is controlled by clicking on the "Leg.
 
219
 box" tab. The appearance and spacing of the legend entries is controlled by
 
220
 the "Legends" tab. For simplicity, label the sets alphabetically and then play
 
221
 with the appearance, etc. to get something you like. 
 
222
</p>
 
223
<p>
 
224
Specifying the placement of the graph by entering the coordinates can be
 
225
 painful, especially the fine tuning. To alleviate this problem, a graphical
 
226
 method is also available, although not readily apparent. After a legend appears,
 
227
 it may be dragged to a new location. To do this, press Ctrl-L with your mouse
 
228
 on the main canvas. You should see the arrow cursor turn into a hand. If this
 
229
 doesn't work, double click on the main canvas (to get its attention) and then
 
230
 press Ctrl-L. Click on the legend and drag it. To cancel the legend drag mode
 
231
 (as with all other modes), click on mouse button 3. 
 
232
</p>
 
233
<sect1>
 
234
A challenge
 
235
<p>
 
236
I got bored so I took the data files and produced my own, albeit ugly,
 
237
 graph. See if you can copy <htmlurl url="mygraph.png" name="mygraph.png"> 
 
238
</p>
 
239
<sect>
 
240
Block Data
 
241
<p>
 
242
A block of data is a table of number which are interpreted as columns of
 
243
 numbers. How sets are created from the columns depends on the information you
 
244
 want to extract from the file. 
 
245
</p>
 
246
<p>
 
247
We first need to read in a block of data. We do this from <em>Main:Data/Import/ASCII</em>.
 
248
 Select the file "3.dat" and Load as "Block data". If the read was successful, a
 
249
 window should pop up asking you to create a set from the block data. At the
 
250
 top it will list how many columns of data were read.
 
251
</p>
 
252
<p>
 
253
First we choose the type of set we would like. For now we'll stick with
 
254
 xy.
 
255
</p>
 
256
<p>
 
257
Next we choose which column of data contains the x-ordinate. If there is
 
258
 no column, we can select "index" which will use the index into the column as
 
259
 the x ordinate starting from one.
 
260
</p>
 
261
<p>
 
262
The values Y1 through Y4 are used for selecting error bars as may be needed
 
263
 by other set types.
 
264
</p>
 
265
<p>
 
266
The last thing to specify is the graph into which to load the set if we
 
267
 have more than 1 set.
 
268
</p>
 
269
<p>
 
270
Finally, hitting accept will create the set.
 
271
</p>
 
272
<p>
 
273
If you close this window, it can reopened by bringing up a set list (eg.
 
274
 <em>Main:Edit/Data_sets</em>) and then selecting Create_new/From_block_data from the
 
275
 menu brought up by right clicking on the set list. 
 
276
</p>
 
277
<p>
 
278
Try creating a new set of type XYdY. This is an XY curve with error bars.
 
279
 Try X, Y, and Y1(the error) from different columns.
 
280
</p>
 
281
<sect>
 
282
Creating sets within Grace
 
283
<p>
 
284
Besides reading in data files, Grace has an extensive scripting language
 
285
 with a large number of math functions built in, These function include the
 
286
 basic add, multiply, square root, etc, and also the cephes library of higher
 
287
 order math functions like Bessel functions and the gamma function. Hence, functions
 
288
 in Grace are basically unlimited. See the user guide for more details. In addition,
 
289
 users can dynamically add libraries to Grace with any desired function. As
 
290
 well, points may be added manually to a set by the use of editors. To begin,
 
291
 choose <em>Main:Edit/Data sets</em>. To create a set, press mouse button 3 (the rightmost
 
292
 one for right handed people) anywhere within the data set list (which may be
 
293
 empty) and select Create new. A menu with 4 different ways of creating new
 
294
 sets will be presented. We'll go through them one by one.
 
295
</p>
 
296
<sect1>
 
297
By formula
 
298
<p>
 
299
The load and evaluate window will pop up when this is selected.
 
300
</p>
 
301
<p>
 
302
<enum>
 
303
 <item>
 
304
The first step is to set up the parameter mesh which will determine the
 
305
 range and sampling of the variable &dollar;t. Most often, &dollar;t will simply
 
306
 be the abscissa.
 
307
 <item>
 
308
Next, choose the type of set you would like to produce.
 
309
 <item>
 
310
Using the syntax of the command language, an expression for x is entered
 
311
 which uses &dollar;t as the independent variable. This can be an extremely
 
312
 complicated function.
 
313
 <item>
 
314
Likewise, an expression for y is entered and for any other expressions
 
315
 that may be needed. Fields after y are labelled y1, y2, y3 and y4. For example,
 
316
 if the set type xydxdy is chosen, y1 will hold dx and y2 will hold dy and it
 
317
 will be necessary to enter expressions for them.
 
318
 <item>
 
319
Pressing apply or accept will perform the calculations and create the new
 
320
 set. You may have to autoscale to see the new set.
 
321
</enum>
 
322
</p><p>
 
323
Below are a few samples:
 
324
</p>
 
325
<p>
 
326
<enum>
 
327
 <item>
 
328
To plot one cycle of a sine wave: Load: Set X, Start load at: <tt>0</tt>, Stop load
 
329
 at: <tt>2*pi</tt>, Length: <tt>100</tt>, X=&dollar;t, Y=<tt>sin(&dollar;t)</tt>
 
330
 <item>
 
331
A unit circle by parameterization: Start at:<tt>0</tt>, Stop at: <tt>2*pi</tt>, Length: <tt>100</tt>,
 
332
 X=cos(&dollar;t), Y=sin(&dollar;t)
 
333
</enum>
 
334
</p><sect1>
 
335
In spreadsheet
 
336
<p>
 
337
If your system has the Xbae widget set, this choice brings up a spreadsheet
 
338
 like editor to allow one to enter the points of the set by hand. Initially,
 
339
 it just has the point ( 0, 0 ). Clicking on add will insert a copy of the currently
 
340
 selected row immediately below the selected row. Clicking delete will delete
 
341
 the row which contains the cursor. This method is best suited to examining
 
342
 or modifying existing sets or creating very small sets. The sets gets updated
 
343
 after one hits enter or leaves the cell.
 
344
</p>
 
345
<sect1>
 
346
In text editor
 
347
<p>
 
348
If your system doesn't have the Xbae widget set or you want the power of
 
349
 your favourite external editor, a text editor of your choice may be used to
 
350
 enter data. The editor is selected by the GRACE_EDITOR environment variable.
 
351
 If the set is new, it will contain only the point (0,0). During editing, no
 
352
 other operations are possible. After the editor is closed, the set will be
 
353
 updated.
 
354
</p>
 
355
<sect1>
 
356
From block data
 
357
<p>
 
358
This creates a new set from a block of data which has been read in. See
 
359
 section 3.
 
360
</p>
 
361
<sect>
 
362
Batch plotting 
 
363
<p>
 
364
Grace supports a large number of command line options which allow the user
 
365
 to control the appearance and placement of graphs. This can be very useful
 
366
 if you want to use it to quickly print something without going through the
 
367
 GUI, use it within a script to automatically generate graphs, or have a plot
 
368
 come up already configured which can be much quicker than going through the
 
369
 GUI menus. 
 
370
</p>
 
371
<sect1>
 
372
Simple nonGUI printing
 
373
<p>
 
374
Invoking Grace with the command "grbatch"from the command line will cause
 
375
 Grace to start, produce a plot, send it to the printer (unless a file is specified)
 
376
 and then exit. In its simplest form, to produce a plot of the file a.agr, type
 
377
</p>
 
378
<p>
 
379
gracebat a.agr
 
380
</p>
 
381
<p>
 
382
If gracebat is unavailable on your system, the hardcopy option to xmgrace
 
383
 will do the same thing. Assuming the hardcopy device is a postscript printer,
 
384
 one could also type
 
385
</p>
 
386
<p>
 
387
xmgrace -hdevice PostScript -hardcopy a.agr
 
388
</p>
 
389
<sect1>
 
390
Multiple graphs
 
391
<p>
 
392
Often, one wishes to plot several graphs with each graph having different
 
393
 characteristics. This is easily accomplished from the command line. Options
 
394
 specified on the command line are parsed in order and stay in effect until
 
395
 overridden by specifying them again.
 
396
</p>
 
397
<p>
 
398
<enum>
 
399
 <item>
 
400
The first step in plotting multiple graphs is usually telling Grace how
 
401
 many graphs we have and how to arrange them. The interpreter command "arrange"
 
402
 will do this. For example, if we want 4 graphs arranged in a simple 2x2 table,
 
403
 we specify 
 
404
-pexec "arrange ( 2, 2, .1, .1,.1,ON,ON,ON)"
 
405
The exact meaning of
 
406
 all the options is explained in the reference manual.
 
407
 <item>
 
408
Specify any global options. 
 
409
 <item>
 
410
Specify for each graph, the data to plot and any options. Options should
 
411
 be specified in the following order:
 
412
 <enum>
 
413
  <item>
 
414
"-graph g" where g is the graph number starting at 0. This says to apply
 
415
 all following options to this graph.
 
416
  <item>
 
417
Set any autoscaling options. Autoscaling is performed when the file is
 
418
 read; ergo, the autoscaling must be specified BEFORE the file is read. Remember,
 
419
 this setting is persistent.
 
420
  <item>
 
421
Set the set type. This is also a persistent setting.
 
422
  <item>
 
423
Specify the graph type and the input file.
 
424
  <item>
 
425
If reading in block data, create the sets with the "-bxy" option.
 
426
  <item>
 
427
Specify any world scaling. It is important to do this AFTER sets are read
 
428
 (unless autoscaling is off) as the graph gets rescaled when data is read in.
 
429
  <item>
 
430
Specify anything else
 
431
 </enum>
 
432
</enum>
 
433
</p><sect2>
 
434
An example
 
435
<p>
 
436
Let's try an example. We will assume 5 plots, the first 4 of which are
 
437
 to be stacked vertically, and the fifth inset into the fourth. We wish to plot
 
438
 the files a.dat, b.dat, c.dat and d.dat with the inset graph being a magnified
 
439
 portion of d.dat. Assume a.dat contains multiple columns of data, b.dat is
 
440
 a block of data from which we wish to make a curve from columns 2 and 4 with
 
441
 the error given by column 3, c.dat is to be represented as a bar graph, and
 
442
 for the inset graph, we wish to graph to region (0,0) to (1,1). This can be
 
443
 accomplished by
 
444
</p>
 
445
<p>
 
446
gracebat -pexec "arrange (4,1,.1,.1,.1,ON,ON,ON)" -nxy a.dat -graph 1 -block
 
447
 b.dat -settype xydy -bxy 2:4:3 -graph 2 -settype bar c.dat -graph 3 -settype
 
448
 xy d.dat -graph 4 d.dat -world 0 0 1 1 -viewport .15 .3 .8 .88
 
449
</p>
 
450
<p>
 
451
Note that the graph numbers start at 0 and that 0 is the default so it
 
452
 does not have to be specified for the first graph.
 
453
</p>
 
454
<sect1>
 
455
Things for which no command line option exists
 
456
<p>
 
457
Undoubtedly, you will reach a point where you want to do something for
 
458
 which no command line option exists. (We have been doing this with the arrange
 
459
 command.) This is where Grace's parameter file language is vital. The option
 
460
 "-pexec" will execute the next argument as if it had read it from a parameter
 
461
 file or excuted on the command line. If you want to do something more complicated
 
462
 than one command, you can use several pexec's or put the commands in a file
 
463
 and run the file with the "-batch" option.
 
464
</p>
 
465
<sect2>
 
466
Pexec example
 
467
<p>
 
468
To read in the files foo.dat and bar.dat and scale foo.dat in Y by 1000,
 
469
 the simplest way is
 
470
</p>
 
471
<p>
 
472
xmgrace foo.dat bar.dat -pexec "s0.y = s0.y * 1000"
 
473
</p>
 
474
<sect2>
 
475
Batch example
 
476
<p>
 
477
To do the same as the previous example but also label the axes and recolour
 
478
 the curves, make a file called "bfile" with the Grace commands
 
479
</p>
 
480
<p>
 
481
<code>
 
482
&num;Obligatory descriptive comment
 
483
s0.y = s0.y * 1000
 
484
s0 line color 3
 
485
s1 line color 4
 
486
title "A Gnasty Graph"
 
487
xaxis label "Time ( s )"
 
488
yaxis label "Gnats ( 1000's  )"
 
489
autoscale 
 
490
</code>
 
491
</p><p>
 
492
and then run xmgrace with
 
493
</p>
 
494
<p>
 
495
xmgrace foo.dat bar.dat -batch bfile
 
496
</p>
 
497
<sect>
 
498
Fitting curves 
 
499
<p>
 
500
This tutorial will explain some of Grace's curve fitting abilities. Grace
 
501
 can perform two types of fittings. The first type is regression or linear fitting
 
502
 where optimization is done on a linear equation or an equation which can be
 
503
 expressed in a linear form. This includes fitting polynomials and certain forms
 
504
 of equations. The other type of fitting is nonlinear and allows for arbitrary
 
505
 user supplied functions.
 
506
</p>
 
507
<p>
 
508
Let's take a curve and see how each type of fitting works. To begin, create
 
509
 a curve of the function <tt>y = sqrt(x) + exp(x)/3 -1</tt> over the range 0 to 3 with
 
510
 100 points.
 
511
</p>
 
512
<sect1>
 
513
Linear Regression
 
514
<p>
 
515
Choosing <em>Main:Data/Transformations/Regression</em> will pop up the Regression
 
516
 window. 
 
517
</p>
 
518
<p>
 
519
<enum>
 
520
 <item>
 
521
Select the set you just created
 
522
 <item>
 
523
Select the type of fit. For now, pick Linear.
 
524
 <item>
 
525
We will load the fitted value for now.
 
526
 <item>
 
527
Press the accept button to see the results of the fit. A window will pop
 
528
 up which will give you the results of the fit including the final expression.
 
529
 You might have to scroll back a bit to see it.
 
530
 <item>
 
531
See how high of a polynomial is needed to get an acceptable fit and try
 
532
 fitting other types of functions. Note that for the non-polynomial fits, <bf></bf><bf><em>A</em></bf><em></em>
 
533
 and <bf></bf><bf><em>B</em></bf><em></em> are the fitting parameters of the equation.
 
534
 <item>
 
535
Now, we are not limited to computing our fitted curve at the points of
 
536
 the original function. Suppose these data are quarterly sales and we wish to
 
537
 predict our next quarter. Choose the type of fit which you found to work best.
 
538
 Instead of loading fitted values,<em> Load: Function.</em> Now the bottom of the widget
 
539
 will become active. We wish to extrapolate over the next quarter, so we would
 
540
 like to start at 0 and end at 4 and choose 100 points. Press accept to see
 
541
 the extrapolation.
 
542
</enum>
 
543
</p><sect1>
 
544
Non-linear
 
545
<p>
 
546
We pop up the widget by selecting <em>Main:Data/Transformations/Non-linear
 
547
 curve fitting</em>. You may want to kill all the sets except the original function
 
548
 and the extrapolated function at this point.
 
549
</p>
 
550
<p>
 
551
<enum>
 
552
 <item>
 
553
Begin by selecting the set to optimize, the original function.
 
554
 <item>
 
555
Next, we write a function of the form we wish to fit. The unknown parameters
 
556
 are labelled a0..a9. You must start with a0 and work your way up. In this case,
 
557
 since you know the form of the equation already, so try: <tt>y = a0*sqrt(x) + a1*exp(x)
 
558
 + a2</tt>.
 
559
 <item>
 
560
Next we must specify that we have three parameters to fit which are a0,
 
561
 a1 and a2 and the tolerance of the solution.
 
562
 <item>
 
563
You must specify initial values for the parameters and put any bounds on
 
564
 them if necessary. Depending on the function you are optimizing, different
 
565
 initial conditions may lead to drastically different optima.
 
566
 <item>
 
567
The solution process is iterative and you must click on a button to run
 
568
 a certain number of iterations. You should see the parameters change and a
 
569
 curve created with these parameters. In this example, the exact solution is
 
570
 reached within 5 steps. More parameters and more difficult functions may require
 
571
 more steps in which case you may choose to run 20 or 100 or more steps. The
 
572
 newly created optimized curve should converge with an increasing number of
 
573
 steps.
 
574
 <item>
 
575
As in linear curve fitting, you can choose to load the fit function at
 
576
 the points of the original curve, over an arbitrary range or load the error
 
577
 at each point. For comparison, load the fitted curve over the range (3,4) by
 
578
 selecting Nonlinear:Options/Load/Function and filling in the bottom of the
 
579
 widget. How does the true answer compare to your previous extrapolation?
 
580
 <item>
 
581
Fitting arbitrary curves can be a tricky business. Initial conditions are
 
582
 very important. If you don't get a good fit, you may have to experiment a lot
 
583
 with the initial parameters values.
 
584
 <item>
 
585
Finally, note that the fitted curve does not get added until the accept
 
586
 button is pressed. This allows you to "fool around" until you get a good fit
 
587
 without creating a lot of garbage sets.
 
588
</enum>
 
589
</p><sect>
 
590
Transformations 
 
591
<sect1>
 
592
Graphical 
 
593
<sect2>
 
594
Simple Geometrical
 
595
<p>
 
596
You can rotate sets around an arbitrary axis perpendicular to the canvas
 
597
(e.g. the Z-axis). Also it is possible to scale sets and translate them.
 
598
<sect2>
 
599
Mathematical operations between sets
 
600
<p>
 
601
It is possible to perform operations between sets. With many operations,
 
602
 however, it is required that the 2 sets have the identical abscissa, i.e.,
 
603
 the x values of both sets are the exact same. This is necessary since most
 
604
 operations are performed on a point by point basis. Eg. multiplying 2 sets
 
605
 is done by multiplying the Y values of the 2 sets together to produce a new
 
606
 Y value. About the only operations that don't do this are filtering and convolution.
 
607
 Fortunately, Grace has a function to help out when the abscissas differ. It
 
608
 is called interpolation which interpolates a set over the domain of another
 
609
 set to produce a new curve.
 
610
</p>
 
611
<p>
 
612
Let us now add the cosine of a set to the sine of another set to create
 
613
 a new curve. However, we will complicate this example by having different domains
 
614
 with different sampling:
 
615
</p>
 
616
<p>
 
617
<enum>
 
618
 <item>
 
619
Read in 7.1.2.agr
 
620
 <item>
 
621
Note how the abscissa are different. We begin by using interpolate to produce
 
622
 a third set which is the second set sampled at the x values of the first. Call
 
623
 up the Interpolate popup from <em>Main:Data/Transformations/Interpolation/splines ...</em>
 
624
 <item>
 
625
Select S1 as the source set but don't specify a destination set. A set
 
626
 will automatically be made. Use the Strict, linear method, Sampling:Abscissas
 
627
 of another set and use S0 as the Sampling set. Pressing Apply should produce
 
628
 a curve which is S1 interpolated at the points of S0. Note that the new curve
 
629
 only exists over the portion of the x axis common to both curves.
 
630
 <item>
 
631
We still have a problem since set 2 is sampled the same as set 0 but has
 
632
 a smaller domain. We can perform the computation only over the common region
 
633
 so we now interpolate on set 0 at points from set 2 to produce set 3. Now set
 
634
 2 and set 3 have the exact same abscissas.
 
635
 <item>
 
636
Call up the command interpreter from <em>Main:Window/Commands</em> ...
 
637
 <item>
 
638
We need to create a set to hold the result, S4. We can either make a copy
 
639
 (using <em>Main:Edit/Set_operations...</em>) of S2 which will be guaranteed to have
 
640
 the proper size to hold out result or we can use type a command: <tt>s4 length
 
641
 s2.length</tt>
 
642
 <item>
 
643
We have to break up the computation into an x part and a y part. In this
 
644
 instance, we simply wish to keep the same x values. The final result will be
 
645
 put into set 4, so we issue the command: <tt>s4.x = s2.x</tt>
 
646
 <item>
 
647
Now we can perform the math between our interpolated copies of sets 0 and
 
648
 1: <tt>s4.y = cos(s3.y) + sin(s2.y)</tt>. 
 
649
 <item>
 
650
So where is the new set? It's there but it's hidden. Since we already have
 
651
 the command window open, we can unhide the set by typing: <tt>S4 on</tt>. For the GUI
 
652
 minded (no offense intended), bring up a set list with the set operations menu
 
653
 (eg. <em>Main:Edit/Data_sets</em> or <em>Main:Plot/Set_appearance</em>),
 
654
 select set 4 and unhide it by selecting show from the operation menu (mouse button 3). 
 
655
</enum>
 
656
</p><p>
 
657
N.B. If the abscissas of the original curves had been the same, we could
 
658
 have started at step 5. If the sampling had been the same we could have skipped
 
659
 step 4.
 
660
</p>
 
661
<sect2>
 
662
Feature extraction 
 
663
<p>
 
664
Feature extraction is a way of creating one curve from a family of curves.
 
665
 It generates one data point from each curve by measuring a characteristic of
 
666
 the curve. For example, one might have a series of curves which plot the gnat
 
667
 population as a function of time. Each curve is produced by varying some condition,
 
668
 like the number of gnus in the environment. Using feature extraction, one could
 
669
 use this family of curves to produce a new curve of the peak number of gnats
 
670
 as a function of gnus or the time of the peak number of gnats as a function
 
671
 of the number of gnus. This is most often useful with more than one graph.
 
672
</p>
 
673
<p>
 
674
<enum>
 
675
 <item>
 
676
Read in graph 7.1.3.agr
 
677
 <item>
 
678
Bring up the feature extraction form by clicking on
 
679
<em>Main:Data/Transformations/Feature_extraction</em>.
 
680
 
 
681
 <item>
 
682
Select Results to graph 1.
 
683
 <item>
 
684
Select the feature you are interested in. Choose Y maximum.
 
685
 <item>
 
686
Select what will determine the x value of the data point. The value of
 
687
 the characteristic determines the Y value. The X value can be determined by
 
688
 the set number. The x or y values of a specified set can also be used to produce
 
689
 the abscissa. Finally, the legend entry of the curve itself can be used to
 
690
 produce the x value. In this case, the legend entry must be specified as a
 
691
 single number. Choose index for now.
 
692
 <item>
 
693
Press accept, click on graph 1 and then click on the autoscale button to
 
694
 see your results.
 
695
 <item>
 
696
Choose another feature, like frequency, this time and get X values from
 
697
 the legend. Make sure that graph 0 has the focus when you hit accept. 
 
698
</enum>
 
699
</p><sect1>
 
700
Restrictions
 
701
<p>
 
702
Often we only wish to examine part of a data set or perform transformations
 
703
 only on a portion of one. Restrictions allow us to define a region of the graph
 
704
 on which to perform operations. 
 
705
</p>
 
706
<sect2>
 
707
Defining a region
 
708
<p>
 
709
There are several ways a region may be defined. It may be defined by a
 
710
 straight line (left of, right of, above, below), by a polygon (inside or outside),
 
711
 or by a range ( in x, out of x, in y, out of y). Call the define region popup
 
712
 from <em>Main:Edit/Regions/Define</em>. Choose which one of the regions you would like
 
713
 to define, and press the define button. 
 
714
</p>
 
715
<p>
 
716
<descrip>
 
717
 <tag>
 
718
Line type</tag>Define the ends of the line by clicking with mouse button
 
719
 1.
 
720
 <tag>
 
721
Polygon type</tag>From the define region popup, choose a polygon type and
 
722
 then the define button. Use mouse button 1 to pick the vertices of the polygon
 
723
 and then mouse button 3 when you are done.
 
724
 <tag>
 
725
Range type</tag>From the define region popup, choose a range type and then
 
726
 pick 2 points which define the range.
 
727
</descrip>
 
728
</p><sect2>
 
729
Using regions
 
730
<p>
 
731
Regions may be only be used to restrict an expression evaluation. Bring
 
732
 up the evaluateExpressions popup (<em>Main:Data/Transformations/Evaluate_expression</em>).
 
733
 Choose the source and destination sets and specify the formula to apply to
 
734
 the region of interest. Not specifying an expression is equivalent to the identity
 
735
 transformation. Choose the region you wish to use. By checking negate, the
 
736
 complement of the specified region is used. 
 
737
</p>
 
738
<p>
 
739
Click on Apply to perform the operation. The resultant set will be the
 
740
 expression evaluated only on points contained in the specified region. Thus,
 
741
 if no expression was specified, the effect is to produce a new set of only
 
742
 those points contained in the region. Conversely, to delete points in a region,
 
743
 leave the expression empty, and negate the region selection.
 
744
</p>
 
745
<sect>
 
746
Using Pipes 
 
747
<p>
 
748
Pipes are a way of capturing the output of a running process without the
 
749
 intermediary step of pacing the output in a file. Instead, the executing program
 
750
 puts the data in one end of the pipe, and Grace reads it from the other end
 
751
 of the pipe.
 
752
</p>
 
753
<sect1>
 
754
Instead of data files
 
755
<p>
 
756
On certain popups, e.g. <em>Main:Data/Import/ASCII</em>, the option to read from
 
757
 a file or pipe can be specified. If a pipe is chosen, the command in the selection
 
758
 widget will be run and the stdout will be captured and treated as though it
 
759
 was data which was read from a file. 
 
760
</p>
 
761
<sect1>
 
762
Named pipes
 
763
<p>
 
764
A named pipe is a special case of the pipe previously described. In the
 
765
 previous case, after the program has finished execution and the output had
 
766
 been read, the pipe was destroyed. A named pipe is a static structure with
 
767
 the property that multiple processes can write to and/or read from it. The
 
768
 purpose of using a named pipe with Grace is to start up a Grace window and
 
769
 then control Grace by sending commands and data through a named pipe. This
 
770
 is very powerful and lets you do practically anything you can do directly from
 
771
 the GUI. To use this feature, try the following:
 
772
</p>
 
773
<p>
 
774
<enum>
 
775
 <item>
 
776
Start a named pipe (you will have to find the command specific to your
 
777
 operating system. For example, it could be <em>mkfifo</em> or <em>mknod</em>): <tt>mkfifo pvc</tt>. If
 
778
 you do a directory listing, you should see the file pvc.
 
779
 <item>
 
780
Start up Grace in the background using the named pipe option: <tt>xmgrace</tt><tt><em> -</em>npipe</tt><em>
 
781
 </em><em><tt></tt></em><tt>p</tt><tt><em>v</em>c</tt>&amp;. Grace is now monitoring the pipe for any data which might be sent
 
782
 to it. It will interpret things as though they were entered using the command
 
783
 interpreter. 
 
784
 <item>
 
785
For a simple test, we will create a simple graph over the pipe. From your
 
786
 command line, type: <tt>echo "read &bsol;"8.2.dat&bsol;"" &gt; pvc</tt><bf>. </bf>(The back slashes
 
787
 are needed to escape the quotation marks so that Grace really received the
 
788
 command :read "8.2.dat".) This just told Grace to read the file data. Now we
 
789
 would like to autoscale. We could simply click on the button but the point
 
790
 is to use a named pipe. This time we type <tt>echo</tt><em> </em><em><tt></tt></em><tt>autoscale &gt; pvc</tt><em> </em>followed
 
791
 by<em> </em><em><tt></tt></em><tt>echo redraw &gt; pvc</tt><em>.</em> Your graph should now have autoscaled and redrawn.
 
792
 Exit Grace with <tt>echo</tt><tt><em> </em>exit</tt><tt><em> &gt; </em>pvc</tt>. You should also clean up by removing pvc.
 
793
 <item>
 
794
The true power in named pipes lies in driving Grace using another program.
 
795
 The controlling program can open a named pipe for writing, which is treated
 
796
 as an ordinary file. It can be opened with the <em>fopen()</em> function or whatever
 
797
 other I/O function you prefer. Commands and data are then written to the file
 
798
 where they are interpreted by Grace.
 
799
</enum>
 
800
</p><sect>
 
801
Multiple Graphs
 
802
<sect1>
 
803
Selecting graphs
 
804
<p>
 
805
When multiple graphs are present, a graph is selected by clicking inside
 
806
 the graph frame. In cases where graph frames overlap, clicking will cycle among
 
807
 the overlapping graphs.
 
808
</p>
 
809
<p>
 
810
It might be annoying if one is trying to work in a region of overlapping
 
811
 graphs. If will not be possible to double click on something because the each
 
812
 click will be interpreted as a single click and you will only end up changing
 
813
 the graph focus. In such an instance, turning off the graph selection by clicking
 
814
 might be desirable. Choose <em>Main:Edit/Preferences</em> and then set
 
815
 <em>Misc:Graph_focus</em> to "As set". This means one must explicitly set
 
816
 the focus. Simply bring up a graph list (eg. <em>Main:Edit/Overlay_graphs</em>
 
817
 is but one), select the graph you  want to work on and then, using the menu under
 
818
 mouse button 3, choose "Focus to".
 
819
</p>
 
820
<sect2>
 
821
Arranging a tableau of graphs
 
822
<p>
 
823
Placing a large number of regularly spaced graphs is easily done with
 
824
<em>Main:Edit/Arrange_graphs</em>. This will automatically calculate the layout:
 
825
</p>
 
826
<p>
 
827
<enum>
 
828
 <item>
 
829
Choose 3 rows and 3 columns and Apply. You should now see 9 graphs. The
 
830
 Order button refers to the way the graphs are numbered. The beginning of the
 
831
 line on the diagram of the button shows which graph is numbered 0 and how the
 
832
 numbers increase, by row or column.
 
833
 <item>
 
834
You realize you need horizontal packing, i.e. no horizontal gap between
 
835
 graphs. Click on the Pack button beside the Hgap/width input and then Apply.
 
836
 <item>
 
837
Suddenly, you realize you only need 6 graphs and not 9. Choose 2 rows and
 
838
 press Apply. There is a slight problem as graphs 6, 7 an 8 are still visible.
 
839
 This is a feature since you don't want to accidentally kill a graph. You can
 
840
 kill the extra graphs by clicking on the "Kill extra graphs" check box. Now,
 
841
 any graphs other than the explicitly arranged ones will be automatically killed.
 
842
 <item>
 
843
The margins are controlled by the Page Offsets, and the intergraph spacing
 
844
 by the Hgap and Vgap inputs.
 
845
 <item>
 
846
Press close to remove the window.
 
847
</enum>
 
848
<p>
 
849
<quote>
 
850
Note that only graphs which are selected are taken into consideration.
 
851
 So, if you wish to reorganize your existing graphs, make sure they are selected
 
852
 or new ones may be created.
 
853
</quote>
 
854
</p><sect2>
 
855
Arranging individual graphs
 
856
<p>
 
857
Arranging individual graphs may either be done (1) exactly, by specifying
 
858
 the viewport coordinates from <em>Main:Plot/Graph_appearance</em> or
 
859
 using the previously explained Arrange graphs popup, or (2) roughly,
 
860
 by double clicking a graph focus marker and then moving it.
 
861
</p>
 
862
<sect1>
 
863
Overlaying Graphs
 
864
<p>
 
865
Overlaying one graph onto another is useful for creating a graph with two
 
866
 different x axes and/or y axes. For example, you may wish to have a graph which
 
867
 on the x axis has the month of the year. There could be 2 curves on it, one
 
868
 using the left y axis which is number of gnus sold and one using the right
 
869
 y-axis which is the number of gnats exported on a logarithmic scale. Likewise,
 
870
 if one is plotting spectral data, one could have one x axis in Hz and another
 
871
 one in wavelength. Let's proceed with an example:data
 
872
</p>
 
873
<p>
 
874
<enum>
 
875
 <item>
 
876
Begin by selecting <em>Main:Edit/Overlay graphs</em> to bring up the Overlay widget.
 
877
 
 
878
 <item>
 
879
Select the graph numbers with which we would like to deal. In this example,
 
880
 we will overlay graph 1 onto graph 0. At this point, only graph 0 is visible.
 
881
 We cannot see Graph 1 to select since it does not exist at this point. We need
 
882
 to create simply by pressing mouse button 3 in a graph list window and selecting
 
883
 create new. 
 
884
 <item>
 
885
The overlay type is determined by what is common among the overlayed graphs.
 
886
 In our example, the x axis is common so we will select <em>X-axes same, Y-axes
 
887
 different. </em>This is important because we don't want to alter any axes of the
 
888
 Overlay graph which we set the same as the underlay graph. In this example,
 
889
 we don't want to alter the x-axis of graph 1.
 
890
 <item>
 
891
We are now ready to label the graph axes and read the data. One thing we
 
892
 must be careful to do is to always make sure that we are working on the intended
 
893
 graph. Seeing as the graphs are overlain, clicking within the frame is ambiguous
 
894
 as to what graph is selected. The rule is that in a region of overlay, clicking
 
895
 will cycle between the graphs. Hence, if graph 1 is selecting, clicking within
 
896
 the frame will toggle to graph 0.
 
897
 <item>
 
898
Making sure that graph 0 is active, bring up the Axis properties widget.
 
899
 Now set the y axis title to Gnus.
 
900
 <item>
 
901
Select graph 1 as active as set the title as Gnats. Notice how it overlaps
 
902
 the Gnus. We want to put this on the right side. From the axis label and bar
 
903
 tab, select label Properties/Side=Opposite.
 
904
 <item>
 
905
Label the x axis to label it. If graph 1 is the current graph, noticed
 
906
 how it is greyed out because only 1 x axis need be active. Select graph 0 and
 
907
 you should now be able to alter the axis label.
 
908
 <item>
 
909
You are ready to read in data. Just make sure the graph that is active
 
910
 when you read in the data (or create your set) is the one in which you intend
 
911
 it to go.
 
912
</enum>
 
913
</p><sect>
 
914
Hot Links
 
915
<p>
 
916
Hot links are a way of of updating a set without having to delete it first
 
917
 and then reread it. The Hot Links window is opened available under <em>Main:Data/Hot
 
918
 links</em>.
 
919
</p>
 
920
<sect1>
 
921
File containing a Single Set
 
922
<p>
 
923
The simplest hot link is to a file containing just one set. To make a hot
 
924
 link to a single set, we must first select the set we want to get updated and
 
925
 then specify the file. We may also link to a pipe in which case we must specify
 
926
 it is a pipe to which we are linking. A command may also be entered which will
 
927
 be run every time the hot link is updated. A common command might be autoscale
 
928
 which will make sure that the entire set can be seen if it changes size. It's
 
929
 possible you may want to execute more commands than one. One could, for example,
 
930
 have a set that is a function of 2 sets that needs to be recomputed if either
 
931
 set is updated. If this is the case, put your commands in a file and then use
 
932
 the "READ BATCH" command.
 
933
</p>
 
934
<p>
 
935
Pressing the Link button will now create the link and if the update button
 
936
 is pressed, the set will be updated with the current contents of the file you
 
937
 linked and the contents of the Command widget will be executed.
 
938
</p>
 
939
<p>
 
940
For a simple example, read in the set 10.1.dat and set up the hot link.
 
941
 Now, run the command shiftdata.sh and update the hotlink. You should have seen
 
942
 the peak in the graph shift. Try repeating this a couple of more times.
 
943
</p>
 
944
<sect1>
 
945
Multiple sets within a file
 
946
<p>
 
947
Sometimes a data file may contain multiple columns of data and we would
 
948
 like to be able to link to all or some of those columns. To specify this, select
 
949
 as many sets as there are xy columns of data in the file. The "x y1 y2" format
 
950
 is assumed. Choose the file the data and <em>link</em>. Now in the link list, the links
 
951
 will show the file name with an appended colon and number. The number tells
 
952
 what column of data the link refers to. Any unwanted columns may be selected
 
953
 and unlinked at this point. When the update button is selected, all sets in
 
954
 the graph will be updated.
 
955
</p>
 
956
<sect1>
 
957
Updating by hot keys
 
958
<p>
 
959
Instead of having to keep the Hot links window open all the time, the update
 
960
 action is bound to alt-u. If you find that alt-u has no effect, try double
 
961
 clicking inside the graph you want to update and close the window that pops
 
962
 up. This will "alert" the canvas to process future hot key strokes.
 
963
</p>
 
964
 
 
965
 
 
966
</article>