Fortran2Ruby

Hi all,

This is kind of silly, but hopefully not too off topic for the list. :slight_smile:

I made a small contribution to a friend’s (food related) blog today
about the 1978 Star Trek Cookbook. The introductory chapter includes a
source code listing of an old fortran program to type and run (on your
PDP-11?). For whatever reason, I took it upon myself to convert it
over to ruby:

http://www.edibleunknown.com/articles/2006/11/17/cooking-with-trek-the-motion-picture

Ultimately it works just fine, but it didn’t come out as cleanly as I
would like. Specifically the part where I had to pad out the arrays
passed to a sprintf string so as not to get a ‘too few arguments’
error. If you don’t feel like clicking over, here’s what I mean:

fmt007 = ’ ’ * 2 + “\n” * 3 + ’ ’ * 5 + ‘%2c’ * 20
pad = Array.new(20).fill(20)

puts fmt007 % [ food[1], waffl[3], dish[2], food[12], dish[3],
fryer[2], waffl[13], *pad ]

I wanted to keep it short and as much in the spirit of the original
fortran program as possible, but that *pad hack bothers me. I’ve
considered using Array#pack instead of the sprintf since the arguments
are much more similar to fortran’s format, but I’d lose the field
width and precision control. Can anyone think of a better way? Maybe
even just a prettier way of padding the array.

And before you tell me, yes, yes… I know that ruby’s not fortran and
fortan’s not ruby and I’m a fool for wasting your time with this. It’s
kind of fun for me though, and I know there are a lot of people out
there more clever than me who enjoy a challenge. Is it possible to
write fortran code in ruby?

Thanks!

-Pawel

Pawel S. wrote:

Hi all,

http://www.edibleunknown.com/articles/2006/11/17/cooking-with-trek-the-motion-picture

As Zefrem Cochrane is my witness, that is the strangest thing
I have heard of in a week.

I wanted to keep it short and as much in the spirit of the original
fortran program as possible, but that *pad hack bothers me. I’ve
considered using Array#pack instead of the sprintf since the arguments
are much more similar to fortran’s format, but I’d lose the field
width and precision control. Can anyone think of a better way? Maybe
even just a prettier way of padding the array.

I’ll have to look at the original and think about this.
Have you considered just fixing all the array handling,
since you’re porting anyway?

And before you tell me, yes, yes… I know that ruby’s not fortran and
fortan’s not ruby and I’m a fool for wasting your time with this. It’s
kind of fun for me though, and I know there are a lot of people out
there more clever than me who enjoy a challenge. Is it possible to
write fortran code in ruby?

It’s possible to write Fortran in any language. :wink:

You’re not a fool, you’re just eccentric… as are many of us here…

Cheers,
Hal

Hal F. wrote:

It’s possible to write Fortran in any language. :wink:
But it’s harder in Ruby than most of the others. :slight_smile:


M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given
rabbits fire.

On 11/18/06, Hal F. [email protected] wrote:

Pawel S. wrote:

Hi all,

http://www.edibleunknown.com/articles/2006/11/17/cooking-with-trek-the-motion-picture

As Zefrem Cochrane is my witness, that is the strangest thing
I have heard of in a week.

Glad to have raised an eyebrow. :slight_smile: Your new book is great by the way!

I’ll have to look at the original and think about this.
Have you considered just fixing all the array handling,
since you’re porting anyway?

Do you mean for the 0-vs-1 based arrays? I had considered it, but I
kind of wanted to keep the original indexes to keep it looking close
to the original. If I was going to go about it in a sensible way
though, I guess it would just be a series of puts statements though or
at least a more ruby-like obfuscation.

Here’s a text version that compiles under f77 by the way:
http://www.edibleunknown.com/files/trek.f

I didn’t really know anything about fortran going in, so I had to play
around with the original to see what the result was supposed to be
first.

It’s possible to write Fortran in any language. :wink:

Ah yes, I’ve heard this corollary and it was part of my inspiration.

You’re not a fool, you’re just eccentric… as are many of us here…

Thanks!

-Pawel

On Nov 18, 2006, at 12:02 AM, Pawel S. wrote:

I made a small contribution to a friend’s (food related) blog today
about the 1978 Star Trek Cookbook. The introductory chapter includes a
source code listing of an old fortran program to type and run (on your
PDP-11?). For whatever reason, I took it upon myself to convert it
over to ruby:

http://www.edibleunknown.com/articles/2006/11/17/cooking-with-trek-
the-motion-picture

Alternatively, you could have stuck with fortran:

http://blog.zenspider.com/archives/2006/10/
inlinefortran_100_released.html