Appendix 3: Advanced Unix Concepts

The following Unix commands are useful with IPW, they are also useful in using Unix in general and will reduce the amount of typing.

1. C-shell for loop

% foreach i (a b c ...)

? ..... $i .....

? end

where a, b, c are variables which can be words or numbers and $i expands to each variable, and ..... represents a Unix or IPW command.

Note: the computer prints the ? at the beginning of the next line.

For example, the following loop creates create masks for 3 land cover types, assuming there is a directory for each land cover category containing a coordinates file.

% foreach i (tree snow road)

? scribe -f -c $i/coords -i blank.ipw > $i/mask.ipw

? end

This loop expands to the following three commands:

% scribe -f -c tree/coords -i blank.ipw > tree/mask.ipw

% scribe -f -c snow/coords -i blank.ipw > snow/mask.ipw

% scribe -f -c road/coords -i blank.ipw > road/mask.ipw

Similarily, the following loop computes histograms for 6 image bands:

% foreach i (1 2 3 4 5 7)

? hist $i.ipw > $i.hst

? end

For loops can be nested so the following loop computes 6 histograms for 3 categories, which would otherwise be 18 commands.

% foreach i (snow glacier rock)

? foreach j (1 2 3 4 5 7)

? hist -m $i/mask.ipw $j.ipw > $i/$j.hst

? end

? end

2. {} syntax

The syntax {a,b,c}.x is a shorthand for a.x b.x c.x

For example, the following command can be used to interleave 6 image files and compute statistics:

% mux {1,2,3,4,5,7}.ipw | mstats > stats

This expands to:

% mux 1.ipw 2.ipw 3.ipw 4.ipw 5.ipw 7.ipw | mstats > stats