#!/bin/sh
#Made by KuLuSz at d17m01y2018
#DC URI calc - DC electronic circuit calculator
#URI - Voltage/Resistance/Amperage
export uri='
2050echo 0U
2050echo 0I
2050echo 0R
2050echo 0P
true
CB
'
RETSTUFF="$(gtkdialog --program=uri --center)"
eval "$RETSTUFF"
if [ "$EXIT" == "uriw" ];then
U=$(echo "$U" | sed 's/,/./')
R=$(echo "$R" | sed 's/,/./')
I=$(echo "$I" | sed 's/,/./')
P=$(echo "$P" | sed 's/,/./')
[ "$(echo "$U" | grep -o 'k$')" == "k" ]&& U=$(echo "scale=4;$(echo $U | cut -f1 -d'k')*1000" | bc -l)
[ "$(echo "$U" | grep -o 'm$')" == "m" ]&& U=$(echo "scale=4;$(echo $U | cut -f1 -d'm')/1000" | bc -l)
[ "$(echo "$R" | grep -o 'k$')" == "k" ]&& R=$(echo "scale=4;$(echo $R | cut -f1 -d'k')*1000" | bc -l)
[ "$(echo "$I" | grep -o 'm$')" == "m" ]&& I=$(echo "scale=4;$(echo $I | cut -f1 -d'm')/1000" | bc -l)
[ "$(echo "$P" | grep -o 'k$')" == "k" ]&& P=$(echo "scale=4;$(echo $P | cut -f1 -d'k')*1000" | bc -l)
[ "$(echo "$P" | grep -o 'm$')" == "m" ]&& P=$(echo "scale=4;$(echo $P | cut -f1 -d'm')/1000" | bc -l)
[ -z "$(echo "$U" | cut -f1 -d'.')" ]&& U=$(echo "0$U")
[ -z "$(echo "$R" | cut -f1 -d'.')" ]&& R=$(echo "0$R")
[ -z "$(echo "$I" | cut -f1 -d'.')" ]&& I=$(echo "0$I")
[ -z "$(echo "$P" | cut -f1 -d'.')" ]&& P=$(echo "0$P")
if [ "$U" != "0" ];then
if [ "$I" != "0" ];then
U2="$U"
R2=$(echo "scale=4;$U/$I" | bc -l)
I2="$I"
P2=$(echo "scale=4;$U*$I" | bc -l)
elif [ "$R" != "0" ];then
U2="$U"
R2="$R"
I2=$(echo "scale=4;$U/$R" | bc -l)
P2=$(echo "scale=4;($U*$U) / $R" | bc -l)
elif [ "$P" != "0" ];then
U2="$U"
R2=$(echo "scale=4;($U*$U)/$P" | bc -l)
I2=$(echo "scale=4;$P/$U" | bc -l)
P2="$P"
fi
fi
if [ "$I" != "0" ];then
if [ "$R" != "0" ];then
U2=$(echo "scale=4;$I*$R" | bc -l)
R2="$R"
I2="$I"
P2=$(echo "scale=4;($I*$I)*$R" | bc -l)
elif [ "$P" != "0" ];then
U2=$(echo "scale=4;$P/$I" | bc -l)
R2=$(echo "scale=4;$P/($I*$I)" | bc -l)
I2="$I"
P2="$P"
fi
fi
if [ "$R" != "0" ];then
if [ "$P" != "0" ];then
U2=$(echo "scale=4;sqrt($P*$R)" | bc -l)
R2="$R"
I2=$(echo "scale=4;sqrt($P/$R)" | bc -l)
P2="$P"
fi
fi
[ -z "$(echo "$U2" | cut -f1 -d'.')" ]&& U2=$(echo "0$U2")
[ -z "$(echo "$R2" | cut -f1 -d'.')" ]&& R2=$(echo "0$R2")
[ -z "$(echo "$I2" | cut -f1 -d'.')" ]&& I2=$(echo "0$I2")
[ -z "$(echo "$P2" | cut -f1 -d'.')" ]&& P2=$(echo "0$P2")
# Mértékegység váltó start
if [ "$CB" == "true" ];then
if [ "$(echo "$U2" | cut -f1 -d'.')" -gt "999" ];then
U2=$(echo "$U2" | cut -f1 -d'.')
U2=$(echo "scale=4;$U2/1000" | bc -l)
U2=$(echo "$U2 k")
fi
if [ "$(echo "$U2" | cut -f1 -d'.')" == "0" ];then
U2=$(echo "scale=4;$U2*1000" | bc -l)
U2=$(echo "$U2 m")
fi
if [ "$(echo "$R2" | cut -f1 -d'.')" -gt "999" ];then
R2=$(echo "$R2" | cut -f1 -d'.')
R2=$(echo "scale=4;$R2/1000" | bc -l)
R2=$(echo "$R2 k")
fi
if [ "$(echo "$I2" | cut -f1 -d'.')" == "0" ];then
I2=$(echo "scale=4;$I2*1000" | bc -l)
I2=$(echo "$I2 m")
fi
if [ "$(echo "$P2" | cut -f1 -d'.')" -gt "999" ];then
P2=$(echo "$P2" | cut -f1 -d'.')
P2=$(echo "scale=4;$P2/1000" | bc -l)
P2=$(echo "$P2 k")
fi
if [ "$(echo "$P2" | cut -f1 -d'.')" == "0" ];then
P2=$(echo "scale=4;$P2*1000" | bc -l)
P2=$(echo "$P2 m")
fi
fi
# Mértékegység váltó end
[ -z "$(echo "$U2" | cut -f1 -d'.')" ]&& U2=$(echo "0$U2")
[ -z "$(echo "$R2" | cut -f1 -d'.')" ]&& R2=$(echo "0$R2")
[ -z "$(echo "$I2" | cut -f1 -d'.')" ]&& I2=$(echo "0$I2")
[ -z "$(echo "$P2" | cut -f1 -d'.')" ]&& P2=$(echo "0$P2")
[ "$U" == "0" ]&& U="-"
[ "$R" == "0" ]&& R="-"
[ "$I" == "0" ]&& I="-"
[ "$P" == "0" ]&& P="-"
U2=$(echo "$U2" | sed 's/\./,/')
R2=$(echo "$R2" | sed 's/\./,/')
I2=$(echo "$I2" | sed 's/\./,/')
P2=$(echo "$P2" | sed 's/\./,/')
export uriw="
"
RETSTUFF2="$(gtkdialog --program=uriw --center)"
eval "$RETSTUFF2"
if [ "$EXIT" == "BACK" ];then
"$0" && exit
else
exit
fi
else
exit
fi