Patches for 3f4 -> 3f5b (fwd)


To ng-spice-devel@ieee.ing.uniroma1.it
From Paolo Nenzi <pnenzi@ieee.ing.uniroma1.it>
Date Tue, 21 Dec 1999 17:19:53 +0100 (CET)
Delivered-To mailing list ng-spice-devel@ieee.ing.uniroma1.it
Mailing-List contact ng-spice-devel-help@ieee.ing.uniroma1.it; run by ezmlm
Reply-To ng-spice-devel@ieee.ing.uniroma1.it



---------- Forwarded message ----------
Date: Tue, 21 Dec 1999 17:15:56 +0100 (CET)
From: Paolo Nenzi <pnenzi@iol.it>
Reply-To: p.nenzi@ieee.org
To: pnenzi@ieee.ing.uniroma1.it
Subject: Patches for 3f4 -> 3f5b (fwd)



---------- Forwarded message ----------
Date: Mon, 20 Dec 1999 18:19:01 +0100 (MET)
From: tuckey@ieee.org
To: p.nenzi@ieee.org
Subject: Patches for 3f4 -> 3f5b

Hi again,

Here are the patches I applied to come up with 3f5b.  They are old so I'm
sure you have applied them already.

>From - Sat Feb 22 10:44:24 1997
Path: 
pellew.ntu.edu.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!metro!munnari.OZ.AU!uunet!in1.uu.net!205.252.116.190!feed1.news.erols.com!howland.erols.net!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!cam-news-feed2.bbnplanet.com!dilbert.whoi.edu!kilowatt.whoi.edu!ned
From: ned@kilowatt.whoi.edu (Ned Forrester)
Newsgroups: sci.electronics.cad,comp.lsi.cad
Subject: Spice 3f5 - Collected patches
Followup-To: sci.electronics.cad
Date: 10 Feb 1997 22:23:20 GMT
Organization: Woods Hole Oceanographic Institution
Lines: 1266
Message-ID: <5do74o$mm112@dilbert.whoi.edu>
NNTP-Posting-Host: kilowatt.whoi.edu
Xref: pellew.ntu.edu.au sci.electronics.cad:10319 comp.lsi.cad:7676

[Note: followups to sci.electronics.cad]

There seems to be some current interest in correction/porting of 
Spice 3f5 so I am reposting those patches I know of through
contributions to these newsgroups.

Please do not ask me to fix bugs (for the most part I would not be 
able to anyway).  I am offering this collected information without 
warranty, of course.  If you have additions for this list, I will try 
to add them on a time-available basis.


Spice 3f5 is the last "official" release of Spice from UC Berkeley.

Following is a note about the changes from 3f4 to 3f5 and a collection 
of various patches for bugs that have been fixed by several people 
since the release of 3f5. 

Contents (updated 2/10/96):
    Note/patches for the evolution of 3f4->3f5 (Beorn Johnson)
    Patch(es) for Arbitrary Source state bug (Beorn Johnson, Eckhard Brass)
    Current Controlled Switch in subckt, parsing bug (Ned Forrester)
    Recognition of scale factors in arbitrary source (Beorn Johnson)
    Noise analysis bug (Richard McRoberts)
    Save segmentation faults (Richard McRoberts)


---------------------------------------------------------------
---------------------------------------------------------------

>From the last maintainer of the 3f5 code at Berkeley (but please don't 
ask him about Spice as he has moved on to other work):

--------------- Begin include of 3f5 note ----------------------

Article: 428 of comp.lsi.cad
From: beorn@swindle.XCF.Berkeley.EDU (Beorn Johnson)
Newsgroups: comp.lsi.cad
Subject: Re: Spice 3f5?
Date: Wed, 21 Jun 95 16:41:13 EDT
Organization: UC Berkeley Experimental Computing Facility (XCF)
Lines: 181
Distribution: inet
Message-ID: <3sa059$fds@agate.berkeley.edu>
References: <3rclso$122@ccshst05.cs.uoguelph.ca> 
<aswellDAAACx.Asy@netcom.com> <3s57mh$2mh@moe.tas.drs.com> 
<BRACKEN.95Jun21105019@kevily.ECE.CMU.EDU>
NNTP-Posting-Host: swindle.xcf.berkeley.edu

J Eric Bracken <bracken@kevily.ECE.CMU.EDU> 
in <BRACKEN.95Jun21105019@kevily.ECE.CMU.EDU>:
- The README in the 3f4 distribution says that it (3f4) will be the last
- supported release of Spice3 from UCB.  That suggests that any 3f5 version
- you might find is "unofficial."

Well, there was a slight goof-up there.  3f5 is the last "official" version,
but for a while it was distributed under the name of "3f4".  The last
few patches (one of which is actually rather important for initial
conditions to work right) were not done in the same way previous sets of
patches were done.  In particular, the version file (which is in
an obscure location) wasn't updated.  This causes lots of confusion,
since you can't tell if you have an updated version of 3f4 or not --
so when you apply the patches, BE CAREFUL and check the results ('patch'
can just as easily work in reverse...).

The patches from 3f4 to 3f5 are available for ftp from ic.eecs.berkeley.edu
and from ilpsoft.eecs.berkeley.edu (which also has a copy of the
'patch' source), but while I'm posting, I guess I might as well post
the patches.  I think you will probably have to apply each patch
separately.  In addition, if you want to update the 'version' to 3f5,
change the file 'util/skeleton/make_def.bd'; edit the line with
"VERSION = 3f4".

Also note that the officially distributed version of 3f5 may have slightly
different changes (but which have the same effect).

        Beorn Johnson
        (beorn@eecs.berkeley.edu)

DISCLAIMER:  This post is informal and done in good faith, but is _not_
        a statement from UC Berkeley or any of its official representatives;
        my email address should be considered merely co-incidental.
        Caveat emptor, etc.

