bes  Updated for version 3.20.6
get_ascii.cc
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // Copyright (c) 2006 OPeNDAP, Inc.
5 // Author: James Gallagher <jgallagher@opendap.org>
6 //
7 // This is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your
10 // option) any later version.
11 //
12 // This is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
22 
23 // This file holds the interface for the 'get data as ascii' function of the
24 // OPeNDAP/HAO data server. This function is called by the BES when it loads
25 // this as a module. The functions in the file ascii_val.cc also use this, so
26 // the same basic processing software can be used both by Hyrax and tie older
27 // Server3.
28 
29 #include <stdio.h>
30 
31 #include <iostream>
32 
33 using std::cerr ;
34 using std::endl ;
35 
36 #include <DataDDS.h>
37 
38 #include <BESDebug.h>
39 
40 #include "get_ascii.h"
41 #include "AsciiOutput.h"
42 //#include "name_map.h"
43 
44 #include "AsciiByte.h"
45 #include "AsciiInt16.h"
46 #include "AsciiUInt16.h"
47 #include "AsciiInt32.h"
48 #include "AsciiUInt32.h"
49 #include "AsciiFloat32.h"
50 #include "AsciiFloat64.h"
51 #include "AsciiStr.h"
52 #include "AsciiUrl.h"
53 #include "AsciiArray.h"
54 #include "AsciiStructure.h"
55 #include "AsciiSequence.h"
56 #include "AsciiGrid.h"
57 
58 namespace dap_asciival {
59 
67 void
68 get_data_values_as_ascii(DDS *dds, ostream &strm)
69 {
70  BESDEBUG("ascii", "In get_data_values_as_ascii; dataset name = " << dds->get_dataset_name() << endl );
71  strm << "Dataset: " << dds->get_dataset_name() << "\n" ;
72 
73  DDS::Vars_iter i = dds->var_begin();
74  while (i != dds->var_end()) {
75  if ((*i)->send_p()) {
76  dynamic_cast<AsciiOutput &>(**i).print_ascii(strm);
77  strm << "\n";
78  }
79  ++i;
80  }
81 
82  BESDEBUG("ascii", "Out get_data_values_as_ascii" << endl );
83 }
84 
85 DDS *datadds_to_ascii_datadds(DDS *dds)
86 {
87  BESDEBUG("ascii", "In datadds_to_ascii_datadds" << endl);
88  // Should the following use AsciiOutputFactory instead of the source DDS'
89  // factory class? It doesn't matter for the following since the function
90  // basetype_to_asciitype() doesn't use the factory. So long as no other
91  // code uses the DDS' factory, this is fine. jhrg 9/5/06
92  DDS *asciidds = new DDS(dds->get_factory(), dds->get_dataset_name());
93 
94  DDS::Vars_iter i = dds->var_begin();
95  while (i != dds->var_end()) {
96  BaseType *abt = basetype_to_asciitype(*i);
97  asciidds->add_var_nocopy(abt);
98 #if 0
99  // add_var makes a copy of the base type passed to it, so delete
100  // it here
101  delete abt;
102 #endif
103  ++i;
104  }
105 
106  // Calling tag_nested_sequences() makes it easier to figure out if a
107  // sequence has parent or child sequences or if it is a 'flat' sequence.
108  asciidds->tag_nested_sequences();
109 
110  return asciidds;
111 }
112 
113 
114 BaseType *
115 basetype_to_asciitype( BaseType *bt )
116 {
117  switch( bt->type() )
118  {
119  case dods_byte_c:
120  return new AsciiByte( dynamic_cast<Byte *>(bt) ) ;
121 
122  case dods_int16_c:
123  return new AsciiInt16( dynamic_cast<Int16 *>(bt) ) ;
124 
125  case dods_uint16_c:
126  return new AsciiUInt16( dynamic_cast<UInt16 *>(bt) ) ;
127 
128  case dods_int32_c:
129  return new AsciiInt32( dynamic_cast<Int32 *>(bt) ) ;
130 
131  case dods_uint32_c:
132  return new AsciiUInt32( dynamic_cast<UInt32 *>(bt) ) ;
133 
134  case dods_float32_c:
135  return new AsciiFloat32( dynamic_cast<Float32 *>(bt) ) ;
136 
137  case dods_float64_c:
138  return new AsciiFloat64( dynamic_cast<Float64 *>(bt) ) ;
139 
140  case dods_str_c:
141  return new AsciiStr( dynamic_cast<Str *>(bt) ) ;
142 
143  case dods_url_c:
144  return new AsciiUrl( dynamic_cast<Url *>(bt) ) ;
145 
146  case dods_array_c:
147  return new AsciiArray( dynamic_cast<Array *>(bt) ) ;
148 
149  case dods_structure_c:
150  return new AsciiStructure( dynamic_cast<Structure *>(bt) ) ;
151 
152  case dods_sequence_c:
153  return new AsciiSequence( dynamic_cast<Sequence *>(bt) ) ;
154 
155  case dods_grid_c:
156  return new AsciiGrid( dynamic_cast<Grid *>(bt) ) ;
157 
158  default:
159  throw InternalErr(__FILE__, __LINE__, "Unknown type");
160  }
161 }
162 
163 } // namespace dap_asciival
AsciiInt32
Definition: AsciiInt32.h:42
AsciiStructure
Definition: AsciiStructure.h:42
AsciiUrl
Definition: AsciiUrl.h:42
AsciiOutput::print_ascii
virtual void print_ascii(ostream &strm, bool print_name=true)
Print values as ASCII Prints the values of this in ASCII suitable for import into a spreadsheet....
Definition: AsciiOutput.cc:73
AsciiFloat32
Definition: AsciiFloat32.h:42
AsciiArray
Definition: AsciiArray.h:44
AsciiUInt16
Definition: AsciiUInt16.h:42
AsciiSequence
Definition: AsciiSequence.h:43
AsciiGrid
Definition: AsciiGrid.h:42
AsciiStr
Definition: AsciiStr.h:42
AsciiInt16
Definition: AsciiInt16.h:42
AsciiOutput
Definition: AsciiOutput.h:46
AsciiUInt32
Definition: AsciiUInt32.h:42
AsciiFloat64
Definition: AsciiFloat64.h:42
AsciiByte
Definition: AsciiByte.h:44