10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-09-02 01:33:42 +02:00

Version:1.1.8

This commit is contained in:
Anthony Scemama 2009-09-09 00:46:42 +02:00
parent 975513a5a2
commit da1125f785
7 changed files with 164 additions and 19 deletions

View File

@ -21,4 +21,16 @@ def main():
import irp_stack
irp_stack.create()
import makefile
makefile.create()
from modules import modules, write_module
for m in modules.keys():
write_module(modules[m])
makefile.run()
import create_man
create_man.run()
main()

View File

@ -6,7 +6,7 @@ mandir = irpf90_t.mandir
FILENAME = "Makefile"
######################################################################
def create():
has_makefile = True
try:
@ -32,3 +32,89 @@ irpf90.make: $(wildcard *.irp.f)
file.write(t)
file.close()
######################################################################
def run():
from modules import modules
mod = []
for m in modules.keys():
mod.append(modules[m])
file = open('irpf90.make','w')
result = "SRC += %sirp_stack.irp.F90"%(irpdir)
for m in mod:
result += " %s%s.irp.F90"%(irpdir,m.name[:-4])
print >>file, result
result = "OBJ += %sirp_stack.irp.o"%(irpdir)
for m in mod:
if not m.is_main:
result += " %s%s.irp.o"%(irpdir,m.name[:-4])
print >>file, result
print >>file, "OBJ1 = $(patsubst %%, %s%%,$(notdir $(OBJ)))"%(irpdir)
all = filter(lambda x: modules[x].is_main, modules)
all = map(lambda x: x[:-6], all)
all_o = map(lambda x: "%s.irp.o"%(x), all)
print >>file, "ALL = %s"%(" ".join(all))
print >>file, "ALL_OBJ = %s"%(" ".join(all_o))
print >>file, "ALL_OBJ1 = $(patsubst %%, %s%%,$(notdir $(ALL_OBJ)))"%(irpdir)
print >>file, "all:$(ALL)"
print >>file, "\t@make -s move"
for m in mod:
if m.is_main:
exe = m.name[:-4]
print >>file, "%s: %s%s.irp.o $(OBJ1)"%(exe,irpdir,exe)
print >>file, "\t$(FC) -o $@ %s$@.irp.o $(OBJ1) $(LIB)"%(irpdir)
print >>file, "\t@make -s move"
buffer = ""
for m in mod:
filename = "%s%s.irp.o:"%(irpdir,m.name[:-4])
mds = map (lambda x: " %s%s.irp.o"%(irpdir,x[:-4]),m.needed_modules)
print >>file, filename+" ".join(mds)
if not m.is_main:
buffer += "\t - @echo '"+filename+" ".join(mds)+"' >> %sdist_Makefile\n"%(irpdir)
print >>file, "%sdist_Makefile:"%(irpdir)
print >>file, "\t- @echo FC=$(FC) > %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo FCFLAGS=$(FCFLAGS) >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo LIB=$(LIB) >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo .DEFAULT_GOAL: exe >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo 'exe: $$(EXE).irp.F90 $(OBJ)' >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo '\t$$(FC) -o $$(EXE) $$(EXE).irp.F90 $(OBJ) $$(LIB)' >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo '%%.o: %%.F90' >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo '\t$$(FC) $$(FCFLAGS) -c $$*.F90 -o $$*.o' >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo 'clean:' >> %sdist_Makefile"%(irpdir)
print >>file, "\t- @echo '\trm *.o *.mod $$(EXE) 2>/dev/null' >> %sdist_Makefile"%(irpdir)
print >>file, buffer
print >>file, "%%.dist: %sdist_Makefile"%(irpdir)
print >>file, "\t- @mkdir -p dist/$*| DO_NOTHING="
print >>file, "\t- @cp %s* dist/$*/| DO_NOTHING="%(irpdir)
print >>file, "\t- @for i in $(ALL) $(OBJ) $(ALL_OBJ); do rm dist/$*/$$i ; done| DO_NOTHING="
print >>file, "\t- @for i in $(ALL) ; do rm dist/$*/$$i.irp.F90 ; done| DO_NOTHING="
print >>file, "\t- @rm dist/$*/{*.irp.f,*.mod,irpf90_entities}| DO_NOTHING="
print >>file, "\t- @rm dist/$*/*.mod 2>/dev/null| DO_NOTHING="
print >>file, "\t- @echo 'EXE = $*' > dist/$*/Makefile| DO_NOTHING="
print >>file, "\t- @cat dist/$*/dist_Makefile >> dist/$*/Makefile| DO_NOTHING="
print >>file, "\t- @rm dist/$*/dist_Makefile| DO_NOTHING="
print >>file, "\t- @cp %s$*.irp.F90 dist/$*/| DO_NOTHING="%(irpdir)
print >>file, "\t- cd dist ; tar -zcvf ../$*.tar.gz $*\n"
print >>file, irpdir+"%.irp.o: "+irpdir+"%.irp.F90"
print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.F90 -o "+irpdir+"$*.irp.o"
print >>file, irpdir+"%.o: %.F90"
print >>file, "\t$(FC) $(FCFLAGS) -c $*.F90 -o "+irpdir+"$*.o"
print >>file, irpdir+"%.o: %.f90\n\t$(FC) $(FCFLAGS) -c $*.f90 -o "+irpdir+"$*.o"
print >>file, irpdir+"%.o: %.f\n\t$(FC) $(FCFLAGS) -c $*.f -o "+irpdir+"$*.o"
print >>file, irpdir+"%.o: %.F\n\t$(FC) $(FCFLAGS) -c $*.F -o "+irpdir+"$*.o"
print >>file, irpdir+"%.irp.F90: irpf90.make\n"
print >>file, "move:\n\t@mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING=\n"
print >>file, "clean:\n\trm -rf $(EXE) $(OBJ1) $(ALL_OBJ1) $(ALL)\n"
print >>file, "veryclean:\n\t- make clean\n"
print >>file, "\t- rm -rf "+irpdir+" "+mandir+" irpf90.make irpf90_variables dist\n"
file.close()

