<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Homepage of Michael Goerz</title>
 <link href="http://michaelgoerz.net/atom.xml" rel="self"/>
 <link href="http://michaelgoerz.net/"/>
 <updated>2012-04-07T13:01:32+02:00</updated>
 <id>http://michaelgoerz.net</id>
 <author>
   <name>Michael Goerz</name>
   <email>goerz@physik.fu-berlin.de</email>
 </author>

 
 <entry>
   <title>Floating Points Numbers, Down to the Bit</title>
   <link href="blog/2011/05/floating-point-numbers-down-to-the-bit/"/>
   <updated>2011-05-28T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2011/05/floating-point-numbers-down-to-the-bit</id>
   <content type="html">&lt;h3 id='floating_point_memory_format'&gt;Floating Point Memory Format&lt;/h3&gt;

&lt;p&gt;The general idea behind floating point numbers is the same as behind scientific notation: write a mantissa, combined with an exponent to move the decimal point. E.g. $1.093 \times 10^5 = 10^5 \sum_{k=0}^3 a_k 10^{-k}$ with $a_k = 1,0,9,3$. The exact same thing can be done in binary:&lt;/p&gt;

&lt;p&gt;$$ v = 2^e \sum_{k=0}^{n-1} a_k 2^{-k} $$&lt;/p&gt;

&lt;p&gt;In memory, floats can be stored by reserving a section of the total available bits to store the exponent, while the mantissa is stored in the remaining bits. For a double precision float, the total size is 64 bit. One bit is used to encode the sign of the number, 11 bits for the exponent, and the remaining 52 bits for the mantissa. In order to only have to store positive integers as exponents, as fixed bias exponent of 1023 is subtracted from the stored exponent. Also, the digit $a_0$ is assumed to be 1, and is not stored explicitly in the mantissa; the effective number of mantissa digits is therefore 53. For details, see the Wikipedia article for the &lt;a href='http://en.wikipedia.org/wiki/Double_precision_floating-point_format'&gt;Double precision floating-point format&lt;/a&gt;. The &lt;a href='http://en.wikipedia.org/wiki/Single_precision_floating-point_format'&gt;Single precision floating-point format&lt;/a&gt; is very similar, but only uses 32 total bits.&lt;/p&gt;

&lt;h3 id='parsing_double_precision_floats_in_python'&gt;Parsing Double Precision Floats in Python&lt;/h3&gt;

&lt;p&gt;It is relatively easy to parse a binary representation of a double precision float. I&amp;#8217;ve written a python script to do so (both for double and single precision), available on &lt;a href='https://github.com/goerz/float_parsers'&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Given a representation (as a hex string) or a float value (as a string like &amp;#8220;1.2&amp;#8221; or &amp;#8220;-2.3456e-192&amp;#8221;) the scripts decompose the binary representation into sign, exponent, and mantissa, and print out this information along with the exact decimal the binary representation corresponds to according to the floating point model.&lt;/p&gt;

&lt;p&gt;A similar online tool for double precision floats is available at &lt;a href='http://www.binaryconvert.com/convert_double.html'&gt;binaryconvert.com&lt;/a&gt; (also &lt;a href='http://www.binaryconvert.com/convert_float.html'&gt;single precision&lt;/a&gt; and &lt;a href='http://www.binaryconvert.com/index.html'&gt;others&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The key routine:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='python'&gt;    &lt;span class='n'&gt;BIAS&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;1023&lt;/span&gt;                &lt;span class='c'&gt;# constant to be subtracted from the stored exponent&lt;/span&gt;
    &lt;span class='n'&gt;SIGN_BIT&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;63&lt;/span&gt;              &lt;span class='c'&gt;# bit index at which the sign is stored&lt;/span&gt;
    &lt;span class='n'&gt;EXP_BIT&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;52&lt;/span&gt;               &lt;span class='c'&gt;# bit index at which the exponent starts&lt;/span&gt;
    &lt;span class='n'&gt;EXP_MASK&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mh'&gt;0x000fffffffffffff&lt;/span&gt;  &lt;span class='c'&gt;# bit-mask to remove exponent, leaving mantissa&lt;/span&gt;
    &lt;span class='n'&gt;NAN_EXP&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mh'&gt;0x7ff&lt;/span&gt;            &lt;span class='c'&gt;# special exponent which encodes NaN/Infinity&lt;/span&gt;
    
    &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;parse_hex&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;hexstring&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;float_format&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;&lt;/span&gt;&lt;span class='si'&gt;%.15e&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;no_decimal&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='bp'&gt;False&lt;/span&gt;&lt;span class='p'&gt;):&lt;/span&gt;
        &lt;span class='sd'&gt;&amp;quot;&amp;quot;&amp;quot; Take a 8-byte hex string (16 digits) representing a double precision,&lt;/span&gt;
