pro jpg_wrapper,year,month=month,outdir=outdir,cadence=cadence

;+
; NAME
;	jpg_wrapper.pro
; PURPOSE
;	Calls mk_smthy_jpgz.pro with cadence=minutes to create the .jpg files 
;	from a file list ,e.g., ok_fts_1995_08.genx, which are
;	used by movy_wrapper.pro to create the .html smoothy.
;	This version does not create jpegs across gaps larger than 1
;	days.
; CALLING SEQUENCE
; 	jpg_wrapper,year,month=month,outdir=outdir
; 	jpg_wrapper,1992
; 	jpg_wrapper,[1993,1998,1999,2000,2001]
; INPUT
;	year
; OPTIONAL KEYWORD INPUT
;	month, set to do a single month
;	outdir, set to use outdir other than 'smthy_jpg/'+yyy+'/'
;	   e.g., outdir='jpg_test/' to put jpgs into jpg_test.
;		 outdir=''/yla/smoothy/smthy_jpg_mission_new/'
;	cadence, minutes between smoothy images (default=32.8)
; OUTPUT
;	Jpeg image files, e.g.,
;	   /yla/smoothy/smthy_jpg/1995/p19950701_2218.jpg
; HISTORY
;	 6-Dec-2016 LWA  Added header.
;	14-Dec-2016 LWA  Modified to skip over gaps > 2 days.
;	16-Mar-2017 LWA  Added keyword month and fixed j loop.
;	 4-Apr-2017 LWA  Added keyword outdir.
;	 9-May-2017 LWA  Added run timer, changed name.
;	 7-Jul-2017 LWA  Set dgap=1.0 in gapper2.
;	14-Sep-2017 LWA  Added keyword cadence.
;-


if not keyword_set(cadence) then cadence=32.8 else cadence=cadence
for i=0,n_elements(year)-1 do begin
   ytim=anytim(!stime)
   yyy=strtrim(year(i),2)
   filz=gapper2(yyy,gapinfo=gpi,month=month,dgap=1.0)
   tta=anytim(mk_ftym(filz,30))
fmt_timer,tta
   sz=size(gpi)
   if sz(0) eq 1 then nj=0 else nj=sz(2)-1
   for j=0,nj do begin
      fr=where(tta ge gpi(0,j) and tta le gpi(1,j),nfr)
      if nfr gt 0 then glist=filz(fr) else goto,skip
      fmt_timer,tta(fr)
      if not keyword_set(outdir) then $
         outdir='smthy_jpg/'+yyy+'/' else outdir=outdir
      help,glist,outdir
      junk=1
      mk_smthy_jpgz,junk,gfil=glist,cadence=cadence,outdir=outdir
   endfor
   skip:
endfor
etim=anytim(!stime)
dtt=(etim-ytim)/60.
print,' It took '+strtrim(dtt,2)+' minutes to make the jpegs for '+yyy+'.' 
end
