Combine the current output_buffer sample into accumulator
per time_op.
MEAN and INTEGRAL fold dt-weighted: accumulator += sample · dt.
With fixed dt this matches a count-weighted sum exactly, so
callers running uniform timesteps see no change. With variable
dt it produces the true (1/T) ∫ f dt (MEAN) or ∫ f dt
(INTEGRAL), which a count-weighted scheme would not.
MAX / MIN are dt-independent — the running extremum doesn’t
care about sample weight.
When v%mask is allocated, the sample is multiplied by the
mask weight (broadcast across z) before folding. Cells with
weight = 0 contribute nothing to MEAN / INTEGRAL. For MAX /
MIN, masked cells are taken as -huge / +huge respectively
so they never win — masked output stays at the seed value.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Source Code
subroutine fold_sample(v,dt)!! Combine the current `output_buffer` sample into `accumulator`!! per `time_op`.!!!! MEAN and INTEGRAL fold dt-weighted: `accumulator += sample · dt`.!! With fixed `dt` this matches a count-weighted sum exactly, so!! callers running uniform timesteps see no change. With variable!! `dt` it produces the true `(1/T) ∫ f dt` (MEAN) or `∫ f dt`!! (INTEGRAL), which a count-weighted scheme would not.!!!! MAX / MIN are dt-independent — the running extremum doesn't!! care about sample weight.!!!! When `v%mask` is allocated, the sample is multiplied by the!! mask weight (broadcast across z) before folding. Cells with!! weight = 0 contribute nothing to MEAN / INTEGRAL. For MAX /!! MIN, masked cells are taken as `-huge` / `+huge` respectively!! so they never win — masked output stays at the seed value.type(diag_var_t),intent(inout)::vreal(wp),intent(in)::dtif(.not.allocated(v%accumulator))return if(allocated(v%mask))then call fold_sample_masked_impl(v%accumulator,v%output_buffer,&v%mask%weight,v%mask%nx,v%mask%ny,&dt,v%time_op)else call fold_sample_unmasked_impl(v%accumulator,v%output_buffer,&dt,v%time_op)end ifv%n_accum=v%n_accum+1end subroutine fold_sample