catching exceptions from fortran

john john.m.roach at
Thu Sep 11 15:43:08 CEST 2008

I wrapped some fortran code using F2PY and need to be able to catch
fortran runtime errors to run the following:

# "grid" is a wrapped fortran module
# no runtime errors incurred when run with the correct inputs for
	def readGrid( self, coord='xyz' ):
		mg = ( '.FALSE.', '.TRUE.' )
		success = False
		for m in mg:
			for f in form:
					if coord == 'xyz':
						self.grid.readxyz( self.filename, f, m )
						success = True
					elif coord == 'xyrb':
						self.grid.readxyrb( self.filename, f, m )
						success = True
						import sys
						print 'gridtype "' + str(coord) + '" not supported. ' \
								+ '<>'
		if not success:
			import sys
			print 'gridfile "' + str(self.filename) + '" not read in any
recognized format' \
					+ ' <>'

basically, what i want to happen is to try to run 'something' with the
wrapped fortran code and if that doesn't work (error encountered,
etc.) try something else.  is there an easier way to go about doing
this?  is there something i'm missing about catching exceptions here?

Thanks in advance!

More information about the Python-list mailing list