How to implement a couple of PXF routines?

Walter Spector w6ws@earthlink.net
Sun Aug 5 17:15:00 GMT 2007


Gfortraners,

A few years ago, I wrote a nearly complete library conforming to the
POSIX 1003.9 Fortran bindings spec.  This to allow development of code
compatible with proprietary implementation of PXF, including Cray, SGI,
and Intel.  (There are, and have been others, too.)  These are incredibly
useful in Fortran programs which require more system services than normal
Fortran can provide.  And, if I may opine, more portable than attempting
to use C Interop to do the same.  (For example, C Interop has no way of
peering into C header files to do a proper job of magically mapping C structs
into Fortran derived types...)

In my library, there are a few entry points that need custom code for
each Fortran implementation.  Not being familiar with gfortrans source,
yet, I was wondering what would be the best way to implement the following:

1.) PXFFILENO - Given a Fortran unit 'iunit', return the POSIX file descriptor
associated with that unit.  If all is well, 0 is returned in ierror.  Otherwise
ierror returns EINVAL (iunit is not an open unit) or EBADF (iunit is not
connected with a file descriptor):

	call PXFFILENO (iunit, ifildes, ierror)

where:

	iunit - (default integer, intent IN) Fortran unit number

	ifildes - (default integer, intent OUT) POSIX file descriptor

	ierror - (default integer, intent OUT) returns 0 if ok, some errno if error

This routine should be fairly trivial to write.  I assume there is a struct
maintained by the I/O library that contains this information.


2.) PXFFDOPEN - Given an open file descriptor (e.g., from PXFOPEN or PXFCREAT),
PXFFDOPEN opens a Fortran logical unit on that FD:

	call PXFFDOPEN (ifildes, iunit, access, ierror)

where:

	ifildes - (default integer, intent IN) POSIX file descriptor

	iunit - (default integer, intent IN) Fortran unit number

	access - (character string, intent IN) A set of keyword=value clauses which
		define characteristics of the file:

	        Keyword   Values          Function        Default
 	       -------   ------          --------        -------
		'newline' 'yes'           I/O type        'yes'
			  'no'

		'blank'   'null'          Interpretation  'null'
			  'zero'          of blanks

		'status'  'old'           File status     'unknown'
			  'scratch'       at open
			  'unknown'

		'form'    'formatted'     Format type     'formatted'
			  'unformatted'

	ierror - (default integer, intent OUT) returns 0 if ok, some errno if error

After a successful PXFFDOPEN, one can use normal Fortran READ/WRITE statements
and/or PXFFGET/PXFFPUT, and so on, on the unit.

This may be a little more challenging.  My dummy routine has a simple parser
to validate and break apart the access string.  But getting through the OPEN
in a way that allows Fortran I/O to work on the unit is obviously the 'interesting'
part...

Is there any interest in getting these routines working with gfortran?

Walter Spector



More information about the Fortran mailing list