      SUBROUTINE RESET(NA,KPARA)
C SUBROUTINE TO DETERMINE THE PROPER VALUES OF CRYSTALLOGRAPHIC 
C  PARAMETERS THAT ARE FUNCTIONS OF OTHER PARAMETERS.. 
      INCLUDE 'RFINE.PRM'
      INCLUDE 'A.INC'
      INCLUDE 'D.INC'
      INCLUDE 'CNSTRS.INC'
      INCLUDE 'XPAR.INC'
      INCLUDE 'LSMAT.INC'
      INCLUDE 'E.INC'
C
      INCLUDE 'SHIFT.INC'
C
      LDEGN=2*NDEGN 
      IF(NA.GT.0)GO TO 340
      IF(NPAR.NE.0.AND.KPARA.EQ.0)CALL FILLIN
C ARE THERE ANY SPECIAL PARAMETERS THAT ARE THEMSELVES DEPENDENT
C  (AS IN NON-CRYSTALLOGRAPHIC SYMMETRY, ISOTROPIC TRANSLATION OR
C  LIBRATION, ETC.)? THESE DEPENDENCIES MUST BE SIMPLE MULTIPLIERS.
      do i=1,ldegn,2
        if(i3(kdegn(i)).eq.0)then
          j=i4(kdegn(i))
c Initialize Dependent parameter to zero
          par(j)=0. 
	endif
      enddo
      do i=1,ldegn,2
        if(i3(kdegn(i)).eq.0)then
            j=i4(kdegn(i))
	    ll=i2(kdegn(i)) 
c if independent parameter is 0,0, initialize to constant.
            if(ll.eq.0)then
	      par(j)=aa(i+1)
	    else
c if independent parameter is not 0,0, apply constraint
	      par(j)=par(j)+par(ll)*aa(i+1) 
	    endif
	endif
      enddo
      RETURN
C COMPUTE NEW VALUES OF PARAMETERS FOR ATOM NA. 
  340 NPARA=5
      IF(ISOT(NA).GE.1)NPARA=NPARA+5
      IF(ISOT(NA).GE.2)NPARA=NPARA+10
      IF(ISOT(NA).GE.3)NPARA=NPARA+15
      IF(LDEGN.LE.0)GO TO 720
      DO 710 J=1,NPARA 
C IS PARAMETER INDEPENDENT? 
      IF(IPARA(KPARA+J).GT.0)GO TO 710
C IS THIS PARAMETER DEPENDENT ON ANY OTHERS?
      DO 700 K=1,LDEGN,2
      IF(I3(KDEGN(K)).NE.NA.OR.I4(KDEGN(K)).NE.J)GO TO 700
C DEPENDENT PARAMETER. SET IT.
      IF(IPARA(KPARA+J).LT.0)GO TO 700
      IPARA(KPARA+J)=-1
      TEMPAR=0. 
      KK=K
      IF(I1(KDEGN(K)).NE.0.OR.I2(KDEGN(K)).NE.0)GO TO 350
      TEMPAR=AA(K+1)
      KK=KK+2
  350 IF(KK.GT.LDEGN)GO TO 480
      DO 410 L=KK,LDEGN,2
      IF(I3(KDEGN(L)).NE.NA.OR.I4(KDEGN(L)).NE.J)GO TO 410
C IS THE INDEPENDENT PARAMETER SPECIAL? 
      MK=I2(KDEGN(L)) 
      IF(I1(KDEGN(L)).EQ.0)GO TO 490
C NO. LINEAR DEPENDENCIES ONLY. WHAT KIND OF PARAMETER?
      MJ=I1(KDEGN(L)) 
      IF(MK.LT.2)GO TO 360
      IF(MK.LT.5)GO TO 370
      IF(MK.LT.11)GO TO 380
      IF(MK-21)390,400,400
  360 IF(ISCAT(2,NA).NE.0)TEMPAR=TEMPAR+OCCA(MJ)*AA(L+1)
      IF(ISCAT(2,NA).EQ.0)TEMPAR=TEMPAR+OCCUP(MJ)*AA(L+1)
      ITYPE=1
      GO TO 410
  370 TEMPAR=TEMPAR+XYZ(MK-1,MJ)*AA(L+1)
      ITYPE=2
      GO TO 410
  380 TEMPAR=TEMPAR+BETA(MK-4,MJ)*AA(L+1) 
      ITYPE=3
      GO TO 410
  390 TEMPAR=TEMPAR+CR(MK-10,MJ)*AA(L+1)
      ITYPE=4
      GO TO 410
  400 TEMPAR=TEMPAR+DR(MK-20,MJ)*AA(L+1)
      ITYPE=5
  410 CONTINUE
  420 GO TO(430,440,450,460,470),ITYPE
  430 IF(ISCAT(2,NA).NE.0)OCCA(NA)=TEMPAR 
      IF(ISCAT(2,NA).EQ.0)OCCUP(NA)=TEMPAR
      GO TO 710
  440 XYZ(J-1,NA)=TEMPAR
      GO TO 710
  450 BETA(J-4,NA)=TEMPAR 
      GO TO 710
  460 CR(J-10,NA)=TEMPAR
      GO TO 710
  470 DR(J-20,NA)=TEMPAR
      GO TO 710
  480 IF(J.EQ.1)ITYPE=1
      IF(J.GE.2)ITYPE=2
      IF(J.GE.5)ITYPE=3
      IF(J.GE.11)ITYPE=4
      IF(J.GE.21)ITYPE=5
      GO TO 420
