From 66bd776f2de39ee0f9350c87355fab5ca6c06c42 Mon Sep 17 00:00:00 2001
From: Miika Turkia <[email protected]>
Date: Tue, 11 Nov 2014 09:40:40 +0800
Subject: [PATCH] Support timedepth mode on UDCF import

Fixes #756

Signed-off-by: Miika Turkia <[email protected]>
---
 xslt/udcf.xslt | 101 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 72 insertions(+), 29 deletions(-)

diff --git a/xslt/udcf.xslt b/xslt/udcf.xslt
index b3c93e8..62cee55 100644
--- a/xslt/udcf.xslt
+++ b/xslt/udcf.xslt
@@ -86,35 +86,78 @@
         </cylinder>
       </xsl:for-each>
 
-      <xsl:variable name="delta" select="SAMPLES/DELTA|samples/delta"/>
-
-      <!-- gas change -->
-      <xsl:for-each select="SAMPLES/SWITCH|samples/switch">
-        <event name="gaschange">
-          <xsl:variable name="timeSec" select="count(preceding-sibling::D|preceding-sibling::d) * $delta"/>
-          <xsl:attribute name="time">
-            <xsl:value-of select="concat(floor($timeSec div 60), ':',
-              format-number(floor($timeSec mod 60), '00'), ' min')"/>
-          </xsl:attribute>
-          <xsl:attribute name="value">
-            <xsl:value-of select="ancestor::DIVE/GASES/MIX[MIXNAME=current()]/O2|ancestor::dive/gases/mix[mixname=current()]/o2 * 100" />
-          </xsl:attribute>
-        </event>
-      </xsl:for-each>
-      <!-- end gas change -->
-
-      <xsl:for-each select="SAMPLES/D|samples/d">
-        <sample>
-          <xsl:variable name="timeSec" select="(position() - 1) * $delta"/>
-          <xsl:attribute name="time">
-            <xsl:value-of select="concat(floor($timeSec div 60), ':',
-              format-number(floor($timeSec mod 60), '00'), ' min')"/>
-          </xsl:attribute>
-          <xsl:attribute name="depth">
-            <xsl:value-of select="concat(., ' m')"/>
-          </xsl:attribute>
-        </sample>
-      </xsl:for-each>
+      <xsl:choose>
+
+	<!-- samples recorded at irregular internal, but storing time stamp -->
+	<xsl:when test="timedepthmode">
+	  <!-- gas change -->
+	  <xsl:for-each select="SAMPLES/SWITCH|samples/switch">
+	    <event name="gaschange">
+	      <xsl:variable name="timeSec" select="following-sibling::T|following-sibling::t"/>
+	      <xsl:attribute name="time">
+		<xsl:value-of select="concat(floor($timeSec div 60), ':',
+		  format-number(floor($timeSec mod 60), '00'), ' min')"/>
+	      </xsl:attribute>
+	      <xsl:attribute name="value">
+		<xsl:value-of select="ancestor::DIVE/GASES/MIX[MIXNAME=current()]/O2|ancestor::dive/gases/mix[mixname=current()]/o2 * 100" />
+	      </xsl:attribute>
+	    </event>
+	  </xsl:for-each>
+	  <!-- end gas change -->
+
+	  <!-- samples -->
+	  <xsl:for-each select="SAMPLES/D|samples/d">
+	    <sample>
+	      <xsl:variable name="timeSec" select="preceding-sibling::T[position()=1]|preceding-sibling::t[position()=1]"/>
+	      <xsl:attribute name="time">
+		<xsl:value-of select="concat(floor($timeSec div 60), ':',
+		  format-number(floor($timeSec mod 60), '00'), ' min')"/>
+	      </xsl:attribute>
+	      <xsl:attribute name="depth">
+		<xsl:value-of select="concat(., ' m')"/>
+	      </xsl:attribute>
+	    </sample>
+	  </xsl:for-each>
+	  <!-- end samples -->
+	</xsl:when>
+
+	<!-- sample recorded at even internals -->
+	<xsl:otherwise>
+	  <xsl:variable name="delta" select="SAMPLES/DELTA|samples/delta"/>
+
+	  <!-- gas change -->
+	  <xsl:for-each select="SAMPLES/SWITCH|samples/switch">
+	    <event name="gaschange">
+	      <xsl:variable name="timeSec" select="count(preceding-sibling::D|preceding-sibling::d) * $delta"/>
+	      <xsl:attribute name="time">
+		<xsl:value-of select="concat(floor($timeSec div 60), ':',
+		  format-number(floor($timeSec mod 60), '00'), ' min')"/>
+	      </xsl:attribute>
+	      <xsl:attribute name="value">
+		<xsl:value-of select="ancestor::DIVE/GASES/MIX[MIXNAME=current()]/O2|ancestor::dive/gases/mix[mixname=current()]/o2 * 100" />
+	      </xsl:attribute>
+	    </event>
+
+	  </xsl:for-each>
+	  <!-- end gas change -->
+
+	  <!-- samples -->
+	  <xsl:for-each select="SAMPLES/D|samples/d">
+	    <sample>
+	      <xsl:variable name="timeSec" select="(position() - 1) * $delta"/>
+	      <xsl:attribute name="time">
+		<xsl:value-of select="concat(floor($timeSec div 60), ':',
+		  format-number(floor($timeSec mod 60), '00'), ' min')"/>
+	      </xsl:attribute>
+	      <xsl:attribute name="depth">
+		<xsl:value-of select="concat(., ' m')"/>
+	      </xsl:attribute>
+	    </sample>
+	  </xsl:for-each>
+	  <!-- end samples -->
+
+	</xsl:otherwise>
+      </xsl:choose>
     </dive>
   </xsl:template>
 </xsl:stylesheet>
-- 
2.1.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to