54 #include "StdinResponse.h" 62 const char *version = CVER
" (" DVR
" DAP/" DAP_PROTOCOL_VERSION
")";
64 extern int libdap::dods_keep_temps;
65 extern int libdap::www_trace;
66 extern int libdap::www_trace_extensive;
68 void 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;
109 bool read_data(FILE * fp)
112 fprintf(stderr,
"getdap: Whoa!!! Null stream pointer.\n");
119 while (fp && !feof(fp) && fread(&c, 1, 1, fp))
125 static 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;
140 int 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;
152 bool verbose =
false;
154 bool accept_deflate =
false;
155 bool print_rows =
false;
156 bool mime_headers =
true;
158 int dap_client_major = 2;
159 int dap_client_minor = 0;
163 _setmode(_fileno(stdout), _O_BINARY);
166 while ((option_char = getopt()) != -1)
167 switch (option_char) {
181 fprintf(stderr,
"getdap version: %s\n", version);
193 www_trace_extensive = 1;
200 expr = getopt.optarg;
204 times = atoi(getopt.optarg);
210 accept_deflate =
true;
216 mime_headers =
false;
219 istringstream iss(getopt.optarg);
221 iss >> dap_client_major;
223 iss >> dap_client_minor;
239 for (
int i = getopt.optind; i < argc; ++i) {
241 fprintf(stderr,
"Fetching: %s\n", argv[i]);
243 string name = argv[i];
252 if (dap_client_major > 2)
255 if (url->is_local()) {
257 fprintf(stderr,
"Assuming that the argument %s is a file that contains a response object; decoding.\n", argv[i]);
266 if (strcmp(argv[i],
"-") == 0) {
269 if (!r->get_stream())
270 throw Error(
"Could not open standard input.");
278 r =
new Response(fopen(argv[i],
"r"), 0);
280 if (!r->get_stream())
281 throw Error(
string(
"The input source: ")
283 + string(
" could not be opened"));
298 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
302 print_data(dds, print_rows);
306 else if (get_version) {
307 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
313 for (
int j = 0; j < times; ++j) {
326 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
330 fprintf(stderr,
"DAS:\n");
338 for (
int j = 0; j < times; ++j) {
352 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
356 fprintf(stderr,
"DDS:\n");
364 for (
int j = 0; j < times; ++j) {
376 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
380 fprintf(stderr,
"DDX:\n");
387 else if (build_ddx) {
388 for (
int j = 0; j < times; ++j) {
403 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
407 fprintf(stderr,
"Client-built DDX:\n");
415 for (
int j = 0; j < times; ++j) {
419 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
420 DBG(cerr <<
"CE: " << expr << endl);
424 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
428 print_data(dds, print_rows);
448 http.set_accept_deflate(accept_deflate);
450 if (dap_client_major > 2)
453 string url_string = argv[i];
454 for (
int j = 0; j < times; ++j) {
456 Response *r = http.fetch_url(url_string);
457 if (!read_data(r->get_stream())) {
479 catch (exception &e) {
480 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.