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;
229 for (
int i = getopt.optind; i < argc; ++i) {
231 fprintf(stderr,
"Fetching: %s\n", argv[i]);
233 string name = argv[i];
242 if (dap_client_major > 2)
245 if (url->is_local()) {
247 fprintf(stderr,
"Assuming that the argument %s is a file that contains a response object; decoding.\n", argv[i]);
256 if (strcmp(argv[i],
"-") == 0) {
259 if (!r->get_stream())
260 throw Error(
"Could not open standard input.");
268 r =
new Response(fopen(argv[i],
"r"), 0);
270 if (!r->get_stream())
271 throw Error(
string(
"The input source: ")
273 + string(
" could not be opened"));
288 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
292 print_data(dds, print_rows);
296 else if (get_version) {
297 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
303 for (
int j = 0; j < times; ++j) {
316 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
320 fprintf(stderr,
"DAS:\n");
328 for (
int j = 0; j < times; ++j) {
342 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
346 fprintf(stderr,
"DDS:\n");
354 for (
int j = 0; j < times; ++j) {
366 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
370 fprintf(stderr,
"DDX:\n");
377 else if (build_ddx) {
378 for (
int j = 0; j < times; ++j) {
393 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
397 fprintf(stderr,
"Client-built DDX:\n");
405 for (
int j = 0; j < times; ++j) {
409 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
410 DBG(cerr <<
"CE: " << expr << endl);
414 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
418 print_data(dds, print_rows);
438 http.set_accept_deflate(accept_deflate);
440 if (dap_client_major > 2)
443 string url_string = argv[i];
444 for (
int j = 0; j < times; ++j) {
446 Response *r = http.fetch_url(url_string);
447 if (!read_data(r->get_stream())) {
468 catch (exception &e) {
469 cerr <<
"C++ library exception: " << e.what() << endl;
virtual void request_ddx(DDS &dds, string expr="")
Get the DDX from a server.
void print(FILE *out)
Print the entire DDS to the specified file.
virtual string URL(bool CE=true)
Get the object's URL.
void set_xdap_protocol(int major, int minor)
Vars_iter var_begin()
Return an iterator to the first variable.
virtual void transfer_attributes(DAS *das)
void print_xml(FILE *out, bool constrained, const string &blob="")
Holds information about the link from a DAP2 client to a dataset.
virtual void print(FILE *out, bool dereference=false)
top level DAP object to house generic methods
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...
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual void request_dds(DDS &dds, string expr="")
Get the DDS from a server.
void set_accept_deflate(bool deflate)
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...
std::string get_error_message() const
virtual void request_das(DAS &das)
Get the DAS from a server.
Vars_iter var_end()
Return an iterator.
Encapsulate a response read from stdin.
The basic data type for the DODS DAP types.
virtual string request_protocol()
Hold attribute data for a DAP2 dataset.
A class for error processing.