?? RIGHT := 110 ??
?? NEWTITLE := 'DEFINE_SUBPRODUCT Subutility: RAP$WRITE_SUBPRODUCT_INFO_FILE Interface.' ??
MODULE ram$write_subproduct_info_file;

{ PURPOSE:
{   This module contains the interface and procedure that writes the
{   subproduct information file.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{   **What do we do about the main title above?  This interface is also
{     called by CREATE_SUBPRODUCT_CORRECTION utility.
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc rac$sif_file_name
*copyc rae$package_software_cc
*copyc rat$path
*copyc rat$subproduct_verify_errors
*copyc rat$subproduct_verify_options
*copyc rat$validation_selections
?? POP ??
*copyc i#current_sequence_position
*copyc osp$append_status_file
*copyc osp$set_status_abnormal
*copyc rap$verify_subproduct
*copyc rap$write_file_from_memory
?? OLDTITLE ??
?? NEWTITLE := '[XDCL] rap$write_subproduct_info_file', EJECT ??

{ PURPOSE:
{   This interface writes the subproduct information file from the
{   subproduct info sequence residing in memory.
{
{ DESIGN:
{   The subproduct information is first verified against the PACS catalog
{   for which it was defined.  How and what is verfied is based on certain
{   criteria.
{
{   The modification date and time and the attributes checksum values stored
{   in the element list are compared with the actual values of the files
{   they define.  Any difference found causes the verification to fail.
{   Verification will stop on first error.
{
{   When contents checksuming is turned on for the subproduct, the contents
{   checksum will be calculated.
{
{   Once verified the subproduct information file is created under the PACS
{   catalog and the sequence copied into it.
{
{ NOTES:
{   **Explain what verify_errors is all about.
{

  PROCEDURE [XDCL] rap$write_subproduct_info_file
    (    pacs_catalog: rat$path;
     VAR subproduct_info_pointers {input} : rat$subproduct_info_pointers;
     VAR status: ost$status);


    VAR
      subproduct_info_file: rat$path,
      validation_selections: rat$validation_selections,
      verify_errors: rat$subproduct_verify_errors,
      verify_options: rat$subproduct_verify_options;


    status.normal := TRUE;
    validation_selections := $rat$validation_selections [rac$loading_cycle_only, rac$no_rings_below_11,
          rac$no_permits];
    verify_errors := $rat$subproduct_verify_errors [];

    IF subproduct_info_pointers.attributes_p^.calculate_contents_checksum THEN
      verify_options := $rat$subproduct_verify_options [rac$calculate_contents_checksum,
            rac$stop_on_first_error, rac$test_attributes_checksum, rac$test_mod_date_time];
    ELSE {do not calculate contents checksum}
      verify_options := $rat$subproduct_verify_options [rac$stop_on_first_error, rac$test_attributes_checksum,
            rac$test_mod_date_time];
    IFEND;

    rap$verify_subproduct (^pacs_catalog.path (1, pacs_catalog.size), validation_selections, FALSE
          {sif present} , verify_options, verify_errors, subproduct_info_pointers, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    IF verify_errors <> $rat$subproduct_verify_errors [] THEN
      osp$set_status_abnormal ('RA', rae$pacs_does_not_verify, subproduct_info_pointers.attributes_p^.name,
            status);
      osp$append_status_file (osc$status_parameter_delimiter, pacs_catalog.path (1, pacs_catalog.size),
            status);
      RETURN;
    IFEND;

    STRINGREP (subproduct_info_file.path, subproduct_info_file.size, pacs_catalog.path (1, pacs_catalog.size),
          '.', rac$sif_file_name);

    rap$write_file_from_memory (subproduct_info_file.path (1, subproduct_info_file.size),
          i#current_sequence_position (subproduct_info_pointers.subproduct_info_seq_p),
          subproduct_info_pointers.subproduct_info_seq_p, status);

  PROCEND rap$write_subproduct_info_file;
MODEND ram$write_subproduct_info_file;

