I'm using python 2.4 under linux (centos 5.1).
I need to pass an array of doubles to a c function
but am getting an error, shown near the bottom of
this post.
----------------------------------------------------
my swig interface file looks like this
* File: rug520.i */
%module rug520
%include "typemaps.i"
%include "carrays.i"
%array_class(double, doubleArray);
%{
#define SWIG_FILE_WITH_INIT
#include "rug520.h"
extern double[] nCmiArray;
%}
%apply int *OUTPUT { char *sRugHier,
char * sRugMax,
int * iRugHier,
int * iRugMax,
double * nCmiValueHier,
double * nCmiValueMax,
int * iAdlSum,
int * iCpsCode,
char * sRugsVersion,
char * sDllVersion,
int * iError };
int RugCalc( char * sMdsRecord,
char * sRehabType,
char * sModel,
int iQuarterlyFlag,
double nCmiArray[],
char * sRugHier,
char * sRugMax,
int * iRugHier,
int * iRugMax,
double * nCmiValueHier,
double * nCmiValueMax,
int * iAdlSum,
int * iCpsCode,
char * sRugsVersion,
char * sDllVersion,
int * iError );
------------------------------------------------------------------
my test code looks like this:
import sys, os, rug520
cmi=[0.0] *59
def getrug(mds):
results = rug520.RugCalc(mds, 'mcare', '34', 0, cmi)
print 'results', results
datafile = open('mdsdata.txt')
for d in datafile:
if d[0]=='B':
getrug(d)
------------------------------------------------------------------------
I get this error message
File "testrug520.py", line 11, in ?
getrug(d)
File "testrug520.py", line 5, in getrug
results = rug520.RugCalc(mds, 'mcare', '34', 0, cmi)
TypeError: in method 'RugCalc', argument 5 of type 'double []'
--------------------------------------------------------------------------
I'm guessing that I am not passing a double array to the c code. I cannot change
the c code due to politics. I could write a c "wrapper" if I had to, but would rather
stay within python or the swig interface definitions if possible/practical.
I'm not much of a c programmer; mostly java and python with a little c++.
I've looked in the swig docs and tried google, but either have not found
it or just don't understand what they are telling me here.
---------------------------------------------------------------------------
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
--------------------------------------------------------------------------- 1 1653
Sells, Fred wrote:
I'm using python 2.4 under linux (centos 5.1).
I need to pass an array of doubles to a c function
but am getting an error, shown near the bottom of
this post.
----------------------------------------------------
my swig interface file looks like this
* File: rug520.i */
%module rug520
%include "typemaps.i"
%include "carrays.i"
%array_class(double, doubleArray);
%{
#define SWIG_FILE_WITH_INIT
#include "rug520.h"
extern double[] nCmiArray;
%}
%apply int *OUTPUT { char *sRugHier,
char * sRugMax,
int * iRugHier,
int * iRugMax,
double * nCmiValueHier,
double * nCmiValueMax,
int * iAdlSum,
int * iCpsCode,
char * sRugsVersion,
char * sDllVersion,
int * iError };
int RugCalc( char * sMdsRecord,
char * sRehabType,
char * sModel,
int iQuarterlyFlag,
double nCmiArray[],
char * sRugHier,
char * sRugMax,
int * iRugHier,
int * iRugMax,
double * nCmiValueHier,
double * nCmiValueMax,
int * iAdlSum,
int * iCpsCode,
char * sRugsVersion,
char * sDllVersion,
int * iError );
------------------------------------------------------------------
my test code looks like this:
import sys, os, rug520
cmi=[0.0] *59
def getrug(mds):
results = rug520.RugCalc(mds, 'mcare', '34', 0, cmi)
print 'results', results
datafile = open('mdsdata.txt')
for d in datafile:
if d[0]=='B':
getrug(d)
------------------------------------------------------------------------
I get this error message
File "testrug520.py", line 11, in ?
getrug(d)
File "testrug520.py", line 5, in getrug
results = rug520.RugCalc(mds, 'mcare', '34', 0, cmi)
TypeError: in method 'RugCalc', argument 5 of type 'double []'
--------------------------------------------------------------------------
I'm guessing that I am not passing a double array to the c code. I cannot
change
the c code due to politics. I could write a c "wrapper" if I had to, but
would rather stay within python or the swig interface definitions if
possible/practical.
I'm not much of a c programmer; mostly java and python with a little c++.
I've looked in the swig docs and tried google, but either have not found
it or just don't understand what they are telling me here.
I don't know swig, but if all you have is a real C-API, try & use ctypes.
It's much easier to create bindings for, keeps you fully in the warm and
cozy womb of python programming and doesn't need no compilation to create
the actual binding.
Diez This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ernie |
last post by:
Hi,
I am learning swig to use C codes from Python.
Here is the swig file mvf.i:
%module mvf
%include "carrays.i"
%array_class(double, doubleArray);
%typemap(out) double, float "$result = PyFloat_FromDouble($1);"
%include mvf.h
|
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c */
#include <time.h>
|
by: RLC |
last post by:
Hello
I am new to python SWIG. Recently I wrote a small program trying to
import collada files(using colladadom) into python so I could use
python cgkit to render them. However, during the progressing, I got
some problems. Every time I quit from Python, I get a segmentation
fault, although the main program runs well. I suspect it is because...
|
by: RLC |
last post by:
Hello
I am new to python SWIG. Recently I wrote a small program trying to
import collada files(using colladadom) into python so I could use
python cgkit to render them. However, during the progressing, I got
some problems. Every time I quit from Python, I get a segmentation
fault, although the main program runs well. I suspect it is because...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |