;+
; Project     :	SOHO - CDS
;
; Name        :	GET_SERIES_INFO
;
; Purpose     :	Gets version number and internal ID for CDHS SERIES table.
;
; Explanation : First checks the current software version number of the wr_series_file code
;               which creates the tables for the study and then searches the series_id database 
;               to determine whether these tables has been used before and if so gets their 
;               internal CDHS IDs.
;               It then searches the commprep database to determine whether the tables are
;               already loaded or gets CDS indeces for loading them.
;               Note that a study may span several series tables.
;
; Use         : <get_series_info, series, cut_off_time>
;
; Inputs      : series      = structure array listing information on current study
;                    .vs     = character string indicating the software version
;                              of the code used to create the table.
;                    .id     = integer planning database ID for the table.
;                    .var    = integer planning database variation for the table.
;                    .cdhsx  = the internal CDHS index where the table is loaded
;                    .cdhsid = the internal CDHS ID used to reference the table
;                    .reus   = a character indicating whether the table is re-usable
;                              or not.
;                    .sft    = a character indicating whether solar feature tracking
;                              is to be used. 
;                    .istate = structure giving initial x, y coords, slitn and gsetid 
;                              of study
;                    .rpt    = character indicating whether series is to be repeated 
;                              indefinitely.
;                    .repn   = integer giving no. of times last raster to be repeated
;                              and IEF flags.
;                    .range  = integer giving the range from the home position that mirror
;                              and slit adjustments can be made for pointing.
;                              Outside of this OPS movements are used.
;                    .dsolx  = deferred solar x pointing for study
;                    .dsoly  = deferred solar y pointing for study
;                    .flagst = character indicating whether flag study or not.
;                    .nextst = cdhs id of next study.
;               cut_off_time = DOUBLE TAI format time before which tables may be overwritten
;
; Opt. Inputs : None.
;
; Outputs     : Updates the entries in series directly.
;                    series.ok     = an integer flag indicating whether table is already 
;                                    loaded onto the CDS.
;                    series.nsubs  = integer giving the number of tables spanned by the
;                                    study (equal to the dimensions of the structure array 
;                                    returned)
;
; Opt. Outputs:	None.
;
; Keywords    : None.
;
; Calls       :	get_version, get_series_id, get_cdhs_index, shorthex.
;                
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Category    :	Command preparation.
;
; Prev. Hist. :	None.
;
; Written     :	Version 0.0, Martin Carter, RAL, 14/10/94
;
; Modified    :	Version 0.1, Martin Carter, RAL, 28/11/94
;                            Added proforma.
;               Version 0.2, MKC, RAL, 2/3/95
;                            Added repn and sft to table info.
;                            Removed some tags from dexwin and vdswin tables. 
;               Version 0.3, MKC, RAL, 6/3/95
;                            Modified printout.
;               Version 0.4, MKC, RAL, 21/3/95
;                            Modified printout.
;               Version 0.5, MKC, RAL, 18/4/95
;                            Adapted from get_table_info.pro .
;                            Modified call to get_version.
;                            Modified argument list.
;               Version 0.6, MKC, RAL, 24/4/95
;                            Modified printout.
;               Version 0.7, MKC, 18/5/95
;                            Modified series structure to include state.
;               Version 0.8, MKC, 24/5/95
;                            Modified seriesID database to include slitn.
;               Version 0.9, MKC, 10/8/95
;                            Added rpt tag to series structure.
;               Version 1.0, MKC, 29/9/95
;                            Added repn tag to series structure.
;               Version 1.1, MKC, 3/11/95
;                            Modified prinrout.
;               Version 1.2, MKC, 7/11/95
;                            Added gsetid.
;               Version 1.3, 1/12/95
;                            Added range to series table structure.
;               Version 1.4, 6/12/95
;                            Added dsolx, dsoly to series structure.
;               Version 1.5, 14/12/95
;                            Added fseries to cope with reverse processing.    
;               Version 1.6, 3/1/96
;                            Added flag study tag to series structure.          
;               Version 1.7, MKC, 3/10/96
;                            Added time to allow previous tables to be overwritten to argument list.
;                            Added check that CDHS ID has not already been set up before interrogating 
;                            the series_id database.
;                            Removed fseries and used nextst tag instead.
;
; Version     :	Version 1.7, 3/10/96
;-
;**********************************************************

PRO get_series_info, series, cut_off_time

  ; get table creation software version

  get_version, 'SERIES', series

  ; check if table already defined and get CDHS ID
  ; gets cdhs ids associated with given study
  ; NB may be multiple CDHS tables associated with single study

  IF series.cdhsid EQ 0 THEN series = get_series_id ( series )

  ; get number of entries found

  nentries = N_ELEMENTS ( series )

  ; set number of entries found

  series.nsubs = nentries

  ; check all tables loaded onto CDHS and get CDHS indeces

  ok = 1

  FOR k = 0, nentries-1 DO BEGIN 

    series(k) = get_cdhs_index ( 'SERIES', series(k), cut_off_time )

    ok = ok AND series(k).ok

  ENDFOR

  ; tables only ok if all ok

  series.ok = ok 

  ; display some info on tables

  FOR k = 0, nentries-1 DO BEGIN

    PRINT,         'SERIES table' ,                             $
                   ' LOADED=', STRTRIM ( series(k).ok, 1 ),     $
                   ' SW=', series(k).vs,                        $
                   ' CDHSID=', STRTRIM ( series(k).cdhsid, 1 ), $
                   ' CDHSX=', STRTRIM ( series(k).cdhsx, 1 ),   $
                   ' ID=', STRTRIM ( series(k).id, 1 ),         $
                   ' VAR=', STRTRIM ( series(k).var, 1 ),       $
                   ' REUS=', series(k).reus

    PRINT,         '            ' ,                                   $
                   ' SFT=', series(k).sft,                            $
                   ' X=', STRTRIM ( series(k).istate.solarx, 1 ),     $
                   ' Y=', STRTRIM ( series(k).istate.solary, 1 ),     $
                   ' SLITN=', STRTRIM ( series(k).istate.slitn, 1 ),  $
                   ' GSETID=',STRTRIM ( series(k).istate.gsetid, 1 ),        $
                   ' RPT=', series(k).rpt,                            $
                   ' REPN=', shorthex( series(k).repn )

    PRINT,         '            ' ,                             $
                   ' RANGE=', STRTRIM ( series(k).range, 1 ),   $
                   ' DSOLX=', STRTRIM ( series(k).dsolx, 1),    $
                   ' DSOLY=', STRTRIM ( series(k).dsoly, 1),    $
                   ' FSTDY=', STRTRIM ( series(k).nextst, 1 ),    $
                   ' FLAGST=', series(k).flagst

   ENDFOR

END
