diff --git a/bin/irpf90 b/bin/irpf90 index e537e26..d9d2360 120000 --- a/bin/irpf90 +++ b/bin/irpf90 @@ -1 +1 @@ -../src/irpf90.exe \ No newline at end of file +../src/irpf90_python.exe \ No newline at end of file diff --git a/example/Makefile b/example/Makefile index 0a69231..2b8aa7f 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,4 +1,4 @@ -IRPF90 = ~/irpf90/bin/irpf90 -a -d +IRPF90 = python ../src/irpf90.py -I input -a -d FC = gfortran FCFLAGS= -O2 diff --git a/man/man1/irpf90.1.gz b/man/man1/irpf90.1.gz index ebc370e..c4212e3 100644 Binary files a/man/man1/irpf90.1.gz and b/man/man1/irpf90.1.gz differ diff --git a/src/command_line.py b/src/command_line.py index 11facfa..4524ecf 100644 --- a/src/command_line.py +++ b/src/command_line.py @@ -73,6 +73,8 @@ class CommandLine(object): self._include_dir = [] for o,a in self.opts: if o in [ "-I", '--'+options['I'][0] ]: + if a[-1] != '/': + a = a+'/' self._include_dir.append(a) return self._include_dir include_dir = property(fget=include_dir) diff --git a/src/init.py b/src/init.py index ceb4719..4fd25d1 100644 --- a/src/init.py +++ b/src/init.py @@ -30,6 +30,7 @@ import os import util import makefile import irpf90_t +from command_line import command_line initialized = False @@ -49,26 +50,34 @@ def init(): except OSError: 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 makefile.create() # Copy current files in the irpdir - for filename in os.listdir(os.getcwd()): - if not filename[0].startswith(".") and not os.path.isdir(filename): - try: - file = open(filename,"r") - except IOError: - print "Warning : Unable to read file %s."%(filename) - else: - buffer = file.readlines() - file.close() - if not util.same_file(irpf90_t.irpdir+filename,buffer): + for dir in ['./']+command_line.include_dir: + for filename in os.listdir(dir): + filename = dir+filename + if not filename[0].startswith(".") and not os.path.isdir(filename): + try: file = open(filename,"r") + except IOError: + print "Warning : Unable to read file %s."%(filename) + else: buffer = file.read() file.close() - file = open(irpf90_t.irpdir+filename,"w") - file.write(buffer) - file.close() + if not util.same_file(irpf90_t.irpdir+filename,buffer): + file = open(irpf90_t.irpdir+filename,"w") + file.write(buffer) + file.close() initialized = True diff --git a/src/irpf90_t.py b/src/irpf90_t.py index 6aaa30a..1068ada 100644 --- a/src/irpf90_t.py +++ b/src/irpf90_t.py @@ -350,10 +350,9 @@ def create_irpf90_files(): return filename.endswith(".irp.f") and not filename.startswith('.') result = filter ( is_irpf90_file, os.listdir(os.getcwd()) ) 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 irpf90_files = create_irpf90_files() -print irpf90_files diff --git a/src/makefile.py b/src/makefile.py index 9cf2858..03ea7fd 100644 --- a/src/makefile.py +++ b/src/makefile.py @@ -68,26 +68,30 @@ def run(): mod.append(m) file = open('irpf90.make','w') - - result = "SRC += %sirp_stack.irp.F90"%(irpdir) + result = "" + 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) if command_line.do_openmp: result += " %sirp_locks.irp.F90"%(irpdir) if command_line.do_profile: result += " %sirp_profile.irp.F90"%(irpdir) for m in mod: - result += " %s%s.irp.F90"%(irpdir,m.name[:-4]) - result += " %s%s.irp.module.F90"%(irpdir,m.name[:-4]) + result += " %s%s.irp.F90"%(irpdir,m.filename) + result += " %s%s.irp.module.F90"%(irpdir,m.filename) 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]) - result += " %s%s.irp.module.o"%(irpdir,m.name[:-4]) + result += " %s%s.irp.o"%(irpdir,m.filename) + result += " %s%s.irp.module.o"%(irpdir,m.filename) 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: print >>file, " %sirp_profile.irp.o"%(irpdir), " irp_rdtsc.o", if command_line.do_openmp: @@ -106,14 +110,14 @@ def run(): print >>file, "ifdef USE_IRPF90_A" for m in mod: 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, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o irpf90.a $(LIB)"%(irpdir,irpdir) print >>file, "\t@$(MAKE) -s move" print >>file, "else" for m in mod: 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, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o $(OBJ1) $(LIB)"%(irpdir,irpdir) print >>file, "\t@$(MAKE) -s move" @@ -121,14 +125,16 @@ def run(): buffer = "" for m in mod: - filename = "%s%s.irp.o: %s%s.irp.module.o"%(irpdir,m.name[:-4],irpdir,m.name[:-4]) - mds = map (lambda x: " %s%s.irp.module.o"%(irpdir,x[:-4]),m.needed_modules) + filename = "%s%s.irp.o: %s%s.irp.module.o"%(irpdir,m.filename,irpdir,m.filename) + 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) if not m.is_main: buffer += "\t - @echo '"+filename+" ".join(mds)+"' >> %sdist_Makefile\n"%(irpdir) print >>file, "%sirp_touches.irp.o:"%(irpdir), 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) if command_line.do_profile: 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- cd dist ; tar -zcvf ../$*.tar.gz $*\n" - print >>file, irpdir+"%.irp.module.o: "+irpdir+"%.irp.module.F90" - print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.module.F90 -o "+irpdir+"$*.irp.module.o" - print >>file, irpdir+"%.irp.o: "+irpdir+"%.irp.module.o "+irpdir+"%.irp.F90" - print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.F90 -o "+irpdir+"$*.irp.o" - 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" + for dir in [ irpdir ] + map(lambda x: irpdir+x, command_line.include_dir): + print >>file, dir+"%.irp.module.o: "+dir+"%.irp.module.F90" + print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.module.F90 -o "+dir+"$*.irp.module.o" + print >>file, dir+"%.irp.o: "+dir+"%.irp.module.o "+dir+"%.irp.F90" + print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o" + print >>file, dir+"%.irp.o: "+dir+"%.irp.F90" + print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o" + print >>file, dir+"%.o: %.F90" + print >>file, "\t$(FC) $(FCFLAGS) -c $*.F90 -o "+dir+"$*.o" + print >>file, dir+"%.o: %.f90\n\t$(FC) $(FCFLAGS) -c $*.f90 -o "+dir+"$*.o" + print >>file, dir+"%.o: %.f\n\t$(FC) $(FCFLAGS) -c $*.f -o "+dir+"$*.o" + 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, "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" diff --git a/src/module.py b/src/module.py index 0711ed4..4bb9f49 100644 --- a/src/module.py +++ b/src/module.py @@ -46,7 +46,8 @@ class Fmodule(object): def __init__(self,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): if '_is_main' not in self.__dict__: diff --git a/src/modules.py b/src/modules.py index ec060a2..2974442 100644 --- a/src/modules.py +++ b/src/modules.py @@ -42,7 +42,7 @@ modules = create_modules() ###################################################################### def write_module(m): # Module data - filename = irpdir+m.name[0:-4]+".irp.module.F90" + filename = irpdir+m.filename+".irp.module.F90" text = m.header + m.head text = map(lambda x: "%s\n"%(x),text) if not same_file(filename,text): @@ -52,7 +52,7 @@ def write_module(m): file.close() # 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 = map(lambda x: "%s\n"%(x),text) if not same_file(filename,text): diff --git a/src/preprocessed_text.py b/src/preprocessed_text.py index 7e7ae4a..4941ea2 100644 --- a/src/preprocessed_text.py +++ b/src/preprocessed_text.py @@ -664,7 +664,11 @@ def change_includes(text): if len(txt) != 3: print txt 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: file = open(filename,'r') file.close() diff --git a/src/util.py b/src/util.py index 54421e3..f5935d2 100644 --- a/src/util.py +++ b/src/util.py @@ -35,7 +35,10 @@ def lower(x): def same_file(filename,txt): assert isinstance(filename,str) - assert type(txt) == list + if (type(txt) == list): + buffer = ''.join(txt) + else: + buffer = txt try: file = open(filename,"r") @@ -44,12 +47,10 @@ def same_file(filename,txt): stream = file.read() file.close() - buffer = ''.join(txt) - if len(stream) != len(buffer): return False if stream != buffer: - return False + return False return True def build_dim(dim): diff --git a/src/variable.py b/src/variable.py index f9eb512..817aba9 100644 --- a/src/variable.py +++ b/src/variable.py @@ -200,7 +200,7 @@ class Variable(object): ############################################################ def fmodule(self): 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 fmodule = property(fmodule) diff --git a/src/version.py b/src/version.py index 26ccef1..253dc6a 100644 --- a/src/version.py +++ b/src/version.py @@ -1 +1 @@ -version = "1.2.22" +version = "1.3.00"