pro make_some_sp_cubes, sp_filelist,                           $ ;
                        sp_filelist_offset=sp_filelist_offset, $ ;
                        num_to_process=num_to_process,         $ ;
                        outdir_str=outdir_str,                 $ ;
                        quiet=quiet,                           $ ;
                        fits_only=fits_only,                   $ ;
                        filldata=filldata,                     $ ;
                        loud=loud,                             $ ;
                        flat_dir_tree=flat_dir_tree
;
;+
;    Name:               make_some_sp_cubes
;
;    Purpose:            This is a wrapper that accepts vectors of SP obsid names and repeatedly invokes sp_make_cube_index.pro 
;                        (which builds multiple data cube products from spectropolarimeter data and save in iris FITS format).
;                        sp_make_cube_index also makes corresponding overview SP image products, i.e., images or movies, as appropriate.
;
;    Input Parameters:   dstring -- the start time/date string of a hinode spectropolarimeter observation.  Required
;
;    Keyword Parameters:
; 
;
;    Output:             driver for sp_make_cube_index.pro that accepts a vector of obsid strings/names.   (Can be a vector of 'one'.)
;
;    Calling Sequence and examples:
;                        IDL>make_some_sp_cubes, sp_filelist,                           $ ;example value: ['20190105_151346', '20190105_171745']
;                                                sp_filelist_offset=sp_filelist_offset, $ ;example value: 10, useful to restart cube generation after a crash without making a new list
;                                                num_to_process=num_to_process,         $ ;example value: 20, useful to make a subset from a longer vector of obsid names
;                                                outdir_str=outdir_str,                 $ ;top of the output directory
;                                                quiet=quiet,                           $ ;example call: /quiet makes this and downstream code slightly less verbose
;                                                fits_only=fits_only,                   $ ;example call: /fits_only skips generation of movies and images, speeds up processing dramatically
;                                                filldata=filldata,                     $ ;example call: /filldata sets fills data for bad pixel values to median value of obs, otherwise 0 
;                                                loud=loud,                             $ ;slightly more verbose calls to sp_quick_cube.pro from sp_make_cube_index
;                                                flat_dir_tree=flat_dir_tree              ;this causes sp_make_cube_index to put fits and image/movie output directories in a flat, single 
;                                                                                         ;directory, instead of the default time heirarchical data path.:w
;                        2019-04-18 PGS          Clean-up, modified output fits format.
;                        2021-07-20 M.DeRosa     removed subdir keyword; full output directory should now be specified in outdir keyword
;
;-
;
if ~keyword_set(sp_filelist_offset) then sp_filelist_offset = 0

;I made some chnages here -- make sure this still works.
;stop, 'what is outdir_str now?  
if ~keyword_set(outdir_str) then outdir = curdir() else outdir = outdir_str  ;  needs to be absolute path, otherwise moviemakine in sp_quick_cube.pro won't work for some reason
mk_dir, outdir
;stop, 'in make_some_sp_cubes -- what is outdir and outdir_str?' 
;
if ~keyword_set(sp_filelist_offset) then oset = 0 else oset=sp_filelist_offset
if ~keyword_set(num_to_process) then num_to_process = n_elements(sp_filelist)
  for i = (0+oset), (num_to_process+oset-1) do begin ;loop over the supplied vector of obsids
    if ~keyword_set(quiet) then box_message, ['In make_some_sp_cubes: in loop:', strtrim(string(i),2)]
    sp_make_cube_index,sp_filelist(i),outdir=outdir,quiet=quiet,fits_only=fits_only,filldata=filldata,loud=loud,flat_dir_tree=flat_dir_tree
  endfor
end
