bes  Updated for version 3.20.6
structT01.cc
1 // structT.cc
2 
3 #include <cstdlib>
4 #include <fstream>
5 #include <iostream>
6 
7 using std::ofstream;
8 using std::ios;
9 using std::cerr;
10 using std::endl;
11 
12 #include <DataDDS.h>
13 #include <Structure.h>
14 #include <Array.h>
15 #include <Byte.h>
16 #include <Int16.h>
17 #include <Int32.h>
18 #include <UInt16.h>
19 #include <UInt32.h>
20 #include <Float32.h>
21 #include <Float64.h>
22 #include <Str.h>
23 #include <Error.h>
24 
25 using namespace libdap;
26 
27 #include <BESDataHandlerInterface.h>
28 #include <BESDataNames.h>
29 #include <BESDebug.h>
30 
31 #include "test_send_data.h"
32 
33 int main(int argc, char **argv)
34 {
35  bool debug = false;
36  if (argc > 1) {
37  for (int i = 0; i < argc; i++) {
38  string arg = argv[i];
39  if (arg == "debug") {
40  debug = true;
41  }
42  }
43  }
44 
45  try {
46  if (debug)
47  BESDebug::SetUp("cerr,fonc");
48 
49  // nested structures
50  DDS *dds = new DDS(NULL, "virtual");
51 
52  Structure s1("s1");
53  Structure s2("s2");
54  Structure s3("s3");
55 
56  Byte b("byte");
57  b.set_value(28);
58  s1.add_var(&b);
59 
60  Int16 i16("i16");
61  i16.set_value(-2048);
62  s2.add_var(&i16);
63 
64  Int32 i32("i32");
65  i32.set_value(-105467);
66  s3.add_var(&i32);
67 
68  UInt16 ui16("ui16");
69  ui16.set_value(2048);
70  s1.add_var(&ui16);
71 
72  UInt32 ui32("ui32a");
73  Array a("array", &ui32);
74  a.append_dim(2, "ui32a_dim1");
75  a.append_dim(5, "ui32a_dim2");
76  vector<dods_uint32> ua;
77  int numi = 0;
78  dods_uint32 i = 10532;
79  for (; numi < 10; numi++) {
80  ua.push_back(i);
81  i += 14992;
82  }
83  a.set_value(ua, ua.size());
84  s2.add_var(&a);
85 
86  Float32 f32("f32");
87  f32.set_value(5.7866);
88  s3.add_var(&f32);
89 
90  Float64 f64("f64");
91  f64.set_value(10245.1234);
92  s1.add_var(&f64);
93 
94  Str str("str");
95  str.set_value("This is a String Value");
96  s2.add_var(&str);
97 
98  s2.add_var(&s3);
99  s1.add_var(&s2);
100 
101  dds->add_var(&s1);
102 
103  build_dods_response(&dds, "./structT01.dods");
104 
105  delete dds;
106  }
107  catch (BESError &e) {
108  cerr << e.get_message() << endl;
109  return 1;
110  }
111  catch (Error &e) {
112  cerr << e.get_error_message() << endl;
113  return 1;
114  }
115  catch (std::exception &e) {
116  cerr << e.what() << endl;
117  return 1;
118  }
119 
120  return 0;
121 }
122 
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