----------
The following patches were ftp-ed from ic.eecs.berkeley.edu on
        Wed Jun 21 13:41:13 PDT 1995

*** spice3f4/grid.c     Sun Apr 25 14:53:11 1993
--- spice3f5/grid.c     Sat Jan 29 10:47:59 1994
***************
*** 17,22 ****
--- 17,23 ----
  #include "suffix.h"
  
  #define RAD_TO_DEG    (180.0 / M_PI)
+ #define LABEL_CHARS   20
  
  static double *lingrid(), *loggrid();
  static void polargrid(), smithgrid();
***************
*** 225,231 ****
      int max;
      static double dd[2];
      int mult = 1;
!     char buf[16], *s;
      int slim, digits;
  
      if (axis == y_axis && graph->grid.ysized) {
--- 226,232 ----
      int max;
      static double dd[2];
      int mult = 1;
!     char buf[LABEL_CHARS], *s;
      int slim, digits;
  
      if (axis == y_axis && graph->grid.ysized) {
***************
*** 477,483 ****
  drawlingrid(graph, units, spacing, nsp, dst, lmt, hmt, onedec, mult, mag,
      digits, axis)
      GRAPH *graph;
!     char units[16];
      bool onedec;
      int nsp, spacing, mult;
      double hmt, lmt, dst;
--- 478,484 ----
  drawlingrid(graph, units, spacing, nsp, dst, lmt, hmt, onedec, mult, mag,
      digits, axis)
      GRAPH *graph;
!     char *units;
      bool onedec;
      int nsp, spacing, mult;
      double hmt, lmt, dst;
***************
*** 488,494 ****
  
      int i, j;
      double m, step;
!     char buf[16];
  
      /* i counts how many pixels we have drawn, and j counts which unit
       * we are at.
--- 489,495 ----
  
      int i, j;
      double m, step;
!     char buf[LABEL_CHARS];
  
      /* i counts how many pixels we have drawn, and j counts which unit
       * we are at.
***************
*** 567,573 ****
      double k;
      double decs;
      double mag, gain;
!     char buf[32], *s;
  
      if (axis == x_axis && graph->grid.xsized) {
        lmt = graph->grid.xaxis.log.lmt;
--- 568,574 ----
      double k;
      double decs;
      double mag, gain;
!     char buf[LABEL_CHARS], *s;
  
      if (axis == x_axis && graph->grid.xsized) {
        lmt = graph->grid.xaxis.log.lmt;
***************
*** 671,677 ****
  {
      int i, j, k, l, m;
      double t;
!     char buf[16];
  
      /* Now plot every pp'th decade line, with subs lines between them. */
      if (subs > 1)
--- 672,678 ----
  {
      int i, j, k, l, m;
      double t;
!     char buf[LABEL_CHARS];
  
      /* Now plot every pp'th decade line, with subs lines between them. */
      if (subs > 1)

*** spice3f4/newcoms.c  Sun Mar  7 16:30:58 1993
--- spice3f5/newcoms.c  Wed Feb 23 22:39:55 1994
***************
*** 151,156 ****
--- 151,160 ----
            /* Copy from the first */
            vname = cp_unquote(wl->wl_word);
            dv = vec_get(vname);
+           if (!dv) {
+               printf("'%s' reference vector not found\n", vname);
+               return;
+           }
            numdims = dv->v_numdims;
            dims = dv->v_dims;
            wl = wl->wl_next;

*** spice3f4/spsmp.c    Wed Feb  3 14:20:50 1993
--- spice3f5/spsmp.c    Sun Jan 30 11:53:10 1994
***************
*** 483,492 ****
  int CreateIfMissing;
  {
  MatrixPtr Matrix = (MatrixPtr)eMatrix;
! ElementPtr Element = Matrix->FirstInCol[Col];
  
  /* Begin `SMPfindElt'. */
      ASSERT( IS_SPARSE( Matrix ) );
      Element = spcFindElementInCol(Matrix, &Element, Row, Col, 
CreateIfMissing);
      return (SMPelement *)Element;
  }
--- 485,497 ----
  int CreateIfMissing;
  {
  MatrixPtr Matrix = (MatrixPtr)eMatrix;
! ElementPtr Element;
  
  /* Begin `SMPfindElt'. */
      ASSERT( IS_SPARSE( Matrix ) );
+     Row = Matrix->ExtToIntRowMap[Row];
+     Col = Matrix->ExtToIntColMap[Col];
+     Element = Matrix->FirstInCol[Col];
      Element = spcFindElementInCol(Matrix, &Element, Row, Col, 
CreateIfMissing);
      return (SMPelement *)Element;
  }

--------------- End include of 3f5 note ----------------------
---------------------------------------------------------------

In addition, there have been other changes proposed beyond the 3f5
release:

----- 1. ASRC bug -----------------------

Article: 4321 of comp.lsi.cad
From: beorn@scam.Berkeley.EDU (Beorn Johnson)
Newsgroups: comp.lsi.cad
Subject: Re: Spice 3F4 "B" Source anomaly?
Date: Fri, 3 Feb 95 06:23:20 EST
Organization: UC Berkeley Experimental Computing Facility (XCF)
Lines: 499
Distribution: world
Message-ID: <3gt3n8$3ms@agate.berkeley.edu>
References: <3gbsm2$nt@voyager.cris.com>, <3glm97$k9o@pearl.whoi.edu>
NNTP-Posting-Host: swindle.berkeley.edu
Originator: beorn@swindle.Berkeley.EDU


Ned Forrester <ned@kilowatt.whoi.edu> in <3glm97$k9o@pearl.whoi.edu>:
- 
-      2 : vt 10 0 1
-      3 : b1 1 0 v = v(10)
-      4 : r1 1 0 1
-      5 : b2 2 0 v = 1
-      6 : r2 2 0 1
-      7 : b3 3 0 i = 1
-      8 : r3 3 0 1
-      9 : .op
-     10 : .end
- 
- [ ... ]
- 
- Note that show always gives zero for the asrc state, and the v=1
- source gives the right current and the wrong voltage... clearly a bug.
- Transient analysis gives the same results for voltages.

I was curious about this, so I fixed a couple of things.  I now get:

        Spice 2 -> print all
        v(1) = 1.000000e+00
        v(2) = 1.000000e+00
        v(3) = -1.00000e+00
        v(10) = 1.000000e+00
        b1#branch = -1.00000e+00
        b2#branch = -1.00000e+00
        vt#branch = 0.000000e+00
        Spice 3 -> show all
         ASRC: Arbitrary Source 
         device           b3        b2        b1
                 i         0        -1        -1
                 v        -1         1         1
          pos_node         4         3         2
          neg_node         0         0         0

         Resistor: Simple linear resistor
         device           r3        r2        r1
         model             R         R         R
        resistance         1         1         1
                 i        -1         1         1
                 p         1         1         1

         Vsource: Independent voltage source
         device           vt
                dc         1
             acmag         0
                 i         0
                 p         0

(Note: the current is still wrong coming out of b3, which is a current
source -- this has to do with the fact that the current (amps) output of
a current source isn't a state variable.  It could be fixed, but I'm not
going to go at it now.  More of a "limitation" than a out-and-out bug.)

Patches are below.  Note I don't get enthusiastic about fixing spice bugs;
this one just happened to catch my eye for various reasons (I was trying
out a new C compiler and I know Spice3 to be a good challange).  If I
left out anything obvious here, though, let me know.

As far as a warranty: "it worked for me" -- that's all you get.
These _patches_ are in the public domain.

        Beorn Johnson
        (beorn@scam.berkeley.edu)

----------
[ Note: I don't know how patch will like the filenames.  If you don't
have "3f5", _first_ get the patches from either
        ftp@ic.eecs.berkeley.edu:/pub/Spice3/3f4_patches.
        ftp@ilpsoft.eecs.berkeley.edu:/pub/SPICE3F5
(one of these, smppatch or whatever, is important for initial conditions).
Note that neither of these sets of patches update the version number to
3f5; do that by hand in "util/skeleton/make_def.bd" where "VERSION" is
defined.  For the following patches I also gave "REVISION" the value of
"b1", so my version calls itself "3f5b1".  Actually, I also have a small
number of less important tweeks that I didn't include here. ]


*** asrcacld.c  Fri Feb  3 01:28:56 1995
--- asrcacld.c.orig     Fri Feb  3 01:28:25 1995
***************
*** 30,36 ****
  
      register ASRCmodel *model = (ASRCmodel*)inModel;
      register ASRCinstance *here;
!     int i, j;
      double *derivs;
      double rhs;
  
--- 30,36 ----
  
      register ASRCmodel *model = (ASRCmodel*)inModel;
      register ASRCinstance *here;
!     int i, v_first, j;
      double *derivs;
      double rhs;
  
***************
*** 48,60 ****
           * entries of the jacobian.
           */
  
          j=0;
-       if( here->ASRCtype == ASRC_VOLTAGE){
-           *(here->ASRCposptr[j++]) += 1.0;
-           *(here->ASRCposptr[j++]) -= 1.0;
-           *(here->ASRCposptr[j++]) -= 1.0;
-           *(here->ASRCposptr[j++]) += 1.0;
-       }
          derivs = here->ASRCacValues;
          rhs = (here->ASRCacValues)[here->ASRCtree->numVars];
  
--- 48,55 ----
           * entries of the jacobian.
           */
  
+         v_first = 1;
          j=0;
          derivs = here->ASRCacValues;
          rhs = (here->ASRCacValues)[here->ASRCtree->numVars];
  
***************
*** 62,83 ****
          switch(here->ASRCtree->varTypes[i]){
          case IF_INSTANCE:
              if( here->ASRCtype == ASRC_VOLTAGE){
!               /* CCVS */
!               *(here->ASRCposptr[j++]) -= derivs[i];
              } else{
!               /* CCCS */
!               *(here->ASRCposptr[j++]) += derivs[i];
!               *(here->ASRCposptr[j++]) -= derivs[i];
              }
              break;
          case IF_NODE:
              if(here->ASRCtype == ASRC_VOLTAGE){
!               /* VCVS */
!               *(here->ASRCposptr[j++]) -= derivs[i];
              } else {
!               /*VCCS*/
!               *(here->ASRCposptr[j++]) += derivs[i];
!               *(here->ASRCposptr[j++]) -= derivs[i];
              }
              break;
          default:
--- 57,92 ----
          switch(here->ASRCtree->varTypes[i]){
          case IF_INSTANCE:
              if( here->ASRCtype == ASRC_VOLTAGE){
!             /* CCVS */
!             if(v_first){
!                 *(here->ASRCposptr[j++]) += 1.0;
!                 *(here->ASRCposptr[j++]) -= 1.0;
!                 *(here->ASRCposptr[j++]) -= 1.0;
!                 *(here->ASRCposptr[j++]) += 1.0;
!                 v_first = 0;
!                }
!             *(here->ASRCposptr[j++]) -= derivs[i];
              } else{
!             /* CCCS */
!             *(here->ASRCposptr[j++]) += derivs[i];
!             *(here->ASRCposptr[j++]) -= derivs[i];
              }
              break;
          case IF_NODE:
              if(here->ASRCtype == ASRC_VOLTAGE){
!             /* VCVS */
!             if( v_first){
!                 *(here->ASRCposptr[j++]) += 1.0;
!                 *(here->ASRCposptr[j++]) -= 1.0;
!                 *(here->ASRCposptr[j++]) -= 1.0;
!                 *(here->ASRCposptr[j++]) += 1.0;
!                 v_first = 0;
!             }
!             *(here->ASRCposptr[j++]) -= derivs[i];
              } else {
!             /*VCCS*/
!             *(here->ASRCposptr[j++]) += derivs[i];
!             *(here->ASRCposptr[j++]) -= derivs[i];
              }
              break;
          default:
*** asrcitf.h   Fri Feb  3 01:47:28 1995
--- asrcitf.h.orig      Fri Feb  3 01:47:26 1995
***************
*** 51,57 ****
      NULL,
  #endif /* DELETES */
      NULL,
!     ASRCask,
      NULL,
  #ifdef AN_pz
      ASRCpzLoad,
--- 51,57 ----
      NULL,
  #endif /* DELETES */
      NULL,
!     NULL,
      NULL,
  #ifdef AN_pz
      ASRCpzLoad,
*** asrcload.c  Fri Feb  3 01:26:41 1995
--- asrcload.c.orig     Thu Feb  2 23:44:57 1995
***************
*** 30,36 ****
  
      register ASRCmodel *model = (ASRCmodel*)inModel;
      register ASRCinstance *here;
!     int i, j, branch;
      int node_num;
      int size;
      double rhs;
--- 30,36 ----
  
      register ASRCmodel *model = (ASRCmodel*)inModel;
      register ASRCinstance *here;
!     int i, v_first, j, branch;
      int node_num;
      int size;
      double rhs;
***************
*** 49,54 ****
--- 49,55 ----
            /*
             * Get the function and its derivatives evaluated 
             */
+           v_first = 1;
            i = here->ASRCtree->numVars;
            if (asrc_nvals < i) {
                    if (asrc_nvals) {
***************
*** 60,65 ****
--- 61,68 ----
                    asrc_derivs = NEWN(double, i);
            }
  
+           j=0;
+ 
            /*
             * Fill the vector of values from the previous solution
             */
***************
*** 113,126 ****
                    }
                }
  
- 
-               j=0;
-               if( here->ASRCtype == ASRC_VOLTAGE){
-                       *(here->ASRCposptr[j++]) += 1.0;
-                       *(here->ASRCposptr[j++]) -= 1.0;
-                       *(here->ASRCposptr[j++]) -= 1.0;
-                       *(here->ASRCposptr[j++]) += 1.0;
-               }
                for(i=0; i < here->ASRCtree->numVars; i++) {
                    rhs -= (asrc_vals[i] * asrc_derivs[i]);
                    switch(here->ASRCtree->varTypes[i]){
--- 116,121 ----
***************
*** 127,132 ****
--- 122,134 ----
                    case IF_INSTANCE:
                        if( here->ASRCtype == ASRC_VOLTAGE){
                            /* CCVS */
+                           if(v_first){
+                               *(here->ASRCposptr[j++]) += 1.0;
+                               *(here->ASRCposptr[j++]) -= 1.0;
+                               *(here->ASRCposptr[j++]) -= 1.0;
+                               *(here->ASRCposptr[j++]) += 1.0;
+                               v_first = 0;
+                           }
                            *(here->ASRCposptr[j++]) -= asrc_derivs[i];
                        } else{
                            /* CCCS */
***************
*** 138,143 ****
--- 140,152 ----
                    case IF_NODE:
                        if(here->ASRCtype == ASRC_VOLTAGE) {
                            /* VCVS */
+                           if( v_first){
+                               *(here->ASRCposptr[j++]) += 1.0;
+                               *(here->ASRCposptr[j++]) -= 1.0;
+                               *(here->ASRCposptr[j++]) -= 1.0;
+                               *(here->ASRCposptr[j++]) += 1.0;
+                               v_first = 0;
+                           }
                            *(here->ASRCposptr[j++]) -= asrc_derivs[i];
                        } else {
                            /*VCCS*/
*** asrcpzld.c  Fri Feb  3 01:31:24 1995
--- asrcpzld.c.orig     Fri Feb  3 01:30:28 1995
***************
*** 27,33 ****
      register ASRCmodel *model = (ASRCmodel*)inModel;
      register ASRCinstance *here;
      double value;
!     int i, j, branch;
      int node_num;
  
      /*  loop through all the Arbitrary source models */
--- 27,33 ----
      register ASRCmodel *model = (ASRCmodel*)inModel;
      register ASRCinstance *here;
      double value;
!     int i, v_first, j, branch;
      int node_num;
  
      /*  loop through all the Arbitrary source models */
***************
*** 37,43 ****
--- 37,45 ----
          for (here = model->ASRCinstances; here != NULL ;
                  here=here->ASRCnextInstance)
        {
+           j = 0;
              /* Get the function evaluated and the derivatives too */
+             v_first = 1;
            i = here->ASRCtree->numVars;
            if (asrc_nvals < i) {
                    if (asrc_nvals) {
***************
*** 61,74 ****
                  }
              }
  
-           j = 0;
-           if(here->ASRCtype == ASRC_VOLTAGE){
-               *(here->ASRCposptr[j++]) += 1.0;
-               *(here->ASRCposptr[j++]) -= 1.0;
-               *(here->ASRCposptr[j++]) -= 1.0;
-               *(here->ASRCposptr[j++]) += 1.0;
-           }
- 
              if( (*(here->ASRCtree->IFeval))(here->ASRCtree, ckt->CKTgmin,
                    &value, asrc_vals, asrc_derivs) == OK){
                  for(i=0; i < here->ASRCtree->numVars; i++){
--- 63,68 ----
***************
*** 76,82 ****
                          case IF_INSTANCE:
                              if( here->ASRCtype == ASRC_VOLTAGE){
                                  /* CCVS */
!                               *(here->ASRCposptr[j++]) -= asrc_derivs[i];
                              } else {
                                  /* CCCS */
                                *(here->ASRCposptr[j++]) += asrc_derivs[i];
--- 70,85 ----
                          case IF_INSTANCE:
                              if( here->ASRCtype == ASRC_VOLTAGE){
                                  /* CCVS */
!                                 if(v_first){
!                                     *(here->ASRCposptr[j++]) += 1.0;
!                                     *(here->ASRCposptr[j++]) -= 1.0;
!                                     *(here->ASRCposptr[j++]) -= 1.0;
!                                     *(here->ASRCposptr[j++]) += 1.0;
!                                     *(here->ASRCposptr[j++]) -= 
asrc_derivs[i];
!                                     v_first = 0;
!                                 } else {
!                                     *(here->ASRCposptr[j++]) -= 
asrc_derivs[i];
!                                 }
                              } else {
                                  /* CCCS */
                                *(here->ASRCposptr[j++]) += asrc_derivs[i];
***************
*** 86,92 ****
                          case IF_NODE:
                              if(here->ASRCtype == ASRC_VOLTAGE){
                                  /* VCVS */
!                               *(here->ASRCposptr[j++]) -= asrc_derivs[i];
                              } else {
                  /* VCCS */
                                  *(here->ASRCposptr[j++]) += asrc_derivs[i];
--- 89,104 ----
                          case IF_NODE:
                              if(here->ASRCtype == ASRC_VOLTAGE){
                                  /* VCVS */
!                                 if( v_first){
!                                     *(here->ASRCposptr[j++]) += 1.0;
!                                     *(here->ASRCposptr[j++]) -= 1.0;
!                                     *(here->ASRCposptr[j++]) -= 1.0;
!                                     *(here->ASRCposptr[j++]) += 1.0;
!                                     *(here->ASRCposptr[j++]) -= 
asrc_derivs[i];
!                                     v_first = 0;
!                                 } else {
!                                     *(here->ASRCposptr[j++]) -= 
asrc_derivs[i];
!                                 }
                              } else {
                  /* VCCS */
                                  *(here->ASRCposptr[j++]) += asrc_derivs[i];
*** asrcset.c   Fri Feb  3 01:24:18 1995
--- asrcset.c.orig      Thu Feb  2 23:35:31 1995
***************
*** 30,35 ****
--- 30,36 ----
      register ASRCinstance *here;
      register ASRCmodel *model = (ASRCmodel*)inModel;
      int error, i, j;
+     int v_first;
      CKTnode *tmp;
  
      /*  loop through all the user models*/
***************
*** 39,44 ****
--- 40,48 ----
          for (here = model->ASRCinstances; here != NULL ;
                  here=here->ASRCnextInstance) {
              
+             here->ASRCposptr = (double **)MALLOC(0);
+             j=0; /* index of the array holding ptrs to SMP */
+             v_first = 1;
              if( here->ASRCtype == ASRC_VOLTAGE){
                  if(here->ASRCbranch==0) {
                      error = CKTmkCur(ckt,&tmp,here->ASRCname,"branch");
***************
*** 64,79 ****
              in the vector of the positions of the SMP */
              if (!here->ASRCtree)
                return E_PARMVAL;
-             j=0; /* index of the array holding ptrs to SMP */
-           if( here->ASRCtype == ASRC_VOLTAGE){
-               here->ASRCposptr = (double **)MALLOC(sizeof(double *) * 4);
-               TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch);
-               TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCbranch);
-               TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCnegNode);
-               TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCposNode);
-           } else
-               here->ASRCposptr = (double **)MALLOC(0);
- 
              for( i=0; i < here->ASRCtree->numVars; i++){
                  switch(here->ASRCtree->varTypes[i]){
                  case IF_INSTANCE:
--- 68,73 ----
***************
*** 89,97 ****
                      }
                      if( here->ASRCtype == ASRC_VOLTAGE){
                          /* CCVS */
!                       here->ASRCposptr = (double **)
!                       REALLOC(here->ASRCposptr, (sizeof(double *)*(j+1)));
!                       TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCcont_br);
                      } else if(here->ASRCtype == ASRC_CURRENT){
                          /* CCCS */
              here->ASRCposptr = (double **)
--- 83,102 ----
                      }
                      if( here->ASRCtype == ASRC_VOLTAGE){
                          /* CCVS */
!                         if(v_first){
!                             here->ASRCposptr = (double **)
!                             REALLOC(here->ASRCposptr, (sizeof(double 
*)*(j+5)));
!                             
TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch);
!                             
TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCbranch);
!                             
TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCnegNode);
!                             
TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCposNode);
!                             
TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCcont_br);
!                             v_first = 0;
!                         } else{
!                             here->ASRCposptr = (double **)
!                             REALLOC(here->ASRCposptr, (sizeof(double 
*)*(j+1)));
!                             
TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCcont_br);
!                         }
                      } else if(here->ASRCtype == ASRC_CURRENT){
                          /* CCCS */
              here->ASRCposptr = (double **)
***************
*** 105,113 ****
                  case IF_NODE:
                      if( here->ASRCtype == ASRC_VOLTAGE){
                          /* VCVS */
!                       here->ASRCposptr = (double **)
                          REALLOC(here->ASRCposptr, (sizeof(double *) * 
(j+1)));
          
MY_TSTALLOC(ASRCposptr[j++],ASRCbranch,here->ASRCtree->vars[i].nValue);
                      } else if(here->ASRCtype == ASRC_CURRENT){
                          /* VCCS */
                          here->ASRCposptr = (double **)
--- 110,129 ----
                  case IF_NODE:
                      if( here->ASRCtype == ASRC_VOLTAGE){
                          /* VCVS */
!                         if(v_first){
!                             here->ASRCposptr = (double **)
!                         REALLOC(here->ASRCposptr, (sizeof(double *) * 
(j+5)));
!                             
TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch);
!                             
TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCbranch);
!                             
TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCnegNode);
!                             
TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCposNode);
!         
MY_TSTALLOC(ASRCposptr[j++],ASRCbranch,here->ASRCtree->vars[i].nValue);
!                             v_first = 0;
!                         } else{
!                             here->ASRCposptr = (double **)
                          REALLOC(here->ASRCposptr, (sizeof(double *) * 
(j+1)));
          
MY_TSTALLOC(ASRCposptr[j++],ASRCbranch,here->ASRCtree->vars[i].nValue);
+                         }
                      } else if(here->ASRCtype == ASRC_CURRENT){
                          /* VCCS */
                          here->ASRCposptr = (double **)

----- END 1. ASRC bug -----------------------

I am no longer sure where the following comments apply, after
application of Beorn's patch above, if they apply at all:

----- 1.1 ASRC bug additional note -----------------------


>From brass@mara.e-technik.uni-dortmund.de Thu Apr 20 09:19:51 1995
Received: from aqua.whoi.edu (AQUA.WHOI.EDU [128.128.16.1]) by 
kilowatt.whoi.edu (8.6.12/8.6.9) with ESMTP id JAA23953 for 
<ned@kilowatt.whoi.edu>; Thu, 20 Apr 1995 09:19:50 -0400
Received: from nx1.HRZ.Uni-Dortmund.DE (nx1.HRZ.Uni-Dortmund.DE 
[129.217.131.3]) by aqua.whoi.edu (8.6.11/8.6.11) with ESMTP id JAA03409 for 
<nforrester@whoi.edu>; Thu, 20 Apr 1995 09:16:11 -0400
Received: from luzi.e-technik.uni-dortmund.de by nx1.hrz.uni-dortmund.de 
          with SMTP (PP); Thu, 20 Apr 1995 14:32:13 +0200
From: Eckhard_Brass <brass@mara.e-technik.uni-dortmund.de>
Date: Thu, 20 Apr 95 14:43:15 +0200
Message-Id: <9504201243.AA10413@mara.e-technik.uni-dortmund.de>
Received: by mara.e-technik.uni-dortmund.de id AA10413;
          Thu, 20 Apr 95 14:43:15 +0200
To: nforrester@whoi.edu
Subject: SPICE3F5_PATCH
Status: R


I read read your remarks in 'comp.lsi.cad':


>I tried the following on a recent copy of 3f5:
>
>-----------------
>
>Program: Spice, version: 3f5
>Date built: Tue Jan 24 11:40:33 EST 1995
>
>Type "help" for more information, "quit" to leave.
>
>Spice 1 -> test
>
>Circuit: * test
>
>Spice 2 -> list
>        * test
>
>     2 : vt 10 0 1
>     3 : b1 1 0 v = v(10)
>     4 : r1 1 0 1
>     5 : b2 2 0 v = 1
>     6 : r2 2 0 1
>     7 : b3 3 0 i = 1
>     8 : r3 3 0 1
>     9 : .op
>    10 : .end
>Spice 3 -> run
>Spice 4 -> print all
>v(1) = 1.000000e+00
>v(2) = 0.000000e+00
>v(3) = -1.00000e+00
>v(10) = 1.000000e+00
>b1#branch = -1.00000e+00
>b2#branch = 1.000000e+00
>vt#branch = 0.000000e+00
>Spice 5 -> show all
> ASRC: Arbitrary Source 
> device           b3        b2        b1
>         i         0         0         0
>         v         0         0         0
>  pos_node         0         0         0
>  neg_node         0         0         0
>
> Resistor: Simple linear resistor
> device           r3        r2        r1
> model             R         R         R
>resistance         1         1         1
>         i        -1         0         1
>         p         1         0         1
>
> Vsource: Independent voltage source
> device           vt
>        dc         1
>     acmag         0
>         i         0
>         p        -0
>
>---------------
>
>Note that show always gives zero for the asrc state, and the v=1
>source gives the right current and the wrong voltage... clearly a bug.
>Transient analysis gives the same results for voltages.
>
>...
>-- 
>Ned Forrester                                       nforrester@whoi.edu
>Applied Ocean Physics and Engineering Dept. / Oceanographic Systems Lab
>Woods Hole Oceanographic Institution          Woods Hole, MA 02543, USA

I think there are two bugs.
                  ---

1. The parser works only correctly if you use at least one circuit node.
  
   v=2*3 does not work, v=2*3+v(0) works!
 
   A quick and dirty fix is to add v(0)=0 !

2. The 'show' command does not work correctly with ASRC devices.
   The bug is easy to fix.

   Patch 'asrcitf.h' in .../src/lib/dev/asrc (add ASRCask).

   Then do a complete rebuild
   ( type 'util/build clean' and then 'util/build sun4 gcc').
 
'asrcitf.h' before patching:
----------------------------

...

#ifdef DELETES
    ASRCmDelete,
    ASRCdelete,
#else /* DELETES */
    NULL,
    NULL,
#endif /* DELETES */
    NULL,
    NULL,
    NULL,
#ifdef AN_pz
    ASRCpzLoad,
#else /* AN_pz */
    NULL,
#endif /* AN_pz */
#ifdef NEWCONV
    ASRCconvTest,
#else /* NEWCONV */
    NULL,
#endif /* NEWCONV */
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,       /* DISTO */
    NULL,       /* NOISE */

    &ASRCiSize,
    &ASRCmSize
};

#endif
#endif


'asrcitf.h' after patching:
--------------------------- 

...
#ifdef DELETES 
    ASRCmDelete, 
    ASRCdelete, 
#else /* DELETES */ 
    NULL, 
    NULL, 
#endif /* DELETES */ 
    NULL, 
    ASRCask,             /* <--- Patch */ 
    NULL,  
#ifdef AN_pz 
    ASRCpzLoad, 
#else /* AN_pz */ 
    NULL, 
#endif /* AN_pz */ 
#ifdef NEWCONV 
    ASRCconvTest, 
#else /* NEWCONV */ 
    NULL, 
#endif /* NEWCONV */ 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    NULL, 
    NULL,       /* DISTO */ 
    NULL,       /* NOISE */ 
 
    &ASRCiSize, 
    &ASRCmSize 
}; 
 
#endif 
#endif


Did you get any response how to fix the first bug?
I have no idea how to fix it.


Regards

Eckhard Brass
Universitaet Dortmund   
AG Mikroelektronik
Emil-Figge-Str. 68
44227 Dortmund
Germany

brass@nora.e-technik.uni-dortmund.de

----- END 1.1 ASRC bug additional note -----------------------
---------------------------------------------------------------


----- 2. Wsw (current controlled switch) in subckt, parsing bug ------

Article: 4313 of comp.lsi.cad
Path: netnews.whoi.edu!kilowatt.whoi.edu!ned
From: ned@kilowatt.whoi.edu (Ned Forrester)
Newsgroups: comp.lsi.cad
Subject: 2 patches for Spice 3f5, wsw and asrc
Date: Thu, 2 Feb 95 14:08:13 EST
Organization: Woods Hole Oceanographic Institution
Lines: 125
Distribution: world
Message-ID: <3grait$hr2@pearl.whoi.edu>
NNTP-Posting-Host: kilowatt.whoi.edu

As there is no longer Spice support at Berkeley it looks like we will
have to do this ourselves:

---------------------------------------------------------

Bug: Current controlled switch inside subcircuit does not expand the
     controlling source correctly: vsrc expands to name:vsrc, 
     not to v:name:src.

Fix: Change src/lib/fte/subckt.c to indicate that w device has only 2 
     not 3 nodes and 1 not zero controlling sources. diff output 
     follows:

diff -c2 subckt.c.orig subckt.c
*** subckt.c.orig       Thu Jul  1 19:25:04 1993
--- subckt.c    Tue Jan 31 15:50:52 1995
***************
*** 649,652 ****
--- 649,655 ----
          case 'H':
          case 'h':
+ /* 2 lines here to fix w bug, NCF 1/31/95 */
+         case 'W':
+         case 'w':
          return (1);
      
***************
*** 945,949 ****
          case 'u': return (3);
          case 'v': return (2);
!         case 'w': return (3);
          case 'z': return (3);
  
--- 948,953 ----
          case 'u': return (3);
          case 'v': return (2);
! /* change 3 to 2 here to fix w bug, NCF 1/31/95 */
!         case 'w': return (2);
          case 'z': return (3);
  
----- END 2. Wsw (current controlled switch) in subckt parsing bug ------
---------------------------------------------------------------

----- 3. scale factors in arbitrary source -----------------------------

Bug: Scale factors (eg. m, k, meg, etc.) for constants in arbitrary 
     sources (b devices) are not recognized. 

Fix: Changes to inpgtok.c and inpptree.c, as supplied by Berkeley.  

NOTE:  These changes were orignally supplied to me as a patch to 3e2 
by Beorn Johnson who was maintaining Spice a while back.  They were 
supposed to have been incorporated in Spice 3f2 at that time, but are
missing from the 3f5 version that I recently got from Berkeley.  I
don't know if they were removed in ignorance or because of a conflict
with some other requirement, but they appear to work in 3f5.  ALSO,
the fix for 3e2 had many more changes, all of which remain in 3f5, so
don't try these alone on 3e2.

Add following Berkeley supplied code to src/lib/inp/inpgtok.c:

diff -c2 inpgtok.c.orig inpgtok.c
*** inpgtok.c.orig      Wed Jul 21 18:40:08 1993
--- inpgtok.c   Tue Jan 24 15:27:34 1995
***************
*** 28,31 ****
--- 28,32 ----
  {
      char * point;
+     int signstate;
  
      /* scan along throwing away garbage characters */
***************
*** 42,45 ****
--- 43,47 ----
      *line = point;
      /* now find all good characters */
+     signstate = 0;
      for(point = *line;*point!='\0';point++) {
          if(*point == ' ') break;
***************
*** 49,52 ****
--- 51,70 ----
          if(*point == ')') break;
          if(*point == ',') break;
+       /* This is not complex enough to catch all errors, but it will
+          get the "good" parses */
+         if(*point == '+' && (signstate == 1 || signstate == 3)) break;
+         if(*point == '-' && (signstate == 1 || signstate == 3)) break;
+         if(*point == '*') break;
+         if(*point == '/') break;
+         if(*point == '^') break;
+       if (isdigit(*point) || *point == '.') {
+           if (signstate > 1)                              
+               signstate = 3;
+           else
+               signstate = 1;
+       } else if (tolower(*point) == 'e' && signstate == 1)
+           signstate = 2;
+       else
+           signstate = 3;
      }
      if (point == *line && *point)     /* Weird items, 1 char */

Change the following line in src/lib/inp/inpptree.c:

diff -c2 inpptree.c.orig inpptree.c
*** inpptree.c.orig     Mon May  3 05:16:54 1993
--- inpptree.c  Tue Jan 24 14:28:50 1995
***************
*** 978,982 ****
          }
  
!       td = INPevaluate(&sbuf, &err, 0);
          if (err == OK) {
              el.token = TOK_VALUE;
--- 978,982 ----
          }
  
!       td = INPevaluate(&sbuf, &err, 1);
          if (err == OK) {
              el.token = TOK_VALUE;

----- END 3. scale factors in arbitrary source -----------------------------

However, note the following:

----- 3.1 note on scale factors in arbitrary source ------------------------

>From beorn@swindle.Berkeley.EDU Fri Feb  3 16:08:14 1995
Return-Path: <beorn@swindle.Berkeley.EDU>
Received: from swindle.Berkeley.EDU by kilowatt.whoi.edu (4.1/SMI-4.1)
        id AA25906; Fri, 3 Feb 95 16:08:12 EST
Received: by swindle.Berkeley.EDU (5.65/XCF-1.34)
        id AA05283; Fri, 3 Feb 95 13:05:16 -0800
Date: Fri, 3 Feb 95 13:05:16 -0800
From: beorn@swindle.Berkeley.EDU (Beorn Johnson)
Message-Id: <9502032105.AA05283@swindle.Berkeley.EDU>
To: ned@kilowatt.whoi.edu
Subject: Re:  Hello again
Status: R
 
Hi Ned,
 
I saw your other post on spice3 bug fixes.  The one on the switch
looks good. 

I can't quite recall why the scale factors for the nonlinear
source didn't get propagated.  I vaguely recall that there was some
problem/conflict and the current parser was just too much of a mess
to do the job right.  I think the problem may have been when you
try to expand a subcircuit containing a nonlinear source that has
scale factors in it.  Maybe.  If it comes to me, I'll let you
know.
 
        Beorn
        (beorn@scam.berkeley.edu)

----- END 3.1 note on scale factors in arbitrary source 
------------------------
---------------------------------------------------------------

----- 4. Bug in noise analysis -----------------------------

Article: 1141 of sci.electronics.cad
From: rdm@bamboo.verinet.com (Richard McRoberts)
Newsgroups: sci.electronics.cad
Subject: Re: spice3f4 noise analysis
Date: Wed, 11 Dec 1996 21:53:57 EST
Organization: Verinet Communications
Lines: 69
Message-ID: <58ns45$24b$1@cactus.verinet.com>
References: <32AD6A23.544E@physik.th-darmstadt.de>
NNTP-Posting-Host: bamboo.verinet.com
X-Newsreader: TIN [version 1.2 PL2]

Dr. Eckehard Onkels wrote (with some deletia):

> Dear spice3f4 users,

> How can i extract spectral noise data from
> .noise -analyses ?

> I'm familar with SPICE2 which would do the intended by a
> .PLOT NOISE INOISE ONOISE
> line.

> Any hint will be helpful,

The syntax for running the analysis is (example):
    noise v(2) isrc dec 0.1meg 100meg 5
                                      ^- points per summary
                                  ^----- fstop
                          ^------------- fstart
                     ^------------------ dec, oct, lin
                 ^---------------------- source reference
           ^---------------------------- output voltage

The resulting noise spectra are vectors named onoise_spectrum
and inoise_spectrum so you can say
    (interactive)     print onoise_spectrum inoise_spectrum
    (Spice 2 style)  .PRINT NOISE onoise_spectrum inoise_spectrum

Warning:  The ac noise analysis in Spice3f4 has a serious bug.  In
interactive mode, it fails to reproduce frequency dependence known
to exist.  In batch (Spice2) mode, it works only if a corresponding
ac analysis has been run first.

This bug is fixed by providing a call to CKTload() in noisean.c as
shown by the source code patch which is attached below.

Hope this helps.

Richard D. McRoberts
Loveland, CO
rdm@csn.net
rdm@verinet.com
=============================================================================

*** NOISEAN.C.orig      Wed Mar 31 08:58:42 1993
--- NOISEAN.C   Tue Sep 17 17:15:48 1996
***************
*** 1,3 ****
--- 1,6 ----
+ /* Patch to noisean.c by Richard D. McRoberts.
+  *
+  */
  /**********
  Copyright 1990 Regents of the University of California.  All rights 
reserved.
  Author: 1987 Gary W. Ng
***************
*** 107,114 ****
--- 110,121 ----
          error = CKTop(ckt, (ckt->CKTmode & MODEUIC) | MODEDCOP | 
MODEINITJCT,
                             (ckt->CKTmode & MODEUIC) | MODEDCOP | 
MODEINITFLOAT,
                             ckt->CKTdcMaxIter);
+         if (error) return(error);

+         ckt->CKTmode = (ckt->CKTmode & MODEUIC) | MODEDCOP | MODEINITSMSIG;
+         error = CKTload(ckt);
          if(error) return(error);
+
          data = (Ndata*)MALLOC(sizeof(Ndata));
          step = 0;
          data->freq = job->NstartFreq;

----- END 4. Bug in noise analysis -----------------------------
---------------------------------------------------------------


----- 5. "save" segmentation faults -----------------------------

Article: 2048 of sci.electronics.cad
From: rdm@bamboo.verinet.com (Richard McRoberts)
Newsgroups: sci.electronics.cad
Subject: Re: Spice for Linux
Date: Mon, 10 Feb 1997 13:23:12 EST
Organization: Verinet Communications
Lines: 31
Message-ID: <5dnp2g$2o0$1@cactus.verinet.com>
References: <E57pHr.5Iu@voder.nsc.com>
NNTP-Posting-Host: bamboo.verinet.com
X-Newsreader: TIN [version 1.2 PL2]

To fix various "save"-related segmentation faults, make this 
one-line patch to outitf.c:
line 356, change
                   unique = devname;
to
                   unique = copy(devname);

If you need Spice3f5 source code (patched for Linux) for recompiling,
I saw it ftp.redhat.com in their contrib directory (as a .src.rpm package).

Hope this helps.

Duff McRoberts
Loveland, CO
rdm@verinet.com

----- END 5. "save" segmentation faults -----------------------------





-- 
Ned Forrester                                       nforrester@whoi.edu
Applied Ocean Physics and Engineering Dept. / Oceanographic Systems Lab
Woods Hole Oceanographic Institution          Woods Hole, MA 02543, USA

-- 
Andrew Tuckey
Postdoctoral Research Scientist
Eindhoven University of Technology
EE Dept., Group EMV,  Room EL 1.13
PO Box 513                        Phone: +31 - 40 2 47 3895
5600 MB EINDHOVEN                 Fax:   +31 - 40 2 43 4364
The Netherlands.                  Email: Tuckey@ieee.org


Partial thread listing: