Swift External Mapper
The external mapper, ext maps based on the output of a supplied Unix executable.
parameter | meaning |
exec | name of the executable (relative to the current directory, if an absolute path is not specified) |
* | Other parameters are passed to the executable prefixed with a - symbol |
The output (stdout) of the executable should consist of two columns of data, separated by a space. The first column should be the path of the mapped variable, in Swift script syntax (for example [2] means the 2nd element of an array) or the symbol $ to represent the root of the mapped variable. The following table shows the symbols that should appear in the first column corresponding to the mapping of different types of swift constructs such as scalars, arrays and structs.
Example:
With the following in mapper.sh,#!/bin/bash
echo "[2] qux"
echo "[0] foo"
echo "[1] bar"
then a mapping statement:
student stus[] <ext;exec="mapper.sh">;
would map
Advanced Example: The following mapper.sh is an advanced example of an external mapper that maps a two-dimensional array to a directory of files. The files in the said directory are identified by their names appended by a number between 000 and 099. The first index of the array maps to the first part of the filename while the second index of the array maps to the second part of the filename.
#!/bin/sh
#take care of the mapper args
while [ $# -gt 0 ]; do
case $1 in
-location) location=$2;;
-padding) padding=$2;;
-prefix) prefix=$2;;
-suffix) suffix=$2;;
-mod_index) mod_index=$2;;
-outer_index) outer_index=$2;;
*) echo "$0: bad mapper args" 1>&2
exit 1;;
esac
shift 2
done
for i in ‘seq 0 ${outer_index}‘
do
for j in ‘seq -w 000 ${mod_index}‘
do
fj=‘echo ${j} | awk ’{print $1 +0}’‘ #format j by removing leading zeros
echo "["${i}"]["${fj}"]" ${location}"/"${prefix}${j}${suffix}
done
done
The mapper definition is as follows:
file_dat dat_files[][] < ext;
exec="mapper.sh",
padding=3,
location="output",
prefix=@strcat( str_root, "_" ),
suffix=".dat",
outer_index=pid,
mod_index=n >;