C  * * * * * * * * * * * * * * * * * * * * * * * * * * * *              
C     SUROUTINE FOR SOIL RESPONSE TO EARTHQUAKE MOTION                  
C  * * * * * * * * * * * * * * * * * * * * * * * * * * * *              
C                                                                       
C                                    CODED BY Y.OHSAKI                  
C                                                                       
C     PURPOSE                                                           
C       TO COMPUTE, BY MEANS OF FREQUENCY RESPONSE FUNCTION, THE RES-   
C       PONSE ACCELERATION TIME-HISTORY AT THE TOP OF THE SPECIFIED     
C       OBJECTIVE LAYER IN A HORIZONTALLY LAYERED SOIL DEPOSIT, WHEN    
C       AN INPUT ACCELERATION TIME-HISTORY IS GIVEN AT THE TOP OF THE   
C       SPECIFIED REFERENCE LAYER.                                      
C                                                                       
C     USAGE                                                             
C       CALL SRES(L,TH,UW,G,ALPHA,BETA,ND1,LOBJ,LREF,DT,NN,DDY,ACC,     
C                ND2,ACMAX,IND)                                         
C                                                                       
C     DESCRIPTION OF ARGUMENTS                                          
C       L          - TOTAL NUMBER OF LAYERS, INCLUDING THE BASE LAYER   
C                    L.LE.60                                            
C       TH(ND1)    - THICKNESS IN METERS                                
C       UW(ND1)    - UNIT WEIGHT IN TONS/CU.METER                       
C       G(ND1)     - SHEAR MODULUS IN TONS/SQ.METER                     
C       ALPHA(ND1) - SCATTER DAMPING COEFFICIENT IN 1/SEC               
C       BETA(ND1)  - MATERIAL DAMPING COEFFICIENT IN DECIMAL FRACTION   
C       ND1        - DIMENSION OF TH,UW,G,ALPHA BETA IN CALLING PROGRAM 
C       LOBJ       - NUMBER OF OBJECTIVE LAYER                          
C       LREF       - NUMBER OF REFERENCE LAYER                          
C       DT         - TIME INCREMENT IN SEC                              
C       NN         - TOTAL NUMBER OF DATA IN THE TIME-HISTORIES         
C                    NN.LE.8192                                         
C       DDY(ND2)   - REFERENCE ACCELERATION TIME-HISTORY IN GALS        
C       ACC(ND2)   - OBJECTIVE ACCELERATION TIME-HISTORY IN GALS        
C       ND2        - DIMENSION OF DDY,ACC IN CALLING PROGRAM            
C       ACMAX      - MAX. ACCELERATION OF ACC IN GALS                   
C       IND        - SEE THE FOLLOWING TABLE                            
C                  ---------------------------------------------------  
C                  I                            I  REFERENCE LAYER   I  
C                  I            IND             I--------------------I  
C                  I                            I INTERNAL I EXPOSED I  
C                  I----------------------------I----------I---------I  
C                  I                 I INTERNAL I    11    I    12   I  
C                  I OBJECTIVE LAYER I----------I----------I---------I  
C                  I                 I EXPOSED  I    21    I    NO   I  
C                  ---------------------------------------------------  
C                                                                       
C     REMARKS                                                           
C       (1) THICKNESS OF BASE LAYER TH(L) IS NOT REQUIRED               
C       (2) THE GROUND SURFACE IS ALWAYS REGARDED AS INTERNAL           
C       (3) WHEN IND=21,THE OBJECTIVE LAYER MUST BE LOCATED DEEPER      
C           THAN THE REFERENCE LAYER                                    
C       (4) THE CASE THAT BOTH REFERENCE AND OBJECTIVE LAYERS ARE       
C           EXPOSED IS NOT PERMITTED                                    
C                                                                       
C     SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED                     
C       FESP FAST                                                       
C                                                                       
      SUBROUTINE SRES(L,TH,UW,G,ALPHA,BETA,ND1,LOBJ,LREF,DT,NN,DDY,     
     *           ACC,ND2,ACMAX,IND)                                     
C                                                                       
      DIMENSION TH(ND1),UW(ND1),G(ND1),ALPHA(ND1),BETA(ND1),DDY(ND2),   
     *          ACC(ND2)                                                
      COMPLEX   H(4097),C(8192)                                         
C                                                                       
C     FOURIER TRANSFORM OF REFERENCE TIME-HISTORY                       
C                                                                       
      NT=2                                                              
  110 IF(NT.GE.NN) GO TO 120                                            
      NT=NT*2                                                           
      GO TO 110                                                         
  120 NFOLD=NT/2+1                                                      
      DO 130 M=1,NN                                                     
      C(M)=CMPLX(DDY(M)/REAL(NT),0.)                                    
  130 CONTINUE                                                          
      IF(NN.EQ.NT) GO TO 150                                            
      DO 140 M=NN+1,NT                                                  
      C(M)=(0.,0.)                                                      
  140 CONTINUE                                                          
  150 CALL FAST(NT,C,8192,-1)                                           
C                                                                       
C     FREQUENCY RESPONSE FUNCTION                                       
C                                                                       
      DF=1./REAL(NT)/DT                                                 
      IF(IND.EQ.21) GO TO 160                                           
      CALL FESP(L,TH,UW,G,ALPHA,BETA,ND1,LOBJ,LREF,DF,NFOLD,H,4097,0,   
     *         IND-11)                                                  
      GO TO 180                                                         
  160 CALL FESP(L,TH,UW,G,ALPHA,BETA,ND1,LREF,LOBJ,DF,NFOLD,H,4097,0,1) 
      DO 170 K=1,NFOLD                                                  
      H(K)=(1.,0.)/H(K)                                                 
  170 CONTINUE                                                          
C                                                                       
C     OBJECTIVE TIME-HISTORY                                            
C                                                                       
  180 C(1)=C(1)*H(1)                                                    
      DO 190 K=2,NFOLD-1                                                
      C(K)=C(K)*H(K)                                                    
      C(NT-K+2)=CONJG(C(K))                                             
  190 CONTINUE                                                          
      C(NFOLD)=C(NFOLD)*H(NFOLD)                                        
      CALL FAST(NT,C,8192,+1)                                           
      ACMAX=0.                                                          
      DO 200 M=1,NN                                                     
      ACC(M)=REAL(C(M))                                                 
      ACMAX=AMAX1(ACMAX,ABS(ACC(M)))                                    
  200 CONTINUE                                                          
      RETURN                                                            
      END                                                               
                                                                        
