58 using namespace libdap ;
67 cerr <<
"Usage: " << name << endl;
69 " [idDaxAVvks] [-B <db>][-c <expr>][-m <num>] <url> [<url> ...]" <<
71 cerr <<
" [VvksM] <file> [<file> ...]" << endl;
73 cerr <<
"In the first form of the command, dereference the URL and"
75 cerr <<
"perform the requested operations. This includes routing" <<
77 cerr <<
"the returned information through the DAP processing" << endl;
78 cerr <<
"library (parsing the returned objects, et c.). If none" <<
80 cerr <<
"of a, d, or D are used with a URL, then the DAP library" <<
82 cerr <<
"routines are NOT used and the URLs contents are dumped" <<
84 cerr <<
"to standard output." << endl;
86 cerr <<
"In the second form of the command, assume the files are" <<
88 cerr <<
"DataDDS objects (stored in files or read from pipes)" << endl;
89 cerr <<
"and process them as if -D were given. In this case the" <<
91 cerr <<
"information *must* contain valid MIME header in order" <<
93 cerr <<
"to be processed." << endl;
95 cerr <<
"Options:" << endl;
96 cerr <<
" i: For each URL, get the server version." << endl;
97 cerr <<
" d: For each URL, get the the DDS." << endl;
98 cerr <<
" a: For each URL, get the the DAS." << endl;
99 cerr <<
" D: For each URL, get the the DataDDS." << endl;
101 " x: For each URL, get the DDX object. Does not get data."
103 cerr <<
" X: Request a DataDDX from the server (the DAP4 data response" << endl;
104 cerr <<
" B: Build a DDX in getdap using the DDS and DAS." << endl;
105 cerr <<
" v: Verbose output." << endl;
106 cerr <<
" V: Version of this client; see 'i' for server version." << endl;
107 cerr <<
" c: <expr> is a constraint expression. Used with -D/X." <<
109 cerr <<
" NB: You can use a `?' for the CE also." << endl;
110 cerr <<
" k: Keep temporary files created by libdap." << endl;
111 cerr <<
" m: Request the same URL <num> times." << endl;
112 cerr <<
" z: Ask the server to compress data." << endl;
113 cerr <<
" s: Print Sequences using numbered rows." << endl;
114 cerr <<
" M: Assume data read from a file has no MIME headers" << endl;
115 cerr <<
" (the default is to assume the headers are present)." << endl;
116 cerr <<
" p: Set DAP protocol to x.y" << endl;
122 fprintf(stderr,
"getdap: Whoa!!! Null stream pointer.\n");
129 while (fp && !feof(fp) && fread(&c, 1, 1, fp))
135 static void print_data(
DDS & dds,
bool print_rows =
false)
137 cout <<
"The data:" << endl;
142 dynamic_cast < Sequence * >(*i)->print_val_by_rows(cout);
147 cout << endl << flush;
150 int main(
int argc,
char *argv[])
152 GetOpt getopt(argc, argv,
"idaDxXBVvkc:m:zshM?Hp:t");
155 bool get_das =
false;
156 bool get_dds =
false;
157 bool get_data =
false;
158 bool get_ddx =
false;
159 bool get_data_ddx =
false;
160 bool build_ddx =
false;
161 bool get_version =
false;
163 bool verbose =
false;
165 bool accept_deflate =
false;
166 bool print_rows =
false;
167 bool mime_headers =
true;
169 int dap_client_major = 2;
170 int dap_client_minor = 0;
174 _setmode(_fileno(stdout), _O_BINARY);
177 while ((option_char = getopt()) != EOF)
178 switch (option_char) {
195 fprintf(stderr,
"getdap version: %s\n",
version);
208 expr = getopt.optarg;
212 times = atoi(getopt.optarg);
218 accept_deflate =
true;
224 mime_headers =
false;
227 istringstream iss(getopt.optarg);
229 iss >> dap_client_major;
231 iss >> dap_client_minor;
248 for (
int i = getopt.optind; i < argc; ++i) {
250 fprintf(stderr,
"Fetching: %s\n", argv[i]);
252 string name = argv[i];
261 if (dap_client_major > 2)
267 "Assuming that the argument %s is a file that contains a DAP2 data object; decoding.\n", argv[i]);
275 if (strcmp(argv[i],
"-") == 0) {
279 throw Error(
"Could not open standard input.");
287 r =
new Response(fopen(argv[i],
"r"), 0);
290 throw Error(
string(
"The input source: ")
292 + string(
" could not be opened"));
307 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
311 print_data(dds, print_rows);
315 else if (get_version) {
316 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
322 for (
int j = 0; j < times; ++j) {
335 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
339 fprintf(stderr,
"DAS:\n");
347 for (
int j = 0; j < times; ++j) {
361 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
365 fprintf(stderr,
"DDS:\n");
373 for (
int j = 0; j < times; ++j) {
385 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
389 fprintf(stderr,
"DDX:\n");
396 else if (build_ddx) {
397 for (
int j = 0; j < times; ++j) {
412 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
416 fprintf(stderr,
"Client-built DDX:\n");
424 for (
int j = 0; j < times; ++j) {
428 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
429 DBG(cerr <<
"CE: " << expr << endl);
433 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
437 print_data(dds, print_rows);
448 else if (get_data_ddx) {
449 for (
int j = 0; j < times; ++j) {
453 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
454 DBG(cerr <<
"CE: " << expr << endl);
458 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
462 print_data(dds, print_rows);
485 if (dap_client_major > 2)
488 string url_string = argv[i];
489 for (
int j = 0; j < times; ++j) {
513 catch (exception &e) {
514 cerr <<
"C++ library exception: " << e.what() << endl;