Changeset 3395 for nappy/trunk


Ignore:
Timestamp:
12/02/08 18:45:50 (12 years ago)
Author:
astephen
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/bin/na2nc.py

    r3351 r3395  
    3737# Import from nappy package 
    3838import nappy.nc_convertor.na_to_nc 
    39  
    40 def makeDictFromCommaSepString(s): 
    41     """ 
    42     Reads in comma-separated list and converts to dictionary of successive 
    43     keyword,value pairs. 
    44     """ 
    45     if s.count(",") % 2 == 0: 
    46         raise Exception("Must provide even number of items in argument of commas-separated pairs of values: " + s) 
    47  
    48     d = {} 
    49     items = value.split(",") 
    50     while len(items) > 0: 
    51         d[items[0]] = items[1] 
    52         items = items[2:]  
    53     return d 
     39import nappy.utils.common_utils 
    5440 
    5541def parseArgs(args): 
     
    7157    a["nc_file"] = None 
    7258 
    73     (arg_list, dummy) = getopt.getopt("i:o:m:v:a:g:t:nr:", args) 
     59    (arg_list, dummy) = getopt.getopt(args, "i:o:m:v:a:g:t:nr:") 
    7460     
    7561    for arg, value in arg_list: 
     
    8571            a["aux_variables"] = value.split(",") 
    8672        elif arg == "-g": 
    87             a["global_attributes"] = makeDictFromCommaSepString(value) 
     73            a["global_attributes"] = nappy.utils.makeDictFromCommaSepString(value) 
    8874        elif arg == "-t": 
    8975            a["time_units"] = value 
     
    9278        elif arg == "-r": 
    9379            a["rename_variables"] = makeDictFromCommaSepString(value) 
     80        else: 
     81            raise Exception("Argument '" + arg + "' not recognised!") 
    9482 
    9583    if not a["na_file"]: 
     
    118106    convertor = apply(nappy.nc_convertor.na_to_nc.NAToNC, [], arg_dict) 
    119107    convertor.convert() 
    120     convertor.write(nc_file, mode)     
     108    convertor.writeNCFile(nc_file, mode)     
    121109 
    122110 
Note: See TracChangeset for help on using the changeset viewer.