!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ! SINE_FIT ! ! Fits a sine to a time series in the file tsa !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ! define/par p1 ? i "frequency guess [d-1] :" ! define/local n/i/1/2 0 define/local gam/d/1/1 0. define/local k1/d/1/1 0. define/local phi/d/1/1 0.3 define/local f/d/1/1 {p1} define/local x/d/1/1 0 f = f*2*3.14 set/graphics pmode=1 stype=1 create/table tsa 3 1000 tsa name/column tsa #1 :time "d" name/column tsa #2 :RV "km/s" name/column tsa #3 :errRV "km/s" ! calculate RV min / max, use max-min as a guess for K stat/table tsa #2 k1 = outputr(2)-outputr(1) !plot/table tsa #1 #2 ! delete the descriptors containing the fit to avoid ! garbling up things when overwriting them below del/desc sinefit.fit fit0001 del/desc sinefit.fit fit0002 write/desc sinefit.fit fit0001/c/1/80 poly(x;a1)a1={gam} write/desc sinefit.fit fit0002/c/1/80 "sin(x;a2,b2,c2)a2={k1} b2={phi} c2={f}@" set/fit method=nr fit/table 20 tsa #2,#3 #1 sinefit gam = {sinefit.fit,fitparam(1)} k1 = {sinefit.fit,fitparam(2)} phi = {sinefit.fit,fitparam(3)} f = {sinefit.fit,fitparam(4)} write/desc sinefit.fit fit0001/c/1/80 poly(x;a1)a1={gam} write/desc sinefit.fit fit0002/c/1/80 "sin(x;a2,b2,c2)a2={k1} b2={phi} c2={f}" fit/table 20 tsa #2,#3 #1 sinefit compute/fit tsa.tbl :fit !set/graph colour=2 bin=off !over/table tsa #1 :fit !set/graph colour=1 open/file sinefit.par append n write/file {n(1)} {sinefit.fit,fitparam(1)} {sinefit.fit,fitparam(2)} {sinefit.fit,fitparam(3)} {sinefit.fit,fitparam(4)} write/file {n(1)} {sinefit.fit,fiterror(1)} {sinefit.fit,fiterror(2)} {sinefit.fit,fiterror(3)} {sinefit.fit,fiterror(4)} close/file {n(1)} return