C******************** START FILE INITVIS.FOR ; GROUP PLOTR1 *************
C---------------------------------------------------------
C  INITVIS
C
C  INITIALIZE ELVIS
C   created efeibush Oct 2002:  integrate with ElVis
C
C   Note: the COMMON blocks are local to this source file only:
C          cmn_trgraf_eflag
C          cmc_trgraf_elvis
C
C
      SUBROUTINE INITVIS(progname_in,scivis_flag)
C
      character*(*), intent(in) :: progname_in
      logical, intent(out) :: scivis_flag
C
C  START OF EXECUTABLE CODE
C
      integer str_length
      integer ilu, ilh, ilp, i, istat
      character*100 username, hostname, id, pidstr
      character*120 scivis_server
      integer collector
C
      logical elvis_flag
      common/cmn_trgraf_eflag/ elvis_flag
      character*20 progname
      common/cmc_trgraf_elvis/ progname
C
      external trgraf_elvis_bdata
C
      INCLUDE 'ELVIS_H'
C
C--------------------------------------------------------------
C
      call sget_env('ELVIS_SERVER',scivis_server)
      if(scivis_server.eq.' ') then
         scivis_flag=.FALSE.
         elvis_flag=.FALSE.
      else

         scivis_flag=.TRUE.
         elvis_flag=.TRUE.
         progname=trim(progname_in)

         ils=str_length(scivis_server)
         write(6,*)
     >      '%'//trim(progname)//':  detected ELVIS_SERVER = "',
     >      scivis_server(1:ils),'".'
C
         istat = ef_initialize()
C
         call sget_pid_str(pidstr, ilp)
         ilp = str_length(pidstr)
C
         call sget_user(username)
         ilu = str_length(username)
CCC        write(*,*) ' username = ', username(1:ilu)
C
         call sget_host(hostname)
         ilh = str_length(hostname)
CCC        write(*,*) ' hostname = ', hostname(1:ilh)
C
         id = 'anyone'
	 collector = 1
         istat = ef_register(trim(progname)//':'//pidstr(1:ilp),
     >      username, hostname, id, collector)

         call trgraf_wname_set(trim(progname)//'_'//pidstr(1:ilp)//
     >        '_'//trim(username)//'_'//trim(hostname))

         call trgraf_sname_clear
      endif
C
C  regardless of ELVIS status:
      progname=trim(progname_in)
      call ulower(progname)
      call urd_setprog(progname)
C
      RETURN
      END
C------------------------------------------------------------------------
      subroutine trgraf_elvis_progname(progname_out)
      character*(*), intent(out) :: progname_out

      logical elvis_flag
      common/cmn_trgraf_eflag/ elvis_flag
      character*20 progname
      common/cmc_trgraf_elvis/ progname

      if(.not.elvis_flag) then
         progname_out=' '
      else
         progname_out=progname
      endif

      return
      end

C------------------------------------------------------------------------
      subroutine trgraf_elvis_flag(elvis_flag_ret)

      logical, intent(out) :: elvis_flag_ret
C
      logical elvis_flag
      common/cmn_trgraf_eflag/ elvis_flag
C
      external trgraf_elvis_bdata
C
      elvis_flag_ret = elvis_flag

      return
      end
C------------------------------------------------------------------------
      block data trgraf_elvis_bdata
C
      logical elvis_flag
      common/cmn_trgraf_eflag/ elvis_flag
C
      data elvis_flag/.FALSE./
C
      end
C******************** END FILE INITVIS.FOR ; GROUP PLOTR1 ***************
