; $Id$
;
; Create the periodogram plot

; Read data

s = H5_PARSE('sigorie-lomb-star-res.h5', /RE)

;freq = REBIN(s.freq._data, 10000)
.P_N = REBIN(s.Theta._data, 10000)
freq = s.freq._data
P_N = s.Theta._data

print,'P_N range:',MIN(P_N),MAX(P_N)
print,'Theta range:',MIN(s.Theta._data),MAX(s.Theta._data)

; Do the plot

xs = 17.8
ys = 7.2

SET_PLOT, 'ps'
DEVICE, FILENAME='fig_periodogram.eps', /ENCAPSULATED, $
        XSIZE=xs, YSIZE=ys

!P.CHARSIZE=0.8
!P.FONT=0

common tick_formats, tick_format_x, tick_format_y, tick_format_z

tick_format_x = '(I0)'
tick_format_y = '(F5.2)'

x_0 = 1200
y_0 = 900

dx = 15800
dy = 6000

setwin, dx, dy, x_0, y_0, 250

PLOT, freq, P_N, $
      XRANGE=[0,100], $
      YRANGE=[0.1,1e4], $
      XSTYLE=1, YSTYLE=1, /YLOG, $
      XTITLE='xt', $
      YTITLE='yt', $
      XTICKFORMAT='fonttick', $
      YTICKFORMAT='fonttick_log'

P_orb = 101.413/60./24. ; From Rowe et al. (2006)
f_rot = 1./P_orb

PRINT, !Y.CRANGE

for h = 1,7 do OPLOT, f_rot*h*[1,1], [2e3,6e3], THICK=3

for h = 1,7 do OPLOT, f_rot*h*[1,1]-1, [2e3,6e3]
for h = 1,7 do OPLOT, f_rot*h*[1,1]-2, [2e3,6e3]
for h = 1,7 do OPLOT, f_rot*h*[1,1]-3, [2e3,6e3]
for h = 1,7 do OPLOT, f_rot*h*[1,1]-4, [2e3,6e3]

for h = 1,7 do OPLOT, f_rot*h*[1,1]+1, [2e3,6e3]
for h = 1,7 do OPLOT, f_rot*h*[1,1]+2, [2e3,6e3]
for h = 1,7 do OPLOT, f_rot*h*[1,1]+3, [2e3,6e3]
for h = 1,7 do OPLOT, f_rot*h*[1,1]+4, [2e3,6e3]

n = 24455
P_fap = 0.05

z_FAP = -ALOG(P_fap/n)
x_FAP = 2*z_FAP/(n-3)

;Theta_FAP = (n-3)*x_FAP/(2-2*x_FAP)
P_N_FAP = -ALOG(P_fap/n)

PRINT, 'P_N FAP:', P_N_FAP

OPLOT, !X.CRANGE, P_N_FAP*[1,1], LINESTYLE=2, THICK=2

DEVICE, /CLOSE

; Fix up axis labels

latexify, 'fig_periodogram.eps', $
          ['xt','yt'], $
          ['$\nu\ ({\rm d^{-1}})$', '$\mathcal{P}$'], [0.9,0.9], width=xs


