#include <stdio.h>
#include <stdlib.h>
#include <hdf5.h>
#include <vector>
#include <map>
#include <string>
Go to the source code of this file.
|
hid_t | open_file (const char *name) |
|
long | read_scalar_attrib (hid_t file, const char *table, const char *attrib) |
|
void | read_data (hid_t file, const char *name, int expected_cols, std::vector< long > &data) |
|
void | create_map (const std::vector< long > &ents, const std::vector< long > &vals, std::map< long, long > &map, const char *name) |
|
std::string | ent_from_handle (const std::map< long, long > &dimmap, const std::map< long, long > &idmap, long handle) |
|
std::string | ent_list_from_handles (const std::map< long, long > &dimmap, const std::map< long, long > &idmap, const std::vector< long > &vect, long start, long stop) |
|
int | main (int argc, char *argv[]) |
|
◆ create_map()
void create_map |
( |
const std::vector< long > & |
ents, |
|
|
const std::vector< long > & |
vals, |
|
|
std::map< long, long > & |
map, |
|
|
const char * |
name |
|
) |
| |
Definition at line 98 of file dump_geom_sets.cxx.
103 if (ents.size() != vals.size()) {
104 fprintf(stderr,
"Invalid data for tag \"%s\": mismatched table lengths.\n", name );
108 std::vector<long>::const_iterator e_iter = ents.begin(), v_iter = vals.begin();
109 for (; e_iter != ents.end(); ++e_iter, ++v_iter)
110 map[*e_iter] = *v_iter;
Referenced by main().
◆ ent_from_handle()
std::string ent_from_handle |
( |
const std::map< long, long > & |
dimmap, |
|
|
const std::map< long, long > & |
idmap, |
|
|
long |
handle |
|
) |
| |
Definition at line 116 of file dump_geom_sets.cxx.
121 std::map<long,long>::const_iterator d_iter, i_iter;
122 d_iter = dimmap.find( handle );
123 i_iter = idmap.find( handle );
124 if (d_iter == dimmap.end() || i_iter == idmap.end())
127 switch (d_iter->second) {
128 case 0: result +=
"v";
break;
129 case 1: result +=
"c";
break;
130 case 2: result +=
"s";
break;
131 case 3: result +=
"V";
break;
133 fprintf(stderr,
"Invalid value in GEOM_DIMENSION tag data.\n");
138 sprintf(
buffer,
"%ld", i_iter->second );
References buffer.
Referenced by ent_list_from_handles(), and main().
◆ ent_list_from_handles()
std::string ent_list_from_handles |
( |
const std::map< long, long > & |
dimmap, |
|
|
const std::map< long, long > & |
idmap, |
|
|
const std::vector< long > & |
vect, |
|
|
long |
start, |
|
|
long |
stop |
|
) |
| |
Definition at line 146 of file dump_geom_sets.cxx.
153 if (start >= (
long)vect.size() || stop >= (
long)vect.size() || stop < start) {
154 fprintf(stderr,
"Invalid set data. Corrupt file?\n");
157 std::vector<long>::const_iterator iter = vect.begin() + start+1,
158 end = vect.begin() + stop+1;
160 for (; iter != end; ++iter)
References ent_from_handle().
Referenced by main().
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 173 of file dump_geom_sets.cxx.
177 printf(
"Usage: %s <file>\n", argv[0] );
182 std::vector<long> set_meta, set_child, set_parent, dim_ents, dim_vals, id_ents, id_vals;
184 read_data( file,
"/tstt/sets/list", 4, set_meta );
185 read_data( file,
"/tstt/sets/parents", 1, set_parent );
186 read_data( file,
"/tstt/sets/children", 1, set_child );
187 read_data( file,
"/tstt/tags/GEOM_DIMENSION/id_list", 1, dim_ents );
188 read_data( file,
"/tstt/tags/GEOM_DIMENSION/values", 1, dim_vals );
189 read_data( file,
"/tstt/tags/GLOBAL_ID/id_list", 1, id_ents );
190 read_data( file,
"/tstt/tags/GLOBAL_ID/values", 1, id_vals );
195 std::map<long,long> dimmap, idmap;
196 create_map( dim_ents, dim_vals, dimmap,
"GEOM_DIMENSION" );
197 create_map( id_ents, id_vals, idmap,
"GLOBAL_ID" );
200 long parent_start = -1l, child_start = -1l;
201 printf(
"handle ID Children Parents\n");
202 for (
unsigned i = 0; i < set_meta.size(); i += 4)
205 long handle = startid + i/4;
211 long child_end = set_meta[i+1];
212 long parent_end = set_meta[i+2];
215 child_start = child_end;
216 parent_start = parent_end;
219 printf(
"%6ld %-6s %-20s %-20s\n", handle, name.c_str(),
children.c_str(), parents.c_str() );
References children, create_map(), ent_from_handle(), ent_list_from_handles(), open_file(), read_data(), and read_scalar_attrib().
◆ open_file()
hid_t open_file |
( |
const char * |
name | ) |
|
Definition at line 13 of file dump_geom_sets.cxx.
15 hid_t handle = H5Fopen( name, H5F_ACC_RDONLY, H5P_DEFAULT );
17 fprintf(stderr,
"Cannot open file: \"%s\"\n", name );
Referenced by main().
◆ read_data()
void read_data |
( |
hid_t |
file, |
|
|
const char * |
name, |
|
|
int |
expected_cols, |
|
|
std::vector< long > & |
data |
|
) |
| |
Definition at line 52 of file dump_geom_sets.cxx.
54 hid_t handle = H5Dopen( file, name );
56 fprintf(stderr,
"Invalid file. Data not found: \"%s\"\n", name );
60 hid_t space = H5Dget_space( handle );
62 fprintf(stderr,
"Internal error accessing: \"%s\"\n", name );
66 int ndims = H5Sget_simple_extent_ndims( space );
68 fprintf(stderr,
"Internal error accessing: \"%s\"\n", name );
71 else if (ndims < 1 || ndims > 2) {
72 fprintf(stderr,
"\"%s\" is an %d-dimension table. Corrupt file?", name, ndims );
76 hsize_t dims[2] = { 0, 1 };
77 H5Sget_simple_extent_dims( space, dims, 0 );
80 if (dims[1] != expected_cols) {
81 fprintf(stderr,
"Error reading \"%s\": expected %d cols, has %d\n", name, expected_cols, (
int)dims[1] );
85 data.resize( dims[0] * dims[1] );
86 herr_t rval = H5Dread( handle, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data[0] );
88 fprintf(stderr,
"Error reading data from: \"%s\"\n", name );
Referenced by main().
◆ read_scalar_attrib()
long read_scalar_attrib |
( |
hid_t |
file, |
|
|
const char * |
table, |
|
|
const char * |
attrib |
|
) |
| |
Definition at line 24 of file dump_geom_sets.cxx.
26 hid_t table_id = H5Dopen( file, table );
28 fprintf(stderr,
"Invalid file. Data not found: \"%s\"\n", table );
32 hid_t attr_id = H5Aopen_name( table_id, attrib );
35 fprintf(stderr,
"Invalid file. No \"%s\" attrib on \"%s\"\n", attrib, table );
40 herr_t rval = H5Aread( attr_id, H5T_NATIVE_LONG, &value );
43 fprintf(stderr,
"Failed to read \"%s\" attrib on \"%s\"\n", attrib, table );
Referenced by main().