10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-22 04:13:33 +01:00

Added -I option

This commit is contained in:
Anthony Scemama 2013-12-11 14:00:27 +01:00
parent efd67d12f9
commit fd3b743792
13 changed files with 74 additions and 51 deletions

View File

@ -1 +1 @@
../src/irpf90.exe ../src/irpf90_python.exe

View File

@ -1,4 +1,4 @@
IRPF90 = ~/irpf90/bin/irpf90 -a -d IRPF90 = python ../src/irpf90.py -I input -a -d
FC = gfortran FC = gfortran
FCFLAGS= -O2 FCFLAGS= -O2

Binary file not shown.

View File

@ -73,6 +73,8 @@ class CommandLine(object):
self._include_dir = [] self._include_dir = []
for o,a in self.opts: for o,a in self.opts:
if o in [ "-I", '--'+options['I'][0] ]: if o in [ "-I", '--'+options['I'][0] ]:
if a[-1] != '/':
a = a+'/'
self._include_dir.append(a) self._include_dir.append(a)
return self._include_dir return self._include_dir
include_dir = property(fget=include_dir) include_dir = property(fget=include_dir)

View File

@ -30,6 +30,7 @@ import os
import util import util
import makefile import makefile
import irpf90_t import irpf90_t
from command_line import command_line
initialized = False initialized = False
@ -49,26 +50,34 @@ def init():
except OSError: except OSError:
os.mkdir(dir) os.mkdir(dir)
for dir in command_line.include_dir:
dir = irpf90_t.irpdir+dir
try:
wd = os.getcwd()
os.chdir(dir)
os.chdir(wd)
except OSError:
os.mkdir(dir)
# Create makefile # Create makefile
makefile.create() makefile.create()
# Copy current files in the irpdir # Copy current files in the irpdir
for filename in os.listdir(os.getcwd()): for dir in ['./']+command_line.include_dir:
if not filename[0].startswith(".") and not os.path.isdir(filename): for filename in os.listdir(dir):
try: filename = dir+filename
file = open(filename,"r") if not filename[0].startswith(".") and not os.path.isdir(filename):
except IOError: try:
print "Warning : Unable to read file %s."%(filename)
else:
buffer = file.readlines()
file.close()
if not util.same_file(irpf90_t.irpdir+filename,buffer):
file = open(filename,"r") file = open(filename,"r")
except IOError:
print "Warning : Unable to read file %s."%(filename)
else:
buffer = file.read() buffer = file.read()
file.close() file.close()
file = open(irpf90_t.irpdir+filename,"w") if not util.same_file(irpf90_t.irpdir+filename,buffer):
file.write(buffer) file = open(irpf90_t.irpdir+filename,"w")
file.close() file.write(buffer)
file.close()
initialized = True initialized = True

View File

@ -350,10 +350,9 @@ def create_irpf90_files():
return filename.endswith(".irp.f") and not filename.startswith('.') return filename.endswith(".irp.f") and not filename.startswith('.')
result = filter ( is_irpf90_file, os.listdir(os.getcwd()) ) result = filter ( is_irpf90_file, os.listdir(os.getcwd()) )
for dir in command_line.include_dir: for dir in command_line.include_dir:
result += map(lambda x: dir+'/'+x, filter ( is_irpf90_file, os.listdir(dir) ) ) result += map(lambda x: dir+x, filter ( is_irpf90_file, os.listdir(dir) ) )
return result return result
irpf90_files = create_irpf90_files() irpf90_files = create_irpf90_files()
print irpf90_files

View File

