Finds cells adjacent to other cells in a multi-dimensional array (R.W. Payne).

### Options

`ADJACENTINDEXES` = pointer |
Pointer containing a variate for each cell, giving the indexes of its adjacent cells |

`DIAGONALS` = string token |
Whether to include diagonal cells (`include` , `exclude` ); default `incl` |

`DISTANCE` = scalar |
Maximum distance between cells and adjacent cells; default `1` |

### Parameters

`DIMENSION` = scalars |
Dimensions of the array |

`CELLS` = variates |
Locations of the cells in each dimension |

`ADJACENTCELLS` = pointers |
The pointer for each `DIMENSION` contains a variate for each cell with the locations of its adjacent cells in that dimension |

### Description

`ADJACENTCELLS`

finds the cells that are adjacent to cells in a multi-dimensional array. The `DISTANCE`

option specifies how close the cells need to be for them to be classed as adjacent. The default of one indicates that they must be alongside each other. A setting of two means that there can be an intervening cell, and so on. The default is to include cells that are diagonal to each other, but you can set option `DIAGONALS=exclude`

to exclude these.

The `DIMENSION`

parameter supplies a list of scalars defining the dimensions of the array (i.e. the number of cells in each direction). The `CELLS`

parameter supplies a list of variates giving the locations of the cells in each dimension.

The adjacent cells can be saved in two different ways. The `ADJACENTCELLS`

parameter can supply a list of pointers, one for each dimension. These contain a variate for each cell, containing the locations of its adjacent cells in that dimension. Alternatively, the `ADJACENTINDEXES`

option can save pointer containing a variate for each cell. This saves the indexes of the adjacent cells for that cell. (These indexes are defined as the locations of the cells within a multi-way table classified by factors representing the dimensions.)

Options: `ADJACENTINDEXES`

, `DIAGONALS`

, `DISTANCE`

.

Parameters: `DIMENSION`

, `CELLS`

, `ADJACENTCELLS`

.

### See also

Procedure: `NEIGHBOURS`

.

Commands for: Spatial statistics.

### Example

CAPTION 'ADJACENTCELLS example'; STYLE=meta VARIATE [VALUES=1,1,2,2] x & [VALUES=2,3,3,4] y & [VALUES=5,3,4,3] z ADJACENTCELLS [ADJACENTINDEXES=index] 2,4,5; CELLS=x,y,z; ADJACENTCELLS=ax,ay,az FACTOR [NVALUES=40; LEVELS=2] fx & [LEVELS=4] fy & [LEVELS=5] fz GENERATE fx,fy,fz " details of the cells adjacent to each original cell " FOR [INDEX=i; NTIMES=4] SCALAR xcell,ycell,zcell; VALUE=x$[i],y$[i],z$[i] " print the coordinates of the cells " CAPTION 'Cell' PRINT xcell,ycell,zcell; FIELD=8; DECIMALS=0 " print the coordinates of its adjacent cells " CAPTION 'Adjacent cells' PRINT ax[i],ay[i],az[i]; FIELD=8; DECIMALS=0 " show the locations of the adjacent cells, using a 3-way table " VARIATE [NVALUES=40] tvals CALCULATE icell = (xcell-1)*4*5 + (ycell-1)*5 + zcell & tvals$[icell] = 1 & tvals$[index[i]] = 2 TABLE [CLASS=fx,fy,fz] tab; VALUES=tvals CAPTION 'Cell locations' PRINT [RLWIDTH=6; VSPECIAL=!(1,2); TSPECIAL=!t('cell','adj')]\ tab; FIELD=6 ENDFOR