/**********
Copyright 1999 AG inc.  All rights reserved.
Author: 1999 Alan Gillespie
**********/

#include "ngspice/ngspice.h"
#include "ngspice/cktdefs.h"
#include "ngspice/suffix.h"

void
CKTncDump(
    CKTcircuit *ckt)
{
  CKTnode *node;
  double new, old;
  int i=1;

  fprintf(stdout,"\n");
  fprintf(stdout,"Last solution and right-hand side\n");
  fprintf(stdout,"---------------------------------\n\n");
  fprintf(stdout,"Both columns are the SAME iteration, not two successive ones, and which\n");
  fprintf(stdout,"physical quantity each holds depends on the row:\n");
  fprintf(stdout,"  ordinary node : solution = node voltage (V), rhs = injected current (A)\n");
  fprintf(stdout,"  ...#branch    : solution = branch current (A), rhs = source voltage (V)\n");
  fprintf(stdout,"'!' marks a non-finite entry.\n\n");
  fprintf(stdout,"%-30s %20s %20s\n", "Node", "Solution", "RHS");
  fprintf(stdout,"%-30s %20s %20s\n", "----", "--------", "---");
  for(node=ckt->CKTnodes->next;node;node=node->next) {
    if (strstr(node->name, "#branch") || !strchr(node->name, '#')) {
      new =  ckt->CKTrhsOld [i] ;
      old =  ckt->CKTrhs [i] ;
      fprintf(stdout,"%-30s %20g %20g", node->name, new, old);
      /* The old code compared these two with a reltol/abstol test and flagged
         the row with '*'.  They are a solution and a right-hand side, of
         different dimensions on every row type, so that comparison was
         meaningless.  What is actually worth seeing on a failed solve is which
         entries have gone non-finite. */
      if (!(new == new) || !(old == old)) {
           fprintf(stdout," !");
      }
      fprintf(stdout,"\n");
    }
    i++;
  }
  fprintf(stdout,"\n");
}
