Beispiel #1
0
void test21(void) {
	RowNode_handle pR=0; 
	int i,j=0;
	printf("\n== OVERWRITE ENTIRE ROW 9 WITH ZEROES ==\n");

	for(i=0;i<10;++i) {
		for(j=0;j<10;++j) {
			insert_element2(&pR,i,j,(i+j)%3);
		}
	}
	printf_rows(pR,"%i",10); printf("\n");

	insert_element2(&pR,3*i,3*j,(3*i+2*j)%5);

	insert_element2(&pR,9,0,0);
	insert_element2(&pR,9,1,0);
	insert_element2(&pR,9,2,0);
	insert_element2(&pR,9,3,0);
	insert_element2(&pR,9,4,0);
	insert_element2(&pR,9,5,0);
	insert_element2(&pR,9,6,0);
	insert_element2(&pR,9,7,0);
	insert_element2(&pR,9,8,0);
	insert_element2(&pR,9,9,0);

	printf_rows(pR,"%i",10); printf("\n");
	print_rows(pR);
	printf("\n");
	free_rows(pR);
}
Beispiel #2
0
void test18(void) {
  RowNode_handle pR=0; 
  int i,j;
  printf("\n== INSERT ELEMENTS IN ROW LIST (WITH ZEROES AND OVERWRITES) ==\n");

  for(i=0;i<30;++i) {
    for(j=0;j<30;++j) {
      insert_element2(&pR,i,j,(i+j)%2);
    }
  }
  printf_rows(pR,"%i",30); printf("\n");
  /* overwrite some */
  for(i=0;i<10;++i) {
    for(j=0;j<10;++j) {
      insert_element2(&pR,3*i,3*j,(3*i+2*j)%5);
    }
  }
  /* overwrite with 0 */
  for(i=0;i<30;++i) {
    for(j=0;j<30;++j) {
      if ((i+j)%8==0) insert_element2(&pR,i,j,0);
    }
  }
  printf_rows(pR,"%i",30); printf("\n");
  print_rows(pR);
  printf("\n");
  free_rows(pR);
}
void test22( void )
{
    RowNode * pR=0, *pR2;
    int i,j;
    printf( "\n===== TRANSPOSITION ========================\n" );
    for( i=0; i<10; ++i ) {
        for( j=0; j<10; ++j ) {
            if( ( i+j )%4 ) insert_element2( &pR,1000*i,1000*j,10*i+j );
        }
    }
    pR2 = transpose( pR );
    printf( "original as list of rows\n" );
    print_rows( pR );
    printf( "\n" );
    printf( "transposed as list of rows\n" );
    print_rows( pR2 );
    printf( "\n" );
    free_rows( pR );
    free_rows( pR2 );
}
Beispiel #4
0
void test17(void) {
  RowNode_handle pR=0; 
  int i,j;
  printf("\n====== INSERT ELEMENTS IN ROW LIST (WITH ZEROES) ===\n");

  for(i=0;i<30;++i) {
    for(j=0;j<30;++j) {
      insert_element2(&pR,i,j,(i+j)%2);
    }
  }
  printf_rows(pR,"%i",30); printf("\n");
  print_rows(pR); printf("\n");
  free_rows(pR);
}
Beispiel #5
0
void test16(void) {
  RowNode_handle pR=0; 
  int i,j;
  printf("\n====== INSERT ELEMENTS IN ROW LIST =========\n");

  for(i=0;i<15;++i) {
    for(j=0;j<10;++j) {
      insert_element2(&pR,2*i,3*j,1+7*( (i+j)%2) );
    }
  }
  printf_rows(pR,"%i",30);
  printf("\n");
  print_rows(pR);
  free_rows(pR);
}
Beispiel #6
0
int main(int argc, char *argv[]){
    MYSQL *connect;
    SQL_ROW_DATA row_data;
    MYSQL_CONNECT_CONF conConf = {
        "xxx.xxx.xxx.xxx",
        "user",
        "pwd",
        "db",
        3306,
        NULL,
        0,
        "utf8"
    };
    
    connect = get_connect(conConf);
    row_data = execute_sql(connect, "SELECT *  FROM tb LIMIT 1000 ");
    if(row_data.row_num > 0){
        printf("-----------has rows-----------\n");

        // 输出第一条
        /*
        if( (row_data.rows[0].cols[3].name) && (row_data.rows[0].cols[3].data) ){
            fprintf(stderr, "[*] \t%s = %s\n", row_data.rows[0].cols[3].name, row_data.rows[0].cols[3].data);
        }
        */

        // 全部输出
        print_rows(row_data);

    }else{
        printf("---------------no rows-------------\n");
    }
    free_data_rows(row_data);
    mysql_close(connect);

    return 0;
}
int main(int argc, const char * argv[])
{
    if (argc != 3) {
        printf("\nUsage: %s <combined.disco (input)> <merged.disco (output)>\n\n", argv[0]);
	printf("I require files as arguments, but commonly they are called combined.disco and merged.disco.\n");
        return 1;
    }
    // argv[1] is the input filename
    // argv[2] is the output filename
    long nlines = file_numrows(argv[1]);
    printf("Number of rows: %ld\n", nlines);
    
    row *rows = (row *)malloc(nlines * sizeof(row));
    
    if(file_to_rows(argv[1], rows, nlines) == nlines)
    {
        do_merge(rows, nlines);
    }
    
    print_rows(rows, nlines, argv[2]);
    
    free(rows);
    return 0;
}
Beispiel #8
0
int main( int argc, char *argv[] )
{

	xmlrpc_env env;
	xmlrpc_value * resultP;
	xmlrpc_value * keyP;
	xmlrpc_value * valueP;
	int struct_size;
	int i, j;
	size_t length;
	const char * str_key_value;
	xmlrpc_int   int_key_value;
	unsigned int max_hits = 0;
	unsigned int rows = 0;
	int rv;
	char *uri;
	int options;		/* what kind of nodes should be processed */
	int uri_pos;		/* position of first non option argument */
	char stropts[16];
	int  pos = 0;
	int  mask_length = 32;	/* 32 means NO aggregate */

	if (argc-1 < 1) {
		print_help();
		exit(0);
	}
	uri_pos = process_options(argc, argv, &options, &mask_length);
	switch (options) {
		case OPT_HOT:
				sprintf(stropts, "HOT");
				break;
		case OPT_ALL:
				sprintf(stropts, "ALL");
				break;
		case OPT_WARM:
				sprintf(stropts, "WARM");
				break;
	}
	printf("Nodes = %s\n", stropts);
	printf("Mask  = /%d\n", mask_length);

	/* Start up our XML-RPC client library. */
	xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION);
	
	/* Initialize our error-handling environment. */
	xmlrpc_env_init(&env);

	/* prototype:
	   xmlrpc_value * xmlrpc_client_call(xmlrpc_env * const envP,
	                                     const char * const server_url, const char * const method_name,
	                                     const char * const format, ...);
	 */
	asprintf(&uri, "http://%s/RPC2", argv[uri_pos]);
	resultP = xmlrpc_client_call(&env, uri,
	                             "pike.top",
	                             "(s)", stropts);
	free(uri);
	die_if_fault_occurred_line(&env, __LINE__);
	
	/* parse returned structure */
	if ( xmlrpc_value_type(resultP) != XMLRPC_TYPE_STRUCT ) {
		printf("unexpected result - should be structure\n");
		xmlrpc_env_clean(&env);
		xmlrpc_client_cleanup();
		exit(1);
	}

	struct_size = xmlrpc_struct_size(&env, resultP);
	die_if_fault_occurred_line(&env, __LINE__);
