Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1994
*January
*February
*March
*April
*May
*June
*July
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1994

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Fortran Real -> Mathematica

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Re: Fortran Real -> Mathematica
  • From: PERKINS TYLER R <perkins at spot.colorado.edu>
  • Date: Thu, 20 Jan 1994 16:36:49 -0700 (MST)

Dr. Stefan P. Mueller <ONM010 at vm.hrz.uni-essen.de> wrote:

>   I have several 100x100 2-D matrices of Fortran-style floating point
>numbers (xxxExx), represented as Mathematica lists. Has anybody on
>this list written a function to convert these numbers to regular
>Mathematica Real objects? I remember seeing something similar but
>unfortunately I lost the message.

OK, here it is again.  It includes a couple simplifications and minor
improvements I've done since the last time, but the old code should work
as well.  As before, I'm including my own mktemp utility in case your
system doesn't have one.

I hope you find this useful.
	Tyler Perkins                       perkins at spot.colorado.edu
	Boulder, CO

-=-=-=-=-=-=-=-=-=-=-=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=-=-=-=-
#!/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 at 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
-=-=-=-=-=-=-=-=-=-=-=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=-=-=-=-
#!/bin/sh

#	NAME
#		mktemp - Create a unique filename.
#
#	SYNOPSIS
#		mktemp [ -c ] [ -d directory_name ] [ -p the_prefix ]
#
#	DESCRIPTION
#		The mktemp command makes a name for the pathname of a temporary #		file and writes that name to standard output. The name will not #		duplicate that of an existing file.  With no arguments, mktemp
#		returns the string "/tmp/username.DDHHMMSSP...P" where username
#		is the user's username, DD is the day of the month, HH is the
#		hour of the day (locally), MM is the minute of the hour, SS is
#		the second of the minute, and P...P is the process id of the
#		user's shell.
#
#	OPTIONS
#
#	-c
#		Create an empty file whose filename is the generated name.
#
#	-d directory_name
#		Force directory_name to be used as the directory portion of
#		the pathname.  If this option is absent, /tmp is used by
#		default.
#
#	-p the_prefix
#		Use string the_prefix as the filename's prefix.  If this option
#		is absent, the user's username is used by default.
#
#	AUTHOR
#		Tyler Perkins			perkins at spot.colorado.edu
#		Boulder, CO

dir="/tmp"
prfx="$USER"
create=false

while [ "$1" != "" ]
do	case $1 in
	-d)	shift
		dir="`echo $1 | sed 's!\(.*\)/$!\1!'`"
		shift
		continue
		;;
	-p)	shift
		prfx=$1
		shift
		continue
		;;
	-c)	shift
		create=true
		continue
		;;
	*)	echo 'mktemp usage: mktemp [-d directory] [-p prefix] [-c]'
		exit 1
		;;
	esac
done

name="$dir/$prfx.`date | sed 's/.*\(..\) \(..\):\(..\):\(..\).*/\1\2\3\4/'`$$"

# If file with name $name already exists, recurse until not.
if [ -f $name  -o  -d $name ]
then	name="`mktemp`"
fi

if $create
then	>$name
else	echo $name
fi





  • Prev by Date: Sounds on the Mac
  • Next by Date: InterpolatingFunction
  • Previous by thread: Sounds on the Mac
  • Next by thread: InterpolatingFunction