26#include <libdap/DDS.h>
27#include <libdap/XMLWriter.h>
28#include <libdap/D4Group.h>
29#include <libdap/D4BaseTypeFactory.h>
30#include <libdap/InternalErr.h>
33#include "DmrppCommon.h"
34#include "DmrppTypeFactory.h"
40DMRpp::DMRpp(DmrppTypeFactory *factory,
const std::string &name) : DMR(factory, name)
71void DMRpp::print_dmrpp(XMLWriter &xml,
const string &href,
bool constrained,
bool print_chunks)
73 bool pc_initial_value = DmrppCommon::d_print_chunks;
74 DmrppCommon::d_print_chunks = print_chunks;
77 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
78 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
80 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns",
81 (
const xmlChar*) get_namespace().c_str()) < 0)
82 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
85 if (DmrppCommon::d_print_chunks)
86 if (xmlTextWriterWriteAttribute(xml.get_writer(),
87 (
const xmlChar*)
string(
"xmlns:").append(DmrppCommon::d_ns_prefix).c_str(),
88 (
const xmlChar*)DmrppCommon::d_dmrpp_ns.c_str()) < 0)
89 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dmrpp");
91 if (!request_xml_base().empty()) {
92 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
93 (
const xmlChar*) request_xml_base().c_str()) < 0)
94 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
97 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion",
98 (
const xmlChar*) dap_version().c_str()) < 0)
99 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
101 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion",
102 (
const xmlChar*) dmr_version().c_str()) < 0)
103 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
105 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*) name().c_str()) < 0)
106 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
110 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
string(DmrppCommon::d_ns_prefix).append(
":href").c_str(),
111 (
const xmlChar*) href.c_str()) < 0)
112 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for href");
114 if (!get_version().empty())
115 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
string(DmrppCommon::d_ns_prefix).append(
":version").c_str(),
116 (
const xmlChar*) get_version().c_str()) < 0)
117 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for version");
120 root()->print_dap4(xml, constrained);
122 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
123 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
126 DmrppCommon::d_print_chunks = pc_initial_value;
130 DmrppCommon::d_print_chunks = pc_initial_value;
140DMRpp::print_dap4(XMLWriter &xml,
bool constrained )
142 print_dmrpp(xml, get_href(), constrained, get_print_chunks());
145libdap::DDS *DMRpp::getDDS() {
147 unique_ptr<DDS> dds(
new DDS(&factory, name()));
148 dds->filename(filename());
151 unique_ptr<vector<BaseType *>> top_vars(root()->transform_to_dap2(&(dds->get_attr_table())));
152 for (vector<BaseType *>::iterator i = top_vars->begin(), e = top_vars->end(); i != e; i++) {
153 dds->add_var_nocopy(*i);
157 return dds.release();