A couple of years ago, I termed the reengineering concept of entombing. This basically takes legacy subprograms and encapsulates the code within a modern framework. The interface block can be very useful in this process, so we will term this interface entombing. Consider the following example of a F77 subroutine. It calculates the average thrust of a rocket engine, given the weight of the rocket, the thrust (F) of the engines, and the velocity (V) of the exhaust gases. Below is the pseudocode for the F77 function SUBACL.
- Compute the mass lost after t seconds: mloss = t (F/−V)
- Compute the net mass remaining after t seconds: mt (remaining) = (W/gravity) − mloss
- Compute the weight at Wt: Wt = mt (remaining) gravity
- Compute the unbalanced force that causes acceleration: Ft=F−Wt
- Compute the acceleration: a = Ft / mt
Here is Fortran 77 function (subacl.for).
REAL FUNCTION SUBACL(RCKTWT,THRUST,VELGAS,TIME)
REAL FUNFOR, FUNACL
FUNFOR(THRUST,VELGAS) = THRUST / (-VELGAS)
FUNACL(FTUNB,MT) = FTUNB/MT
MT = RCKTWT / GRAVTY - FUNFOR(THRUST,VELGAS) * TIME
UBWT = MT * GRAVTY
FTUNB = THRUST - UBWT
SUBACL = FUNACL(FTUNB,MT)
Now we may not want to change anything here, for whatever reason. Note that the variables are all explicitly declared, and the function retains a number of legacy structures. Its functionality could be accessed by a Fortran 95 program which specifies it using an interface block. This basically adds a modern layer of interface between the new program, and the legacy function.
real function subacl(rcktwt,thrust,velgas,time)
real, intent(in) :: rcktwt, thrust, velgas, time
end function subacl
real :: weight, thrust, velgas, time
write(*,*) 'Input data: '
write(*,*) 'Weight of rocket (lbs): '
write(*,*) 'Thrust of the engine (lbs): '
write(*,*) 'Velocity of exhaust gas (ft/sec): '
write(*,*) 'Duration thrust (sec): '
write(*,10) weight, thrust, velgas
10 format(/' ',4x,'Output:' &
/' ',8x,'Weight of rocket:',t42,f10.2,' lbs' &
/' ',8x,'Thrust of engines:',t42,f10.2,' lbs' &
/' ',8x,'Velocity of exhaust:',t42,f10.2,' ft/sec')
12 format(/' ',8x,'Acceleration of the vehicle:',t42,f10.2,' ft/sec*sec')
end program entomb1
Now we can test the program:
Weight of rocket (lbs):
Thrust of the engine (lbs):
Velocity of exhaust gas (ft/sec):
Duration thrust (sec):
Weight of rocket: 10000.00 lbs
Thrust of engines: 80000.00 lbs
Velocity of exhaust: 50000.00 ft/sec
Acceleration of the vehicle: 205.74 ft/sec*sec
Also note how format is used here to format the output (the output of the input is somewhat redundant, but I left it here to show the formatting side of things. Especially make note of the / to imply a line break, and t to tab (to column 42).