29 #include "GridJoinExistingAggregation.h"
31 #include "AggregationUtil.h"
32 #include "ArrayJoinExistingAggregation.h"
34 #include "DDSLoader.h"
35 #include "NCMLDebug.h"
41 static const string DEBUG_CHANNEL(
"ncml:2");
45 GridJoinExistingAggregation::GridJoinExistingAggregation(
const libdap::Grid& proto,
const AMDList& memberDatasets,
46 const DDSLoader& loaderProto,
const Dimension& joinDim)
49 GridAggregationBase(proto.name(), memberDatasets, loaderProto), _joinDim(joinDim)
51 createRep(proto, memberDatasets);
54 GridJoinExistingAggregation::GridJoinExistingAggregation(
const GridJoinExistingAggregation& proto) :
55 GridAggregationBase(proto), _joinDim(proto._joinDim)
61 GridJoinExistingAggregation::~GridJoinExistingAggregation()
67 GridJoinExistingAggregation*
68 GridJoinExistingAggregation::ptr_duplicate()
70 return new GridJoinExistingAggregation(*
this);
73 GridJoinExistingAggregation&
74 GridJoinExistingAggregation::operator=(
const GridJoinExistingAggregation& rhs)
78 GridAggregationBase::operator=(rhs);
84 auto_ptr<ArrayJoinExistingAggregation> GridJoinExistingAggregation::makeAggregatedOuterMapVector()
const
86 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Making an aggregated map " <<
"as a coordinate variable..." << endl);
88 NCML_ASSERT_MSG(pGridGranuleTemplate,
"Expected grid granule template but got null.");
90 const Array* pMapTemplate = AggregationUtil::findMapByName(*pGridGranuleTemplate, _joinDim.name);
91 NCML_ASSERT_MSG(pMapTemplate,
"Expected to find a dim map for the joinExisting agg but failed!");
98 auto_ptr<ArrayJoinExistingAggregation> pNewMap = auto_ptr<ArrayJoinExistingAggregation>(
108 void GridJoinExistingAggregation::transferConstraintsToSubGridHook(Grid* pSubGrid)
111 transferConstraintsToSubGridMaps(pSubGrid);
112 transferConstraintsToSubGridArray(pSubGrid);
117 GridJoinExistingAggregation::getAggregationDimension()
const
127 _joinDim = rhs._joinDim;
130 void GridJoinExistingAggregation::cleanup() throw ()
134 void GridJoinExistingAggregation::createRep(
const libdap::Grid& constProtoSubGrid,
const AMDList& memberDatasets)
137 Grid& protoSubGrid =
const_cast<Grid&
>(constProtoSubGrid);
140 setShapeFrom(protoSubGrid,
false);
144 Grid::Map_iter firstIt = protoSubGrid.map_begin();
145 Grid::Map_iter endIt = protoSubGrid.map_end();
146 for (Grid::Map_iter it = firstIt; it != endIt; ++it) {
149 NCML_ASSERT_MSG((*it)->name() == _joinDim.name,
"Expected the first map to be the outer dimension "
150 "named " + _joinDim.name +
" but it was not! Logic problem.");
155 Array* pMap =
dynamic_cast<Array*
>(*it);
160 BESDEBUG_FUNC(DEBUG_CHANNEL,
"Replacing the Grid's data Array with an ArrayAggregateOnOuterDimension..." << endl);
163 Array* pArr =
static_cast<Array*
>(array_var());
164 NCML_ASSERT_MSG(pArr,
"Expected to find a contained data Array but we did not!");
167 std::auto_ptr<ArrayGetterInterface> arrayGetter(
new TopLevelGridDataArrayGetter());
171 std::auto_ptr<ArrayJoinExistingAggregation> aggDataArray(
new ArrayJoinExistingAggregation(*pArr,
172 memberDatasets, arrayGetter, _joinDim));
176 NCML_ASSERT(!(arrayGetter.get()));
179 set_array(aggDataArray.get());
183 aggDataArray.release();
186 void GridJoinExistingAggregation::transferConstraintsToSubGridMaps(Grid* pSubGrid)
188 BESDEBUG(DEBUG_CHANNEL,
"Transferring constraints to the subgrid maps..." << endl);
189 Map_iter subGridMapIt = pSubGrid->map_begin();
190 for (Map_iter it = map_begin(); it != map_end(); ++it) {
192 if (it != map_begin()) {
193 Array* subGridMap =
static_cast<Array*
>(*subGridMapIt);
194 Array* superGridMap =
static_cast<Array*
>(*it);
204 void GridJoinExistingAggregation::transferConstraintsToSubGridArray(Grid* )