Commit 909df475 authored by erodrigu's avatar erodrigu
Browse files

Fixed error with getting the variable name and simplified functions

parent fcba5b4e
......@@ -139,19 +139,14 @@ def _add_argument_truncation(line, subprogram_call, counter):
def insert_variable_precision_specification(variable, module, insertion_line, condition="", var_name=None):
# Add precision specification
var_name = var_name if var_name != None else variable.name
new_line = condition + " %s%%sbits = emulator_variable_precisions(%i)" % (var_name, variable.id)
module.lines.insert(insertion_line, new_line)
# Add variable usage specification
new_line = condition + " variable_is_used(%i) = .true." % variable.id
# Add apply_truncation
new_line = condition + " CALL apply_truncation(%s)" % var_name
module.lines.insert(insertion_line, new_line)
module.rebuild_text()
def insert_variable_usage(variable, module, insertion_line, condition=None):
if condition is None:
condition = ""
# Add sbits
new_line = condition + " %s%%sbits = emulator_variable_precisions(%i)" % (var_name, variable.id)
module.lines.insert(insertion_line, new_line)
# Add variable usage specification
new_line = condition + " variable_is_used(%i) = .true." % variable.id
......@@ -160,15 +155,6 @@ def insert_variable_usage(variable, module, insertion_line, condition=None):
module.rebuild_text()
def insert_variable_truncation(variable, sourcefile, insertion_line, condition=None, var_name=None):
var_name = var_name if var_name != None else variable.name
if condition is None:
condition = ""
new_line = condition + " CALL apply_truncation(%s)" % var_name
sourcefile.lines.insert(insertion_line, new_line)
sourcefile.rebuild_text()
def insert_variable_precision_specification_to_allocatable(variable, counter_object):
module_where_var_appears = variable.procedure.module.used_by
for module in [variable.module] + module_where_var_appears:
......@@ -180,7 +166,7 @@ def insert_variable_precision_specification_to_allocatable(variable, counter_obj
for arg in arguments:
if arg.count(variable.name):
# Remove the possible array arguments and get only the member and var (foo%var(2:3) --> foo%var)
var_name = arguments[0].split(variable.name)[0] + variable.name
var_name = arg.split(variable.name)[0] + variable.name
break
else:
var_name = None
......@@ -188,7 +174,6 @@ def insert_variable_precision_specification_to_allocatable(variable, counter_obj
variable.mutable = True
counter_object.up()
insert_variable_precision_specification(variable, module, line_index + 1, var_name=var_name)
insert_variable_usage(variable, module, line_index + 1)
......@@ -204,7 +189,6 @@ def insert_variable_precision_specification_to_namelist_parameter(variable, coun
variable.mutable = True
counter_object.up()
insert_variable_precision_specification(variable, module, index + 1)
insert_variable_usage(variable, module, index + 1)
def insert_variable_precision_to_routine_variable(variable, counter_object):
......@@ -222,8 +206,6 @@ def insert_variable_precision_to_routine_variable(variable, counter_object):
if variable.is_member_of:
var_name = BasicFunctions.remove_if_condition(_line).split(variable.name)[0] + variable.name
insert_variable_precision_specification(variable, module, first_use_line, condition, var_name=var_name)
insert_variable_truncation(variable, module, first_use_line + 1, condition)
insert_variable_usage(variable, module, first_use_line + 2, condition)
else:
warnings.warn("Variable %s not found %s in routine %s" % (
variable.name, variable.procedure.module.name, variable.procedure.name))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment