I am rewriting for OpenMP usage a large Fortran-77 program and one of the files contains a subroutine in which important variables marked as SAVE are initialized the first time the main program is called, and then they are used when called in the same subroutine via ENTRY points. I decided to replace this file with a long subroutine with a module containing several subroutines (the functionality of which was called through the ENTRY points), and before the CONTAINS statement, list those important variables that are marked SAVE in the source program so that they are available in all modules subroutines calls.
However, I can't get the functionality to work. How else can I rewrite SAVE-ENTRY constructions in subroutine? My minimal main program example:
c elementary program to add two numbers, using
c a module containing important variables and
c two addition functions, one for the case where
c one number is zero and the second for the case
c of non-zero terms
PROGRAM sum0
USE SUMM
INTEGER i,j
WRITE (6,*) 'Enter two numbers: '
READ (5,*) i,j
IF (i .EQ. 0) THEN
CALL sum1(j)
ELSE IF (j .EQ. 0) THEN
CALL sum1(i)
ELSE
CALL sum2(i,j)
ENDIF
END PROGRAM sum0
And module:
MODULE SUMM
IMPLICIT NONE
c "important" variables that had the status SAVE:
REAL B(2,2), K
c initialization via DATA works similarly to SAVE (I think so):
DATA B/1.0,-3.7,4.3,0.0/, K/33.0/
CONTAINS
SUBROUTINE sum2(i1,j1)
INTEGER i1,j1
i1 = i1 + j1
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i1, '.'
END SUBROUTINE sum2
SUBROUTINE sum1(i1)
INTEGER i1
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i1, '.'
END SUBROUTINE sum1
END MODULE SUMM
Original file:
SUBROUTINE SUMM
IMPLICIT REAL*8 (A-H,O-Z)
REAL B(2,2), K
DATA B/1.0,-3.7,4.3,0.0/
SAVE
K = 33.0
RETURN
ENTRY sum2(i,j)
i = i + j
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i, '.'
RETURN
ENTRY sum1(i)
WRITE (6,*) 'The first element of B is', B(1,1), '.'
WRITE (6,*) 'The K is', K, '.'
WRITE (6,*) 'The sum of the numbers is', i, '.'
RETURN
END
Any help is welcome!