MOCKSTACKS
EN
Questions And Answers

More Tutorials









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 inseq 0 ${outer_index}do
for j inseq -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 >;

Conclusion

In this page (written and validated by ) you learned about Swift External Mapper . What's Next? If you are interested in completing Swift tutorial, your next topic will be learning about: Swift Executing app procedures.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.