#!/usr/bin/env ./gs ! scanff6c.sad (scan-fit.sad) ! k.furukawa, may.28.2003. ! k.f, sep.7.2006. fourier in sub-process ! k.f, sep.18.2006. fourier repeats forever ! k.f, sep.19.2006. test buttons ! ! protocol between this main process and the sub-process ! ! start sub with BidirectionalPipe[] ! main sub ! (initialization) ! BidirectionalPipe[] ! <-- "%%%READY%%%" ! (loop) ! Write[] --> ! --> Read[] ! "###END###" --> ! <-- "%%%BEGIN%%%" ! <-- Print[] ! Read[] <-- ! <-- "%%%END%%%" ! FFS; scanData[]:=Module[{}, aData = {}; current=start; scanDataLoop[]; ]; scanDataLoop[]:=Module[{}, AppendTo[aData,{current,Sin[current*3.1415/180.]+noise*GaussRandom[]}]; If[Length[aData]>1,plotData[]]; current = current + step; If[current<=stop,After[interv,scanDataLoop[]]]; ]; quickData[]:=Module[{}, aData=Table[{current,Sin[current*Pi/180.]+noise*GaussRandom[]}, {current,start,stop,step}]; plotData[]; ]; plotData[]:=Module[{}, Canvas$Widget = c1; g1 = ListPlot[Thread[{Thread[aData][[1]],Thread[aData][[2]]}], FrameLabel->{"Actuater","Response","Raw Graph",""}, PlotJoined->False,Scale->{Linear,Linear}, FrameTicks ->{True,True,False,False}, PlotRange->{Automatic,Automatic},PointColor->"blue" ]; Show[g1]; ]; writeData[]:=Module[{}, fd1=OpenWrite["./scanff.tmp"]; Write[fd1,aData]; Close[fd1]; ]; fitData[]:=Module[{}, Canvas$Widget = c2; g2 = FitPlot[aData, a Cos[x b 0.02 + c] + d, x, {a,1},{b,0.87},{c,-1},{d,0}, FrameLabel->{"Act.","Res."} ]; ]; fourierData[]:=Module[{}, Canvas$Widget = c3; dt=(aData[[-1,1]]-aData[[1,1]])/(Length[aData[[,2]]]-1); Write[out,aData]; Flush[out]; Write[out,"###END###"]; Flush[out]; While[str=Read[in,Word];str<=>"%%%BEGIN%%%", Print["## "//str];]; power=Read[in]; ListPlot[Thread[{Range[0,Length[power]-1]/Length[power]/dt,power}], FrameLabel->{"Frequency (Hz)","Power Spectrum"}, PlotRange->{{Automatic,Automatic},{Automatic,Automatic}}]; ]; w = KBMainFrame["Scan Test",f,Title -> "Scan Test"]; w[AboutMessage]="Scan Test, K. Furukawa, May.2003"; f1 = Frame[f,Side->"left"]; c1 = Canvas[f1,Width->640,Height->320]; c2 = Canvas[f1,Width->640,Height->320]; c3 = Canvas[f1,Width->640,Height->320]; f2 = KBFComponentFrame[f,Side->"right",Add->{ KBFGroup[Text->"Control"], KBFNumber[Text->"Start",Variable:>start,NumberForm->"8.2"], KBFNumber[Text->"Stop",Variable:>stop,NumberForm->"8.2"], KBFNumber[Text->"Step",Variable:>step,NumberForm->"8.2"], KBFNumber[Text->"Interval",Variable:>interv,NumberForm->"8.2"], KBFNumber[Text->"Noise",Variable:>noise,NumberForm->"8.2"], KBFSeparator[], KBFButton[Text->"Scan Test",Command:>scanData[]], KBFButton[Text->"Generate Data",Command:>quickData[]], KBFButton[Text->"Fit Test",Command:>fitData[]], KBFButton[Text->"Write Test",Command:>writeData[]], KBFButton[Text->"Fourier Data",Command:>fourierData[]], } ]; $DisplayFunction=CanvasDrawer; start = -10.; stop = 400.; step = 10.; interv = 0.01; noise = 0.1; {in,out} = BidirectionalPipe["/bin/sh"]; Write[out,"exec ./fourier4.sad"]; Flush[out]; While[str=Read[in,Word];str<=>"%%%READY%%%", Print["## "//str];]; TkWait[];