//	printf("Struct size: %d\n", struct_size);

	if ( ! get_int_from_struct_by_name(resultP, MAX_HITS, &max_hits) ) {
		fprintf(stderr, "ERROR: %s not foung in result\n", MAX_HITS);
		exit (1);
	}
	printf("max_hits = %d\n", max_hits);
	if ( ! get_int_from_struct_by_name(resultP, NUMBER_OF_ROWS, &rows) ) {
		fprintf(stderr, "ERROR: %s not foung in result\n", NUMBER_OF_ROWS);
		exit (1);
	}
	printf("rows = %d\n", rows);
	TopItem top_items[rows];
	TopItem *item;			/* tmp item ptr */
	TopItem *result_items = top_items;	/* if no aggregation use this */
	memset(top_items, 0, sizeof(top_items));

	/* aggregated values */
	
	if ( rows == 0 )
		return 0;
	
	for ( i = 0, item = top_items; i < rows; ++i, ++item ) {
		if ( ! read_row(resultP, i, item) ) {
			fprintf(stderr, "ERROR: while reading row number %d\n", i);
		}
		/* fill in ipv4 addr */
//		printf("item[%d].ip_addr = %s, len = %d\n", i, item->ip_addr, strlen(item->ip_addr));
		rv = inet_pton(AF_INET, item->ip_addr, &item->ipv4_addr);
		if ( rv > 0 ) {
//			printf("IPv4 addr: %x\n", item->ipv4_addr);
		} else {
			fprintf(stderr, "IP conversion failed - not an IPv4 address: '%s'\n", item->ip_addr);	/* conversion failed from any reason */
			printf("item[%d].ipv4_addr = %x\n", i, item->ipv4_addr);
		}
			
	}

	assert( rows > 0 );
	/* if IP mask length is shorter than 32 then aggregate list according to the mask */
	if ( mask_length < 32 ) {
		uint32_t ip_mask = htonl(mask(mask_length));
		
		qsort(top_items, rows, sizeof(TopItem), compare_TopItem_ipv4_addr);		/* sort by IPv4 */

		/* skip items without ipv4 address */
		i = 0;	/* index of non aggregated items */
		while (!top_items[i].ipv4_addr && i < rows ) {
			printf("Skip item[%d] - do not has IPv4 address: %s\n", i, top_items[i].ip_addr);
			memset(&top_items[i], 0, sizeof(TopItem));
			++i;
		}

		j = 0;	/* index of aggregated items */
		if ( i == 0 )
			++i;
		
		top_items[0].ipv4_addr &= ip_mask;
		top_items[0].num_of_ips = 1;
		inet_ntop(AF_INET, &top_items[0].ipv4_addr, top_items[0].ip_addr, sizeof(top_items[0].ip_addr));
		while ( i < rows ) {
			top_items[i].ipv4_addr &= ip_mask;
			
			if ( top_items[j].ipv4_addr == top_items[i].ipv4_addr ) {
				top_items[j].leaf_hits[0] += top_items[i].leaf_hits[0];
				top_items[j].leaf_hits[1] += top_items[i].leaf_hits[1];
				++(top_items[j].num_of_ips);
				++i;
			}
			else {
				++j;
				top_items[j] = top_items[i];
				top_items[j].num_of_ips = 1;
				inet_ntop(AF_INET, &top_items[j].ipv4_addr, top_items[j].ip_addr, sizeof(top_items[j].ip_addr));
				++i;
			}
		}
		rows = j + 1;
	}

	qsort(top_items, rows, sizeof(TopItem), compare_TopItem_hits_reverse);

	print_rows( top_items, rows, mask_length );

	/* Dispose of our result value. */
	xmlrpc_DECREF(resultP);

	/* Clean up our error-handling environment. */
	xmlrpc_env_clean(&env);
	/* Shutdown our XML-RPC client library. */
	xmlrpc_client_cleanup();

	return 0;
}
Beispiel #9
0
void
demo(
    const std::string& host,
    bool               use_ssl)
{
    try
    {
		boost::shared_ptr<cql::cql_builder_t> builder = cql::cql_cluster_t::builder();
		builder->with_log_callback(&log_callback);
        builder->add_contact_point(boost::asio::ip::address::from_string(host));

		if (use_ssl) {
			builder->with_ssl();
		}

		boost::shared_ptr<cql::cql_cluster_t> cluster(builder->build());
		boost::shared_ptr<cql::cql_session_t> session(cluster->connect());

		if (session) {

            // write a query that switches current keyspace to "system"
            boost::shared_ptr<cql::cql_query_t> use_system(
                new cql::cql_query_t("USE system;", cql::CQL_CONSISTENCY_ONE));

            // send the query to Cassandra
            boost::shared_future<cql::cql_future_result_t> future = session->query(use_system);

            // wait for the query to execute
            future.wait();

            // check whether the query succeeded
            std::cout << "switch keyspace successful? " << (!future.get().error.is_err() ? "true" : "false") << std::endl;

            // execute a query, select all rows from the keyspace
            boost::shared_ptr<cql::cql_query_t> select(
                new cql::cql_query_t("SELECT * from schema_keyspaces;", cql::CQL_CONSISTENCY_ONE));
            future = session->query(select);

            // wait for the query to execute
            future.wait();

            // check whether the query succeeded
            std::cout << "select successful? " << (!future.get().error.is_err() ? "true" : "false") << std::endl;
            if (future.get().result) {
                // print the rows return by the successful query
                print_rows(*future.get().result);
            }

            // now a small demonstration on the usage of prepared statements:
            boost::shared_ptr<cql::cql_query_t> unbound_select(
                new cql::cql_query_t("SELECT * FROM schema_keyspaces WHERE keyspace_name=?;", cql::CQL_CONSISTENCY_ONE));
            
            // compile the parametrized query on the server
            future = session->prepare(unbound_select);
            future.wait();
            std::cout << "prepare successful? " << (!future.get().error.is_err() ? "true" : "false") << std::endl;
            
            // read the hash (ID) returned by Cassandra as identificator of prepared query
            std::vector<cql::cql_byte_t> queryid = future.get().result->query_id();
            
            boost::shared_ptr<cql::cql_execute_t> bound(
                new cql::cql_execute_t(queryid, cql::CQL_CONSISTENCY_ONE));
            
            // bind the query with concrete parameter: "system_auth"
            bound->push_back("system_auth");

            // send the concrete (bound) query
            future = session->execute(bound);
            future.wait();
            std::cout << "execute successful? " << (!future.get().error.is_err() ? "true" : "false") << std::endl;
            if (future.get().result) {
                print_rows(*future.get().result);
            }
            
            // close the connection session
            session->close();
		}

		cluster->shutdown();
        std::cout << "THE END" << std::endl;
    }
    catch (std::exception& e)
    {
        std::cout << "Exception: " << e.what() << std::endl;
    }
}
Beispiel #10
0
/* Output the data for a single variable, in CDL syntax. */
int
vardata(
     const ncvar_t *vp,		/* variable */
     size_t vdims[],		/* variable dimension sizes */
     int ncid,			/* netcdf id */
     int varid			/* variable id */
     )
{
    size_t *cor;	     /* corner coordinates */
    size_t *edg;	     /* edges of hypercube */
    size_t *add;	     /* "odometer" increment to next "row"  */
    void *vals;

    int id;
    int ir;
    size_t nels;
    size_t ncols;
    size_t nrows;
    int vrank = vp->ndims;

    cor = (size_t *) emalloc((1 + vrank) * sizeof(size_t));
    edg = (size_t *) emalloc((1 + vrank) * sizeof(size_t));
    add = (size_t *) emalloc((1 + vrank) * sizeof(size_t));

    nels = 1;
    if(vrank == 0) { /*scalar*/
	cor[0] = 0;
	edg[0] = 1;
    } else {
	for (id = 0; id < vrank; id++) {
	    cor[id] = 0;
	    edg[id] = 1;
	    nels *= vdims[id];	/* total number of values for variable */
	}
    }
    printf("\n");
    indent_out();
    printf(" ");
    print_name(vp->name);
    if (vrank <= 1) {
	printf(" = ");
	set_indent ((int)strlen(vp->name) + 4 + indent_get());
    } else {
	printf(" =\n  ");
	set_indent (2 + indent_get());
    }

    if (vrank == 0) {
	ncols = 1;
    } else {
	ncols = vdims[vrank-1];	/* size of "row" along last dimension */
	edg[vrank-1] = ncols;
	for (id = 0; id < vrank; id++)
	  add[id] = 0;
	if (vrank > 1)
	  add[vrank-2] = 1;
    }
    nrows = nels/ncols;		/* number of "rows" */
    vals = emalloc(ncols * vp->tinfo->size);

    /* Test if we should treat array of chars as a string  */
    if(vp->type == NC_CHAR && (vp->fmt == 0 || STREQ(vp->fmt,"%s") || STREQ(vp->fmt,""))) {
	for (ir = 0; ir < nrows; ir++) {
	    if (vrank > 0) {
		if (formatting_specs.brief_data_cmnts != false && vrank > 1 && ncols > 0) {
		    annotate_brief(vp, cor, vdims);
		}
	    }
	    NC_CHECK(nc_get_vara(ncid, varid, cor, edg, vals));
	    pr_tvals(vp, ncols, (ir == nrows-1), (char *) vals, cor);
	    if (ir < nrows-1)
	      if (!upcorner(vdims, vp->ndims, cor, add))
	        error("vardata: odometer overflowed!");
	    set_indent(2);
	}
    } else {
	int level = 0;
	int rank = vp->ndims;
	int marks_pending = 0;
	NC_CHECK(print_rows(level, ncid, varid, vp, ncols, rank, vdims, cor, edg,
			    vals, marks_pending));
    }
    free(vals);
    free(cor);
    free(edg);
    free(add);

    return 0;
}
Beispiel #11
0
/*  Print data values for variable varid.
 *
 * Recursive to handle possibility of variables with multiple
 * unlimited dimensions, for which the CDL syntax requires use of "{"
 * and "}" in data section to disambiguate the size of nested records
 * in a simple linear list of values.
 */
