(length(na.omit(idx_gl))*n/60) has to be
diffs = abs(diff(idx_gl))
mag = sum(diffs, na.rm = TRUE)/
(length(na.omit(diffs))*n/60)
day = rep(data_ip[[2]], 1440/dt0),
Generate sequence of days repeated 1440/dt0, while it has to have each day repeated by 1440/dt0 and followed by the next
ndays = ceiling(as.double(difftime(max(tr), min(tr), units = "days")) + 1) has to be ndays = ceiling(as.double(difftime(max(tr), min(tr), units = "days")))`
grid omits the first measurement of input data and shift timeline -dt0
dti_cum = cumsum(dti) has to be dti_cum = c(0,cumsum(dti))