C   11/10/79 002232100  MEMBER NAME  HWORLD   (JADESR)      FORTRAN
      SUBROUTINE HWORLD(IPLG,JEMPTY,UNBAL)
C
C      SUM UP LEAD GLASS ENERGIES IN 12 DIFFERENT HALF-WORLDS AND SET
C      THE NUMBER JEMPTY = NR OF EMPTY HALFWORLDS
C      THE NUMBER UNBAL = SMALLEST RATIO BETWEEN OPPOSITE HALFWORLDS
C      IPLG = ADDRESS OF LEADGLASS BANK IN /BCS/
C                     J.OLSSON 11.10.79 (AFTER AN IDEA OF W.BARTEL)
C                     LAST CHANGE:       23.02.80
C
      IMPLICIT INTEGER*2 (H)
#include "cdata.for"
      COMMON /CHEADR/ HEAD(108)
      COMMON /CWORK/ SUM12(12),SUMWRD(12)
C
C  THE FOLLOWING ARRAY GIVES HELP INDICES FOR THE ENDCAP BLOCKS
C  A ROUGH DIVISION INTO 12 SECTORS CAUSES A ENDCAP BLOCK TO BELONG TO
C  ONE OR AT MOST TWO (NEIGHBOURING) SECTORS
C
      DIMENSION HELP(2,96)
      DATA HELP /1,0,1,2,2,3,3,0,1,0,1,2,2,0,2,3,3,0,1,0,1,0,1,2,
     1           2,3,3,0,3,0,1,0,1,0,1,2,2,0,2,0,2,0,2,3,3,0,3,0,
     2           4,0,4,5,5,6,6,0,4,0,4,5,5,0,5,6,6,0,4,0,4,0,4,5,
     3           5,6,6,0,6,0,4,0,4,0,4,5,5,0,5,0,5,0,5,6,6,0,6,0,
     4           7,0,7,8,8,9,9,0,7,0,7,8,8,0,8,9,9,0,7,0,7,0,7,8,
     5           8,9,9,0,9,0,7,0,7,0,7,8,8,0,8,0,8,0,8,9,9,0,9,0,
     6 10,0,10,11,11,12,12,0,10,0,10,11,11,0,11,12,12,0,10,0,10,0,10,11,
     7 11,12,12,0,12,0,10,0,10,0,10,11,11,0,11,0,11,0,11,12,12,0,12,0/
      DATA EMIN /50./
C
      JEMPTY = 0
      UNBAL = 1.E+06
      DO 1 I=1,12
      SUMWRD(I)=0.
    1 SUM12(I)=0.
C
C      GET LEAD GLASS ADRESSES
C
      NWO=IDATA(IPLG)
      IF(NWO.GT.3) GO TO 2
      WRITE(6,101) HEAD(18),HEAD(19)
101   FORMAT(' NO LEAD GLASS HITS IN RUN AND EVENT ',2I10)
      GO TO 999
2     IPLG2=2*IPLG + 8
      NWO=IPLG2+2*NWO-8
C
C     CALCULATE ROW , RING , ENDCAP ENERGIES
C
      ETOT = 0.
      DO 10 IJK=IPLG2,NWO,2
      IADR=HDATA(IJK-1)
      ETOT = ETOT + HDATA(IJK)
      IF(IADR.GT.2687) GO TO 11
C ROW NUMBER   0 - 83
      IROW = IADR/32
C SECTOR NUMBER   1 - 12    ( EACH SECTOR HAS 7 ROWS )
      IND12 = IROW/7 + 1
      SUM12(IND12) = SUM12(IND12) + HDATA(IJK)
      GO TO 10
  11  IADR = IADR - 2687
      IF(IADR.GT.96) IADR = IADR - 96
      IF(IADR.GT.96) GO TO 10
      IADDE = HDATA(IJK)
      IF(HELP(1,IADR).NE.0.AND.HELP(2,IADR).NE.0) IADDE = IADDE/2
      DO 12  II = 1,2
      IND12 = HELP(II,IADR)
12    IF(IND12.NE.0) SUM12(IND12) = SUM12(IND12) + IADDE
  10  CONTINUE
C
C      CALCULATE ENERGY ASYMMETRY, MEASURED BY NUMBER OF EMPTY H-WORLDS
C      A HALF-WORLD CONSISTS OF ANY CONSECUTIVE 6 SECTORS
C      CALCULATE ALSO RATIO BETWEEN OPPOSITE HALFWORLDS
C
      DO 13  II = 1,12
      VAR = 0.
      DO 16 JJ = 1,6
      KK = II + JJ - 1
      IF(KK.GT.12) KK = KK - 12
16    VAR = VAR + SUM12(KK)
      SUMX = ETOT - VAR
      IF(SUMX.LT.VAR.AND.VAR.GT.0.) RATIO = SUMX/VAR
      IF(SUMX.GT.VAR.AND.SUMX.GT.0.) RATIO = VAR/SUMX
      IF(RATIO.LT.UNBAL) UNBAL = RATIO
13    SUMWRD(II) = VAR
      DO 14  II = 1,12
14    IF(SUMWRD(II).LT.EMIN) JEMPTY = JEMPTY + 1
999   RETURN
      END