@ -68,26 +68,30 @@ def run():
mod.append(m) mod.append(m)
file = open('irpf90.make','w') file = open('irpf90.make','w')
result = ""
result = "SRC += %sirp_stack.irp.F90"%(irpdir) result += "FC+=-I %s "%(irpdir)
for i in command_line.include_dir:
result += "-I %s%s "%(irpdir,i)
result += "\n"
result += "SRC += %sirp_stack.irp.F90"%(irpdir)
result += " %sirp_touches.irp.F90"%(irpdir) result += " %sirp_touches.irp.F90"%(irpdir)
if command_line.do_openmp: if command_line.do_openmp:
result += " %sirp_locks.irp.F90"%(irpdir) result += " %sirp_locks.irp.F90"%(irpdir)
if command_line.do_profile: if command_line.do_profile:
result += " %sirp_profile.irp.F90"%(irpdir) result += " %sirp_profile.irp.F90"%(irpdir)
for m in mod: for m in mod:
result += " %s%s.irp.F90"%(irpdir,m.name[:-4]) result += " %s%s.irp.F90"%(irpdir,m.filename)
result += " %s%s.irp.module.F90"%(irpdir,m.name[:-4]) result += " %s%s.irp.module.F90"%(irpdir,m.filename)
print >>file, result print >>file, result
result = "OBJ += %sirp_stack.irp.o"%(irpdir) result = "OBJ += %sirp_stack.irp.o"%(irpdir)
for m in mod: for m in mod:
if not m.is_main: if not m.is_main:
result += " %s%s.irp.o"%(irpdir,m.name[:-4]) result += " %s%s.irp.o"%(irpdir,m.filename)
result += " %s%s.irp.module.o"%(irpdir,m.name[:-4]) result += " %s%s.irp.module.o"%(irpdir,m.filename)
print >>file, result print >>file, result
print >>file, "OBJ1 = $(patsubst %%, %s%%,$(notdir $(OBJ))) %sirp_touches.irp.o"%(irpdir,irpdir), print >>file, "OBJ1 = $(OBJ) %sirp_touches.irp.o"%(irpdir),
if command_line.do_profile: if command_line.do_profile:
print >>file, " %sirp_profile.irp.o"%(irpdir), " irp_rdtsc.o", print >>file, " %sirp_profile.irp.o"%(irpdir), " irp_rdtsc.o",
if command_line.do_openmp: if command_line.do_openmp:
@ -106,14 +110,14 @@ def run():
print >>file, "ifdef USE_IRPF90_A" print >>file, "ifdef USE_IRPF90_A"
for m in mod: for m in mod:
if m.is_main: if m.is_main:
exe = m.name[:-4] exe = m.filename
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o irpf90.a"%(exe,irpdir,exe,irpdir,exe) print >>file, "%s: %s%s.irp.o %s%s.irp.module.o irpf90.a"%(exe,irpdir,exe,irpdir,exe)
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o irpf90.a $(LIB)"%(irpdir,irpdir) print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o irpf90.a $(LIB)"%(irpdir,irpdir)
print >>file, "\t@$(MAKE) -s move" print >>file, "\t@$(MAKE) -s move"
print >>file, "else" print >>file, "else"
for m in mod: for m in mod:
if m.is_main: if m.is_main:
exe = m.name[:-4] exe = m.filename
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o $(OBJ1)"%(exe,irpdir,exe,irpdir,exe) print >>file, "%s: %s%s.irp.o %s%s.irp.module.o $(OBJ1)"%(exe,irpdir,exe,irpdir,exe)
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o $(OBJ1) $(LIB)"%(irpdir,irpdir) print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o $(OBJ1) $(LIB)"%(irpdir,irpdir)
print >>file, "\t@$(MAKE) -s move" print >>file, "\t@$(MAKE) -s move"
@ -121,14 +125,16 @@ def run():
buffer = "" buffer = ""
for m in mod: for m in mod:
filename = "%s%s.irp.o: %s%s.irp.module.o"%(irpdir,m.name[:-4],irpdir,m.name[:-4]) filename = "%s%s.irp.o: %s%s.irp.module.o"%(irpdir,m.filename,irpdir,m.filename)
mds = map (lambda x: " %s%s.irp.module.o"%(irpdir,x[:-4]),m.needed_modules) needed_modules = filter( lambda x: modules[x].name in m.needed_modules, modules )
needed_files = map(lambda x: modules[x].filename, needed_modules)
mds = map (lambda x: " %s%s.irp.module.o"%(irpdir,x),needed_files)
print >>file, filename," ".join(mds)," ".join(m.includes) print >>file, filename," ".join(mds)," ".join(m.includes)
if not m.is_main: if not m.is_main:
buffer += "\t - @echo '"+filename+" ".join(mds)+"' >> %sdist_Makefile\n"%(irpdir) buffer += "\t - @echo '"+filename+" ".join(mds)+"' >> %sdist_Makefile\n"%(irpdir)
print >>file, "%sirp_touches.irp.o:"%(irpdir), print >>file, "%sirp_touches.irp.o:"%(irpdir),
mds = filter(lambda x: not x.is_main,mod) mds = filter(lambda x: not x.is_main,mod)
mds = map(lambda x: " %s%s.irp.o %s%s.irp.o"%(irpdir,x.name[:-4],irpdir,x.name[:-4]),mds) mds = map(lambda x: " %s%s.irp.o %s%s.irp.o"%(irpdir,x.filename,irpdir,x.filename),mds)
print >>file," ".join(mds) print >>file," ".join(mds)
if command_line.do_profile: if command_line.do_profile:
print >>file, "%sirp_profile.irp.o:"%(irpdir), print >>file, "%sirp_profile.irp.o:"%(irpdir),
@ -165,18 +171,19 @@ def run():
# print >>file, "\t- @cp %s$*.irp.F90 dist/$*/| DO_NOTHING="%(irpdir) # print >>file, "\t- @cp %s$*.irp.F90 dist/$*/| DO_NOTHING="%(irpdir)
# print >>file, "\t- cd dist ; tar -zcvf ../$*.tar.gz $*\n" # print >>file, "\t- cd dist ; tar -zcvf ../$*.tar.gz $*\n"
print >>file, irpdir+"%.irp.module.o: "+irpdir+"%.irp.module.F90" for dir in [ irpdir ] + map(lambda x: irpdir+x, command_line.include_dir):
print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.module.F90 -o "+irpdir+"$*.irp.module.o" print >>file, dir+"%.irp.module.o: "+dir+"%.irp.module.F90"
print >>file, irpdir+"%.irp.o: "+irpdir+"%.irp.module.o "+irpdir+"%.irp.F90" print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.module.F90 -o "+dir+"$*.irp.module.o"
print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.F90 -o "+irpdir+"$*.irp.o" print >>file, dir+"%.irp.o: "+dir+"%.irp.module.o "+dir+"%.irp.F90"
print >>file, irpdir+"%.irp.o: "+irpdir+"%.irp.F90" print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o"
print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.F90 -o "+irpdir+"$*.irp.o" print >>file, dir+"%.irp.o: "+dir+"%.irp.F90"
print >>file, irpdir+"%.o: %.F90" print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o"
print >>file, "\t$(FC) $(FCFLAGS) -c $*.F90 -o "+irpdir+"$*.o" print >>file, dir+"%.o: %.F90"
print >>file, irpdir+"%.o: %.f90\n\t$(FC) $(FCFLAGS) -c $*.f90 -o "+irpdir+"$*.o" print >>file, "\t$(FC) $(FCFLAGS) -c $*.F90 -o "+dir+"$*.o"
print >>file, irpdir+"%.o: %.f\n\t$(FC) $(FCFLAGS) -c $*.f -o "+irpdir+"$*.o" print >>file, dir+"%.o: %.f90\n\t$(FC) $(FCFLAGS) -c $*.f90 -o "+dir+"$*.o"
print >>file, irpdir+"%.o: %.F\n\t$(FC) $(FCFLAGS) -c $*.F -o "+irpdir+"$*.o" print >>file, dir+"%.o: %.f\n\t$(FC) $(FCFLAGS) -c $*.f -o "+dir+"$*.o"
print >>file, irpdir+"%.irp.F90: irpf90.make\n" print >>file, dir+"%.o: %.F\n\t$(FC) $(FCFLAGS) -c $*.F -o "+dir+"$*.o"
print >>file, dir+"%.irp.F90: irpf90.make\n"
print >>file, "move:\n\t@mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING=\n" print >>file, "move:\n\t@mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING=\n"
print >>file, "irpf90.a: $(OBJ1)\n\t$(AR) crf irpf90.a $(OBJ1)\n" print >>file, "irpf90.a: $(OBJ1)\n\t$(AR) crf irpf90.a $(OBJ1)\n"
print >>file, "clean:\n\trm -rf $(EXE) $(OBJ1) irpf90.a $(ALL_OBJ1) $(ALL)\n" print >>file, "clean:\n\trm -rf $(EXE) $(OBJ1) irpf90.a $(ALL_OBJ1) $(ALL)\n"

