[Jprogramming] dll help
Thimmapuram, Prakash Reddy
prakash at anl.gov
Thu Dec 8 02:03:25 HKT 2005
Your analysis is exactly correct in spite of the limited information I
provided. I incorrectly used (or assumed) that 2$0.0 gives an array of
floats. Using either 2$0,5 or -<.2$0 gave the expected output.
I am developing a J interface for a Vensim model (Vensim is a system
dynamics application developed by The Ventana Simulation Environment).
The procedure vensim_get_val in the dll modifies the parameter of array
of floats (single precision).
Here is the code that works:
b=. 'population initial'; 2$0.5
a=. (vensimdll, 'vensim_get_val % i * *f') cd b
a
+-+------------------+----------+
|1|population initial|1.65e9 0.5|
+-+------------------+----------+
Thanks again for prompt help!
Prakash
-----Original Message-----
From: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] On Behalf Of Henry Rich
Sent: Monday, December 05, 2005 6:20 PM
To: 'Programming forum'
Subject: RE: [Jprogramming] dll help
I don't completely understand what's happening but I can help a little.
2$0.0 does not create a floating-point array. J recognizes that
0.0 equals 0, and reserves just a byte for it:
3!:0 ] 2$0.0
1
so 2{::a is an array, not of floats or doubles, but of integers.
I suspect that vensim_get_val has stuffed a float there and J is
interpreting it as integers. I don't see how the value
1321513473 makes sense, but maybe you can.
If the 2$0.0 is just going to be overwritten, try using
2$0.5 instead - that will be float. Or, use
_<.2$0
which converts to float.
If vensim_get_val creates a single-precision float, you will have to
convert it to double to use it in J.
Henry Rich
> -----Original Message-----
> From: programming-bounces at jsoftware.com
> [mailto:programming-bounces at jsoftware.com] On Behalf Of Thimmapuram,
> Prakash Reddy
> Sent: Monday, December 05, 2005 5:36 PM
> To: programming at jsoftware.com
> Subject: [Jprogramming] dll help
>
>
> Hi,
>
> I am fairly new at J and am trying to call a Vensim dll from J. Here
> is the code and the output
>
> NB. CFUNCTION int EXPORTED_PROC vensim_get_val(const char *name,float
> *val) ;
> b=. 'population initial'; 2$0.0
> a=. (vensimdll, 'vensim_get_val i * *') cd b NB. using i *c
> *f does not work!
> a
> +-+------------------+------------+
> |1|population initial|1321513473 0|
> +-+------------------+------------+
>
> The value "1321513473" in the box is not the correct value (or
> expected
> value) and I thought it is a memory location and when read as below
> gives error messages:
>
> c=. 0{>2{a
> c
> 1321513473
> memr c, 0, 4
> |domain error: memr
> | memr c,0,4
> meme c, 0, 8
> |domain error: meme
> | memr c,0,8
> memr c, 0, 2
> |domain error: memr
> | memr c,0,2
>
> Please help me in understanding whats with the above code
>
> Thanks
> Prakash
>
> ----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list