Running a script function using "GetComponent"

I am trying to automatically run a Heightmapping (terrain generator) script using ‘GetComponent’…

My code looks like this:

if(Input.GetKeyDown (KeyCode.G))
    		{
    			TerrainData Tdata = new TerrainData();
                            GameObject T1 = Terrain.CreateTerrainGameObject(Tdata);
    T1.AddComponent("TerrainToolkit");

This works fine but now I need to access the TerrainToolkit and run the code that gives the terrain its heightmapping, I found this section which I believe is what I need to run:

public float[,] generateDiamondSquare(float[,] heightMap, Vector2 arraySize, GeneratorProgressDelegate generatorProgressDelegate) {
		int Tw = (int) arraySize.x;
		int Th = (int) arraySize.y;
		float heightRange = 1.0f;
		int step = Tw - 1;
		heightMap[0, 0] = 0.5f;
		heightMap[Tw - 1, 0] = 0.5f;
		heightMap[0, Th - 1] = 0.5f;
		heightMap[Tw - 1, Th - 1] = 0.5f;
		generatorProgressDelegate("Fractal Generator", "Generating height map. Please wait.", 0.0f);
		while (step > 1) {
			// diamond
			for (int Tx = 0; Tx < Tw - 1; Tx += step){
				for (int Ty = 0; Ty < Th - 1; Ty += step){
					int sx = Tx + (step >> 1);
					int sy = Ty + (step >> 1);
					Vector2[] points = new Vector2[4];
					points[0] = new Vector2(Tx, Ty);
					points[1] = new Vector2(Tx + step, Ty);
					points[2] = new Vector2(Tx, Ty + step);
					points[3] = new Vector2(Tx + step, Ty + step);
					dsCalculateHeight(heightMap, arraySize, sx, sy, points, heightRange);
				}
			}
			// square
			for (int Tx = 0; Tx < Tw - 1; Tx += step) {
				for (int Ty = 0; Ty < Th - 1; Ty += step) {
					int halfstep = step >> 1;
					int x1 = Tx + halfstep;
					int y1 = Ty;
					int x2 = Tx;
					int y2 = Ty + halfstep;
					Vector2[] points1 = new Vector2[4];
					points1[0] = new Vector2(x1 - halfstep, y1);
					points1[1] = new Vector2(x1, y1 - halfstep);
					points1[2] = new Vector2(x1 + halfstep, y1);
					points1[3] = new Vector2(x1, y1 + halfstep);
					Vector2[] points2 = new Vector2[4];
					points2[0] = new Vector2(x2 - halfstep, y2);
					points2[1] = new Vector2(x2, y2 - halfstep);
					points2[2] = new Vector2(x2 + halfstep, y2);
					points2[3] = new Vector2(x2, y2 + halfstep);
					dsCalculateHeight(heightMap, arraySize, x1, y1, points1, heightRange);
					dsCalculateHeight(heightMap, arraySize, x2, y2, points2, heightRange);
				}
			}
			heightRange *= diamondSquareDelta;
			step >>= 1;
		}
		generatorProgressDelegate("Fractal Generator", "Generating height map. Please wait.", 1.0f);
		return heightMap;
	}

I then use the command T1.GetComponent(TerrainToolkit)().insert command here;
I have been able to successfully change variables within terraintoolkit, but when I insert the above lines of code it gives me an error saying “}” expected right before “public float”

Is my approach correct? This is very confusing and I apologize for the wall of text!

OK I solved it, What I had to do was select the parameters on the editor menus and run it

T1.AddComponent("TerrainToolkit");
	T1.GetComponent<TerrainToolkit>().generatorTypeInt = 1;		
	T1.GetComponent<TerrainToolkit>().diamondSquareDelta = 0.4f;
	T1.GetComponent<TerrainToolkit>().diamondSquareBlend = 1.0f;
    T1.GetComponent<TerrainToolkit>().generateTerrain(GeneratorProgressDelegategeneratorProgressDelegate);