; $Id$
;
; Create light-curve plot

; Read data

s_l2 = H5_PARSE('sigorie-level2.h5', /RE)
s_rc = H5_PARSE('sigorie-recon.h5', /RE)

t = s_l2.HJD._data - 2454416.5D0

F_star = s_l2.F_star._data
F_star_mean = s_l2.F_star_mean._data

mag = -2.5*ALOG10(F_star/F_star_mean)

t_per = s_rc.t._data - 2454416.5D0
F_star_per = s_rc.F_star._data

mag_per = -2.5*ALOG10(1.D0+F_star_per/F_star_mean)

; Set up ranges

x_ext = CEIL((CEIL(MAX(t))-FLOOR(MIN(t)))/4.)

; Do the plot

xs=17.8
ys=18.9

SET_PLOT, 'ps'
DEVICE, FILENAME='fig_light_curve.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 = 1000
y_0 = 1000

dx = 16000
dy = 3650
dyo = 4650

setwin, dx, dy, x_0, y_0+3*dyo, 250

PLOT, [0], [0], /NODATA, $
      XRANGE=[0,x_ext], $
      YRANGE=[0.08,-0.08], $
      XSTYLE=1, YSTYLE=1, $
      YTITLE='yt', $
      XTICKFORMAT='fonttick', $
      YTICKFORMAT='fonttick'
OPLOT, t_per, mag_per
OPLOT, t, mag, PSYM=3

for i = 0,x_ext do OPLOT, [1,1]*(!X.CRANGE[0]+i), !Y.CRANGE, LINESTYLE=2
for i = 0,5 do XYOUTS, 0.85+i, -0.062, 'n'+STRING(12+i, FORMAT='(I0)'), ALIGNMENT=1.0, CHARSIZE=0.6

;

setwin, dx, dy, x_0, y_0+2*dyo, 250

PLOT, [0], [0], /NOERASE, /NODATA, $
      XRANGE=[x_ext,2*x_ext], $
      YRANGE=[0.08,-0.08], $
      XSTYLE=1, YSTYLE=1, $
      YTITLE='yt', $
      XTICKFORMAT='fonttick', $
      YTICKFORMAT='fonttick'
OPLOT, t_per, mag_per
OPLOT, t, mag, PSYM=3

for i = 0,x_ext do OPLOT, [1,1]*(!X.CRANGE[0]+i), !Y.CRANGE, LINESTYLE=2
for i = 6,11 do XYOUTS, 0.85+i, -0.062, 'n'+STRING(12+i, FORMAT='(I0)'), ALIGNMENT=1.0, CHARSIZE=0.6

;

;

setwin, dx, dy, x_0, y_0+1*dyo, 250

PLOT, [0], [0], /NOERASE, /NODATA, $
      XRANGE=[2*x_ext,3*x_ext], $
      YRANGE=[0.08,-0.08], $
      XSTYLE=1, YSTYLE=1, $
      YTITLE='yt', $
      XTICKFORMAT='fonttick', $
      YTICKFORMAT='fonttick'
OPLOT, t_per, mag_per
OPLOT, t, mag, PSYM=3

for i = 0,x_ext do OPLOT, [1,1]*(!X.CRANGE[0]+i), !Y.CRANGE, LINESTYLE=2
for i = 12,17 do XYOUTS, 0.85+i, -0.062, 'n'+STRING(12+i, FORMAT='(I0)'), ALIGNMENT=1.0, CHARSIZE=0.6

;

setwin, dx, dy, x_0, y_0, 250

PLOT, [0], [0], /NOERASE, /NODATA, $
      XRANGE=[3*x_ext,4*x_ext], $
      YRANGE=[0.08,-0.08], $
      XSTYLE=1, YSTYLE=1, $
      XTITLE='xt', $
      YTITLE='yt', $
      XTICKFORMAT='fonttick', $
      YTICKFORMAT='fonttick', $
      PSYM=3
OPLOT, t_per, mag_per
OPLOT, t, mag, PSYM=3

for i = 0,x_ext do OPLOT, [1,1]*(!X.CRANGE[0]+i), !Y.CRANGE, LINESTYLE=2
for i = 18,18 do XYOUTS, 0.85+i, -0.062, 'n'+STRING(12+i, FORMAT='(I0)'), ALIGNMENT=1.0, CHARSIZE=0.6
for i = 19,23 do XYOUTS, 0.85+i, -0.062, 'd'+STRING(i-18, FORMAT='(I0)'), ALIGNMENT=1.0, CHARSIZE=0.6

;

DEVICE, /CLOSE

; Fix up axis labels

date_tags = ['n'+STRING(INDGEN(19)+12, FORMAT='(I0)'), $
             'd'+STRING(INDGEN(5)+1, FORMAT='(I0)')]

dates = ['Nov '+STRING(INDGEN(19)+12, FORMAT='(I0)'), $
         'Dec '+STRING(INDGEN(5)+1, FORMAT='(I0)')]

latexify, 'fig_light_curve.eps', $
          ['xt','yt', date_tags], $
          ['$t$ (HJD) - 2454416.5', '$m$ (mag)', dates], [REPLICATE(0.9, 1+1),REPLICATE(0.7, 19+5)], width=xs
