void Histogram::set_use_frequencies( bool on ) { if( on == frequencies_ || bins_count_ <= 0 ) return; frequencies_ = on; if( on ) std::transform( y_vals_, y_vals_+bins_count_+1, y_vals_, std::bind2nd( std::divides<double>(), double( data_count() ) ) ); else std::transform( y_vals_, y_vals_+bins_count_+1, y_vals_, std::bind2nd( std::multiplies<double>(), double( data_count() ) ) ); }
static void ref_nonsingle(int front, int back) { int i; if (digraph) { for (i = front; i <= back; ++i) data_count(aout, eout, lab[i]); do_ref_nonsingle(); for (i = front; i <= back; ++i) data_count(ain, ein, lab[i]); do_ref_nonsingle(); } else { for (i = front; i <= back; ++i) data_count(adj, edg, lab[i]); do_ref_nonsingle(); } }
END_TEST START_TEST(test_nsdata_count) { hid_t fid, sid; herr_t err; int iseed = 0xaa44; char data_name[32]; int cnt; int gen_cnt, idx; int data; int size; generate_output_file(&fid,&sid); fail_unless(H5_ISA_VALID_ID(sid) && H5_ISA_VALID_ID(fid), "failed to generate test file"); printf("line=%d sid=0x%lx\n", __LINE__,sid); err = data_count(sid,&cnt); fail_unless(H5_RETURN_OK(err), "Failed to return success status"); fail_unless(cnt == 0, "Failed to return correct count (0)"); printf("line=%d sid=0x%lx\n", __LINE__,sid); data = generate_random_int(&iseed); size = 1; //gen_cnt = generate_random_bound_int(10,1024,&iseed); gen_cnt=1; for(idx=0; idx < gen_cnt; idx++) { sprintf(data_name, "Data Mu %04d",idx); data_write_int(sid,data_name,1,&size,&data); } printf("line=%d sid=0x%lx\n", __LINE__,sid); err = data_count(sid,&cnt); fail_unless(H5_RETURN_OK(err), "Failed to return success status"); fail_unless(cnt == gen_cnt, "Failed to return correct count (<0)"); printf("line=%d sid=0x%lx\n", __LINE__,sid); danu_group_close(sid); output_file_close(&fid); //file_delete(); }
static int ref_nonsingle(struct saucy *s, struct coloring *c, const int *adj, const int *edg, int cf) { int i, j, k, ret; const int cb = cf + c->clen[cf]; const int size = cb - cf + 1; /* Double check for nonsingles which became singles later */ if (cf == cb) { return ref_singleton(s, c, adj, edg, cf); } /* Establish connected list */ memcpy(s->junk, c->lab + cf, size * sizeof(int)); for (i = 0; i < size; ++i) { k = s->junk[i]; for (j = adj[k]; j != adj[k+1]; ++j) { data_count(s, c, edg[j]); } } /* Refine the cells we're connected to */ ret = refine_cell(s, c, ref_nonsingle_cell); /* Clear the counts; use lab because junk was overwritten */ for (i = cf; i <= cb; ++i) { k = c->lab[i]; for (j = adj[k]; j != adj[k+1]; ++j) { s->ccount[edg[j]] = 0; } } return ret; }
void Histogram::bins( int n ) { if( n <= 0 ) return; if( n == bins_count_ && !recompute_ ) return; recompute_ = false; clear_plot_values(); bins_count_ = n; x_vals_ = new double[n+1]; y_vals_ = new double[n+1]; if( start_ == end_ ) { for( int j=0; j < n+1; j++ ) { x_vals_[j] = 0; y_vals_[j] = 0; } return; } // compute the sizes of the bins if( logscale_ ) compute_log_bin_sizes( x_vals_, n ); else compute_linear_bin_sizes( x_vals_, n ); // the previous functions only computed n elements x_vals_[n] = *(end_-1); std::vector<float>::iterator start_pos = start_; for( int i = 1; i <= n; i++ ) { std::vector<float>::iterator pos = std::upper_bound( start_pos, end_, x_vals_[i] ); y_vals_[i-1] = std::distance( start_pos, pos ); start_pos = pos; } y_vals_[n] = y_vals_[n-1]; if( frequencies_ ) { for( int i = 0; i <= n; i++ ) y_vals_[i] /= float( data_count() ); } }
int main(void) { user_info user; user_info *p; p = &user; int option, i; printf("%d\n", data_count()); //start = read_data_from_file(start); /* do { //Display user menu printf("0 - quit\n"); printf("1 - add\n"); printf("2 - remove\n"); printf("3 - display all\n"); printf("Enter option: "); fflush(stdout); scanf("%2d", &option); //Process option switch (option) { case 1: start = add_point(start); break; case 2: start = remove_point(start); break; case 3: display_all(start); break; } }while (option != 0); */ //write_all_to_file(start); return 0; }
int main(void) { //retrieves the number if data entries in the file int i = data_count(); int j; FILE *fp1; char fname[] = "user_info.txt"; //declares an array of srtucts, with number of elements //equal to number data entries in the file, //so an element in the array for each data entry user_info users[i]; user_info *p; //declares pointer to struct of type user_info p = &users[0]; //sets address of pointer to the first element of struct array char tmp[3];//temp array used to read in user choices char op;//char which user choice is processed and inserted into //Asks user to enter their choice on what operation to perform. printf("Would you like to read user data or write new information?\n"); printf("r - read data from file.\n"); printf("w - write new data to a new file, overwriting existing file.\n"); printf("a - write new data and append to current file.\n"); //using fgets() to read in choice and sscanf() to process and insert into "op" fgets(tmp, 3, stdin); sscanf(tmp, "%c", &op); //if user wishes to read from file... if (op == 'r' || op == 'R') { FILE *fp1; char fname[] = "user_info.txt"; if ( (fp1 = fopen(fname, "r" )) == NULL ) { printf("cannot open file %s for reading\n", fname); exit(1); } //Number of data entries was counted at the beginning of the program. //Loops through file, transferring each data entry into its own struct. for(j=0;j<i;j++) { //sets address of pointer to the address of current array element p = &users[j]; //reads data from the file into the struct array element read_from_file(fp1, p); } fclose(fp1); }//end of reading from file if condition //If user wishes to write to file... else if (op == 'a' || op == 'A' || op == 'w' || op == 'W') { //calls input function, passing the type of write operation //to be performed as well as the struct input_string(&op, p); } //if user enters wrong choice else { printf("You did not specify a valid option.\n"); } return 0; }
int main(int argc, char ** argv) { int num_errs; char root_file[] = FILE; char test_sim[] = SIM_NAME; char data_name[128]; char **names; int numpe; int i,dim, *size; size_t *nsizes; int ncnt; dsize_t num; double *data,*ref_data; hid_t fid, sid; if ( FILE_EXISTS(root_file) ) { danu_file_delete(root_file); } if ( H5_RETURN_FAIL(create_test_file(root_file) ) ) { DANU_ERROR_MESS("Failed to create the test file"); num_errs++; goto EXIT_NOW; } fid = danu_file_open_append(root_file); if ( H5_RETURN_FAIL(simulation_add(fid,test_sim,&sid) ) ) { DANU_ERROR_MESS("Failed to add simulation"); goto EXIT_NOW; } num_errs = 0; /* Arrays */ size = DANU_MALLOC(int,DIM); /* Write the data */ size[0] = 1; numpe = DUMMY_INT; sprintf(data_name,DATA_INT_NAME); if ( H5_RETURN_FAIL(data_write_int(sid,data_name,1,size,&numpe)) ) { DANU_ERROR_MESS("Failed to write int data"); num_errs++; goto EXIT_NOW; } dim = DIM; num = 1; for(i=0;i<dim;i++) { size[i] = NUMCELLS; num*=NUMCELLS; } data = DANU_MALLOC(double,num); sprintf(data_name,DATA_DBL_NAME); danu_rand_data_double(-5.0,5.0,num,data); if ( H5_RETURN_FAIL(data_write_double(sid,data_name,dim,size,data)) ) { DANU_ERROR_MESS("Failed to write double data"); num_errs++; goto EXIT_NOW; } /* Check data by reading */ ref_data = DANU_MALLOC(double,num); if ( H5_RETURN_FAIL(data_read_double(sid,data_name,dim,size,ref_data) ) ) { num_errs++; goto EXIT_NOW; } for(i=0;i<num;i++) { if ( ref_data[i] != data[i] ) { num_errs++; } } /* Find the number of datasets */ data_count(sid,&ncnt); printf("Found %d datasets\n",ncnt); names = DANU_MALLOC(char *,ncnt); nsizes = convert_int_to_size(ncnt,size); for(i=0;i<ncnt;i++) { size[i] = 128; names[i] = DANU_MALLOC(char,128); } data_list(sid,ncnt,nsizes,names); printf("Found the following datasets\n"); for(i=0;i<ncnt;i++) { printf("\t<%s>\n",names[i]); } /* Free memory */ for(i=0;i<ncnt;i++) { DANU_FREE(names[i]); } DANU_FREE(names); DANU_FREE(ref_data); DANU_FREE(data); DANU_FREE(size); /* Free HDF5 resources */ danu_group_close(sid); danu_file_close(fid); EXIT_NOW: printf("Found %d errors\n",num_errs); return num_errs; }
void getOffsetAndCount(const MultiTag &tag, const DataArray &array, size_t index, NDSize &offsets, NDSize &counts) { DataArray positions = tag.positions(); DataArray extents = tag.extents(); NDSize position_size, extent_size; size_t dimension_count = array.dimensionCount(); if (positions) { position_size = positions.dataExtent(); } if (extents) { extent_size = extents.dataExtent(); } if (!positions || index >= position_size[0]) { throw nix::OutOfBounds("Index out of bounds of positions!", 0); } if (extents && index >= extent_size[0]) { throw nix::OutOfBounds("Index out of bounds of positions or extents!", 0); } if (position_size.size() == 1 && dimension_count != 1) { throw nix::IncompatibleDimensions("Number of dimensions in positions does not match dimensionality of data", "util::getOffsetAndCount"); } if (position_size.size() > 1 && position_size[1] > dimension_count) { throw nix::IncompatibleDimensions("Number of dimensions in positions does not match dimensionality of data", "util::getOffsetAndCount"); } if (extents && extent_size.size() > 1 && extent_size[1] > dimension_count) { throw nix::IncompatibleDimensions("Number of dimensions in extents does not match dimensionality of data", "util::getOffsetAndCount"); } NDSize temp_offset = NDSize{static_cast<NDSize::value_type>(index), static_cast<NDSize::value_type>(0)}; NDSize temp_count{static_cast<NDSize::value_type>(1), static_cast<NDSize::value_type>(dimension_count)}; vector<double> offset; positions.getData(offset, temp_count, temp_offset); NDSize data_offset(dimension_count, static_cast<size_t>(0)); NDSize data_count(dimension_count, static_cast<size_t>(1)); vector<string> units = tag.units(); for (size_t i = 0; i < offset.size(); ++i) { Dimension dimension = array.getDimension(i+1); string unit = "none"; if (i <= units.size() && units.size() > 0) { unit = units[i]; } data_offset[i] = positionToIndex(offset[i], unit, dimension); } if (extents) { vector<double> extent; extents.getData(extent, temp_count, temp_offset); for (size_t i = 0; i < extent.size(); ++i) { Dimension dimension = array.getDimension(i+1); string unit = "none"; if (i <= units.size() && units.size() > 0) { unit = units[i]; } ndsize_t c = positionToIndex(offset[i] + extent[i], unit, dimension) - data_offset[i]; data_count[i] = (c > 1) ? c : 1; } } offsets = data_offset; counts = data_count; }