# Any Fortran Gurus here?

**URL:** <https://boards.straightdope.com/t/any-fortran-gurus-here/567552>\
**Category:** Factual Questions\
**Created:** [January 14, 2011, 2:44am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552 "2011-01-14T02:44:15Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZenBeam](https://avatars.discourse-cdn.com/v4/letter/z/3ab097/32.png) [@ZenBeam](https://boards.straightdope.com/u/ZenBeam)\
**Post date:** [January 14, 2011, 2:44am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/1 "2011-01-14T02:44:15Z")

</div>

I need to write binary files, with the data in a particular form. I can do this when I compile using the Intel Fortran compiler for Windows, using the Form = ‘Binary’ specifier when I open the file. I want to recompile the code on a Linux system, the (I think) Gnu Fortran compiler doesn’t support Form = ‘Binary’, only Form = ‘Unformatted’. That writes records, adding some starting and ending data to bookend the data I’m writing.

For example, if I write four integers using  
WRITE(50) I1, I2, I3, I4  
The binary file will have  
I1, I2, I3, I4  
but the unformatted file will have  
16 I1, I2, I3, I4 16  
where the 16s (10 hex) are the number of bytes written. I can’t have the 16s.

This is a standard in-house file format, so I can’t change it. The only way around this I can think of is to link in some C or C++ code, to write the file correctly. I’ve linked Fortran with C in the past, but it’s been a while and I’ll have to re-figure that out.

Anyone have any other suggestions? Compiler flags to look for, maybe?

I’ll mention that this is not an endianness problem.

---

<div class="post-metadata">

**Author:** ![Bewildebeest](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Bewildebeest](https://boards.straightdope.com/u/Bewildebeest)\
**Post date:** [January 14, 2011, 3:33am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/2 "2011-01-14T03:33:10Z")

</div>

Does CARRIAGECONTROL=‘NONE’ have any positive effect?

---

<div class="post-metadata">

**Author:** ![Uncertain](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@Uncertain](https://boards.straightdope.com/u/Uncertain)\
**Post date:** [January 14, 2011, 5:44am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/3 "2011-01-14T05:44:35Z")

</div>

Is your punched card reader connected properly?

---

<div class="post-metadata">

**Author:** ![FeAudrey](https://avatars.discourse-cdn.com/v4/letter/f/7feea3/32.png) [@FeAudrey](https://boards.straightdope.com/u/FeAudrey)\
**Post date:** [January 14, 2011, 6:28am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/4 "2011-01-14T06:28:28Z")

</div>

The simplest work-around would be to write a post-processing program for the Linux/Gnu version (in whatever language works) that would reformat the problem file to the in-house format.

And DOCUMENT that there’s an extra step in that version, and why.  
(Note to Bewildebeest and Uncertain: I know how to invoke the Fortran senselight function. Don’t make me go there … 😛 )

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [January 14, 2011, 8:05pm UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/5 "2011-01-14T20:05:14Z")

</div>

**Uncertain** , I would probably have found that funny, were it not for the fact that I’m actually down in the trenches with some old F77 code. Completely undocumented F77 code, without comments.

---

<div class="post-metadata">

**Author:** ![CurtC](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@CurtC](https://boards.straightdope.com/u/CurtC)\
**Post date:** [January 14, 2011, 8:31pm UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/6 "2011-01-14T20:31:57Z")

</div>

_I_ for one thought it was real funny. In my college years, the only computer work I did (as an EE major) was Fortran on punched cards.

---

<div class="post-metadata">

**Author:** ![Bewildebeest](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Bewildebeest](https://boards.straightdope.com/u/Bewildebeest)\
**Post date:** [January 14, 2011, 8:56pm UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/7 "2011-01-14T20:56:07Z")

</div>

The 16’s look like record length indicators. Maybe add RECORDLENGTH=16, or RECORDSIZE=16 to your open statement.

---

<div class="post-metadata">

**Author:** ![Bewildebeest](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Bewildebeest](https://boards.straightdope.com/u/Bewildebeest)\
**Post date:** [January 14, 2011, 9:35pm UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/8 "2011-01-14T21:35:56Z")

</div>

Recl=‘16’?

---

<div class="post-metadata">

**Author:** ![ZenBeam](https://avatars.discourse-cdn.com/v4/letter/z/3ab097/32.png) [@ZenBeam](https://boards.straightdope.com/u/ZenBeam)\
**Post date:** [January 14, 2011, 10:39pm UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/9 "2011-01-14T22:39:08Z")

</div>

> [@Bewildebeest](#):
>
> Does CARRIAGECONTROL=‘NONE’ have any positive effect?

I attempted to use an equivalence statement with a character array. but there were still some some extra bytes being written that looked like carriage controls, and I thought of your post. But sadly, CARRIAGECONTROL is also an extension, and not supported by my compiler (gfortran, I’ve since discovered). So this almost helped. The 16s are record length indicators, and I can’t have them in the file.

Thanks for the ideas, everyone, but I’ve moved on to just calling C++. This is almost working (one small bug left, and I need to verify it works with large files), and wasn’t too much trouble.

> [@Uncertain](#):
>
> Is your punched card reader connected properly?

I’ve been programming Fortran for over a quarter century. I have never used punch cards.

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [January 14, 2011, 10:50pm UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/10 "2011-01-14T22:50:40Z")

</div>

Not being a Fortran guru, I don’t have an answer for you, but I suggest trying your question on [Stack Overflow](http://www.stackoverflow.com/). I have been consistently impressed with the answers to my programming queries there, often on rather obscure topics.

---

<div class="post-metadata">

**Author:** ![Bijou\_Drains](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bijou_drains/32/2814_2.png) [@Bijou\_Drains](https://boards.straightdope.com/u/Bijou_Drains)\
**Post date:** [January 15, 2011, 2:11am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/11 "2011-01-15T02:11:46Z")

</div>

Businesses got rid of punch cards by the 80s but I know from personal experience some universities still used them into the early to mid 80s.

---

<div class="post-metadata">

**Author:** ![redtail23](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@redtail23](https://boards.straightdope.com/u/redtail23)\
**Post date:** [January 15, 2011, 3:01am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/12 "2011-01-15T03:01:13Z")

</div>

You got a snicker out of me, **Uncertain**. But then I _have_ done Fortran IV programming, on punch cards. Good times, good times.

---

<div class="post-metadata">

**Author:** ![Khadaji](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Khadaji](https://boards.straightdope.com/u/Khadaji)\
**Post date:** [January 15, 2011, 11:24am UTC](https://boards.straightdope.com/t/any-fortran-gurus-here/567552/13 "2011-01-15T11:24:15Z")

</div>

> [@friedo](#):
>
> Not being a Fortran guru, I don’t have an answer for you, but I suggest trying your question on [Stack Overflow](http://www.stackoverflow.com/). I have been consistently impressed with the answers to my programming queries there, often on rather obscure topics.

I agree with _friedo_, it is a great place to get answers, I rarely wait more than 3 or 4 hours if I post a question before someone has an answer - but IME the board can be a little rough if they think you are a newbie. Be sure to search the board to find out if the question has been answered there already.
