libdap
Updated for version 3.19.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
|
52 #include "StdinResponse.h"
60 const char *version = CVER
" (" DVR
" DAP/" DAP_PROTOCOL_VERSION
")";
62 extern int libdap::dods_keep_temps;
63 extern int libdap::www_trace;
65 void usage(
string name)
67 cerr <<
"Usage: " << name << endl;
68 cerr <<
" [idaDxBzp vVkms][-c <expr>][-m <num>] <url> [<url> ...]" << endl;
69 cerr <<
" [M vVkms] <file> [<file> ...]" << endl;
71 cerr <<
"In the first form of the command, dereference the URL and" << endl;
72 cerr <<
"perform the requested operations. This includes routing" << endl;
73 cerr <<
"the returned information through the DAP processing" << endl;
74 cerr <<
"library (parsing the returned objects, et c.). If none" << endl;
75 cerr <<
"of a, d, or D are used with a URL, then the DAP library" << endl;
76 cerr <<
"routines are NOT used and the URLs contents are dumped" << endl;
77 cerr <<
"to standard output." << endl;
79 cerr <<
"In the second form of the command, assume the files are" << endl;
80 cerr <<
"DataDDS objects (stored in files or read from pipes)" << endl;
81 cerr <<
"and process them as if -D were given. In this case the" << endl;
82 cerr <<
"information *must* contain valid MIME header in order" << endl;
83 cerr <<
"to be processed." << endl;
85 cerr <<
"Options:" << endl;
86 cerr <<
" i: For each URL, get the server version." << endl;
87 cerr <<
" d: For each URL, get the the DDS." << endl;
88 cerr <<
" a: For each URL, get the the DAS." << endl;
89 cerr <<
" D: For each URL, get the the DataDDS." << endl;
90 cerr <<
" x: For each URL, get the (DAP2) DDX object. Does not get data." << endl;
91 cerr <<
" B: Build a DDX in getdap using the DDS and DAS." << endl;
92 cerr <<
" v: Verbose output." << endl;
93 cerr <<
" V: Version of this client; see 'i' for server version." << endl;
94 cerr <<
" c: <expr> is a constraint expression. Used with -D/X and -d/r" << endl;
95 cerr <<
" NB: You can use a `?' for the CE also." << endl;
96 cerr <<
" k: Keep temporary files created by libdap." << endl;
97 cerr <<
" m: Request the same URL <num> times." << endl;
98 cerr <<
" z: Ask the server to compress data." << endl;
99 cerr <<
" s: Print Sequences using numbered rows." << endl;
100 cerr <<
" M: Assume data read from a file has no MIME headers" << endl;
101 cerr <<
" (the default is to assume the headers are present)." << endl;
102 cerr <<
" p: Set DAP protocol to x.y" << endl;
105 bool read_data(FILE * fp)
108 fprintf(stderr,
"getdap: Whoa!!! Null stream pointer.\n");
115 while (fp && !feof(fp) && fread(&c, 1, 1, fp))
121 static void print_data(
DDS & dds,
bool print_rows =
false)
123 cout <<
"The data:" << endl;
127 if (print_rows && (*i)->type() == dods_sequence_c)
128 dynamic_cast < Sequence *
>(*i)->print_val_by_rows(cout);
133 cout << endl << flush;
136 int main(
int argc,
char *argv[])
138 GetOpt getopt(argc, argv,
"idaDxrXBVvkc:m:zshM?Hp:t");
141 bool get_das =
false;
142 bool get_dds =
false;
143 bool get_data =
false;
144 bool get_ddx =
false;
145 bool build_ddx =
false;
146 bool get_version =
false;
148 bool verbose =
false;
150 bool accept_deflate =
false;
151 bool print_rows =
false;
152 bool mime_headers =
true;
154 int dap_client_major = 2;
155 int dap_client_minor = 0;
159 _setmode(_fileno(stdout), _O_BINARY);
162 while ((option_char = getopt()) != -1)
163 switch (option_char) {
177 fprintf(stderr,
"getdap version: %s\n", version);
190 expr = getopt.optarg;
194 times = atoi(getopt.optarg);
200 accept_deflate =
true;
206 mime_headers =
false;
209 istringstream iss(getopt.optarg);
211 iss >> dap_client_major;
213 iss >> dap_client_minor;
230 for (
int i = getopt.optind; i < argc; ++i) {
232 fprintf(stderr,
"Fetching: %s\n", argv[i]);
234 string name = argv[i];
243 if (dap_client_major > 2)
246 if (url->is_local()) {
248 fprintf(stderr,
"Assuming that the argument %s is a file that contains a response object; decoding.\n", argv[i]);
257 if (strcmp(argv[i],
"-") == 0) {
260 if (!r->get_stream())
261 throw Error(
"Could not open standard input.");
269 r =
new Response(fopen(argv[i],
"r"), 0);
271 if (!r->get_stream())
272 throw Error(
string(
"The input source: ")
274 +
string(
" could not be opened"));
289 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
293 print_data(dds, print_rows);
297 else if (get_version) {
298 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
304 for (
int j = 0; j < times; ++j) {
317 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
321 fprintf(stderr,
"DAS:\n");
329 for (
int j = 0; j < times; ++j) {
343 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
347 fprintf(stderr,
"DDS:\n");
355 for (
int j = 0; j < times; ++j) {
367 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
371 fprintf(stderr,
"DDX:\n");
378 else if (build_ddx) {
379 for (
int j = 0; j < times; ++j) {
394 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
398 fprintf(stderr,
"Client-built DDX:\n");
406 for (
int j = 0; j < times; ++j) {
410 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
411 DBG(cerr <<
"CE: " << expr << endl);
415 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
419 print_data(dds, print_rows);
439 http.set_accept_deflate(accept_deflate);
441 if (dap_client_major > 2)
444 string url_string = argv[i];
445 for (
int j = 0; j < times; ++j) {
447 Response *r = http.fetch_url(url_string);
448 if (!read_data(r->get_stream())) {
469 catch (exception &e) {
470 cerr <<
"C++ library exception: " << e.what() << endl;
virtual string URL(bool CE=true)
Get the object's URL.
virtual void request_ddx(DDS &dds, string expr="")
Get the DDX from a server.
void set_xdap_protocol(int major, int minor)
void print_xml(FILE *out, bool constrained, const string &blob="")
A class for error processing.
Encapsulate a response read from stdin.
string get_error_message() const
Hold attribute data for a DAP2 dataset.
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...
void print(FILE *out)
Print the entire DDS to the specified file.
virtual void request_data(DataDDS &data, string expr="")
Get the DAS 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...
virtual void request_dds(DDS &dds, string expr="")
Get the DDS from a server.
virtual void request_das(DAS &das)
Get the DAS from a server.
void set_accept_deflate(bool deflate)
Vars_iter var_begin()
Return an iterator to the first variable.
virtual void print(FILE *out, bool dereference=false)
virtual string request_protocol()
Holds information about the link from a DAP2 client to a dataset.
The basic data type for the DODS DAP types.
virtual void transfer_attributes(DAS *das)
Vars_iter var_end()
Return an iterator.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.