// file: latn_debug_0.cc
//

// isip include files
//
#include "lattice_node.h"
#include "lattice_node_constants.h"

#include <lex_tree.h>
#include <lex_tree_constants.h>

// method: debug_cc
//
// arguments:
//  FILE* fp: (input) a open file pointer
//  char_1* message: (input) a message to be displayed
//
// return: a logical_1 flag indicating success
//
logical_1 Lattice_node::debug_cc(FILE *fp_a, char_1* message_a) {
  
  // dump the contents of the class to the file
  //
  fprintf(fp_a, "%s::%s node_index_d = %ld\n", LATTICE_NODE_CLASS_NAME,
	  message_a, node_index_d);
  fprintf(fp_a, "%s::%s frame_d = %ld\n", LATTICE_NODE_CLASS_NAME,
	  message_a, frame_d);
  fprintf(fp_a, "%s::%s type_d = %ld\n", LATTICE_NODE_CLASS_NAME,
	  message_a, type_d);
  fprintf(fp_a, "%s::%s word_d = %p\n", LATTICE_NODE_CLASS_NAME,
	  message_a, word_d);
  fprintf(fp_a, "%s::%s pron_variant_d = %ld\n", LATTICE_NODE_CLASS_NAME,
	  message_a, pron_variant_d);
  
  fprintf(fp_a, "%s::%s num_arcs_in_d = %ld\n", LATTICE_NODE_CLASS_NAME,
	  message_a, num_arcs_in_d);
  fprintf(fp_a, "%s::%s num_arcs_out_d = %ld\n", LATTICE_NODE_CLASS_NAME,
	  message_a, num_arcs_out_d);

  fprintf(fp_a, "%s::%s prev_nodes_d = %p\n", LATTICE_NODE_CLASS_NAME,
	  message_a, prev_nodes_d);
  fprintf(fp_a, "%s::%s next_nodes_d = %p\n", LATTICE_NODE_CLASS_NAME,
	  message_a, next_nodes_d);

  fprintf(fp_a, "%s::%s lm_scores_d = %p\n", LATTICE_NODE_CLASS_NAME,
	  message_a, lm_scores_d);
  for (int_4 i = 0; i < num_arcs_out_d; i++) {
    fprintf(fp_a, "%s::%s lm_scores_d[%ld] = %f\n", LATTICE_NODE_CLASS_NAME,
	    message_a, i, lm_scores_d[i]);
  }

  fprintf(fp_a, "%s::%s ac_scores_d = %p\n", LATTICE_NODE_CLASS_NAME,
	  message_a, ac_scores_d);
  for (int_4 i = 0; i < num_arcs_out_d; i++) {
    fprintf(fp_a, "%s::%s ac_scores_d[%ld] = %f\n", LATTICE_NODE_CLASS_NAME,
	    message_a, i, ac_scores_d[i]);
  }

  // loop through the prev and next nodes and print the node indices in
  // each case
  //
  fprintf(fp_a, "Prev nodes: ");
  if (prev_nodes_d != (Link_list*)NULL) {
    for (Link_node* node = prev_nodes_d->get_head_cc();
         node != (Link_node*)NULL; node = node->get_next_cc()) {
      Lattice_node* temp_node = (Lattice_node*)(node->get_item_cc());
      
      if (temp_node != (Lattice_node*)NULL) {
	fprintf(fp_a, "%ld", temp_node->get_node_index_cc());
	if (temp_node->word_d != (Word*)NULL) {
	  fprintf(fp_a, "(%ld) ", temp_node->word_d->get_index_cc());
	}
	else {
	  fprintf(fp_a, "() ");
	}
      }
    }
  }
  fprintf(fp_a, "\n");

  fprintf(fp_a, "Next nodes: ");
  if (next_nodes_d != (Link_list*)NULL) {
    for (Link_node* node = next_nodes_d->get_head_cc();
         node != (Link_node*)NULL; node = node->get_next_cc()) {
      Lattice_node* temp_node = (Lattice_node*)(node->get_item_cc());
      
      if (temp_node != (Lattice_node*)NULL) {
	fprintf(fp_a, "%ld", temp_node->get_node_index_cc());
	if (temp_node->word_d != (Word*)NULL) {
	  fprintf(fp_a, "(%ld) ", temp_node->word_d->get_index_cc());
	}
	else {
	  fprintf(fp_a, "() ");
	}
      }
    }
  }
  fprintf(fp_a, "\n");
  
  // print the lexical tree
  //
  fprintf(fp_a, "%s::%s lex_tree_d = %p\n", LATTICE_NODE_CLASS_NAME,
	  message_a, lex_tree_d);
  if (lex_tree_d != (Lex_tree*)NULL) {
    lex_tree_d->debug_cc(fp_a, message_a);
  }
      
  // exit gracefully
  //
  return ISIP_TRUE;
}
