C------------------------------------------------
      INTEGER FUNCTION OPCALOL2(name,trkpaw,swcode1,swtrkcode1)
C------------------------------------------------
c
      IMPLICIT NONE
C
      INCLUDE 'INTEST.TXT'
C
      CHARACTER*200 name
      INTEGER swcode1, swtrkcode1
      INTEGER swcode, swtrkcode,trkpaw
C     
C
      INTEGER lrec
      INTEGER istat, ierr
      integer Iquest(100)    
      PARAMETER (lrec=8190)
C
      double precision al_p(5)
      REAL estrip(2,22,96), ispaw
      LOGICAL good2
      REAL xalig, yalig, zalig
C
      COMMON / clevel1 / al_p,estrip, ispaw,good2,
     &     xalig, yalig, zalig
      SAVE / clevel1 /
C
      REAL hmemor(10000000)
C      
      COMMON / SOFTWARE / SWCODE, SWTRKCODE
      SAVE / SOFTWARE /
C
      COMMON /pawc/hmemor
      save /pawc/
C
      Common /QUEST/ Iquest
      save /quest/
C     
      if ( trkpaw.eq.0 ) then    
         print *,'Calling HLIMIT'
         CALL HLIMIT(10000000)
         Iquest(10) = 512000
      else
         print *,'HLIMIT already called by optrklev2.for! '
      endif
C     
c      print *,'Open file...'
C
      CALL HROPEN(59,'Event',name,'npeq',lrec,istat)
      CALL HBNT(1,'Pamela Calo',' ')
      CALL HBSET('BSIZE',lrec,ierr)
c      CALL HBNAME(1,'calo',OBT,'OBT:R,headc:R,evfile:R,trigty:R,'//
      CALL HBNAME(1,'calo',OBT,'OBT:I,pkt_num:I,pro_num:I,trigty:R,'//
     &     'good:I,perr(4):I,swerr(4):I,crc(4):I,'//
     &     'nstrip:R,qtot:R,'//
     &     'ncore:R,qcore:R,impx:R,impy:R,tanx:R,tany:R,'//
     &     'nint:R,ncyl:R,qcyl:R,qtrack:R,qmax:R,'//
     &     'nx22:R,qx22:R,qq(4):R,'//
     &     'qtrackx:R,qtracky:R,dxtrack:R,dytrack:R,'//
     &     'qlast:R,nlast:R,qpre:R,npre:R,qpresh:R,npresh:R,'//
     &     'qlow:R,nlow:R,qtr:R,ntr:R,'//
     &     'planetot:R,qmean:R,varcfit(2):R,npcfit(2):I,'//
     &     'thex:R,they:R,'//
     &     'cibar(2,22):I,tibar(2,22):I,cbar(2,22):R,tbar(2,22):R')
C
      CALL HBNT(2,'Software version',' ')
      CALL HBSET('BSIZE',lrec,ierr)
      CALL HBNAME(2,'versions',swcode,'swcode:I,swtrkcode:I')
      swcode = swcode1
      swtrkcode = swtrkcode1
      call hfnt(2)
      OPCALOL2 = 0

      RETURN 
      END

