source: nappy/trunk/bin/nc2na @ 368

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/bin/nc2na@368
Revision 368, 3.2 KB checked in by astephen, 14 years ago (diff)

Updates for correctly converting and reducing volume of FAAM flight data using the localRules/aircraftData.py module.

  • 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#   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,1,1f,2f,3f" telling nappy to call rules/aircraftData.py
28                  and interpret the rest of the arguments when called.
29    limitFFI1001Rows - if format FFI is 1001 then chop files up into <limitFFI1001Rows> rows of data.
30    -j          - just display file names that would be produced - without creating files.
31    -s          - resample data to per-second for aircraft data.     
32    floatformat - a python formatting string such as %s or %5.2f
33    spacer      - the spacer you wish to use between data items in the output file such as "   " or "\t"
34    DATE    - to replace first valid Date of data ("DATE") in the file.
35    overwrite_global_metadata           -  one of "DATE", "RDATE", "ANAME", "MNAME",
36           "ONAME", "ORG", "SNAME", "VNAME" followed by "=<overwrite_value>".
37   
38"""
39
40# Imports from python standard library
41import sys, os, time, string, fileinput, re
42sys.path.append("..")
43from cdms2na import *
44
45if __name__=="__main__":
46
47    args=sys.argv[1:]
48
49    allowedOverwriteMetadata=["DATE",  "RDATE", "ANAME", "MNAME",
50           "ONAME", "ORG", "SNAME", "VNAME"]   
51    variables=None
52   
53    if len(args)<4:
54        print helpMessage
55        print "Incorrect number of arguments used."
56        sys.exit()
57
58    nFilesOnly="no"
59    rule=None
60    spacer="    "
61    sizeLimit=None
62    floatFormat="%8.3f" 
63    naVars={}
64
65    for arg in args:
66        if arg=="-i":
67            infile=args[args.index(arg)+1]
68        elif arg=="-o":
69            outfile=args[args.index(arg)+1]
70        elif arg=="-f":
71            floatFormat=args[args.index(arg)+1]
72        elif arg=="-j":
73            nFilesOnly="yes"
74        elif arg=="-r":
75            rule=args[args.index(arg)+1].split(",")
76        elif arg=="-s":
77            spacer=args[args.index(arg)+1]         
78        elif arg=="-d":
79            naVars["DATE"]=args[args.index(arg)+1]         
80        elif arg=="-l":
81            sizeLimit=long(args[args.index(arg)+1])
82        elif arg[0]=="-" and arg[1:] in allowedOverwriteMetadata:
83            naVars[arg[1:]]=args[args.index(arg)+1]
84        elif arg in ("-v", "-vars", "-var", "-variables"):
85            variables=args[args.index(arg)+1].split(",")
86
87    rtvalue=cdms2na(infile, outfile, naVars, variables, nFilesOnly, sizeLimit=sizeLimit, rule=rule, spacer=spacer, 
88floatFormat=floatFormat) 
89    if nFilesOnly=="yes":
90        print "\n\nOutput files would be:"
91        for file in rtvalue:
92            print file
Note: See TracBrowser for help on using the repository browser.