lenAR, float)

# opening log file
f = open('testZ0Influence_2d.log', 'w+')

for counter, ARnum in enumerate(range(7, n)):

    # looping Hn inputs
    AR = float(sys.argv[ARnum])
    Ls = max(3000, AR * h * 5)
    x0, x0C = AR * h / 60, AR * h / 20
    L = AR * h * 2
    L1 = L  #upwind refined area posibly smaller then downwind
    print "----------------------------------"
    if AR == 1000:
        print hilite("flat terrain", 1, 1)
        f.write("flat terrain")
        ARvec[counter] = 0
    else:
        print hilite("AR = " + str(AR), 1, 1)
        f.write("AR = " + str(AR))
        ARvec[counter] = AR

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # #  	      1, 2	 	# # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

    # looping over us until convergence with measurements - using Crude mesh
    notConverged = 1
    # initial guess - according to flat terrain
    us = UM * k / math.log(yM / z0)
U43y = U2y = U43y_plus = U2y_plus = U43y_minus = U2y_minus = ARvec = zeros(lenAR, float)

# opening log file
f = open("testZ0Influence_2d.log", "w+")

for counter, ARnum in enumerate(range(7, n)):

    # looping Hn inputs
    AR = float(sys.argv[ARnum])
    Ls = max(3000, AR * h * 5)
    x0, x0C = AR * h / 60, AR * h / 20
    L = AR * h * 2
    L1 = L  # upwind refined area posibly smaller then downwind
    print "----------------------------------"
    if AR == 1000:
        print hilite("flat terrain", 1, 1)
        f.write("flat terrain")
        ARvec[counter] = 0
    else:
        print hilite("AR = " + str(AR), 1, 1)
        f.write("AR = " + str(AR))
        ARvec[counter] = AR

        # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
        # # # # # # # # # # # # # #  	      1, 2	 	# # # # # # # # # # # # # # # #
        # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

        # looping over us until convergence with measurements - using Crude mesh
    notConverged = 1
    # initial guess - according to flat terrain
    us = UM * k / math.log(yM / z0)
                                                       counter] = y, Ux_y, Uy_y
    else:
        ymat[:, counter], Ux_ymat[:, counter], Uy_ymat[:,
                                                       counter] = y, Ux_y, Uy_y

    # output
    fig1 = plt.figure(100)
    plt.plot(counter * 10 + Ux_y, y, 'k')
    plt.xlabel('U [m/s]')
    plt.ylabel('y [m]')

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # #  		4a	 	# # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

    print hilite("Refinced runs:", 1, 1)
    logger.info("Refinced runs:")
    while notConverged:
        y_plus, Ux_y_plus, Uy_y_plus = run2dHillBase(template0, targetDir,
                                                     target0, hillName, AR, r,
                                                     x, Ls, L, L1, H, x0, z0,
                                                     us, yM, h, "mapFields")
        # checking convergence
        UxSimulation = interp(yM, y_plus, Ux_y_plus)
        err = (UM - UxSimulation) / UM
        notConverged = abs(err) > epsilon
        print hilite(
            "UM = " + str((100 * UM // 1) * 0.01) + " ,UxSimulation = " + str(
                (100 * UxSimulation // 1) * 0.01) + " ,error is " +
            str(err * 100 // 1) + "%", 0, 1)
        logger.info("UM = " + str((100 * UM // 1) * 0.01) +
		ymat[:,counter] , Ux_ymat[:,counter] , Uy_ymat[:,counter] = y, Ux_y, Uy_y
	else:
		ymat[:,counter] , Ux_ymat[:,counter] , Uy_ymat[:,counter] = y, Ux_y, Uy_y

	# output
	fig1 = plt.figure(100)
	plt.plot(counter*10 + Ux_y,y,'k')
	plt.xlabel('U [m/s]')
	plt.ylabel('y [m]')

	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
	# # # # # # # # # # # # # #  		4a	 	# # # # # # # # # # # # # # # #
	# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #


	print hilite("Refinced runs:",1,1)
	logger.info("Refinced runs:")
	while notConverged:
		y_plus,Ux_y_plus,Uy_y_plus = run2dHillBase(template0, targetDir, 
				target0, hillName, AR, r, x, Ls, L, L1, H, x0, z0, us, yM, h, "mapFields")
		# checking convergence
		UxSimulation = interp(yM,y_plus,Ux_y_plus)
		err = (UM-UxSimulation)/UM
		notConverged = abs(err)>epsilon	
		print hilite("UM = " +  str((100*UM//1)*0.01) + " ,UxSimulation = " + 
				str((100*UxSimulation//1)*0.01) + " ,error is " + str(err*100//1) + "%",0,1)
		logger.info("UM = " +  str((100*UM//1)*0.01) + " ,UxSimulation = " + 
				str((100*UxSimulation//1)*0.01) + " ,error is " + str(err*100//1) + "%")
		# changing us
		us = us/(1-err)*relax
		print hilite("us = " +  str((100*us//1)*0.01),0,1)