mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-12-21 11:53:32 +01:00
Version:1.1.10
This commit is contained in:
parent
63a49efe15
commit
98e97dbe22
@ -10,7 +10,7 @@ class Fmodule(object):
|
||||
|
||||
def __init__(self,text,filename):
|
||||
self.text = put_info(text,filename)
|
||||
self.name = "%s_mod"%(filename[:-6].lower())
|
||||
self.name = "%s_mod"%(filename[:-6])
|
||||
|
||||
def is_main(self):
|
||||
if '_is_main' not in self.__dict__:
|
||||
@ -69,8 +69,6 @@ class Fmodule(object):
|
||||
var = variables[var]
|
||||
result += var.provider
|
||||
result += var.builder
|
||||
if var.is_freed:
|
||||
result += var.free
|
||||
if var.is_touched:
|
||||
result += var.toucher
|
||||
if var.is_read:
|
||||
@ -84,6 +82,7 @@ class Fmodule(object):
|
||||
def residual_text(self):
|
||||
if '_residual_text' not in self.__dict__:
|
||||
from variables import build_use
|
||||
from parsed_text import move_to_top
|
||||
def remove_providers(text):
|
||||
result = []
|
||||
inside = False
|
||||
@ -128,21 +127,29 @@ class Fmodule(object):
|
||||
inside = False
|
||||
return use, dec, result
|
||||
|
||||
def provide_variables(text):
|
||||
result = []
|
||||
for vars,line in text:
|
||||
result.append( ([],line) )
|
||||
result += map(lambda x: ([],Simple_line(line.i," call provide_%s"%(x),line.filename)), vars)
|
||||
return result
|
||||
|
||||
result = remove_providers(self.text)
|
||||
result = modify_functions(result)
|
||||
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 = provide_variables(result)
|
||||
result = move_to_top(result,Declaration)
|
||||
result = move_to_top(result,Implicit)
|
||||
result = move_to_top(result,Use)
|
||||
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",
|
||||
" call %s"%(self.prog_name),
|
||||
"end irp_program",
|
||||
"end program",
|
||||
] + result
|
||||
self._residual_text = result
|
||||
return self._residual_text
|
||||
|
@ -14,8 +14,9 @@ def find_variables_in_line(line):
|
||||
buffer = regexps.re_string.sub('',line.text)
|
||||
for v in variables.keys():
|
||||
var = variables[v]
|
||||
if var.regexp.search(buffer) is not None:
|
||||
result.append(var.name)
|
||||
if var.name in buffer.lower():
|
||||
if var.regexp.search(buffer) is not None:
|
||||
result.append(var.same_as)
|
||||
return result
|
||||
|
||||
def find_subroutine_in_line(line):
|
||||
@ -72,6 +73,9 @@ def get_parsed_text():
|
||||
elif isinstance(line,Provide):
|
||||
l = line.text.lower().split()[1:]
|
||||
l = filter(lambda x: x not in varlist, l)
|
||||
for v in l:
|
||||
if v not in variables.keys():
|
||||
error.fail(line,"Variable %s is unknown"%(v))
|
||||
result.append( (l,Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
elif isinstance(line,Call):
|
||||
sub = find_subroutine_in_line(line)
|
||||
@ -82,7 +86,9 @@ def get_parsed_text():
|
||||
t = Simple_line
|
||||
else:
|
||||
t = Provide_all
|
||||
result.append( ([],t(line.i,line.text,line.filename)) )
|
||||
l = find_variables_in_line(line)
|
||||
l = filter(lambda x: x not in varlist, l)
|
||||
result.append( (l,t(line.i,line.text,line.filename)) )
|
||||
elif isinstance(line,Free):
|
||||
vars = line.text.split()
|
||||
if len(vars) < 2:
|
||||
@ -91,9 +97,12 @@ def get_parsed_text():
|
||||
for v in vars:
|
||||
variables[v].is_freed = True
|
||||
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
use = map(lambda x: " use %s"%(variables[x].fmodule),vars)
|
||||
for var in vars:
|
||||
result.append( ([],Simple_line(line.i," call free_%s"%var,
|
||||
line.filename)) )
|
||||
result += map(lambda x: ([],Use(line.i,x,line.filename)),
|
||||
make_single(use))
|
||||
result += map(lambda x: ([],Simple_line(line.i,x,line.filename)),
|
||||
variables[var].free)
|
||||
elif isinstance(line,Irp_read):
|
||||
variables[line.filename].is_read = True
|
||||
result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) )
|
||||
@ -106,7 +115,7 @@ def get_parsed_text():
|
||||
error.fail(line,"Syntax error")
|
||||
vars = map(lower,vars[1:])
|
||||
for v in vars:
|
||||
variables[v].is_touched = True
|
||||
variables[v]._is_touched = True
|
||||
def fun(x):
|
||||
if x not in variables:
|
||||
error.fail(line,"Variable %s unknown"%(x,))
|
||||
@ -121,7 +130,8 @@ def get_parsed_text():
|
||||
if x not in variables:
|
||||
error.fail(line,"Variable %s unknown"%(x,))
|
||||
return [ ([],Simple_line(line.i," call touch_%s"%(x,),line.filename)),
|
||||
([],Simple_line(line.i," %s_is_built = .True."%(x,),line.filename)) ]
|
||||
([],Simple_line(line.i," %s_is_built = .True."%(x,),line.filename)),
|
||||
([],Use(line.i," use %s"%(variables[x].fmodule), line.filename)) ]
|
||||
result += flatten(map( fun, main_vars ))
|
||||
def fun(x):
|
||||
if x not in variables:
|
||||
@ -137,7 +147,7 @@ def get_parsed_text():
|
||||
v = buffer[1].lower()
|
||||
varlist.append(v)
|
||||
variable_list = find_variables_in_line(line)
|
||||
variable_list.remove(v)
|
||||
variable_list.remove(variables[v].same_as)
|
||||
result.append( (variable_list,line) )
|
||||
else:
|
||||
l = find_variables_in_line(line)
|
||||
@ -242,10 +252,33 @@ def move_variables():
|
||||
|
||||
parsed_text = move_variables()
|
||||
|
||||
######################################################################
|
||||
def move_to_top(text,t):
|
||||
assert isinstance(text,list)
|
||||
assert t in [ Declaration, Implicit, Use, Cont_provider ]
|
||||
|
||||
inside = False
|
||||
for i in range(len(text)):
|
||||
vars, line = text[i]
|
||||
if type(line) in [ Begin_provider, Subroutine, Function ]:
|
||||
begin = i
|
||||
inside = True
|
||||
elif type(line) in [ End_provider, End ]:
|
||||
inside = False
|
||||
elif isinstance(line,t):
|
||||
if inside:
|
||||
text.pop(i)
|
||||
begin += 1
|
||||
text.insert(begin,(vars,line))
|
||||
|
||||
return text
|
||||
|
||||
|
||||
######################################################################
|
||||
def build_needs():
|
||||
# Needs
|
||||
for filename, text in parsed_text:
|
||||
var = None
|
||||
for vars,line in text:
|
||||
if isinstance(line,Begin_provider):
|
||||
buffer = map(strip,line.text.replace(']',',').split(','))
|
||||
@ -273,8 +306,9 @@ def build_needs():
|
||||
variables[v].needed_by = variables[main].needed_by
|
||||
for v in variables.keys():
|
||||
var = variables[v]
|
||||
for x in var.needs:
|
||||
variables[x].needed_by.append(var.same_as)
|
||||
if var.is_main:
|
||||
for x in var.needs:
|
||||
variables[x].needed_by.append(var.same_as)
|
||||
for v in variables.keys():
|
||||
var = variables[v]
|
||||
var.needed_by = make_single(var.needed_by)
|
||||
@ -282,11 +316,21 @@ def build_needs():
|
||||
|
||||
build_needs()
|
||||
|
||||
result = []
|
||||
for filename,text in parsed_text:
|
||||
text = move_to_top(text,Declaration)
|
||||
text = move_to_top(text,Implicit)
|
||||
text = move_to_top(text,Use)
|
||||
text = move_to_top(text,Cont_provider)
|
||||
result.append ( (filename,text) )
|
||||
parsed_text = result
|
||||
|
||||
######################################################################
|
||||
if __name__ == '__main__':
|
||||
for i in range(len(parsed_text)):
|
||||
if parsed_text[i][0] == 'mpi.irp.f':
|
||||
print '!-------- %s -----------'%(parsed_text[i][0])
|
||||
for line in parsed_text[i][1]:
|
||||
print line[1]
|
||||
print line[0]
|
||||
print line[0], line[1].filename
|
||||
|
||||
|
@ -111,7 +111,7 @@ def get_type (i, filename, line, is_doc):
|
||||
|
||||
if firstword[0] == '#':
|
||||
result = [ Simple_line(i,line,filename) ]
|
||||
error.warn ( result ,
|
||||
error.warn ( result[0] ,
|
||||
"""irpf90 may not work with preprocessor directives. You can use
|
||||
Irp_if ... Irp_else ... Irp_endif
|
||||
instead of
|
||||
@ -361,7 +361,7 @@ def irp_simple_statements(text):
|
||||
def process_assert(line):
|
||||
assert isinstance(line,Assert)
|
||||
if command_line.do_assert:
|
||||
condition = line.text.split(None,1)[1]
|
||||
condition = "(%s"%(line.text.split('(',1)[1])
|
||||
if condition == "":
|
||||
error.fail(line,"Error in Assert statement")
|
||||
condition_str = condition.replace("'","''")
|
||||
@ -411,14 +411,26 @@ def irp_simple_statements(text):
|
||||
length = len(varname)
|
||||
i = line.i
|
||||
f = line.filename
|
||||
result = [ line,
|
||||
Declaration(i," character*(%d), parameter :: irp_here = '%s'"%(length,varname), f) ]
|
||||
result = [ Begin_provider(i,line.text, (f,varname)),
|
||||
Declaration(i," character*(%d), parameter :: irp_here = '%s'"%(length,varname), filename) ]
|
||||
if command_line.do_assert or command_line.do_debug:
|
||||
result += [
|
||||
Simple_line(i," call irp_enter(irp_here)", f),
|
||||
]
|
||||
return result
|
||||
|
||||
def process_cont_provider(line):
|
||||
assert isinstance(line,Cont_provider)
|
||||
buffer = line.text.replace('['," ")
|
||||
buffer = buffer.replace(']',"")
|
||||
buffer = buffer.split(',')
|
||||
if len(buffer) < 2:
|
||||
error.fail(line,"Error in Cont_provider statement")
|
||||
varname = buffer[1].strip().lower()
|
||||
i = line.i
|
||||
f = line.filename
|
||||
return [ Cont_provider(i,line.text,(f,varname)) ]
|
||||
|
||||
def process_subroutine(line):
|
||||
assert isinstance(line,Subroutine)
|
||||
subname = find_subname(line)
|
||||
@ -462,11 +474,11 @@ def irp_simple_statements(text):
|
||||
Assert : process_assert,
|
||||
End : process_end,
|
||||
Begin_provider : process_begin_provider,
|
||||
Cont_provider : process_cont_provider,
|
||||
End_provider : process_end,
|
||||
Subroutine : process_subroutine,
|
||||
Function : process_function,
|
||||
Program : process_program,
|
||||
Provide : process_provide,
|
||||
}
|
||||
|
||||
result = []
|
||||
@ -661,27 +673,6 @@ def remove_ifdefs(text):
|
||||
result.append(line)
|
||||
return result
|
||||
|
||||
######################################################################
|
||||
def move_to_top(text,t):
|
||||
assert isinstance(text,list)
|
||||
assert t in [ Declaration, Implicit, Use, Cont_provider ]
|
||||
|
||||
inside = False
|
||||
for i in range(len(text)):
|
||||
line = text[i]
|
||||
if type(line) in [ Begin_provider, Subroutine, Function ]:
|
||||
begin = i
|
||||
inside = True
|
||||
elif type(line) in [ End_provider, End ]:
|
||||
inside = False
|
||||
elif isinstance(line,t):
|
||||
if inside:
|
||||
text.pop(i)
|
||||
begin += 1
|
||||
text.insert(begin,line)
|
||||
|
||||
return text
|
||||
|
||||
######################################################################
|
||||
def create_preprocessed_text(filename):
|
||||
file = open(filename,"r")
|
||||
@ -697,10 +688,6 @@ def create_preprocessed_text(filename):
|
||||
result = change_single_line_ifs(result)
|
||||
result = process_old_style_do(result)
|
||||
result = irp_simple_statements(result)
|
||||
result = move_to_top(result,Declaration)
|
||||
result = move_to_top(result,Implicit)
|
||||
result = move_to_top(result,Use)
|
||||
result = move_to_top(result,Cont_provider)
|
||||
return result
|
||||
|
||||
######################################################################
|
||||
|
@ -24,14 +24,7 @@ re_decl = re.compile( "".join( [ r"^\ *",
|
||||
r")[^=(]"
|
||||
] ) )
|
||||
|
||||
re_left = re.compile(r"\[")
|
||||
re_right = re.compile(r"\]")
|
||||
|
||||
re_test = re.compile(r"\( *(.*)(\.[a-zA-Z]*\.|[<>]=?|[=/]=)([^=]*)\)")
|
||||
|
||||
re_space = re.compile("\s")
|
||||
|
||||
re_string = re.compile(r"'.*'")
|
||||
re_assert = re.compile(r"assert *",re.I)
|
||||
re_check = re.compile(r".*[() ].*")
|
||||
|
||||
|
@ -58,7 +58,7 @@ class Sub(object):
|
||||
if '_regexp' not in self.__dict__:
|
||||
import re
|
||||
self._regexp = re.compile( \
|
||||
r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I)
|
||||
r"([^a-z0-9'\"_]|^)%s([^a-z0-9_]|$)"%(self.name),re.I)
|
||||
return self._regexp
|
||||
regexp = property(regexp)
|
||||
|
||||
|
314
src/variable.py
314
src/variable.py
@ -15,10 +15,30 @@ class Variable(object):
|
||||
self.text = text
|
||||
if name is not None:
|
||||
self._name = name.lower()
|
||||
self.is_freed = False
|
||||
self.is_read = False
|
||||
self.is_written = False
|
||||
self.is_touched = False
|
||||
|
||||
############################################################
|
||||
def is_touched(self):
|
||||
'''Name is lowercase'''
|
||||
if '_is_touched' not in self.__dict__:
|
||||
from variables import variables
|
||||
result = True # False
|
||||
#for i in self.children:
|
||||
# if variables[i].is_touched:
|
||||
# result = True
|
||||
# break
|
||||
self._is_touched = result
|
||||
return self._is_touched
|
||||
is_touched = property(is_touched)
|
||||
|
||||
############################################################
|
||||
def is_main(self):
|
||||
'''Name is lowercase'''
|
||||
if '_is_main' not in self.__dict__:
|
||||
self._is_main = (self.name == self.same_as)
|
||||
return self._is_main
|
||||
is_main = property(is_main)
|
||||
|
||||
############################################################
|
||||
def name(self):
|
||||
@ -27,12 +47,8 @@ class Variable(object):
|
||||
buffer = None
|
||||
for line in self.text:
|
||||
if isinstance(line,Begin_provider):
|
||||
buffer = line.text.replace(']',',').split(',')
|
||||
self._name = line.filename[1]
|
||||
break
|
||||
assert buffer is not None
|
||||
if len(buffer) < 3:
|
||||
error.fail(line, "Error in Begin_provider line")
|
||||
self._name = buffer[1].strip().lower()
|
||||
return self._name
|
||||
name = property(name)
|
||||
|
||||
@ -61,11 +77,7 @@ class Variable(object):
|
||||
f = lambda l: type(l) in [Begin_provider, Cont_provider]
|
||||
lines = filter(f, self.text)
|
||||
for line in lines:
|
||||
buffer = line.text.replace(']',',').split(',')
|
||||
if len(buffer) < 3:
|
||||
error.fail(line,"Syntax Error")
|
||||
buffer = buffer[1].strip().lower()
|
||||
result.append(buffer)
|
||||
result.append(line.filename[1])
|
||||
result.remove(self.name)
|
||||
self._others = result
|
||||
return self._others
|
||||
@ -77,10 +89,7 @@ class Variable(object):
|
||||
if isinstance(self.line,Begin_provider):
|
||||
result = self.name
|
||||
else:
|
||||
buffer = self.text[0].text.replace(']',',').split(',')
|
||||
if len(buffer) < 3:
|
||||
error.fail(line,"Syntax Error")
|
||||
result = buffer[1].strip().lower()
|
||||
result = self.text[0].filename[1]
|
||||
self._same_as = result
|
||||
return self._same_as
|
||||
same_as = property(same_as)
|
||||
@ -88,10 +97,13 @@ class Variable(object):
|
||||
############################################################
|
||||
def allocate(self):
|
||||
if '_allocate' not in self.__dict__:
|
||||
from variables import variables
|
||||
def f(var):
|
||||
return variables[var].dim != []
|
||||
self._allocate = filter ( f, self.others + [self.name] )
|
||||
if not self.is_main:
|
||||
self._allocate = []
|
||||
else:
|
||||
from variables import variables
|
||||
def f(var):
|
||||
return variables[var].dim != []
|
||||
self._allocate = filter ( f, self.others + [self.name] )
|
||||
return self._allocate
|
||||
allocate = property(allocate)
|
||||
|
||||
@ -114,7 +126,7 @@ class Variable(object):
|
||||
line = self.line.text
|
||||
buffer = line.split(',')[0]
|
||||
buffer = buffer.split('[')[1].strip()
|
||||
if self.dim != '':
|
||||
if self.dim != []:
|
||||
buffer = "%s, allocatable"%(buffer)
|
||||
self._type = buffer
|
||||
return self._type
|
||||
@ -123,7 +135,7 @@ class Variable(object):
|
||||
############################################################
|
||||
def fmodule(self):
|
||||
if '_fmodule' not in self.__dict__:
|
||||
self._fmodule = self.line.filename.split('.irp.f')[0]+'_mod'
|
||||
self._fmodule = self.line.filename[0].split('.irp.f')[0]+'_mod'
|
||||
return self._fmodule
|
||||
fmodule = property(fmodule)
|
||||
|
||||
@ -132,7 +144,8 @@ class Variable(object):
|
||||
if '_regexp' not in self.__dict__:
|
||||
import re
|
||||
self._regexp = re.compile( \
|
||||
r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I)
|
||||
#r"^.*[^a-z0-9'\"_]+%s([^a-z0-9_]|$)"%(self.name),re.I)
|
||||
r"([^a-z0-9'\"_]|^)%s([^a-z0-9_]|$)"%(self.name),re.I)
|
||||
return self._regexp
|
||||
regexp = property(regexp)
|
||||
|
||||
@ -142,11 +155,8 @@ class Variable(object):
|
||||
f = lambda l: type(l) in [Begin_provider, Cont_provider]
|
||||
lines = filter(f, self.text)
|
||||
for line in lines:
|
||||
buffer = line.text.replace(']',',').split(',')
|
||||
if len(buffer) < 3:
|
||||
error.fail(line,"Syntax Error")
|
||||
buffer = buffer[1].strip().lower()
|
||||
if self.name == buffer:
|
||||
buffer = line.filename[1]
|
||||
if self._name == buffer:
|
||||
self._line = line
|
||||
break
|
||||
assert '_line' in self.__dict__
|
||||
@ -157,18 +167,23 @@ class Variable(object):
|
||||
def header(self):
|
||||
if '_header' not in self.__dict__:
|
||||
name = self.name
|
||||
self._header = [
|
||||
" %s :: %s %s"%(self.type, name, build_dim(self.dim) ),
|
||||
" logical :: %s_is_built = .False."%(name),
|
||||
]
|
||||
def build_dim(d):
|
||||
if d == []:
|
||||
return ""
|
||||
else:
|
||||
x = map(lambda x: ":", self.dim)
|
||||
return "(%s)"%(','.join(x))
|
||||
self._header = [ " %s :: %s %s"%(self.type, name, build_dim(self.dim) ) ]
|
||||
if self.is_main:
|
||||
self._header += [ " logical :: %s_is_built = .False."%(name) ]
|
||||
return self._header
|
||||
header = property(header)
|
||||
|
||||
############################################################
|
||||
def toucher(self):
|
||||
if '_toucher' not in self.__dict__:
|
||||
if self.same_as != self.name:
|
||||
self._toucher = ""
|
||||
if not self.is_main:
|
||||
self._toucher = []
|
||||
else:
|
||||
if '_needed_by' not in self.__dict__:
|
||||
import parsed_text
|
||||
@ -194,81 +209,93 @@ class Variable(object):
|
||||
##########################################################
|
||||
def reader(self):
|
||||
if '_reader' not in self.__dict__:
|
||||
if '_needs' not in self.__dict__:
|
||||
import parsed_text
|
||||
name = self.name
|
||||
result = [ \
|
||||
"subroutine reader_%s(irp_num)"%(name),
|
||||
" use %s"%(self.fmodule),
|
||||
" implicit none",
|
||||
" character*(*), intent(in) :: irp_num",
|
||||
" logical :: irp_is_open",
|
||||
" integer :: irp_iunit" ]
|
||||
if command_line.do_debug:
|
||||
length = len("reader_%s"%(self.name))
|
||||
result += [\
|
||||
" character*(%d), parameter :: irp_here = 'reader_%s'"%(length,name),
|
||||
" call irp_enter(irp_here)" ]
|
||||
result += map(lambda x: " call reader_%s(irp_num)"%(x),self.needs)
|
||||
result += [ \
|
||||
" irp_is_open = .True.",
|
||||
" irp_iunit = 9",
|
||||
" do while (irp_is_open)",
|
||||
" irp_iunit = irp_iunit+1",
|
||||
" inquire(unit=irp_iunit,opened=irp_is_open)",
|
||||
" enddo",
|
||||
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='OLD',action='READ')"%(name),
|
||||
" read(irp_iunit,*) %s%s"%(name,build_dim(self.dim)),
|
||||
" close(irp_iunit)",
|
||||
" call touch_%s"%(self.same_as),
|
||||
" %s_is_built = .True."%(self.same_as) ]
|
||||
if command_line.do_debug:
|
||||
result.append(" call irp_leave(irp_here)")
|
||||
result.append("end subroutine reader_%s"%(name))
|
||||
result.append("")
|
||||
self._reader = result
|
||||
if not self.is_main:
|
||||
self._reader = []
|
||||
else:
|
||||
if '_needs' not in self.__dict__:
|
||||
import parsed_text
|
||||
from variables import variables
|
||||
name = self.name
|
||||
result = [ \
|
||||
"subroutine reader_%s(irp_num)"%(name),
|
||||
" use %s"%(self.fmodule),
|
||||
" implicit none",
|
||||
" character*(*), intent(in) :: irp_num",
|
||||
" logical :: irp_is_open",
|
||||
" integer :: irp_iunit" ]
|
||||
if command_line.do_debug:
|
||||
length = len("reader_%s"%(self.name))
|
||||
result += [\
|
||||
" character*(%d), parameter :: irp_here = 'reader_%s'"%(length,name),
|
||||
" call irp_enter(irp_here)" ]
|
||||
result += map(lambda x: " call reader_%s(irp_num)"%(x),self.needs)
|
||||
result += [ \
|
||||
" irp_is_open = .True.",
|
||||
" irp_iunit = 9",
|
||||
" do while (irp_is_open)",
|
||||
" irp_iunit = irp_iunit+1",
|
||||
" inquire(unit=irp_iunit,opened=irp_is_open)",
|
||||
" enddo"]
|
||||
for n in [ name ]+self.others:
|
||||
result += [\
|
||||
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='OLD',action='READ')"%(n),
|
||||
" read(irp_iunit,*) %s%s"%(n,build_dim(variables[n].dim)),
|
||||
" close(irp_iunit)" ]
|
||||
rsult += [ \
|
||||
" call touch_%s"%(name),
|
||||
" %s_is_built = .True."%(name) ]
|
||||
if command_line.do_debug:
|
||||
result.append(" call irp_leave(irp_here)")
|
||||
result.append("end subroutine reader_%s"%(name))
|
||||
result.append("")
|
||||
self._reader = result
|
||||
return self._reader
|
||||
reader = property(reader)
|
||||
|
||||
##########################################################
|
||||
def writer(self):
|
||||
if '_writer' not in self.__dict__:
|
||||
if '_needs' not in self.__dict__:
|
||||
import parsed_text
|
||||
name = self.name
|
||||
result = [ \
|
||||
"subroutine writer_%s(irp_num)"%(name),
|
||||
" use %s"%(self.fmodule),
|
||||
" implicit none",
|
||||
" character*(*), intent(in) :: irp_num",
|
||||
" logical :: irp_is_open",
|
||||
" integer :: irp_iunit" ]
|
||||
if command_line.do_debug:
|
||||
length = len("writer_%s"%(self.name))
|
||||
result += [\
|
||||
" character*(%d), parameter :: irp_here = 'writer_%s'"%(length,name),
|
||||
" call irp_enter(irp_here)" ]
|
||||
result += [ \
|
||||
" if (.not.%s_is_built) then"%(self.same_as),
|
||||
" call provide_%s"%(self.same_as),
|
||||
" endif" ]
|
||||
result += map(lambda x: " call writer_%s(irp_num)"%(x),self.needs)
|
||||
result += [ \
|
||||
" irp_is_open = .True.",
|
||||
" irp_iunit = 9",
|
||||
" do while (irp_is_open)",
|
||||
" irp_iunit = irp_iunit+1",
|
||||
" inquire(unit=irp_iunit,opened=irp_is_open)",
|
||||
" enddo",
|
||||
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='UNKNOWN',action='WRITE')"%(name),
|
||||
" write(irp_iunit,*) %s%s"%(name,build_dim(self.dim)),
|
||||
" close(irp_iunit)" ]
|
||||
result += map(lambda x: " call writer_%s(irp_num)"%(x),self.others)
|
||||
if command_line.do_debug:
|
||||
result.append(" call irp_leave(irp_here)")
|
||||
result.append("end subroutine writer_%s"%(name))
|
||||
result.append("")
|
||||
self._writer = result
|
||||
if not self.is_main:
|
||||
self._writer = []
|
||||
else:
|
||||
from variables import variables
|
||||
if '_needs' not in self.__dict__:
|
||||
import parsed_text
|
||||
name = self.name
|
||||
result = [ \
|
||||
"subroutine writer_%s(irp_num)"%(name),
|
||||
" use %s"%(self.fmodule),
|
||||
" implicit none",
|
||||
" character*(*), intent(in) :: irp_num",
|
||||
" logical :: irp_is_open",
|
||||
" integer :: irp_iunit" ]
|
||||
if command_line.do_debug:
|
||||
length = len("writer_%s"%(self.name))
|
||||
result += [\
|
||||
" character*(%d), parameter :: irp_here = 'writer_%s'"%(length,name),
|
||||
" call irp_enter(irp_here)" ]
|
||||
result += [ \
|
||||
" if (.not.%s_is_built) then"%(self.same_as),
|
||||
" call provide_%s"%(self.same_as),
|
||||
" endif" ]
|
||||
result += map(lambda x: " call writer_%s(irp_num)"%(x),self.needs)
|
||||
result += [ \
|
||||
" irp_is_open = .True.",
|
||||
" irp_iunit = 9",
|
||||
" do while (irp_is_open)",
|
||||
" irp_iunit = irp_iunit+1",
|
||||
" inquire(unit=irp_iunit,opened=irp_is_open)",
|
||||
" enddo" ]
|
||||
for n in [ name ] + self.others:
|
||||
result += [\
|
||||
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='UNKNOWN',action='WRITE')"%(n),
|
||||
" write(irp_iunit,*) %s%s"%(n,build_dim(variables[n].dim)),
|
||||
" close(irp_iunit)" ]
|
||||
if command_line.do_debug:
|
||||
result.append(" call irp_leave(irp_here)")
|
||||
result.append("end subroutine writer_%s"%(name))
|
||||
result.append("")
|
||||
self._writer = result
|
||||
return self._writer
|
||||
writer = property(writer)
|
||||
|
||||
@ -276,24 +303,14 @@ class Variable(object):
|
||||
def free(self):
|
||||
if '_free' not in self.__dict__:
|
||||
name = self.name
|
||||
result = [ \
|
||||
"subroutine free_%s"%(name),
|
||||
" use %s"%(self.fmodule),
|
||||
" implicit none" ]
|
||||
if command_line.do_debug:
|
||||
length = len("free_%s"%(self.name))
|
||||
result += [\
|
||||
" character*(%d), parameter :: irp_here = 'free_%s'"%(length,name),
|
||||
result = [ "!","! >>> FREE %s"%(self.name),
|
||||
" %s_is_built = .False."%(self.same_as) ]
|
||||
if self.dim != []:
|
||||
result += [ \
|
||||
" if (allocated(%s)) then"%(name),
|
||||
" deallocate (%s)"%(name),
|
||||
" endif" ]
|
||||
if command_line.do_debug:
|
||||
result.append(" call irp_leave(irp_here)")
|
||||
result.append("end subroutine free_%s"%(name))
|
||||
result.append("")
|
||||
result.append("! <<< END FREE")
|
||||
self._free = result
|
||||
return self._free
|
||||
free = property(free)
|
||||
@ -301,6 +318,9 @@ class Variable(object):
|
||||
##########################################################
|
||||
def provider(self):
|
||||
if '_provider' not in self.__dict__:
|
||||
if not self.is_main:
|
||||
self._provider = []
|
||||
else:
|
||||
if '_to_provide' not in self.__dict__:
|
||||
import parsed_text
|
||||
from variables import variables, build_use, call_provides
|
||||
@ -387,11 +407,28 @@ class Variable(object):
|
||||
##########################################################
|
||||
def builder(self):
|
||||
if '_builder' not in self.__dict__:
|
||||
if not self.is_main:
|
||||
self._builder = []
|
||||
if '_needs' not in self.__dict__:
|
||||
import parsed_text
|
||||
from variables import build_use
|
||||
for filename,buffer in parsed_text.parsed_text:
|
||||
if self.line.filename[0].startswith(filename):
|
||||
break
|
||||
text = []
|
||||
same_as = self.same_as
|
||||
inside = False
|
||||
for vars,line in buffer:
|
||||
if isinstance(line,Begin_provider):
|
||||
if line.filename[1] == same_as:
|
||||
inside = True
|
||||
if inside:
|
||||
text.append(line)
|
||||
if isinstance(line,End_provider):
|
||||
if inside:
|
||||
break
|
||||
name = self.name
|
||||
for line in filter(lambda x: type(x) not in [ Begin_doc, End_doc, Doc], self.text):
|
||||
for line in filter(lambda x: type(x) not in [ Begin_doc, End_doc, Doc], text):
|
||||
if type(line) == Begin_provider:
|
||||
result = [ "subroutine bld_%s"%(name) ]
|
||||
result += build_use([name]+self.needs)
|
||||
@ -406,11 +443,54 @@ class Variable(object):
|
||||
return self._builder
|
||||
builder = property(builder)
|
||||
|
||||
##########################################################
|
||||
def children(self):
|
||||
if '_children' not in self.__dict__:
|
||||
if not self.is_main:
|
||||
self._children = []
|
||||
from variables import variables
|
||||
if '_needs' not in self.__dict__:
|
||||
import parsed_text
|
||||
result = []
|
||||
for x in self.needs:
|
||||
result.append(x)
|
||||
try:
|
||||
result += variables[x].children
|
||||
except RuntimeError:
|
||||
pass # Exception will be checked after
|
||||
self._children = make_single(result)
|
||||
if self.name in result:
|
||||
error.fail(self.line,"Cyclic dependencies:\n%s"%(str(self._children)))
|
||||
return self._children
|
||||
children = property(children)
|
||||
|
||||
##########################################################
|
||||
def parents(self):
|
||||
if '_parents' not in self.__dict__:
|
||||
if not self._is_main:
|
||||
self._parents = []
|
||||
else:
|
||||
from variables import variables
|
||||
if '_needed_by' not in self.__dict__:
|
||||
import parsed_text
|
||||
result = []
|
||||
for x in self.needed_by:
|
||||
result.append(x)
|
||||
try:
|
||||
result += variables[x].parents
|
||||
except RuntimeError:
|
||||
pass # Exception will be checked after
|
||||
self._parents = make_single(result)
|
||||
if self.name in result:
|
||||
error.fail(self.line,"Cyclic dependencies:\n%s"%(str(self._parents)))
|
||||
return self._parents
|
||||
parents = property(parents)
|
||||
|
||||
######################################################################
|
||||
if __name__ == '__main__':
|
||||
from preprocessed_text import preprocessed_text
|
||||
from variables import variables
|
||||
#for v in variables.keys():
|
||||
# print v
|
||||
for line in variables['grid_eplf_aa'].builder:
|
||||
for line in variables['e_loc'].parents:
|
||||
print line
|
||||
|
@ -1 +1 @@
|
||||
version = "1.1.9"
|
||||
version = "1.1.10"
|
||||
|
Loading…
Reference in New Issue
Block a user