;+
;Name: messenger_mk_movie
;
;Purpose: Make daily jpegs plots showing messenger data and results of filtering for
; night, high temperature, voltage too low. Make yearly movie of jpegs.   Can
; only be run on hesperia by softw.
; This is run by softw and files are written on hesperia in the messenger archive at
; /data/messenger/daily_plots.  An aaareadme.txt file in that location describes the
; plots.
; 
;Input Keywords:
; just_jpeg - if set, just make the jpeg files for time requested (all times)
; just_movie - if set, just make the movies for all years
; time - time to make jpegs for. If not provided, does whole mission. If scalar, then
;   does that one day.  If 2 elements, then it's the range of times.
;   
;Written: Kim Tolbert, 24-Jul-2014
;Modifications:
;  
;-

pro messenger_mk_movie, just_jpeg=just_jpeg, just_movie=just_movie, time=time

checkvar, just_jpeg, 0
checkvar, just_movie, 0

topdir = '/data/messenger/'
movie_dir = 'daily_plots/'
outdir = topdir + movie_dir
cd, topdir, curr=curr

if ~just_movie then messenger_mk_jpeg, time=time, outdir=outdir

if ~just_jpeg then begin
  jpegs = file_search(outdir, 'mess*.jpeg')
  jpegs = file_basename(jpegs)
  times = file2time(jpegs, out_style='sec')
  for iy = 2004,2050 do begin
    st = anytim(doy2utc(1,iy))
    en = anytim(doy2utc(1,iy+1))
    q = where(times ge st and times lt en, count)
    if count gt 0 then begin
      movie_file = movie_dir + 'amessenger_movie_'+trim(iy) + '.html'
      jsmovie, movie_file, jpegs[q], /range, delay=40, $
        title='MESSENGER Daily Plots', template='$SSW/gen/idl/http/jsmovie_temp2.html'
    endif
  endfor
endif

cd, curr
end