Any Fortran Gurus here?

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.

Does CARRIAGECONTROL=‘NONE’ have any positive effect?

Is your punched card reader connected properly?

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 … :stuck_out_tongue: )

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.

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.

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

Recl=‘16’?

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.

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

Not being a Fortran guru, I don’t have an answer for you, but I suggest trying your question on Stack Overflow. I have been consistently impressed with the answers to my programming queries there, often on rather obscure topics.

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.

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

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.