Skip to content
Snippets Groups Projects
Commit c4ab88aa authored by Moritz Hanke's avatar Moritz Hanke
Browse files

improves weights2vtk tool

* now user can set whether global ids of source and target grid were 0- or 1-based when generating the weight file
parent c1d52c13
No related branches found
No related tags found
No related merge requests found
......@@ -78,11 +78,13 @@ struct grid_config {
char const * filename;
} curve, unstruct;
} config;
int address_offset;
enum grid_type type;
};
int file_exists(char const * filename);
void read_link_data(char const * weight_filename, struct link_data ** links,
void read_link_data(char const * weight_filename, int src_address_offset,
int tgt_address_offset, struct link_data ** links,
unsigned * num_links, enum yac_location ** src_locations,
enum yac_location * tgt_location, unsigned * max_src_idx,
unsigned * max_tgt_idx);
......@@ -124,8 +126,9 @@ int main(int argc, char ** argv) {
unsigned num_links, max_src_idx, max_tgt_idx;
enum yac_location * src_locations;
enum yac_location tgt_location;
read_link_data(weight_filename, &links, &num_links, &src_locations,
&tgt_location, &max_src_idx, &max_tgt_idx);
read_link_data(weight_filename, src_grid_config.address_offset,
tgt_grid_config.address_offset, &links, &num_links,
&src_locations, &tgt_location, &max_src_idx, &max_tgt_idx);
if ((max_src_idx >= yac_get_num_grid_cells(src_grid)) ||
(max_tgt_idx >= yac_get_num_grid_cells(tgt_grid))) {
......@@ -173,7 +176,8 @@ static void handle_error(int status) {
}
#endif
void read_link_data(char const * weight_filename, struct link_data ** links,
void read_link_data(char const * weight_filename, int src_address_offset,
int tgt_address_offset, struct link_data ** links,
unsigned * num_links, enum yac_location ** src_locations,
enum yac_location * tgt_location, unsigned * max_src_idx,
unsigned * max_tgt_idx) {
......@@ -325,7 +329,7 @@ void read_link_data(char const * weight_filename, struct link_data ** links,
if (status != NC_NOERR) handle_error(status);
*max_src_idx = 0;
for (unsigned i = 0; i < num_links_in_file; ++i) {
int idx = address[i] - 1;
int idx = address[i] + src_address_offset;
if (idx < 0) {
fprintf(stderr, "invalid src index (%d)\n", idx);
exit(EXIT_FAILURE);
......@@ -339,7 +343,7 @@ void read_link_data(char const * weight_filename, struct link_data ** links,
if (status != NC_NOERR) handle_error(status);
*max_tgt_idx = 0;
for (unsigned i = 0; i < num_links_in_file; ++i) {
int idx = address[i] - 1;
int idx = address[i] + tgt_address_offset;
if (idx < 0) {
fprintf(stderr, "invalid tgt index (%d)\n", idx);
exit(EXIT_FAILURE);
......@@ -610,6 +614,11 @@ void print_help(char * command) {
"total number of cells\n"
" 'm', 'M': curvilinear grid\n"
" 'i', 'I': unstructured grid\n"
" - a lower case grid type indicates, that the global ids\n"
" of the respective grid were \"0\"-based in the model\n"
" component that generated the weight file\n"
" - an upper case grid type indicates \"1\"-based global\n"
" ids\n"
"\n"
"Example:\n"
" Configuration:\n"
......@@ -671,6 +680,7 @@ void parse_arguments(int argc, char ** argv,
grid_config->type = UNSTRUCT;
break;
};
grid_config->address_offset = (optarg[0] < 'a')?-2:-1;
break;
}
case 's':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment