from mako.template import Template
# the following fortran 90 code will not compile. It is proof of concept
tpl = Template("""!== see 'readme' at bottom of file for explanation of code
close(123)
## note: if rank is 0 for the serial run, then this doesn't actually require a split
% if produceMPI==1:
seed = seed_input-rank !== the seed is specific to the node
% else:
seed = seed_input !== the seed is specific to the node
% endif
!== call ran2 the first time, which upsets the seed number. In place to
!== avoid using the first ran2 output, because otherwise seed gets screwed up (?!)
FirstNumber=ran2(seed)
! write(*,*) 'seed is now ',seed
<%
file = open('parameters.input','w')
file.write(\" 1 1 1 0 \\n \")
file.write(\" var1 var2 nvar indx \\n \")
%>
open(132,file='parameters.input') ! input what parameters to use
read(132,*) omgi,omgf,n_omg,randprop
close(132)
n_open = int(2.0*W/lambda)
!== Total number of channels, both open and closed
!== eof""")
## to produce MPI F90 code, uncomment the following
filename="vary_active_no_uf.mpi.f90"
rendered_tpl = tpl.render(produceMPI=1,noderank="_node_'//int2string(rank)//'",useMPIreduce=0,inputfileparameters = "quasi1d_rect_parameters.input",inputfilewhichfiles = "quasi1d_rect_files.input")
file=open(filename,'w')
file.write(rendered_tpl)
file.close()
#print rendered_tpl # prints to terminal instead of file