C  * * * * * * * * * * * * * * * * * * * * * * * * * * * * *            
C     SUBROUTINE FOR BASE-LINE CORRECTION OF ACCELEROGRAM               
C  * * * * * * * * * * * * * * * * * * * * * * * * * * * * *            
C                                                                       
C                                       CODED BY Y.OHSAKI               
C                                                                       
C     PURPOSE                                                           
C       TO CORRECT THE ORIGINAL ACCELERATION TIME HISTORY BY BASE-LINE  
C       ADJUSTMENT SO THAT (1) THE TERMINAL VELOCITY VANISHES, AND (2)  
C       THE PERMANENT DISPLACEMENT CONVERGES WITHIN A REASONABLE LIMIT  
C                                                                       
C     USAGE                                                             
C       CALL CRAC(DT,NN,DDYMAX,DDY,ND,UW1,UW2)                          
C                                                                       
C     DESCRIPTION OF ARGUMENTS                                          
C       DT      - TIME INCREMENT IN SEC                                 
C       NN      - TOTAL NUMBER OF DATA IN ACCELERATION TIME HISTORY     
C       DDYMAX  - MAX. ACCELERATION IN GALS                             
C       DDY(ND) - ORIGINAL/CORRECTED ACCELERATION TIME HISTORY IN GALS  
C                 AT CALL/RETURN                                        
C       ND      - DIMENSION OF DDY,UW1,UW2 IN CALLING PROGRAM           
C       UW1(ND) - WORKING AREA                                          
C       UW2(ND) - WORKING AREA                                          
C                                                                       
C     SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED                     
C       IACC                                                            
C                                                                       
      SUBROUTINE CRAC(DT,NN,DDYMAX,DDY,ND,UW1,UW2)                      
C                                                                       
      DIMENSION DDY(ND),UW1(ND),UW2(ND)                                 
C                                                                       
      CALL IACC(DT,NN,DDY,UW1,UW2,ND,DUMMY,DUMMY)                       
      TT=REAL(NN-1)*DT                                                  
      T=0.                                                              
      DO 110 M=1,NN                                                     
      UW2(M)=UW2(M)*(3.*TT-2.*T)*T**2                                   
      T=T+DT                                                            
  110 CONTINUE                                                          
      SUM=(UW2(1)+UW2(NN))/2.                                           
      DO 120 M=2,NN-1                                                   
      SUM=SUM+UW2(M)                                                    
  120 CONTINUE                                                          
      SUM=SUM*DT                                                        
      A1=28./13./TT**2*(2.*UW1(NN)-15./TT**5*SUM)                       
      A0=UW1(NN)/TT-A1/2.*TT                                            
      T=0.                                                              
      ACMAX=0.                                                          
      DO 130 M=1,NN                                                     
      DDY(M)=DDY(M)-A0-A1*T                                             
      ACMAX=AMAX1(ACMAX,ABS(DDY(M)))                                    
      T=T+DT                                                            
  130 CONTINUE                                                          
      COEF=DDYMAX/ACMAX                                                 
      DO 140 M=1,NN                                                     
      DDY(M)=DDY(M)*COEF                                                
  140 CONTINUE                                                          
      RETURN                                                            
      END                                                               
