72 cerr <<
"Usage: " << name << endl;
73 cerr <<
" [idaDxBzp vVkms][-c <expr>][-m <num>] <url> [<url> ...]" << endl;
74 cerr <<
" [M vVkms] <file> [<file> ...]" << endl;
76 cerr <<
"In the first form of the command, dereference the URL and" << endl;
77 cerr <<
"perform the requested operations. This includes routing" << endl;
78 cerr <<
"the returned information through the DAP processing" << endl;
79 cerr <<
"library (parsing the returned objects, et c.). If none" << endl;
80 cerr <<
"of a, d, or D are used with a URL, then the DAP library" << endl;
81 cerr <<
"routines are NOT used and the URLs contents are dumped" << endl;
82 cerr <<
"to standard output." << endl;
84 cerr <<
"In the second form of the command, assume the files are" << endl;
85 cerr <<
"DataDDS objects (stored in files or read from pipes)" << endl;
86 cerr <<
"and process them as if -D were given. In this case the" << endl;
87 cerr <<
"information *must* contain valid MIME header in order" << endl;
88 cerr <<
"to be processed." << endl;
90 cerr <<
"Options:" << endl;
91 cerr <<
" i: For each URL, get the server version." << endl;
92 cerr <<
" d: For each URL, get the the DDS." << endl;
93 cerr <<
" a: For each URL, get the the DAS." << endl;
94 cerr <<
" D: For each URL, get the the DataDDS." << endl;
95 cerr <<
" x: For each URL, get the (DAP2) DDX object. Does not get data." << endl;
96 cerr <<
" B: Build a DDX in getdap using the DDS and DAS." << endl;
97 cerr <<
" v: Verbose output." << endl;
98 cerr <<
" e: Extensive (or very) verbose." << endl;
99 cerr <<
" V: Version of this client; see 'i' for server version." << endl;
100 cerr <<
" c: <expr> is a constraint expression. Used with -D/X and -d/r" << endl;
101 cerr <<
" NB: You can use a `?' for the CE also." << endl;
102 cerr <<
" k: Keep temporary files created by libdap." << endl;
103 cerr <<
" m: Request the same URL <num> times." << endl;
104 cerr <<
" z: Ask the server to compress data." << endl;
105 cerr <<
" s: Print Sequences using numbered rows." << endl;
106 cerr <<
" M: Assume data read from a file has no MIME headers" << endl;
107 cerr <<
" (the default is to assume the headers are present)." << endl;
108 cerr <<
" p: Set DAP protocol to x.y" << endl;
113 fprintf(stderr,
"getdap: Whoa!!! Null stream pointer.\n");
120 while (fp && !feof(fp) && fread(&c, 1, 1, fp))
126static void print_data(
DDS &dds,
bool print_rows =
false) {
127 cout <<
"The data:" << endl;
137 cout << endl << flush;
140int main(
int argc,
char *argv[]) {
141 GetOpt getopt(argc, argv,
"idaDxrXBVvekc:m:zshM?Hp:t");
144 bool get_das =
false;
145 bool get_dds =
false;
146 bool get_data =
false;
147 bool get_ddx =
false;
148 bool build_ddx =
false;
149 bool get_version =
false;
150 bool verbose =
false;
151 bool accept_deflate =
false;
152 bool print_rows =
false;
153 bool mime_headers =
true;
155 int dap_client_major = 2;
156 int dap_client_minor = 0;
160 _setmode(_fileno(stdout), _O_BINARY);
163 while ((option_char = getopt()) != -1)
164 switch (option_char) {
178 fprintf(stderr,
"getdap version: %s\n",
version);
199 times = atoi(getopt.
optarg);
205 accept_deflate =
true;
211 mime_headers =
false;
214 istringstream iss(getopt.
optarg);
216 iss >> dap_client_major;
218 iss >> dap_client_minor;
234 for (
int i = getopt.
optind; i < argc; ++i) {
236 fprintf(stderr,
"Fetching: %s\n", argv[i]);
238 string name = argv[i];
247 if (dap_client_major > 2)
253 "Assuming that the argument %s is a file that contains a response object; decoding.\n",
263 if (strcmp(argv[i],
"-") == 0) {
267 throw Error(
"Could not open standard input.");
274 r =
new Response(fopen(argv[i],
"r"), 0);
277 throw Error(
string(
"The input source: ") +
string(argv[i]) +
278 string(
" could not be opened"));
292 fprintf(stderr,
"DAP version: %s, Server version: %s\n", url->
get_protocol().c_str(),
295 print_data(dds, print_rows);
299 else if (get_version) {
300 fprintf(stderr,
"DAP version: %s, Server version: %s\n", url->
request_protocol().c_str(),
305 for (
int j = 0; j < times; ++j) {
317 fprintf(stderr,
"DAP version: %s, Server version: %s\n", url->
get_protocol().c_str(),
320 fprintf(stderr,
"DAS:\n");
328 for (
int j = 0; j < times; ++j) {
341 fprintf(stderr,
"DAP version: %s, Server version: %s\n", url->
get_protocol().c_str(),
344 fprintf(stderr,
"DDS:\n");
352 for (
int j = 0; j < times; ++j) {
363 fprintf(stderr,
"DAP version: %s, Server version: %s\n", url->
get_protocol().c_str(),
366 fprintf(stderr,
"DDX:\n");
373 else if (build_ddx) {
374 for (
int j = 0; j < times; ++j) {
388 fprintf(stderr,
"DAP version: %s, Server version: %s\n", url->
get_protocol().c_str(),
391 fprintf(stderr,
"Client-built DDX:\n");
399 for (
int j = 0; j < times; ++j) {
403 DBG(cerr <<
"URL: " << url->
URL(
false) << endl);
404 DBG(cerr <<
"CE: " << expr << endl);
408 fprintf(stderr,
"DAP version: %s, Server version: %s\n", url->
get_protocol().c_str(),
411 print_data(dds, print_rows);
431 if (dap_client_major > 2)
434 string url_string = argv[i];
435 for (
int j = 0; j < times; ++j) {
457 }
catch (exception &e) {
458 cerr <<
"C++ library exception: " << e.
what() << endl;
The basic data type for the DODS DAP types.
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Holds information about the link from a DAP2 client to a dataset.
void set_accept_deflate(bool deflate)
virtual void request_ddx(DDS &dds, string expr="")
Get the DDX 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...
void set_xdap_protocol(int major, int minor)
virtual string URL(bool CE=true)
Get the object's URL.
virtual void request_data(DataDDS &data, string expr="")
Get the DAS from a server.
virtual void request_das(DAS &das)
Get the DAS from a server.
virtual string request_protocol()
virtual void request_dds(DDS &dds, string expr="")
Get the DDS from a server.
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...
Hold attribute data for a DAP2 dataset.
virtual void print(FILE *out, bool dereference=false)
virtual void transfer_attributes(DAS *das)
void print(FILE *out)
Print the entire DDS to the specified file.
void print_xml(FILE *out, bool constrained, const string &blob="")
Vars_iter var_end()
Return an iterator.
std::vector< BaseType * >::iterator Vars_iter
A class for error processing.
const char * what() const noexcept override
The pointer is valid only for the lifetime of the Error instance. jhrg 9/22/20.
std::string get_error_message() const
void set_accept_deflate(bool deflate)
HTTPResponse * fetch_url(const std::string &url)
static RCReader * instance()
virtual FILE * get_stream() const
virtual void print_val_by_rows(ostream &out, string space="", bool print_decl_p=true, bool print_row_numbers=true)
Encapsulate a response read from stdin.
#define DAP_PROTOCOL_VERSION
int main(int argc, char *argv[])
top level DAP object to house generic methods