import os, sys, traceback

if __name__ == '__main__':
    
    import arcgisscripting
    gp = arcgisscripting.create()
    # Check out any necessary licenses
    gp.CheckOutExtension("spatial")

    gp.OverwriteOutput = 1

    try:
        Input_raster = gp.getparameterastext(0)
        valuetype = gp.GetRasterProperties (Input_raster, 'VALUETYPE')
        valuetypes = {1:'Integer', 2:'Float'}
        if valuetype != 2:
            gp.adderror('Not a float-type raster')
            sys.exit()
        startOID = gp.getparameter(1)

        from floatingrasterclass import FloatRasterSearchcursor, FloatRasterVAT
        gp.addMessage("Raster To Float Conversion")
        fltras = FloatRasterVAT(gp,  Input_raster)
        rows = fltras.FloatRasterSearchcursor()
        gp.addmessage('OID   VALUE   COUNT')
        for row in rows:
            if startOID > row.OID: continue
            gp.addmessage('%s %s %s' %(row.OID, row.Value, row.getvalue('Count')))
            if row.oid > startOID + 50:
                gp.AddWarning('Greater than 50 raster values.')
                break
        gp.addmessage('No. unique values: %d'%len(fltras))
##        #Aquisition test
##        vat = FloatRasterVAT(gp, Input_raster)
##        rows = vat.FloatRasterSearchcursor()
##        for row in rows:
##            gp.addmessage('%s, %s'%(row.Value,vat[row.Value]))
    except SystemExit:
        pass
    except:
        # get the traceback object
        tb = sys.exc_info()[2]
        # tbinfo contains the line number that the code failed on and the code from that line
        tbinfo = traceback.format_tb(tb)[0]
        # concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n    " + \
            str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
        # generate a message string for any geoprocessing tool errors
        msgs = "GP ERRORS:\n" + gp.GetMessages(2) + "\n"
        gp.AddError(msgs)

        # return gp messages for use with a script tool
        gp.AddError(pymsg)

        # print messages for use in Python/PythonWin
        print pymsg
        print msgs
        raise
