c--------------------------------------------------------------
      subroutine trxpl_sc_init(ztime0,ztavg,
     >   tokdev,runid,zdate,scvals,sclabs,numsc,maxsc)
c
c  setup, initialize:  scalar values and scalar labels arrays
c
c  "Ufiles" style scalars
c
      implicit NONE
      INTEGER, PARAMETER :: R8=SELECTED_REAL_KIND(12,100)
c
c  input:
      real*8 ztime0                     ! time of interest (secs)
      real*8 ztavg                      ! +/- averaging time (secs)
      integer maxsc                     ! max no. of scalars
c
c  output:
      character*4 tokdev                ! device label
      character*(*) runid               ! runid
      character*10 zdate                ! shot date
      real*8 scvals(maxsc)              ! scalar values
      character*10 sclabs(3,maxsc)      ! scalar labels
      integer numsc                     ! actual number of defined scalars
c
c----------------------------------
      integer i,ilparen,irparen,ilblank,istyle,ierr,ilr,itmp
      character*40 run_label
      character*4 zmds
      integer lunzer
c----------------------------------
c
      numsc=0
      do i=1,maxsc
         scvals(i)=0.0_R8
         sclabs(1,i)=' '
         sclabs(2,i)=' '
         sclabs(3,i)=' '
      enddo
c
c  1st scalar will contains RUNID information
c
c  get tokdev and run_label information
c  use trread routine
c
      call tget_rlbl(tokdev,run_label)
      write(6,*) ' tokdev    = "',trim(tokdev),'"'
      write(6,*) ' run_label = "',trim(run_label),'"'
c
      numsc=1
      sclabs(1,numsc)='RUNID:'
      ilparen=index(run_label,'(')
      zdate=' ???? '
      if(ilparen.gt.0) then
         istyle=1
         irparen=index(run_label,')')
         if(irparen.le.0) then
            write(lunzer(0),*)
     >         ' %run_label:  no closing parentheses: ',run_label
            irparen=max(ilparen+2,len_trim(run_label))
         endif
         sclabs(2,numsc)=run_label(1:max(1,ilparen-1))
         sclabs(3,numsc)=run_label(ilparen+1:irparen-1)
         runid=sclabs(2,numsc)
      else
         istyle=2
         ilblank=index(run_label,' ')
         sclabs(2,numsc)=run_label(1:max(1,ilblank-1))
         itmp=index(sclabs(2,numsc),'.')
         if(itmp.gt.0) zdate=sclabs(2,numsc)(itmp+1:)
         sclabs(3,numsc)=run_label(ilblank+1:ilblank+10)
         runid=sclabs(3,numsc)
      endif
      write(6,*) ' runid     = "',trim(runid),'"'
c
c  see if this is MDS+ or a file
c
      call tgethost(zmds,run_label)
      if(zmds.eq.'MDS+') then
         scvals(numsc)=istyle
      else
         scvals(numsc)=0.0_R8
      endif
c
c  save the hostname
c
      numsc=numsc+1
      if(zmds.eq.'MDS+') then
         sclabs(1,numsc)='MDS_HOST:'
      else
         sclabs(1,numsc)='FILE_HOST:'
      endif
      sclabs(2,numsc)=run_label(1:10)
      sclabs(3,numsc)=run_label(11:20)
      scvals(numsc)=scvals(numsc-1)
c
c  save the username
c
      numsc=numsc+1
      call sget_user(run_label)
      sclabs(1,numsc)='USER:'
      sclabs(2,numsc)=run_label(1:10)
      sclabs(3,numsc)=run_label(11:20)
      scvals(numsc)=0.0_R8
c
c  save the time of interest and averaging time
c
      numsc=numsc+1
      scvals(numsc)=ztime0
      sclabs(1,numsc)='TIME:'
      sclabs(2,numsc)='time'
      sclabs(3,numsc)='s'
c
      numsc=numsc+1
      scvals(numsc)=ztavg
      sclabs(1,numsc)='DT_AVG:'
      sclabs(2,numsc)='avg +/-'
      sclabs(3,numsc)='s'
c
c  OK -- put plasma current in last scalar.  additional scalars beyond
c  this will be at the user's discretion
c
      numsc=numsc+1
      sclabs(1,numsc)='PCUR:'
      sclabs(2,numsc)='PCUR'
      call trx_scal('PCUR',run_label,scvals(numsc),ierr)
      sclabs(3,numsc)=run_label
c
      return
      end
