54 Array::_duplicate(
const Array &a)
72 Array::update_length(
int)
75 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
76 length *= (*i).c_size > 0 ? (*i).c_size : 1;
133 DBG(cerr <<
"Entering ~Array (" <<
this <<
")" << endl);
134 DBG(cerr <<
"Exiting ~Array" << endl);
140 return new Array(*
this);
149 dynamic_cast<Vector &
>(*this) = rhs;
184 if (v && v->is_dap4_only_type())
185 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Array.");
210 if (v && v->is_dap4_only_type())
211 throw InternalErr(__FILE__, __LINE__,
"Attempt to add a DAP4 type to a DAP2 Array.");
283 _shape.insert(_shape.begin(), d);
307 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
309 (*i).stop = (*i).size - 1;
311 (*i).c_size = (*i).size;
335 static const char *array_sss = \
336 "Invalid constraint parameters: At least one of the start, stride or stop \n\
337 specified do not match the array variable.";
372 if (start >= d.
size || stop >= d.
size || stride > d.
size || stride <= 0)
375 if (((stop - start) / stride + 1) > d.
size)
382 d.
c_size = (stop - start) / stride + 1;
384 DBG(cerr <<
"add_constraint: c_size = " << d.
c_size << endl);
393 return _shape.begin() ;
400 return _shape.end() ;
417 unsigned int dim = 0;
418 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
425 return _shape.end() - _shape.begin();
450 if (!_shape.empty()) {
481 return (!_shape.empty()) ? (*i).start : 0;
505 return (!_shape.empty()) ? (*i).stop : 0;
530 return (!_shape.empty()) ? (*i).stride : 0;
553 "*This* array has no dimensions.");
574 for (
Dim_iter i = _shape.begin(); i != _shape.end(); i++) {
577 return length *
var()->
width(
false);
600 bool constraint_info,
bool constrained)
603 print_decl(oss, space, print_semi, constraint_info, constrained);
604 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
626 bool constraint_info,
bool constrained)
628 if (constrained && !
send_p())
632 var()->
print_decl(out, space,
false, constraint_info, constrained);
634 for (
Dim_citer i = _shape.begin(); i != _shape.end(); i++) {
636 if ((*i).name !=
"") {
637 out <<
id2www((*i).name) <<
" = " ;
640 out << (*i).c_size <<
"]" ;
643 out << (*i).size <<
"]" ;
730 class PrintArrayDimXMLWriter :
public unary_function<Array::dimension&, void>
735 PrintArrayDimXMLWriter(
XMLWriter &xml,
bool c) : xml(xml), d_constrained(c) {}
737 void operator()(Array::dimension &d)
739 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"dimension") < 0)
740 throw InternalErr(__FILE__, __LINE__,
"Could not write dimension element");
743 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)d.name.c_str()) < 0)
744 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
747 size << (d_constrained ? d.c_size : d.size);
748 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"size", (
const xmlChar*)size.str().c_str()) < 0)
749 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
751 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
752 throw InternalErr(__FILE__, __LINE__,
"Could not end dimension element");
759 if (constrained && !
send_p())
762 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar*)tag.c_str()) < 0)
763 throw InternalErr(__FILE__, __LINE__,
"Could not write " + tag +
" element");
766 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
767 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
772 string tmp_name = btp->
name();
779 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
780 throw InternalErr(__FILE__, __LINE__,
"Could not end " + tag +
" element");
796 unsigned int shape[])
799 unsigned int i =
print_array(oss, index, dims, shape);
800 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
818 unsigned int shape[])
822 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
839 for (
unsigned i = 0; i < shape[0] - 1; ++i) {
840 index =
print_array(out, index, dims - 1, shape + 1);
843 index =
print_array(out, index, dims - 1, shape + 1);
855 fwrite(oss.str().data(),
sizeof(char), oss.str().length(), out);
872 unsigned int *shape =
new unsigned int[
dimensions(
true)];
873 unsigned int index = 0;
879 delete [] shape; shape = 0;
901 msg =
"An array variable must have dimensions";
918 << (
void *)
this <<
")" << endl ;
925 unsigned int dim_num = 0 ;
926 for (; i != ie; i++) {