catching exceptions from fortran

john john.m.roach at gmail.com
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
filetype
#-------------------------------
	def readGrid( self, coord='xyz' ):
		mg = ( '.FALSE.', '.TRUE.' )
		form = ( 'FORMATTED', 'UNFORMATTED' )
		success = False
		for m in mg:
			for f in form:
				try:
					if coord == 'xyz':
						self.grid.readxyz( self.filename, f, m )
						success = True
					elif coord == 'xyrb':
						self.grid.readxyrb( self.filename, f, m )
						success = True
					else:
						import sys
						print 'gridtype "' + str(coord) + '" not supported. ' \
								+ '<IO.Plot3d.Plot3d.read>'
				except:
					continue
		if not success:
			import sys
			print 'gridfile "' + str(self.filename) + '" not read in any
recognized format' \
					+ ' <IO.Plot3d.Plot3d.read>'
#----------------------------


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