Attribute VB_Name = "Module2"
'Version 151222
Sub Main
        
	Dim SurferApp As Object
	Dim Doc1 As Object
	Dim Doc2 As Object
	Dim Plotwindow As Object
	Dim Map As Object
	Dim Grid As Object
	Dim ImageMap As Object
	Dim SurfaceMap As Object
	Dim Windows As Object

	Dim Wks As Object
	Dim WksRange As Object


	Dim MapTitle1 As Object
	Dim MapTitle2 As Object
	Dim MapTitle3 As Object

	Dim MethodLabel As Variant
	Dim Reihenfolge As Variant
	Dim GridFile As Variant

	Dim myMap As Variant
	Dim myDoc As Variant
	Dim myGrid As Variant
	Dim myPlotwindow As Variant
	Dim retValue As Boolean

	Dim Data As String
	Dim Path As String
	Dim Spurlaenge As String
	Dim Spurbreite As String
	Dim Index1 As Integer
	Dim Index2 As Integer
	Dim Stringlaenge As Integer
	Dim x_Scale As Double
	Dim y_Scale As Double
	Dim x_Len As Double
	Dim y_Len As Double
	Dim Diff As Double

	Dim DiffGnd As Double

	Dim MaxDiff As Double
	Dim zColumn As Integer
	Dim GridFile1 As String
	Dim GridFile2 As String
	Dim GridFile3 As String
	Dim GridFile4 As String
	Dim GridFile5 As String
	Dim GridFile6 As String

	Dim Method As Integer
	Dim GndCorr As Integer
	Dim Rmax As Double
	Dim Del1Max As Double
	Dim Del1Min As Double
	Dim Del2Max As Double
	Dim Del2Min As Double
	Dim Gnd1Corr As Double
	Dim Gnd2Corr As Double
	Dim k_upper As Double
	Dim	k_lower As Double
	Dim Gnd2Upper As Double
	Dim Gnd2Lower As Double
	Dim Gnd1Upper As Double
	Dim Gnd1Lower As Double
	Dim nTrackStart As Integer
	Dim nTrackEnde As Integer
	Dim tempStr As String
	Dim ntemp As Integer
	Dim result As Integer


		Begin Dialog UserDialog 550,350,"Field Settings"

			TextBox 430,28,80,21,.Text1
			TextBox 430,63,80,21,.Text2
			TextBox 430,98,80,21,.Text3
			TextBox 430,133,80,21,.Text4
			TextBox 430,168,80,21,.Text5
			TextBox 430,203,80,21,.Text6
			TextBox 430,238,80,21,.Text7
			TextBox 430,273,80,21,.Text8


			Text 30,28,400,14,"Track Length [m]",.Spurlänge
			Text 30,63,400,14,"Track Width [m]",.Spurbreite
			Text 30,98,400,14,"Gnd1-Correction [0; 300..700]  0=AUTO",.Gnd1Korr
			Text 30,133,400,14,"Gnd2-Correction [0; 300..700]  0=AUTO",.Gnd2Korr
			Text 30,168,400,14,"Metal Classification Sensitivity [1..10]",.ClassSens
			Text 30,203,400,14,"High Level  [Decrease -> High Sens., Increase -> Low Sens.]",.CompFact
			Text 30,238,400,14,"Low Level   [Decrease -> High Sens., Increase -> Low Sens.]",.UserNoiseLevel
			Text 30,273,400,14,"Filter   [0..5]",.UserFilter

			OKButton 50,310,90,21
			CancelButton 410,310,90,21

		End Dialog
		Dim dlgvar As UserDialog

		On Error Resume Next

		Data = GetFilePath(,"001;TXT",,"Select a Field",0 )
		Index1 = InStrRev(Data,"\")
		Index2 = InStrRev(Data, ".")
		Stringlaenge = Index2 - Index1 - 1
		FName$ = Mid$(Data, Index1+1, Stringlaenge )
		SName$ = Mid$(Data, 1, Index2 )
'----------------------

		Set SurferApp = CreateObject("Surfer.Application")

		SurferApp.Visible = False
		VName$ = Mid$(SurferApp.Version, 1, InStr(SurferApp.Version, ".") -1 )

		Set Windows = SurferApp.Windows

		MethodLabel = Array("Delay 4", "Ground 2", "Delay 3", "Ground 1", "Delay 2", "Metal Classification" )
		Reihenfolge = Array( 26, 22, 25, 21, 24, 23 )
		ErrorText	= Array( 0, 0, 0, 0, 0, 0 )

		GridFile1 = "C:\Delay4.grd"
		GridFile2 = "C:\Ground2.grd"
		GridFile3 = "C:\Delay3.grd"
		GridFile4 = "C:\Ground1.grd"
		GridFile5 = "C:\Delay2.grd"
		GridFile6 = "C:\Classification.grd"
		GridFile = Array( GridFile1,GridFile2,GridFile3,GridFile4,GridFile5,GridFile6 )

		Data1=Right$(Data, 3)
		If Data1 = "001" Then
			Set Wks = SurferApp.Documents.Add (srfDocWks)

			Data1=Mid$( Data,1,Len(Data)- 3 )
			i=1001
			n=0
			m=1
			Do
				ext = Str$(i)
				ext1=Right$(ext,3)
				Data2=Data1+ext1
				Set Wks1 = SurferApp.Documents.Open(Data2)
				If Err.Number=0 Then
					Set WksRange = Wks1.Columns(Col1:="B")
					Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsMaximum)
					Anz = Stats.Maximum+1
					Wks.Cells(m,34).Value = Anz
					m += 1
					Wks1.Close
					If Anz > 1 Then
						Wks.Merge(FileName:=Data2, Row:=GesAnzMessungen+1, Col:=1)
						If n=0 Then
							GesAnzMessungen = 0
							RefAnzMessungen = Anz
						End If
						If (n Mod 2) = 1 Then
							Wks.Transform(FirstRow:=GesAnzMessungen+1, LastRow:=GesAnzMessungen+Anz, Equation:="AR=" & CStr(RefAnzMessungen) )
							Wks.Transform(FirstRow:=GesAnzMessungen+1, LastRow:=GesAnzMessungen+Anz, Equation:="AS=" & CStr(Anz) )
							Wks.Transform(FirstRow:=GesAnzMessungen+1, LastRow:=GesAnzMessungen+Anz, Equation:="AT=AR-((AR/AS)*(B+1))" )
							Wks.Transform(FirstRow:=GesAnzMessungen+1, LastRow:=GesAnzMessungen+Anz, Equation:="B=AT" )
						Else
							Wks.Transform(FirstRow:=GesAnzMessungen+2, LastRow:=GesAnzMessungen+Anz, Equation:="AR=" & CStr(RefAnzMessungen) )
							Wks.Transform(FirstRow:=GesAnzMessungen+2, LastRow:=GesAnzMessungen+Anz, Equation:="AS=" & CStr(Anz) )
							Wks.Transform(FirstRow:=GesAnzMessungen+2, LastRow:=GesAnzMessungen+Anz, Equation:="AT=AR/AS*B" )
							Wks.Transform(FirstRow:=GesAnzMessungen+2, LastRow:=GesAnzMessungen+Anz, Equation:="B=AT" )
						End If
						GesAnzMessungen = GesAnzMessungen + Anz
						i=i+1
						n=n+1
					End If
				Else
					Anz=0
					Wks.Cells(m,34).Value = 0
					If RefAnzMessungen > 0 Then
						Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen+Anz, Equation:="A=A*10" )
					End If
				End If
			Loop Until Anz=0
			Wks.Cells(7, 27)=GesAnzMessungen

				Set WksRange = Wks.Cells(Row:=1, Col:="C", LastRow:=GesAnzMessungen, LastCol:="C")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsMaximum)
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AO=C-" &CStr(Stats.Maximum)  , TreatEmptyAsZero:=True)

				Set WksRange = Wks.Cells(Row:=1, Col:="D", LastRow:=GesAnzMessungen, LastCol:="D")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsMaximum)
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AU=D-" &CStr(Stats.Maximum), TreatEmptyAsZero:=True) ' AU für Gnd2!!
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AT=" &CStr(Stats.Maximum),  TreatEmptyAsZero:=True )
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AN=(AT-D)/4",  TreatEmptyAsZero:=True )				' AN für Anzeige DEL2
				Set WksRange = Wks.Range(Row:=1, Col:="AN", LastRow:=GesAnzMessungen, LastCol:="AN")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
				Wks.Cells(11, 27) = Stats.Maximum
				Wks.Cells(18, 27) = Stats.FirstQuartile

				Set WksRange = Wks.Cells(Row:=1, Col:="E", LastRow:=GesAnzMessungen, LastCol:="E")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsMinimum)
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AL=E-" &CStr(Stats.Minimum) , TreatEmptyAsZero:=True)
				Set WksRange = Wks.Range(Row:=1, Col:="AL", LastRow:=GesAnzMessungen, LastCol:="AL")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
				Wks.Cells(12, 27) = Stats.Maximum
				Wks.Cells(19, 27) = Stats.FirstQuartile

				Set WksRange = Wks.Cells(Row:=1, Col:="F", LastRow:=GesAnzMessungen, LastCol:="F")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsMinimum)
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AR=F-" &CStr(Stats.Minimum) , TreatEmptyAsZero:=True)
				Set WksRange = Wks.Cells(Row:=1, Col:="AR", LastRow:=GesAnzMessungen, LastCol:="AR")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
				Wks.Cells(9, 27) = Stats.Maximum
				Wks.Cells(10, 27) = Stats.FirstQuartile


			Wks.Cells(6, 27) = Wks.Cells(9, 27)
			Wks.Cells(8, 27) = Wks.Cells(10, 27)
			If Wks.Cells(6, 27) < (10*Wks.Cells(10, 27)) Then
				Wks.Cells(6, 27) = 10*Wks.Cells(10, 27)
			End If

			dlgvar.Text1 = "10"
			Wks.Cells(1, 27) = 10
			dlgvar.Text2 = "1.0"
			Wks.Cells(2, 27) = 1.0
			dlgvar.Text3 = "445"
			Wks.Cells(2, 27) = 445
			dlgvar.Text4 = "490"
			Wks.Cells(1, 27) = 490
			dlgvar.Text5 = "5"
			Wks.Cells(1, 27) = 5
			dlgvar.Text6 = Str(Wks.Cells(6, 27))
			dlgvar.Text7 = Str(Wks.Cells(8, 27))
			dlgvar.Text8 = "1"
			Wks.Cells(15, 27) = 1

			Gnd1KorrChange = 1
			Gnd2KorrChange = 1
			ClassSensChange = 1
			UpperLowerChange = 1

		Else
			Set Wks = SurferApp.Documents.Open (Data)
			dlgvar.Text1 = Str(Wks.Cells(1, 27))
			dlgvar.Text2 = Str(Wks.Cells(2, 27))
			dlgvar.Text3 = Str(Wks.Cells(3, 27))
			dlgvar.Text4 = Str(Wks.Cells(4, 27))
			dlgvar.Text5 = Str(Wks.Cells(5, 27))
			dlgvar.Text6 = Str(Wks.Cells(6, 27))
			dlgvar.Text7 = Str(Wks.Cells(8,27))
			dlgvar.Text8 = Str(Wks.Cells(15,27))
			GesAnzMessungen=Wks.Cells(7, 27)

			Gnd1KorrChange = 0
			Gnd2KorrChange = 0
			ClassSensChange = 0
			UpperLowerChange = 0
		End If

		Do
			InputOK = 1
			result = Dialog(dlgvar)
			If(result = 0) Then
				Exit Sub
			End If

			If( Val(dlgvar.Text1) < 1 Or Val(dlgvar.Text5) > 1000 ) Then
				InputOK = 0
				dlgvar.Text1 = Str(Wks.Cells(1, 27))
				Beep
			Else
				If Val(dlgvar.Text1) <> Wks.Cells(1, 27) Then
					LengthChange = 1
					Wks.Cells(1, 27) = Val(dlgvar.Text1)
				End If
			End If

			If( Val(dlgvar.Text2) < 0.1 Or Val(dlgvar.Text2) > 3 ) Then
				InputOK = 0
				dlgvar.Text2 = Str(Wks.Cells(2, 27))
				Beep
			Else
				If Val(dlgvar.Text2) <> Wks.Cells(2, 27) Then
					WidthChange = 1
					Wks.Cells(2, 27) = Val(dlgvar.Text2)
				End If
			End If

			If( (Val(dlgvar.Text3) < 0) Or (Val(dlgvar.Text3) > 0 And Val(dlgvar.Text3) < 300) Or Val(dlgvar.Text3) > 700 )	Then
				InputOK = 0
				dlgvar.Text3 = Str(Wks.Cells(3, 27))
				Beep
			Else
				If Val(dlgvar.Text3) <> Wks.Cells(3, 27) Then
					Gnd1KorrChange = 1
					Wks.Cells(3, 27) = Val(dlgvar.Text3)
				End If
			End If

			If( (Val(dlgvar.Text4) < 0) Or (Val(dlgvar.Text4) > 0 And Val(dlgvar.Text4) < 300) Or Val(dlgvar.Text4) > 700 )	Then
				InputOK = 0
				dlgvar.Text4 = Str(Wks.Cells(4, 27))
				Beep
			Else
				If Val(dlgvar.Text4) <> Wks.Cells(4, 27) Then
					Gnd2KorrChange = 1
					Wks.Cells(4, 27) = Val(dlgvar.Text4)
				End If
			End If

			If( Val(dlgvar.Text5) < 1 Or Val(dlgvar.Text5) > 10 ) Then
				InputOK = 0
				dlgvar.Text5 = Str(Wks.Cells(5, 27))
				Beep
			Else
				If Val(dlgvar.Text5) <> Wks.Cells(5, 27) Then
					ClassSensChange = 1
					Wks.Cells(5, 27) = Val(dlgvar.Text5)
				End If
			End If

			If( Val(dlgvar.Text6) < 0 Or Val(dlgvar.Text6) > 16000000 ) Then
				InputOK = 0
				dlgvar.Text6 = Str(Wks.Cells(6, 27))
				Beep
			Else
				If Val(dlgvar.Text6) <> Wks.Cells(6, 27) Then
					UpperLowerChange = 1
				End If
			End If

			If( Val(dlgvar.Text7) < 0 Or Val(dlgvar.Text7) > 16000000 ) Then
				InputOK = 0
				dlgvar.Text7 = Str(Wks.Cells(8,27))
				Beep
			Else
				If Val(dlgvar.Text7) <> Wks.Cells(8, 27) Then
					UpperLowerChange = 1
				End If
			End If

			If( Val(dlgvar.Text7) >= Val(dlgvar.Text6) ) Then
				InputOK = 0
				dlgvar.Text6 = Str(Wks.Cells(6, 27))
				dlgvar.Text7 = Str(Wks.Cells(8,27))
				Beep
			Else
				Wks.Cells(6, 27) = Val(dlgvar.Text6)
				Wks.Cells(8, 27) = Val(dlgvar.Text7)
			End If

			If( Val(dlgvar.Text8) < 0 Or Val(dlgvar.Text8) > 5 ) Then
				InputOK = 0
				dlgvar.Text8 = Str(Wks.Cells(15, 27))
				Beep
			Else
				Wks.Cells(15, 27) = Val(dlgvar.Text8)
			End If

		Loop Until InputOK = 1

			If Gnd2KorrChange = 1 Then
				If( Val(dlgvar.Text4) = 0 ) Then

					For i=0 To 200	'400
						Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AV=" &CStr(i+400 ), TreatEmptyAsZero:=True)
						Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AS=AR+((AU*AV)/500)", TreatEmptyAsZero:=True)
						Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="V=AS*-1" )
						Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="AD=fabs(V)"	)

						Set WksRange = Wks.Cells(Row:=1, Col:="AD", LastRow:=GesAnzMessungen, LastCol:="AD")
						Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
						Wks.Cells(i,35)=i
						Wks.Cells(i,36)=Stats.FirstQuartile
					Next
					Set WksRange = Wks.Cells(Row:=1, Col:="AJ", LastRow:=400, LastCol:="AJ")
					Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
					AJMin = Stats.Minimum
					For i=1 To 200
						If(Wks.Cells(i,36) = AJMin ) Then
							gnd2korr=i+400
							i=200
						End If
					Next
					Wks.Cells(4,27)=gnd2korr
				Else
					gnd2korr=Wks.Cells(4,27)
				End If

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AV=" &CStr(gnd2korr) ,TreatEmptyAsZero:=True)
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AS=AR+((AU*AV)/500)", TreatEmptyAsZero:=True)
				Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="V=fabs(AS)")
				Set WksRange = Wks.Range(Row:=1, Col:="V", LastRow:=GesAnzMessungen, LastCol:="V")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
				Wks.Cells(14, 27) = Stats.Maximum
				Wks.Cells(16, 27) = Stats.FirstQuartile
				Wks.Cells(20, 27) = Stats.Minimum
				ClassSensChange = 1
				UpperLowerChange = 1
			End If
			If Gnd1KorrChange = 1 Then
				If( Val(dlgvar.Text3) = 0 ) Then
					For i=0 To 200
						Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AX=" &CStr(i+400 ), TreatEmptyAsZero:=True)
						Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AM=AL+((AO*AX)/500)", TreatEmptyAsZero:=True)
						Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="U=fabs(AM)")

						Set WksRange = Wks.Cells(Row:=1, Col:="U", LastRow:=GesAnzMessungen, LastCol:="U")
						Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
						Wks.Cells(i,35)=i
						Wks.Cells(i,36)=Stats.FirstQuartile
					Next
					Set WksRange = Wks.Cells(Row:=1, Col:="AJ", LastRow:=400, LastCol:="AJ")
					Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
					AJMin = Stats.Minimum
					For i=1 To 200
						If(Wks.Cells(i,36) = AJMin ) Then
							gnd1korr=i+400
							i=200
						End If
					Next
					Wks.Cells(3,27)=gnd1korr
				Else
					gnd1korr=Wks.Cells(3,27)
				End If
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AX=" &CStr(gnd1korr) , TreatEmptyAsZero:=True)
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AM=AL+((AO*AX)/500)", TreatEmptyAsZero:=True)
				Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="U=fabs(AM)")
				Set WksRange = Wks.Range(Row:=1, Col:="U", LastRow:=GesAnzMessungen, LastCol:="U")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
				Wks.Cells(13, 27) = Stats.Maximum
				Wks.Cells(17, 27) = Stats.FirstQuartile
				UpperLowerChange = 1
			End If
			If Gnd1KorrChange = 1 Or Gnd2KorrChange = 1 Then
				Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="AD=fabs(AS)"	)
				ClassSensChange = 1
			End If

			If ClassSensChange = 1 Then
				nSens = Val(dlgvar.Text5)
				If nSens < 1 Then nSens = 1
				If nSens > 10 Then nSens = 10
				nFacSens = (10 - nSens)*2 + 3
				nTrackStart = 1
				i = 0
				FltGnd =Wks.Cells(1,30)
				Set WksRange = Wks.Range(Row:=1, Col:="AD", LastRow:=GesAnzMessungen, LastCol:="AD")
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsAll)
				StdDev = Stats.StandardDeviation
				FirstQ = Stats.FirstQuartile
				SMax = Stats.Maximum
				Rmax = (SMax-FirstQ)/(nSens+1) - (SMax-FirstQ)/11 + 3*FirstQ
				If Rmax < 5000 Then	'3000, 10000, 5000
					Rmax = 5000			'3000, 10000, 5000
				End If
				For i=1 To GesAnzMessungen-1
					If Wks.Cells(i,30) > (Rmax*1.15) Then
						Do
							Wks.Cells(i,33) = 1
							i = i+1
						Loop Until Wks.Cells(i,30) < (Rmax*0.85)
						Wks.Cells(i,33) = 0
					Else
						Wks.Cells(i,33) = 0
					End If
				Next
				Wks.Cells(1,33) = 0	' AG
				Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="W=0")
				ZeroDEL2 = Wks.Cells(1,4)
				ZeroDEL4 = Wks.Cells(1,6)
				For i=1 To GesAnzMessungen-1
					If  Wks.Cells(i,33) = 0 And Wks.Cells(i+1,33).Value > 0 Then
						maxi = i+1
						max = Wks.Cells(maxi,30).Value	'AD
						maxstart = max
						starti = maxi
						AktZeroDEL2 = ZeroDEL2
						AktZeroDEL4 = ZeroDEL4
						Do
							i=i+1
							actcell=Wks.Cells(i,30).Value
							If actcell > max Then
								maxi=i
								max = Wks.Cells(maxi,30).Value
							End If
						Loop Until Wks.Cells(i,33) = 0
						i=i-1
						AktMetValue = (AktZeroDEL2 - Wks.Cells(maxi,4).Value)*42/(Wks.Cells(maxi,6).Value - AktZeroDEL4)
						If AktMetValue < 4 Then AktMetValue = 4
						If AktMetValue > 99 Then AktMetValue = 99
						For n=starti To i
							Wks.Cells(n,23) = AktMetValue
						Next
					Else
						ZeroDEL2 = (ZeroDEL2*10+Wks.Cells(i,4)) / 11
						ZeroDEL4 = (ZeroDEL4*10+Wks.Cells(i,6)) / 11
					End If
				Next
			End If

			k_upper = Wks.Cells(6, 27) / Wks.Cells(9, 27)	'UpperLevel / MaxDel4
			k_lower = Wks.Cells(8, 27) / Wks.Cells(10, 27)	'LowerLevel / NoiseDel4

			Del4Lower = Wks.Cells(8, 27)
			Del4Upper = Wks.Cells(6, 27)

			Del3Lower = Wks.Cells(19, 27) * k_lower
			Del3Upper = Wks.Cells(12, 27) * k_upper
			If Del3Upper < (Del3Lower + 10*Wks.Cells(19, 27)) Then
				Del3Upper = Del3Lower + 10*Wks.Cells(19, 27)
			End If

			Del2Lower = Wks.Cells(18, 27) * k_lower
			Del2Upper = Wks.Cells(11, 27) * k_upper
			If Del2Upper < (Del2Lower + 10*Wks.Cells(18, 27)) Then
				Del2Upper = Del2Lower + 10*Wks.Cells(18, 27)
			End If

			Gnd2Lower = Wks.Cells(16, 27) * k_lower
			Gnd2Upper = Wks.Cells(14, 27) * k_upper
			If Gnd2Upper < (Gnd2Lower + 10*Wks.Cells(16, 27)) Then
				Gnd2Upper = Gnd2Lower + 10*Wks.Cells(16, 27)
			End If
			If Gnd2Upper < 20000 Then
				Gnd2Upper = 30000
			End If