&lt;span class='sd'&gt;            parse it, and print detailed information about the represented float&lt;/span&gt;
&lt;span class='sd'&gt;            value.&lt;/span&gt;
&lt;span class='sd'&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class='n'&gt;bits&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;int&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;0x&lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;hexstring&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;16&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='n'&gt;sign&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;+1&amp;#39;&lt;/span&gt;
        &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;test_bit&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;bits&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;SIGN_BIT&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;&amp;gt;&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
            &lt;span class='n'&gt;sign&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;-1&amp;#39;&lt;/span&gt;
        &lt;span class='n'&gt;bits&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;clear_bit&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;bits&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;SIGN_BIT&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='n'&gt;stored_exp&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;bits&lt;/span&gt; &lt;span class='o'&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;EXP_BIT&lt;/span&gt;
        &lt;span class='n'&gt;mantissa&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;bits&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&lt;/span&gt; &lt;span class='n'&gt;EXP_MASK&lt;/span&gt; &lt;span class='c'&gt;# mask the exponent bits&lt;/span&gt;
    
        &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Bytes         = 0x&lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;hexstring&lt;/span&gt;
        &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Float         = &amp;quot;&lt;/span&gt;&lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='n'&gt;float_format&lt;/span&gt; \
                               &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;struct&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;unpack&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;!d&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;hexstring&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;decode&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;hex&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;))[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt;
        &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Sign          = &lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;sign&lt;/span&gt;
        &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;stored_exp&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
            &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exponent      = 0x&lt;/span&gt;&lt;span class='si'&gt;%x&lt;/span&gt;&lt;span class='s'&gt; (Special: Zero/Subnormal)&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;stored_exp&lt;/span&gt;
            &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Mantissa      = 0x&lt;/span&gt;&lt;span class='si'&gt;%x&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;mantissa&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='ow'&gt;not&lt;/span&gt; &lt;span class='n'&gt;no_decimal&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
                &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;mantissa&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
                    &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exact Decimal = &lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt;0&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;sign&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt;
                &lt;span class='k'&gt;else&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
                    &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exact Decimal = &lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt; (subnormal)&amp;quot;&lt;/span&gt; \
                        &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;float2decimal&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;hex2float&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;hexstring&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;
        &lt;span class='k'&gt;elif&lt;/span&gt; &lt;span class='n'&gt;stored_exp&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='n'&gt;NAN_EXP&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
            &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exponent      = 0x&lt;/span&gt;&lt;span class='si'&gt;%x&lt;/span&gt;&lt;span class='s'&gt; (Special: NaN/Infinity)&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;stored_exp&lt;/span&gt;
            &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Mantissa      = 0x&lt;/span&gt;&lt;span class='si'&gt;%x&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;mantissa&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='ow'&gt;not&lt;/span&gt; &lt;span class='n'&gt;no_decimal&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
                &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;mantissa&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
                    &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exact Decimal = &lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt;Infinity&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;sign&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt;
                &lt;span class='k'&gt;else&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
                    &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exact Decimal = NaN&amp;quot;&lt;/span&gt;
        &lt;span class='k'&gt;else&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
            &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exponent      = 0x&lt;/span&gt;&lt;span class='si'&gt;%x&lt;/span&gt;&lt;span class='s'&gt; = &lt;/span&gt;&lt;span class='si'&gt;%i&lt;/span&gt;&lt;span class='s'&gt; (bias &lt;/span&gt;&lt;span class='si'&gt;%i&lt;/span&gt;&lt;span class='s'&gt;)&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;stored_exp&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
                                                           &lt;span class='n'&gt;stored_exp&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;BIAS&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
            &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Mantissa      = 0x&lt;/span&gt;&lt;span class='si'&gt;%x&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;mantissa&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='ow'&gt;not&lt;/span&gt; &lt;span class='n'&gt;no_decimal&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;
                &lt;span class='n'&gt;mantissa&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;set_bit&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;mantissa&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;EXP_BIT&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='c'&gt;# set the implicit bit&lt;/span&gt;
                &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Exact Decimal = &lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt; 2^(&lt;/span&gt;&lt;span class='si'&gt;%i&lt;/span&gt;&lt;span class='s'&gt;) * [0x&lt;/span&gt;&lt;span class='si'&gt;%x&lt;/span&gt;&lt;span class='s'&gt; * 2^(-52)]&amp;quot;&lt;/span&gt; \
                                    &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;sign&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='n'&gt;stored_exp&lt;/span&gt;&lt;span class='o'&gt;-&lt;/span&gt;&lt;span class='n'&gt;BIAS&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;mantissa&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
                &lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;              = &lt;/span&gt;&lt;span class='si'&gt;%s&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='n'&gt;float2decimal&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;hex2float&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;hexstring&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The procedure is quite straightforward:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract the sign from the left-most bit, and set it to 0&lt;/li&gt;

&lt;li&gt;Extract the stored exponent by shifting out the mantissa; to get the actual exponent the bias exponent (1023) has to be subtracted&lt;/li&gt;

&lt;li&gt;Extract the mantissa by setting all bits of the exponential to 0 with a suitable bitmask&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any float can be represented as an exact decimal, without loss of information. The calculating of the exact decimal is not completely trivial to implement. The basic idea is to double the mantissa until it is a (possibly very large) integer. A routine &lt;code&gt;float2decimal&lt;/code&gt; that does this is available in the &lt;a href='http://docs.python.org/release/2.5.2/lib/decimal-faq.html'&gt;FAQ for the Decimal module&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='connection_to_the_fortran_numerical_model'&gt;Connection to the Fortran Numerical Model&lt;/h3&gt;

&lt;p&gt;In Fortran, the numerical model is described as follows (see the &lt;a href='http://portal.acm.org/citation.cfm?id=151166'&gt;Fortran Handbook&lt;/a&gt; section 13.2.3):&lt;/p&gt;

&lt;p&gt;$$ x = s b^e \sum_{k=1}^p f_k b^{-k} $$&lt;/p&gt;

&lt;p&gt;Note that in good Fortran fashion, the index $k$ counts from 1 as opposed to 0. This means that the exponential $e$ is shifted by one compared to the more traditional formula used in the &amp;#8220;Floating Point Memory Format&amp;#8221; section above.&lt;/p&gt;

&lt;p&gt;The specific parameters for single and double precision for a given compiler/system can be found using the very useful &lt;a href='http://portal.acm.org/citation.cfm?id=151166'&gt;kindfinder utility&lt;/a&gt;. On my system, I get the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; FLOATINGPOINT MODEL (Real/Complex):
  Name:                     Single              Double              Extnd1
  KIND:                          4                   8                  16
  DIGITS:                       24                  53                 113
  RADIX:                         2                   2                   2
  MINEXPONENT:                -125               -1021              -16381
  MAXEXPONENT:                 128                1024               16384
  PRECISION:                     6                  15                  33
  RANGE:                        37                 307                4931
  EPSILON:               1.192E-07           2.220E-16           1.926E-34
  HUGE:                  3.403E+38           1.798+308          1.190+4932
  TINY:                  1.175E-38           2.225-308          3.362-4932&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Looking at double precision floats, the &lt;code&gt;DIGITS&lt;/code&gt; corresponds to the total number of mantissa digits, $p$ in the model. Note that &lt;code&gt;DIGITS&lt;/code&gt; is 53, whereas only 52 bits are used to store the mantissa in memory format: the 53rd bit for $2^0$ is implicit, as discussed earlier.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TINY&lt;/code&gt; and &lt;code&gt;HUGE&lt;/code&gt; are the smallest and largest representable numbers, respectively. The &lt;code&gt;parse_dp_float.py&lt;/code&gt; script gives the following information:&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;TINY&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Bytes         = 0x0010000000000000
Float         = 2.225073858507201e-308
Sign          = +1
Exponent      = 0x1 = 1 (bias 1023)
Mantissa      = 0x0
Exact Decimal = + 2^(-1022) * [0x10000000000000 * 2^(-52)]
              = 2.225073858507201383090232717332404064219215980462331830553327
416887204434813918195854283159012511020564067339731035811005152434161553460108
856012385377718821130777993532002330479610147442583636071921565046942503734208
375250806650616658158948720491179968591639648500635908770118304874799780887753
749949451580451605050915399856582470818645113537935804992115981085766051992433
352114352390148795699609591288891602992641511063466313393663477586513029371762
047325631781485664350872122828637642044846811407613911477062801689853244110024
161447421618567166150540154285084716752901903161322778896729707373123334086988
983175067838846926092773977972858659654941091369095406136467568702398678315290
680984617210924625396728515625E-308&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For &lt;code&gt;HUGE&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Bytes         = 0x7fefffffffffffff
Float         = 1.797693134862316e+308
Sign          = +1
Exponent      = 0x7fe = 2046 (bias 1023)
Mantissa      = 0xfffffffffffff
Exact Decimal = + 2^(1023) * [0x1fffffffffffff * 2^(-52)]
              = 17976931348623157081452742373170435679807056752584499659891747
680315726078002853876058955863276687817154045895351438246423432132688946418276
846754670353751698604991057655128207624549009038932894407586850845513394230458
323690322294816580855933212334827479782620414472316873817718091929988125040402
6184124858368&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note the &lt;code&gt;MINEXPONENT = EXPONENT(TINY)&lt;/code&gt; and &lt;code&gt;MAXEXPONENT = EXPONENT(HUGE)&lt;/code&gt;, where &lt;code&gt;EXPONENT&lt;/code&gt; is the Fortran function that returns the exponent in the Fortran numerical model. These values are shifted by one compared to the stored exponent in the binary representation, due to the sum in the numerical model starting at one, as discussed above.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;PRECISION&lt;/code&gt; is the number of significant digits (the digits after the decimal point) that are guaranteed to be represented accurately; That is, when you assign a number to a double precision float, the number actually stored will always match the assigned number within at least 15 significant digits.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;RANGE&lt;/code&gt; is defined as &lt;code&gt;INT(MIN( LOG10(HUGE), -LOG10(TINY) ))&lt;/code&gt;, in this case &lt;code&gt;RANGE = INT(-LOG10(2.225e-308)) = INT(- (308 + 0.347)) = INT(307.653) = 307&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, &lt;code&gt;EPSILON&lt;/code&gt; is the difference between one and the next closest representable number, given as $2^{-52}$. This is the smallest difference for any two neighboring numbers greater than one. &lt;code&gt;0.5*EPSILON&lt;/code&gt; provides an upper bound for the relative error due to rounding.&lt;/p&gt;

&lt;p&gt;Some final observations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Two distinct double precision numbers can look the same when printed to 15 significant digits. The best example for this is &lt;code&gt;one + EPSILON(one)&lt;/code&gt;. However, they will always differ in the 16th significant digit in that case.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;When printing a float to an arbitrary precision (greater the machine precision), there are never any random digits printed. The exact decimal encoded by the float determines the result. However, the digits beyond the machine precision resulting from a &lt;em&gt;computation&lt;/em&gt; involving two floats may depend and the compiler and the environment so that in general, results obtained on different systems cannot be expected to match beyond the machine precision.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;To test whether two floats &lt;code&gt;r1&lt;/code&gt; and &lt;code&gt;r2&lt;/code&gt; are the same within some relative error &lt;code&gt;delta_r&lt;/code&gt;, the following expression can be used:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; approx_eq = (ABS(r1 - r2) &amp;lt;= 0.5d0*ABS(r1+r2) * delta_r)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It makes no sense to use a &lt;code&gt;delta_r &amp;lt; 1.0d-16&lt;/code&gt;; the test would be equivalent to a direct comparison on the bit-level.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;To write out the hex representation of a double precision float &lt;code&gt;r&lt;/code&gt; in Fortran, use &lt;code&gt;write(*,&amp;#39;(Z16)&amp;#39;) transfer(r, 1_8)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Read &lt;a href='http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html'&gt;What Every Computer Scientist Should Know about Floating Numbers&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Advanced Array-Passing in Fortran</title>
   <link href="blog/2011/05/advanced-array-passing-in-fortran/"/>
   <updated>2011-05-19T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2011/05/advanced-array-passing-in-fortran</id>
   <content type="html">&lt;p&gt;There are instances where one wishes to change the rank (the number of dimensions) of an array as it is passed to a subroutine. Maybe you want to call a library routine that expects to get a vector, but you have the data to be passed stored in a matrix. There should be no problem in principle, as the data for an array &amp;#8211; no matter its rank &amp;#8211; is stored sequentially in memory (array element order of subscripts along the first dimension varying more quickly). Thus, it should be possible to simply re-interpret the data to a different shape. In practice, one can change the rank of the array by declaring the dummy array with an explicit shape specification. As soon as the dummy array has an explicit shape, one can pass anything that contains enough elements to fill the dummy array, no matter what the rank or shape. The feature is known as array element sequence association and is illustrated in the following example:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='fortran'&gt;    &lt;span class='k'&gt;program &lt;/span&gt;&lt;span class='nv'&gt;test&lt;/span&gt;
      &lt;span class='k'&gt;implicit none&lt;/span&gt;
&lt;span class='k'&gt;      &lt;/span&gt;&lt;span class='kt'&gt;integer&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;test_array1&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='kt'&gt;integer&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;test_array2&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='nv'&gt;test_array1&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;/&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;3&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;4&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;5&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;6&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;7&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;8&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;9&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='o'&gt;/&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='nv'&gt;test_array2&lt;/span&gt;&lt;span class='p'&gt;(:,&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;/&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;   &lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='mi'&gt;3&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='mi'&gt;4&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='mi'&gt;5&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='mi'&gt;6&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='mi'&gt;7&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='mi'&gt;8&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;  &lt;span class='mi'&gt;9&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='o'&gt;/&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='nv'&gt;test_array2&lt;/span&gt;&lt;span class='p'&gt;(:,&lt;/span&gt;&lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;/&lt;/span&gt;&lt;span class='mi'&gt;11&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;12&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;13&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;14&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;15&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;16&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;17&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;18&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;19&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;20&lt;/span&gt;&lt;span class='o'&gt;/&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;print_a(test_array1, 10)&amp;quot;&lt;/span&gt;
      &lt;span class='k'&gt;call &lt;/span&gt;&lt;span class='nv'&gt;print_a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;test_array1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;print_a(test_array2, 10)&amp;quot;&lt;/span&gt;
      &lt;span class='k'&gt;call &lt;/span&gt;&lt;span class='nv'&gt;print_a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;test_array2&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;print_a(test_array2, 20)&amp;quot;&lt;/span&gt;
      &lt;span class='k'&gt;call &lt;/span&gt;&lt;span class='nv'&gt;print_a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;test_array2&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;20&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;print_a(test_array2(:,2), 10)&amp;quot;&lt;/span&gt;
      &lt;span class='k'&gt;call &lt;/span&gt;&lt;span class='nv'&gt;print_a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;test_array2&lt;/span&gt;&lt;span class='p'&gt;(:,&lt;/span&gt;&lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;print_m(test_array1, 2,5)&amp;quot;&lt;/span&gt;
      &lt;span class='k'&gt;call &lt;/span&gt;&lt;span class='nv'&gt;print_m&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;test_array1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;5&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    
    &lt;span class='k'&gt;contains&lt;/span&gt;
&lt;span class='k'&gt;    &lt;/span&gt;
&lt;span class='k'&gt;      subroutine &lt;/span&gt;&lt;span class='nv'&gt;print_a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;n&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;i&lt;/span&gt;
        &lt;span class='k'&gt;do &lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
          &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='k'&gt;end do&lt;/span&gt;
&lt;span class='k'&gt;      end subroutine&lt;/span&gt;
&lt;span class='k'&gt;    &lt;/span&gt;
&lt;span class='k'&gt;      subroutine &lt;/span&gt;&lt;span class='nv'&gt;print_m&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;m&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;m&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;n&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='nv'&gt;m&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;i&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;j&lt;/span&gt;
        &lt;span class='k'&gt;do &lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
          &lt;span class='k'&gt;do &lt;/span&gt;&lt;span class='nv'&gt;j&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;m&lt;/span&gt;
            &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='nv'&gt;j&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
          &lt;span class='k'&gt;end do&lt;/span&gt;
&lt;span class='k'&gt;        end do&lt;/span&gt;
&lt;span class='k'&gt;      end subroutine&lt;/span&gt;
&lt;span class='k'&gt;    &lt;/span&gt;
&lt;span class='k'&gt;    end program &lt;/span&gt;&lt;span class='nv'&gt;test&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There are two alternatives to do basically the same thing, one standard, one not. The first one is known as assumed-size, and looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='fortran'&gt;      &lt;span class='k'&gt;subroutine &lt;/span&gt;&lt;span class='nv'&gt;print_a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;i&lt;/span&gt;
        &lt;span class='k'&gt;do &lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
          &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='k'&gt;end do&lt;/span&gt;
&lt;span class='k'&gt;      end subroutine&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here, &lt;code&gt;a&lt;/code&gt; has rank one, and a size large enough to fit whatever is passed to the routine. However, the routine does not actually know the size of &lt;code&gt;a&lt;/code&gt; (&lt;code&gt;size(a)&lt;/code&gt; is illegal in this context). There certainly is nothing that ensures that the size of &lt;code&gt;a&lt;/code&gt; is n, and the compiler has no way of perfoming any checks on the use of &lt;code&gt;a&lt;/code&gt;. In that sense, assumed-size is not very useful compared to explicit-shape, except maybe in some rare instances where the array size can somehow be deduced from the data stored in the array, so that the array size &lt;code&gt;n&lt;/code&gt; does not have to be passed along.&lt;/p&gt;

&lt;p&gt;The second alternative is a non-standard trick that behaves identically to assumed-size, but was used before the assumed-size feature was introduced to Fortran. It looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='fortran'&gt;      &lt;span class='k'&gt;subroutine &lt;/span&gt;&lt;span class='nv'&gt;print_a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='k'&gt;intent&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;in&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
        &lt;span class='kt'&gt;integer&lt;/span&gt; &lt;span class='kd'&gt;::&lt;/span&gt; &lt;span class='nv'&gt;i&lt;/span&gt;
        &lt;span class='k'&gt;do &lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nv'&gt;n&lt;/span&gt;
          &lt;span class='k'&gt;write&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='nv'&gt;a&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nv'&gt;i&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='k'&gt;end do&lt;/span&gt;
&lt;span class='k'&gt;      end subroutine&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In principle, this is also an example of array element sequence association. In the subroutine, &lt;code&gt;a&lt;/code&gt; is called with subscripts outside of the bounds of its declared size 1, which is more or less guaranteed to work since the array is passed by reference. Again, the compiler has not idea about the actual size of &lt;code&gt;a&lt;/code&gt;. Most compilers will recognize this trick and not complain about going out of bounds, even with bound-checking enabled, understanding &lt;code&gt;a(1)&lt;/code&gt; to be identical to &lt;code&gt;a(*)&lt;/code&gt;, with the only difference being that &lt;code&gt;size(a)&lt;/code&gt; is legal, but of course returns 1, i.e. not the size of the actual passed array. Declaring &lt;code&gt;a&lt;/code&gt; as &lt;code&gt;a(2)&lt;/code&gt; will not work, however.&lt;/p&gt;

&lt;p&gt;Any of these definitions should only be used if the rank of the array needs to be changed. For just passing arrays of identical rank, but unknown shape, one should always use the assumed-shape syntax (e.g. &lt;code&gt;a(:,:)&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;A few pointers about where to find the discussed concepts in the Fortran 90 Handbook: array element order is discussed in section 6.4.7, the definition of array element sequence association appears in section 12.5.2.1, and explicit-shape, assumed-shape, deferred-shape, and assumed-size specification are explained in section 5.3.1.&lt;/p&gt;

&lt;p&gt;Thanks to the people on &lt;code&gt;comp.lang.fortran&lt;/code&gt; for illuminating some of these concepts to me.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>PDF Bookmarks with LaTeX</title>
   <link href="blog/2011/04/pdf-bookmarks-with-latex/"/>
   <updated>2011-04-29T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2011/04/pdf-bookmarks-with-latex</id>
   <content type="html">&lt;p&gt;The combination of &lt;a href='http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages/'&gt;pdfpages&lt;/a&gt;, &lt;a href='http://www.ctan.org/tex-archive/macros/latex/contrib/hyperref/'&gt;hyperref&lt;/a&gt;, and &lt;a href='http://www.ctan.org/pkg/bookmark'&gt;bookmark&lt;/a&gt; allows for a very neat way of adding an outline to an existing pdf file. For example, we can use the following tex file to add a (partial) outline to my &lt;a href='http://michaelgoerz.net/research/diploma_thesis.pdf)'&gt;diploma thesis&lt;/a&gt;.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='tex'&gt;    &lt;span class='k'&gt;\documentclass&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;article&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\usepackage&lt;/span&gt;&lt;span class='na'&gt;[utf8]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;inputenc&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\usepackage&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;pdfpages&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\usepackage&lt;/span&gt;[
      pdfpagelabels=true,
      pdftitle=&lt;span class='nb'&gt;{&lt;/span&gt;Optimization of a Controlled Phasegate for Ultracold Calcium Atoms in an Optical Lattice&lt;span class='nb'&gt;}&lt;/span&gt;,
      pdfauthor=&lt;span class='nb'&gt;{&lt;/span&gt;Michael Goerz&lt;span class='nb'&gt;}&lt;/span&gt;,
    ]&lt;span class='nb'&gt;{&lt;/span&gt;hyperref&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\usepackage&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;bookmark&lt;span class='nb'&gt;}&lt;/span&gt;

    &lt;span class='k'&gt;\begin&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;document&lt;span class='nb'&gt;}&lt;/span&gt;

    &lt;span class='k'&gt;\pagenumbering&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;arabic&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\setcounter&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;page&lt;span class='nb'&gt;}{&lt;/span&gt;1&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\includepdf&lt;/span&gt;&lt;span class='na'&gt;[pages=1-2]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;diploma&lt;span class='nb'&gt;_&lt;/span&gt;thesis.pdf&lt;span class='nb'&gt;}&lt;/span&gt;

    &lt;span class='k'&gt;\pagenumbering&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;roman&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\setcounter&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;page&lt;span class='nb'&gt;}{&lt;/span&gt;1&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\includepdf&lt;/span&gt;&lt;span class='na'&gt;[pages=3-8]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;diploma&lt;span class='nb'&gt;_&lt;/span&gt;thesis.pdf&lt;span class='nb'&gt;}&lt;/span&gt;

    &lt;span class='k'&gt;\pagenumbering&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;arabic&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\setcounter&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;page&lt;span class='nb'&gt;}{&lt;/span&gt;1&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\includepdf&lt;/span&gt;&lt;span class='na'&gt;[pages=9-]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;diploma&lt;span class='nb'&gt;_&lt;/span&gt;thesis.pdf&lt;span class='nb'&gt;}&lt;/span&gt;

    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=1,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;Title Page&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=9,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;1 Introduction&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=17,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2 Quantum Computation with Calcium Atoms&lt;span class='nb'&gt;}&lt;/span&gt;
        &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=18,level=1]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.1 Trapping of Calcium Atoms&lt;span class='nb'&gt;}&lt;/span&gt;
        &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=20,level=1]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.2 Internal Degrees of Freedom and Description of a Single Qubit&lt;span class='nb'&gt;}&lt;/span&gt;
        &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=21,level=1]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.3 Description of Two Qubits&lt;span class='nb'&gt;}&lt;/span&gt;
            &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=22,level=2]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.3.1 Qubit-Qubit Interaction&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=23,level=2]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.3.2 Harmonic Approximation of the Trap Potential&lt;span class='nb'&gt;}&lt;/span&gt;
            &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=24,level=2]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.3.3 Summary of Two-Qubit Description&lt;span class='nb'&gt;}&lt;/span&gt;
        &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=26,level=1]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.4 Asymptotic Description of Two Qubits&lt;span class='nb'&gt;}&lt;/span&gt;
        &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=27,level=1]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;2.5 Quantum Information Processing with Calcium&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=31,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;3 Numerical Tools&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=47,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;4 Phasegate Optimization Schemes&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=65,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;5 Optimization Results for the Controlled Phasegate&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=87,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;6 Summary and Outlook&lt;span class='nb'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;\bookmark&lt;/span&gt;&lt;span class='na'&gt;[page=93,level=0]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;Appendices&lt;span class='nb'&gt;}&lt;/span&gt;

    &lt;span class='k'&gt;\end&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;document&lt;span class='nb'&gt;}&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Assuming that the above is stored as &lt;code&gt;thesis_with_bm.tex&lt;/code&gt;, simply running &lt;code&gt;pdflatex thesis_with_bm.tex&lt;/code&gt; will create a copy &lt;code&gt;thesis_with_bm.pdf&lt;/code&gt; of &lt;code&gt;diploma_thesis.pdf&lt;/code&gt; that contains the defined outline. Also, the title and author in the pdf meta data are set, and the pages are labeled correctly. A great way to post-process scanned documents!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Creating Combined tikz/png Plots</title>
   <link href="blog/2010/01/creating-combined-tikzpng-plots/"/>
   <updated>2010-01-24T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2010/01/creating-combined-tikzpng-plots</id>
   <content type="html">&lt;p&gt;In order to create truly high quality plots, you can have gnuplot write tikz files. Wheres the latest CVS development version of gnuplot have the tikz terminal included, I&amp;#8217;m still using the &lt;a href='http://peter.affenbande.org/gnuplot/'&gt;patch by Peter Hedwig for gnuplot 4.2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Generating tikz code from gnuplot works very nicely for &amp;#8220;standard&amp;#8221; plots, but can be problematic for others. If the plot contains a lot of points, the resulting tikz file can be hundreds of megabyte in side, and the resulting pdf will constipate your pdf reader, if you get it to compile at all. In fact, you run into the same problem if you use the pdf or postscript terminal in gnuplot directly.&lt;/p&gt;

