Go to the documentation of this file.
27 integer,
allocatable :: n(:)
29 real(kind=
dp),
allocatable :: mean(:)
31 real(kind=
dp),
allocatable :: var(:)
37 integer,
allocatable :: n(:, :)
39 real(kind=
dp),
allocatable :: mean(:, :)
41 real(kind=
dp),
allocatable :: var(:, :)
52 type(
stats_t),
intent(inout) :: stats
66 if (
allocated(stats%n))
then
68 deallocate(stats%mean)
82 if (
allocated(stats%n))
then
84 deallocate(stats%mean)
96 type(
stats_t),
intent(inout) :: stats
98 real(kind=
dp),
intent(in) ::
data
100 stats%n = stats%n + 1
113 real(kind=
dp),
intent(in) ::
data(:)
117 if (.not.
allocated(stats%n))
then
118 allocate(stats%n(
size(data)))
119 allocate(stats%mean(
size(data)))
120 allocate(stats%var(
size(data)))
124 call assert_msg(851913829,
size(stats%n) ==
size(data), &
125 "size mismatch between existing n and newly added data")
126 call assert_msg(933021218,
size(stats%mean) ==
size(data), &
127 "size mismatch between existing mean and newly added data")
128 call assert_msg(170092922,
size(stats%var) ==
size(data), &
129 "size mismatch between existing var and newly added data")
130 stats%n = stats%n + 1
145 real(kind=
dp),
intent(in) ::
data
147 integer,
intent(in) :: i
149 call assert_msg(802003511, i >= 1,
"cannot use a non-positive index")
154 stats%n(i) = stats%n(i) + 1
167 real(kind=
dp),
intent(in) ::
data(:, :)
171 if (.not.
allocated(stats%n))
then
172 allocate(stats%n(
size(
data, 1),
size(
data, 2)))
173 allocate(stats%mean(
size(
data, 1),
size(
data, 2)))
174 allocate(stats%var(
size(
data, 1),
size(
data, 2)))
177 call assert_msg(563659350, all(shape(stats%n) == shape(data)), &
178 "size mismatch between existing n and newly added data")
179 call assert_msg(274220601, all(shape(stats%mean) == shape(data)), &
180 "size mismatch between existing mean and newly added data")
181 call assert_msg(939179895, all(shape(stats%var) == shape(data)), &
182 "size mismatch between existing var and newly added data")
184 stats%n = stats%n + 1
185 do i = 1,
size(
data, 1)
186 do j = 1,
size(
data, 2)
202 real(kind=
dp),
intent(in) ::
data(:)
204 integer,
intent(in) :: i
208 call assert_msg(549391523, i >= 1,
"cannot use a non-positive row")
209 if (
allocated(stats%n))
then
210 call assert_msg(286470660,
size(stats%n, 2) ==
size(data), &
211 "size mismatch between existing n and newly added data")
212 call assert_msg(901102174,
size(stats%mean, 2) ==
size(data), &
213 "size mismatch between existing mean and newly added data")
214 call assert_msg(993806885,
size(stats%var, 2) ==
size(data), &
215 "size mismatch between existing var and newly added data")
224 do j = 1,
size(stats%n, 2)
225 stats%n(i, j) = stats%n(i, j) + 1
240 real(kind=
dp),
intent(in) ::
data(:)
242 integer,
intent(in) :: j
246 call assert_msg(944718123, j >= 1,
"cannot use a non-positive column")
247 if (
allocated(stats%n))
then
248 call assert_msg(170275693,
size(stats%n, 1) ==
size(data), &
249 "size mismatch between existing n and newly added data")
250 call assert_msg(659257452,
size(stats%mean, 1) ==
size(data), &
251 "size mismatch between existing mean and newly added data")
252 call assert_msg(279552980,
size(stats%var, 1) ==
size(data), &
253 "size mismatch between existing var and newly added data")
262 do i = 1,
size(stats%n, 1)
263 stats%n(i, j) = stats%n(i, j) + 1
278 real(kind=
dp),
intent(in) ::
data
280 integer,
intent(in) :: i
282 integer,
intent(in) :: j
284 call assert_msg(522548347, (i >= 1) .and. (j >= 1), &
285 "cannot use non-positive indexes")
290 stats%n(i, j) = stats%n(i, j) + 1
302 type(
stats_t),
intent(in) :: stats
326 do i = 1,
size(stats%n)
347 do i = 1,
size(stats%n, 1)
348 do j = 1,
size(stats%n, 2)
458 real(kind=
dp),
intent(inout) :: mean
460 real(kind=
dp),
intent(inout) :: var
462 real(kind=
dp),
intent(in) ::
data
464 integer,
intent(in) :: n
466 real(kind=
dp) :: data_diff
474 data_diff =
data - mean
475 mean = mean + data_diff / real(n, kind=
dp)
476 var = real(n - 2, kind=
dp) / real(n - 1, kind=
dp) * var &
477 + data_diff**2 / real(n, kind=
dp)
513 integer,
intent(in) :: n_sample
515 real(kind=
dp),
parameter :: limit = 1.959963984540054d0
516 real(kind=
dp),
parameter,
dimension(15) :: values &
517 = (/ 12.7062047364d0, 4.30265272991d0, 3.18244630528d0, &
518 2.7764451052d0, 2.57058183661d0, 2.44691184879d0, 2.36462425101d0, &
519 2.30600413503d0, 2.26215716274d0, 2.22813885196d0, 2.20098516008d0, &
520 2.17881282966d0, 2.16036865646d0, 2.14478668792d0, 2.13144954556d0 /)
525 call assert(359779741, n_dof >= 1)
526 if (n_dof <= 15)
then
528 elseif (n_dof <= 20)
then
530 / real(n_dof, kind=
dp) + limit
533 / real(n_dof, kind=
dp) + limit
554 real(kind=
dp),
intent(in) :: var
556 integer,
intent(in) :: n_sample
561 if (n_sample <= 1)
then
567 / sqrt(real(n_sample, kind=
dp))
577 type(
stats_t),
intent(in) :: stats
579 integer,
intent(in) ::
ncid
581 character(len=*),
intent(in) :: name
583 character(len=*),
optional,
intent(in) :: unit
587 trim(name) //
"_ci_offset", unit=unit)
599 integer,
intent(in) :: ncid
601 character(len=*),
intent(in) :: name
603 character(len=*),
optional,
intent(in) :: dim_name
605 character(len=*),
optional,
intent(in) :: unit
610 trim(name) //
"_ci_offset", dim_name=dim_name, unit=unit)
623 integer,
intent(in) :: ncid
625 character(len=*),
intent(in) :: name
627 character(len=*),
optional,
intent(in) :: dim_name_1
629 character(len=*),
optional,
intent(in) :: dim_name_2
631 character(len=*),
optional,
intent(in) :: unit
634 dim_name_2=dim_name_2, unit=unit)
636 trim(name) //
"_ci_offset", dim_name_1=dim_name_1, &
637 dim_name_2=dim_name_2, unit=unit)
655 character(len=*),
intent(in) :: filename
657 real(kind=
dp),
intent(in) :: dim(:)
659 real(kind=
dp),
allocatable ::
data(:,:)
661 if (
size(dim) /=
size(stats%n))
then
663 //
' does not match stats size ' &
667 allocate(
data(
size(stats%n), 3))
669 data(:,2) = stats%mean
subroutine stats_1d_clear(stats)
Clear data statistics collected so far.
subroutine pmc_nc_write_real_1d(ncid, var, name, dimids, dim_name, unit, long_name, standard_name, description)
Write a simple real array to a NetCDF file.
subroutine stats_2d_output_netcdf(stats, ncid, name, dim_name_1, dim_name_2, unit)
Write statistics (mean and 95% conf. int.) to a NetCDF file.
subroutine stats_1d_output_netcdf(stats, ncid, name, dim_name, unit)
Write statistics (mean and 95% conf. int.) to a NetCDF file.
subroutine pmc_nc_write_real_2d(ncid, var, name, dimids, dim_name_1, dim_name_2, unit, long_name, standard_name, description)
Write a simple real 2D array to a NetCDF file.
real(kind=dp) function conf_95_offset(var, n_sample)
95% confidence interval offset from mean.
subroutine die_msg(code, error_msg)
Error immediately.
Wrapper functions for NetCDF. These all take a NetCDF ncid in data mode and return with it again in d...
integer, parameter dp
Kind of a double precision real number.
subroutine ensure_real_array_size(x, n, only_grow)
Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or ...
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
real(kind=dp) function, dimension(size(stats%n, 1), size(stats%n, 2)) stats_2d_conf_95_offset(stats)
Compute the 95% confidence interval offset from the mean.
subroutine stats_2d_add_col(stats, data, j)
Add a column of new data values to a stats_2d_t structure.
subroutine ensure_real_array_2d_size(x, n1, n2, only_grow)
Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or ...
character(len=pmc_util_convert_string_len) function integer_to_string(val)
Convert an integer to a string format.
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
subroutine pmc_nc_write_real(ncid, var, name, unit, long_name, standard_name, description)
Write a single real to a NetCDF file.
subroutine stats_2d_clear(stats)
Clear data statistics collected so far.
subroutine stats_2d_add(stats, data)
Add all new data values to a stats_2d_t structure.
Structure for online computation of 1D arrays of mean and variance.
real(kind=dp) function stats_conf_95_offset(stats)
Compute the 95% confidence interval offset from the mean.
subroutine stats_output_netcdf(stats, ncid, name, unit)
Write statistics (mean and 95% conf. int.) to a NetCDF file.
subroutine ensure_integer_array_2d_size(x, n1, n2, only_grow)
Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or ...
subroutine stats_2d_add_entry(stats, data, i, j)
Add a single new data value to a stats_2d_t structure.
real(kind=dp) function student_t_95_coeff(n_sample)
Return a fairly tight upper-bound on the Student's t coefficient for the 95% confidence interval.
Common utility subroutines.
Structure for online computation of 2D arrays of mean and variance.
subroutine stats_1d_add(stats, data)
Add all new data values to a stats_1d_t structure.
subroutine stats_2d_add_row(stats, data, i)
Add a row of new data values to a stats_2d_t structure.
Structure for online computation of mean and variance.
subroutine stats_clear(stats)
Clear data statistics collected so far.
subroutine update_mean_var(mean, var, data, n)
Compute a running average and variance.
The stats_t type and associated subroutines.
subroutine savetxt_2d(filename, data)
Write a real 2D array to a text file.
real(kind=dp) function, dimension(size(stats%n)) stats_1d_conf_95_offset(stats)
Compute the 95% confidence interval offset from the mean.
subroutine stats_1d_add_entry(stats, data, i)
Add a new single data value to a stats_1d_t structure.
subroutine stats_1d_output_text(stats, filename, dim)
Write statistics (mean and 95% conf. int.) to a text file.
subroutine ensure_integer_array_size(x, n, only_grow)
Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or ...
subroutine stats_add(stats, data)
Add a new data value to a stats_t structure.