From 8f3f7578137c1d874c9fa404908a6164deacd62b Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sun, 19 Feb 2012 11:11:31 +0000 Subject: [PATCH] command mrdump --- ChangeLog | 4 ++++ src/frontend/com_cdump.c | 26 ++++++++++++++++++++++++++ src/frontend/com_cdump.h | 1 + src/frontend/commands.c | 4 ++++ src/include/ngspice/smpdefs.h | 1 + src/maths/sparse/spoutput.c | 15 ++++++++++----- src/maths/sparse/spsmp.c | 10 ++++++++++ 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ec4d0b61..9b3dfab03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-02-19 Holger Vogt + * com_cdump.c, com_cdump.h, commands.c, smpdefs.h, spoutput.c, spsmp.c, + command mrdump to dump the RHS of the matrix to stdout or to a file + 2012-02-19 Holger Vogt * spiceif.c: savesnap, loadsnap enabled (still experimental!) * com_cdump.c, com_cdump.h, commands.c, smpdefs.h, spoutput.c, spsmp.c, diff --git a/src/frontend/com_cdump.c b/src/frontend/com_cdump.c index 2be33730c..b097cbe0f 100644 --- a/src/frontend/com_cdump.c +++ b/src/frontend/com_cdump.c @@ -172,3 +172,29 @@ com_mdump(wordlist *wl) return; } + +void +com_rdump(wordlist *wl) +{ + CKTcircuit *ckt = NULL; + char *s; + + if (!ft_curckt || !ft_curckt->ci_ckt) { + fprintf(cp_err, "Error: no circuit loaded.\n"); + return; + } + + ckt = ft_curckt->ci_ckt; + + if ((ckt->CKTmatrix) && (ckt->CKTrhs)) + if (wl == NULL) + SMPprintRHS( ckt->CKTmatrix , NULL, ckt->CKTrhs, ckt->CKTirhs); + else { + s = cp_unquote(wl->wl_word); + SMPprintRHS( ckt->CKTmatrix , s, ckt->CKTrhs, ckt->CKTirhs); + } + else + fprintf(cp_err, "Error: no matrix or RHS available.\n"); + + return; +} diff --git a/src/frontend/com_cdump.h b/src/frontend/com_cdump.h index b87d1e10a..3a859a4b5 100644 --- a/src/frontend/com_cdump.h +++ b/src/frontend/com_cdump.h @@ -3,6 +3,7 @@ void com_cdump(wordlist *wl); void com_mdump(wordlist *wl); +void com_rdump(wordlist *wl); #define TABINDENT 2 /* CDHW */ /* The orginal value was 8 */ #endif diff --git a/src/frontend/commands.c b/src/frontend/commands.c index 6679154df..f4040f7f6 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -553,6 +553,10 @@ struct comm spcp_coms[] = { { 0, 0, 0, 0 }, E_DEFHMASK, 0, 1, NULL, "outfile: Dump the current matrix." } , + { "mrdump", com_rdump, FALSE, FALSE, + { 0, 0, 0, 0 }, E_DEFHMASK, 0, 1, + NULL, + "outfile: Dump the current RHS to file." } , { "settype", com_stype, FALSE, FALSE, { 0200000, 040000, 040000, 040000 }, E_DEFHMASK, 2, LOTS, NULL, diff --git a/src/include/ngspice/smpdefs.h b/src/include/ngspice/smpdefs.h index ecaebf101..765bcc458 100644 --- a/src/include/ngspice/smpdefs.h +++ b/src/include/ngspice/smpdefs.h @@ -31,6 +31,7 @@ int SMPnewMatrix( SMPmatrix ** ); void SMPdestroy( SMPmatrix *); int SMPpreOrder( SMPmatrix *); void SMPprint( SMPmatrix * , char *); +void SMPprintRHS( SMPmatrix * , char *, double*, double*); void SMPgetError( SMPmatrix *, int *, int *); int SMPcProdDiag( SMPmatrix *, SPcomplex *, int *); int SMPcDProd(SMPmatrix *Matrix, SPcomplex *pMantissa, int *pExponent); diff --git a/src/maths/sparse/spoutput.c b/src/maths/sparse/spoutput.c index 10bc98c60..6746ed59a 100644 --- a/src/maths/sparse/spoutput.c +++ b/src/maths/sparse/spoutput.c @@ -606,10 +606,14 @@ spFileVector(MatrixPtr eMatrix, char *File, RealVector RHS, RealVector iRHS) /* Begin `spFileVector'. */ assert( IS_SPARSE( Matrix ) && RHS != NULL); - /* Open File in append mode. */ - pMatrixFile = fopen(File,"a"); - if (pMatrixFile == NULL) - return 0; + if (File) { + /* Open File in append mode. */ + pMatrixFile = fopen(File,"a"); + if (pMatrixFile == NULL) + return 0; + } + else + pMatrixFile=stdout; /* Output vector. */ Size = Matrix->Size; @@ -634,7 +638,8 @@ spFileVector(MatrixPtr eMatrix, char *File, RealVector RHS, RealVector iRHS) } /* Close file. */ - if (fclose(pMatrixFile) < 0) return 0; + if (File) + if (fclose(pMatrixFile) < 0) return 0; return 1; } diff --git a/src/maths/sparse/spsmp.c b/src/maths/sparse/spsmp.c index 8e6b880da..245543dd7 100644 --- a/src/maths/sparse/spsmp.c +++ b/src/maths/sparse/spsmp.c @@ -277,6 +277,16 @@ SMPpreOrder(SMPmatrix *Matrix) return spError( Matrix ); } +/* + * SMPprint() + */ + +void +SMPprintRHS(SMPmatrix *Matrix, char *Filename, RealVector RHS, RealVector iRHS) +{ + spFileVector( Matrix, Filename, RHS, iRHS ); +} + /* * SMPprint() */