FORTRAN Formatting on Input/Output

Posted on 2012-09-20
Last Modified: 2012-09-21
I am working with Fortran 77 and Fortran 90 code, some of which is converted and some that is melded together.  I have come across a formatting descriptor that I can not find anywhere in any reference.  Generally, it seems to be used for an integer conversion.  For example, a variable containing the number 810000 (as an integer) is written out to obtain 8.10000 as a result using dfloat, but the descriptor is -5PF9.5.  I cannot find any information anywhere as to what the -5 or the P means.  I know, for instance, if it had been 2F5.2, it would mean to repeat 5.2 twice, but the -5PF9.5 is not the same and I'm baffled as to where this comes from.  I'm guessing that the -5 has something to do with the decimal being inserted 5 places to the left (in this case), but why the 'P'? Does anyone have any insight into the '-5P' portion here?  I've seen different negative numbers, but there is always a P.
Question by:cscpaymaster
    LVL 5

    Accepted Solution

    The P edit descriptor is a very exotic Fortran feature, which I have never used, actually. Its effect is to introduce a scaling in the data of 10 to the power indicated, which can also be negative, in your case it divides the argument by 100000.
    If you have the chance to modify the code I think it would be much more readable to use a plain F9.5 and explicitly divide the variable by 100000, something like:

    WRITE(*,'(F9.5)') REAL(k)/100000.

    Author Comment

    I guess I was on the right track; I tried doing this:

    RATE is declared as REAL*4, ECURRT is an INTEGER*4 (although I don't think that would matter here.


    where ECURRT=810000, but my output (RATE) is 8.00000 instead of the expected 8.10000, so of course it is throwing my calcuation off.  Any idea why it isn't translating all the digits?

    Incidently, also tried RATE=REAL(ECURRT/100000)

    UPDATE - had the parentheses wrong, tried RATE=(ECURRT)/100000 and it worked just fine.  Thank you so much.
    LVL 5

    Expert Comment

    Yes, REAL(ECURRT/100000) computes first the expression as INTEGER then converts to REAL, you need at least REAL(ECURRT)/100000 or ECURRT/100000. (notice the dot!) to have that expression evaluated as floating point.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    779 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

    17 Experts available now in Live!

    Get 1:1 Help Now