Re: passing idl structures in call_external ? [message #6028] |
Wed, 10 April 1996 00:00  |
Robert Cannon
Messages: 5 Registered: February 1996
|
Junior Member |
|
|
Christian Soelle wrote:
>
> As the subject already says, does anybody know how to pass idl-structures
> to a C-function using CALL_EXTERNAL. I couldn't find anything in the help
> nor in the example programs supplied.
>
I don't know anything official, but as the prefious reply said, they
generally turn out to be alligned the same way between c and IDL.
I use the routine below (structtoc) to produce a c header file to
declare the structure once I have defined it in IDL.
I hope it is of some use,
Robert
Neuroscience Research Group
School of Biologial Sciences
Southampton, UK SO16 7PX
rcc@hera.neuro.soton.ac.uk
FUNCTION structname, a
hhh = gethelp ('a')
hh = hhh(0)
fa = strpos (hh, '->')
fb = strpos (hh, 'Arra')
nn = strmid (hh, fa+2, fb - (fa+2) )
IF strlen (nn) EQ 2 THEN nn = 'annon'
return, strlowcase (nn)
END
PRO structtoc, strin
; given an idl structure str, write a c
;header file declaring this struture
str = strin
; types, as returned by size
types = ['undefined ', $ ; 0
'byte ', $ ; 1
'short int ', $ ; 2
'int ', $ ; 3
'float ', $ ; 4
'double ', $ ; 5
'complex ', $ ; 6
'string ', $ ; 7
'struct ', $ ; 8
'dcomplex ']
nt = n_tags (str)
tn = strlowcase (tag_names (str))
nel = n_elements (str)
IF nel gt 1 THEN BEGIN
; str is an array of structures
subs = str(0)
structtoc, subs
END ELSE BEGIN
; check to see if it contains any
structures
FOR i = 0, nt-1 DO BEGIN
sf = size (str.(i))
sr = reverse (sf)
IF sr(1) EQ 6 OR sr(1) EQ 7 OR sr(1) EQ 10 OR sr(1) EQ 0 THEN
BEGIN
message, 'cant do this structure - dont like types'
END
IF sr(1) EQ 8 THEN BEGIN
subs = str.(i)
structtoc, subs
END
END
stnm = structname (str)
print, 'typedef struct '
print, '{'
FOR i = 0, nt-1 DO BEGIN
sf = size (str.(i))
sr = reverse (sf)
vardec = types (sr(1))
IF sr(1) EQ 8 THEN BEGIN
; get the name of the structure
a = str.(i)
vardec = structname (a)
END
IF sf(0) EQ 0 THEN BEGIN
line = vardec + tn(i) + ';'
END ELSE BEGIN
IF sf(0) GT 1 THEN BEGIN
print, '/* following is an idl multidimensional
array: '
print, fix(sf(0)), ' dims: ', fix(sf(1:sf(0))), '*/'
END
line = vardec + tn(i) + $
'[' + strtrim(string(sr(0)), 2) + ']' + ';'
END
print, ' ' + line
END
print, '} ' + stnm + ';'
print
print
END
END
|
|
|