<commit_before>! BIND(C)-based wrapper for {{ context.filename }}
! This file was generated by F2x. Please do not edit directly.
MODULE {{ src.module_name }}_WRAP
	USE, INTRINSIC :: ISO_C_BINDING
	USE WRAP_UTIL
{%- for use in src.uses %}
	USE {{ use.name }}
{%- endfor %}
	USE {{ src.module_name }}
	
	IMPLICIT NONE
	
	INTEGER, PARAMETER :: LF = 8 ! TODO: Move to configuration

CONTAINS
{%- for type_def in src.type_defs %}
	
	!------------------------------------------------------------
	! Interface for {{ type_def.name }} from {{ src.module_name }}.
	!
	FUNCTION {{ type_def.name }}_NEW() BIND(C, NAME="{{ type_def.name }}_new")
		TYPE(C_PTR) :: {{ type_def.name }}_NEW
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		ALLOCATE({{ type_def.name}}_INTERN)
		{{ type_def.name }}_NEW = C_LOC({{ type_def.name }}_INTERN)
	END FUNCTION
	
	SUBROUTINE {{ type_def.name }}_FREE({{ type_def.name }}_INST) BIND(C, NAME="{{ type_def.name }}_free")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		DEALLOCATE({{ type_def.name }}_INTERN)
	END SUBROUTINE
{% for field in type_def.fields %}
{%- if field.type_name %}
	FUNCTION {{ type_def.name }}_GET_{{ field.name }}({{ type_def.name }}_INST) BIND(C, NAME="{{ type_def.name }}_get_{{ field.name }}")
		TYPE(C_PTR) :: {{ type_def.name }}_GET_{{ field.name }}
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		TYPE({{ field.type_name }}), POINTER :: {{ field.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		{{ field.name }}_INTERN => {{ type_def.name }}_INTERN%{{ field.name }}
		{{ type_def.name }}_GET_{{ field.name }} = C_LOC({{ field.name }}_INTERN)
	END FUNCTION
{% elif field.intrinsic_type_char %}
	SUBROUTINE {{ type_def.name }}_GET_{{ field.name }}({{ type_def.name }}_INST, {{ field.name }}_VALUE) BIND(C, NAME="{{ type_def.name }}_get_{{ field.name }}")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ field.name }}_VALUE
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		CALL F_C_STRING({{ type_def.name }}_INTERN%{{ field.name }}, {{ field.char_length }}, {{ field.name }}_VALUE)
	END SUBROUTINE

	SUBROUTINE {{ type_def.name }}_SET_{{ field.name }}({{ type_def.name }}_INST, {{ field.name }}_VALUE) BIND(C, NAME="{{ type_def.name }}_set_{{ field.name }}")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ field.name }}_VALUE
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		CALL C_F_STRING({{ field.name }}_VALUE, {{ field.char_length }}, {{ type_def.name }}_INTERN%{{ field.name }})
	END SUBROUTINE
{% else %}
	FUNCTION {{ type_def.name }}_GET_{{ field.name }}({{ type_def.name }}_INST) BIND(C, NAME="{{ type_def.name }}_get_{{ field.name }}")
		{% if field.type %}{{ field.type }}{% if field.kind %}(KIND={{ field.kind }}){% endif %}{% else %}{{ field.double_type }}{% endif %} :: {{ type_def.name }}_GET_{{ field.name }}
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		{{ type_def.name }}_GET_{{ field.name }} = {{ type_def.name }}_INTERN%{{ field.name }}
	END FUNCTION
	
	SUBROUTINE {{ type_def.name }}_SET_{{ field.name }}({{ type_def.name }}_INST, {{ field.name }}_VALUE) BIND(C, NAME="{{ type_def.name }}_set_{{ field.name }}")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		{% if field.type %}{{ field.type }}{% if field.kind %}(KIND={{ field.kind }}){% endif %}{% else %}{{ field.double_type }}{% endif %}, VALUE, INTENT(IN) :: {{ field.name }}_VALUE
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN

		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		{{ type_def.name }}_INTERN%{{ field.name }} = {{ field.name }}_VALUE
	END SUBROUTINE
{% endif -%}
{% endfor -%}
{% endfor %}

	!------------------------------------------------------------
	! Exported functions and subroutines
	!
{%- for function in src.functions %}{% if not config.has_option('ignore', function.name) %}
!	FUNCTION {{ src.module_name }}_{{ function.name }}({% for arg in function.args %}{{ arg.name }}{% if not loop.last %}, {% endif %}{% endfor %}) BIND(C)
{% for arg_type in function.arg_types %}
!{{ arg_type._ast }}
{% endfor %}
!	END FUNCTION
{% endif %}{% endfor %}
{%- for subroutine in src.subroutines %}
!	SUBROUTINE {{ src.module_name }}_{{ subroutine.name }}({% for arg in subroutine.args %}{{ arg.name }}{% if not loop.last %}, {% endif %}{% endfor %}) BIND(C)
{% for arg_type in subroutine.arg_types %}
!{{ arg_type._ast }}
{% endfor %}
!	END SUBROUTINE
{% endfor %}

	!------------------------------------------------------------
	! Custom extensions
	!
END<commit_msg>First framework for exporting subroutines added.<commit_after>! BIND(C)-based wrapper for {{ context.filename }}
! This file was generated by F2x. Please do not edit directly.
MODULE {{ src.module_name }}_WRAP
	USE, INTRINSIC :: ISO_C_BINDING
	USE WRAP_UTIL
{%- for use in src.uses %}
	USE {{ use.name }}
{%- endfor %}
	USE {{ src.module_name }}
	
	IMPLICIT NONE
	
	INTEGER, PARAMETER :: LF = 8 ! TODO: Move to configuration

