#!/usr/bin/env python

'''
A command line utility module for stripping wavefunctions and
other large netcdf variables out of Dacapo netcdf files. It has been
enhanced to allow recursive stripping.

the simplest usage is

> stripnetcdf yourncfile.nc

To recursively strip all netcdf files try:

> stripnetcdf --recurse

Note this tries to strip all files matching *.nc recursively. If
Dacapo.ReadAtoms(filename) fails, it skips that file, since it is
likely a trajectory file.

One known feature/bug is that in command line use, you may have to
enclose the pattern to match in quotes if there is no match in the
directory you start in.

> stripnetcdf --recurse '*vib*.nc'

This is because the shell will abort the command if *.nc does not
expand to existing files. I do not know if this is avoidable. The
following is also possible, to match several patterns:

> stripnetcdf --keepep --keepwf '*relax.nc' '*cg*.nc'

Here the electrostatic potential and wave function will be kept.
Note each pattern is a string. this is to ensure the shell does not
end the script if there are no matches in the current directory. That
is not necessary if there are matches for these patterns in the
current directory.

John Kitchin
jkitchin@andrew.cmu.edu
'''

import sys
from getopt import getopt
from Dacapo.stripnetcdf import *

opts,patternlist=getopt(sys.argv[1:],"",["keepwf",
					 "keepfft",
					 "keepchd",
					 "keepnlp",
					 "keepep",
					 "keeppcd",
					 "recurse"])

#strip dashes from the options
options = tuple([option[0][2:] for option in opts])

# set default patternlist
if patternlist == []:
    patternlist = ['*.nc']

StripNetCDF(rootdir='.',patternlist=patternlist,options=options)
