import xarray as xr
import sys

ifile = sys.argv[1]
ds = xr.open_dataset(ifile)
if 'PREC' in ifile:
    print('SUM', ifile)
    ds = ds.resample(time='D').sum()
else:
    print('mean', ifile)
    ds = ds.resample(time='D').mean()
df = ds.to_dataframe()
df = df.drop(['lat', 'lon'], axis=1)
out = ifile.replace('nc', 'csv')
df.to_csv(out)
