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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 5 months ago) by jfenwick
File size: 1924 byte(s)
Don't panic.
Updating copyright stamps

1 caltinay 2812
2     /*******************************************************
3     *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 caltinay 2812 * 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 caltinay 2830 EscriptDataset_ptr dataset;
55     #ifdef PASO_MPI
56     MPI_Comm comm = domain->getMPIComm();
57     dataset.reset(new EscriptDataset(comm));
58     #else
59     dataset.reset(new EscriptDataset());
60     #endif
61    
62 caltinay 2812 if (!dataset->initFromEscript(domain, vars, varNames))
63     throw escript::DataException("saveSilo: Error initialising dataset. No Silo support?!");
64    
65     dataset->setCycleAndTime(cycle, time);
66     dataset->saveSilo(filename);
67     }
68    
69     } // namespace escriptexport
70    

  ViewVC Help
Powered by ViewVC 1.1.26