<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libdap++: ce_functions.cc Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">libdap++ <span id="projectnumber">Updated for version 3.8.2</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('ce__functions_8cc.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <h1>ce_functions.cc</h1> </div> </div> <div class="contents"> <a href="ce__functions_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// -*- mode: c++; c-basic-offset:4 -*-</span> <a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="comment">// This file is part of libdap, A C++ implementation of the OPeNDAP Data</span> <a name="l00004"></a>00004 <span class="comment">// Access Protocol.</span> <a name="l00005"></a>00005 <a name="l00006"></a>00006 <span class="comment">// Copyright (c) 2002,2003 OPeNDAP, Inc.</span> <a name="l00007"></a>00007 <span class="comment">// Author: James Gallagher <jgallagher@opendap.org></span> <a name="l00008"></a>00008 <span class="comment">//</span> <a name="l00009"></a>00009 <span class="comment">// This library is free software; you can redistribute it and/or</span> <a name="l00010"></a>00010 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span> <a name="l00011"></a>00011 <span class="comment">// License as published by the Free Software Foundation; either</span> <a name="l00012"></a>00012 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span> <a name="l00013"></a>00013 <span class="comment">//</span> <a name="l00014"></a>00014 <span class="comment">// This library is distributed in the hope that it will be useful,</span> <a name="l00015"></a>00015 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00016"></a>00016 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00017"></a>00017 <span class="comment">// Lesser General Public License for more details.</span> <a name="l00018"></a>00018 <span class="comment">//</span> <a name="l00019"></a>00019 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span> <a name="l00020"></a>00020 <span class="comment">// License along with this library; if not, write to the Free Software</span> <a name="l00021"></a>00021 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span> <a name="l00022"></a>00022 <span class="comment">//</span> <a name="l00023"></a>00023 <span class="comment">// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.</span> <a name="l00024"></a>00024 <a name="l00025"></a>00025 <span class="comment">// (c) COPYRIGHT URI/MIT 1999</span> <a name="l00026"></a>00026 <span class="comment">// Please read the full copyright statement in the file COPYRIGHT_URI.</span> <a name="l00027"></a>00027 <span class="comment">//</span> <a name="l00028"></a>00028 <span class="comment">// Authors:</span> <a name="l00029"></a>00029 <span class="comment">// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu></span> <a name="l00030"></a>00030 <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="comment">// These functions are used by the CE evaluator</span> <a name="l00033"></a>00033 <span class="comment">//</span> <a name="l00034"></a>00034 <span class="comment">// 1/15/99 jhrg</span> <a name="l00035"></a>00035 <a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="config_8h.html">config.h</a>"</span> <a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="keyword">static</span> <span class="keywordtype">char</span> rcsid[]<a class="code" href="config_8h.html#a05e109ec893d0b12023d5b0cf4f718c4">not_used</a> = <a name="l00039"></a>00039 { <span class="stringliteral">"$Id: ce_functions.cc 23551 2010-09-13 21:00:46Z jimg $"</span> <a name="l00040"></a>00040 }; <a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="preprocessor">#include <limits.h></span> <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="preprocessor">#include <cstdlib></span> <span class="comment">// used by strtod()</span> <a name="l00045"></a>00045 <span class="preprocessor">#include <cerrno></span> <a name="l00046"></a>00046 <span class="preprocessor">#include <cmath></span> <a name="l00047"></a>00047 <span class="preprocessor">#include <iostream></span> <a name="l00048"></a>00048 <span class="preprocessor">#include <vector></span> <a name="l00049"></a>00049 <span class="preprocessor">#include <algorithm></span> <a name="l00050"></a>00050 <a name="l00051"></a>00051 <span class="comment">//#define DODS_DEBUG</span> <a name="l00052"></a>00052 <a name="l00053"></a>00053 <span class="preprocessor">#include "<a class="code" href="BaseType_8h.html">BaseType.h</a>"</span> <a name="l00054"></a>00054 <span class="preprocessor">#include "<a class="code" href="Byte_8h.html">Byte.h</a>"</span> <a name="l00055"></a>00055 <span class="preprocessor">#include "<a class="code" href="Int16_8h.html">Int16.h</a>"</span> <a name="l00056"></a>00056 <span class="preprocessor">#include "<a class="code" href="UInt16_8h.html">UInt16.h</a>"</span> <a name="l00057"></a>00057 <span class="preprocessor">#include "<a class="code" href="Int32_8h.html">Int32.h</a>"</span> <a name="l00058"></a>00058 <span class="preprocessor">#include "<a class="code" href="UInt32_8h.html">UInt32.h</a>"</span> <a name="l00059"></a>00059 <span class="preprocessor">#include "<a class="code" href="Float32_8h.html">Float32.h</a>"</span> <a name="l00060"></a>00060 <span class="preprocessor">#include "<a class="code" href="Float64_8h.html">Float64.h</a>"</span> <a name="l00061"></a>00061 <span class="preprocessor">#include "<a class="code" href="Str_8h.html">Str.h</a>"</span> <a name="l00062"></a>00062 <span class="preprocessor">#include "<a class="code" href="Url_8h.html">Url.h</a>"</span> <a name="l00063"></a>00063 <span class="preprocessor">#include "<a class="code" href="Array_8h.html">Array.h</a>"</span> <a name="l00064"></a>00064 <span class="preprocessor">#include "<a class="code" href="Structure_8h.html">Structure.h</a>"</span> <a name="l00065"></a>00065 <span class="preprocessor">#include "<a class="code" href="Sequence_8h.html">Sequence.h</a>"</span> <a name="l00066"></a>00066 <span class="preprocessor">#include "<a class="code" href="Grid_8h.html">Grid.h</a>"</span> <a name="l00067"></a>00067 <span class="preprocessor">#include "<a class="code" href="Error_8h.html">Error.h</a>"</span> <a name="l00068"></a>00068 <span class="preprocessor">#include "<a class="code" href="RValue_8h.html">RValue.h</a>"</span> <a name="l00069"></a>00069 <a name="l00070"></a>00070 <span class="preprocessor">#include "<a class="code" href="GSEClause_8h.html">GSEClause.h</a>"</span> <a name="l00071"></a>00071 <span class="preprocessor">#include "<a class="code" href="GridGeoConstraint_8h.html">GridGeoConstraint.h</a>"</span> <a name="l00072"></a>00072 <span class="preprocessor">#include "<a class="code" href="ArrayGeoConstraint_8h.html">ArrayGeoConstraint.h</a>"</span> <a name="l00073"></a>00073 <a name="l00074"></a>00074 <span class="preprocessor">#include "<a class="code" href="ce__functions_8h.html">ce_functions.h</a>"</span> <a name="l00075"></a>00075 <span class="preprocessor">#include "<a class="code" href="gse__parser_8h.html">gse_parser.h</a>"</span> <a name="l00076"></a>00076 <span class="preprocessor">#include "gse.tab.hh"</span> <a name="l00077"></a>00077 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">debug.h</a>"</span> <a name="l00078"></a>00078 <span class="preprocessor">#include "<a class="code" href="util_8h.html">util.h</a>"</span> <a name="l00079"></a>00079 <a name="l00080"></a>00080 <span class="comment">// We wrapped VC++ 6.x strtod() to account for a short coming</span> <a name="l00081"></a>00081 <span class="comment">// in that function in regards to "NaN". I don't know if this</span> <a name="l00082"></a>00082 <span class="comment">// still applies in more recent versions of that product.</span> <a name="l00083"></a>00083 <span class="comment">// ROM - 12/2007</span> <a name="l00084"></a>00084 <span class="preprocessor">#ifdef WIN32</span> <a name="l00085"></a>00085 <span class="preprocessor"></span><span class="preprocessor">#include <limits></span> <a name="l00086"></a>00086 <span class="keywordtype">double</span> w32strtod(<span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">char</span> **); <a name="l00087"></a>00087 <span class="preprocessor">#endif</span> <a name="l00088"></a>00088 <span class="preprocessor"></span> <a name="l00089"></a>00089 <span class="keyword">using namespace </span>std; <a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="keywordtype">int</span> <a class="code" href="ce__functions_8cc.html#a504da9793f63a21e40595b1f63ae26e0">gse_parse</a>(<span class="keywordtype">void</span> *arg); <a name="l00092"></a>00092 <span class="keywordtype">void</span> <a class="code" href="ce__functions_8cc.html#ac5920db2a87cb7ceb844e9086cfc50a6">gse_restart</a>(FILE * in); <a name="l00093"></a>00093 <a name="l00094"></a>00094 <span class="comment">// Glue routines declared in gse.lex</span> <a name="l00095"></a>00095 <span class="keywordtype">void</span> <a class="code" href="ce__functions_8cc.html#a5d32622eac5582fdf39183af4b9e01ef">gse_switch_to_buffer</a>(<span class="keywordtype">void</span> *new_buffer); <a name="l00096"></a>00096 <span class="keywordtype">void</span> <a class="code" href="ce__functions_8cc.html#a98d472c04ecf1e180f0f81df7e688a8e">gse_delete_buffer</a>(<span class="keywordtype">void</span> *buffer); <a name="l00097"></a>00097 <span class="keywordtype">void</span> *<a class="code" href="ce__functions_8cc.html#a0f1967b84ee5e7c8ab88368e3a769b26">gse_string</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *yy_str); <a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="keyword">namespace </span>libdap { <a name="l00100"></a>00100 <a name="l00102"></a><a class="code" href="namespacelibdap.html#a7e55035aed27d6e56f7219405c803628">00102</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespacelibdap.html#a7e55035aed27d6e56f7219405c803628">double_eq</a>(<span class="keywordtype">double</span> lhs, <span class="keywordtype">double</span> rhs, <span class="keywordtype">double</span> epsilon = 1.0e-5) <a name="l00103"></a>00103 { <a name="l00104"></a>00104 <span class="keywordflow">if</span> (lhs > rhs) <a name="l00105"></a>00105 <span class="keywordflow">return</span> (lhs - rhs) < ((lhs + rhs) / epsilon); <a name="l00106"></a>00106 <span class="keywordflow">else</span> <a name="l00107"></a>00107 <span class="keywordflow">return</span> (rhs - lhs) < ((lhs + rhs) / epsilon); <a name="l00108"></a>00108 } <a name="l00109"></a>00109 <a name="l00117"></a><a class="code" href="namespacelibdap.html#aca7eee077ab6dadb25126a92cf82737a">00117</a> <span class="keywordtype">string</span> <a class="code" href="namespacelibdap.html#aca7eee077ab6dadb25126a92cf82737a">extract_string_argument</a>(<a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> * arg) <a name="l00118"></a>00118 { <a name="l00119"></a>00119 <span class="keywordflow">if</span> (arg-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() != <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ad620cef0bf41edebd4ee802071192a79">dods_str_c</a>) <a name="l00120"></a>00120 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>, <a name="l00121"></a>00121 <span class="stringliteral">"The function requires a DAP string argument."</span>); <a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="keywordflow">if</span> (!arg-><a class="code" href="classlibdap_1_1BaseType.html#a38ff819a432217c55db2e9071928d20c" title="Has this variable been read?">read_p</a>()) <a name="l00124"></a>00124 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00125"></a>00125 <span class="stringliteral">"The CE Evaluator built an argument list where some constants held no values."</span>); <a name="l00126"></a>00126 <a name="l00127"></a>00127 <span class="keywordtype">string</span> s = <span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1Str.html#ad1c8898d979786da1699677c04264aa1">value</a>(); <a name="l00128"></a>00128 <a name="l00129"></a>00129 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"s: "</span> << s << endl); <a name="l00130"></a>00130 <a name="l00131"></a>00131 <span class="keywordflow">return</span> s; <a name="l00132"></a>00132 } <a name="l00133"></a>00133 <span class="keyword">template</span><<span class="keyword">class</span> T> <span class="keyword">static</span> <span class="keywordtype">void</span> set_array_using_double_helper(Array * a, <a name="l00134"></a>00134 <span class="keywordtype">double</span> *src, <span class="keywordtype">int</span> src_len) <a name="l00135"></a>00135 { <a name="l00136"></a>00136 T *values = <span class="keyword">new</span> T[src_len]; <a name="l00137"></a>00137 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < src_len; ++i) <a name="l00138"></a>00138 values[i] = (T) src[i]; <a name="l00139"></a>00139 <a name="l00140"></a>00140 <span class="preprocessor">#ifdef VAL2BUF</span> <a name="l00141"></a>00141 <span class="preprocessor"></span> a->val2buf(values, <span class="keyword">true</span>); <a name="l00142"></a>00142 <span class="preprocessor">#else</span> <a name="l00143"></a>00143 <span class="preprocessor"></span> a->set_value(values, src_len); <a name="l00144"></a>00144 <span class="preprocessor">#endif</span> <a name="l00145"></a>00145 <span class="preprocessor"></span> <a name="l00146"></a>00146 <span class="keyword">delete</span>[]values; <a name="l00147"></a>00147 } <a name="l00148"></a>00148 <a name="l00166"></a><a class="code" href="namespacelibdap.html#a5d52ca5c40dd022353469e7b5d8a9ad4">00166</a> <span class="keywordtype">void</span> <a class="code" href="namespacelibdap.html#a5d52ca5c40dd022353469e7b5d8a9ad4">set_array_using_double</a>(<a class="code" href="classlibdap_1_1Array.html" title="A multidimensional array of identical data types.">Array</a> * dest, <span class="keywordtype">double</span> *src, <span class="keywordtype">int</span> src_len) <a name="l00167"></a>00167 { <a name="l00168"></a>00168 <span class="comment">// Simple types are Byte, ..., Float64, String and Url.</span> <a name="l00169"></a>00169 <span class="keywordflow">if</span> ((dest-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ada8f5df7bb2bc72327fcd16af811562f">dods_array_c</a> && !dest-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#a614ce462dc6236791630f373bf75ad49" title="Returns true if the instance is a numeric, string or URL type variable.">is_simple_type</a>()) <a name="l00170"></a>00170 || dest-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ad620cef0bf41edebd4ee802071192a79">dods_str_c</a> <a name="l00171"></a>00171 || dest-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a64d653d09a50d6d17537c43ed217f665">dods_url_c</a>) <a name="l00172"></a>00172 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00173"></a>00173 <span class="stringliteral">"The function requires a DAP numeric-type array argument."</span>); <a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="comment">// Test sizes. Note that Array::length() takes any constraint into account</span> <a name="l00176"></a>00176 <span class="comment">// when it returns the length. Even if this was removed, the 'helper'</span> <a name="l00177"></a>00177 <span class="comment">// function this uses calls Vector::val2buf() which uses Vector::width()</span> <a name="l00178"></a>00178 <span class="comment">// which in turn uses length().</span> <a name="l00179"></a>00179 <span class="keywordflow">if</span> (dest-><a class="code" href="classlibdap_1_1Vector.html#a5990bd42b49e44c7b7da76e039896ba3">length</a>() != src_len) <a name="l00180"></a>00180 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00181"></a>00181 <span class="stringliteral">"The source and destination array sizes don't match ("</span> <a name="l00182"></a>00182 + <a class="code" href="namespacelibdap.html#a317edea830aab50d2137a5bd313cc86a">long_to_string</a>(src_len) + <span class="stringliteral">" versus "</span> <a name="l00183"></a>00183 + <a class="code" href="namespacelibdap.html#a317edea830aab50d2137a5bd313cc86a">long_to_string</a>(dest-><a class="code" href="classlibdap_1_1Vector.html#a5990bd42b49e44c7b7da76e039896ba3">length</a>()) + <span class="stringliteral">")."</span>); <a name="l00184"></a>00184 <a name="l00185"></a>00185 <span class="comment">// The types of arguments that the CE Parser will build for numeric</span> <a name="l00186"></a>00186 <span class="comment">// constants are limited to Uint32, Int32 and Float64. See ce_expr.y.</span> <a name="l00187"></a>00187 <span class="comment">// Expanded to work for any numeric type so it can be used for more than</span> <a name="l00188"></a>00188 <span class="comment">// just arguments.</span> <a name="l00189"></a>00189 <span class="keywordflow">switch</span> (dest-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>()) { <a name="l00190"></a>00190 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a4124790aeab42dbcd3d5303dea15b200">dods_byte_c</a>: <a name="l00191"></a>00191 set_array_using_double_helper<dods_byte>(dest, src, src_len); <a name="l00192"></a>00192 <span class="keywordflow">break</span>; <a name="l00193"></a>00193 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a84188f64695716d84cefe910704ca094">dods_uint16_c</a>: <a name="l00194"></a>00194 set_array_using_double_helper<dods_uint16>(dest, src, src_len); <a name="l00195"></a>00195 <span class="keywordflow">break</span>; <a name="l00196"></a>00196 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a37d71c620b71be06fbe667e7cb0e80e4">dods_int16_c</a>: <a name="l00197"></a>00197 set_array_using_double_helper<dods_int16>(dest, src, src_len); <a name="l00198"></a>00198 <span class="keywordflow">break</span>; <a name="l00199"></a>00199 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a1bdeca4f415a3372b83448efd87bff83">dods_uint32_c</a>: <a name="l00200"></a>00200 set_array_using_double_helper<dods_uint32>(dest, src, src_len); <a name="l00201"></a>00201 <span class="keywordflow">break</span>; <a name="l00202"></a>00202 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a524bfec434d0a8f82e06bfcc02c9a6b1">dods_int32_c</a>: <a name="l00203"></a>00203 set_array_using_double_helper<dods_int32>(dest, src, src_len); <a name="l00204"></a>00204 <span class="keywordflow">break</span>; <a name="l00205"></a>00205 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a6aff4fd17f027d0f0c41423e2f74a68c">dods_float32_c</a>: <a name="l00206"></a>00206 set_array_using_double_helper<dods_float32>(dest, src, src_len); <a name="l00207"></a>00207 <span class="keywordflow">break</span>; <a name="l00208"></a>00208 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a8661c9f9c227fe59b7f5563f20e145d6">dods_float64_c</a>: <a name="l00209"></a>00209 set_array_using_double_helper<dods_float64>(dest, src, src_len); <a name="l00210"></a>00210 <span class="keywordflow">break</span>; <a name="l00211"></a>00211 <span class="keywordflow">default</span>: <a name="l00212"></a>00212 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00213"></a>00213 <span class="stringliteral">"The argument list built by the CE parser contained an unsupported numeric type."</span>); <a name="l00214"></a>00214 } <a name="l00215"></a>00215 <a name="l00216"></a>00216 <span class="comment">// Set the read_p property.</span> <a name="l00217"></a>00217 dest-><a class="code" href="classlibdap_1_1Vector.html#a58712de8871e28a48fdc95e72a09df71" title="Indicates that the data is ready to send.">set_read_p</a>(<span class="keyword">true</span>); <a name="l00218"></a>00218 } <a name="l00219"></a>00219 <a name="l00220"></a>00220 <span class="keyword">template</span><<span class="keyword">class</span> T> <span class="keyword">static</span> <span class="keywordtype">double</span> *extract_double_array_helper(Array * a) <a name="l00221"></a>00221 { <a name="l00222"></a>00222 <span class="keywordtype">int</span> length = a->length(); <a name="l00223"></a>00223 <a name="l00224"></a>00224 T *b = <span class="keyword">new</span> T[length]; <a name="l00225"></a>00225 a->value(b); <a name="l00226"></a>00226 <a name="l00227"></a>00227 <span class="keywordtype">double</span> *dest = <span class="keyword">new</span> <span class="keywordtype">double</span>[length]; <a name="l00228"></a>00228 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < length; ++i) <a name="l00229"></a>00229 dest[i] = (<span class="keywordtype">double</span>) b[i]; <a name="l00230"></a>00230 <span class="keyword">delete</span>[]b; <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="keywordflow">return</span> dest; <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a name="l00239"></a><a class="code" href="namespacelibdap.html#ae9717ce6442b4909dcd7add356a7ff88">00239</a> <span class="keywordtype">double</span> *<a class="code" href="namespacelibdap.html#ae9717ce6442b4909dcd7add356a7ff88">extract_double_array</a>(<a class="code" href="classlibdap_1_1Array.html" title="A multidimensional array of identical data types.">Array</a> * a) <a name="l00240"></a>00240 { <a name="l00241"></a>00241 <span class="comment">// Simple types are Byte, ..., Float64, String and Url.</span> <a name="l00242"></a>00242 <span class="keywordflow">if</span> ((a-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ada8f5df7bb2bc72327fcd16af811562f">dods_array_c</a> && !a-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#a614ce462dc6236791630f373bf75ad49" title="Returns true if the instance is a numeric, string or URL type variable.">is_simple_type</a>()) <a name="l00243"></a>00243 || a-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ad620cef0bf41edebd4ee802071192a79">dods_str_c</a> || a-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a64d653d09a50d6d17537c43ed217f665">dods_url_c</a>) <a name="l00244"></a>00244 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>, <a name="l00245"></a>00245 <span class="stringliteral">"The function requires a DAP numeric-type array argument."</span>); <a name="l00246"></a>00246 <a name="l00247"></a>00247 <span class="keywordflow">if</span> (!a-><a class="code" href="classlibdap_1_1BaseType.html#a38ff819a432217c55db2e9071928d20c" title="Has this variable been read?">read_p</a>()) <a name="l00248"></a>00248 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00249"></a>00249 <span class="keywordtype">string</span>(<span class="stringliteral">"The Array '"</span>) + a-><a class="code" href="classlibdap_1_1BaseType.html#a0a0c6b5d57813607dc06255b8e0b9bdc" title="Returns the name of the class instance.">name</a>() + <a name="l00250"></a>00250 <span class="stringliteral">"'does not contain values."</span>); <a name="l00251"></a>00251 <a name="l00252"></a>00252 <span class="comment">// The types of arguments that the CE Parser will build for numeric</span> <a name="l00253"></a>00253 <span class="comment">// constants are limited to Uint32, Int32 and Float64. See ce_expr.y.</span> <a name="l00254"></a>00254 <span class="comment">// Expanded to work for any numeric type so it can be used for more than</span> <a name="l00255"></a>00255 <span class="comment">// just arguments.</span> <a name="l00256"></a>00256 <span class="keywordflow">switch</span> (a-><a class="code" href="classlibdap_1_1Vector.html#aa5ccb30d1f27ae587f35216b859feec7">var</a>()-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>()) { <a name="l00257"></a>00257 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a4124790aeab42dbcd3d5303dea15b200">dods_byte_c</a>: <a name="l00258"></a>00258 <span class="keywordflow">return</span> extract_double_array_helper<dods_byte>(a); <a name="l00259"></a>00259 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a84188f64695716d84cefe910704ca094">dods_uint16_c</a>: <a name="l00260"></a>00260 <span class="keywordflow">return</span> extract_double_array_helper<dods_uint16>(a); <a name="l00261"></a>00261 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a37d71c620b71be06fbe667e7cb0e80e4">dods_int16_c</a>: <a name="l00262"></a>00262 <span class="keywordflow">return</span> extract_double_array_helper<dods_int16>(a); <a name="l00263"></a>00263 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a1bdeca4f415a3372b83448efd87bff83">dods_uint32_c</a>: <a name="l00264"></a>00264 <span class="keywordflow">return</span> extract_double_array_helper<dods_uint32>(a); <a name="l00265"></a>00265 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a524bfec434d0a8f82e06bfcc02c9a6b1">dods_int32_c</a>: <a name="l00266"></a>00266 <span class="keywordflow">return</span> extract_double_array_helper<dods_int32>(a); <a name="l00267"></a>00267 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a6aff4fd17f027d0f0c41423e2f74a68c">dods_float32_c</a>: <a name="l00268"></a>00268 <span class="keywordflow">return</span> extract_double_array_helper<dods_float32>(a); <a name="l00269"></a>00269 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a8661c9f9c227fe59b7f5563f20e145d6">dods_float64_c</a>: <a name="l00270"></a>00270 <span class="keywordflow">return</span> extract_double_array_helper<dods_float64>(a); <a name="l00271"></a>00271 <span class="keywordflow">default</span>: <a name="l00272"></a>00272 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00273"></a>00273 <span class="stringliteral">"The argument list built by the CE parser contained an unsupported numeric type."</span>); <a name="l00274"></a>00274 } <a name="l00275"></a>00275 } <a name="l00276"></a>00276 <a name="l00284"></a><a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">00284</a> <span class="keywordtype">double</span> <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(<a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> * arg) <a name="l00285"></a>00285 { <a name="l00286"></a>00286 <span class="comment">// Simple types are Byte, ..., Float64, String and Url.</span> <a name="l00287"></a>00287 <span class="keywordflow">if</span> (!arg-><a class="code" href="classlibdap_1_1BaseType.html#a614ce462dc6236791630f373bf75ad49" title="Returns true if the instance is a numeric, string or URL type variable.">is_simple_type</a>() || arg-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ad620cef0bf41edebd4ee802071192a79">dods_str_c</a> || arg-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() <a name="l00288"></a>00288 == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a64d653d09a50d6d17537c43ed217f665">dods_url_c</a>) <a name="l00289"></a>00289 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>, <a name="l00290"></a>00290 <span class="stringliteral">"The function requires a DAP numeric-type argument."</span>); <a name="l00291"></a>00291 <a name="l00292"></a>00292 <span class="keywordflow">if</span> (!arg-><a class="code" href="classlibdap_1_1BaseType.html#a38ff819a432217c55db2e9071928d20c" title="Has this variable been read?">read_p</a>()) <a name="l00293"></a>00293 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00294"></a>00294 <span class="stringliteral">"The CE Evaluator built an argument list where some constants held no values."</span>); <a name="l00295"></a>00295 <a name="l00296"></a>00296 <span class="comment">// The types of arguments that the CE Parser will build for numeric</span> <a name="l00297"></a>00297 <span class="comment">// constants are limited to Uint32, Int32 and Float64. See ce_expr.y.</span> <a name="l00298"></a>00298 <span class="comment">// Expanded to work for any numeric type so it can be used for more than</span> <a name="l00299"></a>00299 <span class="comment">// just arguments.</span> <a name="l00300"></a>00300 <span class="keywordflow">switch</span> (arg-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>()) { <a name="l00301"></a>00301 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a4124790aeab42dbcd3d5303dea15b200">dods_byte_c</a>: <a name="l00302"></a>00302 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Byte.html" title="Holds a single byte.">Byte</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1Byte.html#afcb7d879a5a0185d39518ff0fcc10afd">value</a>()); <a name="l00303"></a>00303 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a84188f64695716d84cefe910704ca094">dods_uint16_c</a>: <a name="l00304"></a>00304 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1UInt16.html" title="Holds an unsigned 16-bit integer.">UInt16</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1UInt16.html#a9cc3d2c1a8b4abb67096e78f2c3ecbda">value</a>()); <a name="l00305"></a>00305 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a37d71c620b71be06fbe667e7cb0e80e4">dods_int16_c</a>: <a name="l00306"></a>00306 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Int16.html" title="Holds a 16-bit signed integer value.">Int16</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1Int16.html#af9373c11c553ad22baafebb69f35ed37">value</a>()); <a name="l00307"></a>00307 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a1bdeca4f415a3372b83448efd87bff83">dods_uint32_c</a>: <a name="l00308"></a>00308 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1UInt32.html" title="Holds a 32-bit unsigned integer.">UInt32</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1UInt32.html#aa7edf19a8c055d574466ae4e901c1936">value</a>()); <a name="l00309"></a>00309 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a524bfec434d0a8f82e06bfcc02c9a6b1">dods_int32_c</a>: <a name="l00310"></a>00310 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Int32.html" title="Holds a 32-bit signed integer.">Int32</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1Int32.html#a10a0268d3d1ed42fbab3ca92ec8e7ea5">value</a>()); <a name="l00311"></a>00311 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a6aff4fd17f027d0f0c41423e2f74a68c">dods_float32_c</a>: <a name="l00312"></a>00312 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Float32.html" title="Holds a 32-bit floating point value.">Float32</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1Float32.html#a7371bd4111884f04d2e93039312153a4">value</a>()); <a name="l00313"></a>00313 <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a8661c9f9c227fe59b7f5563f20e145d6">dods_float64_c</a>: <a name="l00314"></a>00314 <span class="keywordflow">return</span> <span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Float64.html" title="Holds a 64-bit (double precision) floating point value.">Float64</a>&<span class="keyword">></span>(*arg).<a class="code" href="classlibdap_1_1Float64.html#addf858aa9535d32f638c4e65a4b33256">value</a>(); <a name="l00315"></a>00315 <span class="keywordflow">default</span>: <a name="l00316"></a>00316 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00317"></a>00317 <span class="stringliteral">"The argument list built by the CE parser contained an unsupported numeric type."</span>); <a name="l00318"></a>00318 } <a name="l00319"></a>00319 } <a name="l00320"></a>00320 <a name="l00323"></a>00323 <span class="keywordtype">void</span> <a name="l00324"></a><a class="code" href="namespacelibdap.html#a69a45fe57f5b17b8ab202f454b2f7556">00324</a> <a class="code" href="namespacelibdap.html#a69a45fe57f5b17b8ab202f454b2f7556">function_version</a>(<span class="keywordtype">int</span>, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> *[], <a class="code" href="classlibdap_1_1DDS.html">DDS</a> &, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **btpp) <a name="l00325"></a>00325 { <a name="l00326"></a>00326 <span class="keywordtype">string</span> <a name="l00327"></a>00327 xml_value = <a name="l00328"></a>00328 <span class="stringliteral">"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\</span> <a name="l00329"></a>00329 <span class="stringliteral"> <functions>\</span> <a name="l00330"></a>00330 <span class="stringliteral"> <function name=\"geogrid\" version=\"1.2\"/>\</span> <a name="l00331"></a>00331 <span class="stringliteral"> <function name=\"grid\" version=\"1.0\"/>\</span> <a name="l00332"></a>00332 <span class="stringliteral"> <function name=\"linear_scale\" version=\"1.0b1\"/>\</span> <a name="l00333"></a>00333 <span class="stringliteral"> <function name=\"version\" version=\"1.0\"/>\</span> <a name="l00334"></a>00334 <span class="stringliteral"> </functions>"</span>; <a name="l00335"></a>00335 <a name="l00336"></a>00336 <span class="comment">// <function name=\"geoarray\" version=\"0.9b1\"/></span> <a name="l00337"></a>00337 <a name="l00338"></a>00338 <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a> *response = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a>(<span class="stringliteral">"version"</span>); <a name="l00339"></a>00339 <a name="l00340"></a>00340 response-><a class="code" href="classlibdap_1_1Str.html#ac4083a612e46a9ef2d1cddc2d40a955f">set_value</a>(xml_value); <a name="l00341"></a>00341 *btpp = response; <a name="l00342"></a>00342 <span class="keywordflow">return</span>; <a name="l00343"></a>00343 } <a name="l00344"></a>00344 <a name="l00345"></a>00345 <span class="keyword">static</span> <span class="keywordtype">void</span> parse_gse_expression(gse_arg * arg, BaseType * expr) <a name="l00346"></a>00346 { <a name="l00347"></a>00347 <a class="code" href="ce__functions_8cc.html#ac5920db2a87cb7ceb844e9086cfc50a6">gse_restart</a>(0); <span class="comment">// Restart the scanner.</span> <a name="l00348"></a>00348 <span class="keywordtype">void</span> *cls = <a class="code" href="ce__functions_8cc.html#a0f1967b84ee5e7c8ab88368e3a769b26">gse_string</a>(<a class="code" href="namespacelibdap.html#aca7eee077ab6dadb25126a92cf82737a">extract_string_argument</a>(expr).c_str()); <a name="l00349"></a>00349 <span class="comment">// gse_switch_to_buffer(cls); // Get set to scan the string.</span> <a name="l00350"></a>00350 <span class="keywordtype">bool</span> status = <a class="code" href="ce__functions_8cc.html#a504da9793f63a21e40595b1f63ae26e0">gse_parse</a>((<span class="keywordtype">void</span> *) arg) == 0; <a name="l00351"></a>00351 <a class="code" href="ce__functions_8cc.html#a98d472c04ecf1e180f0f81df7e688a8e">gse_delete_buffer</a>(cls); <a name="l00352"></a>00352 <span class="keywordflow">if</span> (!status) <a name="l00353"></a>00353 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>, <span class="stringliteral">"Error parsing grid selection."</span>); <a name="l00354"></a>00354 } <a name="l00355"></a>00355 <a name="l00356"></a>00356 <span class="keyword">static</span> <span class="keywordtype">void</span> apply_grid_selection_expr(Grid * grid, GSEClause * clause) <a name="l00357"></a>00357 { <a name="l00358"></a>00358 <span class="comment">// Basic plan: For each map, look at each clause and set start and stop</span> <a name="l00359"></a>00359 <span class="comment">// to be the intersection of the ranges in those clauses.</span> <a name="l00360"></a>00360 Grid::Map_iter map_i = grid->map_begin(); <a name="l00361"></a>00361 <span class="keywordflow">while</span> (map_i != grid->map_end() && (*map_i)->name() != clause->get_map_name()) <a name="l00362"></a>00362 ++map_i; <a name="l00363"></a>00363 <a name="l00364"></a>00364 <span class="keywordflow">if</span> (map_i == grid->map_end()) <a name="l00365"></a>00365 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"The map vector '"</span> + clause->get_map_name() <a name="l00366"></a>00366 + <span class="stringliteral">"' is not in the grid '"</span> + grid->name() + <span class="stringliteral">"'."</span>); <a name="l00367"></a>00367 <a name="l00368"></a>00368 <span class="comment">// Use pointer arith & the rule that map order must match array dim order</span> <a name="l00369"></a>00369 Array::Dim_iter grid_dim = (grid->get_array()->dim_begin() + (map_i - grid->map_begin())); <a name="l00370"></a>00370 <a name="l00371"></a>00371 Array *map = dynamic_cast < Array * >((*map_i)); <a name="l00372"></a>00372 <span class="keywordflow">if</span> (!map) <a name="l00373"></a>00373 <span class="keywordflow">throw</span> InternalErr(__FILE__, __LINE__, <span class="stringliteral">"Expected an Array"</span>); <a name="l00374"></a>00374 <span class="keywordtype">int</span> start = max(map->dimension_start(map->dim_begin()), clause->get_start()); <a name="l00375"></a>00375 <span class="keywordtype">int</span> stop = min(map->dimension_stop(map->dim_begin()), clause->get_stop()); <a name="l00376"></a>00376 <a name="l00377"></a>00377 <span class="keywordflow">if</span> (start > stop) { <a name="l00378"></a>00378 ostringstream msg; <a name="l00379"></a>00379 msg <a name="l00380"></a>00380 << <span class="stringliteral">"The expressions passed to grid() do not result in an inclusive \n"</span> <a name="l00381"></a>00381 << <span class="stringliteral">"subset of '"</span> << clause->get_map_name() <a name="l00382"></a>00382 << <span class="stringliteral">"'. The map's values range "</span> << <span class="stringliteral">"from "</span> <a name="l00383"></a>00383 << clause->get_map_min_value() << <span class="stringliteral">" to "</span> <a name="l00384"></a>00384 << clause->get_map_max_value() << <span class="stringliteral">"."</span>; <a name="l00385"></a>00385 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,msg.str()); <a name="l00386"></a>00386 } <a name="l00387"></a>00387 <a name="l00388"></a>00388 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Setting constraint on "</span> << map->name() <a name="l00389"></a>00389 << <span class="stringliteral">"["</span> << start << <span class="stringliteral">":"</span> << stop << <span class="stringliteral">"]"</span> << endl); <a name="l00390"></a>00390 <a name="l00391"></a>00391 <span class="comment">// Stride is always one.</span> <a name="l00392"></a>00392 map->add_constraint(map->dim_begin(), start, 1, stop); <a name="l00393"></a>00393 grid->get_array()->add_constraint(grid_dim, start, 1, stop); <a name="l00394"></a>00394 } <a name="l00395"></a>00395 <a name="l00396"></a>00396 <span class="keyword">static</span> <span class="keywordtype">void</span> apply_grid_selection_expressions(Grid * grid, <a name="l00397"></a>00397 vector < GSEClause * >clauses) <a name="l00398"></a>00398 { <a name="l00399"></a>00399 vector < GSEClause * >::iterator clause_i = clauses.begin(); <a name="l00400"></a>00400 <span class="keywordflow">while</span> (clause_i != clauses.end()) <a name="l00401"></a>00401 apply_grid_selection_expr(grid, *clause_i++); <a name="l00402"></a>00402 <a name="l00403"></a>00403 grid->set_read_p(<span class="keyword">false</span>); <a name="l00404"></a>00404 } <a name="l00405"></a>00405 <a name="l00442"></a>00442 <span class="keywordtype">void</span> <a name="l00443"></a><a class="code" href="namespacelibdap.html#ad495b5febe1ea2b30f9fce7e31e98c9e">00443</a> <a class="code" href="namespacelibdap.html#ad495b5febe1ea2b30f9fce7e31e98c9e">function_grid</a>(<span class="keywordtype">int</span> argc, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> * argv[], <a class="code" href="classlibdap_1_1DDS.html">DDS</a> &, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **btpp) <a name="l00444"></a>00444 { <a name="l00445"></a>00445 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"Entering function_grid..."</span> << endl); <a name="l00446"></a>00446 <a name="l00447"></a>00447 <span class="keywordtype">string</span> info = <a name="l00448"></a>00448 string(<span class="stringliteral">"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"</span>) + <a name="l00449"></a>00449 <span class="stringliteral">"<function name=\"grid\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#grid\">\n"</span> + <a name="l00450"></a>00450 <span class="stringliteral">"</function>\n"</span>; <a name="l00451"></a>00451 <a name="l00452"></a>00452 <span class="keywordflow">if</span> (argc == 0) { <a name="l00453"></a>00453 <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a> *response = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a>(<span class="stringliteral">"info"</span>); <a name="l00454"></a>00454 response-><a class="code" href="classlibdap_1_1Str.html#ac4083a612e46a9ef2d1cddc2d40a955f">set_value</a>(info); <a name="l00455"></a>00455 *btpp = response; <a name="l00456"></a>00456 <span class="keywordflow">return</span>; <a name="l00457"></a>00457 } <a name="l00458"></a>00458 <a name="l00459"></a>00459 <a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a> *original_grid = dynamic_cast < <a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a> * >(argv[0]); <a name="l00460"></a>00460 <span class="keywordflow">if</span> (!original_grid) <a name="l00461"></a>00461 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"The first argument to grid() must be a Grid variable!"</span>); <a name="l00462"></a>00462 <a name="l00463"></a>00463 <span class="comment">// Duplicate the grid; DODSFilter::send_data() will delete the variable</span> <a name="l00464"></a>00464 <span class="comment">// after serializing it.</span> <a name="l00465"></a>00465 <a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a> *l_grid = dynamic_cast < <a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a> * >(original_grid-><a class="code" href="classlibdap_1_1Grid.html#a0c4a5aefa252d3eab94b8a0ce5232dc6">ptr_duplicate</a>()); <a name="l00466"></a>00466 <span class="keywordflow">if</span> (!l_grid) <a name="l00467"></a>00467 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <span class="stringliteral">"Expected a Grid."</span>); <a name="l00468"></a>00468 <a name="l00469"></a>00469 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"grid: past initialization code"</span> << endl); <a name="l00470"></a>00470 <a name="l00471"></a>00471 <span class="comment">// Read the maps. Do this before calling parse_gse_expression(). Avoid</span> <a name="l00472"></a>00472 <span class="comment">// reading the array until the constraints have been applied because it</span> <a name="l00473"></a>00473 <span class="comment">// might be really large.</span> <a name="l00474"></a>00474 <a name="l00475"></a>00475 <span class="comment">// This version makes sure to set the send_p flags which is needed for</span> <a name="l00476"></a>00476 <span class="comment">// the hdf4 handler (and is what should be done in general).</span> <a name="l00477"></a>00477 <a class="code" href="classlibdap_1_1Grid.html#a69ee284e8087d1482373989f3256f95d">Grid::Map_iter</a> i = l_grid-><a class="code" href="classlibdap_1_1Grid.html#a2e9d2e436c0ff138a977dbba54c018eb" title="Returns an iterator referencing the first Map vector.">map_begin</a>(); <a name="l00478"></a>00478 <span class="keywordflow">while</span> (i != l_grid-><a class="code" href="classlibdap_1_1Grid.html#aaebbf2a5329ec01b6527b4bafde87837">map_end</a>()) <a name="l00479"></a>00479 (*i++)->set_send_p(<span class="keyword">true</span>); <a name="l00480"></a>00480 l_grid-><a class="code" href="classlibdap_1_1BaseType.html#a1da003c53f2e663223f603ab3fbd7c8e" title="Read data into a local buffer.">read</a>(); <a name="l00481"></a>00481 <a name="l00482"></a>00482 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"grid: past map read"</span> << endl); <a name="l00483"></a>00483 <a name="l00484"></a>00484 <span class="comment">// argv[1..n] holds strings; each are little expressions to be parsed.</span> <a name="l00485"></a>00485 <span class="comment">// When each expression is parsed, the parser makes a new instance of</span> <a name="l00486"></a>00486 <span class="comment">// GSEClause. GSEClause checks to make sure the named map really exists</span> <a name="l00487"></a>00487 <span class="comment">// in the Grid and that the range of values given makes sense.</span> <a name="l00488"></a>00488 vector < GSEClause * > clauses; <a name="l00489"></a>00489 <a class="code" href="structlibdap_1_1gse__arg.html">gse_arg</a> *arg = <span class="keyword">new</span> <a class="code" href="structlibdap_1_1gse__arg.html">gse_arg</a>(l_grid); <a name="l00490"></a>00490 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i < argc; ++i) { <a name="l00491"></a>00491 parse_gse_expression(arg, argv[i]); <a name="l00492"></a>00492 clauses.push_back(arg-><a class="code" href="structlibdap_1_1gse__arg.html#a63b69a5efec365819548d800d29b7a2a">get_gsec</a>()); <a name="l00493"></a>00493 } <a name="l00494"></a>00494 <span class="keyword">delete</span> arg; <a name="l00495"></a>00495 arg = 0; <a name="l00496"></a>00496 <a name="l00497"></a>00497 apply_grid_selection_expressions(l_grid, clauses); <a name="l00498"></a>00498 <a name="l00499"></a>00499 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"grid: past gse application"</span> << endl); <a name="l00500"></a>00500 <a name="l00501"></a>00501 l_grid-><a class="code" href="classlibdap_1_1Grid.html#a905ac86a44a9d8ce576056ba244cf558" title="Returns the Grid Array. This method returns the array using an Array*, so no cast is required...">get_array</a>()-><a class="code" href="classlibdap_1_1Vector.html#a64815467570490a4a6cddc89f09a2413" title="Indicates that the data is ready to send.">set_send_p</a>(<span class="keyword">true</span>); <a name="l00502"></a>00502 <a name="l00503"></a>00503 l_grid-><a class="code" href="classlibdap_1_1BaseType.html#a1da003c53f2e663223f603ab3fbd7c8e" title="Read data into a local buffer.">read</a>(); <a name="l00504"></a>00504 <a name="l00505"></a>00505 *btpp = l_grid; <a name="l00506"></a>00506 <span class="keywordflow">return</span>; <a name="l00507"></a>00507 } <a name="l00508"></a>00508 <a name="l00544"></a>00544 <span class="keywordtype">void</span> <a name="l00545"></a><a class="code" href="namespacelibdap.html#a97ebb2cf77302bf3dda2934593964ec4">00545</a> <a class="code" href="namespacelibdap.html#a97ebb2cf77302bf3dda2934593964ec4">function_geogrid</a>(<span class="keywordtype">int</span> argc, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> * argv[], <a class="code" href="classlibdap_1_1DDS.html">DDS</a> &, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **btpp) <a name="l00546"></a>00546 { <a name="l00547"></a>00547 <span class="keywordtype">string</span> info = <a name="l00548"></a>00548 string(<span class="stringliteral">"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"</span>) + <a name="l00549"></a>00549 <span class="stringliteral">"<function name=\"geogrid\" version=\"1.2\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#geogrid\">\n"</span>+ <a name="l00550"></a>00550 <span class="stringliteral">"</function>"</span>; <a name="l00551"></a>00551 <a name="l00552"></a>00552 <span class="keywordflow">if</span> (argc == 0) { <a name="l00553"></a>00553 <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a> *response = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a>(<span class="stringliteral">"version"</span>); <a name="l00554"></a>00554 response-><a class="code" href="classlibdap_1_1Str.html#ac4083a612e46a9ef2d1cddc2d40a955f">set_value</a>(info); <a name="l00555"></a>00555 *btpp = response; <a name="l00556"></a>00556 return ; <a name="l00557"></a>00557 } <a name="l00558"></a>00558 <a name="l00559"></a>00559 <span class="comment">// There are two main forms of this function, one that takes a Grid and one</span> <a name="l00560"></a>00560 <span class="comment">// that takes a Grid and two Arrays. The latter provides a way to explicitly</span> <a name="l00561"></a>00561 <span class="comment">// tell the function which maps contain lat and lon data. The remaining</span> <a name="l00562"></a>00562 <span class="comment">// arguments are the same for both versions, although that includes a</span> <a name="l00563"></a>00563 <span class="comment">// varying argument list.</span> <a name="l00564"></a>00564 <a name="l00565"></a>00565 <span class="comment">// Look at the types of the first three arguments to determine which of the</span> <a name="l00566"></a>00566 <span class="comment">// two forms were used to call this function.</span> <a name="l00567"></a>00567 <a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a> *l_grid = 0; <a name="l00568"></a>00568 <span class="keywordflow">if</span> (argc < 1 || !(l_grid = dynamic_cast < Grid * >(argv[0]->ptr_duplicate()))) <a name="l00569"></a>00569 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"The first argument to geogrid() must be a Grid variable!"</span>); <a name="l00570"></a>00570 <a name="l00571"></a>00571 <span class="comment">// Both forms require at least this many args</span> <a name="l00572"></a>00572 <span class="keywordflow">if</span> (argc < 5) <a name="l00573"></a>00573 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"Wrong number of arguments to geogrid() (expected at least 5 args). See geogrid() for more information."</span>); <a name="l00574"></a>00574 <a name="l00575"></a>00575 <span class="keywordtype">bool</span> grid_lat_lon_form; <a name="l00576"></a>00576 <a class="code" href="classlibdap_1_1Array.html" title="A multidimensional array of identical data types.">Array</a> *l_lat = 0; <a name="l00577"></a>00577 <a class="code" href="classlibdap_1_1Array.html" title="A multidimensional array of identical data types.">Array</a> *l_lon = 0; <a name="l00578"></a>00578 <span class="keywordflow">if</span> (!(l_lat = dynamic_cast < Array * >(argv[1]))) <span class="comment">//->ptr_duplicate())))</span> <a name="l00579"></a>00579 grid_lat_lon_form = <span class="keyword">false</span>; <a name="l00580"></a>00580 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!(l_lon = dynamic_cast < Array * >(argv[2]))) <span class="comment">//->ptr_duplicate())))</span> <a name="l00581"></a>00581 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"When using the Grid, Lat, Lon form of geogrid() both the lat and lon maps must be given (lon map missing)!"</span>); <a name="l00582"></a>00582 <span class="keywordflow">else</span> <a name="l00583"></a>00583 grid_lat_lon_form = <span class="keyword">true</span>; <a name="l00584"></a>00584 <a name="l00585"></a>00585 <span class="keywordflow">if</span> (grid_lat_lon_form && argc < 7) <a name="l00586"></a>00586 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"Wrong number of arguments to geogrid() (expected at least 7 args). See geogrid() for more information."</span>); <a name="l00587"></a>00587 <a name="l00588"></a>00588 <span class="preprocessor">#if 0</span> <a name="l00589"></a>00589 <span class="preprocessor"></span> <a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a> *l_grid = dynamic_cast < <a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a> * >(argv[0]-><a class="code" href="classlibdap_1_1BaseType.html#a0b130311c9901fb8a7ab11ea19090ef0">ptr_duplicate</a>()); <a name="l00590"></a>00590 <span class="keywordflow">if</span> (!l_grid) <a name="l00591"></a>00591 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"The first argument to geogrid() must be a Grid variable!"</span>); <a name="l00592"></a>00592 <span class="preprocessor">#endif</span> <a name="l00593"></a>00593 <span class="preprocessor"></span> <span class="comment">// Read the maps. Do this before calling parse_gse_expression(). Avoid</span> <a name="l00594"></a>00594 <span class="comment">// reading the array until the constraints have been applied because it</span> <a name="l00595"></a>00595 <span class="comment">// might be really large.</span> <a name="l00596"></a>00596 <span class="comment">//</span> <a name="l00597"></a>00597 <span class="comment">// Trick: Some handlers build Grids from a combination of Array</span> <a name="l00598"></a>00598 <span class="comment">// variables and attributes. Those handlers (e.g., hdf4) use the send_p</span> <a name="l00599"></a>00599 <span class="comment">// property to determine which parts of the Grid to read *but they can</span> <a name="l00600"></a>00600 <span class="comment">// only read the maps from within Grid::read(), not the map's read()*.</span> <a name="l00601"></a>00601 <span class="comment">// Since the Grid's array does not have send_p set, it will not be read</span> <a name="l00602"></a>00602 <span class="comment">// by the call below to Grid::read().</span> <a name="l00603"></a>00603 <a class="code" href="classlibdap_1_1Grid.html#a69ee284e8087d1482373989f3256f95d">Grid::Map_iter</a> i = l_grid-><a class="code" href="classlibdap_1_1Grid.html#a2e9d2e436c0ff138a977dbba54c018eb" title="Returns an iterator referencing the first Map vector.">map_begin</a>(); <a name="l00604"></a>00604 <span class="keywordflow">while</span> (i != l_grid-><a class="code" href="classlibdap_1_1Grid.html#aaebbf2a5329ec01b6527b4bafde87837">map_end</a>()) <a name="l00605"></a>00605 (*i++)->set_send_p(<span class="keyword">true</span>); <a name="l00606"></a>00606 <a name="l00607"></a>00607 l_grid-><a class="code" href="classlibdap_1_1BaseType.html#a1da003c53f2e663223f603ab3fbd7c8e" title="Read data into a local buffer.">read</a>(); <a name="l00608"></a>00608 <span class="comment">// Calling read() above sets the read_p flag for the entire grid; clear it</span> <a name="l00609"></a>00609 <span class="comment">// for the grid's array so that later on the code will be sure to read it</span> <a name="l00610"></a>00610 <span class="comment">// under all circumstances.</span> <a name="l00611"></a>00611 l_grid-><a class="code" href="classlibdap_1_1Grid.html#a905ac86a44a9d8ce576056ba244cf558" title="Returns the Grid Array. This method returns the array using an Array*, so no cast is required...">get_array</a>()-><a class="code" href="classlibdap_1_1Vector.html#a58712de8871e28a48fdc95e72a09df71" title="Indicates that the data is ready to send.">set_read_p</a>(<span class="keyword">false</span>); <a name="l00612"></a>00612 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"geogrid: past map read"</span> << endl); <a name="l00613"></a>00613 <a name="l00614"></a>00614 <span class="comment">// Look for Grid Selection Expressions tacked onto the end of the BB</span> <a name="l00615"></a>00615 <span class="comment">// specification. If there are any, evaluate them before evaluating the BB.</span> <a name="l00616"></a>00616 <span class="keywordtype">int</span> min_arg_count = (grid_lat_lon_form) ? 7 : 5; <a name="l00617"></a>00617 <span class="keywordflow">if</span> (argc > min_arg_count) { <a name="l00618"></a>00618 <span class="comment">// argv[5..n] holds strings; each are little Grid Selection Expressions</span> <a name="l00619"></a>00619 <span class="comment">// to be parsed and evaluated.</span> <a name="l00620"></a>00620 vector < GSEClause * > clauses; <a name="l00621"></a>00621 <a class="code" href="structlibdap_1_1gse__arg.html">gse_arg</a> *arg = <span class="keyword">new</span> <a class="code" href="structlibdap_1_1gse__arg.html">gse_arg</a>(l_grid); <a name="l00622"></a>00622 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = min_arg_count; i < argc; ++i) { <a name="l00623"></a>00623 parse_gse_expression(arg, argv[i]); <a name="l00624"></a>00624 clauses.push_back(arg-><a class="code" href="structlibdap_1_1gse__arg.html#a63b69a5efec365819548d800d29b7a2a">get_gsec</a>()); <a name="l00625"></a>00625 } <a name="l00626"></a>00626 <span class="keyword">delete</span> arg; <a name="l00627"></a>00627 arg = 0; <a name="l00628"></a>00628 <a name="l00629"></a>00629 apply_grid_selection_expressions(l_grid, clauses); <a name="l00630"></a>00630 } <a name="l00631"></a>00631 <a name="l00632"></a>00632 <span class="keywordflow">try</span> { <a name="l00633"></a>00633 <span class="comment">// Build a GeoConstraint object. If there are no longitude/latitude</span> <a name="l00634"></a>00634 <span class="comment">// maps then this constructor throws Error.</span> <a name="l00635"></a>00635 <a class="code" href="classlibdap_1_1GridGeoConstraint.html">GridGeoConstraint</a> gc(l_grid); <a name="l00636"></a>00636 <a name="l00637"></a>00637 <span class="comment">// This sets the bounding box and modifies the maps to match the</span> <a name="l00638"></a>00638 <span class="comment">// notation of the box (0/359 or -180/179)</span> <a name="l00639"></a>00639 <span class="keywordtype">int</span> box_index_offset = (grid_lat_lon_form) ? 3 : 1; <a name="l00640"></a>00640 <span class="keywordtype">double</span> top = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[box_index_offset]); <a name="l00641"></a>00641 <span class="keywordtype">double</span> left = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[box_index_offset + 1]); <a name="l00642"></a>00642 <span class="keywordtype">double</span> bottom = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[box_index_offset + 2]); <a name="l00643"></a>00643 <span class="keywordtype">double</span> right = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[box_index_offset + 3]); <a name="l00644"></a>00644 gc.<a class="code" href="classlibdap_1_1GeoConstraint.html#a971205af9b456f4594f01aa513b6543c">set_bounding_box</a>(top, left, bottom, right); <a name="l00645"></a>00645 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"geogrid: past bounding box set"</span> << endl); <a name="l00646"></a>00646 <a name="l00647"></a>00647 <span class="comment">// This also reads all of the data into the grid variable</span> <a name="l00648"></a>00648 gc.<a class="code" href="classlibdap_1_1GridGeoConstraint.html#affdc6145014a519bef4874d14716b3cf">apply_constraint_to_data</a>(); <a name="l00649"></a>00649 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"geogrid: past apply constraint"</span> << endl); <a name="l00650"></a>00650 <a name="l00651"></a>00651 <span class="comment">// In this function the l_grid pointer is the same as the pointer returned</span> <a name="l00652"></a>00652 <span class="comment">// by this call. The caller of the function must free the pointer.</span> <a name="l00653"></a>00653 *btpp = gc.<a class="code" href="classlibdap_1_1GridGeoConstraint.html#a712d428422dd23582291ba1ad13137dd">get_constrained_grid</a>(); <a name="l00654"></a>00654 <span class="keywordflow">return</span>; <a name="l00655"></a>00655 } <a name="l00656"></a>00656 <span class="keywordflow">catch</span> (<a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a> &e) { <a name="l00657"></a>00657 <span class="keywordflow">throw</span> e; <a name="l00658"></a>00658 } <a name="l00659"></a>00659 <span class="keywordflow">catch</span> (exception & e) { <a name="l00660"></a>00660 <span class="keywordflow">throw</span> <a name="l00661"></a>00661 <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(<span class="keywordtype">string</span> <a name="l00662"></a>00662 (<span class="stringliteral">"A C++ exception was thrown from inside geogrid(): "</span>) <a name="l00663"></a>00663 + e.what()); <a name="l00664"></a>00664 } <a name="l00665"></a>00665 } <a name="l00666"></a>00666 <a name="l00667"></a>00667 <span class="comment">// These static functions could be moved to a class that provides a more</span> <a name="l00668"></a>00668 <span class="comment">// general interface for COARDS/CF someday. Assume each BaseType comes bundled</span> <a name="l00669"></a>00669 <span class="comment">// with an attribute table.</span> <a name="l00670"></a>00670 <a name="l00671"></a>00671 <span class="comment">// This was ripped from parser-util.cc</span> <a name="l00672"></a>00672 <span class="keyword">static</span> <span class="keywordtype">double</span> string_to_double(<span class="keyword">const</span> <span class="keywordtype">char</span> *val) <a name="l00673"></a>00673 { <a name="l00674"></a>00674 <span class="keywordtype">char</span> *ptr; <a name="l00675"></a>00675 errno = 0; <a name="l00676"></a>00676 <span class="comment">// Clear previous value. 5/21/2001 jhrg</span> <a name="l00677"></a>00677 <a name="l00678"></a>00678 <span class="preprocessor">#ifdef WIN32</span> <a name="l00679"></a>00679 <span class="preprocessor"></span> <span class="keywordtype">double</span> v = w32strtod(val, &ptr); <a name="l00680"></a>00680 <span class="preprocessor">#else</span> <a name="l00681"></a>00681 <span class="preprocessor"></span> <span class="keywordtype">double</span> v = strtod(val, &ptr); <a name="l00682"></a>00682 <span class="preprocessor">#endif</span> <a name="l00683"></a>00683 <span class="preprocessor"></span> <a name="l00684"></a>00684 <span class="keywordflow">if</span> ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE)) <a name="l00685"></a>00685 || *ptr != <span class="charliteral">'\0'</span>) { <a name="l00686"></a>00686 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="keywordtype">string</span>(<span class="stringliteral">"Could not convert the string '"</span>) + val + <span class="stringliteral">"' to a double."</span>); <a name="l00687"></a>00687 } <a name="l00688"></a>00688 <a name="l00689"></a>00689 <span class="keywordtype">double</span> abs_val = fabs(v); <a name="l00690"></a>00690 <span class="keywordflow">if</span> (abs_val > <a class="code" href="dods-limits_8h.html#a0a8ce841d9d9ff15fe487b515f43ff81">DODS_DBL_MAX</a> || (abs_val != 0.0 && abs_val < <a class="code" href="dods-limits_8h.html#a10fd590362c76967923686f27ece6562">DODS_DBL_MIN</a>)) <a name="l00691"></a>00691 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="keywordtype">string</span>(<span class="stringliteral">"Could not convert the string '"</span>) + val + <span class="stringliteral">"' to a double."</span>); <a name="l00692"></a>00692 <a name="l00693"></a>00693 <span class="keywordflow">return</span> v; <a name="l00694"></a>00694 } <a name="l00695"></a>00695 <a name="l00705"></a>00705 <span class="keyword">static</span> <span class="keywordtype">double</span> get_attribute_double_value(BaseType *var, <a name="l00706"></a>00706 vector<string> &attributes) <a name="l00707"></a>00707 { <a name="l00708"></a>00708 <span class="comment">// This code also builds a list of the attribute values that have been</span> <a name="l00709"></a>00709 <span class="comment">// passed in but not found so that an informative message can be returned.</span> <a name="l00710"></a>00710 AttrTable &attr = var->get_attr_table(); <a name="l00711"></a>00711 <span class="keywordtype">string</span> attribute_value = <span class="stringliteral">""</span>; <a name="l00712"></a>00712 <span class="keywordtype">string</span> values = <span class="stringliteral">""</span>; <a name="l00713"></a>00713 vector<string>::iterator i = attributes.begin(); <a name="l00714"></a>00714 <span class="keywordflow">while</span> (attribute_value == <span class="stringliteral">""</span> && i != attributes.end()) { <a name="l00715"></a>00715 values += *i; <a name="l00716"></a>00716 <span class="keywordflow">if</span> (!values.empty()) <a name="l00717"></a>00717 values += <span class="stringliteral">", "</span>; <a name="l00718"></a>00718 attribute_value = attr.get_attr(*i++); <a name="l00719"></a>00719 } <a name="l00720"></a>00720 <a name="l00721"></a>00721 <span class="comment">// If the value string is empty, then look at the grid's array (if it's a</span> <a name="l00722"></a>00722 <span class="comment">// grid) or throw an Error.</span> <a name="l00723"></a>00723 <span class="keywordflow">if</span> (attribute_value.empty()) { <a name="l00724"></a>00724 <span class="keywordflow">if</span> (var->type() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ac41525d2e860d3bcff641eb1fdba41d2">dods_grid_c</a>) <a name="l00725"></a>00725 <span class="keywordflow">return</span> get_attribute_double_value(dynamic_cast<Grid&>(*var).get_array(), attributes); <a name="l00726"></a>00726 <span class="keywordflow">else</span> <a name="l00727"></a>00727 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="keywordtype">string</span>(<span class="stringliteral">"No COARDS/CF '"</span>) + values.substr(0, values.length() - 2) <a name="l00728"></a>00728 + <span class="stringliteral">"' attribute was found for the variable '"</span> <a name="l00729"></a>00729 + var->name() + <span class="stringliteral">"'."</span>); <a name="l00730"></a>00730 } <a name="l00731"></a>00731 <a name="l00732"></a>00732 <span class="keywordflow">return</span> string_to_double(<a class="code" href="namespacelibdap.html#a37a24fcba1630ac658ec4c8a902dd92c">remove_quotes</a>(attribute_value).c_str()); <a name="l00733"></a>00733 } <a name="l00734"></a>00734 <a name="l00735"></a>00735 <span class="keyword">static</span> <span class="keywordtype">double</span> get_attribute_double_value(BaseType *var, <span class="keyword">const</span> <span class="keywordtype">string</span> &attribute) <a name="l00736"></a>00736 { <a name="l00737"></a>00737 AttrTable &attr = var->get_attr_table(); <a name="l00738"></a>00738 <span class="keywordtype">string</span> attribute_value = attr.get_attr(attribute); <a name="l00739"></a>00739 <a name="l00740"></a>00740 <span class="comment">// If the value string is empty, then look at the grid's array (if it's a</span> <a name="l00741"></a>00741 <span class="comment">// grid or throw an Error.</span> <a name="l00742"></a>00742 <span class="keywordflow">if</span> (attribute_value.empty()) { <a name="l00743"></a>00743 <span class="keywordflow">if</span> (var->type() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ac41525d2e860d3bcff641eb1fdba41d2">dods_grid_c</a>) <a name="l00744"></a>00744 <span class="keywordflow">return</span> get_attribute_double_value(dynamic_cast<Grid&>(*var).get_array(), attribute); <a name="l00745"></a>00745 <span class="keywordflow">else</span> <a name="l00746"></a>00746 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="keywordtype">string</span>(<span class="stringliteral">"No COARDS '"</span>) + attribute <a name="l00747"></a>00747 + <span class="stringliteral">"' attribute was found for the variable '"</span> <a name="l00748"></a>00748 + var->name() + <span class="stringliteral">"'."</span>); <a name="l00749"></a>00749 } <a name="l00750"></a>00750 <a name="l00751"></a>00751 <span class="keywordflow">return</span> string_to_double(<a class="code" href="namespacelibdap.html#a37a24fcba1630ac658ec4c8a902dd92c">remove_quotes</a>(attribute_value).c_str()); <a name="l00752"></a>00752 } <a name="l00753"></a>00753 <a name="l00754"></a>00754 <span class="keyword">static</span> <span class="keywordtype">double</span> get_y_intercept(BaseType *var) <a name="l00755"></a>00755 { <a name="l00756"></a>00756 vector<string> attributes; <a name="l00757"></a>00757 attributes.push_back(<span class="stringliteral">"add_offset"</span>); <a name="l00758"></a>00758 attributes.push_back(<span class="stringliteral">"add_off"</span>); <a name="l00759"></a>00759 <span class="keywordflow">return</span> get_attribute_double_value(var, attributes); <a name="l00760"></a>00760 } <a name="l00761"></a>00761 <a name="l00762"></a>00762 <span class="keyword">static</span> <span class="keywordtype">double</span> get_slope(BaseType *var) <a name="l00763"></a>00763 { <a name="l00764"></a>00764 <span class="keywordflow">return</span> get_attribute_double_value(var, <span class="stringliteral">"scale_factor"</span>); <a name="l00765"></a>00765 } <a name="l00766"></a>00766 <a name="l00767"></a>00767 <span class="keyword">static</span> <span class="keywordtype">double</span> get_missing_value(BaseType *var) <a name="l00768"></a>00768 { <a name="l00769"></a>00769 <span class="keywordflow">return</span> get_attribute_double_value(var, <span class="stringliteral">"missing_value"</span>); <a name="l00770"></a>00770 } <a name="l00771"></a>00771 <a name="l00784"></a>00784 <span class="keywordtype">void</span> <a name="l00785"></a><a class="code" href="namespacelibdap.html#acb70f051b4691bdf6d1333a2a7a442f0">00785</a> <a class="code" href="namespacelibdap.html#acb70f051b4691bdf6d1333a2a7a442f0">function_linear_scale</a>(<span class="keywordtype">int</span> argc, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> * argv[], <a class="code" href="classlibdap_1_1DDS.html">DDS</a> &, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **btpp) <a name="l00786"></a>00786 { <a name="l00787"></a>00787 <span class="keywordtype">string</span> info = <a name="l00788"></a>00788 string(<span class="stringliteral">"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"</span>) + <a name="l00789"></a>00789 <span class="stringliteral">"<function name=\"linear_scale\" version=\"1.0b1\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#linear_scale\">\n"</span> + <a name="l00790"></a>00790 <span class="stringliteral">"</function>"</span>; <a name="l00791"></a>00791 <a name="l00792"></a>00792 <span class="keywordflow">if</span> (argc == 0) { <a name="l00793"></a>00793 <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a> *response = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1Str.html" title="Holds character string data.">Str</a>(<span class="stringliteral">"info"</span>); <a name="l00794"></a>00794 response-><a class="code" href="classlibdap_1_1Str.html#ac4083a612e46a9ef2d1cddc2d40a955f">set_value</a>(info); <a name="l00795"></a>00795 *btpp = response; <a name="l00796"></a>00796 <span class="keywordflow">return</span>; <a name="l00797"></a>00797 } <a name="l00798"></a>00798 <a name="l00799"></a>00799 <span class="comment">// Check for 1 or 3 arguments: 1 --> use attributes; 3 --> m & b supplied</span> <a name="l00800"></a>00800 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"argc = "</span> << argc << endl); <a name="l00801"></a>00801 <span class="keywordflow">if</span> (!(argc == 1 || argc == 3 || argc == 4)) <a name="l00802"></a>00802 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"Wrong number of arguments to linear_scale(). See linear_scale() for more information"</span>); <a name="l00803"></a>00803 <a name="l00804"></a>00804 <span class="comment">// Get m & b</span> <a name="l00805"></a>00805 <span class="keywordtype">bool</span> use_missing = <span class="keyword">false</span>; <a name="l00806"></a>00806 <span class="keywordtype">double</span> m, b, missing = 0.0; <a name="l00807"></a>00807 <span class="keywordflow">if</span> (argc == 4) { <a name="l00808"></a>00808 m = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[1]); <a name="l00809"></a>00809 b = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[2]); <a name="l00810"></a>00810 missing = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[3]); <a name="l00811"></a>00811 use_missing = <span class="keyword">true</span>; <a name="l00812"></a>00812 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argc == 3) { <a name="l00813"></a>00813 m = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[1]); <a name="l00814"></a>00814 b = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[2]); <a name="l00815"></a>00815 use_missing = <span class="keyword">false</span>; <a name="l00816"></a>00816 } <span class="keywordflow">else</span> { <a name="l00817"></a>00817 m = get_slope(argv[0]); <a name="l00818"></a>00818 <a name="l00819"></a>00819 <span class="comment">// This is really a hack; on a fair number of datasets, the y intercept</span> <a name="l00820"></a>00820 <span class="comment">// is not given and is assumed to be 0. Here the function looks and</span> <a name="l00821"></a>00821 <span class="comment">// catches the error if a y intercept is not found.</span> <a name="l00822"></a>00822 <span class="keywordflow">try</span> { <a name="l00823"></a>00823 b = get_y_intercept(argv[0]); <a name="l00824"></a>00824 } <a name="l00825"></a>00825 <span class="keywordflow">catch</span> (<a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a> &e) { <a name="l00826"></a>00826 b = 0.0; <a name="l00827"></a>00827 } <a name="l00828"></a>00828 <a name="l00829"></a>00829 <span class="comment">// This is not the best plan; the get_missing_value() function should</span> <a name="l00830"></a>00830 <span class="comment">// do something other than throw, but to do that would require mayor</span> <a name="l00831"></a>00831 <span class="comment">// surgery on get_attribute_double_value().</span> <a name="l00832"></a>00832 <span class="keywordflow">try</span> { <a name="l00833"></a>00833 missing = get_missing_value(argv[0]); <a name="l00834"></a>00834 use_missing = <span class="keyword">true</span>; <a name="l00835"></a>00835 } <a name="l00836"></a>00836 <span class="keywordflow">catch</span> (<a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a> &e) { <a name="l00837"></a>00837 use_missing = <span class="keyword">false</span>; <a name="l00838"></a>00838 } <a name="l00839"></a>00839 } <a name="l00840"></a>00840 <a name="l00841"></a>00841 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"m: "</span> << m << <span class="stringliteral">", b: "</span> << b << endl);<a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"use_missing: "</span> << use_missing << <span class="stringliteral">", missing: "</span> << missing << endl); <a name="l00842"></a>00842 <a name="l00843"></a>00843 <span class="comment">// Read the data, scale and return the result. Must replace the new data</span> <a name="l00844"></a>00844 <span class="comment">// in a constructor (i.e., Array part of a Grid).</span> <a name="l00845"></a>00845 <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> *dest = 0; <a name="l00846"></a>00846 <span class="keywordtype">double</span> *data; <a name="l00847"></a>00847 <span class="keywordflow">if</span> (argv[0]->type() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ac41525d2e860d3bcff641eb1fdba41d2">dods_grid_c</a>) { <a name="l00848"></a>00848 <a class="code" href="classlibdap_1_1Array.html" title="A multidimensional array of identical data types.">Array</a> &source = *<span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Grid.html" title="Holds the Grid data type.">Grid</a>&<span class="keyword">></span>(*argv[0]).get_array(); <a name="l00849"></a>00849 source.<a class="code" href="classlibdap_1_1Vector.html#a64815467570490a4a6cddc89f09a2413" title="Indicates that the data is ready to send.">set_send_p</a>(<span class="keyword">true</span>); <a name="l00850"></a>00850 source.<a class="code" href="classlibdap_1_1BaseType.html#a1da003c53f2e663223f603ab3fbd7c8e" title="Read data into a local buffer.">read</a>(); <a name="l00851"></a>00851 data = <a class="code" href="namespacelibdap.html#ae9717ce6442b4909dcd7add356a7ff88">extract_double_array</a>(&source); <a name="l00852"></a>00852 <span class="keywordtype">int</span> length = source.<a class="code" href="classlibdap_1_1Vector.html#a5990bd42b49e44c7b7da76e039896ba3">length</a>(); <a name="l00853"></a>00853 <span class="keywordtype">int</span> i = 0; <a name="l00854"></a>00854 <span class="keywordflow">while</span> (i < length) { <a name="l00855"></a>00855 <a class="code" href="debug_8h.html#ac1f764c266c50f0050e33557004c914c">DBG2</a>(cerr << <span class="stringliteral">"data["</span> << i << <span class="stringliteral">"]: "</span> << data[i] << endl); <a name="l00856"></a>00856 <span class="keywordflow">if</span> (!use_missing || !<a class="code" href="namespacelibdap.html#a7e55035aed27d6e56f7219405c803628">double_eq</a>(data[i], missing)) <a name="l00857"></a>00857 data[i] = data[i] * m + b; <a name="l00858"></a>00858 <a class="code" href="debug_8h.html#ac1f764c266c50f0050e33557004c914c">DBG2</a>(cerr << <span class="stringliteral">" >> data["</span> << i << <span class="stringliteral">"]: "</span> << data[i] << endl); <a name="l00859"></a>00859 ++i; <a name="l00860"></a>00860 } <a name="l00861"></a>00861 <a name="l00862"></a>00862 <span class="comment">// Vector::add_var will delete the existing 'template' variable</span> <a name="l00863"></a>00863 <a class="code" href="classlibdap_1_1Float64.html" title="Holds a 64-bit (double precision) floating point value.">Float64</a> *temp_f = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1Float64.html" title="Holds a 64-bit (double precision) floating point value.">Float64</a>(source.<a class="code" href="classlibdap_1_1BaseType.html#a0a0c6b5d57813607dc06255b8e0b9bdc" title="Returns the name of the class instance.">name</a>()); <a name="l00864"></a>00864 source.<a class="code" href="classlibdap_1_1Array.html#ac9a68fa480403f9b80285073c653570c" title="Add the BaseType pointer to this constructor type instance.">add_var</a>(temp_f); <a name="l00865"></a>00865 <span class="preprocessor">#ifdef VAL2BUF</span> <a name="l00866"></a>00866 <span class="preprocessor"></span> source.<a class="code" href="classlibdap_1_1Vector.html#a96ecf84f2798065878755d9a9014ee69" title="Reads data into the Vector buffer. Thrown if called for Structure, Sequence or Grid.">val2buf</a>(static_cast<void*>(data), <span class="keyword">false</span>); <a name="l00867"></a>00867 <span class="preprocessor">#else</span> <a name="l00868"></a>00868 <span class="preprocessor"></span> source.<a class="code" href="classlibdap_1_1Vector.html#ac6ffab2a00584c2963c0d521ad4028b5" title="set the value of a byte array">set_value</a>(data, i); <a name="l00869"></a>00869 <span class="preprocessor">#endif</span> <a name="l00870"></a>00870 <span class="preprocessor"></span> <span class="keyword">delete</span> [] data; <span class="comment">// val2buf copies.</span> <a name="l00871"></a>00871 <span class="keyword">delete</span> temp_f; <span class="comment">// add_var copies and then adds.</span> <a name="l00872"></a>00872 dest = argv[0]; <a name="l00873"></a>00873 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argv[0]->is_vector_type()) { <a name="l00874"></a>00874 <a class="code" href="classlibdap_1_1Array.html" title="A multidimensional array of identical data types.">Array</a> &source = <span class="keyword">dynamic_cast<</span><a class="code" href="classlibdap_1_1Array.html" title="A multidimensional array of identical data types.">Array</a>&<span class="keyword">></span>(*argv[0]); <a name="l00875"></a>00875 source.<a class="code" href="classlibdap_1_1Vector.html#a64815467570490a4a6cddc89f09a2413" title="Indicates that the data is ready to send.">set_send_p</a>(<span class="keyword">true</span>); <a name="l00876"></a>00876 <span class="comment">// If the array is really a map, make sure to read using the Grid</span> <a name="l00877"></a>00877 <span class="comment">// because of the HDF4 handler's odd behavior WRT dimensions.</span> <a name="l00878"></a>00878 <span class="keywordflow">if</span> (source.<a class="code" href="classlibdap_1_1BaseType.html#aeabb771d731dbcef92fff731fb429f85">get_parent</a>() && source.<a class="code" href="classlibdap_1_1BaseType.html#aeabb771d731dbcef92fff731fb429f85">get_parent</a>()-><a class="code" href="classlibdap_1_1BaseType.html#abc6b2d7099f00bb5f324ec129bff2a17" title="Returns the type of the class instance.">type</a>() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ac41525d2e860d3bcff641eb1fdba41d2">dods_grid_c</a>) <a name="l00879"></a>00879 source.<a class="code" href="classlibdap_1_1BaseType.html#aeabb771d731dbcef92fff731fb429f85">get_parent</a>()-><a class="code" href="classlibdap_1_1BaseType.html#a1da003c53f2e663223f603ab3fbd7c8e" title="Read data into a local buffer.">read</a>(); <a name="l00880"></a>00880 <span class="keywordflow">else</span> <a name="l00881"></a>00881 source.<a class="code" href="classlibdap_1_1BaseType.html#a1da003c53f2e663223f603ab3fbd7c8e" title="Read data into a local buffer.">read</a>(); <a name="l00882"></a>00882 <a name="l00883"></a>00883 data = <a class="code" href="namespacelibdap.html#ae9717ce6442b4909dcd7add356a7ff88">extract_double_array</a>(&source); <a name="l00884"></a>00884 <span class="keywordtype">int</span> length = source.<a class="code" href="classlibdap_1_1Vector.html#a5990bd42b49e44c7b7da76e039896ba3">length</a>(); <a name="l00885"></a>00885 <span class="keywordtype">int</span> i = 0; <a name="l00886"></a>00886 <span class="keywordflow">while</span> (i < length) { <a name="l00887"></a>00887 <span class="keywordflow">if</span> (!use_missing || !<a class="code" href="namespacelibdap.html#a7e55035aed27d6e56f7219405c803628">double_eq</a>(data[i], missing)) <a name="l00888"></a>00888 data[i] = data[i] * m + b; <a name="l00889"></a>00889 ++i; <a name="l00890"></a>00890 } <a name="l00891"></a>00891 <a name="l00892"></a>00892 <a class="code" href="classlibdap_1_1Float64.html" title="Holds a 64-bit (double precision) floating point value.">Float64</a> *temp_f = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1Float64.html" title="Holds a 64-bit (double precision) floating point value.">Float64</a>(source.<a class="code" href="classlibdap_1_1BaseType.html#a0a0c6b5d57813607dc06255b8e0b9bdc" title="Returns the name of the class instance.">name</a>()); <a name="l00893"></a>00893 source.<a class="code" href="classlibdap_1_1Array.html#ac9a68fa480403f9b80285073c653570c" title="Add the BaseType pointer to this constructor type instance.">add_var</a>(temp_f); <a name="l00894"></a>00894 <a name="l00895"></a>00895 source.<a class="code" href="classlibdap_1_1Vector.html#a96ecf84f2798065878755d9a9014ee69" title="Reads data into the Vector buffer. Thrown if called for Structure, Sequence or Grid.">val2buf</a>(static_cast<void*>(data), <span class="keyword">false</span>); <a name="l00896"></a>00896 <a name="l00897"></a>00897 <span class="keyword">delete</span> [] data; <span class="comment">// val2buf copies.</span> <a name="l00898"></a>00898 <span class="keyword">delete</span> temp_f; <span class="comment">// add_var copies and then adds.</span> <a name="l00899"></a>00899 <a name="l00900"></a>00900 dest = argv[0]; <a name="l00901"></a>00901 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argv[0]->is_simple_type() && !(argv[0]->type() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6ad620cef0bf41edebd4ee802071192a79">dods_str_c</a> <a name="l00902"></a>00902 || argv[0]->type() == <a class="code" href="namespacelibdap.html#a05ca706d4539ae7b750c3bc7066ab6e6a64d653d09a50d6d17537c43ed217f665">dods_url_c</a>)) { <a name="l00903"></a>00903 <span class="keywordtype">double</span> data = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[0]); <a name="l00904"></a>00904 <span class="keywordflow">if</span> (!use_missing || !<a class="code" href="namespacelibdap.html#a7e55035aed27d6e56f7219405c803628">double_eq</a>(data, missing)) <a name="l00905"></a>00905 data = data * m + b; <a name="l00906"></a>00906 <a name="l00907"></a>00907 dest = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1Float64.html" title="Holds a 64-bit (double precision) floating point value.">Float64</a>(argv[0]->name()); <a name="l00908"></a>00908 <a name="l00909"></a>00909 dest-><a class="code" href="classlibdap_1_1BaseType.html#ac360679317a411d7812ca235a1528281" title="Loads class data.">val2buf</a>(static_cast<void*>(&data)); <a name="l00910"></a>00910 <a name="l00911"></a>00911 } <span class="keywordflow">else</span> { <a name="l00912"></a>00912 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"The linear_scale() function works only for numeric Grids, Arrays and scalars."</span>); <a name="l00913"></a>00913 } <a name="l00914"></a>00914 <a name="l00915"></a>00915 *btpp = dest; <a name="l00916"></a>00916 <span class="keywordflow">return</span>; <a name="l00917"></a>00917 } <a name="l00918"></a>00918 <a name="l00919"></a>00919 <span class="preprocessor">#if 0</span> <a name="l00920"></a>00920 <span class="preprocessor"></span> <a name="l00936"></a>00936 <span class="keywordtype">void</span> <a name="l00937"></a>00937 <a class="code" href="namespacelibdap.html#abd2a0e965db0ed47f0206b4c646d9edd">function_geoarray</a>(<span class="keywordtype">int</span> argc, BaseType * argv[], DDS &, BaseType **btpp) <a name="l00938"></a>00938 { <a name="l00939"></a>00939 <span class="keywordtype">string</span> info = <a name="l00940"></a>00940 string(<span class="stringliteral">"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"</span>) + <a name="l00941"></a>00941 <span class="stringliteral">"<function name=\"geoarray\" version=\"0.9b1\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#geoarray\">\n"</span> + <a name="l00942"></a>00942 <span class="stringliteral">"</function>"</span>; <a name="l00943"></a>00943 <a name="l00944"></a>00944 <span class="keywordflow">if</span> (argc == 0) { <a name="l00945"></a>00945 Str *response = <span class="keyword">new</span> Str(<span class="stringliteral">"version"</span>); <a name="l00946"></a>00946 response->set_value(info); <a name="l00947"></a>00947 *btpp = response; <a name="l00948"></a>00948 <span class="keywordflow">return</span>; <a name="l00949"></a>00949 } <a name="l00950"></a>00950 <a name="l00951"></a>00951 <a class="code" href="debug_8h.html#a32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr << <span class="stringliteral">"argc = "</span> << argc << endl); <a name="l00952"></a>00952 <span class="keywordflow">if</span> (!(argc == 5 || argc == 9 || argc == 11)) <a name="l00953"></a>00953 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"Wrong number of arguments to geoarray(). See geoarray() for more information."</span>); <a name="l00954"></a>00954 <a name="l00955"></a>00955 <span class="comment">// Check the Array (and dup because the caller will free the variable).</span> <a name="l00956"></a>00956 Array *l_array = dynamic_cast < Array * >(argv[0]->ptr_duplicate()); <a name="l00957"></a>00957 <span class="keywordflow">if</span> (!l_array) <a name="l00958"></a>00958 <span class="keywordflow">throw</span> Error(<a class="code" href="Error_8h.html#a5806d25bc779e86c285438e687669803">malformed_expr</a>,<span class="stringliteral">"The first argument to geoarray() must be an Array variable!"</span>); <a name="l00959"></a>00959 <a name="l00960"></a>00960 <span class="keywordflow">try</span> { <a name="l00961"></a>00961 <a name="l00962"></a>00962 <span class="comment">// Read the bounding box and variable extents from the params</span> <a name="l00963"></a>00963 <span class="keywordtype">double</span> bb_top = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[1]); <a name="l00964"></a>00964 <span class="keywordtype">double</span> bb_left = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[2]); <a name="l00965"></a>00965 <span class="keywordtype">double</span> bb_bottom = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[3]); <a name="l00966"></a>00966 <span class="keywordtype">double</span> bb_right = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[4]); <a name="l00967"></a>00967 <a name="l00968"></a>00968 <span class="keywordflow">switch</span> (argc) { <a name="l00969"></a>00969 <span class="keywordflow">case</span> 5: { <a name="l00970"></a>00970 ArrayGeoConstraint agc(l_array); <a name="l00971"></a>00971 <a name="l00972"></a>00972 agc.set_bounding_box(bb_left, bb_top, bb_right, bb_bottom); <a name="l00973"></a>00973 <span class="comment">// This also reads all of the data into the grid variable</span> <a name="l00974"></a>00974 agc.apply_constraint_to_data(); <a name="l00975"></a>00975 *btpp = agc.get_constrained_array(); <a name="l00976"></a>00976 <span class="keywordflow">return</span>; <a name="l00977"></a>00977 <span class="keywordflow">break</span>; <a name="l00978"></a>00978 } <a name="l00979"></a>00979 <span class="keywordflow">case</span> 9: { <a name="l00980"></a>00980 <span class="keywordtype">double</span> var_top = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[5]); <a name="l00981"></a>00981 <span class="keywordtype">double</span> var_left = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[6]); <a name="l00982"></a>00982 <span class="keywordtype">double</span> var_bottom = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[7]); <a name="l00983"></a>00983 <span class="keywordtype">double</span> var_right = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[8]); <a name="l00984"></a>00984 ArrayGeoConstraint agc (l_array, var_left, var_top, var_right, var_bottom); <a name="l00985"></a>00985 <a name="l00986"></a>00986 agc.set_bounding_box(bb_left, bb_top, bb_right, bb_bottom); <a name="l00987"></a>00987 <span class="comment">// This also reads all of the data into the grid variable</span> <a name="l00988"></a>00988 agc.apply_constraint_to_data(); <a name="l00989"></a>00989 *btpp = agc.get_constrained_array(); <a name="l00990"></a>00990 <span class="keywordflow">return</span>; <a name="l00991"></a>00991 <span class="keywordflow">break</span>; <a name="l00992"></a>00992 } <a name="l00993"></a>00993 <span class="keywordflow">case</span> 11: { <a name="l00994"></a>00994 <span class="keywordtype">double</span> var_top = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[5]); <a name="l00995"></a>00995 <span class="keywordtype">double</span> var_left = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[6]); <a name="l00996"></a>00996 <span class="keywordtype">double</span> var_bottom = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[7]); <a name="l00997"></a>00997 <span class="keywordtype">double</span> var_right = <a class="code" href="namespacelibdap.html#a3c8b08223f4ea1841cf82dfc743a0d3a">extract_double_value</a>(argv[8]); <a name="l00998"></a>00998 <span class="keywordtype">string</span> projection = <a class="code" href="namespacelibdap.html#aca7eee077ab6dadb25126a92cf82737a">extract_string_argument</a>(argv[9]); <a name="l00999"></a>00999 <span class="keywordtype">string</span> datum = <a class="code" href="namespacelibdap.html#aca7eee077ab6dadb25126a92cf82737a">extract_string_argument</a>(argv[10]); <a name="l01000"></a>01000 ArrayGeoConstraint agc(l_array, <a name="l01001"></a>01001 var_left, var_top, var_right, var_bottom, <a name="l01002"></a>01002 projection, datum); <a name="l01003"></a>01003 <a name="l01004"></a>01004 agc.set_bounding_box(bb_left, bb_top, bb_right, bb_bottom); <a name="l01005"></a>01005 <span class="comment">// This also reads all of the data into the grid variable</span> <a name="l01006"></a>01006 agc.apply_constraint_to_data(); <a name="l01007"></a>01007 *btpp = agc.get_constrained_array(); <a name="l01008"></a>01008 <span class="keywordflow">return</span>; <a name="l01009"></a>01009 <span class="keywordflow">break</span>; <a name="l01010"></a>01010 } <a name="l01011"></a>01011 <span class="keywordflow">default</span>: <a name="l01012"></a>01012 <span class="keywordflow">throw</span> InternalErr(__FILE__, __LINE__, <span class="stringliteral">"Wrong number of args to geoarray."</span>); <a name="l01013"></a>01013 } <a name="l01014"></a>01014 } <a name="l01015"></a>01015 <span class="keywordflow">catch</span> (Error & e) { <a name="l01016"></a>01016 <span class="keywordflow">throw</span> e; <a name="l01017"></a>01017 } <a name="l01018"></a>01018 <span class="keywordflow">catch</span> (exception & e) { <a name="l01019"></a>01019 <span class="keywordflow">throw</span> <a name="l01020"></a>01020 InternalErr(<span class="keywordtype">string</span> <a name="l01021"></a>01021 (<span class="stringliteral">"A C++ exception was thrown from inside geoarray(): "</span>) <a name="l01022"></a>01022 + e.what()); <a name="l01023"></a>01023 <a name="l01024"></a>01024 } <a name="l01025"></a>01025 <a name="l01026"></a>01026 <span class="keywordflow">throw</span> InternalErr(__FILE__, __LINE__, <span class="stringliteral">"Impossible condition in geoarray."</span>); <a name="l01027"></a>01027 } <a name="l01028"></a>01028 <span class="preprocessor">#endif</span> <a name="l01029"></a>01029 <span class="preprocessor"></span> <a name="l01030"></a><a class="code" href="namespacelibdap.html#a5eeabecdc04289ca1ed78d333f29129d">01030</a> <span class="keywordtype">void</span> <a class="code" href="namespacelibdap.html#a5eeabecdc04289ca1ed78d333f29129d">register_functions</a>(<a class="code" href="classlibdap_1_1ConstraintEvaluator.html" title="Evaluate a constraint expression.">ConstraintEvaluator</a> & ce) <a name="l01031"></a>01031 { <a name="l01032"></a>01032 ce.<a class="code" href="classlibdap_1_1ConstraintEvaluator.html#ac42a51af20507806f1e04e24ed9cb0ac" title="Add a boolean function to the list.">add_function</a>(<span class="stringliteral">"grid"</span>, <a class="code" href="namespacelibdap.html#ad495b5febe1ea2b30f9fce7e31e98c9e">function_grid</a>); <a name="l01033"></a>01033 ce.<a class="code" href="classlibdap_1_1ConstraintEvaluator.html#ac42a51af20507806f1e04e24ed9cb0ac" title="Add a boolean function to the list.">add_function</a>(<span class="stringliteral">"geogrid"</span>, <a class="code" href="namespacelibdap.html#a97ebb2cf77302bf3dda2934593964ec4">function_geogrid</a>); <a name="l01034"></a>01034 ce.<a class="code" href="classlibdap_1_1ConstraintEvaluator.html#ac42a51af20507806f1e04e24ed9cb0ac" title="Add a boolean function to the list.">add_function</a>(<span class="stringliteral">"linear_scale"</span>, <a class="code" href="namespacelibdap.html#acb70f051b4691bdf6d1333a2a7a442f0">function_linear_scale</a>); <a name="l01035"></a>01035 <span class="preprocessor">#if 0</span> <a name="l01036"></a>01036 <span class="preprocessor"></span> ce.<a class="code" href="classlibdap_1_1ConstraintEvaluator.html#ac42a51af20507806f1e04e24ed9cb0ac" title="Add a boolean function to the list.">add_function</a>(<span class="stringliteral">"geoarray"</span>, <a class="code" href="namespacelibdap.html#abd2a0e965db0ed47f0206b4c646d9edd">function_geoarray</a>); <a name="l01037"></a>01037 <span class="preprocessor">#endif</span> <a name="l01038"></a>01038 <span class="preprocessor"></span> ce.<a class="code" href="classlibdap_1_1ConstraintEvaluator.html#ac42a51af20507806f1e04e24ed9cb0ac" title="Add a boolean function to the list.">add_function</a>(<span class="stringliteral">"version"</span>, <a class="code" href="namespacelibdap.html#a69a45fe57f5b17b8ab202f454b2f7556">function_version</a>); <a name="l01039"></a>01039 } <a name="l01040"></a>01040 <a name="l01041"></a>01041 } <span class="comment">// namespace libdap</span> </pre></div></div> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="ce__functions_8cc.html">ce_functions.cc</a> </li> <li class="footer">Generated on Tue Feb 8 2011 for libdap++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li> </ul> </div> </body> </html>