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(do uble, 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.t xt')
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 1664
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(do uble, 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.t xt')
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 I
wrapped std::vector objects in C struct and I did not release the
memory properly. Below is the...
|
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 I
wrapped std::vector objects in C struct and I did not release the
memory properly. Below is the...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |