Пример #1
0
void initialize_parser(void)
{
   int i;

   st.globalvars = table_create(TABLESIZE);
   st.classvars = table_create(TABLESIZE);
   st.localvars = table_create(TABLESIZE);
   st.missingvars = table_create(TABLESIZE);

   /* Add function names to table of global identifiers */
   for (i=0; i < numfuncs; i++)
   {
      id_type id = (id_type) SafeMalloc(sizeof(id_struct));
      id->name = Functions[i].name;
      id->type = I_FUNCTION;
      id->idnum = i;  /* For functions, idnum is just index in table, not a real id # */
      if (table_insert(st.globalvars, (void *) id, id_hash, id_compare) != 0)
         simple_error("Duplicate built-in function name %s", id->name);
   }

   /* Add builtin identifiers to appropriate symbol tables */
   for (i=0; i < numbuiltins; i++)
      switch (BuiltinIds[i].type)
      {
      case I_MISSING:
         if (table_insert(st.missingvars, (void *) &BuiltinIds[i], id_hash, id_compare) != 0)
            simple_error("Duplicate builtin identifier name %s", BuiltinIds[i].name);
         break;

      case I_PROPERTY:
         if (table_insert(st.globalvars, (void *) &BuiltinIds[i], id_hash, id_compare) != 0)
            simple_error("Duplicate builtin identifier name %s", BuiltinIds[i].name);
         break;

      default:
         simple_error("Bad type on builtin identifier %s", BuiltinIds[i].name);
         break;
      }

   st.maxid = IDBASE; /* Base for user-defined ids; builtins have lower #s */
   st.maxresources = RESOURCEBASE;
   st.maxlocals = -1; /* So that first local is numbered 0 */
   st.maxclassvars = -1; /* So that first class variable is numbered 0 */
   // XXX not needed because of self
#if 0
   st.maxproperties = -1; /* So that first property is numbered 0 */
#endif

   st.recompile_list = NULL;
   st.constants = NULL;
   st.num_strings = 0;
   st.strings = NULL;
   st.override_classvars = NULL;
}
Пример #2
0
/* Establish an HTTP connection given the address provided in rt_http_open().
 * The read is carried out using an HTTP GET method.
 * Sequence is ignored, but offset is honoured, returning data from
 * offset bytes.
 * Declarations in the configuration [passed in rt_http_init()] dictate
 * the proxy, user accounts, passwords, cookie environment and ssl tokens
 * so that it is hidden from normal use.
 * A table is returned if successful, with a 'data' column and a '_time'
 * column for the time stamp.
 * NULL is returned on failure or if there is no data.
 */
