A rigorous algorithm for template design in stable cellular neural networks