                      SUBROUTINE RESET(NA,KPARA)                        
C                                                                       
C     THIS SUBROUTINE IS  ENTERED (FROM LOADNW)  ONCE FOR  SPECIAL PARA-
C     METERS AND ONCE FOR EACH ATOM TO COMPUTE THE UPDATED VALUES OL ALL
C     DEPENDENT PARAMETERS. LINEAR RELATIONSHIPS AND  RIGID-BODY PARAME-
C     TERS ARE COMPUTED DIRECTLY.    OTHER NON LINEAR  SYSYTEMS OF  CON-
C     STRAINTS MAY BE HANDELED BY THE USE THROUGH  SUBROUTINE * SPVAL *,
C                       SUPPLIED AS A DUMMY.                            
C                                                                       
C                     WRITTEN  BY L. W. FINGER                          
C                                                                       
C       ANHARMONIC THERMAL PARAMETERS OF FIFTH AND SIXTH ORDER ADDED.   
C                                                                       
C             FEBRUARY 1980  BY  U. ZUCKER  MPI-FKF STUTTGART.          
C                                                                       
      DIMENSION SAVE(60),KDEGN(2640),AA(2640),ER(21,6),FR(28,6)         
C                                                                       
      COMMON/A/BETA(6,60),G(3,3),ISOT(60),NATOM,TAG(2,60),TITLE(18),XYZ(
     &3,60),PI,CR(10,60),DR(15,60),ALF(60),ITTYP(60)                             
      COMMON/D/ACALC,AIND(60),ANOM(2,20),BCALC,BIND(60),DADB(6,60),DADO(
     & 60),DADX(3,60),DBDB(6,60),DBDO(60),DBDX(3,60),H(3),IH(3),ISCAT(2,
     & 60),ISCL,MFSEL,OCCA(60),OCCUP(60), SCALE(10), SCAT(20), SITE(60),
     & DADC(10,60),DBDC(10,60),DADD(15,60), DBDD(15,60), AMINUS, BMINUS,
     & DRDE(7),NDEGN,VORFAK,IPAREX(7),DAALFA(60),DBALFA(60)             
      COMMON/XPAR/NPAR,ATOX(3,3),XTOA(3,3),PAR(60),PARNAM(2,60),IPAR(60)
     &,IRPAR(60),OXYZ(3),SXYZ(3),OXP(3),T(3,3),EL(3,3),S(3,3),TRNS(3,3),
     & TTRNS(3,3),TRANSI(3,3),TTRNSI(3,3),RTEM(3),BTEM(6),GTEM(10)      
      COMMON/LSMAT/B(200),IEXT,IPARA(1000),MRANK,KCYL,LABEL(3),JSCRF(10 
     & ),NRSF, SIGMA, MDEGN, MAXIMA, IALFA(60), RDAMP(200), IDAMP(200), 
     & A(2200)                                                          
      COMMON/IND23/IND2(2,6),IND3(3,10)                                 
      COMMON/TAPE/IN,INN,IOUT,ISC1,ISC2,ISC3,ISC4,ISC5,IPUN             
C                                                                       
      EQUIVALENCE (SAVE,AIND),(KDEGN,AA,DADC(1,37)),(DR(1,41),ER),      
     & (DR(7,49),FR)                                                    
C                                                                       
      I1(K) = MOD(K/256**3,256)                                         
      I2(K) = MOD(K/256**2,256)                                         
      I3(K) = MOD(K/256,256)                                            
      I4(K) = MOD(K,256)                                                
C                                                                       
 9200 FORMAT(13H0ERRORMESSAGE/1X,12(1H-)//                              
     & 43H FAULTY DEPENDENCY INFORMATION. RUN ABORTED)                  
C                                                                       
      LDEGN=2*NDEGN                                                     
C                                                                       
      IF(NA.GT.0)GO TO 100                                              
C                                                                       
C---------------------------------------------------------------------- 
C                                                                       
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.
C                                                                       
      DO 90 I=1,LDEGN,2                                                 
      IF(I3(KDEGN(I)).NE.0)GO TO 90                                     
