First Python support

This commit is contained in:
Guilhem Lavaux 2014-05-25 11:11:44 +02:00
parent bc655f1362
commit ab1a181bb6
3 changed files with 70 additions and 3 deletions

View File

@ -1 +1,65 @@
from libcpp cimport bool
import numpy as np
cimport numpy as np
cdef extern from "loadSimu.hpp" namespace "CosmoTool":
cdef cppclass SimuData:
np.float_t BoxSize
np.float_t time
np.float_t Hubble
np.float_t Omega_M
np.float_t Omega_Lambda
np.int64_t TotalNumParticles
np.int64_t NumParticles
np.int64_t *Id
np.float_t *Pos[3]
np.float_t *Vel[3]
int *type
cdef const int NEED_GADGET_ID
cdef const int NEED_POSITION
cdef const int NEED_VELOCITY
cdef const int NEED_TYPE
cdef extern from "loadGadget.hpp" namespace "CosmoTool":
SimuData *loadGadgetMulti(const char *fname, int id, int flags) except +
cdef class Simulation:
cdef float BoxSize
cdef float Hubble
cdef list Position
cdef list Velocities
cdef SimuData *data
def __cinit__(Simulation self):
self.data = <SimuData *>0
def __dealloc__(Simulation self):
if self.data != <SimuData *>0:
del self.data
def loadGadget(str filename, int snapshot_id, bool loadPosition = True, bool loadVelocity = True):
cdef int flags
cdef SimuData *data
cdef Simulation simu
flags = 0
if loadPosition:
flags |= NEED_POSITION
if loadVelocity:
flags |= NEED_VELOCITY
data = loadGadgetMulti(filename, snapshot_id, flags)
simu = Simulation()
simu.data = data
return simu

View File

@ -1,3 +1,5 @@
add_definitions(-fPIC)
SET(CosmoTool_SRCS
fortran.cpp
interpolate.cpp

View File

@ -39,6 +39,7 @@ knowledge of the CeCILL license and that you accept its terms.
#include <string>
#include <stdint.h>
#include <exception>
#include <stdexcept>
#include <cstring>
namespace CosmoTool
@ -83,13 +84,13 @@ namespace CosmoTool
* Base exception class for all exceptions handled by
* this library.
*/
class Exception : public std::exception
class Exception : public std::runtime_error
{
public:
Exception(const std::string& mess)
: msg(mess), msgok(true) {}
: std::runtime_error(mess), msg(mess), msgok(true) {}
Exception()
: msgok(false) {}
: std::runtime_error("No message"), msgok(false) {}
virtual ~Exception() throw () {}