CONTAINS
{%- for type_def in src.type_defs %}
	
	!------------------------------------------------------------
	! Interface for {{ type_def.name }} from {{ src.module_name }}.
	!
	FUNCTION {{ type_def.name }}_NEW() BIND(C, NAME="{{ type_def.name }}_new")
		TYPE(C_PTR) :: {{ type_def.name }}_NEW
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		ALLOCATE({{ type_def.name}}_INTERN)
		{{ type_def.name }}_NEW = C_LOC({{ type_def.name }}_INTERN)
	END FUNCTION
	
	SUBROUTINE {{ type_def.name }}_FREE({{ type_def.name }}_INST) BIND(C, NAME="{{ type_def.name }}_free")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		DEALLOCATE({{ type_def.name }}_INTERN)
	END SUBROUTINE
{% for field in type_def.fields %}
{%- if field.type_name %}
	FUNCTION {{ type_def.name }}_GET_{{ field.name }}({{ type_def.name }}_INST) BIND(C, NAME="{{ type_def.name }}_get_{{ field.name }}")
		TYPE(C_PTR) :: {{ type_def.name }}_GET_{{ field.name }}
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		TYPE({{ field.type_name }}), POINTER :: {{ field.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		{{ field.name }}_INTERN => {{ type_def.name }}_INTERN%{{ field.name }}
		{{ type_def.name }}_GET_{{ field.name }} = C_LOC({{ field.name }}_INTERN)
	END FUNCTION
{% elif field.intrinsic_type_char %}
	SUBROUTINE {{ type_def.name }}_GET_{{ field.name }}({{ type_def.name }}_INST, {{ field.name }}_VALUE) BIND(C, NAME="{{ type_def.name }}_get_{{ field.name }}")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ field.name }}_VALUE
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		CALL F_C_STRING({{ type_def.name }}_INTERN%{{ field.name }}, {{ field.char_length }}, {{ field.name }}_VALUE)
	END SUBROUTINE

	SUBROUTINE {{ type_def.name }}_SET_{{ field.name }}({{ type_def.name }}_INST, {{ field.name }}_VALUE) BIND(C, NAME="{{ type_def.name }}_set_{{ field.name }}")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ field.name }}_VALUE
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		CALL C_F_STRING({{ field.name }}_VALUE, {{ field.char_length }}, {{ type_def.name }}_INTERN%{{ field.name }})
	END SUBROUTINE
{% else %}
	FUNCTION {{ type_def.name }}_GET_{{ field.name }}({{ type_def.name }}_INST) BIND(C, NAME="{{ type_def.name }}_get_{{ field.name }}")
		{% if field.type %}{{ field.type }}{% if field.kind %}(KIND={{ field.kind }}){% endif %}{% else %}{{ field.double_type }}{% endif %} :: {{ type_def.name }}_GET_{{ field.name }}
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN
		
		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		{{ type_def.name }}_GET_{{ field.name }} = {{ type_def.name }}_INTERN%{{ field.name }}
	END FUNCTION
	
	SUBROUTINE {{ type_def.name }}_SET_{{ field.name }}({{ type_def.name }}_INST, {{ field.name }}_VALUE) BIND(C, NAME="{{ type_def.name }}_set_{{ field.name }}")
		TYPE(C_PTR), VALUE, INTENT(IN) :: {{ type_def.name }}_INST
		{% if field.type %}{{ field.type }}{% if field.kind %}(KIND={{ field.kind }}){% endif %}{% else %}{{ field.double_type }}{% endif %}, VALUE, INTENT(IN) :: {{ field.name }}_VALUE
		TYPE({{ type_def.name }}), POINTER :: {{ type_def.name }}_INTERN

		CALL C_F_POINTER({{ type_def.name }}_INST, {{ type_def.name }}_INTERN)
		{{ type_def.name }}_INTERN%{{ field.name }} = {{ field.name }}_VALUE
	END SUBROUTINE
{% endif -%}
{% endfor -%}
{% endfor %}
{% if config.has_section('export') %}
{%- set exports = config.options('export') %}
	!------------------------------------------------------------
	! Exported functions and subroutines
	!
{%- for function in src.functions %}{% if function.name.lower() in exports %}{% set func_name = config.get('export', function.name) %}
	FUNCTION {{ func_name.upper() }}({% for arg in function.args %}{{ arg.name }}{% if not loop.last %}, {% endif %}{% endfor %}) BIND(C, NAME="{{ func_name }}")
{% for arg_type in function.arg_types %}
!{{ arg_type._ast }}
{% endfor %}
	END FUNCTION
{% endif %}{% endfor %}
{%- for subroutine in src.subroutines %}{% if subroutine.name.lower() in exports %}{% set sub_name = config.get('export', subroutine.name) %}
	SUBROUTINE {{ sub_name.upper() }}({% for arg in subroutine.args %}{{ arg.name }}{% if not loop.last %}, {% endif %}{% endfor %}) BIND(C, NAME="{{ sub_name }}")
{% for arg_type in subroutine.arg_types %}
!{{ arg_type._ast }}
{% endfor %}
	END SUBROUTINE
{% endif %}{% endfor %}
{% endif %}
	!------------------------------------------------------------
	! Custom extensions
	!
END
{'fraction_non_alphanumeric': 0.23650911797543728, 'fraction_numerical': 0.0003721622627465575, 'mean_word_length': 3.8245062836624775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5369938', 'n_tokens_mistral': 4224, 'n_tokens_neox': 3934, 'n_words': 869}