#!/bin/sh
#
#	Converts a template file to a typed file
#
#	Usage: maketype type template_file output_file
#
#	In what follows,
#	<T> is the "type", e.g. DComplex
#	<P> is the "precision", e.g. Double
#	<A> is the "abbreviation"
#
#	Description       "Type"    "Precision" "Abbreviation"
#	___________       _____     __________  _____________
#
#	double prec.      Double     double          D
#       float prec.       Float      float           F
#       double complex    DComplex   double          C
#	float complex     FComplex   float           B
#
if [ $# != 3 ]
then
	echo Usage: maketype type template_file output_file
	exit 1
fi
#	Determine the precision and abbreviation
case $1 in 
DComplex)
	precision="Double"
	abbrev="C"
	;;
FComplex)
	precision="Float"
	abbrev="B"
	;;
Float)
	precision="Float"
	abbrev="F"
	;;
Double)
	precision="Double"
	abbrev="D"
	;;
# Default: select first character as abbrev:
*)
	precision=$1
	abbrev=`echo $1 | sed  's/^\([A-Za-z]\).*/\1/'`
	;;
esac
rm -f $3
sed "s/<T>/$1/g; s/<P>/$precision/g; s/<A>/$abbrev/g" $2 >$3
# Readonly to discourage changes:
chmod 444 $3
