Location: Ikeda BMadonna QKDB @ c560868b736d / daeml2bmadonna2.xsl

Author:
Ting Yu <ting.yu@auckland.ac.nz>
Date:
2014-05-05 11:11:02+12:00
Desc:
Change the unit from dimensionless to TODO.
Permanent Source URI:
https://models.physiomeproject.org/workspace/194/rawfile/c560868b736d95fd544954a4a3d5875175c194dc/daeml2bmadonna2.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns:dc="http://purl.org/dc/elements/1.1" 
  xmlns:cmeta="http://www.cellml.org/metadata/1.0#" 
  xmlns:math="http://www.w3.org/1998/Math/MathML" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xlink="http://www.w3.org/1999/xlink" 
  xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <!-- This xsl file converts (partially for now) a DAEML xml file into a Berkeley Madonna model file. -->
  <!-- 24April2008: used Alfredo's cellml2hppv2.xsl -->
  <xsl:output method="text" encoding="UTF-8" indent="no"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <xsl:text>METHOD stiff&#10;</xsl:text>
    <xsl:text>STARTTIME = 0&#10;</xsl:text>
    <xsl:text>STOPTIME = 100&#10;</xsl:text>
    <xsl:text>DT = 0.002&#10;</xsl:text>
    <xsl:text>&#10;</xsl:text>
    <xsl:text>{&#10;</xsl:text>
    <xsl:text>  *&#10;</xsl:text>
    <xsl:text>  *  Test of DAEML translation to Berkeley Madonna&#10;</xsl:text>
    <xsl:text>  *&#10;</xsl:text>
    <xsl:text>}&#10;</xsl:text>
    <xsl:text>&#10;</xsl:text>
    <xsl:text>{ *** Model description***&#10;</xsl:text>
    <xsl:value-of select="daeml/model/description"/>
    <xsl:text>&#10;}&#10;</xsl:text>

    <!--
    <xsl:call-template name="units"/>
    <xsl:call-template name="parameters"/>
    <xsl:call-template name="variables"/>
    <xsl:call-template name="odes"/>
    -->
    <xsl:apply-templates select="daeml/model/list_of_units"/>
    <xsl:apply-templates select="daeml/model/parameters"/>
    <xsl:apply-templates select="daeml/model/variables"/>
    <xsl:apply-templates select="daeml/model/system_equations/derivative_equations"/>
  
  </xsl:template> <!-- End of main template -->

  <!-- 
  Now list the various templates.
  -->
  <xsl:template match="list_of_units" name="units">
    <xsl:text>&#10;; ***Units list goes here***&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="parameters" name="parameters">
    <xsl:text>&#10;{ Parameter list (values don't change during the simulation):&#10;</xsl:text>
    <xsl:for-each select="parameter">
      <xsl:text>&#9;   </xsl:text><!-- tabulation -->
      <xsl:value-of select="@name"/>
      <xsl:text> (</xsl:text>
      <xsl:value-of select="@units"/>
      <xsl:text>), types: </xsl:text>
      <xsl:for-each select="type">
        <xsl:value-of select="."/>
      </xsl:for-each>
      <xsl:text>; </xsl:text>
      <xsl:value-of select="comment"/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
    <xsl:text>}&#10;&#10;</xsl:text>

    <xsl:text>&#10;; ***Parameter values:&#10;</xsl:text>
    <xsl:for-each select="parameter">
      <xsl:choose>
        <xsl:when test="init_value/eq_code/text()">
          <xsl:value-of select="init_value/eq_code"/>
          <xsl:text>&#10;</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="definition/eq_code"/>
          <xsl:text>&#10;</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="variables" name="variables">
  <!-- First, list the variables in a comment. -->
    <xsl:text>&#10;{ Variables (values may change during the simulation):&#10;</xsl:text>
    <xsl:for-each select="variable">
      <xsl:text>&#9;   </xsl:text><!-- tabulation -->
      <xsl:value-of select="@name"/>
      <xsl:text> (</xsl:text>
      <xsl:value-of select="@units"/>
      <xsl:text>), types: </xsl:text>
      <xsl:if test="@state_var='true'"> 
          <xsl:text>state </xsl:text>
      </xsl:if>
      <xsl:for-each select="type">
        <xsl:value-of select="."/>
        <xsl:text> </xsl:text>
      </xsl:for-each>
      <xsl:text>; </xsl:text>
      <xsl:value-of select="comment"/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
    <xsl:text>}&#10;&#10;</xsl:text>

  <!-- Next, give the variable values and definitions. -->
    <xsl:text>&#10;; ***Variable values and definitions:&#10;</xsl:text>
    <xsl:for-each select="variable">
      <xsl:choose>
        <xsl:when test="not(@state_var='true')"> 
          <xsl:choose>
            <xsl:when test="init_value/eq_code/text()">
              <xsl:value-of select="init_value/eq_code"/>
              <xsl:text>&#10;</xsl:text>
            </xsl:when>
            <xsl:when test="definition/eq_code/text()">
              <xsl:value-of select="definition/eq_code"/>
              <xsl:text>&#10;</xsl:text>
            </xsl:when>
            <xsl:when test="definition/function_call">
              <xsl:apply-templates match="definition/function_call">
				<xsl:with-param name="func_name" select="definition/function_call/@name"/>
				<xsl:with-param name="caller_index" select="position()"/>
			</xsl:apply-templates>
            </xsl:when>
          </xsl:choose>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
    <xsl:text>&#10;</xsl:text>

  <!-- Next, initialize the state variables. -->
    <xsl:text>; *** initialize state variables ***&#10;</xsl:text>
    <xsl:for-each select="variable">
        <xsl:if test="@state_var='true'"> 
          <xsl:text>INIT </xsl:text>
          <xsl:value-of select="init_value/eq_code"/> 
          <xsl:text>&#10;</xsl:text>
        </xsl:if>
    </xsl:for-each>
    <xsl:text>&#10;</xsl:text>

  <!-- Finally, set limits, if any, for the state variables. -->
    <xsl:text>; *** range conditions for the state variables ***&#10;</xsl:text>
    <xsl:for-each select="variable">
        <xsl:if test="@state_var='true'"> 
    		<xsl:for-each select="condition">
			<xsl:text>LIMIT </xsl:text>
			<xsl:value-of select="eq_code"/> 
			<xsl:text>&#10;</xsl:text>
    		</xsl:for-each>
        </xsl:if>
    </xsl:for-each>
    <xsl:text>&#10;</xsl:text>

  </xsl:template>

  <xsl:template match="derivative_equations" name="odes">
    <xsl:text>; *** ODEs ***&#10;</xsl:text>
    <xsl:for-each select="ode">
      <xsl:value-of select="eq_code"/>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
  </xsl:template>
<!--  NB: put function definitions off for later:
	<xsl:template match="definition/function_call">
		<xsl:param name="func_name"/>
		<xsl:param name="caller_index"/>
		<xsl:for-each select="map">
		     <xsl:variable name="
			<if test="/daeml/function/@functionName=$func_name">
				<if test="daeml/function/variable/@name=
	</xsl:template>
	-->
</xsl:stylesheet>