&lt;p&gt;Another type of plot where this tends to happen is &lt;a href='http://t16web.lanl.gov/Kawano/gnuplot/plotpm3d-e.html'&gt;3D color maps&lt;/a&gt;. The result in tikz is thousands of small colored squares, each of to be rendered as vector graphics.&lt;/p&gt;

&lt;p&gt;Is there any way to make these plots manageable, while keeping the high quality of tikz output in place? A possible solution is to combine a bitmapped plot with vector-graphics decorations (axes, legend, etc.). To do this, we let gnuplot generate the same plot twice: once with the tikz terminal, and once with the png terminal, but without any axes, labels, etc. We then modify the tikz output and delete all the parts for the actual plot, and insert the png image in their place. This means we have the png image, and everything else drawn on top of it with tikz.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s look at this in practice.&lt;/p&gt;

&lt;p&gt;Suppose I have a &lt;a href='wig.bz2'&gt;huge data file&lt;/a&gt; of a &lt;a href='http://en.wikipedia.org/wiki/Wigner_quasi-probability_distribution'&gt;Wigner plot&lt;/a&gt; that I want to visualize as a color map. I use the following gnuplot file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;set term lua plotsize 8cm,6cm font &amp;quot; \\tiny &amp;quot;
set out &amp;quot;wigner.tikz&amp;quot;

set pm3d map
set palette defined (-0.0015 &amp;quot;blue&amp;quot;, 0 &amp;quot;white&amp;quot;, 0.0015 &amp;quot;red&amp;quot;)

splot &amp;quot;wig&amp;quot; u 1:2:3

set term png size 800,600
set out &amp;quot;wigner.png&amp;quot;

set lmargin at screen 0
set rmargin at screen 1.0
set bmargin at screen 0
set tmargin at screen 1.0

unset tics
unset border

splot &amp;quot;wig&amp;quot; u 1:2:3&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We can see that the tikz plot is create first, then the png plot. With those settings, the png file contains just the actual plot area without any margins whatsoever. It looks like this: &lt;a href='wigner.png'&gt;wigner.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The tikz file that comes out of this has some 150 MB. However, if we open it up in a text editor, we can easily identify its structure, and write a small script that replaces the actual plot with the png file:&lt;/p&gt;

&lt;p&gt;&lt;a href='combine_pm3dmap.pl'&gt;combine_pm3dmap.pl&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second thing this script does is to make the plot legend look quite a bit nicer. In the original, the legend was just a bunch of colored boxes stacked on top of each other to create a fake gradient, which looks horrible. We replace this with two true gradients, which works because we set the colors in the gnuplot script to go from blue to white to red. So we can have one true gradient from blue to white, and one from white to red.&lt;/p&gt;

&lt;p&gt;Of course, the script is not really general, but I think it should work for any pm3d map plot that uses a three-color gradient centered around white as the palette. Also, if it&amp;#8217;s just for a single plot, you could just as easily do this by hand.&lt;/p&gt;

&lt;p&gt;After processing the tikz file by calling &lt;code&gt;./combine_pm3dmap.pl wigner.tikz
wigner.png&lt;/code&gt;, we get this modified tikz file that is only 4.8 KB in size:&lt;/p&gt;

