forked from NCAR/cprnc_python
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcprnc
executable file
·97 lines (78 loc) · 2.79 KB
/
cprnc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
"""
cprnc: program to compare two netcdf files
"""
from __future__ import print_function
import sys
if sys.hexversion < 0x02070000:
print(70 * "*")
print("ERROR: {0} requires python >= 2.7.x. ".format(sys.argv[0]))
print("It appears that you are running python {0}".format(
".".join(str(x) for x in sys.version_info[0:3])))
print(70 * "*")
sys.exit(1)
#
# built-in modules
#
import argparse
import os
import traceback
#
# installed dependencies
#
#
# other modules in this package
#
from cprnc_py.filediffs import FileDiffs
from cprnc_py.netcdf.netcdf_wrapper import netcdf
# -------------------------------------------------------------------------------
#
# User input
#
# -------------------------------------------------------------------------------
def commandline_options():
"""Process the command line arguments.
"""
parser = argparse.ArgumentParser(
description='Compare two netcdf files')
parser.add_argument('file1',
help='File 1 for comparison')
parser.add_argument('file2',
help='File 2 for comparison')
parser.add_argument('--np', dest='nprocs', default=None, type=int,
help="Number of processors; if not specified, use 1 proc "
"without the overhead of a multiprocessing package. "
"Note that specifying --np 1 is NOT the same as leaving out --np: "
"the former will invoke a true multiprocessing package, which carries "
"some overhead (this is mainly useful for testing).")
parser.add_argument('--show-same', action='store_true',
help='show variables which are the same')
parser.add_argument('--backtrace', action='store_true',
help='show exception backtraces as extra debugging '
'output')
parser.add_argument('--debug', action='store_true',
help='extra debugging output (currently unused)')
options = parser.parse_args()
print(options)
return options
# -------------------------------------------------------------------------------
#
# main
#
# -------------------------------------------------------------------------------
def main(options):
ncfile1 = netcdf(options.file1)
ncfile2 = netcdf(options.file2)
diffs = FileDiffs(ncfile1, ncfile2, show_same=options.show_same, separate_dim="time", nprocs=options.nprocs)
print(diffs)
return int(diffs.files_differ())
if __name__ == "__main__":
options = commandline_options()
try:
status = main(options)
sys.exit(status)
except Exception as error:
print(str(error))
if options.backtrace:
traceback.print_exc()
sys.exit(1)