View File

@ -46,7 +46,8 @@ class Fmodule(object):
def __init__(self,text,filename): def __init__(self,text,filename):
self.text = put_info(text,filename) self.text = put_info(text,filename)
self.name = "%s_mod"%(filename[:-6]) self.filename = filename[:-6]
self.name = "%s_mod"%(self.filename).replace('/','__')
def is_main(self): def is_main(self):
if '_is_main' not in self.__dict__: if '_is_main' not in self.__dict__:

View File

@ -42,7 +42,7 @@ modules = create_modules()
###################################################################### ######################################################################
def write_module(m): def write_module(m):
# Module data # Module data
filename = irpdir+m.name[0:-4]+".irp.module.F90" filename = irpdir+m.filename+".irp.module.F90"
text = m.header + m.head text = m.header + m.head
text = map(lambda x: "%s\n"%(x),text) text = map(lambda x: "%s\n"%(x),text)
if not same_file(filename,text): if not same_file(filename,text):
@ -52,7 +52,7 @@ def write_module(m):
file.close() file.close()
# Subroutines # Subroutines
filename = irpdir+m.name[0:-4]+".irp.F90" filename = irpdir+m.filename+".irp.F90"
text = m.header + m.generated_text + m.residual_text text = m.header + m.generated_text + m.residual_text
text = map(lambda x: "%s\n"%(x),text) text = map(lambda x: "%s\n"%(x),text)
if not same_file(filename,text): if not same_file(filename,text):

