How to read single precision (REAL*4) FORTRAN 77 Binary data using Perl 5.6 and above

Posted on 2006-05-19
Last Modified: 2013-11-08
I'm trying to read unformatted fortran 77 data, specifically single precision real*4 data, using perl 5.6.  The reason for using perl for this problem is that I'm analyzing data, and I want the program to be as portable as possible.  The other part of this question is how to read the binary data created on a different bit machine i.e. created on a 32-bit SUN then read on a 64-bit SGI.  I know how to check for the "endian-ness" using perl, however I'm not sure how to read the binary data created by fortran.  Any response will be greatly appreciated.
Question by:jeffag04
    LVL 84

    Accepted Solution

    you can use unpack"f" to unpack binary float data, but it is not portable, since it uses the native format
    to be truely portable you may want to dump the float as a string, or if the format is not under your control, you may have to unpack it bit by bit to convert whatever format it is in.

    Author Comment

    I'm aware of the unpack/pack functions along with the different codes such as f,n,N, etc.  Using unpack "f" doesn't read the binary data correctly on its own.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Title # Comments Views Activity
    can't find import specifications in access 2 26
    sameEnds challenge 3 78
    Regular Expression for URL 10 65
    wordlen challenge 3 26
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    This video teaches viewers about errors in exception handling.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now