bes  Updated for version 3.20.6
arrayT01.cc
1 // arrayT01.cc
2 
3 #include <cstdlib>
4 #include <fstream>
5 #include <iostream>
6 #include <sstream>
7 
8 using std::ofstream;
9 using std::ios;
10 using std::cerr;
11 using std::endl;
12 using std::ostringstream;
13 
14 #include <DataDDS.h>
15 #include <Array.h>
16 #include <Byte.h>
17 #include <Int16.h>
18 #include <Int32.h>
19 #include <UInt16.h>
20 #include <UInt32.h>
21 #include <Float32.h>
22 #include <Float64.h>
23 #include <Str.h>
24 #include <Error.h>
25 
26 using namespace libdap;
27 
28 #include <BESDataHandlerInterface.h>
29 #include <BESDataNames.h>
30 #include <BESDebug.h>
31 
32 #include "test_send_data.h"
33 
34 int main(int argc, char **argv)
35 {
36  bool debug = false;
37  if (argc > 1) {
38  for (int i = 0; i < argc; i++) {
39  string arg = argv[i];
40  if (arg == "debug") {
41  debug = true;
42  }
43  }
44  }
45 
46  try {
47  if (debug)
48  BESDebug::SetUp("cerr,fonc");
49 
50  // build a DataDDS of simple type arrays with shared dimensions
51  DDS *dds = new DDS(NULL, "virtual");
52  {
53  Byte *b = new Byte("byte_array");
54  Array *a = new Array("array", b);
55  delete b;
56  b = 0;
57  a->append_dim(2, "dim1");
58  a->append_dim(5, "dim2");
59  dds->add_var(a);
60  delete a;
61  a = 0;
62 
63  a = dynamic_cast<Array *>(dds->var("byte_array"));
64  if (!a) {
65  delete dds;
66  string err = "cast error for byte_array";
67  throw BESError(err, 0, __FILE__, __LINE__);
68  }
69 
70  vector<dods_byte> ba;
71  for (dods_byte i = 0; i < 10; i++) {
72  ba.push_back(i);
73  }
74  a->set_value(ba, ba.size());
75  }
76  {
77  Int16 *i16 = new Int16("i16_array");
78  Array *a = new Array("array", i16);
79  delete i16;
80  i16 = 0;
81  a->append_dim(2, "dim1");
82  a->append_dim(5, "dim2");
83  dds->add_var(a);
84  delete a;
85  a = 0;
86 
87  a = dynamic_cast<Array *>(dds->var("i16_array"));
88  if (!a) {
89  delete dds;
90  string err = "cast error for i16_array";
91  throw BESError(err, 0, __FILE__, __LINE__);
92  }
93 
94  vector<dods_int16> i16a;
95  for (dods_int16 i = 0; i < 10; i++) {
96  i16a.push_back(i * (-16));
97  }
98  a->set_value(i16a, i16a.size());
99  }
100  {
101  Int32 *i32 = new Int32("i32_array");
102  Array *a = new Array("array", i32);
103  delete i32;
104  i32 = 0;
105  a->append_dim(2, "dim1");
106  a->append_dim(5, "dim2");
107  dds->add_var(a);
108  delete a;
109  a = 0;
110 
111  a = dynamic_cast<Array *>(dds->var("i32_array"));
112  if (!a) {
113  delete dds;
114  string err = "cast error for i32_array";
115  throw BESError(err, 0, __FILE__, __LINE__);
116  }
117 
118  vector<dods_int32> i32a;
119  for (dods_int32 i = 0; i < 10; i++) {
120  i32a.push_back(i * (-512));
121  }
122  a->set_value(i32a, i32a.size());
123  }
124 
125  build_dods_response(&dds, "./arrayT01.dods");
126 
127  delete dds;
128  }
129  catch (BESError &e) {
130  cerr << e.get_message() << endl;
131  return 1;
132  }
133  catch (Error &e) {
134  cerr << e.get_error_message() << endl;
135  return 1;
136  }
137  catch (std::exception &e) {
138  cerr << e.what() << endl;
139  return 1;
140  }
141 
142  return 0;
143 }
144 
BESError::get_message
virtual std::string get_message()
get the error message for this exception
Definition: BESError.h:99
BESDebug::SetUp
static void SetUp(const std::string &values)
Sets up debugging for the bes.
Definition: BESDebug.cc:64
libdap
Definition: BESDapFunctionResponseCache.h:35
Error
BESError
Abstract exception class for the BES with basic string message.
Definition: BESError.h:58