Changeset 1379


Ignore:
Timestamp:
10/08/06 13:19:21 (13 years ago)
Author:
domlowe
Message:

aligned command line args with config options

Location:
TI02-CSML/trunk/Scanner
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/Scanner/csmlscan.py

    r1378 r1379  
    3737                         
    3838                 
    39     -c csmlfeaturetype: The csmlFeatureType of the data. Only GridSeriesProfile is  
     39    -f csmlfeaturetype: The csmlFeatureType of the data. Only GridSeriesProfile is  
    4040                currently implemented. Other feature types are PointFeature 
    4141                PointSeriesFeature ProfileFeature ProfileSeriesFeature and GridFeature. 
     
    4444                different variable name you may supply it with this option. 
    4545 
    46     -r recursive:       if this option is provided along with the -d option, all 
    47                 netcdf files in subdirectories of the -d directory are also processed. 
    48                 If it is not provided, then only the netcdf files in the named directory  
    49                 are processed. 
    50  
    5146    -o outputfile:      Provide the name of the output file, default is csmloutput.xml 
    5247                                which can be found in the directory from which the program is run 
     
    6156         
    6257         
    63         python Coapec2csml.py -d /home/users/me/mynetcdffiles/ -r 
    64                 - processes all netcdf files in the mynetcdffiles directory and 
    65                   any subdirectories, output to default file csmloutput.xml 
    66                   
    67          
    68         python Coapec2csml.py myfile1.nc myfile2.nc myfile3.nc 
    69                 - processes the three named files, output to default file csmloutput.xml 
    70          
    71          
    7258        python Coapec2csml.py myfile1.nc myfile2.nc myfile3.nc -t timevar 
    7359                - processes the three named files, aggregating with the time dimension 
     
    8066                  myfile1.nc, myfile2.nc and myfile3.nc are all ignored. Outputs to 
    8167                  file called myoutput.xml. 
    82                  
    83      
    84 Notes: 
    85  
    86         (1) The files must be CF compliant. 
    87          
    88         (2) Currently only works for GridSeriesFeatures - ie. typical atmospheric model 
    89          output. 
    90          
     68         
     69        TODO: more examples      
    9170         
    9271""" 
     
    11190        sys.argv =optargs 
    11291    try: 
    113             opts, args = getopt.getopt(sys.argv[1:], "c:xd:f:t:m:rpo:h", ["configfile=,directory=", "csmlfeaturetype=", "exitafterconfig","timedimension=", "filemapping=", "recursive", "printscreen", "outputfile=", "help"]) 
     92            opts, args = getopt.getopt(sys.argv[1:], "c:d:f:xt:m:rpo:h", ["configfile=,directory=", "csmlfeaturetype=", "exitafterconfig","timedimension=", "filemapping=", "recursive", "printscreen", "outputfile=", "help"]) 
    11493    except getopt.error, msg: 
    11594            print "Invalid options, use --help for help" 
    11695            sys.exit() 
     96    hasConfig=False 
    11797    for o, v in opts: 
    11898            if o in ("-c", "--configfile"): 
     
    123103                    if o in ("-x", "--exitafterconfig"): 
    124104                        configTest=True 
    125             else: pass #process other args... TODO 
    126  
     105             
     106    #set default values for required configs 
     107    PRINTSCREEN = 0 
     108    MAPPING=None 
     109    TIMEDIMENSION=None 
     110    #... 
    127111    if hasConfig == True: 
    128112        config.read(configfile) 
     
    132116        MAPPING = config.getConfigNoError('files', 'mapping') 
    133117        OUTPUTFILE = config.getConfigNoError('files', 'output') 
     118        PRINTSCREEN = config.getConfigNoError('files', 'printscreen') 
    134119        SRSNAME = config.getConfigNoError('SpatialReference', 'srs') 
    135120        TIMEDIMENSION=config.getConfigNoError('time','timedimension') 
     
    145130            print '\n files:mapping =%s'%MAPPING 
    146131            print '\n files:output =%s'%OUTPUTFILE 
     132            print '\n files:printscreen =%s'%PRINTSCREEN 
    147133            print '\n SpatialReference:srs =%s'%SRSNAME 
    148134            print '\n time:timedimension =%s'%TIMEDIMENSION 
    149135            sys.exit() 
    150     print 'scan as normal....' 
    151          
    152  
    153         
    154 def mainOLD(optargs=None): 
    155     #Main program: 
    156     #*************** 
    157     #Get command line arguments 
    158     if optargs: 
    159         #if called as main(args) from another python module use these args, else use  
    160         #sys.argv if called from command line. 
    161         sys.argv =optargs 
    162     try: 
    163             opts, args = getopt.getopt(sys.argv[1:], "d:c:t:f:rpo:h", ["directory=", "csmlfeaturetype=", "timedimension=", "filemapping=", "recursive", "printscreen", "outputfile=", "help"]) 
    164     except getopt.error, msg: 
    165             print "Invalid options, use --help for help" 
    166             sys.exit() 
    167     print sys.argv 
    168136     
    169     # process options 
    170     directory = None 
    171     csmlfeaturetype = 'GridSeriesFeature'   #default feature type 
    172     timedimension  = 't' 
    173     mapping = None 
    174     recursive = 0 
    175     printscreen=0 
    176     individual = False 
    177     outputfile = 'csmloutput.xml' 
    178     for o, v in opts: 
     137    else: #no config file, get command line args 
     138        for o, v in opts: 
     139            print o,v 
     140        for o, v in opts: 
    179141            if o in ("-d", "--directory"): 
    180                     directory = v 
    181             elif o in ("-c", "--csmlfeaturetype"): 
    182                     csmlfeaturetype = v 
     142                    ROOTDIRECTORY = v 
     143            elif o in ("-f", "--csmlfeaturetype"): 
     144                    FEATURETYPE = v 
    183145            elif o in ("-t", "--timedimension"): 
    184                     timedimension = v 
     146                    TIMEDIMENSION = v 
    185147            elif o in ("-f", "--filemapping"): 
    186                     if v == '11': 
    187                         mapping = 'onetoone' 
    188                     elif v == '1n': 
    189                         mapping = 'onetomany' 
    190                     elif v == '1o': 
    191                         mapping = 'oneonly' 
     148                    MAPPING=v 
    192149            elif o in ("-p", "--printscreen"): 
    193                     printscreen = 1 
     150                    PRINTSCREEN = 1 
    194151            elif o in ("-o", "--outputfile"): 
    195                     outputfile = v 
     152                    OUTPUTFILE = v 
    196153            elif o in ("-h", "--help"): 
    197154                    print usage 
    198                     sys.exit()                           
    199              
    200     #create CSML: 
    201     if csmlfeaturetype == "PointFeature": 
    202         #NOT YET IMPLEMENTED# 
    203         if mapping is None: 
    204             mapping = 'onetoone' #default filemapping for PointFeature (?) 
    205              
    206     elif csmlfeaturetype == "ProfileFeature": 
    207         #NOT YET IMPLEMENTED# 
    208         if mapping is None: 
    209             mapping = 'onetoone' #default filemapping for ProfileFeature (?) 
    210              
    211     elif csmlfeaturetype == "GridFeature": 
    212             #NOT YET IMPLEMENTED# 
    213         if mapping is None: 
    214             mapping = 'onetoone' #default filemapping for GridFeature  
     155                    sys.exit()   
     156                     
     157    # Handle defaults in case of no file mapping: 
     158    if MAPPING is None: 
     159        if FEATURETYPE == "PointFeature": 
     160            MAPPING = 'onetoone' #default filemapping for PointFeature (?) 
     161        elif FEATURETYPE == "ProfileFeature":             
     162            MAPPING = 'onetoone' #default filemapping for ProfileFeature (?) 
     163        elif FEATURETYPE == "GridFeature": 
     164            MAPPING = 'onetoone' #default filemapping for GridFeature  
     165        elif FEATURETYPE == "PointSeriesFeature": 
     166            MAPPING = 'onetomany' 
     167        elif FEATURETYPE == "ProfileSeriesFeature": 
     168            MAPPING = 'onetomany' #default filemapping for ProfileSeriesFeature (?) 
     169        elif FEATURETYPE == "GridSeriesFeature": 
     170            MAPPING = 'onetomany' #default filemapping for GridSeriesFeature 
    215171     
    216     elif csmlfeaturetype == "PointSeriesFeature": 
    217         if mapping is None: 
    218             mapping = 'onetomany' 
    219      
    220     elif csmlfeaturetype == "ProfileSeriesFeature": 
    221         if mapping is None:     #NOT YET IMPLEMENTED# 
    222             mapping = 'onetomany' #default filemapping for ProfileSeriesFeature (?) 
    223              
    224     elif csmlfeaturetype == "GridSeriesFeature": 
    225         if mapping is None: 
    226             mapping = 'onetomany' #default filemapping for GridSeriesFeature 
    227  
    228     csmldataset=csmllibs.csmlbuilder.csmlBuilder(directory,csmlfeaturetype,mapping,timedimension, outputfile, printscreen) 
    229     print 'building csml... with %s mapping '%mapping 
     172    #build CSML document 
     173    print ROOTDIRECTORY 
     174    csmldataset=csmllibs.csmlbuilder.csmlBuilder(ROOTDIRECTORY,FEATURETYPE,MAPPING,TIMEDIMENSION, OUTPUTFILE, PRINTSCREEN) 
    230175    csmldataset.build() 
    231      
    232      
     176 
    233177    print '' 
    234178    print '********************************************************************' 
    235     print 'CSML file is at: ' + outputfile 
     179    print 'CSML file is at: ' + OUTPUTFILE 
    236180    print '********************************************************************'                 
    237181    print '' 
  • TI02-CSML/trunk/Scanner/sampleconfig.cfg

    r1378 r1379  
    77mapping: onetomany 
    88output:csmlout.xml 
     9printscreen:1 
    910 
    1011[SpatialReference] 
Note: See TracChangeset for help on using the changeset viewer.