Problem mit dplotlib.dll (ctypes)
Verfasst: Sonntag 10. Dezember 2006, 19:20
Hallo zusammen,
ich habe in der Vergangenheit unter Fortran ein freies Tool zum Plotten verwendet (DPlot Jr, http://www.dplot.com). DPlotlib.dll wurde dabei in Fortran eingebunden. Nach ersten Gehversuchen in Python möchte ich das Tool auch hier nutzen. Ich habe dazu ctypes verwendet:
DPLOT_DDE_VERSION etc. sind definiert.
DPlot wird zwar geladen, leider erhalte ich jedoch nicht die gewünschte Grafik: manchmal fehlt der Kurvenverlauf, mal fehlt derText.
Was mache ich falsch?
Danke für jeden Beitrag!
Christoph
ich habe in der Vergangenheit unter Fortran ein freies Tool zum Plotten verwendet (DPlot Jr, http://www.dplot.com). DPlotlib.dll wurde dabei in Fortran eingebunden. Nach ersten Gehversuchen in Python möchte ich das Tool auch hier nutzen. Ich habe dazu ctypes verwendet:
Code: Alles auswählen
from ctypes import *
MAXC = 100
class DPLOT(Structure):
_fields_ = [
("Version", c_uint), \
("hwnd", c_uint), \
("DataFormat", c_uint), \
("MaxCurves", c_uint), \
("MaxPoints", c_uint), \
("NumCurves", c_uint), \
("Scale", c_uint), \
("LegendX", c_float), \
("LegendY", c_float), \
("NP", c_uint*MAXC), \
("LineType", c_uint*MAXC), \
("SymbolType", c_uint*MAXC), \
("SizeofExtraInfo", c_uint), \
("Legend", c_char_p*(MAXC+1)), \
("Label", c_char_p*MAXC), \
("Title", c_char_p*3), \
("XAxis", c_char_p), \
("YAxis", c_char_p)
]
def XYExample():
NP = 1001
xarray = c_float*c_int(NP).value
x = xarray()
yarray = c_float*(2*c_int(NP).value)
y = yarray()
for i in range(NP):
x[i] = (4.*i)/(NP-1)
y[i] = sin(pi*x[i])
y[i+NP] = cos(pi*x[i])
DPlot = DPLOT()
DPlot.Version = DPLOT_DDE_VERSION
DPlot.hwnd = 0
DPlot.DataFormat = DATA_XYYY
DPlot.MaxCurves = 2
DPlot.MaxPoints = NP
DPlot.NumCurves = 2
DPlot.Scale = SCALE_LINEARX_LINEARY
DPlot.LegendX = 0.05
DPlot.LegendY = 0.05
DPlot.NP[0] = NP
DPlot.NP[1] = NP
DPlot.LineType[0] = LINESTYLE_SOLID
DPlot.LineType[1] = LINESTYLE_LONGDASH
DPlot.Legend[1] = "sin({\sp}x)" #{\s is DPlot-speak for "use symbol font"
DPlot.Legend[2] = "cos({\sp}x)"
DPlot.Title[0] = "Data sent to DPlot via DPLOTLIB.DLL"
DPlot.XAxis = "x"
DPlot.YAxis = "y"
command = c_char_p( "[ManualScale(0,-1.25,4,1.25)]"+ \
"[TickInterval(1,0.5,0.25)]"+ \
"[Caption(\"DPLOTLIB XY Test\")]"+ \
"[DocMaximize()]"+ \
"[ClearEditFlag()]" )
ret = f.DPlot_Plot(byref(DPlot), byref(x), byref(y), command)
DPlot wird zwar geladen, leider erhalte ich jedoch nicht die gewünschte Grafik: manchmal fehlt der Kurvenverlauf, mal fehlt derText.
Was mache ich falsch?
Danke für jeden Beitrag!
Christoph