Define a module called Simple_Stats which contains encapsulated functions for calculating the mean and standard deviation of an arbitrary length REAL vector. The functions should have the following interfaces:
REAL FUNCTION mean(vec) REAL, INTENT(IN), DIMENSION(:) :: vec END FUNCTION mean REAL FUNCTION Std_Dev(vec) REAL, INTENT(IN), DIMENSION(:) :: vec END FUNCTION Std_Dev
[Hint: In Fortran 90, SIZE(X)
gives the number of elements
in the array X.]
You may like to utilise your earlier code as a basis for this exercise.
Add some more code in the module which records how many times each statistical function is called during the lifetime of a program. Record these numbers in the variables: mean_use and std_dev_use.
Demonstrate the use of this module in a test program; in one execution of the program give the mean and standard deviation of the following sequences of numbers:
5.0 3.0 17.0 -7.56 78.1 99.99 0.8 11.7 33.8 29.6
and
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0
plus two other sequences.
Print out the values of mean_use and std_dev_use for this run of the program.