Fortran2Ruby

  • Thread starter Pawel Szymczykowski
  • Start date
P

Pawel Szymczykowski

Hi all,

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

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
 
H

Hal Fulton

Pawel said:

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. ;)

You're not a fool, you're just eccentric... as are many of us here...


Cheers,
Hal
 
P

Pawel Szymczykowski

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

Glad to have raised an eyebrow. :) 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. ;)

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
 
R

Ryan Davis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,219
Messages
2,571,117
Members
47,729
Latest member
taulaju99

Latest Threads

Top