Translate

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/NorwegianÖversätta till Svensk/Swedishहिन्दी अनुवाद करने के लिए/Hindi
Tradueix al català/CatalanTulkot uz latviešu/LatvianPreložiť do slovenčiny/SlovakVertaal aan het Nederlands/Dutchترجمة الى العربية/ArabicTraduzca al Español/SpanishTraduisez au Français/French
Traduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplified中文翻译/Chinese TraditionalПереклад на українську/Ukrainian
Image of XSLT 2.0 and XPath 2.0 Programmer's Reference (Programmer to Programmer)
Image of Beginning Google Maps API 3
Image of Operating System Concepts
Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)

Korn Shell 93 Extended I/0

The Korn shell 93 exec command is a special overloaded built-in command that contains a number of very useful extensions relating to file descriptors and input/output which most shell programmers are unaware of. This post explains these extensions and shows examples of their use.

Half-Precision Floating Point Format

Half precision floating point is a 16-bit binary floating-point interchange format.  It was not part of the original ANSI/IEEE 754 Standard for Binary Floating-Point Arithmetic published in 1985 but is included in the current version of the standard, IEEE 754-2008 (previously known as IEEE 754r) which was published last August.  See this Wikipedia article for background information.

Floating point formats defined by this standard are classified as either interchange or non-interchange.  In the standard storage formats are narrow interchange formats, i.e. the set of floating point values that can be stored by the specified binary encoding is a proper subset of wider floating point formats such as the 32-bit float and 64-bit double.  In particular, the standard defines the encodings for one binary storage floating-point format of 16 bits length and radix 2, and one decimal storage floating-point format of 32 bits length.  Note that these two formats are for storage only and are not defined for in-memory arithmetic operations.  The remainder of this post is about the 16-bit binary storage format which we will refer to as half precision.

Half precision (also known as a 1.5.10 or s10e5 minifloat) was added to the standard because it is the de facto storage format for certain floating-point values frequently used in modern graphics processing units (GPUs) where minimizing memory usage and bus traffic is a major challange and priority.&  It is used in several computer graphics environments including OpenGL, OpenEXR, and by hardware in MP3 decoders and nVidia graphic cards.&nbsp This format became popular because it can store a larger range of values than an int16 without requiring the bandwidth and storage space of a float type.  Typically this increased range of numbers is used to preserve more highlighting and shadow detail.  The minimum and maximum representable values are 2.98×10-8 and 65504 respectively.

I only know of one C or C++ compiler which supports half precision i.e. Sourcery G++ Lite.  It uses an __fp16 type to represent half precision with a number of limitations.  However, whether __fp16 becomes part of ISO C remains to be seen.&  The lastest version of the C++ ABI also provides some support for name mangling of half precisions.  The GNU debugger appears to have some limited support.  Ruby supports half precision (IEEE_binary16) using the float-formats package (but only for little endian platforms according to the float-formats README).  The Python structs module which is the logical home for half-precision support does not currently support this format.  A cursory search of CPAN did not

XSLT Copy with Exception

A recent problem that was posed to me concerned how to copy the entire contents of an XML document with certain exceptions.  Turns out that the simplest way to handle this requirement in XSLT1.0 was to include the standard XSL identity template in my stylesheet and add another template to handle the exception.

A simple example will make things clearer.  Suppose we have the following XML document (which I shamelessly copied from W3Schools.com and modified to simplify) and we want to copy this document in its entirety except for details of CDs by a specific artist. <?xml version="1.0"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <YEAR>1988</YEAR> </CD> <CD> <TITLE>Greatest Hits</TITLE> <ARTIST>Dolly Parton</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>RCA</COMPANY> <YEAR>1982</YEAR> </CD> <CD> <TITLE>One night only</TITLE> <ARTIST>Bee Gees</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <YEAR>1998</YEAR> </CD> <CD> <TITLE>Sylvias Mother</TITLE> <ARTIST>Dr.Hook</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS</COMPANY> <YEAR>1973</YEAR> </CD> <CD> <TITLE>Maggie May</TITLE> <ARTIST>Rod Stewart</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Pickwick</COMPANY> <YEAR>1990</YEAR> </CD> </CATALOG>

Below is the stylesheet.  It accepts one parameter, i.e. the name, or part of the name, of an artist.  It copies all nodes and attributes to the output document except those nodes and attributes related to the artist whose name matches or is is a superset of the inputted string. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="artist"></xsl:param> <xsl:output method="xml"/> <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="/CATALOG/CD"> <xsl:if test="not(contains(./ARTIST,$artist))"> <xsl:copy-of select="." /> </xsl:if> </xsl:template> </xsl:stylesheet>

The first template is the standard identity template from the XSL 1.0 Transformations Recommendation.  It matches all attributes and all nodes being children of other nodes, and copies them to the output document.   The second template cancels the automatic copying of the <CD> nodes and children, checks to see that the name, or part of the name, of the artist does not match the search string, and only does a deep copy of the nodes and attributes to the output document if there is no match.

Assuming you are on a Linux system, you can use the command line utility xsltproc (which is part of the XSLT C library for GNOME) to transform the input document into the following output document when &quotStewart&quot is passed as a parameter to the stylesheet.  BTW, note the use of Java style string quotes for the parameter string. $ xsltproc -param artist "’Stewart’" file.xsl file.xml

Here is the output document. It is a copy of the input document except the "record" for the Rod

Korn Shell 93 Alarm Builtin

This post discusses the undocumented alarm builtin in Korn Shell 93.

