Skip to content
Snippets Groups Projects
Select Git revision
  • 6b872992efa8acecb5d53c0677f4d5e370eb9a2f
  • main default protected
  • nour2
  • aleks4
  • geno2
  • petri-net-output
  • nour
  • deep-rl-1
  • geno3
  • paula
  • aleks2
  • aleks3
  • Nour
  • geno
  • aleks
15 results

Dockerfile

Blame
  • kissplotcsv 2.94 KiB
    #!/bin/bash -e
    #
    # eisgenerator - a shared libary and application to generate EIS spectra
    # Copyright (C) 2022-2024 Carl Philipp Klemm <carl@uvos.xyz>
    #
    # This file is part of eisgenerator.
    #
    # eisgenerator is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Lesser General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # eisgenerator is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Lesser General Public License for more details.
    #
    # You should have received a copy of the GNU Lesser General Public License
    # along with eisgenerator.  If not, see <http://www.gnu.org/licenses/>.
    #
    
    print_help () {
    	echo "Usage: kisscsvplot -f [filename]"
    	echo "Options:"
    	echo "	-h:		print this help"
    	echo "	-x:		Set x axis label"
    	echo "	-y:		Set y axis label"
    	echo "	-r:		plot a bode plot of re(Z)"
    	echo "	-i:		plot a bode plot of im(Z)"
    	echo "	-l:		allways use linear scale"
    	echo "	-n:		dont reverse x scale in nyquist plot"
    	echo "	-o:		if this is set instead of an interactive terminal images will be output to this directory"
    }
    
    if ! command -v gnuplot &> /dev/null; then
    	echo "gnuplot is required in \$PATH"
    	exit
    fi
    
    mode="2:3"
    xLabel='Z_{re}'
    yLabel='Z_{im}'
    logscale=""
    reverse="set yrange reverse;"
    plotterminal="set terminal qt enhanced font \",15\" title \"EIS Plot\";"
    
    while getopts "?rihy:x:f:lno:" 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;"
    		reverse=""
    		;;
    	i)
    		mode="1:3"
    		xLabel='Omega'
    		yLabel='Z_{im}'
    		logscale="set logscale x;"
    		reverse=""
    	;;
    	y)
    		yLabel=$OPTARG
    	;;
    	x)
    		xLabel=$OPTARG
    	;;
    	l)
    		logscale=""
    	;;
    	n)
    		reverse=""
    		yLabel="Z_{im}"
    	;;
    	o)
    		if [[ ! -f $file && $file != "-" ]]; then
    			echo "the -f option must be given before -o"
    			exit 1
    		fi
    		outfilename="$OPTARG/$(basename $file).png"
    		if [[ $file == "-" ]]; then
    			outfilename="$OPTARG/stdin.png"
    		fi
    		plotterminal="set term png size 1024,1024; set output \"$outfilename\";"
    		mkdir $OPTARG 2> /dev/null || true
    	;;
    	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
    
    if [[ $file != "-" ]]; then
    	spectra="$(< $file)"
    else
    	spectra="$(< /dev/stdin)"
    fi
    
    header=$(echo "$spectra" | awk -F, 'NR==1{print $1}')
    if [[ $header != "EISF" ]]; then
    	echo "$file is not a valid EIS spectra file!"
    	exit 1
    fi
    
    echo "$spectra" | gnuplot -p -e "\
    $plotterminal \
    set style line 1 lw 3 lc \"blue\"; \
    set ylabel '$yLabel'; \
    set xlabel '$xLabel'; \
    $reverse \
    $logscale \
    set tics font \"Sans,12\"; \
    set xlabel font \"Sans,15\"; \
    set ylabel font \"Sans,15\"; \
    set datafile separator ','; \
    plot '-' using $mode skip 3 notitle w l;
    "