예제 #1
0
파일: arma_x12.c 프로젝트: maupatras/gretl
static void 
output_series_to_spc (const int *list, const DATASET *dset,
		      int t1, int t2, FILE *fp)
{
    int i, t, done = 0;

    for (t=t1; t<=t2 && !done; t++) {
	for (i=1; i<=list[0] && !done; i++) {
	    if (na(dset->Z[list[i]][t])) {
		fputs(" missingcode=-99999\n", fp);
		done = 1;
	    }
	}
    }

    fputs(" data=(\n", fp);

    for (t=t1; t<=t2; t++) {
	for (i=1; i<=list[0]; i++) {
	    if (na(dset->Z[list[i]][t])) {
		fputs("-99999 ", fp);
	    } else {
		fprintf(fp, "%.15g ", dset->Z[list[i]][t]);
	    }
	}
	fputc('\n', fp);
    }

    fputs(" )\n", fp);
}
예제 #2
0
static int anova_print_means (struct anova *v, const double *xt,
			      const double *y, double ybar,
			      int t1, int t2, PRN *prn)
{
    double d, *csd = malloc(v->nt * sizeof *csd);
    int c1, c2, c3, c4;
    int i, t;

    if (csd == NULL) {
	return E_ALLOC;
    }

    for (i=0; i<v->nt; i++) {
	csd[i] = 0.0;
    }

    for (t=t1; t<=t2; t++) {
	if (!na(xt[t]) && !na(y[t])) {
	    for (i=0; i<v->nt; i++) {
		if (xt[t] == v->tvals->val[i]) {
		    d = y[t] - v->cmeans[i];
		    csd[i] += d * d;
		    break;
		}
	    }
	}
    }

    c1 = g_utf8_strlen(_("Level"), -1);
    c2 = g_utf8_strlen(_("n"), -1);
    c3 = g_utf8_strlen(_("mean"), -1);
    c4 = g_utf8_strlen(_("std. dev"), -1);

    c1 = (c1 < 8)? 8 : c1;
    c2 = (c2 > 6)? c2 + 1 : (c2 < 6)? 6 : c2;
    c3 = (c3 > 10)? c3 + 1 : (c3 < 10)? 10 : c3;
    c4 = (c4 > 12)? c4 + 1 : (c4 < 12)? 12 : c4;

    pprintf(prn, "  %-*s %*s %*s %*s\n\n", c1, _("Level"), c2, _("n"), 
	    c3, _("mean"), c4, _("std. dev"));

    for (i=0; i<v->nt; i++) {
	if (v->ccount[i] > 1) {
	    csd[i] /= v->ccount[i] - 1;
	    csd[i] = sqrt(csd[i]);
	    pprintf(prn, "  %-*g %*d %*g %#*.5g\n", c1, v->tvals->val[i], 
		    c2, v->ccount[i], c3, v->cmeans[i], c4, csd[i]);
	} else {
	    pprintf(prn, "  %-*g %*d %*g %*s\n", c1, v->tvals->val[i], 
		    c2, v->ccount[i], c3, v->cmeans[i], c4, "NA");
	}
    } 

    pprintf(prn, "\n  %s = %g\n\n", _("Grand mean"), ybar);

    free(csd);

    return 0;
}
예제 #3
0
파일: audioprint.c 프로젝트: tidatida/gretl
static void audio_rsqline (const MODEL *pmod, PRN *prn)
{
    if (!na(pmod->rsq)) {
        pprintf(prn, "Unadjusted R-squared %.3f.\n", pmod->rsq);
    }
    if (!na(pmod->adjrsq)) {
        pprintf(prn, "Adjusted R-squared %.3f.\n", pmod->adjrsq);
    }
}
예제 #4
0
static int import_prune_columns (DATASET *dset)
{
    int allmiss = 1, ndel = 0;
    int i, t, err = 0;

    for (i=dset->v-1; i>0 && allmiss; i--) {
	for (t=0; t<dset->n; t++) {
	    if (!na(dset->Z[i][t])) {
		allmiss = 0;
		break;
	    }
	}
	if (allmiss) ndel++;
    }

    if (ndel == dset->v - 1) {
	gretl_errmsg_set(_("No numeric data were found"));
	err = E_DATA;
    } else if (ndel > 0) {
	fprintf(stderr, "Sheet has %d trailing empty variables\n", ndel);
	err = dataset_drop_last_variables(dset, ndel);
    }

    return err;
}
예제 #5
0
mat rotation_matrix( const vec &a, double angle ) {
	// init cross-product
	mat cp( 3, 3 );

	// zero out the response
	cp.zeros( 3, 3 );

	vec na(a);
	// create a new rotation matrix
	mat rm( 3, 3 );
	// zero out the response
	rm.zeros( 3, 3 );
	// calculate cp
	cp( 0, 1 ) = -a( 2 );
	cp( 1, 2 ) = -a( 0 );
	cp( 2, 0 ) = -a( 1 );
	cp( 0, 2 ) = a( 1 );
	cp( 1, 0 ) = a( 2 );
	cp( 2, 1 ) = a( 0 );
	// calculate rotation matrix
	rm = (	cos( angle ) * eye( 3, 3 )
			+ 1 - cos( angle )) * a * a.t()
			+ sin( angle ) * cp;
	return rm;
}
예제 #6
0
static int few_vals (int t1, int t2, const double *x, double *ratio)
{
    double test[FEWVALS];
    int match;
    int i, t, n = 0, nv = 0;

    for (t=t1; t<=t2; t++) {
	if (!na(x[t])) {
	    match = 0;
	    for (i=0; i<nv; i++) {
		if (x[t] == test[i]) {
		    match = 1;
		    break;
		}
	    }
	    if (!match) {
		if (nv == FEWVALS) {
		    nv++;
		    break;
		}
		test[nv++] = x[t];
	    }
	    n++;
	}
    }

    *ratio = (double) nv / n;

    return nv;
}
예제 #7
0
int gretl_iscount (int t1, int t2, const double *x)
{
    int t, xi;
    int g1 = 0;
    int ret = 1;

    for (t=t1; t<=t2; t++) {
	if (na(x[t])) {
	    continue;
	}
	if (x[t] < 0.0) {
	    ret = 0;
	    break;
	}
	xi = x[t];
	if (x[t] != (double) xi) {
	    ret = 0;
	    break;
	}
	if (x[t] > 1.0) {
	    g1 = 1;
	}
    }

    if (g1 == 0) {
	ret = 0;
    }

    return ret;
}
예제 #8
0
ATTR_TYPE getPlugAttrType(const char *plugName, MFnDependencyNode& dn)
{
	MDGContext ctx = MDGContext::fsNormal;
	MStatus stat = MS::kSuccess;
	MPlug plug = dn.findPlug(plugName, &stat);
	if( !stat )
		return ATTR_TYPE::ATTR_TYPE_NONE;

	MObject attObj = plug.attribute(&stat);
	MFnAttribute att(attObj);
	if( !stat )
		return ATTR_TYPE::ATTR_TYPE_NONE;

	if(att.isUsedAsColor())
		return ATTR_TYPE::ATTR_TYPE_COLOR;
	if( attObj.apiType() == MFn::kNumericAttribute)
	{
		MFnNumericAttribute na(attObj, &stat);
		if( !stat )
			return ATTR_TYPE::ATTR_TYPE_NONE;
		if( na.unitType() == MFnNumericData::Type::kFloat )
			return ATTR_TYPE::ATTR_TYPE_FLOAT;
	}
	return ATTR_TYPE::ATTR_TYPE_NONE;
}
예제 #9
0
double sur_loglik (equation_system *sys)
{
    int m = sys->neqns;
    int T = sys->T;
    gretl_matrix *tmp;
    double ldet;
    int err = 0;

    tmp = gretl_matrix_alloc(m, m);
    if (tmp == NULL) {
	return NADBL;
    }

    gls_sigma_from_uhat(sys, tmp, 0);
    ldet = gretl_vcv_log_determinant(tmp, &err);

    if (na(ldet)) {
	sys->ll = NADBL;
    } else {
	sys->ll = -(m * T / 2.0) * (LN_2_PI + 1.0);
	sys->ll -= (T / 2.0) * ldet;
    }

    gretl_matrix_free(tmp);

    return sys->ll;
}
예제 #10
0
galera::ReplicatorSMM::InitConfig::InitConfig(gu::Config&       conf,
                                              const char* const node_address)
{
    Replicator::register_params(conf);

    std::map<std::string, std::string>::const_iterator i;

    for (i = defaults.map_.begin(); i != defaults.map_.end(); ++i)
    {
        if (i->second.empty())
            conf.add(i->first);
        else
            conf.add(i->first, i->second);
    }

    // what is would be a better protection?
    int const pv(gu::from_string<int>(conf.get(Param::proto_max)));
    if (pv > MAX_PROTO_VER)
    {
        log_warn << "Can't set '" << Param::proto_max << "' to " << pv
                 << ": maximum supported value is " << MAX_PROTO_VER;
        conf.add(Param::proto_max, gu::to_string(MAX_PROTO_VER));
    }

    conf.add(COMMON_BASE_HOST_KEY);
    conf.add(COMMON_BASE_PORT_KEY);

    if (node_address && strlen(node_address) > 0)
    {
        gu::URI na(node_address, false);

        try
        {
            std::string const host = na.get_host();

            if (host == "0.0.0.0" || host == "0:0:0:0:0:0:0:0" || host == "::")
            {
                gu_throw_error(EINVAL) << "Bad value for 'node_address': '"
                                       << host << '\'';
            }

            conf.set(BASE_HOST_KEY, host);
        }
        catch (gu::NotSet& e) {}

        try
        {
            conf.set(BASE_PORT_KEY, na.get_port());
        }
        catch (gu::NotSet& e) {}
    }

    /* register variables and defaults from other modules */
    gcache::GCache::register_params(conf);
    gcs_register_params(reinterpret_cast<gu_config_t*>(&conf));
    Certification::register_params(conf);
    ist::register_params(conf);
}
예제 #11
0
static void single_series_view_print (windata_t *vwin)
{
    series_view *sview = (series_view *) vwin->data;
    char num_format[32];
    double x;
    PRN *prn;
    int i, t, obslen;
    int err = 0;

    if (bufopen(&prn)) {
	return;
    }

    if (sview->view == VIEW_STANDARD) {
	int list[2] = { 1, sview->varnum };

	/* regular printout: unsort if need be */
	if (sview->sorted) {
	    series_view_unsort(sview);
	}
	
	err = printdata(list, NULL, dataset, OPT_O, prn);
	if (err) {
	    gui_errmsg(err);
	} 
	goto finalize;
    }

    obslen = max_obs_marker_length(dataset);

    if (sview->format == 'g') {
	sprintf(num_format, "%%#13.%dg\n", sview->digits);
    } else {
	sprintf(num_format, "%%13.%df\n", sview->digits);
    }
	
    pprintf(prn, "\n%*s ", obslen, " ");
    pprintf(prn, "%13s\n\n", dataset->varname[sview->varnum]);

    for (i=0; i<sview->npoints; i++) {
	t = sview->points[i].obsnum;
	x = sview->points[i].val;
	print_obs_marker(t, dataset, obslen, prn);
	if (na(x)) {
	    pputc(prn, '\n');
	} else {
	    pprintf(prn, num_format, x);
	} 
    }

 finalize:

    if (!err) {
	textview_set_text(vwin->text, gretl_print_get_buffer(prn));
    }

    gretl_print_destroy(prn);
}
예제 #12
0
static gretl_matrix *cluster_var_values (const double *cvar,
					 MODEL *pmod,
					 int *err)
{
    gretl_matrix *cvals = NULL;
    int t;

    if (pmod->missmask != NULL) {
	double *ctmp = malloc(pmod->nobs * sizeof *ctmp);

	if (ctmp == NULL) {
	    *err = E_ALLOC;
	} else {
	    int i = 0;

	    for (t=pmod->t1; t<=pmod->t2 && !*err; t++) {
		if (pmod->missmask[t] != '1') {
		    if (na(cvar[t])) {
			*err = E_MISSDATA;
		    } else {
			ctmp[i++] = cvar[t];
		    }
		}
	    }

	    if (!*err) {
		cvals = gretl_matrix_values(ctmp, pmod->nobs, OPT_S, err);
	    }
	    free(ctmp);
	}
    } else {
	/* no interior missing values for y or X */
	for (t=pmod->t1; t<=pmod->t2 && !*err; t++) {
	    if (na(cvar[t])) {
		*err = E_MISSDATA;
	    }
	}
	if (!*err) {
	    cvals = gretl_matrix_values(cvar + pmod->t1, pmod->nobs, 
					OPT_S, err);
	}
    }

    return cvals;
}
예제 #13
0
static int if_eval (const char *s, DATASET *dset, void *ptr, int *err)
{
    GENERATOR *ifgen = NULL;
    double val = NADBL;
    int ret = -1;

#if IFDEBUG
    fprintf(stderr, "if_eval: s = '%s'\n", s);
#endif

    while (*s == ' ') s++;

    if (ptr != NULL) {
	/* We're being called from a loop, with the implicit
	   request that the if-condition be "compiled" (if
	   that's not already done) and subsequently executed
	   without having to be evaluated from scratch.
	*/
	ifgen = *(GENERATOR **) ptr;

	if (ifgen == NULL) {
	    /* Generator not compiled yet: do it now. The
	       flags OPT_P and OPT_S indicate that we're
	       generating a "private" scalar.
	    */
	    GENERATOR **pgen = (GENERATOR **) ptr;

	    *pgen = ifgen = genr_compile(s, dset, OPT_P | OPT_S, err);
	}
    }

    if (ifgen != NULL) {
	val = evaluate_if_cond(ifgen, dset, err);
    } else {
	*err = 0;
	val = generate_scalar(s, dset, err);
    }

#if IFDEBUG
    fprintf(stderr, "if_eval: generate returned %d\n", *err);
#endif

    if (*err) {
	gretl_errmsg_set(_("error evaluating 'if'"));
    } else if (na(val)) {
	*err = 1;
	gretl_errmsg_set(_("indeterminate condition for 'if'"));
    } else {
	ret = (int) val;
    }

#if IFDEBUG
    fprintf(stderr, "if_eval: returning %d\n", ret);
#endif

    return ret;
}
예제 #14
0
void  CMlStaticStructLearn::CreateResultBNet(CDAG* pDAG)
{
    int i, j, k, ns;
    int nnodes = m_nNodes;
    CDAG* iDAG = pDAG->TopologicalCreateDAG(m_vResultRenaming);
    nodeTypeVector vnt;
    m_pGrModel->GetNodeTypes(&vnt);
    intVector na(nnodes);
    const int* nas = m_pGrModel->GetNodeAssociations();
    for(i=0; i<nnodes; i++) na[i] = nas[m_vResultRenaming[i]];
    m_pResultBNet = CBNet::Create(nnodes, vnt.size(), &vnt.front(),
                                  &na.front(), static_cast<CGraph*>(iDAG));
    const CNodeType* nt;

    int nEv = m_Vector_pEvidences.size();
    CEvidence** pEv = new CEvidence*[nEv];
    intVector obsnodes(nnodes);
    for(i=0; i<nnodes; i++) obsnodes[i] = i;
    valueVector new_data;
    const Value* val;
    for(i = 0 ; i < nEv; i++)
    {
        for(j=0; j<nnodes; j++)
        {
            val = m_Vector_pEvidences[i]->GetValue(m_vResultRenaming[j]);
            nt = m_pResultBNet->GetNodeType(j);
            if(nt->IsDiscrete())
            {
                new_data.push_back(*val);
            }
            else
            {
                ns = nt->GetNodeSize();
                for(k=0; k<ns; k++)
                    new_data.push_back(*(val+k));
            }
        }
        pEv[i] = CEvidence::Create(m_pResultBNet, nnodes, &obsnodes.front(), new_data);
        new_data.clear();
    }
    vnt.clear();

    intVector vFamily;
    m_pResultBNet->AllocFactors();
    for(i=0; i<nnodes; i++)
    {
        vFamily.clear();
        iDAG->GetParents(i, &vFamily);
        vFamily.push_back(i);
        CCPD* iCPD = ComputeFactor(vFamily, m_pResultBNet, pEv);
        m_pResultBNet->AttachFactor(iCPD);
    }

    for(i=0; i<nEv; i++)delete pEv[i];
    delete[] pEv;
}
예제 #15
0
static int qr_make_hac (MODEL *pmod, const DATASET *dset, 
			gretl_matrix *XTXi)
{
    gretl_matrix *X, *XOX, *V = NULL;
    gretl_matrix umat;
    VCVInfo vi;
    int T = pmod->nobs;
    int err = 0;

    X = make_data_X(pmod, dset);
    if (X == NULL) {
	return E_ALLOC;
    }

    /* pmod->uhat is a full-length series: we must take an offset
       into it, equal to the offset of the data on which the model
       is actually estimated.
    */
    gretl_matrix_init(&umat);
    umat.rows = T;
    umat.cols = 1;
    umat.val = pmod->uhat + pmod->t1;

    XOX = HAC_XOX(&umat, X, &vi, 0, &err);

    if (!err) {
	V = gretl_matrix_alloc(XOX->rows, XOX->rows);
	if (V == NULL) {
	    err = E_ALLOC;
	}
    }

    if (!err) {
	gretl_matrix_qform(XTXi, GRETL_MOD_TRANSPOSE, XOX,
			   V, GRETL_MOD_NONE);
	/* Transcribe vcv into triangular representation */
	err = qr_make_vcv(pmod, V, VCV_ROBUST);
    }

    if (!err) {
	gretl_model_set_full_vcv_info(pmod, vi.vmaj, vi.vmin,
				      vi.order, vi.flags,
				      vi.bw);
	if (!na(vi.bw)) {
	    gretl_model_set_double(pmod, "hac_bw", vi.bw);
	} else {
	    gretl_model_set_double(pmod, "hac_bw", (double) vi.order);
	}
    }	

    gretl_matrix_free(X);
    gretl_matrix_free(XOX);
    gretl_matrix_free(V);

    return err;
}
예제 #16
0
static double normal_ll (const garch_container *DH)
{
    double e2t, ht, ll = 0.0;
    int t;

    for (t=DH->t1; t<=DH->t2; t++) {
	e2t = DH->e2[t];
	ht = DH->h[t];
	if (na(e2t) || na(ht)) {
	    return NADBL;
	}
	ll -= log(ht) + e2t / ht;
    }

    ll *= 0.5;
    ll -= (DH->t2 - DH->t1 + 1) * LN_SQRT_2_PI;

    return ll;
} 
예제 #17
0
static int column_is_blank (wsheet *sheet, int k, int n)
{
    int t, s = (sheet->colheads)? 1 : 0;

    for (t=0; t<n; t++) {
	if (!na(sheet->Z[k][s++])) {
	    return 0;
	}
    }

    return 1;
}
예제 #18
0
static int cval_count (MODEL *pmod, double cvi, const double *cZ)
{
    int t, cc = 0;

    for (t=pmod->t1; t<=pmod->t2; t++) {
	if (!na(pmod->uhat[t]) && cZ[t] == cvi) {
	    cc++;
	}
    }

    return cc;
}
예제 #19
0
int transcribe_array (double *targ, const double *src, 
		      const DATASET *dset) 
{
    int t, n = 0;

    for (t=dset->t1; t<=dset->t2; t++) {
	if (!na(src[t])) {
	    targ[n++] = src[t];
	}
    }

    return n;
}
예제 #20
0
int gretl_rand_normal_full (double *a, int t1, int t2,
			    double mean, double sd) 
{
    int t;

    if (na(mean) && na(sd)) {
	mean = 0.0;
	sd = 1.0;
    } else if (na(mean) || na(sd) || sd <= 0.0) {
	return E_INVARG;
    }

    gretl_rand_normal(a, t1, t2);

    if (mean != 0.0 || sd != 1.0) {
	for (t=t1; t<=t2; t++) {
	    a[t] = mean + a[t] * sd;
	}
    }
    
    return 0;
}
예제 #21
0
int gretl_iszero (int t1, int t2, const double *x)
{
    double sum = 0.0;
    int t;

    for (t=t1; t<=t2; t++) {
	if (!na(x[t])) {
	    sum += x[t] * x[t];
	}
    }

    return floateq(sum, 0.0);
}
예제 #22
0
int gretl_isint (int t1, int t2, const double *x)
{
    int t, ret = 1;

    for (t=t1; t<=t2; t++) {
	if (!na(x[t]) && x[t] != floor(x[t])) {
	    ret = 0;
	    break;
	}
    }

    return ret;
}
예제 #23
0
static int results_agree (MODEL *pmod, int digits, int errs, int *abort)
{
    int i, j;
    char v1[48], v2[48];

    for (i=0; i<pmod->ncoeff; i++) {
	j = find_coeff_number(pmod, tester.coeffs[i].name);
	if (j < 0) {
	    fprintf(stderr, "%s: ERROR: Couldn't find param '%s'\n",
		    tester.datname, tester.coeffs[i].name);
	    continue;
	}
	if (errs == 0) {
	    sprintf(v1, "%#.*g", digits, tester.coeffs[i].val);
	    sprintf(v2, "%#.*g", digits, pmod->coeff[j]);
	    if (na(pmod->coeff[j])) *abort = 1;
	    if (doubles_differ(v1, v2)) {
		char s[32];

		sprintf(s, "coeff for %s", tester.coeffs[i].name);
		print_result_error(digits, v1, v2, s);
		return 0;
	    }
	} else {
	    sprintf(v1, "%#.*g", digits, tester.coeffs[i].sderr);
	    sprintf(v2, "%#.*g", digits, pmod->sderr[j]);
	    if (na(pmod->sderr[j])) *abort = 1;
	    if (doubles_differ(v1, v2)) {
		char s[32];

		sprintf(s, "std err for %s", tester.coeffs[i].name);
		print_result_error(digits, v1, v2, s);
		return 0; 
	    }
	}
    }

    return 1;
}
예제 #24
0
파일: na49geomfile.C 프로젝트: amadio/geant
void na49geomfile()
{
  //   Before executing this macro, the file makegeometry.C must have been executed
  //
  gBenchmark->Start("geometry");
  TGeometry *n49 = (TGeometry *)gROOT->FindObject("na49");
  if (n49) {
    TFile na("na49.root", "RECREATE");
    n49->Write();
    na.Write();
  }
  gBenchmark->Show("geometry");
}
예제 #25
0
static void 
real_arima_difference_series (double *dx, const double *x,
			      int t1, int t2, int *delta, 
			      int k)
{
    int i, p, t, s = 0;
    
    for (t=t1; t<=t2; t++) {
	dx[s] = x[t];
	for (i=0; i<k && !na(dx[s]); i++) {
	    if (delta[i] != 0) {
		p = t - i - 1;
		if (p < 0 || na(x[p])) {
		    dx[s]  = NADBL;
		} else {
		    dx[s] -= delta[i] * x[p];
		}
	    }
	}
	s++;
    }
}
예제 #26
0
static void estimates_ok (MODEL *pmod)
{
    int i, j;
    char v1[48], v2[48];

    for (i=0; i<pmod->ncoeff; i++) {
	j = find_coeff_number(pmod, tester.coeffs[i].name);

	if (j < 0) {
	    fprintf(stderr, "%s: ERROR: Couldn't find param '%s'\n",
		    tester.datname, tester.coeffs[i].name);
	    continue;
	}

	/* coefficients */
	total_coeffs++;
	sprintf(v1, "%#.*g", CHECK_DIGITS, tester.coeffs[i].val);
	sprintf(v2, "%#.*g", CHECK_DIGITS, pmod->coeff[j]);
	if (na(pmod->coeff[j])) {
	    continue;
	}
	if (doubles_differ(v1, v2) == 0) {
	    ok_coeffs++;
	}

	/* standard errors -- Lanczos1 is a special case */
	if (strcmp(tester.datname, "Lanczos1")) {
	    total_sderrs++;
	    sprintf(v1, "%#.*g", CHECK_DIGITS, tester.coeffs[i].sderr);
	    sprintf(v2, "%#.*g", CHECK_DIGITS, pmod->sderr[j]);
	    if (na(pmod->sderr[j])) {
		continue;
	    }
	    if (doubles_differ(v1, v2) == 0) {
		ok_sderrs++;
	    }
	}
    }
}
예제 #27
0
static void min_max (const double *x, double *min, double *max,
		     int n)
{
    int i;

    *min = *max = x[0];

    for (i=1; i<n; i++) {
	if (!na(x[i])) {
	    if (x[i] < *min) *min = x[i];
	    if (x[i] > *max) *max = x[i];
	}
    }
}
예제 #28
0
int gretl_rand_uniform_minmax (double *a, int t1, int t2,
			       double min, double max) 
{
    int t;

    if (na(min) && na(max)) {
	min = 0.0;
	max = 1.0;
    } else if (na(min) || na(max) || max <= min) {
	return E_INVARG;
    }

    for (t=t1; t<=t2; t++) {
	if (use_dcmt) {
	    a[t] = to_real2(dcmt_rand32()) * (max - min) + min;
	} else {
	    /* FIXME use native array functionality? */
	    a[t] = to_real2(sfmt_rand32()) * (max - min) + min;
	}
    }

    return 0;
}
예제 #29
0
const char *series_table_get_string (series_table *st, double val)
{
    const char *ret = NULL;

    if (!na(val)) {
	int k = val;

	if (k > 0 && k <= st->n_strs) {
	    ret = st->strs[k-1];
	}
    }

    return ret;
}
예제 #30
0
static void xlsx_check_top_left (xlsx_info *xinfo, int r, int c,
				 int stringcell, const char *s,
				 double x)
{
    if (r == xinfo->yoffset + 1 && c == xinfo->xoffset + 1) {
	/* We're in the top left cell of the reading area:
	   this could be blank, or could hold the first
	   varname, could hold "obs" or similar, or could
	   be the first numerical value.
	*/
#if XDEBUG
	fprintf(stderr, "xlsx_check_top_left: r=%d, c=%d, x=%g, stringcell=%d, "
		"s='%s'\n", r, c, x, stringcell, s);
#endif
	if (!na(x)) {
	    /* got a valid numerical value: that means we don't
	       have variable names on the top row */
	    xinfo->flags |= BOOK_AUTO_VARNAMES;
	} else if (stringcell && import_obs_label(s)) {
	    /* blank or "obs" or similar */
	    xinfo->flags |= BOOK_OBS_LABELS;
	    xinfo->obscol = c;
	}
	if (!na(x) || stringcell) {
	    /* record the fact that the top-left corner is not empty */
	    xinfo->flags &= ~BOOK_TOP_LEFT_EMPTY;
	}
    } else if (r == xinfo->yoffset + 1 && c == xinfo->xoffset + 2) {
	/* first row, second column */
	if (!na(x)) {
	    /* got a number, not a varname */
	    xinfo->flags |= BOOK_AUTO_VARNAMES;
	} else {
	    xinfo->namerow = r;
	}
    }
}