0
In your code, almost everything is similar:
What you could do is write a script in whatever language you like (Python, Perl, Ruby, etc...) that will generate your fortran code.
Here is a script in Python that would do what you want:
#!/usr/bin/env python
replacements = {
"x" : {
"j...