A very flexible way to manipulate data is the use of variables. Details about the FORTRAN style interpreter and the usage of variables were discussed in chapter 6. Two simple examples are given here for illustration.
In the first example we assume having a data set containing measured
intensities as function of some angle
.
The following KUPLOT commands will create values for
according to the
relation
.
1 do i[1]=1,np[1]
2 dy[1,i[1]]=sqrt(y[1,i[1]])
3 enddo
The first line starts a DO loop over all data points of data set one,
assuming that is where our data are stored. The variable i[1] is the
loop control variable and np[1] contains the number of data points of
data set one. For a complete list of variables refer to section
6.1 of this users guide. Next the value of
for data
point i[1] is computed (line 2). The first parameter in 'dy[1,i[1]]'
specifies data set one. Finally (line 3) the loop is closed. The
corresponding plot with the error bars of the newly created values
of
is shown in Figure 7.2.
The second example shows how to create a new data set using variables.
We assume that we have two data sets loaded, both having the same length
and identical x-values. We want to create a new data set with
the same x-values and y-values that are the average of the y-values of
the two load data sets, thus
.
Here y''' stands for the new data set whereas y'' and y'represent the values of the two loaded data sets. The KUPLOT
commands for our task are listed below:
1 alloc aver.xy,np[1]
2 #
3 do i[1]=1,np[1]
4 x[3,i[1]]=x[1,i[1]]
5 y[3,i[1]]=0.5*(y[1,i[1]]+y[2,i[1]])
6 enddo
First we have to allocate space for the new data set. This is normally done by the command 'load' or 'func', but the command 'alloc' allows the user to create an empty data set, just what we need here. The name 'aver.xy' given as parameter to the 'alloc' command in line 1 is the internal name for the data set, e.g. showing up in the top left corner of the plot or when using the 'show' command. This is an arbitrary name and no file of that name needs to exist. The second parameter specifies the size of the new data set, in out case the same size as data sets one (variable np[1]) or two. Next we have a loop as in the previous example over all data points (line 3). In lines 4-5 the x- and y-values of the new data set number 3 are computed. Since we assumed that both original data sets have the same x-values, we just use one of them as x-values for the new set. Finally the loop is closed (line 6).
Although the usage of variables allows one to perform the same functions as the 'ccal' and 'kcal' commands, the usage of variables is much slower especially for large data sets.