#! /usr/bin/python import getopt import sys from export import Export import Image from my_exceptions import * from message import Message from double_lin_reg import Double_Linear_Regression from box_counting import Box_Counting def main(): message=Message() Exp=Export() #Output variable Construction nb_export=Exp.size_of_export_list() output_long_option=["output="] for i in range(2,(nb_export -1)): output_long_option=output_long_option+["output"+`i`+"="] #We recover options and arguments try: opts, args = getopt.gnu_getopt(sys.argv[1:], "fhm:p:o:", ["help","output_name=", "method=","precision=","force"]+output_long_option) except getopt.GetoptError: message.help() sys.exit(2) for o,a in opts: if o in ("-h", "--help"): message.help() sys.exit() Bc=Box_Counting(args[0]) #Default variable definition force=False error=False #We analyse options for o, a in opts: #help if o in ("-h", "--help"): message.help() sys.exit() #confirmation? if o in ("-f", "--force"): force=True #output if o in ("-o", "--output"): try: Exp.set_export(a) except InvalidArgument, argument : message.invalid_output() error=True for i in range(2,nb_export): if o ==("--output"+`i`): try: Exp.add_export(a) except InvalidArgument, argument : message.invalid_output(argument) error=True #output name if o =="--output_name": Exp.set_output_file_name(a) #precision if o in ("-p", "--precision"): try: af=float(a) if af>1 and af<=2: Bc.set_precision(af) else: error=True message.invalid_precision() except: message.invalid_precision() error=True #method if o in ("-m", "--method"): try: Bc.set_method(a) except InvalidArgument,detail: error=True message.invalid_method() #We test the outputfile #If there was error in the options, we ask the user if he want to continu #If the user want to continu, the bad arguments are simply ignored if not Exp.check_right(): error=True if error: message.doyouwanttocontinu() #We calculate the plot and the double linear regression Bc.compute() Dlr=Double_Linear_Regression(Bc.plot()) reg=Dlr.double_lin_reg() # We export the result. Exp.set_reg(reg) Exp.set_plot(Bc.plot()) Exp.export() main()