From fa12d4a6140f14e71fdcc4d90df7482f3124d790 Mon Sep 17 00:00:00 2001
From: Carl Philipp Klemm <philipp@uvos.xyz>
Date: Thu, 16 Nov 2023 13:41:37 +0100
Subject: [PATCH] kissplotcsv: add support for bode plots

---
 kissplotcsv | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 5 deletions(-)

diff --git a/kissplotcsv b/kissplotcsv
index 8e7a7c8..11de28d 100755
--- a/kissplotcsv
+++ b/kissplotcsv
@@ -1,22 +1,63 @@
 #!/bin/bash -e
 
+print_help () {
+	echo "Usage: kisscsvplot -f [filename]"
+}
+
 if ! command -v gnuplot &> /dev/null; then
 	echo "gnuplot is required in \$PATH"
 	exit
 fi
 
-if [[ $# < 1 ]]; then
-	echo "Usage: kisscsvplot [FILE]"
+mode="2:3"
+xLabel='Z_{im}'
+yLabel='Z_{re}'
+logscale=""
+
+while getopts "?rihy:x:f:" opt; do
+	case "$opt" in
+	h|\?)
+		print_help
+		exit 0
+		;;
+	f)
+		file=$OPTARG
+		;;
+	r)
+		mode="1:2"
+		xLabel='Omega'
+		yLabel='Z_{re}'
+		logscale="set logscale x;"
+		;;
+	i)
+		mode="1:3"
+		xLabel='Omega'
+		yLabel='Z_{im}'
+		logscale="set logscale x;"
+	;;
+	y)
+		yLabel=$OPTARG
+	;;
+	x)
+		xLabel=$OPTARG
+	;;
+	esac
+done
+
+if [[ ! -f $file && $file != "-" ]]; then
+	echo "a -f option must be given and it must be a regular file or - for stdin"
+	exit 1
 fi
 
 gnuplot -p -e "\
 set terminal qt enhanced font \",15\" title \"EIS Plot\"; \
 set style line 1 lw 3 lc \"blue\"; \
-set ylabel 'Z_{im}'; \
-set xlabel 'Z_{re}'; \
+set ylabel '$yLabel'; \
+set xlabel '$xLabel'; \
+$logscale \
 set tics font \"Helvetica,12\"; \
 set xlabel font \"Helvetica,15\"; \
 set ylabel font \"Helvetica,15\"; \
 set datafile separator ','; \
-plot '$1' using 2:3 notitle w l ls 3;
+plot '$file' using $mode skip 3 notitle w l;
 "
-- 
GitLab