import sys
import pandas as pd
import datetime
import os
import glob
import yaml

def asc2raindat():
    
    data_dir = './'
    flist = glob.glob(data_dir + '*.asc')
    print(flist)

    f_rain = data_dir + 'rain.dat'

    fo = open(f_rain, mode='w')
    fo.close()
    it = 0
    for f in flist:
        df = pd.read_csv(f, sep=' ', header=None, skiprows=7)
        n_rows, n_cols = df.shape
        print(n_rows, n_cols)
        
        s = str(1800*it) + ' ' + str(n_cols) + ' ' + str(n_rows) + '\n'
        with open(f_rain, mode = 'a') as fo:
            fo.write(s)

        df.to_csv(f_rain, sep=' ', index=False, header=False, mode='a')
        it = it + 1

    fo.close()

if __name__ == '__main__':
    asc2raindat()
