bes  Updated for version 3.17.0
reproj_functions.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2002,2003 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 // (c) COPYRIGHT URI/MIT 1999
26 // Please read the full copyright statement in the file COPYRIGHT_URI.
27 //
28 // Authors:
29 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
30 
31 
32 // These functions are used by the CE evaluator
33 //
34 // 1/15/99 jhrg
35 
36 #include "config.h"
37 
38 #include <limits.h>
39 
40 #if 0
41 #include <cstdlib> // used by strtod()
42 #include <cerrno>
43 #include <cmath>
44 #endif
45 #include <iostream>
46 #if 0
47 #include <vector>
48 #include <algorithm>
49 #endif
50 
51 // #include <gdal.h>
52 // #include <gdal_priv.h>
53 
54 #define DODS_DEBUG
55 
56 #include "BaseType.h"
57 
58 #include "Str.h"
59 #include "Array.h"
60 #include "Grid.h"
61 
62 #include "Error.h"
63 #include "debug.h"
64 
65 #include "DAP_Dataset.h"
66 #include "reproj_functions.h"
67 
68 // We wrapped VC++ 6.x strtod() to account for a short coming
69 // in that function in regards to "NaN". I don't know if this
70 // still applies in more recent versions of that product.
71 // ROM - 12/2007
72 #ifdef WIN32
73 #include <limits>
74 double w32strtod(const char *, char **);
75 #endif
76 
77 using namespace std;
78 //using namespace libdap;
79 
80 namespace libdap {
81 
90 void function_swath2array(int argc, BaseType * argv[], DDS &, BaseType **btpp)
91 {
92  DBG(cerr << "Entering function_swath2array..." << endl);
93 
94  // Use the same documentation for both swath2array and swath2grid
95  string info = string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
96  + "<function name=\"swath2array\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid\">\n"
97  + "</function>\n";
98 
99  if (argc == 0) {
100  Str *response = new Str("info");
101  response->set_value(info);
102  *btpp = response;
103  return;
104  }
105 
106  // TODO Add optional fourth arg that lets the caller say which datum to use;
107  // default to WGS84
108  if (argc != 3)
109  throw Error("The function swath2array() requires three arguments. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
110 
111  Array *src = dynamic_cast<Array*>(argv[0]);
112  if (!src)
113  throw Error("The first argument to swath2array() must be a data array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
114 
115  Array *lat = dynamic_cast<Array*>(argv[1]);
116  if (!lat)
117  throw Error("The second argument to swath2array() must be a latitude array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
118 
119  Array *lon = dynamic_cast<Array*>(argv[2]);
120  if (!lon)
121  throw Error("The third argument to swath2array() must be a longitude array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
122 
123  // The args passed into the function using argv[] are deleted after the call.
124 
125  DAP_Dataset ds(src, lat, lon);
126 
127  try {
128  ds.InitialDataset(0);
129 
130  *btpp = ds.GetDAPArray();
131  }
132  catch (Error &e) {
133  DBG(cerr << "caught Error: " << e.get_error_message() << endl);
134  throw e;
135  }
136  catch(...) {
137  DBG(cerr << "caught unknown exception" << endl);
138  throw;
139  }
140 
141  return;
142 }
143 
152 void function_swath2grid(int argc, BaseType * argv[], DDS &, BaseType **btpp)
153 {
154  DBG(cerr << "Entering function_swath2grid..." << endl);
155 
156  string info = string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
157  + "<function name=\"swath2grid\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid\">\n"
158  + "</function>\n";
159 
160  if (argc == 0) {
161  Str *response = new Str("info");
162  response->set_value(info);
163  *btpp = response;
164  return;
165  }
166 
167  // TODO Add optional fourth arg that lets the caller say which datum to use;
168  // default to WGS84
169  if (argc != 3)
170  throw Error("The function swath2grid() requires three arguments. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
171 
172  Array *src = dynamic_cast<Array*>(argv[0]);
173  if (!src)
174  throw Error("The first argument to swath2grid() must be a data array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
175 
176  Array *lat = dynamic_cast<Array*>(argv[1]);
177  if (!lat)
178  throw Error("The second argument to swath2grid() must be a latitude array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
179 
180  Array *lon = dynamic_cast<Array*>(argv[2]);
181  if (!lon)
182  throw Error("The third argument to swath2grid() must be a longitude array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");
183 
184  // The args passed into the function using argv[] are deleted after the call.
185 
186  DAP_Dataset ds(src, lat, lon);
187 
188  try {
189  ds.InitialDataset(0);
190 
191  *btpp = ds.GetDAPGrid();
192  }
193  catch (Error &e) {
194  DBG(cerr << "caught Error: " << e.get_error_message() << endl);
195  throw e;
196  }
197  catch(...) {
198  DBG(cerr << "caught unknown exception" << endl);
199  throw;
200  }
201 
202  return;
203 }
204 
205 
206 
207 
208 
209 } // namespace libdap
STL namespace.