# module load netcdf4-python/1.5.3-foss-2015a-Python-3.7.3
# module load pynco/1.0.0-foss-2015a-Python-3.7.3

import netCDF4 as nc
from nco import Nco
import os,re,glob

nco = Nco()

src_dir = '/esarchive/oper/S2S4E-data'
search  = '/*/*/inflwrate*percentiles*'

files = glob.glob(src_dir + search)
for filepath in files:
    print(filepath)
    file = nc.Dataset(filepath)
    dims = file.variables['p33'].get_dims()
    if dims[0].name == "subid":
        nco.ncpdq(input=filepath, output=filepath, options=["-a","time,subid"])
    else:
        print("files dimensions in correct order")