'			Gnd1Lower = Gnd2Lower
			Gnd1Lower = Wks.Cells(17, 27) * k_lower
			Gnd1Upper = Wks.Cells(13, 27) * k_upper
			If Gnd1Upper < (Gnd1Lower + 10*Wks.Cells(17, 27)) Then
				Gnd1Upper = Gnd1Lower + 10*Wks.Cells(17, 27)
			End If
			If Gnd1Upper < 20000 Then
				Gnd1Upper = 30000
			End If

			If UpperLowerChange = 1 Then
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AS=AR+((AU*AV)/500)", TreatEmptyAsZero:=True)
				Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="V=fabs(AS)")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Gnd2Lower ))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MAX(AC,V)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="V=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Gnd2Upper ))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MIN(AC,V)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="V=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AM=AL+((AO*AX)/500)", TreatEmptyAsZero:=True)
				Wks.Transform(FirstRow:=1, LastRow:=GesAnzMessungen, Equation:="U=fabs(AM)")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Gnd1Lower ) )
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MAX(AC,U)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="U=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Gnd1Upper ))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MIN(AC,U)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="U=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Del2Lower ))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MAX(AC,AN)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="X=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Del2Upper ))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MIN(AC,X)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="X=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Del3Lower ))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MAX(AC,AL)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="Y=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Del3Upper ))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MIN(AC,Y)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="Y=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Del4Lower))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MAX(AC,AR)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="Z=AB")

				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AC=" &Str$( Del4Upper))
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="AB=MIN(AC,Z)")
				Wks.Transform2(TransformType:=wksTransformWithCol, RangeMin:=1, RangeMax:=GesAnzMessungen, Equation:="Z=AB")
			End If

			Data=Left$( Data, Index2 )+"TXT"
			Wks.SaveAs( Data,,srfSaveFormatText )

			PosLat$=Trim(Str(Wks.Cells(1,10)))
			PosNorth$=Trim(Str(Wks.Cells(1,11)))
			PosIndex = InStrRev(PosLat, ".")
			PosLatGrad$ = Mid$(PosLat, 1, PosIndex-3 )
			PosLatMin$ = Mid$(PosLat,PosIndex-2, 2 )
			PosLatFracMin$ = Right$(PosLat, Len(PosLat)-PosIndex)
			DivMask$ = "100000"
			PosDiv$ = Left$( DivMask, Len(PosLatFracMin)+1 )
			PosSeconds = Val(PosLatFracMin)*60/Val(PosDiv)
			PosLatSec$ = Format(PosSeconds, "00.00" )
			PosLat$ = PosLatGrad+Chr(176)+PosLatMin+Chr(180)+PosLatSec+Chr(34)+" "+PosNorth
			PosLon$=Trim(Str(Wks.Cells(1,12)))
			PosEast$=Trim(Str(Wks.Cells(1,13)))
			PosIndex = InStrRev(PosLon, ".")
			PosLonGrad$ = Mid$(PosLon, 1, PosIndex-3 )
			PosLonMin$ = Mid$(PosLon,PosIndex-2, 2 )
			PosLonFracMin$ = Right$(PosLon, Len(PosLon)-PosIndex)
			DivMask$ = "100000"
			PosDiv$ = Left$( DivMask, Len(PosLonFracMin)+1 )
			PosSeconds = Val(PosLonFracMin)*60/Val(PosDiv)
			PosLonSec$ = Format(PosSeconds, "00.00" )
			PosLon$ = PosLonGrad+Chr(176)+PosLonMin+Chr(180)+PosLonSec+Chr(34)+" "+PosEast

			For i=0 To 5 Step 1
				Set WksRange = Wks.Columns(Col1:=Reihenfolge(i))
				Set Stats = WksRange.Statistics(Sample:=True, Header:=True, Flags:=wksStatsRange)
				If Stats.Range = 0 Then
					ErrorText( i ) = 1
				End If
			Next

			SurferApp.Visible = True

			Set Doc1 = SurferApp.Documents.Add
			Set Plotwindow = Doc1.Windows(1)
			Plotwindow.AutoRedraw = True
			SurferApp.WindowState = srfWindowStateMaximized
			Windows.Arrange(ArrangeType:=srfTileVert)
			Plotwindow.Zoom(srfZoomPage)
			Path = Left$(Data, Index1)
			For i = 0 To 5 Step 1
			  	zColumn = Reihenfolge(i)
		  		If ErrorText( i ) = 1 Then zColumn = 99
			    If zColumn <> 99 Then
					If zColumn = 23 Then
						retValue = SurferApp.GridData(DataFile:=Data, Algorithm:=srfNearestNeighbor, _
												  ShowReport:=False, OutGrid:=GridFile(i), zCol:=zColumn )
					Else
						If Val(dlgvar.Text8) <> 0 Then
							retValue = SurferApp.GridData(DataFile:=Data, Algorithm:=srfKriging, _
									  			  ShowReport:=False, OutGrid:="C:\out.grd", zCol:=zColumn )
							status = SurferApp.GridFilter( "C:\out.grd", srfFilter9PixelAvg, NumPasses:=Val(dlgvar.Text8), OutGrid:=GridFile(i))
						Else
							retValue = SurferApp.GridData(DataFile:=Data, Algorithm:=srfKriging, _
									  			  ShowReport:=False, OutGrid:=GridFile(i), zCol:=zColumn )
						End If
					End If

					Set Grid = SurferApp.NewGrid
					Grid.LoadFile(GridFile(i), False)
					SurferApp.GridTransform(InGrid:=GridFile(i), Operation:=srfGridTransScale, xScale:=Wks.Cells(2, 27)*0.1, yScale:=Wks.Cells(1, 27)/Grid.yMax, _
										OutGrid:=GridFile(i), OutFmt:=srfGridFmtS7)

					Set Map = Doc1.Shapes.AddImageMap(GridFile(i))
					Set ImageMap = Map.Overlays(1)

					ImageMap.ColorMap.LoadFile(FileName:=SurferApp.Path+"\ColorScales\Rainbow.clr")
					ImageMap.HillShading = False

					If zColumn = 23 Then
						ImageMap.InterpolatePixels = False
						ImageMap.ColorMap.SetDataLimits( 0, 99 )

						If VName$ = "12" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 2.46
							ImageMap.ColorScale.Top = 3.4
							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, "99")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , "0")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If
						If VName$ = "13" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 2.46
							ImageMap.ColorScale.Top = 3.4
							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, "99")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , "0")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If
					Else
						ImageMap.InterpolatePixels = True
					End If

					If zColumn = 22 Then
						DiffGnd = Gnd2Upper - Gnd2Lower
						ImageMap.ColorMap.SetDataLimits( Gnd2Lower, Gnd2Lower + DiffGnd )	'DiffGnd
					End If

					If zColumn = 21 Then
						ImageMap.ColorMap.SetDataLimits( Gnd1Lower, Gnd1Upper )	'DiffGnd
					End If

					If zColumn = 26 Then
						Diff = Del4Upper - Del4Lower
						ImageMap.ColorMap.SetDataLimits( Del4Lower, Del4Lower + Diff )
					End If

					If zColumn = 25 Then
						ImageMap.ColorMap.SetDataLimits( Del3Lower, Del3Lower + Diff )
					End If

					If zColumn = 24 Then
						ImageMap.ColorMap.SetDataLimits( Del2Lower, Del2Lower + Diff )

						If VName$ = "13" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Top = 9.85-1.5
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 5.6

							ColorScaleTop = ImageMap.ColorScale.Top
							ColorScaleHeight = ImageMap.ColorScale.Height

							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, Str(Wks.Cells(6, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABaseline
							If Wks.Cells(9, 27) < Del4Upper Then
								Offset = ImageMap.ColorScale.Height * (Wks.Cells(9, 27)-Wks.Cells(8, 27))/(Del4Upper-Wks.Cells(8, 27))
								Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height + Offset, "----")
								MapTitle2.Font.HAlign = srfTARight
								MapTitle2.Font.VAlign = srfTABottom
							End If

							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , Str(Wks.Cells(8, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If

						If VName$ = "12" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Top = 9.85
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 5.6

							ColorScaleTop = ImageMap.ColorScale.Top
							ColorScaleHeight = ImageMap.ColorScale.Height

							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, Str(Wks.Cells(6, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABaseline

							If Wks.Cells(9, 27) < Del4Upper Then
								Offset = ImageMap.ColorScale.Height * (Wks.Cells(9, 27)-Wks.Cells(8, 27))/(Del4Upper-Wks.Cells(8, 27))
								Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height + Offset, "----")
								MapTitle2.Font.HAlign = srfTARight
								MapTitle2.Font.VAlign = srfTABottom
							End If

							Set MapTitle2 = Doc1.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , Str(Wks.Cells(8, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If
					End If

					xLen = Grid.xMax/10 * Wks.Cells(2, 27)
					yLen = Wks.Cells(1, 27)

					If xLen > yLen Then
						Map.Width = 3
						Map.Height= 3*yLen/xLen
					Else
						Map.Width = 3*xLen/yLen
						Map.Height= 3
					End If

					Map.Left = 0.75 + (i Mod 2) * (3 + .5)
					Map.Top = 10.0 - Int(i / 2) * (3.0 + .3) + 0.25
					If i=1 Then
						DimLeft = Map.Left
						DimTop = Map.Top
						Set MapTitle2 = Doc1.Shapes.AddText(Map.Left + 1.6, Map.Top + .2, "Gnd2-Correction "& Str(Wks.Cells(4, 27)))
					End If
					If i=3 Then
						Set MapTitle2 = Doc1.Shapes.AddText(Map.Left + 1.6, Map.Top + .2, "Gnd1-Correction "  & Str(Wks.Cells(3, 27)))
					End If
					If i=5 Then
						Set MapTitle2 = Doc1.Shapes.AddText(Map.Left + 1.7, Map.Top + .2, "Metal Class. Sens. " & Str(Wks.Cells(5, 27)))
					End If
					Set MapTitle2 = Doc1.Shapes.AddText(Map.Left + .25, Map.Top + .2, MethodLabel(i))
					Set MapTitle3 = Doc1.Shapes.AddText(Map.Left + Map.Width + 0.15 , Map.Top - Map.Height + 0.2, "[m]" )
					Set MapTitle3 = Doc1.Shapes.AddText(Map.Left - .25, Map.Top, "[m]" )
				Else
					Set MapTitle2 = Doc1.Shapes.AddText(5.85, Map.Top + .2, "Metal Class. Sens. " & Str(Wks.Cells(5, 27)))
					Set MapTitle2 = Doc1.Shapes.AddText(0.75 + (i Mod 2) * (3 + .5) + .25, Map.Top + .2, MethodLabel(i))
					Set MapTitle2 = Doc1.Shapes.AddText(0.75 + (i Mod 2) * (3 + .5) + .25, 10.0 - Int(i / 2) * (3.0 + .3) + 0.25 - .5, "Signal intensity too low for classification !")
					Set MapTitle2 = Doc1.Shapes.AddText(0.75 + (i Mod 2) * (3 + .5) + .25, 10.0 - Int(i / 2) * (3.0 + .3) - .5, "Increase Metal Class. Sens.")
				End If
			Next

			Set MapTitle1 = Doc1.Shapes.AddText(4.5, 0.5, "Field Properties: "+FName$+"  Signal Max.: "+Str(Wks.Cells(9, 27))+"  Signal Noise: "+Str(Wks.Cells(10, 27))+"  Pos 0/0: "+PosLat+"  "+PosLon )
			MapTitle1.Font.HAlign = srfTACenter
			Plotwindow.AutoRedraw = True

			Set Doc2 = SurferApp.Documents.Add

			Windows.Arrange(ArrangeType:=srfTileVert)
			Count = Windows.Count
			Set Plotwindow = Doc2.Windows(1)
			Plotwindow.Zoom(srfZoomPage)
			For i = 1 To Count Step 1
				Windows(i).Zoom(srfZoomPage)
			Next
			Plotwindow.AutoRedraw = True
			For i = 0 To 5 Step 1
		    	zColumn = Reihenfolge(i)
		   	  	If ErrorText( i ) = 1 Then zColumn = 99
			    If zColumn <> 99 Then
					Set Map = Doc2.Shapes.AddSurface(GridFile(i))
					Set ImageMap = Map.Overlays(1)
					ImageMap.UpperColorMap.LoadFile(SurferApp.Path+"\ColorScales\Rainbow.clr")

					If zColumn = 23 Then
						Map.zMapPerPU = 50
						ImageMap.UpperColorMap.SetDataLimits( 0, 99 )


						If VName$ = "12" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 2.46
							ImageMap.ColorScale.Top = 3.4
							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, "99")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , "0")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If
						If VName$ = "13" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 2.46
							ImageMap.ColorScale.Top = 3.4
							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, "99")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , "0")
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If
					End If

					If zColumn = 22 Then
						ImageMap.UpperColorMap.SetDataLimits( Gnd2Lower, Gnd2Lower + DiffGnd )	'DiffGnd
						zScaleGnd = DiffGnd / 2.0	'DiffGnd
						Map.zMapPerPU = zScaleGnd
					End If

					If zColumn = 21 Then
'						Map.zMapPerPU = zScaleGnd

						Map.zMapPerPU = (Gnd1Upper - Gnd1Lower) / 2.0
						ImageMap.UpperColorMap.SetDataLimits( Gnd1Lower, Gnd1Upper )	'DiffGnd
					End If

					If zColumn = 26 Then
						ImageMap.UpperColorMap.SetDataLimits( Del4Lower, Del4Lower + Diff )
						zScale = Diff / 2.0
						Map.zMapPerPU = zScale
					End If

					If zColumn = 24 Then
						ImageMap.UpperColorMap.SetDataLimits( Del2Lower, Del2Lower + Diff )
						Map.zMapPerPU = zScale
					End If

					If zColumn = 25 Then
						ImageMap.UpperColorMap.SetDataLimits(Del3Lower, Del3Lower + Diff )
						Map.zMapPerPU = zScale


						If VName$ = "13" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Top = 9.85-1.5
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 5.6

							ColorScaleTop = ImageMap.ColorScale.Top
							ColorScaleHeight = ImageMap.ColorScale.Height

							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, Str(Wks.Cells(6, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABaseline
							If Wks.Cells(9, 27) < Del4Upper Then
								Offset = ImageMap.ColorScale.Height * (Wks.Cells(9, 27)-Wks.Cells(8, 27))/(Del4Upper-Wks.Cells(8, 27))
								Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height + Offset, "----")
								MapTitle2.Font.HAlign = srfTARight
								MapTitle2.Font.VAlign = srfTABottom
							End If

							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , Str(Wks.Cells(8, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If

						If VName$ = "12" Then
							ImageMap.ShowColorScale = True
							ImageMap.ColorScale.LabelFont.Color = srfColorWhite
							ImageMap.ColorScale.LabelFont.Size = 2
							ImageMap.ColorScale.FrameLine.ForeColorRGBA.Color = srfColorWhite
							ImageMap.ColorScale.Rotation = 0
							ImageMap.ColorScale.Top = 9.85
							ImageMap.ColorScale.Left = 7.9
							ImageMap.ColorScale.Width = 0.2
							ImageMap.ColorScale.Height = 5.6

							ColorScaleTop = ImageMap.ColorScale.Top
							ColorScaleHeight = ImageMap.ColorScale.Height

							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top+1/16, Str(Wks.Cells(6, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABaseline

							If Wks.Cells(9, 27) < Del4Upper Then
								Offset = ImageMap.ColorScale.Height * (Wks.Cells(9, 27)-Wks.Cells(8, 27))/(Del4Upper-Wks.Cells(8, 27))
								Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height + Offset, "----")
								MapTitle2.Font.HAlign = srfTARight
								MapTitle2.Font.VAlign = srfTABottom
							End If

							Set MapTitle2 = Doc2.Shapes.AddText(ImageMap.ColorScale.Left+0.2, ImageMap.ColorScale.Top - ImageMap.ColorScale.Height - 0.25 , Str(Wks.Cells(8, 27)))
							MapTitle2.Font.HAlign = srfTARight
							MapTitle2.Font.VAlign = srfTABottom
						End If
					End If

					xLen = Grid.xMax / 10 * Wks.Cells(2, 27)
					yLen = Wks.Cells(1, 27)

					If xLen > yLen Then
						Map.Width = 3
						Map.Height= 3*yLen/xLen
					Else
						Map.Width = 3*xLen/yLen
						Map.Height= 3
					End If
					Map.Left = 0.75 + (i Mod 2) * (3 + .5)
					Map.Top = 10.0 - Int(i / 2) * (3.0 + .3) + 0.25
					If i=1 Then
						Set MapTitle2 = Doc2.Shapes.AddText(Map.Left + 1.6, Map.Top + .2, "Gnd2-Correction "& Str(Wks.Cells(4, 27)))
					End If
					If i=3 Then
						Set MapTitle2 = Doc2.Shapes.AddText(Map.Left + 1.6, Map.Top + .2, "Gnd1-Correction "  & Str(Wks.Cells(3, 27)))
					End If
					If i=5 Then
						Set MapTitle2 = Doc2.Shapes.AddText(Map.Left + 1.7, Map.Top + .2, "Metal Class. Sens. " & Str(Wks.Cells(5, 27)))
					End If

					Set MapTitle2 = Doc2.Shapes.AddText(Map.Left + .25, Map.Top + .2, MethodLabel(i))
				Else
					Set MapTitle2 = Doc2.Shapes.AddText(5.85, Map.Top + .2, "Metal Class. Sens. " & Str(Wks.Cells(5, 27)))
					Set MapTitle2 = Doc2.Shapes.AddText(0.75 + (i Mod 2) * (3 + .5) + .25, Map.Top + .2, MethodLabel(i))
					Set MapTitle2 = Doc2.Shapes.AddText(0.75 + (i Mod 2) * (3 + .5) + .25, 10.0 - Int(i / 2) * (3.0 + .3) + 0.25 - .5, "Signal intensity too low for classification !")
					Set MapTitle2 = Doc2.Shapes.AddText(0.75 + (i Mod 2) * (3 + .5) + .25, 10.0 - Int(i / 2) * (3.0 + .3) - .5, "Increase Metal Class. Sens.")
				End If
			Next
			Set MapTitle1 = Doc2.Shapes.AddText(4.5, 0.5, "Field Properties: "+FName$+"  Signal Max.: "+Str(Wks.Cells(9, 27))+"  Signal Noise: "+Str(Wks.Cells(10, 27))+"  Pos 0/0: "+PosLat+"  "+PosLon )

			MapTitle1.Font.HAlign = srfTACenter

			Plotwindow.AutoRedraw = True
			SurferApp.Visible = True
			Wks.Close
			Windows.Arrange(ArrangeType:=srfTileVert)
			Count = Windows.Count
			For i = 1 To Count Step 1
				Windows(i).Zoom(srfZoomPage)
			Next

End Sub

