/*MAIN
 Overview
 
 RECONSTRUCTION2 is a sub-procedure of the main reconstruction procedure 
    RECONSTRUCTION1.  This procedure handles the case where there is not entry
    in the BFST, but there are entries in the GFST.  This situation occurs when
    all the telemetry data processed produced only good frames.
MAIN*/

/*ARGUMENTS
  Arguments
 
  RECONSTRUCTION2 takes the following arguments, all of which have an IN 
  parameter mode:
   - GFST (VARCHAR2).  This argument represents the name of the Good Frames 
     Statistics Table that was posted by Labview just prior to the onset of 
     reconstruction.  Entries in the GFST were built and logged into a script
     file during processing of the annotated minor frames file by AD.

   - START_TIME (NUMBER, default NULL).  This argument represents the time 
     from which a quick-look window of time from a message may start.
ARGUMENTS*/

/*DEPENDENCIES
 Dependencies
 
 The following are the procedures called by RECONSTRUCTION2 (listed in their
 order of call):
   - SWITCH.  This is the package that manipulates the switches for all 
     the reconstruction rules.

   - OPEN_AND_PARSE.  This function combines what would otherwise have
     been separate calls to the native Oracle DBMS_SQL.OPEN_CURSOR and
     DBMS_SQL.PARSE procedures, into a single function.

   - DBMS_UTILITY.GET_TIME.  The GET_TIME function of the native oracle package
     DBMS_UTILITY returns the elapsed time since an arbitrary time in 100ths of
     seconds

   - EXECUTE_AND_CLOSE.  This function combines what would otherwise have
     been separate calls to the native Oracle DBMS_SQL.EXECUTE and
     DBMS_SQL.CLOSE procedures, into a single function.

   - DBMS_SQL.  This the native Oracle dynamic SQL package.

   - UPDATE_MNFFPT.  This procedure is executed to update table MNFFPT (minor
     frames file pointer table) by assigning unique small and long pointer to
     the session being processed.

   - INITIALIZE.  This procedure performs some initialization steps on the
     reconstruction tables, such as making sure that temporary tables do not
     exist from a previous session, and truncating tables that need to be
     truncated.

   - POST_STATE.  This is a package of three procedures and one function all
     of which serve the role of writing the states of all rules as they become
     available, in the system_state table.

   - RULES_STATES.  This is a package of three procedures and one function all
     of which track and post reconstruction states for all rules as they become
     available, in the temporary table LOGT.

   - PWIW_ORDER_TIME.  This procedure sets the order time for the PWIW mission,
     i.e. that if turned on, the frames reconstructed are ordered by UTC time,
     and if turned off the frames reconstructed will be ordered by spacecraft
     time which is the default.

   - GFST_CHECK_SPANS.  This procedure identifies the number of distinct
     dataspans available in the GFST.

   - CONFIG.  This is the stored package that manipulates the configuration 
     parameters for all the reconstruction rules.

   - LOG_FILE.  This is a package of procedures which handle the tasks of 
     creating the file in which reconstruction output messages will be written
     to, writing to the latter file, and closing it at the end of 
     reconstruction.
   
   - CP_LPOINTER.  This procedure inserts the session's long pointer into the
     GFST as a new column.

   - GFST_PROCESS1.  This procedure dynamically add columns to the GFST and
     checks for missing major frames within each dataspan of the GFST based
     on periodicity.

   - CREATE_INDEXES.  This procedure creates indexes used during reconstruction.

   - GFST_PROCESS2.  This procedure checks for missing major frames across
     dataspans of the BFST based on periodicity for the following missions:
     WIND, POLAR, and GEOTAIL.

   - GFST_PROCESS2_PWIW.  This procedure checks for missing major frames across
     dataspans of the BFST based on periodicity for the PWIW mission.

   - DET_QL_WINDOW.  This procedure determines the quick-look window of time.

   - CROSS_CHECK_TIMES.  This procedure cross-checks the datetimes of grade 1 major
     frames in the GFST against those of major frames in the AFST.

   - GFST_CHECK_INSERTS.  This procedure checks entries in the GFST against entries
     in the temporary table GRADE2_TEMP_STOR.

   - GEN_RECIPE5.  This procedure inserts into table WFST with grade 2 major frame 
     entries from the temporary table GRADE2_TEMP_STOR.

   - CREATE_TEMP_AFST.  This procedure creates the temporary table TEMP_AFST used
     by procedure QA_AFST to match major frames in the Accumulated Frames Statistics
     Table (AFST), against those in the GFST.

   - QA_AFST.  This procedure attempts to eliminate major frames in the AFST that
     are also reported in the GFST as grade 0 major frames.

   - TERMINATE_REC.  This procedure performs some closure steps on the reconstruction
     tables, such as making sure that temporary tables are dropped, cached tables are
     altered to non-cached when appropriate, and not needed indexes are dropped.

   - DROP_OBJECT.  This procedure drops the specified object.
DEPENDENCIES*/

