Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:58:03+00:00 2026-06-08T02:58:03+00:00

I have a binary file that I would like to read with Fortran. The

  • 0

I have a binary file that I would like to read with Fortran. The problem is that it was not written by Fortran, so it doesn’t have the record length indicators. So the usual unformatted Fortran read won’t work.

I had a thought that I could be sneaky and read the file as a formatted file, byte-by-byte (or 4 bytes by 4 bytes, really) into a character array and then convert the contents of the characters into integers and floats via the transfer function or the dreaded equivalence statement. But this doesn’t work: I try to read 4 bytes at a time and, according to the POS output from the inquire statement, the read skips over like 6000 bytes or so, and the character array gets loaded with junk.

So that’s a no go. Is there some detail in this approach I am forgetting? Or is there just a fundamentally different and better way to do this in Fortran? (BTW, I also tried reading into an integer*1 array and a byte array. Even though these codes would compile, when it came to the read statement, the code crashed.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:58:05+00:00Added an answer on June 8, 2026 at 2:58 am

    Yes.

    Fortran 2003 introduced stream access into the language. Prior to this most processors supported something equivalent as an extension, perhaps called “binary” or similar.

    Unformatted stream access imposes no record structure on the file. As an example, to read data from the file that corresponds to a single int in the companion C processor (if any) for a particular Fortran processor:

    USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT
    INTEGER, PARAMETER :: unit = 10
    CHARACTER(*), PARAMETER :: filename = 'name of your file'
    INTEGER(C_INT) :: data
    !***
    OPEN(unit, filename, ACCESS='STREAM', FORM='UNFORMATTED')
    READ (unit) data
    CLOSE(unit)
    PRINT "('data was ',I0)", data
    

    You may still have issues with endianess and data type size, but those aspects are language independent.

    If you are writing to a language standard prior to Fortran 2003 then unformatted direct access reading into a suitable integer variable may work – it is Fortran processor specific but works for many of the current processors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a binary file that I would like to regex search/replace hex bytes
I have a binary file, that was written in C, which contains a long
We have large files with zlib-compressed binary data that we would like to memory
I have a binary file that contains blocks of information ( I'll refer to
I have a function that copies binary file public static void copyFile(String Src, String
I have a raw image file that is saved in binary data (no encoding).
I have response stream from a ftp web request that returns binary file. I
I have a binary file that was created on a unix machine. It's just
I have a ASCII file where every line contains a record of variable length.
I would like to read an file into a string. I am looking for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.