コード例 #1
0
ファイル: Hash.cpp プロジェクト: Jerrydj/snow
	static Value hash_inspect(const Value& self, const Arguments& args) {
		NORMAL_SCOPE();
		auto hash = object_cast<Hash>(self);
		ASSERT(hash);
		ASSERT_ARGS(args.size == 0);

		// XXX: Convert to Array because it is currently unsafe to iterate through a
		// ValueMap if a GC happens while iterating.
		Handle<Array> keys = hash->keys();
		Handle<Array> values = hash->values();

		std::stringstream ss;
		ss << "hash(";
		size_t len = keys->length();
		for (size_t i = 0; i < len; ++i) {
			ss << value_to_string(snow::call_method((*keys)[i], "inspect"));
			ss << " => ";
			ss << value_to_string(snow::call_method((*values)[i], "inspect"));
			if (i != len-1) {
				ss << ", ";
			}
		}
		ss << ")";
		return gc_new<String>(ss.str());
	}
コード例 #2
0
ファイル: http_dbase.c プロジェクト: NormB/opensips
static int append_values (var_str * q,const char * name, const db_val_t* v,
		int n, int * started )
{
	int i;

	if( v != NULL)
	{
		if( *started )
			CHECK(append_const(q,"&"),0,error);

		CHECK(append_const(q,(char*)name),0,error);
		CHECK(append_const(q,"="),0,error);

		for(i=0;i<n;i++)
		{
			CHECK(append_str(q,url_encode(value_to_string(&v[i]))),0,error);
			if( i < n-1)
				CHECK(append_const(q,val_delim_s),0,error);
		}

		*started = 1;

	}
	return 0;

error:
	return -1;

}
コード例 #3
0
ファイル: libs.c プロジェクト: clarkok/cript
static Value
_lib_sizeof(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);
    Value query_val = hash_find(args, 1);

    if (value_is_string(query_val)) {
        CString *string = value_to_string(query_val);
        return value_from_int(string->length);
    }
    else if (value_is_ptr(query_val)) {
        Hash *hash = value_to_ptr(query_val);
        while (hash->type == HT_REDIRECT) hash = (Hash*)hash->size;
        assert(hash->type != HT_GC_LEFT);

        switch (hash->type) {
            case HT_OBJECT:
            case HT_ARRAY:
                return value_from_int(hash_size(hash));
            case HT_LIGHTFUNC:
            case HT_CLOSURE:
            case HT_USERDATA:
                return value_from_int(-1);
            default: assert(0);
        }
    }

    return value_from_int(-1);
}
コード例 #4
0
ファイル: libs.c プロジェクト: clarkok/cript
static Value
_lib_parse_number(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);
    CString *string = value_to_string(hash_find(args, 1));
    int ret_val;
    sscanf(string->content, "%d", &ret_val);
    return value_from_int(ret_val);
}
コード例 #5
0
ファイル: libs.c プロジェクト: clarkok/cript
static Value
_lib_import(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);
    CString *path = value_to_string(hash_find(args, 1));
    ParseState *state = parse_state_expand_from_file(vm, path->content);
    parse(state);
    Value ret = cvm_state_import_from_parse_state(vm, state);
    parse_state_destroy(state);
    return ret;
}
コード例 #6
0
ファイル: libs.c プロジェクト: clarkok/cript
static Value
_lib_char_code_at(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);
    CString *string = value_to_string(hash_find(args, 1));
    int index = value_to_int(hash_find(args, 2));

    if (index < 0 || index >= string->length) {
        error_f("Out of range when get char_at(%.*s, %d)", string->length, string->content, index);
        return value_undefined();
    }

    return value_from_int(string->content[index]);
}
コード例 #7
0
String yl_data_point::to_string() const
{
	String result("{");
	String key = key_to_string();
	if (key.length())
	{
		result += key;
		result += ",";
	}
	result += "\"value\":";
	result += value_to_string();
	result += "}";

	return result;
}
コード例 #8
0
ファイル: libs.c プロジェクト: clarkok/cript
static Value
_lib_char_at(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);
    CString *string = value_to_string(hash_find(args, 1));
    int index = value_to_int(hash_find(args, 2));

    if (index < 0 || index >= string->length) {
        error_f("Out of range when get char_at(%.*s, %d)", string->length, string->content, index);
        return value_undefined();
    }

    char buffer[2];
    buffer[0] = string->content[index];
    buffer[1] = 0;

    return cvm_get_cstring_value(vm, buffer);
}
コード例 #9
0
ファイル: libs.c プロジェクト: clarkok/cript
static Value
_lib_print(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);

    for (uintptr_t i = 1; i < hash_size(args); ++i) {
        Value val = hash_find(args, i);

        if (value_is_int(val)) {
            printf("%d", value_to_int(val));
        }
        else {
            CString *string = value_to_string(val);
            printf("%.*s", string->length, string->content);
        }
    }

    return value_undefined();
}
コード例 #10
0
ファイル: libs.c プロジェクト: clarkok/cript
static Value
_lib_concat(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);

    char buffer[256],
        *ptr = buffer;

    for (size_t i = 1; i < hash_size(args); ++i) {
        CString *string = value_to_string(hash_find(args, i));
        strncpy(ptr, string->content, 255 - (ptr - buffer));
        ptr += string->length;
        if (ptr - buffer >= 255) {
            ptr = buffer + 255;
            break;
        }
    }

    return value_from_string(string_pool_insert_vec(&vm->string_pool, buffer, ptr - buffer));
}
コード例 #11
0
ファイル: stage_write.c プロジェクト: icedwater/ADIOS
int process_metadata(int step)
{
    int retval = 0;
    int i, j;
    char gdims[256], ldims[256], offs[256];
    uint64_t sum_count;
    ADIOS_VARINFO *v; // shortcut pointer

    if (step > 1)
    {
        // right now, nothing to prepare in later steps
        print("Step %d. return immediately\n",step);
        return 0;
    }

    /* First step processing */

    // get groupname of stream, then declare for output
    adios_get_grouplist(f, &group_namelist);
    print0("Group name is %s\n", group_namelist[0]);
    adios_declare_group(&gh,group_namelist[0],"",adios_flag_yes);


    varinfo = (VarInfo *) malloc (sizeof(VarInfo) * f->nvars);
    if (!varinfo) {
        print("ERROR: rank %d cannot allocate %lu bytes\n", rank, sizeof(VarInfo)*f->nvars);
        return 1;
    }

    write_total = 0;
    largest_block = 0;

    // Decompose each variable and calculate output buffer size
    for (i=0; i<f->nvars; i++) 
    {
        print0 ("Get info on variable %d: %s\n", i, f->var_namelist[i]); 
        varinfo[i].v = adios_inq_var_byid (f, i);
        v = varinfo[i].v; // just a shortcut
        if (v == NULL) {
            print ("rank %d: ERROR: Variable %s inquiry failed: %s\n", 
                   rank, f->var_namelist[i], adios_errmsg());
            return 1;
        }

        // print variable type and dimensions
        print0("    %-9s  %s", adios_type_to_string(v->type), f->var_namelist[i]);
        if (v->ndim > 0) {
            print0("[%llu", v->dims[0]);
            for (j = 1; j < v->ndim; j++)
                print0(", %llu", v->dims[j]);
            print0("] :\n");
        } else {
            print0("\tscalar\n");
        }

        // determine subset we will write
        decompose (numproc, rank, v->ndim, v->dims, decomp_values,
                   varinfo[i].count, varinfo[i].start, &sum_count);
        varinfo[i].writesize = sum_count * adios_type_size(v->type, v->value);

        if (varinfo[i].writesize != 0) {
            write_total += varinfo[i].writesize;
            if (largest_block < varinfo[i].writesize)
                largest_block = varinfo[i].writesize; 
        }

    }

    // determine output buffer size and allocate it
    uint64_t bufsize = write_total + f->nvars*128 + f->nattrs*32 + 1024; 
    if (bufsize > max_write_buffer_size) {
        print ("ERROR: rank %d: write buffer size needs to hold about %llu bytes, "
                "but max is set to %d\n", rank, bufsize, max_write_buffer_size);
        return 1;
    }
    print0 ("Rank %d: allocate %llu MB for output buffer\n", rank, bufsize/1048576+1);
    adios_allocate_buffer (ADIOS_BUFFER_ALLOC_NOW, bufsize/1048576+1); 

    // allocate read buffer
    bufsize = largest_block + 128;
    if (bufsize > max_read_buffer_size) {
        print ("ERROR: rank %d: read buffer size needs to hold at least %llu bytes, "
                "but max is set to %d\n", rank, bufsize, max_read_buffer_size);
        return 1;
    }
    print0 ("Rank %d: allocate %g MB for input buffer\n", rank, (double)bufsize/1048576.0);
    readbuf = (char *) malloc ((size_t)bufsize);
    if (!readbuf) {
        print ("ERROR: rank %d: cannot allocate %llu bytes for read buffer\n",
               rank, bufsize);
        return 1;
    }

    // Select output method
    adios_select_method (gh, wmethodname, wmethodparams, "");

    // Define variables for output based on decomposition
    char *vpath, *vname;
    for (i=0; i<f->nvars; i++) 
    {
        v = varinfo[i].v;
        if (varinfo[i].writesize != 0) {
            // define variable for ADIOS writes
            getbasename (f->var_namelist[i], &vpath, &vname);

            if (v->ndim > 0) 
            {
                int64s_to_str (v->ndim, v->dims, gdims);
                int64s_to_str (v->ndim, varinfo[i].count, ldims);
                int64s_to_str (v->ndim, varinfo[i].start, offs);

                print ("rank %d: Define variable path=\"%s\" name=\"%s\"  "
                       "gdims=%s  ldims=%s  offs=%s\n", 
                       rank, vpath, vname, gdims, ldims, offs);

                adios_define_var (gh, vname, vpath, v->type, ldims, gdims, offs);
            }
            else 
            {
                print ("rank %d: Define scalar path=\"%s\" name=\"%s\"\n",
                       rank, vpath, vname);

                adios_define_var (gh, vname, vpath, v->type, "", "", "");
            }
            free(vpath);
            free(vname);
        }
    }

    if (rank == 0)
    {
        // get and define attributes
        enum ADIOS_DATATYPES attr_type;
        void * attr_value;
        char * attr_value_str;
        int  attr_size;
        for (i=0; i<f->nattrs; i++) 
        {
            adios_get_attr_byid (f, i, &attr_type, &attr_size, &attr_value);
            attr_value_str = (char *)value_to_string (attr_type, attr_value, 0);
            getbasename (f->attr_namelist[i], &vpath, &vname);
            if (vpath && !strcmp(vpath,"/__adios__")) { 
                // skip on /__adios/... attributes 
                print ("rank %d: Ignore this attribute path=\"%s\" name=\"%s\" value=\"%s\"\n",
                        rank, vpath, vname, attr_value_str);
            } else {
                adios_define_attribute (gh, vname, vpath,
                        attr_type, attr_value_str, "");
                print ("rank %d: Define attribute path=\"%s\" name=\"%s\" value=\"%s\"\n",
                        rank, vpath, vname, attr_value_str);
                free (attr_value);
            }
        }
    }

    return retval;
}
コード例 #12
0
ファイル: test.c プロジェクト: xhd0216/zztest
int main(){
	
	printf("ok, it is done\n");
	lru_cache_t * lru;
	hash_map_t * hash_map;
	int res = hash_map_init(&hash_map, &simple_hash_function, &key_cmp_cbf, &key_free_cbf, & key_clone_cbf);
	printf("hash init result: %d\n", res);
	int rest = lru_cache_init(&lru, &simple_hash_function, &key_cmp_cbf, &key_free_cbf, &key_clone_cbf);
	printf("lru init result: %d\n", rest);
	lru_dump(lru, &value_to_string, &key_to_string);
	int i = 1;
	test_key_t key;
	test_value_t value;
	test_value_t * vp;
	int ret = 0;
	while(i){
		printf("0: quit\n1: insert\n2: lookup\n3: delete\nyour choice:");
		scanf("%d", &i);
		switch(i){
		case 1:
			printf("key:");
			scanf("%19s", key.key);
			printf("got key: %s\nvalue:", key.key);
			scanf("%19s", value.value);
			if(value.value[0] == '0') i=0;
			ret = lru_cache_insert(lru, (const void *)(&key), (const void *)(&value), &value_clone_cbf, &value_free_cbf); 
			if(!ret){
				printf("insert (%s, %s) failed", key.key, value.value);
			}
			break;
		case 3:
			ret = lru_delete_auto(lru);
			if(!ret){
				printf("delete failed\n");
			}
			break;
		case 2:
			printf("key:");
			scanf("%19s", key.key);
			ret = lru_cache_get(lru, (const void *) &key, (void **)(&vp));
			if(!ret || !vp){
				printf("key does not exist\n");
			}
			else{
				printf("key=%s, value=%s\n", key_to_string((const void *)&key), value_to_string((const void *)vp));
			}
			break;
		default:
			i = 0;
			break;
		}
		lru_dump(lru, value_to_string, key_to_string);
	}
	printf("quit cache; test hash map");
	i = 1;
	while(i){
		printf("0: quit\n1: insert\n2: lookup\n3: delete\nyour choice:");
		scanf("%d", &i);
		switch(i){
		case 1:
			printf("key:");
			scanf("%19s", key.key);
			printf("got key: %s\nvalue:", key.key);
			scanf("%19s", value.value);
			if(value.value[0] == '0') i=0;
			ret = hash_map_insert(hash_map, (const void *)(&key), (const void *)(&value), &value_clone_cbf, &value_free_cbf); 
			if(!ret){
				printf("insert (%s, %s) failed", key.key, value.value);
			}
			break;
		case 3:
			printf("key:");
			scanf("%19s", key.key);
			ret = hash_map_delete_entry(hash_map, (const void *) &key);
			if(!ret){
				printf("delete failed\n");
			}
			break;
		case 2:
			printf("key:");
			scanf("%19s", key.key);
			ret = hash_map_lookup(hash_map, (const void *) &key, (void **)(&vp));
			if(!ret || !vp){
				printf("key does not exist\n");
			}
			else{
				printf("key=%s, value=%s\n", key_to_string((const void *)&key), value_to_string((const void *)vp));
			}
			break;
		default:
			i = 0;
			break;
		}
		hash_map_dump(hash_map, &key_to_string, &value_to_string);
	}
	hash_map_fini(hash_map);
	printf("quit hash map\n");
	
	return 0;
}
コード例 #13
0
 virtual void print() { cout << get_name() << ": " << value_to_string() << endl; }
