Re: 'getenv' behavior in NCL not as advertised...

From: Mary Haley (haley AT unknown)
Date: Thu Mar 01 2001 - 14:01:55 MST

  • Next message: Andy Holland: "ctrans"

    > According to
    >
    > http://ngwww.ucar.edu/ngdoc/ng/ref/ncl/functions/getenv.html,
    >
    > "The getenv function returns either an empty string when the shell
    > environment variable does not exist, or the string value of the
    > environment parameter requested."
    >
    > However, if I do a getenv on an undefined environment variable, I get
    > a fatal error:
    >
    > fatal:getenv : (NDAYS) is not a defined environment parameter
    >
    > Something of a curioisity.
    >
    > Gary Strand

    If "getenv" is passed an environment variable that doesn't exist, then
    the value returned will be a missing value. The fatal error message
    returned from "getenv" doesn't actually cause NCL to quit, which might
    be a little misleading.

    Gary later asked if there was a way to check the status of the return
    value from the "getenv" function so that if it fails, he won't try to
    access that environment variable.

    To do this, you can check if it is missing with the "ismissing"
    function as follows:

      if(.not.ismissing(getenv("FILENAME"))) then
        ...access the FILENAME environment variable...
      else
        ...do something else...
      end if
      
    --Mary Haley
    haley AT unknown



    This archive was generated by hypermail 2b29 : Thu Mar 01 2001 - 14:20:48 MST