      REAL FUNCTION calibc()
*********************************************************
*                                                       *
* This file was generated by HUWFUN.                    *
*                                                       *
*********************************************************
*
*     Ntuple Id:      2    
*     Ntuple Title:   Pamela data
*     Creation:       13/07/2004 11.39.53
*
*********************************************************
*
      INCLUDE 'comcheck.txt'
*
      vector pede(2,22,96)
      vector matmip(2,22,96)
      real bas, valore
      integer m, inf, sup
*
*--   Enter user code here
*     
      do i=1,2
         do j=1,22
c
c     commenta questo per la mip totale globale
c
c            if (i.eq.2.and.j.eq.1) then
               pre = 0
               do k=1,96
                  if (mod(k+15,16).eq.0) pre = pre + 1
c     print *,k, pre
                  if (dexyc(i,j,k).gt.0) then
                     calbase = 0.
                     
                     if (base(i,j,pre).eq.0.) then
                        inf = (pre - 1) * 16 + 1
                        sup = pre * 16 
C                     print *,'i s ',inf,sup,pre
                        do m = inf, sup
                           valore = valore + dexyc(i,j,m) 
                        enddo
                        bas = valore / 16.
c                     bas = base(i,j,pre)
                     else
                        bas = base(i,j,pre)
                     endif
                     
                    calbase=(dexyc(i,j,k)-bas-pede(i,j,k))/matmip(i,j,k)
                     call hf1(1600,calbase,1.)
                  endif
                  call hf1(1700,dexyc(i,j,k),1.)
                  call hf1(1800,dexy(i,j,k),1.)
                  call hf1(1900,base(i,j,pre),1.)
c               if (cal_rms(i,j,k).ne.0.)
c     &         print *,'rms ',cal_rms(i,j,k),' i=',i,' j=',j,' k=',k
               enddo
c
c     e commenta anche qua ovviamente!
c
c            endif
         enddo
      enddo      
c
      calib = 1.
*
      END
