[PATCH] Fix MacDive import to convert Imperial temperature

Miika Turkia miika.turkia at gmail.com
Tue Feb 26 21:01:22 PST 2013


MacDive import needs to convert temperatures to Celcius. However, it
seems that MacDive reports no reading as 32F (and probably 0C when using
Metric). There is no way of knowing whether we have no reading or
the temperature is actually zero, so we use the given temperature
currently as 0C is a valid temperature...

Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
 xslt/MacDive.xslt |   41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/xslt/MacDive.xslt b/xslt/MacDive.xslt
index c7c4065..35a5a78 100644
--- a/xslt/MacDive.xslt
+++ b/xslt/MacDive.xslt
@@ -208,22 +208,34 @@
       <temperature>
         <xsl:if test="tempAir != ''">
           <xsl:attribute name="air">
-            <xsl:value-of select="concat(tempAir, ' C')"/>
+            <xsl:call-template name="tempConvert">
+              <xsl:with-param name="temp" select="tempAir"/>
+              <xsl:with-param name="units" select="$units"/>
+            </xsl:call-template>
           </xsl:attribute>
         </xsl:if>
         <xsl:if test="tempLow != ''">
           <xsl:attribute name="water">
-            <xsl:value-of select="concat(tempLow, ' C')"/>
+            <xsl:call-template name="tempConvert">
+              <xsl:with-param name="temp" select="tempLow"/>
+              <xsl:with-param name="units" select="$units"/>
+            </xsl:call-template>
           </xsl:attribute>
         </xsl:if>
         <xsl:if test="tempair != ''">
           <xsl:attribute name="air">
-            <xsl:value-of select="concat(tempair, ' C')"/>
+            <xsl:call-template name="tempConvert">
+              <xsl:with-param name="temp" select="tempair"/>
+              <xsl:with-param name="units" select="$units"/>
+            </xsl:call-template>
           </xsl:attribute>
         </xsl:if>
         <xsl:if test="templow != ''">
           <xsl:attribute name="water">
-            <xsl:value-of select="concat(templow, ' C')"/>
+            <xsl:call-template name="tempConvert">
+              <xsl:with-param name="temp" select="temlow"/>
+              <xsl:with-param name="units" select="$units"/>
+            </xsl:call-template>
           </xsl:attribute>
         </xsl:if>
       </temperature>
@@ -288,7 +300,10 @@
           </xsl:if>
           <xsl:if test="temperature != ''">
             <xsl:attribute name="temp">
-              <xsl:value-of select="concat(temperature, ' C')"/>
+              <xsl:call-template name="tempConvert">
+                <xsl:with-param name="temp" select="temperature"/>
+                <xsl:with-param name="units" select="$units"/>
+              </xsl:call-template>
             </xsl:attribute>
           </xsl:if>
         </sample>
@@ -378,6 +393,22 @@
   </xsl:template>
   <!-- end convert pressure -->
 
+  <!-- convert temperature to C -->
+  <xsl:template name="tempConvert">
+    <xsl:param name="temp"/>
+    <xsl:param name="units"/>
+
+    <xsl:choose>
+      <xsl:when test="$units = 'Imperial'">
+        <xsl:value-of select="concat(format-number(($temp - 32) * 5 div 9, '0.0'), ' C')"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="concat($temp, ' C')"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  <!-- end convert temperature -->
+
   <!-- convert time in seconds to minutes:seconds -->
   <xsl:template name="timeConvert">
     <xsl:param name="timeSec"/>
-- 
1.7.9.5



More information about the subsurface mailing list