コード例 #14
0
ファイル: map.c プロジェクト: Dumbear/ADIOS
int main (int argc, char ** argv) 
{
    int         i, j, k,l;
    MPI_Comm    comm_dummy = 0;  /* MPI_Comm is defined through adios_read.h */

    if (argc < 2) {
        printf("Usage: %s <BP-file>\n", argv[0]);
        return 1;
    }

    adios_read_init_method (ADIOS_READ_METHOD_BP, comm_dummy, "show_hidden_attrs");
    ADIOS_FILE * f;
    f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
    if (f == NULL) {
        printf ("%s\n", adios_errmsg());
        return -1;
    }

    /* For all variables */
    printf("  Variables=%d:\n", f->nvars);
    for (i = 0; i < f->nvars; i++) {
        ADIOS_VARINFO * v = adios_inq_var_byid (f, i);
        adios_inq_var_stat (f, v, 0, 1);
        adios_inq_var_blockinfo (f, v);

        uint64_t total_size = adios_type_size (v->type, v->value);
        for (j = 0; j < v->ndim; j++)
            total_size *= v->dims[j];

        printf("    %-9s  %s", adios_type_to_string(v->type), f->var_namelist[i]);
        if (v->ndim == 0) {
            /* Scalars do not need to be read in, we get it from the metadata
               when using adios_inq_var */
            printf(" = %s\n", value_to_string(v->type, v->value, 0));
        } else {
            /* Arrays, print min/max statistics*/
            printf("[%lld",v->dims[0]);
            for (j = 1; j < v->ndim; j++)
                printf(", %lld",v->dims[j]);
            //printf("] = \n");

            if (v->type == adios_integer)
                printf("] : min=%d  max=%d\n", 
                        (*(int*)v->statistics->min), (*(int*)v->statistics->max));
            else if (v->type == adios_double)
                printf("] : min=%lg  max=%lg\n", 
                        (*(double*)v->statistics->min), (*(double*)v->statistics->max));

            /* Print block info */
            for (l=0; l<v->nsteps; l++) {
                printf("        step %3d: \n", l);
                for (j=0; j<v->nblocks[l]; j++) {
                    printf("          block %3d: [", j);
                    for (k=0; k<v->ndim; k++) {
                        printf("%3lld:%3lld", v->blockinfo[j].start[k],
                                v->blockinfo[j].start[k]+v->blockinfo[j].count[k]-1);
                        if (k<v->ndim-1)
                            printf(", ");
                    }
                    printf("]\n");
                }
            }

        }

        adios_free_varinfo (v);
    } /* variables */

    /* For all attributes */
    printf("  Attributes=%d:\n", f->nattrs);
    for (i = 0; i < f->nattrs; i++) {
        enum ADIOS_DATATYPES atype;
        int  asize;
        void *adata;
        adios_get_attr_byid (f, i, &atype, &asize, &adata);
        printf("    %-9s  %s = %s\n", adios_type_to_string(atype), 
                f->attr_namelist[i], value_to_string(atype, adata, 0));
        free(adata);
    } /* attributes */

    adios_read_close (f);

    return 0;
}
コード例 #15
0
void MainWindow::updateStats(const struct oc_stats *stats, QString dtls)
{
    emit stats_changed_sig(value_to_string(stats->tx_bytes),
                           value_to_string(stats->rx_bytes), dtls);
}
コード例 #16
0
ファイル: ns_cmn_kvp.c プロジェクト: andreiw/polaris
/*
 * ns_set_value() sets the passed in kvp in the passed in printer structure,
 * This is done by converting the value to a string first.
 */
