diff --git a/README.md b/README.md index a5a4be4..208697e 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ userR2={ v1, v2, ..., Vm } ; user list of 'm' values @0.1% userR2tol=0.1 ; baseR2 percent tolerance: use 0.1 for 0.1% tolerance userR2desc="user list of 'm' values @0.1% tolerance" ; description max 64 chars ``` -When valTolBest=1 and lists=2 ReSolve will discard values when: +When bestTol=1 and lists=2 ReSolve will discard values when: ``` - series : 10*userR(1%) > userR2(0.1%) - parallel: userR(1%) < 10*userR2(0.1%) @@ -376,8 +376,10 @@ v0.11.09h 2023/10/01 - CLI: new output formatting to show tolerance of each component - CLI: use 80 columns for output formatting - GUI: enlarged to 722 pixels to accomodate 80 cols output formatting + - GUI: support for lists=2 new config: userR2, userR2tol, userR2desc, valTolBest - GUI: new widgets to support lists=2, (in)activate meaning widgets - LIB: extended support to 8 decades, GUI too + - LIB: print with eng/SIprefix notation with mem=0 - GUI: working Stop button - LIB: reduced memory allocation/compute time for input descriptions: baseR[3+2],mem=0,lists2=2,valTolBest=0: 1.7 kB => 840 B , 0.000704 s => 0.000905 s @@ -402,7 +404,21 @@ v0.11.09h 2023/10/01 * Fix: - LIB: fix conversion to eng notation in case: -1000E-09 instead of -1E-06 - LIB: parsing of reSolveConf.txt more robust for duplicates and comments - - GUI: target and decades are not updated on direct type + - GUI: target and decades was not updated on direct type + +v0.11.09h 2023/12/29 +* Added: + - created test cases to check output consistency + - improved (cross-)package creation +* Fix: + - LIB: save position of last single input value to correctly show solutions with 2 resistors + - LIB: save numV in numF to avoid memory leak on lists=2 and bestTol=1 + - LIB: can read userR2 with only one value from config file + - LIB: correctly show tolerance ratio +* Cosmetic + - LIB: refactor showVal4(numBestRes),showVal3(numBestRes) in showVal43(numBestRes, num); + - LIB: refactor showValX(),showValMemLow() functions moving CLI/GUI maxRp==? mem=? inside LIB + - LIB: renamed 'valTolBest' to 'bestTol' in config file ToDo: ----- @@ -410,17 +426,13 @@ ToDo: - LIB: add custom E24 using closest E96 values - LIB: add custom E12 using closest E96 values - LIB: add hybrid Eseries: E48+E24, E96+E24, E192+E24 -- LIB: minValue=10 ; when !=0 skip Eserie values lesser than minValue -- LIB: maxValue=0 ; when !=0 skip Eserie values greather than maxValue +- LIB: maxR=100E3 ; when !=0 skip Eserie/User values greather than maxR +- LIB: minR=10 ; when !=0 skip Eserie/User values smaller than minR +- LIB: separate value below and over the target value +- LIB: print exact results, separated by approximate results - GUI: show values read from reSolveConf.txt userR in engineering notation -- GUI: support for lists=2 new config: userR2, userR2tol, userR2desc, valTolBest -- LIB: print with eng/SIprefix notation with mem=0 -- LIB: refactor showValX() functions moving CLI/GUI mem==? and maxRp==? inside LIB - LIB: numberOfResults=0 with mem=0 meaning all - LIB: use multi-threading to speed-up calculation with multicore CPU/GPU -- LIB: remove duplicated triangular solutions with MaxRp=2 -- LIB: print exact results, separated by approximate results -- LIB: separate value below and over the target value - LIB: support for 0 Ohm value in formula denominator (division by 0) - LIB: add support for variables with an index number. Es. R1, R2 - LIB: add support for variables/letters other than a-b. Autoinit values @@ -439,6 +451,8 @@ Distribution: ------------- In the tar.gz package you will find the sources GNU GPL3 license and binaries compiled for various platforms and operative systems. +For Linux is also provided the cross-distro AppImage file format. $ chmod +x *.AppImage +For MacOS is also provided the DMG disk file As a free software, if you redistribute or modify it, you must redistribute everytime the sources too. @@ -453,22 +467,25 @@ src/exprParser.c expression parser src/reSolveLib.c ReSolve lib implementation src/reSolveCli.c main CLI source src/reSolveGui.c main GUI source -src/Makefile Makefile +src/Makefile Makefile to build on Linux, MinGW/MSYS2 or MacOS src/Makefile32 Makefile to build from Linux64 to Linux32 -src/MakefileX Makefile to cross-build from Linux to Win64 -src/MakefileX32 Makefile to cross-build from Linux to Win32 -src/makeAppDir.sh script use to prepare distribution packages +src/MakefileX Makefile to cross-build from Linux to Win64 with MXE +src/MakefileX32 Makefile to cross-build from Linux to Win32 with MXE +src/makePkg.sh script used to prepare distribution packages src/reSolve.desktop Linux desktop integration file src/ReSolve.png Linux icon file -src/AppRun AppImage run file template +src/ReSolve.ico Windows icon file +src/ReSolve.icns MacOS icon file +src/ReSolve.bundle MacOS packaging file +src/Info.plist MacOS DMG package file reSolveLinux32 CLI binary for Linux/x86 reSolveGuiLinux32 GUI binary for Linux/x86 reSolveLinux64 CLI binary for Linux/amd64 reSolveGuiLinux64 GUI binary for Linux/amd64 -reSolveWin32.exe CLI binary for Win32/x86 -reSolveGuiWin32.exe GUI binary for Win32/x86 -reSolveWin64.exe CLI binary for Win64/amd64 -reSolveGuiWin64.exe GUI binary for Win64/amd64 +reSolveWinMxe32.exe CLI binary for Win32/x86 +reSolveGuiWinMxe32.exe GUI binary for Win32/x86 +reSolveWinMxe64.exe CLI binary for Win64/amd64 +reSolveGuiWinMxe64.exe GUI binary for Win64/amd64 circuit???.png Circuit images with example formula reSolveConf.txt Configuration file reSolve.glade GUI resource XML file diff --git a/reSolveConf.txt b/reSolveConf.txt index a4d32be..8ad6f01 100644 --- a/reSolveConf.txt +++ b/reSolveConf.txt @@ -5,7 +5,7 @@ ; strings are enclosed in "", keep in one line, shorter than 78 chars ; vectors are {} enclosed and comma separated (space and multi lines allowed) ; comments follow ; -; remember that command line arguments take precedence to config values +; remember that command line arguments take precedence to config file values ; -h|--help to see command line syntax expr="1.25*(1+b/a)" ; default formula. Use only 'a' and 'b' as variables @@ -46,4 +46,4 @@ userR2={ 10, 12.1, 14.7, 17.8, 21.5, 26.1, 31.6, 38.3, 46.4, 56.2, 68.1, 82.5, 1 userR2tol=0.1 ; baseR2 percent tolerance: use 0.1 for 0.1% tolerance userR2desc="user list of 77 E48/4 values @0.1%, 10-22M Ohm" ; description max 64 chars -valTolBest=1 ; 0 keep all values, 1 skip: serie 10*R1%>R0.1%, // R1%<10*R0.1% +bestTol=1 ; 0 keep all values, 1 skip: serie 10*R1%>R0.1%, // R1%<10*R0.1% diff --git a/reSolveReadme.txt b/reSolveReadme.txt index a5a4be4..4836fea 100644 --- a/reSolveReadme.txt +++ b/reSolveReadme.txt @@ -75,7 +75,7 @@ userR2={ v1, v2, ..., Vm } ; user list of 'm' values @0.1% userR2tol=0.1 ; baseR2 percent tolerance: use 0.1 for 0.1% tolerance userR2desc="user list of 'm' values @0.1% tolerance" ; description max 64 chars ``` -When valTolBest=1 and lists=2 ReSolve will discard values when: +When bestTol=1 and lists=2 ReSolve will discard values when: ``` - series : 10*userR(1%) > userR2(0.1%) - parallel: userR(1%) < 10*userR2(0.1%) @@ -376,8 +376,10 @@ v0.11.09h 2023/10/01 - CLI: new output formatting to show tolerance of each component - CLI: use 80 columns for output formatting - GUI: enlarged to 722 pixels to accomodate 80 cols output formatting + - GUI: support for lists=2 new config: userR2, userR2tol, userR2desc, valTolBest - GUI: new widgets to support lists=2, (in)activate meaning widgets - LIB: extended support to 8 decades, GUI too + - LIB: print with eng/SIprefix notation with mem=0 - GUI: working Stop button - LIB: reduced memory allocation/compute time for input descriptions: baseR[3+2],mem=0,lists2=2,valTolBest=0: 1.7 kB => 840 B , 0.000704 s => 0.000905 s @@ -402,7 +404,21 @@ v0.11.09h 2023/10/01 * Fix: - LIB: fix conversion to eng notation in case: -1000E-09 instead of -1E-06 - LIB: parsing of reSolveConf.txt more robust for duplicates and comments - - GUI: target and decades are not updated on direct type + - GUI: target and decades was not updated on direct type + +v0.11.09h 2023/12/29 +* Added: + - created test cases to check output consistency + - improved (cross-)package creation +* Fix: + - LIB: save position of last single input value to correctly show solutions with 2 resistors + - LIB: save numV in numF to avoid memory leak on lists=2 and bestTol=1 + - LIB: can read userR2 with only one value from config file + - LIB: correctly show tolerance ratio +* Cosmetic + - LIB: refactor showVal4(numBestRes),showVal3(numBestRes) in showVal43(numBestRes, num); + - LIB: refactor showValX(),showValMemLow() moved CLI/GUI maxRp==? mem=? inside LIB showVal() + - LIB: renamed 'valTolBest' to 'bestTol' in config file ToDo: ----- @@ -410,17 +426,13 @@ ToDo: - LIB: add custom E24 using closest E96 values - LIB: add custom E12 using closest E96 values - LIB: add hybrid Eseries: E48+E24, E96+E24, E192+E24 -- LIB: minValue=10 ; when !=0 skip Eserie values lesser than minValue -- LIB: maxValue=0 ; when !=0 skip Eserie values greather than maxValue +- LIB: maxR=100E3 ; when !=0 skip Eserie/User values greather than maxR +- LIB: minR=10 ; when !=0 skip Eserie/User values smaller than minR +- LIB: separate value below and over the target value +- LIB: print exact results, separated by approximate results - GUI: show values read from reSolveConf.txt userR in engineering notation -- GUI: support for lists=2 new config: userR2, userR2tol, userR2desc, valTolBest -- LIB: print with eng/SIprefix notation with mem=0 -- LIB: refactor showValX() functions moving CLI/GUI mem==? and maxRp==? inside LIB - LIB: numberOfResults=0 with mem=0 meaning all - LIB: use multi-threading to speed-up calculation with multicore CPU/GPU -- LIB: remove duplicated triangular solutions with MaxRp=2 -- LIB: print exact results, separated by approximate results -- LIB: separate value below and over the target value - LIB: support for 0 Ohm value in formula denominator (division by 0) - LIB: add support for variables with an index number. Es. R1, R2 - LIB: add support for variables/letters other than a-b. Autoinit values @@ -439,6 +451,8 @@ Distribution: ------------- In the tar.gz package you will find the sources GNU GPL3 license and binaries compiled for various platforms and operative systems. +For Linux is also provided the cross-distro AppImage file format. $ chmod +x *.AppImage +For MacOS is also provided the DMG disk file As a free software, if you redistribute or modify it, you must redistribute everytime the sources too. @@ -453,22 +467,25 @@ src/exprParser.c expression parser src/reSolveLib.c ReSolve lib implementation src/reSolveCli.c main CLI source src/reSolveGui.c main GUI source -src/Makefile Makefile +src/Makefile Makefile to build on Linux, MinGW/MSYS2 or MacOS src/Makefile32 Makefile to build from Linux64 to Linux32 -src/MakefileX Makefile to cross-build from Linux to Win64 -src/MakefileX32 Makefile to cross-build from Linux to Win32 -src/makeAppDir.sh script use to prepare distribution packages +src/MakefileX Makefile to cross-build from Linux to Win64 with MXE +src/MakefileX32 Makefile to cross-build from Linux to Win32 with MXE +src/makePkg.sh script used to prepare distribution packages src/reSolve.desktop Linux desktop integration file src/ReSolve.png Linux icon file -src/AppRun AppImage run file template +src/ReSolve.ico Windows icon file +src/ReSolve.icns MacOS icon file +src/ReSolve.bundle MacOS packaging file +src/Info.plist MacOS DMG package file reSolveLinux32 CLI binary for Linux/x86 reSolveGuiLinux32 GUI binary for Linux/x86 reSolveLinux64 CLI binary for Linux/amd64 reSolveGuiLinux64 GUI binary for Linux/amd64 -reSolveWin32.exe CLI binary for Win32/x86 -reSolveGuiWin32.exe GUI binary for Win32/x86 -reSolveWin64.exe CLI binary for Win64/amd64 -reSolveGuiWin64.exe GUI binary for Win64/amd64 +reSolveWinMxe32.exe CLI binary for Win32/x86 +reSolveGuiWinMxe32.exe GUI binary for Win32/x86 +reSolveWinMxe64.exe CLI binary for Win64/amd64 +reSolveGuiWinMxe64.exe GUI binary for Win64/amd64 circuit???.png Circuit images with example formula reSolveConf.txt Configuration file reSolve.glade GUI resource XML file diff --git a/src/AppRun b/src/AppRun deleted file mode 100755 index 5d5d340..0000000 --- a/src/AppRun +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -BITS="is32whenLinux32pkgAndRunOnLinux64" -#echo BITS:'$BITS'" -SELF=$(readlink -f "$0") -#echo "SELF:'$SELF'"; echo "" -HERE="${SELF%/*}" -#echo "HERE:'$HERE'"; echo "" -cd ${HERE} - -#export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:"${HERE}"/usr/bin:"${PATH}" -export PATH="${HERE}":"${PATH}" -#echo "PATH:'$PATH'"; echo "" -#export LD_LIBRARY_PATH=/lib64:/usr/lib:/lib:/usr/lib/x86_64-linux-gnu:"${HERE}"/usr/lib:"${LD_LIBRARY_PATH}" -export LD_LIBRARY_PATH="${HERE}"/lib:"${LD_LIBRARY_PATH}" -#echo "LD_LIBRARY_PATH:'$LD_LIBRARY_PATH'"; echo "" - -#export UNION_PRELOAD="${HERE}" -#echo "UNION_PRELOAD:'$UNION_PRELOAD'"; echo "" -#LIBS=:$(find . -type f -name "*.so.*" | tr '\n' ':' | sed 's|:$||g') -#echo "LIBS:'$LIBS'"; echo "" -#export LD_PRELOAD=`echo $LIBS | sed 's|:|:'${HERE}'/|g' | sed 's|/\./|/|g' | sed 's|^:||g'` -#echo "LD_PRELOAD:'$LD_PRELOAD'"; echo "" -#export PKG_CONFIG_PATH="${HERE}"/usr/share/pkgconfig:$PKG_CONFIG_PATH -#EXEC=$(grep -e '^Exec=.*' "${HERE}"/*.desktop | head -n 1 | cut -d "=" -f 2- | sed -e 's| %.||g') -EXEC=reSolveGuiLinux${BITS} -#echo "EXEC:'$EXEC'"; echo "RUN:${HERE}/${EXEC}" -exec ${HERE}/${EXEC} "$@" diff --git a/src/Info.plist b/src/Info.plist index 6828357..e7e8db5 100644 --- a/src/Info.plist +++ b/src/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable reSolveGuiMacOS64 CFBundleGetInfoString - 0.11.09h beta 2023/08/28, Copyright 2023 Valerio Messina + 0.11.09h beta 2023/12/29, Copyright 2023 Valerio Messina CFBundleIconFile ReSolve.icns CFBundleIdentifier @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 0.11.09h beta 2023/08/28 + 0.11.09h beta 2023/12/29 NSHumanReadableCopyright Copyright 2023 Valerio Messina, GNU General Public License. LSMinimumSystemVersion diff --git a/src/Makefile b/src/Makefile index 91f1009..0fcec6a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,100 +1,100 @@ -# Makefile: Copyright 2005-2023 Valerio Messina efa@iol.it -# -# Makefile is part of ReSolve - solve math expressions using discrete values -# ReSolve is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. -# -# ReSolve 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with ReSolve. If not, see . -# -# Makefile to build 'ReSolve' using GCC+GNUtoolchain on Linux -# Linux32=>Linux32, Linux64=>Linux64, MinGw32=>Win32, MinGw64=>Win64, macOS64=>macOS64 -# -# To build for debug use: $ make BUILD=debug debug - -HOST=$(shell uname) -PKG=Linux -ifneq ($(HOST),Darwin) - HOST=$(shell uname -o) -else - # on macOS run make inside $ jhbuild shell - PKG=MacOS -endif -ifeq ($(HOST),Msys) - PKG=Win -endif -BIT := $(shell getconf LONG_BIT) - -BUILD?=release -ifeq ($(BUILD),debug) - COPT=-O1 -g -fsanitize=address -fno-omit-frame-pointer - LOPT=-fsanitize=address -else - COPT=-O3 -endif - -CC=gcc -CFLAGS=-std=gnu11 -Wall $(COPT) -D__USE_MINGW_ANSI_STDIO=1 -PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH -GFLAGS=`pkg-config --cflags gtk+-3.0` -LDFLAGS=$(LOPT) -lm -GLDFLAGS=`pkg-config --libs gtk+-3.0` -TARGET=reSolve$(PKG)$(BIT) -GUI=reSolveGui$(PKG)$(BIT) - -all: $(TARGET) $(GUI) $(TARGET2) - @rm -f *.gch - -$(GUI): fileIo.o exprParser.o reSolveLib.o reSolveGui.o - $(CC) $^ $(LDFLAGS) $(GLDFLAGS) -o $@ - -$(TARGET): fileIo.o exprParser.o reSolveLib.o reSolveCli.o - $(CC) $^ $(LDFLAGS) -o $@ - -fileIo.o: comType.h fileIo.h fileIo.c - -exprParser.o: exprParser.h exprParser.c - -reSolveLib.o: comType.h fileIo.h exprParser.h reSolveLib.h reSolveLib.c - -reSolveCli.o: comType.h fileIo.h exprParser.h reSolveLib.h reSolveCli.c - -reSolveGui.o: comType.h fileIo.h exprParser.h reSolveLib.h reSolveGui.c - $(CC) $(CFLAGS) -c $^ $(GFLAGS) - -strip: -ifeq ($(OS),Windows_NT) # on MINGW strip need .exe - strip $(TARGET).exe $(GUI).exe -else - strip $(TARGET) $(GUI) -endif - -cleanobj: - rm -f *.o - @rm -f *.gch - -cleanbin: - rm -f $(TARGET) $(GUI) - -clean: cleanobj cleanbin - -debug: cleanobj all cleanobj - -bin: all cleanobj strip - -force: clean bin - rm -f *.o - -rel: force - mv $(TARGET) $(GUI) .. - -pkg: rel - @echo "" - @makeAppDir.sh $(PKG) $(BIT) +# Makefile: Copyright 2005-2023 Valerio Messina efa@iol.it +# +# Makefile is part of ReSolve - solve math expressions using discrete values +# ReSolve is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# ReSolve 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ReSolve. If not, see . +# +# Makefile to build 'ReSolve' using GCC+GNUtoolchain on Linux, MinGw on Win, Clang on MacOS +# Linux32=>Linux32, Linux64=>Linux64, MinGw32=>Win32, MinGw64=>Win64, macOS64=>macOS64 +# +# To build for debug use: $ make BUILD=debug debug + +HOST=$(shell uname) +PKG=Linux +ifneq ($(HOST),Darwin) + HOST=$(shell uname -o) +else + # on macOS run make inside $ jhbuild shell + PKG=MacOS +endif +ifeq ($(HOST),Msys) + PKG=WinMgw +endif +BIT := $(shell getconf LONG_BIT) + +BUILD?=release +ifeq ($(BUILD),debug) + COPT=-O1 -g -fsanitize=address -fno-omit-frame-pointer + LOPT=-fsanitize=address +else + COPT=-O3 +endif + +CC=gcc +CFLAGS=-std=gnu11 -Wall $(COPT) -D__USE_MINGW_ANSI_STDIO=1 +PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH +GFLAGS=`pkg-config --cflags gtk+-3.0` +LDFLAGS=$(LOPT) -lm +GLDFLAGS=`pkg-config --libs gtk+-3.0` +TARGET=reSolve$(PKG)$(BIT) +GUI=reSolveGui$(PKG)$(BIT) + +all: $(TARGET) $(GUI) $(TARGET2) + @rm -f *.gch + +$(GUI): fileIo.o exprParser.o reSolveLib.o reSolveGui.o + $(CC) $^ $(LDFLAGS) $(GLDFLAGS) -o $@ + +$(TARGET): fileIo.o exprParser.o reSolveLib.o reSolveCli.o + $(CC) $^ $(LDFLAGS) -o $@ + +fileIo.o: comType.h fileIo.h fileIo.c + +exprParser.o: exprParser.h exprParser.c + +reSolveLib.o: comType.h fileIo.h exprParser.h reSolveLib.h reSolveLib.c + +reSolveCli.o: comType.h fileIo.h exprParser.h reSolveLib.h reSolveCli.c + +reSolveGui.o: comType.h fileIo.h exprParser.h reSolveLib.h reSolveGui.c + $(CC) $(CFLAGS) -c $^ $(GFLAGS) + +strip: +ifeq ($(OS),Windows_NT) # on MINGW strip need .exe + strip $(TARGET).exe $(GUI).exe +else + strip $(TARGET) $(GUI) +endif + +cleanobj: + rm -f *.o + @rm -f *.gch + +cleanbin: + rm -f $(TARGET) $(GUI) + +clean: cleanobj cleanbin + +debug: cleanobj all cleanobj + +bin: all cleanobj strip + +force: clean bin + rm -f *.o + +pkg: + @echo "" + mv $(TARGET) $(GUI) .. + @makePkg.sh $(PKG) $(BIT) + +rel: force pkg diff --git a/src/Makefile32 b/src/Makefile32 index 89e1bd1..3092a59 100644 --- a/src/Makefile32 +++ b/src/Makefile32 @@ -80,9 +80,9 @@ bin: all cleanobj strip force: clean bin rm -f *.o -rel: force +pkg: + @echo "" mv $(TARGET) $(GUI) .. + @makePkg.sh $(PKG) $(BIT) -pkg: rel - @echo "" - @makeAppDir.sh $(PKG) $(BIT) +rel: force pkg diff --git a/src/MakefileX b/src/MakefileX index b5eeb05..4a32b6b 100644 --- a/src/MakefileX +++ b/src/MakefileX @@ -14,13 +14,13 @@ # You should have received a copy of the GNU General Public License # along with ReSolve. If not, see . # -# Makefile to crossbuild 'reSolve' from Linux to Win64 +# Makefile to crossbuild 'reSolve' from Linux to Win64 using MXE # Linux=>Win64 # # To build for debug use: $ make BUILD=debug debug HOST=$(shell uname -o) -PKG=Win +PKG=WinMxe BIT=64 BUILD?=release @@ -82,9 +82,9 @@ bin: all cleanobj strip force: clean bin rm -f *.o -rel: force +pkg: + @echo "" mv $(TARGET) $(GUI) .. + @makePkg.sh $(PKG) $(BIT) -pkg: rel - @echo "" - @makeAppDir.sh $(PKG) $(BIT) +rel: force pkg diff --git a/src/MakefileX32 b/src/MakefileX32 index 34d1e86..6ef674a 100644 --- a/src/MakefileX32 +++ b/src/MakefileX32 @@ -14,13 +14,13 @@ # You should have received a copy of the GNU General Public License # along with ReSolve. If not, see . # -# Makefile to crossbuild 'reSolve' from Linux to Win32 +# Makefile to crossbuild 'reSolve' from Linux to Win32 using MXE # Linux=>Win32 # # To build for debug use: $ make BUILD=debug debug HOST=$(shell uname -o) -PKG=Win +PKG=WinMxe BIT=32 BUILD?=release @@ -82,9 +82,9 @@ bin: all cleanobj strip force: clean bin rm -f *.o -rel: force +pkg: + @echo "" mv $(TARGET) $(GUI) .. + @makePkg.sh $(PKG) $(BIT) -pkg: rel - @echo "" - @makeAppDir.sh $(PKG) $(BIT) +rel: force pkg diff --git a/src/ReSolve.ods b/src/ReSolve.ods new file mode 100644 index 0000000..461b3af Binary files /dev/null and b/src/ReSolve.ods differ diff --git a/src/comType.h b/src/comType.h index 17893d8..127b265 100644 --- a/src/comType.h +++ b/src/comType.h @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2005-2023 Valerio Messina http://users.iol.it/efa */ /* comType.h is part of ReSolve ReSolve is free software: you can redistribute it and/or modify diff --git a/src/exprParser.c b/src/exprParser.c index 0b3ddf3..8d7c646 100644 --- a/src/exprParser.c +++ b/src/exprParser.c @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2005-2023 Valerio Messina http://users.iol.it/efa */ /* exprParser.c is part of ReSolve ReSolve is free software: you can redistribute it and/or modify diff --git a/src/exprParser.h b/src/exprParser.h index a52fef4..9b4d796 100644 --- a/src/exprParser.h +++ b/src/exprParser.h @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2005-2023 Valerio Messina http://users.iol.it/efa */ /* exprParser.h is part of ReSolve ReSolve is free software: you can redistribute it and/or modify diff --git a/src/fileIo.c b/src/fileIo.c index 5e72284..e79da33 100644 --- a/src/fileIo.c +++ b/src/fileIo.c @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2005-2023 Valerio Messina http://users.iol.it/efa */ /* fileIo.c is part of ReSolve ReSolve is free software: you can redistribute it and/or modify @@ -287,6 +287,7 @@ errOk parseConf(char* bufPtr, char* paramPtr, char paramValue[LineLen]) { if (chPtr==NULL) break; //if (dbgLev>=PRINTDEBUG) printNchar(chPtr, 10); } + if (size==0) size=1; // one value, so no comma if (dbgLev>=PRINTDEBUG) printf("size:%u\n", size); double* vectorVal = malloc(size*sizeof(double)); //must be freed by caller chPtr = vectorChr; diff --git a/src/fileIo.h b/src/fileIo.h index 4100346..3cb4389 100644 --- a/src/fileIo.h +++ b/src/fileIo.h @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2005-2023 Valerio Messina http://users.iol.it/efa */ /* fileIo.h is part of ReSolve ReSolve is free software: you can redistribute it and/or modify diff --git a/src/makeAppDir.sh b/src/makeAppDir.sh deleted file mode 100755 index aa15eb2..0000000 --- a/src/makeAppDir.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash -# makeAppDir.sh: this script generate the AppDir for ReSolve. 2023-10-01 -echo "makeAppDir.sh: generating the AppDir for ReSolve ..." -if (test "" = "$1") then - echo "makeAppDir.sh ERROR: need the target platform to create package" - echo "Syntax: $ makeAppDir.sh Linux|Win|MacOS [32|64]" - exit -fi -PKG=$1 -if (test "" = "$2") then - BIT=$(getconf LONG_BIT) -else - BIT=$2 -fi -cp -a ../reSolveReadme.txt ../README.md -CPU=`uname -m` -if (test "$CPU" = "x86_64" && test "$BIT" = "32") then - CPU=i686 -fi -if (test "$PKG" = "Win") then - EXT=".exe" -fi -echo "makeAppDir.sh: generating $PKG $CPU $BIT bit package ..." -ver=`grep SourceVersion reSolveLib.h | cut -d' ' -f3 | tr -d '."'` -date=`date -I` -echo ver:$ver date:$date - -if (test "$PKG" = "MacOS") then - if (test "$BIT" = "32") then - echo "Unsupported 32 bit on MacOS" - exit - fi - gtk-mac-bundler ReSolve.bundle - cd ../.. - AppName=reSolveGuiMacOS64 - ls -l $AppName.app - tar -cf $AppName.app.tgz $AppName.app - wp=0 # write protect - echo "Generating uncompressesd DMG ..." - rm -rf DiskImage - mkdir DiskImage - mv $AppName.app DiskImage - rm $AppName$ver.dmg 2> /dev/null - if (test "$wp" = 1) then - genisoimage -V $AppName -D -r -apple -no-pad -o $AppName$ver.dmg DiskImage - else - genisoimage -V $AppName -D -R -apple -no-pad -o $AppName$ver.dmg DiskImage - fi - rm -rf DiskImage - echo "Compressing DMG ..." - mv $AppName$ver.dmg uncompressed.dmg - dmg uncompressed.dmg $AppName$ver.dmg - rm uncompressed.dmg - echo "$AppName$ver.dmg created." - exit -fi - -rm -rf AppDir -mkdir -p AppDir/usr/bin -rm -rf ReSolve -mkdir -p ReSolve/src -cd .. -cp -a reSolveConf.txt reSolve.glade circuit*.png ReSolve.png src/AppDir/usr/bin -cp -a reSolveConf.txt reSolve.glade circuit*.png ReSolve.png src/ReSolve -cp -a reSolveReadme.txt src/AppDir/usr/bin -cp -a reSolveReadme.txt src/ReSolve -cp -a reSolve${PKG}${BIT}${EXT} src/AppDir/usr/bin/reSolve${PKG}${BIT}${EXT} -cp -a reSolve${PKG}${BIT}${EXT} src/ReSolve/reSolve${PKG}${BIT}${EXT} -cp -a reSolveGui${PKG}${BIT}${EXT} src/AppDir/usr/bin/reSolveGui${PKG}${BIT}${EXT} -cp -a reSolveGui${PKG}${BIT}${EXT} src/ReSolve/reSolveGui${PKG}${BIT}${EXT} -cd src -cp -a *.h *.c Makefile* ReSolve/src -rm ReSolve/src/reSolveLibOld.c ReSolve/src/engStrTst.c 2> /dev/null -cp -aP reSolveConf.txt reSolve.glade circuit*.png ReSolve.png ReSolve/src - -if (test "$PKG" = "Linux" && (test "$CPU" = "x86_64" || test "$CPU" = "i686")) then # skip on ARM&RISC-V - echo "makeAppDir.sh: generating the AppImage for ReSolve (about 2') ..." - if (test -f logWget$date.txt) then { rm logWget$date.txt ; } fi - if (test "$BIT" = "64") then - if (! test -x linuxdeploy-x86_64.AppImage) then - wget -nv "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" 2>> logWget$date.txt - chmod +x linuxdeploy-x86_64.AppImage - fi - if (! test -x linuxdeploy-plugin-gtk.sh) then - wget -nv "https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh" 2>> logWget$date.txt - chmod +x linuxdeploy-plugin-gtk.sh - fi - linuxdeploy-x86_64.AppImage -e ../reSolveGuiLinux64 --appdir AppDir -p gtk -i ReSolve.png -d reSolve.desktop --output appimage > logLinuxdeploy$date.txt - file=reSolve${ver}_${date}_Linux_${CPU}_${BIT}bit.AppImage - mv ReSolveGui-x86_64.AppImage ../$file - cp -a ../$file ../.. - echo "AppImage created: $file" - fi - if (test "$BIT" = "32") then - echo "As now skip AppImage at 32 bit" - fi -fi -if (test "$PKG" = "Linux") then - file=reSolve${ver}_${date}_Linux_${CPU}_${BIT}bit.tgz - echo "Creating package file:'$file' ..." - if (test -f $file) then { rm $file ; } fi - tar -cvaf $file ReSolve - mv $file ../.. - echo "Package file:'$file' done" -fi -if (test "$PKG" = "Win") then - file=reSolve${ver}_${date}_Win_${BIT}bit.7z - echo "Creating package file:'$file' ..." - if (test -f $file) then { rm $file ; } fi - cd ReSolve/src - rm reSolveConf.txt reSolve.glade circuit*.png ReSolve.png # remove links - cd ../.. - 7z a -m0=lzma -mx=9 -r $file ReSolve > /dev/null - mv $file ../.. - echo "Package file:'$file' done" -fi -rm -rf AppDir ReSolve diff --git a/src/makePkg.sh b/src/makePkg.sh new file mode 100755 index 0000000..71cfa24 --- /dev/null +++ b/src/makePkg.sh @@ -0,0 +1,214 @@ +#!/bin/bash +# makePkg.sh: Copyright 2005-2023 Valerio Messina efa@iol.it +# makePkg is part of ReSolve - solve math expressions using discrete values +# ReSolve is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# ReSolve 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ReSolve. If not, see . +# +# Script to generate a Linux|Mingw|MXE|OSX package of 'ReSolve' +# used on: Linux=>bin64, Linux=>bin32, Linux=>macOS64 +# MinGw64=>bin64, MinGw32=>bin32, MXE64=>bin64, MXE32=>bin32 +# +# Syntax: $ makePkg.sh Linux|WinMxe|WinMgw|MacOS [32|64] + +makever=2023-12-29 + +DEPSPATHMGW64="/mingw64/bin" # path of DLLs needed to generate the Mingw64 package +DEPSPATHMGW32="/mingw32/bin" # path of DLLs needed to generate the Mingw32 package +DEPSLISTMGW="" # list of dll for MinGW + +DSTPATH=".." # path where create the Linux|WinMxe|WinMgw|MacOS package directory + +echo "makePkg.sh: create a Linux|WinMxe|WinMgw|MacOS package for ReSolve ..." + +# check for external dependency compliance +flag=0 +for extCmd in 7z cp cut grep mkdir mv rm tar uname ; do + exist=`which $extCmd 2> /dev/null` + if (test "" = "$exist") then + echo "Required external dependency: "\"$extCmd\"" unsatisfied!" + flag=1 + fi +done +if [[ "$flag" = 1 ]]; then + echo "ERROR: Install the required packages and retry. Exit" + exit +fi + +if [[ "$1" = "" || "$1" != "Linux" && "$1" != "WinMxe" && "$1" != "WinMgw" && "$1" != "MacOS" ]]; then + echo "makePkg ERROR: need the target platform to create package" + echo "Syntax: $ makePkg.sh Linux|WinMxe|WinMgw|MacOS [32|64]" + exit +fi + +exist=`which gtk-mac-bundler 2> /dev/null` +if (test "$1" = "MacOS" && test "" = "$exist") then + echo "ERROR: makePkg depend on 'gtk-mac-bundler' to generate for macOS. Exit" + exit +fi + +PKG="$1" +CPU=`uname -m` # i686 or x86_64 +if (test "" = "$2") then + BIT=$(getconf LONG_BIT) +else + BIT="$2" +fi +if (test "$CPU" = "x86_64" && test "$BIT" = "32") then + CPU=i686 +fi +if (test "$PKG" = "WinMxe" || test "$PKG" = "WinMgw") then + EXT=".exe" +fi +OS=`uname` +if (test "$OS" != "Darwin") then + OS=`uname -o` # Msys or GNU/Linux, illegal on macOS +fi +VER=`grep SourceVersion reSolveLib.h | cut -d' ' -f3 | tr -d '."'` +DATE=`date -I` +SRC=`pwd` +TGT=$PKG +if [[ "$OS" = "Msys" ]]; then + if [[ "$BIT" = "64" ]]; then + DEPSRC=$DEPSPATHMGW64 + fi + if [[ "$BIT" = "32" ]]; then + DEPSRC=$DEPSPATHMGW32 + fi +fi +DMG="" +if [[ "$PKG" = "MacOS" ]]; then + DMG="DiskImage/ReSolve.app/Contents/MacOS" +fi +DST="ReSolve${VER}_${DATE}_${TGT}_${CPU}_${BIT}bit" + +if [[ "$OS" != "Msys" && "$OS" != "GNU/Linux" ]]; then + echo "ERROR: work in WinMgw|WinMxe(Linux) only" + exit +fi +if [[ "$OS" = "Msys" && "$PKG" != "WinMgw" ]]; then + echo "ERROR makePkg: Unsupported target package:$PKG on MinGW/MSYS2" + exit +fi + +if [[ "$OS" = "GNU/Linux" && "$PKG" != "Linux" && "$PKG" != "WinMxe" && "$PKG" != "MacOS" ]]; then + echo "ERROR makePkg: Unsupported target package:$PKG on Linux" + exit +fi + +echo "PKG : $PKG" +echo "CPU : $CPU" +echo "BIT : $BIT" +echo "OS : $OS" +echo "VER : $VER" +echo "SRC : $SRC" +echo "TGT : $TGT" +echo "DEP : $DEPSRC" +echo "DST : $DSTPATH/$DST" +echo "DATE: $DATE" +read -p "Proceed? A key to continue" +echo "" + +echo "makePkg: Creating ReSolve $VER package for $CPU $TGT $BIT bit ..." +cp -a ../reSolveReadme.txt ../README.md + +if (test "$PKG" = "MacOS") then + if (test "$BIT" = "32") then + echo "Unsupported 32 bit on MacOS" + exit + fi + gtk-mac-bundler ReSolve.bundle + cd ../.. + AppName=reSolveGuiMacOS64 + ls -l $AppName.app + tar -cf $AppName.app.tgz $AppName.app + wp=0 # write protect + echo "Generating uncompressesd DMG ..." + rm -rf DiskImage + mkdir DiskImage + mv $AppName.app DiskImage + rm $AppName$VER.dmg 2> /dev/null + if (test "$wp" = 1) then + genisoimage -V $AppName -D -r -apple -no-pad -o $AppName$VER.dmg DiskImage + else + genisoimage -V $AppName -D -R -apple -no-pad -o $AppName$VER.dmg DiskImage + fi + rm -rf DiskImage + echo "Compressing DMG ..." + mv $AppName$VER.dmg uncompressed.dmg + dmg uncompressed.dmg $AppName$VER.dmg + rm uncompressed.dmg + echo "$AppName$VER.dmg created." + exit +fi + +rm -rf AppDir +mkdir -p AppDir/usr/bin +rm -rf ReSolve +mkdir -p ReSolve/src +cd .. +cp -a reSolveConf.txt reSolve.glade circuit*.png ReSolve.png src/AppDir/usr/bin +cp -a reSolveConf.txt reSolve.glade circuit*.png ReSolve.png src/ReSolve +cp -a reSolveReadme.txt LICENSE src/AppDir/usr/bin +cp -a reSolveReadme.txt LICENSE src/ReSolve +cp -a reSolve${PKG}${BIT}${EXT} src/AppDir/usr/bin/reSolve${PKG}${BIT}${EXT} +cp -a reSolve${PKG}${BIT}${EXT} src/ReSolve/reSolve${PKG}${BIT}${EXT} +cp -a reSolveGui${PKG}${BIT}${EXT} src/AppDir/usr/bin/reSolveGui${PKG}${BIT}${EXT} +cp -a reSolveGui${PKG}${BIT}${EXT} src/ReSolve/reSolveGui${PKG}${BIT}${EXT} +cd src +cp -a *.h *.c Makefile* ReSolve/src +cp -aP reSolveConf.txt reSolve.glade circuit*.png ReSolve.png ReSolve/src +cp -a makePkg.sh ReSolve.ico ReSolve.icns ReSolve.bundle reSolve.desktop Info.plist ReSolve/src + +if (test "$PKG" = "Linux" && (test "$CPU" = "x86_64" || test "$CPU" = "i686")) then # skip on ARM&RISC-V + echo "makePkg.sh: generating the AppImage for ReSolve (about 2') ..." + if (test -f logWget$DATE.txt) then { rm logWget$DATE.txt ; } fi + if (test "$BIT" = "64") then + if (! test -x linuxdeploy-x86_64.AppImage) then + wget -nv "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" 2>> logWget$DATE.txt + chmod +x linuxdeploy-x86_64.AppImage + fi + if (! test -x linuxdeploy-plugin-gtk.sh) then + wget -nv "https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh" 2>> logWget$DATE.txt + chmod +x linuxdeploy-plugin-gtk.sh + fi + pwd + linuxdeploy-x86_64.AppImage -e ../reSolveGuiLinux64 --appdir AppDir -p gtk -i ReSolve.png -d reSolve.desktop --output appimage > logLinuxdeploy$DATE.txt + file=reSolve${VER}_${DATE}_Linux_${CPU}_${BIT}bit.AppImage + mv ReSolveGui-x86_64.AppImage ../$file + cp -a ../$file ../.. + echo "AppImage created: $file" + fi + if (test "$BIT" = "32") then + echo "As now skip AppImage at 32 bit" + fi +fi +if (test "$PKG" = "Linux") then + file=reSolve${VER}_${DATE}_Linux_${CPU}_${BIT}bit.tgz + echo "Creating package file:'$file' ..." + if (test -f $file) then { rm $file ; } fi + tar -cvaf $file ReSolve + mv $file ../.. + echo "Package file:'$file' done" +fi +if (test "$PKG" = "WinMxe" || test "$PKG" = "WinMgw") then + file=reSolve${VER}_${DATE}_${PKG}_${BIT}bit.7z + echo "Creating package file:'$file' ..." + if (test -f $file) then { rm $file ; } fi + cd ReSolve/src + rm reSolveConf.txt reSolve.glade circuit*.png ReSolve.png # remove links + cd ../.. + 7z a -m0=lzma -mx=9 -r $file ReSolve > /dev/null + mv $file ../.. + echo "Package file:'$file' done" +fi +rm -rf AppDir ReSolve diff --git a/src/reSolveCli.c b/src/reSolveCli.c index 5c64419..b7b2c2f 100644 --- a/src/reSolveCli.c +++ b/src/reSolveCli.c @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2005-2023 Valerio Messina http://users.iol.it/efa */ /* reSolveCli.c is part of ReSolve ReSolve is free software: you can redistribute it and/or modify @@ -151,48 +151,11 @@ int main(int numPar, char* paramPtr[]) { // CLI entry point printf("Compute time: %f s\n", time); // 9 - print results - if (mem==0) { // old memory hungry strategy - gprintf(gui, "Printing best:%u found solutions (top worst, botton best) in all configurations\n\n", numBestRes); - if (maxRp==1) { // no need to showVal4,3,2 ... - gprintf(gui, "Show %u solutions with 2 resistors:\n", numBestRes); - ret = showVal2(numBestRes); // LIB: - } else { - gprintf(gui, "Show %u solutions with up to 4 resistors:\n", numBestRes); - ret = showVal(first); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show %u solutions with 4 resistors:\n", numBestRes); - ret = showVal4(numBestRes); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show %u solutions with 3 resistors:\n", numBestRes); - ret = showVal3(numBestRes); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show %u solutions with 2 resistors:\n", numBestRes); - ret = showVal2(numBestRes); // LIB: - } - } else { // new mem low strategy - gprintf(gui, "Printing best:%u found solutions (top worst, botton best) in all configurations\n\n", numBestRes); - if (maxRp==1) { // no need to showVal4,3,2 ... - gprintf(gui, "Show best:%u solutions with 2 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results2LowPtr); // LIB: - } else { - gprintf(gui, "Show best:%u solutions with up to 4 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, resultsLowPtr); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show best:%u solutions with 4 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results4LowPtr); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show best:%u solutions with 3 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results3LowPtr); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show best:%u solutions with 2 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results2LowPtr); // LIB: - } - } - gprintf(gui, "\n"); + gprintf(gui, "Printing best:%u found solutions (top worst, botton best) in all configurations\n\n", numBestRes); + ret = showVal(numBestRes); // LIB: show Solutions // 10 - freeing dynamic allocated memory ... //printf("Quit...\n"); - memInpCalc(); // if needed restore numV to the allocated value ret = freeMem(); // LIB: free memory if (userR) free(userR); // free mem allocated by fillConfigVars() diff --git a/src/reSolveGui.c b/src/reSolveGui.c index e350f13..68a4413 100644 --- a/src/reSolveGui.c +++ b/src/reSolveGui.c @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2022-2023 Valerio Messina http://users.iol.it/efa */ /* reSolveGui.c is part of ReSolve ReSolve is free software: you can redistribute it and/or modify @@ -475,9 +475,9 @@ static void bestTolWhf(GtkWidget* widgetWhfPtr, gpointer dataPtr) { // called on guint checkVal = gtk_toggle_button_get_active((GtkToggleButton*)widgetWhfPtr); g_print("value:'%u'\n", checkVal); if (checkVal == TRUE) - valTolBest = 1; + bestTol = 1; else - valTolBest = 0; + bestTol = 0; } // bestTolWhf() static void userRtolWhf(GtkWidget* widgetWhfPtr, gpointer dataPtr) { // called on userRtol @@ -779,7 +779,7 @@ static void resultsWhf(GtkWidget* widgetWhfPtr, gpointer dataPtr) { // called on return; } u64 tmpNum = atoi(txtPtr); - u64 tmpMax=(1<<(8*sizeof(numBestRes)))-1; // 65535 + u64 tmpMax=NumberResMax; // 512000U if (tmpNum==0 || tmpNum>tmpMax) { printf("Unsupported:'%s'\n", txtPtr); numBestRes=NumberResDefault; @@ -927,44 +927,8 @@ int runReSolve() { // memSize, memAlloc, doCalc, show output, freeMem // 9 - print results winGuiLoop = 0; // Win loop gtk_events_pending/gtk_main_iteration to update GUI - if (mem==0) { // old memory hungry strategy - gprintf(gui, "Printing best:%u solutions (top worst, botton best) in all configurations\n\n", numBestRes); - if (maxRp==1) { // no need to showVal4,3,2 ... - gprintf(gui, "Show %u solutions with 2 resistors:\n", numBestRes); - ret = showVal2(numBestRes); // LIB: - } else { - gprintf(gui, "Show %u solutions with up to 4 resistors:\n", numBestRes); - ret = showVal(first); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show %u solutions with 4 resistors:\n", numBestRes); - ret = showVal4(numBestRes); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show %u solutions with 3 resistors:\n", numBestRes); - ret = showVal3(numBestRes); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show %u solutions with 2 resistors:\n", numBestRes); - ret = showVal2(numBestRes); // LIB: - } - } else { // new mem low strategy - gprintf(gui, "Printing best:%u solutions (top worst, botton best) in all configurations\n\n", numBestRes); - if (maxRp==1) { // no need to showVal4,3,2 ... - gprintf(gui, "Show best:%u solutions with 2 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results2LowPtr); // LIB: - } else { - gprintf(gui, "Show best:%u solutions with up to 4 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, resultsLowPtr); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show best:%u solutions with 4 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results4LowPtr); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show best:%u solutions with 3 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results3LowPtr); // LIB: - gprintf(gui, "\n"); - gprintf(gui, "Show best:%u solutions with 2 resistors:\n", numBestRes); - ret = showValMemLow(numBestRes, results2LowPtr); // LIB: - } - } - gprintf(gui, "\n"); + gprintf(gui, "Printing best:%u solutions (top worst, botton best) in all configurations\n\n", numBestRes); + ret = showVal(numBestRes); // LIB: show Solutions winGuiLoop = 1; // Win loop gtk_events_pending/gtk_main_iteration to update GUI // 10 - freeing dynamic allocated memory ... @@ -1108,7 +1072,7 @@ int guiUpdateStart() { // update widgets with input/config values at startup } widgetPtr = GTK_WIDGET(gtk_builder_get_object(builderPtr, "valTolBestWdg")); - if (valTolBest==1) { // bestTol checked + if (bestTol==1) { // bestTol checked gtk_toggle_button_set_active((GtkToggleButton*)widgetPtr, TRUE); } else { gtk_toggle_button_set_active((GtkToggleButton*)widgetPtr, FALSE); diff --git a/src/reSolveLib.c b/src/reSolveLib.c index 6d8aee5..2a06a85 100644 --- a/src/reSolveLib.c +++ b/src/reSolveLib.c @@ -1,4 +1,4 @@ -/* ReSolve v0.11.09h 2023/10/01 solve math expressions using discrete values*/ +/* ReSolve v0.11.09h 2023/12/29 solve math expressions using discrete values*/ /* Copyright 2005-2023 Valerio Messina http://users.iol.it/efa */ /* reSolveLib.c is part of ReSolve ReSolve is free software: you can redistribute it and/or modify @@ -32,7 +32,7 @@ u16 numR; // number of values from both user lists OR Eseries*decades //u16 listNumber = ListNumber; // user list quantity u32 numV = NumV; /* number of input possible values (all configurations), need u32 */ u64 totV = TotV; /* number of results values to try, need u64 */ -u16 numBestRes = NumberResDefault; /* number of best results to show */ +u32 numBestRes = NumberResDefault; /* number of best results to show */ char baseE1desc[65] = "standard serie E1 @80% tolerance"; // max 64 chars double baseE1[1] = { 1.0 }; // E1 IEC 60063 @@ -107,6 +107,14 @@ double baseE192[192] = { 1.00, 1.01, 1.02, 1.04, 1.05, 1.06, 1.07, 1.09, // E192 char userRdesc[65]=""; // description: reserve space for 65 chars double* userR; // declare vector pointer, will be a vector of double userR[numR1] +u32 numS; // number of single values, like plv+1 +u32 pfv; // position of first single value +u32 plv; // position of last single value +u32 pfs; // position of first serie +u32 pls; // position of last serie +u32 pfp; // position of first parallel +u32 plp; // position of last parallel +u32 numF; // save calculated numV for memory free u08 lists = 1; // 1 normal, 2 use userR as low precision & userR2 as hi prec double* userR2; // declare vector pointer, will be a vector of double userR2[numR2] @@ -114,9 +122,10 @@ float userRtol; // userR percent tolerance: 0.1, 1, 2, 5, 10, 20, 40 float userR2tol; // userR2 percent tolerance: 0.1, 1, 2, 5, 10, 20, 40 char userR2desc[65]; // description print: reserve space for 65 chars u16 numR2; // number of values in second user list -u32 numT; // number of valid numV values, need u32 -u08 valTolBest; // 0 normal, 1 use userR2 as 1/10 tolerance than userR +u08 bestTol; // 0 normal, 1 use userR2 as 1/10 tolerance than userR float tolRatio; // userR2 to userR tolerance +char tol1str[3]; // userRtol tolerance as strings for showVal() +char tol2str[3]; // userR2tol tolerance as strings for showVal() //char Exx[24]=""; // description for single result when maxRp=2: "Exx serie " char Vdesc[][17] = { "UserList ", // 0 @@ -137,13 +146,11 @@ char Vdesc[][17] = { "UserList ", // 0 "Parallel ", // 15 low + hi tolerance, lists=2 "Parallel ", // 16 hi + hi tolerance, lists=2 }; // Possible type of values -char tol1str[3]; // userRtol tolerance as strings for showVal() -char tol2str[3]; // userR2tol tolerance as strings for showVal() //static struct rValuesTy rValues[numV]; /* allocate memory for single, series & parallel */ -struct rValuesTy* rValues; /* pointer to memory for single, series & parallel rValues[numV] */ +struct rValuesTy* rValues; // pointer to rValues[numV] for single, series & parallel //static struct resultsTy results[totV]; /* allocate memory for results: [(12*7)^2] */ -struct resultsTy* results; /* pointer to memory for results: [(12*7)^2] results[totV] */ +struct resultsTy* results; // pointer to results[totV] for results. Ex.[(12*7)^2] u16 valTy, resTy; // sizeof struct u32 rValueSize; // sizeof vector of struct: rValues[numV] @@ -179,6 +186,7 @@ void chDirBin(char* argList) { // call with chDirBin(argv[0]); cwdPath = malloc(PATH_MAX); cwdPath = getcwd(cwdPath, PATH_MAX); //printf("cwdPath='%s'\n", cwdPath); + free(cwdPath); realpath(argList, absPath); //printf("realpath()='%s'\n", absPath); int len = strlen(absPath); @@ -190,7 +198,6 @@ void chDirBin(char* argList) { // call with chDirBin(argv[0]); } //printf("absPath()='%s'\n", absPath); chdir(absPath); - free(cwdPath); return; } // chDirBin() @@ -383,16 +390,29 @@ int updateRdesc(bit force) { // update userRdesc from baseEdesc return OK; } // int updateRdesc() +void showQty() { // show compute quantities + printf("%s user list numR1:%u @%g%% tolerance\n", __FUNCTION__, numR1, userRtol); + printf("%s user list2 numR2:%u @%g%% tolerance\n", __FUNCTION__, numR2, userR2tol); + printf("%s user lists numR :%u\n", __FUNCTION__, numR); + printf("%s user lists numS :%u\n", __FUNCTION__, numS); + printf("%s user lists numV :%u\n", __FUNCTION__, numV); + printf("%s user lists numF :%u\n", __FUNCTION__, numF); + printf("%s user lists totV :%llu\n", __FUNCTION__, totV); +} // showQty() + +void showInPos() { // show input value positions + printf("position of first Value :%u\n", pfv); + printf("position of last Value :%u\n", plv); + printf("position of first Serie :%u\n", pfs); + printf("position of last Serie :%u\n", pls); + printf("position of first Parallel:%u\n", pfp); + printf("position of last Parallel:%u\n", plp); +} // showInPos() + int globalInit() { // basic initialization //printf("FUNCT: %s\n", __FUNCTION__); - //printf("%s user list numR1:%u @%g%% tolerance\n", __FUNCTION__, numR1, userRtol); - //printf("%s user list2 numR2:%u @%g%% tolerance\n", __FUNCTION__, numR2, userR2tol); - //printf("%s user lists numR :%u\n", __FUNCTION__, numR); + //showQty(); //numR = numR1; - if (lists==2) { // lists=2, imply maxRp=2 and Eserie=0 - maxRp = 2; - Eserie = 0; - } // calculate numR & numV & totV //printf("%s calculate numR & numV & totV\n", __FUNCTION__); if (lists==1) { @@ -412,6 +432,8 @@ int globalInit() { // basic initialization numV=2*numR+numR*numR; /* number of possible values x each position */ } } else { // lists=2, imply maxRp=2 and Eserie=0 + maxRp = 2; + Eserie = 0; numR=numR1+numR2; numV=2*numR+numR*numR; // space for all values } @@ -421,11 +443,8 @@ int globalInit() { // basic initialization totV=((u64)numV)*((u64)numV); /* number of values to try */ } tolRatio = userRtol/userR2tol; // 1/0.1=10 - //printf("%s user list numR1:%u @%g%% tolerance\n", __FUNCTION__, numR1, userRtol); - //printf("%s user list2 numR2:%u @%g%% tolerance\n", __FUNCTION__, numR2, userR2tol); - //printf("%s user lists numR :%u\n", __FUNCTION__, numR); - //printf("%s user lists numV :%u\n", __FUNCTION__, numV); - //printf("%s user lists totV :%llu\n", __FUNCTION__, totV); + //printf("FUNCT: %s\n", __FUNCTION__); + //showQty(); //strcpy(Exx, "E"); //char series[4]; @@ -466,14 +485,13 @@ int showConf() { // show config set //printf("sizeof (results[%lu]):%lu\n", totV, res); if (lists==2) { gprintf(gui, "Custom lists number: %u\n", lists); - gprintf(gui, "Tolerance ratio: %u\n", tolRatio); + gprintf(gui, "Tolerance ratio: %g\n", tolRatio); gprintf(gui, "Keep only values of best tolerance: "); - if (valTolBest) gprintf(gui, "TRUE\n"); + if (bestTol) gprintf(gui, "TRUE\n"); else gprintf(gui, "FALSE\n"); } - //printf("%s user list numR1:%u @%g%% tolerance\n", __FUNCTION__, numR1, userRtol); - //printf("%s user list2 numR2:%u @%g%% tolerance\n", __FUNCTION__, numR2, userR2tol); - //printf("%s user lists numR :%u\n", __FUNCTION__, numR); + //printf("FUNCT: %s\n", __FUNCTION__); + //showQty(); //gprintf(gui, "numR2 :%u\n", numR2); if (Eserie>0) { gprintf(gui, "Resistors serie:E%u, Decades:%u\n", Eserie, decades); @@ -499,7 +517,7 @@ int showConf() { // show config set if (mem==0) // 0 use old memory hungry strategy gprintf(gui, "Using the old memory hungry strategy\n"); else // 1 use new mem low strategy - gprintf(gui, "Using the new memory save strategy\n"); + gprintf(gui, "Using the memory save strategy\n"); //gprintf(gui, "Will allocate a total RAM of %llu B\n", allocatedB); char* stringPtr; stringPtr = siMem(allocatedB); @@ -694,7 +712,7 @@ int fillConfigVars(void) { // load and check users config file } //printf("numberOfResults='%s'\n", paramValue); u64 tmpNum = strtol(paramValue, &endPtr, 10); - u64 tmpMax=(1<<(8*sizeof(numBestRes)))-1; // 65535 + u64 tmpMax=NumberResMax; // 512000U if (endPtr==paramValue) { if (dbgLev>=PRINTERROR) printf("ERROR %s: cannot copy paramValue='%s'\n", __FUNCTION__, paramValue); return ERROR; @@ -853,20 +871,20 @@ int fillConfigVars(void) { // load and check users config file } if (dbgLev>=PRINTDEBUG) printf("userR2desc='%s'\n", userR2desc); - strcpy(paramName, "valTolBest"); + strcpy(paramName, "bestTol"); ret = parseConf (bufferPtr, paramName, paramValue); if (ret!=OK) { if (dbgLev>=PRINTERROR) printf("ERROR %s: cannot find:%s in config file\n", __FUNCTION__, paramName); free(bufferPtr); return ERROR; } - //printf("valTolBest='%s'\n", paramValue); - valTolBest = strtol(paramValue, &endPtr, 10); + //printf("bestTol='%s'\n", paramValue); + bestTol = strtol(paramValue, &endPtr, 10); if (endPtr==paramValue) { - if (dbgLev>=PRINTERROR) printf("ERROR %s: cannot find digits in valTolBest='%s'\n", __FUNCTION__, paramValue); + if (dbgLev>=PRINTERROR) printf("ERROR %s: cannot find digits in bestTol='%s'\n", __FUNCTION__, paramValue); return ERROR; } - if (dbgLev>=PRINTDEBUG) printf("valTolBest=%u\n", valTolBest); + if (dbgLev>=PRINTDEBUG) printf("bestTol=%u\n", bestTol); //dbgLev=PRINTF; //printf("Freeing buffer ...\n"); @@ -932,8 +950,8 @@ int fillConfigVars(void) { // load and check users config file if (dbgLev>=PRINTERROR) printf("ERROR %s: unsupported userR2tol:%g\n", __FUNCTION__, userR2tol); return ERROR; } - if (valTolBest>1) { - if (dbgLev>=PRINTERROR) printf("ERROR %s: unsupported valTolBest:%u\n", __FUNCTION__, valTolBest); + if (bestTol>1) { + if (dbgLev>=PRINTERROR) printf("ERROR %s: unsupported bestTol:%u\n", __FUNCTION__, bestTol); return ERROR; } if (lists==0 || lists>2) { @@ -950,7 +968,7 @@ int fillConfigVars(void) { // load and check users config file } for (u16 p=0; p=PRINTF) printf("%g, ", userR[p]); - if (userR[p]==0) { + if (userR2[p]==0) { if (dbgLev>=PRINTERROR) printf("ERROR %s: value 0 in 'userR2' not allowed\n", __FUNCTION__); return ERROR; } @@ -959,9 +977,8 @@ int fillConfigVars(void) { // load and check users config file } // int fillConfigVars() int memInpCalc() { // memory size calculation for input values - //printf("%s user list numR1:%u @%g%% tolerance\n", __FUNCTION__, numR1, userRtol); - //printf("%s user list2 numR2:%u @%g%% tolerance\n", __FUNCTION__, numR2, userR2tol); - //printf("%s user lists numR :%u\n", __FUNCTION__, numR); + //printf("FUNCT: %s\n", __FUNCTION__); + //showQty(); // 3 - calculate the needed memory valTy = sizeof(struct rValuesTy); rValueSize = numV*valTy; // expected no more than '1536x48=73728' @@ -1171,7 +1188,7 @@ s16 calcEserie(void) { // or fill with the custom list of values when Eserie=0 if (dbgLv>=PRINTDEBUG) printf("rValue:%g\n", val); } } - } else { // custom list of values + } else { // Eserie=0 custom list of values if (lists==1) { //printf("calcEserie numR:%d\n", numR); for (pos=0; pos=PRINTVERBOSE) printf("rValue:%g\n", val); } } + pos--; // so point to last filled position } if (dbgLv>=PRINTDEBUG) printf("calcEserie pos:%d\n", pos); + //printf("calcEserie pos:%d\n", pos); //printf("calcEserie numR:%d\n", numR); - return pos; + //printf("calcEserie numR1:%d\n", numR1); + numS = pos+1; + return pos; // last filled position } // s16 calcEserie(void) void showEserie() { // show all Eserie resistor values printf("Resistor values (Eserie/custom):\n"); - for (u16 pos=0; pos rValues[pos].r, rValues[pos].rp[p], rValues[pos].desc -int calcRvalues(void) { /* when MaxRp=2 also in series and parallel */ +// use pre-calculated [numR] ==> rValues[numV] +int calcRvalues(void) { /* lists=1, when MaxRp=2 also in series and parallel */ u32 pos; double val; u16 rp1, rp2; u08 p; - //printf("calcRvalues numR:%d\n", numR); - //printf("calcRvalues numV:%d\n", numV); - //printf("calcRvalues totV:%lld\n", totV); + //printf("FUNCT: %s\n", __FUNCTION__); + //showQty(); + pfv = 0; // position of first single value /* at first calculate the single values (Eserie) or fill custom values */ pos = calcEserie(); // calculate all standard Exx series values if (pos==ERROR) { @@ -1240,11 +1262,13 @@ int calcRvalues(void) { /* when MaxRp=2 also in series and parallel */ } //printf("numR:%u numV:%u totV:%llu numBestRes:%u\n", numR, numV, totV, numBestRes); if (dbgLv>=PRINTDEBUG) printf("calcRvalues pos:%d\n", pos); + plv = pos; // position of last single value //showEserie(); if (maxRp==2) { // as now support only maxRp=2 resistances per position /* now calculate all series values with 2 resistances per position */ //printf("calcRvalues pos:%d numR:%d\n", pos, numR); - pos = numR; // can be commented + pos++; // first serie, pos = numR; + pfs = pos; // position of fist serie for (rp1=0; rp1=PRINTDEBUG) printf("calcRvalues pos:%d\n", pos); + pls = pos-1; // position of last serie + pfp = pos; // position of first parallel /* now calculate all parallel values with 2 resistances per position */ for (rp1=0; rp1=PRINTDEBUG) printf("calcRvalues pos:%d end\n", pos); + //printf("calcRvalues numV:%d\n", numV); + //showInPos(); + //showRvalues(); + numF=numV; // save calculated numV for memory free if (maxRp>2) { printf("Unsupported maxRp:%u. Supported maxRp 1 or 2\n", maxRp); return ERROR; } - if (dbgLv>=PRINTDEBUG) printf("calcRvalues pos:%d end\n", pos); - //firstSingle =0; - //lastSingle =numR-1; - //firstSeries =numR; - //lastSeries =numR+(numR*numR+numR)/2-1; - //firstParallel = numR+(numR*numR+numR)/2; - //lastParallel =numV-1; // pos - //rValues[ lastSingle:firstSingle ] are single (Exx or custom) - //rValues[ firstSeries:lastSeries ] are series - //rValues[firstParallel:lastParallel] are parallel - numT=pos; - //printf("calcRvalues numT:%d\n", numT); - //showRvalues(); return OK; } // int calcRvalues(void) /* calculate all possible resistive values using 'MaxRp' resistances */ // when lists=2, series: skip when 10*R1%>R0.1%, parallel: skip when 10*R1% rValues[pos].r, rValues[pos].rp[p], rValues[pos].desc -int calcR2values() { // MaxP=2: using userR[]:1%+userR2[]:0.1% and R1%//R0.1% +// use pre-calculated [numR] ==> rValues[numV] +int calcR2values() { // lists=2, bestTol=1: using userR[]:1%+userR2[]:0.1% and R1%//R0.1% // valid only for: lists=2, Eserie=0, maxRp==2 u32 pos; double val, v1, v2; u16 rp1, rp2; u08 p; u08 descIdx; - //printf("calcR2values numR1:%d\n", numR1); - //printf("calcR2values numR2:%d\n", numR2); - //printf("calcR2values numR:%d\n", numR); - //printf("calcR2values numV:%d\n", numV); - //printf("calcR2values totV:%lld\n", totV); - if (Eserie!=0) Eserie = 0; // at first fill custom values - pos = calcEserie(); // calculate all standard Exx series values + //printf("FUNCT: %s\n", __FUNCTION__); + //showQty(); + pfv = 0; // position of first single value + //if (Eserie!=0) Eserie = 0; // at first fill custom values + pos = calcEserie(); // fill with hi precision custom values for lists=2 if (pos==ERROR) { printf("calcEserie returned ERROR\n"); return ERROR; } - //showEserie(); //printf("calcRvalues pos:%d numR2:%d\n", pos, numR2); - pos = numR2; // so will overwrite Custom list1 @1% if (dbgLv>=PRINTDEBUG) printf("calcR2values pos:%d\n", pos); + plv = pos; // position of last single value + //showEserie(); + pos = numR2; // so keep Custom list2 and overwrite Custom list1 @1% + numS = pos; // number of single values + plv = pos-1; // position of last single value after overwrite + pfs = pos; // position of first serie after overwrite // now calculate all series values: R1%+R0.1% for (rp1=0;rp1=numR2) || - (valTolBest==1 && rp1>=numR2 && tolRatio*v1>v2)) { // series: skip when 10*R1%>R0.1% + if ((bestTol==1 && rp2>=numR2) || + (bestTol==1 && rp1>=numR2 && tolRatio*v1>v2)) { // series: skip when 10*R1%>R0.1% //val = 0; v1 = 0; v2 = 0; continue; } //else @@ -1364,6 +1387,8 @@ int calcR2values() { // MaxP=2: using userR[]:1%+userR2[]:0.1% and R1%//R0.1% } } if (dbgLv>=PRINTDEBUG) printf("calcR2values pos:%d\n", pos); + pls = pos-1; // position of last serie + pfp = pos; // position of first parallel // now calculate all parallel values: R1%//R0.1% for (rp1=0;rp1=numR2) || - (valTolBest==1 && rp1>=numR2 && v1=numR2) || + (bestTol==1 && rp1>=numR2 && v1R0.1%%, // R1%%<%u*R0.1%%\n", numV-numT, tolRatio, tolRatio); - numV=numT; // reduce to the real finded values - totV=numV*numV; // reduce to the real finded values + gprintf(gui, "Found %d high precision values\n", pos); + if (bestTol==1) gprintf(gui, "Discarding %u low precision values: skip ++ %g*R1%%>R0.1%%, // R1%%<%g*R0.1%%\n", numV-pos, tolRatio, tolRatio); + numF=numV; // save calculated numV for memory free + numV=pos; // reduce to the real found values + totV=numV*numV; // reduce to the real found values + //printf("calcR2values numV:%d\n", numV); return OK; } // calcR2values() void showRvalues() { // show all input resistor values + //printf("FUNCT: %s\n", __FUNCTION__); + //showQty(); printf("Input values (single, serie, parallel):\n"); - for (u32 pos=0; pos results[totV] int calcFm0values(void) { u32 rc1, rc2; /*float res[maxRc];*/ /* single case, normally 2 resistances */ @@ -1434,21 +1464,23 @@ int calcFm0values(void) { double val; double delta = 0; u32 pos = 0; + //printf("FUNCT: %s\n", __FUNCTION__); + //showInPos(); if (dbgLv>=PRINTDEBUG) printf("numV:%u, totV:%llu\n", numV, totV); if (dbgLv>=PRINTDEBUG) printf("expr:'%s'\n", expr); if (dbgLv>=PRINTF) gprintf(gui, "sol="); // here print something for user feedback (take time) fflush(NULL); // user space stdout flush fsync(1); // kernel space stdout flush - for (rc1=0; rc1=PRINTDEBUG) printf("exprVarsParser[0]:%g\n", exprVarsParser[0]); //printf("rc1:%d 0:%f\n", rc1, exprVarsParser[0]); //if (exprVarsParser[0]==0.) { //printf("rc1:%d skip:%f\n", rc1, exprVarsParser[0]); // continue; //} - for (rc2=0; rc2=PRINTDEBUG) printf("exprVarsParser[1]:%g\n", exprVarsParser[1]); //printf("rc1:%d rc2:%d 0:%f 1:%f\n", rc1, rc2, exprVarsParser[0], exprVarsParser[1]); //if (exprVarsParser[1]==0.) { @@ -1484,11 +1516,6 @@ int calcFm0values(void) { //if (dbgLv>=PRINTF) gprintf(gui, "%u\n", rc1*numV-1); // here print something for user feedback (take time) if (dbgLv>=PRINTF) gprintf(gui, "100%%\n"); // here print something for user feedback (take time) //printf("pos:%u totV:%llu\n", pos, totV); - if (lists==2) { - gprintf(gui, "Found %d high precision solutions\n", pos); - if (totV-pos>0) gprintf(gui, "Discarding %llu solutions: skip + %u*R1%%>R0.1%%, // R1%%<%u*R0.1%%\n", totV-pos, tolRatio, tolRatio); - totV=pos; // reduce to the real finded values - } return OK; } // int calcFm0values(void) @@ -1515,11 +1542,14 @@ bool is_double_le(double a, double b, double epsilon) { } /* calculate best formula results using 'maxRc' resistances: mem=1,lists=1/2 */ +// use rValues[numV] ==> resultsXLow[totV] int calcFm1values(void) { u32 rc1, rc2; u64 per; // percentage progress double val; double delta = 0; + //printf("FUNCT: %s\n", __FUNCTION__); + //showInPos(); if (dbgLv>=PRINTDEBUG) printf("numR:%u, numV:%u, totV:%llu\n", numR, numV, totV); if (dbgLv>=PRINTDEBUG) printf("expr:'%s'\n", expr); w2 = 0; @@ -1541,53 +1571,52 @@ int calcFm1values(void) { if (dbgLv>=PRINTF) gprintf(gui, "sol="); // here print something for user feedback (take time) fflush(NULL); // user space stdout flush fsync(1); // kernel space stdout flush -//printf("\n"); -//printf("numR:%u numV:%u totV:%llu numBestRes:%u\n", numR, numV, totV, numBestRes); -//printf("rValues[numV:%u] results[totV:%llu] results4LowPtr[numBestRes:%u]\n", numV, totV, numBestRes); -//firstSeries =numR; -//lastSeries =numR+(numR*numR+numR)/2-1; -//firstParallel = numR+(numR*numR+numR)/2; -//lastParallel =numV-1; + //printf("\n"); + //printf("numR:%u numV:%u totV:%llu numBestRes:%u\n", numR, numV, totV, numBestRes); + //printf("rValues[numV:%u] results[totV:%llu] results4LowPtr[numBestRes:%u]\n", numV, totV, numBestRes); + //printf("firstSeries =numR :%u\n", numR); if (dbgLv>=PRINTDEBUG) printf("numR:%u, numV:%u, totV:%llu, numBestRes:%u\n", numR, numV, totV, numBestRes); - for (rc1=0; rc1=PRINTDEBUG) printf("exprVarsParser[0]:%g\n", exprVarsParser[0]); - for (rc2=0; rc2=PRINTDEBUG) printf("exprVarsParser[1]:%g\n", exprVarsParser[1]); + //printf("\nexprVarsParser[0]:%g\n", exprVarsParser[0]); + //printf("exprVarsParser[1]:%g\n", exprVarsParser[1]); val = evalExprParser (expr); delta = val - target; //printf("rc1:%u rc2:%u val:%g delta:%g\n", rc1, rc2, val, delta); - if (maxRp==1) { // + if (maxRp==1) { // single value only // if (fabs(delta) <= delta2Worst) { // if (delta2Worst > fabs(delta)) { // if ( definitelyGreaterThan(delta2Worst, fabs(delta), Epsilon )) { //gprintf(gui, "rc1:%d rc2:%d val:%.1f delta:%f delta2Worst:%f, w2:%u\n", rc1, rc2, val, fabs(delta), delta2Worst, w2); - if (is_double_le(fabs(delta), delta2Worst, Epsilon)) { + if (is_double_le(fabs(delta), delta2Worst, Epsilon)) { // this is for 2 resistors //printf("new better result:%f delta:%.4f oldDeltaMin:%.4f\n", val, delta, deltaWorst); - //gprintf(gui, "rc1:%03u rc2:%03u old delta:%f fill at:%d with new delta:%f\n", rc1, rc2, delta2Worst, w2, fabs(delta)); + //gprintf(gui, "rc1:%03u rc2:%03u oldDelta:%.2f fill at:%d with newDelta:%.2f\n", rc1, rc2, delta2Worst, w2, fabs(delta)); results2LowPtr[w2].pos[0] = rc1; // always insert in worst pos results2LowPtr[w2].pos[1] = rc2; // always insert in worst pos results2LowPtr[w2].delta = delta; // always insert in worst pos findWorst(results2LowPtr, &w2, &delta2Worst); // find worst (higher delta) solution } } - if (maxRp==2) { // - if (is_double_le(fabs(delta), deltaWorst, Epsilon)) { + if (maxRp==2) { // single value, series and parallels + if (is_double_le(fabs(delta), deltaWorst, Epsilon)) { // this is for up to 4 resistors //printf("new better result:%f delta:%.4f oldDeltaMax:%.4f\n", val, delta, deltaWorst); - //printf("rc1:%03u rc2:%03u old delta:%f fill at:%d with new delta:%f\n", rc1, rc2, deltaWorst, w, fabs(delta)); + //printf("rc1:%03u rc2:%03u oldDelta:%.2f fill at:%d with newDelta:%.2f\n", rc1, rc2, deltaWorst, w, fabs(delta)); resultsLowPtr[w].pos[0] = rc1; // always insert in worst pos resultsLowPtr[w].pos[1] = rc2; // always insert in worst pos resultsLowPtr[w].delta = delta; // always insert in worst pos findWorst(resultsLowPtr, &w, &deltaWorst); // find worst (higher delta) solution } bool cmp0, cmp1; - if (is_double_le(fabs(delta), delta4Worst, Epsilon)) { - //printf("new better result:%.1f delta:%.4f oldDelta:%.1f\n", val, delta, delta4Worst); - //printf("rc1:%03u rc2:%03u old delta:%.1f fill at:%d with new delta:%.1f\n", rc1, rc2, delta4Worst, w4, fabs(delta)); - if (rc1totV) numBestRes = totV; - first = totV-numBestRes; /* 0 worse, 'first' 1st printed, 'totV' best, numBestRes # of best print */ // 8 - sorting of solutions if (mem==0) { @@ -1799,8 +1834,8 @@ int doCalc() { // fill inputs, calcs, sort solutions return OK; } // int doCalc() -/* print last 'numBestRes = totV-first' results */ -int showVal(u32 first) { // solutions with up to 4 resistors +/* print last 'numBestRes = totV-first' results, mem=0 */ +int showVal2to4(u32 first) { // show Solutions when mem=0 u32 pos; int cmp0, cmp1; u08 descIdx; @@ -1856,95 +1891,24 @@ int showVal(u32 first) { // solutions with up to 4 resistors } } return OK; -} // int showVal(u32 first) +} // int showVal2to4(u32 first) -/* print best 'numBestRes' results */ -int showVal4(u32 numBestRes) { // Solutions with 4 resistors +/* print best 'numBestRes' results, mem=0 */ +int showVal43(u32 numBestRes, u08 numRes) { // Solutions with 4/3 resistors s32 pos, best; - u32 count = 0; int cmp0, cmp1; - u32 res[NumberResMax]; u08 descIdx; char* tol0; char* tol1; - - //printf("numBestRes:%ld NumberResMax:%d\n", numBestRes, NumberResMax); - if (numBestRes>NumberResMax) numBestRes=NumberResMax; - //printf("numBestRes:%ld NumberResMax:%d\n", numBestRes, NumberResMax); - for (pos=totV-1; pos>=0; pos--) { // [totV] is the best solution - /*printf("pos:%9lu", pos);*/ - if (count>=numBestRes) break; // found 'numBestRes' results - //cmp0 = (strcmp(rValues[results[pos].pos[0]].descIdx, "Custom list")!=0) && - // (strcmp(rValues[results[pos].pos[0]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) - if (rValues[results[pos].pos[0]].descIdx<11) cmp0 = 0; else cmp0 = 1; // 0 when single (Exx or custom), 1 when two (series or //) - //cmp1 = (strcmp(rValues[results[pos].pos[1]].descIdx, "Custom list")!=0) && - // (strcmp(rValues[results[pos].pos[1]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) - if (rValues[results[pos].pos[1]].descIdx<11) cmp1 = 0; else cmp1 = 1; // 0 when single (Exx or custom), 1 when two (series or //) - if (cmp0==0 || cmp1==0) continue; // skip when one is 0 (so skip when are less than 4 resistances, do when both are series/parallel) - res[count]=pos; - //printf("showVal4 added pos:%ld\n", pos); - count++; - } - for (best=count-1; best>=0; best--) { // [0] is the best solution - pos = res[best]; - //cmp0 = (strcmp(rValues[results[pos].pos[0]].descIdx, "Custom list")!=0) && - // (strcmp(rValues[results[pos].pos[0]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) - if (rValues[results[pos].pos[0]].descIdx<11) cmp0 = 0; else cmp0 = 1; // 0 when single (Exx or custom), 1 when two (series or //) - //cmp1 = (strcmp(rValues[results[pos].pos[1]].descIdx, "Custom list")!=0) && - // (strcmp(rValues[results[pos].pos[1]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) - if (rValues[results[pos].pos[1]].descIdx<11) cmp1 = 0; else cmp1 = 1; // 0 when single (Exx or custom), 1 when two (series or //) - gprintf(gui, "val:%11G delta:%11.4G", target+results[pos].delta, results[pos].delta); - gprintf(gui, " e%%:%9.2G", results[pos].delta/target*100); - gprintf(gui, " a:%11G b:%11G\n", rValues[results[pos].pos[0]].r, rValues[results[pos].pos[1]].r); - if (maxRp==2) { // maybe a series or parallel value - descIdx = rValues[results[pos].pos[0]].descIdx; - if (cmp0==0) { // single resistors - tol0 = tol1str; - if (descIdx==2) tol0 = tol2str; - gprintf(gui, "a:%-9s:%8G@%2s%% ", Vdesc[rValues[results[pos].pos[0]].descIdx], rValues[results[pos].pos[0]].rp[0], tol0); - } else { // 2 resistors in series or parallel - tol0 = tol1str; - if (descIdx==2 || descIdx==13 || descIdx==16) tol0 = tol2str; - tol1 = tol1str; - if (descIdx==2 || descIdx==12 || descIdx==13 || descIdx==15 || descIdx==16) tol1 = tol2str; - if (descIdx<14) // series - gprintf(gui, "a:%-9s:%8G@%2s%% ++%8G@%2s%% " , Vdesc[rValues[results[pos].pos[0]].descIdx], rValues[results[pos].pos[0]].rp[0], tol0, rValues[results[pos].pos[0]].rp[1], tol1); - else // parallel - gprintf(gui, "a:%-9s:%8G@%2s%% //%8G@%2s%% " , Vdesc[rValues[results[pos].pos[0]].descIdx], rValues[results[pos].pos[0]].rp[0], tol0, rValues[results[pos].pos[0]].rp[1], tol1); - } - descIdx = rValues[results[pos].pos[1]].descIdx; - if (cmp1==0) { // single resistors - tol0 = tol1str; - if (descIdx==2) tol0 = tol2str; - gprintf(gui, "b:%-9s:%8G@%2s%%", Vdesc[rValues[results[pos].pos[1]].descIdx], rValues[results[pos].pos[1]].rp[0], tol0); - } else { // 2 resistors in series or parallel - tol0 = tol1str; - if (descIdx==2 || descIdx==13 || descIdx==16) tol0 = tol2str; - tol1 = tol1str; - if (descIdx==2 || descIdx==12 || descIdx==13 || descIdx==15 || descIdx==16) tol1 = tol2str; - if (descIdx<14) // series - gprintf(gui, "b:%-9s:%8G@%2s%% ++%8G@%2s%%", Vdesc[rValues[results[pos].pos[1]].descIdx], rValues[results[pos].pos[1]].rp[0], tol0, rValues[results[pos].pos[1]].rp[1], tol1); - else // parallel - gprintf(gui, "b:%-9s:%8G@%2s%% //%8G@%2s%%", Vdesc[rValues[results[pos].pos[1]].descIdx], rValues[results[pos].pos[1]].rp[0], tol0, rValues[results[pos].pos[1]].rp[1], tol1); - } - gprintf(gui, "\n"); - } - } - return OK; -} // int showVal4(u32 numBestRes) - -/* print best 'numBestRes' results */ -int showVal3(u32 numBestRes) { // Solutions with 3 resistors - s32 pos, best; u32 count = 0; - int cmp0, cmp1; u32 res[NumberResMax]; - u08 descIdx; - char* tol0; - char* tol1; - if (numBestRes>NumberResMax) numBestRes=NumberResMax; + if (numRes<3 || numRes>4) { + printf("numRes:%hu can be 3 or 4\n", numRes); + return ERROR; + } for (pos=totV-1; pos>=0; pos--) { // [totV] is the best solution + /*printf("pos:%9lu", pos);*/ if (count>=numBestRes) break; // found 'numBestRes' results //cmp0 = (strcmp(rValues[results[pos].pos[0]].descIdx, "Custom list")!=0) && // (strcmp(rValues[results[pos].pos[0]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) @@ -1952,23 +1916,27 @@ int showVal3(u32 numBestRes) { // Solutions with 3 resistors //cmp1 = (strcmp(rValues[results[pos].pos[1]].descIdx, "Custom list")!=0) && // (strcmp(rValues[results[pos].pos[1]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) if (rValues[results[pos].pos[1]].descIdx<11) cmp1 = 0; else cmp1 = 1; // 0 when single (Exx or custom), 1 when two (series or //) - if (cmp0==cmp1) continue; // skip when both 0 or both 1 (both Arb/Exx or both series/parallel, so do when are 3 resistances) + if (numRes==4) if (cmp0==0 || cmp1==0) continue; // skip when one is 0 (so skip when are less than 4 resistances, do when both are series/parallel) + if (numRes==3) if (cmp0==cmp1) continue; // skip when both 0 or both 1 (both User/Exx or both series/parallel, so do when are 3 resistances) res[count]=pos; - //printf("showVal3 added pos:%ld\n", pos); + //printf("%s added pos:%ld\n", __FUNCTION__, pos); count++; } for (best=count-1; best>=0; best--) { // [0] is the best solution pos = res[best]; + //printf("pos:%d results[pos].pos[0]:%u, results[pos].pos[1]:%u\n", pos, results[pos].pos[0], results[pos].pos[1]); + //cmp0 = (strcmp(rValues[results[pos].pos[0]].descIdx, "Custom list")!=0) && // (strcmp(rValues[results[pos].pos[0]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) if (rValues[results[pos].pos[0]].descIdx<11) cmp0 = 0; else cmp0 = 1; // 0 when single (Exx or custom), 1 when two (series or //) //cmp1 = (strcmp(rValues[results[pos].pos[1]].descIdx, "Custom list")!=0) && // (strcmp(rValues[results[pos].pos[1]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) if (rValues[results[pos].pos[1]].descIdx<11) cmp1 = 0; else cmp1 = 1; // 0 when single (Exx or custom), 1 when two (series or //) + gprintf(gui, "val:%11G delta:%11.4G", target+results[pos].delta, results[pos].delta); gprintf(gui, " e%%:%9.2G", results[pos].delta/target*100); gprintf(gui, " a:%11G b:%11G\n", rValues[results[pos].pos[0]].r, rValues[results[pos].pos[1]].r); - if (maxRp==2) { // maybe a series or parallel value + if (maxRp==2) { // maybe a series or parallel value, when maxRp==1 is a repetition of 'a' and 'b' as are User list descIdx = rValues[results[pos].pos[0]].descIdx; if (cmp0==0) { // single resistors tol0 = tol1str; @@ -2003,19 +1971,19 @@ int showVal3(u32 numBestRes) { // Solutions with 3 resistors } } return OK; -} // int showVal3(u32 numBestRes) +} // int showVal43(u32 numBestRes, u08 numRes) -/* print best 'numBestRes' results */ +/* print best 'numBestRes' results, mem=0 */ int showVal2(u32 numBestRes) { // Solutions with 2 resistors s32 pos, best; - u32 count = 0; int cmp0, cmp1; - u32 res[NumberResMax]; u08 descIdx; char* tol0; + u32 count = 0; + u32 res[NumberResMax]; - if (numBestRes>NumberResMax) numBestRes=NumberResMax; for (pos=totV-1; pos>=0; pos--) { // [totV] is the best solution + /*printf("pos:%9lu", pos);*/ if (count>=numBestRes) break; // found 'numBestRes' results //cmp0 = (strcmp(rValues[results[pos].pos[0]].descIdx, "Custom list")!=0) && // (strcmp(rValues[results[pos].pos[0]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) @@ -2025,7 +1993,7 @@ int showVal2(u32 numBestRes) { // Solutions with 2 resistors if (rValues[results[pos].pos[1]].descIdx<11) cmp1 = 0; else cmp1 = 1; // 0 when single (Exx or custom), 1 when two (series or //) if (cmp0!=0 || cmp1!=0) continue; // skip when one is 1 (so skip when are more than 2 resistances, do when both are Exx/custom) res[count]=pos; - //printf("showVal2 added pos:%ld\n", pos); + //printf("%s added pos:%ld\n", __FUNCTION__, pos); count++; } for (best=count-1; best>=0; best--) { // [0] is the best solution @@ -2034,7 +2002,7 @@ int showVal2(u32 numBestRes) { // Solutions with 2 resistors gprintf(gui, "val:%11G delta:%11.4G", target+results[pos].delta, results[pos].delta); gprintf(gui, " e%%:%9.2G", results[pos].delta/target*100); gprintf(gui, " a:%11G b:%11G\n", rValues[results[pos].pos[0]].r, rValues[results[pos].pos[1]].r); - if (maxRp==2) { // when maxRp==1 is a repetition of 'a' and 'b' as are Custom list + if (maxRp==2) { // maybe a series or parallel value, when maxRp==1 is a repetition of 'a' and 'b' as are User list descIdx = rValues[results[pos].pos[0]].descIdx; tol0 = tol1str; if (descIdx==2) tol0 = tol2str; @@ -2049,135 +2017,201 @@ int showVal2(u32 numBestRes) { // Solutions with 2 resistors return OK; } // int showVal2(u32 numBestRes) -/* print best 'numBestRes' LowMem results */ -int showValMemLow(u32 numBestRes, struct resultsTy* resultsNLowPtr) { // Solutions +/* print best 'numBestRes' LowMem results, mem=1 */ +int showValMemLow(u32 numBestRes) { // show Solutions when mem=1 + struct resultsTy* resultsNLowPtr=NULL; u08 descIdx; char* tol0; char* tol1; if (dbgLv>=PRINTDEBUG) gprintf(gui, "numR:%u, numV:%u, totV:%llu, numBestRes:%u\n", numR, numV, totV, numBestRes); - for (int s=0; s= numV || resultsNLowPtr[s].pos[1] >= numV) continue; - //printf("s:%02d delta:%.5f MaxValue/2:%.5f\n", s, resultsNLowPtr[s].delta, MaxValue/2); - //gprintf(gui, "-\n"); - //if (resultsNLowPtr[s].delta>MaxValue/2) continue; - if (dbgLv>=PRINTDEBUG) gprintf(gui, "valid s:%02d resultsNLowPtr[].pos[0]:%03u resultsNLowPtr[].pos[1]:%03u\n", s, resultsNLowPtr[s].pos[0], resultsNLowPtr[s].pos[1]); - if (format==0) { - gprintf(gui, "val:%11G", target+resultsNLowPtr[s].delta); - gprintf(gui, " delta:%11.4G", resultsNLowPtr[s].delta); - gprintf(gui, " e%%:%9.2G", resultsNLowPtr[s].delta/target*100); - gprintf(gui, " a:%11G", rValues[resultsNLowPtr[s].pos[0]].r); - gprintf(gui, " b:%11G\n", rValues[resultsNLowPtr[s].pos[1]].r); - } else { - char* valPtr = engStr(target+resultsNLowPtr[s].delta, 6, false, format-1); - char* deltaPtr = engStr(resultsNLowPtr[s].delta, 4, false, format-1); - char* aPtr = engStr(rValues[resultsNLowPtr[s].pos[0]].r, 6, false, format-1); - char* bPtr = engStr(rValues[resultsNLowPtr[s].pos[1]].r, 6, false, format-1); - gprintf(gui, "val:%11s", valPtr); - gprintf(gui, " delta:%11s", deltaPtr); - gprintf(gui, " e%%:%9.2G", resultsNLowPtr[s].delta/target*100); - gprintf(gui, " a:%11s", aPtr); - gprintf(gui, " b:%11s\n", bPtr); - free(valPtr); - free(deltaPtr); - free(aPtr); - free(bPtr); + for (u08 v=5; v>=2; v--) { // up to 4, 4, 3, 2 resistors + //printf("v:%u\n", v); + if (maxRp==1 && v>2) continue; + if (maxRp==2) { // when maxRp==2 need to showVal4+,4,3 ... + if (v==5) { + gprintf(gui, "Show best:%u solutions with up to 4 resistors:\n", numBestRes); + resultsNLowPtr = resultsLowPtr; + } + if (v==4) { + gprintf(gui, "Show best:%u solutions with 4 resistors:\n", numBestRes); + resultsNLowPtr = results4LowPtr; + } + if (v==3) { + gprintf(gui, "Show best:%u solutions with 3 resistors:\n", numBestRes); + resultsNLowPtr = results3LowPtr; + } } - if (maxRp==2) { // maybe a series or parallel value - int cmp0, cmp1; - //cmp0 = (strcmp(rValues[resultsNLowPtr[s].pos[0]].descIdx, "Custom list")!=0) && - // (strcmp(rValues[resultsNLowPtr[s].pos[0]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) - if (rValues[resultsNLowPtr[s].pos[0]].descIdx<11) cmp0 = 0; else cmp0 = 1; // 0 when single (Exx or custom), 1 when two (series or //) - //cmp1 = (strcmp(rValues[resultsNLowPtr[s].pos[1]].descIdx, "Custom list")!=0) && - // (strcmp(rValues[resultsNLowPtr[s].pos[1]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) - if (rValues[resultsNLowPtr[s].pos[1]].descIdx<11) cmp1 = 0; else cmp1 = 1; // 0 when single (Exx or custom), 1 when two (series or //) - if (dbgLv>=PRINTDEBUG) gprintf(gui, "s:%d cmp0:%d cmp1:%d\n", s, cmp0, cmp1); - descIdx = rValues[resultsNLowPtr[s].pos[0]].descIdx; - if (cmp0==0) { // single resistors - tol0 = tol1str; - if (descIdx==2) tol0 = tol2str; - if (format==0) { // sci format - //gprintf(gui, "a:%-9s:%8G ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0]); - gprintf(gui, "a:%-9s:%8G@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], tol0); - } else { // eng/SIprefix format - char* aPtr = engStr(rValues[resultsNLowPtr[s].pos[0]].rp[0], 6, false, format-1); - gprintf(gui, "a:%-9s:%8s@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], aPtr, tol0); - free(aPtr); + if (v==2) { // when maxRp==1 no need to showVal4+,4,3 ... + gprintf(gui, "Show best:%u solutions with 2 resistors:\n", numBestRes); + resultsNLowPtr = results2LowPtr; + } + for (int s=0; s= numV || resultsNLowPtr[s].pos[1] >= numV) continue; + //printf("s:%02d delta:%.5f MaxValue/2:%.5f\n", s, resultsNLowPtr[s].delta, MaxValue/2); + //gprintf(gui, "-\n"); + //if (resultsNLowPtr[s].delta>MaxValue/2) continue; + if (dbgLv>=PRINTDEBUG) gprintf(gui, "valid s:%02d resultsNLowPtr[].pos[0]:%03u resultsNLowPtr[].pos[1]:%03u\n", s, resultsNLowPtr[s].pos[0], resultsNLowPtr[s].pos[1]); + if (format==0) { + gprintf(gui, "val:%11G", target+resultsNLowPtr[s].delta); + gprintf(gui, " delta:%11.4G", resultsNLowPtr[s].delta); + gprintf(gui, " e%%:%9.2G", resultsNLowPtr[s].delta/target*100); + gprintf(gui, " a:%11G", rValues[resultsNLowPtr[s].pos[0]].r); + gprintf(gui, " b:%11G\n", rValues[resultsNLowPtr[s].pos[1]].r); + } else { + char* valPtr = engStr(target+resultsNLowPtr[s].delta, 6, false, format-1); + char* deltaPtr = engStr(resultsNLowPtr[s].delta, 4, false, format-1); + char* aPtr = engStr(rValues[resultsNLowPtr[s].pos[0]].r, 6, false, format-1); + char* bPtr = engStr(rValues[resultsNLowPtr[s].pos[1]].r, 6, false, format-1); + gprintf(gui, "val:%11s", valPtr); + gprintf(gui, " delta:%11s", deltaPtr); + gprintf(gui, " e%%:%9.2G", resultsNLowPtr[s].delta/target*100); + gprintf(gui, " a:%11s", aPtr); + gprintf(gui, " b:%11s\n", bPtr); + free(valPtr); + free(deltaPtr); + free(aPtr); + free(bPtr); + } + if (maxRp==2) { // maybe a series or parallel value + int cmp0, cmp1; + //cmp0 = (strcmp(rValues[resultsNLowPtr[s].pos[0]].descIdx, "Custom list")!=0) && + // (strcmp(rValues[resultsNLowPtr[s].pos[0]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) + if (rValues[resultsNLowPtr[s].pos[0]].descIdx<11) cmp0 = 0; else cmp0 = 1; // 0 when single (Exx or custom), 1 when two (series or //) + //cmp1 = (strcmp(rValues[resultsNLowPtr[s].pos[1]].descIdx, "Custom list")!=0) && + // (strcmp(rValues[resultsNLowPtr[s].pos[1]].descIdx, Exx )!=0); // 0 when single (Exx or custom), 1 when two (series or //) + if (rValues[resultsNLowPtr[s].pos[1]].descIdx<11) cmp1 = 0; else cmp1 = 1; // 0 when single (Exx or custom), 1 when two (series or //) + if (dbgLv>=PRINTDEBUG) gprintf(gui, "s:%d cmp0:%d cmp1:%d\n", s, cmp0, cmp1); + descIdx = rValues[resultsNLowPtr[s].pos[0]].descIdx; + if (cmp0==0) { // single resistors + tol0 = tol1str; + if (descIdx==2) tol0 = tol2str; + if (format==0) { // sci format + //gprintf(gui, "a:%-9s:%8G ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0]); + gprintf(gui, "a:%-9s:%8G@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], tol0); + } else { // eng/SIprefix format + char* aPtr = engStr(rValues[resultsNLowPtr[s].pos[0]].rp[0], 6, false, format-1); + gprintf(gui, "a:%-9s:%8s@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], aPtr, tol0); + free(aPtr); + } + } else { // 2 resistors in series or parallel + tol0 = tol1str; + if (descIdx==2 || descIdx==13 || descIdx==16) tol0 = tol2str; + tol1 = tol1str; + if (descIdx==2 || descIdx==12 || descIdx==13 || descIdx==15 || descIdx==16) tol1 = tol2str; + if (format==0) { // sci format + //gprintf(gui, "a:%-9s:%8G & %8G " , Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], rValues[resultsNLowPtr[s].pos[0]].rp[1]); + if (descIdx<14) // series + gprintf(gui, "a:%-9s:%8G@%2s%% ++%8G@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[0]].rp[1], tol1); + else // parallel + gprintf(gui, "a:%-9s:%8G@%2s%% //%8G@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[0]].rp[1], tol1); + } else { // eng/SIprefix format + char* a0Ptr = engStr(rValues[resultsNLowPtr[s].pos[0]].rp[0], 6, false, format-1); + char* a1Ptr = engStr(rValues[resultsNLowPtr[s].pos[0]].rp[1], 6, false, format-1); + if (descIdx<14) // series + gprintf(gui, "a:%-9s:%8s@%2s%% ++%8s@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], a0Ptr, tol0, a1Ptr, tol1); + else // parallel + gprintf(gui, "a:%-9s:%8s@%2s%% //%8s@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], a0Ptr, tol0, a1Ptr, tol1); + free(a0Ptr); + free(a1Ptr); + } } - } else { // 2 resistors in series or parallel - tol0 = tol1str; - if (descIdx==2 || descIdx==13 || descIdx==16) tol0 = tol2str; - tol1 = tol1str; - if (descIdx==2 || descIdx==12 || descIdx==13 || descIdx==15 || descIdx==16) tol1 = tol2str; - if (format==0) { // sci format - //gprintf(gui, "a:%-9s:%8G & %8G " , Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], rValues[resultsNLowPtr[s].pos[0]].rp[1]); - if (descIdx<14) // series - gprintf(gui, "a:%-9s:%8G@%2s%% ++%8G@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[0]].rp[1], tol1); - else // parallel - gprintf(gui, "a:%-9s:%8G@%2s%% //%8G@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], rValues[resultsNLowPtr[s].pos[0]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[0]].rp[1], tol1); - } else { // eng/SIprefix format - char* a0Ptr = engStr(rValues[resultsNLowPtr[s].pos[0]].rp[0], 6, false, format-1); - char* a1Ptr = engStr(rValues[resultsNLowPtr[s].pos[0]].rp[1], 6, false, format-1); - if (descIdx<14) // series - gprintf(gui, "a:%-9s:%8s@%2s%% ++%8s@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], a0Ptr, tol0, a1Ptr, tol1); - else // parallel - gprintf(gui, "a:%-9s:%8s@%2s%% //%8s@%2s%% ", Vdesc[rValues[resultsNLowPtr[s].pos[0]].descIdx], a0Ptr, tol0, a1Ptr, tol1); - free(a0Ptr); - free(a1Ptr); + descIdx = rValues[resultsNLowPtr[s].pos[1]].descIdx; + if (cmp1==0) { // single resistors + tol0 = tol1str; + if (descIdx==2) tol0 = tol2str; + if (format==0) { // sci format + //gprintf(gui, "b:%-9s:%8G" , Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0]); + gprintf(gui, "b:%-9s:%8G@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], tol0); + } else { // eng/SIprefix format + char* bPtr = engStr(rValues[resultsNLowPtr[s].pos[1]].rp[0], 6, false, format-1); + gprintf(gui, "b:%-9s:%8s@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], bPtr, tol0); + free(bPtr); + } + } else { // 2 resistors in series or parallel + tol0 = tol1str; + if (descIdx==2 || descIdx==13 || descIdx==16) tol0 = tol2str; + tol1 = tol1str; + if (descIdx==2 || descIdx==12 || descIdx==13 || descIdx==15 || descIdx==16) tol1 = tol2str; + if (format==0) { // sci format + //gprintf(gui, "b:%-9s:%8G & %8G ", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], rValues[resultsNLowPtr[s].pos[1]].rp[1]); + if (descIdx<14) // series + gprintf(gui, "b:%-9s:%8G@%2s%% ++%8G@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[1]].rp[1], tol1); + else // parallel + gprintf(gui, "b:%-9s:%8G@%2s%% //%8G@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[1]].rp[1], tol1); + } else { // eng/SIprefix format + char* b0Ptr = engStr(rValues[resultsNLowPtr[s].pos[1]].rp[0], 6, false, format-1); + char* b1Ptr = engStr(rValues[resultsNLowPtr[s].pos[1]].rp[1], 6, false, format-1); + if (descIdx<14) // series + gprintf(gui, "b:%-9s:%8s@%2s%% ++%8s@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], b0Ptr, tol0, b1Ptr, tol1); + else // parallel + gprintf(gui, "b:%-9s:%8s@%2s%% //%8s@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], b0Ptr, tol0, b1Ptr, tol1); + free(b0Ptr); + free(b1Ptr); + } + } // single or serie/parallel + gprintf(gui, "\n"); + } // maxRp=2 maybe a series or parallel value + } // for each bestRes + gprintf(gui, "\n"); + } // up to 4, 4, 3, 2 resistors + return OK; +} // int showValMemLow(u32 numBestRes) + +/* print last 'numBestRes = totV-first' results */ +int showVal(u32 numBestRes) { // show Solutions + int ret = OK; + + //printf("numBestRes:%ld NumberResMax:%d\n", numBestRes, NumberResMax); + if (numBestRes>NumberResMax) numBestRes=NumberResMax; + //printf("numBestRes:%ld NumberResMax:%d\n", numBestRes, NumberResMax); + first = totV-numBestRes; /* 0 worse, 'first' 1st printed, 'totV' best, numBestRes # of best print */ + //printf("totV:%llu numBestRes:%u first:%u\n", totV, numBestRes, first); + + if (mem==0) { + for (u08 v=5; v>=2; v--) { // up to 4, 4, 3, 2 resistors + //printf("v:%u\n", v); + if (maxRp==1 && v>2) continue; + if (maxRp==2) { // when maxRp==2 need to showVal4+,4,3 ... + if (v==5) { + gprintf(gui, "Show %u solutions with up to 4 resistors:\n", numBestRes); + ret = showVal2to4(first); } - } - descIdx = rValues[resultsNLowPtr[s].pos[1]].descIdx; - if (cmp1==0) { // single resistors - tol0 = tol1str; - if (descIdx==2) tol0 = tol2str; - if (format==0) { // sci format - //gprintf(gui, "b:%-9s:%8G" , Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0]); - gprintf(gui, "b:%-9s:%8G@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], tol0); - } else { // eng/SIprefix format - char* bPtr = engStr(rValues[resultsNLowPtr[s].pos[1]].rp[0], 6, false, format-1); - gprintf(gui, "b:%-9s:%8s@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], bPtr, tol0); - free(bPtr); + if (v==4) { + gprintf(gui, "Show %u solutions with 4 resistors:\n", numBestRes); + ret = showVal43(numBestRes, 4); } - } else { // 2 resistors in series or parallel - tol0 = tol1str; - if (descIdx==2 || descIdx==13 || descIdx==16) tol0 = tol2str; - tol1 = tol1str; - if (descIdx==2 || descIdx==12 || descIdx==13 || descIdx==15 || descIdx==16) tol1 = tol2str; - if (format==0) { // sci format - //gprintf(gui, "b:%-9s:%8G & %8G ", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], rValues[resultsNLowPtr[s].pos[1]].rp[1]); - if (descIdx<14) // series - gprintf(gui, "b:%-9s:%8G@%2s%% ++%8G@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[1]].rp[1], tol1); - else // parallel - gprintf(gui, "b:%-9s:%8G@%2s%% //%8G@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], rValues[resultsNLowPtr[s].pos[1]].rp[0], tol0, rValues[resultsNLowPtr[s].pos[1]].rp[1], tol1); - } else { // eng/SIprefix format - char* b0Ptr = engStr(rValues[resultsNLowPtr[s].pos[1]].rp[0], 6, false, format-1); - char* b1Ptr = engStr(rValues[resultsNLowPtr[s].pos[1]].rp[1], 6, false, format-1); - if (descIdx<14) // series - gprintf(gui, "b:%-9s:%8s@%2s%% ++%8s@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], b0Ptr, tol0, b1Ptr, tol1); - else // parallel - gprintf(gui, "b:%-9s:%8s@%2s%% //%8s@%2s%%", Vdesc[rValues[resultsNLowPtr[s].pos[1]].descIdx], b0Ptr, tol0, b1Ptr, tol1); - free(b0Ptr); - free(b1Ptr); + if (v==3) { + gprintf(gui, "Show %u solutions with 3 resistors:\n", numBestRes); + ret = showVal43(numBestRes, 3); } } + if (v==2) { // when maxRp==1 no need to showVal4+,4,3 ... + gprintf(gui, "Show %u solutions with 2 resistors:\n", numBestRes); + ret = showVal2(numBestRes); + } gprintf(gui, "\n"); - } + } // up to 4, 4, 3, 2 resistors + } else { // mem=1 + ret = showValMemLow(numBestRes); // show Solutions when mem=1 } - return OK; -} // int showValMemLow(u32 numBestRes, struct resultsTy* resultsNLowPtr) + return ret; +} // int showVal(u32 numBestRes) int freeMem() { // free memory + numV=numF; // if needed restore numV + memInpCalc(); // if needed recalc the allocated size // 10 - freeing dynamic allocated memory ... - for (u32 e=0; e