      integer function rdrefe (ref, key, value, file, oper, maxch)
      integer ref
      integer maxch
      integer*2 key(*)
      integer*2 value(*)
      integer*2 file(*)
      integer*2 oper(*)
      logical more
      logical title
      integer ic
      integer nc
      integer status
      logical Memb(1)
      integer*2 Memc(1)
      integer*2 Mems(1)
      integer Memi(1)
      integer*4 Meml(1)
      real Memr(1)
      double precision Memd(1)
      complex Memx(1)
      equivalence (Memb, Memc, Mems, Memi, Meml, Memr, Memd, Memx)
      common /Mem/ Memd
      integer sp
      integer root
      integer line
      logical strne
      integer getlie
      integer ctowrd
      logical xerflg
      common /xercom/ xerflg
      integer*2 temple(20)
      integer*2 badtie(44)
      integer*2 st0001(9)
      integer*2 st0002(8)
      integer*2 st0003(2)
      save
      integer iyy
      data (temple(iyy),iyy= 1, 8) / 42, 46,100, 48,104, 44, 42, 95/
      data (temple(iyy),iyy= 9,16) /114, 97,119, 46,102,105,116,115/
      data (temple(iyy),iyy=17,20) / 91, 48, 93, 0/
      data (badtie(iyy),iyy= 1, 8) / 73,110,118, 97,108,105,100, 32/
      data (badtie(iyy),iyy= 9,16) /105,110,112,117,116, 32,102,105/
      data (badtie(iyy),iyy=17,24) /108,101, 58, 32,116,105,116,108/
      data (badtie(iyy),iyy=25,32) /101, 32,108,105,110,101, 32,105/
      data (badtie(iyy),iyy=33,40) /115, 32,105,110, 99,111,114,114/
      data (badtie(iyy),iyy=41,44) /101, 99,116, 0/
      data (st0001(iyy),iyy= 1, 8) / 82, 79, 79, 84, 78, 65, 77, 69/
      data (st0001(iyy),iyy= 9, 9) / 0/
      data st0002 / 75, 69, 89, 87, 79, 82, 68, 0/
      data st0003 /105, 0/
         call smark (sp)
         call salloc (root, 255 , 2)
         call salloc (line, 1023 , 2)
         more = .true.
110      if (.not.(more)) goto 111
            status = getlie (ref, memc(line))
            if (.not.(status .eq. -2)) goto 120
               goto 111
120         continue
            title = memc(line) .eq. 35
            if (.not.(title)) goto 130
               ic = 2
               goto 131
130         continue
               ic = 1
131         continue
            nc = ctowrd (memc(line), ic, memc(root), 255 )
            nc = ctowrd (memc(line), ic, key, maxch)
            nc = ctowrd (memc(line), ic, value, maxch)
            nc = ctowrd (memc(line), ic, file, maxch)
            nc = ctowrd (memc(line), ic, oper, maxch)
            if (.not.(title)) goto 140
               if (.not.(strne (memc(root), st0001) .or. strne (key, 
     *         st0002))) goto 150
                  call xerror(1, badtie)
                  if (xerflg) goto 100
150            continue
140         continue
            more = title .or. memc(root) .eq. 0 .or. key(1) .eq. 0
            goto 110
111      continue
         if (.not.(status .ne. -2 .and. oper(1) .eq. 0)) goto 160
            call opnrot (temple, memc(root), file, maxch)
            call xstrcy(st0003, oper, maxch)
160      continue
         call sfree (sp)
         rdrefe = (status)
         goto 100
100      return
      end
c     temple  template
c     rdrefe  rd_reffile
c     opnrot  opnroot
c     getlie  getline
c     badtie  badtitle
