crop_vbat.awk

stream discharging battery data crop utility

discharge log
Rev.1.01 (2026-02-17)
Takayuki HOSODA

crop_vbat.awk reads numeric voltage samples from standard input or files and extracts (crops) discharge segments based on monotonic voltage behavior. It is designed as a UNIX-style stream filter that can be composed with small tools.

Synopsis

crop_vbat.awk
  [-v v_start=V]
  [-v v_term=V]
  [-v v_delta=V]
  [-v v_abn=V]
  [-v cont=N]
  [-v myname=NAME]
  [FILE ...]

Description

Input must contain one numeric value per line. Non-numeric lines are rejected and reported to stderr. All computations are done numerically, but output preserves the original text format.

Start and termination of a discharge segment are detected using either delta-based or absolute threshold criteria. Multiple segments can be extracted from one stream when continuation mode is enabled.

Input format

Accepted examples:

+01.234
0.98
3.01E+00
.75
2.
Decimal point must be '.' (no locale conversion).

Segment detection

Start condition (output enabled):

Termination condition (output disabled):

Options

All options are given via awk -v variables.

Integers are exact up to 253 - 1.

Output

Cropped samples are written to stdout unchanged. Diagnostic messages are written to stderr with the program label prefix.

Exit status

EXAMPLES

Extract a voltage column and crop one discharge segment:

cut -f 4 data.tsv | crop_vbat.awk

Use explicit thresholds:

crop_vbat.awk -v v_start=1.25 -v v_term=0.95 log.txt

Allow three discharge segments:

crop_vbat.awk -v cont=3 log.txt

Capacity estimate with fixed interval and load:

cut -f 4 sample1.dat \
| crop_vbat.awk \
| stats.awk -v out=tsv \
| grep sum \
| awk -v r=2.5 -v dt=10 '{print $2 * dt / r / 3600 * 1000}'

Download

Download crop_vbat.awk-1.01.tar.gz — SPDX-License-Identifier: BSD-3-Clause

Hash values

Archive contains SHA256 and MD5 hash files.

SHA256 (crop_vbat.awk) = 25c3aa6c3ff62ad085f3c4cf19bfea486810f7fe6faec62a0429ccb402bd9a7f
MD5 (crop_vbat.awk) = 83c3400f7ca388c1e81f7745bec8cfab

Users can verify the distributed crop_vbat.awk using:

sha256 crop_vbat.awk
md5    crop_vbat.awk

See Also


www.finetune.co.jp [Mail] yokohamaat finetune dotco dotjp © 2000 Takayuki HOSODA.