int
ns_set_value(const char *key, const void *value, ns_printer_t *printer)
{
	return (ns_set_value_from_string(key,
			value_to_string(key, (void *)value), printer));
}
コード例 #17
0
ファイル: ns_cmn_kvp.c プロジェクト: andreiw/polaris
/*
 * ns_get_value_string() gets the value of the key passed in from the
 * printer structure passed in.  The results is an ascii string.
 */
char *
ns_get_value_string(const char *key, const ns_printer_t *printer)
{
	return ((char *)value_to_string(key, ns_get_value(key, printer)));
}
コード例 #18
0
ファイル: read_all.c プロジェクト: VisBlank/sirius
int main (int argc, char ** argv) 
{
    int         i, j, k, l, t;
    MPI_Comm    comm_dummy = 0;  /* MPI_Comm is defined through adios_read.h */
    void      * data = NULL;
    uint64_t    start[] = {0,0,0,0,0,0,0,0,0,0};
    uint64_t    count[10];
    ADIOS_SELECTION *sel;

    if (argc < 2) {
        printf("Usage: %s <BP-file>\n", argv[0]);
        return 1;
    }

    ADIOS_FILE * f;
    //int step;
    //for (step=0; step < 2; step++) {
        f = adios_read_open_file (argv[1], ADIOS_READ_METHOD_BP, comm_dummy);
        if (f == NULL) {
            printf ("%s\n", adios_errmsg());
            return -1;
        }

        /* For all variables */
        printf("  Variables=%d:\n", f->nvars);
        for (i = 0; i < f->nvars; i++) {
            ADIOS_VARINFO * v = adios_inq_var_byid (f, i);
            adios_inq_var_stat (f, v, 0, 0);

            uint64_t total_size = adios_type_size (v->type, v->value);
            for (j = 0; j < v->ndim; j++)
                total_size *= v->dims[j];

            printf("    %-9s  %s", adios_type_to_string(v->type), f->var_namelist[i]);
            if (v->ndim == 0) {
                /* Scalars do not need to be read in, we get it from the metadata
                   when using adios_inq_var */
                printf(" = %s\n", value_to_string(v->type, v->value, 0));
            } else {
                /* Arrays have to be read in from the file */
                if (v->nsteps > 1) {
                    printf(" %d*",v->nsteps);
                }
                printf("[%" PRIu64,v->dims[0]);
                for (j = 1; j < v->ndim; j++)
                    printf(", %" PRIu64,v->dims[j]);
                //printf("] = \n");
                
                if (v->type == adios_integer)
                    printf("] = min=%d  max=%d\n", (*(int*)v->statistics->min), (*(int*)v->statistics->max));
                else if (v->type == adios_double)
                    printf("] = min=%lg  max=%lg\n", (*(double*)v->statistics->min), (*(double*)v->statistics->max));
                
                if (total_size > 1024*1024*1024) {
                    printf("        // too big, do not read in\n");
                } else {
                    data = malloc (total_size);
                    if (data == NULL) {
                        fprintf (stderr, "malloc failed.\n");
                        return -1;
                    }

                    for (j = 0; j < v->ndim; j++) 
                        count[j] = v->dims[j];   

                    for (t=0; t<v->nsteps; t++) {
                        sel = adios_selection_boundingbox (v->ndim, start, count);
                        adios_schedule_read_byid (f, sel, i, t, 1, data);
                        adios_perform_reads (f, 1);

                        printf("      Step %d:\n", t);
                        if (adios_errno) {
                            printf ("%s\n", adios_errmsg());
                        } else if (total_size > 1024*1024) {
                            printf ("Too big to print\n");
                        } else if (v->ndim == 1) {
                            printf ("        [");
                            for (j = 0; j < v->dims[0]; j++) 
                                printf("%s ", value_to_string(v->type, data, j));
                            printf ("]\n");
                        } else if (v->ndim == 2) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("        row %d: [", j);
                                for (k = 0; k < v->dims[1]; k++) 
                                    printf("%s ", value_to_string(v->type, data, j*v->dims[1] + k));
                                printf ("]\n");
                            }
                        } else if (v->ndim == 3) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("      block %d: \n", j);
                                for (k = 0; k < v->dims[1]; k++) {
                                    printf ("        row %d: [", k);
                                    for (l = 0; l < v->dims[2]; l++) {
                                        // NCSU ALACRITY-ADIOS - Fixed bug, k*v->dims[1] changed to  k*v->dims[2]
                                        printf("%s ", value_to_string(v->type, data, j*v->dims[1]*v->dims[2] + k*v->dims[2] + l));
                                    }
                                    printf ("]\n");
                                }
                                printf ("\n");
                            }
                        } else {
                            printf ("    cannot print arrays with >3 dimensions\n");
                        }
                    }
                    free (data);
                }
            }

            adios_free_varinfo (v);
        } /* variables */

        /* For all attributes */
        printf("  Attributes=%d:\n", f->nattrs);
        for (i = 0; i < f->nattrs; i++) {
            enum ADIOS_DATATYPES atype;
            int  asize;
            void *adata;
            adios_get_attr_byid (f, i, &atype, &asize, &adata);
            int type_size = adios_type_size (atype, adata);
            int nelems = asize / type_size;
            printf("    %-9s  %s = ", adios_type_to_string(atype), f->attr_namelist[i]);
            char *p = (char*)adata;
            if (nelems>1) printf("{");
            for (j=0; j<nelems; j++) {
                if (j>0) printf(", ");
                printf ("%s", value_to_string(atype, p, 0));
                p += type_size;
            }
            if (nelems>1) printf("}");
            printf("\n");
            free(adata);
        } /* attributes */

        adios_read_close (f);

    //} /* loop 'step' */
    return 0;
}
コード例 #19
0
ファイル: read_all_v1.c プロジェクト: VisBlank/sirius
int main (int argc, char ** argv) 
{
    int         gidx, i, j, k,l;
    MPI_Comm    comm_dummy = 0;  /* MPI_Comm is defined through adios_read.h */
    void      * data = NULL;
    uint64_t    start[] = {0,0,0,0,0,0,0,0,0,0};
    uint64_t    count[10];
    int64_t     bytes_read = 0;

    if (argc < 2) {
        printf("Usage: %s <BP-file>\n", argv[0]);
        return 1;
    }

    ADIOS_FILE * f;
    //int step;
    //for (step=0; step < 2; step++) {
        f = adios_fopen (argv[1], comm_dummy);
        if (f == NULL) {
            printf ("%s\n", adios_errmsg());
            return -1;
        }

        /* For all groups */
        for (gidx = 0; gidx < f->groups_count; gidx++) {
            printf("Group %s:\n", f->group_namelist[gidx]);
            ADIOS_GROUP * g = adios_gopen (f, f->group_namelist[gidx]);
            if (g == NULL) {
                printf ("%s\n", adios_errmsg());
                return -1;
            }

            /* For all variables */
            printf("  Variables=%d:\n", g->vars_count);
            for (i = 0; i < g->vars_count; i++) {
                ADIOS_VARINFO * v = adios_inq_var_byid (g, i);

                uint64_t total_size = adios_type_size (v->type, v->value);
                for (j = 0; j < v->ndim; j++)
                    total_size *= v->dims[j];

                printf("    %-9s  %s", adios_type_to_string(v->type), g->var_namelist[i]);
                if (v->ndim == 0) {
                    /* Scalars do not need to be read in, we get it from the metadata
                       when using adios_inq_var */
                    printf(" = %s\n", value_to_string(v->type, v->value, 0));
                } else {
                    /* Arrays have to be read in from the file */
                    printf("[%" PRIu64,v->dims[0]);
                    for (j = 1; j < v->ndim; j++)
                        printf(", %" PRIu64,v->dims[j]);
                    //printf("] = \n");
                    if (v->type == adios_integer)
                        printf("] = min=%d  max=%d  timedim=%d\n", (*(int*)v->gmin), (*(int*)v->gmax), v->timedim);
                    else if (v->type == adios_double)
                        printf("] = min=%lg  max=%lg  timedim=%d\n", (*(double*)v->gmin), (*(double*)v->gmax), v->timedim);
                    if (total_size > 1024*1024*1024) {
                        printf("        // too big, do not read in\n");
                    } else {
                        data = malloc (total_size);
                        if (data == NULL) {
                            fprintf (stderr, "malloc failed.\n");
                            return -1;
                        }

                        for (j = 0; j < v->ndim; j++) 
                            count[j] = v->dims[j];   

                        bytes_read = adios_read_var_byid (g, i, start, count, data);

                        if (bytes_read < 0) {
                            printf ("%s\n", adios_errmsg());
                        } else if (bytes_read > 1024*1024) {
                            printf ("Too big to print\n");
                        } else if (v->ndim == 1) {
                            printf ("        [");
                            for (j = 0; j < v->dims[0]; j++) 
                                printf("%s ", value_to_string(v->type, data, j));
                            printf ("]\n");
                        } else if (v->ndim == 2) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("        row %d: [", j);
                                for (k = 0; k < v->dims[1]; k++) 
                                    printf("%s ", value_to_string(v->type, data, j*v->dims[1] + k));
                                printf ("]\n");
                            }
                        } else if (v->ndim == 3) {
                            for (j = 0; j < v->dims[0]; j++) {
                                printf ("      block %d: \n", j);
                                for (k = 0; k < v->dims[1]; k++) {
                                    printf ("        row %d: [", k);
                                    for (l = 0; l < v->dims[2]; l++) {
                                        printf("%s ", value_to_string(v->type, data, j*v->dims[1]*v->dims[2] + k*v->dims[1] + l));
                                    }
                                    printf ("]\n");
                                }
                                printf ("\n");
                            }
                        } else {
                            printf ("    cannot print arrays with >3 dimensions\n");
                        }
                        free (data);
                    }
                }

                adios_free_varinfo (v);
            } /* variables */

            /* For all attributes */
            printf("  Attributes=%d:\n", g->attrs_count);
            for (i = 0; i < g->attrs_count; i++) {
                enum ADIOS_DATATYPES atype;
                int  asize;
                void *adata;
                adios_get_attr_byid (g, i, &atype, &asize, &adata);
                printf("    %-9s  %s = %s\n", adios_type_to_string(atype), 
                        g->attr_namelist[i], value_to_string(atype, adata, 0));
                free(adata);
            } /* attributes */

            adios_gclose (g);
        } /* groups */

        adios_fclose (f);

    //} /* loop 'step' */
    return 0;
}
コード例 #20
0
void MemoryViewWidget::Update()
{
  clearSelection();

  setColumnCount(3 + GetColumnCount(m_type));

  if (rowCount() == 0)
    setRowCount(1);

  setRowHeight(0, 24);

  // Calculate (roughly) how many rows will fit in our table
  int rows = std::round((height() / static_cast<float>(rowHeight(0))) - 0.25);

  setRowCount(rows);

  for (int i = 0; i < rows; i++)
  {
    setRowHeight(i, 24);

    u32 addr = m_address - ((rowCount() / 2) * 16) + i * 16;

    auto* bp_item = new QTableWidgetItem;
    bp_item->setFlags(Qt::ItemIsEnabled);
    bp_item->setData(Qt::UserRole, addr);

    setItem(i, 0, bp_item);

    auto* addr_item = new QTableWidgetItem(QStringLiteral("%1").arg(addr, 8, 16, QLatin1Char('0')));

    addr_item->setData(Qt::UserRole, addr);
    addr_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);

    setItem(i, 1, addr_item);

    if (addr == m_address)
      addr_item->setSelected(true);

    if (Core::GetState() != Core::State::Paused || !PowerPC::HostIsRAMAddress(addr))
    {
      for (int c = 2; c < columnCount(); c++)
      {
        auto* item = new QTableWidgetItem(QStringLiteral("-"));
        item->setFlags(Qt::ItemIsEnabled);
        item->setData(Qt::UserRole, addr);

        setItem(i, c, item);
      }

      continue;
    }

    auto* description_item =
        new QTableWidgetItem(QString::fromStdString(PowerPC::debug_interface.GetDescription(addr)));

    description_item->setForeground(Qt::blue);
    description_item->setFlags(Qt::ItemIsEnabled);

    setItem(i, columnCount() - 1, description_item);

    bool row_breakpoint = true;

    auto update_values = [&](auto value_to_string) {
      for (int c = 0; c < GetColumnCount(m_type); c++)
      {
        auto* hex_item = new QTableWidgetItem;
        hex_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
        const u32 address = addr + c * (16 / GetColumnCount(m_type));

        if (PowerPC::memchecks.OverlapsMemcheck(address, 16 / GetColumnCount(m_type)))
          hex_item->setBackground(Qt::red);
        else
          row_breakpoint = false;

        setItem(i, 2 + c, hex_item);

        if (PowerPC::HostIsRAMAddress(address))
        {
          hex_item->setText(value_to_string(address));
          hex_item->setData(Qt::UserRole, address);
        }
        else
        {
          hex_item->setFlags(0);
          hex_item->setText(QStringLiteral("-"));
        }
      }
    };

    switch (m_type)
    {
    case Type::U8:
      update_values([](u32 address) {
        const u8 value = PowerPC::HostRead_U8(address);
        return QStringLiteral("%1").arg(value, 2, 16, QLatin1Char('0'));
      });
      break;
    case Type::ASCII:
      update_values([](u32 address) {
        const char value = PowerPC::HostRead_U8(address);
        return std::isprint(value) ? QString{QChar::fromLatin1(value)} : QStringLiteral(".");
      });
      break;
    case Type::U16:
      update_values([](u32 address) {
        const u16 value = PowerPC::HostRead_U16(address);
        return QStringLiteral("%1").arg(value, 4, 16, QLatin1Char('0'));
      });
      break;
    case Type::U32:
      update_values([](u32 address) {
        const u32 value = PowerPC::HostRead_U32(address);
        return QStringLiteral("%1").arg(value, 8, 16, QLatin1Char('0'));
      });
      break;
    case Type::Float32:
      update_values([](u32 address) { return QString::number(PowerPC::HostRead_F32(address)); });
      break;
    }

    if (row_breakpoint)
    {
      bp_item->setData(Qt::DecorationRole,
                       Resources::GetScaledThemeIcon("debugger_breakpoint").pixmap(QSize(24, 24)));
    }
  }

  setColumnWidth(0, 24 + 5);
  for (int i = 1; i < columnCount(); i++)
  {
    resizeColumnToContents(i);
    // Add some extra spacing because the default width is too small in most cases
    setColumnWidth(i, columnWidth(i) * 1.1);
  }

  viewport()->update();
  update();
}
コード例 #21
0
ファイル: easing_edit.cpp プロジェクト: LibreGames/bear
/**
 * \brief Method called when the value has been changed, to update the display.
 */
