HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Procedure interface
Chapter 7 189
PRINT *, 'Minimum =', user_stats%min
PRINT *, 'Sum =', user_stats%sum
PRINT *, 'Average =', user_stats%avg
END PROGRAM main
SUBROUTINE get_data(data)
! this subroutine stores user-input values and the number
! of values stored in data
! make the definition of raw_data accessible
USE def_assign_stats
TYPE (raw_data) :: data ! the argument
REAL :: val
INTEGER :: i
! get user input
DO i = 1, 100
PRINT *, 'Enter a positive real (negative to quit):'
READ *, val
IF (val < 0.0) EXIT ! negative, so leave
data%x(i) = val
data%n = i ! count of values so far
END DO
END SUBROUTINE get_data
Here are the command lines to compile and execute the program, along with the output from
a sample run:
$ f90 def_assign.f90
$ a.out
Enter a positive real (negative to quit):
25.5
Enter a positive real (negative to quit):
35.5
Enter a positive real (negative to quit):
45.5
Enter a positive real (negative to quit):
-1
Maximum = 45.5
Minimum = 25.5
Sum = 106.5
Average = 35.5