Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29275 토론

Problems with a FORTRAN 77 format specifier

david_sallngc_com
초급자
1,671 조회수
I am trying to help someone run a FORTRAN 77 code on the Intel Fortran 11 compiler where they are having difficulty with a FORMAT specifier. They have told me that the followingFORMAT worked on COMPAQ Fortran,

format((g13.6, ','),(g13.6,','), (g13.6,','),(g13.6))

even when N = 1. Running this on Intel Fortran will create an error when N = 1.

I have written a "variable" format specifier for them but was wondering if there is a way of setting one of the Project properties to allow this to work?

Thank you very much for your help.

Sincerely,

David
0 포인트
7 응답
mecej4
명예로운 기여자 III
1,671 조회수
A copy of the CVF reference manual is available online .

The CVF 6.6 reference manual states on p.51 of the I/O Formatting chapter:

"If the value of a variable format expression does not obey the restrictions on magnitude applying to its use in the format, an error occurs",

and on p.8 of the same chapter: "r Is a repeat specification. The range of r is 1 through 2147483647 (2**31-1). If r is omitted, it is assumed to be 1."

These quotes refute what you were told regarding the use of a zero repeat factor.
0 포인트
DavidWhite
소중한 기여자 II
1,671 조회수
Why not change your code to
format((g13.6, ','), (g13.6,','),(g13.6))

This will then work for all N>=1

David
0 포인트
jimdempseyatthecove
명예로운 기여자 III
1,671 조회수
Good catch David

I think the original code was a modification when the format specifier had different width.
He could also use
format((g13.6,','))
0 포인트
david_sallngc_com
초급자
1,671 조회수
Hi David!

The person I am trying to help wants to write out a file in CSV format which would put commas in between each output variable. Your fix would only work for N > 0. He has cases of N = 0. I guess he was mistaken about the case when N = 0. As I said in my original post, I sent him a modified version that will create a variable format by constructing a format string, fmt,that is used as,

format(fid, fmt) x, y, ...

Thanks for your input!

David
0 포인트
TimP
명예로운 기여자 III
1,671 조회수
It's possible that CVF did something which worked in this context, even though the action for N==0 wasn't defined. Of course, this never was Fortran 77, even within the limits where CVF defined it. Dependence on implementation dependent behavior of 0 length constructs was more common prior to F77; F77 compilers often had switches to support some of it.
0 포인트
mecej4
명예로운 기여자 III
1,671 조회수
Here is a test with CVF 6.6.
[fxfortran]      program refute
      integer N
      real X(2)
      X(1)=10.0
      X(2)=20.0
      N=3
      write(*,10)X
      N=2
      WRITE(*,10)x(2)
      N=1
      WRITE(*,10)x(2)
   10 format((g13.6,','))
      end
[/fxfortran]
The output:

[bash]  10.0000    ,  20.0000    ,
  20.0000    ,
forrtl: severe (68): variable format expression value error, unit -1, file CONOUT$
Image              PC        Routine            Line        Source
ref.exe            00405749  Unknown               Unknown  Unknown
ref.exe            004055A7  Unknown               Unknown  Unknown
ref.exe            00404784  Unknown               Unknown  Unknown
ref.exe            00404BB9  Unknown               Unknown  Unknown
ref.exe            00403A77  Unknown               Unknown  Unknown
ref.exe            00402AC3  Unknown               Unknown  Unknown
ref.exe            00401122  REFUTE                     11  ref.f
ref.exe            00427399  Unknown               Unknown  Unknown
ref.exe            0041E684  Unknown               Unknown  Unknown
kernel32.dll       7C817077  Unknown               Unknown  Unknown[/bash]
0 포인트
IanH
명예로운 기여자 III
1,671 조회수
One more format unto the breach...

If "someone" was happy using an extension to F77 previously, then I could suggest another F77 extension that is pretty common in fortran compilers these days (the extension being part of F90...).

And you can get rid of that pesky N thing.

[fortran]program format_me
  implicit none
  real :: x(5) = [1.0,2.0,3.0,4.0,5.0]

  write (*, 100) x(1:0)
  write (*, 100) x(1:1)
  write (*, 100) x(1:2)
  write (*, 100) x(1:5)

  100 format(99999(G13.6,:,','))

end program format_me
[/fortran]

0 포인트
응답