Favicon Issues

Today I decided to add some color to my blog by adding a picture to my profile and to the title bar.   As soon as I have my profile picture in place, I decided that it would be a good idea to use this same picture to add a favicon to my blog.  Bad mistake!  Turns out that Blogger.com does not allow you to upload a favicon (AKA shortcut icon) file.  Instead you are expected to link to a shortcut icon file residing on another host.

Well, I decided that I did not want to set up another account on another host just to display a favicon so I figured that there must be some way of embedding the shortcut icon in my Blogger template.  After some experimentation I have managed to embed a shortcut icon in my template such that the shortcut icon is displayed correctly with Firefox.

Here is the code I inserted into my template just after the <title> line. <link rel=”shortcut icon” type=”image/x-icon” href=”data:image/x-icon;base64, AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAABILAAASCwAAAAEA AAABAAAHCgwACAoMAAoLDAAGDRIACA0RAAgOFAANEBIADxITABQREQAUFBIAEBUYABIXHQAYFRMA DhgjABEcLAAbHyUAFyIsABwmLgAbIjUAGSs5ACMeGAAoIx8AJiUjACEgKQAlJigAJycoACUlLwAp JikALSotACAuNgAhLjkAKikyAC4tMgAiMTsAJjQ9AC8xMQAqMTsAKzM9AC0yPAA5MSwAMjcwADAw OwA0Pj4AODM2ADo1NgA7NTcAPDc4AB42bAAbNncAISxRACY4SQAqNkUALTZCACs7WwA4OUcAOj9I ADE+XwAjO2QALTtvAC49agAiOnoAJjh8ACg1cgA7QjcAPENBADdHVQA7RlMAO05cADZSaQA/VWgA QTMxAEQ5OABARjgAREg9AFdMPQBeST0Ack03AH5MMAB8UjcAT0xKAEBOWwBBUVoAS1tTAFdISQBc UVAAQFhpAEVYaQBGXG8ASV5pAEhdbwBCXXUAUGVcAFJkXQBUZl8ARmV/AEhjdwBLZ34AT2d8AFdi ZQBdbWQAWmdwAFlrdgBea3cAXXJqAF1yawBhTUYAa1NEAGNRXwBoVlMAa1hRAHRSQABwWksAcVpL AHJZSQB1WEsAelhEAH1ZQgB4WksAfl5NAGRcZgBmXWsAb2VXAHJqXQB+YFAAYGluAGN0bgBjem8A b3J5AG5+eABufX0AcGNgAH5uZwB9bnoAfHN+AHp4eAAeM4oAIjuHACo7kwAlQoAALkqFACpBlAAv RpwALE6rADNXpwA3WKwAMlWyADNWtgA0U7oAOVaxADhetAA5W7kAOmKvADpitwA9ZL0ANEzAADdQ wAA+Y8gAQFWQAEhngABJaIAASmuDAEdikQBNc44AT3ubAE98nwBSboQAWHaLAFl4jQBTepcAU32d AF9/lgBOb6sAZF6CAGB1ggBgdoUAZnmHAEFzzQBSfOMAcoR8AFqIqAB5jYYAeY+IAHqOkAB9jJ4A fpKGAH+TjAB/mJQAZoqkAGqTrgBikrUAYpO0AGKUtgBmmLwAaZOwAGqdvwB7i6EAVYfIAFGL2ABW jt0ATpHnAFmN5wBWleQAXJ/vAGqdwQBro8oAbaPIAIBTOgCHY04Ai2BDAIhjTQCCZFAAjGdSAIpy ZwCLd20Aj356AJN4YACPjIoAhYiSAIaNlwCBkYkAgZSMAIGVjACAlo0AgZeOAIKXkACDmZEAg5mS AICZlACFmpIAhpiSAIaakwCGnJUAiZySAJKfjwCMopkAkaWcAJSonwCZqJgAiae2AJ+jpgCer6YA layzAJe1rACZsKcAtpiKAKCnrACnqacAqqakAKerswChs6kAsLCwAKrBtAC0xbQAtMa0AAAAAAAA AAAAw7V+Z2ddfvK4uuLl87Ln+X+GY1tdUj/t6rrk4ObmufDY1HyAKD8/YvrquOK0tODl1FNk+CxJ L6Hp/PO54IF6avTWZe83Ty/FxPH823nSTkzV2q3vcVOPycrJ7tdN0dPShben98+Lk7HGx6t7cm1s VITZr/p3MD2MkLCdR0YsLS1KeWb2eIeJm7CZkWtObnN0QBgQIDY8jZSQlY6s0HVxcQMTDQQOiJqW mJKKEhQWJ0ujpEQyDzE+Ojg7NQYFAwIMqbO9vSIIGBsbHCALCgYBAFq9wsuoMxcaHyklHSEeEQhD VWBeVUE0JCZCV1ZZpaanoqCgX1FYqru8vGFQYMDNzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=” />

How did I come up with this base64 image string?  First of all, I created a favicon.ico file from my profile picture using the free favicon generator at iconj.com.  Then I used another free tool Base64 Online Encoder to convert the contents of the favicon.ico file into a base64 string which I then embedded into the HTML <link> element as shown above.

Here is what it looks like when this blog is viewed using Firebox.

As you can see the favicon displays correctly on both a tabbed window and the toolbar.  However this hack does not work for any version of Internet Explorer or Safari that I know of.

Incidently, the image used to create the blog title bar came from recent photograph taken at dawn on Panglao Island, PH by Ms P. Correia.