# Fortran2Ruby

**URL:** <https://www.ruby-forum.com/t/fortran2ruby/76394>\
**Category:** Ruby\
**Created:** [November 18, 2006, 9:04am UTC](https://www.ruby-forum.com/t/fortran2ruby/76394 "2006-11-18T09:04:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 18, 2006, 9:04am UTC](https://www.ruby-forum.com/t/fortran2ruby/76394/1 "2006-11-18T09:04:18Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 18, 2006, 9:33pm UTC](https://www.ruby-forum.com/t/fortran2ruby/76394/2 "2006-11-18T21:33:26Z")

</div>

Pawel S. wrote:

> Hi all,
> 
> [http://www.edibleunknown.com/articles/2006/11/17/cooking-with-trek-the-motion-picture](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. 😉

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

Cheers,  
Hal

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 19, 2006, 3:17am UTC](https://www.ruby-forum.com/t/fortran2ruby/76394/3 "2006-11-19T03:17:57Z")

</div>

Hal F. wrote:

> It’s possible to write Fortran in any language. 😉  
> But it’s harder in Ruby than most of the others. 🙂

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

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

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 18, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/fortran2ruby/76394/4 "2006-11-18T22:41:31Z")

</div>

On 11/18/06, Hal F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Pawel S. wrote:
> 
> > Hi all,
> > 
> > [http://www.edibleunknown.com/articles/2006/11/17/cooking-with-trek-the-motion-picture](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. 🙂 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](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

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 20, 2006, 5:17pm UTC](https://www.ruby-forum.com/t/fortran2ruby/76394/5 "2006-11-20T17:17:04Z")

</div>

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-](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/](http://blog.zenspider.com/archives/2006/10/)  
inlinefortran\_100\_released.html
