Skip to content
Snippets Groups Projects
Commit 50c0d424 authored by kgao's avatar kgao
Browse files

Added -s functionality

If -s is specified alone, script creates file from -s to end of the day
argparse now allows format YYYY-MM-DD
parent f48c5cc9
No related branches found
No related tags found
No related merge requests found
......@@ -266,7 +266,10 @@ def createMultiple(filenames, outputFilenames, zlib, chunkSize):
def _dt_convert(datetime_str):
#parse datetime string, return datetime object
return dt.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S')
try:
return dt.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S')
except:
return dt.strptime(datetime_str, '%Y-%m-%d')
def main():
import argparse
......@@ -280,8 +283,11 @@ def main():
help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)')
#argparse start and end times
parser.add_argument('-s', '--start-time', type=_dt_convert, help="Start time of massive netcdf file")
parser.add_argument('-e', '--end-time', type=_dt_convert, help='End time of massive netcdf file')
parser.add_argument('-s', '--start-time', type=_dt_convert,
help="Start time of massive netcdf file, if only -s is given, a netcdf file for only that day is given" +
". Formats allowed: \'YYYY-MM-DDTHH:MM:SS\', \'YYYY-MM-DD\'")
parser.add_argument('-e', '--end-time', type=_dt_convert, help='End time of massive netcdf file. Formats allowed:' +
"\'YYYY-MM-DDTHH:MM:SS\', \'YYYY-MM-DD\'")
parser.add_argument('-cs', '--chunk-size', type=int, help='chunk Size for the netCDF file')
parser.add_argument('-z', '--zlib', action='store_true', help='compress netCDF file with zlib')
......@@ -302,8 +308,14 @@ def main():
if(result == False):
raise IOError('An empty ASCII file was found')
elif(args.start_time or args.end_time):
print('USAGE: start time and end time must both be specified or not specified')
elif(args.start_time):
end_time = args.start_time.replace(hour=23, minute=59, second=59)
result = createGiantNetCDF(args.start_time, end_time, args.input_files, args.output[0], args.zlib, args.chunk_size)
if(result == False):
raise IOError('An empty ASCII file was found')
elif(args.end_time):
print('USAGE: start time must be specified when end time is specified')
else:
createMultiple(args.input_files, args.output, args.zlib, args.chunk_size)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment