Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/capgen_unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y build-essential ${{matrix.fortran-compiler}} cmake python3 git libxml2-utils
- name: Run unit tests
run: cd test && ./run_fortran_tests.sh

- name: Run Fortran to metadata test
run: cd test && ./test_fortran_to_metadata.sh
10 changes: 10 additions & 0 deletions scripts/ccpp_fortran_to_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from parse_tools import init_log, set_log_level
from parse_tools import CCPPError, ParseInternalError
from parse_tools import reset_standard_name_counter, unique_standard_name
from parse_tools import register_fortran_ddt_name
from fortran_tools import parse_fortran_file
from file_utils import create_file_list
from metadata_table import blank_metadata_line
Expand Down Expand Up @@ -67,6 +68,10 @@ def parse_command_line(args, description):
metavar='VARDEF1[,VARDEF2 ...]', type=str, default='',
help="Proprocessor directives used to correctly parse source files")

parser.add_argument("--ddt-names",
metavar='DDT_NAME1[,DDT_NAME2 ...]', type=str, default='',
help="Comma-separated DDT names that may be used in the parsed Fortran files")

parser.add_argument("--output-root", type=str,
metavar='<directory for generated files>',
default=os.getcwd(),
Expand Down Expand Up @@ -198,6 +203,11 @@ def _main_func():
elif verbosity > 0:
set_log_level(_LOGGER, logging.INFO)
# end if
if args.ddt_names:
for dname in args.ddt_names.split(','):
register_fortran_ddt_name(dname)
# end for
# end if
# Make sure we know where output is going
output_dir = os.path.abspath(args.output_root)
# Optional table separator comment
Expand Down
4 changes: 3 additions & 1 deletion scripts/parse_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from parse_checkers import fortran_list_match
from parse_checkers import registered_fortran_ddt_name
from parse_checkers import register_fortran_ddt_name
from parse_checkers import registered_fortran_ddt_names
from parse_checkers import check_units, check_dimensions, check_cf_standard_name
from parse_checkers import check_default_value, check_valid_values, check_molar_mass
from parse_log import init_log, set_log_level, flush_log
Expand Down Expand Up @@ -65,9 +66,10 @@
'ParseObject',
'PreprocStack',
'PrettyElementTree',
'register_fortran_ddt_name',
'read_xml_file',
'register_fortran_ddt_name',
'registered_fortran_ddt_name',
'registered_fortran_ddt_names',
'reset_standard_name_counter',
'set_log_level',
'set_log_to_file',
Expand Down
2 changes: 1 addition & 1 deletion scripts/parse_tools/parse_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def check_cf_standard_name(test_val, prop_dict, error):
FORTRAN_DP_RE = re.compile(r"(?i)double\s*precision")
FORTRAN_TYPE_RE = re.compile(r"(?i)type\s*\(\s*("+FORTRAN_ID+r")\s*\)")

_REGISTERED_FORTRAN_DDT_NAMES = []
_REGISTERED_FORTRAN_DDT_NAMES = ["ccpp_constituent_prop_ptr_t"]

########################################################################

Expand Down
37 changes: 37 additions & 0 deletions test/test_fortran_to_metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /bin/bash

## Relevant directories and file paths
test_dir="$(cd $(dirname ${0}); pwd -P)"
script_dir="$(dirname ${test_dir})/scripts"
sample_files_dir="${test_dir}/unit_tests/sample_files"
f2m_script="${script_dir}/ccpp_fortran_to_metadata.py"
filename="test_fortran_to_metadata"
test_input="${sample_files_dir}/${filename}.F90"
tmp_dir="${test_dir}/unit_tests/tmp"
sample_meta="${sample_files_dir}/check_fortran_to_metadata.meta"

# Run the script
opts="--ddt-names serling_t"
${f2m_script} --output-root "${tmp_dir}" ${opts} "${test_input}"
res=$?

retval=0
if [ ${res} -ne 0 ]; then
echo "FAIL: ccpp_fortran_to_metadata.py exited with error ${res}"
retval=${res}
elif [ ! -f "${tmp_dir}/${filename}.meta" ]; then
echo "FAIL: metadata file, '${tmp_dir}/${filename}.meta', not created"
retval=1
else
cmp --quiet "${sample_meta}" "${tmp_dir}/${filename}.meta"
res=$?
if [ ${res} -ne 0 ]; then
echo "FAIL: Comparison with correct metadata file failed"
retval=${res}
else
echo "PASS"
# Cleanup
rm "${tmp_dir}/${filename}.meta"
fi
fi
exit ${retval}
31 changes: 31 additions & 0 deletions test/unit_tests/sample_files/check_fortran_to_metadata.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[ccpp-table-properties]
name = do_stuff
type = scheme

[ccpp-arg-table]
name = do_stuff_run
type = scheme
[ const_props ]
standard_name = enter_standard_name_1
units = enter_units
type = ccpp_constituent_prop_ptr_t
dimensions = (enter_standard_name_5:enter_standard_name_6)
intent = in
[ twilight_zone ]
standard_name = enter_standard_name_2
units = enter_units
type = serling_t
dimensions = ()
intent = inout
[ errmsg ]
standard_name = enter_standard_name_3
units = enter_units
type = character | kind = len=512
dimensions = ()
intent = out
[ errflg ]
standard_name = enter_standard_name_4
units = enter_units
type = integer
dimensions = ()
intent = out
28 changes: 28 additions & 0 deletions test/unit_tests/sample_files/test_fortran_to_metadata.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module dme_adjust

use ccpp_kinds, only: kind_phys

implicit none

contains
!===============================================================================
!> \section arg_table_do_stuff_run Argument Table
!! \htmlinclude do_stuff_run.html
!!
subroutine do_stuff_run(const_props, twilight_zone, errmsg, errflg)
!
! Arguments
!
type(ccpp_constituent_prop_ptr_t), intent(in) :: const_props(:)
type(serling_t), intent(inout) :: twilight_zone

character(len=512), intent(out) :: errmsg
integer, intent(out) :: errflg

errmsg = ' '
errflg = 0
twilight_zone('adjust_set')

end subroutine dme_adjust_run

end module dme_adjust