<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
     Written by Laurent Lemaitre - r29173@users.sourceforge.net
     Documentation:
       http://sourceforge.net/docman/display_doc.php?docid=18993&group_id=84289
     Target Interface: ngspice
     Supported by adms-1.x.x
     This file is used by adms - http://sourceforge.net/projects/mot-adms.
     adms is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
     adms is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
     You should have received a copy of the GNU General Public License
     along with adms; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->

<!DOCTYPE admst SYSTEM "admst.dtd">
<admst version="2.3.0" xmlns:admst="http://mot-adms.sourceforge.net/xml-files/admst">


<admst:template match="code">
<admst:value-of select="attribute[name='ngspicename']/value"/>
<admst:variable name="module" select="%s"/>

#include &quot;ngspice/ngspice.h&quot;
#include &quot;ngspice/devdefs.h&quot;
#include &quot;$(module)defs.h&quot;
#include &quot;ngspice/suffix.h&quot;

IFparm $(module)pTable[] = {
<admst:for-each select="variable[parametertype='instance' and input='yes']">
  <admst:choose>
    <admst:when test="[type='real']">
  IOP("%(lower-case(name))",$(module)_instance_%(name),IF_REAL,"%(name)"),
    </admst:when>
    <admst:when test="[type='integer']">
  IOP("%(lower-case(name))",$(module)_instance_%(name),IF_INTEGER,"%(name)"),
    </admst:when>
    <admst:otherwise>
      <admst:fatal format="parameter of type 'string' not supported\n"/>
    </admst:otherwise>
  </admst:choose>
</admst:for-each>

<admst:for-each select="variable">
  <admst:if test="attribute[name='desc']">
    <admst:if test="[not((input='yes' and (parametertype='model' or parametertype='instance')) or (input='np' and (scope='global_model' or scope='global_instance')))]">
      <admst:choose>
        <admst:when test="[type='real']">
  OP("%(lower-case(name))",$(module)_ask_%(name),IF_REAL,"%(attribute[name='desc']/value)"),
        </admst:when>
        <admst:otherwise>
          <admst:fatal format="parameter of type 'string' not supported\n"/>
        </admst:otherwise>
      </admst:choose>
    </admst:if>
  </admst:if>
</admst:for-each>
};

<admst:text format="IFparm $(module)mPTable[] = {\n"/>
<admst:join select="variable[parametertype='model' and input='yes']" separator=",\n">
  <admst:choose>
    <admst:when test="[type='real']">
      <admst:value-of select="name"/>
      <admst:value-of select="name"/>
      <admst:value-of select="lower-case(name)"/>
      <admst:text format=" IOP(&quot;%s&quot;,$(module)_model_%s,IF_REAL,&quot;%s&quot;)"/>
    </admst:when>
    <admst:when test="[type='integer']">
      <admst:value-of select="name"/>
      <admst:value-of select="name"/>
      <admst:value-of select="lower-case(name)"/>
      <admst:text format=" IOP(&quot;%s&quot;,$(module)_model_%s,IF_INTEGER,&quot;%s&quot;)"/>
    </admst:when>
    <admst:otherwise>
      <admst:fatal format="parameter of type 'string' not supported\n"/>
    </admst:otherwise>
  </admst:choose>
</admst:join>
<admst:text format="\n};\n"/>

char *$(module)names[] = {
<admst:join select="node[location='external' and grounded='no']" separator=",\n">
  <admst:choose>
    <admst:when test="attribute[name='name']">
      <admst:for-each select="attribute[name='name']">
        <admst:value-of select="value"/>
      </admst:for-each>
    </admst:when>
    <admst:otherwise>
      <admst:value-of select="name"/>
    </admst:otherwise>
  </admst:choose>
  <admst:text format=" &quot;%s&quot;"/>
</admst:join>
};

int $(module)nSize = NUMELEMS($(module)names);
int $(module)pTSize = NUMELEMS($(module)pTable);
int $(module)mPTSize = NUMELEMS($(module)mPTable);
int $(module)iSize = sizeof($(module)instance);
int $(module)mSize = sizeof($(module)model);

</admst:template>

<admst:for-each select="/module">
  <admst:value-of select="attribute[name='ngspicename']/value"/>
  <admst:open file="%s.c">
    <admst:text format="/***\n*** Interface: %(/simulator/package_string)\n"/>
    <admst:text format=" *** created by: %(/simulator/fullname) ***/\n"/>
    <admst:apply-templates select="." match="code"/>
  </admst:open>
  <admst:value-of select="attribute[name='ngspicename']/value"/>
  <admst:message format="%s.c: file created\n"/>
</admst:for-each>

</admst>
