source: nappy/trunk/bin/na2nc @ 347

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/bin/na2nc@347
Revision 347, 1.4 KB checked in by selatham, 15 years ago (diff)

Incorporates changes by selatham and Ag Stephens. as of 5/11/04.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/env python
2"""
3na2cdms.py
4==========
5
6Module holds the na2cdms function to convert a NASA Ames file to a CDMS
7file (NetCDF).
8
9"""
10
11helpMessage="""
12
13na2nc
14=====
15
16Converts a NASA Ames file to a NetCDF file.
17
18Usage
19=====
20
21   na2nc.py [<options>] -i <infilename> -o <outfilename>
22
23Where
24-----
25
26    infilename  - name of input file (NASA Ames).
27    outfilename - name of output file (NetCDF).
28    options     - list of options:
29                    -t <time_units_string>  (such as "hours since 2003-04-30 10:00:00")
30   
31"""
32
33# Imports from python standard library
34import sys
35sys.path.append(r"..")
36import os
37import re
38import time
39
40# Import from nappy package
41import general
42import cdmsMap
43
44def na2cdms(nafile, ncfile, time_units=None, rules=None):
45    print "Reading data from: %s" % nafile
46    file=general.openNAFile(nafile)
47
48    print "Writing output NetCDF file: %s\n" % ncfile
49    file.toCdmsFile(ncfile, time_units=time_units)
50   
51    print "\nNetCDF file written successfully: %s" % ncfile
52
53    return 1
54
55if __name__=="__main__":
56
57    args=sys.argv[1:]
58    if len(args)<4:
59        print helpMessage
60        print "Incorrect number of arguments used."
61        sys.exit()
62       
63    time_units=None
64    for arg in args:
65        if arg=="-i":
66            infile=args[args.index(arg)+1]
67        elif arg=="-o":
68            outfile=args[args.index(arg)+1]
69        elif arg=="-t":
70            time_units=args[args.index(arg)+1]
71
72    na2cdms(infile, outfile, time_units=time_units) 
73
Note: See TracBrowser for help on using the repository browser.