#!/usr/bin/env python

## Just run code in recipes, use it carefully
## example: use netcdf4 to make cache file. Since python is faster than ncl.
#;DIAG_NORCPM; RUNTHESECODES: print('    no codes run here.')

import xarray as xr
from os.path import exists
from sys import exit
ccfn = "N1_HIST_PRECC_ensmean_1980-2020.nc"
clfn = "N1_HIST_PRECL_ensmean_1980-2020.nc"
scfn = "N1_HIST_PRECSC_ensmean_1980-2020.nc"
slfn = ""
outfile = "N1_HIST_PRECT_ensmean_1980-2020.nc"

if exists(outfile): 
    print(outfile+' available, skip')
    exit()
ccds = xr.open_dataset(ccfn)
clds = xr.open_dataset(clfn)
ctds  = xr.Dataset({'PRECT':ccds['PRECC']+clds['PRECL']})

ctds.to_netcdf(outfile)


