diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5dd8fd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Makefile.deps \ No newline at end of file diff --git a/Makefile b/Makefile index bca8937..3e6d520 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,31 @@ all: make -C pico_osc - make -C pico_adc make -C sig_filter make -C sig_viewer - make -C fit_res -dir=/usr$(subst ${prefix},,${libdir})/tcl +#dir=/usr$(subst ${prefix},,${libdir})/tcl name=SigLoad ver=1.0 +DESTDIR ?= +prefix ?= $(DESTDIR)/usr +bindir ?= $(DESTDIR)/usr/bin +datadir ?= $(DESTDIR)/usr/share +libdir ?= $(DESTDIR)/usr/lib64 +sysconfdir ?= $(DESTDIR)/etc +initdir ?= $(DESTDIR)/etc/init.d +tcldatadir ?= $(DESTDIR)/usr/share/tcl +man1dir ?= $(DESTDIR)/usr/share/man/man1 +srvdir ?= $(DESTDIR)/usr/lib/systemd/system + bindir ?= /usr/bin install: all - mkdir -p ${bindir} ${libdir}/tcl/ ${datadir}/tcl/${name}-${ver} - install -m755 pico_osc/pico_osc pico_adc/pico_adc ${bindir} - install -m755 sig_filter/{sig_filter,sig_pnmtopng,sig_pnginfo} ${bindir} + mkdir -p ${bindir} ${libdir}/tcl/ ${tcldatadir}/${name}-${ver} + install -m755 pico_osc/pico_osc ${bindir} + install -m755 sig_filter/sig_filter sig_filter/sig_pnmtopng sig_filter/sig_pnginfo ${bindir} install -m755 sig_pngfig/sig_pngfig ${bindir} - install -m755 fit_res/fit_res ${bindir} install -m644 sig_viewer/sig_load.so ${libdir}/tcl/ sed 's|%LIB_DIR%|${dir}|' sig_viewer/pkgIndex.tcl > ${datadir}/tcl/${name}-${ver}/pkgIndex.tcl sed 's|^load ./sig_load.so|package require SigLoad|' sig_viewer/sig_viewer > ${bindir}/sig_viewer diff --git a/Readme.md b/Readme.md index eb0e384..2fb762c 100644 --- a/Readme.md +++ b/Readme.md @@ -2,18 +2,37 @@ ### Folders: -* pico_rec -- SPP inderface to Picoscope 4000 devices. +* pico_rec -- SPP interface to Picoscope 4000 devices. (SPP is a "simple pipe protocol" used +to communicate with command-line programs via unix pipes. It is used in some of +my programs: graphene, device2. This allows to use the oscilloscopes in the device2 system, +but the communication can be also done with simple shell scripts). +Program res + +* pico_log_py -- Python library for accessing oscilloscopes (by M.Will). + +* sig_filter -- Program for processing signals recorded by pico_rec program. +I'm using a simple custom format SIG for recording signals. It contains a +text header and binary data from oscilloscope. There is also SIGF +variant written in frequency domain (it is possible to reduce frequency +range and make files a lot smaller). Sig_filter program +does a lot of operations with signals. + +* sig_pngfig -- Working with PNG spectrograms with fig wrapper. It is possible +to convert sig file to a png spectrogram with additional information +about original time and frequency range; put it in a fig file (for xfig +vector editor), manually mark some features and then use sig_filter to extract +data from sig files using these marks. -* pico_adc -- SPP inderface to PicoADC24 devices. - -* pico_repack -- scripts for repacking pico libraries from original DEBs to Altlinux RPMs. +* sig_viewer -- TCL viewer for signal (and text) files -* ps3000 -- old programs for ps3000 device: HTTP server + tcl interface +* sig_python -- a simple python library for reading sig files -* sig_filter -- program for processing signals recorded by pico_rec program +* signals -- signal examples -* sig_viewer -- TCL viewer for signal (and text) files +* ps3000 -- old programs for ps3000 device: HTTP server + tcl interface -* signals -- signal examples +* pico_repack -- scripts for repacking pico libraries from original DEBs +to Altlinux RPMs. -* sig_pngfig -- working with PNG spectrograms with fig wrapper \ No newline at end of file +* modules -- I'm using my mapsoft2 build system with local set of modules. +See https://github.com/slazav/mapsoft2-libs diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..9d59965 --- /dev/null +++ b/debian/control @@ -0,0 +1,10 @@ +Source: pico-rec +Section: System +Priority: optional +Maintainer: Vladislav Zavjalov +Build-Depends: libmicrohttpd-dev, libjansson-dev, libcurl-dev +Standards-Version: 4.0.0 + +Package: pico-rec +Architecture: any +Description: record signals with Picoscope PS4224 and process them diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..15c1c3d --- /dev/null +++ b/debian/copyright @@ -0,0 +1,2 @@ +V.Zavjalov + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..3094b53 --- /dev/null +++ b/debian/rules @@ -0,0 +1,20 @@ +#!/usr/bin/make -f + +DESTDIR=debian/package +binary-arch: + $(checkdir) + $(checkroot) + + $(MAKE) + $(MAKE) install DESTDIR=$(DESTDIR) + + # Install Program Resources + mkdir $(DESTDIR)/DEBIAN + dpkg-gencontrol -P$(DESTDIR) + [ ! -f debian/conffiles ] || cp debian/conffiles $(DESTDIR)/DEBIAN/conffiles + cd $(DESTDIR) && find . -type f ! -regex '.*DEBIAN/.*' -printf '%P\0' | xargs -r0 md5sum > DEBIAN/md5sums + dpkg-deb -b $(DESTDIR) ../ + +# Below here is fairly generic really +binary: binary-indep binary-arch +.PHONY: binary binary-arch binary-indep clean build diff --git a/fit_res/.gitignore b/fit_res/.gitignore deleted file mode 100644 index 3f6cbea..0000000 --- a/fit_res/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -fit_res -*.o \ No newline at end of file diff --git a/fit_res/Makefile b/fit_res/Makefile deleted file mode 100644 index 312d12c..0000000 --- a/fit_res/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -LDLIBS = -lgsl -lm - -CC=g++ - -all: fit_res - -fit_res: fit_res.o fit.o -fit_res.o: fit.h - - -clean: - rm -f fit_res *.o - - - -#test: fit_res_test -# ./fit_res_test > fit_res.dat -# ./plot -# -#fit_res_test: fit_res_test.o fit.o -#fit_res_test.o: fit.h -# -# -#split_sweeps: split_sweeps.o - diff --git a/fit_res/Readme.md b/fit_res/Readme.md deleted file mode 100644 index 00ab0e7..0000000 --- a/fit_res/Readme.md +++ /dev/null @@ -1,32 +0,0 @@ -## fit_res - -Program reads resonance data (time, w, X, Y) from stdin, -fits data with a Lorentzian function: -``` -(X + iY) = (A + iB) + (C + iD)/(w0^2 - w^2 - iw*dw) -``` - -and prints a line with 14 values to stdout: -- time -- center of the time range -- f_error -- mean square difference between data and fit -- A, A_error, B, E_error -- shift in x and y component -- C, C_error, D, D_error -- driving force (not amplitude! -- w, w_error == resonance frequency (in Hz or rad/s dependind on input data) -- dw, dw_error -- width at 1/2 height of amplitude curve, - or (appoximately) distance between dispersion minimum - and maximum. If frequency data is in rad/s then df=2/tau, - if data in Hz then df = pi/tau - -Each parameter is followed by corresponding parameter error. - -The program can be used as a filter in `graphene_filter` script -(see https://github.com/slazav/graphene/ ) - - -Program uses libgsl library for fitting. - -#### Overload detection - -There is an option (turned on by default) for detecting overloaded signals. -Signals are fit twice: in a usual way and with points inside largest 5% of -the data range removed. The fit with smaller error is chosen. diff --git a/fit_res/examples/Readme b/fit_res/examples/Readme deleted file mode 100644 index d5d9a38..0000000 --- a/fit_res/examples/Readme +++ /dev/null @@ -1,3 +0,0 @@ -wire1.dat, wire2.dat -- MCTi wire signals from Lancaster Fridge4 -wire_ov.dat -- MCTi wire signals from Lancaster Fridge4, overloaded - diff --git a/fit_res/examples/get_data b/fit_res/examples/get_data deleted file mode 100644 index 50eada5..0000000 --- a/fit_res/examples/get_data +++ /dev/null @@ -1,5 +0,0 @@ - -d1=$(date +%s -d '2019-12-25 23:27:56') -d2=$(date +%s -d '2019-12-25 23:32:58') - -ssh -T f4a -- device -d db -cmd "'get_range wire_mc_cont $d1 $d2'" > wire_ov.dat diff --git a/fit_res/examples/plot_wire1 b/fit_res/examples/plot_wire1 deleted file mode 100755 index 249d1e4..0000000 --- a/fit_res/examples/plot_wire1 +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/gnuplot - -file = "wire1.dat" - -A=0.000111673 -B=-7.84857e-05 -C=0.05654 -D=-1.40903 -f0=1097.59 -df=1.53934 - -X(w) = A + (C*(f0**2-w**2) + D*w*df) / ((f0**2-w**2)**2 + (w*df)**2) -Y(w) = B + (D*(f0**2-w**2) - C*w*df) / ((f0**2-w**2)**2 + (w*df)**2) - -set nokey -set samples 1000 - -plot\ - file using 2:3 with points lc 3 pt 7 ps 1,\ - file using 2:4 with points lc 6 pt 7 ps 1,\ - X(x) lc 2, Y(x) lc 0,\ - -pause -1 - -set parametric -plot [1082:1112]\ - file using 3:4 with points lc 2 pt 7 ps 1,\ - X(t), Y(t) lc 0,\ - - -pause -1 - diff --git a/fit_res/examples/plot_wire2 b/fit_res/examples/plot_wire2 deleted file mode 100755 index 6dba39a..0000000 --- a/fit_res/examples/plot_wire2 +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/gnuplot - -file = "wire2.dat" - -A = 1.089275e-04 -B = -8.003296e-05 -C = 3.876585e-02 -D = -1.401328e+00 -f0 = 1.096880e+03 -df = 6.061935e+00 - -X(w) = A + (C*(f0**2-w**2) + D*w*df) / ((f0**2-w**2)**2 + (w*df)**2) -Y(w) = B + (D*(f0**2-w**2) - C*w*df) / ((f0**2-w**2)**2 + (w*df)**2) - - -set nokey -set samples 1000 - -plot\ - file using 2:3 with points lc 3 pt 7 ps 1,\ - file using 2:4 with points lc 6 pt 7 ps 1,\ - X(x) lc 2, Y(x) lc 0,\ - -pause -1 - -set parametric -plot [1082:1112]\ - file using 3:4 with points lc 2 pt 7 ps 1,\ - X(t), Y(t) lc 0,\ - - -pause -1 diff --git a/fit_res/examples/plot_wire_ov b/fit_res/examples/plot_wire_ov deleted file mode 100755 index 7353438..0000000 --- a/fit_res/examples/plot_wire_ov +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/gnuplot - -file = "wire_ov.dat" - -A = 1.14966238783069e-04 -B = -7.60473400025780e-05 -C = -1.61793188002281e-01 -D = -1.33925762054206e+00 -f0 = 1.09769110677181e+03 -df = 2.96768686138105e+00 - -A = 1.08639349503655e-04 -B = -7.96697345344945e-05 -C = 4.56372765075504e-02 -D = -1.40412170633463e+00 -f0 = 1.09754352623431e+03 -df = 2.07463939912798e+00 - - -X(w) = A + (C*(f0**2-w**2) + D*w*df) / ((f0**2-w**2)**2 + (w*df)**2) -Y(w) = B + (D*(f0**2-w**2) - C*w*df) / ((f0**2-w**2)**2 + (w*df)**2) - - -set nokey -set samples 1000 - -plot\ - file using 2:3 with points lc 3 pt 7 ps 1,\ - file using 2:4 with points lc 6 pt 7 ps 1,\ - X(x) lc 2, Y(x) lc 0,\ - -pause -1 - -set parametric -plot [1082:1112]\ - file using 3:4 with points lc 2 pt 7 ps 1,\ - X(t), Y(t) lc 0,\ - - -pause -1 diff --git a/fit_res/examples/run b/fit_res/examples/run deleted file mode 100755 index bda4208..0000000 --- a/fit_res/examples/run +++ /dev/null @@ -1 +0,0 @@ -../fit_res < wire2.dat diff --git a/fit_res/examples/wire1.dat b/fit_res/examples/wire1.dat deleted file mode 100644 index e2d93d7..0000000 --- a/fit_res/examples/wire1.dat +++ /dev/null @@ -1,200 +0,0 @@ -1577276001.406000000 1082 0.000114799 -0.000119329 -1577276002.821000000 1082.15 0.000112296 -0.000119567 -1577276004.145000000 1082.3 0.000112057 -0.000119806 -1577276005.463000000 1082.45 0.000109673 -0.000121594 -1577276007.005000000 1082.6 0.000114203 -0.00012254799 -1577276008.420000000 1082.75 0.000111342 -0.000122071 -1577276009.859000000 1082.9 0.000111819 -0.000123502 -1577276011.661000000 1083.0601 0.000112057 -0.000125051 -1577276013.105000000 1083.21 0.000111223 -0.00012219 -1577276014.514000000 1083.36 0.000106454 -0.000120402 -1577276015.796000000 1083.51 0.000109554 -0.000123144 -1577276017.221000000 1083.66 0.000110984 -0.00012254799 -1577276018.396000000 1083.8101 0.000108958 -0.000126959 -1577276019.826000000 1083.96 0.000106812 -0.00012469399 -1577276021.244000000 1084.11 0.000109196 -0.000125051 -1577276022.958000000 1084.26 0.000109554 -0.000126363 -1577276024.375000000 1084.41 0.000109673 -0.000125886 -1577276025.816000000 1084.5601 0.000111223 -0.00012231 -1577276027.998000000 1084.71 0.000110865 -0.000127436 -1577276029.413000000 1084.86 0.00011158 -0.000129462 -1577276030.860000000 1085.02 0.000110031 -0.000129105 -1577276032.058000000 1085.17 0.000110865 -0.000130535 -1577276033.466000000 1085.3199 0.000110388 -0.000128509 -1577276034.883000000 1085.47 0.000108719 -0.00012767399 -1577276037.073000000 1085.62 0.000111104 -0.000129105 -1577276039.284000000 1085.77 0.000108719 -0.000134469 -1577276040.831000000 1085.92 0.000108123 -0.00013637599 -1577276042.283000000 1086.0699 0.000108243 -0.000135184 -1577276043.444000000 1086.22 0.00011015 -0.000133038 -1577276044.860000000 1086.37 0.000111938 -0.000135065 -1577276046.316000000 1086.52 0.000111342 -0.000133158 -1577276047.740000000 1086.67 0.000110984 -0.000134231 -1577276049.063000000 1086.8199 0.000108243 -0.00013709201 -1577276050.483000000 1086.97 0.000108839 -0.000138164 -1577276051.992000000 1087.13 0.000111104 -0.00013709201 -1577276053.346000000 1087.28 0.000112534 -0.000138164 -1577276054.765000000 1087.4301 0.000112176 -0.000143767 -1577276056.180000000 1087.58 0.000110031 -0.00014150199 -1577276057.616000000 1087.73 0.000108481 -0.000142337 -1577276058.808000000 1087.88 0.000108958 -0.000145436 -1577276060.275000000 1088.03 0.000108123 -0.00014710501 -1577276061.691000000 1088.1801 0.000111223 -0.00014782 -1577276063.183000000 1088.33 0.000108243 -0.00014770099 -1577276064.867000000 1088.48 0.000109196 -0.000149489 -1577276066.421000000 1088.63 0.000111461 -0.000152946 -1577276067.831000000 1088.78 0.000112772 -0.000148416 -1577276069.378000000 1088.9301 0.000105858 -0.00015175399 -1577276070.814000000 1089.09 0.00010705 -0.000155331 -1577276072.221000000 1089.24 0.00010717 -0.000156404 -1577276073.965000000 1089.39 0.000107766 -0.000154496 -1577276075.259000000 1089.54 0.000108004 -0.000157476 -1577276076.708000000 1089.6899 0.000107766 -0.000158072 -1577276078.124000000 1089.84 0.000105024 -0.00016307901 -1577276079.424000000 1089.99 0.000106454 -0.000162126 -1577276080.841000000 1090.14 0.000103832 -0.000165344 -1577276082.264000000 1090.29 0.000107527 -0.000166179 -1577276083.799000000 1090.4399 0.000108123 -0.000169397 -1577276085.247000000 1090.59 0.000108958 -0.00016772799 -1577276086.656000000 1090.74 0.000104428 -0.00017142401 -1577276088.109000000 1090.89 0.000104785 -0.00017416599 -1577276089.308000000 1091.05 0.000105858 -0.00017714599 -1577276090.721000000 1091.2 0.000101328 -0.000180245 -1577276092.158000000 1091.35 0.000102282 -0.000178576 -1577276093.568000000 1091.5 0.000106097 -0.000181437 -1577276094.978000000 1091.65 0.000103236 -0.00018632501 -1577276096.260000000 1091.8 9.9420999e-05 -0.00018882799 -1577276097.678000000 1091.95 0.000103593 -0.00018990099 -1577276099.217000000 1092.1 9.9301797e-05 -0.000197054 -1577276100.653000000 1092.25 9.7156e-05 -0.000198604 -1577276103.071000000 1092.4 9.4294999e-05 -0.00020384901 -1577276104.998000000 1092.55 9.7275202e-05 -0.00020635199 -1577276107.695000000 1092.7 9.4652598e-05 -0.000209213 -1577276108.944000000 1092.85 9.7036798e-05 -0.000210167 -1577276110.361000000 1093.01 9.0718699e-05 -0.00021469699 -1577276111.714000000 1093.16 9.0241898e-05 -0.00021767701 -1577276113.036000000 1093.3101 8.9765097e-05 -0.000227333 -1577276114.524000000 1093.46 9.15532e-05 -0.00023222101 -1577276115.938000000 1093.61 8.9049798e-05 -0.000235439 -1577276117.253000000 1093.76 8.7023203e-05 -0.000241161 -1577276118.659000000 1093.91 8.16588e-05 -0.00024390301 -1577276120.071000000 1094.0601 8.0943602e-05 -0.000255825 -1577276121.485000000 1094.21 8.1181999e-05 -0.000259997 -1577276122.897000000 1094.36 7.4983102e-05 -0.00026977199 -1577276124.699000000 1094.51 6.7830602e-05 -0.00027609101 -1577276126.015000000 1094.66 6.6519198e-05 -0.00028276601 -1577276127.446000000 1094.8101 6.2466097e-05 -0.000293138 -1577276128.860000000 1094.96 5.6147801e-05 -0.00030565399 -1577276130.275000000 1095.12 4.99489e-05 -0.00031912501 -1577276131.685000000 1095.27 3.8504801e-05 -0.00033545701 -1577276133.113000000 1095.42 3.1948301e-05 -0.00034761601 -1577276134.689000000 1095.5699 1.75239e-05 -0.000364901 -1577276136.265000000 1095.72 2.2649899e-06 -0.00037777601 -1577276137.692000000 1095.87 -1.5735701e-05 -0.00039708801 -1577276139.142000000 1096.02 -3.5166999e-05 -0.00041508899 -1577276140.570000000 1096.17 -6.22277e-05 -0.00043750001 -1577276141.992000000 1096.3199 -9.5844698e-05 -0.000457527 -1577276143.424000000 1096.47 -0.00014281399 -0.000486376 -1577276144.840000000 1096.62 -0.00019550401 -0.00049531797 -1577276146.256000000 1096.77 -0.000263097 -0.00050938502 -1577276147.664000000 1096.92 -0.00034988101 -0.00051343802 -1577276149.104000000 1097.08 -0.00046432199 -0.000475409 -1577276150.338000000 1097.23 -0.00054777 -0.00044286399 -1577276151.751000000 1097.38 -0.00064087298 -0.00032115201 -1577276153.246000000 1097.53 -0.00070465001 -0.00016927801 -1577276154.546000000 1097.6801 -0.00072288897 -3.07562e-05 -1577276155.831000000 1097.83 -0.00066578801 0.000124813 -1577276157.279000000 1097.98 -0.00056219503 0.000236989 -1577276158.692000000 1098.13 -0.00046015001 0.00030052799 -1577276160.135000000 1098.28 -0.00036430499 0.00032234401 -1577276161.451000000 1098.4301 -0.00028634301 0.00032341701 -1577276162.915000000 1098.58 -0.000212074 0.00031137699 -1577276164.317000000 1098.73 -0.000160695 0.000298144 -1577276165.807000000 1098.88 -0.000117541 0.000277402 -1577276167.161000000 1099.04 -8.9049798e-05 0.000262382 -1577276168.641000000 1099.1899 -5.9247199e-05 0.00023794299 -1577276170.059000000 1099.34 -3.6001398e-05 0.000222565 -1577276171.624000000 1099.49 -2.1457799e-05 0.00020492201 -1577276173.040000000 1099.64 -5.2452401e-06 0.000188709 -1577276174.333000000 1099.79 1.03713e-05 0.000174046 -1577276175.750000000 1099.9399 1.4186e-05 0.00016141 -1577276176.936000000 1100.09 2.4676399e-05 0.00015545 -1577276178.383000000 1100.24 3.5763002e-05 0.00014197901 -1577276179.576000000 1100.39 4.22003e-05 0.00013637599 -1577276180.691000000 1100.54 4.6849502e-05 0.000125886 -1577276182.145000000 1100.6899 5.3167601e-05 0.00011623 -1577276183.554000000 1100.84 5.9366499e-05 0.00010705 -1577276184.992000000 1100.99 6.2823798e-05 0.000105143 -1577276186.313000000 1101.15 6.5684799e-05 9.4056602e-05 -1577276187.723000000 1101.3 6.9976297e-05 8.6784799e-05 -1577276189.143000000 1101.45 7.3433403e-05 8.1539598e-05 -1577276190.580000000 1101.6 7.3314201e-05 7.5698401e-05 -1577276191.998000000 1101.75 7.7486497e-05 6.9261099e-05 -1577276193.413000000 1101.9 8.0347498e-05 6.6280802e-05 -1577276194.872000000 1102.05 7.9155398e-05 5.88896e-05 -1577276196.282000000 1102.2 8.1062797e-05 5.8412799e-05 -1577276197.727000000 1102.35 8.6307999e-05 5.6624602e-05 -1577276199.136000000 1102.5 8.5711901e-05 4.8876002e-05 -1577276200.576000000 1102.65 8.7500099e-05 4.3749998e-05 -1577276201.895000000 1102.8 8.5592699e-05 3.68359e-05 -1577276203.225000000 1102.95 8.6307999e-05 3.6001398e-05 -1577276204.419000000 1103.11 9.1076399e-05 3.3736502e-05 -1577276205.831000000 1103.26 9.2030001e-05 3.26636e-05 -1577276207.625000000 1103.41 9.3222101e-05 2.7895099e-05 -1577276209.052000000 1103.5601 9.4652598e-05 2.51533e-05 -1577276210.493000000 1103.71 9.6679199e-05 2.4438001e-05 -1577276211.900000000 1103.86 9.27453e-05 2.4557199e-05 -1577276213.345000000 1104.01 9.2626098e-05 2.0981e-05 -1577276214.757000000 1104.16 9.7394499e-05 1.9311999e-05 -1577276216.215000000 1104.3101 9.6321601e-05 1.5735701e-05 -1577276217.534000000 1104.46 9.9182602e-05 1.31131e-05 -1577276218.947000000 1104.61 9.9301797e-05 1.32323e-05 -1577276220.363000000 1104.76 9.7513701e-05 8.8215502e-06 -1577276221.793000000 1104.91 9.9659403e-05 5.8412802e-06 -1577276223.204000000 1105.0699 0.000101567 7.2717999e-06 -1577276224.634000000 1105.22 0.000103474 3.2186699e-06 -1577276226.040000000 1105.37 0.000102044 4.7683998e-06 -1577276227.722000000 1105.52 0.00010109 -1.6689399e-06 -1577276229.035000000 1105.67 9.9897901e-05 9.5368205e-07 -1577276230.447000000 1105.8199 0.000101328 2.3842e-07 -1577276231.866000000 1105.97 0.000104666 -5.2452401e-06 -1577276233.286000000 1106.12 0.00010264 -4.88761e-06 -1577276234.633000000 1106.27 0.000101805 -4.1723501e-06 -1577276235.802000000 1106.42 0.000101328 -7.9870797e-06 -1577276237.198000000 1106.5699 9.9182602e-05 -1.03713e-05 -1577276238.622000000 1106.72 0.000102759 -8.5831298e-06 -1577276240.044000000 1106.87 0.000101686 -1.06097e-05 -1577276241.513000000 1107.03 0.000106931 -1.43052e-05 -1577276243.824000000 1107.1801 0.00010407 -1.26362e-05 -1577276244.987000000 1107.33 0.00010407 -1.49012e-05 -1577276246.282000000 1107.48 0.000105143 -1.29939e-05 -1577276247.957000000 1107.63 0.000106216 -1.40668e-05 -1577276249.267000000 1107.78 0.000103832 -1.7881501e-05 -1577276250.680000000 1107.9301 0.00010717 -1.53781e-05 -1577276251.967000000 1108.08 0.000103832 -1.7046999e-05 -1577276253.289000000 1108.23 0.000107527 -2.0146501e-05 -1577276254.702000000 1108.38 0.000103951 -2.26499e-05 -1577276256.200000000 1108.53 0.000108243 -2.1577e-05 -1577276257.619000000 1108.6801 0.000106216 -2.1100201e-05 -1577276259.040000000 1108.83 0.000105858 -2.06233e-05 -1577276260.454000000 1108.98 0.000108719 -2.37228e-05 -1577276261.861000000 1109.14 0.0001086 -2.4557199e-05 -1577276263.171000000 1109.29 0.000105858 -2.6702999e-05 -1577276264.579000000 1109.4399 0.000108362 -2.7537501e-05 -1577276265.893000000 1109.59 0.00010407 -3.0160099e-05 -1577276267.192000000 1109.74 0.000105024 -2.7537501e-05 -1577276268.872000000 1109.89 0.000106931 -2.82527e-05 -1577276270.175000000 1110.04 0.00010705 -2.6107e-05 -1577276271.401000000 1110.1899 0.000105143 -2.8014299e-05 -1577276272.611000000 1110.34 0.000103117 -2.8967999e-05 -1577276273.850000000 1110.49 0.000105978 -2.94448e-05 -1577276275.265000000 1110.64 0.000109435 -3.1113901e-05 -1577276276.711000000 1110.79 0.000108719 -2.9802401e-05 -1577276278.128000000 1110.9399 0.000110388 -3.3021199e-05 -1577276279.484000000 1111.1 0.0001086 -3.3140401e-05 -1577276280.893000000 1111.25 0.000105978 -3.2544402e-05 -1577276282.058000000 1111.4 0.000105739 -3.2544402e-05 -1577276283.505000000 1111.55 0.000105739 -3.46901e-05 -1577276284.920000000 1111.7 0.000109315 -3.46901e-05 -1577276286.226000000 1111.85 0.000107766 -3.73127e-05 -1577276287.400000000 1112 0.000105978 -3.8743299e-05 diff --git a/fit_res/examples/wire2.dat b/fit_res/examples/wire2.dat deleted file mode 100644 index 3a1a3ad..0000000 --- a/fit_res/examples/wire2.dat +++ /dev/null @@ -1,200 +0,0 @@ -1577300767.126000000 1082 9.9778597e-05 -0.00012254799 -1577300768.550000000 1082.15 0.000103117 -0.000121117 -1577300769.960000000 1082.3 9.9897901e-05 -0.000122906 -1577300771.373000000 1082.45 0.000102878 -0.00012624401 -1577300772.802000000 1082.6 0.000103117 -0.000122071 -1577300774.227000000 1082.75 0.000101328 -0.000122429 -1577300775.639000000 1082.9 9.8825003e-05 -0.000120759 -1577300777.085000000 1083.0601 0.000100971 -0.000120521 -1577300778.432000000 1083.21 0.00010252 -0.000122667 -1577300779.848000000 1083.36 0.000103474 -0.000127436 -1577300781.259000000 1083.51 0.000102401 -0.00012624401 -1577300782.709000000 1083.66 0.000101328 -0.00012445499 -1577300783.882000000 1083.8101 0.000102878 -0.00012445499 -1577300785.373000000 1083.96 9.8944198e-05 -0.000127912 -1577300786.782000000 1084.11 9.7990502e-05 -0.000126959 -1577300788.210000000 1084.26 0.000101567 -0.00012767399 -1577300789.629000000 1084.41 0.000101328 -0.000124575 -1577300791.427000000 1084.5601 9.7275202e-05 -0.00012624401 -1577300792.967000000 1084.71 9.7752098e-05 -0.00013089299 -1577300794.397000000 1084.86 9.6440803e-05 -0.000128151 -1577300795.712000000 1085.02 9.9301797e-05 -0.000129939 -1577300797.153000000 1085.17 9.7990502e-05 -0.000130416 -1577300798.508000000 1085.3199 9.7990502e-05 -0.000132085 -1577300799.922000000 1085.47 9.2983697e-05 -0.000132681 -1577300801.364000000 1085.62 9.5844698e-05 -0.000132681 -1577300802.804000000 1085.77 9.3222101e-05 -0.000134469 -1577300804.223000000 1085.92 9.6202399e-05 -0.000134469 -1577300805.634000000 1086.0699 9.5844698e-05 -0.000133277 -1577300808.361000000 1086.22 9.39374e-05 -0.000135065 -1577300809.778000000 1086.37 9.6559997e-05 -0.000135661 -1577300811.197000000 1086.52 9.15532e-05 -0.00013435 -1577300812.742000000 1086.67 9.6679199e-05 -0.00014031 -1577300814.195000000 1086.8199 9.3699004e-05 -0.000136138 -1577300815.609000000 1086.97 9.6083197e-05 -0.00014221801 -1577300816.892000000 1087.13 9.5248703e-05 -0.00014186 -1577300818.340000000 1087.28 9.27453e-05 -0.000144006 -1577300819.516000000 1087.4301 9.4533403e-05 -0.000142456 -1577300821.002000000 1087.58 9.1433998e-05 -0.000144006 -1577300822.412000000 1087.73 8.7023203e-05 -0.000145675 -1577300823.876000000 1087.88 9.0122703e-05 -0.00014519801 -1577300825.227000000 1088.03 9.03611e-05 -0.00014770099 -1577300826.677000000 1088.1801 8.79769e-05 -0.00014770099 -1577300828.348000000 1088.33 9.0122703e-05 -0.000150205 -1577300829.629000000 1088.48 9.03611e-05 -0.000148655 -1577300831.051000000 1088.63 8.4162202e-05 -0.00014901299 -1577300832.987000000 1088.78 8.4281397e-05 -0.00014877399 -1577300834.407000000 1088.9301 8.2016501e-05 -0.00014734401 -1577300835.697000000 1089.09 8.4162202e-05 -0.000155211 -1577300837.109000000 1089.24 8.3566199e-05 -0.000154258 -1577300838.554000000 1089.39 8.3327803e-05 -0.000151635 -1577300839.975000000 1089.54 7.7009703e-05 -0.00015282699 -1577300841.386000000 1089.6899 7.96323e-05 -0.000154735 -1577300842.826000000 1089.84 7.9751502e-05 -0.000156404 -1577300844.246000000 1089.99 8.0347498e-05 -0.000160695 -1577300845.665000000 1090.14 7.4625503e-05 -0.000157 -1577300847.156000000 1090.29 7.5817603e-05 -0.00015998 -1577300848.570000000 1090.4399 7.2241302e-05 -0.000160814 -1577300849.980000000 1090.59 7.0572401e-05 -0.00016307901 -1577300851.396000000 1090.74 6.97379e-05 -0.00016951701 -1577300852.844000000 1090.89 6.7115303e-05 -0.00016689399 -1577300854.261000000 1091.05 6.2823798e-05 -0.00016844401 -1577300855.709000000 1091.2 6.6519198e-05 -0.00016796699 -1577300857.119000000 1091.35 5.9724101e-05 -0.000169993 -1577300858.543000000 1091.5 5.8412799e-05 -0.00017201999 -1577300859.857000000 1091.65 5.7459099e-05 -0.00017655001 -1577300861.290000000 1091.8 5.1617899e-05 -0.000176311 -1577300863.460000000 1091.95 5.2690699e-05 -0.000175954 -1577300864.866000000 1092.1 5.23331e-05 -0.000178338 -1577300866.313000000 1092.25 4.8279999e-05 -0.000173212 -1577300867.725000000 1092.4 4.3153999e-05 -0.000182868 -1577300868.908000000 1092.55 4.01738e-05 -0.000183702 -1577300870.319000000 1092.7 3.5643799e-05 -0.00018704 -1577300871.761000000 1092.85 3.7670401e-05 -0.000186563 -1577300873.179000000 1093.01 3.0160099e-05 -0.000185371 -1577300874.532000000 1093.16 2.9564e-05 -0.000186563 -1577300875.946000000 1093.3101 1.97889e-05 -0.000185729 -1577300877.362000000 1093.46 1.4782e-05 -0.000188113 -1577300878.794000000 1093.61 1.07289e-05 -0.000183941 -1577300880.208000000 1093.76 8.9407504e-06 -0.000182034 -1577300881.631000000 1093.91 -7.1525898e-07 -0.00018859 -1577300883.047000000 1094.0601 -8.3446901e-07 -0.000189663 -1577300884.526000000 1094.21 -6.79496e-06 -0.00019097399 -1577300885.953000000 1094.36 -1.50204e-05 -0.000187517 -1577300887.369000000 1094.51 -2.0981e-05 -0.000185014 -1577300888.802000000 1094.66 -2.4318801e-05 -0.000183702 -1577300890.221000000 1094.8101 -3.1352301e-05 -0.00018274901 -1577300891.684000000 1094.96 -4.1485098e-05 -0.000177861 -1577300893.105000000 1095.12 -4.91145e-05 -0.00017547701 -1577300894.775000000 1095.27 -5.54326e-05 -0.000173212 -1577300896.058000000 1095.42 -5.8412799e-05 -0.00016605901 -1577300897.476000000 1095.5699 -6.6638502e-05 -0.00016117201 -1577300898.887000000 1095.72 -6.9618698e-05 -0.000158549 -1577300900.325000000 1095.87 -7.5936798e-05 -0.000146748 -1577300901.750000000 1096.02 -8.4639098e-05 -0.000139118 -1577300903.085000000 1096.17 -8.7261702e-05 -0.000135542 -1577300904.395000000 1096.3199 -9.0480302e-05 -0.00012469399 -1577300905.812000000 1096.47 -9.39374e-05 -0.000114918 -1577300907.255000000 1096.62 -0.000100375 -0.000102044 -1577300908.669000000 1096.77 -0.000102282 -9.4294999e-05 -1577300910.109000000 1096.92 -0.000101209 -8.2254897e-05 -1577300911.523000000 1097.08 -0.000102878 -7.0095499e-05 -1577300912.938000000 1097.23 -0.000102878 -6.1631697e-05 -1577300915.385000000 1097.38 -9.59639e-05 -4.9472099e-05 -1577300916.672000000 1097.53 -9.5606301e-05 -4.5419001e-05 -1577300918.101000000 1097.6801 -8.8811401e-05 -3.5763002e-05 -1577300919.279000000 1097.83 -8.6665597e-05 -2.7656701e-05 -1577300920.729000000 1097.98 -7.9513098e-05 -1.94312e-05 -1577300922.143000000 1098.13 -7.65328e-05 -8.5831298e-06 -1577300923.426000000 1098.28 -7.0214701e-05 -3.0994599e-06 -1577300925.223000000 1098.4301 -5.6982299e-05 -2.3842e-07 -1577300926.686000000 1098.58 -5.7339901e-05 5.8412802e-06 -1577300928.100000000 1098.73 -4.7207101e-05 9.4175903e-06 -1577300929.386000000 1098.88 -4.4703698e-05 1.5974199e-05 -1577300931.096000000 1099.04 -3.5166999e-05 1.9192799e-05 -1577300932.507000000 1099.1899 -3.03985e-05 1.65702e-05 -1577300933.956000000 1099.34 -1.94312e-05 1.74047e-05 -1577300935.368000000 1099.49 -1.83583e-05 1.76431e-05 -1577300936.784000000 1099.64 -8.70234e-06 2.08617e-05 -1577300938.075000000 1099.79 -5.8412802e-06 2.30075e-05 -1577300939.491000000 1099.9399 5.2452401e-06 2.4318801e-05 -1577300940.946000000 1100.09 7.7486602e-06 2.07425e-05 -1577300942.363000000 1100.24 6.55654e-06 2.3365101e-05 -1577300943.786000000 1100.39 1.8835201e-05 1.51396e-05 -1577300945.329000000 1100.54 3.36173e-05 2.4318801e-05 -1577300946.757000000 1100.6899 3.5286201e-05 3.1352301e-05 -1577300948.168000000 1100.84 3.5643799e-05 1.84776e-05 -1577300949.600000000 1100.99 2.3842e-05 9.77522e-06 -1577300951.013000000 1101.15 3.6359099e-05 1.76431e-05 -1577300952.426000000 1101.3 3.6716701e-05 1.8716e-05 -1577300953.834000000 1101.45 4.2081101e-05 1.29939e-05 -1577300955.244000000 1101.6 4.24387e-05 1.21594e-05 -1577300957.074000000 1101.75 4.5061301e-05 1.33515e-05 -1577300958.382000000 1101.9 5.1021801e-05 1.13249e-05 -1577300959.924000000 1102.05 5.1856299e-05 1.16826e-05 -1577300961.231000000 1102.2 5.2809901e-05 1.16826e-05 -1577300962.436000000 1102.35 5.42405e-05 7.7486602e-06 -1577300963.693000000 1102.5 6.0200899e-05 3.9339402e-06 -1577300965.109000000 1102.65 6.3181396e-05 1.54973e-06 -1577300966.438000000 1102.8 6.0439299e-05 -5.9604997e-07 -1577300967.859000000 1102.95 6.2943e-05 2.1457799e-06 -1577300969.279000000 1103.11 6.4015898e-05 -9.5368205e-07 -1577300971.466000000 1103.26 7.0810798e-05 -2.3842e-07 -1577300972.902000000 1103.41 7.1287599e-05 1.1920999e-06 -1577300974.318000000 1103.5601 6.8903399e-05 -4.4107701e-06 -1577300975.732000000 1103.71 7.2956602e-05 -3.0994599e-06 -1577300977.037000000 1103.86 7.1287599e-05 -5.3644499e-06 -1577300978.458000000 1104.01 7.4387099e-05 -7.5102098e-06 -1577300979.881000000 1104.16 7.5221498e-05 -5.4836601e-06 -1577300981.293000000 1104.3101 7.5102304e-05 -9.4175903e-06 -1577300982.702000000 1104.46 7.3314201e-05 -1.22786e-05 -1577300984.115000000 1104.61 7.96323e-05 -1.18018e-05 -1577300985.558000000 1104.76 8.1778002e-05 -8.8215502e-06 -1577300986.975000000 1104.91 8.08244e-05 -1.03713e-05 -1577300988.425000000 1105.0699 8.2731698e-05 -1.5974199e-05 -1577300989.877000000 1105.22 8.3566199e-05 -1.49012e-05 -1577300991.558000000 1105.37 8.16588e-05 -1.38283e-05 -1577300992.993000000 1105.52 8.3923798e-05 -1.53781e-05 -1577300994.403000000 1105.67 8.3566199e-05 -1.8000699e-05 -1577300995.696000000 1105.8199 8.4996696e-05 -1.31131e-05 -1577300997.103000000 1105.97 8.6427201e-05 -1.32323e-05 -1577300998.537000000 1106.12 8.4281397e-05 -2.08617e-05 -1577300999.958000000 1106.27 9.0122703e-05 -1.84776e-05 -1577301001.381000000 1106.42 9.1910799e-05 -2.0146501e-05 -1577301002.798000000 1106.5699 8.8215304e-05 -1.96696e-05 -1577301004.238000000 1106.72 8.7380897e-05 -2.08617e-05 -1577301005.365000000 1106.87 8.8692199e-05 -2.2411499e-05 -1577301006.896000000 1107.03 9.0718699e-05 -2.26499e-05 -1577301008.353000000 1107.1801 8.8096102e-05 -2.41996e-05 -1577301009.776000000 1107.33 9.2268499e-05 -2.6464601e-05 -1577301011.254000000 1107.48 8.9169e-05 -2.6822199e-05 -1577301012.665000000 1107.63 9.3460498e-05 -2.9921601e-05 -1577301014.075000000 1107.78 9.1910799e-05 -2.7775901e-05 -1577301015.493000000 1107.9301 9.4294999e-05 -2.86103e-05 -1577301016.904000000 1108.08 9.6917604e-05 -2.83719e-05 -1577301018.318000000 1108.23 9.59639e-05 -2.8967999e-05 -1577301019.728000000 1108.38 9.2864502e-05 -2.9802401e-05 -1577301021.182000000 1108.53 9.4175797e-05 -3.0875399e-05 -1577301023.016000000 1108.6801 9.4294999e-05 -3.0875399e-05 -1577301024.432000000 1108.83 9.9301797e-05 -3.0994601e-05 -1577301026.276000000 1108.98 9.3699004e-05 -3.4332501e-05 -1577301027.597000000 1109.14 9.5367897e-05 -3.3140401e-05 -1577301029.060000000 1109.29 9.5010299e-05 -3.17099e-05 -1577301030.474000000 1109.4399 9.5367897e-05 -3.05178e-05 -1577301031.885000000 1109.59 9.3460498e-05 -3.6001398e-05 -1577301033.225000000 1109.74 9.4533403e-05 -3.0994601e-05 -1577301034.394000000 1109.89 9.6321601e-05 -3.0994601e-05 -1577301035.793000000 1110.04 9.4533403e-05 -3.4809302e-05 -1577301037.223000000 1110.1899 9.9182602e-05 -3.4451699e-05 -1577301038.647000000 1110.34 9.7275202e-05 -3.4809302e-05 -1577301040.064000000 1110.49 9.59639e-05 -3.2902e-05 -1577301041.475000000 1110.64 9.7632903e-05 -3.8504801e-05 -1577301042.926000000 1110.79 0.00010109 -4.0293002e-05 -1577301044.335000000 1110.9399 0.000100375 -3.89817e-05 -1577301045.554000000 1111.1 9.8228898e-05 -3.3140401e-05 -1577301046.722000000 1111.25 0.000100255 -3.24252e-05 -1577301048.150000000 1111.4 9.9420999e-05 -3.9100902e-05 -1577301049.560000000 1111.55 0.000101567 -3.9816099e-05 -1577301050.999000000 1111.7 0.000102163 -3.9816099e-05 -1577301052.166000000 1111.85 9.8944198e-05 -3.9577699e-05 -1577301053.570000000 1112 9.8705801e-05 -4.0531399e-05 diff --git a/fit_res/examples/wire_ov.dat b/fit_res/examples/wire_ov.dat deleted file mode 100644 index c2e6fb5..0000000 --- a/fit_res/examples/wire_ov.dat +++ /dev/null @@ -1,200 +0,0 @@ -1577309281.744000000 1082 0.000107892 -0.000118837 -1577309283.156000000 1082.15 0.00010673 -0.000118301 -1577309284.476000000 1082.3 0.000107155 -0.000120201 -1577309285.887000000 1082.45 0.000106849 -0.000117533 -1577309287.359000000 1082.6 0.00010708 -0.00012221299 -1577309289.165000000 1082.75 0.000106253 -0.00012270499 -1577309290.581000000 1082.9 0.000105717 -0.000121139 -1577309292.064000000 1083.0601 0.000109196 -0.0001226 -1577309293.473000000 1083.21 0.00010743 -0.000121639 -1577309295.016000000 1083.36 0.000105717 -0.000124999 -1577309296.460000000 1083.51 0.000109822 -0.000125215 -1577309297.872000000 1083.66 0.000108935 -0.000125484 -1577309299.163000000 1083.8101 0.000108429 -0.000127361 -1577309300.836000000 1083.96 0.000109651 -0.000127123 -1577309302.266000000 1084.11 0.000106186 -0.000127115 -1577309303.670000000 1084.26 0.000106432 -0.000125737 -1577309305.609000000 1084.41 0.000107028 -0.00012569199 -1577309307.022000000 1084.5601 0.000106454 -0.000127987 -1577309309.209000000 1084.71 0.000106007 -0.000130446 -1577309311.437000000 1084.86 0.000105344 -0.00013122099 -1577309313.106000000 1085.02 0.000108824 -0.000129969 -1577309314.451000000 1085.17 0.000107833 -0.000127212 -1577309315.860000000 1085.3199 0.000104659 -0.00013245 -1577309317.052000000 1085.47 0.000105091 -0.000136466 -1577309318.244000000 1085.62 0.000100963 -0.000136205 -1577309319.654000000 1085.77 0.000104398 -0.000130639 -1577309321.087000000 1085.92 0.000105031 -0.000134462 -1577309322.499000000 1086.0699 0.000103012 -0.00013668201 -1577309323.931000000 1086.22 0.000103496 -0.000134462 -1577309325.343000000 1086.37 0.000107363 -0.00013777 -1577309326.534000000 1086.52 0.00010705 -0.00013601901 -1577309327.948000000 1086.67 0.000106909 -0.00013586201 -1577309329.362000000 1086.8199 0.000106059 -0.000140169 -1577309330.783000000 1086.97 0.000105955 -0.000137732 -1577309332.098000000 1087.13 0.000106253 -0.000139781 -1577309333.636000000 1087.28 0.000102588 -0.00014191199 -1577309334.961000000 1087.4301 0.000104093 -0.00014341 -1577309336.639000000 1087.58 0.000104435 -0.000145347 -1577309338.048000000 1087.73 0.000104763 -0.00014595799 -1577309339.725000000 1087.88 0.00010404 -0.00014364799 -1577309341.024000000 1088.03 0.00010334 -0.000149653 -1577309342.437000000 1088.1801 0.000104115 -0.00015054 -1577309343.864000000 1088.33 0.000100546 -0.000146062 -1577309345.274000000 1088.48 0.000103042 -0.00015171 -1577309346.998000000 1088.63 0.000104942 -0.000151129 -1577309348.347000000 1088.78 0.000101902 -0.00015346801 -1577309349.662000000 1088.9301 0.000101395 -0.000152768 -1577309351.115000000 1089.09 0.000102163 -0.000157745 -1577309352.413000000 1089.24 9.9830802e-05 -0.000156754 -1577309353.592000000 1089.39 9.7141099e-05 -0.000156016 -1577309355.001000000 1089.54 0.000101075 -0.00015745399 -1577309356.552000000 1089.6899 9.77819e-05 -0.00016001701 -1577309357.828000000 1089.84 0.000102506 -0.00016018101 -1577309359.256000000 1089.99 0.000100762 -0.000162513 -1577309360.670000000 1090.14 0.0001015 -0.000164301 -1577309362.598000000 1090.29 9.6247102e-05 -0.000166253 -1577309363.783000000 1090.4399 9.9637102e-05 -0.00016961301 -1577309365.197000000 1090.59 9.8489698e-05 -0.000172817 -1577309366.610000000 1090.74 9.91528e-05 -0.000170381 -1577309368.024000000 1090.89 9.7521101e-05 -0.00017525299 -1577309369.522000000 1091.05 9.73274e-05 -0.00017846499 -1577309371.706000000 1091.2 9.7081502e-05 -0.00017874 -1577309373.155000000 1091.35 9.6068303e-05 -0.000182801 -1577309374.570000000 1091.5 0.000100643 -0.000184358 -1577309376.012000000 1091.65 9.3579802e-05 -0.000185945 -1577309377.418000000 1091.8 9.2432398e-05 -0.000186861 -1577309378.827000000 1091.95 8.7477703e-05 -0.000187823 -1577309380.339000000 1092.1 8.9049798e-05 -0.000197046 -1577309381.758000000 1092.25 8.5540603e-05 -0.000201167 -1577309383.178000000 1092.4 8.6822103e-05 -0.000204706 -1577309384.679000000 1092.55 8.3364997e-05 -0.000201338 -1577309386.097000000 1092.7 8.50414e-05 -0.000203998 -1577309388.420000000 1092.85 8.3871702e-05 -0.000215494 -1577309389.869000000 1093.01 7.8164499e-05 -0.000212737 -1577309391.289000000 1093.16 8.0876503e-05 -0.000217685 -1577309392.579000000 1093.3101 7.9036203e-05 -0.000218445 -1577309394.069000000 1093.46 7.4960801e-05 -0.000218445 -1577309395.506000000 1093.61 7.1011898e-05 -0.000218445 -1577309396.922000000 1093.76 6.6772598e-05 -0.000218445 -1577309398.466000000 1093.91 6.3583699e-05 -0.000218445 -1577309399.880000000 1094.0601 5.97986e-05 -0.000218445 -1577309401.303000000 1094.21 5.6490499e-05 -0.000218445 -1577309402.744000000 1094.36 4.96211e-05 -0.000218445 -1577309404.157000000 1094.51 4.52327e-05 -0.000218445 -1577309406.794000000 1094.66 3.6060999e-05 -0.000218445 -1577309408.464000000 1094.8101 3.2753e-05 -0.000218445 -1577309409.890000000 1094.96 2.1874999e-05 -0.000218445 -1577309411.302000000 1095.12 1.7173699e-05 -0.000218445 -1577309413.099000000 1095.27 4.47037e-08 -0.000218445 -1577309414.370000000 1095.42 -6.2659701e-06 -0.000218445 -1577309415.781000000 1095.5699 -1.85223e-05 -0.000218445 -1577309417.210000000 1095.72 -3.8519702e-05 -0.000218445 -1577309419.127000000 1095.87 -6.6012602e-05 -0.000218445 -1577309420.439000000 1096.02 -8.4616702e-05 -0.000218445 -1577309421.851000000 1096.17 -0.000111238 -0.000218445 -1577309423.267000000 1096.3199 -0.00014598 -0.000218445 -1577309424.686000000 1096.47 -0.000187025 -0.000218445 -1577309426.104000000 1096.62 -0.000218445 -0.000218445 -1577309427.555000000 1096.77 -0.000218445 -0.000218445 -1577309428.969000000 1096.92 -0.000218445 -0.000218445 -1577309430.400000000 1097.08 -0.000218445 -0.000218445 -1577309431.815000000 1097.23 -0.000218445 -0.000218445 -1577309433.249000000 1097.38 -0.000218445 -0.000178375 -1577309435.187000000 1097.53 -0.000218445 -7.5348202e-05 -1577309436.605000000 1097.6801 -0.000218445 -8.9482101e-06 -1577309438.053000000 1097.83 -0.000218445 6.5423999e-05 -1577309439.403000000 1097.98 -0.000218445 0.000121132 -1577309440.842000000 1098.13 -0.000218445 0.000167907 -1577309442.252000000 1098.28 -0.000218445 0.000195653 -1577309443.695000000 1098.4301 -0.000218445 0.00020925001 -1577309444.941000000 1098.58 -0.00020889301 0.000218437 -1577309446.358000000 1098.73 -0.00016793 0.000215338 -1577309447.781000000 1098.88 -0.000134395 0.000210279 -1577309449.706000000 1099.04 -9.4376999e-05 0.00019952 -1577309451.118000000 1099.1899 -7.7434299e-05 0.00019310501 -1577309452.475000000 1099.34 -5.23778e-05 0.000183606 -1577309453.653000000 1099.49 -3.7268001e-05 0.000174114 -1577309455.192000000 1099.64 -2.3082001e-05 0.00016051601 -1577309456.375000000 1099.79 -6.1840101e-06 0.000153103 -1577309457.806000000 1099.9399 5.50601e-06 0.00013426 -1577309459.218000000 1100.09 1.70321e-05 0.000140705 -1577309460.625000000 1100.24 1.8075199e-05 0.000135743 -1577309462.106000000 1100.39 2.6546501e-05 0.00012426201 -1577309463.518000000 1100.54 4.26027e-05 0.000112996 -1577309464.922000000 1100.6899 3.6314399e-05 9.5196498e-05 -1577309466.334000000 1100.84 4.8399201e-05 9.2432398e-05 -1577309467.744000000 1100.99 4.98521e-05 8.3961102e-05 -1577309469.154000000 1101.15 5.3212301e-05 7.8693498e-05 -1577309470.950000000 1101.3 5.5417699e-05 7.2539297e-05 -1577309472.165000000 1101.45 6.2622603e-05 6.9931601e-05 -1577309473.329000000 1101.6 6.3270803e-05 6.4254302e-05 -1577309475.247000000 1101.75 6.3762498e-05 6.1885003e-05 -1577309476.674000000 1101.9 7.0892696e-05 5.9128e-05 -1577309477.985000000 1102.05 7.5251301e-05 5.3867901e-05 -1577309479.389000000 1102.2 7.4536103e-05 5.11783e-05 -1577309481.185000000 1102.35 7.57952e-05 4.6298101e-05 -1577309482.621000000 1102.5 7.70767e-05 4.2751701e-05 -1577309484.031000000 1102.65 8.1345897e-05 4.14776e-05 -1577309485.496000000 1102.8 8.0049504e-05 3.6031201e-05 -1577309486.909000000 1102.95 8.2455997e-05 3.3341599e-05 -1577309488.197000000 1103.11 7.9848302e-05 2.9176599e-05 -1577309489.603000000 1103.26 8.1547099e-05 2.7358599e-05 -1577309491.020000000 1103.41 8.7895001e-05 2.5093699e-05 -1577309492.437000000 1103.5601 8.6330299e-05 2.4154901e-05 -1577309493.851000000 1103.71 8.6337801e-05 1.91407e-05 -1577309495.281000000 1103.86 8.8997702e-05 1.66149e-05 -1577309496.455000000 1104.01 9.1389302e-05 1.43722e-05 -1577309497.864000000 1104.16 9.1866103e-05 1.35527e-05 -1577309499.303000000 1104.3101 8.9370202e-05 1.50055e-05 -1577309500.713000000 1104.46 9.3818198e-05 1.14069e-05 -1577309502.141000000 1104.61 9.4578099e-05 8.8588004e-06 -1577309503.557000000 1104.76 9.1389302e-05 7.8380699e-06 -1577309506.402000000 1104.91 9.4771902e-05 3.7849099e-06 -1577309507.576000000 1105.0699 9.4146002e-05 2.0712801e-06 -1577309509.013000000 1105.22 9.5546697e-05 3.89668e-06 -1577309510.422000000 1105.37 9.97116e-05 1.8105e-06 -1577309512.094000000 1105.52 9.5449897e-05 -3.12926e-06 -1577309513.408000000 1105.67 9.8914403e-05 -5.1483798e-06 -1577309514.813000000 1105.8199 9.7163502e-05 -6.1095102e-06 -1577309516.234000000 1105.97 9.6939999e-05 -8.3000004e-06 -1577309517.642000000 1106.12 9.7632903e-05 -8.8439001e-06 -1577309518.993000000 1106.27 9.8191696e-05 -5.90834e-06 -1577309520.407000000 1106.42 9.9264602e-05 -1.06618e-05 -1577309521.813000000 1106.5699 0.000100613 -9.6411104e-06 -1577309523.229000000 1106.72 9.9875499e-05 -1.27331e-05 -1577309524.639000000 1106.87 0.000103117 -1.25543e-05 -1577309526.065000000 1107.03 9.6157703e-05 -1.20551e-05 -1577309527.745000000 1107.1801 9.8675999e-05 -2.1301301e-05 -1577309529.159000000 1107.33 0.000100829 -1.99304e-05 -1577309530.597000000 1107.48 9.7863798e-05 -1.65479e-05 -1577309532.006000000 1107.63 9.9488097e-05 -1.8105e-05 -1577309533.459000000 1107.78 0.000100829 -1.6853301e-05 -1577309534.810000000 1107.9301 9.6656797e-05 -1.93493e-05 -1577309536.230000000 1108.08 0.000100591 -2.26871e-05 -1577309537.804000000 1108.23 0.000103698 -2.18899e-05 -1577309539.220000000 1108.38 0.000104055 -2.31714e-05 -1577309540.646000000 1108.53 0.000103117 -2.13162e-05 -1577309542.983000000 1108.6801 0.000105009 -2.6412399e-05 -1577309544.398000000 1108.83 0.000103936 -2.46243e-05 -1577309545.878000000 1108.98 0.000103295 -2.53321e-05 -1577309547.292000000 1109.14 0.000102185 -2.71426e-05 -1577309548.600000000 1109.29 9.7342301e-05 -2.48776e-05 -1577309550.017000000 1109.4399 0.000101999 -2.64795e-05 -1577309551.298000000 1109.59 0.000102379 -2.6956301e-05 -1577309552.744000000 1109.74 0.000103251 -2.67328e-05 -1577309554.168000000 1109.89 0.000104718 -3.1486401e-05 -1577309555.513000000 1110.04 0.000104115 -2.9511901e-05 -1577309556.919000000 1110.1899 0.000100434 -3.02644e-05 -1577309558.369000000 1110.34 0.000102953 -3.0867999e-05 -1577309560.940000000 1110.49 0.000102476 -2.96013e-05 -1577309562.381000000 1110.64 0.000103139 -3.1858901e-05 -1577309563.790000000 1110.79 0.000108377 -3.1911099e-05 -1577309565.108000000 1110.9399 0.00010176 -3.4541099e-05 -1577309566.522000000 1111.1 0.000102662 -3.11064e-05 -1577309567.964000000 1111.25 0.000104122 -3.1694999e-05 -1577309569.401000000 1111.4 0.000105389 -3.2112199e-05 -1577309570.813000000 1111.55 0.000106045 -3.3185101e-05 -1577309572.097000000 1111.7 0.000105083 -3.6105699e-05 -1577309573.821000000 1111.85 0.000101805 -3.6090802e-05 -1577309575.225000000 1112 0.000104398 -3.68732e-05 diff --git a/fit_res/fit.c b/fit_res/fit.c deleted file mode 100644 index 0deb86d..0000000 --- a/fit_res/fit.c +++ /dev/null @@ -1,339 +0,0 @@ -#include -#include -#include -#include -#include -#include -//#include -//#include - -/********************************************************************/ - -// modified Gaussian example from -//https://www.gnu.org/software/gsl/doc/html/nls.html#c.gsl_multifit_nlinear_fdf - -struct data { - double *w; - double *x; - double *y; - size_t n; -}; - -/* model function: - -(X + iY) = (A + iB) + (C + iD)/(w0^2 - w^2 - iw*dw) - -X(w) = A + (C*(w0^2-w^2) + D*w*dw) / ((w0^2-w^2)^2 + (w*dw)^2) -Y(w) = B + (D*(w0^2-w^2) - C*w*dw) / ((w0^2-w^2)^2 + (w*dw)^2) - -*/ - -int -func_f (const gsl_vector * x, void *params, gsl_vector * f) { - struct data *d = (struct data *) params; - double A = gsl_vector_get(x, 0); - double B = gsl_vector_get(x, 1); - double C = gsl_vector_get(x, 2); - double D = gsl_vector_get(x, 3); - double w0 = gsl_vector_get(x, 4); - double dw = gsl_vector_get(x, 5); - size_t i; - - for (i = 0; i < d->n; ++i) { - double wi = d->w[i]; - double Xi = d->x[i]; - double Yi = d->y[i]; - - double wa = w0*w0 - wi*wi; - double wb = wi*dw; - double z = wa*wa + wb*wb; - double X = A + (C*wa + D*wb)/z; - double Y = B + (D*wa - C*wb)/z; - - gsl_vector_set(f, 2*i, Xi - X); - gsl_vector_set(f, 2*i+1, Yi - Y); - } - - return GSL_SUCCESS; -} - - -// function derivatives -int -func_df (const gsl_vector * x, void *params, gsl_matrix * J) { - struct data *d = (struct data *) params; - double A = gsl_vector_get(x, 0); - double B = gsl_vector_get(x, 1); - double C = gsl_vector_get(x, 2); - double D = gsl_vector_get(x, 3); - double w0 = gsl_vector_get(x, 4); - double dw = gsl_vector_get(x, 5); - size_t i; - - for (i = 0; i < d->n; ++i) { - double wi = d->w[i]; - double Xi = d->x[i]; - double Yi = d->y[i]; - - double wa = w0*w0 - wi*wi; - double wb = wi*dw; - double z = wa*wa + wb*wb; - - gsl_matrix_set(J, 2*i, 0, -1); - gsl_matrix_set(J, 2*i, 1, 0); - gsl_matrix_set(J, 2*i, 2, -wa/z); - gsl_matrix_set(J, 2*i, 3, -wb/z); - gsl_matrix_set(J, 2*i, 4, -2*C*w0/z + (C*wa+D*wb)/z/z * 4*wa*w0); - gsl_matrix_set(J, 2*i, 5, -D*wi/z + (C*wa+D*wb)/z/z * 2*wb*wi); - - gsl_matrix_set(J, 2*i+1, 0, 0); - gsl_matrix_set(J, 2*i+1, 1, -1); - gsl_matrix_set(J, 2*i+1, 2, wb/z); - gsl_matrix_set(J, 2*i+1, 3, -wa/z); - gsl_matrix_set(J, 2*i+1, 4, -2*D*w0/z + (D*wa-C*wb)/z/z * 4*wa*w0); - gsl_matrix_set(J, 2*i+1, 5, +C*wi/z + (D*wa-C*wb)/z/z * 2*wb*wi); - } - - return GSL_SUCCESS; -} - -/* -// Additional derivatives for the accelerated method -// (see fdf_params.trs = gsl_multifit_nlinear_trs_lmaccel) -int -func_fvv (const gsl_vector * x, const gsl_vector * v, - void *params, gsl_vector * fvv) -{ - struct data *d = (struct data *) params; - double a = gsl_vector_get(x, 0); - double b = gsl_vector_get(x, 1); - double c = gsl_vector_get(x, 2); - double va = gsl_vector_get(v, 0); - double vb = gsl_vector_get(v, 1); - double vc = gsl_vector_get(v, 2); - size_t i; - - for (i = 0; i < d->n; ++i) { - double ti = d->t[i]; - double zi = (ti - b) / c; - double ei = exp(-0.5 * zi * zi); - double Dab = -zi * ei / c; - double Dac = -zi * zi * ei / c; - double Dbb = a * ei / (c * c) * (1.0 - zi*zi); - double Dbc = a * zi * ei / (c * c) * (2.0 - zi*zi); - double Dcc = a * zi * zi * ei / (c * c) * (3.0 - zi*zi); - double sum; - - sum = 2.0 * va * vb * Dab + - 2.0 * va * vc * Dac + - vb * vb * Dbb + - 2.0 * vb * vc * Dbc + - vc * vc * Dcc; - - gsl_vector_set(fvv, i, sum); - } - - return GSL_SUCCESS; -} -*/ - -/********************************************************************/ - -void -callback(const size_t iter, void *params, - const gsl_multifit_nlinear_workspace *w) { - - /* - - gsl_vector *f = gsl_multifit_nlinear_residual(w); - gsl_vector *x = gsl_multifit_nlinear_position(w); - double avratio = gsl_multifit_nlinear_avratio(w); - double rcond; - - (void) params; // not used - - // compute reciprocal condition number of J(x) - gsl_multifit_nlinear_rcond(&rcond, w); - - fprintf(stderr, "iter %2zu: a = %.4f, b = %.4f, c = %.4f, |a|/|v| = %.4f cond(J) = %8.4f, |f(x)| = %.4f\n", - iter, - gsl_vector_get(x, 0), - gsl_vector_get(x, 1), - gsl_vector_get(x, 2), - avratio, - 1.0 / rcond, - gsl_blas_dnrm2(f)); - */ -} - -double -solve_system(gsl_vector *x, gsl_vector *xe, gsl_multifit_nlinear_fdf *fdf, - gsl_multifit_nlinear_parameters *params) { - - const gsl_multifit_nlinear_type *T = gsl_multifit_nlinear_trust; - - const size_t max_iter = 200; - const double xtol = 1.0e-10; - const double gtol = 1.0e-10; - const double ftol = 1.0e-10; - - const size_t n = fdf->n; - const size_t p = fdf->p; - - gsl_multifit_nlinear_workspace *work = - gsl_multifit_nlinear_alloc(T, params, n, p); - gsl_vector * f = gsl_multifit_nlinear_residual(work); - gsl_vector * y = gsl_multifit_nlinear_position(work); - - - int info; - double chisq0, chisq, rcond; - size_t i; - - - /* initialize solver */ - gsl_multifit_nlinear_init(x, fdf, work); - - /* store initial cost */ - gsl_blas_ddot(f, f, &chisq0); - - /* iterate until convergence */ - gsl_multifit_nlinear_driver(max_iter, xtol, gtol, ftol, - callback, NULL, &info, work); - - /* store final cost */ - gsl_blas_ddot(f, f, &chisq); - - /* store cond(J(x)) */ - gsl_multifit_nlinear_rcond(&rcond, work); - - gsl_vector_memcpy(x, y); - - /* compute parameter errors (see first example in - https://www.gnu.org/software/gsl/doc/html/nls.html ) */ - { - gsl_matrix *covar = gsl_matrix_alloc (p, p); - gsl_matrix *J = gsl_multifit_nlinear_jac(work); - double c = sqrt(chisq / (n-p)); - gsl_multifit_nlinear_covar (J, 0.0, covar); - - for (i=0; inevalf); - fprintf(stderr, "Jacobian evaluations: %zu\n", fdf->nevaldf); - fprintf(stderr, "reason for stopping: %s\n", - (info == 1) ? "small step size" : "small gradient"); - fprintf(stderr, "initial |f(x)| = %f\n", sqrt(chisq0)); - fprintf(stderr, "final |f(x)| = %f\n", sqrt(chisq)); - */ - - gsl_multifit_nlinear_free(work); - return sqrt(chisq/n); -} - -/********************************************************************/ -// Find initial conditions by some trivial assumptions. - -void -fit_res_init (const size_t n, - double * freq, double * real, double * imag, - double pars[6]) { - - // A,B - in the middle between first and last point: - double A = (real[0] + real[n-1])/2; - double B = (imag[0] + imag[n-1])/2; - - // Find furthest point from (A,B), - // It should be the resonance - double dmax=0; - size_t imax=0; - for (size_t i = 0; idmax) {dmax=d; imax=i;} - } - double w0 = freq[imax]; - - // Find dmax/sqrt(2) distance. It should be - // maxima of dispersion component - int ih1=0, ih2=n-1; - for (size_t i = 0; idmax/sqrt(2)) {ih1=i; break;} - } - for (size_t i = n-1; i>=imax; i--) { - double d = hypot(real[i]-A, imag[i]-B); - if (d>dmax/sqrt(2)) {ih2=i; break;} - } - double dw = (freq[ih2]-freq[ih1]); - - // amplitudes: - double D = freq[imax]*dw*(real[imax]-A); - double C = -freq[imax]*dw*(imag[imax]-B); - - pars[0] = A; - pars[1] = B; - pars[2] = C; - pars[3] = D; - pars[4] = w0; - pars[5] = dw; -} - -/********************************************************************/ -// Fit resonance with Lorentzian curve -double -fit_res (const size_t n, - double * freq, double * real, double * imag, - double pars[6], double pars_e[6]) { - - const size_t p = 6; /* number of model parameters */ - - gsl_vector *f = gsl_vector_alloc(2*n); - gsl_vector *x = gsl_vector_alloc(p); - gsl_vector *xe = gsl_vector_alloc(p); - gsl_multifit_nlinear_fdf fdf; - gsl_multifit_nlinear_parameters fdf_params = - gsl_multifit_nlinear_default_parameters(); - size_t i; - struct data fit_data; - - fit_data.n = n; - fit_data.w = freq; - fit_data.x = real; - fit_data.y = imag; - - /* define function to be minimized */ - fdf.f = func_f; - fdf.df = func_df; // NULL; - fdf.fvv = NULL; //func_fvv; - fdf.n = 2*n; - fdf.p = p; - fdf.params = & fit_data; - - /* starting point */ - for (i=0; i -#include - -#include -#include -#include -#include -#include -#include "math.h" - -#include "fit.h" - -/* - Program reads resonance data (time, freq, x, y) from stdin, - fits data with a Lorentzian function: - (X + iY) = (A + iB) + (C + iD)/(w0^2 - w^2 - iw*dw) - - and prints a line with 14 values to stdout: - - time -- center of the time range - - function error -- mean square difference between data and fit - - A, A_error, B, B_error -- shift in x and y component - - C, C_error, D, D_error -- driving force (not amplitude! - - w0, w0_error == resonance frequency (in Hz or rad/s depending on input data) - - dw, dw_error -- width at 1/2 height of amplitude curve, - or (approximately) distance between dispersion minimum - and maximum. If frequency data is in rad/s then df=2/tau, - if data in Hz then df = pi/tau - -The program can be used as a filter in -graphene_filter script. - -*/ - -int -main (int argc, char *argv[]) { - - // Note: graphene_filter can add command line arguments! - - std::vector freq, real, imag, time; - std::vector pars(6), pars_e(6); - - // - bool overload_detection = true; - - double maxx=0, maxy=0; - while (!std::cin.eof()){ - std::string l; - getline(std::cin, l); - - std::istringstream ss(l); - double t,f,x,y; - ss >> t >> f >> x >> y; - time.push_back(t); - freq.push_back(f); - real.push_back(x); - imag.push_back(y); - - // find maximum - for overload detection - if (fabs(x)>maxx) maxx=fabs(x); - if (fabs(y)>maxy) maxy=fabs(y); - } - - if (freq.size()<6) return 0; - - // initial guess: - fit_res_init(freq.size(), - freq.data(), real.data(), imag.data(), - pars.data()); - - // fit - double func_e = fit_res(freq.size(), - freq.data(), real.data(), imag.data(), - pars.data(), pars_e.data()); - - - // overload detection (remove largest values and compare result) - if (overload_detection) { - std::vector freq1, real1, imag1; - std::vector pars1(pars), pars_e1(6); - for (int i=0; i maxx*0.95 || fabs(imag[i]) > maxy*0.95) continue; - freq1.push_back(freq[i]); - real1.push_back(real[i]); - imag1.push_back(imag[i]); - } - if (freq1.size() >= 6) { - double func_e1 = fit_res(freq1.size(), - freq1.data(), real1.data(), imag1.data(), - pars1.data(), pars_e1.data()); - if (func_e1 < func_e) { - pars.swap(pars1); - pars_e.swap(pars_e1); - func_e = func_e1; - } - } - } - - double t = (*time.begin() + *time.rbegin())/2; - - std::cout << std::setprecision(14) - << std::fixed << " " << t - << std::scientific - << " " << func_e; - for (size_t i = 0; i<6; i++) { - std::cout << " " << pars[i] - << " " << pars_e[i]; - } - - std::cout << "\n"; - return 0; -} diff --git a/fit_res/misc/.gitignore b/fit_res/misc/.gitignore deleted file mode 100644 index a4c0bb2..0000000 --- a/fit_res/misc/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.dat -*.o -mk_res_sig -split_sweeps \ No newline at end of file diff --git a/fit_res/misc/Makefile b/fit_res/misc/Makefile deleted file mode 100644 index 5fac774..0000000 --- a/fit_res/misc/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -LDLIBS = -lgsl -lm - -CC=g++ - -all: split_sweeps mk_res_sig - - -clean: - rm -f split_sweeps *.o - - -split_sweeps: split_sweeps.o - diff --git a/fit_res/misc/mk_res_sig.c b/fit_res/misc/mk_res_sig.c deleted file mode 100644 index aff07af..0000000 --- a/fit_res/misc/mk_res_sig.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include - -#include -#include - -// Make signal sutable for fit_res. -// Signal contains gaussian noise with sigma=0.1 -// Same value should appear in f_error value -// of res_fit output - -int -main (void) { - const size_t n = 300; /* number of data points */ - - double A = 1.1; - double B = 0.1; - double C = 3000.2; - double D = 2.2; - double w0 = 1023; - double dw = 11; - - double noise_s = 0.1; - - /* generate synthetic data with noise */ - { - int i; - gsl_rng * r; - const gsl_rng_type * T = gsl_rng_default; - gsl_rng_env_setup (); - r = gsl_rng_alloc (T); - - for (i = 0; i < n; ++i) { - - double wi = w0 + 3*dw*( (double)i / (double) n - 0.5); - double wa = w0*w0 - wi*wi; - double wb = wi*dw; - double z = wa*wa + wb*wb; - double X = A + (C*wa + D*wb)/z; - double Y = B + (D*wa - C*wb)/z; - - double Nx = gsl_ran_gaussian (r, noise_s); - double Ny = gsl_ran_gaussian (r, noise_s); - - printf("%d %e %e %e\n", i, wi, X + Nx, Y+Ny); - } - gsl_rng_free(r); - - } - - return 0; -} diff --git a/fit_res/misc/split_sweeps.cpp b/fit_res/misc/split_sweeps.cpp deleted file mode 100644 index dd2b634..0000000 --- a/fit_res/misc/split_sweeps.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#include -#include -#include -#include - -void -process_data(const std::vector & data){ - for (int i=0; i data; - - double fprev=0, fdiff=0; - int nall=0, nswp=0; - - while (!std::cin.eof()){ - std::string l; - getline(std::cin, l); - - std::istringstream ss(l); - double f; - ss >> f; - - // reset sweep - if (nswp>0 && (f-fprev)*fdiff <= 0){ - - nswp = 0; - fdiff = f-fprev; - if (data.size()>2) process_data(data); - data.clear(); - data.push_back(fprev); - } - else { - fdiff = f-fprev; - } - - - data.push_back(f); - nall++; - nswp++; - fprev=f; - } - if (data.size()>2) process_data(data); - data.clear(); - - std::cout << "\n"; - return 0; -} diff --git a/fit_res/misc/split_sweeps_test b/fit_res/misc/split_sweeps_test deleted file mode 100755 index 4e65327..0000000 --- a/fit_res/misc/split_sweeps_test +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -./split_sweeps < should be a source .test.cpp and # a script .test.script -# OTHER_TESTS -- Any programs or scripts which shoukld be run after building +# OTHER_TESTS -- Any programs or scripts which should be run after building +# PKG_CONFIG -- external libraries used in this module, controlled by +# pkg-config. Default path includes +# $(PKG_CONFIG_PATH) and $(MODDIR)/pc +# LDLIBS, LDFLAGS, CXXFLAGS, etc. -- standard Makefile variables ###################################################### MODDIR ?= .. @@ -25,7 +29,7 @@ MOD_STATIC := MOD_OBJECTS := ifdef MOD_HEADERS - MOD_NAME := $(shell a=$$(pwd); echo $${a\#\#*/}) + MOD_NAME := $(notdir $(shell pwd)) MOD_STATIC := $(MOD_NAME).a endif ifdef MOD_SOURCES @@ -35,49 +39,45 @@ endif SHARED_LIB_SO := $(patsubst %, %.so, $(SHARED_LIB)) ###################################################### -# Dependency search for ALL_SOURCES +# Main building rules +all: make_deps make_nodeps +clean: + rm -f *.o *.a *.so *.test *.passed Makefile.deps $(PROGRAMS) -ALL_SOURCES += $(MOD_SOURCES) $(MOD_HEADERS) -ALL_SOURCES += $(patsubst %,%.test.cpp, $(SIMPLE_TESTS)) -ALL_SOURCES += $(patsubst %,%.test.cpp, $(SCRIPT_TESTS)) -ALL_SOURCES += $(patsubst %,%.cpp, $(PROGRAMS)) +###################################################### +# Build and include dependency file (using get_deps script). +$(shell $(MODDIR)/get_deps $(MODDIR) . > Makefile.deps) +ifneq (${.SHELLSTATUS},0) +$(error "get_deps failed: ${.SHELLSTATUS}") +endif +-include Makefile.deps -# Extract #include statements from MOD_SOURCES and MOD_HEADERS: -HDEPS := $(shell cat $(ALL_SOURCES) |\ - sed -rne 's|^\#include +"([^/]*/[^/]*)".*|$(MODDIR)/\1|p'\ - | sort -u) +###################################################### +# Building flags +# user-defined flags are added _after_ this -# List of modules which should be rebuilt (in correct order). -# Here an extenal script is used (get_deps). It is also possble -# to build the list similarly to HDEPS and then visit all modules -# recursively, but then one module can be visited many times. -MDEPS := $(shell $(MODDIR)/get_deps $(MODDIR) $(ALL_SOURCES)) -# a-files (should be in opposite order then MDEPS) -ADEPS := $(shell for i in $(MDEPS); do echo $(MODDIR)/$$i/$${i\#*/}.a; done | tac) +override CXXFLAGS_ += $(shell [ "$(PKG_CONFIG)" = "" ] ||\ + PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(MODDIR)/pc\ + pkg-config --cflags '$(PKG_CONFIG)') +override LDLIBS_ += $(shell [ "$(PKG_CONFIG)" = "" ] ||\ + PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(MODDIR)/pc\ + pkg-config --libs '$(PKG_CONFIG)') -###################################################### -# Building flags +override CXXFLAGS_ += -std=gnu++11 -Werror=return-type -O2 -fPIC -I$(MODDIR) -override CXXFLAGS += $(shell [ "$(PKG_CONFIG)" == "" ] ||\ - pkg-config --cflags '$(PKG_CONFIG)') -override LDLIBS += $(shell [ "$(PKG_CONFIG)" == "" ] ||\ - pkg-config --libs '$(PKG_CONFIG)') -override CXXFLAGS += -std=gnu++11 -Werror=return-type -O2 -fPIC -override CXXFLAGS += -I$(MODDIR) +CXXFLAGS := $(CXXFLAGS_) $(CXXFLAGS) +LDLIBS := $(LDLIBS_) $(LDLIBS) ###################################################### -# Building rules -all: make_deps make_nodeps -make_nodeps: $(MOD_STATIC) $(PROGRAMS) $(SHARED_LIB_SO) make_tests -clean: - rm -f *.o *.a *.so *.test *.passed $(PROGRAMS) - +# make_deps/make_nodeps building rules: make_deps: @echo "## Building dependencies: [$(MDEPS)]" - @for i in $(MDEPS); do $(MAKE) -C $(MODDIR)/$$i make_nodeps; done + @sh -e -c 'for i in $(MDEPS); do $(MAKE) -C $(MODDIR)/$$i make_nodeps; done' @echo "## Finish building dependencies" +make_nodeps: $(MOD_STATIC) $(PROGRAMS) $(SHARED_LIB_SO) make_tests + ###################################################### # Building rules for tests SIMPLE_TEST_PROGS := $(patsubst %, %.test, $(SIMPLE_TESTS)) @@ -90,44 +90,44 @@ $(SCRIPT_TEST_RES): TEST_DEP := %.test.script $(SIMPLE_TEST_RES): TEST_CMD = ./$< && > $<.passed $(SCRIPT_TEST_RES): TEST_CMD = ./$<.script && > $<.passed -TEST_OBJECTS += $(patsubst %,%.o, $(SIMPLE_TESTS) $(SCRIPT_TESTS)) +TEST_OBJECTS := $(patsubst %,%.test.o, $(SIMPLE_TESTS) $(SCRIPT_TESTS)) $(SIMPLE_TEST_PROGS) $(SCRIPT_TEST_PROGS): CC:=$(CXX) $(SIMPLE_TEST_PROGS) $(SCRIPT_TEST_PROGS): %: %.o $(MOD_OBJECTS) $(ADEPS) -$(TEST_OBJECTS): %.o: %.cpp $(MOD_HEADERS) $(HDEPS) +$(TEST_OBJECTS): %.o: %.cpp %.test.passed: %.test $(TEST_DEP) @echo "## Running test: $<" @$(TEST_CMD) make_tests: $(SIMPLE_TEST_RES) $(SCRIPT_TEST_RES) - @for i in $(OTHER_TESTS); do echo "## Running test: $$i"; ./$$i; done + @sh -e -c 'for i in $(OTHER_TESTS); do echo "## Running test: $$i"; ./$$i; done' ###################################################### # building rules for programs and shared lib -PROG_OBJECTS += $(patsubst %,%.o, $(PROGRAMS)) +PROG_OBJECTS := $(patsubst %,%.o, $(PROGRAMS)) $(PROGRAMS): CC:=$(CXX) $(PROGRAMS): %: %.o $(MOD_OBJECTS) $(ADEPS) -$(PROG_OBJECTS): %.o: %.cpp $(MOD_HEADERS) $(HDEPS) +$(PROG_OBJECTS): %.o: %.cpp $(SHARED_LIB_SO): %.so: $(MOD_OBJECTS) $(ADEPS) $(CXX) -shared $(LDFLAGS) $+ $(LDLIBS) -o $@ ###################################################### # Building rules for module static library -$(MOD_OBJECTS): $(MOD_HEADERS) $(HDEPS) $(MOD_STATIC): $(MOD_OBJECTS) ar crs $@ $+ ###################################################### -print_info: +info: @echo "###########################" @echo "## Module <<$(MOD_NAME)>>" @echo "MOD_STATIC: $(MOD_STATIC)" @echo "MOD_SOURCES: $(MOD_SOURCES)" @echo "MOD_HEADERS: $(MOD_HEADERS)" - @echo "HDEPS: $(HDEPS)" @echo "MDEPS: $(MDEPS)" @echo "ADEPS: $(ADEPS)" - @echo "LDLIBS: $(LDLIBS)" + @echo "LDEPS: $(LDEPS)" @echo "SIMPLE_TESTS: $(SIMPLE_TESTS)" @echo "SCRIPT_TESTS: $(SCRIPT_TESTS)" + @echo "LDLIBS: $(LDLIBS)" + @echo "CXXFLAGS: $(CXXFLAGS)" diff --git a/modules/err/Makefile b/modules/err/Makefile index e9b74fc..a96672b 100644 --- a/modules/err/Makefile +++ b/modules/err/Makefile @@ -1,5 +1,4 @@ -MOD_HEADERS := err.h -MOD_SOURCES := -SIMPLE_TESTS := err +MOD_HEADERS := err.h assert_err.h +SIMPLE_TESTS := err assert_err include ../Makefile.inc diff --git a/modules/err/Readme b/modules/err/Readme deleted file mode 100644 index d7c6944..0000000 --- a/modules/err/Readme +++ /dev/null @@ -1,8 +0,0 @@ -================================================== -Human-readable text exceptions (with optional error codes) - -================================================== -Changelog: - -2019.05.02 V.Zavjalov 1.0: -- First version (used widely in many of my projects) diff --git a/modules/err/Readme.md b/modules/err/Readme.md new file mode 100644 index 0000000..59db07b --- /dev/null +++ b/modules/err/Readme.md @@ -0,0 +1,45 @@ +## Err class + +Human-readable text exceptions (with optional error codes) + +- Throwing an error: +```c +throw Err() << "some message"; +``` + +- Catching and printing error: +```c +catch (Err E){ cerr << "Error: " << E.str() << "\n"; } +``` + +- Integer error code can be set as an optional constructor parameter + and extracted by `code` method: `E.code()`. Default code is -1. +```c +try {throw Err(1); } catch (Err E) {int code=E.code();} +``` + +## assert_err macro + +``` +#include "err/assert_err.h" +assert_err(, ) +``` + + +------------------ +## Changelog: +2020.09.18 V.Zavjalov 1.3: +- Add Err::operator= + +2020.08.13 V.Zavjalov 1.2.5: +- err: add std::exception interface + +2019.10.10 V.Zavjalov 1.2: +- Add assert_eq, assert_deq, and assert_feq macro +- Print more information in assert_* + +2019.08.16 V.Zavjalov 1.1: +- Add assert_err macro + +2019.05.02 V.Zavjalov 1.0: +- First version (used widely in many of my projects) diff --git a/modules/err/assert_err.h b/modules/err/assert_err.h new file mode 100644 index 0000000..a9eed85 --- /dev/null +++ b/modules/err/assert_err.h @@ -0,0 +1,64 @@ +#ifndef ASSERT_ERR_H +#define ASSERT_ERR_H + +///\addtogroup libmapsoft +///@{ + +#include // fabs +#include "err.h" + +// assert_err macro + +#define assert_err(cmd,ret)\ + {try{\ + cmd;\ + throw Err(-9999)\ + << "assert_err: " << __FILE__ << ":" << __LINE__ << ": error is not thrown:\n"\ + << "command: " << #cmd << "\n"\ + << "expected error: " << (ret)<< "\n";\ + } catch (Err & e) {\ + if (e.code()==-9999) throw;\ + if (e.str()!=(ret)){\ + throw Err()\ + << "assert_err: " << __FILE__ << ":" << __LINE__ << ": wrong error message:\n"\ + << "command: " << #cmd << "\n"\ + << "expected error: " << (ret) << "\n"\ + << "actual error: " << e.str()<< "\n";\ + }\ + }} + +// catch an error and check it +#define assert_eq(v1,v2)\ + {if ((v1) != (v2)){\ + throw Err()\ + << "assert_eq: " << __FILE__ << ":" << __LINE__ << ": arguments are not equal:\n"\ + << "v1: " << #v1 << "\n"\ + << " " << (v1) << "\n"\ + << "v2: " << #v2 << "\n"\ + << " " << (v2) << "\n";\ + }} + +// compare two double values and check that difference is less then e +#define assert_feq(v1,v2,e)\ + {if (fabs((v1) - (v2)) > e){\ + throw Err()\ + << "assert_feq: " << __FILE__ << ":" << __LINE__ << ": arguments are not equal:\n"\ + << "v1: " << #v1 << "\n"\ + << " " << (v1) << "\n"\ + << "v2: " << #v2 << "\n"\ + << " " << (v2) << "\n";\ + }} + +// compare two objects with a dist(a,b) function, check thet the result is less then e +#define assert_deq(v1,v2,e)\ + {if (dist((v1),(v2)) > e){\ + throw Err()\ + << "assert_feq: " << __FILE__ << ":" << __LINE__ << ": arguments are not equal:\n"\ + << "v1: " << #v1 << "\n"\ + << " " << (v1) << "\n"\ + << "v2: " << #v2 << "\n"\ + << " " << (v2) << "\n";\ + }} + +///@} +#endif diff --git a/modules/err/assert_err.test.cpp b/modules/err/assert_err.test.cpp new file mode 100644 index 0000000..9345be4 --- /dev/null +++ b/modules/err/assert_err.test.cpp @@ -0,0 +1,53 @@ +///\cond HIDDEN (do not show this in Doxyden) + +#include +#include "assert_err.h" + +void errorfunc(){ + throw Err() << "some error"; +} + +void nonerrorfunc(){} + +double dist(double v1, double v2){return fabs(v1-v2);} + +int +main(){ + try{ + assert_err(errorfunc(), "some error"); + +// assert_err(errorfunc(), "some error1"); +// assert_err(nonerrorfunc(), "some error"); + + assert_err(throw Err() << "eee", "eee"); + + assert_eq(10, 10); + assert_eq(20-10, 10); + assert_eq(10, 20-10); + + assert_feq(10.0, 10.0, 1e-6); + assert_feq(10.1, 10.2, 0.2); + assert_feq(10.2, 10.1, 0.2); + + assert_feq(1, 2-1, 1e-6); + assert_feq(2-1, 1, 1e-6); + + // using dist() function + assert_deq(10.0, 10.0, 1e-6); + assert_deq(10.1, 10.2, 0.2); + assert_deq(10.2, 10.1, 0.2); + + assert_deq(1, 2-1, 1e-6); + assert_deq(2-1, 1, 1e-6); + + + + } + catch (Err & e) { + std::cerr << "Error: " << e.str() << "\n"; + return 1; + } + return 0; +} + +///\endcond \ No newline at end of file diff --git a/modules/err/err.h b/modules/err/err.h index cddf844..2f13213 100644 --- a/modules/err/err.h +++ b/modules/err/err.h @@ -7,6 +7,8 @@ #include #include #include +#include + /***********************************************************/ /** A simple class for exceptions. @@ -32,20 +34,33 @@ catch (Err E){ ``` */ -class Err { +class Err: public std::exception { std::ostringstream s; // stream for error messages + + // This buf string is here only because of std::exception interface. + // To return `const char*` we need some place where to keep + // the message until Err object exists. Unfortunately we + // can not fill the buffer in what() method because it is + // marked as const. + std::string buf; + int c; public: /// Constructor with optional error code. - Err(int c_ = -1): c(c_) {} + Err(int c_ = -1): s(std::ostringstream::ate), c(c_) {} /// Copy constructor. - Err(const Err & o) { c=o.c; s << o.s.str(); } + Err(const Err & o): s(std::ostringstream::ate) { + c=o.c; s.str(o.s.str()); buf = s.str();} + + /// operator= + Err operator=(const Err & o) {c=o.c; s.str(o.s.str()); buf = o.buf; return *this;} + /// Operator << for error messages. template - Err & operator<<(const T & o){ s << o; return *this; } + Err & operator<<(const T & o){ s << o; buf = s.str(); return *this; } /// Get error code. int code() const {return c;} @@ -53,6 +68,9 @@ class Err { /// Get error message. std::string str() const { return s.str(); } + const char* what() const noexcept override { + return buf.c_str(); } + }; ///@} diff --git a/modules/err/err.test.cpp b/modules/err/err.test.cpp index 635f665..ea1067c 100644 --- a/modules/err/err.test.cpp +++ b/modules/err/err.test.cpp @@ -5,10 +5,41 @@ int main(){ + + Err e1(12); e1 << "123"; + Err e2(e1); + Err e3; e3 << "234"; + e3 = e1; + assert(e1.str()=="123"); + assert(e2.str()=="123"); + assert(e3.str()=="123"); + e3 << "234"; + assert(e3.str()=="123234"); + + assert(e1.code()==12); + assert(e2.code()==12); + assert(e3.code()==12); + + // copy constructor test + e3 = Err() << "aaaa"; + e3 << "mm"; + assert(e3.str()=="aaaamm"); + e3 << "xx"; + assert(e3.str()=="aaaammxx"); + try { + try { throw e3;} + catch (Err & e) { e << "yy"; throw;} + } + catch (Err & e) { + assert(e.str() == "aaaammxxyy"); + } + + + try { throw Err() << "text " << 123; } - catch (Err E){ + catch (Err & E){ assert (E.str() == "text 123"); assert (E.code() == -1); } @@ -16,11 +47,22 @@ main(){ try { throw Err(3) << "text " << 123; } - catch (Err E){ + catch (Err & E){ assert (E.str() == "text 123"); assert (E.code() == 3); } return 0; + + // std::exception interface test + try { + throw Err(3) << "text " << 123; + } + catch (std::exception & e){ + assert (std::string(e.what()) == "text 123"); + } + return 0; + + } ///\endcond \ No newline at end of file diff --git a/modules/fft/Makefile b/modules/fft/Makefile index fee2046..312e22b 100644 --- a/modules/fft/Makefile +++ b/modules/fft/Makefile @@ -2,5 +2,6 @@ MOD_HEADERS := fft.h MOD_SOURCES := +PKG_CONFIG := fftw3 include ../Makefile.inc diff --git a/modules/fit_signal/Makefile b/modules/fit_signal/Makefile index d52f846..f74c08e 100644 --- a/modules/fit_signal/Makefile +++ b/modules/fit_signal/Makefile @@ -2,6 +2,7 @@ MOD_SOURCES := fit_signal.cpp MOD_HEADERS := fit_signal.h +PKG_CONFIG := fftw3 #SIMPLE_TESTS := fit_signal diff --git a/modules/fit_signal/fit_signal.cpp b/modules/fit_signal/fit_signal.cpp index e49f6dd..151fb47 100644 --- a/modules/fit_signal/fit_signal.cpp +++ b/modules/fit_signal/fit_signal.cpp @@ -28,42 +28,45 @@ vector fit_signal(const int16_t *buf, int len, double sc, double dt, dou fftw_execute(plan); // first step: find max(abs(fft)) - // index limits - int i1f = max(0.0, floor(fmin/df)); + int i1f = max(0, int(floor(fmin/df))); int i2f = min(0.5*len, ceil(fmax/df)); - double vm = hypot(cbuf[i1f][0], cbuf[i1f][1]); + double vm = 0; int im = i1f; - for (int i = i1f; i=vm) {vm=v; im=i;} + double v1 = hypot(cbuf[i-1][0], cbuf[i-1][1]); + double v2 = hypot(cbuf[i+1][0], cbuf[i+1][1]); + if (v>v1 && v>=v2 && v>=vm) {vm=v; im=i;} } - // second step: find parabolic fit near maximum if (im=i2f-1) throw Err() << "Can't find signal frequency"; - double x1 = df*(im-1); - double x2 = df*im; - double x3 = df*(im+1); - double y1 = hypot(cbuf[im-1][0], cbuf[im-1][1]); - double y2 = hypot(cbuf[im ][0], cbuf[im ][1]); - double y3 = hypot(cbuf[im+1][0], cbuf[im+1][1]); - double A = ((y1-y2)/(x1-x2) - (y2-y3)/(x2-x3))/(x1-x3); - double B = (y1-y2)/(x1-x2) - A*(x1+x2); - double C = y1 - A*x1*x1 - B*x1; - // fre - positin of the parabola maximum - // rtau - distance between zero crossings - // amp0 - value in the maximum - double fre = -B/(2*A); - double rtau = -sqrt(B*B-4*A*C)*M_PI/2/A; - double amp0 = C - B*B/(4*A); - + double amp0 = df; + double fre = im*df; // third step: fit 1/fft by a linear function - // adjust index limits - double dff = rtau; - i1f = max(0.0, floor((fre-dff)/df)); - i2f = min(0.5*len, ceil((fre+dff)/df)); + + // Adjust index limits. + // Select range where amplitude is growing from both ends + // towards the maximum at im: + int i1 = im; + while (1){ + if (i1 >= i2f) break; + if (hypot(cbuf[i1][0], cbuf[i1][1]) < + hypot(cbuf[i1+1][0], cbuf[i1+1][1])) break; + i1++; + } + i2f = i1; + + i1 = im; + while (1){ + if (i1 <= i1f) break; + if (hypot(cbuf[i1][0], cbuf[i1][1]) < + hypot(cbuf[i1-1][0], cbuf[i1-1][1])) break; + i1--; + } + i1f = i1; // linear fit with weight w double sx2=0, sx1=0, sx0=0; @@ -92,7 +95,7 @@ vector fit_signal(const int16_t *buf, int len, double sc, double dt, dou amp*=2*dt; // Exact freq an tau: fre = fre - (BB/AA).real(); - rtau = -2*M_PI*(BB/AA).imag(); + double rtau = -2*M_PI*(BB/AA).imag(); // Boundary-dependent factor: complex v1 = exp(2*M_PI*fre*I*tmin - tmin*rtau); complex v2 = exp(2*M_PI*fre*I*tmax - tmax*rtau); diff --git a/sig_filter/test_fit_signal/.gitignore b/modules/fit_signal/tests/.gitignore similarity index 100% rename from sig_filter/test_fit_signal/.gitignore rename to modules/fit_signal/tests/.gitignore diff --git a/modules/fit_signal/tests/Makefile b/modules/fit_signal/tests/Makefile new file mode 100644 index 0000000..55f006f --- /dev/null +++ b/modules/fit_signal/tests/Makefile @@ -0,0 +1,4 @@ +PROGRAMS := single_rel single_pure double_rel + +MODDIR = ../../ +include $(MODDIR)/Makefile.inc diff --git a/sig_filter/test_fit_signal/Readme b/modules/fit_signal/tests/Readme similarity index 100% rename from sig_filter/test_fit_signal/Readme rename to modules/fit_signal/tests/Readme diff --git a/modules/fit_signal/tests/double_rel.cpp b/modules/fit_signal/tests/double_rel.cpp new file mode 100644 index 0000000..dcfbcd9 --- /dev/null +++ b/modules/fit_signal/tests/double_rel.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +#include "fit_signal/fit_signal.h" + +using namespace std; + +int +main(){ + // parameters + double dt = 0.411e-5; + double f1 = 32660; + double f2 = 32764; + double rtau1 = 1.2; + double rtau2 = 30; + double amp = 0.582; + double ph = 0.1234; + double n2a = 0.2; + + ofstream ff("double_rel.dat"); + + int N = 100000; + double df = 1.0/((N-1)*dt); + + + ff << "# f2, noise/amp, fre_err, rtau_err, amp_err, ph_err"; + vector buf(N); + int max=1<<15; + double sc = amp*(2+n2a)/0.5/max; + + + for (double f=f1; f ret = fit_signal(buf.data(), buf.size(), sc, dt, 0, 0, f2); + ff << f << " " + << n2a << " " + << setprecision(12) << ret[0] << setprecision(6) << " " + << ret[1] << " " + << ret[2] << " " + << ret[3] << "\n"; + } + ff << "\n"; + +} diff --git a/modules/fit_signal/tests/double_rel.plot b/modules/fit_signal/tests/double_rel.plot new file mode 100755 index 0000000..0b3e9f0 --- /dev/null +++ b/modules/fit_signal/tests/double_rel.plot @@ -0,0 +1,35 @@ +#!/usr/bin/gnuplot + +fname="double_rel.dat" + +set nokey +set xlabel "freq" + +set title "Frequency error" +plot \ + fname using 1:($3-$1) pt 7,\ + 0 lc 0 + +pause -1 + +set title "Relaxartion" +plot \ + fname using 1:4 pt 7,\ + 0 lc 0 + +pause -1 + + +set title "Amplitude" +plot \ + fname using 1:5 pt 7,\ + 0.582 lc 0 + +pause -1 + +set title "Phase" +plot \ + fname using 1:6 pt 7,\ + 0.1234 lc 0 + +pause -1 diff --git a/modules/fit_signal/tests/single_pure.cpp b/modules/fit_signal/tests/single_pure.cpp new file mode 100644 index 0000000..0a3aa3f --- /dev/null +++ b/modules/fit_signal/tests/single_pure.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include "fit_signal/fit_signal.h" + +using namespace std; + +int +main(){ + // parameters + double dt = 0.411e-5; + double f0 = 32764; + double amp = 0.582; + double ph = 0.1234; + + ofstream ff("single_pure.dat"); + + int N = 100000; + double df = 1.0/((N-1)*dt); + + + ff << "# f0, noise/amp, fre_err, rtau_err, amp_err, ph_err"; + for (double n2a=0; n2a<2; n2a+=0.1){ // noise/amp ratio + vector buf(N); + int max=1<<15; + double sc = amp*(1+n2a)/0.5/max; + + + for (double f=f0; f ret1 = fit_signal(buf.data(), buf.size(), sc, dt, 0); + vector ret2 = fit_signal_fixfre(buf.data(), buf.size(), sc, dt, 0); + + ff << f << " " + << n2a << " " + << (ret1[0]-f)/f << " " + << ret1[1] << " " + << (ret1[2]-amp)/amp << " " + << ret1[3]-ph << " " + << (ret2[0]-f)/f << " " + << ret2[1] << " " + << (ret2[2]-amp)/amp << " " + << ret2[3]-ph << "\n"; + } + ff << "\n"; + } + +} diff --git a/modules/fit_signal/tests/single_pure.plot b/modules/fit_signal/tests/single_pure.plot new file mode 100755 index 0000000..2ef718f --- /dev/null +++ b/modules/fit_signal/tests/single_pure.plot @@ -0,0 +1,39 @@ +#!/usr/bin/gnuplot + +fname="single_pure.dat" + +set nokey +set xlabel "noise/amp ratio" + +set title "Frequency, relative error" +plot \ + fname using 2:3 pt 7,\ + fname using 2:7 pt 7,\ + 4e-7*x lc 0, -4e-7*x lc 0 + +pause -1 + +set title "Relaxartion, relative error" +plot \ + fname using 2:4 pt 7,\ + fname using 2:8 pt 7,\ + 0.06*x lc 0, -0.06*x lc 0 + +pause -1 + + +set title "Amplitude, relative error" +plot \ + fname using 2:5 pt 7,\ + fname using 2:9 pt 7,\ + 0.015*x lc 0, -0.015*x lc 0 + +pause -1 + +set title "Phase error" +plot \ + fname using 2:6 pt 7,\ + fname using 2:10 pt 7,\ + 0.015*x lc 0, -0.015*x lc 0 + +pause -1 diff --git a/modules/fit_signal/tests/single_rel.cpp b/modules/fit_signal/tests/single_rel.cpp new file mode 100644 index 0000000..3cc5501 --- /dev/null +++ b/modules/fit_signal/tests/single_rel.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include "fit_signal/fit_signal.h" + +using namespace std; + +int +main(){ + // parameters + double dt = 0.411e-5; + double f0 = 32764; + double rtau = 1.212; + double amp = 0.582; + double ph = 0.1234; + + ofstream ff("single_rel.dat"); + + int N = 100000; + double df = 1.0/((N-1)*dt); + + + ff << "# f0, noise/amp, fre_err, rtau_err, amp_err, ph_err"; + for (double n2a=0; n2a<2; n2a+=0.1){ // noise/amp ratio + vector buf(N); + int max=1<<15; + double sc = amp*(1+n2a)/0.5/max; + + + for (double f=f0; f ret = fit_signal(buf.data(), buf.size(), sc, dt, 0); + ff << f << " " + << n2a << " " + << (ret[0]-f)/f << " " + << (ret[1]-rtau)/rtau << " " + << (ret[2]-amp)/amp << " " + << ret[3]-ph << "\n"; + } + ff << "\n"; + } + +} diff --git a/modules/fit_signal/tests/single_rel.plot b/modules/fit_signal/tests/single_rel.plot new file mode 100755 index 0000000..c0076a8 --- /dev/null +++ b/modules/fit_signal/tests/single_rel.plot @@ -0,0 +1,35 @@ +#!/usr/bin/gnuplot + +fname="single_rel.dat" + +set nokey +set xlabel "noise/amp ratio" + +set title "Frequency, relative error" +plot \ + fname using 2:3 pt 7,\ + 4e-7*x lc 0, -4e-7*x lc 0 + +pause -1 + +set title "Relaxartion, relative error" +plot \ + fname using 2:4 pt 7,\ + 0.06*x lc 0, -0.06*x lc 0 + +pause -1 + + +set title "Amplitude, relative error" +plot \ + fname using 2:5 pt 7,\ + 0.015*x lc 0, -0.015*x lc 0 + +pause -1 + +set title "Phase error" +plot \ + fname using 2:6 pt 7,\ + 0.015*x lc 0, -0.015*x lc 0 + +pause -1 diff --git a/modules/get_deps b/modules/get_deps index 53e4ba4..a9eb9bd 100755 --- a/modules/get_deps +++ b/modules/get_deps @@ -2,31 +2,46 @@ use warnings; use strict; -# Print list of modules which are needed for building of -# a given module or a program. +# get_deps -- print a part of Makefile with module dependencies. # # Usage: -# get_deps ... +# get_deps # +# Module contains following components: +# * headers -- from MOD_HEADERS variable +# * sources -- from MOD_SOURCES variable +# * program sources -- from PROGRAMS variable +# * test sources -- from SIMPLE_TESTS, SCRIPT_TESTS variable +# * pkg-config names -- from PKG_CONFIG variable +# +# We build following dependencies: +# 1. For each source all included h-files (local and module) are extracted recursively +# 2. For all headers and sources recursive sorted module list is built +# based on h-files. It is used to build all modules and link executables +# 3. For the same module list a library list for pkg-config is built. + +# Program takes two arguments: root directory for all modules; build directory -my $mod_dir = shift @ARGV || '.'; -my @targets = @ARGV; +# read options +my $lib_dir = shift @ARGV || '..'; +my $mod_dir = shift @ARGV; -$#targets>=0 or die "Usage: get_deps ...\n"; +die "Usage: get_deps \n" + unless defined $mod_dir; ###################################################################### -# read Makefile, extract list of sources (cpp, h) +# Read all variables from a module Makefile. + sub read_make ($) { my $fname = shift; my %info; - open F, $fname or die "can't read $fname file: $!"; + open F, $fname or die "can't read $fname file: $fname: $!"; while (my $line = ){ - next unless $line =~ /^\s*([A-Za-z0-9_]+)\s*:?=\s*(.*)/; + next unless $line =~ /^\s*([A-Za-z0-9_]+)\s*[+:]?=\s*(.*)/; my $key = $1; $line = $2; # join lines with \ at the end, remove extra spaces - $line .= while $line =~ /\\$/; - $line =~ s/\\\n//g; + $line .= while $line =~ s/\\$//; $line =~ s/\s+/ /g; $info{$key} = $line; } @@ -34,41 +49,98 @@ sub read_make ($) { return %info; } -# read sources, extract dependencies (only #include "/") -sub get_hdeps ($$) { +###################################################################### +# extract sources from module information +sub extract_src($$) { + my $info = shift; + my $add_h = shift; + my @files; + push @files, $_ + foreach (split /\s+/, ($info->{MOD_SOURCES}||'')); + push @files, "$_.cpp" + foreach (split /\s+/, ($info->{PROGRAMS}||'')); + push @files, "$_.test.cpp" + foreach (split /\s+/, ($info->{SIMPLE_TESTS}||'')); + push @files, "$_.test.cpp" + foreach (split /\s+/, ($info->{SCRIPT_TESTS}||'')); + if ($add_h){ + push @files, $_ + foreach (split /\s+/, ($info->{MOD_HEADERS}||'')); + } + return @files; +} + +###################################################################### +# Read files, extract h-dependencies. +# mode 0: Read only #include "/" records +# return non-recursive module set +# mode 1: Recursively find all "/" +# and "" h-dependensies + +sub get_hdeps { my $dir = shift; my $files = shift; - my (%hdeps, %mdeps); + my $mode = shift || 0; + my %deps; foreach my $f (@{$files}) { - unless(open F, "$dir/$f"){ + my $ff; + unless(open $ff, "$dir/$f"){ warn "can't open $dir/$f: $!"; next; } - while (my $l=) { + while (my $l=<$ff>) { next unless $l=~/^#/; - if ($l=~m|^#include\s+"([^"/]+)/([^"/]+)"|) { - $hdeps{"$1/$2"} = 1; - $mdeps{"$1"} = 1; + + if ($l=~m|^#\s*include\s+"([^"/]+)/([^"/]+)"|) { + die "Can't find file \"$1/$2\" included in \"$f\"\n" + unless -f "$lib_dir/$1/$2"; + if ($mode == 0) { + $deps{"$1"} = 1; + } + else { + my $file = "$lib_dir/$1/$2"; + next if exists $deps{$file}; + $deps{$file} = 1; + my %rec = get_hdeps("$lib_dir/$1", [$2], $mode); + %deps = (%deps, %rec); + } + } + + if ($l=~m|^#\s*include\s+"([^"/]+)"|) { + die "Can't find file \"$1\" included in \"$f\"\n" + unless -f "$dir/$1"; + if ($mode!=0){ + my $file = "$dir/$1"; + next if exists $deps{$file}; + $deps{$file} = 1; + my %rec = get_hdeps($dir, [$1], $mode); + %deps = (%deps, %rec); + } } } - close F; + close $ff; } - return %mdeps; + + return %deps; } -# recurcively go through all modules, collect their dependencies + +###################################################################### +# recursively go through all modules, collect their module dependencies + sub add_mod_dep { my $mods = shift; my $mod = shift; - my $skip = shift || 0; - my %info = read_make "$mod_dir/$mod/Makefile"; - my @files = split /\s+/, ($info{MOD_SOURCES}||'')." ".($info{MOD_HEADERS}||''); - my %mdeps = get_hdeps("$mod_dir/$mod", \@files); - $mods->{$mod} = [keys %mdeps] unless $skip; + my %info = read_make "$lib_dir/$mod/Makefile"; + my @files = extract_src(\%info, 1); + my %mdeps = get_hdeps("$lib_dir/$mod", \@files); + $mods->{$mod} = [keys %mdeps] unless exists($mods->{$mod}); add_mod_dep($mods, $_) foreach (keys %mdeps); } -# build an ordered dependencie list +###################################################################### +# Build an ordered dependencie list. + sub optimize_deps { my $mods = shift; my @ret; @@ -92,20 +164,75 @@ sub optimize_deps { return @ret; } -my %mods; -foreach my $target (@targets) { - if (-d "$mod_dir/$target") { - add_mod_dep(\%mods, $target, 1); - } - elsif (-f $target) { - my %mdeps = get_hdeps(".", [$target]); - add_mod_dep(\%mods, $_) foreach (keys %mdeps); - } - else { - warn "No file or directory: $target\n"; +###################################################################### +# Read library deps for a given Makefile. +sub add_lib_dep { + my $pkgc = shift; + my $libs = shift; + my $mfile = shift; + my %info = read_make $mfile; + my @pkgc = split /\s+/, ($info{PKG_CONFIG}||''); + my @libs = split /\s+/, ($info{LDLIBS}||''); + $pkgc->{$_} = 1 foreach @pkgc; + $libs->{$_} = 1 foreach @libs; +} + +###################################################################### +###################################################################### +## Main + +# 1st step -- module source dependencies + +# find all module c-files and h-files +my @files; + +die "Can't find $mod_dir/Makefile\n" unless -f "$mod_dir/Makefile"; +my %info = read_make "$mod_dir/Makefile"; +@files = extract_src(\%info, 0); + +print "### This file is generated by get_deps program.\n\n"; +print "# 1. module source dependencies (recoursive h-file includes):\n\n"; + +# for each file find dependencies recursively +foreach my $file (@files) { + my $f = "$mod_dir/$file"; # copy for modification + my $dir = "."; + if ($f =~ m|(.*)/(.*)|){ + $dir = $1; $f = $2; } + my %deps = get_hdeps($dir, [$f], 1); + $f =~ s/(.cpp|.c)$/.o/; + print "$f: ", join(" ", keys %deps), "\n\n"; } +# second step -- module deps + +# find modue dependency structure: mod1->[mod2,mod3...] +# Here we use not only c-files, but h-files also +@files = extract_src(\%info, 1); +my %mods; + +my %mdeps = get_hdeps($mod_dir, \@files, 0); +add_mod_dep(\%mods, $_) foreach (keys %mdeps); + +# optimize dependencies, get list of modules in the correct order. my @list = optimize_deps(\%mods); -print "$_\n" foreach (@list); + +print "# 2. sorted module dependencies\n\n"; +print "MDEPS := ", join(" ", @list), "\n\n"; + +print "# 3. a-file list for linking (reverse order)\n\n"; +print "ADEPS :="; +print " $lib_dir/$_/$_.a" foreach reverse(@list); +print "\n\n"; + + +print "# 4. library dependencies\n\n"; +my %libs; +my %pkgc; +add_lib_dep(\%pkgc, \%libs, "$mod_dir/Makefile"); +add_lib_dep(\%pkgc,\%libs, "$lib_dir/$_/Makefile") foreach (@list); +print "LDLIBS := ", join(" ", keys %libs), "\n\n"; +print "PKG_CONFIG := ", join(" ", keys %pkgc), "\n\n"; + diff --git a/modules/read_words/Makefile b/modules/read_words/Makefile index c71dc70..42f2817 100644 --- a/modules/read_words/Makefile +++ b/modules/read_words/Makefile @@ -1,5 +1,6 @@ -MOD_HEADERS := read_words.h -MOD_SOURCES := read_words.cpp -SCRIPT_TESTS := read_words +MOD_HEADERS := read_words.h read_conf.h +MOD_SOURCES := read_words.cpp read_conf.cpp +SCRIPT_TESTS := read_words read_words2 +SIMPLE_TESTS := read_conf read_words1 include ../Makefile.inc diff --git a/modules/read_words/Readme b/modules/read_words/Readme deleted file mode 100644 index cc26409..0000000 --- a/modules/read_words/Readme +++ /dev/null @@ -1,15 +0,0 @@ -================================================== -Read one line from the stream and extract words, separated by spaces. -- words are splitted by ' ' or '\t' symbols, -- comments (everything from # symbol to end of the line) are skipped, -- empty lines are skipped, -- words can be quoted by " or ', -- any symbol (including newline) can be escaped by '\', - -`std::vector read_words(std::istream & ss);` - -================================================== -Changelog: - -2019.05.02 V.Zavjalov 1.0: -- First version diff --git a/modules/read_words/Readme.md b/modules/read_words/Readme.md new file mode 100644 index 0000000..88effd4 --- /dev/null +++ b/modules/read_words/Readme.md @@ -0,0 +1,105 @@ +## read_words + +Read one line from the stream and extract words, separated by spaces. + + - Comments (everything from # symbol to end of the line) are skipped. + + - Empty lines are skipped. + + - Words are splitted by SPACE or TAB symbols, or by '\' + NEWLINE sequence. + + - Words can be quoted by " or '. Empty words can be created as '' or "". + + - ANSY escape sequences are supported: \a, \b, \f, \n, \r, \t, \v, + \\, \", \'. In addition, symbols #, SPACE and TAB can be escaped. + Escaped NEWLINE works as word separator. + Escape sequences \ and \x are supported. Octal number + can contain 1..3 digits, hex number should always contain 2 digits. + + - Empty vector is returned only at the end of input. + + - If line_num parameter is not NULL, it should be initialized + by 0,0 before the first call. Then starting line number of the first + word and number of the last line read is returned there. + In this error messages will contain line number. + + - If lc parameter is true then all Latin characters are converted to lower case. + + - If raw parameter is true, read everything as a single string, without + processing special characters. This is useful if one wants to read + a single "line" which can be sent to another program which uses read_words + to read it. + +```c++ +std::vector read_words( + std::istream & ss, int line_num[] = NULL, const bool lc=false); +``` + +## join_words + +Inverse operation: join all "words" to have string readable for `read_words()`. +- All `\` and `"` are replaced with `\\` and `\"`. +- Characters `\`, `#`, `'`, and `"` are protected with `\`. +- All words are joined with space character between them. + +## unquote_words + +Read text by read_words and join everything using space. +`"a b" \'c --> a b 'c` + +## read_conf + +This is an example of using `read_words`. +Read options from a simple config file. All known options should be +mentioned in `known` list. If `should_exist=true` and file is missing +then error will be thrown. + +Each line shold contain pairs of words: + + +```c++ +Opt read_conf(const std::string & fname, + std::list known, bool should_exist=false); +``` + +------------ +## Changelog: + +2022.08.31 V.Zavjalov 1.9: +- add read_words_defs class: define and substitute variables + +2022.06.19 V.Zavjalov 1.8: +- add unquote_words function + +2021.03.11 V.Zavjalov 1.7: +- raw mode: read everything as a single string +- join_words(): inverse operation, join all "words" to have string readable for read_words + +2020.09.30 V.Zavjalov 1.6: +- allow empty words, '' or "". + +2020.09.30 V.Zavjalov 1.5: +- read_conf function + +2020.09.30 V.Zavjalov 1.4: +- Use ANSI escape sequencies (\n, \t, etc.). +- Do not allow escaping normal characters (A, c, etc.). +- Use \ and \x sequences. +- Fix error in line counting. + +2020.01.02 V.Zavjalov 1.3: +- symbol \n protected by \ works as word separator, not as literal \n + +2019.10.23 V.Zavjalov 1.2: +- lc parameter affects only Latin characters. + Reasons: tolower() anyway did not work with UTF characters, + proper wide character reading is needed; together with Gtk::Main + it produce unexpected conversions (Cyrrilic "г" to Cyrillic "У"). + +2019.06.01 V.Zavjalov 1.1: +- Do not stop reading if newlines is inside quotes. +- Add line counting (line_num parameter). +- Add option for case-insensetive reading (lc parameter). + +2019.05.02 V.Zavjalov 1.0: +- First version diff --git a/modules/read_words/read_conf.cpp b/modules/read_words/read_conf.cpp new file mode 100644 index 0000000..d49a62f --- /dev/null +++ b/modules/read_words/read_conf.cpp @@ -0,0 +1,41 @@ +#include "read_conf.h" +#include "read_words.h" +#include + +Opt +read_conf(const std::string & fname, + std::list known, + bool should_exist){ + + std::ifstream ss(fname); + if (!ss){ + if (should_exist) throw Err() << fname + << ": can't read file"; + else return Opt(); + } + + int N[2] = {0,0}; + Opt ret; + while (1){ + std::vector vs = read_words(ss, N, false); + if (vs.size()<1) break; + + // allow only two-word lines + if (vs.size()!=2) throw Err() << fname << ":" << N[0] + << ": two words expected"; + + bool found = false; + for (auto const & k: known){ + if (vs[0] == k) { + ret.put(vs[0], vs[1]); + found = true; + break; + } + } + + if (!found) + throw Err() << fname << ":" << N[0] + << ": unknown parameter: " << vs[0]; + } + return ret; +} diff --git a/modules/read_words/read_conf.h b/modules/read_words/read_conf.h new file mode 100644 index 0000000..43159fb --- /dev/null +++ b/modules/read_words/read_conf.h @@ -0,0 +1,17 @@ +#ifndef READ_CONF_H +#define READ_CONF_H + +#include +#include "opt/opt.h" + +/* + Read options from a simple config file. + All known options should be mentioned in `known` list. + If `should_exist=true` and file is missing then error will be thrown. +*/ + +Opt read_conf(const std::string & fname, + std::list known, + bool should_exist=false); + +#endif \ No newline at end of file diff --git a/modules/read_words/read_conf.test.cpp b/modules/read_words/read_conf.test.cpp new file mode 100644 index 0000000..83af885 --- /dev/null +++ b/modules/read_words/read_conf.test.cpp @@ -0,0 +1,35 @@ +///\cond HIDDEN (do not show this in Doxyden) + +#include +#include "read_conf.h" +#include "err/assert_err.h" + +int +main(int argc, const char* argv[]){ + try { + + assert_eq(read_conf("test_data/missing", {}), Opt()); + + assert_err(read_conf("test_data/missing", {}, true), + "test_data/missing: can't read file"); + + Opt o; + o.put("key1","val1"); + o.put("key2","val 2"); + o.put("key3","val3a\n val3b"); + assert_eq(read_conf("test_data/conf1", {"key1","key2","key3"}), o); + + assert_err(read_conf("test_data/conf1", {"key1","key3"}, true), + "test_data/conf1:5: unknown parameter: key2"); + + assert_err(read_conf("test_data/conf2", {"key1","key2"}, true), + "test_data/conf2:4: two words expected"); + } + catch (Err & e) { + std::cerr << "Error: " << e.str() << "\n"; + return 1; + } + return 0; +} + +///\endcond diff --git a/modules/read_words/read_words.cpp b/modules/read_words/read_words.cpp index 37769d4..4484711 100644 --- a/modules/read_words/read_words.cpp +++ b/modules/read_words/read_words.cpp @@ -1,51 +1,282 @@ #include "err/err.h" #include "read_words.h" -std::vector read_words(std::istream & ss) { +std::vector read_words( + std::istream & ss, int line_num[2], + const bool lc, const bool raw) { + + bool first = true; std::string str; std::vector ret; bool quote1=false, quote2=false, comment=false; + bool qq=false; // empty strings are added if they were quoted. + + try { + + // read stream char by char + for (char c; ss.get(c); !ss.eof()){ + if (raw) str += c; + + if (c == '\n' && line_num) line_num[1]++; + + // end of line + if (c == '\n' && !quote1 && !quote2) { + comment=false; + if (str!="" || qq) ret.push_back(str); + str=""; qq=false; + if (ret.size()) return ret; + else continue; + } + + // comments -- until end of line + if (c == '#' && !quote1 && !quote2) comment=true; + if (comment) continue; - // read stream char by char - for (char c; ss.get(c); !ss.eof()){ + // escape character (all chars including newline can be escaped!) + if (c == '\\') { + ss.get(c); + if (raw) str += c; + switch (c) { + //protected \n works as word separator: + case '\n': + if (line_num) line_num[1]++; + if ((str!="" || qq) && !raw){ + ret.push_back(str); + str=""; + } + qq=false; + continue; + // standard ANSI escape sequences + '#', space, tab: + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + case '\\': + case '\'': case '\"': + case '?': case '#': + case ' ': case '\t': + break; + // oct code + case '0': case '1': + case '2': case '3': + case '4': case '5': + case '6': case '7': + // read two more symbols if they are numbers + c-='0'; + for (int i=0; i<2; ++i){ + char c1; + ss.get(c1); + if (c1<'0' || c1>'7'){ + ss.unget(); + break; + } + if (raw) str += c1; + c = (c<<3) + (c1-'0'); + } + break; + // hex code, read exactly two symbols + case 'x':{ + char c1,c2; + ss.get(c1); + ss.get(c2); + if (raw) { + str += c1; + str += c2; + } + if (c1>='0' && c1<='9') c1-='0'; + else if (c1>='A' && c1<='F') c1-='A'-10; + else if (c1>='a' && c1<='f') c1-='a'-10; + else throw Err() << "bad hex escape sequence"; + if (c2>='0' && c2<='9') c2-='0'; + else if (c2>='A' && c2<='F') c2-='A'-10; + else if (c2>='a' && c2<='f') c2-='a'-10; + else throw Err() << "bad hex escape sequence"; + c = (c1<<4) + c2; + break; + } + default: + throw Err() << "bad escape sequence"; + } + // add character + goto add_char; + } - // end of line - if (c == '\n') { - comment=false; - if (str!="") ret.push_back(str); - str=""; - if (ret.size()) return ret; - else continue; + // quote + if (c == '"' && !quote2) {quote1=!quote1; qq=true; continue; } + if (c == '\'' && !quote1) {quote2=!quote2; qq=true; continue; } + + + // space -- word separaters unless quoted + if (!quote1 && !quote2 && (c == ' ' || c == '\t')){ + if ((str!="" || qq) && !raw){ + ret.push_back(str); + str=""; + } qq=false; + continue; + } + + // to lower case if needed + if (lc && c>='A' && c<='Z') c = tolower(c); + + // append normal characters + add_char: + if (!raw) str += c; + if (first && line_num) {line_num[0] = line_num[1]+1; first=false;} } - // comments -- until end of line - if (c == '#' && !quote1 && !quote2) comment=true; - if (comment) continue; + // at end of input we have unclosed quote: + if (quote1 || quote2) throw Err() << "Unclosed quote"; - // escape character (all chars including newline can be escaped!) - if (c == '\\') { - ss.get(c); - str += c; - continue; + } + catch (Err & e){ + if (line_num) e << " in line " << line_num[1]; + throw; + } + + if ((str!="") | qq) ret.push_back(str); + return ret; +} + +std::string +join_words(const std::vector & words){ + std::string ret; + for (auto const & w:words) { + + auto str(w); + std::string::size_type pos; + + pos = 0u; + while((pos = str.find("\\", pos)) != std::string::npos){ + str.insert(pos, 1, '\\'); + pos += 2; } - // quote - if (c == '"' && !quote2) {quote1=!quote1; continue; } - if (c == '\'' && !quote1) {quote2=!quote2; continue; } + pos = 0u; + while((pos = str.find("\"", pos)) != std::string::npos){ + str.insert(pos, 1, '\\'); + pos += 2; + } + pos = 0u; + while((pos = str.find("\'", pos)) != std::string::npos){ + str.insert(pos, 1, '\\'); + pos += 2; + } - // space -- word separaters unless quoted - if (!quote1 && !quote2 && (c == ' ' || c == '\t')){ - if (str!="") ret.push_back(str); - str=""; - continue; + pos = 0u; + while((pos = str.find("#", pos)) != std::string::npos){ + str.insert(pos, 1, '\\'); + pos += 2; } + bool qq = (str.find(' ') != std::string::npos || + str.find('\t') != std::string::npos || + str.find('\n') != std::string::npos || + str.size()==0); - // append normal characters - str+=c; + if (ret.size()) ret += ' '; + if (qq) ret+='\"'; + ret+=str; + if (qq) ret+='\"'; } + return ret; +} - if (quote1 || quote2) throw Err() << "Unclosed quote"; - if (str!="") ret.push_back(str); +std::string +unquote_words(const std::string & in){ + std::string ret; + std::istringstream ss(in); + while (1){ + auto words = read_words(ss); + if (words.size()==0) break; + for (auto const & w:words){ + if (ret.size()) ret+=" "; + ret += w; + } + } return ret; } + +/***********************************/ + +void +read_words_defs::apply(std::string & str) const{ + while (1) { + auto n1 = str.find("${"); + if (n1 == std::string::npos) break; + auto n2 = str.find("}", n1); + auto v = find(str.substr(n1+2, n2-n1-2)); + if (v == end()) throw Err() << "Undefined variable: " << str.substr(n1, n2-n1+1); + str.replace(n1,n2-n1+1, v->second); + } +} + +bool +read_words_stdcmds(std::vector & words, read_words_defs & defs, std::deque & ifs){ + + // endif command + if (words[0] == "endif"){ + if (ifs.size()<1) throw Err() << "unexpected endif command"; + ifs.pop_back(); + return 1; + } + // else command + if (words[0] == "else"){ + if (ifs.size()<1) throw Err() << "unexpected else command"; + ifs.back() = !ifs.back(); + return 1; + } + + // check if conditions + bool skip = false; + for (auto const & c:ifs) + if (c == false) {skip = true; break;} + if (skip) return 1; + + // apply definitions + defs.apply(words); + + // if command + if (words[0] == "if"){ + if (words.size() == 4 && words[2] == "=="){ + ifs.push_back(words[1] == words[3]); + } + else if (words.size() == 4 && words[2] == "!="){ + ifs.push_back(words[1] != words[3]); + } + else + throw Err() << "wrong if syntax"; + return 1; + } + // ifdef command + if (words[0] == "ifdef"){ + if (words.size() != 2) + throw Err() << "wrong ifdef syntax"; + ifs.push_back(defs.count(words[1])>0); + return 1; + } + // ifndef command + if (words[0] == "ifndef"){ + if (words.size() != 2) + throw Err() << "wrong ifndef syntax"; + ifs.push_back(defs.count(words[1])==0); + return 1; + } + + // define -- define a variable + if (words[0] == "define") { + if (words.size()!=3) throw Err() << "define: arguments expected: "; + defs.define(words[1], words[2]); + return 1; + } + // define_if_undef -- define a variable if it is not defined + if (words[0] == "define_if_undef") { + if (words.size()!=3) throw Err() << "define_if_undef: arguments expected: "; + if (defs.count(words[1])==0) defs.define(words[1], words[2]); + return 1; + } + + return 0; +} diff --git a/modules/read_words/read_words.h b/modules/read_words/read_words.h index 042e2fc..c29166f 100644 --- a/modules/read_words/read_words.h +++ b/modules/read_words/read_words.h @@ -3,18 +3,85 @@ #include #include +#include +#include #include ///\addtogroup libmapsoft ///@{ -/// Read one line from the stream and extract words, separated by spaces. -/// - comments (everything from # symbol to end of the line) are skipped, -/// - empty lines are skipped, -/// - words are splitted by ' ' or '\t' symbols, -/// - words can be quoted by " or ', -/// - any symbol (including newline) can be escaped by '\', -std::vector read_words(std::istream & ss); +/* + Read one line from the stream and extract words, separated by spaces. + - Comments (everything from # symbol to end of the line) are skipped. + - Empty lines are skipped. + - Words are splitted by ' ' or '\t' symbols. + - Words can be quoted by " or '. + - Any symbol (including newline) can be escaped by '\'. + - Empty vector is returned only at the end of input. + - If line_num parameter is not NULL, it should be initialized + by 0,0 before the first call. Then line number of the first word and + number of the last read wline is returned there. + - If lc parameter is true then all characters are converted to lower case. + - If raw parameter is true, read everything as a single string, without + processing special characters. This is useful if one wants to read + a single "line" which can be sent to another program which uses read_words + to read it. +*/ +std::vector read_words( + std::istream & ss, + int line_num[2] = NULL, + const bool lc = false, + const bool raw = false +); + + +/* Inverse operation: join all "words" to have string readable for read_words(). +- Characters `\`, `#`, `'`, and `"` are protected with `\`. +- If a word contais ` `, `\t` or `\n` or it is empty, it is surrounded with `"`. +- All words are joined with " " character between them. +*/ +std::string join_words(const std::vector & words); + +/* + Read text by read_words and join everything using space. + "a b" \'c --> a b 'c +*/ +std::string unquote_words(const std::string & in); + +/***********************************/ +// Define/substitute variables +// (copy from cryoblocks project) + +class read_words_defs : public std::map { +public: + // initialize from map, or Opt + read_words_defs(const std::map & map): + std::map(map){} + read_words_defs() {} + + void define(const std::string & name, const std::string & value){ + if (count(name)) erase(name); + emplace(name, value); + } + + void apply(std::string & str) const; + + void apply(std::vector & vs) const { + for (auto &s:vs) apply(s); } +}; + +// Process standard commands in the read_words output: +// - define +// - define_if_undef +// - if/ifdef/ifindef/else/endif +// Arduments: +// - words -- output of read_words +// - defs -- read_words_defs class, variable definitions +// - ifs -- state queue for if commands +// Return true if line is consumed, false if thurther processing is needed. +bool +read_words_stdcmds(std::vector & words, + read_words_defs & defs, std::deque & ifs); ///@} #endif diff --git a/modules/read_words/read_words.test.cpp b/modules/read_words/read_words.test.cpp index 070fe3c..77f8eea 100644 --- a/modules/read_words/read_words.test.cpp +++ b/modules/read_words/read_words.test.cpp @@ -3,21 +3,57 @@ #include #include "read_words.h" #include "err/err.h" +#include "err/assert_err.h" int -main(){ -try{ +main(int argc, const char* argv[]){ + try { + bool lc=false, raw=false; + + for (int i=1; i vs = read_words(std::cin); - if (std::cin.eof() && vs.size()<1) break; - std::vector::const_iterator i; - for (i=vs.begin(); i!=vs.end(); i++) - std::cout << " [" << *i << "]"; + std::vector vs = read_words(std::cin, N, lc, raw); + if (vs.size()<1) break; + + // definitions + defs.apply(vs); + if (vs[0] == "define"){ + if (vs.size()!=3) throw Err() << "bad definition in line " << N[0] + << ": expected: define "; + defs.define(vs[1], vs[2]); + } + + if (raw) { + if (vs.size()) std::cout << "> " << vs[0]; + continue; + } + + std::cout << N[0] << "-" << N[1] << ":"; + for (auto const & i:vs) std::cout << " [" << i << "]"; std::cout << "\n"; + + // test join_words + std::string str = join_words(vs); + std::istringstream ss(str); + + std::vector vs1 = read_words(ss, NULL, false, false); + std::vector vs2 = read_words(ss, NULL, false, false); + assert_eq(vs2.size(), 0 ); + assert_eq(vs1.size(), vs.size()); + for (size_t i = 0; i&1)" \ +"Error: Unclosed quote in line 4" diff --git a/modules/read_words/read_words.test_data1 b/modules/read_words/read_words.test_data1 deleted file mode 100644 index 214639f..0000000 --- a/modules/read_words/read_words.test_data1 +++ /dev/null @@ -1,8 +0,0 @@ -a \# b c " a\' s " # aa -d e f " a\' s" -\\ - -# -abc\ -def -aa bb "cc\"\"dd\'\'ee" diff --git a/modules/read_words/read_words1.test.cpp b/modules/read_words/read_words1.test.cpp new file mode 100644 index 0000000..99025bb --- /dev/null +++ b/modules/read_words/read_words1.test.cpp @@ -0,0 +1,21 @@ +///\cond HIDDEN (do not show this in Doxyden) + +#include +#include "read_words.h" +#include "err/assert_err.h" + +int +main(int argc, const char* argv[]){ + try { + + std::string s("\"a b\" \\\'c"); + assert_eq(unquote_words(s), "a b \'c"); + } + catch (Err & e) { + std::cerr << "Error: " << e.str() << "\n"; + return 1; + } + return 0; +} + +///\endcond diff --git a/modules/read_words/read_words2.test.cpp b/modules/read_words/read_words2.test.cpp new file mode 100644 index 0000000..ac38c5a --- /dev/null +++ b/modules/read_words/read_words2.test.cpp @@ -0,0 +1,56 @@ +///\cond HIDDEN (do not show this in Doxyden) + +// More complicated script: preprocessing iostream (if, define, include) commands + +#include +#include "read_words.h" +#include "err/assert_err.h" + + + + +int +main(){ + + std::string fname="stdin"; +// std::ifstream ff(fname); +// if (!ff) throw Err() << "can't open file: " << fname; +// auto path = file_get_prefix(fname); + + int line_num[2] = {0,0}; // line counter for read_words + std::deque ifs; // for if/endif commands + read_words_defs defs; + + while (1){ + auto vs = read_words(std::cin, line_num, false); + if (vs.size()==0) break; + + try{ + if (read_words_stdcmds(vs, defs, ifs)) continue; + for (const auto & v:vs) std::cout << " " << v; + std::cout << "\n"; + +/* + // include command + if (vs[0] == "include"){ + if (vs.size()!=2) throw Err() << "include: filename expected"; + auto fn = vs[1]; + // should not happend, but lets check before accessing fn[0]: + if (fn.size() == 0) throw Err() << "include: empty filename"; + + if (fn[0] != '/') fn = path + fn; + load(fn, defs); + type=-1; + continue; + } +*/ + + } + catch (Err & e) { + throw Err() << fname << ":" << line_num[0] << ": " << e.str(); + } + } + +} + +///\endcond diff --git a/modules/read_words/read_words2.test.script b/modules/read_words/read_words2.test.script new file mode 100755 index 0000000..a552abf --- /dev/null +++ b/modules/read_words/read_words2.test.script @@ -0,0 +1,65 @@ +#!/bin/sh -efu + +prog=${1:-./read_words2.test} + +assert(){ + res="$1" + exp="$2" + if [ "$res" != "$exp" ]; then + printf "ERROR:\n" + printf " exp: %s\n" "$exp" + printf " res: %s\n" "$res" + return 1 + fi + return 0 +} + +i=' +define a 4 +define a 5 +ifdef a + print a=${a} +else + print a undefined +endif +ifndef b + print b undefined +else + print b=${b} +endif +if ${a} == 5 + print ${a} == 5 +else + print ${a} != 5 +endif +if ${a} == 4 + print ${a} == 4 +else + print ${a} != 4 +endif +if ${a} == 5 + ifdef a + ifndef b + ok + endif + endif +endif +define_if_undef a 4 +define_if_undef b 4 +if ${a} == 5 + ok + if ${b} == 4 + ok + endif +endif +' + +o=' print a=5 + print b undefined + print 5 == 5 + print 5 != 4 + ok + ok + ok' + +assert "$(echo "$i" | "$prog")" "$o" diff --git a/modules/read_words/test_data/conf1 b/modules/read_words/test_data/conf1 new file mode 100644 index 0000000..0b2447b --- /dev/null +++ b/modules/read_words/test_data/conf1 @@ -0,0 +1,9 @@ +# this is example config file + +key1 val1 + +key2 "val 2" + +key3 "val3a + val3b" + diff --git a/modules/read_words/test_data/conf2 b/modules/read_words/test_data/conf2 new file mode 100644 index 0000000..6a93cc9 --- /dev/null +++ b/modules/read_words/test_data/conf2 @@ -0,0 +1,5 @@ +# wrong file: 3 words in line 4 + +key1 val1 +key2 val2 val3 + diff --git a/modules/read_words/test_data/read_words1 b/modules/read_words/test_data/read_words1 new file mode 100644 index 0000000..a3d4f2c --- /dev/null +++ b/modules/read_words/test_data/read_words1 @@ -0,0 +1,10 @@ +a \# ABc aBC " a\' s " # aa +d e f " a\' s" +\\ + +# +ab\nc\ +de\tf +abc\ + def +aa bb "cc\"\"dd\'\'ee" "" '' "''" diff --git a/modules/read_words/test_data/read_words1r b/modules/read_words/test_data/read_words1r new file mode 100644 index 0000000..c30e739 --- /dev/null +++ b/modules/read_words/test_data/read_words1r @@ -0,0 +1,10 @@ +> a \# ABc aBC " a\' s " # aa +> d e f " a\' s" +> \\ +> +> # +> ab\nc\ +de\tf +> abc\ + def +> aa bb "cc\"\"dd\'\'ee" "" '' "''" diff --git a/modules/read_words/read_words.test_data2 b/modules/read_words/test_data/read_words2 similarity index 71% rename from modules/read_words/read_words.test_data2 rename to modules/read_words/test_data/read_words2 index 2c9b1bf..393cf7e 100644 --- a/modules/read_words/read_words.test_data2 +++ b/modules/read_words/test_data/read_words2 @@ -1,2 +1,9 @@ a 'b "C" d' e\ e# aa a "b 'C' d" e\ e# aa +"a +b +c +" +'a +b +c' diff --git a/modules/read_words/test_data/read_words2r b/modules/read_words/test_data/read_words2r new file mode 100644 index 0000000..8e7a920 --- /dev/null +++ b/modules/read_words/test_data/read_words2r @@ -0,0 +1,9 @@ +> a 'b "C" d' e\ e# aa +> a "b 'C' d" e\ e# aa +> "a +b +c +" +> 'a +b +c' diff --git a/modules/read_words/test_data/read_words3 b/modules/read_words/test_data/read_words3 new file mode 100644 index 0000000..f932d84 --- /dev/null +++ b/modules/read_words/test_data/read_words3 @@ -0,0 +1,21 @@ +# 'a' = 0x61 = 0141 +# '\n' = 0xA = 012 +# this three words should be same: + +\x61\x0A +\141\12 +\141\012 + +# 9 is not an octal digit! +\141\129 +# not more then 3 chars read +\1411\129 + +## this should be errors: +#\A +#\8 +#\xAn + +# sequence at the end should not be error +# \xA at the end should be +\12 diff --git a/modules/read_words/test_data/read_words3r b/modules/read_words/test_data/read_words3r new file mode 100644 index 0000000..b10eb36 --- /dev/null +++ b/modules/read_words/test_data/read_words3r @@ -0,0 +1,21 @@ +> # 'a' = 0x61 = 0141 +> # '\n' = 0xA = 012 +> # this three words should be same: +> +> \x61\x0A +> \141\12 +> \141\012 +> +> # 9 is not an octal digit! +> \141\129 +> # not more then 3 chars read +> \1411\129 +> +> ## this should be errors: +> #\A +> #\8 +> #\xAn +> +> # sequence at the end should not be error +> # \xA at the end should be +> \12 diff --git a/modules/read_words/test_data/read_words4 b/modules/read_words/test_data/read_words4 new file mode 100644 index 0000000..e03b2d6 --- /dev/null +++ b/modules/read_words/test_data/read_words4 @@ -0,0 +1,2 @@ +define w1 123 +use ${w1} diff --git a/modules/signal/signal.cpp b/modules/signal/signal.cpp index 7173438..46d6e14 100644 --- a/modules/signal/signal.cpp +++ b/modules/signal/signal.cpp @@ -154,6 +154,10 @@ Signal read_signal(istream & ff){ IFilter flt(ff, "gunzip"); return read_signal(flt.stream()); } + + // read text file (columns separated by spaces, comments are #) + return read_txt(ff); + throw Err() << "unknown format (not SIG, WAV, FLAC or GZ)"; } @@ -315,6 +319,78 @@ Signal read_sig(istream & ff){ return sig; } +/***********************************************************/ +Signal read_txt(istream & ff){ + + if (ff.fail()) throw Err() << "Can't read file"; + Signal sig; + vector tt; + vector vmax; + vector > vv; + + // Read data lines + while (!ff.eof()){ + // read line + std::string line; + getline(ff,line); + + // remove comments + size_t nc = line.find('#'); + if (nc!=string::npos) line = line.substr(0,nc); + + // read all numeric values from the line + istringstream ls(line); + vector vl; + while (1){ + double v; + ls >> v; + if (!ls.fail()) vl.push_back(v); + else break; + } + + if (vl.size()==0) continue; // empty, non-numeric lines + if (vl.size()==1) + throw Err() << "only one column found in the line: " << line; + + // if we are reading first line, resize data storage: + if (vv.size()==0){ + vv.resize(vl.size()-1); + vmax.resize(vl.size()-1, 0); + } + + // number of columns in all lines should be same: + if (vv.size()!=vl.size()-1) + throw Err() << "wrong number of columns in the line: " << line; + + // collect values to tt and vv arrays + // find max values for each channel + tt.push_back(vl[0]); + for (int n=0; n vmax[n]) vmax[n] = abs(vl[n+1]); + } + } + + // set t0 and dt values - signal does not contain time values! + if (tt.size()>0){ + sig.t0 = tt[0]; + sig.dt = (tt[tt.size()-1]-tt[0])/(tt.size()-1); + } + + // transfer data to sig object + sig.chan.resize(vv.size()); + for (int n = 0; n -#include - -// Functions for converting ADC24 constants -// from/to string representation. - -/************************************************/ -// Conversion time. -// String values have same format as in get_tconvs() -// output: 60 100 180 340 660. - -HRDL_CONVERSION_TIME str_to_convt(const std::string & s){ - if (s== "60") return HRDL_60MS; - if (s=="100") return HRDL_100MS; - if (s=="180") return HRDL_180MS; - if (s=="340") return HRDL_340MS; - if (s=="660") return HRDL_660MS; - throw Err() << "error: unknown conversion time: " << s; -} - -std::string convt_to_str(const HRDL_CONVERSION_TIME tconv){ - switch (tconv){ - case HRDL_60MS: return "60"; - case HRDL_100MS: return "100"; - case HRDL_180MS: return "180"; - case HRDL_340MS: return "340"; - case HRDL_660MS: return "660"; - } - throw Err() << "error: unknown conversion time: " << tconv; -} - -/************************************************/ -// Voltage range. -// String values have same format as in get_ranges() -// output: 2500 1250 625 312.5 156.25 78.125 39.0625 - -HRDL_RANGE str_to_range(const std::string & s){ - if (s=="2500") return HRDL_2500_MV; - if (s=="1250") return HRDL_1250_MV; - if (s=="625") return HRDL_625_MV; - if (s=="312.5") return HRDL_313_MV; - if (s=="156.25") return HRDL_156_MV; - if (s=="78.125") return HRDL_78_MV; - if (s=="39.0625") return HRDL_39_MV; - throw Err() << "error: unknown input range: " << s; -} - -std::string range_to_str(const HRDL_RANGE r){ - switch (r){ - case HRDL_2500_MV: return "2500"; - case HRDL_1250_MV: return "1250"; - case HRDL_625_MV: return "625"; - case HRDL_313_MV: return "312.5"; - case HRDL_156_MV: return "156.25"; - case HRDL_78_MV: return "78.125"; - case HRDL_39_MV: return "39.0625"; - } - throw Err() << "error: unknown input range: " << r; -} - -double str_to_volt(const std::string & s){ - if (s=="2500") return 2.5; - if (s=="1250") return 1.25; - if (s=="625") return 0.625; - if (s=="312.5") return 0.3125; - if (s=="156.25") return 0.15625; - if (s=="78.125") return 0.078125; - if (s=="39.0625") return 0.0390625; - throw Err() << "error: unknown input range: " << s; -} - -double range_to_volt(const HRDL_RANGE r){ - return(str_to_volt(range_to_str(r))); -} - -/************************************************/ -// Block method (not used). - -HRDL_BLOCK_METHOD str_to_blockm(const std::string & s){ - if (strcasecmp(s.c_str(),"block")==0) return HRDL_BM_BLOCK; - if (strcasecmp(s.c_str(),"window")==0) return HRDL_BM_WINDOW; - if (strcasecmp(s.c_str(),"stream")==0) return HRDL_BM_STREAM; - throw Err() << "error: unknown block method: " << s; -} - -/************************************************/ -// errors: - -std::string err_to_str(const int e){ - switch ((enHRDLErrorCode)e){ - case HRDL_OK: return "No error"; - case HRDL_KERNEL_DRIVER: return "driver error"; - case HRDL_NOT_FOUND: return "device not found"; - case HRDL_CONFIG_FAIL: return "device configuration error"; - case HRDL_ERROR_OS_NOT_SUPPORTED: return "OS not supported"; - case HRDL_MAX_DEVICES: return "device limit reached"; - } - return "unknown error"; -} - -std::string serr_to_str(const int e){ - switch ((enSettingsError)e){ - case SE_CONVERSION_TIME_OUT_OF_RANGE: return "conversion time out of range"; - case SE_SAMPLEINTERVAL_OUT_OF_RANGE: return "sampling interval out of range"; - case SE_CONVERSION_TIME_TOO_SLOW: return "conversion time too slow"; - case SE_CHANNEL_NOT_AVAILABLE: return "channel not available"; - case SE_INVALID_CHANNEL: return "invalid channel"; - case SE_INVALID_VOLTAGE_RANGE: return "invalid voltage range"; - case SE_INVALID_PARAMETER: return "invalid parameter"; - case SE_CONVERSION_IN_PROGRESS: return "conversion in progress"; - case SE_COMMUNICATION_FAILED: return "communication failed"; - case SE_OK: return "no errors"; - } - return "unknown error"; -} - -#endif - - diff --git a/pico_adc/Makefile b/pico_adc/Makefile deleted file mode 100644 index 9ae5b5e..0000000 --- a/pico_adc/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -PROGRAMS = pico_adc - - -MOD_HEADERS := device.h ADC24_const.h commands.h -MOD_SOURCES := device.cpp commands.cpp - -LDLIBS += -lm -lpicohrdl - -MODDIR = ../modules -include $(MODDIR)/Makefile.inc - diff --git a/pico_adc/Readme.md b/pico_adc/Readme.md deleted file mode 100644 index 4adca57..0000000 --- a/pico_adc/Readme.md +++ /dev/null @@ -1,73 +0,0 @@ -# pico_adc program -- SPP interface for Pico ADC24 device. - -### Command line options: - -* `-l` -- list all connected devices and exit -* `-d ` -- device ID (autodetect by default) -* `-m ` -- set mains frequency, Hz (50 or 60, default 50) -* `-h` -- write this help message and exit - -### SPP commands - -* `get_time` -- Get current time (unix seconds with ms precision). - -* `*idn?` -- Get ID string: `pico_adc `. - -* `help` -- Get list of commands. - -* `get_info` -- Get device information. - -* `ranges` -- Get available range settings (mV): - `2500 1250 625 312.5 156.25 78.125 39.0625`. - -* `tconvs` -- Get available conversion time settings (ms): - `60 100 180 340 660` - -* `get_val ` -- Measure a single value. - This command do measurement of a single value on the channel `` - (1..16). Boolean parameter `` specifies single/differential mode. - Only odd channels (1,3,5,...) can be used for differential mode, - next channel number is used as the second channel. - Parameter `` is measurement range, one of values returned by - `ranges` command. `convt` is conversion time, one of values returned - by `tconvs` command. Use longer time for more accurate measurement. - In the case of overflow +/-Inf is returned. - -* `set_dig_out ` -- Set digital outputs. - Using digital ports for input is not supported. - -Commands listed below are used for "block read mode", to do measurement -of multiple channels. In this mode one should set channel parameters and -measurement timings in advance, and then do the measurement. Note that -real measurements are still done in series, channel by channel. If device -is used by multible users (e.g. with device2 server) then device locking -is needed during the measurement. It is not recommended to use -block read mode (use `get_val` instead), and especially not recommended -to mix `get_val` measurements with the block read measuremens. - -* `chan_set ` -- set channel parameters. - - `chs` -- Channels: 01 to 16, multiple channels allowed. - - `en` -- Enable channels: 1 or 0. - - `sngl` -- Single/Differential mode: 1 or 0. - - `rng` -- Input range, mV (see `ranges` command). - -* `disable_all` -- Disable all channels. Do this before - setting up channels if the device was in unknown state. - -* `chan_get ` -- get channel parameters (` `, - or ` disabled` for disabled channels. - -* `chan_get_n` -- get number of enabled analog channels. - -* `set_t
` -- Set timings. - Parameter `dt` is measurement time [ms]. If N is number of enabled channels - then dt should be: N*conv_t < dt <= 1000*N*conv_t. It makes sense - only for block reads with multiple measurements which are not supported now. - Set this to the smallest possible value (N*conv_t+1). - Parameter `conv_t` is ADC conversion time for a single value [ms]. - Use longer times for more accurate measurements. - -* `get` -- collect and return a single data block. - Returns one value for each enabled channel. - `chan_set` and `set_t` should be done before. - In case of overflow +/-Inf is returned; \ No newline at end of file diff --git a/pico_adc/commands.cpp b/pico_adc/commands.cpp deleted file mode 100644 index de14d8b..0000000 --- a/pico_adc/commands.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include "commands.h" -#include "err/err.h" - -#include -#include -#include // gettimeofday - - -using namespace std; - -// compare strings -bool -is_cmd(const vector & args, const char *name){ - return strcasecmp(args[0].c_str(), name)==0; -} - -// print command list -const char * -cmd_help() { - return - "get_time -- Get current time.\n" - "*idn? -- Get ID string: \"pico_adc " VERSION "\".\n" - "help -- Get list of commands.\n" - "get_info -- Get device information.\n" - "ranges -- Get available range settings.\n" - "tconvs -- Get available conversion time settings.\n" - "get_val -- Measure a single value.\n" - "set_dig_out -- Set digital outputs.\n" - "\n" - " Below are commands for 'block read mode'.\n" - " It's not recommended to use them.\n" - "\n" - "chan_set -- set channel parameters\n" - " chs -- Channels: 01 to 16, multiple channels allowed\n" - " en -- Enable channels: 1 or 0\n" - " sngl -- Single/Differential mode: 1 or 0.\n" - " rng -- Input range, mV (see ranges command).\n" - "chan_get -- get channel parameters ( ,\n" - " or ' disabled' for disabled channels.\n" - "chan_get_n -- Get number of enabled analog channels.\n" - "set_t
-- Set timings.\n" - " dt -- time step between measurements\n" - " tconv -- conversion time for one channel (see tconvs command)\n" - "get -- collect and return a single data block.\n" - " chan_set and set_t should be done before.\n" - ; -} - -void -cmd(ADC24 & dev, const vector & args){ - if (args.size()<1) return; // should not happen - - // print time - if (is_cmd(args, "get_time")){ - if (args.size()!=1) throw Err() << "Usage: get_time"; - struct timeval tv; - gettimeofday(&tv, NULL); - cout << tv.tv_sec << "." << setfill('0') << setw(6) << tv.tv_usec << "\n"; - return; - } - - // print id - if (is_cmd(args, "*idn?")){ - if (args.size()!=1) throw Err() << "Usage: *idn?"; - cout << "pico_adc " VERSION "\n"; - return; - } - - // print help - if (is_cmd(args, "help")){ - if (args.size()!=1) throw Err() << "Usage: help"; - cout << cmd_help(); - return; - } - - // print device info - if (is_cmd(args, "get_info")){ - if (args.size()!=1) throw Err() << "Usage: get_info"; - dev.print_info(); - return; - } - - // show available range settings - if (is_cmd(args, "ranges")){ - if (args.size()!=1) throw Err() << "Usage: ranges"; - cout << dev.get_ranges() << "\n"; - return; - } - - // show available time conversion settings - if (is_cmd(args, "tconvs")){ - if (args.size()!=1) throw Err() << "Usage: tconvs"; - cout << dev.get_tconvs() << "\n"; - return; - } - - // get a single value. - if (is_cmd(args, "get_val")) { - if (args.size()!=5) throw Err() - << "Usage: get_val "; - - int ch = str_to_type(args[1]); - bool sngl = str_to_type(args[2]); - auto & rng = args[3]; - auto & convt = args[4]; - - auto v = dev.get_single(ch, sngl, rng, convt); - std::cout << v << "\n"; - return; - } - - // set digital output. - if (is_cmd(args, "set_dig_out")) { - if (args.size()!=5) throw Err() - << "Usage: get_val "; - int v = 0; - for (int i=0; i<4; i++) - v = (v<<1) | (str_to_type(args[i+1])? 1:0); - dev.set_dig_out(v); - return; - } - - // Block read commands: - - // set channel parameters for block mode - if (is_cmd(args, "chan_set")) { - if (args.size()!=5) throw Err() - << "Usage: chan_set "; - // set multiple channels - int8_t len = args[1].length(); - - if (len!=1 && len%2) throw Err() << "bad channel option"; - for (int i=0; i(sch); - auto en = str_to_type(args[2]); - auto sngl = str_to_type(args[3]); - auto & rng = args[4]; - dev.set_channel(ch, en, sngl, rng); - } - return; - } - - // disable all channels - if (is_cmd(args, "disable_all")) { - if (args.size()!=1) throw Err() << "Usage: disable_all"; - dev.disable_all(); - return; - } - - // print number of active channels for block mode - if (is_cmd(args, "chan_get_n")){ - if (args.size()!=1) throw Err() << "Usage: get_chan_n"; - cout << dev.chan_get_num() << "\n"; - return; - } - - // set timings for block mode - if (is_cmd(args, "set_t")){ - if (args.size()!=3) throw Err() << "Usage: set_t
"; - dev.set_timing(str_to_type(args[1]), args[2]); - return; - } - - // get values in block mode - if (is_cmd(args, "get")) { - if (args.size()!=1) throw Err() - << "Usage: get"; - - int16_t nvals = 1; - auto v = dev.get_block(nvals); - - auto nchan = dev.chan_get_num(); - if (nvals*nchan != v.size()) - throw Err() << "get_block() returned wrong number of samples"; - - for (size_t nv = 0; nv0) std::cout << " "; - std::cout << v[ind]; - } - std::cout << "\n"; - } - return; - } - - throw Err() << "Unknown command: " << args[0]; -} diff --git a/pico_adc/commands.h b/pico_adc/commands.h deleted file mode 100644 index 617affa..0000000 --- a/pico_adc/commands.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef COMMANDS_H -#define COMMANDS_H - -#include "device.h" -#include -#include - -// define all SPP commands -void cmd(ADC24 &dev, const std::vector & args); - -#endif diff --git a/pico_adc/device.cpp b/pico_adc/device.cpp deleted file mode 100644 index de8ee14..0000000 --- a/pico_adc/device.cpp +++ /dev/null @@ -1,326 +0,0 @@ -#include // strcasecmp -#include // usleep -#include -#include -#include -#include -#include // setfill -#include "err/err.h" - -#include -#include "device.h" -#include "ADC24_const.h" - -using namespace std; - -/**********************************************************/ -// return newline-separated list of all connected devices -// See code in https://github.com/picotech/picosdk-c-examples/blob/master/picohrdl/picohrdlCon/picohrdlCon.c -std::string -ADC24::dev_list(){ - std::string ret; - int16_t devices[HRDL_MAX_PICO_UNITS]; - - for (int i = 0; i < HRDL_MAX_UNITS; i++) { - devices[i] = HRDLOpenUnit(); - if (devices[i] > 0) { - auto line = get_unit_info(devices[i], HRDL_BATCH_AND_SERIAL); - ret += line + "\n"; - } - else { - auto err = str_to_type(get_unit_info(devices[i], HRDL_ERROR)); - if (err != HRDL_NOT_FOUND) - throw Err() << "can't open device " << i << ":" << err_to_str(err); - } - } - // close devices - for (int i = 0; i < HRDL_MAX_PICO_UNITS; i++) { - if (devices[i] > 0) HRDLCloseUnit(devices[i]); - } - return ret; -} - -// Constructor and destructor: open/close device, throw errors if any. -// See code in https://github.com/picotech/picosdk-c-examples/blob/master/picohrdl/picohrdlCon/picohrdlCon.c -// for their strange way of finding correct device... -ADC24::ADC24(const std::string & name): time_conf(false){ - - // open all devices, as in dev_list() - int16_t devices[HRDL_MAX_PICO_UNITS]; - devh=-1; devn=-1; - - // initialize device array - for (int i = 0; i < HRDL_MAX_UNITS; i++) devices[i] = 0; - - // open all devices, as in dev_list(), find which one to use - for (int i = 0; i < HRDL_MAX_UNITS; i++) { - devices[i] = HRDLOpenUnit(); - if (devices[i] > 0) { - auto line = get_unit_info(devices[i], HRDL_BATCH_AND_SERIAL); - if (name=="" || strcasecmp(name.c_str(), line.c_str())==0){ - devh = devices[i]; devn = i; break; - } - } - } - - // close all devices except one - for (int i = 0; i < HRDL_MAX_PICO_UNITS; i++) { - if (devices[i] > 0 && i!=devn) HRDLCloseUnit(devices[i]); - } - - if (devn == -1){ - if (name=="") throw Err() << "No PicoLog devices found"; - else throw Err() << "PicoLog device not found: " << name; - } - - chconf.resize(HRDL_MAX_ANALOG_CHANNELS); -} - -// destructor -ADC24::~ADC24(){ - HRDLCloseUnit(devh); -} - - -/**********************************************************/ - -// Returns unit info for a device handle (used in list method and constuctor) -std::string -ADC24::get_unit_info(const int16_t h, const uint16_t info) { - std::string str('0', 80); - if (!HRDLGetUnitInfo(h,(int8_t *)str.data(),str.size(),info)) - throw Err() << "failed to get unit info"; - return str; -} - -std::string -ADC24::get_error(){ - // In the case of parameter error HRDL returns strange string: 8PPPP<...>. - // Use only the first digit to get error code: - auto e = get_unit_info(devh, HRDL_ERROR); - int ne = e.size()? e[0]-'0' : 0; - if (ne != 0 && ne != 8) return err_to_str(ne); - - e = get_unit_info(devh, HRDL_SETTINGS); - ne = e.size()? e[0]-'0' : 0; - return serr_to_str(ne); -} - -// configures the mains noise rejection setting -void -ADC24::set_mains(bool m60Hz) { - if (!HRDLSetMains(devh,m60Hz)) - throw Err() << "failed to set mains: " << get_error(); -} - -// get device information -void -ADC24::print_info(){ - const int16_t ui_buflen=1024; - char ui_v[ui_buflen],ui_n[ui_buflen]; - std::cout << "DRIVER_VERSION: " << get_unit_info(devh, HRDL_DRIVER_VERSION) << "\n"; - std::cout << "HARDWARE_VERSION: " << get_unit_info(devh, HRDL_HARDWARE_VERSION) << "\n"; - std::cout << "VARIANT_INFO: " << get_unit_info(devh, HRDL_VARIANT_INFO) << "\n"; - std::cout << "BATCH_AND_SERIAL: " << get_unit_info(devh, HRDL_BATCH_AND_SERIAL) << "\n"; - std::cout << "CAL_DATE: " << get_unit_info(devh, HRDL_CAL_DATE) << "\n"; - std::cout << "KERNEL_DRIVER_VERSION: " << get_unit_info(devh, HRDL_KERNEL_DRIVER_VERSION) << "\n"; - std::cout << "ERROR CODE: " << get_unit_info(devh, HRDL_ERROR) << "\n"; - std::cout << "SETTINGS ERROR CODE: " << get_unit_info(devh, HRDL_SETTINGS) << "\n"; - std::cout << "ERROR MESSAGE: " << get_error() << "\n"; -} - -// get available range constants -std::string -ADC24::get_ranges(){ - std::string ret; - for (int i = 0; i != HRDL_MAX_RANGES; ++i) { - if (i>0) ret+=" "; - ret+=range_to_str((HRDL_RANGE)i); - } - return ret; -} - -// get available time conversion constants -std::string -ADC24::get_tconvs() { - std::string ret; - for (int i = 0; i != HRDL_MAX_CONVERSION_TIMES; ++i) { - if (i>0) ret+=" "; - ret+=convt_to_str((HRDL_CONVERSION_TIME)i); - } - return ret; -} - -// measure a single value with full channel setup. -double -ADC24::get_single( const int ch, const bool single, - const std::string & rng, const std::string & convt ) { - - // more understandable error message: - if (ch<1 || ch>HRDL_MAX_ANALOG_CHANNELS) throw Err() - << "channel number out of range"; - if (ch%2==0 && !single) throw Err() - << "only odd channels can be set for differential measurements"; - - int32_t val; - int16_t ovfl; - - // get value - auto res = HRDLGetSingleValue(devh, ch, str_to_range(rng), - str_to_convt(convt), (int16_t)single, &ovfl, &val); - - if (res==0) throw Err() - << "can't get value from ADC: " << get_error(); - - // Block mode channel configuration becomes invalid after - // call to HRDLGetSingleValue. Update it. - for (int n=1; n<=HRDL_MAX_ANALOG_CHANNELS; n++){ - ChConf_t C; - if (ch == n){ // only one channel enabled - C.en = true; C.rng = str_to_range(rng); - C.sngl = single; - } - chconf[(int)ch] = C; - } - - // get max integer value - int32_t min,max; - if (!HRDLGetMinMaxAdcCounts(devh,&min,&max,ch)) - throw Err() << "failed to get max ADC count: " << get_error(); - - double v = (str_to_volt(rng)*val)/max; - if (ovfl & (1<HRDL_MAX_ANALOG_CHANNELS) throw Err() - << "channel number out of range"; - if (ch%2==0 && !single) throw Err() - << "only odd channels can be set for differential measurements"; - - // convert values to ADC24 types. - ChConf_t C; - C.en = enable; C.sngl = single; - C.rng = str_to_range(rng); - - // apply changes - if (!(HRDLSetAnalogInChannel(devh,ch,C.en,C.rng,C.sngl))) - throw Err() << "failed to set channel " << ch << ": " << get_error(); - - // get max/min SDC count for this channel - if (!HRDLGetMinMaxAdcCounts(devh,&C.min,&C.max,ch)) - throw Err() << "failed to get min/max ADC count: " << get_error(); - - chconf[ch] = C; // save channel configuration -} - -// Disable all channels -void -ADC24::disable_all(){ - for (int ch=1; ch<=HRDL_MAX_ANALOG_CHANNELS; ch++){ - ChConf_t C; - if (!(HRDLSetAnalogInChannel(devh,ch,false,C.rng,true))) - throw Err() << "failed to disable channel " << ch << ": " << get_error(); - chconf[(int)ch] = C; - } -} - -// Print channel settings. -void -ADC24::print_channel(int ch){ - if (chconf[ch].en) { - cout << ch << " " - << chconf[ch].en << " " - << chconf[ch].sngl << " " - << range_to_str(chconf[ch].rng) << "\n"; - } - else cout << ch << " disabled\n"; -} - -// Set timing parameters. -void -ADC24::set_timing(int32_t dt, const std::string & convt){ - if (!HRDLSetInterval(devh,dt,str_to_convt(convt))) - throw Err() << "failed to set timings: " << get_error(); - time_conf = true; -} - -// Returns the number of channels enabled. -int -ADC24::chan_get_num(){ - int16_t n; - if (HRDLGetNumberOfEnabledChannels(devh, &n)) return n; - throw Err() << "can't get number of enabled channels: " << get_error(); - return n; -} - -// Returns list of enabled channels. -std::vector -ADC24::chan_get_list(){ - std::vector ret; - for (int i=0; i -ADC24::get_block(int32_t nvals) { - - // check if timings are configured (or block mode will stuck!) - if (!time_conf) throw Err() << "timings are not configured"; - - if (!chan_get_num()) throw Err() << "channels are not configured"; - - // run block mode for a ginev number of readings - if (!HRDLRun(devh, nvals, HRDL_BM_BLOCK)) - throw Err() << "failed to run block mode: " << get_error(); - - // wait until values are ready - while (1) { - usleep(1000); - if (HRDLReady(devh)) break; - } - - // get list of enabled channels, allocate data arrays - auto ch_e = chan_get_list(); - size_t N = nvals*ch_e.size(); - std::vector ivals(N); - std::vector vals(N); - std::vector ovfl(nvals); - - // read data, (res - actual number of samples) - auto res = HRDLGetValues(devh,ivals.data(),ovfl.data(),nvals); - if (res==0) throw Err() << "can't get values from ADC: " << get_error(); - - // convert int data to double - for (int32_t nv = 0; nv -#include -#include -#include - -// analog channel configuration -struct ChConf_t{ - int16_t en; - int16_t sngl; - HRDL_RANGE rng; - int32_t min, max; - ChConf_t(): en(false), sngl(false), rng(HRDL_2500_MV),min(-1),max(1) {} -}; - -class ADC24{ - -protected: - std::vector chconf; // channel configuration for block mode - int16_t devh; // device handle - int16_t devn; // device number (1..20) - bool time_conf; // are timings configured (block mode stucks if not!) - -public: - - /**********************************************************/ - - // return list of available devices - static std::string dev_list(); - - // constructor: find and open device with the name - ADC24(const std::string & name); - - // destructor: close device - ~ADC24(); - - /**********************************************************/ - - // General device/program settings - - // Return unit information for a handler (used in list method - // and constuctor with different handlers). - static std::string get_unit_info(const int16_t h, const uint16_t info); - - // Get error information and return message - std::string get_error(); - - // Configure the mains noise rejection setting (60 or 50 Hz). - void set_mains(const bool m60Hz); - - // Print device information. - void print_info(); - - // Get available range constants. - std::string get_ranges(); - - // Get available time conversion constants. - std::string get_tconvs(); - - // Measure a single value with full channel setup. - // (no need for other setup functions) - // returns overflow flag. - double get_single(const int ch, const bool single, - const std::string & rng, const std::string & convt); - - // Set four digital lines as outputs, set values - // according with the bitmask - void set_dig_out(const int bitmask); - - // Block read mode (set channels, set timings, read data block). - // Using this mode by multiple users (through device server) - // will require device locking between setting parameters - // and making the measurement. - - // Set channel parameters. - void set_channel(int chan, bool enable, - bool single, const std::string & rng); - - // Disable all channels - void disable_all(); - - // Print channel settings. - void print_channel(int chan); - - // Set timing parameters. - void set_timing(int32_t dt, const std::string & convt); - - // Returns the number of channels enabled. - int chan_get_num(); - - // Returns list of enabled channels. - std::vector chan_get_list(); - - // Get block of data. - std::vector get_block(int32_t nvals); - -}; - -/*************************/ - -#include -#include -#include "err/err.h" -// convert values to strings and back -template -T str_to_type(const std::string & s){ - std::istringstream ss(s); - T val; - ss >> std::showbase >> val; - if (ss.fail() || !ss.eof()) - throw Err() << "can't parse value: \"" << s << "\""; - return val; -} -template -std::string type_to_str(const T & t){ - std::ostringstream ss; - ss << t; - return ss.str(); -} - -#endif diff --git a/pico_adc/pico_adc.cpp b/pico_adc/pico_adc.cpp deleted file mode 100644 index 88e88e3..0000000 --- a/pico_adc/pico_adc.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include - -#include "err/err.h" -#include "read_words/read_words.h" - -#include "device.h" -#include "commands.h" - -/* SPP-compatable interface to ADC-24 device */ - -using namespace std; - -/*********************************************************************/ -int -main(int argc, char *argv[]){ - try { - - /* default values */ - const char *dev=""; - int16_t mainsHz; - - /* parse options */ - while(1){ - opterr=0; - int c = getopt(argc, argv, "hm:d:l"); - if (c==-1) break; - switch (c){ - case '?': - case ':': throw Err() << "incorrect options, see -h"; /* error msg is printed by getopt*/ - case 'd': dev = optarg; break; - case 'l': cout << ADC24::dev_list(); return 0; - - case 'm': - mainsHz=atoi(optarg); - if (mainsHz != 50 && mainsHz != 60) throw Err() - << "incorrect mains freq. option: should be 50 or 60 Hz"; - break; - case 'h': - cout << "pico_adc -- record values using Pico ADC\n" - "Usage: pico_adc [options]\n" - "Options:\n" - " -l -- list all connected devices and exit\n" - " -d -- device ID (autodetect by default)\n" - " -m -- set mains frequency, Hz (50 or 60, default: 50)\n" - " -h -- write this help message and exit\n"; - return 0; - } - } - - // open the device - ADC24 adc24(dev); - // configure the mains noise rejection - adc24.set_mains(mainsHz == 60); - - cout << "#SPP001\n"; // a command-line protocol, version 001. - cout << "Pico ADC24 device is opened. Type help to see command list.\n"; - cout << "#OK\n"; - while (1){ - try { - auto args = read_words(cin); - if (args.size()<1) break; - cmd(adc24, args); - cout << "#OK\n" << flush; - } - catch (Err E){ cout << "\n#Error: " << E.str() << "\n" << flush; } - } - - } - catch (Err E){ - cout << "#SPP001\n"; // a command-line protocol, version 001. - cerr << "#Error: " << E.str() << "\n"; - return 1; - } - -} diff --git a/pico_osc-9999.ebuild b/pico_osc-9999.ebuild index 378c43b..a6ac150 100644 --- a/pico_osc-9999.ebuild +++ b/pico_osc-9999.ebuild @@ -28,7 +28,6 @@ src_compile() { } src_install() { - dobin pico_adc/pico_adc dobin pico_osc/pico_osc dobin sig_filter/{sig_filter,sig_pnmtopng,sig_pnginfo} dobin sig_viewer/sig_viewer diff --git a/pico_osc/device4224.h b/pico_osc/device4224.h index e1c4042..6df99e7 100644 --- a/pico_osc/device4224.h +++ b/pico_osc/device4224.h @@ -227,11 +227,37 @@ class Pico4224 : public PicoOsc { // convert time step (seconds) into timebase: dt2tbase(dt); uint32_t dt2tbase(float dt){ - // this works only for 4224, 4224, 4432, 4424 - if (dt <= 12e-9) return 0; - if (dt <= 50e-9) return round(log(8e7*dt)); - if (dt <= (pow(2,30)-2)/2e7) return floor(2e7*dt+1); - return (1<<30)-1; + + // get oscilloscope model + const int16_t buflen=1024; + char buf[buflen]; + int16_t res,len; + res = ps4000GetUnitInfo(h,(int8_t *)buf,buflen,&len, PICO_VARIANT_INFO); + if (res!=PICO_OK) throw Err() << "GetUnitInfo error: " << pico_err(res); + std::string model(buf, len-1); // last char is \r? + + if (model=="4262"){ + if (dt <= 0) return 0; + if (dt <= pow(2,30)/1e7) return floor(1e7*dt-1); + return (1<<30)-1; + } + if (model=="4226" || model=="4227"){ + if (dt <= 8e-9) return 0; + if (dt <= 16e-9) return 1; + if (dt <= 32e-9) return 2; + if (dt <= 64e-9) return 3; + if (dt <= (pow(2,30)-3)/3.125e7) return floor(3.125e7*dt+1); + return (1<<30)-1; + } + if (model=="4223" || model=="4224" || + model=="4423" || model=="4424"){ + if (dt <= 25e-9) return 0; + if (dt <= 50e-9) return 1; + if (dt <= 100e-9) return 2; + if (dt <= (pow(2,30)-2)/2e7) return floor(2e7*dt+1); + return (1<<30)-1; + } + throw Err() << "dt2tbase: unknown oscilloscope model: " << model; } // show data buffer to oscilloscope: set_buff("A",buf); diff --git a/pico_osc/test_osc_gen b/pico_osc/test_osc_gen index 21d9efc..4186d92 100755 --- a/pico_osc/test_osc_gen +++ b/pico_osc/test_osc_gen @@ -2,7 +2,7 @@ # A is genegator output: burst mode 32764Hz, 10V, 100 cycles # B is fork output -./pico_rec < Mon, 20 Nov 2023 19:16:02 +0000 diff --git a/pico_repack/libpico.debian/debian/compat b/pico_repack/libpico.debian/debian/compat new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/pico_repack/libpico.debian/debian/compat @@ -0,0 +1 @@ +10 diff --git a/pico_repack/libpico.debian/debian/control b/pico_repack/libpico.debian/debian/control new file mode 100644 index 0000000..c5be8ce --- /dev/null +++ b/pico_repack/libpico.debian/debian/control @@ -0,0 +1,9 @@ +Source: libpico +Section: alien +Priority: extra +Maintainer: Slava Zavjalov + +Package: libpico +Architecture: amd64 +Depends: ${shlibs:Depends} +Description: Pico Technology libraries (repacked) diff --git a/pico_repack/libpico.debian/debian/copyright b/pico_repack/libpico.debian/debian/copyright new file mode 100644 index 0000000..31d819a --- /dev/null +++ b/pico_repack/libpico.debian/debian/copyright @@ -0,0 +1,17 @@ +This package was debianized by the alien program by converting +a binary .deb package on Mon, 20 Nov 2023 19:16:02 +0000 + +Copyright: see /usr/share/doc/libpicohrdl/copyright + +Information from the binary package: +Package: libpicohrdl +Version: 2.0.17-1r1441 +Architecture: amd64 +Maintainer: Pico Support +Installed-Size: 318 +Depends: debconf (>= 0.5) | debconf-2.0, libc6 (>= 2.3.2), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.1.1), libusb-1.0-0 (>= 2:1.0.8) +Section: libs +Priority: extra +Homepage: +Description: Pico Technology High Resolution Data Logger + diff --git a/pico_repack/libpico.debian/debian/rules b/pico_repack/libpico.debian/debian/rules new file mode 100755 index 0000000..5f1ca4b --- /dev/null +++ b/pico_repack/libpico.debian/debian/rules @@ -0,0 +1,39 @@ +#!/usr/bin/make -f +# debian/rules for alien + +PACKAGE=$(shell dh_listpackages) + +%: + dh $@ + +override_dh_clean: + dh_clean -d + +override_dh_auto_configure: + +override_dh_auto_build: + +override_dh_auto_install: + mkdir -p debian/$(PACKAGE) + # Copy the packages's files. + find . -maxdepth 1 -mindepth 1 -not -name debian -print0 | \ + sed -e s#'./'##g | \ + xargs -0 -r -i cp -a ./{} debian/$(PACKAGE)/{} +# +# If you need to move files around in debian/$(PACKAGE) or do some +# binary patching, do it here +# + +override_dh_strip: +# This has been known to break on some wacky binaries. + # dh_strip + +override_dh_usrlocal: + -dh_usrlocal || printf "Your package seems to be installing files into /usr/local/, which could be buggy. Will continue anyway.\n" + +override_dh_fixperms: +# dh_fixperms + +override_dh_shlibdeps: + -dh_shlibdeps + diff --git a/pico_repack/repack b/pico_repack/repack index d5587da..b0cf02f 100755 --- a/pico_repack/repack +++ b/pico_repack/repack @@ -7,8 +7,8 @@ info='\ -libp libpicoipp 1.3.0 4r21 -libp libps4000 2.1.0 2r570 +libp libpicoipp 1.4.0 4r133 +libp libps4000 2.1.83 2r3073 libp libpicohrdl 2.0.17 1r1441 ' #arches="amd64 i386" @@ -18,7 +18,7 @@ rpm_name="libpico" for arch in $arches; do - dest="$HOME/tmp/libpico-buildroot" + dest="libpico.rpm" rm -rf -- ${dest} libdir=/usr/lib @@ -36,7 +36,8 @@ for arch in $arches; do echo Processing: ${name}_${ver}-${rel}_${arch} ### download packages. ### check for new versions! -# wget http://labs.picotech.com/debfix/pool/main/${dir}/${name}/${fname} + [ -f $fname ] || + wget http://labs.picotech.com/debian/pool/main/${dir}/${name}/${fname} rm -rf -- ${dname} alien --to-rpm -g ${fname} diff --git a/pico_repack/repack_deb b/pico_repack/repack_deb new file mode 100755 index 0000000..db8dca0 --- /dev/null +++ b/pico_repack/repack_deb @@ -0,0 +1,53 @@ +#!/bin/sh + +# Repack pico libraries into a single altlinux RPM +# Debian packages are downloaded from +# http://labs.picotech.com/debian/pool/main/ +# check for new versions! + + +info='\ +libp libpicoipp 1.4.0 4r133 +libp libps4000 2.1.83 2r3073 +libp libpicohrdl 2.0.17 1r1441 +' +#arches="amd64 i386" +arches="amd64" +rpm_ver="1.2" +rpm_name="libpico" + +for arch in $arches; do + + dest="libpico.debian" + rm -rf -- ${dest}/usr + + libdir=/usr/lib + [ "$arch" != "amd64" ] || libdir=/usr/lib64 + incdir=/usr/include/pico + docdir=/usr/share/doc/pico + mkdir -p -- $dest/$libdir $dest/$incdir $dest/$docdir + + echo "$info" | + while read dir name ver rel; do + [ -n "$name" ] || continue + fname=${name}_${ver}-${rel}_${arch}.deb + oname=${name}-${ver}.orig + dname=${name}-${ver} + + echo Processing: ${name}_${ver}-${rel}_${arch} + ### download packages. + ### check for new versions! + [ -f $fname ] || + wget http://labs.picotech.com/debian/pool/main/${dir}/${name}/${fname} + + rm -rf -- ${dname} ${oname} + alien --to-deb -g ${fname} + mv ${oname}/opt/picoscope/lib/* ${dest}/$libdir + mv ${oname}/opt/picoscope/include/*/* ${dest}/$incdir + mv ${oname}/opt/picoscope/share/doc/${name}/* ${dest}/$docdir + mv ${oname}/usr/share/doc/${name}/* ${dest}/$docdir +# rm -rf -- ${dname} + done +done + +cd libpico.debian && ./build diff --git a/sig_filter/Makefile b/sig_filter/Makefile index 4d28395..4f50ff8 100644 --- a/sig_filter/Makefile +++ b/sig_filter/Makefile @@ -4,7 +4,7 @@ PROGRAMS := sig_filter testsig_decay testsig_2decay testsig_noise\ MOD_SOURCES := filters.cpp MOD_HEADERS := filters.h -LDLIBS += -lm -lfftw3 -lpng +LDLIBS += -lm -lpng CPPFLAGS += -g MODDIR = ../modules diff --git a/sig_filter/filters.cpp b/sig_filter/filters.cpp index e3d18da..76c0af6 100644 --- a/sig_filter/filters.cpp +++ b/sig_filter/filters.cpp @@ -27,26 +27,6 @@ using namespace std; -/******************************************************************/ -void -flt_txt(ostream & ff, const Signal & s, const int argc, char **argv){ - const char *name = "txt"; - if (argc>1) throw Err() << name << ": extra argument found: " << argv[1]; - - int N = s.get_n(); - int cN = s.get_ch(); - if (N<1 || cN<1) return; - - ff << scientific; - for (int i=0; i0) throw Err() << name << ": extra argument found: " << argv[0]; @@ -1019,7 +1001,7 @@ fitn(ostream & ff, const Signal & s, const int argc, char **argv) { ind.push_back(is); fre.push_back(ret[0]); rel.push_back(ret[1]); - amp.push_back(ret[2]/2); + amp.push_back(ret[2]); ph.push_back(ret[3]); // subtract it @@ -1030,15 +1012,16 @@ fitn(ostream & ff, const Signal & s, const int argc, char **argv) { } // sort results by frequency - - class sort_indices{ - private: - std::vector mparr; - public: - sort_indices(std::vector parr) : mparr(parr) {} - bool operator()(int i, int j) const { return mparr[i] mparr; + public: + sort_indices(std::vector parr) : mparr(parr) {} + bool operator()(int i, int j) const { return mparr[i]1) throw Err() << name << ": extra argument found: " << argv[1]; + + write_txt(ff, s); +} diff --git a/sig_filter/sig_filter.cpp b/sig_filter/sig_filter.cpp index 3584b2a..7f11b17 100644 --- a/sig_filter/sig_filter.cpp +++ b/sig_filter/sig_filter.cpp @@ -34,8 +34,6 @@ void help(){ " Signals are aligned by t=0 point and cropped to the shortest signal.\n" " -c, -T, -U options are applied to each signal before joining.\n" "Filters:\n" - " txt -- Print a text table with all channels.\n" - " No filter options.\n" " pnm -- Make image with all channels.\n" " Options:\n" " -W -- image width, pixels (default: 1024)\n" @@ -125,6 +123,7 @@ void help(){ " -F -- low frequency limit\n" " -G -- high frequency limit\n" " -N -- number of signals (default 1)\n" + " -s (1|0) -- sort results by frequency (default 1)\n" " lockin -- Detect signal using another channel as reference.\n" " Options:\n" " -F -- low frequency limit\n" @@ -154,6 +153,8 @@ void help(){ " -G -- high frequency limit\n" " sig -- Print SIG file.\n" " wav -- Print WAV file.\n" + " txt -- Print text file.\n" + " No filter options.\n" ; } diff --git a/sig_filter/test_fit/plot.gp b/sig_filter/test_fit/plot.gp deleted file mode 100755 index 197a9a4..0000000 --- a/sig_filter/test_fit/plot.gp +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/gnuplot - -set title "1 correlation" -plot [][0:1.5]\ - "dat1.0.nc.txt" using 1:2 with lines,\ - "dat1.0.nc.txt" using 1:3 with lines,\ - "dat1.0.co.txt" using 1:2 with lines - -pause -1 - -set title "1/2 correlation" -plot [][0:1.5]\ - "dat0.5.nc.txt" using 1:2 with lines,\ - "dat0.5.nc.txt" using 1:3 with lines,\ - "dat0.5.co.txt" using 1:2 with lines - -pause -1 - - -set title "0 correlation" -plot [][0:1.5]\ - "dat0.0.nc.txt" using 1:2 with lines,\ - "dat0.0.nc.txt" using 1:3 with lines,\ - "dat0.0.co.txt" using 1:2 with lines - -pause -1 diff --git a/modules/fit_signal/test/.gitignore b/sig_filter/test_fit_py/.gitignore similarity index 100% rename from modules/fit_signal/test/.gitignore rename to sig_filter/test_fit_py/.gitignore diff --git a/modules/fit_signal/test/run_test b/sig_filter/test_fit_py/run_test similarity index 100% rename from modules/fit_signal/test/run_test rename to sig_filter/test_fit_py/run_test diff --git a/modules/fit_signal/test/test_freq b/sig_filter/test_fit_py/test_freq similarity index 100% rename from modules/fit_signal/test/test_freq rename to sig_filter/test_fit_py/test_freq diff --git a/sig_filter/test_fit_signal/Makefile b/sig_filter/test_fit_signal/Makefile deleted file mode 100644 index ef18b0d..0000000 --- a/sig_filter/test_fit_signal/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -LDLIBS = -lm -lfftw3 -CPPFLAGS = -g -CC=g++ - -all: test_fit_signal - ./test_fit_signal > res.txt - ./plot_res.gp - -test_fit_signal: test_fit_signal.cpp ../fit_signal.cpp - -clean: - rm -f *.o test_fit_signal - - - diff --git a/sig_filter/test_fit_signal/plot_res.gp b/sig_filter/test_fit_signal/plot_res.gp deleted file mode 100755 index 699261d..0000000 --- a/sig_filter/test_fit_signal/plot_res.gp +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/gnuplot - -set title "Frequency, relative error" -plot \ - "res.txt" using 0:($1/32674-1) pt 7 title "fre" - -pause -1 - -set title "Relaxartion time, relative error" -plot \ - "res.txt" using 0:(1/$2/0.925-1) pt 7 title "tau" -pause -1 - - -set title "Amplitude, relative error" -plot \ - "res.txt" using 0:($3/0.582-1) pt 7 title "amp" - -pause -1 - -set title "Phase" -plot \ - "res.txt" using 0:($4) pt 7 title "amp", 0.1234 - -pause -1 diff --git a/sig_filter/test_fit_signal/test_fit_signal.cpp b/sig_filter/test_fit_signal/test_fit_signal.cpp deleted file mode 100644 index fbad5c5..0000000 --- a/sig_filter/test_fit_signal/test_fit_signal.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "../fit_signal.h" - -using namespace std; - -main(){ - // parameters - double dt = 0.411e-5; - double f0 = 32674; - double w0 = 2*M_PI*f0; - double tau = 0.925; - double amp = 0.582; - double ph = 0.1234; - double noise = 0.5; - - int N1 = 10; - int N2 = 10000; - - - for (N2=100000; N2<100150; N2++){ - int N=N2-N1; - vector buf(N); - int max=1<<15; - double sc = (amp+noise)/max; - - // build a pure sine signal - for (int i = N1; i ret = fit_signal(buf.data(), buf.size(), sc, dt, N1*dt); - cout << setprecision(12) << ret[0] << " " - << setprecision(6) << ret[1] << " " - << setprecision(6) << ret[2] << " " - << setprecision(6) << ret[3] << "\n"; - } - -} diff --git a/sig_filter/test_fit_signal1/Readme b/sig_filter/test_fit_signal1/Readme deleted file mode 100644 index 5d246d4..0000000 --- a/sig_filter/test_fit_signal1/Readme +++ /dev/null @@ -1,7 +0,0 @@ -test signal fitting: - -w1rXX -- weight setting y^4 -w2rXX -- weight setting 1/(x^2 + 1/t)^2 - -XX -- 1/2 of fitting range in 1/tau -w1r1.txt means range -1/tau..1/tau \ No newline at end of file diff --git a/sig_filter/test_fit_signal1/mktest b/sig_filter/test_fit_signal1/mktest deleted file mode 100755 index 76f6d2c..0000000 --- a/sig_filter/test_fit_signal1/mktest +++ /dev/null @@ -1,6 +0,0 @@ -for n in 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0; do - ../testsig_decay -T 0.1 -A 1 -n $n -F 2132 -D 2.27e-5 -N 44000 > a.sig - a=$(../sig_filter -f fit a.sig) - echo "$n $a" -done > a.txt - diff --git a/sig_filter/test_fit_signal1/plot_amp b/sig_filter/test_fit_signal1/plot_amp deleted file mode 100755 index d6be496..0000000 --- a/sig_filter/test_fit_signal1/plot_amp +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/gnuplot - -set xlabel "noise/signal ratio" -set ylabel "amplitude" - -plot\ - "w1r2pi.txt" using 1:5 with linespoints pt 6,\ - "w1r2.txt" using 1:5 with linespoints pt 6,\ - "w1r1.txt" using 1:5 with linespoints pt 6,\ - "w1r.5.txt" using 1:5 with linespoints pt 6,\ - "w1r.25.txt" using 1:5 with linespoints pt 6,\ - "w2r1.txt" using 1:5 with linespoints pt 6,\ -2 - -pause -1 \ No newline at end of file diff --git a/sig_filter/test_fit_signal1/plot_fre b/sig_filter/test_fit_signal1/plot_fre deleted file mode 100755 index 8434e16..0000000 --- a/sig_filter/test_fit_signal1/plot_fre +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/gnuplot - -set xlabel "noise/signal ratio" -set ylabel "freq" - -plot\ - "w1r2pi.txt" using 1:3 with linespoints pt 6,\ - "w1r2.txt" using 1:3 with linespoints pt 6,\ - "w1r1.txt" using 1:3 with linespoints pt 6,\ - "w1r.5.txt" using 1:3 with linespoints pt 6,\ - "w1r.25.txt" using 1:3 with linespoints pt 6,\ - "w2r1.txt" using 1:3 with linespoints pt 6,\ -2132 - -pause -1 \ No newline at end of file diff --git a/sig_filter/test_fit_signal1/plot_ph b/sig_filter/test_fit_signal1/plot_ph deleted file mode 100755 index 8bee8a1..0000000 --- a/sig_filter/test_fit_signal1/plot_ph +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/gnuplot - -set xlabel "noise/signal ratio" -set ylabel "phase" - -plot\ - "w1r2pi.txt" using 1:6 with linespoints pt 6,\ - "w1r2.txt" using 1:6 with linespoints pt 6,\ - "w1r1.txt" using 1:6 with linespoints pt 6,\ - "w1r.5.txt" using 1:6 with linespoints pt 6,\ - "w1r.25.txt" using 1:6 with linespoints pt 6,\ - "w2r1.txt" using 1:6 with linespoints pt 6,\ -0.1 - -pause -1 \ No newline at end of file diff --git a/sig_filter/test_fit_signal1/plot_tau b/sig_filter/test_fit_signal1/plot_tau deleted file mode 100755 index 047819d..0000000 --- a/sig_filter/test_fit_signal1/plot_tau +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/gnuplot - -set xlabel "noise/signal ratio" -set ylabel "decay time" - -plot\ - "w1r2pi.txt" using 1:(1/$4) with linespoints pt 6 title "2pi/tau",\ - "w1r2.txt" using 1:(1/$4) with linespoints pt 6 title "2/tau",\ - "w1r1.txt" using 1:(1/$4) with linespoints pt 6 title "1/tau",\ - "w1r.5.txt" using 1:(1/$4) with linespoints pt 6 title "1/2tau",\ - "w1r.25.txt" using 1:(1/$4) with linespoints pt 6 title "1/25tau",\ - "w2r1.txt" using 1:(1/$4) with linespoints pt 6 title "1/tau --",\ -0.1 - -pause -1 \ No newline at end of file diff --git a/sig_filter/tests/.gitignore b/sig_filter/tests/.gitignore deleted file mode 100644 index bdb1039..0000000 --- a/sig_filter/tests/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.txt -*.dat -*.png \ No newline at end of file diff --git a/sig_filter/tests/plot_fft.gp b/sig_filter/tests/plot_fft.gp deleted file mode 100755 index 40e8eb7..0000000 --- a/sig_filter/tests/plot_fft.gp +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/gnuplot - -plot "ex1ch_fft.txt" using 1:(sqrt($2**2+$3**2)) with lines -pause -1 - -plot "ex2ch_fft.txt" using 1:(sqrt($2**2+$3**2)) with lines -pause -1 - -plot "test1_fft.txt" using 1:(sqrt($2**2+$3**2)) with lines -pause -1 - -plot "test2_fft.txt" using 1:(sqrt($2**2+$3**2)) with lines -pause -1 diff --git a/sig_filter/tests/plot_raw.gp b/sig_filter/tests/plot_raw.gp deleted file mode 100755 index 5cc880d..0000000 --- a/sig_filter/tests/plot_raw.gp +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/gnuplot - -set terminal x11 -plot "ex1ch.txt" with lines -pause -1 - -plot "ex2ch.txt" with lines -pause -1 - -plot "test1.txt" with lines -pause -1 - -plot "test2.txt" with lines -pause -1 diff --git a/sig_filter/tests/plot_sfft.gp b/sig_filter/tests/plot_sfft.gp deleted file mode 100755 index 11b7d2e..0000000 --- a/sig_filter/tests/plot_sfft.gp +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/gnuplot - -set terminal x11 -splot "ex1ch_sfft.txt" using 1:2:(sqrt($3**2+$4**2)) with lines -pause -1 - -splot "ex2ch_sfft.txt" using 1:2:(sqrt($3**2+$4**2)) with lines -pause -1 - -splot "test1_sfft.txt" using 1:2:(sqrt($3**2+$4**2)) with lines -pause -1 - -splot "test2_sfft.txt" using 1:2:(sqrt($3**2+$4**2)) with lines -pause -1 diff --git a/sig_filter/tests/plot_taf.gp b/sig_filter/tests/plot_taf.gp deleted file mode 100755 index e9c867f..0000000 --- a/sig_filter/tests/plot_taf.gp +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/gnuplot - -set terminal x11 -plot "ex1ch_taf.txt" using 1:3 with linespoints pt 7 -pause -1 - -plot "ex2ch_taf.txt" using 1:3 with linespoints pt 7 -pause -1 - -plot "test1_taf.txt" using 1:2 with linespoints pt 7,\ - 0.582 * exp(-x/0.325) -pause -1 - -plot "test1_taf.txt" using 1:3 with linespoints pt 7,\ - 32674 -pause -1 - -plot "test2_taf.txt" using 1:2 with linespoints pt 7,\ - 0.582 * exp(-x/0.325) -pause -1 - -plot "test2_taf.txt" using 1:3 with linespoints pt 7,\ - 32674 + 1000*exp(-x/0.12) - -pause -1 - -# double dt = 1e-5; -# double f0 = 32674; -# double tau = 0.325; -# double amp = 0.582; -# double noise = 0; - -# double ftau = 0.112; -# double famp = 0; - - diff --git a/sig_pngfig/sig_pngfig b/sig_pngfig/sig_pngfig index 011bb38..485b114 100755 --- a/sig_pngfig/sig_pngfig +++ b/sig_pngfig/sig_pngfig @@ -310,7 +310,7 @@ sub add_data { my $ky = shift; my @a = split /\s+/, $line; - next if scalar @a < 7; + die "Bad data line: $line\n" if scalar @a < 6; my $type = $a[0]; my $color = $a[1]; diff --git a/sig_python/sig.py b/sig_python/sig.py new file mode 100644 index 0000000..b2d1165 --- /dev/null +++ b/sig_python/sig.py @@ -0,0 +1,62 @@ +# Reading *.sig (and probably *.sigf) files recorded +# by pico_osc program (https://github.com/slazav/pico_osc) + +import numpy +import re + +def read(name): + fo=open(name,'rb') + + info={ + "dt": 0.0, + "t0": 0.0, + "t0abs": 0.0, + "points": 0, + "navr": 0, + "ch": [], # channel names (A,B,C...) + "sc": [], # scales for each channels (integer data to voltage conversion factor) + "ov": [], # overload flags for each channel + # over field will be written as strings + } + info["chans"]=[] + info["chans"]=[] + while 1: + line = fo.readline().decode('ascii') + if not line: + print("no data found!") + exit(1) + + line = re.sub(r'#.*$','',line) + m = re.match(r'^\s+(\S+):\s*(.*)$', line) + if m: + k = m.group(1) + v = m.group(2) + if k in ("dt", "t0", "t0abs"): + info[k]=float(v) + elif k in ("points", "navr"): + info[k]=int(v) + elif k=="chan": + (n,sc,ov) = re.split(r'\s+', v) + info["ch"].append(n) + info["sc"].append(float(sc)) + info["ov"].append(bool(ov)) + else: + info[k]=v + + if re.fullmatch(r'^\*\s*$',line): + break + nch = len(info["ch"]) + data = numpy.fromfile(fo, dtype='int16') + data = numpy.reshape(data, (-1,nch)) + data = numpy.transpose(data) + data = data.astype(float) + for i in range(nch): + data[i,:] *= info["sc"][i] + return (data, info) + +def make_tgrid(info): + npt = info["points"] + dt = info["dt"] + time=numpy.linspace(0,dt*(npt-1),npt) + return time + diff --git a/sig_python/sig.test b/sig_python/sig.test new file mode 100755 index 0000000..637c2a7 --- /dev/null +++ b/sig_python/sig.test @@ -0,0 +1,18 @@ +#!/usr/bin/python3 + +import matplotlib.pyplot as plt +import sig + +(data, info) = sig.read("sig.test.dat") +time = sig.make_tgrid(info) + +plt.plot(time, data[0,:], 'r-', linewidth=0.5, label="Sig") +plt.xlabel('time, s') +plt.ylabel('voltage, V') + +plt.ylim([-0.04,0.04]) + +plt.legend() +fig = plt.gcf() +fig.set_size_inches(12, 6) +plt.savefig("sig.test.png", dpi=100) diff --git a/sig_python/sig.test.dat b/sig_python/sig.test.dat new file mode 100644 index 0000000..a560721 Binary files /dev/null and b/sig_python/sig.test.dat differ diff --git a/sig_viewer/Makefile b/sig_viewer/Makefile index 0141ef8..ad08e04 100644 --- a/sig_viewer/Makefile +++ b/sig_viewer/Makefile @@ -1,7 +1,11 @@ SHARED_LIB := sig_load MOD_SOURCES := sig_load.cpp -LDLIBS += -lBLT -ltk -lfftw3 +PKG_CONFIG += tcl + +LDLIBS += -lBLT -ltk -lfftw3 -ltcl +CXXFLAGS = -I/usr/include/tcl + MODDIR = ../modules include $(MODDIR)/Makefile.inc