#!/bin/sh

#	NAME
#		sci2mma - Scientific to Mathematica Format converter
#
#	SYNOPSIS
#		sci2mma [ file ] ...
#
#	DESCRIPTION
#		sci2mma acts as a filter or file conversion utility to convert
#		occurances of strings of the form "1.234e-5" to "1.234*10^-5 .
#		Thus a text file produced by a program written in C, Fortran,
#		etc., may be used as input to Mathematica using its Get[..]
#		function.
#
#		When called with no filename arguments, sci2mma takes the
#		standard input as input and sends its output to the standard
#		output.  If called with filename arguments, each file is
#		modified as described above.
#
#	AUTHOR
#		Tyler Perkins			perkins@spot.colorado.edu
#		Boulder, CO

#	Command to tell sed how to edit each line.  Do substitution.
sedcmd='s/\([0-9\.]\)[eE]\([0-9\+\-]\)/\1*10^\2/g'

if [ "$*" = "" ]
then	sed $sedcmd

#	Otherwise, do each file in turn, using a temporary file who's name
#	is generated by the utility mktemp.
else	temp=`mktemp`
	for f in $*
	do	sed $sedcmd $f >$temp
		mv $temp $f
	done
fi
