source: nappy/tags/nappy_pre_refactor_feb2008/nappy/bin/nc2na @ 3313

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/tags/nappy_pre_refactor_feb2008/nappy/bin/nc2na@3313
Revision 3313, 3.4 KB checked in by astephen, 12 years ago (diff)

Moved to new version as tagged backup.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
3#   This software may be distributed under the terms of the
4#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5
6helpMessage="""
7
8nc2na.py
9========
10
11Converts a NetCDF file into one a NASA Ames file.
12
13Usage
14=====
15
16    nc2na [-v <var_list>] [-r <rulename>[,<ruletype>[,<ra1>[,<ra2>[,<ra3>]]]]]] [-j] [-f <float_format>]
17              [-s <spacer>] [-d <DATE>] [-l <limitFFI1001Rows>]
18              [-e <ex_var_list>] [<overwrite_global_metadata>] -i <infilename> -o <outfilename>
19
20Where
21-----
22
23    infilename  - name of input file (NetCDF).
24    outfilename - name of output file (NASA Ames).
25    varlist     - a comma separated list of variables to include in the output file.
26    -r          - provide rule arguments for calling additional routines held in nappy/rules sub-package.
27                  example call would be "-r aircraft,av,flag,1,0,1" telling nappy to call rules/aircraftData.py
28                  and interpret the rest of the arguments when called (in this case sub-sampling by averaging.
29                  Or "-r aircraft,ss,flag,1,0,1" to sub-sample by selection using the flag variable at
30                  a sampling rate of 1Hz using valid flags of 0 and 1 only.
31    limitFFI1001Rows - if format FFI is 1001 then chop files up into <limitFFI1001Rows> rows of data.
32    -j          - just display file names that would be produced - without creating files.
33    -s          - resample data to per-second for aircraft data.     
34    floatformat - a python formatting string such as %s or %5.2f
35    spacer      - the spacer you wish to use between data items in the output file such as "   " or "\t"
36    DATE    - to replace first valid Date of data ("DATE") in the file.
37    overwrite_global_metadata           -  one of "DATE", "RDATE", "ANAME", "MNAME",
38           "ONAME", "ORG", "SNAME", "VNAME" followed by "=<overwrite_value>".
39   
40"""
41
42# Imports from python standard library
43import sys, os, time, string, fileinput, re
44sys.path.append("..")
45from cdms2na import *
46
47if __name__=="__main__":
48
49    args=sys.argv[1:]
50
51    allowedOverwriteMetadata=["DATE",  "RDATE", "ANAME", "MNAME",
52           "ONAME", "ORG", "SNAME", "VNAME"]   
53    variables=None
54   
55    if len(args)<4:
56        print helpMessage
57        print "Incorrect number of arguments used."
58        sys.exit()
59
60    nFilesOnly="no"
61    rule=None
62    spacer="    "
63    sizeLimit=None
64    floatFormat="%8.3f" 
65    naVars={}
66
67    for arg in args:
68        if arg=="-i":
69            infile=args[args.index(arg)+1]
70        elif arg=="-o":
71            outfile=args[args.index(arg)+1]
72        elif arg=="-f":
73            floatFormat=args[args.index(arg)+1]
74        elif arg=="-j":
75            nFilesOnly="yes"
76        elif arg=="-r":
77            rule=args[args.index(arg)+1].split(",")
78        elif arg=="-s":
79            spacer=args[args.index(arg)+1]         
80        elif arg=="-d":
81            naVars["DATE"]=args[args.index(arg)+1]         
82        elif arg=="-l":
83            sizeLimit=long(args[args.index(arg)+1])
84        elif arg[0]=="-" and arg[1:] in allowedOverwriteMetadata:
85            naVars[arg[1:]]=args[args.index(arg)+1]
86        elif arg in ("-v", "-vars", "-var", "-variables"):
87            variables=args[args.index(arg)+1].split(",")
88
89    rtvalue=cdms2na(infile, outfile, naVars, variables, nFilesOnly, sizeLimit=sizeLimit, rule=rule, spacer=spacer, 
90floatFormat=floatFormat) 
91    if nFilesOnly=="yes":
92        print "\n\nOutput files would be:"
93        for file in rtvalue:
94            print file
Note: See TracBrowser for help on using the repository browser.