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

/*ARGUMENTS
  Arguments
 
  RECONSTRUCTION3 takes the following arguments, all of which have an IN 
  parameter mode:
   - BFST (VARCHAR2).  This argument represents the name of the bad Frames 
     Statistics Table that was posted by Labview just prior to the onset of 
     reconstruction.  Entries in the BFST 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 RECONSTRUCTION3 (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.

   - BFST_SET_MNFSKIP.  This function sets the minor frame skip in the BFST.

   - 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.

   - BFST_SET_MNFCERR.  This procedure sets the minor frames counter error flag.

   - PWIW_SMOOTH_GRT.  This procedure smooths the PWIW ground receipt time when
     the order time is by UTC time.

   - RESET_TIME.  This procedure when turned on, sets the spacecraft time in the
     BFST for each minor frame to that of minor frame 0 of the major frame to
     which the minor frames belong, if the second argument to the procedure is
     -1, or sets the spacecraft time in the BFST for each minor frame to its
     original value from that of minor frame 0, if the second argument to the
     procedure is 1.

   - BFST_SET_MODEERR.  This procedure sets the mode error flag for minor frames
     in the BFST for the following missions: WIND, POLAR, and GEOTAIL.

   - BFST_SET_MODEERR_PWIW.  This procedure sets the mode error flag for minor
     frames in the BFST for the PWIW mission.

   - BFST_SET_DATEERR.  This procedure sets the date error flag for minor frames
     in the BFST.

   - BFST_FILL_TIMES.  This procedure attempts to fill the spacecraft time for minor
     frames in the BFST where it was not originally unpacked so that they may be
     identified and recovered.

   - BFST_CORRECT_UMNFC.  This procedure corrects the unpacked minor frame counter
     for the GEOTAIL mission.

   - BFST_REFILL_TIMES.  This procedure attempts to fill the spacecraft time for
     minor frames in the BFST where it was not originally unpacked, and that did
     not get filled by procedure BFST_FILL_TIMES.

   - BFST_CHECK_FILLED_TIMES.  This procedure compares times computed against those
     originally unpacked in the BFST.

   - CREATE_WFST.  This procedure creates the Working Frames Statistics Table.

   - WFST_VERIFY_TIME.  This procedure verifies the datetimes of major frames in the
     WFST against that in the AFST and Minor Frames Location Tables (MNFLT1, ...).

   - BFST_FAIL_DUPLICATES.  This procedure fails duplicate minor frames in the
     BFST.

   - CREATE_QUAL_COMP.  This procedure creates the temporary table QUAL_COMP.

   - CREATE_GFST_FROM_BFST.  This procedure creates a GFST from minor frames entries 
     in the BFST.  The name of the GFST is made by replacing the string 'BAD' with
     'GOOD' in the name of the BFST.

   - DROP_OBJECT.  This procedure drops the specified object.
 
   - 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.

   - GEN_RECIPE3.  This procedure generates a recipe for a quick-look session.

   - MFT_FILL_STATE.  This procedure reports on the the fill state of major frames
     reconstructed.

   - GEN_RECIPE1.  This procedure assigns pointers in the minor frames location
     tables to minor frames of major frames reported in the BFST (and WFST).

   - CREATE_SPOINTERT1.  This procedure creates the temporary table SPOINTERT and
     inserts into it all small pointers referenced in the location tables across
     all major frames reconstructed within the current message.

   - UPDATE_CDM.  This procedure updates the Current Data Mode for all major frames
     reconstructed.

   - BFST_ASS_QRANK.  This procedure assigns quality ranks to minor frames in the
     BFST that will be part of the recipe of the following missions: WIND, POLAR,
     and GEOTAIL.

   - BFST_ASS_QRANK_PWIW.  This procedure assigns quality ranks to minor frames in
     the BFST that will be part of the recipe of the PWIW mission.

   - BFST_COMP_QUAL.  This procedure compares the quality of minor frames received
     during the current session with that of the same minor frames received in
     previous sessions.

   - GEN_RECIPE2.  This procedure reads the session's recipe from the minor frame
     location tables and writes it in the recipe table.

   - MFT_FILL_STATE.  This procedure reports on the the fill state of major frames
     reconstructed.

   - 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.

   - UPDATE_IFST.  This procedure copies information on inverted minor frames in
     the session's BFST and write it in the Inverted Frames Statistics Table (IFST).

   - SET_TTCD.  This procedure sets the Time Tag Correlation Data (TTCD) for GEOTAIL
     filled frames in the RECIPE table.

   - SET_HRP_SEQ_NO.  This procedure sets the High-Rate Processor (HRP) sequence
     number for PWIW filled frames in HRP mode in the RECIPE table.

   - 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.
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.

   - TABLE_NAME (VARCHAR2(50)).  Represents the name of the GFST created from minor 
     frame entries in the BFST.

   - S_CREATE_GFST_FROM_BFST (INTEGER).  Represents and indicator of the state of 
     procedure CREATE_GFST_FROM_BFST.  This variable tells procedure RECONSTRUCTION3
     whether a GFST was created from the BFST or not. 
VARIABLES*/

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

   BEGIN
       RECONSTRUCTION3 ('GEOTAIL1997274142242671BAD',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 GFST has no major frame entries and the BFST
   has minor frame entries, a recipe will be generated for such a message only is
   procedure CREATE_GFST_FROM_BFST is able to create a GFST from entries in the 
   BFST, the name of the GFST being made by replacing the string 'BAD' with the 
   string 'GOOD' in the name of the BFST.  Therefore if no major frame can be
   identified from the BFST, the session's data is not recoverable.  When a GFST
   is created from a BFST, the major frames in the GFST are all grade 1 and will
   be part of the reconstructed.

 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, RECONSTRUCTION2, 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*/
