
C INITIALIZES I/O SYSTEM COMMON BLOCKS.
C DEPENDENT OF CRAPSI, SHOULD *NEVER* BE CALLED DIRECTLY.

      SUBROUTINE POPCORN(MEMSIZ)
      IMPLICIT INTEGER (A-Z)

      COMMON /INCORE/ ICREC(2),USEC,IXT(2),IMOD(2)
      COMMON /MACHSP/ IINTLN,IFLTLN,IINTFP,IALONE,IBITWD
      COMMON /FILES/ LUOUT,MOINTS
      COMMON /FLAGS/ IFLAGS(100)
      COMMON /IOPOS/ ICRSIZ,ICHCSZ,IOFFX(2),LENREC
      COMMON /FILSPC/ IBUFLN,IPRCLN,IPRCWD
      COMMON /ISTART/ I0
      COMMON /CACHEINF/ CACHNUM,CACHNMP1,CACHDIR(100),CACHPOS(100),
     &                  CACHFILE(100),CACHMOD(100),OLDEST

      if (memsiz.lt.1) return

C SET IOPOS COMMON BLOCK PARAMETERS

      CALL IZERO(CACHDIR,400)

C   o SIZE OF INDIVIDUAL CACHE RECORD
      ICHCSZ=IFLAGS(37)

C   o NUMBER OF RECORDS IN I/O CACHE
      CACHNUM=IFLAGS(44)
      CACHNMP1=CACHNUM+1

C   o CORE SIZE LEFT AFTER ALLOCATING CACHE AREA
      ICRSIZ=MEMSIZ-CACHNUM*ICHCSZ
c NO - make sure that icrsiz is even for alignment
      icrsiz=icrsiz-mod(icrsiz,2)

C   o PHYSICAL RECORD SIZE (INTEGERS)
      LENREC=ICHCSZ

C   o PHYSICAL RECORD SIZE (INTEGERS)
      IPRCWD=ICHCSZ

C   o PHYSICAL RECORD SIZE (BYTES)
      IPRCLN=ICHCSZ*IINTLN

c YAU - This was obsoleted by replacing the only two occurances of idaccr
c with iprcwd*idaccm.
cC   o PHYSICAL RECORD SIZE (RECLS)
c      idaccr=iprcwd*idaccm

C CACHE OFFSETS IN ICORE ARRAY
      IOFF=I0
      DO I=1,CACHNUM
         CACHPOS(I)=IOFF
         IOFF=IOFF+LENREC
      END DO
      I0=IOFF

      RETURN
      END

