#include "stplugin.h" // Simple class declaration with a routine to compute varsum, and a routine // to access the stored sum. // class VarLogic { public: VarLogic(void) { sum = 0.0 ; } // constructor ~VarLogic(void) { return ; } // destructor ST_retcode computeSum(void) ; // method defined below protected: ST_double sum ; // object's sum variable }; // Method to compute our varsum // ST_retcode VarLogic::computeSum(void) { ST_int j, k ; ST_double z ; ST_retcode rc ; if(SF_nvars() < 2) { return((ST_retcode) 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((ST_retcode) 0) ; } // Regular C-style stata_call() // STDLL stata_call(int argc, char *argv[]) { VarLogic vlogic ; // Object with varsum logic return vlogic.computeSum() ; // Calculate varsum }