View File

@ -4,21 +4,14 @@ from irpf90_t import *
from variable import *
from variables import variables
import preprocessed_text
from util import *
class Fmodule(object):
def __init__(self,text,filename):
self.text = text
self.text = put_info(text,filename)
self.name = "%s_mod"%(filename[:-6].lower())
def put_info(text):
if len(text) > 0:
lenmax = 80 - len(filename)
format = "%"+str(lenmax)+"s ! %s:%4s"
for vars,line in text:
line.text = format%(line.text.ljust(lenmax),line.filename,str(line.i))
return text
def is_main(self):
if '_is_main' not in self.__dict__:
self._is_main = self.prog_name is not None
@ -45,9 +38,17 @@ class Fmodule(object):
def head(self):
if '_head' not in self.__dict__:
result = [ "module %s"%(self.name) ]
result = [ "! -*- F90 -*-",
"!",
"!-----------------------------------------------!",
"! This file was generated with the irpf90 tool. !",
"! !",
"! DO NOT MODIFY IT BY HAND !",
"!-----------------------------------------------!",
"", "module %s"%(self.name) ]
result += self.use
result += self.dec
result += flatten( map(lambda x: variables[x].header,self.variables) )
result.append( "end module %s"%(self.name) )
self._head = result
return self._head
@ -97,6 +98,7 @@ class Fmodule(object):
def modify_functions(text):
result = []
variable_list = []
for vars,line in text:
if type(line) in [ Subroutine, Function ]:
variable_list = list(vars)
@ -128,12 +130,14 @@ class Fmodule(object):
result = remove_providers(self.text)
result = modify_functions(result)
result = preprocessed_text.move_to_top(result,Declaration)
result = preprocessed_text.move_to_top(result,Use)
use,dec,result = extract_use_dec_text(result)
self._use = make_single(map(lambda x: " "+x[1].text, use))
self._dec = make_single(map(lambda x: " "+x[1].text, dec))
result = map(lambda x: " "+x[1].text, result)
result = map(lambda x: x[1], result)
result = preprocessed_text.move_to_top(result,Declaration)
result = preprocessed_text.move_to_top(result,Implicit)
result = preprocessed_text.move_to_top(result,Use)
result = map(lambda x: x.text, result)
if self.is_main:
result = [ \
"program irp_program",
@ -159,17 +163,20 @@ class Fmodule(object):
def needed_modules(self):
if '_needed_modules' not in self.__dict__:
buffer = filter(lambda x: isinstance(x,Use), self.generated_text)
buffer += filter(lambda x: isinstance(x,Use), self.head)
buffer += filter(lambda x: isinstance(x,Use), self.residual_text)
buffer = map(lambda x: x.text.split()[1].lower(), buffer)
self._needed_modules = make_single(buffer)
return self._needed_modules
needed_modules = property(needed_modules)
######################################################################
if __name__ == '__main__':
from parsed_text import parsed_text
for filename, text in parsed_text:
if filename == 'random.irp.f':
x = Fmodule(text,filename)
break
for line in x.residual_text:
for line in x.head:
print line

View File

@ -1,5 +1,32 @@
#!/usr/bin/python
def residual_text():
pass
from irpf90_t import *
from parsed_text import parsed_text
from module import Fmodule
from util import *
######################################################################
def create_modules():
result = {}
for filename,text in parsed_text:
result[filename] = Fmodule(text,filename)
return result
modules = create_modules()
######################################################################
def write_module(m):
filename = irpdir+m.name[0:-4]+".irp.F90"
text = m.head + m.generated_text + m.residual_text
text = map(lambda x: "%s\n"%(x),text)
if not same_file(filename,text):
print filename
file = open(filename,"w")
file.writelines(text)
file.close()
######################################################################
if __name__ == '__main__':
write_module(modules['electrons.irp.f'])

View File

@ -78,6 +78,19 @@ def dimsize(x):
size = "%s - %s + 1"%(b1,b0)
return size
def put_info(text,filename):
assert isinstance(text,list)
if len(text) > 0:
assert isinstance(text[0],tuple)
from irpf90_t import Line
assert isinstance(text[0][0],list)
assert isinstance(text[0][1],Line)
lenmax = 80 - len(filename)
format = "%"+str(lenmax)+"s ! %s:%4s"
for vars,line in text:
line.text = format%(line.text.ljust(lenmax),line.filename,str(line.i))
return text
if __name__ == '__main__':
print "10",dimsize("10") #-> "10"
print "0:10",dimsize("0:10") # -> "11"

View File

@ -98,7 +98,7 @@ class Variable(object):
############################################################
def dim(self):
if '_dim' not in self.__dict__:
line = self.line.text
line = self.line.text.split('!')[0]
buffer = line.replace(']','').split(',',2)
if len(buffer) == 2:
self._dim = []

View File

@ -1 +1 @@
version = "1.1.7"
version = "1.1.8"