C INDEPENDENT PARAMETER SPECIAL, SET ALL DEPENDENT PARAMETERS FOR
C  THIS ATOM WHICH DEPEND ON THIS SET OF SPECIAL PARAMETERS. 
  490 IF(I1(IPAR(MK)).EQ.1)GO TO 530
      IF(I1(IPAR(MK)).EQ.0)GO TO 500
      CALL SPVAL(NA,IPAR(MK),J) 
      GO TO 710
C DEPENDENT PARAMETER IS A LINEAR FUNCTION OF SPECIAL PARAMETERS. 
  500 DO 510 NK=L,LDEGN,2
      IF(I3(KDEGN(NK)).NE.NA.OR.I4(KDEGN(NK)).NE.J)GO TO 510
      IF(I1(KDEGN(NK)).NE.0)GO TO 520
      MK=I2(KDEGN(NK))
      TEMPAR=TEMPAR+PAR(MK)*AA(NK+1)
  510 CONTINUE
      GO TO 480
  520 WRITE(IOUT,10)
   10 FORMAT('0FAULTY DEPENDENCY INFORMATION. RUN ABORTED') 
      STOP
C GET SET DESIGNATOR, AND CLEAR ALL ARRAYS. 
  530 ISET=I2(IPAR(MK)) 
      CALL MULMM(XTOA,TRNS(1,1,ISET),TTRNS)
C DO WE NEED TO TRANSFORM XYZ FROM CRYSTAL TO SPECIAL? ANSWER IS YES
C  IF NO XYZ IS MENTIONED AS A DEPENDENT PARAMETER.
      DO 540 II=1,LDEGN,2
      JJ=I3(KDEGN(II))
      KK=I4(KDEGN(II))
      LL=I1(KDEGN(II))
      IF(JJ.EQ.NA.AND.KK.GE.2.AND.KK.LE.4.AND.LL.EQ.0)GO TO 560
  540 CONTINUE
      DO 550 II=1,3
  550 RTEM(II)=XYZ(II,NA)-OXYZ(II,ISET)
      CALL MULMV(TTRNSI(1,1,ISET),RTEM,SXYZ(1,NA,ISET))
      GO TO 590
C XYZ DEPENDENT ON SPECIAL PARAMETER. COMPUTE THEM. 
  560 CALL MULMV(TTRNS,SXYZ(1,NA,ISET),RTEM) 
      DO 570 II=1,3
  570 XYZ(II,NA)=RTEM(II)+OXYZ(II,ISET)
      DO 580 II=2,4
  580 IPARA(KPARA+II)=-1
C IF BETAS ARE DEPENDENT, COMPUTE THEM. 
  590 DO 630 II=1,LDEGN,2
      JJ=I1(KDEGN(II))
      KK=I3(KDEGN(II))
      LL=I4(KDEGN(II))
      IF(JJ.NE.0.OR.KK.NE.NA.OR.LL.LT.5.OR.LL.GT.10)GO TO 630
C APPLY LIBRATION CORRECTION TO SXYZ
      CALL CORLIB(RTEM,EL(1,1,ISET),SXYZ(1,NA,ISET)) 
      DO 610 JJ=1,6
      JK=IND2(1,JJ) 
      JL=IND2(2,JJ) 
  600 BTEM(JJ)=SKTLS(RTEM,JK,JL,T(1,1,ISET),EL(1,1,ISET),S(1,1,ISET)) 
  610 CONTINUE
      CALL TFM2(TTRNS,BTEM,BETA(1,NA))
      DO 620 JJ=5,10
  620 IPARA(KPARA+JJ)=-1
      IF(ISOT(NA)-2)700,640,640
  630 CONTINUE
C IF GAMMAS ARE DEPENDENT, COMPUTE THEM.
  640 DO 690 II=1,LDEGN,2
      JJ=I1(KDEGN(II))
      KK=I3(KDEGN(II))
      LL=I4(KDEGN(II))
      IF(JJ.NE.0.OR.KK.NE.NA.OR.LL.LT.11.OR.LL.GT.20)GO TO 690
  650 DO 670 JJ=1,10
      JK=IND3(1,JJ) 
      JL=IND3(2,JJ) 
      JM=IND3(3,JJ) 
  660 GTEM(JJ)=TKTLS(RTEM,JK,JL,JM,EL(1,1,ISET),S(1,1,ISET))
  670 CONTINUE
      CALL TFM3(TTRNS,GTEM,CR(1,NA))
      DO 680 JJ=11,20
  680 IPARA(KPARA+JJ)=-1
      GO TO 700
  690 CONTINUE
  700 CONTINUE
  710 CONTINUE
  720 DO 730 I=1,NPARA 
      IF(IPARA(KPARA+I).LT.0)IPARA(KPARA+I)=0
  730 CONTINUE
      KPARA=KPARA+NPARA 
      RETURN
      END 
