program DL_POLY_HISTORY
    implicit none                              !implicit(˵����ĳһ��ĸ��ͷ�ı���Ϊָ��������) 
    character *72 header
    integer keytri, imcon, megatm, frame, records
    character *8 timestep
    integer nstep, megatm_a, keytri_a, imcon_a
    real tstep, time
    real va_x, va_y, va_z, vb_x, vb_y, vb_z, vc_x, vc_y, vc_z
    character *8 atmnam
    integer iatm
    real weight, charge, rsd
    real c_x, c_y, c_z, v_x, v_y, v_z, f_x, f_y, f_z
    integer K, Q
    integer i, j 
    open(30, file = 'RSD', status = 'unknown')        !��һ������ļ������ڴ洢ions
    open(20, file = 'RSD_CM', status = 'unknown')     !��һ������ļ������ڴ洢Cations
    open(15, file = 'RSD_AM', status = 'unknown')      !��һ������ļ������ڴ洢Anions
    !open(40, file = 'HISTORY_v', status = 'unknown')  !��һ������ļ������ڴ洢Anions(CWQ)
    !open(1, file = 'HISTORY', status = 'unknown')      !���ļ�������ȡ
    open(1, file = 'HISTORY', status = 'unknown')      !���ļ�������ȡ
    read(1, *) header
    read(1, *) keytri, imcon, megatm, frame, records
    K = (megatm+1)*4
    Q = megatm*4
    !do i = 1, (records-Q), K
    do i = 1, (501*K+2-Q), K !����ֻȡ1ns�����ݼ���
    !do i = (K*(50000-1)+1), (52500*K+2-Q), K
    !do i = (K*(10000-1)+1), (10000*K+2-Q), K
    !do i = 1, (1*K+2-Q), K
        read(1, *) timestep, nstep, megatm_a, keytri_a, imcon_a, tstep, time
        read(1, *) va_x, va_y, va_z
        read(1, *) vb_x, vb_y, vb_z
        read(1, *) vc_x, vc_y, vc_z
        do j = 1, Q, 4
            read(1, *) atmnam, iatm, weight, charge, rsd
            read(1, *) c_x, c_y, c_z 
            read(1, *) v_x, v_y, v_z 
            read(1, *) f_x, f_y, f_z
            !if(atmnam == 'F' .OR. atmnam == 'B') then
                !write(15, "(A8, I10, F20.10, F20.10, F20.10)") atmnam, iatm, weight, charge, rsd
            !else if(atmnam /= 'C') then
                !write(20, "(A8, I10, F20.10, F20.10, F20.10)") atmnam, iatm, weight, charge, rsd
            !end if
            !if(atmnam /= 'C') then
                !write(30, "(A8, I10, F20.10, F20.10, F20.10)") atmnam, iatm, weight, charge, rsd
            !end if            
            !write(40, "(A8, I10, F20.10, F20.10, F20.10, F20.10, F20.10, F20.10)") atmnam, iatm, weight, charge, rsd, c_x, c_y, c_z
            !if(atmnam /= 'C') then
               !write(30, "(A8, F20.10, F20.10, F20.10)") atmnam, weight, charge, rsd
            !end if
            if(atmnam == 'F' .OR. atmnam == 'B') then
            !if(atmnam == 'F' .OR. atmnam == 'P') then
            !if(atmnam == 'Cl') then
                write(15, "(F20.10)") rsd
            else if(atmnam /= 'C') then
                write(20, "(F20.10)") rsd
            end if
            if(atmnam /= 'C') then
                write(30, "(F20.10)") rsd
            end if
            !write(40, "(F20.10, F20.10, F20.10)") v_x, v_y, v_z !(CWQ)
            end do
        end do
    end