02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PRINT *, 'Minimum =', user_stats%min<br />

PRINT *, 'Sum =', user_stats%sum<br />

PRINT *, 'Average =', user_stats%avg<br />

END PROGRAM main<br />

SUBROUTINE get_data(data)<br />

! this subroutine stores user-input values and the number<br />

! of values stored in data<br />

! make the definition of raw_data accessible<br />

USE def_assign_stats<br />

TYPE (raw_data) :: data ! the argument<br />

REAL :: val<br />

INTEGER :: i<br />

! get user input<br />

DO i = 1, 100<br />

PRINT *, 'Enter a positive real (negative to quit):'<br />

READ *, val<br />

IF (val < 0.0) EXIT ! negative, so leave<br />

data%x(i) = val<br />

data%n = i ! count of values so far<br />

END DO<br />

END SUBROUTINE get_data<br />

Program units and procedures<br />

Procedure interface<br />

Here are the command lines to compile and execute the program, along with the output from<br />

asamplerun:<br />

$ f90 def_assign.f90<br />

$ a.out<br />

Enter a positive real (negative to quit):<br />

25.5<br />

Enter a positive real (negative to quit):<br />

35.5<br />

Enter a positive real (negative to quit):<br />

45.5<br />

Enter a positive real (negative to quit):<br />

-1<br />

Maximum = 45.5<br />

Minimum = 25.5<br />

Sum = 106.5<br />

Average = 35.5<br />

Chapter 7 157

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!