54#include "StdinResponse.h"
62const char *version = CVER
" (" DVR
" DAP/" DAP_PROTOCOL_VERSION
")";
64extern int libdap::dods_keep_temps;
65extern int libdap::www_trace;
66extern int libdap::www_trace_extensive;
68void usage(
string name)
70 cerr <<
"Usage: " << name << endl;
71 cerr <<
" [idaDxBzp vVkms][-c <expr>][-m <num>] <url> [<url> ...]" << endl;
72 cerr <<
" [M vVkms] <file> [<file> ...]" << endl;
74 cerr <<
"In the first form of the command, dereference the URL and" << endl;
75 cerr <<
"perform the requested operations. This includes routing" << endl;
76 cerr <<
"the returned information through the DAP processing" << endl;
77 cerr <<
"library (parsing the returned objects, et c.). If none" << endl;
78 cerr <<
"of a, d, or D are used with a URL, then the DAP library" << endl;
79 cerr <<
"routines are NOT used and the URLs contents are dumped" << endl;
80 cerr <<
"to standard output." << endl;
82 cerr <<
"In the second form of the command, assume the files are" << endl;
83 cerr <<
"DataDDS objects (stored in files or read from pipes)" << endl;
84 cerr <<
"and process them as if -D were given. In this case the" << endl;
85 cerr <<
"information *must* contain valid MIME header in order" << endl;
86 cerr <<
"to be processed." << endl;
88 cerr <<
"Options:" << endl;
89 cerr <<
" i: For each URL, get the server version." << endl;
90 cerr <<
" d: For each URL, get the the DDS." << endl;
91 cerr <<
" a: For each URL, get the the DAS." << endl;
92 cerr <<
" D: For each URL, get the the DataDDS." << endl;
93 cerr <<
" x: For each URL, get the (DAP2) DDX object. Does not get data." << endl;
94 cerr <<
" B: Build a DDX in getdap using the DDS and DAS." << endl;
95 cerr <<
" v: Verbose output." << endl;
96 cerr <<
" e: Extensive (or very) verbose." << endl;
97 cerr <<
" V: Version of this client; see 'i' for server version." << endl;
98 cerr <<
" c: <expr> is a constraint expression. Used with -D/X and -d/r" << endl;
99 cerr <<
" NB: You can use a `?' for the CE also." << endl;
100 cerr <<
" k: Keep temporary files created by libdap." << endl;
101 cerr <<
" m: Request the same URL <num> times." << endl;
102 cerr <<
" z: Ask the server to compress data." << endl;
103 cerr <<
" s: Print Sequences using numbered rows." << endl;
104 cerr <<
" M: Assume data read from a file has no MIME headers" << endl;
105 cerr <<
" (the default is to assume the headers are present)." << endl;
106 cerr <<
" p: Set DAP protocol to x.y" << endl;
109bool read_data(FILE * fp)
112 fprintf(stderr,
"getdap: Whoa!!! Null stream pointer.\n");
119 while (fp && !feof(fp) && fread(&c, 1, 1, fp))
125static void print_data(
DDS & dds,
bool print_rows =
false)
127 cout <<
"The data:" << endl;
131 if (print_rows && (*i)->type() == dods_sequence_c)
132 dynamic_cast < Sequence *
>(*i)->print_val_by_rows(cout);
137 cout << endl << flush;
140int main(
int argc,
char *argv[])
142 GetOpt getopt(argc, argv,
"idaDxrXBVvekc:m:zshM?Hp:t");
145 bool get_das =
false;
146 bool get_dds =
false;
147 bool get_data =
false;
148 bool get_ddx =
false;
149 bool build_ddx =
false;
150 bool get_version =
false;
151 bool verbose =
false;
152 bool accept_deflate =
false;
153 bool print_rows =
false;
154 bool mime_headers =
true;
156 int dap_client_major = 2;
157 int dap_client_minor = 0;
161 _setmode(_fileno(stdout), _O_BINARY);
164 while ((option_char = getopt()) != -1)
165 switch (option_char) {
179 fprintf(stderr,
"getdap version: %s\n", version);
191 www_trace_extensive = 1;
197 expr = getopt.optarg;
200 times = atoi(getopt.optarg);
206 accept_deflate =
true;
212 mime_headers =
false;
215 istringstream iss(getopt.optarg);
217 iss >> dap_client_major;
219 iss >> dap_client_minor;
235 for (
int i = getopt.optind; i < argc; ++i) {
237 fprintf(stderr,
"Fetching: %s\n", argv[i]);
239 string name = argv[i];
248 if (dap_client_major > 2)
251 if (url->is_local()) {
253 fprintf(stderr,
"Assuming that the argument %s is a file that contains a response object; decoding.\n", argv[i]);
262 if (strcmp(argv[i],
"-") == 0) {
265 if (!r->get_stream())
266 throw Error(
"Could not open standard input.");
274 r =
new Response(fopen(argv[i],
"r"), 0);
276 if (!r->get_stream())
277 throw Error(
string(
"The input source: ")
279 +
string(
" could not be opened"));
285 cerr << e.get_error_message() << endl;
294 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
298 print_data(dds, print_rows);
302 else if (get_version) {
303 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
309 for (
int j = 0; j < times; ++j) {
315 cerr << e.get_error_message() << endl;
322 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
326 fprintf(stderr,
"DAS:\n");
334 for (
int j = 0; j < times; ++j) {
341 cerr << e.get_error_message() << endl;
348 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
352 fprintf(stderr,
"DDS:\n");
360 for (
int j = 0; j < times; ++j) {
367 cerr << e.get_error_message() << endl;
372 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
376 fprintf(stderr,
"DDX:\n");
383 else if (build_ddx) {
384 for (
int j = 0; j < times; ++j) {
394 cerr << e.get_error_message() << endl;
399 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
403 fprintf(stderr,
"Client-built DDX:\n");
411 for (
int j = 0; j < times; ++j) {
415 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
416 DBG(cerr <<
"CE: " << expr << endl);
420 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
424 print_data(dds, print_rows);
427 cerr << e.get_error_message() << endl;
444 http.set_accept_deflate(accept_deflate);
446 if (dap_client_major > 2)
449 string url_string = argv[i];
450 for (
int j = 0; j < times; ++j) {
452 Response *r = http.fetch_url(url_string);
453 if (!read_data(r->get_stream())) {
460 cerr << e.get_error_message() << endl;
471 cerr << e.get_error_message() << endl;
475 catch (exception &e) {
476 cerr <<
"C++ library exception: " << e.what() << endl;
The basic data type for the DODS DAP types.
Holds information about the link from a DAP2 client to a dataset.
void set_accept_deflate(bool deflate)
virtual void request_ddx(DDS &dds, string expr="")
Get the DDX from a server.
virtual void read_data_no_mime(DataDDS &data, Response *rs)
Read data from a file which does not have response MIME headers. This method is a companion to read_d...
void set_xdap_protocol(int major, int minor)
virtual string URL(bool CE=true)
Get the object's URL.
virtual void request_data(DataDDS &data, string expr="")
Get the DAS from a server.
virtual void request_das(DAS &das)
Get the DAS from a server.
virtual string request_protocol()
virtual void request_dds(DDS &dds, string expr="")
Get the DDS from a server.
virtual void read_data(DataDDS &data, Response *rs)
Read data which is preceded by MIME headers. This method works for both data dds and data ddx respons...
Hold attribute data for a DAP2 dataset.
virtual void transfer_attributes(DAS *das)
void print(FILE *out)
Print the entire DDS to the specified file.
void print_xml(FILE *out, bool constrained, const string &blob="")
Vars_iter var_end()
Return an iterator.
A class for error processing.
Encapsulate a response read from stdin.
top level DAP object to house generic methods