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.
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:
k=810000
...
WRITE(*,'(F9.5)') REAL(k)/100000.
0
cscpaymasterAuthor Commented:
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.
RATE=ECURRT/100000
WRITE(lu02,"(F9.5)")RATE
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.
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.
0
Featured Post
Solve your biggest tech problems alongside global tech experts with 1:1 help.
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:
k=810000
...
WRITE(*,'(F9.5)') REAL(k)/100000.