! This subroutine set the PLPLOT_LIB environment variable
! with the passed in PATH arguments. It shoud be called
! before any PLPLOT routines are called. 
!
! Example:
!        CALL SET_PLPLOT_LIBVAR("C:\PLPLOT_DATA")
!
! results in placing PLPLOT_LIB=C:\PLPLOT_DATA in the
! current program's environment so the PLPlot library
! will look in C:\PLPLOT_DATA for the PLPlot resources
!

      SUBROUTINE SET_PLPLOT_LIBVAR(PATH)
      USE ISO_C_BINDING
      IMPLICIT NONE
      CHARACTER(LEN=*) :: PATH
      CHARACTER(LEN=LEN_TRIM(PATH)+16) :: VAR_AND_VAL
      INTERFACE
        SUBROUTINE PUTENV(ARG) BIND(C,NAME="putenv")
        USE ISO_C_BINDING
        IMPLICIT NONE
        INTEGER(INT_PTR_KIND()),VALUE :: ARG
        END SUBROUTINE
      END INTERFACE

      VAR_AND_VAL="PLPLOT_LIB="//TRIM(PATH)//CHAR(0)
      CALL PUTENV(LOC(VAR_AND_VAL))
      
      END
