/[escript]/trunk/dataexporter/src/FileSavers.cpp
ViewVC logotype

Contents of /trunk/dataexporter/src/FileSavers.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2812 - (show annotations)
Tue Dec 8 00:12:07 2009 UTC (11 years, 6 months ago) by caltinay
File size: 1809 byte(s)
Implemented saveSilo within a new dataexporter module. If Silo is not available
at compile time the function throws. Ultimately, saveVTK will be moved here as
well.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14 #include <escriptexport/FileSavers.h>
15 #include <escriptexport/EscriptDataset.h>
16 #include <escript/Data.h>
17
18 #include <boost/python/extract.hpp>
19 #include <iostream>
20
21 using boost::python::dict;
22 using escript::Domain_ptr;
23 using std::string;
24
25 namespace escriptexport
26 {
27
28 // extracts Data objects and their names from src into vars and names
29 void unpackDict(const dict& src, DataVec& vars, StringVec& names)
30 {
31 int numData = boost::python::extract<int>(src.attr("__len__")());
32 if (numData > 0) {
33 boost::python::list keys = src.keys();
34
35 for (int i=0; i<numData; i++) {
36 string varName = boost::python::extract<string>(keys[i]);
37 names.push_back(varName);
38 escript::Data varData = boost::python::extract<escript::Data>(
39 src[keys[i]]);
40 vars.push_back(varData);
41 }
42 }
43
44 }
45
46 void saveSilo(const string& filename, int cycle, double time,
47 Domain_ptr domain, const dict& datavars)
48 {
49 DataVec vars;
50 StringVec varNames;
51
52 unpackDict(datavars, vars, varNames);
53
54 EscriptDataset_ptr dataset = EscriptDataset_ptr(new EscriptDataset());
55 if (!dataset->initFromEscript(domain, vars, varNames))
56 throw escript::DataException("saveSilo: Error initialising dataset. No Silo support?!");
57
58 dataset->setCycleAndTime(cycle, time);
59 dataset->saveSilo(filename);
60 }
61
62 } // namespace escriptexport
63

  ViewVC Help
Powered by ViewVC 1.1.26