Commit 2fcdfdf5 authored by sparonuz's avatar sparonuz
Browse files

[(nobranch,rebasingotinto/AutoRPE#91)]: # This is a combination of 49 commits.

[otinto/AutoRPE#91]: CleanCode cleans code, and has to be used to produce sources for ImplementRPEtoSources and MakeVault scripts

[otinto/AutoRPE#91]: Function preprocess_sources now divided between the part that cleans the code and the one that creates files with RPE type declaration
[otinto/AutoRPE#91]: No tmp folder are required in MakeVault.
[otinto/AutoRPE#91]: Removed some unused function, and removed useless layer for getting members of structures
[otinto/AutoRPE#91]: BugFix for allocate with '::'symbol detected as var declaration
[otinto/AutoRPE#91]: Update of the test with refactoring, and fix for imports`
[otinto/AutoRPE#91]: Added array for external types used and manage the case a external type is used
[otinto/AutoRPE#91]: Test for the find_function_type_from_header were failing, fixed a bug. Closing Issue #93
[otinto/AutoRPE#91]: Fixed for: functions as arugments, external variables as arguments, a call to get_type_of_contents was made without specifying the routine.
[otinto/AutoRPE#91]: Introduction of get_function_type , to shorten a bit get_type_of_contents, that is still too long.
[otinto/AutoRPE#91]:  Regex for hardcoded array was matching with array inside function. Closes #95 .
[otinto/AutoRPE#91]: check for keyword argument was missing in  get_dimension_of_contents
[otinto/AutoRPE#91]: Partially fix the case a write statement was using an array. Added corresponding test
[otinto/AutoRPE#91]: Changed the name of replace_real to replace_real_with_RPE_declaration + refactoring
[otinto/AutoRPE#91]: Fixed and moved regex for real declaration (Issue #96 ). Small renaming
[otinto/AutoRPE#91]:  This solves the variables duplication
[otinto/AutoRPE#91]: Function/Subroutine/Interfaces are subprograms, Function/Subroutine/Interfaces/Main/DerivedType are procedures. Everything was mixed, and called routine, sometimes procedure.
[otinto/AutoRPE#91]: Renamed function that fill dictionary of var, and fix the syntax.
[otinto/AutoRPE#91]: Trying to speed up with dictionary otinto/AutoRPE#41
[otinto/AutoRPE#91]: DerivedType class moved to BasicStructure for coherency. Changes for adding the dict of accessible_var
[otinto/AutoRPE#91]: is_call_to_function_vault added check for intrinsics + added check for array  to is_call_to_function+Formatting
[otinto/AutoRPE#91]:fix import + get_variable_by_name: now properly uses dictionary accessible_var, in the correct order + function for filling those dict
parent c9a0c5d0
......@@ -93,7 +93,7 @@ if __name__ == "__main__":
m = re.search(pattern, _l)
var, value = m.groups()
# Use the vault to determine the type of the variable
type_of_var = get_type_of_contents(var, routine=None, vault=vault)
type_of_var = get_type_of_contents(var, procedure=None, vault=vault)
# In case the variable is a rpe_var, add a %val suffix
if type_of_var == "rpe_var":
......
......@@ -33,34 +33,34 @@ def fix_casts(source_path, vault_path, list_filename=None):
# Check if there's a routine call with a cast to real
if re.search(pattern, line, re.I):
try:
calls = calls_to_routines(line)
calls = call_to_subroutine(line)
except ValueError:
continue
for call in calls:
arguments = find_call_arguments(call)
routine_name = re.search(call_pattern, call, re.I).group(1)
procedure_name = re.search(call_pattern, call, re.I).group(1)
try:
routine = vault.get_procedure_by_name(routine_name)
procedure = vault.get_procedure_by_name(procedure_name)
except ProcedureNotFound:
continue
# If it is an interface, find the specific routine being used
if isinstance(routine, Interface):
# If it is an interface, find the specific procedure being used
if isinstance(procedure, Interface):
try:
routine = match_arguments_and_interface(arguments, interface=routine, vault=vault)
procedure = match_arguments_and_interface(arguments, interface=procedure, vault=vault)
except AssertionError:
routine = None
procedure = None
for index, argument in enumerate(arguments):
if re.search(cast_pattern, argument, re.I):
if routine is not None:
if procedure is not None:
if not is_keyword_argument(argument):
target_precision = routine.get_variable_by_position(index).precision
target_precision = procedure.get_variable_by_position(index).precision
else:
key = argument.split("=")[0].strip()
target_precision = routine.get_variable_by_name(key).precision
target_precision = procedure.get_variable_by_name(key).precision
else:
# For now we will assume that in this case it is not necessary to change the cast
continue
# Problematic to assume that the precision of an external routine is either double or single
# Problematic to assume that the precision of an external procedure is either double or single
# target_precision = 52
target_precision = 23
try:
......
############################################
# Purpose: This script has multiple purposes:
# Firstly, it can be used to check whether a code has coherency in the types
# of function and routine calls.
# of subprograms call.
#
# Secondly, it can fix the code whenever it can be solved with a cast.
#
......@@ -22,7 +22,7 @@
from AutoRPE.UtilsRPE.SourceManager import expand_sources
from AutoRPE.UtilsRPE.SourceManager import load_vault
from AutoRPE.UtilsRPE.ImplementRPE import ImplementRPE
from AutoRPE.UtilsRPE.CurrentBlock import CurrentBlock
import AutoRPE.UtilsRPE.CurrentBlock as CurrentBlock
from AutoRPE.UtilsRPE.Inserter import find_call_in_original_file
from AutoRPE.UtilsRPE.Getter import get_real_in_line
import AutoRPE.UtilsRPE.VariablePrecision as VariablePrecision
......@@ -32,10 +32,10 @@ import warnings
def code_check_file(filename, vault, fix=False, original_sources=None):
"""
Check that all functions and routines in a source code have coherent types.
Check that all functions and subroutines in a source code have coherent types.
"""
try:
current_block = CurrentBlock(vault[filename.split("/")[-1].replace(".f90", "")].main())
current_block = CurrentBlock.CurrentBlock(vault[filename.split("/")[-1].replace(".f90", "")].main())
except AttributeError:
warnings.warn("No module %s" % filename)
return
......@@ -83,7 +83,7 @@ def code_check_file(filename, vault, fix=False, original_sources=None):
print("Can't be fixed")
else:
# If not, look if the code is entering or exiting a routine block
# If not, look if the code is entering or exiting a procedure block
current_block = current_block.in_which_block(line, vault=vault)
......
......@@ -2,52 +2,29 @@
# Purpose:
# This script can be used to remove all the contents of a Fortran code that can make it harder to parse.
# It will merge split lines, remove comments and empty lines.
#
# Inputs:
#
# "-s", "--input-source" path to a source-code folder which code will be cleaned.
#
#
############################################
from AutoRPE.UtilsRPE.SourceManager import preprocess_sources
from AutoRPE.UtilsRPE.Error import PathType
def get_command_line_arguments():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input-sources", required=True, type=PathType(exists=True, type='dir'),
help="Path to a folder that contains the preprocessed code source")
parser.add_argument("-o", "--output-sources", required=True,
help="Path to the folder that will contain the clean code")
args = parser.parse_args()
return args
from AutoRPE.UtilsRPE.Cleaner import remove_empty_lines, merge_lines, remove_comments
from AutoRPE.UtilsRPE.SourceManager import store_lines_into_file, load_file, expand_sources
if __name__ == "__main__":
# Use OptionParser to parse command line arguments.
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-s", "--input-source", dest="input_source",
default=None, metavar="FILE")
(options, args) = parser.parse_args()
path = options.input_source
if path is None:
parser.print_help()
exit(0)
# Find all files inside the provided path
files = expand_sources(path)
# Loop over files
for index, fn in enumerate(files):
# Read file
lines = load_file(fn)
# Remove comments ignoring preprocessor statements
for line_index, line in enumerate(lines):
if line[0] == "#":
continue
lines[line_index] = remove_comments(line)
# Remove empty lines
lines = remove_empty_lines(lines)
# Merge lines
lines = merge_lines(lines)
# Remove empty lines again
lines = remove_empty_lines(lines)
# Overwrite file with clean source
store_lines_into_file(lines, fn)
args = get_command_line_arguments()
path_to_input_sources = args.input_sources
path_to_output_sources = args.output_sources
preprocess_sources(path_to_input_sources, path_to_output_sources)
############################################
# Purpose:
# This script is indented to identify which variables are used in calls to external functions or routines.
# This script is indented to identify which variables are used in calls to external subprogram.
#
# Inputs:
#
......@@ -10,11 +10,11 @@
#
############################################
from AutoRPE.UtilsRPE.SourceManager import expand_sources, load_vault, store_variable_list
from AutoRPE.UtilsRPE.BasicStructures import Routine, Interface
from AutoRPE.UtilsRPE.CallManager import calls_to_routines, find_called_routine, find_call_arguments
from AutoRPE.UtilsRPE.BasicStructures import SubRoutine, Interface
from AutoRPE.UtilsRPE.CallManager import call_to_subroutine, find_called_subroutine, find_call_arguments
from AutoRPE.UtilsRPE.Getter import get_variable
from AutoRPE.UtilsRPE.ImplementRPE import ImplementRPE
from AutoRPE.UtilsRPE.CurrentBlock import CurrentBlock
import AutoRPE.UtilsRPE.CurrentBlock as CurrentBlock
from AutoRPE.UtilsRPE.Error import ProcedureNotFound
import AutoRPE.UtilsRPE.VariablePrecision as VariablePrecision
from os.path import basename, isfile, isdir
......@@ -47,7 +47,7 @@ def get_command_line_arguments():
def find_variables_used_in_external_calls(files, vault, exceptions):
external_routines_found = []
external_subprogram_found = []
variables = []
for filepath in files:
module_name = basename(filepath).split(".")[0]
......@@ -57,37 +57,37 @@ def find_variables_used_in_external_calls(files, vault, exceptions):
file_info = ImplementRPE(filepath, vault)
file_info.pre_process()
current_block = CurrentBlock(module.main())
current_block = CurrentBlock.CurrentBlock(module.main())
for index, line in enumerate(file_info.lines):
print("\r %04i/%04i %50s" % (index + 1, len(file_info.lines), module_name), end="")
try:
routine_calls = calls_to_routines(line)
subroutine_calls = call_to_subroutine(line)
except ValueError:
continue
if routine_calls:
for call in routine_calls:
if subroutine_calls:
for call in subroutine_calls:
is_external = False
called_routine = find_called_routine(call)
called_subroutine = find_called_subroutine(call)
# Find the procedure called (object)
try:
procedure = vault.get_procedure_by_name(called_routine)
subroutine = vault.get_procedure_by_name(called_subroutine)
except ProcedureNotFound:
procedure = None
subroutine = None
pass
if isinstance(procedure, Routine):
if isinstance(subroutine, SubRoutine):
continue
elif isinstance(procedure, Interface):
elif isinstance(subroutine, Interface):
continue
else:
is_external = True
if is_external:
external_routines_found.append(called_routine)
external_subprogram_found.append(called_subroutine)
# Starting with the exceptions!"
is_exception = False
for exception in exceptions:
if called_routine.count(exception):
if called_subroutine.count(exception):
is_exception = True
break
if is_exception:
......@@ -99,7 +99,7 @@ def find_variables_used_in_external_calls(files, vault, exceptions):
else:
for argument in called_arguments:
try:
variable = get_variable(argument, routine=current_block.routine, vault=vault)
variable = get_variable(argument, procedure=current_block.procedure, vault=vault)
except AssertionError:
continue
except ValueError:
......
############################################
# Purpose:
# This script takes a vault and creates a namelist_precisions for that vault.
#
# Inputs:
#
# -v, --vault : Path to the vault.
# -o, --output-namelist : name of output namelist to specify the precision of each variable.
#
############################################
from AutoRPE.UtilsRPE.SourceManager import load_list_of_files_to_keep_unmodified, load_vault, \
preprocess_sources, postprocess_sources, parse_sources
from AutoRPE.UtilsRPE.Inserter import add_sbits_to_rpe_variables, insert_read_precisions_module_to_file
from os import mkdir, rename
import AutoRPE.UtilsRPE.SourceManager as SourceManager
import AutoRPE.UtilsRPE.Inserter as Inserter
from AutoRPE.UtilsRPE.Error import PathType
from os import mkdir
from os.path import isdir
from shutil import rmtree
......@@ -19,19 +14,15 @@ from shutil import rmtree
def get_command_line_arguments():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input-source", default=None,
help="Path to a folder that contains the preprocessed code source")
parser.add_argument("-o", "--output-vault", default="vault.pkl",
parser.add_argument("-i", "--input-sources", required=True, type=PathType(exists=True, type='dir'),
help="Path to a folder that contains the preprocessed cleaned code source")
parser.add_argument("-o", "--output-sources", default="SourcesWithRPE",
help="Path to the folder that will contain the AutoRPE implementation ")
parser.add_argument("--output-vault", default="vault.pkl",
help="Filename of the output database")
args = parser.parse_args()
if args.input_source is None:
parser.error("Argument -i/--input-sources required!")
if not isdir(args.input_source):
parser.error("Argument -v/--vault %s is not a file." % args.vault)
return args
......@@ -39,43 +30,45 @@ if __name__ == "__main__":
args = get_command_line_arguments()
path_to_input_sources = args.input_source
path_to_input_sources = args.input_sources
path_to_output_sources = args.output_sources
output_vault = args.output_vault
# Paths to source folders
path_to_preprocessed_sources = "./tmp_processedsources/"
path_to_output_sources = "./tmp_outputsources/"
if isdir(path_to_preprocessed_sources):
rmtree(path_to_preprocessed_sources)
mkdir(path_to_preprocessed_sources)
if isdir(path_to_output_sources):
rmtree(path_to_output_sources)
mkdir(path_to_output_sources)
mkdir(path_to_preprocessed_sources)
print("Starting the implementation of the reduced precision emulator in:\n %s\n\n" % path_to_input_sources)
# List of files that should not be processed, as red from "list_of_files_to_keep_unmodified.txt"
preprocess_blacklist = load_list_of_files_to_keep_unmodified()
preprocess_blacklist = SourceManager.load_list_of_files_to_keep_unmodified()
# Format text + replace real declarations with type(rpe_var)
preprocess_sources(path_to_input_sources, path_to_preprocessed_sources, blacklist=preprocess_blacklist)
SourceManager.replace_real_with_RPE_declaration(path_to_input_sources,
path_to_preprocessed_sources,
preprocess_blacklist)
# Obtain source information
vault = parse_sources(path_to_preprocessed_sources, save_vault=True)
vault = SourceManager.parse_sources(path_to_preprocessed_sources, save_vault=True)
# We load the code information into the vault
try:
vault
except NameError:
vault = load_vault()
vault = SourceManager.load_vault()
# Process the sources to fix call to functions, read/write, ...
postprocess_sources(path_to_preprocessed_sources, path_to_output_sources, vault=vault)
SourceManager.postprocess_sources(path_to_preprocessed_sources, path_to_output_sources, vault=vault)
# Insert precision specification
add_sbits_to_rpe_variables(path_to_output_sources, vault=vault)
Inserter.add_sbits_to_rpe_variables(path_to_output_sources, vault=vault)
# Assign ids to variables that still don't have any (can't have it's precision changed online)
# and set them as mutable=False
......@@ -83,15 +76,9 @@ if __name__ == "__main__":
# Add the read_precisions module into a file (should be accessible for all the other modules)
file_to_add_read_precisions_module = None
insert_read_precisions_module_to_file(path_to_output_sources, file_to_add_read_precisions_module,
vault=vault)
Inserter.insert_read_precisions_module_to_file(path_to_output_sources, file_to_add_read_precisions_module,
vault=vault)
# Deleting temporary folders
if isdir(path_to_preprocessed_sources):
rmtree(path_to_preprocessed_sources)
output_folder = "SourcesWithRPE"
if isdir(output_folder):
rmtree(output_folder)
if isdir(path_to_output_sources):
rename(path_to_output_sources, output_folder)
......@@ -4,8 +4,8 @@
from AutoRPE.UtilsRPE.MainFunctions import parse_sources, postprocess_sources, assign_sbits_to_rpe_variables, \
create_read_precisions_module_and_add_to_file, preprocess_sources
from AutoRPE.UtilsRPE.Functions import load_vault, remove_comments
from AutoRPE.UtilsRPE.Classes import Current_block
from AutoRPE.UtilsRPE.CodeTools import replace_real_declaration, merge_lines
from AutoRPE.UtilsRPE.CurrentBlock import Current_block
from AutoRPE.UtilsRPE.Inserter import replace_real_declaration
from os import listdir, mkdir
from os.path import join, isdir, isfile
from shutil import rmtree
......@@ -35,7 +35,7 @@ def merge_declaration_lines(code_text):
return "\n".join(lines).strip()
def replace_routine_name(old_name, new_name, code_text):
def replace_subroutine_name(old_name, new_name, code_text):
pattern = r"(subroutine +\b)%s\b" % old_name
pat = re.compile(pattern, re.I)
replacement = r"\1 %s" % new_name
......@@ -54,17 +54,17 @@ def find_declaration_line(variable, routine_code):
real_pattern = r"real.*::"
lines = [l for l in routine_code.split("\n")]
current_block = Current_block(vault[variable.routine.module.name].main())
current_block = Current_block(vault[variable.procedure.module.name].main())
for _index, _line in enumerate(lines):
_line = remove_comments(_line).strip()
if re.search(pattern, _line):
if current_block.routine == variable.routine:
if current_block.procedure == variable.procedure:
return _index
else:
current_block = in_which_block(_line, current_block, vault=vault)
print("Declaration of variable %s with id %i not found in module %s" % (variable.name,variable.id, variable.routine.module.name))
print("Declaration of variable %s with id %i not found in module %s" % (variable.name,variable.id, variable.procedure.module.name))
return None
......
import AutoRPE.UtilsRPE.VariablePrecision as VariablePrecision
from AutoRPE.UtilsRPE.SourceManager import parse_sources, preprocess_sources, load_vault
from AutoRPE.UtilsRPE.SourceManager import parse_sources, load_vault
from AutoRPE.UtilsRPE.TrackDependency import track_dependencies, propagate_dependencies
from os.path import isdir, abspath
from os import listdir, mkdir
......@@ -55,22 +55,8 @@ if __name__ == "__main__":
# In case no vault has been provided it will create it from the sources in the input sources folder
if vault_path is None:
# Paths to source folders
# Path_to_input_sources
path_to_preprocessed_sources = "tmp_processedsources/"
path_to_output_sources = "tmp_outputsources/"
if not isdir(path_to_preprocessed_sources):
mkdir(path_to_preprocessed_sources)
if not isdir(path_to_output_sources):
mkdir(path_to_output_sources)
# List of files that should not be processed, as red from "list_of_files_to_keep_unmodified.txt"
preprocess_blacklist = listdir(path_to_input_sources)
# Format text + replace real declarations with type(rpe_var)
preprocess_sources(path_to_input_sources, path_to_preprocessed_sources, blacklist=preprocess_blacklist)
# Obtain source information
vault = parse_sources(path_to_preprocessed_sources, save_vault=False)
vault = parse_sources(path_to_input_sources, save_vault=False)
else:
vault = load_vault(vault_path)
......@@ -87,7 +73,7 @@ if __name__ == "__main__":
# Track dependencies and propagate it
# Create empty graph
graph = nx.DiGraph()
track_dependencies(path_to_preprocessed_sources, vault, graph=graph)
track_dependencies(path_to_input_sources, vault, graph=graph)
if export_graph:
nx.readwrite.gexf.write_gexf(graph, "./graph.gexf")
propagate_dependencies(vault, graph=graph)
......@@ -100,9 +86,3 @@ if __name__ == "__main__":
sys.setrecursionlimit(20000)
pickle.dump(vault, open(output_vault, "wb"))
print("Vault successfully dumped to ", abspath(output_vault))
# Deleting temporary folders
if isdir(path_to_preprocessed_sources):
rmtree(path_to_preprocessed_sources)
if isdir(path_to_output_sources):
rmtree(path_to_output_sources)
......@@ -12,15 +12,15 @@ def translate_vault(list1, path1, path2, output_filename, print_id_not_found=Fal
variables02 = [var for var in vault02.variables if var.id]
for var01 in variables01:
name01 = var01.name
routine01 = var01.routine.name
module01 = var01.routine.module.name
procedure01 = var01.procedure.name
module01 = var01.procedure.module.name
var_found = False
for var02 in variables02:
id02 = var02.id
name02 = var02.name
routine02 = var02.routine.name
module02 = var02.routine.module.name
if name02 == name01 and routine02 == routine01 and module02 == module01:
procedure02 = var02.procedure.name
module02 = var02.procedure.module.name
if name02 == name01 and procedure02 == procedure01 and module02 == module01:
list_of_equivalent_id.append(id02)
variables02.remove(var02)
var_found = True
......
import unittest
import AutoRPE.UtilsRPE.Error as Error
class TestFunctionMethods(unittest.TestCase):
def test_type_of_real_cast_with_double_specification(self):
from AutoRPE.UtilsRPE.Functions import type_of_real_cast
import AutoRPE.UtilsRPE.Getter as Getter
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),dp)'
self.assertEqual(type_of_real_cast(string), 'double')
self.assertEqual(Getter.get_type_of_real_cast(string), 'double')
def test_type_of_real_cast_with_single_specification(self):
from AutoRPE.UtilsRPE.Functions import type_of_real_cast
import AutoRPE.UtilsRPE.Getter as Getter
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1),sp)'
self.assertEqual(type_of_real_cast(string), 'single')
self.assertEqual(Getter.get_type_of_real_cast(string), 'single')
def test_type_of_real_cast_no_specification(self):
from AutoRPE.UtilsRPE.Functions import type_of_real_cast
from AutoRPE.UtilsRPE.Functions import working
import AutoRPE.UtilsRPE.Getter as Getter
from AutoRPE.UtilsRPE.VariablePrecision import wp
string = 'real((ssh(:,:,kmm)+ssh_ref)*tmask(:,:,1))'
self.assertEqual(type_of_real_cast(string), working)
self.assertEqual(Getter.get_type_of_real_cast(string), wp)
def test_separate_line_container_and_arguments_1(self):
from AutoRPE.UtilsRPE.Functions import separate_line_container_and_arguments
import AutoRPE.UtilsRPE.Splitter as Splitter
string = 'write(numicb,*) \'bergstep \',nktberg,\' send ns: \', ibergs_to_send_n, ibergs_to_send_s'
line_container, arguments = separate_line_container_and_arguments(string=string)
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
actual_arguments = ["'bergstep '", 'nktberg', "' send ns: '", ' ibergs_to_send_n', ' ibergs_to_send_s']
actual_line_container = 'write(numicb,*) ###TOREPLACE###'
self.assertTrue(line_container == actual_line_container and actual_arguments == arguments)
def test_separate_line_container_and_arguments_2(self):
from AutoRPE.UtilsRPE.Functions import separate_line_container_and_arguments
import AutoRPE.UtilsRPE.Splitter as Splitter
string = "WRITE(cl_asmbkg, FMT='(A,\".nc\")' ) TRIM( c_asmbkg )"
line_container, arguments = separate_line_container_and_arguments(string=string)
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
actual_arguments = ['TRIM( c_asmbkg )']
actual_line_container = 'WRITE(cl_asmbkg, FMT=\'(A,".nc")\' ) ###TOREPLACE###'
self.assertTrue(line_container == actual_line_container and actual_arguments == arguments)
def test_separate_line_container_and_arguments_3(self):
from AutoRPE.UtilsRPE.Functions import separate_line_container_and_arguments
import AutoRPE.UtilsRPE.Splitter as Splitter
string = "IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)') ' =======>> 1/2 time step before the start of the run DATE Y/M/D = ', nyear, '/', nmonth, '/', nday, ' nsec_day:', nsec_day, ' nsec_monday:', nsec_monday, ' nsec_month:', nsec_month , ' nsec_year:' , nsec_year"
line_container, arguments = separate_line_container_and_arguments(string=string)
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_separate_line_container_and_arguments_4(self):
from AutoRPE.UtilsRPE.Functions import separate_line_container_and_arguments
string='IF( lwriter ) WRITE(numtime,*) \' ===> W A R N I N G: \''
line_container, arguments = separate_line_container_and_arguments(string=string)
import AutoRPE.UtilsRPE.Splitter as Splitter
string = 'IF( lwriter ) WRITE(numtime,*) \' ===> W A R N I N G: \''
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_separate_line_container_and_arguments_4(self):
from AutoRPE.UtilsRPE.Functions import separate_line_container_and_arguments
string='IF (ln_grid_search_lookup)WRITE(numout,*) \' Grid search lookup file header cn_gridsearchfile = \', cn_gridsearchfile'
line_container, arguments = separate_line_container_and_arguments(string=string)
import AutoRPE.UtilsRPE.Splitter as Splitter
string = 'IF (ln_grid_search_lookup)WRITE(numout,*) \' Grid search lookup file header cn_gridsearchfile = \', cn_gridsearchfile'
line_container, arguments = Splitter.split_line_container_and_arguments(string=string)
condition = arguments[0].count("WRITE") == 0
self.assertTrue(condition)
def test_dimension_of_contents_1(self):
from AutoRPE.UtilsRPE.Functions import dimension_of_contents
self.assertEqual(dimension_of_contents("1.0"), 0)
import AutoRPE.UtilsRPE.Getter as Getter
self.assertEqual(Getter.get_dimension_of_contents("1.0"), 0)
def test_dimension_of_contents_2(self):
from AutoRPE.UtilsRPE.Functions import dimension_of_contents
import AutoRPE.UtilsRPE.Getter as Getter
string = "real( ( ( z3d(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 )"
dimension = dimension_of_contents(string)
dimension = Getter.get_dimension_of_contents(string)