C                                                                       
C---- A DEPENDENT SPECIAL PARAMETER. HAS IT ALREADY BEEN SET?           
C                                                                       
      J=I4(KDEGN(I))                                                    
      IF(IRPAR(J).NE.0)GO TO 90                                         
C                                                                       
C---- NO IT HASN'T. PROCEED TO SET IT.                                  
C                                                                       
      IRPAR(J)=-1                                                       
      PAR(J)=0.                                                         
C                                                                       
C---- IF INDEPENDENT PARAMETER IS 0,0, INITIALIZE TO CONSTANT.          
C                                                                       
      KK=I                                                              
      IF(I2(KDEGN(I)).NE.0)GO TO 20                                     
      KK=KK+2                                                           
      PAR(J)=AA(I+1)                                                    
 20   IF(KK.GT.LDEGN)GO TO 90                                           
      DO 50 K=KK,LDEGN,2                                                
      IF(I3(KDEGN(K)).NE.0.OR.I4(KDEGN(K)).NE.J)GO TO 50                
      LL=I2(KDEGN(K))                                                   
      PAR(J)=PAR(J)+PAR(LL)*AA(K+1)                                     
 50   CONTINUE                                                          
 90   CONTINUE                                                          
      DO 95 I=1,NPAR                                                    
      IF(IRPAR(I).LT.0)IRPAR(I)=0                                       
 95   CONTINUE                                                          
      RETURN                                                            
C---------------------------------------------------------------------- 
C                                                                       
C---- COMPUTE NEW VALUES OF PARAMETERS FOR ATOM NA.                     
C                                                                       
 100  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(ISOT(NA).GE.4)NPARA=NPARA+21                                   
      IF(ISOT(NA).GE.5)NPARA=NPARA+28                                   
      IF(LDEGN.LE.0)GO TO 1001                                          
C                                                                       
      DO 1000 ID = 1,NPARA                                              
      J = ID                                                            
C                                                                       
C---- IS PARAMETER INDEPENDENT?                                         
C                                                                       
      IF(IPARA(KPARA+J).GT.0)GO TO 1000                                 
C                                                                       
C---- IS THIS PARAMETER DEPENDENT ON ANY OTHERS?                        
C                                                                       
      DO 900 K=1,LDEGN,2                                                
      IF(I3(KDEGN(K)).NE.NA.OR.I4(KDEGN(K)).NE.J)GO TO 900              
C                                                                       
C---- DEPENDENT PARAMETER. SET IT.                                      
C                                                                       
      IF(IPARA(KPARA+J).LT.0)GO TO 900                                  
      IPARA(KPARA+J)=-1                                                 
      TEMPAR=0.                                                         
      KK=K                                                              
      IF(I1(KDEGN(K)).NE.0.OR.I2(KDEGN(K)).NE.0)GO TO 110               
      TEMPAR=AA(K+1)                                                    
      KK=KK+2                                                           
 110  IF(KK.GT.LDEGN)GO TO 170                                          
      DO 150 L=KK,LDEGN,2                                               
      IF(I3(KDEGN(L)).NE.NA.OR.I4(KDEGN(L)).NE.J)GO TO 150              
C                                                                       
C---- IS THE INDEPENDENT PARAMETER SPECIAL?                             
C                                                                       
      MK=I2(KDEGN(L))                                                   
      IF(I1(KDEGN(L)).EQ.0)GO TO 200                                    
