def main(argv):

    gibsColorMaps = []
    
    sldFile   = ""
    units     = None
    layerName = ""
    offset    = 0.0
    factor    = 1.0
    rgbaOrder = "RGBA"
    format    = "{}"
    densify   = None


    try:
        opts, args = getopt.getopt(argv,"hs:l:u:o:p:f:r:d:",["sld=","layer=","units=","offset=","precision=","factor=","rgba_order=","densify="])
    except getopt.GetoptError:
        print("Usage: SLDtoColorMap.py -s <sld> -l <layer> -u <units> -o <offset> -f <factor> -r <rgba_order>")
        print("\nOptions:")
        print("  -h, --help             show this help message and exit")
        print("  -s SLD_FILE, --sld SLD_FILE")
        print("  						Path to SLD file to be converted")
        print("  -l LAYER_NAME, --layer LAYER_NAME")
        print("							Value to be placed in the NamedLayer/Name element")
        print("  -u UNITS, --units UNITS")
        print("							Units to be appended to data values when generating labels.  (Optional)")
        print("  -o OFFSET, --offset OFFSET")
        print("							Floating point value used as an offset when calculating raw data values from SLD values.  (Optional)")
        print("  -f FACTOR, --factor FACTOR")
        print("							Floating point value used as factor when calculating raw data values from SLD values.  (Optional)")
        print("  -r RGBA_ORDER , --rgba_order RGBA_ORDER")
        print("							The RGBA ordering to be used when parsing the SLD v1.1.0 fallbackValue.")
        print("							The alpha value is optional.  Sample values \"RGB\", \"ARGB\"")
        print("  -p PRECISION, --precision PRECISION")
        print("							The number of decimal places to round values to plus the format specifier for floating point (f) ")
        print("							or exponential (e).  Example: '2f' or '3e'  (Optional)")
        print("  -d DENSIFY, --densify DENSIFY")
        print("							The algorithm used to densify an SLD into a GIBS colormap by adding additional colors and data steps.")
        print("							Format: '[ors][0-9]*'. The first character specifies the algorithm (o = override / r = ramp / s = step).")
        print("							An integer value follows the algorithm specifying how much to densify.  Example: 'r20' or 's5'   (Optional)")
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print("Usage: SLDtoColorMap.py -s <sld> -l <layer> -u <units> -o <offset> -f <factor> -r <rgba_order>")
            print("\nOptions:")
            print("  -h, --help             show this help message and exit")
            print("  -s SLD_FILE, --sld SLD_FILE")
            print("							Path to SLD file to be converted")
            print("  -l LAYER_NAME, --layer LAYER_NAME")
            print("							Value to be placed in the NamedLayer/Name element")
            print("  -u UNITS, --units UNITS")
            print("							Units to be appended to data values when generating labels.  (Optional)")
            print("  -o OFFSET, --offset OFFSET")
            print("							Floating point value used as an offset when calculating raw data values from SLD values.  (Optional)")
            print("  -f FACTOR, --factor FACTOR")
            print("							Floating point value used as factor when calculating raw data values from SLD values.  (Optional)")
            print("  -r RGBA_ORDER , --rgba_order RGBA_ORDER")
            print("							The RGBA ordering to be used when parsing the SLD v1.1.0 fallbackValue.")
            print("							The alpha value is optional.  Sample values \"RGB\", \"ARGB\"")
            print("  -p PRECISION, --precision PRECISION")
            print("							The number of decimal places to round values to plus the format specifier for floating point (f) ")
            print("							or exponential (e).  Example: '2f' or '3e'  (Optional)")
            print("  -d DENSIFY, --densify DENSIFY")
            print("							The algorithm used to densify an SLD into a GIBS colormap by adding additional colors and data steps.")
            print("							Format: '[ors][0-9]*'. The first character specifies the algorithm (o = override / r = ramp / s = step).")
            print("							An integer value follows the algorithm specifying how much to densify.  Example: 'r20' or 's5'   (Optional)")
            sys.exit()
        elif opt in ("-s", "--sld"):
            sldFile = arg
        elif opt in ("-l", "--layer"):
            layerName = arg
        elif opt in ("-u", "--units"):
            units = arg
        elif opt in ("-f", "--factor"):
            factor = float(arg)
        elif opt in ("-o", "--offset"):
            offset = float(arg)
        elif opt in ("-p", "--precision"):
            format = "{:." + arg + "}"
        elif opt in ("-r", "--rgba_order"):
            rgbaOrder = arg        
        elif opt in ("-d", "--densify"):
            if not re.match("[sro][0-9]*", arg):
                print("Invalid densification.  Please try again.")
                exit(-1)
            else:
                densify = arg


    sldXmldoc = minidom.parse(sldFile)
    attrDict = dict(sldXmldoc.documentElement.attributes.items())
    
    if 'version' in attrDict:
        if attrDict['version'] == "1.0.0":
            gibsColorMaps = parseSLD_v1_0_0(sldFile, layerName, units, offset, factor)
        elif attrDict['version'] == "1.1.0":
            gibsColorMaps = parseSLD_v1_1_0(sldFile, layerName, units, offset, factor, rgbaOrder, format, densify)
        else:
            print("Invalid version specified: " + attrDict['version'])
            exit(-1)
        
        generateColorMap(gibsColorMaps, units, format)
    else:
        print("Version not specified in the SLD")
        exit(-1)
dataset/ETHPy150Open nasa-gibs/onearth/src/scripts/SLDtoColorMap.py/main/original