39 {
"$Id: getdap.cc 21695 2009-11-04 17:45:04Z jimg $" 71 cerr <<
"Usage: " << name << endl;
73 " [idDaxAVvks] [-B <db>][-c <expr>][-m <num>] <url> [<url> ...]" <<
75 cerr <<
" [VvksM] <file> [<file> ...]" << endl;
77 cerr <<
"In the first form of the command, dereference the URL and" 79 cerr <<
"perform the requested operations. This includes routing" <<
81 cerr <<
"the returned information through the DAP processing" << endl;
82 cerr <<
"library (parsing the returned objects, et c.). If none" <<
84 cerr <<
"of a, d, or D are used with a URL, then the DAP library" <<
86 cerr <<
"routines are NOT used and the URLs contents are dumped" <<
88 cerr <<
"to standard output." << endl;
90 cerr <<
"In the second form of the command, assume the files are" <<
92 cerr <<
"DataDDS objects (stored in files or read from pipes)" << endl;
93 cerr <<
"and process them as if -D were given. In this case the" <<
95 cerr <<
"information *must* contain valid MIME header in order" <<
97 cerr <<
"to be processed." << endl;
99 cerr <<
"Options:" << endl;
100 cerr <<
" i: For each URL, get the server version." << endl;
101 cerr <<
" d: For each URL, get the the DDS." << endl;
102 cerr <<
" a: For each URL, get the the DAS." << endl;
103 cerr <<
" D: For each URL, get the the DataDDS." << endl;
105 " x: For each URL, get the DDX object. Does not get data." 107 cerr <<
" X: Request a DataDDX from the server (the DAP4 data response" << endl;
108 cerr <<
" B: Build a DDX in getdap using the DDS and DAS." << endl;
109 cerr <<
" v: Verbose output." << endl;
110 cerr <<
" V: Version of this client; see 'i' for server version." << endl;
111 cerr <<
" c: <expr> is a constraint expression. Used with -D/X." <<
113 cerr <<
" NB: You can use a `?' for the CE also." << endl;
114 cerr <<
" k: Keep temporary files created by libdap." << endl;
115 cerr <<
" m: Request the same URL <num> times." << endl;
116 cerr <<
" z: Ask the server to compress data." << endl;
117 cerr <<
" s: Print Sequences using numbered rows." << endl;
118 cerr <<
" M: Assume data read from a file has no MIME headers" << endl;
119 cerr <<
" (the default is to assume the headers are present)." << endl;
120 cerr <<
" p: Set DAP protocol to x.y" << endl;
126 fprintf(stderr,
"getdap: Whoa!!! Null stream pointer.\n");
133 while (fp && !feof(fp) && fread(&c, 1, 1, fp))
139 static void print_data(
DDS & dds,
bool print_rows =
false)
141 cout <<
"The data:" << endl;
146 dynamic_cast < Sequence * >(*i)->print_val_by_rows(cout);
151 cout << endl << flush;
154 int main(
int argc,
char *argv[])
156 GetOpt getopt(argc, argv,
"idaDxXBVvkc:m:zshM?Hp:t");
159 bool get_das =
false;
160 bool get_dds =
false;
161 bool get_data =
false;
162 bool get_ddx =
false;
163 bool get_data_ddx =
false;
164 bool build_ddx =
false;
165 bool get_version =
false;
167 bool verbose =
false;
169 bool accept_deflate =
false;
170 bool print_rows =
false;
171 bool mime_headers =
true;
173 int dap_client_major = 2;
174 int dap_client_minor = 0;
178 _setmode(_fileno(stdout), _O_BINARY);
181 while ((option_char = getopt()) != EOF)
182 switch (option_char) {
199 fprintf(stderr,
"getdap version: %s\n",
version);
212 expr = getopt.optarg;
216 times = atoi(getopt.optarg);
222 accept_deflate =
true;
228 mime_headers =
false;
231 istringstream iss(getopt.optarg);
233 iss >> dap_client_major;
235 iss >> dap_client_minor;
252 for (
int i = getopt.optind; i < argc; ++i) {
254 fprintf(stderr,
"Fetching: %s\n", argv[i]);
256 string name = argv[i];
265 if (dap_client_major > 2)
271 "Assuming that the argument %s is a file that contains a DAP2 data object; decoding.\n", argv[i]);
279 if (strcmp(argv[i],
"-") == 0) {
283 throw Error(
"Could not open standard input.");
291 r =
new Response(fopen(argv[i],
"r"), 0);
294 throw Error(
string(
"The input source: ")
296 + string(
" could not be opened"));
311 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
315 print_data(dds, print_rows);
319 else if (get_version) {
320 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
326 for (
int j = 0; j < times; ++j) {
339 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
343 fprintf(stderr,
"DAS:\n");
351 for (
int j = 0; j < times; ++j) {
365 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
369 fprintf(stderr,
"DDS:\n");
377 for (
int j = 0; j < times; ++j) {
389 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
393 fprintf(stderr,
"DDX:\n");
400 else if (build_ddx) {
401 for (
int j = 0; j < times; ++j) {
416 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
420 fprintf(stderr,
"Client-built DDX:\n");
428 for (
int j = 0; j < times; ++j) {
432 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
433 DBG(cerr <<
"CE: " << expr << endl);
437 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
441 print_data(dds, print_rows);
452 else if (get_data_ddx) {
453 for (
int j = 0; j < times; ++j) {
457 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
458 DBG(cerr <<
"CE: " << expr << endl);
462 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
466 print_data(dds, print_rows);
489 if (dap_client_major > 2)
492 string url_string = argv[i];
493 for (
int j = 0; j < times; ++j) {
517 catch (exception &e) {
518 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.
HTTPResponse * fetch_url(const string &url)
virtual void print(FILE *out, bool dereference=false)
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 FILE * get_stream() const
std::vector< BaseType * >::iterator Vars_iter
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...
string get_error_message() const
virtual void request_das(DAS &das)
Get the DAS from a server.
void set_accept_deflate(bool defalte)
Vars_iter var_end()
Return an iterator.
Encapsulate a response read from stdin.
The basic data type for the DODS DAP types.
virtual void request_data_ddx(DataDDS &data, string expr="")
int main(int argc, char *argv[])
virtual string request_protocol()
Hold attribute data for a DAP2 dataset.
A class for error processing.
#define DAP_PROTOCOL_VERSION
static RCReader * instance()
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)=0
Prints the value of the variable.