C                                                                       
C---- NO. LINEAR DEPENDENCIES ONLY. WHAT KIND OF PARAMETER?             
C                                                                       
      MJ=I1(KDEGN(L))                                                   
      IF(MK.LT.2)GO TO 112                                              
      IF(MK.LT.5)GO TO 116                                              
      IF(MK.LT.11)GO TO 120                                             
      IF(MK.LT.21)GO TO 124                                             
      IF(MK.LT.36)GO TO 128                                             
      IF(MK-57)1281,1282,1282                                           
 112  TEMPAR=TEMPAR+OCCA(MJ)*AA(L+1)                                    
      ITYPE=1                                                           
      GO TO 150                                                         
 116  TEMPAR=TEMPAR+XYZ(MK-1,MJ)*AA(L+1)                                
      ITYPE=2                                                           
      GO TO 150                                                         
 120  TEMPAR=TEMPAR+BETA(MK-4,MJ)*AA(L+1)                               
      ITYPE=3                                                           
      GO TO 150                                                         
 124  TEMPAR=TEMPAR+CR(MK-10,MJ)*AA(L+1)                                
      ITYPE=4                                                           
      GO TO 150                                                         
 128  TEMPAR=TEMPAR+DR(MK-20,MJ)*AA(L+1)                                
      ITYPE=5                                                           
      GOTO 150                                                          
 1281 TEMPAR=TEMPAR+ER(MK-35,MJ)*AA(L+1)                                
      ITYPE=6                                                           
      GOTO 150                                                          
 1282 TEMPAR=TEMPAR+FR(MK-56,MJ)*AA(L+1)                                
      ITYPE=7                                                           
 150  CONTINUE                                                          
 151  GO TO(152,154,156,158,160,162,164),ITYPE                          
 152  OCCA(NA)=TEMPAR                                                   
      GO TO 1000                                                        
 154  XYZ(J-1,NA)=TEMPAR                                                
      GO TO 1000                                                        
 156  BETA(J-4,NA)=TEMPAR                                               
      GO TO 1000                                                        
 158  CR(J-10,NA)=TEMPAR                                                
      GO TO 1000                                                        
 160  DR(J-20,NA)=TEMPAR                                                
      GO TO 1000                                                        
 162  ER(J-35,NA)=TEMPAR                                                
      GO TO 1000                                                        
 164  FR(J-56,NA)=TEMPAR                                                
      GO TO 1000                                                        
 170  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                                                
      IF(J.GE.36)ITYPE=6                                                
      IF(J.GE.57)ITYPE=7                                                
      GO TO 151                                                         
C                                                                       
C---- INDEPENDENT PARAMETER SPECIAL, SET ALL DEPENDENT  PARAMETERS  FOR 
C     THIS ATOM  WHICH  DEPEND  ON  THIS  SET  OF  SPECIAL  PARAMETERS. 
C                                                                       
  200 CONTINUE                                                          
C                                                                       
C>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
C                                                                       
C                        CALL OVERLAY                                   
C                     CALL LLINK("R3OV1")                               
C                                                                       
C>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
C                                                                       
      IF(I1(IPAR(MK)).EQ.1)GO TO 210                                    
      IF(I1(IPAR(MK)).EQ.0)GO TO 2000                                   
C                                                                       
C                                                                       
      CALL SPVAL(NA,IPAR(MK),J)                                         
C                                                                       
C                                                                       
      GO TO 1000                                                        
C                                                                       
C---- DEPENDENT PARAMETER IS A LINEAR FUNCTION OF SPECIAL PARAMETERS.   
C                                                                       
 2000 DO 2100 NK=L,LDEGN,2                                              
      IF(I3(KDEGN(NK)).NE.NA.OR.I4(KDEGN(NK)).NE.J)GO TO 2100           
      IF(I1(KDEGN(NK)).NE.0)GO TO 2200                                  
      MK=I2(KDEGN(NK))                                                  
      TEMPAR=TEMPAR+PAR(MK)*A(NK+1)                                     
 2100 CONTINUE                                                          
      GO TO 170                                                         
 2200 WRITE(IOUT,9200)                                                  
      CALL EXIT                                                         
