Skip to content
Snippets Groups Projects
Commit aa064dfb authored by Andreas Freise's avatar Andreas Freise
Browse files

trying to make more example files work:

- extending SIfloat to work with lists
- adding SIfloat to axis conversion.
parent a77ef735
No related branches found
No related tags found
No related merge requests found
import os import os
import re import re
"""
class SIfloat(value):
def __init__(self, value):
self.__value = value
"""
#staticmethod #staticmethod
def SIfloat(value): def SIfloat(value):
value=str(value) if type(value)==list:
return [convertToFloat(s) for s in value]
else:
return convertToFloat(value)
def convertToFloat(value):
__prefix = {'y': 1e-24, # yocto __prefix = {'y': 1e-24, # yocto
'z': 1e-21, # zepto 'z': 1e-21, # zepto
'a': 1e-18, # atto 'a': 1e-18, # atto
...@@ -30,7 +28,7 @@ def SIfloat(value): ...@@ -30,7 +28,7 @@ def SIfloat(value):
'Z': 1e21, # zetta 'Z': 1e21, # zetta
'Y': 1e24, # yotta 'Y': 1e24, # yotta
} }
value = str(value)
for i, j in __prefix.iteritems(): for i, j in __prefix.iteritems():
value=value.replace(i, str(j)) value=value.replace(i, str(j))
return float(value) return float(value)
...@@ -83,7 +83,7 @@ class xaxis(Command): ...@@ -83,7 +83,7 @@ class xaxis(Command):
if numpy.size(limits) != 2 : if numpy.size(limits) != 2 :
raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis") raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis")
self.limits = numpy.array(limits).astype(float) self.limits = numpy.array(SIfloat(limits)).astype(float)
if steps <= 0 : if steps <= 0 :
raise exceptions.ValueError("steps value should be > 0") raise exceptions.ValueError("steps value should be > 0")
......
...@@ -71,7 +71,7 @@ class Component(object) : ...@@ -71,7 +71,7 @@ class Component(object) :
class Param(float): class Param(float):
def __new__(self,name,value): def __new__(self,name,value):
return float.__new__(self,value) return float.__new__(self,SIfloat(value))
def __init__(self,name,value): def __init__(self,name,value):
self.__name = name self.__name = name
......
...@@ -122,7 +122,7 @@ class kat(object): ...@@ -122,7 +122,7 @@ class kat(object):
def parseKatCode(self, code): def parseKatCode(self, code):
#commands = code.split("\n") #commands = code.split("\n")
self.parseCommands(commands) self.parseCommands(code)
def parseCommands(self, commands): def parseCommands(self, commands):
blockComment = False blockComment = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment