A mean is a sum divided by the number of active observations.

Program

Play the program to change how many values contribute to the mean.

mean_with_count.f90
program mean_with_count_demo
    implicit none
    integer :: values(4)
    integer :: active_count
    integer :: i
    integer :: total
    real :: mean

    values = [4, 6, 11, 15]
    active_count = 
    total = 0
    do i = 1, active_count
        total = total + values(i)
    end do
    mean = real(total) / real(active_count)
    print '(I0, 1X, F0.1)', active_count, mean
end program mean_with_count_demo
program mean_with_count_demo
    implicit none
    integer :: values(4)
    integer :: active_count
    integer :: i
    integer :: total
    real :: mean

    values = [4, 6, 11, 15]
    active_count = 
    total = 0
    do i = 1, active_count
        total = total + values(i)
    end do
    mean = real(total) / real(active_count)
    print '(I0, 1X, F0.1)', active_count, mean
end program mean_with_count_demo
program mean_with_count_demo
    implicit none
    integer :: values(4)
    integer :: active_count
    integer :: i
    integer :: total
    real :: mean

    values = [4, 6, 11, 15]
    active_count = 
    total = 0
    do i = 1, active_count
        total = total + values(i)
    end do
    mean = real(total) / real(active_count)
    print '(I0, 1X, F0.1)', active_count, mean
end program mean_with_count_demo
active count `active_count` controls how much of the fixed array is summarized.
running total The loop adds each active observation into `total`.
real division `real(total) / real(active_count)` keeps the mean as a real number.