void bf::easing_edit::value_updated()
{
  SetValue( value_to_string() );
} // easing_edit::value_updated()
コード例 #22
0
ファイル: ns_cmn_kvp.c プロジェクト: andreiw/polaris
/*
 * FUNCTION:
 *	ns_r_get_value(const char *key, const ns_printer_t *printer)
 * INPUT(S):
 *	const char *key
 *		- key for matching
 *	const ns_printer_t *printer
 *		- printer to glean this from
 * OUTPUT(S):
 *	char * (return value)
 *		- NULL, if not matched
 * DESCRIPTION:
 */
static void *
ns_r_get_value(const char *key, const ns_printer_t *printer, int level)
{
	ns_kvp_t *kvp, **attrs;

	if ((key == NULL) || (printer == NULL) ||
	    (printer->attributes == NULL))
		return (NULL);

	if (level++ == 16)
		return (NULL);

	/* find it right here */
	if ((kvp = list_locate((void **)printer->attributes,
			(COMP_T)ns_kvp_match_key, (void *)key)) != NULL) {
		void *value = string_to_value(key, kvp->value);

		/* fill in an empty printer for a bsdaddr */
		if (strcmp(key, NS_KEY_BSDADDR) == 0) {
			ns_bsd_addr_t *addr = value;

			if (addr->printer == NULL)
				addr->printer = strdup(printer->name);
		}
		return (value);
	}

	/* find it in a child */
	for (attrs = printer->attributes; attrs != NULL && *attrs != NULL;
	    attrs++) {
		void *value = NULL;

		if ((strcmp((*attrs)->key, NS_KEY_ALL) == 0) ||
		    (strcmp((*attrs)->key, NS_KEY_GROUP) == 0)) {
			char **printers;

			for (printers = string_to_value((*attrs)->key,
						(*attrs)->value);
			    printers != NULL && *printers != NULL; printers++) {
				ns_printer_t *printer =
					ns_printer_get_name(*printers, NULL);

				if ((value = ns_r_get_value(key, printer,
							    level)) != NULL)
					return (value);
				ns_printer_destroy(printer);
			}
		} else if (strcmp((*attrs)->key, NS_KEY_LIST) == 0) {
			ns_printer_t **printers;

			for (printers = string_to_value((*attrs)->key,
						(*attrs)->value);
			    printers != NULL && *printers != NULL; printers++) {
				if ((value = ns_r_get_value(key, *printers,
							    level)) != NULL)
					return (value);
			}
		} else if (strcmp((*attrs)->key, NS_KEY_USE) == 0) {
			char *string = NULL;
			ns_printer_t *printer =
				ns_printer_get_name((*attrs)->value, NULL);
			if ((value = ns_r_get_value(key, printer,
					level)) != NULL)
				string = value_to_string(string, value);
			if (string != NULL)
				value = string_to_value(key, string);
			ns_printer_destroy(printer);
		}

		if (value != NULL)
			return (value);
	}

	return (NULL);
}
コード例 #23
0
ファイル: bp2h5.c プロジェクト: Dumbear/ADIOS
int main (int argc, char ** argv)  
{
    char        filename [256]; 
    int         rank, size, gidx, i, j, k,l;
    MPI_Comm    comm_dummy = MPI_COMM_WORLD;  /* MPI_Comm is defined through adios_read.h */
    enum ADIOS_DATATYPES attr_type;
    void      * data = NULL;
    uint64_t    start[] = {0,0,0,0,0,0,0,0,0,0};
    uint64_t    count[MAX_DIMS], hcount[MAX_DIMS], bytes_read = 0;
    herr_t      h5_err;
    char        h5name[256],aname[256],fname[256];
    int         dims [MAX_DIMS];
    int         h5rank[MAX_DIMS];
    int         h5i, level;
    hid_t       grp_id [GMAX+1], space_id, dataset_id;
    hid_t       memspace_id, dataspace_id, att_id;
    char        ** grp_name;
    hid_t       type_id;
    hid_t       h5_type_id;
    hsize_t     adims;

    if (argc < 2) {
        printf("Usage: %s <BP-file> <HDF5-file>\n", argv[0]);
        return 1;
    }

    MPI_Init(&argc, &argv);
    h5_err = H5Eset_auto(NULL, NULL );
    ADIOS_FILE * f = adios_fopen (argv[1], comm_dummy);
    HDF5_FILE = H5Fcreate(argv[2],H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /* create the complex types for HDF5 */
    complex_real_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_real_t));
    H5Tinsert (complex_real_id, "real", HOFFSET(complex_real_t,re), H5T_NATIVE_FLOAT);
    H5Tinsert (complex_real_id, "imaginary", HOFFSET(complex_real_t,im), H5T_NATIVE_FLOAT);

    complex_double_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_double_t));
    H5Tinsert (complex_double_id, "real", HOFFSET(complex_double_t,re), H5T_NATIVE_DOUBLE);
    H5Tinsert (complex_double_id, "imaginary", HOFFSET(complex_double_t,im), H5T_NATIVE_DOUBLE);

    if (f == NULL) {
        if (DEBUG) printf ("%s\n", adios_errmsg());
	return -1;
    }
    /* For all groups */
    for (gidx = 0; gidx < f->groups_count; gidx++) {
        if (DEBUG) printf("Group %s:\n", f->group_namelist[gidx]);
        ADIOS_GROUP * g = adios_gopen (f, f->group_namelist[gidx]);
        if (g == NULL) {
            if (DEBUG) printf ("%s\n", adios_errmsg());
            return -1;
        }
/* First create all of the groups */
        grp_id [0] = HDF5_FILE;
        for (i = 0; i < g->vars_count; i++) {
             ADIOS_VARINFO * v = adios_inq_var_byid (g, i);
             strcpy(h5name,g->var_namelist[i]);
             grp_name = bp_dirparser (h5name, &level);
             for (j = 0; j < level-1; j++) {
                grp_id [j + 1] = H5Gopen (grp_id [j], grp_name [j]);
                if (grp_id [j + 1] < 0) {
                   grp_id [j + 1] = H5Gcreate (grp_id [j], grp_name [j], 0);
                }
             }
             for (j=1; j<level; j++) {
                  H5Gclose(grp_id[j]);
             }
        }
/* Now we can write data into these scalars */        
        /* For all variables */
        if (DEBUG) printf("  Variables=%d:\n", g->vars_count);
        for (i = 0; i < g->vars_count; i++) {
             ADIOS_VARINFO * v = adios_inq_var_byid (g, i);

            uint64_t total_size = adios_type_size (v->type, v->value);
            for (j = 0; j < v->ndim; j++)
                total_size *= v->dims[j];
            strcpy(h5name,g->var_namelist[i]);
            if (DEBUG) printf("    %-9s  %s", adios_type_to_string(v->type), g->var_namelist[i]);
            h5_err = bp_getH5TypeId (v->type, &h5_type_id);
            if (v->type==adios_string) H5Tset_size(h5_type_id,strlen(v->value)); 
            if (v->ndim == 0) {
                /* Scalars do not need to be read in, we get it from the metadata
                   when using adios_inq_var */
                if (DEBUG) printf(" = %s\n", value_to_string(v->type, v->value, 0));
                 // add the hdf5 dataset, these are scalars
                for (h5i = 0;h5i<MAX_DIMS;h5i++) 
                   count[0] = 0;
                count[0] = 1; // we are writing just 1 element, RANK=1
                h5_err = bp_getH5TypeId (v->type, &h5_type_id);
                H5LTmake_dataset(HDF5_FILE,h5name,1,count,h5_type_id,v->value);
            } else {

                    h5_err = readVar(g, v,  h5name);
            }
            adios_free_varinfo (v);
        } /* variables */

        /* For all attributes */
        if (DEBUG) printf("  Attributes=%d:\n", g->attrs_count);
        for (i = 0; i < g->attrs_count; i++) {
            enum ADIOS_DATATYPES atype;
            int  asize;
	    void *adata;
            adios_get_attr_byid (g, i, &atype, &asize, &adata);
            grp_name = bp_dirparser (g->attr_namelist[i], &level);
            strcpy(aname,grp_name[level-1]); 
// the name of the attribute is the last in the array
// we then need to concat the rest together
            strcpy(fname,"/");
            for (j=0;j<level-1;j++) {
              strcat(fname,grp_name[j]); 
            }
            h5_err = bp_getH5TypeId (atype, &h5_type_id);

            // let's create the attribute
            adims = 1;
            if (atype==adios_string) H5Tset_size(h5_type_id,strlen(adata)); 
            space_id = H5Screate(H5S_SCALAR); // just a scalar
            att_id = H5Acreate(HDF5_FILE, g->attr_namelist[i], h5_type_id, space_id,H5P_DEFAULT);
            h5_err = H5Awrite(att_id, h5_type_id, adata);
            h5_err = H5Aclose(att_id);
            h5_err = H5Sclose(space_id);

            if (DEBUG) printf("    %-9s  %s = %s\n", adios_type_to_string(atype), 
                    g->attr_namelist[i], value_to_string(atype, adata, 0));
            free(adata);
        } /* attributes */

        adios_gclose (g);
    } /* groups */

    adios_fclose (f);
    h5_err =  H5Fclose(HDF5_FILE);

    MPI_Finalize();
    return 0;
}