        subroutine BLDDEF(OFFSET,NREC)
      include 'SIZE.INC'
      include 'UNITS.INC'
        real MAS
        integer map(VARIEC), IBUFF(VARIEC)
        integer OFFSET,IN,NENT,I,NREC,MAPLO,MAPHI,L,M,IM,LL,K,J,IT
        integer RECDAT(FILDAT), HRECS, LRAIL
        character INPUT*80, TABLE*6, VARTAB*6, COM*1, COM1*1
        character CBUFF(VARCEC)*1, CCHAR*1
      write (PRINTR(MACHNO),5000)
5000  format (///,'1',15X,'+**********************+'/16X,'|        EXAMS
     &         |'/16X,'|    BLDDEF Utility    |'/16X,'|      02-Nov-88  
     &     |'/16X,'+**********************+')
      open (unit=AUDLUN(MACHNO),FILE='TYPE.DAT',status='OLD')
      open (unit=DOLUN(MACHNO),FILE='HELPVAR.DAT',status='OLD')
      if (.not.(TOPOPN(MACHNO))) then
         rewind AUDLUN(MACHNO)
         rewind DOLUN(MACHNO)
      endif
      IN = OFFSET
      NENT = VARIEC/3
      I = NREC/NENT
      if (I*NENT.lt.NREC) I = I+1
      MAPLO = IN+1
      MAPHI = IN+I
      write (PRINTR(MACHNO),5010)
5010  format (//' Pointers to the descriptive text entries are stored')
      if (MAPLO.eq.MAPHI) then
         write (PRINTR(MACHNO),5020) MAPLO
5020     format (' in record ',I5,'.')
      else
         write (PRINTR(MACHNO),5030) MAPLO,MAPHI
5030     format (' in records ',I5,' through ',I5,'.')
      endif
      write (PRINTR(MACHNO),5040)
5040  format (//' Element number -  Name  - Record no. - Offset -',' No.
     & of chars.'/' ==============   ======   ==========   ======  ',' =
     &============'/)
      IN = MAPHI
      L = 0
      M = 0
      MAS = 0.
      IM = 1
      map(IM) = IN+1
      map(IM+1) = 1
      LL = 0
100   continue
      read (AUDLUN(MACHNO),5050,end=150) COM,TABLE
      if (COM.eq.'*') go to 100
5050  format (A1,3X,A6)
110   continue
      read (DOLUN(MACHNO),5050,end=220) COM1,VARTAB
      if (COM1.eq.'*') go to 110
      if (TABLE.ne.VARTAB) go to 140
      do 130 I = 1, 10
         read (DOLUN(MACHNO),5060,end=230) INPUT
5060     format (A80)
         if (COM.eq.'C') go to 130
         if (I.eq.1) LL = LL+1
         K = LRAIL(INPUT,80)+1
         do 120 J = 1, K
            M = M+1
            MAS = MAS+1.
            L = L+1
            if (L.gt.VARCEC) then
               IN = IN+1
               write (RANUNT(MACHNO),rec=IN) CBUFF
               L = 1
            endif
            CCHAR = '$'
            if (J.ne.K) CCHAR = INPUT(J:J)
            CBUFF(L) = CCHAR
120      continue
130   continue
      if (COM.eq.'C') then
         write (PRINTR(MACHNO),5070) TABLE
5070     format (/' Labeled COMMON name--',A6/)
         go to 100
      endif
      map(IM+2) = M
      M = 0
      write (PRINTR(MACHNO),5080) LL,TABLE,map(IM),map(IM+1),map(IM+2)
5080  format (1X,6X,I3,6X,2X,A6,3X,3X,I4,7X,I4,10X,I4)
      IM = IM+3
      if (IM+2.le.VARIEC) then
         map(IM) = IN+1
         map(IM+1) = L+1
         go to 100
      endif
      write (RANUNT(MACHNO),rec=MAPLO) map
      write (PRINTR(MACHNO),5090) MAPLO,map(1),map(IM-3)
5090  format (/' Record ',I5,' contains pointers to the'/' text entries 
     &numbered ',I5,' through ',I5/)
      IM = 1
      MAPLO = MAPLO+1
      map(1) = IN+1
      map(2) = L+1
      go to 100
140   continue
      write (PRINTR(MACHNO),5100) TABLE,VARTAB,LL
5100  format (/' Input from file TYPE was    > ',A6/' Input from file HE
     &LPVAR was > ',A6/1X,I10,' records processed.')
      go to 240
150   continue
      IN = IN+1
      write (RANUNT(MACHNO),rec=IN) CBUFF
      write (PRINTR(MACHNO),5090) MAPLO,map(1),IN
      if (MAPLO.le.MAPHI) then
         map(IM+1) = M
         write (RANUNT(MACHNO),rec=MAPLO) map
      endif
      IT = IN-OFFSET
      HRECS = FILDAT/VARIEC
      if (FILDAT-VARIEC*HRECS.ne.0) HRECS = HRECS+1
      M = 0
      do 170 I = 1, HRECS
         read (RANUNT(MACHNO),rec=I) IBUFF
         do 160 L = 1, VARIEC
            M = M+1
            if (M.gt.FILDAT) go to 180
            RECDAT(M) = IBUFF(L)
160      continue
170   continue
180   continue
      RECDAT(7) = OFFSET+1
      RECDAT(8) = IN-OFFSET
      do 210 I = 1, HRECS
         J = (I-1)*VARIEC
         K = J+VARIEC
         J = J+1
         M = 0
         do 190 L = J, K
            M = M+1
            if (L.gt.FILDAT) go to 200
            IBUFF(M) = RECDAT(L)
190      continue
200      continue
         write (RANUNT(MACHNO),rec=I) IBUFF
210   continue
      write (PRINTR(MACHNO),5110) IT
5110  format (//1X,'Records created for the Model Parameters'/1X,'HELP t
     &ext database total ',I5)
      write (PRINTR(MACHNO),5120) MAS
5120  format (//' Total number of characters stored in the'/' descriptiv
     &e text records is ',F8.0)
      OFFSET = IN
      write (PRINTR(MACHNO),5130) LL
5130  format (/' End-of-file on file TYPE;',I10,' entries processed.')
      go to 240
220   continue
      write (PRINTR(MACHNO),5140) LL
5140  format (/' E-O-F on file HELPVAR;',I10,' records processed.')
      go to 240
230   continue
      write (PRINTR(MACHNO),5150) I,LL
5150  format (/' E-O-F while reading identification records.'/' Record n
     &umber = ',I3,' output record # ',I5)
240   continue
      close (unit=AUDLUN(MACHNO))
      close (unit=DOLUN(MACHNO))
      return
      end
