67 static void usage(
const string &name)
69 cerr <<
"Usage: " << name << endl;
70 cerr <<
" [dD vVikmzstM][-c <expr>][-m <num>] <url> [<url> ...] | <file> [<file> ...]" << endl;
72 cerr <<
"In the first form of the command, dereference the URL and" << endl;
73 cerr <<
"perform the requested operations. This includes routing" << endl;
74 cerr <<
"the returned information through the DAP processing" << endl;
75 cerr <<
"library (parsing the returned objects, et c.). If none" << endl;
76 cerr <<
"of a, d, or D are used with a URL, then the DAP library" << endl;
77 cerr <<
"routines are NOT used and the URLs contents are dumped" << endl;
78 cerr <<
"to standard output." << endl;
80 cerr <<
"In the second form of the command, assume the files are" << endl;
81 cerr <<
"DataDDS objects (stored in files or read from pipes)" << endl;
82 cerr <<
"and process them as if -D were given. In this case the" << endl;
83 cerr <<
"information *must* contain valid MIME header in order" << endl;
84 cerr <<
"to be processed." << endl;
86 cerr <<
"Options:" << endl;
87 cerr <<
" d: For each URL, get the (DAP4) DMR object. Does not get data." << endl;
88 cerr <<
" D: For each URL, get the DAP4 Data response." << endl;
90 cerr <<
" v: Verbose output." << endl;
91 cerr <<
" V: Version of this client; see 'i' for server version." << endl;
92 cerr <<
" i: For each URL, get the server version." << endl;
93 cerr <<
" k: Keep temporary files created by libdap." << endl;
94 cerr <<
" m: Request the same URL <num> times." << endl;
95 cerr <<
" z: Ask the server to compress data." << endl;
96 cerr <<
" s: Print Sequences using numbered rows." << endl;
97 cerr <<
" t: Trace www accesses." << endl;
98 cerr <<
" M: Assume data read from a file has no MIME headers; use only with files" << endl;
100 cerr <<
" c: <expr> is a constraint expression. Used with -d/D" << endl;
101 cerr <<
" NB: You can use a `?' for the CE also." << endl;
109 fprintf(stderr,
"getdap4: Whoa!!! Null stream pointer.\n");
116 while (fp && !feof(fp) && fread(&c, 1, 1, fp))
123 static void read_response_from_file(
D4Connect *url,
DMR &dmr,
Response &r,
bool mime_headers,
bool get_dap4_data,
bool get_dmr)
131 throw Error(
"Only supports Data or DMR responses");
139 throw Error(
"Only supports Data or DMR responses");
143 static void print_data(
DMR &dmr,
bool print_rows =
false)
145 cout <<
"The data:" << endl;
150 dynamic_cast < D4Sequence * >(*i)->print_val_by_rows(cout);
155 cout << endl << flush;
158 int main(
int argc,
char *argv[])
160 GetOpt getopt(argc, argv,
"[dDvVikrm:Mzstc:]");
163 bool get_dmr =
false;
164 bool get_dap4_data =
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;
172 bool report_errors =
false;
174 int dap_client_major = 4;
175 int dap_client_minor = 0;
179 _setmode(_fileno(stdout), _O_BINARY);
182 while ((option_char = getopt()) != -1)
183 switch (option_char) {
188 get_dap4_data =
true;
194 cerr <<
"getdap4 version: " <<
version << endl;
205 report_errors =
true;
209 times = atoi(getopt.optarg);
212 accept_deflate =
true;
218 mime_headers =
false;
227 expr = getopt.optarg;
240 for (
int i = getopt.optind; i < argc; ++i) {
242 cerr <<
"Fetching: " << argv[i] << endl;
244 string name = argv[i];
253 if (dap_client_major > 2)
258 cerr <<
"Assuming " << argv[i] <<
" is a file that contains a response object; decoding." << endl;
264 if (strcmp(argv[i],
"-") == 0) {
268 throw Error(
"Could not open standard input.");
270 read_response_from_file(url, dmr, r, mime_headers, get_dap4_data, get_dmr);
273 fstream f(argv[i], std::ios_base::in);
274 if (!f.is_open() || f.bad() || f.eof())
275 throw Error((
string)
"Could not open: " + argv[i]);
279 read_response_from_file(url, dmr, r, mime_headers, get_dap4_data, get_dmr);
283 cerr <<
"DAP version: " << url->
get_protocol().c_str() <<
" Server version: "
292 print_data(dmr, print_rows);
300 for (
int j = 0; j < times; ++j) {
308 cout <<
"DMR:" << endl;
323 else if (get_dap4_data) {
324 for (
int j = 0; j < times; ++j) {
332 cout <<
"DMR:" << endl;
339 print_data(dmr, print_rows);
354 if (dap_client_major > 2)
357 string url_string = argv[i];
358 for (
int j = 0; j < times; ++j) {
363 copy(headers->begin(), headers->end(), ostream_iterator<string>(cout,
"\n"));
379 else if (get_version) {
380 fprintf(stderr,
"DAP version: %s, Server version: %s\n",
381 url->request_protocol().c_str(),
391 cerr <<
"exiting" << endl;
394 catch (exception &e) {
395 cerr <<
"C++ library exception: " << e.what() << endl;
396 cerr <<
"exiting" << endl;
void print_dap4(XMLWriter &xml, bool constrained=false)
string get_error_message() const
std::vector< BaseType * >::iterator Vars_iter
std::string get_version()
void set_xdap_protocol(int major, int minor)
HTTPResponse * fetch_url(const string &url)
std::string get_protocol()
void set_accept_deflate(bool deflate)
virtual void request_dmr(DMR &dmr, const std::string expr="")
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
int main(int argc, char *argv[])
virtual void read_dmr(DMR &dmr, Response &rs)
void set_accept_deflate(bool defalte)
virtual void request_dap4_data(DMR &dmr, const std::string expr="")
virtual void read_dmr_no_mime(DMR &dmr, Response &rs)
Encapsulate a response read from stdin.
virtual void read_data_no_mime(DMR &data, Response &rs)
A class for error processing.
#define DAP_PROTOCOL_VERSION
virtual void read_data(DMR &data, Response &rs)
virtual std::istream * get_cpp_stream() const
virtual std::vector< std::string > * get_headers() const
virtual FILE * get_stream() const