## Usage of codewords in xnd.

This file suppose that the basic implemantation of variables in xnd is already known. Examples of reation are given for:

### Variables block for an orthorhombic cell

The following lines are an example for a simple parameter block corresponding to an orthorhombic cell. There is only one relation between the variation of a and of b, c is free. The angles can not be refined. If we remember that the parameter block contains the sample displascement before the values of parameters and always a code specifying the kind of ther block.
```1
0.000   0
5.375  11    1.0     5.375  11    1.0
6.789   1            90.0    0
90.0    0            90.0    0
```

### Variables block for an cubic cell

That is the same for a cubic block, but a, b and c are varied together.
```1
0.000   0
1.234  11    1.0     1.234  11    1.0
1.234  11    1.0     90.0    0
90.0    0            90.0    0
```

### Variables block for a hexagonal cell with thermal expansion

If the hexagonal cell has to follow the temperature with a linear thermal expansion. A parameter can be written as :
a = a0 + da/dt DT
There is 2 terms, then the block should be written as :
``` 2
0.000    0       0.0    0
5.1234  12 1.0   0.002 13 1.0
5.1234  12 1.0   0.002 13 1.0
8.2345   1       0.004  1
90       0       0      0
90       0       0      0
120      0       0      0
```
If a linear expansion is not enough, we can write a more complicated expansion :
a = a0 + da/dt DT + d2a/dt2 DT^2
Then the block should be written as :
``` 3
0.000    0       0.0    0       0.0     0
5.1234  12 1.0   0.002 13 1.0   0.0001 14 1.0
5.1234  12 1.0   0.002 13 1.0   0.0001 14 1.0
8.2345   1       0.004  1       0.0002  1
90       0       0      0       0       0
90       0       0      0       0       0
120      0       0      0       0       0
```

### chemical substitution of atoms

The chemical substitution may lead to a more complicated problem. Let us consider a substitution with 3 chemicaly different atoms on a site. The only way to describe the relation is to write that the variation of each occupation depends on to parameters called in the following example p15 and p16.
T(At1) = T0(At1) + 0.5 * p15 + p16
T(At2) = T0(At2) + 0.5 * p15 - p16
T(At3) = T0(At3) - p15
Then we will write a first order block with 2 dimensions.
```
At1 FE 0
-1 2
0.25     0       0              X and Y are on special position
0.25     0       0
0.413   14  1.0  0 0            Z has to be the same for all atoms
0.700   15  0.5 16 1.0          t11 = p15 / 2 + p16
1.0      7  1.0  0              B common thermal factor
At2 CO 0
-1 2 ....
0.413   14  1.0  0 0            Z is the same for all atoms
0.100   15  0.5 16 -1.0         t12 = p15 / 2 - p16
...
At3 NI 0
-1 2 ...
0.200   15 -1.0  0 0            t13 = -p15
...
```
If the substitution depend on the temperature, this will be more complicated to write but always possible as it can be seen on one of the preceeding atom.
```
At1 FE 0
-2 2
0.25   0      0      0      0      0
0.25   0      0      0      0      0
0.413 14 1.0  0 0    0.001 17 1.0  0
0.700 15 0.5 16 1.0  0.010 18 0.5 19 1.0
1.0   17 1.0  0      0.10  20 1.0  0
```
This structure allows to write all linear relation between parameters. However in a block the number of terms in the expansion and the size of the relation is the same for all the variables.

### alternate refinement of parameters

In case of strong correlation between some crystallographic parameters, it is possible without modifying at each cycle the command file to alternate the refined parameters. This can easily be done using some cycling utilities like cycle.xnd (Unix) or xnd_bat.bat (msdos).
In all cases the ValidRef parameter in the header is used to specify the strategy. Then at each time xnd is started the program uses the value of PrtNew to choose the refined parameters. As PrtNew increases the refined parameters will change.

 code refined if ValidRef coupling 1 1 always used 2 .. 9 10 .. 199 read 200 ..999 read 2..9 1 always used 2 PrtNew % ValidRef == 0 3 PrtNew % ValidRef == 1 9 PrtNew % ValidRef == 7 10 .. 199 read always used 200 ..299 read PrtNew % ValidRef == 0 300 ..399 read PrtNew % ValidRef == 1 400 ..499 read PrtNew % ValidRef == 2

The following table represent the inside of a block and what append for ValidRef = 4. Note that ValidRef is restricted to values between 2 and 9 and that codeword are always lower than 1000.
 code value coupling refined if PrtNew is 0.105 1 always used 0.251 2 0, 4, 8, ... 0.249 3 1, 5, 9, ... 0.413 11 1.0 always used 0.413 199 1.0 always used 0.700 200 1.0 0, 4, 8, ... 0.700 201 1.0 0, 4, 8, ... 0.700 300 1.0 1, 5, 9, ...

JFB Feb 21th, 1997