C   25/11/83 312082016  MEMBER NAME  NEWCAL   (JADEGS)      FORTRAN
      SUBROUTINE NEWCAL
C
C  JADE GRAPHICS ROUTINE:   DOES A COMPLETE RECALIBRATION OF LEADGLASS
C                           AND JET CHAMBER DATA, AND CALLS LEADGLASS
C                           ANALYSIS AND PATTERN RECOGNITION.
C     LAST CHANGE 08.12.83                    J.OLSSON  25.11.83
C
      IMPLICIT INTEGER*2 (H)
      COMMON /CLGPRM/ ITH
#include "cgraph.for"
#include "cdata.for"
      COMMON /CHEADR/ HEAD(108)
      COMMON /CNWCAL/ IFILE
C
C  IF TRAILING PARAMETER NONZERO, INTERPRET AS CLUSTER THRESHOLD
C
      ITH = 45
      NN = ACMD
      IF(NN.GT.0) ITH = NN
C
      IF(HEAD(18).LT.100) CALL TRMOUT(80,' NO RECALIBRATION IN MC..^')
      IF(HEAD(18).LT.100) RETURN
C
      IF(IFILE.NE.0) GO TO 2201
      CALL TRMOUT(80,'FOR LG RECALIBR., YOU NEED BUPDAT0 AND BUPDAT1. YO
     $U HAVE ALLOCATED AUPDAT1^')
      CALL TRMOUT(80,'THEREFORE ONLY JETC DATA WILL BE RECALIBRATED^')
      GO TO 2202
2201  CALL BDLS('ALGN',1)
      CALL BDLS('LGCL',1)
C  DELETE ALREADY CALIBRATED JETC BANK AND RENUMBER UNCALIBRATED JETC
2202  IPNJET=IDATA(IBLN('JETC'))
      IF(IPNJET.LE.0) GO TO 1
      NUMJET=IDATA(IPNJET-2)
      IPNNEX=IDATA(IPNJET-1)
      IF(IPNNEX.LE.0) GO TO 411
      NUMNEX=IDATA(IPNNEX-2)
      CALL BDLS('JETC',NUMJET)
      CALL BRNM('JETC',NUMNEX,'JETC',NUMJET)
411   CONTINUE
      IPGVTX = IDATA(IBLN('GVTX'))
      IF(IPGVTX.LE.0) GO TO 3012
      NRGVTX = IDATA(IPGVTX - 2)
      CALL BDLS('GVTX',NRGVTX)
3012  IPDEDX = IDATA(IBLN('DEDX'))
      IF(IPDEDX.LE.0) GO TO 3013
      NRDEDX = IDATA(IPDEDX - 2)
      CALL BDLS('DEDX',NRDEDX)
3013  IPTOFR = IDATA(IBLN('TOFR'))
      IF(IPTOFR.LE.0) GO TO 3014
      NRTOFR = IDATA(IPTOFR - 2)
      CALL BDLS('TOFR',NRTOFR)
3014  CALL BGAR(IGA)
      CALL TRMOUT(80,'OLD BANKS DELETED (ALGN,LGCL,JETC,DEDX,TOFR,GVTX)
     $...^')
C
C  AFTER DELETION OF OLD BANKS, NOW RECALIBRATE
C
      IF(IFILE.NE.0) CALL LGCALB(*1225)
      GO TO 731
1225  CALL TRMOUT(80,'LEAD GLASS CALIBRATION HAS ABENDED..')
731   CALL JETCAL
      CALL TRMOUT(80,'LEADGLASS / JETCHAMBER DATA WERE RECALIBRATED^')
C
C Z-RECALIBRATION
C
      MODE = 1
      CALL ZSFIT(MODE,0,0,0,0,1) ! PMF 03/12/99: four dummy arguments + 6th argument added
      CALL TRMOUT(80,' Z-RECALIBRATION HAS BEEN PERFORMED,MODE=1...^')
C
C NOW CALL ANALYSIS ROUTINES
C
      CALL PATREC(0)
C
      IF(IFILE.EQ.0) GO TO 6600
      IF(ITH.NE.45) WRITE(6,1301) ITH
1301  FORMAT(' NON STANDARD THRESHOLD IN CLUSTER SEARCH:',I4,' MEV')
      CALL LGANAL
6600  IPPATR = IDATA(IBLN('PATR'))
      IPALGN = IDATA(IBLN('ALGN'))
      IPLGCL = IDATA(IBLN('LGCL'))
      CALL LGCDIR(IPPATR,IPALGN,IPLGCL)
      CALL TRMOUT(80,'PATREC,LGANAL / LGCDIR HAVE BEEN CALLED..^')
      RETURN
1     CONTINUE
      WRITE(6,5201)
5201  FORMAT(' NO JETC BANK, RECALIBRATION WILL NOT BE DONE...')
      RETURN
      END
