void tri_grid::load(std::string filename) { std::cout << "# Loading mesh" << std::endl; // do this as a text file first std::ifstream in; in.open(filename.c_str(), std::ios::in | std::ios::binary); if (!in) throw(std::string("Loading mesh. File could not be opened ") + filename); meta_data = read_meta_data(in); // read in the point cloud point_cloud_instance.load(in); // read in the number of triangle roots int n_tris = read_int(in); // create the quad trees for the triangle roots // start with the first triangle indexed_force_tri_3D* current_tri = new indexed_force_tri_3D; current_tri->load(in, &point_cloud_instance); // now loop through the rest of the triangles for (int i=0; i<(int)(n_tris); i++) { triangles.push_back(new quadtree<indexed_force_tri_3D>); // get the current node as the first root node QT_TRI_NODE* current_node = triangles[i]->get_root(); current_tri = load_node(in, current_node, current_tri, &point_cloud_instance); } in.close(); }
int main( int argc, char **argv ) { int status = 0; FLD_TYPE *flds = NULL; int n_flds; long long num_rows; char *meta_data_file = NULL; char *data_file = NULL; char *str_load_fld = NULL; char **nn_fnames = NULL, **sz_fnames = NULL; if ( argc != 4 ) { go_BYE(-1); } meta_data_file = argv[1]; data_file = argv[2]; str_load_fld = argv[3]; status = read_meta_data(meta_data_file, &flds, &n_flds); cBYE(status); fprintf(stdout, "n_flds = %d \n", n_flds); status = read_csv(flds, n_flds, data_file, str_load_fld, '"', ',', '\n', true, false, false, &nn_fnames, &sz_fnames, &num_rows); cBYE(status); for ( int i = 0; i < n_flds; i++ ) { pr_fld_meta(flds[i]); fprintf(stderr, "DBG ---- Field %d ------------------\n", i); if ( sz_fnames[i] != NULL ) { fprintf(stdout, "Aux sz field exists. file = %s \n", sz_fnames[i]); } if ( nn_fnames[i] != NULL ) { fprintf(stdout, "Aux nn field exists. file = %s \n", nn_fnames[i]); } } for ( int i = 0; i < n_flds; i++ ) { free_if_non_null(nn_fnames[i]); free_if_non_null(sz_fnames[i]); } free_if_non_null(nn_fnames); free_if_non_null(sz_fnames); BYE: free_if_non_null(flds); return(status); }
void data_store::load(std::string f_name) { std::cout << "# Loading regridded data" << std::endl; // delete data if it already exists if (data) delete [] data; std::ifstream in; // open the file in binary mode in.open(f_name.c_str(), std::ios::in | std::ios::binary); if (!in) throw(std::string("Loading regridded data. File could not be opened ") + f_name); meta_data = read_meta_data(in); // read the number of time steps and indices n_t_steps = read_int(in); n_idxs = read_int(in); missing_value = read_float(in); // create the data storage data = new FP_TYPE[n_t_steps * n_idxs]; // read in the data in.read(reinterpret_cast<char*>(data), sizeof(FP_TYPE)*n_t_steps*n_idxs); in.close(); }
static struct stat_info rados_tile_stat(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z) { struct stat_info tile_stat; char * buf; int offset, mask; mask = METATILE - 1; offset = (x & mask) * METATILE + (y & mask); buf = read_meta_data(store, xmlconfig, options, x, y, z); if (buf == NULL) { tile_stat.size = -1; tile_stat.expired = 0; tile_stat.mtime = 0; tile_stat.atime = 0; tile_stat.ctime = 0; return tile_stat; } memcpy(&tile_stat,buf, sizeof(struct stat_info)); tile_stat.size = ((struct meta_layout *) (buf + sizeof(struct stat_info)))->index[offset].size; return tile_stat; }
static int rados_tile_read(struct storage_backend * store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int * compressed, char * log_msg) { char meta_path[PATH_MAX]; int meta_offset; unsigned int header_len = sizeof(struct meta_layout) + METATILE*METATILE*sizeof(struct entry); struct meta_layout *m = (struct meta_layout *)malloc(header_len); size_t file_offset, tile_size; int mask; int err; char * buf_raw; mask = METATILE - 1; meta_offset = (x & mask) * METATILE + (y & mask); rados_xyzo_to_storagekey(xmlconfig, options, x, y, z, meta_path); buf_raw = read_meta_data(store, xmlconfig, options, x, y, z); if (buf_raw == NULL) { snprintf(log_msg,1024, "Failed to read metadata of tile\n"); free(m); return -3; } memcpy(m, buf_raw + sizeof(struct stat_info), header_len); if (memcmp(m->magic, META_MAGIC, strlen(META_MAGIC))) { if (memcmp(m->magic, META_MAGIC_COMPRESSED, strlen(META_MAGIC_COMPRESSED))) { snprintf(log_msg,1024, "Meta file header magic mismatch\n"); free(m); return -4; } else { *compressed = 1; } } else *compressed = 0; // Currently this code only works with fixed metatile sizes (due to xyz_to_meta above) if (m->count != (METATILE * METATILE)) { snprintf(log_msg, 1024, "Meta file header bad count %d != %d\n", m->count, METATILE * METATILE); free(m); return -5; } file_offset = m->index[meta_offset].offset + sizeof(struct stat_info); tile_size = m->index[meta_offset].size; free(m); if (tile_size > sz) { snprintf(log_msg, 1024, "Truncating tile %zd to fit buffer of %zd\n", tile_size, sz); tile_size = sz; return -6; } err = rados_read(((struct rados_ctx *)store->storage_ctx)->io, meta_path, buf, tile_size, file_offset); if (err < 0) { snprintf(log_msg, 1024, "Failed to read tile data from rados %s offset: %li length: %li: %s\n", meta_path, file_offset, tile_size, strerror(-err)); return -1; } return tile_size; }