C                                                                       
C---- GET SET DESIGNATOR, AND CLEAR ALL ARRAYS.                         
C                                                                       
 210  ISET=I2(IPAR(MK))                                                 
      DO 214 II=1,3                                                     
      OXYZ(II)=0.                                                       
      SXYZ(II)=0.                                                       
      OXP(II)=0.                                                        
      DO 214 JJ=1,3                                                     
      T(II,JJ)=0.                                                       
      EL(II,JJ)=0.                                                      
 214  S(II,JJ)=0.                                                       
C                                                                       
C---- FILL IN VALUES FROM THIS SET.                                     
C                                                                       
      DO 220 ID2 = 1,NPAR                                               
      II=ID2                                                            
      IF(I2(IPAR(II)).NE.ISET)GO TO 220                                 
      CALL FILLIN(II,I4(IPAR(II)),PAR(II),NA)                           
 220  CONTINUE                                                          
      CALL EULER(OXP(3),OXP(2),OXP(1),TRNS)                             
      CALL MULMM(XTOA,TRNS,TTRNS)                                       
C                                                                       
C---- DO WE NEED TO TRANSFORM XYZ FROM CRYSTAL TO SPECIAL? ANSWER IS YES
C     IF NO XYZ IS MENTIONED AS A DEPENDENT PARAMETER.                  
C                                                                       
      DO 230 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 240         
 230  CONTINUE                                                          
      CALL TRNSPS(TRNS,TRANSI)                                          
      CALL MULMM(TRANSI,ATOX,TTRNSI)                                    
      DO 232 II=1,3                                                     
 232  RTEM(II)=XYZ(II,NA)-OXYZ(II)                                      
      CALL MULMV(TTRNSI,RTEM,SXYZ)                                      
      GO TO 250                                                         
C                                                                       
C---- XYZ DEPENDENT ON SPECIAL PARAMETER. COMPUTE THEM.                 
C                                                                       
 240  CALL MULMV(TTRNS,SXYZ,RTEM)                                       
      DO 244 II=1,3                                                     
 244  XYZ(II,NA)=RTEM(II)+OXYZ(II)                                      
      DO 246 II=2,4                                                     
 246  IPARA(KPARA+II)=-1                                                
C                                                                       
C     IF BETAS ARE DEPENDENT, COMPUTE THEM.                             
C                                                                       
 250  DO 268 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 268           
C                                                                       
C---- APPLY LIBRATION CORRECTION TO SXYZ                                
C                                                                       
      CALL CORLIB(RTEM,EL,SXYZ)                                         
      DO 260 JJ=1,6                                                     
      JK=IND2(1,JJ)                                                     
      JL=IND2(2,JJ)                                                     
 258  BTEM(JJ)=SKTLS(RTEM,JK,JL,T,EL,S)                                 
 260  CONTINUE                                                          
      CALL TFM2(TTRNS,BTEM,BETA(1,NA))                                  
      DO 264 JJ=5,10                                                    
 264  IPARA(KPARA+JJ)=-1                                                
      IF(ISOT(NA)-2)900,270,270                                         
 268  CONTINUE                                                          
C                                                                       
C---- IF GAMMAS ARE DEPENDENT, COMPUTE THEM.                            
C                                                                       
 270  DO 298 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 298          
 280  DO 290 JJ=1,10                                                    
      JK=IND3(1,JJ)                                                     
      JL=IND3(2,JJ)                                                     
      JM=IND3(3,JJ)                                                     
 282  GTEM(JJ)=TKTLS(RTEM,JK,JL,JM,EL,S)                                
 290  CONTINUE                                                          
      CALL TFM3(TTRNS,GTEM,CR(1,NA))                                    
      DO 294 JJ=11,20                                                   
 294  IPARA(KPARA+JJ)=-1                                                
      GO TO 900                                                         
 298  CONTINUE                                                          
 900  CONTINUE                                                          
 1000 CONTINUE                                                          
 1001 DO 1005 I=1,NPARA                                                 
      IF(IPARA(KPARA+I).LT.0)IPARA(KPARA+I)=0                           
 1005 CONTINUE                                                          
      KPARA=KPARA+NPARA                                                 
C                                                                       
      RETURN                                                            
      END                                                               
