Skip to content

Commit

Permalink
python 3 support for garefl
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Dec 18, 2018
1 parent f8df7c0 commit 764ca3f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions refl1d/garefl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"""
__all__ = ["load"]

import sys
import os
from os import getpid
from ctypes import CDLL, c_int, c_double, c_void_p, c_char_p, byref
Expand All @@ -49,6 +50,13 @@
from .profile import Microslabs
from .material import SLD, Vacuum

if sys.version_info[0] >= 3:
def tostr(s):
return s.decode('ascii')
else:
def tostr(s):
return s

def trace(fn):
"""simple function trace function"""
return fn # Comment this to turn on tracing
Expand Down Expand Up @@ -240,7 +248,7 @@ def _getdata(self, k, xs):
if n == 0:
return None
data = empty((n, 4), 'd')
filename = self.dll.ex_get_data(self.models, k, xs, data.ctypes)
filename = tostr(self.dll.ex_get_data(self.models, k, xs, data.ctypes))
Q, dQ, R, dR = data.T
probe = QProbe(Q, dQ, data=(R, dR), name=filename)
return probe
Expand Down Expand Up @@ -276,7 +284,7 @@ def output_model(self):

@trace
def par_names(self):
return [self.dll.ex_par_name(self.models, i)
return [tostr(self.dll.ex_par_name(self.models, i))
for i in range(self.num_pars)]

@trace
Expand Down

0 comments on commit 764ca3f

Please sign in to comment.