Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: How to check the contents of matrix elements in C plugin


From   "Lei Xuan" <[email protected]>
To   <[email protected]>
Subject   st: How to check the contents of matrix elements in C plugin
Date   Tue, 25 Apr 2006 11:02:06 -0500

Hi,

I copied a piece of C code from online www.stata.com/plugins Section 8b, 8d.
to test -SF_mat_el()-.  My question is how I can see/check the contents of
matrix elements.

If I included the following code, given in Section 8d for debugging and
printing out results, the C compiler reported errors (I use Microsoft Visual
C++ 6). I changed "snprintf" to "sprintf", errors are gone, but warnings are
still there. 

/* --------------- Begin change12.c-----------------------------------*/
#include <stdio.h>
#include <string.h>

#include "stplugin.h"

        STDLL stata_call(int argc, char *argv[])         
        {
          char buf[80];
	    ST_double z;
				
            SF_mat_el(argv[0],1,2,&z);
	      snprintf(buf, 80, "The value of z is %lf\n",z);
	      SF_display(buf);
      
            return(0) ;
        }

/* --- End change12.c (see www.stata.com\plugins Section 8b) ------*/

Importantly, when running the last line of the following code test.do,
either STATA winddow disappeared, or STATA reported "cannot read memory"

//---------- Begin test.do (Section 8b)----------------------
tempname mymat
mat `mymat'=(1,2 \3,4)
program change12, plugin using("c:\ado\personal\c\changemx.dll")
plugin call change12, `mymat'

// --------- End test.do ------------------------------------

 
Interestingly, if I don't print out the result, the programs work fine. 
But how can I know programs work correctly?
 
Thanks a lot,
Lei


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index