Re: getting env. variables in gfortran...



On Thu, 13 Apr 2006, icksa1@xxxxxxxxx wrote:

Hi:
I'm trying to compile a code in gfortran that needs to know the values
of several environment variables...I was wondering if there was a
function, like getenv, that would return the values, something like...

path = getenv("PATH") or
call getenv("PATH",path)

Be careful what you ask for.

Rather than ask: "how can I do XXX in gfortan/ifort/icc/...?" it is generally better to ask: "is there a well documented, well engineered, and portable library that provides the functionality I need across a reasonable set of platforms?". This should lead you to consider using:

subroutine pxfgetenv( name, lenname, value, lenval, ierror )

c subroutine pxfgetenv() is described in section 4.6.1. the
c character length conventions are described in section 2.3.2.4.
c
c name [in] environment variable to be matched.
c lenname [in] length of name. if 0, trim trailing spaces.
c value [out] value of the variable.
c lenval [out] length of value. if 0, name was matched but no value.
c ierror [out] return code. 0 for success.
c EINVAL if not in the environment list.
c ETRUNC if value required truncation.
c -1 for other errors.
c

Google for "pxfgetenv" gives pages of hits (curiously, "libpxf" gets none). SGI's http://techpubs.sgi.com is a good place to read the IRIX man pages.

Gfortran almost certainly implements "getenv" functionality in some idiosyncratic, undocumented, and potentially unsafe (in the sense of not checking that the buffer is long enough to hold "$PATH") way. Walter Spector recently asked on this list for expressions of interest in his implementation of the POSIX bindings for Fortran, libpxf.

Ron Shepard also implemented some of the pxf functions. I've used his library wqith g77 on OS/2, Win16, and NeXtStep, assorted unixes, and linux. Now I'm using it with g95 on linux.

--
George N. White III <aa056@xxxxxxxxxxxxxx>

.



Relevant Pages

  • Re: IDS recommendations
    ... those are simply the facts in a large environment. ... vulnerabilities and insures proper functionality. ... applications in a large enterprise pretty much loses steam. ... is beta software and does not go through a quality assurance process. ...
    (Focus-IDS)
  • Re: Moving the Islands within Sequence Space
    ... level functional complexity beyond the 1000 fsaar threshold. ... To get a clear idea of why it is nonsense, let’s take the environment ... functionality, for functionality of a structure can only be assessed ... environment you choose a functional flagellar motility system, ...
    (talk.origins)
  • Re: Moving the Islands within Sequence Space
    ... The rule is that they _maintain_ the ability to reproduce, ... environment - or even a non-changing environment. ... beneficial sequence must be found by random mutations. ...  because functionality IS the availability of squares.. ...
    (talk.origins)
  • Re: Moving the Islands within Sequence Space
    ... Earth's existence. ... level functional complexity beyond the 1000 fsaar threshold. ... To get a clear idea of why it is nonsense, let’s take the environment ... functionality, for functionality of a structure can only be assessed ...
    (talk.origins)