source: TI02-CSML/trunk/Scanner/ppCheck.py @ 1266

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/Scanner/ppCheck.py@1266
Revision 1266, 2.2 KB checked in by domlowe, 15 years ago (diff)

Added scanning utility code:
ppCheck.py -checks pp files are valid and can be opened in cdms.
nappySummary.py provides a summary of contents of a NASAAmes file in readable form (not finished).

Line 
1#!/usr/bin/env python
2#**************************************************************************************
3#ppcheck
4#**************************************************************************************
5
6import cdms
7import getopt
8import sys
9import csmllibs
10
11def main(optargs=None):
12    #get commandline args
13    if optargs:
14        #if called as main(args) from another python module use these args, else use
15        #sys.argv if called from command line.
16        sys.argv =optargs
17    try:
18            opts, args = getopt.getopt(sys.argv[1:], "d:o:", ["directory=",  "outputfile=",])
19    except getopt.error, msg:
20            print "Invalid options, use --help for help"
21            sys.exit()
22    print opts
23    for o, v in opts:
24            if o in ("-d", "--directory"):
25                    directory = v
26            elif o in ("-o", "--outputfile"):
27                    outputfile = v                     
28
29    tree = csmllibs.csmldirectory.DirectoryTree()
30    tree.setTopDirectory(directory)
31    tree.readDirectory()
32   
33    success=[]
34    failure=[]
35    nonPP=[]
36    for subdir in tree.getSubDirectories():
37        for file in tree.getFilesInSubDir(subdir):
38           
39            if file[-3:] == '.pp':
40                try:
41                    f=cdms.open(file)
42                    success.append(str(file))
43                    #print '%s opened successfully' % str(file)                       
44                    f.close()
45                    print 'closed'
46                except:
47                    failure.append(str(subdir)+ '   ' + str(file))
48                        #print 'could not open file %s' % str(file)
49
50
51   
52               
53    outf = open(outputfile, "w")
54    outf.write('\n Results for directory; %s' % directory)
55    outf.write('\n \n Executive Summary:')
56    outf.write('\n %d files can be read by cdunif' % len(success))
57    outf.write('\n %d files are unreadable cdunif' % len(failure))
58    outf.write('\n \n \n  The following files appeared to open OK:')
59    for f in success:
60        outf.write('\n %s'%f)
61    outf.write('\n \n \n The following would NOT open:')
62    for f in failure:
63        outf.write('\n %s'%f)
64   
65    outf.close()
66    print 'Results written to %s' % outputfile
67       
68if __name__=='__main__':
69    main() 
Note: See TracBrowser for help on using the repository browser.