Ejemplo n.º 1
0
/* ------------------ L2str ------------------- */
void __CDECL
L2str( const PLstr s )
{
	if (LTYPE(*s)==LINTEGER_TY) {
#if defined(WCE) || defined(__BORLANDC__)
		LTOA(LINT(*s),LSTR(*s),10);
#else
		sprintf(LSTR(*s), "%ld", LINT(*s));
#endif
		LLEN(*s) = STRLEN(LSTR(*s));
	} else {	/* LREAL_TY */
		/* There is a problem with the Windows CE */
		char	str[50];
		size_t	len;

		snprintf(str, sizeof(str), "%.*g", lNumericDigits, LREAL(*s));
		/* --- remove the last dot from the number --- */
		len = STRLEN(str);
#ifdef WCE
		if (str[len-1] == '.') len--;
#endif
		if (len>=LMAXLEN(*s)) Lfx(s,len);
		MEMCPY(LSTR(*s),str,len);
		LLEN(*s) = len;
	}
	LTYPE(*s) = LSTRING_TY;
} /* L2str */
Ejemplo n.º 2
0
/* we should change the string                     */
void __CDECL
_L2num( const PLstr s, const int type )
{
	LASCIIZ(*s);
	switch (type) {
		case LINTEGER_TY:
			/*////LINT(*s) = atol( LSTR(*s) ); */
			LINT(*s) = (long)lLastScannedNumber;
			LTYPE(*s) = LINTEGER_TY;
			LLEN(*s) = sizeof(long);
			break;

		case LREAL_TY:
			/*////LREAL(*s) = strtod( LSTR(*s), NULL ); */
			LREAL(*s) = lLastScannedNumber;
			if ((double)((long)LREAL(*s)) == LREAL(*s)) {
				LINT(*s) = (long)LREAL(*s);
				LTYPE(*s) = LINTEGER_TY;
				LLEN(*s) = sizeof(long);
			} else {
				LTYPE(*s) = LREAL_TY;
				LLEN(*s) = sizeof(double);
			}
			break;
		default:
			Lerror(ERR_BAD_ARITHMETIC,0);
	}
} /* _L2num */
Ejemplo n.º 3
0
/* ------------------ L2int ------------------- */
void __CDECL
L2int( const PLstr s )
{
	if (LTYPE(*s)==LREAL_TY) {
		if ((double)((long)LREAL(*s)) == LREAL(*s))
			LINT(*s) = (long)LREAL(*s);
		else
			Lerror(ERR_INVALID_INTEGER,0);
	} else { /* LSTRING_TY */
		LASCIIZ(*s);
		switch (_Lisnum(s)) {
			case LINTEGER_TY:
				LINT(*s) = (long)lLastScannedNumber;
				break;

			case LREAL_TY:
				LREAL(*s) = lLastScannedNumber;
				if ((double)((long)LREAL(*s)) == LREAL(*s))
					LINT(*s) = (long)LREAL(*s);
				else
					Lerror(ERR_INVALID_INTEGER,0);
				break;

			default:
				Lerror(ERR_INVALID_INTEGER,0);
		}
	}
	LTYPE(*s) = LINTEGER_TY;
	LLEN(*s) = sizeof(long);
} /* L2int */
Ejemplo n.º 4
0
/* ---------------- Lstrcpy ----------------- */
void __CDECL
Lstrcpy( const PLstr to, const PLstr from )
{
	if (LLEN(*from)==0) {
		LLEN(*to) = 0;
		LTYPE(*to) = LSTRING_TY;
	} else {
		if (LMAXLEN(*to)<=LLEN(*from)) Lfx(to,LLEN(*from));
		switch ( LTYPE(*from) ) {
			case LSTRING_TY:
				MEMCPY( LSTR(*to), LSTR(*from), LLEN(*from) );
				break;

			case LINTEGER_TY:
				LINT(*to) = LINT(*from);
				break;

			case LREAL_TY:
				LREAL(*to) = LREAL(*from);
				break;
		}
		LTYPE(*to) = LTYPE(*from);
		LLEN(*to) = LLEN(*from);
	} 
} /* Lstrcpy */
Ejemplo n.º 5
0
/* ----------------- Lrdint ------------------ */
long __CDECL
Lrdint( const PLstr s )
{
	if (LTYPE(*s)==LINTEGER_TY) return LINT(*s);

	if (LTYPE(*s)==LREAL_TY) {
		if ((double)((long)LREAL(*s)) == LREAL(*s))
			return (long)LREAL(*s);
		else
			Lerror(ERR_INVALID_INTEGER,0);
	} else { /* LSTRING_TY */
		LASCIIZ(*s);
		switch (_Lisnum(s)) {
			case LINTEGER_TY:
				/*///return atol( LSTR(*s) ); */
				return (long)lLastScannedNumber;

			case LREAL_TY:
				/*///d = strtod( LSTR(*s), NULL );
				//////if ((double)((long)d) == d)
				//////	return (long)d; */
				if ((double)((long)lLastScannedNumber) == lLastScannedNumber)
					return (long)lLastScannedNumber;
				else
					Lerror(ERR_INVALID_INTEGER,0);
				break;

			default:
				Lerror(ERR_INVALID_INTEGER,0);
		}
	}
	return 0;	/* never gets here but keeps compiler happy */
} /* Lrdint */
Ejemplo n.º 6
0
/* ------------------ L2num ------------------- */
void __CDECL
L2num( const PLstr s )
{
	switch (_Lisnum(s)) {
		case LINTEGER_TY:
			/*//LINT(*s) = atol( LSTR(*s) ); */
			LINT(*s) = (long)lLastScannedNumber;
			LTYPE(*s) = LINTEGER_TY;
			LLEN(*s) = sizeof(long);
			break;

		case LREAL_TY:
			/*///LREAL(*s) = strtod( LSTR(*s), NULL ); */
			LREAL(*s) = lLastScannedNumber;
/*
//// Numbers like 2.0 should be treated as real and not as integer
//// because in cases like factorial while give an error result
////			if ((double)((long)LREAL(*s)) == LREAL(*s)) {
////				LINT(*s) = (long)LREAL(*s);
////				LTYPE(*s) = LINTEGER_TY;
////				LLEN(*s) = sizeof(long);
////			} else {
*/
				LTYPE(*s) = LREAL_TY;
				LLEN(*s) = sizeof(double);
/*
////			}
*/
			break;

		default:
			Lerror(ERR_BAD_ARITHMETIC,0);
	}
} /* L2num */
Ejemplo n.º 7
0
/* ---------------- Licpy ------------------ */
void __CDECL
Licpy( const PLstr to, const long from )
{
	LLEN(*to)  = sizeof(long);
	LTYPE(*to) = LINTEGER_TY;
	LINT(*to)  = from;
} /* Licpy */
Ejemplo n.º 8
0
/* --------------------------------------------------------------- */
void R_sql( const int func )
{
	int rc;
	const char *tail;

	if (ARGN!=1) Lerror(ERR_INCORRECT_CALL,0);
	get_s(1);

	if (!sqldb)   Lerror(ERR_DATABASE,1);

	if (sqlstmt) {
		sqlite3_finalize(sqlstmt);
		sqlstmt = NULL;
	}

	Licpy(ARGR, sqlite3_prepare_v2(sqldb, LSTR(*ARG1), LLEN(*ARG1), &sqlstmt, &tail));
	if (LINT(*ARGR) == SQLITE_OK) {
		if (sqlite3_bind_parameter_count(sqlstmt)==0) {
			rc = sqlite3_step(sqlstmt);
			if (rc == SQLITE_ROW)
				Lscpy(ARGR, "ROW");
			else
			if (rc == SQLITE_DONE)
				Licpy(ARGR, SQLITE_OK);
			else
				Licpy(ARGR, rc);
		}
	}
} /* R_sql */
Ejemplo n.º 9
0
/* ---------------- Lintdiv ---------------- */
void __CDECL
Lintdiv( const PLstr to, const PLstr A, const PLstr B )
{
	double	b;

	b = Lrdreal(B);

	if (b == 0) Lerror(ERR_ARITH_OVERFLOW,0);

	LINT(*to)  = (long) (Lrdreal(A) / b);
	LTYPE(*to) = LINTEGER_TY;
	LLEN(*to)  = sizeof(long);
} /* Lintdiv */
Ejemplo n.º 10
0
/* ------------------ L2real ------------------- */
void __CDECL
L2real( const PLstr s )
{
	if (LTYPE(*s)==LINTEGER_TY)
		LREAL(*s) = (double)LINT(*s);
	else { /* LSTRING_TY */
		LASCIIZ(*s);
		if (_Lisnum(s)!=LSTRING_TY)
			/*/////LREAL(*s) = strtod( LSTR(*s), NULL ); */
			LREAL(*s) = lLastScannedNumber;
		else
			Lerror(ERR_BAD_ARITHMETIC,0);
	}
	LTYPE(*s) = LREAL_TY;
	LLEN(*s) = sizeof(double);
} /* L2real */
Ejemplo n.º 11
0
/* ----------------- Lrdreal ------------------ */
double __CDECL
Lrdreal( const PLstr s )
{
	if (LTYPE(*s)==LREAL_TY) return LREAL(*s);

	if (LTYPE(*s)==LINTEGER_TY)
		return (double)LINT(*s);
	else { /* LSTRING_TY */
		LASCIIZ(*s);
		if (_Lisnum(s)!=LSTRING_TY)
			/*///// return strtod( LSTR(*s), NULL ); */
			return lLastScannedNumber;
		else
			Lerror(ERR_BAD_ARITHMETIC,0);
	}
	return 0.0;
} /* Lrdreal */
Ejemplo n.º 12
0
Archivo: gen.c Proyecto: kohsiangyu/Lab
StringSet::StringSet(LINT nitems, 	// number of items
		     PatternPar par,	// npats, patlen, corr, conf & conf_var
		     Taxonomy *ptax,	// taxonomy (optional)
		     FLOAT rept,	// repetition-level
		     FLOAT rept_var	// variation in repetition-level
		     )
  : tax(ptax)
{
  NormalDist conf(par.conf, par.conf_var);
  ExpDist freq;
  ExpDist corr_lvl;
  PoissonDist len(par.patlen-1);	// string length
  NormalDist repeat(rept, rept_var);
  UniformDist ud;

  items = new ItemSet(nitems, tax);	// associate probabilities with items

  LINT i, j, num_same;
  FLOAT tot;

  npats = par.npats;
//  last_pat = 0;
  pat = new StringP [npats];
  for (i = 0; i < npats; i++)
    {
      pat[i] = new String( 1+len() );

      // fill correlated items
      if (par.corr > 0 && i > 0) {	// correlated patterns
	// each pattern has some items same as the previous pattern
	num_same = LINT( pat[i]->size() * par.corr * corr_lvl() + 0.5 );
	if ( num_same > pat[i-1]->size() )
	  num_same = pat[i-1]->size();
	if ( num_same > pat[i]->size() )
	  num_same = pat[i]->size();
	// choose num_same items at random from previous pattern
	Choose shuffle(pat[i-1]->size(), num_same);
	for (j = 0; j < num_same; j++)
	  pat[i]->items[j] = pat[i-1]->item( shuffle.pos(j) );
//	pat[i-1]->shuffle(num_same);
//	for (j = 0; j < num_same; j++)
//	  pat[i]->items[j] = pat[i-1]->rand_item(j);
      }
      else {	// no correlation
	num_same = 0;
      }

      if (rept == 0) {
	// fill remaining items at random
	for (j = num_same; j < pat[i]->size(); j++)
	  pat[i]->items[j] = items->get_item();
//	pat[i]->items[j] = LINT(1 + nitems * rand());
      }
      else {
	// some items are repetitions
	FLOAT rept_lvl = repeat();
	for (j = num_same; j < pat[i]->size(); j++)
	  if ( j > 0 && ud() < rept_lvl )	// pick a previous item
	    pat[i]->items[j] = pat[i]->items[ LINT(j*ud()) ];
	  else	// pick random item
	    pat[i]->items[j] = items->get_item();
      }
      pat[i]->prob = freq(); // prob. that this pattern will be picked
      pat[i]->conf = conf(); // used in Transaction::add and CustSeq::add
      			     // to decide how many items to drop from
			     //  this pattern to corrupt it
    }

  if (tax) {
    // weight probabilites with geometric mean of probabilities of items
    for (i = 0; i < npats; i++)
      {
	DOUBLE weight = 1;
	for (j = 0; j < pat[i]->size(); j++)
	  weight *= items->weight(pat[i]->items[j]);
//	cerr << "WEIGHT = " << weight;
	weight = pow(weight, DOUBLE(1)/pat[i]->size());
//	cerr << "  " << weight << endl;
	pat[i]->prob *= weight;
      }
  }

  // normalize probabilites (why -- see get_pat)
  cum_prob = new FLOAT [npats];
  tot = 0;
  for (i = 0; i < npats; i++)
    tot += pat[i]->prob;
  for (i = 0; i < npats; i++)
    pat[i]->prob /= tot;

  // calulate cumulative probabilities
  cum_prob[0] = pat[0]->prob;
  for (i = 1; i < npats; i++)
    cum_prob[i] = cum_prob[i-1] + pat[i]->prob;
//  cerr << cum_prob[npats-1] << endl << flush;

  // allocate space for answer
  LINT maxlen = 0;
  for (i = 1; i < npats; i++)
    if (pat[i]->size() > maxlen)
      maxlen = pat[i]->size();
  answer = new String(maxlen);
}
Ejemplo n.º 13
0
void get_args(SeqPar &par, int argc, char **argv)
{
  LINT arg_pos = 2;
  
  strcpy(data_file, "data");
  strcpy(pat_file, "pat");
  strcpy(tax_file, "tax");
  while (arg_pos < argc)
    {
      if (strcmp(argv[arg_pos], "-ncust") == 0) {
	// g++ LINT LINT 
	par.ncust = LINT (1000 * atof(argv[++arg_pos]));
	cat_fname(".ncust_", argv[arg_pos]);
	arg_pos++;
	if (par.ncust < 1) exit_fail_with_msg("ntrans must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-slen") == 0) {
	par.slen = atof(argv[++arg_pos]);
	cat_fname(".slen_", argv[arg_pos]);
	arg_pos++;
	if (par.slen < 1) exit_fail_with_msg("slen must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-tlen") == 0) {
	par.tlen = atof(argv[++arg_pos]);
	cat_fname(".tlen_", argv[arg_pos]);
	arg_pos++;
	if (par.tlen < 1) exit_fail_with_msg("tlen must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-nitems") == 0) {
	// g++ LINT 
	par.nitems = LINT (1000 * atof(argv[++arg_pos]));
	cat_fname(".nitems_", argv[arg_pos]);
	arg_pos++;
	if (par.nitems < 1) exit_fail_with_msg("nitems must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-rept") == 0) {
	par.rept = atof(argv[++arg_pos]);
	cat_fname(".rept_", argv[arg_pos]);
	arg_pos++;
	if (par.rept < 0 || par.rept > 1) 
	  exit_fail_with_msg("repetition-level must be between 0 and 1");
	continue;
      }

      else if (strcmp(argv[arg_pos], "-seq.npats") == 0) {
	par.lseq.npats = atoi(argv[++arg_pos]);
	cat_fname(".seq.npats_", argv[arg_pos]);
	arg_pos++;
	if (par.lseq.npats < 1) exit_fail_with_msg("npats must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-seq.patlen") == 0) {
	par.lseq.patlen = atof(argv[++arg_pos]);
	cat_fname(".seq.patlen_", argv[arg_pos]);
	arg_pos++;
	if (par.lseq.patlen <= 0) exit_fail_with_msg("patlen must be > 0");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-seq.corr") == 0) {
	par.lseq.corr = atof(argv[++arg_pos]);
	cat_fname(".seq.corr_", argv[arg_pos]);
	arg_pos++;
	continue;
      }
      else if (strcmp(argv[arg_pos], "-seq.conf") == 0) {
	par.lseq.conf = atof(argv[++arg_pos]);
	cat_fname(".seq.conf_", argv[arg_pos]);
	arg_pos++;
	if (par.lseq.conf > 1 || par.lseq.conf < 0) 
	  exit_fail_with_msg("conf must be between 0 and 1");
	continue;
      }

      else if (strcmp(argv[arg_pos], "-lit.npats") == 0) {
	par.lits.npats = atoi(argv[++arg_pos]);
	cat_fname(".lit.npats_", argv[arg_pos]);
	arg_pos++;
	if (par.lits.npats < 1) exit_fail_with_msg("npats must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-lit.patlen") == 0) {
	par.lits.patlen = atof(argv[++arg_pos]);
	cat_fname(".lit.patlen_", argv[arg_pos]);
	arg_pos++;
	if (par.lits.patlen <= 0) exit_fail_with_msg("patlen must be > 0");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-lit.corr") == 0) {
	par.lits.corr = atof(argv[++arg_pos]);
	cat_fname(".lit.corr_", argv[arg_pos]);
	arg_pos++;
	continue;
      }
      else if (strcmp(argv[arg_pos], "-lit.conf") == 0) {
	par.lits.conf = atof(argv[++arg_pos]);
	cat_fname(".lit.conf_", argv[arg_pos]);
	arg_pos++;
	if (par.lits.conf > 1 || par.lits.conf < 0) 
	  exit_fail_with_msg("conf must be between 0 and 1");
	continue;
      }

      else if (strcmp(argv[arg_pos], "-fname") == 0) {
        strcpy(data_file, argv[++arg_pos]);
        strcat(data_file, ".data");
        strcpy(pat_file, argv[arg_pos]);
        strcat(pat_file, ".pat");
        strcpy(tax_file, argv[arg_pos++]);
        strcat(tax_file, ".tax");
        userfile = true;
	continue;
      }
      else if (strcmp(argv[arg_pos], "-ascii") == 0) {
	par.ascii = true;
	cat_fname(".ascii", "");
	arg_pos++;
	continue;
      }
      else if (strcmp(argv[arg_pos], "-version") == 0) {
	cout << VERSION << endl;
	exit(EXIT_SUCCESS);
      }
      else {
	command_line(par);
      }
    }  // end while
}
Ejemplo n.º 14
0
void get_args(TaxPar &par, int argc, char **argv)
{
  LINT arg_pos = 2;
  
  strcpy(data_file, "data");
  strcpy(pat_file, "pat");
  strcpy(tax_file, "tax");
  while (arg_pos < argc)
    {
      if (strcmp(argv[arg_pos], "-ntrans") == 0) {
	// g++ LINT !!
	par.ntrans = LINT (1000 * atof(argv[++arg_pos]));
	cat_fname(".ntrans_", argv[arg_pos]);
	arg_pos++;
	if (par.ntrans < 1) exit_fail_with_msg("ntrans must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-tlen") == 0) {
	par.tlen = atof(argv[++arg_pos]);
	cat_fname(".tlen_", argv[arg_pos]);
	arg_pos++;
	if (par.tlen < 1) exit_fail_with_msg("tlen must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-nitems") == 0) {
	// g++ the LINT worm is back again! 
	par.nitems = LINT (1000 * atof(argv[++arg_pos]));
	cat_fname(".nitems_", argv[arg_pos]);
	arg_pos++;
	if (par.nitems < 1) exit_fail_with_msg("nitems must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-nroots") == 0) {
	par.nroots = atoi(argv[++arg_pos]);
	cat_fname(".nroots_", argv[arg_pos]);
	arg_pos++;
	if (par.nroots < 1) exit_fail_with_msg("nroots must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-nlevels") == 0) {
	par.nlevels = atof(argv[++arg_pos]);
	cat_fname(".nlevels_", argv[arg_pos]);
	arg_pos++;
	if (par.nlevels < 1) exit_fail_with_msg("nlevels must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-fanout") == 0) {
	par.fanout = atof(argv[++arg_pos]);
	cat_fname(".fanout_", argv[arg_pos]);
	arg_pos++;
	if (par.fanout < 1) exit_fail_with_msg("fanout must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-depth") == 0) {
	par.depth_ratio = atof(argv[++arg_pos]);
	cat_fname(".depth_", argv[arg_pos]);
	arg_pos++;
	if (par.depth_ratio <= 0) exit_fail_with_msg("fanout must be > 0");
	continue;
      }

      else if (strcmp(argv[arg_pos], "-npats") == 0) {
	par.lits.npats = atoi(argv[++arg_pos]);
	cat_fname(".npats_", argv[arg_pos]);
	arg_pos++;
	if (par.lits.npats < 1) exit_fail_with_msg("npats must be >= 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-patlen") == 0) {
	par.lits.patlen = atof(argv[++arg_pos]);
	cat_fname(".patlen_", argv[arg_pos]);
	arg_pos++;
	if (par.lits.patlen <= 0) exit_fail_with_msg("patlen must be > 0");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-corr") == 0) {
	par.lits.corr = atof(argv[++arg_pos]);
	cat_fname(".corr_", argv[arg_pos]);
	arg_pos++;
	continue;
      }
      else if (strcmp(argv[arg_pos], "-conf") == 0) {
	par.lits.conf = atof(argv[++arg_pos]);
	cat_fname(".conf_", argv[arg_pos]);
	arg_pos++;
	if (par.lits.conf > 1 || par.lits.conf < 0) 
	  exit_fail_with_msg("conf must be between 0 and 1");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-fname") == 0) {
        strcpy(data_file, argv[++arg_pos]);
        strcat(data_file, ".data");
        strcpy(pat_file, argv[arg_pos]);
        strcat(pat_file, ".pat");
        strcpy(tax_file, argv[arg_pos++]);
        strcat(tax_file, ".tax");
        userfile = true;
	continue;
      }
      else if (strcmp(argv[arg_pos], "-ascii") == 0) {
	par.ascii = true;
	cat_fname(".ascii", "");
	arg_pos++;
	continue;
      }
      else if (strcmp(argv[arg_pos], "-randseed") == 0) {
	par.seed = atoi(argv[++arg_pos]);
	arg_pos++;
	if (par.seed >= 0)
	  exit_fail_with_msg("randseed must be negative");
	continue;
      }
      else if (strcmp(argv[arg_pos], "-version") == 0) {
	cout << VERSION << endl;
	exit(EXIT_SUCCESS);
      }
      else {
	command_line(par);
      }
    }  // end while

  par.calc_values();
}