static int
print_rows(
    int level,          /* 0 at top-level, incremented for each recursive level */
    int ncid,		/* netcdf id */
    int varid,		/* variable id */
    const ncvar_t *vp,	/* variable */
    size_t ncols,	/* number of values in a row */
    int rank,	       	/* number of elements in following 3 arrays  */
    size_t vdims[],    	/* variable dimension sizes */
    size_t cor[],      	/* corner coordinates */
    size_t edg[],      	/* edges of hypercube */
    void *vals,   	/* allocated buffer for ncols values in a row */
    int marks_pending	/* number of pending closing "}" record markers */
    )
{
    int d0 = 0;
    size_t inc = 1;
    int i;
    bool_t mark_record = (level > 0 && is_unlim_dim(ncid, vp->dims[level]));
    safebuf_t *sb = sbuf_new();
    if (rank > 0)
	d0 = vdims[level];
    for(i = level + 1; i < rank; i++) {
	inc *= vdims[i];
    }
    if(mark_record) { /* the whole point of this recursion is printing these "{}" */
	lput("{");
	marks_pending++;	/* matching "}"s to emit after last "row" */
    }
    if(rank - level > 1) {     	/* this level is just d0 next levels */
	size_t *local_cor = emalloc((rank + 1) * sizeof(size_t));
	size_t *local_edg = emalloc((rank + 1) * sizeof(size_t));
	for(i = 0; i < rank; i++) {
	    local_cor[i] = cor[i];
	    local_edg[i] = edg[i];
	}
	local_cor[level] = 0;
	local_edg[level] = 1;
	for(i = 0; i < d0 - 1; i++) {
	    print_rows(level + 1, ncid, varid, vp, ncols, rank, vdims,
		       local_cor, local_edg, vals, 0);
	    local_cor[level] += 1;
	}
	print_rows(level + 1, ncid, varid, vp, ncols, rank, vdims,
		   local_cor, local_edg, vals, marks_pending);
	free(local_edg);
	free(local_cor);
    } else {			/* bottom out of recursion */
	char *valp = vals;
	bool_t lastrow;
	int j;
	if(formatting_specs.brief_data_cmnts && rank > 1) {
	    annotate_brief(vp, cor, vdims);
	}
	NC_CHECK(nc_get_vara(ncid, varid, cor, edg, (void *)valp));
	for(i=0; i < d0 - 1; i++) {
	    print_any_val(sb, vp, (void *)valp);
	    valp += vp->tinfo->size; /* next value according to type */
	    if (formatting_specs.full_data_cmnts) {
		printf("%s, ", sb->buf);
		annotate (vp, cor, i);
	    } else {
		sbuf_cat(sb, ", ");
		lput(sbuf_str(sb));
	    }
	}
	print_any_val(sb, vp, (void *)valp);
	/* determine if this is the last row */
	lastrow = true;
	for(j = 0; j < rank - 1; j++) {
	    if (cor[j] != vdims[j] - 1) {
		lastrow = false;
		break;
	    }
	}
	if (formatting_specs.full_data_cmnts) {
	    for (j = 0; j < marks_pending; j++) {
		sbuf_cat(sb, "}");
	    }
	    printf("%s", sbuf_str(sb));
	    lastdelim (0, lastrow);
	    annotate (vp, cor, i);
	} else {
	    for (j = 0; j < marks_pending; j++) {
		sbuf_cat(sb, "}");
	    }
	    lput(sbuf_str(sb));
	    lastdelim2 (0, lastrow);
	}
    }
    sbuf_free(sb);
    return NC_NOERR;
}
Beispiel #12
0
int
main(int argc,
     char**)
{
    try
    {
        // Initialize the IO service, this allows us to perform network operations asyncronously
        boost::asio::io_service io_service;

        // Typically async operations are performed in the thread performing the request, because we want synchronous behavior
        // we're going to spawn a thread whose sole purpose is to perform network communication, and we'll use this thread to
        // initiate and check the status of requests.
        //
        // Also, typically the boost::asio::io_service::run will exit as soon as it's work is done, which we want to prevent
        // because it's in it's own thread.  Using boost::asio::io_service::work prevents the thread from exiting.
        std::auto_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(io_service));
        boost::thread thread(boost::bind(static_cast<size_t(boost::asio::io_service::*)()>(&boost::asio::io_service::run), &io_service));

        // decide which client factory we want, SSL or non-SSL.  This is a hack, if you pass any commandline arg to the
        // binary it will use the SSL factory, non-SSL by default
        boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);
        cql::cql_client_pool_t::cql_client_callback_t client_factory;
        if (argc > 1) {
            client_factory = client_ssl_functor_t(io_service, ctx, &log_callback);
        }
        else {
            client_factory = client_functor_t(io_service, &log_callback);
        }

        // Construct the pool
        std::auto_ptr<cql::cql_client_pool_t> pool(cql::cql_client_pool_factory_t::create_client_pool_t(client_factory, NULL, NULL));

        // Add a client to the pool, this operation returns a future.
        boost::shared_future<cql::cql_future_connection_t> connect_future = pool->add_client("localhost", 9042);

        // Wait until the connection is complete, or has failed.
        connect_future.wait();

        // Check whether or not the connection was successful.
        std::cout << "connect successfull? ";
        if (!connect_future.get().error.is_err()) {
            // The connection succeeded
            std::cout << "TRUE" << std::endl;

            // execute a query, switch keyspaces
            boost::shared_future<cql::cql_future_result_t> future = pool->query("USE system;", cql::CQL_CONSISTENCY_ONE);

            // wait for the query to execute
            future.wait();

            // check whether the query succeeded
            std::cout << "switch keyspace successfull? " << (!future.get().error.is_err() ? "true" : "false") << std::endl;

            // execute a query, select all rows from the keyspace
            future = pool->query("SELECT * from schema_keyspaces;", cql::CQL_CONSISTENCY_ONE);

            // wait for the query to execute
            future.wait();

            // check whether the query succeeded
            std::cout << "select successfull? " << (!future.get().error.is_err() ? "true" : "false") << std::endl;
            if (future.get().result) {
                // print the rows return by the successful query
                print_rows(*future.get().result);
            }

            // close the connection pool
            pool->close();
        }
        else {
            // The connection failed
            std::cout << "FALSE" << std::endl;
        }

        work.reset();
        thread.join();

        std::cout << "THE END" << std::endl;
    }
    catch (std::exception& e)
    {
        std::cout << "Exception: " << e.what() << std::endl;
    }
    return 0;
}
Beispiel #13
0
/* Output the data for a single variable, in CDL syntax. */
int
vardata(
     const ncvar_t *vp,		/* variable */
     size_t vdims[],		/* variable dimension sizes */
     int ncid,			/* netcdf id */
     int varid			/* variable id */
     )
{
    size_t *cor;	     /* corner coordinates */
    size_t *edg;	     /* edges of hypercube */
    size_t *add;	     /* "odometer" increment to next "row"  */
    void *vals;

    int id;
    size_t nels;
    size_t ncols;
    size_t nrows;
    int vrank = vp->ndims;

    int level = 0;
    int marks_pending = 0;

    cor = (size_t *) emalloc((1 + vrank) * sizeof(size_t));
    edg = (size_t *) emalloc((1 + vrank) * sizeof(size_t));
    add = (size_t *) emalloc((1 + vrank) * sizeof(size_t));

    nels = 1;
    if(vrank == 0) { /*scalar*/
	cor[0] = 0;
	edg[0] = 1;
    } else {
	for (id = 0; id < vrank; id++) {
	    cor[id] = 0;
	    edg[id] = 1;
	    nels *= vdims[id];	/* total number of values for variable */
	}
    }
    printf("\n");
    indent_out();
    printf(" ");
    print_name(vp->name);
    if (vrank <= 1) {
	printf(" = ");
	set_indent ((int)strlen(vp->name) + 4 + indent_get());
    } else {
	printf(" =\n  ");
	set_indent (2 + indent_get());
    }

    if (vrank == 0) {
	ncols = 1;
    } else {
	ncols = vdims[vrank-1];	/* size of "row" along last dimension */
	edg[vrank-1] = ncols;
	for (id = 0; id < vrank; id++)
	  add[id] = 0;
	if (vrank > 1)
	  add[vrank-2] = 1;
    }
    nrows = nels/ncols;		/* number of "rows" */
    vals = emalloc(ncols * vp->tinfo->size);
    
    NC_CHECK(print_rows(level, ncid, varid, vp, vdims, cor, edg, vals, marks_pending));
    free(vals);
    free(cor);
    free(edg);
    free(add);

    return 0;
}
Beispiel #14
0
//----------------------------------------------------------------------
const char* parse_args(int argc, const char** argv, int parseonly,
                       struct log2mem_handle * handle)
{
  int i = 1;
  const char* filename = 0;
  int defaultshow = 1;

