- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have the source code for a program that was written in Fortran 77 (i.e. program.for). I get many compiler errors when I try to compile this file. I believe the problem is that many of the lines of code exceed the 72 columns allowed inFortran77. I want to convert this file to a .f90. Is there a simple command for visual studio or command line that I can use to convert this file or do I have to do it manually?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have seen tools to do this, but they're not part of the Intel Visual Fortran product. You can specify a fixed form line length of 80 or 132 - that's probably a better bet. In Visual Studio, this is under Fortran > Language.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have seen tools to do this, but they're not part of the Intel Visual Fortran product. You can specify a fixed form line length of 80 or 132 - that's probably a better bet. In Visual Studio, this is under Fortran > Language.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here's what I made to do this for me a few years ago. Just run it and give the source file name to convert.
[bash] CHARACTER*133 LINE(6000),FILE1*64,FILE2*64,C
READ (*,'(A64)') FILE1
OPEN(1,FILE=FILE1)
L=LEN_TRIM(FILE1)
FILE2=FILE1(:L-3)//"F90"
OPEN (2,FILE=FILE2,STATUS='REPLACE')
N=1
10 READ (1,'(A132)',END=20) LINE(N)
N=N+1
GO TO 10
20 DO I=N-1,1,-1
L=LEN_TRIM(LINE(I))
IF (L.EQ.0) CYCLE
IF (LINE(I)(1:1).EQ.CHAR(9)) then
LINE(I)(7:)=LINE(I)(2:)
LINE(I)(1:6)=' '
ELSEIF (LINE(I)(2:2).EQ.CHAR(9)) then
LINE(I)(7:)=LINE(I)(3:)
LINE(I)(2:6)=' '
ELSEIF (LINE(I)(3:3).EQ.CHAR(9)) then
LINE(I)(7:)=LINE(I)(4:)
LINE(I)(3:6)=' '
ELSEIF (LINE(I)(4:4).EQ.CHAR(9)) then
LINE(I)(7:)=LINE(I)(5:)
LINE(I)(4:6)=' '
ELSEIF (LINE(I)(5:5).EQ.CHAR(9)) then
LINE(I)(7:)=LINE(I)(6:)
LINE(I)(5:6)=' '
ELSEIF (LINE(I)(6:6).EQ.CHAR(9)) then
LINE(I)(6:6)=' '
ENDIF
IF (LINE(I)(1:1) .EQ. 'C' .OR. LINE(I)(1:1).EQ. '*') THEN
LINE(I)(1:1)='!'
ELSEIF (LINE(I)(6:6) .EQ.CHAR(9)) THEN
LINE(I)(6:6)=' '
ELSEIF (LINE(I)(6:6) .NE.' ') THEN
LINE(I)(6:6)='&'
L=LEN_TRIM(LINE(I-1))
LINE(I-1)(L+1:L+1)='&'
ENDIF
END DO
WRITE(2,'("!DEC$ FREEFORM")')
DO I=1,N-1
K=1
DO WHILE (K.GT.0)
K=INDEX(LINE(I),CHAR(9))
J=MOD(K,4)
IF (K.GT.0) THEN
LINE(I)(K+J+1:)=LINE(I)(K+1:)
LINE(I)(K:K+J)=' '
ENDIF
END DO
L=LEN_TRIM(LINE(I))
IF (L .LE.132) THEN
K=INDEX(LINE(I),'REAL*8')
IF (K.GT.0) LINE(I)(1:L+1)=LINE(I)(1:K-1)//'REAL(8)'//LINE(I)(K+6:L)
K=INDEX(LINE(I),'REAL*4')
IF (K.GT.0) LINE(I)(1:L+1)=LINE(I)(1:K-1)//'REAL(4)'//LINE(I)(K+6:L)
K=INDEX(LINE(I),'INTEGER*4')
IF (K.GT.0) LINE(I)(1:L+1)=LINE(I)(1:K-1)//'INTEGER(4)'//LINE(I)(K+9:L)
K=INDEX(LINE(I),'INTEGER*2')
IF (K.GT.0) LINE(I)(1:L+1)=LINE(I)(1:K-1)//'INTEGER(2)'//LINE(I)(K+9:L)
K=INDEX(LINE(I),'LOGICAL*4')
IF (K.GT.0) LINE(I)(1:L+1)=LINE(I)(1:K-1)//'LOGICAL(4)'//LINE(I)(K+9:L)
K=INDEX(LINE(I),'LOGICAL*2')
IF (K.GT.0) LINE(I)(1:L+1)=LINE(I)(1:K-1)//'LOGICAL(2)'//LINE(I)(K+9:L)
K=INDEX(LINE(I),'LOGICAL*1')
IF (K.GT.0) LINE(I)(1:L+1)=LINE(I)(1:K-1)//'LOGICAL(1)'//LINE(I)(K+9:L)
L=LEN_TRIM(LINE(I))
K=INDEX(LINE(I),'SETCOM.FOR')
IF (K.GT.0) LINE(I)(K:K+9)='SETCOM.F90'
IF (INDEX(LINE(I),'AUTOMATIC')) CYCLE
WRITE(2,'(A)') LINE(I)(1:L)
ELSEIF(LINE(I)(133:133) .EQ. '&') THEN
C=LINE(I)(132:132)
LINE(I)(132:132)='&'
LINE(I+1)(8:)=LINE(I+1)(7:)
LINE(I+1)(7:7)=C
WRITE(2,'(A)') LINE(I)(1:132)
ENDIF
END DO
END[/bash]
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page