source: nappy/trunk/nappy/na2cdms.py @ 3314

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/na2cdms.py@3314
Revision 3314, 1.7 KB checked in by astephen, 12 years ago (diff)

Re-factored under a nappy directory for a start.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
4#   This software may be distributed under the terms of the
5#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
6
7"""
8na2cdms.py
9==========
10
11Module holds the na2cdms function to convert a NASA Ames file to a CDMS
12file (NetCDF).
13
14"""
15
16helpMessage="""
17
18na2nc
19=====
20
21Converts a NASA Ames file to a NetCDF file.
22
23Usage
24=====
25
26   na2nc.py [<options>] -i <infilename> -o <outfilename>
27
28Where
29-----
30
31    infilename  - name of input file (NASA Ames).
32    outfilename - name of output file (NetCDF).
33    options     - list of options:
34                    -t <time_units_string>  (such as "hours since 2003-04-30 10:00:00")
35   
36"""
37
38# Imports from python standard library
39import sys
40sys.path.append(r"..")
41import os
42import re
43import time
44
45# Import from nappy package
46import general
47import cdmsMap
48
49def na2cdms(nafile, ncfile, time_units=None, rules=None):
50    print "Reading data from: %s" % nafile
51    file=general.openNAFile(nafile)
52
53    print "Writing output NetCDF file: %s\n" % ncfile
54    file.toCdmsFile(ncfile, time_units=time_units)
55   
56    print "\nNetCDF file written successfully: %s" % ncfile
57
58    return 1
59
60if __name__=="__main__":
61    print "I DON'T THINK THIS IS NEEDED, TRY bin/na2nc instead"
62    sys.exit()
63    args=sys.argv[1:]
64    if len(args)<4:
65        print helpMessage
66        print "Incorrect number of arguments used."
67        sys.exit()
68       
69    time_units=None
70    for arg in args:
71        if arg=="-i":
72            infile=args[args.index(arg)+1]
73        elif arg=="-o":
74            outfile=args[args.index(arg)+1]
75        elif arg=="-t":
76            time_units=args[args.index(arg)+1]
77
78    na2cdms(infile, outfile, time_units=time_units) 
79
Note: See TracBrowser for help on using the repository browser.