<!-- !This file uses the Genshi template language: http://genshi.edgewall.org/wiki/Documentation/xml-templates.html -->
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/">
    <py:def function="attributes(attrs)">
        <dl py:if="attrs" class="attributes">
            <py:for each="k, v in attrs.items()">
                <dt>${k}</dt>
                <dd py:choose="">
                    <py:when test="isinstance(v, dict)">${attributes(v)}</py:when>
                    <py:otherwise>${v}</py:otherwise>
                </dd>
            </py:for>
        </dl>
    </py:def>

    <div py:def="children(var)" class="children">
        <fieldset py:for="child in var.walk()">
            <legend>${child.name}</legend>

            <?python
                from pydap.model import *
            ?>
            <py:choose test="">
                <p py:when="isinstance(child, SequenceType)" class="filter">
                    <select class="var1" name="var1_${child.id}[0]" id="var1_${child.id}[0]">
                        <option value="--" selected="selected">--</option>
                        <option py:for="grandchild in child.walk()" value="${grandchild.id}">${grandchild.id}</option>
                    </select>
                    <select class="op" name="op_${child.id}[0]" id="op_${child.id}[0]">
                        <option value="%3D" selected="selected">=</option>
                        <option value="%21%3D">!=</option>
                        <option value="%3C">&lt;</option>
                        <option value="%3C%3D">&lt;=</option>
                        <option value="%3E">&gt;</option>
                        <option value="%3E%3D">&gt;=</option>
                        <option value="%3D%7E">=~</option>
                    </select>
                    <input type="text" name="var2_${child.id}[0]" id="var2_${child.id}[0]" value="" class="var2" />
                </p>
                <div py:when="isinstance(child, (BaseType, GridType))">
                    <p><input type="checkbox" name="${child.id}" id="${child.id}" />
                        <label for="${child.id}">Retrieve this variable<py:if test="child.shape"> at indices (start, step, stop)</py:if>:</label>
                    </p>
                    <?python 
                        dimensions = child.dimensions or ['dim_%id' % j for j in range(len(child.shape))]
                    ?>
                    <div py:for="i in range(len(child.shape))">
                        <label for="${child.id}[${i}]">${dimensions[i]}</label>:<br />
                        <input type="text" name="${child.id}[${i}]" id="${child.id}[${i}]" value="0:1:${child.shape[i]-1}" /><br />
                    </div>
                </div>
            </py:choose>

            ${attributes(child.attributes)}
            <py:if test="not isinstance(child, GridType)">
                ${children(child)}
            </py:if>
        </fieldset>
    </div>

    <head>
        <title>Pydap server: ${dataset.name}</title>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <link type="text/css" href="${root}/.static/css/smoothness/jquery-ui-1.7.1.custom.css" rel="stylesheet" />  
        <link type="text/css" href="${root}/.static/css/default.css" rel="stylesheet" />  
        <script type="text/javascript" src="${root}/.static/js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="${root}/.static/js/jquery-ui-1.7.1.custom.min.js"></script>
        <script type="text/javascript" src="${root}/.static/js/OpenLayers/OpenLayers.js"></script>
        <script type="text/javascript" src="${root}/.static/js/html_form.js"></script>
    </head>

    <body>
        <div id="main">
            <h1>Download data from <code>${dataset.name}</code></h1>

            <hr />
            <p><a href="${base}/"><img src="${root}/.static/images/folder_explore.png" />Parent directory</a></p>

            <!-- Global attributes -->
            <h2>Global attributes</h2>
            ${attributes(dataset.attributes)}

            <hr />

            <div id="tabs">
                <ul>
                    <li><a href="#html" title="Download data using an HTML form"><span>HTML form</span></a></li>
                    <li py:if="'wms' in responses"><a href="#wms" title="Visualize data on a map"><span>Map</span></a></li>
                    <li><a href="#ferret" title="Download data using Ferret"><span>Ferret</span></a></li>
                    <li><a href="#grads" title="Download data using GrADS"><span>GrADS</span></a></li>
                    <li><a href="#idl" title="Download data using IDL"><span>IDL</span></a></li>
                    <li><a href="#pydap" title="Download data using Pydap"><span>Pydap</span></a></li>
                    <li><a href="#other" title="Download data with a different Opendap client"><span>Other clients</span></a></li>
                </ul>

                <div id="html">
                    <h2>Downloading data</h2>
                    <p>In the form below you can specify desired variables and their dimensions, and have the data downloaded in different formats depending on the server configuration.</p>

                    <form id="dods_form" method="post" action="${location}">
                        <!-- Dataset variables -->
                        ${children(dataset)}

                        <p><input type="submit" id="submit" value="Download data" /> as 
                        <select id="response" name="response">
                            <option value="ascii" selected="selected">ASCII</option>
                            <option py:for="response in responses" value="$response">$response</option>
                        </select>
                        <br /><input type="reset" value="Reset" /></p>
                    </form>
                </div>

                <div id="ferret">
                    <h2>Downloading data with Ferret</h2>
                    <p>To access this dataset with the <a href="http://ferret.pmel.noaa.gov/Ferret/">Ferret</a> visualization and analysis environment from <a href="http://www.pmel.noaa.gov/">PMEL</a>:</p>

                    <pre><code>$ ferret
yes? use "${location[:-5]}"
yes? show data</code></pre>
                </div>

                <div id="grads">
                    <h2>Downloading data with GrADS</h2>
                    <p>To access this dataset with the <a href="http://www.iges.org/grads/">GrADS</a> data analysis and visualization software developed by <a href="http://www.iges.org/cola.html">COLA</a>:</p>

                    <pre><code>$ gradsdap
ga-&gt; sdfopen ${location[:-5]}
ga-&gt; query file</code></pre>
                </div>

                <div id="idl">
                    <h2>Downloading data with IDL</h2>
                    <p>To access this dataset with the <a href="http://opendap.org/download/idl-client.html">OPeNDAP IDL Client</a>, a tool for the <a href="http://www.ittvis.com/ProductServices/IDL.aspx">IDL</a> data analysis and visualization package:</p>

                    <pre><code>IDL&gt; url = '${location[:-5]}'
IDL&gt; stat = opendap_get(url, def, mode='dds')
IDL&gt; help, def, /structures</code></pre>
                </div>

                <div id="pydap">
                    <h2>Downloading data with Pydap</h2>
                    <p>To access this dataset using the <a href="http://pydap.org/">Pydap</a> Python module:</p>

                    <pre><code>$ python
&gt;&gt;&gt; from pydap.client import open_url
&gt;&gt;&gt; dataset = open_url("${location[:-5]}")
&gt;&gt;&gt; print dataset.keys()
${str(dataset.keys())}</code></pre>
                </div>

                <div id="other">
                    <h2>Downloading data with other Opendap clients</h2>
                    <p>There are other <a href="http://www.opendap.org/faq/whatClients.html">Opendap clients</a> that can access this dataset, including Matlab and several command line utilities. You should know that the URL for this dataset is <code>${location[:-5]}</code> (i.e., the <code>.html</code> extension should be omitted when opening this dataset on an Opendap client).</p>
                </div>

                <div id="wms">
                    <div id="map"></div>
                </div>
            </div>

            <hr />
            <p class="footnote"><em><a href="http://pydap.org/">pydap/$version</a></em></p>
        </div>
    </body>
</html>

<!--! vim:ft=genshi
-->
