       SUBROUTINE Z_SET_GLOBAL(NAME,VALUE)
C
C----------------------------------------------------------------------
C
C.IDENTIFICATION: Subroutine Z_SET_GLOBAL
C.LIBRARY:        VOS (experimental version)
C.AUTHOR:         L.Chiappetti - IFCTR Milano
C.VERSIONS:       0.0 - 09 Apr 92 - Test version (Ultrix)
C                 0.1 - 19 Jun 92 - finalised interface to new zc_setenv
C                 0.2 - 26 Oct 92 - only XAS_ prefixed variables are set
C.VERSIONS:       1.0 - 29 Oct 92 - New error handling codes
C                 1.1 - 14 Jan 93 - fixed bug : VOSCOMMON_ERROR now initialized to zero
C                 1.2 - 26 May 94 - now calls ZC_PUTENV
C.PURPOSE:        set a global variable (character only)
C.METHOD:         use environment variables
C                 plus environment saved in backing file (this is
C                 reloaded only the first time the routine is called
C                 in each program)
C
C.SYNTAX:         CALL Z_SET_GLOBAL(name,value)
C.PARAMETERS:     CHARACTER*(*) name     : global variable name (in)
C-                CHARACTER*(*) value    : global variable value (in)
C.RESTRICTIONS:   variable 'name' is equated to symbol XAS_'name'
C                 if return of the value to the parent shell is wished,
C                 one shall execute an eval `importback`.
C                 It is also strongly recommended NOT to use this call
C                 to set non-XAS variables, and NOT to use setenv (but
C                 only XASSET) to set XAS variables    
C.NOTES:
C.FILES:          none
C.REFERENCES:     C wrappers ZC_PUTENV in VOS library
C
C----------------------------------------------------------------------
C
C      INCLUDE       'implicit_none.inc'
       CHARACTER*(*) NAME,VALUE
       INCLUDE       'voscommon.inc'
       INCLUDE       'errors.inc'
       INTEGER       LNAME,KNAME
       INTEGER       ZC_PUTENV,TRUE_LENGTH,NTIMES
       SAVE          NTIMES
       DATA          NTIMES/0/
C
C      initialize error code
       VOSCOMMON_ERROR=0
C
C      first time only, make sure to update environment from disk
       IF(NTIMES.EQ.0)THEN
         NTIMES=1
         CALL Z_INITENV
C-->     test VOS errors ?
       ENDIF  
C
C      arguments shall be stripped of trailing blanks
       LNAME=TRUE_LENGTH(NAME)  
       KNAME=TRUE_LENGTH(VALUE)    
C      it shall also be converted to upper case
       CALL UPCASE(NAME)
C
C      if VALUE is blank protect
C-->    so that ZC_PUTENV can do an unsetenv ...in the future !
       IF(KNAME.NE.0)THEN
          VOSCOMMON_SYSTEMERROR=ZC_PUTENV('XAS_'//NAME(:LNAME)//CHAR(0),
     .    VALUE(:KNAME)//CHAR(0))
       ELSE
          VOSCOMMON_SYSTEMERROR=ZC_PUTENV('XAS_'//NAME(:LNAME)//CHAR(0),
     .    CHAR(0)//CHAR(0))
       ENDIF
C      Return codes from C wrapper ZC_PUTENV are :
C             0 for success
C           TBD if  unable to extend environment 
C      VOSCOMMON_SYSTEMERROR shall be normalized to a VOS error code
       IF(VOSCOMMON_SYSTEMERROR.NE.0)VOSCOMMON_ERROR=VE_GLOBAL
       RETURN
       END
