source: TI02-CSML/trunk/Examples/ScanningStuff/nappySummary.py @ 1460

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/Examples/ScanningStuff/nappySummary.py@1460
Revision 1460, 1.9 KB checked in by domlowe, 15 years ago (diff)

Moving various non-core scripts etc out of scanner directory

Line 
1#!/usr/bin/env python
2
3#Little program to summarise contents of a NASAAmes file for human consumption.
4#Dominic Lowe, British Atmospheric Data Centre, 3rd July 2006
5
6import nappy
7import getopt
8import sys
9from csmllibs import csmldataiface
10
11
12def printSummary(DI, outputfile):
13    print dir(DI)
14    print '     Contains Independent Variables (Axes):'
15    i =0
16    for axis in DI.getListOfAxes():
17        i = i +1
18        print '        Axis %d: %s, size: %s' % (i, axis, DI.getSizeOfAxis(axis))
19       
20    print '      Contains Dependent Variables:'
21    i=0
22    for var in  DI.getListofVariables():
23        i=i +1
24        DI.setVariable(var)
25        print '         Variable %d: %s, shape: %s' %(i, var, DI.getShapeOfVar())
26   
27    if outputfile is not None:
28        pass #need to write to file
29    DI.closeFile()
30
31def main(optargs=None):
32    #get commandline args
33    inputfile = None
34    outputfile=None
35    if optargs:
36        #if called as main(args) from another python module use these args, else use
37        #sys.argv if called from command line.
38        sys.argv =optargs
39    try:
40            opts, args = getopt.getopt(sys.argv[1:], "i:o:", ["inputfile=",  "outputfile=",])
41    except getopt.error, msg:
42            print "Invalid options, use --help for help"
43            sys.exit()
44    print opts
45    for o, v in opts:
46            if o in ("-i", "--inputfile"):
47                    inputfile = v
48            elif o in ("-o", "--outputfile"):
49                    outputfile = v             
50                   
51    if inputfile is None:
52        print 'You must specify an inputfile using -i [filename]'
53        sys.exit()
54    else: pass
55   
56    try:
57        DI = csmldataiface.DataInterface()
58        DI = DI.getUnknownInterfaceType(inputfile)
59        DI.openFile(inputfile)
60    except:
61        print 'Could not open file %s' % str(inputfile)
62        sys.exit()
63
64    printSummary(DI,outputfile)
65                   
66if __name__=='__main__':
67    main() 
Note: See TracBrowser for help on using the repository browser.