View File

@ -664,7 +664,11 @@ def change_includes(text):
if len(txt) != 3: if len(txt) != 3:
print txt print txt
error.fail(line,"Error in include statement") error.fail(line,"Error in include statement")
filename = txt[1].strip() directory = (("./"+line.filename).rsplit('/',1)[0]+'/')[2:]
if directory == "":
filename = txt[1].strip()
else:
filename = directory+txt[1].strip()
try: try:
file = open(filename,'r') file = open(filename,'r')
file.close() file.close()

View File

@ -35,7 +35,10 @@ def lower(x):
def same_file(filename,txt): def same_file(filename,txt):
assert isinstance(filename,str) assert isinstance(filename,str)
assert type(txt) == list if (type(txt) == list):
buffer = ''.join(txt)
else:
buffer = txt
try: try:
file = open(filename,"r") file = open(filename,"r")
@ -44,12 +47,10 @@ def same_file(filename,txt):
stream = file.read() stream = file.read()
file.close() file.close()
buffer = ''.join(txt)
if len(stream) != len(buffer): if len(stream) != len(buffer):
return False return False
if stream != buffer: if stream != buffer:
return False return False
return True return True
def build_dim(dim): def build_dim(dim):

View File

@ -200,7 +200,7 @@ class Variable(object):
############################################################ ############################################################
def fmodule(self): def fmodule(self):
if '_fmodule' not in self.__dict__: if '_fmodule' not in self.__dict__:
self._fmodule = self.line.filename[0].split('.irp.f')[0]+'_mod' self._fmodule = self.line.filename[0].replace('/','__').split('.irp.f')[0]+'_mod'
return self._fmodule return self._fmodule
fmodule = property(fmodule) fmodule = property(fmodule)

View File

@ -1 +1 @@
version = "1.2.22" version = "1.3.00"