TABLE rt_http_tread  (RT_LLD lld, int seq, int offset)
{
     RT_HTTPD rt;
     char *text;
     TABLE tab;
     int r;

     rt = rt_http_from_lld(lld);

     text = http_get(rt->url, NULL, NULL, NULL, 0);
     if (!text)
	  return NULL;

     /* create the list */
     tab = table_create();
     r = table_scan(tab, text, "\t", TABLE_SINGLESEP, TABLE_HASCOLNAMES, 
		    TABLE_HASRULER);
#if 0
     tab = table_create_a(rt_http_tabschema);
     table_addemptyrow(tab);
     table_replacecurrentcell(tab, "data", text);
     table_replacecurrentcell_alloc(tab, "_time", util_i32toa(time(NULL)));
#endif
     table_freeondestroy(tab, text);
     if (r < 1) {
	  /* empty table, no data or error */
	  table_destroy(tab);
	  tab = NULL;
     }

     return tab;
}
Пример #3
0
void
table_main(int ac, char **av)
{
	if (!strncmp(*av, "append", strlen(*av))) {
		table_append(ac, av);
	} else if (!strncmp(*av, "remove", strlen(*av))) {
		table_remove(ac, av);
	} else if (!strncmp(*av, "flush", strlen(*av))) {
		table_flush(ac, av);
	} else if (!strncmp(*av, "list", strlen(*av))) {
		table_list(ac, av);
	} else if (!strncmp(*av, "show", strlen(*av))) {
		table_show(ac, av);
	} else if (!strncmp(*av, "type", strlen(*av))) {
		table_create(ac, av);
	} else if (!strncmp(*av, "delete", strlen(*av))) {
		table_delete(ac, av);
	} else if (!strncmp(*av, "test", strlen(*av))) {
		table_test(ac,av);
	} else if (!strncmp(*av, "name", strlen(*av))) {
		table_rename(ac, av);
	} else {
		errx(EX_USAGE, "bad ipfw table command `%s'", *av);
	}
}
Пример #4
0
void
test_unsequantial_records_in_table_with_keys(void)
{
  grn_obj *table;
  grn_id id, expected_id = 1;
  const gchar *keys[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  int i, n_keys = sizeof(keys) / sizeof(keys[0]);

  table = table_create("Weekdays", GRN_OBJ_TABLE_HASH_KEY, "ShortText", NULL);
  grn_test_assert_context(context);

  for (i = 0; i < n_keys; ++i) {
    id = grn_table_add(context, table, keys[i], strlen(keys[i]), NULL);
    cut_assert_equal_int(expected_id++, id);
    grn_test_assert_context(context);
  }

  grn_table_delete_by_id(context, table, 3);
  grn_table_delete_by_id(context, table, 6);

  cut_assert_equal_string("table_create Weekdays TABLE_HASH_KEY ShortText\n"
                          "load --table Weekdays\n"
                          "[\n"
                          "[\"_key\"],\n"
                          "[\"Sun\"],\n"
                          "[\"Mon\"],\n"
                          "[\"Wed\"],\n"
                          "[\"Thu\"],\n"
                          "[\"Sat\"]\n"
                          "]",
                          send_command("dump"));
}
Пример #5
0
static int
table_static_update(struct table *table)
{
	struct table	*t;
	void		*p = NULL;

	/* no config ? ok */
	if (table->t_config[0] == '\0')
		goto ok;

	t = table_create("static", table->t_name, "update", table->t_config);
	if (!table_config(t))
		goto err;

	/* replace former table, frees t */
	while (dict_poproot(&table->t_dict, NULL, (void **)&p))
		free(p);
	dict_merge(&table->t_dict, &t->t_dict);
	table_destroy(t);

ok:
	log_info("info: Table \"%s\" successfully updated", table->t_name);
	return 1;

err:
	table_destroy(t);
	log_info("info: Failed to update table \"%s\"", table->t_name);
	return 0;
}
Пример #6
0
/*
* strtab_create:  Return pointer to strtab; to be passed to strtab_insert()
*	and strtab_free().
*/
STRTAB *
strtab_create(void)
{
    STRTAB *strtab;

    /*
       * Set alignSize to one less thatn the least power of 2 greater or
       * equal to IDSIZE.
       * This is assumed to be the maximum required alignment for this type.
     */
    if (alignSize == 0) {	/* first time only */
	alignSize = 1;
	while (alignSize < IDSIZE)
	    alignSize <<= 1;
	--alignSize;
    }

    strtab = (STRTAB *) malloc(sizeof *strtab);
    CHECK_MALLOC(strtab);

    strtab->buf_list = NULL;
    strtab->buf_ptr = NULL;
    strtab->size = 0;
    strtab->index = (TABLE *) table_create(strcmp);
    if (strtab->index == NULL) {
	free(strtab);
	return (NULL);
    }
    strtab->upfix = (void *) upfix_init(UPFIX_MAX_LEN, NULL);
    CHECK_MALLOC(strtab->upfix);

    return strtab;
}
Пример #7
0
/**
 * Creates a new URLENCODED parser.
 *
 * @return New parser, or NULL on memory allocation failure.
 */
htp_urlenp_t *htp_urlenp_create(htp_tx_t *tx) {
    htp_urlenp_t *urlenp = calloc(1, sizeof (htp_urlenp_t));
    if (urlenp == NULL) return NULL;

    urlenp->tx = tx;

    urlenp->params = table_create(HTP_URLENP_DEFAULT_PARAMS_SIZE);
    if (urlenp->params == NULL) {
        free(urlenp);
        return NULL;
    }

    urlenp->_bb = bstr_builder_create();
    if (urlenp->_bb == NULL) {
        table_destroy(&urlenp->params);
        free(urlenp);
        return NULL;
    }

    urlenp->argument_separator = '&';
    urlenp->decode_url_encoding = 1;
    urlenp->_state = HTP_URLENP_STATE_KEY;

    return urlenp;
}
Пример #8
0
/*
* LoadResources: Load all resources into a newly allocated table.
*   Return True on success, False iff no resource files found.
*/
Bool LoadResources(void)
{
	Bool rsc_loaded, rsb_loaded;
	
	/* Initialize new table */
	t = table_create(TABLE_SIZE);
	
	ignore_duplicates = True;
	// Load combined rscs, then normal rscs
	rsb_loaded = LoadRscFilesSorted(rsb_spec);
	rsc_loaded = LoadRscFiles(rsc_spec);
	
	// Built-in resources for About box
	RscAddCallback("", ABOUT_RSC, "aarmor.bgf");
	RscAddCallback("", ABOUT_RSC1, "c1.bgf");
	RscAddCallback("", ABOUT_RSC2, "c2.bgf");
	RscAddCallback("", ABOUT_RSC3, "c3.bgf");
	RscAddCallback("", LAGBOXICON_RSC, "ilagbox.bgf");
	RscAddCallback("", LAGBOXNAME_RSC, "Latency");
	
	ignore_duplicates = False;
	
	if (!rsb_loaded && !rsc_loaded)
	{
		debug(("Couldn't load any resources!\n"));
		return False;
	}
	
	return True;
}
Пример #9
0
int main(void) {

    Table *table = table_create(compareString);
    //table_setKeyMemHandler(table, free);
    //table_setValueMemHandler(table,free);
    //char *key1 = "key1";
    //char *key2 = "key2";
    //char *value1 = "value1";
    //char *value2 = "value2";

    if(table_isEmpty(table)){
        printf("The table is empty\n");
    } else {
        printf("The table is not empty\n");
    }

    //printf("key 101 has value %d\n", *((int*)table_lookup(table, intPtrFromInt(101))));
    //table_insert(table, key1, value1);
    //table_insert(table, key2, value2);
    //table_remove(table, key1);

    //if (table_isEmpty(table)) {
    //    printf("The table is empty\n");
    //} else {
    //    printf("The table is not empty\n");
    //}

    //printf("key 101 has value %s\n", ((char *) table_lookup(table, key2)));
    table_free(table);
    //free(table);

    return 0;
}
Пример #10
0
void fake_data()
{
	/* use this function to create fake data to test your analysis, before you try real data */

	/* how many data in all? */
	int numdata = 999;

	/* create internal table to hold data */
	table_create("fakedata");

	/* define table structure */ 
	// table_addcolumn("fakedata", <column_name>);
	// ...

	/* create fake data */
	for(int ii = 0; ii < numdata; ii++)
	{
		/* compute values of a fake data row */

		/* write these values to the data (as if reading real data) */
		// table_writevalue("fakedata", <column_name>, ii, <computed_value>);
		// ...
	}

	/* output data to use later on */
	table_output("fakedata","./workspace/mymodel_fakedata.txt");

	return;
}
Пример #11
0
bool init_inotify() {
  inotify_fd = inotify_init();
  if (inotify_fd < 0) {
    int e = errno;
    userlog(LOG_ERR, "inotify_init: %s", strerror(e));
    if (e == EMFILE) {
      message(MSG_INSTANCE_LIMIT);
    }
    return false;
  }
  userlog(LOG_DEBUG, "inotify fd: %d", get_inotify_fd());

  read_watch_descriptors_count();
  if (watch_count <= 0) {
    close(inotify_fd);
    inotify_fd = -1;
    return false;
  }
  userlog(LOG_INFO, "inotify watch descriptors: %d", watch_count);

  watches = table_create(watch_count);
  if (watches == NULL) {
    userlog(LOG_ERR, "out of memory");
    close(inotify_fd);
    inotify_fd = -1;
    return false;
  }

  return true;
}
Пример #12
0
int init_tests( void ) {
	ASSERT_TRUE(table_create(&test_table, HASH_DEFAULT_SIZE));

	value = (int*) malloc(sizeof(int));
	ASSERT_NOT_NULL(value);
	*value = 0;

	ASSERT_TRUE(table_put(&test_table, L"test", value, NULL));
	return 0;
}
Пример #13
0
void
test_table_create(gconstpointer data)
{
  table_create(gcut_data_get_string(data, "name"),
               gcut_data_get_uint(data, "flags"),
               gcut_data_get_string(data, "key_type_name"),
               gcut_data_get_string(data, "value_type_name"));
  cut_assert_equal_string(gcut_data_get_string(data, "expected"),
                          send_command("dump"));
}
Пример #14
0
int srslte_modem_table_set(srslte_modem_table_t* q, cf_t* table, uint32_t nsymbols, uint32_t nbits_x_symbol) {
  if (q->nsymbols) {
    return SRSLTE_ERROR;
  }
  q->nsymbols = nsymbols;
  if (table_create(q)) {
    return SRSLTE_ERROR;
  }
  memcpy(q->symbol_table,table,q->nsymbols*sizeof(cf_t));
  q->nbits_x_symbol = nbits_x_symbol;
  return SRSLTE_SUCCESS;
}
Пример #15
0
void hash_reads( table* T, const char* reads_fn, interval_stack* is )
{
    samfile_t* reads_f = samopen( reads_fn, "rb", NULL );
    if( reads_f == NULL ) {
        failf( "Can't open bam file '%s'.", reads_fn );
    }

    bam_index_t* reads_index = bam_index_load( reads_fn );
    if( reads_index == NULL ) {
        failf( "Can't open bam index '%s.bai'.", reads_fn );
    }

    bam_init_header_hash( reads_f->header );

    table_create( T, reads_f->header->n_targets );
    T->seq_names = (char**)malloc( sizeof(char*) * reads_f->header->n_targets );
    size_t k;
    for( k = 0; k < reads_f->header->n_targets; k++ ) {
        T->seq_names[k] = strdup(reads_f->header->target_name[k]);
    }

    log_puts( LOG_MSG, "hashing reads ... \n" );
    log_indent();
    bam_iter_t read_iter;
    bam1_t* read = bam_init1();
    int tid;

    interval_stack::iterator i;
    for( i = is->begin(); i != is->end(); i++ ) {
        tid = bam_get_tid( reads_f->header, i->seqname );
        if( tid < 0 ) continue;

        read_iter = bam_iter_query( reads_index, tid,
                                    i->start, i->end );

        while( bam_iter_read( reads_f->x.bam, read_iter, read ) >= 0 ) {
            if( bam1_strand(read) == i->strand ) {
                table_inc( T, read );
            }
        }

        bam_iter_destroy(read_iter);
    }

    bam_destroy1(read);

    log_unindent();
    log_printf( LOG_MSG, "done. (%zu unique reads hashed)\n", T->m );


    bam_index_destroy(reads_index);
    samclose(reads_f);
}
Пример #16
0
int modem_table_set(modem_table_t* q, cf* table, soft_table_t *soft_table, int nsymbols, int nbits_x_symbol) {
	if (q->nsymbols) {
		return -1;
	}
	q->nsymbols = nsymbols;
	if (table_create(q)) {
		return -1;
	}
	memcpy(q->symbol_table,table,q->nsymbols*sizeof(cf));
	memcpy(&q->soft_table,soft_table,sizeof(soft_table_t));
	q->nbits_x_symbol = nbits_x_symbol;
	return 0;
}
Пример #17
0
Файл: table.c Проект: mity/mctrl
MC_HTABLE MCTRL_API
mcTable_Create(WORD wColumnCount, WORD wRowCount, DWORD dwReserved)
{
    table_t* table;

    table = table_create(wColumnCount, wRowCount);
    if(MC_ERR(table == NULL)) {
        MC_TRACE("mcTable_Create: table_create() failed.");
        return NULL;
    }

    return table;
}
Пример #18
0
int srslte_modem_table_lte(srslte_modem_table_t* q, srslte_mod_t modulation) {
  srslte_modem_table_init(q);
  switch(modulation) {
  case SRSLTE_MOD_LAST:
  case SRSLTE_MOD_BPSK:
    q->nbits_x_symbol = 1;
    q->nsymbols = 2;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_BPSKtable(q->symbol_table);
    break;
  case SRSLTE_MOD_QPSK:
    q->nbits_x_symbol = 2;
    q->nsymbols = 4;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_QPSKtable(q->symbol_table);
    break;
  case SRSLTE_MOD_16QAM:
    q->nbits_x_symbol = 4;
    q->nsymbols = 16;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_16QAMtable(q->symbol_table);
    break;
  case SRSLTE_MOD_64QAM:
    q->nbits_x_symbol = 6;
    q->nsymbols = 64;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_64QAMtable(q->symbol_table);
    break;
  }
  return SRSLTE_SUCCESS;
}
Пример #19
0
/**
 * Creates a new transaction structure.
 *
 * @param cfg
 * @param is_cfg_shared
 * @param conn
 * @return The newly created transaction, or NULL on memory allocation failure.
 */
htp_tx_t *htp_tx_create(htp_cfg_t *cfg, int is_cfg_shared, htp_conn_t *conn) {
    htp_tx_t *tx = calloc(1, sizeof (htp_tx_t));
    if (tx == NULL) return NULL;

    tx->conn = conn;
    tx->cfg = cfg;
    tx->is_cfg_shared = is_cfg_shared;

    tx->conn = conn;

    tx->request_header_lines = list_array_create(32);
    tx->request_headers = table_create(32);
    tx->request_line_nul_offset = -1;
    tx->parsed_uri = calloc(1, sizeof (htp_uri_t));
    tx->parsed_uri_incomplete = calloc(1, sizeof (htp_uri_t));

    tx->response_header_lines = list_array_create(32);
    tx->response_headers = table_create(32);

    tx->request_protocol_number = -1;

    return tx;
}
Пример #20
0
int modem_table_std(modem_table_t* q, enum modem_std  std, bool compute_soft_demod) {
	switch(std) {
	case LTE_BPSK:
		q->nbits_x_symbol = 1;
		q->nsymbols = 2;
		if (table_create(q)) {
			return -1;
		}
		set_BPSKtable(q->symbol_table, &q->soft_table, compute_soft_demod);
		break;
	case LTE_QPSK:
		q->nbits_x_symbol = 2;
		q->nsymbols = 4;
		if (table_create(q)) {
			return -1;
		}
		set_QPSKtable(q->symbol_table, &q->soft_table, compute_soft_demod);
		break;
	case LTE_QAM16:
		q->nbits_x_symbol = 4;
		q->nsymbols = 16;
		if (table_create(q)) {
			return -1;
		}
		set_16QAMtable(q->symbol_table, &q->soft_table, compute_soft_demod);
		break;
	case LTE_QAM64:
		q->nbits_x_symbol = 6;
		q->nsymbols = 64;
		if (table_create(q)) {
			return -1;
		}
		set_64QAMtable(q->symbol_table, &q->soft_table, compute_soft_demod);
		break;
	}
	return 0;
}
Пример #21
0
int srslte_modem_table_lte(srslte_modem_table_t* q, srslte_mod_t modulation, bool compute_soft_demod) {
  switch(modulation) {
  case SRSLTE_MOD_BPSK:
    q->nbits_x_symbol = 1;
    q->nsymbols = 2;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_BPSKtable(q->symbol_table, &q->soft_table, compute_soft_demod);
    break;
  case SRSLTE_MOD_QPSK:
    q->nbits_x_symbol = 2;
    q->nsymbols = 4;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_QPSKtable(q->symbol_table, &q->soft_table, compute_soft_demod);
    break;
  case SRSLTE_MOD_16QAM:
    q->nbits_x_symbol = 4;
    q->nsymbols = 16;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_16QAMtable(q->symbol_table, &q->soft_table, compute_soft_demod);
    break;
  case SRSLTE_MOD_64QAM:
    q->nbits_x_symbol = 6;
    q->nsymbols = 64;
    if (table_create(q)) {
      return SRSLTE_ERROR;
    }
    set_64QAMtable(q->symbol_table, &q->soft_table, compute_soft_demod);
    break;
  }
  return SRSLTE_SUCCESS;
}
Пример #22
0
void
test_column_create(gconstpointer data)
{
  const gchar *expected;
  table_create("Blog", 0, NULL, NULL);
  column_create(gcut_data_get_string(data, "table"),
                gcut_data_get_string(data, "name"),
                gcut_data_get_uint(data, "flags"),
                gcut_data_get_string(data, "type_name"),
                gcut_data_get_string(data, "source"));
  expected = gcut_data_get_string(data, "expected");
  cut_assert_equal_string(
    cut_take_printf("table_create Blog TABLE_HASH_KEY\n%s", expected),
    send_command("dump"));
}
Пример #23
0
int 
main (int argc, char *argv[])
{
	gst_init_tool ("services-admin", argc, argv, NULL);
	tool = gst_services_tool_new ();

	gst_dialog_connect_signals (tool->main_dialog, signals);
	table_create ();
	service_settings_table_create ();

	gtk_widget_show (GTK_WIDGET (tool->main_dialog));
	gtk_main ();

	return 0;
}
Пример #24
0
/**
 * Creates new multipart part.
 *
 * @param mpartp
 */
htp_mpart_part_t *htp_mpart_part_create(htp_mpartp_t *mpartp) {
    htp_mpart_part_t * part = calloc(1, sizeof (htp_mpart_part_t));
    if (part == NULL) return NULL;

    part->headers = table_create(4);
    if (part->headers == NULL) {
        free(part);
        return NULL;
    }

    part->mpartp = mpartp;
    part->mpartp->pieces_form_line = 0;    

    bstr_builder_clear(mpartp->part_pieces);

    return part;
}
Пример #25
0
void
test_vector_column(gconstpointer data)
{
  const gchar *expected;
  grn_id id, type_id;
  grn_obj vector;
  grn_obj *elements;
  grn_obj *table, *column;
  const gchar *type_name;
  type_name = gcut_data_get_string(data, "type_name");
  type_id = grn_obj_id(context, get_object(type_name));

  table = table_create("Table", GRN_OBJ_TABLE_NO_KEY, NULL, NULL);
  grn_test_assert_context(context);
  column = column_create("Table", "Column", GRN_OBJ_COLUMN_VECTOR,
                         type_name, NULL);
  grn_test_assert_context(context);
  id = grn_table_add(context, table, NULL, 0, NULL);
  grn_test_assert_context(context);
  cut_assert_equal_int(1, id);
  elements = construct_elements(data);

  GRN_TEXT_INIT(&vector, GRN_OBJ_VECTOR);
  grn_vector_add_element(context, &vector,
                         GRN_TEXT_VALUE(&elements[0]),
                         GRN_TEXT_LEN(&elements[0]), 0, type_id);
  grn_vector_add_element(context, &vector,
                         GRN_TEXT_VALUE(&elements[1]),
                         GRN_TEXT_LEN(&elements[1]), 0, type_id);
  grn_vector_add_element(context, &vector,
                         GRN_TEXT_VALUE(&elements[2]),
                         GRN_TEXT_LEN(&elements[2]), 0, type_id);
  grn_obj_set_value(context, column, id, &vector, GRN_OBJ_SET);

  expected = cut_take_printf("table_create Table TABLE_NO_KEY\n"
                             "column_create Table Column COLUMN_VECTOR %s\n"
                             "load --table Table\n"
                             "[\n"
                             "[\"_id\",\"Column\"],\n"
                             "[1,%s]\n"
                             "]",
                             type_name,
                             gcut_data_get_string(data, "expected"));
  cut_assert_equal_string(expected, send_command("dump"));
  GRN_OBJ_FIN(context, &vector);
}
Пример #26
0
void fake_data()
{
    /* use this to create fake data to test your analysis, before you try real data */
    /* do we get these parameters back out again? */
    double true_m0 = 2.0, true_beta=0.010, true_gph=0.40, true_gdepth=0.00, true_gmoss=0.20; // nb -- no effect of depth
    double phref=7.0, depthref=10.0, mossref=0.0;
    double ph, depth, moss, lambda, count;
    int ii;

    /* create internal table to hold data, and model predictions (written in later) */
    table_create("fakedata");
    table_addcolumn("fakedata","ph");
    table_addcolumn("fakedata","depth");
    table_addcolumn("fakedata","moss");
    table_addcolumn("fakedata","count");

    /* how many data in all? */
    numdata = 999;

    for(ii=0 ; ii<numdata ; ii++)
    {
        /* draw fakedata values for factors: ph, depth, moss */
        depth = random(0.0,20.0);
        ph = 5.0 + 2.0*(depth/20.0) + random(0.0,2.0);

        if(random(0.0,1.0)<0.50)
            moss = 1.0;
        else
            moss = 0.0;

        /* calculte lambda (=average seedling count) for these conditions */
        lambda = true_beta + true_m0*exp( true_gph*(ph-phref) + true_gdepth*(depth-depthref) + true_gmoss*(moss-mossref));
        /* draw fakedata no. of seedlings from poisson with this lambda */
        count = poisson_draw(lambda);

        /* write these values to the data (as if reading real data) */
        table_writevalue("fakedata","moss",ii,moss);
        table_writevalue("fakedata","ph",ii,ph);
        table_writevalue("fakedata","depth",ii,depth);
        table_writevalue("fakedata","count",ii,count);
    }

    table_output("fakedata","./workspace/EgDataz2_seedrain.txt");

    return;
}
Пример #27
0
int main(int argc, char **argv){
  NumberLoads=0;
  NumberStores=0;

  if(argc !=  4){
    printf(" *** Error: Usage %s <instr_file> <num_registers> <map_file>\n",argv[0]);
    return -1;
  }

  initDataStructures();

  readInstructionsFromFile(argv[1]);

  NumberRegisters = atoi(argv[2]);
  if(NumberRegisters <= 0){
	/* DO SOMETHING */
	printf(" Number of Registers: %d\n",NumberRegisters);
	printf(" Number Load Operations: 0\n");
	printf(" Number Store Operations: 0\n");
	return 0;
  }

  readVarMapFromFile(argv[3]);

  /* YOUR CODE HERE */
  printf(" Number of Registers: %d\n", NumberRegisters); // ok

  registers=table_create(NumberRegisters);
  
 // ciclo para usar o checkInstruction() em cada BasicBlock
  checkBasicBlock(Code);
  count_Loads_and_Stores();

  // outputs the result
//  printBasicBlock(Code);
  dumpBasicBlock(Output);


  printf(" Number Load Operations: %d\n", NumberLoads);
  printf(" Number Store Operations: %d\n", NumberStores);

  return 0;
}
Пример #28
0
static void browser_history_button_click(GtkWidget *button, void *(table_create)())
{
	gtk_container_forall(GTK_CONTAINER(browser_table),(GtkCallback)gtk_widget_destroy,NULL);
	table_create();
	GList *hbox_children = gtk_container_get_children(GTK_CONTAINER(browser_scroll_hbox));
	int found = 0;
	while(hbox_children!=NULL)
	{
		if(hbox_children->data == button)
		{
			gtk_widget_destroy(button);	
			found = 1;
		}
		if(found)
			gtk_widget_destroy(GTK_WIDGET(hbox_children->data));
		hbox_children = hbox_children->next;
	}

}
Пример #29
0
void fake_data()
{
	/* use this to create fake data to test your analysis, before you try real data */
	/* do we get these parameters back out again? */
	double true_sigma1 = 9.0;
	double true_mean1 = 37.0;
	double true_sigma2 = 25.0;
	double true_mean2 = 100.0;
	double true_q = 0.80;

	/* how many data in all? */
	int numdata = 99;

	/* create internal table to hold data */
	table_create("fakedata");
	table_addcolumn("fakedata","y");

	for(int ii=0 ; ii<numdata ; ii++)
	{
		/* first, randomly choose normal1, or normal 2 */
		int choice;
		if(random(0.0,1.0)<true_q)
			choice = 1;
		else
			choice = 2;

		/* now draw random value for y from the appropriate normal distribution */
		double y;
		if(choice==1)
			y = normal_draw(true_mean1,true_sigma1);
		if(choice==2)
			y = normal_draw(true_mean2,true_sigma2);

		/* write the y value to the data (as if reading real data) */
		table_writevalue("fakedata","y",ii,y);
	}

	/* output data to use later on */
	table_output("fakedata","./workspace/eg03_mixednormal_fakedata.txt");

	return;
}
Пример #30
0
/*
 * Inicia o skeleton da tabela.
 * O main() do servidor deve chamar este método antes de usar a
 * funço invoke(). O parâmetro n_lists define o número de listas a serem
 * usadas pela tabela mantida no servidor. O parâmetro filename corresponde ao
 * nome a ser usado nos ficheiros de log e checkpoint.
 * Retorna 0 (OK) ou -1 (erro, por exemplo OUT OF MEMORY).
 */
int table_skel_init(int n_lists, char *filename) {

    //verifica a validade dos parâmetros
    if(n_lists <= 0 || filename == NULL) {
        ERROR("table_skel: NULL filename or invalid nlists");
        return -1;
    }

    if(!sharedPtable) {
        //cria e verifica uma nova tabela
        struct table_t *sharedTable;
        if((sharedTable = table_create(n_lists)) == NULL) {
            ERROR("table_skel: table_create");
            return -1;
        }

        //cria e verifica um novo persistence_manager
        struct pmanager_t *sharedPmanager;
        if((sharedPmanager = pmanager_create(filename, MAX_LOG_SIZE, MODE_DSYNC)) == NULL) {
            ERROR("table_skel: pmanager_create");
            table_destroy(sharedTable);
            return -1;
        }

        //cria e verifica um persistent_table
        if((sharedPtable = ptable_open(sharedTable, sharedPmanager)) == NULL) {
            ERROR("table_skel: ptable_open");
            table_destroy(sharedTable);
            pmanager_destroy(sharedPmanager);
            return -1;
        }
		
		// Garbage collection
		ptable_collect_garbage(sharedPtable);
    }

    //em caso de sucesso
    return 0;

}