int main(int argc, char** argv) { stack adata = NULL; int c1, c2, c3; printf("Testando append_dim:"); append_dim(&adata, 7); if(adata != NULL && *((int*) adata->next->element) == 7) printf(" OK\n"); else printf(" ERROR\n"); printf("Testando count_dim:"); c1 = count_dim(adata); append_dim(&adata, 112); c2 = count_dim(adata); if(c1 == 1 && c2 == 2) printf(" OK\n"); else printf(" ERROR wrong count: c1=%i c2=%i\n", c1, c2); printf("Testando len_dim:"); c1 = len_dim(adata, 2); if(c1 == 7) printf(" OK\n"); else printf(" ERROR wrong length: %i\n", c1); printf("Testando desloc_dim:"); append_dim(&adata, 10); c1 = desloc_dim(adata, 1); c2 = desloc_dim(adata, 2); c3 = desloc_dim(adata, 3); if(c1 == 0 && c2 == 10 && c3 == 1120) printf(" OK\n"); else printf(" ERROR wrong desloc: c1=%i c2=%i\n", c1, c2); return 0; }
std::vector<int> ParsedName::List::count () const { if (! list[0]->ndim()) { if (size() == 1) return (std::vector<int>()); else throw Exception ("image number mismatch"); } std::vector<int> dim ( list[0]->ndim(), 0); size_t current_entry = 0; count_dim (dim, current_entry, 0); return dim; }
void ParsedName::List::count_dim (std::vector<int>& dim, size_t& current_entry, size_t current_dim) const { int n; bool stop = false; std::shared_ptr<const ParsedName> first_entry ( list[current_entry]); for (n = 0; current_entry < size(); n++) { for (size_t d = 0; d < current_dim; d++) if ( list[current_entry]->index (d) != first_entry->index (d)) stop = true; if (stop) break; if (current_dim < list[0]->ndim()-1) count_dim (dim, current_entry, current_dim+1); else current_entry++; } if (dim[current_dim] && dim[current_dim] != n) throw Exception ("number mismatch between number of images along different dimensions"); dim[current_dim] = n; }