ReadArray.cpp 1.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#include <iostream>
#include <stdlib.h>
#include <XdmfArray.hpp>
#include <XdmfDomain.hpp>
#include <XdmfUnstructuredGrid.hpp>
#include <XdmfRectilinearGrid.hpp>
#include <XdmfGeometry.hpp>
#include <XdmfArrayType.hpp>
#include <XdmfReader.hpp>
#include <XdmfWriter.hpp>

shared_ptr<XdmfArray> maximum(std::vector<shared_ptr<XdmfArray> > values);

int main(int, char **)
{
	XdmfArray::addFunction("MAX", maximum);
	shared_ptr<XdmfReader> testReader = XdmfReader::New();
	/*
	shared_ptr<XdmfArray> readArray = shared_dynamic_cast<XdmfArray>(testReader->read("array.xmf"));
	printf("Array ocntains %s\n", readArray->getValuesString());
	*/
	shared_ptr<XdmfDomain> readDomain = shared_dynamic_cast<XdmfDomain>(testReader->read("array.xmf"));
	printf("pulling out unstructured grid\n");
	shared_ptr<XdmfRectilinearGrid> readGrid = readDomain->getRectilinearGrid(0);
	//printf("pulling out geometry\n");
	//shared_ptr<XdmfGeometry> readGeometry = readGrid->getGeometry();
	printf("pulling out dimensions\n");
	std::vector<shared_ptr<XdmfArray> > readDimensions = readGrid->getCoordinates();
	printf("Geometry contains %s\n", readDimensions[0]->getValuesString());
	shared_ptr<XdmfWriter> testWriter = XdmfWriter::New("arrayoutput.xmf");
	readGrid->accept(testWriter);
	//readArray->accept(testWriter);
	return 0;
}

shared_ptr<XdmfArray> maximum(std::vector<shared_ptr<XdmfArray> > values)
{
	if (values[0]->getArrayType() == XdmfArrayType::String())
	{
		shared_ptr<XdmfArray> returnArray = XdmfArray::New();
		returnArray->pushBack(values[0]->getValue<std::string>(0));
		return returnArray;
	}
	else
	{
		double maxVal = values[0]->getValue<double>(0);
		for (int i = 0; i < values.size(); i++)
		{
			for (int j = 0; j < values[i]->getSize(); j++)
			{
				if (maxVal < values[i]->getValue<double>(j))
				{
					maxVal = values[i]->getValue<double>(j);
				}
			}
		}
		shared_ptr<XdmfArray> returnArray = XdmfArray::New();
		returnArray->pushBack(maxVal);
		return returnArray;
	}
}