&lt;p&gt;&lt;a href='wigner.tikz'&gt;wigner.tikz&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It can be easily compiled (e.g with the &lt;a href='http://kogs-www.informatik.uni-hamburg.de/~meine/tikz/process/#tikz2pdf'&gt;tikz2pdf&lt;/a&gt; script, and don&amp;#8217;t forget to include &lt;a href='http://peter.affenbande.org/gnuplot/'&gt;gnuplot-lua-tikz.sty&lt;/a&gt;), resulting in the following pdf:&lt;/p&gt;

&lt;p&gt;&lt;a href='wigner.pdf'&gt;wigner.pdf&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Accessing GMail through Python</title>
   <link href="blog/2009/11/accessing-gmail-through-python/"/>
   <updated>2009-11-29T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2009/11/accessing-gmail-through-python</id>
   <content type="html">&lt;p&gt;Over the last couple of years, I&amp;#8217;ve made several attempts at efficiently interacting with Gmail through Python. There were a number of motivations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filtering mail: Putting emails into folder based on more elaborate rules than the server-side filters Gmail provides.&lt;/li&gt;

&lt;li&gt;Processing mail: Modifying emails, for example decrypting gpg-encrypted mails, or fixing missing header fields.&lt;/li&gt;

&lt;li&gt;Import and export: You want to keep local backups of your emails, and restore them.&lt;/li&gt;

&lt;li&gt;New mail notification, distinguishing between senders.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='how_does_gmail_work'&gt;How Does Gmail Work?&lt;/h3&gt;

&lt;p&gt;Gmail follows a somewhat new paradigm compared to traditional mail systems.&lt;/p&gt;

&lt;p&gt;Traditionally, a mailbox contains a ordered list of messages. These messages can sometimes have a limited number of tags (e.g. &amp;#8216;replied&amp;#8217;), and conversation threads can be constructed from the &amp;#8216;references&amp;#8217; field in the email&amp;#8217;s header. In Python, there is a class describing the traditional &lt;a href='http://docs.python.org/library/mailbox.html'&gt;mailbox interface&lt;/a&gt;. There tends to be a collection of mailboxes (folders) associated with one email account / server, usually at least an Inbox and a Sent mailbox.&lt;/p&gt;

&lt;p&gt;In contrast, a Gmail mailbox does not center around messages, but instead around conversation threads: the mailbox is an unordered list of conversation threads. Each thread can have a number of tags or labels associated with it. Note that theses labels are not associated with the individual messages, but always with the thread as a whole. Threads cannot be split or combined, there is no guaranteed relationship between the &amp;#8216;references&amp;#8217; header field in the messages and the membership to a thread.&lt;/p&gt;

&lt;p&gt;Also, even though the &amp;#8216;Inbox&amp;#8217;, &amp;#8216;Sent&amp;#8217;, &amp;#8216;All Mail&amp;#8217;, etc. look very similar to the structure of multiple folders on, say, an IMAP server, this can be misleading. You should look at your Gmail account as a single mailbox, with &amp;#8216;Inbox&amp;#8217;, &amp;#8216;Sent&amp;#8217;, &amp;#8216;All Mail&amp;#8217;, etc. being labels to threads. The difference is that each thread can have multiple labels, compared to a message always being in a single folder. If you put a message into multiple folders on your IMAP server, these messages would be completely independent: They&amp;#8217;d take up more space, and deleting the message from one folder would leave it entirely unaffected in the other. In Gmail, applying additional labels to a thread does not use more space, and putting a thread into the Trash removes the entire thread globally. Google explains this in their &lt;a href='http://mail.google.com/support/bin/answer.py?hl=en&amp;amp;amp;answer=10708'&gt;help section&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='how_does_gmail_work_through_imap'&gt;How Does Gmail Work through IMAP?&lt;/h3&gt;

&lt;p&gt;In addition to its web interface, which is based on the paradigm I just explained, Google also provides &lt;a href='http://mail.google.com/support/bin/topic.py?topic=12806'&gt;access via IMAP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To do this, it is necessary to map Gmail features somehow into IMAP. Google decided to break the focus on threads (in the web interface, you&amp;#8217;ll always have entire threads in your Inbox, for example, while in IMAP, not all of the messages belonging to the same thread have to be in the Inbox at the same time). Also, they mapped labels to folders. This means that from the IMAP client&amp;#8217;s point of view identical messages have no immediate connection between them, they have to be downloaded multiple times, and any changes to one do not affect the other copies. To keep the consistency, Google behaves as if there constantly was a second IMAP client connected to the account, reacting to anything you do. If you move a message to the Trash, the shadow client will also delete the copies of the message from all other folders. In this way, Google conforms to the IMAP standard, while keeping the consistency with their paradigm.&lt;/p&gt;

&lt;p&gt;Nonetheless, in many situations the way in which the Gmail system was mapped to IMAP is not so well chosen. For one thing, it would be nice to (at least optionally) keep the messages of a thread together even in the IMAP interface. Of course, this would mean even more intrusion by the shadow client, but at least you&amp;#8217;d be able to look at the entire thread without having to switch to the &amp;#8216;All Mail&amp;#8217; folder. It is also not always clear when a message will show up in a given folder.&lt;/p&gt;

&lt;p&gt;Secondly, at least from the programmer&amp;#8217;s point of view, it would be nice to have access to the labels of a message not just through different folders. It turns out the the IMAP standard allows for arbitrary labels (&amp;#8216;flags&amp;#8217;) to messages (&lt;a href='http://tools.ietf.org/html/rfc3501#section-2.3.2'&gt;RFC3501&lt;/a&gt;. I am not aware of any email client that makes full use of this possibility, a few (like Thunderbird) use quasi-standard labels &amp;#8216;$1&amp;#8217;, &amp;#8216;$2&amp;#8217;, etc and internally map them to labels like &amp;#8216;personal&amp;#8217;, &amp;#8216;work&amp;#8217;, etc. This lack of support is probably what suggested Google to use folders instead. Nonetheless, there is no reason why the Gmail IMAP server should not provide access to the label-flags directly.&lt;/p&gt;

&lt;h3 id='gmail_mailbox_class'&gt;Gmail Mailbox Class&lt;/h3&gt;

&lt;p&gt;It would be nice to have a Python class that provides a high level interface to Gmail through IMAP. Of course, one can access the Gmail account just on the normal IMAP level, as explained in the previous section. For this, I&amp;#8217;ve written a package called &lt;a href='http://github.com/goerz/procimap/'&gt;ProcImap&lt;/a&gt;. Just using that, one can already do a lot. However, one would really like to move slightly more in the direction of the unique Gmail paradigm. Specifically, we want two additional methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Return all the labels of a given message&lt;/li&gt;

&lt;li&gt;Return all messages that belong to the same thread as a given message.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It turns out that both of these demands are extremely difficult to fulfill. I experimented with some implementations for this in a Gmail module as part of the ProcImap package, which was meanwhile removed again due to the difficulties involved. Obviously, if Google decided to give access to the labels via the IMAP flags feature, the first problem would be solved. For the second problem, Google would have to keep a strict correlation between the &amp;#8216;references&amp;#8217; headers in the messages and the thread status.&lt;/p&gt;

&lt;p&gt;So, what makes this problem so hard? Essentially, it comes down to the fact that you have to deal with multiple copies of the same messages in different folders. We could just go through all folders, find out which of them contain a copy of the given message, and thus reconstruct a list of labels. Likewise, we could reconstruct the threads (to the limit of the information we can get from the &amp;#8216;references&amp;#8217; headers) by identifying copies of the same message.&lt;/p&gt;

&lt;p&gt;Unfortunately, this is something IMAP was absolutely not made for. There simply is no efficient way to decide whether two email messages are copies of each other. In theory, the &amp;#8216;message-id&amp;#8217; header field should fulfill this purpose, but its proper use has never been enforced. Messages may have missing IDs, or different messages may have the same ID. Comparing the full header of two messages is also not enough: one could be a copy of the other, stripped of attachments, for example. The only thing that would work is to compare a hash of the full messages. This is highly inefficient and also very sensitive to any sort of corruption.&lt;/p&gt;

&lt;p&gt;There is also one last issue: Gmail sometimes considers different mails as identical, and refuses to add them to the account. It is completely unclear under which conditions this happens. For example, I&amp;#8217;ve had instances where Gmail would refuse to add (i.e. silently ignore) the decrypted version of an email while the encrypted version was still in the mailbox. Also, trying to upload a copy of an email with some modified header fields often fails.&lt;/p&gt;

&lt;p&gt;The severity of these problems becomes clear when we look at the decryption problem again in detail. We would have to follow the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save all the labels of the message. As discussed above, this is very difficult.&lt;/li&gt;

&lt;li&gt;Download the encrypted email and move the original to the Trash (direct deletion of a message is not possible). This will remove all copies of the message from all folders.&lt;/li&gt;

&lt;li&gt;Identify the message in the Trash, and delete it from there. As discussed above, the identification is hard. If we neglect this step we may run into the problem that the upload of the decrypted message will fail. Alternatively, we can delete the entire trash, this however may be undesirable.&lt;/li&gt;

&lt;li&gt;Decrypt the message and upload it again.&lt;/li&gt;

&lt;li&gt;Store copies in all the original labels.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So far, there is no satisfactory way to go through this process.&lt;/p&gt;

&lt;h3 id='brute_forcing_gmail'&gt;Brute Forcing Gmail&lt;/h3&gt;

&lt;p&gt;There is one possible but inefficient way out of this: Download every message in every folder (that means downloading multiple copies of the same message), and analyze the structure of the messages. We can then keep the information of which message has which labels, and which message belongs to which thread in a local cache. We would have to update that cache in regular intervals (which could be done at a sufficiently small cost since we only need to process changes since the last update). Using that cache, we could implement an interface that provides access to most aspects of the Gmail paradigm. The no longer existing Gmail class in the ProcImap package experimented with that approach, but the entire concept turned out to be very inelegant in its implementation.&lt;/p&gt;

&lt;p&gt;Nonetheless, the brute force approach can be useful for certain applications. For example, I have a collection of python scripts (&lt;a href='http://github.com/goerz/gmailbkp'&gt;gmailbkp&lt;/a&gt;) that work on top of ProcImap and provide incremental backup of your gmail mailbox.&lt;/p&gt;

&lt;h3 id='libgmail'&gt;libgmail&lt;/h3&gt;

&lt;p&gt;There is one available alternative to the IMAP approach: The &lt;a href='http://libgmail.sourceforge.net/'&gt;libgmail&lt;/a&gt; package. This package uses Java Script to access Gmail (basically, it connects like a browser to the Gmail website). The package provides a full abstraction of the Gmail paradigm, and it does absolutely everything we want exactly how we want it. There is one big drawback, however: Google does not support the library and monitors their web interface for &amp;#8216;suspicious activity&amp;#8217;. If you access your account too intensely using libgmail, Google will lock you out for 24 hours. This makes it impossible to use the library for backup purposes. I did try: &lt;a href='http://github.com/goerz/gmail_archive.py'&gt;gmail_archive.py&lt;/a&gt;. Be warned that using this script will very likely get you locked out of your account.&lt;/p&gt;

&lt;p&gt;For smaller tasks, libgmail can be extremely valuable. It probably could solve the decryption example. However, even with such small task the danger of being locked out is always present.&lt;/p&gt;

&lt;p&gt;In conclusion, there is no satisfactory way to interface Python with Gmail. You either have to limit yourself to IMAP, or work with the dangers of libgmail. The ProcImap package will probably not provide any explicit support for Gmail in the future.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Three little git scripts</title>
   <link href="blog/2009/10/three-little-git-scripts/"/>
   <updated>2009-10-24T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/10/three-little-git-scripts</id>
   <content type="html">&lt;p&gt;I have three scripts that help me with my daily use of git&lt;/p&gt;

&lt;h3 id='gitcat'&gt;git-cat&lt;/h3&gt;

&lt;p&gt;I like to have a quick way to look at the contents of a file in an old revision. In SVN, that was &lt;code&gt;svn cat&lt;/code&gt;. With git, you could use &lt;code&gt;git show&lt;/code&gt;, as in &lt;code&gt;git show rev:&amp;lt;relative/to/repo/root/file&amp;gt;&lt;/code&gt;, but that requires to give the full path of the file you&amp;#8217;re trying to cat. Not very practical. My &lt;a href='git-cat'&gt;git-cat&lt;/a&gt; script solves this. It&amp;#8217;s just one line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git cat-file -p $(git ls-tree $1 &amp;quot;$2&amp;quot; | cut -d &amp;quot; &amp;quot; -f 3 | cut -f 1)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You use it as &lt;code&gt;git cat rev file&lt;/code&gt;. I suppose it should be possible to define this as an alias, but somehow I wasn&amp;#8217;t able to get that to work.&lt;/p&gt;

&lt;h3 id='gitvimdiff'&gt;git-vimdiff&lt;/h3&gt;

&lt;p&gt;While the colored diffs that git provides are extremely nice, I sometimes like to compare the modified and the unmodified version of a file side-by-side in vim. That&amp;#8217;s what &lt;a href='git-vimdiff'&gt;git-vimdiff&lt;/a&gt; does. It relies on the above git-cat script. All it really does is to cat the HEAD version of the file to a temporary file, and call vimdiff.&lt;/p&gt;

&lt;h3 id='gitgraph'&gt;git-graph&lt;/h3&gt;

&lt;p&gt;Lastly, I like to look at graphs. &lt;a href='git-graph.py'&gt;git-graph&lt;/a&gt; helps with that. It&amp;#8217;s not that different from doing &lt;code&gt;git log --graph --decorate --all&lt;/code&gt;, but first of all, I don&amp;#8217;t like to remember all of that (sure, I can define an alias). git-graph also shows the references in a nicer way (shorter, color coded: green for local, blue for remote). Lastly, it can also show SVN revision numbers, which is extremely useful when you&amp;#8217;re using git-svn.&lt;/p&gt;

&lt;p&gt;When you download the git-graph script, it&amp;#8217;s best to save it without the extension (like the other two scripts). The thing is, when you have one of the newer versions of git installed where you can use both the dashed (&lt;code&gt;git-clone&lt;/code&gt;) and the non-dashed (&lt;code&gt;git clone&lt;/code&gt;) version of commands, this extends to anything on your system. When you call &lt;code&gt;git graph&lt;/code&gt;, git will automatically execute &lt;code&gt;git-graph&lt;/code&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Installing a CVS version of Gnuplot in MacPorts</title>
   <link href="blog/2009/10/installing-a-cvs-version-of-gnuplot-in-macports/"/>
   <updated>2009-10-24T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/10/installing-a-cvs-version-of-gnuplot-in-macports</id>
   <content type="html">&lt;p&gt;I wanted to have a bleeding edge version of gnuplot, mostly for the new TikZ terminal. Here&amp;#8217;s what to do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Download the CVS version of gnuplot with&lt;/p&gt;

&lt;p&gt;cvs -z3 -d:pserver:anonymous@gnuplot.cvs.sourceforge.net:/cvsroot/gnuplot export -D now gnuplot&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Run &lt;code&gt;./prepare&lt;/code&gt; inside of the gnuplot folder, in order to generate a configure script&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Rename the gnuplot folder to &lt;code&gt;gnuplot-4.5.0&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Create a tarball &lt;code&gt;gnuplot-4.5.0.tar.gz&lt;/code&gt; and put it up on some server&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Create a local portfile repository, as explained in the &lt;a href='http://guide.macports.org/#development.local-repositories'&gt;MacPorts Guide&lt;/a&gt;. I created mine in&lt;/p&gt;

&lt;p&gt;~/.macports/portrepo&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Take a copy of the &lt;a href='http://gnuplot.darwinports.com/dports/math/gnuplot/Portfile'&gt;original gnuplot Portfile&lt;/a&gt; and put it in&lt;/p&gt;

&lt;p&gt;~/.macports/portrepo/science/gnuplot&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Modify the Portfile to adapt it to your self-created tarball. I end up with &lt;a href='Portfile.gz'&gt;Portfile&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update the version to 4.5.0&lt;/li&gt;

&lt;li&gt;Set your url at the master site&lt;/li&gt;

&lt;li&gt;Update the checksums (use md5sum and openssl as described in the the &lt;a href='http://guide.macports.org/#development.creating-portfile'&gt;MacPorts Guide&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;Take out the references to gnuplot.pdf&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Make sure that your local portfile repository is listed in&lt;/p&gt;

&lt;p&gt;/opt/local/etc/macports/sources.conf&lt;/p&gt;

&lt;p&gt;and do &lt;code&gt;portindex&lt;/code&gt; inside of the repository&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;You can now do&lt;/p&gt;

&lt;p&gt;sudo port install gnuplot&lt;/p&gt;

&lt;p&gt;in order to install your CVS version&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lastly, if you hate the Aquaterm terminal as much as I do, you can change the default by putting &lt;code&gt;export GNUTERM=x11&lt;/code&gt; in your &lt;code&gt;.bashrc&lt;/code&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Annotating LaTeX Lists with Flowchart symbols</title>
   <link href="blog/2009/10/annotating-latex-lists-with-flowchart-symbols/"/>
   <updated>2009-10-06T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/10/annotating-latex-lists-with-flowchart-symbols</id>
   <content type="html">&lt;p&gt;There&amp;#8217;s a neat little trick of putting TikZ code in the place of list bullets in LaTeX. Together with TikZ&amp;#8217;s overlay feature, I was able to make a small graphical flowchart out of of list items: You just put a small tikzpicture in the place of every bullet, defining some globally accessible node with the &amp;#8216;remember picture&amp;#8217; option. This has to be done by defining a command for inserting the picture, like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='latex'&gt;    &lt;span class='k'&gt;\newcommand\fcInstr&lt;/span&gt;&lt;span class='na'&gt;[1]&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;&lt;span class='c'&gt;%&lt;/span&gt;
      &lt;span class='k'&gt;\begin&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;tikzpicture&lt;span class='nb'&gt;}&lt;/span&gt;[x=10pt, y=10pt, remember picture]&lt;span class='c'&gt;%&lt;/span&gt;
        &lt;span class='k'&gt;\node&lt;/span&gt;&lt;span class='na'&gt;[coordinate]&lt;/span&gt; (#1) at (1,0.5) &lt;span class='nb'&gt;{}&lt;/span&gt;;
        &lt;span class='k'&gt;\draw&lt;/span&gt; (0,0) rectangle (2,1);&lt;span class='c'&gt;%&lt;/span&gt;
      &lt;span class='k'&gt;\end&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;tikzpicture&lt;span class='nb'&gt;}&lt;/span&gt;&lt;span class='c'&gt;%&lt;/span&gt;
    &lt;span class='nb'&gt;}&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Not that the node is named after the first parameter: every node needs to have a unique name.&lt;/p&gt;

&lt;p&gt;You then write your list&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='latex'&gt;    &lt;span class='k'&gt;\begin&lt;/span&gt;&lt;span class='nb'&gt;{&lt;/span&gt;itemize&lt;span class='nb'&gt;}&lt;/span&gt;
      &lt;span class='k'&gt;\item&lt;/span&gt;&lt;span class='na'&gt;[\fcInstr{a}]&lt;/span&gt; Set &lt;span class='s'&gt;$&lt;/span&gt;&lt;span class='nb'&gt;t_n&lt;/span&gt;&lt;span class='s'&gt;$&lt;/span&gt;: time grid for global &lt;span class='s'&gt;$&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='m'&gt;0&lt;/span&gt;&lt;span class='nb'&gt;,T&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;&lt;span class='s'&gt;$&lt;/span&gt;
      ...
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Lastly, you can add add another tikzpicture to your document in which the defined nodes are referenced. In my example, I want to draw arrows between the &amp;#8216;bullet&amp;#8217; picture.&lt;/p&gt;

&lt;p&gt;Alltogether, it comes out like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='flowchart.tex'&gt;flowchart.tex&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='flowchart.pdf'&gt;flowchart.pdf&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Command Line Interface for InsomniaX</title>
   <link href="blog/2009/09/command-line-interface-for-insomniax/"/>
   <updated>2009-09-03T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/09/command-line-interface-for-insomniax</id>
   <content type="html">&lt;p&gt;For the brief period of time that &lt;a href='http://semaja2.net/insomniaxinfo'&gt;InsomniaX&lt;/a&gt; did not work on Snow Leopard, I tried to work with the legacy (0.5) version, but it was a mess. &lt;a href='https://twitter.com/4lex'&gt;@4lex&lt;/a&gt; pointed out to me that you can just load the kernel extension that Insomnia provides from the command line.&lt;/p&gt;

&lt;p&gt;Meanwhile, Insomnia has been updated for Snow Leopard, but nontheless it is very convenient to have a command line interface. So, here&amp;#8217;s the script:&lt;/p&gt;
&lt;script src='http://gist.github.com/180474.js' /&gt;
&lt;p&gt;You can do &lt;code&gt;insomnia load&lt;/code&gt;, &lt;code&gt;insomnia on&lt;/code&gt;, or &lt;code&gt;insomnia start&lt;/code&gt;, to enable Insomnia mode (load the kernel extension) and to start the InsomniaX application. You can do &lt;code&gt;insomnia unload&lt;/code&gt;, &lt;code&gt;insomnia off&lt;/code&gt;, or &lt;code&gt;insomnia stop&lt;/code&gt; to unload the kernel extension and kill InsomniaX. On top of that, you can use &lt;code&gt;insomnia show&lt;/code&gt; and &lt;code&gt;insomnia hide&lt;/code&gt; to start or kill InsomniaX (not changing the status of the kernel extension).&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Adding Local-File fields to BibDesk created BibTeX File</title>
   <link href="blog/2009/08/adding-local-file-fields-to-bibdesk-created-bibtex-file/"/>
   <updated>2009-08-25T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/08/adding-local-file-fields-to-bibdesk-created-bibtex-file</id>
   <content type="html">&lt;p&gt;BibTeX files that were created with the BibDesk program on the Mac store links to local files as smart references, which has a lot of benefits:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To be precise, it&amp;#8217;s a base64 encoded (keyed) archived dictionary containing a relative path and a file alias (an alias stores a full path and a file ID). It is designed to support a large range of storage procedures, as it can find a file by relative path, absolute path, and file ID (in that order). This means that you can&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;move/rename the .bib file (as it stores full paths)&lt;/li&gt;

&lt;li&gt;move/rename a linked file (as it stores file IDs)&lt;/li&gt;

&lt;li&gt;move the .bib file and linked files together (as it stores relative paths)&lt;/li&gt;

&lt;li&gt;copy the .bib file and linked files togther, even between different machines (as it stores relative paths) &lt;a href='http://n2.nabble.com/Path-implications-when-sharing-bib-files-with-Bdsk-File-1-entries-td661338.html#a662004'&gt;(bibdesk user mailing list)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;This works perfectly as long as you stay on a Mac. However, if you have to share the BibTeX file with someone who cannot run BibDesk, it may be useful to add some human-readable information as well. For this, I&amp;#8217;ve written a small script that is an adaption of the code found at &lt;a href='http://bibdesk-users.661331.n2.nabble.com/Loss-of-local-file-links-td2209604.html'&gt;http://n2.nabble.com/Loss-of-local-file-links-td2209604.html&lt;/a&gt; It adds a Local-File field to the BibTeX file with the relative path of the referenced file.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/env python
&amp;quot;&amp;quot;&amp;quot; Add/update Local-File field to BibDesk-organized BibTeX file &amp;quot;&amp;quot;&amp;quot;
import sys
import base64
import re
import shutil
from Foundation import *

key_pattern = re.compile(r&amp;#39;^(?P&amp;lt;indent&amp;gt;\s*)Bdsk-File-1 = \{(?P&amp;lt;key&amp;gt;.*)\}[,}]$&amp;#39;)


def decode_bdisk(key):
    &amp;quot;&amp;quot;&amp;quot;Return the relative path of file referenced by key &amp;quot;&amp;quot;&amp;quot;
    decodedBytes = base64.b64decode(key)
    nsData = NSData.dataWithBytes_length_(decodedBytes, len(decodedBytes))
    plist, fmt, error \
    = NSPropertyListSerialization\
      .propertyListFromData_mutabilityOption_format_errorDescription_(\
      nsData, 0, None, None)
    if plist is None:
        print &amp;quot;key: %s&amp;quot; % key
        print &amp;quot;failed to decode archive due to error: %s&amp;quot; % (error)
        exit(1)
    # currently an implementation detail; may not be at position 6 in future
    if (len(plist[&amp;quot;$objects&amp;quot;]) &amp;gt; 6):
        return plist[&amp;quot;$objects&amp;quot;][6]
    else:
        print &amp;quot;unknown format for property list %s&amp;quot; % (str(plist))

file = sys.argv[1]
backup = &amp;quot;%s~&amp;quot; % file
shutil.copy(file, backup)
out = open(file, &amp;#39;w&amp;#39;)
for line in open(backup):
    key_match = key_pattern.search(line)
    if key_match:
        out.write(&amp;quot;%sLocal-File = {%s},\n&amp;quot;
                  % (key_match.group(&amp;#39;indent&amp;#39;),
                     decode_bdisk(key_match.group(&amp;#39;key&amp;#39;))))
    if not re.search(&amp;quot;^\s*Local-File = &amp;quot;, line):
        out.write(line)&lt;/code&gt;&lt;/pre&gt;</content>
 </entry>
 
 <entry>
   <title>Converting a SVN repository to git</title>
   <link href="blog/2009/08/svn_to_git/"/>
   <updated>2009-08-09T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/08/svn_to_git</id>
   <content type="html">&lt;p&gt;A few lines to converte a subversion repository in &lt;code&gt;SVNURL&lt;/code&gt; to a repository &lt;code&gt;GITNAME.git&lt;/code&gt; which is accessible at &lt;code&gt;GITURL/GITNAME.git&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This assumes to that you crated a &lt;code&gt;users.txt&lt;/code&gt; file in the current directory.&lt;/p&gt;

&lt;p&gt;This does not take care of the whole subversion branches/tags issue (you&amp;#8217;d have to add a few lines)&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    &lt;span class='nb'&gt;pushd&lt;/span&gt; .
    git-svn clone SVNURL --authors-file&lt;span class='o'&gt;=&lt;/span&gt;users.txt --no-metadata GITNAME
    mkdir GITNAME.git
    &lt;span class='nb'&gt;cd &lt;/span&gt;GITNAME.git
    git --bare init
    &lt;span class='nb'&gt;cd&lt;/span&gt; ..
    &lt;span class='nb'&gt;cd &lt;/span&gt;GITNAME
    git remote add origin GITURL/GITNAME.git
    git push origin master
    &lt;span class='nb'&gt;popd&lt;/span&gt;
&lt;span class='nb'&gt;    &lt;/span&gt;rm -rf GITNAME
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>OCT Diagrams in TikZ</title>
   <link href="blog/2009/07/oct-diagrams-in-tikz/"/>
   <updated>2009-07-26T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/07/oct-diagrams-in-tikz</id>
   <content type="html">&lt;p&gt;I decided to make my first really complex TikZ drawing: A diagram explaining the implementation of an Optimal Control Theory algorithm I did recently. There is a print version:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='oct_diagram.pdf'&gt;oct_diagram.pdf&lt;/a&gt; (&lt;a href='oct_diagram.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='oct_diagram.tikz'&gt;oct_diagram.tikz&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to that, there are some animated presentation slides, explaining three variations of the algorithm:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='oct_slides.pdf'&gt;oct_slides.pdf&lt;/a&gt; (&lt;a href='oct_slides.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='oct_storeall.tikz'&gt;oct_storeall.tikz&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='oct_storenone.tikz'&gt;oct_storenone.tikz&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='oct_segments.tikz'&gt;oct_segments.tikz&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The process of creating these diagrams was fairly involved, but not more than I would have expected. I don&amp;#8217;t think any other tool would have been up to the task, and the result is quite exhilarating. The principles of TeX/TikZ make it quite easy to create variations of existing pictures.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Printable Paper with LaTeX and TikZ</title>
   <link href="blog/2009/07/printable-paper-with-latex-and-tikz/"/>
   <updated>2009-07-17T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/07/printable-paper-with-latex-and-tikz</id>
   <content type="html">&lt;p&gt;A little while ago, I played around with &lt;a href='http://www.texample.net/tikz/'&gt;TikZ&lt;/a&gt; to make printable paper. As it turns out, this is absolutely trivial, and with just a few lines you can generate pretty much anything you can imagine. Here are the examples that I generated:&lt;/p&gt;

&lt;h4 id='a4_paper'&gt;A4 paper&lt;/h4&gt;

&lt;h5 id='blank_paper'&gt;Blank Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='a4_lin24_blank.pdf'&gt;Lin 24 blank page with right margin&lt;/a&gt; (&lt;a href='a4_lin24_blank.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id='ruled_paper'&gt;Ruled Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='a4_lin25_lined.pdf'&gt;Lin 25 9mm rules with right margin&lt;/a&gt; (&lt;a href='a4_lin25_lined.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='a4_lin27_lined.pdf'&gt;Lin 27 9mm rules with two margins&lt;/a&gt; (&lt;a href='a4_lin27_lined.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id='graph_paper'&gt;Graph Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='a4_lin22_squared.pdf'&gt;Lin 22 5mm graph paper, no margins&lt;/a&gt; (&lt;a href='a4_lin22_squared.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='a4_lin23_rect5x9.pdf'&gt;Lin 23 5x9mm graph paper, no margins&lt;/a&gt; (&lt;a href='a4_lin23_rect5x9.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='a4_lin26_squared.pdf'&gt;Lin 26 5mm graph paper with right margin&lt;/a&gt; (&lt;a href='a4_lin26_squared.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='a4_lin28_squared.pdf'&gt;Lin 28 5mm graph paper with two margins&lt;/a&gt; (&lt;a href='a4_lin28_squared.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='a4_millimeter.pdf'&gt;Millimeter graph paper&lt;/a&gt; (&lt;a href='a4_millimeter.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id='underlay_paper'&gt;Underlay Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='a4_lin22_squared_master.pdf'&gt;Lin 22 5mm underlay, no margins&lt;/a&gt; (&lt;a href='a4_lin22_squared_master.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='a4_lin28_squared_master.pdf'&gt;Lin 28 5mm underlay with two margins&lt;/a&gt; (&lt;a href='a4_lin28_squared_master.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='a4_personal_master.pdf'&gt;Personal Correspondence&lt;/a&gt; (&lt;a href='a4_personal_master.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id='letter_size_paper'&gt;Letter size paper&lt;/h4&gt;

&lt;h5 id='cornell_paper'&gt;Cornell Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='letter_cornell_blank.pdf'&gt;Cornell blank note taking paper&lt;/a&gt; (&lt;a href='letter_cornell_blank.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='letter_cornell_ruled.pdf'&gt;Cornell college ruled note taking paper&lt;/a&gt; (&lt;a href='letter_cornell_ruled.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='letter_cornell_graph.pdf'&gt;Cornell ¼ inch graph note taking paper&lt;/a&gt; (&lt;a href='letter_cornell_graph.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id='ruled_paper'&gt;Ruled Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='letter_narrow_ruled.pdf'&gt;Narrow ruled paper&lt;/a&gt; (&lt;a href='letter_narrow_ruled.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='letter_college_ruled.pdf'&gt;College ruled paper&lt;/a&gt; (&lt;a href='letter_college_ruled.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='letter_wide_ruled.pdf'&gt;Wide ruled paper&lt;/a&gt; (&lt;a href='letter_wide_ruled.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id='graph_paper'&gt;Graph Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='letter_inch4squared.pdf'&gt;¼ inch graph paper with two margins&lt;/a&gt; (&lt;a href='letter_inch4squared.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='letter_millimeter.pdf'&gt;Millimeter graph paper&lt;/a&gt; (&lt;a href='letter_millimeter.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id='underlay_paper'&gt;Underlay Paper&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='letter_inch4squared_master.pdf'&gt;¼ inch graph underlay with two margins&lt;/a&gt; (&lt;a href='letter_inch4squared_master.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;

&lt;li&gt;&lt;a href='letter_personal_master.pdf'&gt;Personal Correspondence&lt;/a&gt; (&lt;a href='letter_personal_master.tex'&gt;TeX&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can adapt any of these examples to your needs easily, as well as create more complicated layouts. Anything you can find on &lt;a href='http://www.printablepaper.net/'&gt;http://www.printablepaper.net/&lt;/a&gt;, for sure. To compile, run the tex file through pdflatex twice.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using Gmail through Mailplane</title>
   <link href="blog/2009/07/using-gmail-through-mailplane/"/>
   <updated>2009-07-16T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/07/using-gmail-through-mailplane</id>
   <content type="html">&lt;p&gt;I just looked at &lt;a href='http://mailplaneapp.com/'&gt;Mailplane&lt;/a&gt; again, and found it to be working perfectly (or at least much better then what I remembered from last time I checked it out). While for general web browsing Safari lacks important features compared to Firefox, the infinitely better speed and responsiveness comes in very handy for a specific application like Gmail.&lt;/p&gt;

&lt;p&gt;I was somewhat concerned that tweaking Gmail in Mailplane would be more limited than in Firefox, but with some customization I managed to get everything working. Specifically, I had the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No Ads&lt;/li&gt;

&lt;li&gt;Monospace Font&lt;/li&gt;

&lt;li&gt;Writing Emails in MacVim&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first two points can be done by providing a custom stylesheet, as described here: &lt;a href='http://mailplaneapp.com/screencasts/entry/install_custom_stylesheet/'&gt;http://mailplaneapp.com/screencasts/entry/install_custom_stylesheet/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The stylesheet I&amp;#8217;m using is this one:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='css'&gt;    &lt;span class='c'&gt;/* -----------------------------------------------------&lt;/span&gt;
&lt;span class='c'&gt;    Mailplane Hide Gmail Ads CSS&lt;/span&gt;
&lt;span class='c'&gt;    ----------------------------------------------------- */&lt;/span&gt;
    
    &lt;span class='c'&gt;/* Hide the ads */&lt;/span&gt;
    &lt;span class='nc'&gt;.oM&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt;
    &lt;span class='nc'&gt;.u7&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt;
    &lt;span class='nc'&gt;.V3vJRb&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt;
    &lt;span class='nc'&gt;.yxEQwb&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='k'&gt;display&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt; &lt;span class='k'&gt;none&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt;
    
    &lt;span class='c'&gt;/* Hide the footer */&lt;/span&gt;
    &lt;span class='nc'&gt;.l2&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='k'&gt;display&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt; &lt;span class='k'&gt;none&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt;
    
    &lt;span class='c'&gt;/* -----------------------------------------------------&lt;/span&gt;
&lt;span class='c'&gt;    Fixed Font&lt;/span&gt;
&lt;span class='c'&gt;    ----------------------------------------------------- */&lt;/span&gt;
    
    &lt;span class='nc'&gt;.gs&lt;/span&gt; &lt;span class='nc'&gt;.ii&lt;/span&gt;&lt;span class='o'&gt;,&lt;/span&gt; &lt;span class='nt'&gt;textarea&lt;/span&gt;&lt;span class='nc'&gt;.dV&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;font-family&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt; &lt;span class='n'&gt;MonoSpace&lt;/span&gt; &lt;span class='cp'&gt;!important&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='k'&gt;font-size&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt; &lt;span class='m'&gt;9pt&lt;/span&gt; &lt;span class='cp'&gt;!important&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It also hides the footer, which is nice.&lt;/p&gt;

&lt;p&gt;The third point, writing emails with MacVim, is also a built-in feature, which really surprised me. There is &amp;#8220;Edit in MacVim&amp;#8221; in the Edit menu. This is actually also present in standard Safari, something I was not aware of. In Firefox I get this from the &lt;a href='http://vimperator.org'&gt;vimperator&lt;/a&gt; extension (or alternatively, from &lt;a href='https://addons.mozilla.org/en-US/firefox/addon/4125'&gt;It&amp;#8217; All Text!&lt;/a&gt;). The only problem was the somewhat complicated shortcut in Mailplane. As it turns out, the shortcut is customizable as well: &lt;a href='http://mailplaneapp.com/screencasts/entry/change_keyboard_shortcuts/'&gt;http://mailplaneapp.com/screencasts/entry/change_keyboard_shortcuts/&lt;/a&gt;. I changed it to Ctrl+I, which is the same shortcut I have in vimperator.&lt;/p&gt;

&lt;p&gt;One other important feature, attachments by drag-and-drop (which I had in Firefox via an extension that stopped working with Firefox 3.5) is a standard feature in Mailplane, of course (and works very well).&lt;/p&gt;

&lt;p&gt;So, can only recommend using Mailplane!&lt;/p&gt;

&lt;h5 id='update'&gt;Update&lt;/h5&gt;

&lt;p&gt;Going even further, I added the functionality of the &lt;a href='http://userstyles.org/styles/226'&gt;Gmail 2 small attachment icons script&lt;/a&gt;. The resulting css file is this one: &lt;a href='mailplane.css'&gt;mailplane.css&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Integrating VIM with IPython II</title>
   <link href="blog/2009/04/integrating-vim-with-ipython-ii/"/>
   <updated>2009-04-15T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/04/integrating-vim-with-ipython-ii</id>
   <content type="html">&lt;p&gt;After some suggestions by Peter Battaglia, I rewrote the send.vim script to work better for its original purpose: sending text from vim to ipython. See the &lt;a href='http://michaelgoerz.net/blog/2008/09/integrating-vim-with-ipython/'&gt;original post&lt;/a&gt; for the idea.&lt;/p&gt;

&lt;p&gt;The send.vim script is now in the vim script repository:&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.vim.org/scripts/script.php?script_id=2608'&gt;http://www.vim.org/scripts/script.php?script_id=2608&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem was that it&amp;#8217;s not enough to send the text as-is. The ipython shell needs additional newlines to tell it when a code block ends at indentation level zero. Another problem are blank lines: a blank line in your source code might unintentionally end a code block when you send it to ipython. Hence, it&amp;#8217;s best not to send empty lines at all.&lt;/p&gt;

&lt;p&gt;The special behavior required for ipython meant that I had to extend the functionality of the script somewhat. I still want the plugin to be of general purpose, with all the ipython-specific behavior being optional. So, in addition to setting the &lt;code&gt;g:sendToProgramName&lt;/code&gt; variable, you also have to set the &lt;code&gt;g:sendToProgramMode&lt;/code&gt; to &amp;#8216;ipython&amp;#8217; now in order to enable it.&lt;/p&gt;

&lt;p&gt;It seems very feasible to add modes like this for other situations in the future.&lt;/p&gt;

&lt;p&gt;In the reimplementation of the plugin, I also made it more robust to work per-buffer. In addition to the global settings (&lt;code&gt;g:sendToProgramName&lt;/code&gt; etc.), you can also give settings local to the buffer by setting (for example) the &lt;code&gt;b:sendToProgramName&lt;/code&gt; variable. Local settings, if present, override global settings. The plugin also keeps its internal state per buffer.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Poster for DPG Conference</title>
   <link href="blog/2009/03/poster-for-dpg-conference/"/>
   <updated>2009-03-30T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/03/poster-for-dpg-conference</id>
   <content type="html">&lt;p&gt;This is the poster I did for the &lt;a href='http://www.dpg-physik.de/index.html'&gt;DPG&lt;/a&gt; &lt;a href='http://hamburg09.dpg-tagungen.de/index.html'&gt;Spring Conference&lt;/a&gt; that took place in Hamburg the first week of march.&lt;/p&gt;

&lt;p&gt;&lt;a href='dpg_poster.pdf'&gt;dpg_poster.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Doing it in LaTeX was quite a nice experience. I used the &lt;a href='http://www.ctan.org/tex-archive/help/Catalogue/entries/a0poster.html'&gt;a0poster&lt;/a&gt; package. Most of the figures are done in &lt;a href='http://www.texample.net/tikz/'&gt;TikZ&lt;/a&gt;. This includes the plots: there is a very nice &lt;a href='http://peter.affenbande.org/gnuplot/'&gt;TikZ-Terminal&lt;/a&gt; for &lt;a href='http://www.gnuplot.info/'&gt;gnuplot&lt;/a&gt;. You have to recompile your own gnuplot in order to use that terminal, but that wasn&amp;#8217;t so hard. The gate diagram was done using &lt;a href='http://www.media.mit.edu/quanta/qasm2circ/'&gt;quasm&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is the complete source for the poster, without the data for the pulses:&lt;/p&gt;

&lt;p&gt;&lt;a href='poster.zip'&gt;poster.zip&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>New ASCII Table</title>
   <link href="blog/2009/03/new-ascii-table/"/>
   <updated>2009-03-30T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2009/03/new-ascii-table</id>
   <content type="html">&lt;p&gt;For quite a while I wanted to redo in LaTeX the &lt;a href='http://michaelgoerz.net/blog/2008/09/ascii-table/'&gt;ASCII file table&lt;/a&gt; I did more than 8 years ago. The original was done in Word, in a dozen different fonts. Of course, this only ever worked on the original machine I prepared the file on. I was basically left with a scanned version of a printout of the original. Exactly why Word sucks.&lt;/p&gt;

&lt;p&gt;So, after doing a &lt;a href='http://michaelgoerz.net/blog/2009/03/poster-for-dpg-conference/'&gt;poster&lt;/a&gt; recently in LaTeX, I finally found a way to do it: using the &lt;a href='http://www.ctan.org/tex-archive/help/Catalogue/entries/textpos.html'&gt;textpos&lt;/a&gt; package. Now I hopefully have something that will remain editable for all future times. The result is on the &lt;a href='http://michaelgoerz.net/refcards/index.html#ascii)'&gt;Refcard page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As opposed to my older ASCII Table, this one shows the extended character set for Latin1/CP1252 (aka the default Windows encoding). It&amp;#8217;s much more relevant than CP850 that was active on my computer 8 years ago. If would like a different codepage, there&amp;#8217;s a little python script that you can use to replace symbols in the ascii.tex file. You&amp;#8217;ll have to edit the source. The script reads the symbols (latex code) from a text file and inserts them into ascii.tex.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='build_ascii.py'&gt;build_ascii.py&lt;/a&gt; The script&lt;/li&gt;

&lt;li&gt;&lt;a href='latin1_symbols.txt'&gt;latin1_symbols.txt&lt;/a&gt; The text file I used to generate this version of the ascii table&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Still, three questions remain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why can&amp;#8217;t I compile this with pdflatex? I get error about the fonts. XeTeX seems to be the only thing producing PDF that can handle this.&lt;/li&gt;

&lt;li&gt;Why is the font rendering bitmapped?&lt;/li&gt;

&lt;li&gt;Why is it so difficult to get a page into landscape? Why do I have to compile it differently depending on the page format? Why does using the hyperref package have an influence on the page orientation?&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Vim Plugin for Completion of Fortran Structures</title>
   <link href="blog/2008/12/vim-plugin-for-completion-of-fortran-structures/"/>
   <updated>2008-12-18T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/12/vim-plugin-for-completion-of-fortran-structures</id>
   <content type="html">&lt;p&gt;I wrote a little plugin for vim that allows you to complete Fortran 90 structures by pressing F7.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.vim.org/scripts/script.php?script_id=2487'&gt;http://www.vim.org/scripts/script.php?script_id=2487&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The plugin in written in python, so you need to have your vim compiled with python support in order to use it.&lt;/p&gt;

&lt;p&gt;The intention is to complete &amp;#8220;program&amp;#8221;, &amp;#8220;type&amp;#8221;, &amp;#8220;interface&amp;#8221;, &amp;#8220;module&amp;#8221;, &amp;#8220;subroutine&amp;#8221;, &amp;#8220;function&amp;#8221;, &amp;#8220;do&amp;#8221;, and &amp;#8220;select&amp;#8221; constructs. You write the first line of such a construct (e.g. &amp;#8220;subroutine foo(a, b)&amp;#8221;, then press F7, and the script will add the closing line &amp;#8220;end subroutine foo&amp;#8221; and put the cursor between the two lines, indented by one level.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Fortran 90 Reference Card</title>
   <link href="blog/2008/12/fortran-90-reference-card/"/>
   <updated>2008-12-10T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/12/fortran-90-reference-card</id>
   <content type="html">&lt;p&gt;A Fortran 90 reference card seems hard to come by. So I created one:&lt;/p&gt;

&lt;p&gt;&lt;a href='http://michaelgoerz.net/refcards/index.html#fortran'&gt;Fortran 90 Reference Card&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Creating an ISO image on MacOS X</title>
   <link href="blog/2008/11/creating-an-iso-image-on-macos-x/"/>
   <updated>2008-11-30T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/11/creating-an-iso-image-on-macos-x</id>
   <content type="html">&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Insert your CD/DVD. Check that MacOS has mounted it in as a Volume (It will appear on the Desktop).&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Identify which device the CD/DVD is.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is the trickiest part of the whole procedure. First, use &lt;code&gt;drutil&lt;/code&gt; to get some comprehensive information about your CD/DVD&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  $ drutil status
  Vendor   Product           Rev
  HL-DT-ST DVDRW  GS21N      SA15

  Type: CD-ROM               Name: /dev/disk4
  Sessions: 1                  Tracks: 1
  Overwritable: 00:00:00         blocks:        0 /   0.00MB /   0.00MiB
  Space Free:   00:00:00         blocks:        0 /   0.00MB /   0.00MiB
  Space Used:   30:12:40         blocks:   135940 / 278.41MB / 265.51MiB
  Writability:&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note the device name here (&lt;code&gt;/dev/disk4&lt;/code&gt;) and the &amp;#8220;Space Used&amp;#8221; (265.51MiB). If you do everything right, your iso file should end up with the size that you see here.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/dev/disk4&lt;/code&gt; may not be the right device yet, however. It may be that you have to use a subdevice. Check which device MacOS used for mounting the CD. In my example, I got this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  $ df -h
  /dev/disk4s1s2      50Mi   50Mi    0Bi   100%    /Volumes/hp LaserJet 1010 Series&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This CD is pretty special. It contains printer drivers for both Windows and Mac, and is split in two parts. Mac OS only mounted the Mac-readable part, which is on device &lt;code&gt;/dev/disk4s1s2&lt;/code&gt;. As you can see, this part is only 50 MiB, which is less than the 266 MiB that we&amp;#8217;re expecting. If you check which devices actually exist in &lt;code&gt;/dev/&lt;/code&gt;, you&amp;#8217;ll find&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   /dev/disk4
   /dev/disk4s1
   /dev/disk4s1s2&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The one you have to use here is &lt;code&gt;/dev/disk4s1&lt;/code&gt;. This one contains the proper file system of the whole CD.&lt;/p&gt;

&lt;p&gt;In general, if you see something like &lt;code&gt;/dev/disk4&lt;/code&gt; in the output of &lt;code&gt;df -h&lt;/code&gt;, that&amp;#8217;s what you should use. If you see something like &lt;code&gt;/dev/disk4s1&lt;/code&gt; or &lt;code&gt;/dev/disk4s1s2&lt;/code&gt;, you&amp;#8217;ll most likely have to go with &lt;code&gt;/dev/disk4s1.&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the ISO file&lt;br /&gt; &lt;code&gt;$ cat /dev/disk4s1 &amp;gt; file.iso&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You may get this error message:&lt;br /&gt; &lt;code&gt;cat: /dev/disk4s1: Resource busy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you do, use the following command:&lt;br /&gt; &lt;code&gt;diskutil unmountDisk /dev/disk4s1&lt;/code&gt;&lt;br /&gt; &lt;code&gt;Disk /dev/disk4s1 unmounted&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After that, &lt;code&gt;cat&lt;/code&gt; should work.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test the ISO image by mounting the new file (or open with Finder):&lt;br /&gt; &lt;code&gt;$ hdiutil attach file.iso&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;</content>
 </entry>
 
 <entry>
   <title>Setting up a CLI environment on MacOS X</title>
   <link href="blog/2008/11/setting-up-a-cli-environment-on-macos-x/"/>
   <updated>2008-11-09T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/11/setting-up-a-cli-environment-on-macos-x</id>
   <content type="html">&lt;p&gt;While enjoying the truly amazing graphical user interface that the MacOS X Leopard provides on my new MacBook, I still strongly believe in the power of the command line. Setting up a complete environment had some challenges.&lt;/p&gt;

&lt;p&gt;First of all, what do I need?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Command line apps&lt;/p&gt;

&lt;p&gt;This come down to an installation of MacVim. Vim and mutt are just two examples of programs I use all the time.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;xterm&lt;/p&gt;

&lt;p&gt;xterm seems to be vastly superior to any other terminal emulator. Especially Terminal.app. What I absolutely need is support for &lt;a href='http://www.frexx.de/xterm-256-notes/'&gt;256 colors&lt;/a&gt;. I do 99% of my text editing with vim inside xterm, and I need a decent color profile. I also use &lt;code&gt;ssh -X&lt;/code&gt; all the time, so I need the X server anyway. I want to use the terminus font - big and readable. &lt;strong&gt;Update:&lt;/strong&gt; Since &lt;a href='http://iterm.sourceforge.net/'&gt;iTerm&lt;/a&gt; started supporting 256 colors, it has become my favorite Terminal. Easy copy+paste is wonderful!&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;US Keyboard Layout&lt;/p&gt;

&lt;p&gt;I type on an US keyboard layout - first of all because that what I learned to touch type one and secondly because it&amp;#8217;s the only layout that&amp;#8217;s usable for programming, where you need brackets, etc.However, I also have to type umlauts and similar unitt symbols. The way I want it to work is to have the umlauts as a third modification of the A, O, U, etc. keys. Hitting Alt+U should give me ü, Alt+Shift+U should give Ü. The caps lock key should be remapped to have the same effect as Alt. This keyboard layout should work anywhere in MacOS, including xterm. I want characters to be shown properly.&lt;/p&gt;

&lt;p&gt;All of my text files are encoded in UTF-8. I want to work with these files on the command line, and edit them with vim. Mutt should show umlauts in messages, instead of &amp;#8216;??&amp;#8217;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;screen&lt;/p&gt;

&lt;p&gt;I use screen a lot. Naturally, 256 colors and unicode support have to be active inside a screen session as well.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Installing MacPorts is relatively easy. Just follow the instructions. In addition, you need to set some environment variables in your &lt;a href='bashrc'&gt;&lt;code&gt;.bashrc&lt;/code&gt;&lt;/a&gt;. I set the complete &lt;code&gt;PATH&lt;/code&gt; manually to include MacPorts, my Enthought Python, and a local &lt;code&gt;~/bin&lt;/code&gt; folder. The &lt;code&gt;MANPATH&lt;/code&gt; needs to be extended to include MacPort manpages as well. Do not set the &lt;code&gt;DISPLAY&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;The vim that comes with MacOS is not very feature-rich. I need full scripting support (python, perl) at the very least. MacPorts provides variants of vim where you can put in all the features. With mutt, you also have to make sure to get the devel-version if you want decent features.&lt;/p&gt;

&lt;p&gt;Next, the xterm. The one that came with my MacOS X Leopard was perfectly fine. Specifically, it had the 256-colors support compiled in. As far as I know, not all previous editions of MacOS X had this. You could always compile your own from MacPorts. To activate the 256 colors, I make sure that the TERM variable is set to &amp;#8220;xterm-256colors&amp;#8221; in my &lt;code&gt;.bashrc&lt;/code&gt;. The terminus font is available from MacPorts as well. I had trouble installing it, though, since the link in the Portfile was broken. The solution was &lt;a href='http://trac.macports.org/wiki/ProblemHotlist#Fetchfailures'&gt;here&lt;/a&gt;. After installing the font, I had to create the &lt;code&gt;fonts.dir&lt;/code&gt; file using the &lt;code&gt;mkfontdir&lt;/code&gt; utility.&lt;/p&gt;

&lt;p&gt;Making the X-Server know about that font path was actually really hard. I tried doing &lt;code&gt;xset fp+ /opt/local/X11R6/lib/X11/fonts/local&lt;/code&gt; in my bashrc. This caused the X server not to start up at all. It turns out you cannot just put &lt;code&gt;xset&lt;/code&gt; commands in your &lt;code&gt;.bashrc&lt;/code&gt;. See my &lt;a href='http://discussions.apple.com/thread.jspa?threadID=1778092'&gt;discussion on the Apple Forum&lt;/a&gt; for the details. In the end, what I had to do was to edit the file &lt;code&gt;/usr/X11/lib/X11/xinit/xinitrc.d/10-fontdir.sh&lt;/code&gt; and add a line for the &lt;code&gt;/opt/local/X11R6/lib/X11/fonts/local/&lt;/code&gt; path. This is a change affecting all users, of course.&lt;/p&gt;

&lt;p&gt;I want the audible bell to be off. To do this, I added &lt;code&gt;xset -b&lt;/code&gt; near the beginning of&lt;code&gt;/usr/X11/lib/X11/xinit/xinitrc&lt;/code&gt;. Again, this cannot be set in your &lt;code&gt;.bashrc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, the keyboard. First, I made a custom keyboard layout, which goes into &lt;a href='usumlaut.keylayout'&gt;~/System/Keyboard Layouts/usumlaut.keylayout&lt;/a&gt;. You can change the layout with the &lt;a href='http://scripts.sil.org/ukelele'&gt;Ukelele&lt;/a&gt; program. After saving it in the right place (and possibly logging out and in again), you can activate the keyboard layout in &lt;code&gt;System Preference &amp;gt; International&lt;/code&gt; The keyboard layout does not yet include the remapping of Caps Lock. To do that, go to &lt;code&gt;System Preferences &amp;gt;
Keyboard &amp;gt;  Modifier Keys&lt;/code&gt; In order to have the keyboard layout active in xterm as well, you have to activate &amp;#8220;Follow system keyboard layout&amp;#8221; in the X11 Input Preferences. Finally, you also have to create a file &lt;code&gt;.inputrc&lt;/code&gt; in your home directory, with the following content:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;set meta-flag on
set convert-meta off
set output-meta on&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Copy and paste is a problem, too (&lt;strong&gt;Update&lt;/strong&gt;: not with iTerm!). I activate the &amp;#8220;Emulate three button mouse&amp;#8221; and &amp;#8220;Enable key equivalents under X11&amp;#8221; in the X11 Input Preferences. Inside X11, I do the normal copy/paste with the middle mouse button (if I have an external three-button USB mouse attached) or the Alt+Shift+Click combination (if I only have the touch pad). To copy from X11 to normal Mac applications, I select the text and hit Cmd+C for copy and then Cmd+V for paste in the other application. For the reverse, it&amp;#8217;s Cmd+C for copy and the middle click in X11. Note that copy/paste in vim only works if you do &amp;#8216;set mouse=&amp;#8217; temporarily. As an alternative, however, it is very nice to use the &lt;a href='http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/pbcopy.1.html'&gt;pbcopy&lt;/a&gt; and &lt;a href='http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/pbcopy.1.html'&gt;pbpaste&lt;/a&gt; utilities, e.g. in conjunction with my &lt;a href='http://michaelgoerz.net/blog/2008/09/integrating-vim-with-ipython/'&gt;send.vim&lt;/a&gt; script.&lt;/p&gt;

&lt;p&gt;At this point, I still had to activate UTF-8 for the terminal. All you have to do is to set the &lt;code&gt;LC_CTYPE&lt;/code&gt; environment variable to &lt;code&gt;en_US.UTF-8&lt;/code&gt;. You&amp;#8217;d think it&amp;#8217;s enough to declare it in your .bashrc - it&amp;#8217;s not! You have to create the file &lt;a href='environment.plist'&gt;&lt;code&gt;~/.MacOSX/environment.plist&lt;/code&gt;&lt;/a&gt; using the Property List Editor, and add it there as well. Setting this had the effect I could edit my UTF-8 textfiles with vim, and also solved the problem of mutt not showing accented characters correctly.&lt;/p&gt;

&lt;p&gt;One remaining problem with my current setup is that screen only works with 256 colors if you start it manually from an xterm. For ease of use, I&amp;#8217;d like to put a shortcut like &lt;code&gt;xterm -e &amp;#39;&amp;#39;screen -D -r || screen&amp;quot;&lt;/code&gt; in the &amp;#8220;Applications&amp;#8221; menu of X11, but then I only have the emulated subset of the full colors.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Setting Adium Status Messages with Quicksilver</title>
   <link href="blog/2008/11/setting-adium-status-messages-with-quicksilver/"/>
   <updated>2008-11-09T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/11/setting-adium-status-messages-with-quicksilver</id>
   <content type="html">&lt;p&gt;Switching from &lt;a href='http://www.pidgin.im/'&gt;Pidgin&lt;/a&gt; to &lt;a href='http://www.adiumx.com/'&gt;Adium&lt;/a&gt;, one missing feature was the saved status messages for different accounts. I have an ICQ account with only German contacts, and an AIM account with only American contacts. In Pidgin, I can create and save a status message &amp;#8220;Dining Hall&amp;#8221; that will set both accounts to away and set different status messages for each of them, e.g. &amp;#8220;Mensa&amp;#8221; for the ICQ and &amp;#8220;At the dining hall&amp;#8221; for AIM. In fact, I can save such collections of status data where both the status and the status message is different for any of my IM accounts.&lt;/p&gt;

&lt;p&gt;In Adium I can only define saved statuses with a single status and a single message, and then apply any of those saved statuses to any single account or to the entirety of all my accounts.&lt;/p&gt;

&lt;p&gt;However, with AppleScript, this is easy to add. The &lt;a href='http://trac.adiumx.com/wiki/AppleScript_Support_1.2'&gt;Adium&amp;#8217;s AppleScript API&lt;/a&gt; was a little hard to find, but once you have that, the rest is easy. For example, I&amp;#8217;ll create a script &lt;code&gt;AdiumDiningHall.applescript&lt;/code&gt; in &lt;code&gt;~/Library/Scripts&lt;/code&gt; with the following lines:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/osascript
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;micgoe01&amp;quot; to go online
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;175434867&amp;quot; to go online&amp;lt;/code&amp;gt;

tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;micgoe01&amp;quot; to go away
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;175434867&amp;quot; to go away

tell application &amp;quot;Adium&amp;quot; to set status message of account &amp;quot;micgoe01&amp;quot; to &amp;quot;At the dining hall&amp;quot;
tell application &amp;quot;Adium&amp;quot; to set status message of account &amp;quot;175434867&amp;quot; to &amp;quot;Mensa&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If I leave out the first part about going online, the status will only be set for accounts that are already online. I could also write a script that sets all accounts to Available:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/osascript
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;michaelgoerz@gmail.com&amp;quot; to go online
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;175434867&amp;quot; to go online&amp;lt;/code&amp;gt;

tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;micgoe01&amp;quot; to go available
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;175434867&amp;quot; to go available&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or one that signs out of all my accounts:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/osascript
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;micgoe01&amp;quot; to go offline
tell application &amp;quot;Adium&amp;quot; to tell the account &amp;quot;175434867&amp;quot; to go offline&amp;lt;/code&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The beauty of having these scripts in &lt;code&gt;~/Library/Scripts/&lt;/code&gt; is that they are available to &lt;a href='http://www.blacktree.com/'&gt;QuickSilver&lt;/a&gt;. I just hit Cmd+Space, type part of my script name, hit Enter, and my predefined status is set in Adium. It doesn&amp;#8217;t get any faster than that.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Some Fortran String Gotchas</title>
   <link href="blog/2008/10/some-string-gotchas/"/>
   <updated>2008-10-20T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/10/some-string-gotchas</id>
   <content type="html">&lt;p&gt;I fell on my nose the other day from a misunderstanding about how passing strings works in fortran.&lt;/p&gt;

&lt;p&gt;Consider the following program:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;implicit none
integer, parameter :: stringlength=100
character (len=10) :: a
character (len=10) :: b
character (len=stringlength) :: c

a = &amp;#39;Hello&amp;#39;
b = &amp;#39;World&amp;#39;
c = trim(a)//&amp;#39; &amp;#39;//trim(b)
call printstring(c)
call printstring(trim(a)//&amp;#39; &amp;#39;//trim(b))

contains

subroutine printstring(s)
character (len=stringlength) :: s ! this is a bug

write (*,*) &amp;quot;&amp;quot;
write (*,*) &amp;quot;len(s) = &amp;quot;, len(s)
if (s == &amp;#39;Hello World&amp;#39;) then
write (*,*) &amp;quot;s == &amp;#39;Hello World&amp;#39; is True&amp;quot;
else
write (*,*) &amp;quot;s == &amp;#39;Hello World&amp;#39; is False&amp;quot;
end if

write (*,*) &amp;#39;trim(s) = &amp;quot;&amp;#39;//trim(s)//&amp;#39;&amp;quot;&amp;#39;
end subroutine printstring

end program teststrings&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output of this program is the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;len(s) =          100
s == &amp;#39;Hello World&amp;#39; is True
trim(s) = &amp;quot;Hello World&amp;quot;

len(s) =          100
s == &amp;#39;Hello World&amp;#39; is False
trim(s) = &amp;quot;Hello WorldS,AF(sdfl0qhahsd j
i2S.F*df&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, if I change line 18 to&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;character (len=*) :: s&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I get this output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;len(s) =          100
s == &amp;#39;Hello World&amp;#39; is True
trim(s) = &amp;quot;Hello World&amp;quot;

len(s) =           11
s == &amp;#39;Hello World&amp;#39; is True
trim(s) = &amp;quot;Hello World&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This illustrates the following points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside subroutines, you must &lt;em&gt;always&lt;/em&gt; declare string dummy parameters as &lt;code&gt;character (len=*)&lt;/code&gt;. This is called &amp;#8216;assumed length&amp;#8217; (cf. Fortran 90 Handbook, section 12.5.1). The parameter will end up with the the same length as the variable or string that is passed to the subroutine. If you don&amp;#8217;t use &lt;code&gt;len=*&lt;/code&gt;, you will run into problems if the string that you pass to the subroutine is shorter than what you declared for dummy parameter. Not observing this rule can easily introduce serious bugs into your program.&lt;/li&gt;

&lt;li&gt;String comparisons between strings of different length work like this: The shorter string is padded on the right with spaces until it matches the length of the longer string. Then, both strings are compared. (cf. Fortran 90 Handbook, section 7.3.1.2). So, comparing strings of different length works, you don&amp;#8217;t have to use the trim function.&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Superkaramba StopTimer</title>
   <link href="blog/2008/10/superkaramba-stoptimer/"/>
   <updated>2008-10-12T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/10/superkaramba-stoptimer</id>
   <content type="html">&lt;p&gt;A while back, I was looking for an utility that would allow me to manage my studying time. Basically, a timer that I would set to a certain number of hours; then I&amp;#8217;d punch in when I was working, pausing it for breaks, and it&amp;#8217;d tell me when my hours are up. Also, I wanted it to be resistant to closing the application, or my computer crashing. I didn&amp;#8217;t find anything that did what I wanted. Not being too much into GUI programming, I tried doing it as a &lt;a href='http://netdragon.sourceforge.net/ssuperkaramba.html'&gt;Superkaramba&lt;/a&gt; widget. Thus, it&amp;#8217;s only for my KDE desktop, but it did the job. Here&amp;#8217;s a screenshot:&lt;/p&gt;
&lt;a href='http://users.physik.fu-berlin.de/~mgoerz/blog/wp-content/uploads/2008/10/stoptimer2.png'&gt;&lt;img alt='StopTimer Widget Screenshot' class='size-medium wp-image-357' height='188' src='http://users.physik.fu-berlin.de/~mgoerz/blog/wp-content/uploads/2008/10/stoptimer2.png' title='stoptimer2.png' width='233' /&gt;&lt;/a&gt;&lt;a href='http://users.physik.fu-berlin.de/~mgoerz/blog/wp-content/uploads/2008/10/stoptimer.png'&gt;&lt;img alt='StopTimer Widget Screenshot' class='size-full wp-image-356' height='188' src='http://users.physik.fu-berlin.de/~mgoerz/blog/wp-content/uploads/2008/10/stoptimer.png' title='stoptimer.png' width='233' /&gt;&lt;/a&gt;
&lt;p&gt;When stopped, you can set the start time by clicking on the time display and the &amp;#8220;alarm&amp;#8221; time by clicking on the lightening symbol. Not that the alarm time might be less than the start time: in this case, the clock runs backwards. To start the timer, click on the play button.&lt;/p&gt;

&lt;p&gt;When the timer is running, you can pause it by clicking any of the buttons. When paused, you can click the stop button to return to the stopped state, or the play button to continue running.&lt;/p&gt;

&lt;p&gt;The whole thing is basically a python script, with the necessary extra files for the superkaramba framework. Just the python code is here:&lt;/p&gt;

&lt;p&gt;&lt;a href='http://users.physik.fu-berlin.de/~mgoerz/blog/wp-content/uploads/2008/10/stoptimer.py'&gt;stoptimer.py&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the complete widget, you have to download and extract this archive:&lt;/p&gt;

&lt;p&gt;&lt;a href='http://users.physik.fu-berlin.de/~mgoerz/blog/wp-content/uploads/2008/10/stoptimer.tgz'&gt;stoptimer.tgz&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Basic idb usage</title>
   <link href="blog/2008/10/basic-idb-usage/"/>
   <updated>2008-10-08T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/10/basic-idb-usage</id>
   <content type="html">&lt;p&gt;I tried to use the debugger that comes with the intel fortran compiler (idb) to look at some code in detail. Here is the first steps I had to do to get it working:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;compile the program with the -g flag. To do this, I put the line FFLAGS = -g # DEBUGGING in the makefile (replaceing the existing definition of FFLAGS). The compilation resulted an executable CaGate, in my case.&lt;/li&gt;

&lt;li&gt;call &lt;code&gt;idb CaGate&lt;/code&gt;. Do not specify any command line options that you would normally call CaGate with. You should end up in the debugger, which shows an &amp;#8220;(idb)&amp;#8221; prompt.&lt;/li&gt;

&lt;li&gt;Set a breakpoint. To do this, issue the &lt;code&gt;break&lt;/code&gt; command to the debugger. If the main program was defined as &lt;code&gt;program CaGate&lt;/code&gt; in your source code, you could do &lt;code&gt;break CaGate&lt;/code&gt; to break at the beginning of the program. You could also specify a source file + line number as a breakpoint, e.g. &lt;code&gt;break
inout.f90:100&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;Run the program with the &lt;code&gt;run&lt;/code&gt; command. This is where you specify the command line parameters, too. In my case, I would normally run the program as &lt;code&gt;CaGate
runs/intens001&lt;/code&gt;, so for the debugger, I say &lt;code&gt;run runs/intens001&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;The program will stop at any breakpoint you specified. You can then use the &amp;#8220;next&amp;#8221; or &amp;#8220;step&amp;#8221; commands to go through the program line by line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For all the details of how to use the debugger, look at the documentation. On my system, it&amp;#8217;s at &lt;a href='file:///opt/intel10/doc/idb_manual/index.htm'&gt;file:///opt/intel10/doc/idb_manual/index.htm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There&amp;#8217;s also a &lt;code&gt;help&lt;/code&gt; command inside the debugger.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Vim Reference Card</title>
   <link href="blog/2008/09/vim-reference-card/"/>
   <updated>2008-09-29T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/09/vim-reference-card</id>
   <content type="html">&lt;p&gt;This is my reference card for the vim editor:&lt;/p&gt;

&lt;p&gt;&lt;a href='http://michaelgoerz.net/refcards/index.html#vim'&gt;Vim Reference Card&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>ASCII Table</title>
   <link href="blog/2008/09/ascii-table/"/>
   <updated>2008-09-29T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/09/ascii-table</id>
   <content type="html">&lt;p&gt;&lt;a href='ascii.gif'&gt;&lt;img alt='ascii table thumbnail' src='ascii-150x150.gif' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This ASCII table contains the regular character codes 0 - 127 and the extended character codes 128 - 255 in codepage 850. Every character is given as decimal, hexadecimal and binary.&lt;/p&gt;

&lt;p&gt;&lt;a href='ascii.pdf'&gt;ASCII Table&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Integrating VIM with IPython</title>
   <link href="blog/2008/09/integrating-vim-with-ipython/"/>
   <updated>2008-09-20T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/09/integrating-vim-with-ipython</id>
   <content type="html">&lt;p&gt;When writing python scripts, I often want to run some code snippets in &lt;a href='http://ipython.scipy.org/'&gt;ipython&lt;/a&gt; for testing/debugging purposes. Until now, the only way to do this was to copy and paste the code snippets from &lt;a href='http://www.vim.org/'&gt;vim&lt;/a&gt; to ipython. I wanted to have a way to send lines of text from vim to ipython directly.&lt;/p&gt;

&lt;p&gt;More generally, I wanted to send text from vim to any (text-based) application at all. Instead of ipython, this might be a &lt;a href='http://www.gnuplot.info/'&gt;gnuplot&lt;/a&gt; session, or a &lt;a href='http://www.wolfram.com/products/mathematica/index.html'&gt;Mathematica&lt;/a&gt; kernel.&lt;/p&gt;

&lt;p&gt;To do this sort of thing, I used a feature of &lt;a href='http://www.gnu.org/software/screen/'&gt;screen&lt;/a&gt;. If you have a program running inside a screen session, you can &lt;a href='http://aperiodic.net/screen/faq#how_to_send_a_command_to_a_window_in_a_running_screen_session_from_the_commandline'&gt;send arbitrary commands&lt;/a&gt; to it by executing something like &lt;code&gt;screen -S sessionname -p 0 -X stuff &amp;#39;command
to execute^M&amp;#39;&lt;/code&gt; So, all I had to do was to generate a call like that from vim.&lt;/p&gt;

&lt;p&gt;I split the job in two parts. First, there is a script that reads from stdin and sends every line it receives to a screen session. The script takes the -S and -p parameters with the same meaning as screen itself.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m calling it &lt;a href='send2screen.py'&gt;send2screen.py&lt;/a&gt;. (Update: April 15, 2009)&lt;/p&gt;

&lt;p&gt;Second, there is the vim plugin, which just takes a range and sends all the lines in the range to the stdin of an arbitrary program (for our purpose, that arbitrary program will be send2screen.py, of course)&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.vim.org/scripts/script.php?script_id=2608'&gt;http://www.vim.org/scripts/script.php?script_id=2608&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The plugin goes into &lt;a href='send.vim'&gt;~/.vim/plugins/send.vim&lt;/a&gt; (&lt;a href='http://michaelgoerz.net/blog/2009/04/integrating-vim-with-ipython-ii/'&gt;Update: April 15, 2009&lt;/a&gt; )&lt;/p&gt;

&lt;p&gt;To use it, I set the sendToProgramName variable in vim to point to send2screen.py appropriately (update: you also need to set the sendToProgramMode to &amp;#8216;ipython&amp;#8217;), select some text in visual mode, and do: : &amp;#8217;&amp;#60;,&amp;#8217;&amp;#62; python send() Or, to send the current line: : . python send() Of course, you could also map shortcuts to execute these commands.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>ifort compiler definition for vim</title>
   <link href="blog/2008/07/ifort-compiler-definition-for-vim/"/>
   <updated>2008-07-14T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/07/ifort-compiler-definition-for-vim</id>
   <content type="html">&lt;p&gt;I put together a very quick compiler script for using ifort in vim, from an error format pattern I found here: &lt;a href='http://vim.wikia.com/wiki/Errorformat_for_Intel_ifort'&gt;http://vim.wikia.com/wiki/Errorformat_for_Intel_ifort&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the script: &lt;a href='ifort.vim'&gt;ifort.vim&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Put it in &lt;code&gt;~/.vim/compiler&lt;/code&gt; and add the line &lt;code&gt;autocmd FileType fortran compiler
ifort&lt;/code&gt; to your .vimrc.&lt;/p&gt;

&lt;p&gt;The effect of this is that when you type &lt;code&gt;:make&lt;/code&gt; in vim, it will parse any error messages that &amp;#8216;make&amp;#8217; throws up and allow you to navigate between error lines (use &lt;code&gt;:copen&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;This isn&amp;#8217;t tested very thoroughly, but it seems to work.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Installing Wordpress</title>
   <link href="blog/2008/06/installing-wordpress/"/>
   <updated>2008-06-17T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/06/installing-wordpress</id>
   <content type="html">&lt;p&gt;Installing Wordpress turned out to be easy, basically just following the instructions at http://codex.wordpress.org/Installing_WordPress. The only thing that caused a little bit of trouble (after finding out that I had to email the ZEDV for MySQL login data) was that I had to specify the webserver (&amp;#8220;www&amp;#8221;) explicitly, whereas the Wordpress documentation assumes that the webserver is localhost. This meant two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For creating the mysql table I had to do&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mysql -u adminusername -p -h www&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;In &lt;code&gt;wp-config.php&lt;/code&gt; I had to change the line&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;define(&amp;#39;DB_HOST&amp;#39;, &amp;#39;localhost&amp;#39;);    // 99% chance you won&amp;#39;t need to change this value&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;define(&amp;#39;DB_HOST&amp;#39;, &amp;#39;www&amp;#39;);    // 99% chance you won&amp;#39;t need to change this value&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Vim Color Profile</title>
   <link href="blog/2008/05/vim-color-profile/"/>
   <updated>2008-05-25T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/05/vim-color-profile</id>
   <content type="html">&lt;p&gt;Since I didn&amp;#8217;t like any of the existing color profiles for vim (what&amp;#8217;d you expect), I wrote my own:&lt;/p&gt;

&lt;p&gt;&lt;a href='goerz.vim'&gt;goerz.vim&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s intended to be used mainly in a 256 color terminal (xterm with 256color support, which is my preferred way to run vim). It also works with gvim, and under 88 color terminals (not as perfect). You can see how it looks on this screenshot, which is vim running inside yakuake (which supports 256 colors):&lt;/p&gt;
&lt;a href='vimbig.png'&gt;&lt;img alt='Vim Screenshot' height='234' src='vimbig-300x234.png' title='vimbig' width='300' /&gt;&lt;/a&gt;</content>
 </entry>
 
 <entry>
   <title>xml_taginsert Vim Plugin</title>
   <link href="blog/2008/05/xml_taginsert-vim-plugin/"/>
   <updated>2008-05-23T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/05/xml_taginsert-vim-plugin</id>
   <content type="html">&lt;p&gt;I&amp;#8217;ve written a vim plugin that allows to easier editing of html/xml files. If you load the plugin, you can use &lt;code&gt;F7&lt;/code&gt; to insert tags.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.vim.org/scripts/script.php?script_id=2248'&gt;http://www.vim.org/scripts/script.php?script_id=2248&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Python Refcard</title>
   <link href="blog/2008/05/python-refcard/"/>
   <updated>2008-05-14T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/05/python-refcard</id>
   <content type="html">&lt;p&gt;This is my Python 2.5 reference card:&lt;/p&gt;

&lt;p&gt;&lt;a href='http://michaelgoerz.net/refcards/#python25'&gt;Python 2.5 Reference Card&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Vim LatexSuite Refcard</title>
   <link href="blog/2008/05/vim-latexsuite-refcard/"/>
   <updated>2008-05-11T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2008/05/vim-latexsuite-refcard</id>
   <content type="html">&lt;p&gt;This is my (unfinished) quick reference card for the &lt;a href='http://vim-latex.sourceforge.net/'&gt;LatexSuite&lt;/a&gt; plugin package for vim.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://michaelgoerz.net/refcards/#latexsuite'&gt;Vim LatexSuite Refcard&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>VIM Syntax File for TeX</title>
   <link href="blog/2008/03/vim-syntax-file-for-tex/"/>
   <updated>2008-03-30T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/03/vim-syntax-file-for-tex</id>
   <content type="html">&lt;p&gt;I wasn&amp;#8217;t quite happy with how the TeX syntax file looks that comes with VIM, so I modified it. I wanted section (subsection, etc.) titles to be emphasized so that I can see them easily while scrolling through the file.&lt;/p&gt;

&lt;p&gt;I also wanted spell check to be switched off for comments. Comments in TeX are usually disabled parts of text, with latex commands which will show up as spelling mistakes.&lt;/p&gt;

&lt;p&gt;&lt;a href='tex.vim'&gt;tex.vim&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Instuctions for TightVNC</title>
   <link href="blog/2008/03/instuctions-for-tightvnc/"/>
   <updated>2008-03-12T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/03/instuctions-for-tightvnc</id>
   <content type="html">&lt;p&gt;This guide will show you how to install &lt;a href='http://www.tightvnc.com/index.html'&gt;TightVNC&lt;/a&gt; on your Windows computer. TightVNC is a remote control software that allows you to give me temporary access to your computer for maintenance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Download the installation programm. The following screenshots are from the installation of &lt;a href='http://downloads.sourceforge.net/vnc-tight/tightvnc-1.3.9-setup.exe'&gt;tightvnc-1.3.9-setup.exe&lt;/a&gt;. If you want to use a newer version, there shouln&amp;#8217;t be too many problems.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Install the software as shown on the screenshots&lt;/p&gt;

&lt;p&gt;&lt;a href='vnc01.png'&gt;&lt;img alt='vnc01' src='vnc01-300x227.png' /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Just keep clicking &amp;#8220;next&amp;#8221;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href='vnc06.png'&gt;&lt;img alt='vnc06' src='vnc06-300x227.png' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#8230; and complete the installation.&lt;/p&gt;

&lt;p&gt;&lt;a href='vnc07.png'&gt;&lt;img alt='vnc07' src='vnc07-300x227.png' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Usually, you will not have to restart your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href='vnc08.png'&gt;&lt;img alt='vnc08' src='vnc08-300x227.png' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Start the VPNServer from the start menu&lt;/p&gt;

&lt;p&gt;&lt;a href='vnc09.png'&gt;&lt;img alt='vnc09' src='vnc09-300x194.png' /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;If the program requires you to make any settings, you can use the following:&lt;/p&gt;

&lt;p&gt;&lt;a href='vnc12.png'&gt;&lt;img alt='vnc12' src='vnc12-300x179.png' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can choose any password you like for &amp;#8220;Password&amp;#8221; and &amp;#8220;Password (view only)&amp;#8221;, it will not be needed. Then disable &amp;#8220;Accept socket connections&amp;#8221;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Open a connection to a new client by right clicking the tray icon. You have to enter my client&amp;#8217;s adress, which I will give you.&lt;/p&gt;

&lt;p&gt;If my client is running, I can now remotely control your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href='vnc10.png'&gt;&lt;img alt='vnc10' src='vnc10.png' /&gt;&lt;/a&gt; &lt;a href='vnc11.png'&gt;&lt;img alt='vnc11' src='vnc11-300x102.png' /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Commenting PDF files with Adobe Reader</title>
   <link href="blog/2008/03/commenting-pdf-files/"/>
   <updated>2008-03-11T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/03/commenting-pdf-files</id>
   <content type="html">&lt;p&gt;This guide will show you how to add comments to PDF files, using &lt;a href='http://www.adobe.com/products/acrobat/readstep2.html'&gt;Adobe Reader&lt;/a&gt;. The guide applies to version 8 of the Reader, but the procedure should be the same with slightly older versions.&lt;/p&gt;

&lt;p&gt;Commenting is not a general feature of the free Reader software; it has to be enabled for a specific PDF file from the full commercial Adobe Acrobat program. If you receive a PDF file in which I have enabled commenting, the reader will display the Review &amp;#38; Comment tools. You can use the commenting tools to add text edits or sticky notes to the PDF. Use sticky notes only for general comments that are not localized to a specific position in the text. You can also review existing comments, and add replies to them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Enable the Comment &amp;#38; Markup Toolbar&lt;/p&gt;

&lt;p&gt;When the PDF file has commenting enabled, you will probably see the &lt;code&gt;Review &amp;gt; Comment&lt;/code&gt; button. To get full access to all commenting tools (especially text edits), you should enabled to full toolbar.&lt;/p&gt;
&lt;a href='01_activate_toolbar.png'&gt;&lt;img alt='Enable the Comment &amp;amp; Markup Toolbar' height='445' src='01_activate_toolbar.png' title='01_activate_toolbar' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;You will see a toolbar that looks like this:&lt;/p&gt;
&lt;a href='02_toolbar.png'&gt;&lt;img alt='Toolbar' height='40' src='02_toolbar.png' title='02_toolbar' width='500' /&gt;&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Make text edits&lt;/p&gt;

&lt;p&gt;The best way to indicate changes of the text is to use the Text Edits tool. When you click on the Text Edits button, you will see a brief help message that explains the process.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Basically, adding appropriate comments is just like editing the text in a word processor. Set the cursor, and type.&lt;/p&gt;
&lt;a href='03_text_edits.png'&gt;&lt;img alt='Make text edits ' height='445' src='03_text_edits.png' title='03_text_edits' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;For example, you can select some text and type in a replacement:&lt;/p&gt;
&lt;a href='04_replacement.png'&gt;&lt;img alt='Replacements' height='300' src='04_replacement.png' title='04_replacement' width='400' /&gt;&lt;/a&gt;
&lt;p&gt;After you are finished, the comment will look like this:&lt;/p&gt;
&lt;a href='05_replacement_done.png'&gt;&lt;img alt='Finished replacement' height='300' src='05_replacement_done.png' title='05_replacement_done' width='400' /&gt;&lt;/a&gt;
&lt;p&gt;You can also add text at a specific position (see the blue insertion mark) or delete it (red striked-out).&lt;/p&gt;
&lt;a href='06_insert_delete.png'&gt;&lt;img alt='Insertion and deletion' height='357' src='06_insert_delete.png' title='06_insert_delete' width='457' /&gt;&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Add Sticky Notes&lt;/p&gt;

&lt;p&gt;For general comments that are not connected to a very specific text position, you can add Sticky Notes.&lt;/p&gt;
&lt;a href='07_sticky_note.png'&gt;&lt;img alt='Add sticky notes' height='445' src='07_sticky_note.png' title='07_sticky_note' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;There is also a variant of the Sticky Notes that is localized to text as a part of the Text Edits tool: select some texts and then click and hold the Text Edits button to see it. Using a localized Sticky Notes may be more appropriate in most situations.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Review Comments&lt;/p&gt;

&lt;p&gt;You can see existing comments when you open the apropriate panel at the bottom of the screen.&lt;/p&gt;
&lt;a href='08_view_notes.png'&gt;&lt;img alt='Review comments' height='445' src='08_view_notes.png' title='08_view_notes' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;Each comment is saved with the name of the user that made the comment. This way, a PDF document can be sent back and forth between reviewers, each adding and modifying comments.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Reply to Comments&lt;/p&gt;

&lt;p&gt;Specifically, you can add replies to a comment another reviewer has made. You right-click the comment and selecting Reply&lt;/p&gt;
&lt;a href='09_reply.png'&gt;&lt;img alt='Reply to comments' height='445' src='09_reply.png' title='09_reply' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;You can then add you own comment in a tree-like fashion.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Save the PDF&lt;/p&gt;

&lt;p&gt;When you are done, you can save the PDF to create a new file that includes all the comments. The saved file will still have commenting enabled.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Perl Refcard</title>
   <link href="blog/2008/02/perl-refcard/"/>
   <updated>2008-02-01T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2008/02/perl-refcard</id>
   <content type="html">&lt;p&gt;This is my Perl Reference Card:&lt;/p&gt;

&lt;p&gt;&lt;a href='http://michaelgoerz.net/refcards/#perl'&gt;Perl Reference Card&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>GSP Tools Macro Set </title>
   <link href="blog/2007/09/gsp-tools-macro-set/"/>
   <updated>2007-09-24T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2007/09/gsp-tools-macro-set</id>
   <content type="html">&lt;p&gt;I wrote a collection of macros for MSWord to aid in formatting documents for &lt;a href='http://www.gsp-online.org/'&gt;GSP&lt;/a&gt; journals.&lt;/p&gt;

&lt;p&gt;The GSP Tools Macro Set contains&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A number of MS Word 2003 macros that assist in formatting GSP material&lt;/li&gt;

&lt;li&gt;A menu bar that gives access to the macros.&lt;/li&gt;

&lt;li&gt;A number of standard styles that should be used for GSP journals&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id='download'&gt;Download&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='gspmacros.dot'&gt;GSPMacros.dot&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id='installation_and_template_use'&gt;Installation and Template Use&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Download the .dot-template file above. You can put it in your default template folder if you like, which is usually at &lt;code&gt;C:\Documents and Settings\username\Application Data\Microsoft\Templates&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Create New File from the Template. If you saved the template in the default template folder, you can got to &lt;code&gt;File &amp;gt; New&lt;/code&gt; and then click on &lt;code&gt;On my computer&lt;/code&gt; in the Templates-section of the appearing sidebar. The template should appear in the list there.&lt;/li&gt;
&lt;/ul&gt;
&lt;img alt='Screenshot' src='01.jpg' /&gt;
&lt;p&gt;Alternatively, if you did not save in the default location, you can go to you hard drive and double click the template file. This will automatically create a new Word file.&lt;/p&gt;

&lt;h4 id='apply_template_to_existing_file'&gt;Apply Template to Existing File&lt;/h4&gt;

&lt;p&gt;If you are working on an existing file, e.g. an article that needs to be cleaned up, and you would like to use the macros and styles of the GSP Macro Set, you can do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Go to Tools &amp;#62; Templates and Add-Ins, click on &amp;#8220;Attach&amp;#8221; and select the template file&lt;/p&gt;
&lt;img alt='Screenshot' src='02.png' /&gt;&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;If you would like to use the styles in the template, check &amp;#8220;Automatically update document styles&amp;#8221;. This may cause a lot of clutter in the Styles and Formatting list, however, since the document will retain its current formatting, and created modified styles to accommodate that.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;For importing or exporting Styles or Macros from the template file to any other Word document, you can use the Organizer tool which you find at the bottom of the Templates and Add-Ins dialog.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If everything went fine while applying the template, you should now have the macros at your disposal.&lt;/p&gt;

&lt;p&gt;Also, the GSPTools toolbar should be visible (or you may have to enable it).&lt;/p&gt;
&lt;img alt='Screenshot' src='03.gif' /&gt;&lt;img alt='Screenshot' src='04.png' /&gt;
&lt;p&gt;All macros can be accessed from the menu in the toolbar. The most important macro is &amp;#8220;FullCleanup&amp;#8221;, which executes everything in the Individual-Cleanups-submenu. The function of all other macros should be pretty self-explanatory from their menu names.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Immortality</title>
   <link href="blog/2007/03/immortality/"/>
   <updated>2007-03-06T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2007/03/immortality</id>
   <content type="html">&lt;p&gt;Here&amp;#8217;s the handout of a lecture on immortality that I gave at Hofstra University on March 5th, 2007&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='immortality_handout.pdf'&gt;immortality_handout.pdf&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='immortality_handout.tex'&gt;immortality_handout.tex&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>pdfWriteBookmarks</title>
   <link href="blog/2006/03/pdfwritebookmarks/"/>
   <updated>2006-03-21T00:00:00+01:00</updated>
   <id>http://litanyagainstfear.comblog/2006/03/pdfwritebookmarks</id>
   <content type="html">&lt;p&gt;Since I frequently want to add bookmarks to a scanned PDF (e.g. my lecture notes), I wrote a small Java program that reads bookmarks from a text file in a simple format and adds them to an exisiting PDF.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://github.com/goerz/pdfWriteBookmarks'&gt;pdfWriteBookmarks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The program is accompanied with a Python script that can modify the bookmarks in the textfile and convert them to other formats&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://github.com/goerz/bmconverter.py'&gt;bmconverter.py&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Mathematica Assumptions</title>
   <link href="blog/2005/04/mathematica-assumptions/"/>
   <updated>2005-04-30T00:00:00+02:00</updated>
   <id>http://litanyagainstfear.comblog/2005/04/mathematica-assumptions</id>
   <content type="html">&lt;p&gt;The following Notebook explains how to tell &lt;em&gt;Mathematica&lt;/em&gt; that a variable represents a real number, is greater than zero, or similar conditions.&lt;/p&gt;

&lt;p&gt;&lt;a href='assumptions.nb'&gt;assumptions.nb&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 
</feed>

