/*MAIN
 Overview
 
 GEN_RECIPE4 is a sub-procedure of the reconstruction procedure GEN_RECIPE2.
    The purpose of this procedure is to read information from any of the five 
    minor frames location tables (MNFLT1, MNFLT2, MNFLT3, MNFLT4, and MNFLT5),
    about major frames to be reconstructed as indicated in the Working Frames
    Statistics Table (WFST), and convert this information into instructions to 
    be later retrieved by AD from the RECIPE table.
MAIN*/

/*ARGUMENTS
  Arguments
 
  GEN_RECIPE4 takes the following arguments, all of which have an IN 
  parameter mode except for NMFINR:
   - SUBTABLE (VARCHAR2).  This variable represents the name of one of the five 
     minor frames location tables (MNFLT1, MNFLT2, MNFLT3, MNFLT4, and MNFLT5).

   - LOW_INDEX (NUMBER).  This argument represents the lowest minor frame counter
     reported in the minor frame location table.

   - HIGH_INDEX (NUMBER).  This argument represents the highest minor frame counter
     reported in the minor frame location table. 

   - MAX_QRANK1 (NUMBER).  This argument represents the maximum quality rank a 
     minor frame may have for the mission. 

   - NMFINR (INTEGER).  This argument, which will be returned to procedure 
     GEN_RECIPE2 by procedure GEN_RECIPE4, represents the number of minor 
     frames in the RECIPE table.

ARGUMENTS*/

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

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

   - RULE.  This is the stored package that manipulates the reconstruction rules
     numbers, name and version number.

   - CONFIG.  This is the stored package that manipulates the configuration
     parameters 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_SQL.  This the native Oracle dynamic SQL package.

   - FILL_FLAG.  This is a function that operates on the Minor Frames Quality
     table (MNFQT), returning the fill flag when provided with a minor frame
     quality rank (QRANK).

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

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

   - 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.
DEPENDENCIES*/

/*VARIABLES
 Variables

 The following are variables used in the procedure:
   - C, D, and E (INTEGER). Cursor handles.

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

   - FP_UMF_DATETIME1 (NUMBER).  Represents the value of the Unpacked Major
     Frame Floating Point Datetime (the major frame spacecraft time).

   - MNF_LOC1 (INTEGER).  Represents the location of the minor frame in the amf
     file.

   - QUALITY1 (INTEGER).  Represents the overall quality of the minor frame.

   - TABLE_LENTGH (INTEGER).  Represents the configuration parameter
     MAX_TABLE_NAME_LENGTH (maximum table name length).

   - COL_VALUE (NUMBER).  Represents the value stored in the BFST column whose
     identity is stored in the configuration parameter RECIPE_COL_NAME.

   - CDM (INTEGER).  Represents the Current Data Mode.  

   - COUNT1 (INTEGER).  Represents a running count of the number of major frames
     inserted into the RECIPE table.

   - NEW_UMFC1 (NUMBER).  Represents the value of the unpacked major frame counter
     for the major frame for which a recipe is being generated.

   - POINTER1 (NUMBER).  Represents the minor frame's SPOINTER (short pointer) 
     stored in the minor frames location table.

   - NEW_FILE1 (SESSIONS_PARAMETERS.BFST%TYPE).  Represents the name of the BFST
     where the minor frame was found (i.e. the table to file to which the short
     pointer points).

   - ROWID1 (ROWID).  Represents the rowid of the major frame being reconstructed,
     in the minor frames location table.

   - MFP (NUMBER).  Represents the major frame period.

   - COL_NAME (VARCHAR2(50)).  Represents the configuration parameter RECIPE_COL_NAME,
     which is the name of the column in the RECIPE table that is peculiar to this 
     mission.  
VARIABLES*/

/*EXAMPLES
  Example
 
  Here is a call to GEN_RECIPE4:

   DECLARE NMFINR INTEGER;
   BEGIN
       GEN_RECIPE4 ('MNFLT1',0,50,32,NMFINR);
   END;
   /
 
 The arguments of this procedure are passed in from procedure GEN_RECIPE2.
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.

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

  - SUBTABLE.  

  - MNFFPT.  This is the minor frame file pointer table used to keep statistic
    information on at most one thousand sessions.  Among other data, this table
    stores the short and long pointers for each session.

  - RECIPE.  This table stores instructions about how and where to recover minor
    frames of all reconstructed frames.  These instructions are read by AD to 
    assemble and decommutate imperfect frames.

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

/*OTHERS
 Others
 
 It should be noted that because there are five minor frames location tables 
   (MNFLT1, MNFLT2, MNFLT3, MNFLT4, and MNFLT5), this procedure is called five
   time by rule GEN_RECIPE2, each time passing a different location table.

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