  enum showbits
  {
    eSummary  = 0x01,
    eCounters = 0x02,
    eRows     = 0x04,
    eVars     = 0x08
  };
  int toshow = 0;

  for (;i < argc; i++)
  {
    if ( strcmp(argv[i], "-h")==0 || strcmp(argv[i],"--help")==0 ) help();
    else if (strcmp(argv[i], "-s")==0)
    {
      toshow |= eSummary;
    }
    else if (strcmp(argv[i], "-c")==0)
    {
      toshow |= eCounters;
    }
    else if (strcmp(argv[i], "-r")==0)
    {
      toshow |= eRows;
    }
    else if (strcmp(argv[i], "-v")==0)
    {
      toshow |= eVars;
    }
    else if (strcmp(argv[i], "-a")==0)
    {
      toshow |= ~eSummary;
    }
    else if (strcmp(argv[i], "-F")==0)
    {
      if (++i >= argc) die("missing argument to -F", NULL);
      g_delim = argv[i];
      g_showdelim = 1;
    }
    else if (strcmp(argv[i], "-z")==0)
    {
      g_showdelim = 0;
    }
    else if (strcmp(argv[i], "-t")==0)
    {
      g_terse = 1;
    }
    else if (strcmp(argv[i], "--version")==0)
    {
      printf("log2mem version: " PACKAGE_VERSION "\n");
      exit(1);
    }
    else if (strncmp(argv[i], OPT_DOUBLE, strlen(OPT_DOUBLE))==0)
    {
      set_var_double(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else if (strncmp(argv[i], OPT_INT, strlen(OPT_INT))==0)
    {
      set_var_int(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else if (strncmp(argv[i], OPT_STRING, strlen(OPT_STRING))==0)
    {
      set_var_string(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else if ((strncmp(argv[i], "--",2)==0) && strlen(argv[i])>2 )
    {
      set_var_by_name(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else
    {
      if (filename == 0)
        filename = argv[i];
      else
      {
        die("unexpected argument: ", argv[i]);
      }
    }
  }

  if (defaultshow && !toshow) toshow = 0xFFFF;

  if (!parseonly)
  {
    //if (toshow & eSummary)  print_summary(handle);
    if (toshow & eRows)     print_rows(handle);
    if (toshow & eCounters) print_counters(handle);
    if (toshow & eVars)     print_vars(handle);
  }

  return filename;
}