/*VARIABLES
 Variables

 The following are variables used in the procedure:
   - C (INTEGER). Cursor handle.

   - EXECUTE1 (INTEGER).  The number of rows processed by the SQL statement
     if that statement is an UPDATE, INSERT, or DELETE.  If the SQL statement is
     not an UPDATE, INSERT, or DELETE, this value should be ignored.

   - X (VARCHAR2(50)).  Represents the GFST.

   - Y (VARCHAR2(50)).  Represents the BFST.

   - DIRECTION1 (INTEGER).  Represents the direction of the message: forward or
     reverse ordered.

   - AMF_FILE1 (MNFFPT.AMF_FILE%TYPE).  Represents the name of the annotated minor 
     frames file created for this session by the Frame Synchronizer software.

   - NUM_MISSING (INTEGER).  Represents the total number of major frames found 
     missing in the session's GFST.

   - RETURN_VAL1 (INTEGER).  Represents the number of major frames found missing 
     within the dataspans of the GFST.

   - RETURN_VAL2 (INTEGER, default 0).  Represents the number of major frames found  
     missing across the dataspans of the GFST.

   - RETURN_VAL3 (INTEGER, default 0).  Represents the number of major frames found  
     missing across the dataspans of the GFST for the PWIW mission.

   - SPAN_NUMBER (INTEGER).  Represents the number of dataspans found in the
     session's GFST.
VARIABLES*/

/*EXAMPLES
  Examples
 
  Here are two calls to RECONSTRUCTION2:
 
   BEGIN
       RECONSTRUCTION2 ('GEOTAIL1997274142242671GOOD');
   END;
   /

   BEGIN
       RECONSTRUCTION2 ('GEOTAIL1997274142242671GOOD',2952303829.622000);
   END;
   /
 
 The arguments of this procedure are passed in from Assembly/Decommutation. 
EXAMPLES*/

/*EXCEPTIONS
 Exceptions

 There are no named exceptions for this procedure, except for the generic one
   WHEN OTHERS.  When the latter is triggered, the error message is outputted
   along with the name of the module that erred, and any cursors that may still
   be opened are closed.  
EXCEPTIONS*/

/*ERRORS
 Errors

 There are no errors that this procedure is known to generate.  Should an
   error occur, take action based on the description of the error.
ERRORS*/

/*TABLES
 Tables
 
 The following tables are referenced in this procedure:
  - GFST. This is the Good Frames Statistics Table that was posted by
    AD just prior to the onset of reconstruction.

  - LOGT.  This is the log table in which the states of all rules are dynamically
    posted and computed before being written to the system_state table.

  - BFST. This is the Bad Frame statistics Table that was posted by AD
    just prior to the onset of reconstruction.
  
  - WFST.  This is the Working Frames Statistics Table, a temporary table 
    created to hold information on missing and reconstructed frames that
    will ultimately be written to the AFST.

  - SESSIONS_PARAMETERS.  This table stores information on parameters of all 
    reconstruction sessions.

  - AFST.  This is the Accumulated Frames Statistics Table, which stores information
    about major frames of all grades that have ever been processed.

 For more information on these and other tables, see the documentation on tables.
TABLES*/

/*OTHERS
 Others
 
 It should be noted that when the BFST has no minor frame entries and the GFST
   has major frame entries, a recipe will not be generated at the end of the 
   reconstruction session since there is nothing to reconstruct.  The purpose
   of this type of reconstruction is to update the AFST on all grade 0 frames
   that were received and on any major frames that are thought to be missing 
   from the current message.

 Also note that in this procedure table LOGT is updated through INSERT and UPDATE
   statements whereas in other procedures (except INITIALIZE and UPDATE_MNFFPT,
   UNLOAD, RECONSTRUCTION1, and RECONSTRUCTION3), table LOGT is updated through
   the RULES_STATES package.  The reason for the latter is because the session's
   pointer has not been assigned through procedure UPDATE_MNFFPT, and the events
   count has not been initialized through procedure POST_STATE.INIT_EVENT.

 For more details on this procedure see the reconstruction documentation.
OTHERS*/
