      subroutine sget_env(varname,value)
C
C  get the value of an environment variable
C
C  14Mar2005   jim.conboy@jet.uk
C              if __IDL6_FIX, use cget_env ; w/around for name conflict between
C              IDL Vn 6 & Lahey/F90 getenv functions
C
#ifdef __NAGWARE
      use f90_unix_env
#endif
C
      implicit none
C
C  input:
      character*(*) varname             ! name to be translated
C  output:
      character*(*) value               ! translation returned
C
C  local:
#if __CRAY || __NAGWARE 
      integer length,ierr
#endif
#if __IBM || __RS6000 || __IDL6_FIX || __X1
      integer iret, cget_env
#endif
C
C  value=' ' on exit, if the environment variable (logical name) is
C  undefined.
C
      integer ilvar
C
      ilvar=max(1,len_trim(varname))
C
      value=' '
C
#if __IBM || __RS6000 || __IDL6_FIX || __X1
      iret = cget_env(varname(1:ilvar),value)
      if( iret.eq.0 ) value=' '
#elif __CRAY
      call pxfgetenv(varname(1:ilvar),0,value,length,ierr)
      if(ierr.ne.0) value=' '
#elif __NAGWARE
      call getenv(varname(1:ilvar),value,length,ierr)
      if(ierr.ne.0) value=' '
#elif __ABS
      call getenv_(varname(1:ilvar),value)
#else
      call getenv(varname(1:ilvar),value)
#endif
      call str_pad(value)
      return
      end
