Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Error with plugin
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Error with plugin
Date
Mon, 24 Sep 2012 17:39:57 +0100
I passed smoothly and painlessly from not needing to use plugins to
being aware that Mata offered the power of plug-ins without the pain.
So here I am guessing.
r(102) is explained within what you cite as not enough variables. So,
the natural debug question is what in what you typed is to leading to
Stata failing to see a (large enough) varlist? I would point a finger
at your line
plugin call varsum, x1 x2 x3
Here the comma is, I guess, leading to an empty varlist and your error
message. I see no grounds for inserting a comma there.
Nick
On Mon, Sep 24, 2012 at 5:27 PM, Pradipto Banerjee
<[email protected]> wrote:
> I am trying to run the example code for Stata plugin given at http://www.stata.com/plugins/. The code I was trying to run is the example given in section 8a
>
> ---------
> #include "stplugin.h"
>
> STDLL stata_call(int argc, char *argv[])
> {
> ST_int j, k;
> ST_double sum, z;
> ST_retcode rc;
>
> if (SF_nvars() < 2) {
> return(102); /* not enough variables specified */
> }
>
> for (j=SF_in1(); j<=SF_in2(); j++) {
> if (SF_ifobs(j)) {
> sum = 0.0 ;
> for (k=1; k< SF_nvars(); k++) {
> if (rc = SF_vdata(k, j, &z)) return(rc);
> sum += z;
> }
> if (rc=SF_vstore(SF_nvars(), j, sum)) return(rc);
> }
> }
>
> return (0);
> }
> ---------
>
> I complied it with gcc under cygwin (Windows) by following the suggestion on the Stata website: "gcc -shared -mno-cygwin stplugin.c varsum.c -o varsum.plugin". Then within Stata, I did the following:
>
> .program varsum, plugin
>
> .plugin call varsum, x1 x2 x3
>
> r(102);
>
> The expected code was supposed to add x1 & x2 and place it in x3. However, it gives "r(102)". I can't figure out what is wrong, but clearly the code views SF_nvars() as having 1 or less arguments supplied to it, even though I have supplied 3 arguments.
>
> Any idea what might be the issue?
>
> (p.s. To add: I am running Stata 9.2. Two other earlier examples of Section 5 & Section 7 of http://www.stata.com/plugins/ worked fine.)
>
> By any chance, should I be using the version 1.0 of stplugin.h / stplugin.c for Stata 9.2?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/