!------------------------------------------------------------------------------ ! DETREND.PRG !------------------------------------------------------------------------------ ! purpose: fit a Fourier series of sine/cosines to the data and subtract ! them then ! author: B. Gaensicke ! last revision: 2010-04-30 ! ! allow for the number of harmonics to be specified ! dump MIDAS log to detrend.log to fetch the STDOUT output from sinefit/tsa !------------------------------------------------------------------------------ ! You need to specify ! ! p1 = input file ! p2 = output file ! p3 = best guess of the frequency ! p4 = number of iterations in the fit [1: do not fit the frequency] ! p5 = number of harmonics to be used [0=constant, 1=fundamental, 2=fund.+harm.] !------------------------------------------------------------------------------ set/context tsa define/par p1 tsa c "Input file = " define/par p2 tsa_resid c "Output file = " define/par p3 0 n "f[d-1] = " define/par p4 30 n "No. of iterations = " define/par p5 1 n "No. of harmonics = " define/local ifile/c/1/80 {p1} define/local ofile/c/1/80 {p2} define/local freq/d/1/1 {p3} define/local nit/i/1/1 {p4} define/local nharm/i/1/1/ {p5} define/local start/d/1/1 0 define/local end/d/1/1 0 start = freq*0.9 end = freq*1.1 define/local step/d/1/1 0. define/local nstep/i/1/1 5000 step = (end-start)/nstep ! Read in data create/table target * * {ifile} $MID_WORK/period.fmt set/tsa starttsa = {start} set/tsa steptsa = {step} set/tsa nsteps = {nstep} ! fit and subtract sine waves write/out sinefit/tsa target resid {freq} {nharm} {nit} sinefit/tsa target resid {freq} {nharm} {nit} assign/print file detrend.log print/log assign/print file tmp.dat print/table resid :time :value N $ awk '{print $2,$3}' tmp.dat > {ofile} return