Commit cc28fb57 authored by Jorn Bruggeman's avatar Jorn Bruggeman
Browse files

pyfabm: provide access to error messages

parent 7530d47e
......@@ -62,6 +62,8 @@ fabm.get_coupling.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_void_p),ctype
fabm.get_coupling.restype = None
fabm.get_error_state.argtypes = []
fabm.get_error_state.restype = ctypes.c_int
fabm.get_error.argtypes = [ctypes.c_int, ctypes.c_char_p]
fabm.get_error.restype = None
# Read access to variable attributes
fabm.variable_get_metadata.argtypes = [ctypes.c_void_p,ctypes.c_int,ctypes.c_char_p,ctypes.c_char_p,ctypes.c_char_p]
......@@ -180,6 +182,12 @@ def createPrettyUnit(unit):
def hasError():
return fabm.get_error_state() != 0
def getError():
if hasError():
strmessage = ctypes.create_string_buffer(1024)
fabm.get_error(1024, strmessage)
return strmessage.value.decode('ascii')
def printTree(root,stringmapper,indent=''):
"""Print an indented tree of objects, encoded by dictionaries linking the names of children to
their subtree, or to their object. Objects are finally printed as string obtained by
......
......@@ -25,6 +25,7 @@ except ImportError:
def processFile(infile,outfile,subtract_background=False,add_missing=False):
# Create model object from YAML file.
model = pyfabm.Model(infile)
assert not pyfabm.hasError(), 'An error occurred while parsing %s:\n%s' % (infile, pyfabm.getError())
# Load the old configuration
with open(infile,'rU') as f:
......
......@@ -42,6 +42,7 @@
real(c_double),pointer :: column_depth
type (type_link_list),save :: coupling_link_list
logical, save :: error_occurred = .false.
character(len=:), allocatable, save :: error_message
type (type_property_dictionary),save,private :: forced_parameters,forced_couplings
......@@ -193,6 +194,13 @@
get_error_state = logical2int(error_occurred)
end function get_error_state
subroutine get_error(length, message) bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: get_error
integer(c_int), intent(in), value :: length
character(kind=c_char),intent(out),dimension(length) :: message
call copy_to_c_string(error_message, message)
end subroutine get_error
integer(c_int) function model_count() bind(c)
!DIR$ ATTRIBUTES DLLEXPORT :: model_count
......@@ -670,9 +678,9 @@
class (type_python_driver),intent(inout) :: self
character(len=*), intent(in) :: location,message
if (error_occurred) return
error_occurred = .true.
!write (*,*) trim(location)//': '//trim(message)
!stop 1
error_message = trim(location) // ': ' // trim(message)
end subroutine python_driver_fatal_error
subroutine python_driver_log_message(self,message)
......
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