//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "math.h"
#include <iomanip>
#include "stdio.h"
#include <vector>  //2022-2-4
#include "ctime.h"  //2022-2-4
#include <fstream>  //2022-2-4
#include "assert.h" //2022-2-4
#include "io.h"     //2022-2-4
#include <windows.h>
#include "Unit3.h"
#include "Unit4.h"
#include <cstring>
#include <algorithm>
#include <Dialogs.hpp>
#include "string.h"
#include "iostream.h"
#include "stdlib.h"
#include "ctype.h"
#include "conio.h"
#include "Unit5.h"
#include "Unit6.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define N 1100
TForm1 *Form1;
TForm4 *Form4;
using namespace std;
//using System.dll;
//using System.IO;
int index=1000,index1;
 float data[50000][50],data1[50000][50];
AnsiString Save_Name;

        AnsiString Well_Name_1;
        AnsiString Well_Name_2;
        AnsiString Well_Name_1_path;
        AnsiString Well_Name_2_path;

        AnsiString old_order[20];
        AnsiString new_order[20];
        //
        float data_01[50000][20];
        float data_02[50000][20];
        String jh[100];
        int LA_count1 = 0;
        int LA_count2 = 0;
        int old_count = 0;
        //
        String jhw[1000];
        float xcw[1000];
        float first_distance = 0;
        float SentResult[200];
        float SentResult2[200];
        String FinUnitName[200];
float FinDepth[200];
String DBF055;
String DBF055_Name;
String DBF055_NEW;
int DataBase = 0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
MOD = 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GetFileName(String str)
{
  Integer i;
 String x,y;
 x=ExtractFileName(str);  //取文件名+扩展名，不包含文件路径
  y=ExtractFileExt(str);   //取文件的扩展名
//  i=Pos(y,x);              //确定扩展名所在位置
//  str=Copy(x,0,i-1);  //复制文件名，忽略掉后面的扩展名
//ChangeFileExt(const AnsiString FileName, const AnsiString Extension);
  str=ChangeFileExt(x,"S11.dat"); //更换扩展名
  newname=str;
 //  PaintBox2->Canvas->TextOutA(20,200,newname);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LA1Click(TObject *Sender)
{
    short i1,i2;float f;
   Top_deep=0.0;
   int flag,i3;

 FILE *fp;
 // int Rd_valueGTzero=0;
//  int RMN_valueGTzero=0;
 // int AC_value=0;
     MN_pos=0;
     MK_pos=0;
     Rd_pos=0;
     Rs_pos=0;
     Ac_pos=0;
     Rxo_pos=0;
     GR_pos=0;
     SP_pos=0;
     DEN_pos=0;
     R25_pos=0;
  int line6[6];
 OpenDialog1->Filter="测井数据文件la(*.la)|*.la|LA文件（LA*)|LA*|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute()){
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fp=fopen(OpenDialog1->Files->Strings[I].c_str(),"rb");
   cc1=OpenDialog1->Files->Strings[I].c_str();
    ccp=ExtractFileName(OpenDialog1->FileName);
    //CCP1 = ccp;
   // GetFileName(ccp);// PaintBox2->Canvas->TextOutA(50,350,ccp);
 if(fp){
 fread(str0,84,1,fp);
 fread(str1,80,1,fp);
 i2=getint(fp);
 i1=getint(fp);
 fread(str,80,1,fp);
//startdp
 stdp=getfloat(fp);
//endp
 endp=getfloat(fp);
//cyjj
 relv=getfloat(fp);
 i1=getint(fp);
 i2=getint(fp);
 f=getfloat(fp);
 fread(str11,80,1,fp);
 fread(str3,148,1,fp);
 for(int i7=0;i7<int(Top_deep/relv);i7++)
 {
  for(int j7=1;j7<41;j7++)
  {
   a[i7][j7]=1.0;
   data[i7][j7]=1.0;
   }
  }
   stdp=stdp-Top_deep;
 i1=0+int(Top_deep/relv);
 stedp=int((endp-stdp)/relv);
while(i1<stedp)
 {
  for(int j=1;j<41;j++)
  {
  for(int i=i1;i<i1+62;i++)
  {
   a[i][j]=getfloat(fp);
   if(fabs(a[i][j])>999.0)
   {
      a[i][j]=999.0;
   }
   data[i][j]=a[i][j];
   }
   }
  i1=i1+62;
  }
 }
 }
 }
 for(int i=0;i<3;i++)
    {
         for(int j=0;j<4;j++)
            {
             temp_index[i][j]=-1;
             }
          }
 for(int i0=0;i0<stedp;i0++)
  {
   a[i0][0]=stdp+i0*relv;
   data[i0][0]=stdp+i0*relv;
   }
  int i4,i,j,ip;
 cname3[0][5]="DEPT ";
 i4=1;
 for(i=0;i<80;i+=4)
 {
  i2=0;
  for(j=i;j<i+4;j++)
  {
   if(str[j]!=' ')i2++;
   }
   j=i;
  for(i3=0;i3<4;i3++)
   str2[i3]=0;
  for(i3=0;i3<i2;i3++)
  {
   str2[i3]=str[j];
   j++;
   }
   if((str2[0]!=' ')&&(str2[0]!='\0'))
   {
     cname3[i4][5]=str2;
     if(strcmp(str2,"RMN")==0||strcmp(str2,"MNOR")==0)
         {
             MN_pos=i4;
             line6[0]=i4;
             temp_index[0][0]=i4;
         }
         if(strcmp(str2,"RML")==0||strcmp(str2,"RMK")==0||strcmp(str2,"RMM")==0||strcmp(str2,"RMG")==0)
         {
             MK_pos=i4;
             temp_index[1][0]=i4;
         }
         if(strcmp(str2,"RLLD")==0||strcmp(str2,"RL3D")==0||strcmp(str2,"LLD")==0)
         {
             Rd_pos=i4;
             line6[1]=i4;
             temp_index[0][1]=i4;
         }
         if(strcmp(str2,"RLLS")==0||strcmp(str2,"RL3S")==0||strcmp(str2,"LLS")==0)
         {
             Rs_pos=i4;
             temp_index[1][1]=i4;
         }
         if(strcmp(str2,"AC")==0||strcmp(str2,"DT")==0)
         {
             Ac_pos=i4;
             temp_index[0][3]=i4;
         }
         if(strcmp(str2,"MSFL")==0||strcmp(str2,"RXO")==0)
         {
             Rxo_pos=i4;
             line6[2]=i4;
             temp_index[2][1]=i4;
         }
         if(strcmp(str2,"GR")==0)
         {
             GR_pos=i4;
             line6[3]=i4;
             temp_index[0][2]=i4;
         }
         if(strcmp(str2,"SP")==0)
         {
             SP_pos=i4;
             temp_index[1][2]=i4;
         }
         if(strcmp(str2,"R25")==0||strcmp(str2,"R250")==0||strcmp(str2,"R2.5")==0)
         {
             R25_pos=i4;
             temp_index[2][2]=i4;
         }
         if(strcmp(str2,"DEN")==0)
         {
             DEN_pos=i4;
             line6[4]=i4;
             temp_index[1][3]=i4;
         }
        if(strcmp(str2,"HAC")==0)
         {
             HAC_pos=i4;
             line6[5]=i4;
             temp_index[2][3]=i4;
         }
     i4++;
     }
   }

 stedp=int((endp-stdp)/relv);

  //---------------------------------------------------------
 ip=i4;
 i4=i4-1;
 for(int i0=1;i0<(ip+1);i0++)
  {
   smaxmin(i0);
   ma[i0]=max;
   mi[i0]=min;
   }

///////////////////////////////////////////////////////////////////
    int start = 0;
    int end = 0;
   for(int i = 0;i < 50000;i ++)
   {
        if(data[i][line6[0]] * data[i][line6[1]] * data[i][line6[2]] * data[i][line6[3]] * data[i][line6[4]] * data[i][line6[5]] == 0)
        {
                start = i;
        }
        else
        {
            int temp = 0;
            for(int j = 0;j < 6;j ++)
            {
                if(data[i][line6[j]] < -2000)
                {
                        temp = 1;
                }
            }
            if(temp == 1)
            {
                start = i;
                continue;

            }
            else
                break;
        }

   }
   for(int i = 49999;i > start;i --)
   {
        if(data[i][line6[0]] * data[i][line6[1]] * data[i][line6[2]] * data[i][line6[3]] * data[i][line6[4]] * data[i][line6[5]] == 0)
                end = i;
        else
                break;
   }

  // int temp = 0;
   for(int i = start;i < end + 1;i ++)
   {
        for(int j = 0;j < 50;j ++)
        {
                a[i - start][j] = a[i][j];
                data[i - start][j] = data[i][j];
        }
   }
    endp = a[end - start][0];
    stdp = a[0][0];
    stedp = end - start;



   draw(temp_index,tracknum,data,stedp,stdp,relv);
   onpaint_switch=0;
   painthead(Sender);
   Form1->Caption=cc1+"                                            采 油 二 厂 储 层 自 动 对 比 技 术";
 //  paintdepth(stdp,stedp,relv);
   //StatusBar1->Panels->Items[0]->Text="LA文件名："+cc;

   fclose(fp); // PaintBox2->Canvas->TextOutA(50,400,newname);
}
//---------------------------------------------------------------------------
__fastcall TForm1::getint(FILE *fp)
{

 char *s;short i;
 (short *)s=&i;
 s[1]=getc(fp);s[0]=getc(fp);
 return(i);
 }
//---------------------------------------------------------------------------
float __fastcall TForm1::getfloat(FILE *fp)
{
 char *s;float f;
 (float *)s=&f;
 s[3]=getc(fp);s[2]=getc(fp);s[1]=getc(fp);s[0]=getc(fp);
 return(f);
 }
//---------------------------------------------------------------------------
__fastcall TForm1::putint(short ii,FILE *fp)
{

 char *s;
 (short *)s=&ii;
 putc(s[1],fp);putc(s[0],fp);
  }
//---------------------------------------------------------------------------
__fastcall TForm1::putfloat(float ff,FILE *fp)
{
 char *s;
 (float *)s=&ff;
 putc(s[3],fp);putc(s[2],fp);putc(s[1],fp);putc(s[0],fp);
 }
//---------------------------------------------------------------------------
void __fastcall TForm1::smaxmin(int i0)
{
 float ma0[50000],min0;
 int i9,ij=0;
 Top_deep=0.0;
 i9=int(Top_deep/relv);
 for(int l=i9+10;l<stedp;l++)
 {
  ma0[ij]=data[l][i0]; ij++;
  }
 for(int l=100;l<ij-101;l++)
 {
  for(int k=l+1;k<ij-100;k++)
  {
   if(ma0[l]>ma0[k])
   {
    min0=ma0[l];
    ma0[l]=ma0[k];
    ma0[k]=min0;
   }
  }
 }
   int i1=0;
   while((ma0[i1]<0.001)&&(ma0[i1]>-0.001))
    {
    i1++;
    }
    if(i1<ij-20)
    {
     min=int(ma0[i1]);
     max=int(ma0[ij-101])+1;
    }
}
//-------------------------------------------------------------------------
void __fastcall TForm1::paintdepth(float stdp0,int stedp0,float relv0)
{
 int deep,deep1,deep2,ip,ip1,sti,linelength=20;
  {
 PaintBox2->Top=-ScrollBox2->VertScrollBar->Position;

 stdp0=stdp0+ScrollBox2->VertScrollBar->Position*relv0;

 PaintBox2->Canvas->Pen->Color=clBlack;
 PaintBox2->Canvas->Pen->Style=psSolid;
 PaintBox2->Canvas->MoveTo(linelength,0);
 PaintBox2->Canvas->LineTo(linelength,PaintBox2->Height);
 ip=(int)(stdp0*10);
 ip1=(int)(ip/2);
 if(ip1*2==ip)
 {
  sti=0;
  }
  else
  {
   ip=(int)((stdp0+relv0)*10);
   ip1=(int)(ip/2);
   if(ip1*2==ip)
   {
    sti=1;
    }
    else
    {
    sti=2;
    }
    }
 deep=int(stdp0/100.);
 deep=deep*100;
 deep2=int(stdp0/2.);
 deep2=deep2*2;
 PaintBox2->Canvas->MoveTo(linelength+0,0);
 PaintBox2->Canvas->LineTo(linelength+5,0);
 for(int i0=sti;i0<stedp0;i0+=4)
 {
  deep1=int(stdp0+i0*relv0);
  if(deep1==(deep2+2))
  {
   PaintBox2->Canvas->MoveTo(linelength,i0);
   PaintBox2->Canvas->LineTo(linelength+10,i0);
   PaintBox2->Canvas->TextOut(linelength+14,i0-5,AnsiString(deep2+2));
   deep2=deep2+2;
  }
   else
   {
    PaintBox2->Canvas->MoveTo(linelength+0,i0);
    PaintBox2->Canvas->LineTo(linelength+5,i0);
    }
   }
  }

 }
//---------------------------------------------------------------------------------
void __fastcall TForm1::painthead(TObject *Sender)
{
  tracknum=2;Name_Height=113;index=1000;relv=0.05;
 trackwidth=Form1->Width/(tracknum*(4+1.5));
  PaintBox1->Width=2+100+trackwidth*5+3;
  PaintBox1->Canvas->Pen->Color=clGreen;
  PaintBox1->Canvas->Pen->Width=2;
  PaintBox1->Canvas->MoveTo(2,2);
  PaintBox1->Canvas->LineTo(2,PaintBox1->Height);
  PaintBox1->Canvas->LineTo(2+100+trackwidth*5,PaintBox1->Height);
  PaintBox1->Canvas->LineTo(2+100+trackwidth*5,2);
  PaintBox1->Canvas->LineTo(2,2);
  PaintBox1->Canvas->MoveTo(2+50,2);
  PaintBox1->Canvas->LineTo(2+50,PaintBox1->Height);
  PaintBox1->Canvas->MoveTo(12,PaintBox1->Height/2-20);
  PaintBox1->Canvas->TextOutA(12,PaintBox1->Height/2-20,"Depth");
  PaintBox1->Canvas->TextOutA(12+120+trackwidth*4,PaintBox1->Height/2-20,"Inter_Result");
  // PaintBox1->Canvas->TextOutA(100+trackwidth*4,PaintBox1->Height/2,cc1);
     for(int i=0;i<2;i++)
     {
        PaintBox1->Canvas->Pen->Style=psSolid;
        PaintBox1->Canvas->Pen->Color=clBlack;
        PaintBox1->Canvas->Pen->Width=2;
        PaintBox1->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(i*1)+50,0);
        PaintBox1->Canvas->LineTo(2+trackwidth*1.2+(trackwidth)*(i*1)+50,index);
     }
     for(int i=2;i<4;i++)
     {
        PaintBox1->Canvas->Pen->Style=psSolid;
        PaintBox1->Canvas->Pen->Color=clBlack;
        PaintBox1->Canvas->Pen->Width=2;
        if(i==3)
        {
         PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+42,0);
         PaintBox1->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+42,index);
         }
         else
         {
          PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+50,0);
          PaintBox1->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+50,index);
          }

     }
       PaintBox1->Canvas->Pen->Width=1;
     PaintBox1->Canvas->Pen->Style=psSolid;
     PaintBox1->Canvas->Pen->Color=clBlack;
     PaintBox1->Canvas->TextOutA(2+trackwidth/2.5,PaintBox1->Height/3-15,"0");
     PaintBox1->Canvas->TextOutA(2+trackwidth/2.5+trackwidth/2,PaintBox1->Height/3-15,"RMN");
     PaintBox1->Canvas->TextOutA(2+trackwidth/2.5+trackwidth,PaintBox1->Height/3-15,"25");
     PaintBox1->Canvas->MoveTo(2+trackwidth/3,PaintBox1->Height/3);
     PaintBox1->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(0*1)+trackwidth/3,PaintBox1->Height/3);
          PaintBox1->Canvas->Pen->Style=psDash;
     PaintBox1->Canvas->Pen->Color=clBlue;
     PaintBox1->Canvas->Font->Color=clBlue;
     PaintBox1->Canvas->TextOutA(2+trackwidth/2.5,PaintBox1->Height/3*2-15,"0");
     PaintBox1->Canvas->TextOutA(2+trackwidth/2.5+trackwidth/2,PaintBox1->Height/3*2-15,"RML");
     PaintBox1->Canvas->TextOutA(2+trackwidth/2.5+trackwidth,PaintBox1->Height/3*2-15,"25");
     PaintBox1->Canvas->MoveTo(2+trackwidth/3,PaintBox1->Height/3*2);
     PaintBox1->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(0*1)+trackwidth/3,PaintBox1->Height/3*2);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     //end first trace
     //second trace
     PaintBox1->Canvas->Pen->Style=psDash;
     PaintBox1->Canvas->Pen->Color=clBlue;
     PaintBox1->Canvas->Font->Color=clBlue;
     PaintBox1->Canvas->TextOutA(2+1.6*trackwidth+trackwidth*0,PaintBox1->Height/4-15,"0");
     PaintBox1->Canvas->TextOutA(2+1.4*trackwidth+trackwidth/2,PaintBox1->Height/4-15,"RLLD");
     PaintBox1->Canvas->TextOutA(2+2*trackwidth+trackwidth/3,PaintBox1->Height/4-15,"120");
     PaintBox1->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(0*1)+trackwidth/3,PaintBox1->Height/4);
     PaintBox1->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(1*1)+trackwidth/3,PaintBox1->Height/4);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     PaintBox1->Canvas->Pen->Style=psDot;
     PaintBox1->Canvas->Pen->Color=clRed;
     PaintBox1->Canvas->Font->Color=clRed;
     PaintBox1->Canvas->TextOutA(2+1.6*trackwidth+trackwidth*0,PaintBox1->Height/4*2-15,"0");
     PaintBox1->Canvas->TextOutA(2+1.4*trackwidth+trackwidth/2,PaintBox1->Height/4*2-15,"RLLS");
     PaintBox1->Canvas->TextOutA(2+2*trackwidth+trackwidth/3,PaintBox1->Height/4*2-15,"120");
     PaintBox1->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(0*1)+trackwidth/3,PaintBox1->Height/4*2);
     PaintBox1->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(1*1)+trackwidth/3,PaintBox1->Height/4*2);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     PaintBox1->Canvas->Pen->Style=psSolid;
     PaintBox1->Canvas->Pen->Color=clBlack;
     PaintBox1->Canvas->Font->Color=clBlack;
     PaintBox1->Canvas->TextOutA(2+1.6*trackwidth+trackwidth*0,PaintBox1->Height/4*3-15,"0");
     PaintBox1->Canvas->TextOutA(2+1.4*trackwidth+trackwidth/2,PaintBox1->Height/4*3-15,"MSFL");
     PaintBox1->Canvas->TextOutA(2+2*trackwidth+trackwidth/3,PaintBox1->Height/4*3-15,"120");
     PaintBox1->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(0*1)+trackwidth/3,PaintBox1->Height/4*3);
     PaintBox1->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(1*1)+trackwidth/3,PaintBox1->Height/4*3);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     //end second trace
     //third trace
     PaintBox1->Canvas->Pen->Style=psSolid;
     PaintBox1->Canvas->Pen->Color=clBlack;
     PaintBox1->Canvas->Font->Color=clBlack;
     PaintBox1->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*2,PaintBox1->Height/3-15,"20");
     PaintBox1->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*2,PaintBox1->Height/3-15,"GR");
     PaintBox1->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*2,PaintBox1->Height/3-15,"150");
     PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(1*1.2)+trackwidth/3,PaintBox1->Height/3);
     PaintBox1->Canvas->LineTo(2+trackwidth+(trackwidth)*(2*1.0)+trackwidth/3,PaintBox1->Height/3);
     PaintBox1->Canvas->Pen->Style=psDot;
     PaintBox1->Canvas->Pen->Color=clRed;
     PaintBox1->Canvas->Font->Color=clRed;
     PaintBox1->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*2,PaintBox1->Height/3*2-15,"-50");
     PaintBox1->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*2,PaintBox1->Height/3*2-15,"SP");
     PaintBox1->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*2,PaintBox1->Height/3*2-15,"50");
     PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(1*1.2)+trackwidth/3,PaintBox1->Height/3*2);
     PaintBox1->Canvas->LineTo(2+trackwidth+(trackwidth)*(2*1.0)+trackwidth/3,PaintBox1->Height/3*2);
     PaintBox1->Canvas->Pen->Style=psSolid;
     PaintBox1->Canvas->Pen->Color=clBlue;
     PaintBox1->Canvas->Font->Color=clBlue;
     PaintBox1->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*2,PaintBox1->Height/3*3-15,"10");
     PaintBox1->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*2,PaintBox1->Height/3*3-15,"R25");
     PaintBox1->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*2,PaintBox1->Height/3*3-15,"50");
     PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(1*1.2)+trackwidth/3,PaintBox1->Height/3*3);
     PaintBox1->Canvas->LineTo(2+trackwidth+(trackwidth)*(2*1.0)+trackwidth/3,PaintBox1->Height/3*3);
     //end third trace
     //forth trace
     PaintBox1->Canvas->Pen->Style=psSolid;
     PaintBox1->Canvas->Pen->Color=clBlue;
     PaintBox1->Canvas->Font->Color=clBlack;
     PaintBox1->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*3,PaintBox1->Height/3-15,"200");
     PaintBox1->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*3,PaintBox1->Height/3-15,"AC");
     PaintBox1->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*3,PaintBox1->Height/3-15,"500");
     PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(2*1.1)+trackwidth/3,PaintBox1->Height/3);
     PaintBox1->Canvas->LineTo(2+1.25*trackwidth*0.9+(trackwidth)*(3*1.0)+trackwidth/3,PaintBox1->Height/3);
      PaintBox1->Canvas->Pen->Style=psSolid;
     PaintBox1->Canvas->Pen->Color=clBlack;
     PaintBox1->Canvas->Font->Color=clBlack;
     PaintBox1->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*3,PaintBox1->Height/3+40,"200");
     PaintBox1->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*3,PaintBox1->Height/3+40,"HAC");
     PaintBox1->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*3,PaintBox1->Height/3+40,"500");
     PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(2*1.1)+trackwidth/3,PaintBox1->Height/3*2.6);
     PaintBox1->Canvas->LineTo(2+1.25*trackwidth*0.9+(trackwidth)*(3*1.0)+trackwidth/3,PaintBox1->Height/3*2.6);
     PaintBox1->Canvas->Pen->Style=psDash;
     PaintBox1->Canvas->Pen->Color=clRed;
     PaintBox1->Canvas->Font->Color=clRed;
     PaintBox1->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*3,PaintBox1->Height/3*2-20,"1.0");
     PaintBox1->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*3,PaintBox1->Height/3*2-20,"DEN");
     PaintBox1->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*3,PaintBox1->Height/3*2-20,"3.0");
     PaintBox1->Canvas->MoveTo(2+trackwidth+(trackwidth)*(2*1.1)+trackwidth/3,PaintBox1->Height/3*2-5);
     PaintBox1->Canvas->LineTo(2+1.25*trackwidth*0.9+(trackwidth)*(3*1.0)+trackwidth/3,PaintBox1->Height/3*2-5);
     //end forth trace
}

//---------------------------------------------------------------------------------------------
void __fastcall TForm1::draw(int temp[3][4],int tracknum,float data[50000][50],int index,float stdp0,float relv0)
{
     TColor a[5]={clBlack,clBlue,clRed,clYellow,clGreen};
     TPenStyle b[5]={psSolid,psDash,psDot,psDashDot,psDashDotDot};
//////////////////////////////////////////////////////////////////////
        tracknum=2;Name_Height=113;relv=0.05;
        trackwidth=Form1->Width/(tracknum*(4+1.5));

        index=index+50;//starti1=0;
        starti1=int(ScrollBox2->VertScrollBar->Position);
     PaintBox2->Height=index;
     PaintBox2->Top=-ScrollBox2->VertScrollBar->Position;

     PaintBox2->Width=2+100+trackwidth*5+3;
     PaintBox2->Left=(ScrollBox2->Width-PaintBox2->Width)/2;
     PaintBox2->Canvas->Pen->Color=clBlack;
     PaintBox2->Canvas->Pen->Width=2;
     PaintBox2->Canvas->MoveTo(2,0);
     PaintBox2->Canvas->LineTo(2,index);
     //first trace
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);
     PaintBox2->Canvas->Pen->Style=psSolid;
     PaintBox2->Canvas->Pen->Color=clBlack;
     PaintBox2->Canvas->Pen->Width=1;

     //draw the log curve
     int value_range_left=0,value_range_right=0;
     for(int j=0;j<2;j++)
     {
        if(j==0)
        {
            value_range_left=0;
            value_range_right=25;
        }
        else if(j==1)
        {
            value_range_left=0;
            value_range_right=120;
        }
        for(int i=0;i<3;i++)
        {

            if(temp[i][j]!=-1)
            {
                 PaintBox2->Canvas->MoveTo(2+10+trackwidth*(1.3+j),0);
                 PaintBox2->Canvas->Pen->Color=a[i+j];
                 PaintBox2->Canvas->Pen->Style=b[i+j];
                 if(i+j==3)
                 {
                     PaintBox2->Canvas->Pen->Color=clBlack;
                     PaintBox2->Canvas->Pen->Style=psSolid;
                 }
                 for(int k=starti1;k<starti1+1000;k++)
                 {
                      int temppos=0;  int twidth=trackwidth+(trackwidth)*(j*1.1)+60;
                      temppos=2+30+30*j+trackwidth*(0.3+j)+floor((data[k][temp[i][j]]-value_range_left)/(value_range_right-value_range_left)*twidth);
                      PaintBox2->Canvas->LineTo(temppos,k);
                      PaintBox2->Canvas->MoveTo(temppos,k);
                 }
            }
        }
     }
      for(int i=0;i<2;i++)
     {
        PaintBox2->Canvas->Pen->Style=psSolid;
        PaintBox2->Canvas->Pen->Color=clBlack;
        PaintBox2->Canvas->Pen->Width=2;
        PaintBox2->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(i*1)+68,0);
        PaintBox2->Canvas->LineTo(2+trackwidth*1.2+(trackwidth)*(i*1)+68,index);
     }
     for(int i=2;i<4;i++)
     {
        PaintBox2->Canvas->Pen->Style=psSolid;
        PaintBox2->Canvas->Pen->Color=clBlack;
        PaintBox2->Canvas->Pen->Width=2;
        if(i==3)
        {
         PaintBox2->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+60,0);
         PaintBox2->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+60,index);
         }
         else
         {
          PaintBox2->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+68,0);
          PaintBox2->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+68,index);
          }

     }
     PaintBox2->Canvas->MoveTo(2+70,0);
     PaintBox2->Canvas->LineTo(2+70,index);
     //---------------------------------------------------------draw GR curve
     PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);
           if(temp[0][2]!=-1)
     {
          for(int i=starti1;i<starti1+1000;i++)
          {

                 int temppos=0;
                 PaintBox2->Canvas->Pen->Style=psSolid;
                 PaintBox2->Canvas->Pen->Color=clBlack;
                 PaintBox2->Canvas->Pen->Width=1;
                 temppos=2+50+trackwidth*2+floor((data[i][temp[0][2]]-20)/(150-20)*trackwidth);
                 PaintBox2->Canvas->LineTo(temppos,i);
          }
     }
 //-------------------------------------------------------------draw  SP  curve
   //  smaxmin(temp[1][2]);
     float datsp[50000];
   //  int po=max-min;
     for(int n=starti1;n<starti1+1000;n++)
     {
     // if(abs(po)<0.00001)po=1;
      datsp[n]=data[n][temp[1][2]];
     }
     PaintBox2->Canvas->MoveTo(2+20+trackwidth*2,0);
     PaintBox2->Canvas->Pen->Style=psDot;
     PaintBox2->Canvas->Pen->Color=clRed;
     if(temp[1][2]!=-1)
     {
          for(int i=starti1;i<starti1+1000;i++)
          {
                 int temppos=0;
                 temppos=2+trackwidth*3+floor((datsp[i]-(-50.))/(50.0-(-50.))*trackwidth);
                 PaintBox2->Canvas->LineTo(temppos,i);
          }
     }
//-------------------------------------------------------------draw  R25  curve
   //  smaxmin(temp[1][2]);
     float datR25[50000];
   //  int po=max-min;
     for(int n=starti1;n<starti1+1000;n++)
     {
     // if(abs(po)<0.00001)po=1;
      datR25[n]=data[n][temp[2][2]];
     }
     PaintBox2->Canvas->MoveTo(2+20+trackwidth*2,0);
     PaintBox2->Canvas->Pen->Style=psSolid;
     PaintBox2->Canvas->Pen->Color=clBlue;
     if(temp[1][2]!=-1)
     {
          for(int i=starti1;i<starti1+1000;i++)
          {
                 int temppos=0;
                 temppos=2+trackwidth*3+floor((datR25[i]-(10.0))/(50.0-(10.0))*trackwidth);
                 PaintBox2->Canvas->LineTo(temppos,i);
          }
     }
//-------------------------------------------------------------------------draw AC curve
     PaintBox2->Canvas->MoveTo(2+50+trackwidth*3,0);
     PaintBox2->Canvas->Pen->Style=psDot;
     PaintBox2->Canvas->Pen->Color=clBlue;
     if(temp[0][3]!=-1)
     {
          for(int i=starti1;i<starti1+1000;i++)
          {
                 int temppos=0;
                 temppos=2+50+trackwidth*3+floor((data[i][temp[0][3]]-200)/(600-200)*trackwidth);
                 PaintBox2->Canvas->LineTo(temppos,i);
          }
     }
//--------------------------------------------------------------------Draw  HAC  curve
     smaxmin(temp[2][3]);
     PaintBox2->Canvas->MoveTo(2+50+trackwidth*3,0);
     PaintBox2->Canvas->Pen->Style=psSolid;
     PaintBox2->Canvas->Pen->Color=clBlack;
     if(temp[2][3]!=-1)
     {
          for(int i=starti1;i<starti1+1000;i++)
          {
                 int temppos=0;
                 temppos=2+trackwidth*4+floor((data[i][temp[2][3]]-200)/(600-200)*trackwidth);
                 PaintBox2->Canvas->LineTo(temppos,i);
          }
     }
//----------------------------------------------------------------------Draw  DEN   curve
    PaintBox2->Canvas->MoveTo(2+50+trackwidth*3,0);
    PaintBox2->Canvas->Pen->Style=psDash;
    PaintBox2->Canvas->Pen->Color=clRed;
     if(temp[1][3]!=-1)
     {
          for(int i=starti1;i<starti1+1000;i++)
          {
                 int temppos=0;
                 temppos=2+50+trackwidth*3+floor((data[i][temp[1][3]]-1.0)/(3.0-1.0)*trackwidth);
                  PaintBox2->Canvas->LineTo(temppos,i);
          }
     }
//---------------------------------------------------------------------Draw Depth
int deep,deep1,deep2,ip,ip1,sti,linelength=20;
  PaintBox2->Canvas->Pen->Color=clBlack;
 PaintBox2->Canvas->Pen->Style=psSolid;
 PaintBox2->Canvas->MoveTo(linelength,0);
 PaintBox2->Canvas->LineTo(linelength,PaintBox2->Height);
 ip=(int)(stdp0*10);
 ip1=(int)(ip/2);
 if(ip1*2==ip)
 {
  sti=0;
  }
  else
  {
   ip=(int)((stdp0+relv0)*10);
   ip1=(int)(ip/2);
   if(ip1*2==ip)
   {
    sti=1;
     }
    else
    {
     sti=2;
     }
   }
 deep=int(stdp0/100.);
 deep=deep*100;
 deep2=int(stdp0/2.);
 deep2=deep2*2;
 PaintBox2->Canvas->MoveTo(linelength+0,0);
 PaintBox2->Canvas->LineTo(linelength+5,0);
 for(int i0=sti;i0<index;i0+=4)
 {
  deep1=int(stdp0+i0*relv0);
  if(deep1==(deep2+2))
  {
   PaintBox2->Canvas->MoveTo(linelength,i0);
   PaintBox2->Canvas->LineTo(linelength+10,i0);
   PaintBox2->Canvas->TextOut(linelength+14,i0-5,AnsiString(deep2+2));
   deep2=deep2+2;
   }
   else
   {
    PaintBox2->Canvas->MoveTo(linelength+0,i0);
    PaintBox2->Canvas->LineTo(linelength+5,i0);
    }
   }
}
//------------------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 tracknum=2;Name_Height=113;index=1000;relv=0.05;
 trackwidth=Form1->Width/(tracknum*(4+1.5));
 onpaint_switch=1;
 onpaint_switch1=1;
 open_switch=1;
 Form1->WindowState=wsMaximized;
// Form1->ClientHeight=804;
 //Form1->ClientWidth=1580;
 DBGrid1->Visible=false;
 Form1->VertScrollBar->Visible=False;
 ScrollBox1->Left=0;
 ScrollBox1->Top=0;
 ScrollBox1->Width=Form1->Width/tracknum-5;
 ScrollBox1->Height=Form1->Name_Height;
 ScrollBox3->Left=Form1->Width/tracknum-5;
 ScrollBox3->Top=0;
 ScrollBox3->Width=Form1->Width/tracknum-5;
 ScrollBox3->Height=Name_Height;
 ScrollBox2->Left=0;
 ScrollBox2->Top=Name_Height+1;
 ScrollBox2->Width=Form1->Width/tracknum-5;
 ScrollBox2->Height=Form1->Height-180;
 ScrollBox4->Left=Form1->Width/tracknum-5;
 ScrollBox4->Top=Name_Height+1;
 ScrollBox4->Width=Form1->Width/tracknum-5;
 ScrollBox4->Height=Form1->Height-180;
 PaintBox1->Left=0;
 PaintBox1->Top=0;
 PaintBox1->Width=Form1->Width/tracknum-5;
 PaintBox1->Height=Form1->Name_Height;
 PaintBox3->Left=0;
 PaintBox3->Top=0;
 PaintBox3->Width=ScrollBox3->Width;
 PaintBox3->Height=Form1->Name_Height;
 PaintBox2->Left=0;
 PaintBox2->Top=0;
 PaintBox2->Width=ScrollBox2->Width;
 PaintBox2->Height=Form1->Height-180;
 PaintBox4->Left=0;
 PaintBox4->Top=0;
 PaintBox4->Width=ScrollBox4->Width;
 PaintBox4->Height=Form1->Height-180;
 PaintBox5->Left=0;
 PaintBox5->Top=0;
 PaintBox5->Width=ScrollBox4->Width;
 PaintBox5->Height=Form1->Height-180;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::ScrollBox3CanResize(TObject *Sender, int &NewWidth,
      int &NewHeight, bool &Resize)
{
   ScrollBox1->VertScrollBar->Position=ScrollBox3->VertScrollBar->Position;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ScrollBox4CanResize(TObject *Sender, int &NewWidth,
      int &NewHeight, bool &Resize)
{
    if(open_switch>0)
  {
    ScrollBox2->VertScrollBar->Position=ScrollBox4->VertScrollBar->Position;
    }
  PaintBox4->Refresh();
     /*     tracknum=2;Name_Height=113;//relv1=0.05;
        trackwidth=Form1->Width/(tracknum*(4+1.5));
        index1=index1+50;
       starti2=int(ScrollBox4->VertScrollBar->Position);
     PaintBox5->Height=index1;
     PaintBox5->Top=-ScrollBox4->VertScrollBar->Position;
     PaintBox5->Width=2+100+trackwidth*5+3;
     PaintBox5->Left=(Form1->ScrollBox4->Width-PaintBox5->Width)/2; */

}
//---------------------------------------------------------------------------

void __fastcall TForm1::ScrollBox1CanResize(TObject *Sender, int &NewWidth,
      int &NewHeight, bool &Resize)
{
  ScrollBox3->VertScrollBar->Position=ScrollBox1->VertScrollBar->Position;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::js(TObject *Sender, int &NewWidth,
      int &NewHeight, bool &Resize)
{
    if(open_switch==1)
    {
      ScrollBox4->VertScrollBar->Position=ScrollBox2->VertScrollBar->Position;
    }
    if(open_switch==2)
    {
      ScrollBox4->VertScrollBar->Position=ScrollBox2->VertScrollBar->Position-pos2_4;

    }
   PaintBox2->Refresh();

}
//---------------------------------------------------------------------------

void __fastcall TForm1::LA2Click(TObject *Sender)
{
       short i1,i2;float f;
     Top_deep1=0.0;
     int flag,i3;
     moveopen2=0;
 FILE *fp;
  // int Rd_valueGTzero=0;
 // int RMN_valueGTzero=0;
 // int AC1_value=0;
     MN1_pos=0;
     MK1_pos=0;
     Rd1_pos=0;
     Rs1_pos=0;
     Ac1_pos=0;
     Rxo1_pos=0;
     GR1_pos=0;
     SP1_pos=0;
     DEN1_pos=0;
     int line6[6];
     R251_pos=0;
 OpenDialog1->Filter="新井测井数据(*.la)|*.la|LA文件（LA*)|LA*|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute()){
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fp=fopen(OpenDialog1->Files->Strings[I].c_str(),"rb");
   cc2=OpenDialog1->Files->Strings[I].c_str();
   ccp2=ExtractFileName(OpenDialog1->FileName);
   //CCP2 = ccp2;
   Save_Name = ChangeFileExt(ccp2,"");
   Save_Name = UpperCase(Save_Name).c_str();
   //Jhc[i] = UpperCase(ccp2);
 if(fp){
 fread(str0,84,1,fp);
 fread(str1,80,1,fp);
 i2=getint(fp);
 i1=getint(fp);
 fread(str,80,1,fp);
//startdp
 stdp1=getfloat(fp);
//endp
 endp1=getfloat(fp);
//cyjj
 relv1=getfloat(fp);
 i1=getint(fp);
 i2=getint(fp);
 f=getfloat(fp);
 fread(str11,80,1,fp);
 fread(str3,148,1,fp);
/*  for(int i7=0;i7<int(Top_deep1/relv1);i7++)
 {
  for(int j7=1;j7<41;j7++)
  {
   a1[i7][j7]=1.0;
   data1[i7][j7]=1.0;
   }
  } */
 stdp1=stdp1-Top_deep1;
 i1=0+int(Top_deep1/relv1);
 stedp1=int((endp1-stdp1)/relv1);
while(i1<stedp1)
 {
  for(int j=1;j<41;j++)
  {
  for(int i=i1;i<i1+62;i++)
  {
   a1[i][j]=getfloat(fp);
   if(fabs(a1[i][j])>999.0)
   {
      a1[i][j]=999.0;
   }
   data1[i][j]=a1[i][j];;
   }
   }
  i1=i1+62;
  }
 }
 }
 }
 for(int i=0;i<3;i++)
         for(int j=0;j<4;j++)
             temp_index1[i][j]=-1;

 for(int i0=0;i0<stedp1;i0++)
  {
   a1[i0][0]=stdp1+i0*relv1;
   data1[i0][0]=stdp1+i0*relv1;
   }
  int i4,i,j,ip;
 cname3[0][5]="DEPT ";
 i4=1;
 for(i=0;i<80;i+=4)
 {
  i2=0;
  for(j=i;j<i+4;j++)
  {
   if(str[j]!=' ')i2++;
   }
   j=i;
  for(i3=0;i3<4;i3++)
   str2[i3]=0;
  for(i3=0;i3<i2;i3++)
  {
   str2[i3]=str[j];
   j++;
   }
   if((str2[0]!=' ')&&(str2[0]!='\0'))
   {
     cname3[i4][5]=str2;
     if(strcmp(str2,"RMN")==0||strcmp(str2,"MNOR")==0)
         {
             MN1_pos=i4;
             line6[0] = i4;
             temp_index1[0][0]=i4;
         }
         if(strcmp(str2,"RML")==0||strcmp(str2,"RMK")==0||strcmp(str2,"RMM")==0||strcmp(str2,"RMG")==0)
         {
             MK1_pos=i4;
             temp_index1[1][0]=i4;
         }
         if(strcmp(str2,"RLLD")==0||strcmp(str2,"RL3D")==0||strcmp(str2,"LLD")==0)
         {
             Rd1_pos=i4;
             line6[1] = i4;
             temp_index1[0][1]=i4;
         }
         if(strcmp(str2,"RLLS")==0||strcmp(str2,"RL3S")==0||strcmp(str2,"LLS")==0)
         {
             Rs1_pos=i4;
             temp_index1[1][1]=i4;
         }
         if(strcmp(str2,"MSFL")==0||strcmp(str2,"RXO")==0)
         {
             Rxo1_pos=i4;
             line6[2] = i4;
             temp_index1[2][1]=i4;
         }
         if(strcmp(str2,"GR")==0)
         {
             GR1_pos=i4;
             line6[3] = i4;
             temp_index1[0][2]=i4;
         }
         if(strcmp(str2,"SP")==0)
         {
             SP1_pos=i4;
             temp_index1[1][2]=i4;
         }
         if(strcmp(str2,"R25")==0||strcmp(str2,"R250")==0||strcmp(str2,"R2.5")==0)
         {
             R251_pos=i4;
             temp_index1[2][2]=i4;
         }
         if(strcmp(str2,"AC")==0||strcmp(str2,"DT")==0)
         {
             Ac1_pos=i4;
             temp_index1[0][3]=i4;
         }
         if(strcmp(str2,"DEN")==0)
         {
             DEN1_pos=i4;
             line6[4] = i4;
             temp_index1[1][3]=i4;
         }
        if(strcmp(str2,"HAC")==0)
         {
             HAC1_pos=i4;
             line6[5] = i4;
             temp_index1[2][3]=i4;
         }
     i4++;
     }
   }
    /////////////////////////////////////////////////
  int start = 0;
    int end = 0;
   for(int i = 0;i < 50000;i ++)
   {
        if(data1[i][line6[0]] * data1[i][line6[1]] * data1[i][line6[2]] * data1[i][line6[3]] * data1[i][line6[4]] * data1[i][line6[5]] == 0)
        {
                start = i;
        }
        else
        {
            int temp = 0;
            for(int j = 0;j < 6;j ++)
            {
                if(data1[i][line6[j]] < -2000)
                {
                        temp = 1;
                }
            }
            if(temp == 1)
            {
                start = i;
                continue;

            }
            else
                break;
        }

   }
   for(int i = 49999;i > start;i --)
   {
        if(data1[i][line6[0]] * data1[i][line6[1]] * data1[i][line6[2]] * data1[i][line6[3]] * data1[i][line6[4]] * data1[i][line6[5]] == 0)
                end = i;
        else
                break;
   }

  // int temp = 0;
   for(int i = start;i < end + 1;i ++)
   {
        for(int j = 0;j < 50;j ++)
        {
                a1[i - start][j] = a1[i][j];
                data1[i - start][j] = data1[i][j];
        }
   }
    endp1 = a1[end - start][0];
    stdp1 = a1[0][0];
    stedp1 = end - start;
   /////////////////////////////////////////////////


 fendp=0;
 //stedp1=int((endp1-stdp1)/relv1);
 ip=i4;i4=i4-1;
 for(int i0=stedp1;i0>(stedp1-300);i0--)
 {
    fdp0=a1[i0][MN1_pos]*a1[i0][Rd1_pos]*a1[i0][Rxo1_pos]*a1[i0][GR1_pos]*a1[i0][DEN1_pos]*a1[i0][HAC1_pos];
    fdp01=(a1[i0][MN1_pos]-a1[i0+1][MN1_pos])*(a1[i0][Rd1_pos]-a1[i0+1][Rd1_pos])*(a1[i0][Rxo1_pos]-a1[i0+1][Rxo1_pos])*(a1[i0][GR1_pos]-a1[i0+1][GR1_pos])*(a1[i0][DEN1_pos]-a1[i0+1][DEN1_pos])*(a1[i0][HAC1_pos]-a1[i0+1][HAC1_pos]);
    if(((fdp01*fdp0)>1.0)&&(fendp==0))
    {
        fendp=stdp1+i0*relv1;
    }
 }
 for(int i0=1;i0<(ip+1);i0++)
  {
   smaxmin1(i0);
   ma[i0]=max;
   mi[i0]=min;
   }
   onpaint_switch1=0;
   draw1(temp_index1,tracknum,data1,stedp1,stdp1,relv1);
   painthead1(Sender);
  // paintdepth1(stdp1,stedp1,relv1);
 // StatusBar2->Panels->Items[0]->Text="LA文件名："+cc;
  Form1->Caption=cc1+"                                                             采 油 二 厂 储 层 自 动 对 比 技 术                                                         "+cc2;
   fclose(fp);
 // bzc0(Sender);   //标准层
}
//---------------------------------------------------------------------------
void __fastcall TForm1::smaxmin1(int i0)
{
 float ma1[50000],min2;
  int i9,ij=0;
 i9=int(Top_deep1/relv);

 for(int l=i9+10;l<stedp1;l++)
 {
  ma1[ij]=data1[l][i0];ij++;
  }
 for(int l=100;l<ij-101;l++)
 {
  for(int k=l+1;k<ij-100;k++)
  {
   if(ma1[l]>ma1[k])
   {
    min2=ma1[l];
    ma1[l]=ma1[k];
    ma1[k]=min2;
   }
  }
 }
   int i1=0;
   while((ma1[i1]<0.001)&&(ma1[i1]>-0.001))
    {
    i1++;
    }
    if(i1<ij-20)
    {
     min1=int(ma1[i1]);
     max1=int(ma1[ij-101])+1;
    }
}
//-------------------------------------------------------------------------
void __fastcall TForm1::draw1(int temp1[3][4],int tracknum,float data1[50000][50],int index1,float stdp1,float relv1)
{
     TColor a[5]={clBlack,clBlue,clRed,clYellow,clGreen};
     TPenStyle b[5]={psSolid,psDash,psDot,psDashDot,psDashDotDot};
//////////////////////////////////////////////////////////////////////
        int trackwidth;
        tracknum=2;Name_Height=113;//relv1=0.05;
        trackwidth=Form1->Width/(tracknum*(4+1.5));
        index1=index1+50;
       starti2=int(ScrollBox4->VertScrollBar->Position);
     PaintBox4->Height=index1;
     PaintBox4->Top=-ScrollBox4->VertScrollBar->Position;
     PaintBox4->Width=2+100+trackwidth*5+3;
     PaintBox4->Left=(Form1->ScrollBox4->Width-PaintBox4->Width)/2;
     PaintBox4->Canvas->Pen->Color=clBlack;
     PaintBox4->Canvas->Pen->Width=2;
     PaintBox4->Canvas->MoveTo(2,0);
     PaintBox4->Canvas->LineTo(2,index1);

     //draw the log curve
     int value_range_left=0,value_range_right=0;
     PaintBox4->Canvas->Pen->Width=1;
     for(int j=0;j<2;j++)
     {
        if(j==0)
        {
            value_range_left=0;
            value_range_right=25;
        }
        else if(j==1)
        {
            value_range_left=0;
            value_range_right=120;
        }
        for(int i=0;i<3;i++)
        {

            if(temp1[i][j]!=-1)
            {
                 PaintBox4->Canvas->MoveTo(2+10+trackwidth*(1.3+j),0);
                 PaintBox4->Canvas->Pen->Color=a[i+j];
                 PaintBox4->Canvas->Pen->Style=b[i+j];
                 if(i+j==3)
                 {
                     PaintBox4->Canvas->Pen->Color=clBlack;
                     PaintBox4->Canvas->Pen->Style=psSolid;
                 }
                 for(int k=starti2;k<starti2+1000;k++)
                 {
                      int temppos=0;  int twidth=trackwidth+(trackwidth)*(j*1.1)+60;
                      temppos=2+30+30*j+trackwidth*(0.3+j)+floor((data1[k][temp1[i][j]]-value_range_left)/(value_range_right-value_range_left)*twidth);
                      PaintBox4->Canvas->LineTo(temppos,k);
                      PaintBox4->Canvas->MoveTo(temppos,k);
                 }
            }
        }
     }
      for(int i=0;i<2;i++)
     {
        PaintBox4->Canvas->Pen->Style=psSolid;
        PaintBox4->Canvas->Pen->Color=clBlack;
        PaintBox4->Canvas->Pen->Width=2;
        PaintBox4->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(i*1)+68,0);
        PaintBox4->Canvas->LineTo(2+trackwidth*1.2+(trackwidth)*(i*1)+68,index1);
     }
     for(int i=2;i<4;i++)
     {
        PaintBox4->Canvas->Pen->Style=psSolid;
        PaintBox4->Canvas->Pen->Color=clBlack;
        PaintBox4->Canvas->Pen->Width=2;
        if(i==3)
        {
         PaintBox4->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+60,0);
         PaintBox4->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+60,index1);
         }
         else
         {
          PaintBox4->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+68,0);
          PaintBox4->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+68,index1);
          }

     }
     PaintBox4->Canvas->MoveTo(2+70,0);
     PaintBox4->Canvas->LineTo(2+70,index1);
     //---------------------------------------------------------draw GR curve
     PaintBox4->Canvas->MoveTo(2+50+trackwidth*2,0);
           if(temp1[0][2]!=-1)
     {
          for(int i=starti2;i<starti2+1000;i++)
          {

                  int temppos=0;
                 PaintBox4->Canvas->Pen->Style=psSolid;
                 PaintBox4->Canvas->Pen->Color=clBlack;
                 PaintBox4->Canvas->Pen->Width=1;
                 temppos=2+50+trackwidth*2+floor((data1[i][temp1[0][2]]-20)/(150-20)*trackwidth);
                 PaintBox4->Canvas->LineTo(temppos,i);
          }
     }
 //-------------------------------------------------------------draw  SP  curve
   //  smaxmin1(temp1[1][2]);
     float datsp[50000]; //int po=max1-min1;
   //  if(po<0.001)po=1;
     for(int n=starti2;n<starti2+1000;n++)
     {
      datsp[n]=data1[n][temp1[1][2]];
     }
     PaintBox4->Canvas->MoveTo(2+20+trackwidth*2,0);
     PaintBox4->Canvas->Pen->Style=psDot;
     PaintBox4->Canvas->Pen->Color=clRed;
     if(temp1[1][2]!=-1)
     {
          for(int i=starti2;i<starti2+1000;i++)
          {
                 int temppos=0;
                 temppos=2+trackwidth*3+floor((datsp[i]-(-50.))/(50.0-(-50.))*trackwidth);
                 PaintBox4->Canvas->LineTo(temppos,i);
          }
     }
//-------------------------------------------------------------draw  R25  curve
   //  smaxmin1(temp1[1][2]);
     float datR25[50000]; //int po=max1-min1;
   //  if(po<0.001)po=1;
     for(int n=starti2;n<starti2+1000;n++)
     {
      datR25[n]=data1[n][temp1[2][2]];
     }
     PaintBox4->Canvas->MoveTo(2+20+trackwidth*2,0);
     PaintBox4->Canvas->Pen->Style=psSolid;
     PaintBox4->Canvas->Pen->Color=clBlue;
     if(temp1[1][2]!=-1)
     {
          for(int i=starti2;i<starti2+1000;i++)
          {
                 int temppos=0;
                 temppos=2+trackwidth*3+floor((datR25[i]-(10.0))/(50.0-(10.0))*trackwidth);
                 PaintBox4->Canvas->LineTo(temppos,i);
          }
     }
//-------------------------------------------------------------------------draw AC curve
        PaintBox4->Canvas->MoveTo(2+50+trackwidth*3,0);
     PaintBox4->Canvas->Pen->Style=psSolid;
     PaintBox4->Canvas->Pen->Color=clBlue;
     if(temp1[0][3]!=-1)
     {
          for(int i=starti2;i<starti2+1000;i++)
          {
                 int temppos=0;
                 temppos=2+50+trackwidth*3+floor((data1[i][temp1[0][3]]-200)/(600-200)*trackwidth);
                 PaintBox4->Canvas->LineTo(temppos,i);
          }
     }
//--------------------------------------------------------------------Draw  HAC  curve
   //  smaxmin1(temp1[2][3]);
     PaintBox4->Canvas->MoveTo(2+50+trackwidth*3,0);
     PaintBox4->Canvas->Pen->Style=psSolid;
     PaintBox4->Canvas->Pen->Color=clBlack;
     if(temp1[2][3]!=-1)
     {
          for(int i=starti2;i<starti2+1000;i++)
          {
                 int temppos=0;
                 temppos=2+trackwidth*4+floor((data1[i][temp1[2][3]]-200)/(600-200)*trackwidth);
                 PaintBox4->Canvas->LineTo(temppos,i);
          }
     }
//----------------------------------------------------------------------Draw  DEN   curve
     PaintBox4->Canvas->MoveTo(2+50+trackwidth*3,0);
     PaintBox4->Canvas->Pen->Style=psDash;
     PaintBox4->Canvas->Pen->Color=clRed;
     if(temp1[1][3]!=-1)
     {
          for(int i=starti2;i<starti2+1000;i++)
          {
                 int temppos=0;
                 temppos=2+50+trackwidth*3+floor((data1[i][temp1[1][3]]-1.0)/(3.0-1.0)*trackwidth);
                  PaintBox4->Canvas->LineTo(temppos,i);
          }
     }
//----------------------------------------------------------------------Draw  Depth
     int deep,deep1,deep2,ip,ip1,sti,linelength=20;
 PaintBox4->Canvas->Pen->Color=clBlack;
 PaintBox4->Canvas->Pen->Style=psSolid;
 PaintBox4->Canvas->MoveTo(linelength,0);
 PaintBox4->Canvas->LineTo(linelength,PaintBox4->Height);
 ip=(int)(stdp1*10);
 ip1=(int)(ip/2);
 if(ip1*2==ip)
 {
  sti=0;
  }
  else
  {
   ip=(int)((stdp1+relv1)*10);
   ip1=(int)(ip/2);
   if(ip1*2==ip)
   {
    sti=1;
     }
    else
    {
     sti=2;
     }
   }
 deep=int(stdp1/100.);
 deep=deep*100;
 deep2=int(stdp1/2.);
 deep2=deep2*2;
 PaintBox4->Canvas->MoveTo(linelength+0,0);
 PaintBox4->Canvas->LineTo(linelength+5,0);
 for(int i0=sti;i0<index1;i0+=4)
 {
  deep1=int(stdp1+i0*relv1);
  if(deep1==(deep2+2))
  {
   PaintBox4->Canvas->MoveTo(linelength,i0);
   PaintBox4->Canvas->LineTo(linelength+10,i0);
   PaintBox4->Canvas->TextOut(linelength+14,i0-5,AnsiString(deep2+2));
   deep2=deep2+2;
   }
   else
   {
    PaintBox4->Canvas->MoveTo(linelength+0,i0);
    PaintBox4->Canvas->LineTo(linelength+5,i0);
    }
   }
  //   paintdepth1(stdp1,index1,relv1);
  //   Form1->Refresh();
}
//---------------------------------------------------------------------------------------------------------------------------------
void __fastcall TForm1::painthead1(TObject *Sender)
{
  tracknum=2;Name_Height=113;relv1=0.05;
  trackwidth=Form1->Width/(tracknum*(4+1.5));
  //index=1000;
  PaintBox3->Width=2+100+trackwidth*5+3;
  PaintBox3->Canvas->Pen->Color=clGreen;
  PaintBox3->Canvas->Pen->Width=2;
  PaintBox3->Canvas->MoveTo(2,2);
  PaintBox3->Canvas->LineTo(2,PaintBox3->Height);
  PaintBox3->Canvas->LineTo(2+100+trackwidth*5,PaintBox3->Height);
  PaintBox3->Canvas->LineTo(2+100+trackwidth*5,2);
  PaintBox3->Canvas->LineTo(2,2);
  PaintBox3->Canvas->MoveTo(2+50,2);
  PaintBox3->Canvas->LineTo(2+50,PaintBox3->Height);
  PaintBox3->Canvas->MoveTo(12,PaintBox3->Height/2-20);
  PaintBox3->Canvas->TextOutA(12,PaintBox3->Height/2-20,"Depth");
  PaintBox3->Canvas->TextOutA(12+120+trackwidth*4,PaintBox3->Height/2-20,"Inter_Result");
 // PaintBox3->Canvas->TextOutA(100+150*4,PaintBox3->Height/2,cc2);
/*  for(int i=0;i<4;i++)
  {
      PaintBox3->Canvas->MoveTo(2+70+trackwidth*(i+1),2);
      PaintBox3->Canvas->LineTo(2+70+trackwidth*(i+1),PaintBox3->Height);
  } */

//////////////////////////////////////////////////////////////////////
        for(int i=0;i<2;i++)
     {
        PaintBox3->Canvas->Pen->Style=psSolid;
        PaintBox3->Canvas->Pen->Color=clBlack;
        PaintBox3->Canvas->Pen->Width=2;
        PaintBox3->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(i*1)+50,0);
        PaintBox3->Canvas->LineTo(2+trackwidth*1.2+(trackwidth)*(i*1)+50,index);
     }
     for(int i=2;i<4;i++)
     {
        PaintBox3->Canvas->Pen->Style=psSolid;
        PaintBox3->Canvas->Pen->Color=clBlack;
        PaintBox3->Canvas->Pen->Width=2;
        if(i==3)
        {
         PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+42,0);
         PaintBox3->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+42,index);
         }
         else
         {
          PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(i*1.1)+50,0);
          PaintBox3->Canvas->LineTo(2+trackwidth+(trackwidth)*(i*1.1)+50,index);
          }

     }
     PaintBox3->Canvas->Pen->Width=1;
     PaintBox3->Canvas->Pen->Style=psSolid;
     PaintBox3->Canvas->Pen->Color=clBlack;
     PaintBox3->Canvas->TextOutA(2+trackwidth/2.5,PaintBox3->Height/3-15,"0");
     PaintBox3->Canvas->TextOutA(2+trackwidth/2.5+trackwidth/2,PaintBox3->Height/3-15,"RMN");
     PaintBox3->Canvas->TextOutA(2+trackwidth/2.5+trackwidth,PaintBox3->Height/3-15,"25");
     PaintBox3->Canvas->MoveTo(2+trackwidth/3,PaintBox3->Height/3);
     PaintBox3->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(0*1)+trackwidth/3,PaintBox3->Height/3);
          PaintBox3->Canvas->Pen->Style=psDash;
     PaintBox3->Canvas->Pen->Color=clBlue;
     PaintBox3->Canvas->Font->Color=clBlue;
     PaintBox3->Canvas->TextOutA(2+trackwidth/2.5,PaintBox3->Height/3*2-15,"0");
     PaintBox3->Canvas->TextOutA(2+trackwidth/2.5+trackwidth/2,PaintBox3->Height/3*2-15,"RML");
     PaintBox3->Canvas->TextOutA(2+trackwidth/2.5+trackwidth,PaintBox3->Height/3*2-15,"25");
     PaintBox3->Canvas->MoveTo(2+trackwidth/3,PaintBox3->Height/3*2);
     PaintBox3->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(0*1)+trackwidth/3,PaintBox3->Height/3*2);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     //end first trace
     //second trace
     PaintBox3->Canvas->Pen->Style=psDash;
     PaintBox3->Canvas->Pen->Color=clBlue;
     PaintBox3->Canvas->Font->Color=clBlue;
     PaintBox3->Canvas->TextOutA(2+1.6*trackwidth+trackwidth*0,PaintBox3->Height/4-15,"0");
     PaintBox3->Canvas->TextOutA(2+1.4*trackwidth+trackwidth/2,PaintBox3->Height/4-15,"RLLD");
     PaintBox3->Canvas->TextOutA(2+2*trackwidth+trackwidth/3,PaintBox3->Height/4-15,"120");
     PaintBox3->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(0*1)+trackwidth/3,PaintBox3->Height/4);
     PaintBox3->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(1*1)+trackwidth/3,PaintBox3->Height/4);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     PaintBox3->Canvas->Pen->Style=psDot;
     PaintBox3->Canvas->Pen->Color=clRed;
     PaintBox3->Canvas->Font->Color=clRed;
     PaintBox3->Canvas->TextOutA(2+1.6*trackwidth+trackwidth*0,PaintBox3->Height/4*2-15,"0");
     PaintBox3->Canvas->TextOutA(2+1.4*trackwidth+trackwidth/2,PaintBox3->Height/4*2-15,"RLLS");
     PaintBox3->Canvas->TextOutA(2+2*trackwidth+trackwidth/3,PaintBox3->Height/4*2-15,"120");
     PaintBox3->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(0*1)+trackwidth/3,PaintBox3->Height/4*2);
     PaintBox3->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(1*1)+trackwidth/3,PaintBox3->Height/4*2);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     PaintBox3->Canvas->Pen->Style=psSolid;
     PaintBox3->Canvas->Pen->Color=clBlack;
     PaintBox3->Canvas->Font->Color=clBlack;
     PaintBox3->Canvas->TextOutA(2+1.6*trackwidth+trackwidth*0,PaintBox3->Height/4*3-15,"0");
     PaintBox3->Canvas->TextOutA(2+1.4*trackwidth+trackwidth/2,PaintBox3->Height/4*3-15,"MSFL");
     PaintBox3->Canvas->TextOutA(2+2*trackwidth+trackwidth/3,PaintBox3->Height/4*3-15,"120");
     PaintBox3->Canvas->MoveTo(2+trackwidth*1.2+(trackwidth)*(0*1)+trackwidth/3,PaintBox3->Height/4*3);
     PaintBox3->Canvas->LineTo(2+trackwidth*1.1+(trackwidth)*(1*1)+trackwidth/3,PaintBox3->Height/4*3);
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

     //end second trace
     //third trace
     PaintBox3->Canvas->Pen->Style=psSolid;
     PaintBox3->Canvas->Pen->Color=clBlack;
     PaintBox3->Canvas->Font->Color=clBlack;
     PaintBox3->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*2,PaintBox3->Height/3-15,"20");
     PaintBox3->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*2,PaintBox3->Height/3-15,"GR");
     PaintBox3->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*2,PaintBox3->Height/3-15,"150");
     PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(1*1.2)+trackwidth/3,PaintBox3->Height/3);
     PaintBox3->Canvas->LineTo(2+trackwidth+(trackwidth)*(2*1.05)+trackwidth/3,PaintBox3->Height/3);
     PaintBox3->Canvas->Pen->Style=psDot;
     PaintBox3->Canvas->Pen->Color=clRed;
     PaintBox3->Canvas->Font->Color=clRed;
     PaintBox3->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*2,PaintBox3->Height/3*2-15,"-50");
     PaintBox3->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*2,PaintBox3->Height/3*2-15,"SP");
     PaintBox3->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*2,PaintBox3->Height/3*2-15,"50");
     PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(1*1.2)+trackwidth/3,PaintBox3->Height/3*2);
     PaintBox3->Canvas->LineTo(2+trackwidth+(trackwidth)*(2*1.05)+trackwidth/3,PaintBox3->Height/3*2);
     PaintBox3->Canvas->Pen->Style=psDash;
     PaintBox3->Canvas->Pen->Color=clBlue;
     PaintBox3->Canvas->Font->Color=clBlue;
     PaintBox3->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*2,PaintBox3->Height/3*3-15,"10");
     PaintBox3->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*2,PaintBox3->Height/3*3-15,"R25");
     PaintBox3->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*2,PaintBox3->Height/3*3-15,"50");
     PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(1*1.2)+trackwidth/3,PaintBox3->Height/3*3);
     PaintBox3->Canvas->LineTo(2+trackwidth+(trackwidth)*(2*1.05)+trackwidth/3,PaintBox3->Height/3*3);
     //end third trace
     //forth trace
     PaintBox3->Canvas->Pen->Style=psDot;
     PaintBox3->Canvas->Pen->Color=clBlue;
     PaintBox3->Canvas->Font->Color=clBlack;
     PaintBox3->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*3,PaintBox3->Height/3-15,"200");
     PaintBox3->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*3,PaintBox3->Height/3-15,"AC");
     PaintBox3->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*3,PaintBox3->Height/3-15,"500");
     PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(2*1.1)+trackwidth/3,PaintBox3->Height/3);
     PaintBox3->Canvas->LineTo(2+1.25*trackwidth*0.9+(trackwidth)*(3*1.0)+trackwidth/3,PaintBox3->Height/3);
      PaintBox3->Canvas->Pen->Style=psSolid;
     PaintBox3->Canvas->Pen->Color=clBlack;
     PaintBox3->Canvas->Font->Color=clBlack;
     PaintBox3->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*3,PaintBox3->Height/3+40,"200");
     PaintBox3->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*3,PaintBox3->Height/3+40,"HAC");
     PaintBox3->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*3,PaintBox3->Height/3+40,"500");
     PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(2*1.1)+trackwidth/3,PaintBox3->Height/3*2.6);
     PaintBox3->Canvas->LineTo(2+1.25*trackwidth*0.9+(trackwidth)*(3*1.0)+trackwidth/3,PaintBox3->Height/3*2.6);
     PaintBox3->Canvas->Pen->Style=psDash;
     PaintBox3->Canvas->Pen->Color=clRed;
     PaintBox3->Canvas->Font->Color=clRed;
     PaintBox3->Canvas->TextOutA(2+0.6*trackwidth+trackwidth*3,PaintBox3->Height/3*2-20,"1.0");
     PaintBox3->Canvas->TextOutA(2+1.0*trackwidth+trackwidth*3,PaintBox3->Height/3*2-20,"DEN");
     PaintBox3->Canvas->TextOutA(2+1.35*trackwidth+trackwidth*3,PaintBox3->Height/3*2-20,"3.0");
     PaintBox3->Canvas->MoveTo(2+trackwidth+(trackwidth)*(2*1.1)+trackwidth/3,PaintBox3->Height/3*2-5);
     PaintBox3->Canvas->LineTo(2+1.25*trackwidth*0.9+(trackwidth)*(3*1.0)+trackwidth/3,PaintBox3->Height/3*2-5);
     //end forth trace

}
//------------------------------------------------------------------------------------------------
void __fastcall TForm1::paintdepth1(float stdp1,int stedp1,float relv1)
{
 int deep,deep1,deep2,ip,ip1,sti,linelength=20;
  {
 PaintBox4->Top=-ScrollBox4->VertScrollBar->Position;
 stdp1=stdp1+ScrollBox4->VertScrollBar->Position/2.*relv1;
 PaintBox4->Canvas->Pen->Color=clBlack;
 PaintBox4->Canvas->Pen->Style=psSolid;
 PaintBox4->Canvas->MoveTo(linelength,0);
 PaintBox4->Canvas->LineTo(linelength,PaintBox4->Height);
 ip=int(stdp1*10);
 ip1=int(ip/2);
 if(ip1*2==ip)
 {
  sti=0;
  }
  else
  {
   ip=int((stdp1+relv1)*10);
   ip1=int(ip/2);
   if(ip1*2==ip)
   {
    sti=1;
    }
    else
    {
    sti=2;
    }
    }
 deep=int(stdp1/100.);
 deep=deep*100;
 deep2=int(stdp1/2.);
 deep2=deep2*2;
 PaintBox4->Canvas->MoveTo(linelength+0,0);
 PaintBox4->Canvas->LineTo(linelength+5,0);
 for(int i0=sti;i0<stedp1;i0+=4)
 {
  deep1=int(stdp1+i0*relv1);
  if(deep1==(deep2+2))
  {
   PaintBox4->Canvas->MoveTo(linelength+0,i0*2);
   PaintBox4->Canvas->LineTo(linelength+10,i0*2);
   PaintBox4->Canvas->TextOut(linelength+14,i0*2-5,AnsiString(deep2+2));
   deep2=deep2+2;
  }
 // else if(deep1==(deep+10))
 // {
 //  PaintBox4->Canvas->MoveTo(linelength,i0*2);
//   PaintBox4->Canvas->LineTo(linelength+12,i0*2);
//   PaintBox4->Canvas->TextOut(linelength+14,i0*2-5,AnsiString(deep1));
//   deep=deep+10;
//   }
   else
   {
    PaintBox4->Canvas->MoveTo(linelength+0,i0*2);
    PaintBox4->Canvas->LineTo(linelength+5,i0*2);
    }
   }
  }

 }
//---------------------------------------------------------------------------------

void __fastcall TForm1::N4Click(TObject *Sender)
{
   open_switch=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N5Click(TObject *Sender)
{
     open_switch=2;
   pos2_4= ScrollBox2->VertScrollBar->Position-ScrollBox4->VertScrollBar->Position;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::PaintBox2Paint(TObject *Sender)
{
if(onpaint_switch<1)
 {
  draw(temp_index,tracknum,data,stedp,stdp,relv);
  paintfenceng(Sender);
 }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
  if(onpaint_switch<1)
 {
   painthead(Sender);
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCanResize(TObject *Sender, int &NewWidth,
      int &NewHeight, bool &Resize)
{

 Form1->VertScrollBar->Visible=False;
 ScrollBox1->Left=0;
 ScrollBox1->Top=0;
 ScrollBox1->Width=Form1->Width/tracknum-5;
 ScrollBox1->Height=Form1->Name_Height;
 ScrollBox3->Left=Form1->Width/tracknum-5;
 ScrollBox3->Top=0;
 ScrollBox3->Width=Form1->Width/tracknum-5;
 ScrollBox3->Height=Name_Height;
 ScrollBox2->Left=0;
 ScrollBox2->Top=Name_Height+1;
 ScrollBox2->Width=Form1->Width/tracknum-5;
 ScrollBox2->Height=Form1->Height-180;
 ScrollBox4->Left=Form1->Width/tracknum;
 ScrollBox4->Top=Name_Height+1;
 ScrollBox4->Width=Form1->Width/tracknum-5;
 ScrollBox4->Height=Form1->Height-180;
// PaintBox1->Canvas=Refresh();
// PaintBox3->Canvas=Clear();
/* draw(temp_index,tracknum,data,stedp,stdp,relv);
 painthead(Sender);
 draw1(temp_index1,tracknum,data1,stedp1,stdp1,relv1);
 painthead1(Sender); */


/* PaintBox1->Left=0;
 PaintBox1->Top=0;
 PaintBox1->Width=Form1->Width/tracknum-5;
 PaintBox1->Height=Form1->Name_Height;
 PaintBox3->Left=0;
 PaintBox3->Top=0;
 PaintBox3->Width=ScrollBox3->Width;
 PaintBox3->Height=ScrollBox3->Height+10;
 PaintBox2->Left=0;
 PaintBox2->Top=0;
 PaintBox2->Width=ScrollBox2->Width;
 PaintBox2->Height=Form1->Height-240;
 PaintBox4->Left=0;
 PaintBox4->Top=0;
 PaintBox4->Width=ScrollBox4->Width;
 PaintBox4->Height=Form1->Height-240;
  */
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox3Paint(TObject *Sender)
{
   if(onpaint_switch1<1)
 {
   painthead1(Sender);
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox4Paint(TObject *Sender)
{
 if(onpaint_switch1<1)
 {
    draw1(temp_index1,tracknum,data1,stedp1,stdp1,relv1);
    paintfenceng1(Sender);
   // paintfencengnew(Sender);
    paintfencengnewDice(Sender);
   // bzcpaint(Sender);   //标准层显示
 }

}
//-----------------------------------------------------------------------------
void __fastcall TForm1::bccwsjk(TObject *Sender)   //保存层位数据库
{
 FILE *fp;short i1=2,i2=3,ii=40;int i3; AnsiString cc;

 SaveDialog1->Filter="DBF数据库文件（*.dbf)|*.dbf|所有文件(*.*)|*.*";
 if(SaveDialog1->Execute())
 {
 for(int I=0;I<SaveDialog1->Files->Count;I++)
  {
   fp=fopen(SaveDialog1->Files->Strings[I].c_str(),_T("w"));
//   cc=SaveDialog1->Files->Strings[I].c_str(); //打开的数据文件名
 //  cc=ExtractFilePath(SaveDialog1->FileName);
  // Image1->Canvas->TextOutA(5,5,cc);          //数据库文件所在的路径
  if(fp)
   {
   // TTable*newtable=new TTable(this);
   TTable*newTable;
   newTable=new TTable(this);
    newTable->Active=false;
   // if(newTable->Exists)return;
    newTable->DatabaseName=ExtractFilePath(SaveDialog1->FileName);
    newTable->TableName=SaveDialog1->FileName;             //或者Table1->TableName=cc;
    newTable->TableType=ttDBase;
    newTable->FieldDefs->Clear();
    newTable->FieldDefs->Add("井号外",ftString,8,false);
    newTable->FieldDefs->Add("小层界限外",ftFloat,0,false);
    newTable->FieldDefs->Add("顶部深度外",ftFloat,0,false);
    newTable->FieldDefs->Add("厚度外",ftFloat,0,false);
    newTable->FieldDefs->Add("顶部深度",ftFloat,0,false);
    newTable->FieldDefs->Add("砂岩厚度",ftFloat,0,false);
    newTable->FieldDefs->Add("有效厚度顶",ftFloat,0,false);
    newTable->FieldDefs->Add("有效",ftFloat,0,false);
    newTable->FieldDefs->Add("类别",ftString,1,false);
    newTable->FieldDefs->Add("夹层数",ftInteger,0,false);
    newTable->FieldDefs->Add("解释序号",ftInteger,0,false);
    newTable->FieldDefs->Add("孔隙度",ftFloat,0,false);
    newTable->FieldDefs->Add("渗透率特征",ftString,1,false);
    newTable->FieldDefs->Add("自渗透率",ftFloat,0,false);
    newTable->FieldDefs->Add("自地层系数",ftFloat,0,false);
    newTable->FieldDefs->Add("含水饱和度",ftFloat,0,false);
    newTable->FieldDefs->Add("束缚水饱和",ftFloat,0,false);
    newTable->FieldDefs->Add("水淹解释结",ftString,1,false);
    newTable->FieldDefs->Add("电测解释结",ftString,1,false);
    newTable->FieldDefs->Add("射孔",ftString,1,false);
    newTable->FieldDefs->Add("补孔",ftString,1,false);
    newTable->CreateTable();
    DataSource1->DataSet=newTable;
    newTable->TableName=SaveDialog1->FileName;
    newTable->Active=true;
    newTable->Insert();
    newTable->Open();
  //  if(newTable->State==dsInsert)ShowMessage("数据库处于可插入状态");
    newTable->DisableControls();
    newTable->First();
         for(int i=0;i<totalnum;i++)
        {
          newTable->Insert();
          newTable->FieldByName("井号外")->AsString=jhw1[i];
          newTable->FieldByName("小层界限外")->Value=FormatFloat("0.0",xcw1[i]);
          newTable->FieldByName("顶部深度外")->Value=FormatFloat("0.0",dsw1[i]);
          newTable->FieldByName("厚度外")->Value=FormatFloat("0.0",hdw1[i]);
          newTable->FieldByName("顶部深度")->Value=FormatFloat("0.0",dbsd1[i]);
          newTable->FieldByName("砂岩厚度")->Value=FormatFloat("0.0",syhd1[i]);
          newTable->FieldByName("有效厚度顶")->Value=FormatFloat("0.0",yxhdd1[i]);
          newTable->FieldByName("有效")->Value=FormatFloat("0.0",dsw1[i]);
          newTable->FieldByName("类别")->AsString=lb1[i];
          newTable->FieldByName("夹层数")->Value=jcs1[i];
          newTable->FieldByName("解释序号")->Value=jsxh[i];
          newTable->FieldByName("孔隙度")->Value=FormatFloat("0.0",kxd1[i]);
          newTable->FieldByName("渗透率特征")->AsString=stltz1[i];
          newTable->FieldByName("自渗透率")->Value=FormatFloat("0.0",zstl1[i]);
          newTable->FieldByName("自地层系数")->Value=FormatFloat("0.0",zdcxs1[i]);
          newTable->FieldByName("含水饱和度")->Value=FormatFloat("0.0",hsbhd1[i]);
          newTable->FieldByName("束缚水饱和")->Value=FormatFloat("0.0",sfsbh1[i]);
          newTable->FieldByName("水淹解释结")->AsString=syjs1[i];
          newTable->FieldByName("电测解释结")->AsString=dcjs1[i];
          newTable->FieldByName("射孔")->AsString=sk1[i];
          newTable->FieldByName("补孔")->AsString=bk1[i];
     //     Image1->Canvas->TextOutA(120,10+i*25,FormatFloat("0.0",xcw[i]));
          newTable->Next();

         }

        newTable->Active=false;
         newTable->EnableControls();
         newTable->Close();
        }
    }
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GetFileName1(String str,int im)
{
  Integer i;
 String x,y,pm;
 x=ExtractFileName(str);  //取文件名+扩展名，不包含文件路径
  y=ExtractFileExt(str);   //取文件的扩展名
//  i=Pos(y,x);              //确定扩展名所在位置
//  str=Copy(x,0,i-1);  //复制文件名，忽略掉后面的扩展名
//ChangeFileExt(const AnsiString FileName, const AnsiString Extension);
  pm=str6[im]+".dat";
  str=ChangeFileExt(x,pm); //更换扩展名
  newname1=str;
 //  PaintBox2->Canvas->TextOutA(20,200,newname);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::dkcwsjk(TObject *Sender)  //打开层位数据库  nnnnnn
{
 int i=0,j,i1,i2=0,i3,flag=0,n;AnsiString cc;
 FILE *fp;
 OpenDialog1->Filter="分层数据库文件（*.DBF)|*.DBF|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fp=fopen(OpenDialog1->Files->Strings[I].c_str(),_T("r"));
   cc=OpenDialog1->Files->Strings[I].c_str();
   DBF055 = cc;
   ccp0=ExtractFileName(OpenDialog1->FileName);
   DBF055_Name = ccp0;
  //  GetFileName1(ccp0);
  if(fp)
   {
   Table1->TableName=cc;
   Table1->Open();
   DBGrid1->DataSource=DataSource1;

   Table1->Active=true;
   Table1->First();
  while(!Table1->Eof)
  {
   if(Table1->FieldByName("井号外")->Value.IsEmpty())
   {
    jhw[i]=NULL;
    }
    else
    {
     jhw[i]=Table1->FieldByName("井号外")->AsString;
     }
   xcw[i]=Table1->FieldByName("小层界限外")->Value; //读取分层数据信息
   dsw[i]=Table1->FieldByName("顶部深度外")->Value;
   hdw[i]=Table1->FieldByName("厚度外")->Value;
   dbsd[i]=Table1->FieldByName("顶部深度")->Value;
   syhd[i]=Table1->FieldByName("砂岩厚度")->Value;
   yxhdd[i]=Table1->FieldByName("有效厚度顶")->Value;
   yx[i]=Table1->FieldByName("有效")->Value;
   if(Table1->FieldByName("类别")->Value.IsEmpty())
   {
    lb[i]=NULL;
    }
    else
    {
     lb[i]=Table1->FieldByName("类别")->AsString;
     }
   jcs[i]=Table1->FieldByName("夹层数")->Value;
   jsxh[i]=Table1->FieldByName("解释序号")->Value;
   kxd[i]=Table1->FieldByName("孔隙度")->Value;
   if(Table1->FieldByName("渗透率特征")->Value.IsEmpty())
   {
    stltz[i]=NULL;
    }
    else
    {
     stltz[i]=Table1->FieldByName("渗透率特征")->AsString;
     }
   zstl[i]=Table1->FieldByName("自渗透率")->Value;
   zdcxs[i]=Table1->FieldByName("自地层系数")->Value;
   hsbhd[i]=Table1->FieldByName("含水饱和度")->Value;
   sfsbh[i]=Table1->FieldByName("束缚水饱和")->Value;
   if(Table1->FieldByName("水淹解释结")->Value.IsEmpty())
   {
    syjs[i]=NULL;
    }
    else
    {
     syjs[i]=Table1->FieldByName("水淹解释结")->AsString;
     }
    if(Table1->FieldByName("电测解释结")->Value.IsEmpty())
    {
     dcjs[i]=NULL;
     }
     else
     {
      dcjs[i]=Table1->FieldByName("电测解释结")->AsString;
      }
     if(Table1->FieldByName("射孔")->Value.IsEmpty())
     {
      sk[i]=NULL;
      }
      else
      {
       sk[i]=Table1->FieldByName("射孔")->AsString;
       }
      if(Table1->FieldByName("补孔")->Value.IsEmpty())
      {
       bk[i]=NULL;
       }
       else
       {
        bk[i]=Table1->FieldByName("补孔")->AsString;
        }

  // Image1->Canvas->TextOutA(10,10+i*25,FormatFloat("0.0",xcw[i]));
  // Image1->Canvas->TextOutA(120,10+i*25,FormatFloat("0.0",dsw[i]));

   i++;
   Table1->Next();
   }
   totalnum=i-1;
 //  Image1->Canvas->TextOutA(80,10,totalnum);
    }
   }
  }
  Table1->First();
  Table1->Close();
  fclose(fp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::dkcwsjk1(TObject *Sender)  //打开层位数据库
{
 int i=0,j,i1,i2=0,i3,flag=0,n;AnsiString cc;
 FILE *fp;
 OpenDialog1->Filter="分层数据库文件（*.DBF)|*.DBF|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fp=fopen(OpenDialog1->Files->Strings[I].c_str(),_T("r"));
   cc=OpenDialog1->Files->Strings[I].c_str();
   DBF055 = cc;
   ccp0=ExtractFileName(OpenDialog1->FileName);
   DBF055_Name = ccp0;
  //  GetFileName1(ccp0);
  if(fp)
   {
   Table1->TableName=cc;
   Table1->Open();
   DBGrid1->DataSource=DataSource1;

   Table1->Active=true;
   Table1->First();
  while(!Table1->Eof)
  {
   if(Table1->FieldByName("井号外")->Value.IsEmpty())
   {
    jhw[i]=NULL;
    }
    else
    {
     jhw[i]=Table1->FieldByName("井号外")->AsString;
     }
   xcw[i]=Table1->FieldByName("小层界限外")->Value; //读取分层数据信息
   dsw[i]=Table1->FieldByName("顶部深度外")->Value;
   hdw[i]=Table1->FieldByName("厚度外")->Value;
   dbsd[i]=Table1->FieldByName("顶部深度")->Value;
   syhd[i]=Table1->FieldByName("砂岩厚度")->Value;
   yxhdd[i]=Table1->FieldByName("有效厚度顶")->Value;
   yx[i]=Table1->FieldByName("有效")->Value;
   if(Table1->FieldByName("类别")->Value.IsEmpty())
   {
    lb[i]=NULL;
    }
    else
    {
     lb[i]=Table1->FieldByName("类别")->AsString;
     }
   jcs[i]=Table1->FieldByName("夹层数")->Value;
   jsxh[i]=Table1->FieldByName("解释序号")->Value;
   kxd[i]=Table1->FieldByName("孔隙度")->Value;
   if(Table1->FieldByName("渗透率特征")->Value.IsEmpty())
   {
    stltz[i]=NULL;
    }
    else
    {
     stltz[i]=Table1->FieldByName("渗透率特征")->AsString;
     }
   zstl[i]=Table1->FieldByName("自渗透率")->Value;
   zdcxs[i]=Table1->FieldByName("自地层系数")->Value;
   hsbhd[i]=Table1->FieldByName("含水饱和度")->Value;
   sfsbh[i]=Table1->FieldByName("束缚水饱和")->Value;
   if(Table1->FieldByName("水淹解释结")->Value.IsEmpty())
   {
    syjs[i]=NULL;
    }
    else
    {
     syjs[i]=Table1->FieldByName("水淹解释结")->AsString;
     }
    if(Table1->FieldByName("电测解释结")->Value.IsEmpty())
    {
     dcjs[i]=NULL;
     }
     else
     {
      dcjs[i]=Table1->FieldByName("电测解释结")->AsString;
      }
     if(Table1->FieldByName("射孔")->Value.IsEmpty())
     {
      sk[i]=NULL;
      }
      else
      {
       sk[i]=Table1->FieldByName("射孔")->AsString;
       }
      if(Table1->FieldByName("补孔")->Value.IsEmpty())
      {
       bk[i]=NULL;
       }
       else
       {
        bk[i]=Table1->FieldByName("补孔")->AsString;
        }

  // Image1->Canvas->TextOutA(10,10+i*25,FormatFloat("0.0",xcw[i]));
  // Image1->Canvas->TextOutA(120,10+i*25,FormatFloat("0.0",dsw[i]));

   i++;
   Table1->Next();
   }
   totalnum1=i-1;
 //  Image1->Canvas->TextOutA(80,10,totalnum);
    }
   }
  }
  Table1->First();
  Table1->Close();
  fclose(fp);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N7Click(TObject *Sender)
{
 FILE *fp; int i2=7;ie=0;  xzkg=1;
/*  OpenDialog1->Filter="老井厚度数据(*.dat)|*.dat|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fp=fopen(OpenDialog1->Files->Strings[I].c_str(),"r");
   ccold=OpenDialog1->Files->Strings[I].c_str();
        if(fp)
        {
         while(feof(fp)==0)
         {
           fread(str5,8,1,fp);
           str6[ie]=str5;
          for(int j=0;j<i2;j++)
           {
             fscanf(fp,"%f",&a2[ie][j]);
           }
          ie++;
           }
         }
    }
  }
  ljcgs=ie;  */
  dkcwsjk(Sender);  //打开层位数据库
  for(int i1=0;i1<totalnum+1;i1++)
  {
       AnsiString(str5)=jhw[i1];
       str6[i1]=jhw[i1].c_str();
       a2[i1][0]=xcw[i1];
  }
  ljcgs=totalnum+1;
  ie=totalnum+1;
 paintfenceng(Sender);
 N9Click(Sender);
 DataBase = 1;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::paintfenceng(TObject *Sender)
{
  PaintBox2->Canvas->Pen->Width=1;
  PaintBox2->Canvas->Pen->Style=psSolid;
  PaintBox2->Canvas->Pen->Color=clBlack;
  int ii0=0;
  ljcs=0;//老井层数
  float deep1;
  int tw;
  tw=Form1->Width/2.2;
 for(int i0=0;i0<stedp;i0++)
 {
  deep1=stdp+i0*relv;
  if(fabs(a2[ii0][0]-deep1)<0.001)
         {
          PaintBox2->Canvas->MoveTo(4+0,i0);
          PaintBox2->Canvas->LineTo(tw+30,i0);
          PaintBox2->Canvas->TextOut(tw+4,i0-14,str6[ii0]);
          PaintBox2->Canvas->TextOut(tw+4,i0+3,AnsiString(FormatFloat("0.0",a2[ii0][0])));
          str16[ljcs]=str6[ii0];
          a21lj[ljcs]=a2[ii0][0];
          ljcs=ljcs+1;
          if(ii0<ie)ii0=ii0+1;
          while((a2[ii0][0]<0.1)&&(ii0<ie))
          {
           ii0=ii0+1;
           }
         }
   }
  ljhdhf(Sender);
}
//-----------------------------------------------------------------------------------

void __fastcall TForm1::N8Click(TObject *Sender)
{
  FILE *fp; int i2=7;ie2=0; xzkg=1;
/*  OpenDialog1->Filter="新井层位数据(*.dat)|*.dat|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fp=fopen(OpenDialog1->Files->Strings[I].c_str(),"r");
   cc1=OpenDialog1->Files->Strings[I].c_str();
        if(fp)
        {
         while(feof(fp)==0)
         {
           fread(str05,8,1,fp);
           str7[ie1]=str05;
          for(int j=0;j<i2;j++)
           {
             fscanf(fp,"%f",&a3[ie1][j]);
           }
          ie1++;
           }
         }
    }
  }   */
  int fl=0;
   dkcwsjk1(Sender);  //打开层位数据库
  for(int i1=0;i1<totalnum1+1;i1++)
  {
       AnsiString(str05)=jhw[i1];
       str7[i1]=jhw[i1].c_str();
       a3[i1][0]=xcw[i1];
       if(xcw[i1]>0.1)
       {
          xjcw9[fl]=xcw[i1];
          fl=fl+1;
       }
  }

  ie2=totalnum1+1;
   ie1=ie2;

 paintfenceng1(Sender);
 fclose(fp);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::paintfenceng1(TObject *Sender)
{
  PaintBox4->Canvas->Pen->Width=1;
  PaintBox4->Canvas->Pen->Style=psSolid;
  PaintBox4->Canvas->Pen->Color=clBlack;
  int ii0=0;
  float deep1;
  int tw;
  tw=Form1->Width/2.2-5;
 for(int i0=0;i0<stedp1;i0++)
 {
  deep1=stdp1+i0*relv1;
  if(fabs(deep1-a3[ii0][0])<0.01)
    {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,str7[ii0]);
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",a3[ii0][0])));
          if(ii0<zxjcgs)ii0=ii0+1;    //总新井层个数
          while((a3[ii0][0]<0.01)&&(ii0<zxjcgs))
          {
           ii0=ii0+1;

           }
      }
  }

}
//-----------------------------------------------------------------------------------
//------------------------------------------------------------------
void __fastcall TForm1::PaintBox2MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
 /*  POINT MousePos; int mouse_y;
  GetCursorPos(&MousePos);
  bool in_the_te=false,in_the_ef=false;
  mouse_y=ScrollBox2->VertScrollBar->Position+ScreenToClient(MousePos).y-121;
  PaintBox2->Canvas->Pen->Width=1;
  PaintBox2->Canvas->Pen->Style=psSolid;
  PaintBox2->Canvas->Pen->Color=clGray;

          PaintBox2->Canvas->MoveTo(4+0,Y);
          PaintBox2->Canvas->LineTo(100+150*4+30,Y);
          PaintBox2->Canvas->Pen->Color=clBlack;  */
 //         PaintBox2->Canvas->TextOut(100+150*4+4,i0-14,str6[ii0]);
  //        PaintBox2->Canvas->TextOut(100+150*4+4,i0+3,AnsiString(a2[ii0][0]));

}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox2MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
          int tw;
          tw=Form1->Width/2.2;
          float deep1;
          PaintBox2->Canvas->Pen->Width=1;
          PaintBox2->Canvas->Pen->Style=psSolid;
          PaintBox2->Canvas->Pen->Color=clBlack;
          deep1=stdp+Y*relv;
          PaintBox2->Canvas->MoveTo(4+0,Y);
          PaintBox2->Canvas->LineTo(tw+30,Y);
          PaintBox2->Canvas->TextOut(tw+4,Y+6,AnsiString(FormatFloat("0.0",deep1)));
          PaintBox2->Canvas->TextOut(24,Y+6,"RMN: ");
          PaintBox2->Canvas->TextOut(50+5,Y+6,AnsiString(FormatFloat("0.00",a[Y][MN_pos])));
          PaintBox2->Canvas->TextOut(84,Y+6,"RMK: ");
          PaintBox2->Canvas->TextOut(110+5,Y+6,AnsiString(FormatFloat("0.00",a[Y][MK_pos])));
          PaintBox2->Canvas->TextOut(140,Y+6,"RlLLD: ");
          PaintBox2->Canvas->TextOut(170+5,Y+6,AnsiString(FormatFloat("0.00",a[Y][Rd_pos])));
          PaintBox2->Canvas->TextOut(204,Y+6,"RLLS: ");
          PaintBox2->Canvas->TextOut(230+5,Y+6,AnsiString(FormatFloat("0.00",a[Y][Rs_pos])));
          PaintBox2->Canvas->TextOut(264,Y+6,"RXO: ");
          PaintBox2->Canvas->TextOut(300,Y+6,AnsiString(FormatFloat("0.00",a[Y][Rxo_pos])));
          PaintBox2->Canvas->TextOut(334,Y+6,"HAC: ");
          PaintBox2->Canvas->TextOut(360,Y+6,AnsiString(FormatFloat("0.00",a[Y][HAC_pos])));
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox2MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
          int tw;
          tw=Form1->Width/2.2;
          PaintBox2->Canvas->Pen->Width=1;
          PaintBox2->Canvas->Pen->Style=psSolid;
          PaintBox2->Canvas->Pen->Color=clBtnFace;
          PaintBox2->Canvas->MoveTo(4+0,Y);
          PaintBox2->Canvas->LineTo(tw+30,Y);
          PaintBox2->Canvas->TextOut(tw+4,Y+6,AnsiString("                                "));
          PaintBox2->Canvas->TextOut(24,Y+6,"         ");
          PaintBox2->Canvas->TextOut(50,Y+6,"                        ");
          PaintBox2->Canvas->TextOut(84,Y+6,"               ");
          PaintBox2->Canvas->TextOut(110,Y+6,"                     ");
          PaintBox2->Canvas->TextOut(140,Y+6,"                      ");
          PaintBox2->Canvas->TextOut(170,Y+6,"                            ");
          PaintBox2->Canvas->TextOut(204,Y+6,"                ");
          PaintBox2->Canvas->TextOut(230,Y+6,"                        ");
          PaintBox2->Canvas->TextOut(264,Y+6,"                      ");
          PaintBox2->Canvas->TextOut(300,Y+6,"                         ");
          PaintBox2->Canvas->TextOut(334,Y+6,"                      ");
          PaintBox2->Canvas->TextOut(360,Y+6,"                            ");
          PaintBox2Paint(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox4MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
        if(Button==mbRight)
        {
                Form4->Show();
                Form4->Edit1->Text="";
                Form4->Edit2->Text="";
                Form4->Left=100;
                Form4->Height=180;
                Form4->Width =330;
                Form4->Label1->Width=190;
                Form4->Label2->Width=161;
                Form4->Label3->Width=161;
                Form4->Edit3->Text=FloatToStr(stdp1+Y*relv1);
                Ym=Y;

        }




          int tw;
          tw=Form1->Width/2.2;
          float deep1;
          PaintBox4->Canvas->Pen->Width=1;
          PaintBox4->Canvas->Pen->Style=psSolid;
          PaintBox4->Canvas->Pen->Color=clBlack;
          deep1=stdp1+Y*relv1;
          PaintBox4->Canvas->MoveTo(4+0,Y);
          PaintBox4->Canvas->LineTo(tw+30,Y);
          PaintBox4->Canvas->TextOut(tw+4,Y+6,AnsiString(FormatFloat("0.0",deep1)));
          PaintBox4->Canvas->TextOut(24,Y+6,"RMN: ");
          PaintBox4->Canvas->TextOut(50+5,Y+6,AnsiString(FormatFloat("0.00",a1[Y][MN1_pos])));
          PaintBox4->Canvas->TextOut(84,Y+6,"RMK: ");
          PaintBox4->Canvas->TextOut(110+5,Y+6,AnsiString(FormatFloat("0.00",a1[Y][MK1_pos])));
          PaintBox4->Canvas->TextOut(140,Y+6,"RlLLD: ");
          PaintBox4->Canvas->TextOut(170+5,Y+6,AnsiString(FormatFloat("0.00",a1[Y][Rd1_pos])));
          PaintBox4->Canvas->TextOut(204,Y+6,"RLLS: ");
          PaintBox4->Canvas->TextOut(230+5,Y+6,AnsiString(FormatFloat("0.00",a1[Y][Rs1_pos])));
          PaintBox4->Canvas->TextOut(264,Y+6,"RXO: ");
          PaintBox4->Canvas->TextOut(300,Y+6,AnsiString(FormatFloat("0.00",a1[Y][Rxo1_pos])));
          PaintBox4->Canvas->TextOut(334,Y+6,"HAC: ");
          PaintBox4->Canvas->TextOut(360,Y+6,AnsiString(FormatFloat("0.00",a1[Y][HAC1_pos])));

  for(int ii0=0;ii0<ljcgs;ii0++)
  {
     moveopen2=1;
     if((PaintBox4->Canvas->Pixels[X][Y]==RGB(210,20,ii0))||(PaintBox4->Canvas->Pixels[X][Y-1]==RGB(210,20,ii0))||(PaintBox4->Canvas->Pixels[X][Y+1]==RGB(210,20,ii0))\
     ||(PaintBox4->Canvas->Pixels[X][Y+2]==RGB(210,20,ii0))||(PaintBox4->Canvas->Pixels[X][Y-2]==RGB(210,20,ii0))||(PaintBox4->Canvas->Pixels[X][Y+3]==RGB(210,20,ii0))||(PaintBox4->Canvas->Pixels[X][Y-3]==RGB(210,20,ii0)))
     {
            PaintBox4->Canvas->Pen->Width=1;
            PaintBox4->Canvas->Pen->Style=psSolid;
            PaintBox4->Canvas->Pen->Color=clBtnFace;
            PaintBox4->Canvas->MoveTo(4+0,Y);
            PaintBox4->Canvas->LineTo(100+150*4+30,Y);
            pd1=1;Y1=Y;icolor=ii0;

     }
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox4MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
         int tw;
          tw=Form1->Width/2.2;
          PaintBox4->Canvas->Pen->Width=1;
          PaintBox4->Canvas->Pen->Style=psSolid;
          PaintBox4->Canvas->Pen->Color=clBtnFace;
          PaintBox4->Canvas->MoveTo(4+0,Y);
          PaintBox4->Canvas->LineTo(tw+30,Y);
          PaintBox4->Canvas->TextOut(tw+4,Y+6,AnsiString("                       "));
          PaintBox4->Canvas->TextOut(24,Y+6,"         ");
          PaintBox4->Canvas->TextOut(50,Y+6,"                        ");
          PaintBox4->Canvas->TextOut(84,Y+6,"               ");
          PaintBox4->Canvas->TextOut(110,Y+6,"                     ");
          PaintBox4->Canvas->TextOut(140,Y+6,"                      ");
          PaintBox4->Canvas->TextOut(170,Y+6,"                            ");
          PaintBox4->Canvas->TextOut(204,Y+6,"                ");
          PaintBox4->Canvas->TextOut(230,Y+6,"                        ");
          PaintBox4->Canvas->TextOut(264,Y+6,"                      ");
          PaintBox4->Canvas->TextOut(300,Y+6,"                         ");
          PaintBox4->Canvas->TextOut(334,Y+6,"                   ");
          PaintBox4->Canvas->TextOut(360,Y+6,"                          ");
   if(pd1==1)    //putdown
   {
            int ii0=icolor;
            PaintBox4->Canvas->Pen->Width=1;
            PaintBox4->Canvas->Pen->Style=psSolid;
            PaintBox4->Canvas->Pen->Color=RGB(210,20,ii0);
            PaintBox4->Canvas->MoveTo(4+0,Y);
            PaintBox4->Canvas->LineTo(140+150*4+30,Y);
            PaintBox4->Canvas->TextOutA(140+150*4-14,Y-13,str8[ii0]);
            mbdeep[ii0]=stdp1+Y*relv1;
            PaintBox4->Canvas->TextOutA(140+150*4-14,Y+3,AnsiString(FormatFloat("0.0",mbdeep[ii0])));
            pd1=0;
   }
      moveopen2=0;
       /*   else
          {
             PaintBox4->Canvas->Pen->Width=1;
             PaintBox4->Canvas->Pen->Style=psSolid;
             PaintBox4->Canvas->Pen->Color=clRed;
             float deep1;
             deep1=stdp1+Y*relv1;
                 for(int ii0=0;ii0<(izz-1);ii0++)
                 {
                   if(fabs(deep1-zzppsd[ii0])<0.01)
                   {

                     PaintBox4->Canvas->MoveTo(4+0,Y);
                     PaintBox4->Canvas->LineTo(140+150*4+30,Y);
                     PaintBox4->Canvas->TextOut(140+150*4+4,Y-14,str8[ii0]);
                     PaintBox4->Canvas->TextOut(140+150*4+4,Y+3,AnsiString(FormatFloat("0.0",zzppsd[ii0])));
                   }
                 }
          }   */
        PaintBox4Paint(Sender);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::N9Click(TObject *Sender)
{
    FILE *fp1; int totalnum;  float startd,end;

   String Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\";
   int ii0=0;



       float deep1;
       for(int i0=0;i0<stedp;i0++)
       {
          startd=a2[ii0][0]-2.8;               //n7-4-sp2038   S11----941.5
          end=a2[ii0][0]+2.8;                  //n7-4-sp2038   S12---end=a2[0][0]+0.8;
          totalnum=int((end-startd)/0.05);
          if(fabs(a[i0][0]-startd)<0.001)
         {
           GetFileName1(ccp0,ii0);
           String p1=str6[ii0];
           String Fname=Dir+p1;
           if(!DirectoryExists(Fname))
           {
             //throw Exception("Cannot create "+Fname);
             CreateDir(Fname);//文件夹不存在则创建
           }
           ss3=Fname+"\\"+newname1;
            fp1=fopen(ss3.c_str(),"wt");
            if(fp1)
            {
               fprintf(fp1,"%8.1f\n",a2[ii0][0]);
                for(int i=i0;i<i0+totalnum+1;i++)
                {
                   fprintf(fp1,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a[i][0],a[i][MN_pos],a[i][Rd_pos],a[i][DEN_pos],a[i][HAC_pos],a[i][Rxo_pos],a[i][GR_pos]);

                }
            }

            fclose(fp1);
          if(ii0<ie)ii0=ii0+1;
          while((a2[ii0][0]<0.1)&&(ii0<ie))
          {
           ii0=ii0+1;
           }
         }
        }


 // fclose(fp1);

}
//---------------------------------------------------------------------------

void __fastcall TForm1::N3Click(TObject *Sender)
{
//储层自动对比
  FILE *fp; int i2=7;ie1=0;
   fp=fopen(ss3.c_str(),"r");
        if(fp)
        {
         ie1=0;
         fscanf(fp,"%f",&S11d);
         S11d=StrToFloat(FormatFloat("0.00",S11d));
         while(feof(fp)==0)
         {
          for(int j=0;j<i2;j++)
           {
             fscanf(fp,"%f",&xcsj[ie1][j]);
             xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
            }
          ie1++;
           }
        }
  Guiyihua(1,ie1);//微电位归一化
  RMNmax=Cmax;
  RMNmin=Cmin;
  for(int i=0;i<ie1-1;i++)
  {
   I[i][0]=StrToFloat(FormatFloat("0.00",xcsj[i][0]));
   I[i][1]=(xcsj[i][1])/StrToFloat(FormatFloat("0.00",RMNmin));
   }
  Guiyihua(2,ie1);//深侧向归一化
  RDmax=Cmax;
  RDmin=Cmin;
  for(int i=0;i<ie1-1;i++)
  {
   I[i][2]=(xcsj[i][2])/StrToFloat(FormatFloat("0.00",RDmin));
  }
  Guiyihua(3,ie1);//密度归一化
  DENmax=Cmax;
  DENmin=Cmin;
  for(int i=0;i<ie1-1;i++)
  {
   I[i][3]=(xcsj[i][3])/StrToFloat(FormatFloat("0.00",DENmin));
  }
  Guiyihua(4,ie1);//声波归一化
  HACmax=Cmax;
  HACmin=Cmin;
  for(int i=0;i<ie1-1;i++)
  {
   I[i][4]=(xcsj[i][4])/StrToFloat(FormatFloat("0.00",HACmax));
  }
  Guiyihua(5,ie1);//声波归一化
  RXOmax=Cmax;
  RXOmin=Cmin;
  for(int i=0;i<ie1-1;i++)
  {
   I[i][5]=(xcsj[i][5])/StrToFloat(FormatFloat("0.00",RXOmax));
  }
    Guiyihua(6,ie1);//声波归一化
  GRmax=Cmax;
  GRmin=Cmin;
  for(int i=0;i<ie1-1;i++)
  {
   I[i][6]=(xcsj[i][6])/StrToFloat(FormatFloat("0.00",GRmax));
  }

  //Gauss函数 e=2.71828
  float t,o,p1,p2,p3,e=2.71828; int D=2;
 // t=float(ie1-1);
  t=0.8;
  o=2.0*sqrt(t);
  p1=pow(2.0*3.1415926*o,D/2.0);
 // PaintBox1->Canvas->TextOut(50,20+20,"p1= "+AnsiString(p1));
  for(int i=-1;i<ie1+1;i++)
  {
    for(int j=0;j<20;j++)
    {
     fi[i][j]=0.0;
     }
  }
  for(int i=0;i<ie1-1;i++)
  {
   p2=-(pow(I[i][1],2.0)+pow(I[i][2],2.0)+pow(I[i][3],2.0)+pow(I[i][4],2.0)+pow(I[i][5],2.0)+pow(I[i][6],2.0))/(2.0*t);
   fi[i][1]=fi[i-1][1]+I[i][1]*pow(e,p2)/p1;      //微电位特征值
   fi[i][2]=fi[i-1][2]+I[i][2]*pow(e,p2)/p1;      //深侧向特征值
   fi[i][3]=fi[i-1][3]+I[i][3]*pow(e,p2)/p1;      //密度特征值
   fi[i][4]=fi[i-1][4]+I[i][4]*pow(e,p2)/p1;      //声波特征值
   fi[i][5]=fi[i-1][5]+I[i][5]*pow(e,p2)/p1;      //微球特征值
   fi[i][6]=fi[i-1][6]+I[i][6]*pow(e,p2)/p1;      //伽马特征值
      if(fabs(I[i][0]-S11d)<0.001)
      {
          fi[1][11]=I[i][1]*pow(e,p2)/p1;      //S11微电位特征值
          fi[2][12]=I[i][2]*pow(e,p2)/p1;      //S11深侧向特征值
          fi[3][13]=I[i][3]*pow(e,p2)/p1;      //S11密度特征值
          fi[4][14]=I[i][4]*pow(e,p2)/p1;      //S11声波特征值
          fi[5][15]=I[i][5]*pow(e,p2)/p1;      //S11微球特征值
          fi[6][16]=I[i][6]*pow(e,p2)/p1;      //S11伽马特征值
 //  PaintBox2->Canvas->TextOut(50+150*0+4,10+i*20,"深度 "+AnsiString(I[i][0]));
 //  PaintBox2->Canvas->TextOut(100+150*2+4,80+i*20,"RMNmin "+AnsiString(FormatFloat("0.000",RMNmin)));
 //  PaintBox2->Canvas->TextOut(100+150*2+4,10+i*20,"I[1]--- "+AnsiString(I[i][1]));

      }
//   PaintBox2->Canvas->TextOut(50+150*0+4,10+i*20,"深度 "+AnsiString(I[i][0]));
//   PaintBox2->Canvas->TextOut(100+150*1+4,10+i*20,"点深度 "+AnsiString(S11d));
//   PaintBox2->Canvas->TextOut(100+150*2+4,10+i*20,"fiden "+AnsiString(fi[i][3]));
//   PaintBox2->Canvas->TextOut(100+150*3+4,10+i*20,"HAC=I "+AnsiString(fi[i][4]));
//   PaintBox2->Canvas->TextOut(100+150*4+4,10+i*20,"p2= "+AnsiString(p2));
//   PaintBox4->Canvas->TextOut(100+150*0+4,10+i*20,"pow "+AnsiString(pow(e,p2)));
//   PaintBox2->Canvas->TextOut(100+150*1+4,10+i*20,"RD=I "+AnsiString(I[i][2]));
//   PaintBox4->Canvas->TextOut(100+150*2+4,10+i*20,"RD=pow*I "+AnsiString(I[i][2]*pow(e,p2)));
//   PaintBox2->Canvas->TextOut(110+150*3+4,10+i*20,"p1 "+AnsiString(p1));
//   PaintBox4->Canvas->TextOut(10+150*4+4,10+i*20,"POW/p1= "+AnsiString(pow(e,p2)/p1));

   }
   Gausstezhengzhipanduan(ie1);       //Gauss特征值判断层位

//   PaintBox2->Canvas->TextOut(100+150*4+4,10,"ie1= "+AnsiString(ie1));
//   PaintBox2->Canvas->TextOut(100+150*4+4,30,"RD= "+AnsiString(fi1[2][12]));
//   PaintBox2->Canvas->TextOut(100+150*4+4,70,"DEN= "+AnsiString(fi1[3][13]));
//   PaintBox2->Canvas->TextOut(100+150*4+4,90,"HAC= "+AnsiString(fi1[4][14]));
// paintfenceng1(Sender);
 fclose(fp);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Guiyihua(int i,int ie)
{
  float xsj0[500],p1;

 //  ie=ie+1;
  for(int i1=0;i1<ie-1;i1++)
  {
   xsj0[i1]=xcsj[i1][i];
  }
  for(int i1=0;i1<ie-2;i1++)
   {
    for(int i2=i1+1;i2<ie-1;i2++)
     {
        if(xsj0[i1]<xsj0[i2])
        {
         p1=xsj0[i1];
         xsj0[i1]=xsj0[i2];
         xsj0[i2]=p1;
         }
      }
    }
   Cmax=StrToFloat(FormatFloat("0.00",xsj0[0]));
   Cmin=StrToFloat(FormatFloat("0.00",xsj0[ie-2]));
    if(Cmin<0.50)Cmin=0.50;
   if(Cmax<1.2)Cmax=1.2;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::Gausshanshutezhengzhi(int ie)
{
  //Gauss函数 e=2.71828
  float t,o,p1,p2,p3,e=2.71828; int D=2;
 // t=float(ie-1);
 //ie=ie+1;
  t=0.8;
  o=2.0*sqrt(t);
  p1=pow(2.0*3.1415926*o,D/2.0);
    for(int i=-1;i<ie+1;i++)
  {
    for(int j=0;j<20;j++)
    {
     fi1[i][j]=0.0;
     }
  }

  for(int i=0;i<ie-1;i++)
  {
   p2=-(pow(I1[i][1],2.0)+pow(I1[i][2],2.0)+pow(I1[i][3],2.0)+pow(I1[i][4],2.0)+pow(I1[i][5],2.0)+pow(I1[i][6],2.0))/(2.0*t);
   fi1[i][1]=fi1[i-1][1]+I1[i][1]*pow(e,p2)/p1;      //微电位特征值
   fi1[i][2]=fi1[i-1][2]+I1[i][2]*pow(e,p2)/p1;      //深侧向特征值
   fi1[i][3]=fi1[i-1][3]+I1[i][3]*pow(e,p2)/p1;      //密度特征值
   fi1[i][4]=fi1[i-1][4]+I1[i][4]*pow(e,p2)/p1;      //声波特征值
   fi1[i][5]=fi1[i-1][5]+I1[i][5]*pow(e,p2)/p1;      //微球特征值
   fi1[i][6]=fi1[i-1][6]+I1[i][6]*pow(e,p2)/p1;      //伽马特征值

   fi1[i][11]=I1[i][1]*pow(e,p2)/p1;      //微电位特征值
   fi1[i][12]=I1[i][2]*pow(e,p2)/p1;      //深侧向特征值
   fi1[i][13]=I1[i][3]*pow(e,p2)/p1;      //密度特征值
   fi1[i][14]=I1[i][4]*pow(e,p2)/p1;      //声波特征值
   fi1[i][15]=I1[i][5]*pow(e,p2)/p1;      //声波特征值
   fi1[i][16]=I1[i][6]*pow(e,p2)/p1;      //声波特征值
 //  PaintBox4->Canvas->TextOut(50+150*0+4,10+i*20,"p2= "+AnsiString(I1[i][6]));
  //  PaintBox4->Canvas->TextOut(10+150*3+4,10+i*20,"POW= "+AnsiString(pow(e,p2)/p1));
 //   PaintBox4->Canvas->TextOut(100+150*1+4,10+i*20,"I5= "+AnsiString(I1[i][5]));
   }
}
//------------------------------------------------------------------------------
void __fastcall TForm1::Guiyihua1(int i,int ie)
{
  float xsj[500][15],Cmax1[300],Cmin1[300],p1; int n=7;
 // ie=ie+1;
  for(int j1=0;j1<n;j1++)
   {
    for(int i1=0;i1<ie-1;i1++)
    {
      xsj[i1][j1]=1.0;
      I1[i1][j1]=1.0;
      }
    }
  for(int i1=i;i1<i+ie-1;i1++)
  {
     xsj[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]));
      xsj[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]));
       xsj[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]));
        xsj[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]));
          xsj[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]));
           xsj[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]));
  }
 for(int j1=1;j1<n;j1++)
 {
  for(int i1=0;i1<ie-2;i1++)
   {
    for(int i2=i1+1;i2<ie-1;i2++)
     {
        if(xsj[i1][j1]<xsj[i2][j1])
        {
         p1=xsj[i1][j1];
         xsj[i1][j1]=xsj[i2][j1];
         xsj[i2][j1]=p1;
         }
      }
    }
   Cmax1[j1]=StrToFloat(FormatFloat("0.00",xsj[0][j1]));
   Cmin1[j1]=StrToFloat(FormatFloat("0.00",xsj[ie-2][j1]));
   if(Cmin1[j1]<0.50)Cmin1[j1]=0.50;
   if(Cmax1[j1]<1.2)Cmax1[j1]=1.2;
 }
  RMNmin1=Cmin1[1];
  for(int i1=i;i1<i+ie-1;i1++)
  {
   I1[i1-i][0]=StrToFloat(FormatFloat("0.00",a1[i1][0]));
   I1[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[1]));   //微电位归一化
   I1[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[2])); //深侧向归一化
   I1[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[3])); //密度归一化
   I1[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[4])); //声波归一化
   I1[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[5])); //微球归一化
   I1[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[6])); //伽马归一化
  // PaintBox2->Canvas->TextOut(50+150*0+4,10+(i1-i)*20,"p2-I6= "+AnsiString(I1[i1-i][6]));
  //  PaintBox2->Canvas->TextOut(10+150*3+4,10+(i1-i)*20,"Cmax1[6]= "+AnsiString(Cmax1[6]));
  //  PaintBox2->Canvas->TextOut(100+150*1+4,10+(i1-i)*20,"I5= "+AnsiString(I1[i1-i][5]));
  }

}
//------------------------------------------------------------------------------
void __fastcall TForm1::Gausstezhengzhipanduan(int ie)
{
 // ie=ie+1;
   float Gmn1[500][15],Gmn2[500][15],GRd1[500][15],GRd2[500][15];
   float GAc1[500][15],GAc2[500][15],d1=10.0,d2=10.0,d3=10.0,d4=10.0,d5=10.0;
   int Gm1=0,Gm2=0,Gd1=0,Gd2=0,Gen1=0,Gen2=0,Gc1=0,Gc2=0,Gxo01=0,Gxo02=0;
   float Gxo1[500][15],Gxo2[500][15],Ggr1[500][15],Ggr2[500][15];
   float GDEN2[500][15],GDEN1[500][15],d6=10.0,deep[15];
   int Ggr01=0,Ggr02=0;
   stedp1=stedp1;
for(int i1=0;i1<stedp1-ie-2;i1++)
 {
//  if(fabs(a1[i1][0]-940.6)<0.01)
//  {
  Guiyihua1(i1,ie);
  Gausshanshutezhengzhi(ie);
 for(int i=0;i<ie-1;i++)
  {
/*    PaintBox4->Canvas->TextOut(100+150*2+4,10+i*20,"Rd= "+AnsiString(FormatFloat("0.00",a1[i1+i][Rd1_pos])));
   PaintBox4->Canvas->TextOut(150+150*1+4,10+i*20,"RMN= "+AnsiString(FormatFloat("0.00",a1[i1+i][MN1_pos])));
   PaintBox2->Canvas->TextOut(100+150*0+4,10+i*20,"f1[11]= "+AnsiString(FormatFloat("0.000",I1[i][0])));
   PaintBox2->Canvas->TextOut(100+150*3+4,10+i*20,"f1[12]= "+AnsiString(fabs(fi1[i][12])));
   PaintBox2->Canvas->TextOut(100+150*1+4,10+i*20,"f[12]= "+AnsiString(fabs(fi[2][12])));
   PaintBox4->Canvas->TextOut(100+150*0+4,10+i*20,"fi1[12]-fi[12]= "+AnsiString(fabs(fi1[i][12]-fi[2][12])));
   PaintBox4->Canvas->TextOut(100+150*3+4,10+i*20,"I1[1]--- "+AnsiString(I1[i][1]));
    }
  }
 }  */
   for(int i8=0;i8<ie-1;i8++)
  {
   if(fabs(fi1[i8][11]-fi[1][11])<d1)
   {
     d1=fabs(fi1[i8][11]-fi[1][11]);
     deep[1]=StrToFloat(FormatFloat("0.00",a1[i1+i8][0]));
     }
   if(fabs(fi1[i8][12]-fi[2][12])<d2)
   {
    d2=fabs(fi1[i8][12]-fi[2][12]);
    deep[2]=StrToFloat(FormatFloat("0.00",a1[i1+i8][0]));
    }
   if(fabs(fi1[i8][13]-fi[3][13])<d3)
   {
     d3=fabs(fi1[i8][13]-fi[3][13]);
     deep[3]=StrToFloat(FormatFloat("0.00",a1[i1+i8][0]));
     }
   if(fabs(fi1[i8][14]-fi[4][14])<d4)
   {
     d4=fabs(fi1[i8][14]-fi[4][14]);
     deep[4]=StrToFloat(FormatFloat("0.00",a1[i1+i8][0]));
     }
    if(fabs(fi1[i8][15]-fi[5][15])<d5)
   {
     d5=fabs(fi1[i8][15]-fi[5][15]);
     deep[5]=StrToFloat(FormatFloat("0.00",a1[i1+i8][0]));
     }
    if(fabs(fi1[i8][16]-fi[6][16])<d6)
   {
     d6=fabs(fi1[i8][16]-fi[6][16]);
     deep[6]=StrToFloat(FormatFloat("0.00",a1[i1+i8][0]));
     }
   }

   if(fabs((fi1[i][1]-fi[i][1])*10000.0)<0.003)
   {
     Gmn1[Gm1][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     Gmn1[Gm1][1]=fabs(fi1[i][1]-fi[i][1]);
     PaintBox2->Canvas->TextOut(100+150*0+4,10+Gm1*20,"bestRMN1  "+AnsiString(FormatFloat("0.0",Gmn1[Gm1][0])));
     Gm1=Gm1+1;
    }
   if(fabs((fi1[i][11]-fi[1][11])*10000.0)<0.003)
   {
     Gmn2[Gm2][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     Gmn2[Gm2][1]=fabs(fi1[i][11]-fi[1][11]);
     PaintBox4->Canvas->TextOut(100+150*1+4,10+Gm2*20,"bestRMN2  "+AnsiString(FormatFloat("0.0",Gmn2[Gm2][0])));
     Gm2=Gm2+1;
    }
    if(fabs((fi1[i][2]-fi[i][2])*10000.0)<0.003)
   {
     GRd1[Gd1][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     GRd1[Gd1][1]=fabs(fi1[i][2]-fi[i][2]);
     PaintBox4->Canvas->TextOut(0+150*2+4,10+Gd1*20,"bestRd1  "+AnsiString(FormatFloat("0.0",GRd1[Gd1][0])));
     Gd1=Gd1+1;
    }
   if(fabs((fi1[i][12]-fi[2][12])*10000.0)<0.004)
   {
     GRd2[Gd2][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     GRd2[Gd2][1]=fabs(fi1[i][12]-fi[2][12]);
     PaintBox4->Canvas->TextOut(100+150*3+4,10+Gd2*20,"bestRd2  "+AnsiString(FormatFloat("0.0",GRd2[Gd2][0])));
     Gd2=Gd2+1;
    }
    if(fabs((fi1[i][3]-fi[i][3])*10000.0)<0.003)
   {
     GDEN1[Gen1][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     GDEN1[Gen1][1]=fabs(fi1[i][3]-fi[i][3]);
     PaintBox4->Canvas->TextOut(150+150*0+4,10+Gen1*20,"bestDEN1 "+AnsiString(FormatFloat("0.0",GDEN1[Gen1][0])));
     Gen1=Gen1+1;
    }
   if(fabs((fi1[i][13]-fi[3][13])*10000.0)<0.004)
   {
     GDEN2[Gen2][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     GDEN2[Gen2][1]=fabs(fi1[i][13]-fi[3][13]);
     PaintBox4->Canvas->TextOut(100+150*2+4,10+Gen2*20,"bestDEN2 "+AnsiString(FormatFloat("0.0",GDEN2[Gen2][0])));
     Gen2=Gen2+1;
    }
    if(fabs((fi1[i][4]-fi[i][4])*10000.0)<0.003)
   {
     GAc1[Gc1][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     GAc1[Gc1][1]=fabs(fi1[i][4]-fi[i][4]);
     PaintBox4->Canvas->TextOut(100+150*2+4,10+Gc1*20,"bestHAC1 "+AnsiString(FormatFloat("0.0",GAc1[Gc1][0])));
     Gc1=Gc1+1;
    }
   if(fabs((fi1[i][14]-fi[4][14]))*10000.0<0.004)
   {
     GAc2[Gc2][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     GAc2[Gc2][1]=fabs(fi1[i][14]-fi[4][14]);
     PaintBox4->Canvas->TextOut(100+150*4+4,10+Gc2*20,"bestHAC2 "+AnsiString(FormatFloat("0.0",GAc2[Gc2][0])));
     Gc2=Gc2+1;

    }
    if(fabs((fi1[i][5]-fi[i][5])*10000.0)<0.003)
   {
     Gxo1[Gxo01][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     Gxo1[Gxo01][1]=fabs(fi1[i][5]-fi[i][5]);
     PaintBox2->Canvas->TextOut(100+150*2+4,10+Gxo01*20,"bestRXO1 "+AnsiString(FormatFloat("0.0",Gxo1[Gxo01][0])));
     Gxo01=Gxo01+1;
    }
   if(fabs((fi1[i][15]-fi[5][15]))*10000.0<0.004)
   {
     Gxo2[Gxo02][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     Gxo2[Gxo02][1]=fabs(fi1[i][15]-fi[5][15]);
     PaintBox2->Canvas->TextOut(100+150*3+4,10+Gxo02*20,"bestRXO2 "+AnsiString(FormatFloat("0.0",Gxo2[Gxo02][0])));
     Gxo02=Gxo02+1;

    }
     if(fabs((fi1[i][5]-fi[i][5])*10000.0)<0.003)
   {
     Ggr1[Ggr01][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     Ggr1[Ggr01][1]=fabs(fi1[i][5]-fi[i][5]);
     PaintBox2->Canvas->TextOut(100+150*1+4,10+Ggr01*20,"bestGR1 "+AnsiString(FormatFloat("0.0",Ggr1[Ggr01][0])));
     Ggr01=Ggr01+1;
    }
   if(fabs((fi1[i][15]-fi[5][15]))*10000.0<0.004)
   {
     Ggr2[Ggr02][0]=StrToFloat(FormatFloat("0.00",a1[i1+i][0]));
     Ggr2[Ggr02][1]=fabs(fi1[i][15]-fi[5][15]);
     PaintBox2->Canvas->TextOut(100+150*4+4,10+Ggr02*20,"bestGR2 "+AnsiString(FormatFloat("0.0",Ggr2[Ggr02][0])));
     Ggr02=Ggr02+1;

    }

   }

 }
   PaintBox2->Canvas->TextOut(100+150*0+4,10+1*20,"bestdeep1  "+AnsiString(FormatFloat("0.0",deep[1])));
   PaintBox2->Canvas->TextOut(100+150*0+4,10+2*20,"bestdeep2  "+AnsiString(FormatFloat("0.0",deep[2])));
   PaintBox2->Canvas->TextOut(100+150*0+4,10+3*20,"bestdeep3  "+AnsiString(FormatFloat("0.0",deep[3])));
   PaintBox2->Canvas->TextOut(100+150*0+4,10+4*20,"bestdeep4  "+AnsiString(FormatFloat("0.0",deep[4])));
   PaintBox2->Canvas->TextOut(100+150*0+4,10+5*20,"bestdeep5  "+AnsiString(FormatFloat("0.0",deep[5])));
   PaintBox2->Canvas->TextOut(100+150*0+4,10+6*20,"bestdeep6  "+AnsiString(FormatFloat("0.0",deep[6])));
 paixu(Gm1,Gmn1);
 bestdp1[0]=StrToFloat(FormatFloat("0.00",bestdp0)); //PaintBox4->Canvas->TextOut(100+150*4+4,30+1*20,"best "+AnsiString(1)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gm2,Gmn2);
 bestdp1[1]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+2*20,"best "+AnsiString(2)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gd1,GRd1);
 bestdp1[2]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+3*20,"best "+AnsiString(3)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gd2,GRd2);
 bestdp1[3]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+4*20,"best "+AnsiString(4)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gen1,GDEN1);
 bestdp1[4]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+5*20,"best "+AnsiString(5)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gen2,GDEN2);
 bestdp1[5]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+6*20,"best "+AnsiString(6)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gc1,GAc1);
 bestdp1[6]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+7*20,"best "+AnsiString(7)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gc2,GAc2);
 bestdp1[7]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+8*20,"best "+AnsiString(8)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
  paixu(Gxo01,Gxo1);
 bestdp1[8]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+7*20,"best "+AnsiString(7)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Gxo02,Gxo2);
 bestdp1[9]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+8*20,"best "+AnsiString(8)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
  paixu(Ggr01,Ggr1);
 bestdp1[10]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+7*20,"best "+AnsiString(7)+"   "+AnsiString(FormatFloat("0.0",bestdp)));
 paixu(Ggr02,Ggr2);
 bestdp1[11]=StrToFloat(FormatFloat("0.00",bestdp0));// PaintBox4->Canvas->TextOut(100+150*4+4,30+8*20,"best "+AnsiString(8)+"   "+AnsiString(FormatFloat("0.0",bestdp)));

 int i3;
 for(int i1=1;i1<11;i1++)
 {
  for(int i2=i1+2;i2<12;i2++)
   {
     if((fabs(bestdp1[i1]-bestdp1[i2])<0.001)&&((bestdp1[i1]>1.)||(bestdp1[i2]>1.0)))
      {
        bestdeep=StrToFloat(FormatFloat("0.00",bestdp1[i1]));
    //    i3=int(float(i1)/2.0)*2;
     //    if(i3<i1)
         {
          PaintBox4->Canvas->TextOut(90+150*4,210+i1*20,"best point( "+AnsiString(i1)+")=   "+AnsiString(bestdeep));
         }
      }
    }
   }

}
//------------------------------------------------------------------------------
void __fastcall TForm1::paixu(int nn,float mn[500][15])
{
  float p;
  for(int i1=0;i1<nn-2;i1++)
   {
    for(int i2=i1+1;i2<nn-1;i2++)
    {
     if(mn[i1][1]>mn[i2][1])
     {
      p=mn[i1][0];
      mn[i1][0]=mn[i2][0];
      mn[i2][0]=p;
      p=mn[i1][1];
      mn[i1][1]=mn[i2][1];
      mn[i2][1]=p;
      }
     }
    }
    bestdp0=mn[0][0];
//    PaintBox2->Canvas->TextOut(10+150*2+4,10+nn*20,"best***"+AnsiString(bestdp));
}
//------------------------------------------------------------------------------
void __fastcall TForm1::N10Click(TObject *Sender)
{
    n=6; i01=0;
   FILE *fp; int i2=7;ie1=0;AnsiString Dir;
   Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\S11\\";
   TSearchRec sr;
   TStringList *FileList = new TStringList();
//   TStrings *FileList;
if (FindFirst(Dir + "\\*.*", faAnyFile, sr) == 0)
{
do{
   FileList->Add(Dir + "\\" + sr.Name);
   i01=i01+1;
   fp=fopen((Dir + sr.Name).c_str(),"r");
        if(fp&&(FileList!="0"))
        {
         ie1=0;
         fscanf(fp,"%f",&S11d);
         S11d=StrToFloat(FormatFloat("0.00",S11d));
         while(feof(fp)==0)
         {
          for(int j=0;j<i2;j++)
           {
             fscanf(fp,"%f",&xcsj[ie1][j]);
             if((j==4)||(j==6))
             {
              if(xcsj[ie1][j]<1.0)xcsj[ie1][j]=1.0;
              xcsj[ie1][j]=1.0/StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
              }
              else
             xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
            }
          ie1++;
           }
        }
      PaintBox1->Canvas->TextOut(10+4,15,"打开井数=  "+AnsiString(i01));
 /*  fp=fopen("D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\S11","r");
        if(fp)
        {
         ie1=0;
         fscanf(fp,"%f",&S11d);
         S11d=StrToFloat(FormatFloat("0.00",S11d));
         while(feof(fp)==0)
         {
          for(int j=0;j<i2;j++)
           {
             fscanf(fp,"%f",&xcsj[ie1][j]);
             xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
            }
          ie1++;
           }
        } */
   for(is=0;is<ie1-n-1;is++)
   {
      if(fabs(S11d-xcsj[is+2][0])<0.002)
      {
       readData(Sender);
       power(Sender);   //求特征值及特征向量
       tzzbz[0]=m;                  //Image1->Canvas->TextOutA(350,10+(0)*25,AnsiString(m));
         for(int i=1;i<=n;i++)
          {
           tzzbz[i]=next_z[i];      //特征值标准
                                    //  Image1->Canvas->TextOutA(350,30+(i)*25,AnsiString(next_z[i]));
           }
    //    readData(Sender);
        calCovariation(A);            //求协方差矩阵
        for(int i=0;i<n;i++)
        {
          for(int j=0;j<n;j++)
           {
            A[i+1][j+1]=dst[i][j];
            }
          }
        power(Sender);
        xfcbz[0]=m;
         for(int i=1;i<=n;i++)
          {
           xfcbz[i]=next_z[i];// PaintBox4->Canvas->TextOutA(50,30+(i)*25,"协方差"+AnsiString(FormatFloat("0.000",next_z[i])));

           }
       }

    }
  Cacu(Sender);
   }while(FindNext(sr) == 0);
    FindClose(sr);
   }

 //   return 0;
  fclose(fp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::reckonResidue(TObject *Sender)
{
    float sum=0;
    for (int i=1;i<=n;i++)
    {
        sum+=abs(z[i]-next_z[i]);
    }
    if((sum<0.001)||(open1>1000))
    {
        flag=1;
    }
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::readData(TObject *Sender)
{
    for (int j=1;j<=n;j++)
      {
        sun[j]=0.0;
         for (int i=1;i<=n;i++)
         {
            //  cin>>A[i][j];
            A[i][j]=xcsj[is+i-1][j];
            sun[j]=sun[j]+A[i][j];
          }
         for(int i=1;i<=n;i++)
         {
           A[i][j]=A[i][j]-sun[j]/float(n);
         }
       }

    return ;
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::power(TObject *Sender)
{
    m=next_m;
    open1=0;
    flag=0;
    eclipse=1e-5;
    for (int i=1;i<=n;i++)
    {
        z[i]=1;
        next_z[i]=1;
    }
    do
    {
        sum=0;open1=open1+1;
        for (int i=1;i<=n;i++)
            z[i]=next_z[i];
        matrixFact(Sender);
        Findmax(Sender);
        newZ(Sender);
        reckonResidue(Sender);
    }while (!flag);
    printResult(Sender);
    return ;
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::matrixFact(TObject *Sender)
{
    for (int i=1;i<=n;i++)
    {
        sum=0;
        for (int j=1;j<=n;j++)
        {
            sum+=A[i][j]*z[j];
        }
        y[i]=sum;
    }
    for (int i=1;i<=n;i++)
    {
        cout<<y[i]<<" ";
    }
    cout<<endl;
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::Findmax(TObject *Sender)
{
    m=0;
    for (int i=1;i<=n;i++)
    {
        if (fabs(m)<fabs(y[i]))
        {
            m=y[i];
        }
    }
   // cout<<"m:"<<m<<endl;
 //   Image1->Canvas->TextOutA(10,10,"矩阵A的最大特征值为:"+AnsiString(m));
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::newZ(TObject *Sender)
{
    if(fabs(m)<0.0001)m=0.0001;//if(fabs(m)<0.000001)m=0.0001;
    for (int i=1;i<=n;i++)
    {
        next_z[i]=y[i]/m;
    }
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::printResult(TObject *Sender)
{
   // cout<<"矩阵A的最大特征值为:"<<m<<endl;
   // cout<<"其对应的特征向量为:(";
 //  Image1->Canvas->TextOutA(10+10,10,"矩阵A的最大特征值为:m= "+AnsiString(FormatFloat("0.000",m)));

    for (int i=1;i<=n;i++)
    {
       // cout<<next_z[i];
     //   Image1->Canvas->TextOutA(10,30+(i)*25,"其对应的特征向量为:("+AnsiString(next_z[i])+")");
        if (i!=n)
        {
           // cout<<",";
        }
    }
   // cout<<")"<<endl;
    return ;
}
//----------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Cacu(TObject *Sender)
{
     int ip=0,ip2=0; int op1=0,op2=0;
     for(int io=0;io<stedp1-n;io++)
    {
     //  Image1->Canvas->TextOutA(550,10+(is)*20,AnsiString(data[io-2][0]));
       for(int i=1;i<=n;i++)
        {
            A1[i][1]=a1[io+i-1][MN1_pos];
            A1[i][2]=a1[io+i-1][Rd1_pos];
            A1[i][3]=a1[io+i-1][DEN1_pos];
            if(a1[io+i-1][HAC1_pos]<1.0)a1[io+i-1][HAC1_pos]=1.0;
            A1[i][4]=1.0/a1[io+i-1][HAC1_pos];
            A1[i][5]=a1[io+i-1][Rxo1_pos];
            if(a1[io+i-1][GR1_pos]<1.0)a1[io+i-1][GR1_pos]=1.0;
            A1[i][6]=1.0/a1[io+i-1][GR1_pos];
         }


        for (int j=1;j<=n;j++)
        {
             sun1[j]=0.0;
             for (int i=1;i<=n;i++)
             {
                //  cin>>A[i][j];
                 sun1[j]=sun1[j]+A1[i][j];
             }
             for(int i=1;i<=n;i++)
             {
                 A1[i][j]=A1[i][j]-sun1[j]/float(n);
             }
         }
       power1(Sender); //矩阵特征值及特征向量
          for(int i=1;i<=n;i++)
          {
              if((next_z1[i]!=0)&&(next_z1[i]!=1)&&(fabs(tzzbz[i]-next_z1[i])<0.008||fabs(tzzbz[0]-m1)<0.008)) //next_z1[i]=1是否该舍去，需要考量
            // if((fabs(tzzbz[i]-next_z1[i])<0.0008||fabs(tzzbz[0]-m1)<0.0008))
              {
                op1=1;
                bestdp[ip][0]=m1;
                bestdp[ip][i]=next_z1[i];
                bestdp[ip][n+1]=a1[io+2][0];
              }
           }
           if(op1==1)
           {
             ip=ip+1;
             op1=0;
            }

        calCovariation(A1);         //计算协方差矩阵
        for(int i=0;i<n;i++)
        {
          for(int j=0;j<n;j++)
           {
            A1[i+1][j+1]=dst[i][j];
            }
          }
          power1(Sender);
        //求取协方差矩阵特征值及特征向量，并存入数组中
         for(int i=1;i<=n;i++)
          {
              if((next_z1[i]!=0)&&(next_z1[i]!=1)&&(fabs(xfcbz[i]-next_z1[i])<0.008||fabs(xfcbz[0]-m1)<0.008)) //next_z1[i]=1是否该舍去，需要考量
             // if((fabs(xfcbz[i]-next_z1[i])<0.0008||fabs(xfcbz[0]-m1)<0.0008))
              {
                op2=1;
                xfcdp[ip2][0]=m1;
                xfcdp[ip2][i]=next_z1[i];
                xfcdp[ip2][n+1]=a1[io+2][0];
              }
           }
          if(op2==1)
          {
           ip2=ip2+1;
           op2=0;
           }
      }

     int iu=0;
     for(int i=0;i<ip;i++)
     {
        for(int j=0;j<ip2;j++)
        {
            if(fabs(bestdp[i][n+1]-xfcdp[j][n+1])<0.00001)
            {
             if(i01<6)
             PaintBox2->Canvas->TextOutA(20+i01*120,4+(iu)*20,"最佳匹配深度 : "+AnsiString(FormatFloat("0.0",bestdp[i][n+1])));
             else
             PaintBox4->Canvas->TextOutA(20+(i01-6)*120,4+(iu)*20,"最佳匹配深度 : "+AnsiString(FormatFloat("0.0",bestdp[i][n+1])));
             iu++;
             }
         }
      }
     if(iu==0)
     {
      PaintBox4->Canvas->TextOutA(150,40+(iu)*25,"未能找到最佳匹配深度 : "+AnsiString(0));
      }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::power1(TObject *Sender)
{
    m1=next_m;
  //  m1=n;
    open=0;
    flag=0;
    eclipse=1e-5;
    for (int i=1;i<=n;i++)
    {
        z1[i]=1;
        next_z1[i]=1;
    }
    do
    {
        sum=0; open=open+1;
        for (int i=1;i<=n;i++)
            z1[i]=next_z1[i];
        matrixFact1(Sender);
        Findmax1(Sender);
        newZ1(Sender);
        reckonResidue1(Sender);
    }while (!flag);
    printResult1(Sender);
    return ;
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::matrixFact1(TObject *Sender)
{
    for (int i=1;i<=n;i++)
    {
        sum=0;
        for (int j=1;j<=n;j++)
        {
            sum+=A1[i][j]*z1[j];
        }
        y1[i]=sum;
    }
    for (int i=1;i<=n;i++)
    {
        cout<<y1[i]<<" ";
    }
    cout<<endl;
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::Findmax1(TObject *Sender)
{
    m1=0;
    for (int i=1;i<=n;i++)
    {
        if (fabs(m1)<fabs(y1[i]))
        {
            m1=y1[i];
        }
    }
   // cout<<"m:"<<m<<endl;
 //   Image1->Canvas->TextOutA(10,10,"矩阵A的最大特征值为:"+AnsiString(m));
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::newZ1(TObject *Sender)
{
    if(fabs(m1)<0.0001)m1=0.0001;
    for (int i=1;i<=n;i++)
    {
        next_z1[i]=y1[i]/m1;
    }
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::printResult1(TObject *Sender)
{
   // cout<<"矩阵A的最大特征值为:"<<m<<endl;
   // cout<<"其对应的特征向量为:(";
 //  Image1->Canvas->TextOutA(10+10,25,"矩阵A的最大特征值为:m1= "+AnsiString(m1));

    for (int i=1;i<=n;i++)
    {
       // cout<<next_z[i];
   //     Image1->Canvas->TextOutA(10,30+(i)*25,"其对应的特征向量为:("+AnsiString(next_z1[i])+")");
        if (i!=n)
        {
           // cout<<",";
        }
    }
   // cout<<")"<<endl;
    return ;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::reckonResidue1(TObject *Sender)
{
    float sum=0;
    for (int i=1;i<=n;i++)
    {
        sum+=fabs(z1[i]-next_z1[i]);
    }
    if((sum<0.001)||(open>1000))
    {
        flag=1;
    }
    return ;
}
//----------------------------------------------------------------------------
//计算协方差
float __fastcall TForm1::calCovariation(float aa[500][50])
{
   int i, j, k;
//doubleVector tempDst(inputTrain[0].size(), 0);
//vector<doubleVector> dst(inputTrain.size(), tempDst);

for(i=0;i<n;i++)
{
  Input_Meam[i]= 0;
}
for(i=0;i<n;i++)
{
 for(j=0;j<n;j++)
  {
   inputTrain[i][j]=aa[i+1][j+1];
   dst[i][j]=0.0;
   }
  }

//计算均值
for(i=0;i<n;i++)
{
   for(j=0;j<n;j++)
   {
    Input_Meam[i] += inputTrain[j][i];
   }
Input_Meam[i] = Input_Meam[i]/float(n);
}

//计算协方差
for(i=0; i<n; i++)
{
  for(j=0; j<n; j++)
  {
    for(k=0; k<n; k++)
    {
     dst[i][j]=dst[i][j]+(inputTrain[k][i]-Input_Meam[i])*(inputTrain[k][j]-Input_Meam[j]);
    }
     dst[i][j]=dst[i][j]/(n-1);
   }
}

//return dst;
 }
//使用Jacobi计算协方差的特征值和特征矩阵
//-----------------------------------------------------------------------------
//计算目的层段各曲线平均值
void __fastcall TForm1::pingjunzhi(TObject *Sender)
{
     n=6;int i01=0;
   FILE *fp; int i2=7;ie1=0;AnsiString Dir;
   Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\S11\\";
   TSearchRec sr;
   TStringList *FileList = new TStringList();
//   TStrings *FileList;
if (FindFirst(Dir + "\\*.*", faAnyFile, sr) == 0)
{
do{
    FileList->Add(Dir + "\\" + sr.Name);

    fp=fopen((Dir + sr.Name).c_str(),"r");
        if(fp&&(FileList!="0"))
        {
         ie1=0; i01=i01+1;  //计算打开非零文件个数
         fscanf(fp,"%f",&S11d);
         S11d=StrToFloat(FormatFloat("0.00",S11d));
           while(feof(fp)==0)
           {
            for(int j=0;j<i2;j++)
             {
               fscanf(fp,"%f",&xcsj[ie1][j]);
               xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
              }
               ie1++;
             }
           SMN=0.0;SRD=0.0;SDEN=0.0;SHAC=0.0;SRXO=0.0;SGR=0.0;
    //       PaintBox2->Canvas->TextOutA(20,260+i01*20,"IE1值="+AnsiString(ie1));
           Guiyihua(1,ie1);//微电位归一化
           RMNmax=Cmax; PaintBox2->Canvas->TextOutA(220,60,"S11微电极最大值"+AnsiString(RMNmax));
           RMNmin=Cmin; PaintBox2->Canvas->TextOutA(220,80,"S11微电极最小值"+AnsiString(RMNmin));
           if(RMNmax<1.0)RMNmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
             I[i][0]=StrToFloat(FormatFloat("0.00",xcsj[i][0]));
             I[i][1]=(xcsj[i][1])/StrToFloat(FormatFloat("0.00",RMNmax));
           }
           Guiyihua(2,ie1);//深侧向归一化
           RDmax=Cmax;
           RDmin=Cmin;
           if(RDmax<1.0)RDmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][2]=(xcsj[i][2])/StrToFloat(FormatFloat("0.00",RDmax));
           }
           Guiyihua(3,ie1);//密度归一化
           DENmax=Cmax;
           DENmin=Cmin;
           if(DENmax<1.0)DENmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
             I[i][3]=(xcsj[i][3])/StrToFloat(FormatFloat("0.00",DENmax));
           }
           Guiyihua(4,ie1);//声波归一化
           HACmax=Cmax;
           HACmin=Cmin;
           if(HACmax<1.0)HACmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][4]=(xcsj[i][4])/StrToFloat(FormatFloat("0.00",HACmax));
           }
           Guiyihua(5,ie1);//微球归一化
           RXOmax=Cmax;
           RXOmin=Cmin;
           if(RXOmax<1.0)RXOmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][5]=(xcsj[i][5])/StrToFloat(FormatFloat("0.00",RXOmax));
           }
           Guiyihua(6,ie1);//伽马归一化
           GRmax=Cmax;
           GRmin=Cmin;
           if(GRmax<1.0)GRmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][6]=(xcsj[i][6])/StrToFloat(FormatFloat("0.00",GRmax));
           }
             for(int iu=0;iu<ie1-1;iu++)
              {
               SMN=SMN+I[iu][1];
               SRD=SRD+I[iu][2];
               SDEN=SDEN+I[iu][3];
               SHAC=SHAC+I[iu][4];
               SRXO=SRXO+I[iu][5];
               SGR=SGR+I[iu][6];
              }
              SMN=SMN/float(ie1-1);
              SRD=SRD/float(ie1-1);
              SDEN=SDEN/float(ie1-1);
              SHAC=SHAC/float(ie1-1);
              SRXO=SRXO/float(ie1-1);
              SGR=SGR/float(ie1-1);
              sigma[1][i01]=SMN;
              sigma[2][i01]=SRD;
              sigma[3][i01]=SDEN;
              sigma[4][i01]=SHAC;
              sigma[5][i01]=SRXO;
              sigma[6][i01]=SGR;
        }
   }while(FindNext(sr) == 0);
 }
 for(int iu=1;iu<=i01;iu++)
 {
  sigma[0][1]=sigma[0][1]+sigma[1][iu];
  sigma[0][2]=sigma[0][2]+sigma[2][iu];
  sigma[0][3]=sigma[0][3]+sigma[3][iu];
  sigma[0][4]=sigma[0][4]+sigma[4][iu];
  sigma[0][5]=sigma[0][5]+sigma[5][iu];
  sigma[0][6]=sigma[0][6]+sigma[6][iu];
  }

  sigma[0][1]=sigma[0][1]/float(i01); PaintBox2->Canvas->TextOutA(20,100,"S11微电极平均值"+AnsiString(sigma[0][1]));
  sigma[0][2]=sigma[0][2]/float(i01); PaintBox2->Canvas->TextOutA(20,120,"S11侧向平均值"+AnsiString(sigma[0][2]));
  sigma[0][3]=sigma[0][3]/float(i01); PaintBox2->Canvas->TextOutA(20,140,"S11密度平均值"+AnsiString(sigma[0][3]));
  sigma[0][4]=sigma[0][4]/float(i01); PaintBox2->Canvas->TextOutA(20,160,"S11声波平均值"+AnsiString(sigma[0][4]));
  sigma[0][5]=sigma[0][5]/float(i01); PaintBox2->Canvas->TextOutA(20,180,"S11微球平均值"+AnsiString(sigma[0][5]));
  sigma[0][6]=sigma[0][6]/float(i01); PaintBox2->Canvas->TextOutA(20,200,"S11伽马平均值"+AnsiString(sigma[0][6]));
  PaintBox2->Canvas->TextOutA(80,280,"i01   值"+AnsiString(i01));
}
//------------------------------------------------------------------------------
//老井标准层S11概率密度函数
void __fastcall TForm1::laojinggailvmidu(TObject *Sender)
{
   pingjunzhi(Sender);
     n=6;int i01=0; int stdi;//标准层位置
   FILE *fp; int i2=7;ie1=0;AnsiString Dir;
   Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\S11\\";
   TSearchRec sr;
   TStringList *FileList = new TStringList();
//   TStrings *FileList;
if (FindFirst(Dir + "\\*.*", faAnyFile, sr) == 0)
{
do{
    FileList->Add(Dir + "\\" + sr.Name);

    fp=fopen((Dir + sr.Name).c_str(),"r");
        if(fp&&(FileList!="0"))
        {
         ie1=0; i01=i01+1;  //计算打开非零文件个数
         fscanf(fp,"%f",&S11d);
         S11d=StrToFloat(FormatFloat("0.00",S11d));
           while(feof(fp)==0)
           {
            for(int j=0;j<i2;j++)
             {
               fscanf(fp,"%f",&xcsj[ie1][j]);
               xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
        //       if(abs(xcsj[ie1][0]-S11d)<0.002)stdi=ie1;
              }
               ie1++;
             }
           SMN=0.0;SRD=0.0;SDEN=0.0;SHAC=0.0;SRXO=0.0;SGR=0.0;stdi=16;
           float Smx0=0.0,Smxd0=0.0;
       //    PaintBox2->Canvas->TextOutA(120,260+i01*20,"IE1-2值="+AnsiString(ie1));
           Guiyihua(1,ie1);//微电位归一化
           RMNmax=Cmax;
           RMNmin=Cmin;
           if(RMNmax<1.0)RMNmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
             I[i][0]=StrToFloat(FormatFloat("0.00",xcsj[i][0]));
             I[i][1]=(xcsj[i][1])/StrToFloat(FormatFloat("0.00",RMNmax));
           }
           Guiyihua(2,ie1);//深侧向归一化
           RDmax=Cmax;
           RDmin=Cmin;
           if(RDmax<1.0)RDmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][2]=(xcsj[i][2])/StrToFloat(FormatFloat("0.00",RDmax));
           }
           Guiyihua(3,ie1);//密度归一化
           DENmax=Cmax;
           DENmin=Cmin;
           if(DENmax<1.0)DENmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
             I[i][3]=(xcsj[i][3])/StrToFloat(FormatFloat("0.00",DENmax));
           }
           Guiyihua(4,ie1);//声波归一化
           HACmax=Cmax;
           HACmin=Cmin;
           if(HACmax<1.0)HACmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][4]=(xcsj[i][4])/StrToFloat(FormatFloat("0.00",HACmax));
           }
            Guiyihua(5,ie1);//微球归一化
           RXOmax=Cmax;
           RXOmin=Cmin;
           if(RXOmax<1.0)RXOmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][5]=(xcsj[i][5])/StrToFloat(FormatFloat("0.00",RXOmax));
           }
           Guiyihua(6,ie1);//伽马归一化
           GRmax=Cmax;
           GRmin=Cmin;
           if(GRmax<1.0)GRmax=1.0;
           for(int i=0;i<ie1-1;i++)
           {
            I[i][6]=(xcsj[i][6])/StrToFloat(FormatFloat("0.00",GRmax));
           }

             for(int iu=0;iu<=stdi;iu++)
              {
               SMN=SMN+(I[iu][1]-sigma[0][1])*float(iu)/float(stdi);
               SRD=SRD+(I[iu][2]-sigma[0][2])*float(iu)/float(stdi);
               SDEN=SDEN+(I[iu][3]-sigma[0][3])*float(iu)/float(stdi);
               SHAC=SHAC+(I[iu][4]-sigma[0][4])*float(iu)/float(stdi);
               SRXO=SRXO+(I[iu][5]-sigma[0][5])*float(iu)/float(stdi);
               SGR=SGR+(I[iu][6]-sigma[0][6])*float(iu)/float(stdi);
               Smx0=Smx0+(I[iu][1]+I[iu][2]+I[iu][3]+1.0/I[iu][4]+I[iu][5]+1.0/I[iu][6])*float(iu)/float(stdi);
               Smxd0=Smxd0+(I[iu][1]+I[iu][2]+I[iu][5])*float(iu)/float(stdi);    //电阻率曲线概率密度
              }
              for(int iu=stdi+1;iu<ie1-1;iu++)
              {
               SMN=SMN+(I[iu][1]-sigma[0][1])*float((ie1-1)-iu)/float(ie1-1-stdi);
               SRD=SRD+(I[iu][2]-sigma[0][2])*float((ie1-1)-iu)/float(ie1-1-stdi);
               SDEN=SDEN+(I[iu][3]-sigma[0][3])*float((ie1-1)-iu)/float(ie1-1-stdi);
               SHAC=SHAC+(I[iu][4]-sigma[0][4])*float((ie1-1)-iu)/float(ie1-1-stdi);
               SRXO=SRXO+(I[iu][5]-sigma[0][5])*float((ie1-1)-iu)/float(ie1-1-stdi);
               SGR=SGR+(I[iu][6]-sigma[0][6])*float((ie1-1)-iu)/float(ie1-1-stdi);
               Smx0=Smx0+(I[iu][1]+I[iu][2]+I[iu][3]+1.0/I[iu][4]+I[iu][5]+1.0/I[iu][6])*float((ie1-1)-iu)/float(ie1-1-stdi);
               Smxd0=Smxd0+(I[iu][1]+I[iu][2]+I[iu][5])*float((ie1-1)-iu)/float(ie1-1-stdi);
              }
              S11[i01][1]=SMN;
              S11[i01][2]=SRD;
              S11[i01][3]=SDEN;
              S11[i01][4]=SHAC;
              S11[i01][5]=SRXO;
              S11[i01][6]=SGR;
              S11[i01][8]=Smxd0;
              S11[i01][9]=Smx0;
        }
   }while(FindNext(sr) == 0);
 }
  for(int j=1;j<n+1;j++)
  {
     S11[0][j]=0.0;
     for(int i=1;i<=i01;i++)
     {
       S11[0][j]=S11[0][j]+S11[i][j];
     }
  }
  S11[0][8]=0.0;S11[0][9]=0.0;
  for(int i=1;i<=i01;i++)
   {
    S11[0][8]=S11[0][8]+S11[i][8];
    S11[0][9]=S11[0][9]+S11[i][9];
   }
   S11[0][8]=S11[0][8]/float(i01);
   S11[0][9]=S11[0][9]/float(i01);  //S11标准层平均混合概率密度
  for(int j=1;j<n+1;j++)
  {
    S11[0][j]=S11[0][j]/float(i01);  //S11标准层平均概率密度
  }
//  PaintBox2->Canvas->TextOutA(120,260,"IE1-2值="+AnsiString(ie1));
  fclose(fp);
}
//------------------------------------------------------------------------------
void __fastcall TForm1::N11Click(TObject *Sender)
{

    imn=0,ird=0,iden=0,ihac=0,ipj=0,ixo=0,igr=0,imx=0,imxd=0,nn=7;
   laojinggailvmidu(Sender);

     for(int i=0;i<5000;i++)
     {
        for(int j=0;j<20;j++)
        {
          Sdeep[i][j]=0.0;
        }
     }
 //  PaintBox2->Canvas->TextOutA(20,20,"S11概率密度值 ="+AnsiString(S11[0][1]));
//   PaintBox2->Canvas->TextOutA(20,40,"S11微电极平均值"+AnsiString(sigma[0][1]));
//   PaintBox2->Canvas->TextOutA(20,240,"ie1=  "+AnsiString(ie1));
   for(int i=0;i<stedp1-ie1;i++)
   {
           for(int j1=0;j1<nn;j1++)
           {
             for(int i1=0;i1<ie1-1;i1++)
             {
               xsj[i1][j1]=0.0;
               I1[i1][j1]=0.0;
              }
            }
          for(int i1=i;i1<i+ie1-1;i1++)
          {
            xsj[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]));
              xsj[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]));
                xsj[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]));
                  xsj[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]));
                    xsj[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]));
                      xsj[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]));
          }
      for(int j1=1;j1<nn;j1++)
      {
       sig[j1]=0.0;//计算各条曲线测量值总和，再求平均值
        for(int i1=0;i1<ie1-2;i1++)
         {
          for(int i2=i1+1;i2<ie1-1;i2++)
           {
             if(xsj[i1][j1]<xsj[i2][j1])
             {
               p1=xsj[i1][j1];
               xsj[i1][j1]=xsj[i2][j1];
               xsj[i2][j1]=p1;
              }
            }
         }
        Cmax1[j1]=StrToFloat(FormatFloat("0.00",xsj[0][j1]));
        Cmin1[j1]=StrToFloat(FormatFloat("0.00",xsj[ie1-2][j1]));
        if(Cmin1[j1]<0.50)Cmin1[j1]=0.50;
        if(Cmax1[j1]<1.0)Cmax1[j1]=1.0;

     }
     RMNmin1=Cmin1[1];
     for(int i1=i;i1<i+ie1-1;i1++)
     {
       I1[i1-i][0]=StrToFloat(FormatFloat("0.00",a1[i1][0]));
       I1[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[1]));   //微电位归一化
       I1[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[2])); //深侧向归一化
       I1[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[3])); //密度归一化
       I1[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[4])); //声波归一化
       I1[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[5])); //微球归一化
       I1[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]))/StrToFloat(FormatFloat("0.00",Cmax1[6])); //伽马归一化

     }
             int stdi0=15;
             for(int j1=1;j1<nn;j1++)
             {
                sig[j1]=0.0;
                for(int iu=0;iu<ie1-1;iu++)
                {
                 sig[j1]=sig[j1]+I1[iu][j1];
                 }
             }
               for(int j1=1;j1<nn;j1++)
               {
                   sig[j1]=sig[j1]/float(ie1-1);
                   if(fabs(sig[j1]-sigma[0][j1])<0.0001)
                   {
                     ipj=ipj+1;
                     PaintBox2->Canvas->TextOutA(20,20+ipj*20,"S11平均密度值深度 ="+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
                    }
                }
              SMNT=0.0;SRDT=0.0;SDENT=0.0;SHACT=0.0;SRXOT=0.0;SGRT=0.0;
              float Smx=0.0,Smxd=0.0;
              for(int iu=0;iu<=stdi0;iu++)
              {
               if(I1[iu][4]<0.001)I1[iu][4]=0.001;
               if(I1[iu][6]<0.001)I1[iu][6]=0.001;
               SMNT=SMNT+(I1[iu][1]-sig[1])*float(iu)/float(stdi0);
               SRDT=SRDT+(I1[iu][2]-sig[2])*float(iu)/float(stdi0);
               SDENT=SDENT+(I1[iu][3]-sig[3])*float(iu)/float(stdi0);
               SHACT=SHACT+(I1[iu][4]-sig[4])*float(iu)/float(stdi0);
               SRXOT=SRXOT+(I1[iu][5]-sig[5])*float(iu)/float(stdi0);
               SGRT=SGRT+(I1[iu][6]-sig[6])*float(iu)/float(stdi0);
               Smx=Smx+(I1[iu][1]+I1[iu][2]+I1[iu][3]+1.0/I1[iu][4]+I1[iu][5]+1.0/I1[iu][6])*float(iu)/float(stdi0);
               Smxd=Smxd+(I1[iu][1]+I1[iu][2]+I1[iu][5])*float(iu)/float(stdi0);    //电阻率曲线概率密度
              }
              for(int iu=stdi0+1;iu<ie1-1;iu++)
              {
             //  if(I1[iu][2]<0.001)I1[iu][2]=0.01;
                if(I1[iu][4]<0.001)I1[iu][4]=0.001;
               if(I1[iu][6]<0.001)I1[iu][6]=0.001;
               SMNT=SMNT+(I1[iu][1]-sig[1])*float((ie1-1)-iu)/float(ie1-1-stdi0);
               SRDT=SRDT+(I1[iu][2]-sig[2])*float((ie1-1)-iu)/float(ie1-1-stdi0);
               SDENT=SDENT+(I1[iu][3]-sig[3])*float((ie1-1)-iu)/float(ie1-1-stdi0);
               SHACT=SHACT+(I1[iu][4]-sig[4])*float((ie1-1)-iu)/float(ie1-1-stdi0);
               SRXOT=SRXOT+(I1[iu][5]-sig[5])*float((ie1-1)-iu)/float(ie1-1-stdi0);
               SGRT=SGRT+(I1[iu][6]-sig[6])*float((ie1-1)-iu)/float(ie1-1-stdi0);
               Smx=Smx+(I1[iu][1]+I1[iu][2]+I1[iu][3]+1.0/I1[iu][4]+I1[iu][5]+1.0/I1[iu][6])*float((ie1-1)-iu)/float(ie1-1-stdi0);
               Smxd=Smxd+(I1[iu][1]+I1[iu][2]+I1[iu][5])*float((ie1-1)-iu)/float(ie1-1-stdi0);
              }


           if(fabs(SMNT-S11[0][1])<0.08)
           {
          //   PaintBox4->Canvas->TextOutA(20,20+(imn)*20,"微电极最佳匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[imn][1]=I1[stdi0][0];
             Sdeep[imn][11]=fabs(SMNT-S11[0][1]);
         //    PaintBox2->Canvas->TextOutA(320,10,"S11标准概率密度值 ="+AnsiString(S11[0][1]));
        //   PaintBox2->Canvas->TextOutA(420,20+imn*20,"S11概率密度值 ="+AnsiString(SMNT));
             imn=imn+1;
             }
            if(fabs(SRDT-S11[0][2])<0.04)
           {
            // PaintBox4->Canvas->TextOutA(220,20+(ird)*20,"侧向最佳匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[ird][2]=I1[stdi0][0];
             Sdeep[ird][12]=fabs(SRDT-S11[0][2]);
             ird=ird+1;
             }
             if(fabs(SDENT-S11[0][3])<0.008)
           {
           //  PaintBox4->Canvas->TextOutA(420,20+(iden)*20,"密度最佳匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[iden][3]=I1[stdi0][0];
             Sdeep[iden][13]=fabs(SDENT-S11[0][3]);
             iden=iden+1;
             }
              if(fabs(SHACT-S11[0][4])<0.008)
           {
          //   PaintBox4->Canvas->TextOutA(620,20+(ihac)*20,"声波最佳匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[ihac][4]=I1[stdi0][0];
             Sdeep[ihac][14]=fabs(SHACT-S11[0][4]);
             ihac=ihac+1;
             }
             if(fabs(SRXOT-S11[0][5])<0.08)
           {
             PaintBox2->Canvas->TextOutA(220,20+(ixo)*20,"微球最佳匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[ixo][5]=I1[stdi0][0];
             Sdeep[ixo][15]=fabs(SRXOT-S11[0][5]);
             ixo=ixo+1;
             }
              if(fabs(SGRT-S11[0][6])<0.008)
           {
         //    PaintBox2->Canvas->TextOutA(420,20+(igr)*20,"伽马最佳匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[igr][6]=I1[stdi0][0];
             Sdeep[igr][16]=fabs(SGRT-S11[0][6]);
             igr=igr+1;
             }
             if(fabs(Smx-S11[0][9])<0.05)
           {
             PaintBox2->Canvas->TextOutA(620,20+(imx)*20,"整体混合匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[imx][9]=I1[stdi0][0];
             Sdeep[imx][19]=fabs(Smx-S11[0][9]);
             imx=imx+1;
             }
            if(fabs(Smxd-S11[0][8])<0.08)
           {
           //  PaintBox2->Canvas->TextOutA(420,20+(imxd)*20,"电阻率混合匹配深度 : "+AnsiString(FormatFloat("0.0",I1[stdi0][0])));
             Sdeep[imxd][8]=I1[stdi0][0];
             Sdeep[imxd][18]=fabs(Smxd-S11[0][8]);
             imxd=imxd+1;
             }
   }
             paidui(11,imn,Sdeep);
             paidui(12,ird,Sdeep);
             paidui(13,iden,Sdeep);
             paidui(14,ihac,Sdeep);
             paidui(15,ixo,Sdeep);
             paidui(16,igr,Sdeep);
             paidui(18,imxd,Sdeep);
             paidui(19,imx,Sdeep);
             for(int iu=11;iu<17;iu++)
             {
              PaintBox2->Canvas->TextOutA(420,20+(iu)*15,"最佳匹配深度 : "+AnsiString(FormatFloat("0.0",Sdeep[0][iu-10])));
             }
             PaintBox2->Canvas->TextOutA(420,20+(18)*15,"最佳匹配深度 : "+AnsiString(FormatFloat("0.0",Sdeep[0][8])));
             PaintBox2->Canvas->TextOutA(420,20+(19)*15,"最佳匹配深度 : "+AnsiString(FormatFloat("0.0",Sdeep[0][9])));
             int imm=0,ixm=0,ixmm=0,ixmx=0;
             for(int iu=0;iu<imn;iu++)
             {
               for(int ib=0;ib<imx;ib++)
               {
                 if(fabs(Sdeep[iu][1]-Sdeep[ib][9])<0.3)
                  {
                   PaintBox4->Canvas->TextOutA(580,20+(imm)*20,"微电极混合最佳匹配深度 : "+AnsiString(FormatFloat("0.0",Sdeep[ib][9])));
                   imm=imm+1;
                  }
               }
             }
             for(int iu=0;iu<ixo;iu++)
             {
               for(int ib=0;ib<imx;ib++)
               {
                 if(fabs(Sdeep[iu][5]-Sdeep[ib][9])<0.3)
                  {
                   PaintBox4->Canvas->TextOutA(380,20+(ixm)*20,"微球混合最佳匹配深度 : "+AnsiString(FormatFloat("0.0",Sdeep[ib][9])));
                   ixm=ixm+1;
                  }
               }
             }
             for(int iu=0;iu<imxd;iu++)
             {
               for(int ib=0;ib<imx;ib++)
               {
                 if(fabs(Sdeep[iu][8]-Sdeep[ib][9])<0.3)
                  {
                   PaintBox4->Canvas->TextOutA(220,20+(ixmm)*20,"电混合匹配深度 : "+AnsiString(FormatFloat("0.0",Sdeep[ib][9])));
                   ixmm=ixmm+1;
                  }
               }
             }
              for(int iu=0;iu<ixo;iu++)
             {
               for(int ib=0;ib<imxd;ib++)
               {
                 if(fabs(Sdeep[iu][5]-Sdeep[ib][8])<0.3)
                  {
                   PaintBox4->Canvas->TextOutA(20,20+(ixmx)*20,"微球电混合匹配深度 : "+AnsiString(FormatFloat("0.0",Sdeep[ib][8])));
                   ixmx=ixmx+1;
                  }
               }
             }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::paidui(int j1,int nc,float dp[8000][20])
{
  float p;
     for(int i1=0;i1<nc-1;i1++)
     {
        for(int i2=i1+1;i2<nc;i2++)
        {
            if(dp[i1][j1]>dp[i2][j1])
            {
              p=dp[i1][j1];
              dp[i1][j1]=dp[i2][j1];
              dp[i2][j1]=p;
              p=dp[i1][j1-10];
              dp[i1][j1-10]=dp[i2][j1-10];
              dp[i2][j1-10]=p;
            }

        }
     }
}
//------------------------------------------------------------------------------

void __fastcall TForm1::N12Click(TObject *Sender)
{
   ic1=0,ic2=0,ic3=0,ic4=0,ic5=0,ic6=0;float menkanzhi=0.003,shendumenkan=0.01;
 //--------------------------------------
   n=6;
   FILE *fp; int i2=7;ie1=0;
   fp=fopen("D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\S11\\S11","rt");
   if(fp)
   {
         ie1=0;
         fscanf(fp,"%f",&S11d);
         S11d=StrToFloat(FormatFloat("0.00",S11d));
         while(feof(fp)==0)
         {
            for(int j=0;j<i2;j++)
            {
             fscanf(fp,"%f",&xcsj[ie1][j]);
             xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
            }
            ie1++;
          }
   }
 //--------------------------------------
  for(int i=0;i<=ie1-1;i++)
  {
    for(int j=0;j<=n;j++)
    {
      GYHC[i][j]=xcsj[i][j];   //PaintBox4->Canvas->TextOutA(50,10+(i)*20,"std dat=  "+AnsiString(xcsj[i][1]));
    }
  }
  GuiYiHua(ie1,n,GYHmax,GYHmin,GYHC);
  quxianxiangsutezhengfenjie(ie1,n,30,GYHC);
  for(int i=1;i<=n;i++)
  {
   WeiShu0[i]=WeiShu[i];   //各曲线标准层数据维数
  }
       for(int io=0;io<stedp1-ie1-1;io++)
       {
     //  PaintBox4->Canvas->TextOutA(550,10+(is)*20,AnsiString(data[io-2][0]));
         for(int i=io;i<=io+ie1-1;i++)
          {
            xssj[i-io][1]=data1[i][MN1_pos];
            xssj[i-io][2]=data1[i][Rd1_pos];
            xssj[i-io][3]=data1[i][DEN1_pos];    //PaintBox4->Canvas->TextOutA(250,10+(i)*20,"dat=  "+AnsiString(data[i][DEN_pos]));
            xssj[i-io][4]=data1[i][HAC1_pos];
            xssj[i-io][5]=data1[i][Rxo1_pos];
            xssj[i-io][6]=data1[i][GR1_pos];
          }
          GuiYiHua(ie1,n,GYHmax,GYHmin,xssj);
          quxianxiangsutezhengfenjie(ie1,n,30,xssj);
             if(fabs(WeiShu0[1]-WeiShu[1])<menkanzhi)      //微电极维数
             {
               //Image1->Canvas->TextOutA(10+30,10+(ic)*20,AnsiString(data[io+16][0]));
              // Image1->Canvas->TextOutA(10+230,10+(ic)*20,"ws0= "+AnsiString(WeiShu0[i]));
              // Image1->Canvas->TextOutA(10+380,30+(ic)*20,"ws=  "+AnsiString(WeiShu[i]));
               WSDeep[ic1][1]=StrToFloat(FormatFloat("0.00",data[io+17][0]));
               ic1=ic1+1;
             }
             if(fabs(WeiShu0[2]-WeiShu[2])<menkanzhi)                       //深侧向维数
             {
               WSDeep[ic2][2]=StrToFloat(FormatFloat("0.00",data[io+17][0]));
               ic2=ic2+1;
             }
             if(fabs(WeiShu0[3]-WeiShu[3])<menkanzhi)                        //密度维数
             {
               WSDeep[ic3][3]=StrToFloat(FormatFloat("0.00",data[io+17][0]));
               ic3=ic3+1;
             }
             if(fabs(WeiShu0[4]-WeiShu[4])<menkanzhi)                        //声波维数
             {
               WSDeep[ic4][4]=StrToFloat(FormatFloat("0.00",data[io+17][0]));
               ic4=ic4+1;
             }
             if(fabs(WeiShu0[5]-WeiShu[5])<menkanzhi)                        //微球维数
             {
               WSDeep[ic5][5]=StrToFloat(FormatFloat("0.00",data[io+17][0]));
               ic5=ic5+1;
             }
             if(fabs(WeiShu0[6]-WeiShu[6])<menkanzhi)                        //伽马维数
             {
               WSDeep[ic6][6]=StrToFloat(FormatFloat("0.00",data[io+17][0]));
               ic6=ic6+1;
             }
         }
        inu1=0,inu2=0,inu3=0,inu4=0,inu5=0,inu6=0,inu7=0,inu8=0,inu9=0,inu10=0;
        for(int i1=0;i1<ic1-1;i1++)
        {
          for(int i2=0;i2<ic2-1;i2++)
          {
               if((fabs(WSDeep[i1][1]-WSDeep[i2][2])<shendumenkan))                //微电极与深侧向深度匹配
               {
                 PaintBox4->Canvas->TextOutA(10+130,(inu1)*12,"WSDeep1-2= "+AnsiString((FormatFloat("0.0",WSDeep[i1][1]))));
                 WSDeep[inu1][11]=StrToFloat(FormatFloat("0.00",WSDeep[i1][1]));
                 inu1=inu1+1;
               }

           }
         }
        for(int i2=0;i2<ic2-1;i2++)
        {
           for(int i5=0;i5<ic5-1;i5++)
            {                                                              //深侧向与微球深度匹配
               if(fabs(WSDeep[i5][5]-WSDeep[i2][2])<shendumenkan)
               {
                PaintBox4->Canvas->TextOutA(10+330,(inu2)*12,"WSDeep2-5= "+AnsiString((FormatFloat("0.0",WSDeep[i2][2]))));
                WSDeep[inu2][12]=StrToFloat(FormatFloat("0.00",WSDeep[i2][2]));
                inu2=inu2+1;
               }
            }
        }
        for(int i1=0;i1<inu1-1;i1++)
        {                                                                 // 微电极与深侧向深度匹配和深侧向与微球深度匹配对比

           for(int i5=0;i5<inu2-1;i5++)
            {

               if((fabs(WSDeep[i1][11]-WSDeep[i5][12])<shendumenkan))
               {
                PaintBox4->Canvas->TextOutA(10+530,(inu3)*12,"WSDeep12-11= "+AnsiString((FormatFloat("0.0",WSDeep[i5][12]))));
                WSDeep[inu3][20]=StrToFloat(FormatFloat("0.00",WSDeep[i5][12]));
                inu3=inu3+1;
               }
            }
        }
        for(int i3=0;i3<ic3-1;i3++)
        {

           for(int i4=0;i4<ic4-1;i4++)
            {
                                                                           //密度与声波匹配深度
               if((fabs(WSDeep[i3][3]-WSDeep[i4][4])<shendumenkan))
               {
             //   Image1->Canvas->TextOutA(10+630,(inu4)*12,"WSDeep3-4= "+AnsiString((FormatFloat("0.0",WSDeep[i4][4]))));
                WSDeep[inu4][13]=StrToFloat(FormatFloat("0.00",WSDeep[i3][3]));
                inu4=inu4+1;
               }
            }
        }
         for(int i3=0;i3<ic3-1;i3++)
        {

           for(int i6=0;i6<ic6-1;i6++)                                   //密度与伽马匹配深度
            {

               if((fabs(WSDeep[i3][3]-WSDeep[i6][6])<shendumenkan))
               {
              //  Image1->Canvas->TextOutA(10+630,(inu5)*12,"WSDeep3-4= "+AnsiString((FormatFloat("0.0",WSDeep[i3][3]))));
                WSDeep[inu5][14]=StrToFloat(FormatFloat("0.00",WSDeep[i3][3]));
                inu5=inu5+1;
               }
            }
        }
        for(int i4=0;i4<inu4-1;i4++)
        {

           for(int i5=0;i5<inu5-1;i5++)
            {                                                              //密度与声波匹配深度和密度与伽马匹配深度对比

               if((fabs(WSDeep[i4][13]-WSDeep[i5][14])<shendumenkan))
               {
                PaintBox4->Canvas->TextOutA(50+630,(inu6)*12,"WSDeep13-14= "+AnsiString((FormatFloat("0.0",WSDeep[i5][14]))));
                WSDeep[inu6][21]=StrToFloat(FormatFloat("0.00",WSDeep[i5][14]));
                inu6=inu6+1;
               }
            }
        }
         for(int i0=0;i0<inu3-1;i0++)
        {

           for(int i1=0;i1<inu6-1;i1++)
            {

               if((fabs(WSDeep[i0][20]-WSDeep[i1][21])<shendumenkan))
               {
                PaintBox2->Canvas->TextOutA(160,(inu7)*12,"WSDeep20-21= "+AnsiString((FormatFloat("0.0",WSDeep[i0][20]))));
                WSDeep[inu3][24]=StrToFloat(FormatFloat("0.00",WSDeep[i0][20]));
                inu7=inu7+1;
               }
            }
        }
        for(int i1=0;i1<ic1-1;i1++)
        {
          for(int i5=0;i5<ic5-1;i5++)
          {
               if((fabs(WSDeep[i1][1]-WSDeep[i5][5])<shendumenkan))                //微电极与微球深度匹配
               {
                 PaintBox2->Canvas->TextOutA(30,(inu8)*12,"WSDeep1-5= "+AnsiString((FormatFloat("0.0",WSDeep[i1][1]))));
                 WSDeep[inu8][15]=StrToFloat(FormatFloat("0.00",WSDeep[i1][1]));
                 inu8=inu8+1;
               }

           }
         }
        for(int i2=0;i2<inu2-1;i2++)
        {

           for(int i6=0;i6<inu6-1;i6++)
            {                                                              //微电极与深侧向匹配深度和微电极与微球深度匹配深度对比

               if((fabs(WSDeep[i2][12]-WSDeep[i6][21])<shendumenkan))
               {
                PaintBox2->Canvas->TextOutA(290,(inu9)*12,"WSDeep12-16= "+AnsiString((FormatFloat("0.0",WSDeep[i6][21]))));
                WSDeep[inu9][22]=StrToFloat(FormatFloat("0.00",WSDeep[i6][21]));
                inu9=inu9+1;
               }
            }
        }
        for(int i6=0;i6<inu6-1;i6++)
        {

           for(int i9=0;i9<inu9-1;i9++)
            {                                                              //微电极与深侧向匹配深度和微电极与微球深度匹配--同--密度与声波匹配深度和密度与伽马匹配深度对比

               if((fabs(WSDeep[i6][21]-WSDeep[i9][22])<shendumenkan))
               {
                PaintBox2->Canvas->TextOutA(480,(inu10)*12,"WSDeep21-22= "+AnsiString((FormatFloat("0.0",WSDeep[i9][22]))));
                WSDeep[inu10][22]=StrToFloat(FormatFloat("0.00",WSDeep[i9][22]));
                inu10=inu10+1;
               }
            }
        }
      PaintBox2->Canvas->TextOutA(20,120,"符合总层数 "+AnsiString(ic1));

}
//---------------------------------------------------------------------------
void __fastcall TForm1::quxianxiangsutezhengfenjie(int totali,int columi,int BuChang,float XSTZ[500][50])     //测井曲线像素特征向量分解法
{
 float DetLenth=1.0/float(BuChang),x=1.0,y=1.0,BuChang2=BuChang*3,DetLenth1=1.0/float(BuChang2);
 int C1=0,C2[20],C3=0,C4[20];
// totali=totali+1;
  for(int j=1;j<=columi;j++)
   {
      C2[j]=0;
      for(int i=0;i<=totali-2;i++)
       {
        //x=DetLenth*float(i);
       // y=(XSTZ[i+1][j]-XSTZ[i][j])/float(i+1-i)*x+float(i+1)*XSTZ[i][j]-float(i)*XSTZ[i+1][j];
        C1=ceil((XSTZ[i+1][j]-XSTZ[i][j])/DetLenth);
        if(C1>BuChang)C2[j]=C2[j]+C1+BuChang-2-1;
        if(C1<BuChang)C2[j]=C2[j]+C1+BuChang-1-1;
        if(C1=BuChang)C2[j]=C2[j]+(C1+BuChang)/2-1;
       }
   }
  for(int j=1;j<=columi;j++)
   {
      C4[j]=0;
      for(int i=0;i<totali-2;i++)
       {
        //x=DetLenth*float(i);
       // y=(XSTZ[i+1][j]-XSTZ[i][j])/float(i+1-i)*x+float(i+1)*XSTZ[i][j]-float(i)*XSTZ[i+1][j];
        C3=ceil((XSTZ[i+1][j]-XSTZ[i][j])/DetLenth1);
        if(C3>BuChang2)C4[j]=C4[j]+C3+BuChang2-2-1;
        if(C3<BuChang2)C4[j]=C4[j]+C3+BuChang2-1-1;
        if(C3=BuChang2)C4[j]=C4[j]+(C3+BuChang2)/2-1;
       }
   }
  for(int j=1;j<=columi;j++)
   {
    WeiShu[j]=0.0;
    WeiShu[j]=float(C4[j]-C2[j])/float((BuChang2-BuChang)*float(ie1));
   // WeiShu[j]=float(C4[j])/float(BuChang2*float(ie1))-float(C2[j])/float(BuChang*float(ie1));
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GuiYiHua(int totali,int columi,float GYmax[50],float GYmin[50],float GYH[500][50])
{
 float GYH1[500][50],p;
 totali=totali+1;
 for(int i=0;i<totali-1;i++)
   {
      for(int j=1;j<=columi;j++)
       {
         GYH1[i][j]=GYH[i][j];
       }
   }
  for(int j=1;j<=columi;j++)
   {
    for(int i=0;i<totali-2;i++)
     {
       for(int i1=i+1;i1<totali-1;i1++)
         {
           if(GYH1[i][j]<GYH1[i1][j])
            {
              p=GYH1[i][j];
              GYH1[i][j]=GYH1[i1][j];
              GYH1[i1][j]=p;
            }
         }
       }
       GYmax[j]=GYH1[0][j];
       GYmin[j]=GYH1[totali-2][j];
   }
   for(int i=0;i<totali-1;i++)
   {
      for(int j=1;j<=columi;j++)
       {
         GYH[i][j]=GYH1[i][j]/GYmax[j];
       }
    //  GYH[i][1]=GYH[i][1]+GYH[i][2]+GYH[i][5];
   }


}
//-----------------------------------------------------------------------------
void __fastcall TForm1::xiangsuweishu(int totali,int columi,float detL,float relv,float XS[500][50])  //任意步长像素维数
{
 float sti,detL1,x0[500][50],y,renyi[500][50],x;
 int totalc,totalc1,n1,n2,n0=0,S[50],S1[50];//总步长段数
 sti=detL/relv;
 detL1=detL*2.0;
 totalc=ceil((totali-1)*relv/detL);
 for(int j=1;j<=columi;j++)
 {
     x0[0][j]=0.0;
     y=0.0;
     RWS[j]=0.0;
 }
 for(int j=1;j<=columi;j++)
 {
   S[j]=0;n0=0;
   for(int i=0;i<totalc;i++)
    {

     n1=floor(detL*float(i)/relv);
     n2=ceil(detL*float(i)/relv);
   //  x0[i][j]=detL*float(i)-float(n1)*relv;             //    2021年8月13日以前
   //  y=(XS[n2][j]-XS[n1][j])/x0[i][j]+x0[i][j]*XS[n1][j];
       x=detL*float(i)-float(n1)*relv;                                                                              //2021年8月13日
       y=(XS[n2][j]-XS[n1][j])*x/relv+(float(n2)*relv-detL*float(i))*XS[n1][j]-(float(n1)*relv-detL*float(i))*XS[n2][j];
      for(int i1=n0;i1<=n1;i1++)
       {
        renyi[i1-n0][j]=XS[i1][j];
       }
       Smaxmin(n1-n0,j,y,totali,XCmax,XCmin,renyi);
       n0=n2;
       S[j]=S[j]+ceil((XCmax[j]-XCmin[j])/detL);
    }
 }

   totalc1=ceil((totali-1)*relv/detL1);
 for(int j=1;j<=columi;j++)
 {
     x0[0][j]=0.0;
     y=0.0;

 }
 for(int j=1;j<=columi;j++)
 {
   S1[j]=0;
   for(int i=0;i<totalc1;i++)
    {

     n1=floor(detL1*float(i)/relv);
     n2=ceil(detL1*float(i)/relv);
   //  x0[i][j]=detL1*float(i)-float(n1)*relv;
   //  y=(XS[n2][j]-XS[n1][j])/x0[i][j]+x0[i][j]*XS[n1][j];
      x=detL1*float(i)-float(n1)*relv;                                                                              //2021年8月13日
       y=(XS[n2][j]-XS[n1][j])*x/relv+(float(n2)*relv-detL1*float(i))*XS[n1][j]-(float(n1)*relv-detL1*float(i))*XS[n2][j];
      for(int i1=n0;i1<=n1;i1++)
       {
        renyi[i1-n0][j]=XS[i1][j];
       }
       Smaxmin(n1-n0,j,y,totali,XCmax,XCmin,renyi);
       n0=n2;
       S1[j]=S1[j]+ceil((XCmax[j]-XCmin[j])/detL1);
    }
 }

  for(int j=1;j<=columi;j++)
 {
   RWS[j]=0.0;
   RWS[j]=float((S[j]-S1[j]))/float((totalc-totalc1));
 }


}
//-------------------------------------------------------------------------------
void __fastcall TForm1::Smaxmin(int n1,int j,float y,int totali,float XCmax1[50],float XCmin1[50],float XS[500][50])
{
  float xcc[500][50],p;
   for(int i=0;i<totali-1;i++)
   {
   //   for(int j=1;j<=columi;j++)
       {
         xcc[i][j]=XS[i][j];
       }
   }
   for(int i=0;i<n1;i++)
   {
     for(int i1=i+1;i1<=n1;i1++)
      {
         if(xcc[i][j]<xcc[i1][j])
         {
          p=xcc[i][j];
          xcc[i][j]=xcc[i1][j];
          xcc[i1][j]=p;
         }
      }
   }
   XCmax1[j]=xcc[0][j];
   if(n1==0)
   {
      if(y<xcc[n1][j])
      {
       xcc[n1][j]=y;
      }
      else
      {
       XCmax1[j]=y;
       XCmin1[j]=xcc[0][j];
      }
   }
   else
   {
      XCmin1[j]=xcc[n1][j];
   }

 //  Image1->Canvas->TextOutA(895,10+(j)*20,"XCmin1[j]=  "+AnsiString(FormatFloat("0.0",xcc[n1][j])));
   if(y>XCmax1[j])XCmax1[j]=y;
   if(y<XCmin1[j])XCmin1[j]=y;
   if(XCmax1[j]<0.001)XCmax1[j]=0.001;
   if(XCmin1[j]<0.00001)XCmin1[j]=0.00001;
 //  XCmax1[j]=xcc[0][j];
 //  XCmin1[j]=xcc[n1][j];
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

void __fastcall TForm1::N13Click(TObject *Sender)
{
   int ic1=0,ic2=0,ic3=0,ic4=0,ic5=0,ic6=0;
    float detL0=0.2,bdmkz=0.001;
    float p1=10.0,p2=10.0,p3=10.0,p4=10.0,p5=10.0,p6=10.0;
    float d1,d2,d3,d4,d5,d6;
   // float menkanzhi=-402.62*pow(detL0,4.0)+773.88*pow(detL0,4.0)-532.01*pow(detL0,3.0)+164.22*pow(detL0,2.0)-22.636*detL0+1.145;
    float menkanzhi;
    if(detL0<=0.2)
    {
       menkanzhi=0.09;
     }
     else if((detL0<=0.3)&&(detL0>0.2))
    {
       menkanzhi=0.06;
     }
     else if((detL0>0.3)&&(detL0<=0.5))
    {
       menkanzhi=0.07;
     }
     else if(detL0>0.5)
    {
       menkanzhi=1.01;
     }
    PaintBox2->Canvas->TextOutA(795,10+(20)*20,"menkanzhi=  "+AnsiString(menkanzhi));
    n=6;
   FILE *fp; int i2=7;ie1=0;
   int im=0,iRD=0,iDN=0,iAC=0,iRxo=0,iGR=0;
   fp=fopen("D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\S11\\S11","rt");
   if(fp)
   {
         ie1=0;
         fscanf(fp,"%f",&S11d);
         S11d=StrToFloat(FormatFloat("0.00",S11d));
         while(feof(fp)==0)
         {
            for(int j=0;j<i2;j++)
            {
             fscanf(fp,"%f",&xcsj[ie1][j]);
             xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
            }
            ie1++;
          }
   }
   fclose(fp);
 //--------------------------------------
  for(int i=0;i<ie1-1;i++)
  {
    for(int j=0;j<=n;j++)
    {
      GYHC[i][j]=xcsj[i][j];   //Image1->Canvas->TextOutA(50,10+(i)*20,"std dat=  "+AnsiString(xcsj[i][1]));
    }
  }
 // GuiYiHua(ie1,n,GYHmax,GYHmin,GYHC);
  xiangsuweishu(ie1,n,detL0,relv1,GYHC);   //像素维数计算
  for(int j=1;j<=n;j++)
  {
   RWS0[j]=RWS[j]; PaintBox2->Canvas->TextOutA(550,10+(j)*20,"RWS0=  "+AnsiString(FormatFloat("0.0",RWS0[j])));
  }
       for(int io=2;io<stedp1-ie1-1;io++)
       {
     //  Image1->Canvas->TextOutA(700,10+(io)*14,"deep= "+AnsiString((FormatFloat("0.00",data[io-2][0]))));
         for(int i=io;i<=io+ie1-1;i++)
          {
            xssj[i-io][0]=data1[i][0];
            xssj[i-io][1]=data1[i][MN1_pos];    // Image1->Canvas->TextOutA(750,10+(i)*20,"RMN=  "+AnsiString(data1[i][MN1_pos]));
            xssj[i-io][2]=data1[i][Rd1_pos];
            xssj[i-io][3]=data1[i][DEN1_pos];    //Image1->Canvas->TextOutA(250,10+(i)*20,"dat=  "+AnsiString(data1[i][DEN1_pos]));
            xssj[i-io][4]=data1[i][HAC1_pos];
            xssj[i-io][5]=data1[i][Rxo1_pos];
            xssj[i-io][6]=data1[i][GR1_pos];
          }
    //      GuiYiHua(ie1,n,GYHmax,GYHmin,xssj);
          xiangsuweishu(ie1,n,detL0,relv1,xssj);
          if((fabs(RWS0[1]-RWS[1])<menkanzhi*20.)&&(data1[io+ie1-1][MN1_pos]>1.0))
             {
               PaintBox2->Canvas->TextOutA(30,30+(ic1)*14,"ic1=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
            //   Image1->Canvas->TextOutA(10+230,10+(ic)*20,"ws0= "+AnsiString(WeiShu0[i]));
             //  Image1->Canvas->TextOutA(10+380,30+(ic)*20,"ws=  "+AnsiString(WeiShu[i]));
               WSDeep[ic1][1]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));
               ic1=ic1+1;
               if(p1>fabs(RWS0[1]-RWS[1]))
                 {
                  p1=fabs(RWS0[1]-RWS[1]);
                  d1=data1[io+16][0];
                 }
               if(fabs(RWS0[1]-RWS[1])<=bdmkz)
                {
                 BD[im][1]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));PaintBox4->Canvas->TextOutA(40,10+(im)*14,"BD1=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
                 im=im+1;
                }

             }
             if((fabs(RWS0[2]-RWS[2])<menkanzhi)&&(data1[io+ie1-1][Rd1_pos]>1.0))
             {
               PaintBox2->Canvas->TextOutA(110,10+(ic2)*14,"ic2=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
               WSDeep[ic2][2]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));
               ic2=ic2+1;
                if(p2>fabs(RWS0[2]-RWS[2]))
                 {
                  p2=fabs(RWS0[2]-RWS[2]);
                  d2=data1[io+16][0];
                 }
                if(fabs(RWS0[2]-RWS[2])<=bdmkz)
                {
                 BD[iRD][2]=StrToFloat(FormatFloat("0.00",data1[io+16][0])); PaintBox4->Canvas->TextOutA(120,10+(iRD)*14,"BD2=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
                 iRD=iRD+1;
                }
             }
             if((fabs(RWS0[3]-RWS[3])<(menkanzhi*200.0))&&(data1[io+ie1-1][DEN1_pos]>1.0))
             {
              PaintBox2->Canvas->TextOutA(190,10+(ic3)*14,"ic3=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
               WSDeep[ic3][3]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));
               ic3=ic3+1;
                 if(p3>fabs(RWS0[3]-RWS[3]))
                 {
                  p3=fabs(RWS0[3]-RWS[3]);
                  d3=data1[io+16][0];
                 }
                 if(fabs(RWS0[3]-RWS[3])<=bdmkz)
                {
                 BD[iDN][3]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));PaintBox4->Canvas->TextOutA(220,10+(iDN)*14,"BD3=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
                 iDN=iDN+1;
                }
             }
             if((fabs(RWS0[4]-RWS[4])<(menkanzhi*200.0))&&(data1[io+ie1-1][HAC1_pos]>1.0))
             {
               PaintBox2->Canvas->TextOutA(270,10+(ic4)*14,"ic4=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
               WSDeep[ic4][4]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));
               ic4=ic4+1;
                 if(p4>fabs(RWS0[4]-RWS[4]))
                 {
                  p4=fabs(RWS0[4]-RWS[4]);
                  d4=data1[io+16][0];
                 }
                 if(fabs(RWS0[4]-RWS[4])<=bdmkz)
                {
                 BD[iAC][4]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));PaintBox4->Canvas->TextOutA(320,10+(iAC)*14,"BD4=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
                 iAC=iAC+1;
                }
             }
             if((fabs(RWS0[5]-RWS[5])<menkanzhi)&&(data[io+ie1-1][Rxo1_pos]>1.0))
             {
              PaintBox2->Canvas->TextOutA(350,10+(ic5)*14,"ic5=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
               WSDeep[ic5][5]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));
               ic5=ic5+1;
                 if(p5>fabs(RWS0[5]-RWS[5]))
                 {
                  p5=fabs(RWS0[5]-RWS[5]);
                  d5=data1[io+16][0];
                 }
                if(fabs(RWS0[5]-RWS[5])<=bdmkz)
                {
                 BD[iRxo][5]=StrToFloat(FormatFloat("0.00",data1[io+16][0])); PaintBox4->Canvas->TextOutA(420,10+(iRxo)*14,"BD5=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
                 iRxo=iRxo+1;
                }
             }
             if((fabs(RWS0[6]-RWS[6])<(menkanzhi*100))&&(data1[io+ie1-1][GR1_pos]>1.0))
             {
               PaintBox2->Canvas->TextOutA(430,10+(ic6)*14,"ic6=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
               WSDeep[ic6][6]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));
               ic6=ic6+1;
                 if(p6>fabs(RWS0[6]-RWS[6]))
                 {
                  p6=fabs(RWS0[6]-RWS[6]);
                  d6=data1[io+16][0];
                 }
                 if(fabs(RWS0[6]-RWS[6])<=bdmkz)
                {
                 BD[iGR][6]=StrToFloat(FormatFloat("0.00",data1[io+16][0]));PaintBox4->Canvas->TextOutA(520,10+(iGR)*14,"BD6=  "+AnsiString(FormatFloat("0.00",data1[io+16][0])));
                 iGR=iGR+1;
                }
             }
         }
       PaintBox4->Canvas->TextOutA(630,10+14*1,"d1=  "+AnsiString(FormatFloat("0.00",d1)));
       PaintBox4->Canvas->TextOutA(630,10+14*2,"d2=  "+AnsiString(FormatFloat("0.00",d2)));
       PaintBox4->Canvas->TextOutA(630,10+14*3,"d3=  "+AnsiString(FormatFloat("0.00",d3)));
       PaintBox4->Canvas->TextOutA(630,10+14*4,"d4=  "+AnsiString(FormatFloat("0.00",d4)));
       PaintBox4->Canvas->TextOutA(630,10+14*5,"d5=  "+AnsiString(FormatFloat("0.00",d5)));
       PaintBox4->Canvas->TextOutA(630,10+14*6,"d6=  "+AnsiString(FormatFloat("0.00",d6)));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::syjsytd(TObject *Sender) //时域及时域梯度
{
  /* float p,I[500][20]; //均值、标准层概率密度
    int stdi=cwjd;
    n=6;
   for(int j=1;j<=n;j++)                   //取最大值、最小值
   {
       for(int i1=0;i1<ie1-2;i1++)
       {
           for(int i2=i1+1;i2<ie1-1;i2++)
           {
               if(bzcsj[i1][j]<bzcsj[i2][j])
               {
                   p=bzcsj[i1][j];
                   bzcsj[i1][j]=bzcsj[i2][j];
                   bzcsj[i2][j]=p;
               }
           }
       }
   }
   for(int j=1;j<=n;j++)
   {

       for(int i1=0;i1<ie1-1;i1++)
       {                                          //归一化
          I[i1][j]=xcsj[i1][j]/bzcsj[0][j];

       }

   }
   float sig[20],jz1[20],mdgm[20],mdgm1[30],dtgm[20]; float pp1[20],pp2[20],menkan[20];
   for(int j1=1;j1<=n;j1++)
   {
      pp1[j1]=99999.0;
      pp2[j1]=99999.0;
      menkan[j1]=99999.0;
   }
    pp1[11]=999999.0;
   for(int i=5;i<stedp-ie1-200;i++)
   {
           for(int j1=0;j1<=n;j1++)
           {
             for(int i1=0;i1<ie1-1;i1++)
             {
               xsj[i1][j1]=0.0;
               I1[i1][j1]=0.0;
              }
            }
          for(int i1=i;i1<i+ie1-1;i1++)
          {
            xsj[i1-i][1]=StrToFloat(FormatFloat("0.00",data1[i1][MN1_pos]));
              xsj[i1-i][2]=StrToFloat(FormatFloat("0.00",data1[i1][Rd1_pos]));
                xsj[i1-i][3]=StrToFloat(FormatFloat("0.00",data1[i1][DEN1_pos]));
                  xsj[i1-i][4]=StrToFloat(FormatFloat("0.00",data1[i1][HAC1_pos]));
                    xsj[i1-i][5]=StrToFloat(FormatFloat("0.00",data1[i1][Rxo1_pos]));
                      xsj[i1-i][6]=StrToFloat(FormatFloat("0.00",data1[i1][GR1_pos]));
          }
      float p1;
      for(int j1=1;j1<=n;j1++)
      {
       //sig[j1]=0.0;//计算各条曲线测量值总和，再求平均值
        for(int i1=0;i1<ie1-2;i1++)
         {
          for(int i2=i1+1;i2<ie1-1;i2++)
           {
             if(xsj[i1][j1]<xsj[i2][j1])
             {
               p1=xsj[i1][j1];
               xsj[i1][j1]=xsj[i2][j1];
               xsj[i2][j1]=p1;
              }
            }
         }

     }

     for(int i1=i;i1<i+ie1-1;i1++)
     {
       I1[i1-i][0]=StrToFloat(FormatFloat("0.00",data1[i1][0]));
       I1[i1-i][1]=StrToFloat(FormatFloat("0.00",data1[i1][MN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][1]));   //微电位归一化
       I1[i1-i][2]=StrToFloat(FormatFloat("0.00",data1[i1][Rd1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][2])); //深侧向归一化
       I1[i1-i][3]=StrToFloat(FormatFloat("0.00",data1[i1][DEN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][3])); //密度归一化
       I1[i1-i][4]=StrToFloat(FormatFloat("0.00",data1[i1][HAC1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][4])); //声波归一化
       I1[i1-i][5]=StrToFloat(FormatFloat("0.00",data1[i1][Rxo1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][5])); //微球归一化
       I1[i1-i][6]=StrToFloat(FormatFloat("0.00",data1[i1][GR1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][6])); //伽马归一化

     }
     for(int j=1;j<=n;j++)
     {   //PaintBox2->Canvas->TextOutA(30+j*100,12+4,"xsj[0][j]  "+AnsiString(FormatFloat("0.000",xsj[0][j])));
         float s1[20];
         s1[j]=0.0;
         for(int i1=1;i1<ie1-1;i1++)      //时域及时域梯度  运行结果完美
         {
           s1[j]=s1[j]+0.5*fabs(I[i1][j]-I1[i1][j])+0.5*fabs((I[i1][j]-I[i1-1][j])-(I1[i1][j]-I1[i1-1][j]));
          // PaintBox2->Canvas->TextOutA(30+j*100,i1*12+4,"I1[j]  "+AnsiString(FormatFloat("0.000",I1[i1][j])));  出错
          }
          if(s1[j]<menkan[j])
          {
            menkan[j]=s1[j]; // PaintBox2->Canvas->TextOutA(30+j*100,0+40,"s1[j]  "+AnsiString(FormatFloat("0.000",s1[j])));
            sytdu[j]=I1[stdi][0];//PaintBox2->Canvas->TextOutA(30+j*100,0+80,"I1[stdi][0]  "+AnsiString(FormatFloat("0.000",I1[stdi][0])));
          }
       // PaintBox2->Canvas->TextOutA(30+j*100,0+120,"sytdu[j]  "+AnsiString(FormatFloat("0.000",sytdu[j])));
     }
   }   */
}
//--------------------------------------------------------------------------------------------------------------------------------
void __fastcall TForm1::N14Click(TObject *Sender)                   //动态时间概率密度弯曲度正式算法
{
   Well_Name_1 = ccp;Well_Name_2 = ccp2;Well_Name_1_path = cc1;Well_Name_2_path = cc2;
   ljcw=0; icount=0; n=6;  //老井层位数
   cwjd=16+40;   //层位节点
   int totalnum;  float start,end;
 //  izz=0;      //最终层个数
   ljsdc=0.0;  //老井深度差
   zxcjj=9999.0;    //最小层间距
   int ljcw0=0;
   float a2lj0[500];
  // float bzcsj[500][20];//标准层数据
      FILE *fd,*fgm,*fds,*fsytd;
       FILE *jgdb;//结果对比
   jgdb=fopen("D:\\sddb.dat","wt");   //深度对比
   fd=fopen("D:\\Pearson.dat","wt");
   fgm=fopen("D:\\DTGm.dat","wt");
   fds=fopen("D:\\DS.dat","wt");    //动态时间
   fsytd=fopen("D:\\SYTD.dat","wt"); //时域梯度


     if(fd)
     {
       fprintf(fd,"%s      %s        %s   %s        %s    %s       %s   %s         %s   %s       %s   %s         %s\n",str6[lj],"RMN","RMNDP","RD","RDDP","DEN","DENDP","HAC","HACDP","RXO","RXODP","GR","GRDP");
     }
     if(fgm)
     {
         fprintf(fgm,"%s      %s        %s   %s        %s    %s       %s   %s         %s   %s       %s   %s         %s\n",str6[lj],"RMN","RMNDP","RD","RDDP","DEN","DENDP","HAC","HACDP","RXO","RXODP","GR","GRDP");

     }
     if(fds)
     {
         fprintf(fds,"%s      %s        %s   %s        %s    %s       %s   %s         %s   %s       %s   %s         %s\n",str6[lj],"RMN","RMNDP","RD","RDDP","DEN","DENDP","HAC","HACDP","RXO","RXODP","GR","GRDP");
     }
     if(fsytd)
     {
         fprintf(fsytd,"%s      %s        %s   %s        %s    %s       %s   %s         %s   %s       %s   %s         %s\n",str6[lj],"RMN","RMNDP","RD","RDDP","DEN","DENDP","HAC","HACDP","RXO","RXODP","GR","GRDP");

     }

   //--------------------------------------
   for(int lj0=0;lj0<ljcgs-1;lj0++)
  {
    if(a2[lj0][0]>20.0)    //除掉0
    {
       a2lj0[ljcw0]=a2[lj0][0];
       cjmk[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]+0.5;
       cjmk0[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]-0.6;
       if(cjmk0[ljcw0]<0.2)cjmk0[ljcw0]=0.2;
       ljcw0=ljcw0+1;
    }
  //  cjmk[lj]=1.0+8.0*(1-1.0/float(xzkg));       //2022-10-31修改        严重错误  lj  至少应该改成lj0
   // cjmk0[lj]=1.0-2.0*(1-1.0/float(xzkg));

  }
  for(int ii1=0;ii1<ljcw0-1;ii1++)
  {
     if((zxcjj>fabs(a2lj0[ii1+1]-a2lj0[ii1]))&&(fabs(a2lj0[ii1+1]-a2lj0[ii1])>0.2))
     {
        zxcjj=fabs(a2lj0[ii1+1]-a2lj0[ii1]);
     }
  }
  zxcjj=zxcjj;    //最小层间距   2022-10-31以前

  for(lj=0;lj<ljcgs-1;lj++)    //2022-2-9早上修改  <  换成  <=
  {
    if((a2[lj][0]>20.0)&&((fendp-zzppsd[ljcw-2])>3.0))    //除掉0
    {
      start=a2[lj][0]-2.8;               //n7-4-sp2038   S11----941.5
      end=a2[lj][0]+2.8;                  //n7-4-sp2038   S12---end=a2[0][0]+0.8;
      totalnum=int((end-start)/0.05);
      open_correct=0;//校正开关
    //  PaintBox2->Canvas->TextOutA(80,10+14*(ljcw+1),"处理层位  ");
      str8[ljcw]=str6[lj];   //非空层号
      a2lj[ljcw]=a2[lj][0];
      ljcw=ljcw+1;         //老井层位
      for(int i0=0;i0<stedp;i0++)
      {
            if(fabs(a[i0][0]-start)<0.005)
            {
                 ie1=0;
                 for(int i=i0;i<i0+totalnum+1;i++)
                 {
                      //   fprintf(fp1,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a[i][0],a[i][MN_pos],a[i][Rd_pos],a[i][DEN_pos],a[i][HAC_pos],a[i][Rxo_pos],a[i][GR_pos]);
                        xcsj[ie1][0]=StrToFloat(FormatFloat("0.0",a[i][0]));            //2021年11月2日修改原来深度保留2位小数
                        bzcsj[ie1][0]=xcsj[ie1][0];
                        xcsj[ie1][1]=StrToFloat(FormatFloat("0.00",a[i][MN_pos]));
                        bzcsj[ie1][1]=xcsj[ie1][1];
                        xcsj[ie1][2]=StrToFloat(FormatFloat("0.00",a[i][Rd_pos]));
                        bzcsj[ie1][2]=xcsj[ie1][2];
                        xcsj[ie1][3]=StrToFloat(FormatFloat("0.00",a[i][DEN_pos]));
                        bzcsj[ie1][3]=xcsj[ie1][3];
                        xcsj[ie1][4]=StrToFloat(FormatFloat("0.00",a[i][HAC_pos]));
                        bzcsj[ie1][4]=xcsj[ie1][4];
                        xcsj[ie1][5]=StrToFloat(FormatFloat("0.00",a[i][Rxo_pos]));
                        bzcsj[ie1][5]=xcsj[ie1][5];
                        xcsj[ie1][6]=StrToFloat(FormatFloat("0.00",a[i][GR_pos]));
                        bzcsj[ie1][6]=xcsj[ie1][6];


                        ie1++;
                 }
            }
      }
   //  cjmkz(Sender);
     PaintBox2->Canvas->TextOutA(230,300+14*6,"正在处理第            个小层;");
     PaintBox2->Canvas->TextOutA(306,300+14*6,AnsiString(ljcw));
     PaintBox2->Canvas->TextOutA(400,300+14*6,"共计           个小层!");
     PaintBox2->Canvas->TextOutA(434,300+14*6,AnsiString(ljcw0));
     if((ljcw-1)==(ljcw0-1))
     {
       PaintBox2->Canvas->TextOutA(230,350+14*6,"正在处理最后一个小层,请稍后");
     }
     dtsjglmdwqd(Sender);    //动态时间概率密度弯曲度正式算法
     if(fd)
     {
          fprintf(fd,"%7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f\n",xjcw9[ljcw-1],po2[1],deep2[1],po2[2],deep2[2],po2[3],deep2[3],po2[4],deep2[4],po2[5],deep2[5],po2[6],deep2[6]);
     }
     if(fgm)
     {

         fprintf(fgm,"%7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f\n",xjcw9[ljcw-1],poGM[1],GMdeep2[1],poGM[2],GMdeep2[2],poGM[3],GMdeep2[3],poGM[4],GMdeep2[4],poGM[5],GMdeep2[5],poGM[6],GMdeep2[6]);

     }
     if(fds)
     {

         fprintf(fds,"%7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f\n",xjcw9[ljcw-1],pdtsj1[1],deep1[1],pdtsj1[2],deep1[2],pdtsj1[3],deep1[3],pdtsj1[4],deep1[4],pdtsj1[5],deep1[5],pdtsj1[6],deep1[6]);
     }
     if(fsytd)
     {

         fprintf(fsytd,"%7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f  %7.4f  %7.1f\n",xjcw9[ljcw-1],menkan3[1],sytdu[1],menkan3[2],sytdu[2],menkan3[3],sytdu[3],menkan3[4],sytdu[4],menkan3[5],sytdu[5],menkan3[6],sytdu[6]);

     }

     zzbdp=0.0;
     int in=1,ic=0;
       if((zzppsd[ljcw-1-1]<20.0)&&(ljcw-1)>2)
       {
          for(int ij=1;ij<10;ij++)
          {
             if((zzppsd[ljcw-1-ij]<20.0)&&(ic==0))
             {
                 in=in+1;
             }
             else if(zzppsd[ljcw-1-ij]>20.0)
             {
                ic=1;
             }
          }
       }
          cjmk[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]+0.7;
          cjmk0[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]-0.6;
                if((zzppsd[ljcw-1]>10.0)&&(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1])&&(zzppsd[ljcw-1]>(zzppsd[ljcw-1-in]+zxcjj-0.5))&&((ljcw-1)>1))
                {
                   open_correct=1;
                }
                if(((zzppsd[ljcw-1]<10.0)||(zzppsd[ljcw-1]<zzppsd[ljcw-1-in])||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<zxcjj)||((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<cjmk0[ljcw-1])||((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>cjmk[ljcw-1]))&&(open_correct<3)&&((ljcw-1)>1)) //||(sdeep>0.4)   //&&(open_correct<2)
                {
                   open_correct=0;                 //izz   ->ljcw-1
                }
                if(((zzppsd[ljcw-1]<10.0)||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<zxcjj)||(zzppsd[ljcw-1]<zzppsd[ljcw-1-in])||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<cjmk0[ljcw-1])||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>cjmk[ljcw-1]))&&((ljcw-1)>1)&&(open_correct2<3)&&(open_correct==0))   //||(closefs[ljcw-1]==0)
                {
                   isname=ljcw-1;
                   yxz(Sender);
                }
                if((zzppsd[ljcw-1]<10.0)&&((ljcw-1)<2)&&(open_correct==0))
                {
                   isname=ljcw-1;
                   yxz(Sender);
                }
               if(zzppsd[ljcw-1]<20.0)
                {
                  if((ljcw-1)>55)
                  {
                     PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=             ");
                     PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=    此处层位可能断失 ");
                  }
                  else
                  {
                     PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=             ");
                     PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=    此处层位可能断失 ");
                  }
                }

               //if(zzppsd[ljcw-1]<20.0)zzppsd[ljcw-1]=0.0;
               if(jgdb)
               {
                    fprintf(jgdb,"%s    %8.1f  %8.1f\n",str8[ljcw-1],xjcw9[ljcw-1],zzppsd[ljcw-1]);
               }

    }

   }

                            //整体检查yxz出错层及ljcw-1后置层

       PaintBox2->Canvas->TextOutA(230,350+14*6,"全部处理完成               请核查");
    //   ShowMessage("处理完毕！请核验保存！");
       fclose(fd);fclose(fgm);fclose(fds);fclose(fsytd); fclose(jgdb);


 ///////////////      paintfencengnew(Sender);



     /*
     int JC = 0;
     for(int i = 0;i < 200;i ++)
     {
        if(str6[i] == "JC")
                JC = i;
     }
     for(int i = JC;i < 200;i ++)
     {
        if(zzppsd[i] > 100)
                SentResult[i - JC] = zzppsd[i];
        else
                SentResult[i - JC] = 0;
     }

     if(DBF073_path.Length() > 5)
     {
        Form1->BitBtn6Click(Sender);
                int LastTemp = 0;
                        for(int i = 200 - JC;i > 1;i --)
                        {
                                if(zzppsd[i + JC] > 100)
                                {
                                        LastTemp = i;
                                        break;
                                }

                        }
                        //for(int i = 0;i < 100;i ++)
                        for(int i = 0;i < LastTemp + JC;i ++)
                        {
                                if(zzppsd[i + JC] < 100 && FinDepth[i] > 100)
                                {
                                        if(FinDepth[i] > 100 && FinDepth[i + 1] > 100 && FinDepth[i] > FinDepth[i + 1])
                                        {
                                                float swap = FinDepth[i];
                                                FinDepth[i] = FinDepth[i + 1];
                                                FinDepth[i + 1] = swap;
                                        }


                                        str8[i + JC] = FinUnitName[i];
                                        zzppsd[i + JC] = FinDepth[i];
                                        //ljcw ++;
                                }
                        }
     }
     */


}
//----------------------------------------------------------------------------
void __fastcall TForm1::dtsjglmdwqd(TObject *Sender)  //动态时间概率密度弯曲度正式算法
{
   float s0[30],s1[30],s3[30],s5[30],dfo[30],ds[30],df2[30],df3[30],ss1=0.0,ss2=0.0,ss3=0.0,ds1=0.0,ds2,ds3,dso=0.0,dist1[30],dist2[30];
   int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0;
   float xgxs=0.8,p1[30],p2[30];
   n=6;   open_correct=0;open_correct2=0;
    for(int j=1;j<=n;j++)
    {
      s0[j]=0.0;p1[j]=100000000.0;p2[j]=0.01; bedeep[j][0]=0.0;bedeep[j][1]=0.0;
      for(int i1=0;i1<ie1-1;i1++)
      {
       s0[j]=s0[j]+xcsj[i1][j];
      }
      s0[j]=s0[j]/float(ie1-1);

    }

 //--------------------------------------
         for(int i0=5;i0<stedp1-ie1-20;i0++)
         {
             for(int i=i0;i<i0+ie1+20;i++)
             {
                xssj[i-i0][0]=StrToFloat(FormatFloat("0.00",data1[i][0]));
                xssj[i-i0][1]=data1[i][MN1_pos];
                xssj[i-i0][2]=data1[i][Rd1_pos];
                xssj[i-i0][3]=data1[i][DEN1_pos];
                xssj[i-i0][4]=data1[i][HAC1_pos];
                xssj[i-i0][5]=data1[i][Rxo1_pos];
                xssj[i-i0][6]=data1[i][GR1_pos];
             }
             for(int j=1;j<=n;j++)
             {
                     //皮尔逊相似度
                     s1[j]=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                       s1[j]=s1[j]+xssj[i1][j];
                     }
                     s1[j]=s1[j]/float(ie1-1);
                     ss1=0.0;ss2=0.0;ss3=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                        ss1=ss1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                        ss2=ss2+pow((xcsj[i1][j]-s0[j]),2);
                        ss3=ss3+pow((xssj[i1][j]-s1[j]),2);
                     }
                     dist2[j]=(ss1/sqrt(ss2*ss3));       //皮尔逊相似度
                     if((i0<(stedp1-20))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {

                           if((p2[j]<dist2[j])&&(data1[i0+cwjd][0]>100.0))
                           {
                              p2[j]=dist2[j];
                              po2[j]=dist2[j];
                              deep2[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0])); //2021年11月2日修改原来深度保留2位小数
                              dp2MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                           }
                      }
                    //动态时间弯曲度
                    ds1=0.0;int ic;float sp=0.0,p;ds2=0.0;ds3=0.0,dso=0.0;
                    for(int i1=0;i1<ie1-1;i1++)
                    {
                       if(i1==0)
                       {
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                       else if(i1==1)
                       {
                         sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])      //是否可以使用dfo[i3]>dfo[i4]?
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if(i1==2)
                       {
                         sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                          for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if((i1>2)&&(i1<ie1-4))
                       {
                          sp=0.0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/7.0;
                          ic=0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-4))
                      {
                          sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                          for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-3))
                      {
                          sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                      }
                      else if(i1==(ie1-2))
                      {
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                     }
                      dist1[j]=(ds1/sqrt(ds2*ds3));       //皮尔逊相似度
                      if((i0<(stedp1-50))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {
                        if((p1[j]>dso)&&(data1[i0+cwjd*3][0]>100.0))
                        {
                            p1[j]=dso;
                            pdtsj1[j]=p1[j];
                            deep1[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0]));    //2021年11月2日修改原来深度保留2位小数
                            dp1MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                         }

                      }

             }

         }
//--------------------------------------------------------------------------------
   float bdp0[20],bdp1[20]; int ic0=0,ic=0;
    dtgmwqd(Sender);   //动态概率密度弯曲度
    ljxjdb(Sender); //老井新井对比





}
//---------------------------------------------------------------------------
void __fastcall TForm1::dtgmwqd(TObject *Sender) //动态概率密度弯曲度
{
  float p,I[500][20],jz0[20],bcgm[20]; //均值、标准层概率密度
    int stdi=cwjd; n=6;
   for(int j=1;j<=n;j++)                   //取最大值、最小值
   {
       for(int i1=0;i1<ie1-2;i1++)
       {
           for(int i2=i1+1;i2<ie1-1;i2++)
           {
               if(bzcsj[i1][j]<bzcsj[i2][j])
               {
                   p=bzcsj[i1][j];
                   bzcsj[i1][j]=bzcsj[i2][j];
                   bzcsj[i2][j]=p;
               }
           }
       }
   }
   for(int j=1;j<=n;j++)
   {
       jz0[j]=0.0;
       bcgm[j]=0.0;
       bcgm[j+10]=0.0;
       for(int i1=0;i1<ie1-1;i1++)
       {                                          //归一化
          I[i1][j]=xcsj[i1][j]/bzcsj[0][j];
          jz0[j]=jz0[j]+I[i1][j];
       }
       jz0[j]=jz0[j]/float(ie1-1);
   }
   for(int j=1;j<=n;j++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float(iu)/float(stdi);                 //标准层各条曲线单独概率密度
        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float((ie1-1)-iu)/float(ie1-1-stdi);
        }
   }
 //----------------------------------------------------------------------------- //新井概率密度求取
   float sig[20],jz1[20],mdgm[20],mdgm1[30],dtgm[20]; float pp1[20],pp2[20],menkan[20];
   n=6;
   for(int j1=1;j1<=n;j1++)
   {
      pp1[j1]=99999.0;
      pp2[j1]=99999.0;
      menkan[j1]=99999.0;
   }
    pp1[11]=999999.0;
   for(int i=5;i<stedp1-ie1-20;i++)
   {
           for(int j1=0;j1<=n;j1++)
           {
             for(int i1=0;i1<ie1-1;i1++)
             {
               xsj[i1][j1]=0.0;
               I1[i1][j1]=0.0;
              }
            }
          for(int i1=i;i1<i+ie1-1;i1++)
          {
            xsj[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]));
              xsj[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]));
                xsj[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]));
                  xsj[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]));
                    xsj[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]));
                      xsj[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]));
          }
      float p1;
      for(int j1=1;j1<=n;j1++)
      {
       //sig[j1]=0.0;//计算各条曲线测量值总和，再求平均值
        for(int i1=0;i1<ie1-2;i1++)
         {
          for(int i2=i1+1;i2<ie1-1;i2++)
           {
             if(xsj[i1][j1]<xsj[i2][j1])
             {
               p1=xsj[i1][j1];
               xsj[i1][j1]=xsj[i2][j1];
               xsj[i2][j1]=p1;
              }
            }
         }

     }
     //RMNmin1=Cmin1[1];
     for(int i1=i;i1<i+ie1-1;i1++)
     {
       I1[i1-i][0]=StrToFloat(FormatFloat("0.00",a1[i1][0]));
       I1[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][1]));   //微电位归一化
       I1[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][2])); //深侧向归一化
       I1[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][3])); //密度归一化
       I1[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][4])); //声波归一化
       I1[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][5])); //微球归一化
       I1[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][6])); //伽马归一化
     }
      for(int j=1;j<=n;j++)
     {
         float s1=0.0;
         for(int i1=1;i1<ie1-1;i1++)      //时域及时域梯度  运行结果完美
         {
           s1=s1+0.5*fabs(I[i1][j]-I1[i1][j])+0.5*fabs((I[i1][j]-I[i1-1][j])-(I1[i1][j]-I1[i1-1][j]));
         }
          if(s1<menkan[j])
          {
             menkan[j]=s1;
             menkan3[j]=menkan[j];
             sytdu[j]=I1[stdi][0];
             sytdMN[j]=xsj[stdi][1];
          }
     }
     for(int j1=1;j1<=n;j1++)
     {
         jz1[j1]=0.0; mdgm[j1]=0.0;mdgm[j1+10]=0.0;mdgm1[j1]=0.0;
         for(int i1=0;i1<ie1-1;i1++)
         {
           jz1[j1]=jz1[j1]+I1[i1][j1];
         }
         jz1[j1]=jz1[j1]/float(ie1-1);
     }
   for(int j1=1;j1<=n;j1++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
         //   mdgm[j1]=mdgm[j1]+(I1[iu][j1]-jz1[j1])*I1[iu][j1]/(jz1[j1]*float(ie1-1));            //float(iu)/float(stdi);                 //目的层各条曲线单独概率密度
            if(iu==0)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
            }
            else if(iu==1)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                            //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
              mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==2)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if((iu>2)&&(iu<=stdi))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));            //       float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }

        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            if((iu>=stdi)&&(iu<ie1-4))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));          //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-4)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));       // float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-3)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                    //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-2)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                        //float((ie1-1)-iu)/float(ie1-1-stdi);
            }
        }
   }
        float menkan[20];
           for(int j1=1;j1<=n;j1++)
          {
             menkan[j1]=99999.0;
             if((mdgm1[j1]<pp2[j1])&&((a1[i+20][MN1_pos]*a1[i+20][Rd1_pos]*a1[i+20][DEN1_pos]*a1[i+20][HAC1_pos]*a1[i+20][Rxo1_pos]*a1[i+20][GR1_pos])>1.0))
             {
                pp2[j1]=mdgm1[j1];
                poGM[j1]=pp2[j1];
                GMdeep2[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][0]));
                GMMN[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][MN1_pos]));
             }
          }

    }



}
//--------------------------------------------------------------------------------------------------------------------------------

void __fastcall TForm1::ljxjdb(TObject *Sender) //老井新井对比
{
     float s[30],dp[30],s2[30],s3[30],s4[30],p01=0.0,p02=0.0,p03=0.0,p04=0.0,p11=9999.0,p22=9999.0,p33=9999.0,p44=9999.0; //新老深度
     int dbnum=0;  //对比数
    // sdeep1=0.0;
     float dp1=0.0,dp2=0.0,dp3=0.0;
     n=6;
          int in=1,ic=0;
          if((zzppsd[ljcw-1-1]<20.0)&&(ljcw-1)>2)
          {
             for(int ij=1;ij<20;ij++)
             {
                if((zzppsd[ljcw-1-ij]<20.0)&&(ic==0))
                {
                    in=in+1;
                }
                else if(zzppsd[ljcw-1-ij]>20.0)
                {
                   ic=1;
                }
             }
          }


          cjmk[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]+0.7;
          cjmk0[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]-0.6;
     for(int i1=-1;i1<29;i1++)
     {
        s[i1]=9999.0;
        s2[i1]=9999.0;
        s3[i1]=9999.0;
        s4[i1]=9999.0;
        xldeep[i1]=-1.0;    //新老深度
        dp[i1]=-1.0;
        xlzjdeep[i1]=-1.0;   // 新老最佳深度
     }
     for(int j=1;j<=n;j++)
     {
      if(((ljcw-1)<2))
      {
          if(((ljcw-1)==0))       //第一个层       2022-11-03            if((str8[iop]=="JC")||(str8[iop]=="S31")||(str8[iop]=="S37")||(str8[iop]=="P21"))
          {

            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
            {
               if((s[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(p01<dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p01=dp2MN[j];
               }
            }
            else
            {
               if((s[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(p11>dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p11=dp2MN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
            {
               if((s[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(p02<sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p02=sytdMN[j];
               }
            }
            else
            {
               if((s[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(p22>sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p22=sytdMN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
            {
               if((s[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(p03<dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
               }
            }
            else
            {
               if((s[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(p33>dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p33=dp1MN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
            {
               if((s[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(p04<GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
               }
            }
            else
            {
               if((s[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(p44>GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p44=GMMN[j];
               }
            }
          }

          if((ljcw-1)==1)                                            //第二个层
          {
              ljsdc=0.0;p01=0.0;p02=0.0;p03=0.0;p04=0.0;p11=9999.0;p22=9999.0;p33=9999.0;p44=9999.0;
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="P21"))
              {
                 if((p01<dp1MN[j])&&(s2[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                 {
                    s2[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                    xldeep[1]=deep2[j];
                    p01=dp2MN[j];
                 }
              }
              else
              {
                 if((p11>dp1MN[j])&&(s2[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                 {
                    s2[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                    xldeep[1]=deep2[j];
                    p11=dp2MN[j];
                 }
              }
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
              {
                  if((p02<sytdMN[j])&&(s2[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                    s2[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                    xldeep[2]=sytdu[j];
                    p02=sytdMN[j];
                  }
              }
              else
              {
                  if((p22>sytdMN[j])&&(s2[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                    s2[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                    xldeep[2]=sytdu[j];
                    p22=sytdMN[j];
                  }
              }
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="P21"))
              {
                  if((p03<dp1MN[j])&&(s2[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                     xldeep[3]=deep1[j];
                     p03=dp1MN[j];
                  }
              }
              else
              {
                  if((p33>dp1MN[j])&&(s2[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                     xldeep[3]=deep1[j];
                     p33=dp1MN[j];
                  }
              }
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
              {
                  if((p04<GMMN[j])&&(s2[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                     xldeep[4]=GMdeep2[j];
                     p04=GMMN[j];
                  }
              }
              else
              {
                  if((p44>GMMN[j])&&(s2[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                     xldeep[4]=GMdeep2[j];
                     p44=GMMN[j];
                  }
              }
          }
      }
      else                                         //第三个层及以后的层
      {

          float f1[10];p01=0.0;p02=0.0;p03=0.0;p04=0.0;p11=9999.0;p22=9999.0;p33=9999.0;p44=9999.0;
          f1[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
          f1[1]=deep2[j]-zzppsd[ljcw-1-in];
          f1[2]=sytdu[j]-zzppsd[ljcw-1-in];
          f1[3]=deep1[j]-zzppsd[ljcw-1-in];
          f1[4]=GMdeep2[j]-zzppsd[ljcw-1-in];
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
             if((p01<dp2MN[j])&&(s3[1]>fabs(f1[0]-f1[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                s3[1]=fabs(f1[0]-f1[1]);
                xldeep[1]=deep2[j];
                p01=dp2MN[j];
             }
          }
          else
          {
              if((p11>dp2MN[j])&&(s3[1]>fabs(f1[0]-f1[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                 s3[1]=fabs(f1[0]-f1[1]);
                 xldeep[1]=deep2[j];
                 p11=dp2MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
             if((p02<sytdMN[j])&&(s3[2]>fabs(f1[0]-f1[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                 s3[2]=fabs(f1[0]-f1[2]);
                 xldeep[2]=sytdu[j];
                 p02=sytdMN[j];
             }
          }
          else
          {
              if((p22>sytdMN[j])&&(s3[2]>fabs(f1[0]-f1[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                  s3[2]=fabs(f1[0]-f1[2]);
                  xldeep[2]=sytdu[j];
                  p22=sytdMN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
             if((p03<dp1MN[j])&&(s3[3]>fabs(f1[0]-f1[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                 s3[3]=fabs(f1[0]-f1[3]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
             }
          }
          else
          {
              if((p33>dp1MN[j])&&(s3[3]>fabs(f1[0]-f1[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                  s3[3]=fabs(f1[0]-f1[3]);
                  xldeep[3]=deep1[j];
                  p33=dp1MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
             if((p04<GMMN[j])&&(s3[4]>fabs(f1[0]-f1[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                 s3[4]=fabs(f1[0]-f1[4]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
             }
          }
          else
          {
              if((p44>GMMN[j])&&(s3[4]>fabs(f1[0]-f1[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                  s3[4]=fabs(f1[0]-f1[4]);
                  xldeep[4]=GMdeep2[j];
                  p44=GMMN[j];
              }
          }

       if((zzppsd[ljcw-1-1]<20.0)&&((ljcw-1)>1))   //上层判别无结果
       {

          float f2[10];p01=0.0;p02=0.0;p03=0.0;p04=0.0;p11=9999.0;p22=9999.0;p33=9999.0;p44=9999.0;
          f2[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
          f2[1]=deep2[j]-zzppsd[ljcw-1-in];
          f2[2]=sytdu[j]-zzppsd[ljcw-1-in];
          f2[3]=deep1[j]-zzppsd[ljcw-1-in];
          f2[4]=GMdeep2[j]-zzppsd[ljcw-1-in];
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
              if((p01<dp2MN[j])&&(s4[1]>fabs(f2[0]-f2[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[1]=fabs(f2[0]-f2[1]);
                  xldeep[1]=deep2[j];
                  p01=dp2MN[j];
              }
          }
          else
          {
              if((p11>dp2MN[j])&&(s4[1]>fabs(f2[0]-f2[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[1]=fabs(f2[0]-f2[1]);
                  xldeep[1]=deep2[j];
                  p11=dp2MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
              if((p02<sytdMN[j])&&(s4[2]>fabs(f2[0]-f2[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((sytdu[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[2]=fabs(f2[0]-f2[2]);
                  xldeep[2]=sytdu[j];
                  p02=sytdMN[j];
              }
          }
          else
          {
              if((p22>sytdMN[j])&&(s4[2]>fabs(f2[0]-f2[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((sytdu[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[2]=fabs(f2[0]-f2[2]);
                  xldeep[2]=sytdu[j];
                  p22=sytdMN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
              if((p03<dp1MN[j])&&(s4[3]>fabs(f2[0]-f2[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep1[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[3]=fabs(f2[0]-f2[3]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
              }
          }
          else
          {
              if((p33>dp1MN[j])&&(s4[3]>fabs(f2[0]-f2[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep1[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[3]=fabs(f2[0]-f2[3]);
                 xldeep[3]=deep1[j];
                 p33=dp1MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21")||(str8[ljcw-1]=="JCJC"))
          {
              if((p04<GMMN[j])&&(s4[4]>fabs(f2[0]-f2[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((GMdeep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[4]=fabs(f2[0]-f2[4]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
              }
          }
          else
          {
              if((p44>GMMN[j])&&(s4[4]>fabs(f2[0]-f2[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((GMdeep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[4]=fabs(f2[0]-f2[4]);
                 xldeep[4]=GMdeep2[j];
                 p44=GMMN[j];
              }
          }
       }
      }
     }
        int ip1[10],ip2[10],ik=0;
         float f22[10];

         for(int j0=0;j0<10;j0++)
         {
            f22[j0]=1.0;
         }                               //此处添加   2022-11-1晚上
        if(xldeep[1]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[1]=deep2[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[1]))&&(fabs(deep2[j0]-deep2[j1])<0.4)&&(deep2[j0]>zzppsd[ljcw-1-in])&&(deep2[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[1]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(deep2[ip1[iy]],deep2[ip2[iy]],ljcw-1);
               xldeep[1]=hfsd;
           }
        }
        ik=0;

        if(xldeep[2]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[2]=sytdu[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[2]))&&(fabs(sytdu[j0]-sytdu[j1])<0.4)&&(sytdu[j0]>zzppsd[ljcw-1-in])&&(sytdu[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f2[0]-f2[2]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(sytdu[ip1[iy]],sytdu[ip2[iy]],ljcw-1);
               xldeep[2]=hfsd;
           }
        }
        ik=0;

        if(xldeep[3]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[3]=deep1[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[3]))&&(fabs(deep1[j0]-deep1[j1])<0.4)&&(deep1[j0]>zzppsd[ljcw-1-in])&&(deep1[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[3]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
                xjwdjzxz(deep1[ip1[iy]],deep1[ip2[iy]],ljcw-1);
                xldeep[3]=hfsd;
           }
        }
        ik=0;

        if(xldeep[4]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];

                  f22[4]=GMdeep2[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[4]))&&(fabs(GMdeep2[j0]-GMdeep2[j1])<0.4)&&(GMdeep2[j0]>zzppsd[ljcw-1-in])&&(GMdeep2[j1]>zzppsd[ljcw-1-in]))
                  {
                   //  float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[4]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(GMdeep2[ip1[iy]],GMdeep2[ip2[iy]],ljcw-1);
               xldeep[4]=hfsd;
           }
        }
    if((ljcw-1)>55)
    {
       PaintBox4->Canvas->TextOutA(230+1*100,0+(ljcw-57)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
       PaintBox4->Canvas->TextOutA(230+2*100,0+(ljcw-57)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
       PaintBox4->Canvas->TextOutA(230+3*100,0+(ljcw-57)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
       PaintBox4->Canvas->TextOutA(230+4*100,0+(ljcw-57)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
    else
    {
        PaintBox2->Canvas->TextOutA(230+1*100,0+(ljcw-1)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
        PaintBox2->Canvas->TextOutA(230+2*100,0+(ljcw-1)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
        PaintBox2->Canvas->TextOutA(230+3*100,0+(ljcw-1)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
        PaintBox2->Canvas->TextOutA(230+4*100,0+(ljcw-1)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
     dbnum=0;

     f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];

     float pmin=9999.0;
     int correct=0;
  if((ljcw-1)<=2)
  {
     for(int i1=1;i1<=3;i1++)
     {
         for(int i2=i1+1;i2<=4;i2++)
         {

            if((fabs(xldeep[i1]-xldeep[i2])<0.42)&&(dbnum<4)&&(xldeep[i1]>20.0))     // 此处可以选取微电极最低值
            {

             //     float hfsd;       //回返深度
                  xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

                  xlzjdeep[0]=hfsd;
                  open_correct=1;
                  dbnum=dbnum+1;
            }
         }
     }
  }
  else if((ljcw-1)>2)
  {
     for(int i1=1;i1<=3;i1++)
     {
         for(int i2=i1+1;i2<=4;i2++)
         {
            f22[5]=xldeep[i1]-zzppsd[ljcw-1-in];
            f22[6]=xldeep[i2]-zzppsd[ljcw-1-in];
            if((correct==0)&&(fabs(xldeep[i1]-xldeep[i2])<0.42)&&(dbnum<4)&&(xldeep[i1]>20.0)&&(fabs(f22[0]-f22[5])<cjmk[ljcw-1])&&(pmin>fabs(f22[0]-f22[5])))     // 此处可以选取微电极最低值
            {
                  pmin=fabs(f22[0]-f22[5]);
             //     float hfsd;       //回返深度
                  xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

                  xlzjdeep[0]=hfsd;
                  open_correct=1;
                  correct=1;
                  dbnum=dbnum+1;
            }
            else if((correct==0)&&(fabs(f22[0]-f22[5])<0.42))
            {
                 // xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

                  xlzjdeep[0]=xldeep[i1];
                  open_correct=1;
                  correct=1;
                  dbnum=dbnum+1;
            }
            else if((correct==0)&&(fabs(f22[0]-f22[6])<0.42))
            {

                  xlzjdeep[0]=xldeep[i2];
                  open_correct=1;
                  correct=1;
                  dbnum=dbnum+1;
            }
         }
     }
  }
                zzppsd[ljcw-1]=xlzjdeep[0];   //最终匹配深度
                if(zzppsd[ljcw-1]>20.0)
                {
                   open_correct=1;
                }
                if((zzppsd[ljcw-1-1]<20.0)&&(zzppsd[ljcw-1]>20.0)&&(zzppsd[ljcw-1]>zzppsd[ljcw-1-in])&&((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
                {
                   open_correct2=3;
                }
              if((ljcw-1)>55)
              {
                PaintBox4->Canvas->TextOutA(80+0*120,0+(ljcw-57)*12,str8[ljcw-1]);
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=             ");
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw-1])));
              }
              else
              {
                 PaintBox2->Canvas->TextOutA(80+0*120,0+(ljcw-1)*12,str8[ljcw-1]);
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=             ");
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw-1])));
              }

}
//-----------------------------------------------------------------------------------
void __fastcall TForm1::paintfencengnew(TObject *Sender)
{
  PaintBox4->Canvas->Pen->Width=1;
  PaintBox4->Canvas->Pen->Style=psSolid;
  float deep1;
  int tw;
  tw=Form1->Width/2.2-5;
 for(int i0=0;i0<stedp1;i0++)
 {
    deep1=stdp1+i0*relv1;
    for(int ii0=0;ii0<ljcw;ii0++)
    {
      if(fabs(deep1-mbdeep[ii0])<0.01)
      {
          PaintBox4->Canvas->Pen->Color=RGB(210,20,ii0);
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(40+tw+30,i0);
          if(moveopen2==0)
          {
             PaintBox4->Canvas->TextOut(40+tw-14,i0-14,str8[ii0]);
             PaintBox4->Canvas->TextOut(40+tw-14,i0+3,AnsiString(FormatFloat("0.0",mbdeep[ii0])));
          }
       }
    }
  }
    hdhf(Sender);  //厚度划分
}
//-----------------------------------------------------------------------------------
void __fastcall TForm1::yxz(TObject *Sender)    //硬修正 2021-12-24日增加
{

   n=6;int i01=0;//open_switch=1;
   FILE *fp; int i2=n+1;ie1=0;AnsiString Dir;
   if(xzkg==1)
   {          // xzkg;  //选择开关
       Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\"+str16[isname]+"\\";
   }
   else if(xzkg==2)
   {
      Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\沉积单元数据库\\"+str16[isname]+"\\";
   }
   TSearchRec sr;
   TStringList *FileList = new TStringList();


   ccp2.SetLength(ccp2.Length()-3);
   AnsiString filename = ccp2;                 //文件名
   ccp2.SetLength(ccp2.Length()+3);
   int count = filename.Length();              //文件名字符数
   AnsiString s1;
   AnsiString s2;
   AnsiString s4;
   AnsiString s6;

   char * filename1 = filename.c_str();
   for(int i = 0;i < count-1;i++)
   {
        s1 = s1 + filename1[i];
   }
   for(int i = 0;i < count-2;i++)
   {
        s2 = s2 + filename1[i];
   }
   for(int i = 0;i < count-4;i++)
   {
        s4 = s4 + filename1[i];
   }
   for(int i = 0;i < count-6;i++)
   {
        s6 = s6 + filename1[i];
   }

   AnsiString Dir00 = Dir + "n*.*" + '.';      //n开头文件
   AnsiString Dir1 = Dir + s1 + "*.*" + '.';   //前count-1个字符相同文件
   AnsiString Dir2 = Dir + s2 + "*.*" + '.';   //前count-2个字符相同文件
   AnsiString Dir4 = Dir + s4 + "*.*" + '.';   //前count-4个字符相同文件
   AnsiString Dir6 = Dir + s6 + "*.*" + '.';   //前count-6个字符相同文件

   int same = 0;                               //重复文件名判断
   vector<AnsiString> temp;                    //操作数组
   vector<AnsiString> fil;                     //文件名序列数组
   vector<AnsiString> fil2;                    //文件名数组


   FindFirst(Dir1, faAnyFile, sr);             //前count-1个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir2, faAnyFile, sr);            //前count-2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));

   FindFirst(Dir4, faAnyFile, sr);            //前count-4个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
////                                          //前count-6个字符相同文件加入FileList和fil数组
   FindFirst(Dir6, faAnyFile, sr);
   do{
     same = 0;
     for(int i =0;i<temp.size();i++)
     {
        if(temp[i]==Dir + sr.Name) same = 1;
     }
     if (same == 1) continue;
     FileList->Add(Dir + sr.Name);
     fil.push_back(Dir + sr.Name);
     fil2.push_back(sr.Name);
     }while(FindNext(sr) == 0);
     same = 0;
////                                           ////n开头文件加入FileList和fil数组
     FindFirst(Dir00, faAnyFile, sr);
     do{
     same = 0;
     for(int i =0;i<temp.size();i++)
     {
        if(temp[i]==Dir + sr.Name) same = 1;
     }
     if (same == 1) continue;
     FileList->Add(Dir + sr.Name);
     fil.push_back(Dir + sr.Name);
     fil2.push_back(sr.Name);
     }while((FindNext(sr) == 0));
     same = 0;


   temp.clear();
   FileList->Count;                           //文件名列表计数
   AnsiString o1 = FileList->Text;
   FileList->SaveToFile("D:\\001.txt");     //输出文件名到txt

   string fname[20];                         //文件路径数组
   string fn[20];                         //文件名数组
   int file_count = 0;
   for(int i = 0;i < 20;i ++)                //前20个文件
   {
        fname[i] = fil[i].c_str();
        fn[i] = fil2[i].c_str();
        file_count ++;
        if(file_count == fil.size())
        break;
   }

int num = 0;
if (file_count >3)
{
do{
      if (num == file_count)
      break;
      //FileList->Add(Dir + sr.Name);
     // PaintBox2->Canvas->TextOut(120,2+(i01+1)*14,fn[num].c_str());
      if((zzppsd[isname]<10.0)&&(open_correct==0)&&(isname<=2))
      {
        fp=fopen(fname[num].c_str(),"r");
        if(fp)
        {
           ie1=0; i01=i01+1;  //计算打开非零文件个数
           fscanf(fp,"%f",&S11d);
           S11d=StrToFloat(FormatFloat("0.00",S11d));
           while(feof(fp)==0)
           {
                for(int j=0;j<i2;j++)
                {
                        fscanf(fp,"%f",&xcsj[ie1][j]);
                        xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
                        bzcsj[ie1][j]=xcsj[ie1][j];
                }
                ie1++;
           }
           dtsjglmdwqd(Sender);
        }

      }
       int in=1,ic=0;
       if((zzppsd[isname]<20.0)&&((ljcw-1)>2))    //上层判别无结果
       {
          for(int ij=0;ij<10;ij++)
          {
             if((zzppsd[isname-ij]<20.0)&&(ic==0))
             {
                 in=in+1;
             }
             else if(zzppsd[ljcw-1-ij]>20.0)
             {
                ic=1;
             }
          }
       }
       cjmk[isname]=a2lj[isname]-a2lj[isname-in]+0.7;
       cjmk0[isname]=a2lj[isname]-a2lj[isname-in]-0.6;
      if((((zzppsd[isname]<10.0)||(zzppsd[isname]<zzppsd[isname-in+1])||(fabs(zzppsd[isname]-zzppsd[isname-in+1])<cjmk0[isname])||(fabs(zzppsd[isname]-zzppsd[isname-in+1])>cjmk[isname])))&&(isname>1)&&(open_correct==0))      //(open_correct2==0)||if((zzppsd[isname]<0.0)||(zzppsd[ljcw-1]<zzppsd[ljcw-2])||(open_correct2==0;))  2022-1 - 1晚修改  ||(closefs[ljcw-1]==0)
      {
        fp=fopen(fname[num].c_str(),"r");
        if(fp)
        {
           ie1=0; i01=i01+1;  //计算打开非零文件个数
           fscanf(fp,"%f",&S11d);
           S11d=StrToFloat(FormatFloat("0.00",S11d));
           while(feof(fp)==0)
           {
             for(int j=0;j<i2;j++)
              {
                  fscanf(fp,"%f",&xcsj[ie1][j]);
                  xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
                  bzcsj[ie1][j]=xcsj[ie1][j];
              }
               ie1++;
            }

             dtsjglmdwqd(Sender);
        }
      }
      num ++;
     fclose(fp);
     }while((i01 < 5));    //while((i01 < 20));   2023-08-13  改为循环5口井

    FindClose(sr);
    open_correct=3;  //校正开关
    open_correct2=3;

   }

}
//--------------------------------------------------------------------
void __fastcall TForm1::xjwdjzxz(float dp1,float dp2,int iop)  //新井微电极最小值  返回深度
{
   float MNZ1,MNZ2;
   if((str8[iop]=="JC")||(str8[iop]=="S31")||(str8[iop]=="S37")||(str8[iop]=="P21")||(str8[iop]=="JCJC"))
   {
      for(int i0=0;i0<stedp1-50;i0++)
      {
          if(fabs(a1[i0][0]-dp1)<0.03)
           {
             MNZ1=a1[i0][MN1_pos];
           }
          if(fabs(a1[i0][0]-dp2)<0.03)
           {
             MNZ2=a1[i0][MN1_pos];
           }
      }
      if(MNZ1>MNZ2)
      {
        hfsd=dp1;
      }
      else
      {
         hfsd=dp2;            //回返深度
      }

   }
   else
   {
      for(int i0=0;i0<stedp1-50;i0++)
      {
          if(fabs(a1[i0][0]-dp1)<0.03)
           {
             MNZ1=a1[i0][MN1_pos];
           }
          if(fabs(a1[i0][0]-dp2)<0.03)
           {
             MNZ2=a1[i0][MN1_pos];
           }
      }
      if(MNZ1<MNZ2)
      {
        hfsd=dp1;
      }
      else
      {
         hfsd=dp2;            //回返深度
      }
   }


}
//------------------------------------------------------------------------------
void __fastcall TForm1::PaintBox4MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
 if(pd1==1)    //putdown
   {

            int ii0=icolor;
            PaintBox4->Canvas->Pen->Width=5;
            PaintBox4->Canvas->Pen->Style=psSolid;
            PaintBox4->Canvas->Pen->Color=clBtnFace;
            PaintBox4->Canvas->MoveTo(4+0,Y1);
            PaintBox4->Canvas->LineTo(140+150*4+30,Y1);
            PaintBox4->Canvas->TextOutA(140+150*4,Y1-14,"                                                             ");
            PaintBox4->Canvas->TextOutA(140+150*4,Y1+3,"                                                              ");
            PaintBox4->Canvas->Pen->Width=1;
            PaintBox4->Canvas->Pen->Style=psSolid;
            PaintBox4->Canvas->Pen->Color=RGB(210,20,ii0);
            PaintBox4->Canvas->MoveTo(4+0,Y);
            PaintBox4->Canvas->LineTo(140+150*4+30,Y);
            PaintBox4->Canvas->TextOutA(140+150*4-14,Y-14,str8[ii0]);
            mbdeep[ii0]=stdp1+Y*relv1;
            PaintBox4->Canvas->TextOutA(140+150*4-14,Y+3,AnsiString(FormatFloat("0.0",mbdeep[ii0])));
            Y1=Y;

   }

     PaintBox4Paint(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::cjmkz(TObject *Sender)    //层间门槛值
{
   int im=0; float zxcjj2;
   if(zxcjj<=0.41)
   {
      zxcjj2=zxcjj*2.0;          //最小层间距
   }
   else if((zxcjj>0.41)&&(zxcjj<=0.61))
   {
      zxcjj2=zxcjj*1.5;
   }
   else if((zxcjj>0.61)&&(zxcjj<=0.81))
   {
      zxcjj2=zxcjj*1.2;
   }
   else
   {
      zxcjj2=zxcjj;
   }
   if((ljcw-1)>1)
   {
      if(zzppsd[ljcw-1-1]>20.0)
      {
          cjmk[ljcw-1]=(a2lj[ljcw-1]-a2lj[ljcw-2])+float(xzkg)*zxcjj2;    //基于老井层间距   最小层间距      原来zxcjj=3.0；
          cjmk0[ljcw-1]=(a2lj[ljcw-1]-a2lj[ljcw-2])-float(xzkg)*zxcjj2;
          if(cjmk0[ljcw-1]<0.3)cjmk0[ljcw-1]=0.3;
      }
      else
      {
          do{
              im=im+1;
          }while((zzppsd[ljcw-1-im]<20.0));
        //  cjmk[ljcw-1]=(a2lj[ljcw-1]-a2lj[ljcw-1-2])+zxcjj+1.8;    //基于老井层间距   最小层间距      原来zxcjj=3.0；
        //  cjmk0[ljcw-1]=(a2lj[ljcw-1]-a2lj[ljcw-1-2])-zxcjj-2.0;
          cjmk[ljcw-1]=(a2lj[ljcw-1]-a2lj[ljcw-1-im]-1)+float(xzkg)*(im+1)*zxcjj2;    //基于老井层间距   最小层间距      原来zxcjj=3.0；
          cjmk0[ljcw-1]=(a2lj[ljcw-1]-a2lj[ljcw-1-im-1])-float(xzkg)*(im+1)*zxcjj2;
          if(cjmk0[ljcw-1]<0.3)cjmk0[ljcw-1]=0.3;
      }
     // cjmk=(a2[lj-1][0]-a2[lj-2][0])+4.0;
    /*  PaintBox2->Canvas->TextOut(120+150*4,(ljcw-1)*14+3,"a2-a1= "+AnsiString(FormatFloat("0.0",(a2lj[ljcw-1]-a2lj[ljcw-2]))));
      PaintBox2->Canvas->TextOut(120+150*3,(ljcw-1)*14+3,"cjmk= "+AnsiString(FormatFloat("0.0",cjmk[ljcw-1])));
      PaintBox2->Canvas->TextOut(120+150*2,(ljcw-1)*14+3,"cjmk0= "+AnsiString(FormatFloat("0.0",cjmk0[ljcw-1])));
      PaintBox2->Canvas->TextOut(120+150*1,(ljcw-1)*14+3,"zxcjj= "+AnsiString(FormatFloat("0.0",zxcjj)));  */
   }
   else
   {
      if((str16[ljcw-1]>="S11")&&(str16[ljcw-1]<"S999+999"))
      {
         cjmk[ljcw-1]=5.0+4.4*(1.0-1.0/float(xzkg));
      }
      else if((str16[ljcw-1]>="P11")&&(str16[ljcw-1]<"P999+999"))
      {
         cjmk[ljcw-1]=20.0/float(xzkg);
      }
      else if((str16[ljcw-1]>="G11")&&(str16[ljcw-1]<"G999+999"))
      {
         cjmk[ljcw-1]=12.0-2.0*(1-1/float(xzkg));
      }
      else
      {
         cjmk[ljcw-1]=13.0;
      }
   }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::N16Click(TObject *Sender)
{
       int totalnum1=ljcw;
       for(int i=0;i<totalnum1;i++)
        {
          jhw1[i]=str8[i];
         // xcw1[i]=zzppsd[i];
          xcw1[i]=mbdeep[i];
          dsw1[i]=0.0;
          hdw1[i]=0.0;
          dbsd1[i]=0.0;
          syhd1[i]=0.0;
          yxhdd1[i]=0.0;
          dsw1[i]=0.0;
          lb1[i]=NULL;
          jcs1[i]=0;
          jsxh[i]=0;
          kxd1[i]=0.0;
          stltz1[i]=NULL;
          zstl1[i]=0.0;
          zdcxs1[i]=0.0;
          hsbhd1[i]=0.0;
          sfsbh1[i]=0.0;
          syjs1[i]=NULL;
          dcjs1[i]=NULL;
          sk1[i]=NULL;
          bk1[i]=NULL;
        }

    bccwsjk(Sender);       //保存层位数据库
}
//---------------------------------------------------------------------------
void __fastcall TForm1::hdhf(TObject *Sender)  //新井厚度划分
{
      float deep1,deep2,deep3,MNmkz,HACmkz;    //MN门槛值、HAC门槛值
      MNmkz=4.0;
      HACmkz=290.0;
      int tw,sw1=0;
      tw=Form1->Width/19.0;
          PaintBox4->Canvas->Pen->Width=2;
          PaintBox4->Canvas->Pen->Style=psSolid;
          PaintBox4->Canvas->Pen->Color=clBlack;
      int ihd=0,ihd0=0;
 for(int i0=0;i0<stedp1;i0++)
 {
    deep1=stdp1+i0*relv1;
    for(int ii0=0;ii0<(ljcw-1-1);ii0++)
    {
      if((fabs(deep1-zzppsd[ii0])<0.01))    //&&(deep1<=zzppsd[ii0+1])
      {

          for(int i1=i0;i1<=i0+int((zzppsd[ii0+1]-zzppsd[ii0])/relv1);i1++)
          {
                if((a1[i1][MN1_pos]>MNmkz)&&(a1[i1][HAC1_pos]>HACmkz)&&(sw1==0))
                {
                        PaintBox4->Canvas->MoveTo(tw,i1);
                        PaintBox4->Canvas->LineTo(tw+7,i1);
                        xjbwhd0[ihd0][0]=stdp1+i1*relv1;

                        PaintBox4->Canvas->MoveTo(tw,i1);
                        sw1=1;

                 }
                        deep2=stdp1+(i1+1)*relv1;
                        if((fabs(deep2-zzppsd[ii0+1])<0.01)&&(sw1==1))
                        {
                           PaintBox4->Canvas->LineTo(tw,i1);
                           PaintBox4->Canvas->MoveTo(tw,i1);
                           PaintBox4->Canvas->LineTo(tw+7,i1);
                           xjbwhd0[ihd0][1]=stdp1+i1*relv1;
                           ihd0=ihd0+1;
                           xjbwhd0[ihd0][0]=stdp1+i1*relv1;

                           PaintBox4->Canvas->MoveTo(tw,i1);

                           sw1=0;
                        }
                if(((a1[i1][MN1_pos]<MNmkz)||(a1[i1][HAC1_pos]<HACmkz))&&(sw1==1))
                {
                        PaintBox4->Canvas->LineTo(tw,i1);
                        PaintBox4->Canvas->MoveTo(tw,i1);
                        PaintBox4->Canvas->LineTo(tw+7,i1);
                        xjbwhd0[ihd0][1]=stdp1+i1*relv1;
                        ihd0=ihd0+1;
                        sw1=0;
                }
          }

       }
    }
  }
     for(int i0=0;i0<ihd0;i0++)
     {
        if((xjbwhd0[i0][1]-xjbwhd0[i0][0])>=0.2)
        {
           xjbwhd[ihd][0]=xjbwhd0[i0][0];
           xjbwhd[ihd][1]=xjbwhd0[i0][1];
           ihd=ihd+1;
        }
     }
            PaintBox4->Canvas->Pen->Width=2;
            PaintBox4->Canvas->Pen->Style=psSolid;
            PaintBox4->Canvas->Pen->Color=clRed;
     int ih=0;
      for(int i0=0;i0<stedp1;i0++)
      {
           deep3=stdp1+i0*relv1;
           if(fabs(deep3-xjbwhd[ih][0])<0.01)
           {
              PaintBox4->Canvas->MoveTo(tw-5,i0);
              PaintBox4->Canvas->LineTo(tw+7-5,i0);
              PaintBox4->Canvas->MoveTo(tw-5,i0);
           }
           if(fabs(deep3-xjbwhd[ih][1])<0.01)
           {
              PaintBox4->Canvas->LineTo(tw-5,i0);
              PaintBox4->Canvas->MoveTo(tw-5,i0);
              PaintBox4->Canvas->LineTo(tw+7-5,i0);
              ih=ih+1;
           }
      }


}
//-----------------------------------------------------------------------------
void __fastcall TForm1::ljhdhf(TObject *Sender)  //老井厚度划分
{
      float deep1,deep2,deep3,MNmkz,HACmkz;    //MN门槛值、HAC门槛值
      MNmkz=4.0;
      HACmkz=290.0;
      int tw,sw1=0;
      tw=Form1->Width/19.0;
            PaintBox2->Canvas->Pen->Width=2;
            PaintBox2->Canvas->Pen->Style=psSolid;
            PaintBox2->Canvas->Pen->Color=clRed;
      int ihd0=0,ihd=0;
 for(int i0=0;i0<stedp;i0++)
 {
    deep1=stdp+i0*relv;
    for(int ii0=0;ii0<(ljcs-1-1);ii0++)
    {
      if((fabs(deep1-a21lj[ii0])<0.01))     //&&(deep1<=a21lj[ii0+1])
      {
          for(int i1=i0;i1<=i0+int((a21lj[ii0+1]-a21lj[ii0])/relv);i1++)
          {
                if((a[i1][MN_pos]>MNmkz)&&(a[i1][HAC_pos]>HACmkz)&&(sw1==0))
                {
                        PaintBox2->Canvas->MoveTo(tw,i1);
                        PaintBox2->Canvas->LineTo(tw+7,i1);
                        ljbwhd0[ihd0][0]=stdp+i1*relv;

                        PaintBox2->Canvas->MoveTo(tw,i1);
                        sw1=1;

                 }
                        deep2=stdp+(i1+1)*relv;
                        if((fabs(deep2-a21lj[ii0+1])<0.01)&&(sw1==1))
                        {
                           PaintBox2->Canvas->LineTo(tw,i1);
                           PaintBox2->Canvas->MoveTo(tw,i1);
                           PaintBox2->Canvas->LineTo(tw+7,i1);
                           ljbwhd0[ihd0][1]=stdp+i1*relv;
                           ihd0=ihd0+1;
                           ljbwhd0[ihd0][0]=stdp+i1*relv;
                           PaintBox2->Canvas->MoveTo(tw,i1);

                           sw1=0;
                        }
                if(((a[i1][MN_pos]<MNmkz)||(a[i1][HAC_pos]<HACmkz))&&(sw1==1))
                {
                        PaintBox2->Canvas->LineTo(tw,i1);
                        PaintBox2->Canvas->MoveTo(tw,i1);
                        PaintBox2->Canvas->LineTo(tw+7,i1);
                        ljbwhd0[ihd0][1]=stdp+i1*relv;
                        ihd0=ihd0+1;
                        sw1=0;
                }
          }

       }
    }
  }
     for(int i0=0;i0<ihd0;i0++)
     {
        if((ljbwhd0[i0][1]-ljbwhd0[i0][0])>=0.2)
        {
           ljbwhd[ihd][0]=ljbwhd0[i0][0];
           ljbwhd[ihd][1]=ljbwhd0[i0][1];
           ihd=ihd+1;
        }
     }
            PaintBox2->Canvas->Pen->Width=2;
            PaintBox2->Canvas->Pen->Style=psSolid;
            PaintBox2->Canvas->Pen->Color=clBlack;
     int ih=0;
      for(int i0=0;i0<stedp;i0++)
      {
           deep3=stdp+i0*relv;
           if(fabs(deep3-ljbwhd[ih][0])<0.01)
           {
              PaintBox2->Canvas->MoveTo(tw-5,i0);
              PaintBox2->Canvas->LineTo(tw+7-5,i0);
              PaintBox2->Canvas->MoveTo(tw-5,i0);
           }
           if(fabs(deep3-ljbwhd[ih][1])<0.01)
           {
              PaintBox2->Canvas->LineTo(tw-5,i0);
              PaintBox2->Canvas->MoveTo(tw-5,i0);
              PaintBox2->Canvas->LineTo(tw+7-5,i0);
              ih=ih+1;
           }
      }

}
//-----------------------------------------------------------------------------
void __fastcall TForm1::N18Click(TObject *Sender)     //储层连通性对比
{
  Form3->Show();

}
//---------------------------------------------------------------------------

void __fastcall TForm1::N20Click(TObject *Sender)  //Frechet 断层识别   Spearman断层识别  ，K近邻局部密度
{  Form5->inum=0;Form5->inum1=0;
   Form5->Show();
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TForm1::Spearman(TObject *Sender)  //Spearman 相关系数
{
  /*  float d=0.0;
    for(int i0=0;i0<ie1-1;i0++)
    {
       d=d+(xxjtz[i0][pos]-xljtz[i0][pos])*(xxjtz[i0][pos]-xljtz[i0][pos]);

    }
    Sl=(1.0-6.0*d/float((ie1-1)*((ie1-1)*(ie1-1)-1)));  */

}
//---------------------------------------------------------------------------
 __fastcall TForm1::paixu2(int nn,float mn[500][15],int pos)
{
  float p;
  for(int i1=0;i1<nn-2;i1++)
   {
    for(int i2=i1+1;i2<nn-1;i2++)
    {
     if(mn[i1][pos]>=mn[i2][pos])
     {
         /* p=mn[i1][0];
           mn[i1][0]=mn[i2][0];
           mn[i2][0]=p;*/
         p=mn[i1][pos];
         mn[i1][pos]=mn[i2][pos];
         mn[i2][pos]=p;
      }
     }
    }
  //  bestdp0=mn[0][0];
//    PaintBox2->Canvas->TextOut(10+150*2+4,10+nn*20,"best***"+AnsiString(bestdp));
}
//------------------------------------------------------------------------------
void __fastcall TForm1::xjsj(TObject *Sender)  //新井数据
{
   float pmax1[10];
   for(int i0=1;i0<=6;i0++)
   {
      pmax1[i0]=0.0;
   }
          for(int i12=itz;i12<itz+ie1;i12++)
          {
            xsj[i12-itz][1]=StrToFloat(FormatFloat("0.000",a1[i12][MN1_pos]));
            xxjtz[i12-itz][1]=xsj[i12-itz][1];
            if(xxjtz[i12-itz][1]>pmax1[1])
            {
               pmax1[1]=xxjtz[i12-itz][1];
            }
              xsj[i12-itz][2]=StrToFloat(FormatFloat("0.000",a1[i12][Rd1_pos]));
              xxjtz[i12-itz][2]=xsj[i12-itz][2];
              if(xxjtz[i12-itz][2]>pmax1[2])
              {
                 pmax1[2]=xxjtz[i12-itz][2];
              }
                xsj[i12-itz][3]=StrToFloat(FormatFloat("0.000",a1[i12][DEN1_pos]));
                xxjtz[i12-itz][3]=xsj[i12-itz][3];
                if(xxjtz[i12-itz][3]>pmax1[3])
                {
                   pmax1[3]=xxjtz[i12-itz][3];
                }
                  xsj[i12-itz][4]=StrToFloat(FormatFloat("0.000",a1[i12][HAC1_pos]));
                  xxjtz[i12-itz][4]=xsj[i12-itz][4];
                  if(xxjtz[i12-itz][4]>pmax1[4])
                  {
                     pmax1[4]=xxjtz[i12-itz][4];
                  }
                    xsj[i12-itz][5]=StrToFloat(FormatFloat("0.000",a1[i12][Rxo1_pos]));
                    xxjtz[i12-itz][5]=xsj[i12-itz][5];
                    if(xxjtz[i12-itz][5]>pmax1[5])
                    {
                         pmax1[5]=xxjtz[i12-itz][5];
                    }
                      xsj[i12-itz][6]=StrToFloat(FormatFloat("0.000",a1[i12][GR1_pos]));
                      xxjtz[i12-itz][6]=xsj[i12-itz][6];
                      if(xxjtz[i12-itz][6]>pmax1[6])
                      {
                           pmax1[6]=xxjtz[i12-itz][6];
                      }

          }
    /*   for(int i0=0;i0<ie1-1;i0++)
       {
          for(int j0=1;j0<=6;j0++)
          {
              xxjtz[i0][j0]=xxjtz[i0][j0]/pmax1[j0];
          }
       }    */
    //   paixu2(ie1,xxjtz,pos);  Spearman  排序
   //   PaintBox2->Canvas->TextOutA(550,itz*14,"ite= "+ AnsiString(ite));
    //  PaintBox2->Canvas->TextOutA(650,itz*14,"ie1= "+ AnsiString(ie1));
}
//------------------------------------------------------------------------------
void __fastcall TForm1::ljtzzxq(TObject *Sender)  //老井特征值选取
{
 /*   float pljmax=0.0;
    iljtzz=0;

     int pos=3;

    for(int i0=1;i0<ie1-1;i0++)
    {
       if(xcsj[i0][pos]>pljmax)
       {
          pljmax=xcsj[i0][pos];
       }
       if((xcsj[i0][pos]>xcsj[i0-1][pos])&&(xcsj[i0][pos]>xcsj[i0+1][pos])&&(fabs(xcsj[i0][pos]-xcsj[i0-1][pos])>0.001)&&(fabs(xcsj[i0][pos]-xcsj[i0+1][pos])>0.001))
       {
          xljtz[iljtzz][0]=xcsj[i0][0];
          xljtz[iljtzz][1]=xcsj[i0][pos];          //老井最大值
       }
       if((xcsj[i0][pos]<xcsj[i0-1][pos])&&(xcsj[i0][pos]<xcsj[i0+1][pos])&&(fabs(xcsj[i0][pos]-xcsj[i0-1][pos])>0.001)&&(fabs(xcsj[i0][pos]-xcsj[i0+1][pos])>0.001))
       {
          xljtz[iljtzz][2]=xcsj[i0][0];
          xljtz[iljtzz][3]=xcsj[i0][pos];      //老井最小值
          iljtzz=iljtzz+1;
       }
    }            */
 /*   for(int i0=0;i0<=iljtzz-1;i0++)
    {
       xljtz[i0][1]=xljtz[i0][1]/pljmax;       //归一化
       xljtz[i0][3]=xljtz[i0][3]/pljmax;
    }  */



}
//----------------------------------------------------------------------------
void __fastcall TForm1::xjtzzxq(TObject *Sender)  //新井特征值选取
{
 /*    int iop=0;
     int i12=itz+1;
     float pxjmax=0;
     ixjtzz=0;

     int pos=3;

     do{
           xsj[i12-itz-1][0]=a1[i12-1][0];
           xsj[i12-itz-1][1]=StrToFloat(FormatFloat("0.00",a1[i12-1][MN1_pos]));
              xsj[i12-itz-1][2]=StrToFloat(FormatFloat("0.00",a1[i12-1][Rd1_pos]));
                xsj[i12-itz-1][3]=StrToFloat(FormatFloat("0.00",a1[i12-1][DEN1_pos]));
                  xsj[i12-itz-1][4]=StrToFloat(FormatFloat("0.00",a1[i12-1][HAC1_pos]));
                    xsj[i12-itz-1][5]=StrToFloat(FormatFloat("0.00",a1[i12-1][Rxo1_pos]));
                      xsj[i12-itz-1][6]=StrToFloat(FormatFloat("0.00",a1[i12-1][GR1_pos]));
            xsj[i12-itz][1]=StrToFloat(FormatFloat("0.00",a1[i12][MN1_pos]));
              xsj[i12-itz][2]=StrToFloat(FormatFloat("0.00",a1[i12][Rd1_pos]));
                xsj[i12-itz][3]=StrToFloat(FormatFloat("0.00",a1[i12][DEN1_pos]));
                  xsj[i12-itz][4]=StrToFloat(FormatFloat("0.00",a1[i12][HAC1_pos]));
                    xsj[i12-itz][5]=StrToFloat(FormatFloat("0.00",a1[i12][Rxo1_pos]));
                      xsj[i12-itz][6]=StrToFloat(FormatFloat("0.00",a1[i12][GR1_pos]));
            xsj[i12-itz+1][1]=StrToFloat(FormatFloat("0.00",a1[i12+1][MN1_pos]));
              xsj[i12-itz+1][2]=StrToFloat(FormatFloat("0.00",a1[i12+1][Rd1_pos]));
                xsj[i12-itz+1][3]=StrToFloat(FormatFloat("0.00",a1[i12+1][DEN1_pos]));
                  xsj[i12-itz+1][4]=StrToFloat(FormatFloat("0.00",a1[i12+1][HAC1_pos]));
                    xsj[i12-itz+1][5]=StrToFloat(FormatFloat("0.00",a1[i12+1][Rxo1_pos]));
                      xsj[i12-itz+1][6]=StrToFloat(FormatFloat("0.00",a1[i12+1][GR1_pos]));

          if(xsj[i12-itz][pos]>pxjmax)
          {
             pxjmax=xsj[i12-itz][pos];
          }
          if((xsj[i12-itz][pos]>xsj[i12-itz-1][pos])&&(xsj[i12-itz][pos]>xsj[i12-itz+1][pos])&&(fabs(xsj[i12-itz][pos]-xsj[i12-itz-1][pos])>0.001)&&(fabs(xsj[i12-itz][pos]-xsj[i12-itz+11][pos])>0.001))
          {
             xxjtz[ixjtzz][0]=a1[i12][0];
             xxjtz[ixjtzz][1]=xsj[i12-itz][pos];          //新井最大值
          }
           if((xsj[i12-itz][pos]<xsj[i12-itz-1][pos])&&(xsj[i12-itz][pos]<xsj[i12-itz+1][pos])&&(fabs(xsj[i12-itz][pos]-xsj[i12-itz-1][pos])>0.001)&&(fabs(xsj[i12-itz][pos]-xsj[i12-itz+1][pos])>0.001))
          {
             xxjtz[ixjtzz][2]=a1[i12][0];
             xxjtz[ixjtzz][3]=xsj[i12-itz][pos];          //新井最小值
             ixjtzz=ixjtzz+1;
          }
          if(ixjtzz==iljtzz)iop=1;
         //  PaintBox4->Canvas->TextOutA(350,ljcw*14,"ixjtzz="+AnsiString(ixjtzz));
          // PaintBox4->Canvas->TextOutA(450,ljcw*14,"iljtzz="+AnsiString(iljtzz));
          i12=i12+1;

      }while(iop==0);*/           // PaintBox4->Canvas->TextOutA(250,ljcw*14,"i1="+AnsiString(i1));
   /*    for(int i13=0;i13<=ixjtzz-1;i13++)
       {
          xxjtz[i13][1]=xljtz[i13][1]/pxjmax;       //归一化
          xxjtz[i13][3]=xljtz[i13][3]/pxjmax;
       }   */



}
//---------------------------------------------------------------------------
void __fastcall TForm1::Frechetjl(TObject *Sender)  //Frechet 距离
{
/*    sos=0.0;
   for(int i14=0;i14<ixjtzz;i14++)
   {
       sos=sos+fabs((xxjtz[i14][1]-xljtz[i14][1])-(xxjtz[i14][3]-xljtz[i14][3]));
   }
   if(sos<Frechetmenkan)              //&&(xsj[57][0]>(Frechdeep[ljcw-1-1]+0.3)))
   {
       Frechetmenkan=sos;
       Frechdeep[ljcw-1]=xsj[57][0];
   }

     */
}
//----------------------------------------------------------------------------

void __fastcall TForm1::N15Click(TObject *Sender)
{
    int i2=7;ie=0; xzkg=2;
    String p;
    ie=0;
    ccpdy=ccp;
    ljcjdysjk(Sender);   //老井沉积单元数据库
    for(int i1=0;i1<totalnum+1;i1++)
    {
         p=Yczmc[i1]+Dymc[i1];
         AnsiString(str5)=p;
         if(Dyds[i1]>100.0)
         {
              str6[ie]=p.c_str();
              a2[ie][0]=Dyds[i1];
              ie=ie+1;
         }
    }
  //  ljcgs=totalnum+1;
  //  ie=totalnum+1;
    ljcgs=ie;
  //  PaintBox4->Canvas->TextOutA(100,90,ie);
  //  PaintBox4->Canvas->TextOutA(100,110,totalnum);
    paintfenceng(Sender);
    cjdyljsjk(Sender);    //沉积单元邻井数据库
    DataBase=2;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N21Click(TObject *Sender)
{
    int fl=0; int i2=7;ie2=0;  xzkg=2;
   String p;
    ccpdy2=ccp2;
    xjcjdysjk(Sender);   //新井沉积单元数据库
  for(int i1=0;i1<totalnum1+1;i1++)
  {
       p=Yczmc1[i1]+Dymc1[i1];
       AnsiString(str05)=p;
       str7[i1]=p.c_str();
       a3[i1][0]=Dyds1[i1];
       if(Dyds1[i1]>0.1)
       {
          xjcw9[fl]=Dyds1[i1];
          fl=fl+1;
       }
  }

  ie2=totalnum1+1;
   zxjcgs=ie2;

 paintfenceng1(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ljcjdysjk(TObject *Sender)      //老井沉积单元数据库
{
   int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;AnsiString cc,Bzz; totalnum=0;
 FILE *fc,*fo;

 String File_name=ChangeFileExt(ccpdy,"");
 OpenDialog1->Filter="daa073（*.DBF)|*.DBF|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fc=fopen(OpenDialog1->Files->Strings[I].c_str(),_T("r"));
   cc=OpenDialog1->Files->Strings[I].c_str();
   DBF073_path = cc;
  if(fc)
   {
     Table1->TableName=cc;
     Table1->Open();
     DBGrid1->DataSource=DataSource1;

     Table1->Active=true;
     Table1->First();
     while((flag1<1)&&(!Table1->Eof))
    {
       jjhh=Table1->FieldByName("Jh")->AsString;
       jjhh=LowerCase(jjhh); //
       if(jjhh==File_name)
       {
        do{
             jjhh=Table1->FieldByName("Jh")->AsString;
             jjhh=LowerCase(jjhh);flag1=1;
             Xhc[ia]=Table1->FieldByName("Xh")->Value;
           //  Jhc[ia]=Table1->FieldByName("Jh")->AsString;      //加新井井名
             Yczmcc[ia]=Table1->FieldByName("Yczmc")->AsString;  //油层组名称
             Dymcc[ia]=Table1->FieldByName("Dymc")->AsString;  //单元名称
             Bzc[ia]=Table1->FieldByName("Bz")->AsString;
            // PaintBox2->Canvas->TextOutA(100,10+14*(ia),"Dymcc[ia]  "+Dymcc[ia]);
            // PaintBox2->Canvas->TextOutA(40,10+14*(ia),"ia  "+AnsiString(ia));
             ia++;
             Table1->Next();
          }while((jjhh==File_name)&&(!Table1->Eof));

       }
       if((flag1<1)&&(!Table1->Eof))
          {
            Table1->Next();
          }
    }
     Table1->First();
    while((flag<1)&&(!Table1->Eof))
    {
       jjhh=Table1->FieldByName("Jh")->AsString;
       jjhh=LowerCase(jjhh);
       String temp1=Table1->FieldByName("Bz")->AsString;
       if(temp1=="")
        {
             Bzz="";
        }
        else
        {
             Bzz=temp1;   //备注
        }
     if((jjhh==File_name)&&((Bzz=="")))
      {
       do{
           flag=3;
           Xh[i]=Table1->FieldByName("Xh")->Value;
           String temp = "999";

           temp = Table1->FieldByName("Jh")->Value;
           if(temp == "")
           {
                Jh[i]="";
           }
           else
           {
                Jh[i]=Table1->FieldByName("Jh")->AsString;   //井号
           }

           temp = Table1->FieldByName("Yczmc")->Value;
           if(temp == "")
           {
                Yczmc[i]="";
           }
           else
           {
                Yczmc[i]=Table1->FieldByName("Yczmc")->AsString;  //油层组名称
           }

           temp = Table1->FieldByName("Dymc")->Value;
           if(temp == "")
           {
                Dymc[i]="";
           }
           else
           {
                Dymc[i]=Table1->FieldByName("Dymc")->AsString;  //单元名称
           }
           Dyds[i]=Table1->FieldByName("Dyds")->Value;     //单元顶深

           temp = Table1->FieldByName("Bz")->Value;
           if(temp == "")
           {
                Bz[i]="";
           }
           else
           {
                Bz[i]=Table1->FieldByName("Bz")->AsString;   //井号
           }
          if(jjhh == File_name && Bz[i]=="W")
          break;

          i++;
          Table1->Next();

        }while((jjhh==File_name)&&(!Table1->Eof)&&(Bz[i]==""));

     }
     if((flag<1)&&(!Table1->Eof))
     {
       Table1->Next();
     }

      }
      totalnum=i-1;
     }
   }
  }
  Table1->First();


  Table1->Close();
  fclose(fc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::xjcjdysjk(TObject *Sender)      //新井沉积单元数据库
{
   int i=0,j,i1,i2=0,i3,flag=0,n;AnsiString cc,Bzz;totalnum1=0;
 FILE *fc,*fo;
// fo=fopen("D:\\test1.txt","wt");
 String File_name=ChangeFileExt(ccpdy2,"");
 OpenDialog1->Filter="daa073（*.DBF)|*.DBF|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fc=fopen(OpenDialog1->Files->Strings[I].c_str(),_T("r"));
   cc=OpenDialog1->Files->Strings[I].c_str();
  if(fc)
   {
     Table1->TableName=cc;
     Table1->Open();
     DBGrid1->DataSource=DataSource1;

     Table1->Active=true;
     Table1->First();

    while((flag<1)&&(!Table1->Eof))
     {
       jjhh=Table1->FieldByName("Jh")->AsString;
       jjhh=LowerCase(jjhh);
       String temp1=Table1->FieldByName("Bz")->AsString;
       if(temp1=="")
        {
             Bzz="";
        }
        else
        {
             Bzz=temp1;   //备注
        }
     if((jjhh==File_name)&&((Bzz=="")))
      {
       do{
           flag=3;
           Xh1[i]=Table1->FieldByName("Xh")->Value;
           String temp = "999";

           temp = Table1->FieldByName("Jh")->Value;
           if(temp == "")
           {
                Jh1[i]="";
           }
           else
           {
                Jh1[i]=Table1->FieldByName("Jh")->AsString;   //井号
           }

           temp = Table1->FieldByName("Yczmc")->Value;
           if(temp == "")
           {
                Yczmc1[i]="";
           }
           else
           {
                Yczmc1[i]=Table1->FieldByName("Yczmc")->AsString;  //油层组名称
           }

           temp = Table1->FieldByName("Dymc")->Value;
           if(temp == "")
           {
                Dymc1[i]="";
           }
           else
           {
                Dymc1[i]=Table1->FieldByName("Dymc")->AsString;  //单元名称
           }
           Dyds1[i]=Table1->FieldByName("Dyds")->Value;     //单元顶深

           temp = Table1->FieldByName("Bz")->Value;
           if(temp == "")
           {
                Bz1[i]="";
           }
           else
           {
                Bz1[i]=Table1->FieldByName("Bz")->AsString;   //标注
           }
          if(jjhh == File_name && Bz1[i]=="W")
          break;

          i++;
          Table1->Next();

        }while((jjhh==File_name)&&(!Table1->Eof)&&(Bz1[i]==""));

     }
     if((flag<1)&&(!Table1->Eof))
     {
       Table1->Next();
     }

      }
      totalnum1=i-1;
     }
   }
  }
  Table1->First();
  Table1->Close();
  fclose(fc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::cjdyljsjk(TObject *Sender)     //沉积单元邻井数据库
{
    FILE *fp1; int totalnumt,ik=1;  float startd[500],endd[500];
    String Fn=ChangeFileExt(ccpdy,"");
   String Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\沉积单元数据库\\";
   int ii0=0;wincu1=2.4;wincd1=2.5;
  
   while(ii0<ie)
   {
       float deep1;
       for(int i0=0;i0<stedp;i0++)
       {
          if(ii0==0)
          {
             startd[ii0]=a2[ii0][0]-wincu1;               //n7-4-sp2038   S11----941.5   wincu1=2.4;wincd1=2.5;
             endd[ii0]=a2[ii0+1][0];
          }
          else if(ii0==(ie-1))
          {
             startd[ii0]=a2[ii0-1][0];               //n7-4-sp2038   S11----941.5   wincu1=2.4;wincd1=2.5;
             endd[ii0]=a2[ii0][0]+wincd1*1.5;
            /* PaintBox5->Canvas->TextOutA(80,30,startd[ii0]);
             PaintBox5->Canvas->TextOutA(80,50,endd[ii0]);
             PaintBox5->Canvas->TextOutA(180,30,ljcgs);
             PaintBox5->Canvas->TextOutA(180,50,ie); */
          }
          else
          {
             startd[ii0]=a2[ii0-1][0];               //n7-4-sp2038   S11----941.5   wincu1=2.4;wincd1=2.5;
             endd[ii0]=a2[ii0+1][0];                  //n7-4-sp2038   S12---end=a2[0][0]+0.8;
          }
          int il=1;
          while((endd[ii0]<startd[ii0])&&(ii0<ie))
         {
           dc=ii0;
            PaintBox5->Canvas->TextOutA(80,90+ik*14,ik);
            PaintBox5->Canvas->TextOutA(120+ik*120,90,"              数据可能有问题");
            PaintBox5->Canvas->TextOutA(140+ik*120,90,str6[dc]);
            PaintBox5->Canvas->TextOutA(80+ik*120,140,"起始深度:");
            PaintBox5->Canvas->TextOutA(140+ik*120,140,startd[ii0]);
            PaintBox5->Canvas->TextOutA(80+ik*120,160,"终止深度:");
            PaintBox5->Canvas->TextOutA(140+ik*120,160,endd[ii0]);
            ik++;
           if(a2[ii0+il][0]>startd[ii0])
           {
              endd[ii0]=a2[ii0+il][0];
              il++;
            }
            else
            {
               endd[ii0]=a2[ii0][0]+wincd1*il;
               il++;
            }
         }
          totalnumt=int((endd[ii0]-startd[ii0])/0.05);
          if(fabs(a[i0][0]-startd[ii0])<0.001)
          {
              GetFileName1(ccp0,ii0);
              String p1=str6[ii0];
              String Fname=Dir+p1;
              if(!DirectoryExists(Fname))
              {

                   CreateDir(Fname);//文件夹不存在则创建
              }
              ss3=Fname+"\\"+Fn+newname1;
              if((endd[ii0]>100.0)&&(totalnumt>1))
              {
                   fp1=fopen(ss3.c_str(),"wt");
              }
              if((fp1)&&(endd[ii0]>100.0)&&(totalnumt>1))
              {
                  fprintf(fp1,"%8.1f %8.1f %8.1f  %8.4f  %d\n",startd[ii0],endd[ii0],a2[ii0][0],relv,totalnumt);
                  for(int i=i0;i<i0+totalnumt+1;i++)
                  {
                      fprintf(fp1,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a[i][0],a[i][MN_pos],a[i][Rd_pos],a[i][DEN_pos],a[i][HAC_pos],a[i][Rxo_pos],a[i][GR_pos]);

                  }
              }

              fclose(fp1);
              if(ii0<ie)ii0=ii0+1;
             /* while(a2[ii0][0]<10.1)
              {
                 ii0=ii0+1;
              }   */
          }
        }
   }

 // fclose(fp1);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::bccjdysjk(TObject *Sender)   //保存沉积单元数据库
{
 FILE *fp;short i1=2,i2=3,ii=40;float f=62;int i3; AnsiString cc;
    int is_open = 0;
 SaveDialog1->Filter="DBF数据库文件（*.dbf)|*.dbf|所有文件(*.*)|*.*";
 if(SaveDialog1->Execute())
 {
 for(int I=0;I<SaveDialog1->Files->Count;I++)
 {
  //fp=fopen(SaveDialog1->Files->Strings[I].c_str(),_T("w"));


    is_open = 0;
    TTable*newTable;
    newTable=new TTable(this);
    newTable->TableName="";             //或者Table1->TableName=cc;
    newTable->TableType=ttFoxPro;
    AnsiString Dir = SaveDialog1->FileName;
    AnsiString Dir3 = SaveDialog1->FileName;
    AnsiString Dir2 = Dir.SubString(Dir.Length()-3,Dir.Length());
    AnsiString Dir4 = SaveDialog1->FileName;
    Dir.Length();

    int temp = 0;
    for(int i = 1;i < Dir.Length();i++)
    {
        if(Dir[i] == '\\')
        temp = i;
    }
    if(Dir2 == ".DBF" || Dir2 == ".dbf")
    {
        Dir = Dir.Delete(Dir.Length()-3,Dir.Length());
    }
    if(temp > 0)
    {
        Dir = Dir.Delete(1,temp);
    }


  if(is_open == 0)
   {
    // TTable*newtable=new TTable(this);
    TTable*newTable;
    newTable=new TTable(this);
    newTable->TableName="";             //或者Table1->TableName=cc;
    newTable->TableType=ttFoxPro;
    newTable->DatabaseName=ExtractFilePath(SaveDialog1->FileName);
    newTable->TableName=SaveDialog1->FileName;
    newTable->FieldDefs->Clear();
    if(Yczmcc[0] != "" && Yczmcc[0] != NULL)
    {
        newTable->FieldDefs->Add("Xh",ftInteger,0,false);
        newTable->FieldDefs->Add("Jh",ftString,16,false);
        newTable->FieldDefs->Add("Yczmc",ftString,8,false);
        newTable->FieldDefs->Add("Dymc",ftString,8,false);
        newTable->FieldDefs->Add("Dyds",ftFloat,0,false);
        newTable->FieldDefs->Add("Bz",ftString,8,false);
    }
    else
    {
        newTable->FieldDefs->Add("井号外",ftString,8,false);
        newTable->FieldDefs->Add("小层界限外",ftFloat,0,false);
    }

    newTable->CreateTable();
    DataSource1->DataSet=newTable;
    newTable->TableName=SaveDialog1->FileName;
    newTable->Active=true;
    newTable->Insert();
    newTable->Open();
   // if(newTable->State==dsInsert)ShowMessage("数据库保存成功！");
    newTable->DisableControls();
    newTable->First();

      if(Yczmcc[0] != "" && Yczmcc[0] != NULL && DataBase == 2)
      {
        for(int i=0;i<196;i++)
        {
          newTable->Insert();
          String File_name=ChangeFileExt(ccp2,"");
          Jhc[i] = UpperCase(File_name).c_str();
          //Jhc[i] = UpperCase(ccp2);
          newTable->FieldByName("Xh")->Value=i+1;    //Xhc[i];
          newTable->FieldByName("Jh")->AsString=Save_Name;
          newTable->FieldByName("Yczmc")->AsString=Yczmcc[i];
          newTable->FieldByName("Dymc")->AsString=Dymcc[i];
          if((Yczmcc[i]+Dymcc[i])==str6[i])
          {
                newTable->FieldByName("Dyds")->Value=FormatFloat("0.0",mbdeep[i]);
                if(mbdeep[i]<20)
                        newTable->FieldByName("Bz")->AsString="F";

          }
          else
          {
                newTable->FieldByName("Bz")->AsString="W";
          }
          newTable->Next();
        }
        newTable->Active=false;
        newTable->EnableControls();
        newTable->Close();
      }
      else
      {
        String TS = "";
        newTable->Active=false;
        newTable->EnableControls();
        newTable->Close();

        DBF055_NEW = Dir4;
        AnsiString Dir2 = Dir4.SubString(Dir4.Length()-3,Dir4.Length());
        if(Dir2 != ".DBF" && Dir2 != ".dbf")
        {
                DBF055_NEW = DBF055_NEW + ".DBF";
        }



        N111Click(Sender);


      }



    }
  }
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N22Click(TObject *Sender)
{
   bccjdysjk(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::charucjdy(TObject *Sender)       //插入新沉积单元
{
    float db1;
    p1yczmc=Form4->Edit1->Text;
    p2dymc=Form4->Edit2->Text;
    p3dysd=StrToFloat(Form4->Edit3->Text);
    db1=stdp1+Ym*relv1;
    if(db1>zzppsd[ljcw-1])
    {
      //str8[ljcw]=Yczmc[ljcw]+Dymc[ljcw];          //p1yczmc+p2dymc;
      str8[ljcw]=p1yczmc+p2dymc;
      zzppsd[ljcw]=stdp1+Ym*relv1;
      ljcw=ljcw+1;
    }
    for(int ii0=0;ii0<ljcw;ii0++)
    {

       if((p1yczmc+p2dymc)==str8[ii0])
       {

            PaintBox4->Canvas->Pen->Width=1;
            PaintBox4->Canvas->Pen->Style=psSolid;
            PaintBox4->Canvas->Pen->Color=RGB(210,20,ii0);
            PaintBox4->Canvas->MoveTo(4+0,Ym);
            PaintBox4->Canvas->LineTo(140+150*4+30,Ym);
            PaintBox4->Canvas->TextOutA(140+150*4-14,Ym-14,str8[ii0]);
            zzppsd[ii0]=stdp1+Ym*relv1;
            PaintBox4->Canvas->TextOutA(140+150*4-14,Ym+3,AnsiString(FormatFloat("0.0",zzppsd[ii0])));
            Form4->Edit3->Text=FloatToStr(zzppsd[ii0]);
       }
    }

    PaintBox4Paint(Sender);
}

//--------------------------------------------------------------------------





void __fastcall TForm1::N24Click(TObject *Sender)
{
  Form6->Show();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::zdjzcjdyljsjk(TObject *Sender)  //自动加载沉积单元老井数据库  2023-2-4
{
    int i2=7;ie=0; xzkg=2;
    String p;
    ie=0;
    ccpdy=ccp;
    zdljcjdysjk(Sender);   //老井沉积单元数据库
    for(int i1=0;i1<totalnum+1;i1++)
    {
         p=Yczmc[i1]+Dymc[i1];
         AnsiString(str5)=p;
         str6[i1]=p.c_str();
         a2[i1][0]=Dyds[i1];
         //ckdeep[i1]=a2[i1][0];
        // PaintBox2->Canvas->TextOutA(120,15+i1*15,a2[i1][0]);
    }
    ljcgs=totalnum+1;
    ie=totalnum+1;
    paintfenceng(Sender);
    cjdyljsjk(Sender);    //沉积单元邻井数据库


 /*   int i2=7;ie=0; xzkg=2;
    String p;
    ie=0;
    ccpdy=ccp;
    ljcjdysjk(Sender);   //老井沉积单元数据库

    for(int i1=0;i1<totalnum+1;i1++)
    {
         p=Yczmc[i1]+Dymc[i1];
         AnsiString(str5)=p;
         if(Dyds[i1]>100.0)
         {
              str6[ie]=p.c_str();
              a2[ie][0]=Dyds[i1];
              ie=ie+1;
         }
    }
  //  ljcgs=totalnum+1;
  //  ie=totalnum+1;
    ljcgs=ie;
  //  PaintBox4->Canvas->TextOutA(100,90,ie);
  //  PaintBox4->Canvas->TextOutA(100,110,totalnum);
    paintfenceng(Sender);
    cjdyljsjk(Sender);    //沉积单元邻井数据库
    DataBase=2; */
}
//---------------------------------------------------------------------------
void __fastcall TForm1::zdljcjdysjk(TObject *Sender)      //自动老井沉积单元数据库
{
   int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;AnsiString cc,Bzz; totalnum=0;
 FILE *fc,*fo;

 String File_name=ChangeFileExt(ccpdy,"");
/* OpenDialog1->Filter="daa073（*.DBF)|*.DBF|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fc=fopen(OpenDialog1->Files->Strings[I].c_str(),_T("r"));
   cc=OpenDialog1->Files->Strings[I].c_str();   */
   fc=fopen("D:\\二厂统层对比有形化平台\\测井数据\\2018\\曲线\\daaa073-2018.DBF",_T("r"));
   cc="D:\\二厂统层对比有形化平台\\测井数据\\2018\\曲线\\daaa073-2018.DBF";
  if(fc)
   {
     Table1->TableName=cc;
     Table1->Open();
     DBGrid1->DataSource=DataSource1;

     Table1->Active=true;
     Table1->First();
     while((flag1<1)&&(!Table1->Eof))
    {
       jjhh=Table1->FieldByName("Jh")->AsString;
       jjhh=LowerCase(jjhh); //
       if(jjhh==File_name)
       {
        do{
             jjhh=Table1->FieldByName("Jh")->AsString;
             jjhh=LowerCase(jjhh);flag1=1;
             Xhc[ia]=Table1->FieldByName("Xh")->Value;
           //  Jhc[ia]=Table1->FieldByName("Jh")->AsString;      //加新井井名
             Yczmcc[ia]=Table1->FieldByName("Yczmc")->AsString;  //油层组名称
             Dymcc[ia]=Table1->FieldByName("Dymc")->AsString;  //单元名称
             Bzc[ia]=Table1->FieldByName("Bz")->AsString;
            // PaintBox2->Canvas->TextOutA(100,10+14*(ia),"Dymcc[ia]  "+Dymcc[ia]);
            // PaintBox2->Canvas->TextOutA(40,10+14*(ia),"ia  "+AnsiString(ia));
             ia++;
             Table1->Next();
          }while((jjhh==File_name)&&(!Table1->Eof));

       }
       if((flag1<1)&&(!Table1->Eof))
          {
            Table1->Next();
          }
    }
     Table1->First();
    while((flag<1)&&(!Table1->Eof))
    {
       jjhh=Table1->FieldByName("Jh")->AsString;
       jjhh=LowerCase(jjhh);
       String temp1=Table1->FieldByName("Bz")->AsString;
       if(temp1=="")
        {
             Bzz="";
        }
        else
        {
             Bzz=temp1;   //备注
        }
     if((jjhh==File_name)&&((Bzz=="")))
      {
       do{
           flag=3;
           Xh[i]=Table1->FieldByName("Xh")->Value;
           String temp = "999";

           temp = Table1->FieldByName("Jh")->Value;
           if(temp == "")
           {
                Jh[i]="";
           }
           else
           {
                Jh[i]=Table1->FieldByName("Jh")->AsString;   //井号
           }

           temp = Table1->FieldByName("Yczmc")->Value;
           if(temp == "")
           {
                Yczmc[i]="";
           }
           else
           {
                Yczmc[i]=Table1->FieldByName("Yczmc")->AsString;  //油层组名称
           }

           temp = Table1->FieldByName("Dymc")->Value;
           if(temp == "")
           {
                Dymc[i]="";
           }
           else
           {
                Dymc[i]=Table1->FieldByName("Dymc")->AsString;  //单元名称
           }
           Dyds[i]=Table1->FieldByName("Dyds")->Value;     //单元顶深

           temp = Table1->FieldByName("Bz")->Value;
           if(temp == "")
           {
                Bz[i]="";
           }
           else
           {
                Bz[i]=Table1->FieldByName("Bz")->AsString;   //井号
           }
          if(jjhh == File_name && Bz[i]=="W")
          break;

          i++;
          Table1->Next();

        }while((jjhh==File_name)&&(!Table1->Eof)&&(Bz[i]==""));

     }
     if((flag<1)&&(!Table1->Eof))
     {
       Table1->Next();
     }

      }
      totalnum=i-1;
     }
  // }
 // }
  Table1->First();


  Table1->Close();
  fclose(fc);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::LA3Click(TObject *Sender)
{
   LA1Click(Sender);
   zdjzcjdyljsjk(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::zdjzxjcjdysjk(TObject *Sender)     //自动加载新井沉积单元数据库
{
    int fl=0; int i2=7;ie2=0;  xzkg=2;
   String p;
    ccpdy2=ccp2;
    zdxjcjdysjk(Sender);   //新井沉积单元数据库
  for(int i1=0;i1<totalnum1+1;i1++)
  {
       p=Yczmc1[i1]+Dymc1[i1];
       AnsiString(str05)=p;
       str7[i1]=p.c_str();
       a3[i1][0]=Dyds1[i1];
       if(Dyds1[i1]>0.1)
       {
          xjcw9[fl]=Dyds1[i1];
          fl=fl+1;
       }
  }

  ie2=totalnum1+1;
   ie1=ie2;

 paintfenceng1(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::zdxjcjdysjk(TObject *Sender)      //自动新井沉积单元数据库
{
   int i=0,j,i1,i2=0,i3,flag=0,n;AnsiString cc,Bzz;totalnum1=0;
 FILE *fc,*fo;
// fo=fopen("D:\\test1.txt","wt");
 String File_name=ChangeFileExt(ccpdy2,"");
/* OpenDialog1->Filter="daa073（*.DBF)|*.DBF|所有文件(*.*)|*.*";
 if(OpenDialog1->Execute())
 {
 for(int I=0;I<OpenDialog1->Files->Count;I++)
  {
   fc=fopen(OpenDialog1->Files->Strings[I].c_str(),_T("r"));
   cc=OpenDialog1->Files->Strings[I].c_str();  */
   fc=fopen("D:\\二厂统层对比有形化平台\\测井数据\\2018\\曲线\\daaa073-2018.DBF",_T("r"));
   cc="D:\\二厂统层对比有形化平台\\测井数据\\2018\\曲线\\daaa073-2018.DBF";
  if(fc)
   {
     Table1->TableName=cc;
     Table1->Open();
     DBGrid1->DataSource=DataSource1;

     Table1->Active=true;
     Table1->First();

    while((flag<1)&&(!Table1->Eof))
     {
       jjhh=Table1->FieldByName("Jh")->AsString;
       jjhh=LowerCase(jjhh);
       String temp1=Table1->FieldByName("Bz")->AsString;
       if(temp1=="")
        {
             Bzz="";
        }
        else
        {
             Bzz=temp1;   //备注
        }
     if((jjhh==File_name)&&((Bzz=="")))
      {
       do{
           flag=3;
           Xh1[i]=Table1->FieldByName("Xh")->Value;
           String temp = "999";

           temp = Table1->FieldByName("Jh")->Value;
           if(temp == "")
           {
                Jh1[i]="";
           }
           else
           {
                Jh1[i]=Table1->FieldByName("Jh")->AsString;   //井号
           }

           temp = Table1->FieldByName("Yczmc")->Value;
           if(temp == "")
           {
                Yczmc1[i]="";
           }
           else
           {
                Yczmc1[i]=Table1->FieldByName("Yczmc")->AsString;  //油层组名称
           }

           temp = Table1->FieldByName("Dymc")->Value;
           if(temp == "")
           {
                Dymc1[i]="";
           }
           else
           {
                Dymc1[i]=Table1->FieldByName("Dymc")->AsString;  //单元名称
           }
           Dyds1[i]=Table1->FieldByName("Dyds")->Value;     //单元顶深

           temp = Table1->FieldByName("Bz")->Value;
           if(temp == "")
           {
                Bz1[i]="";
           }
           else
           {
                Bz1[i]=Table1->FieldByName("Bz")->AsString;   //标注
           }
          if(jjhh == File_name && Bz1[i]=="W")
          break;

          i++;
          Table1->Next();

        }while((jjhh==File_name)&&(!Table1->Eof)&&(Bz1[i]==""));

     }
     if((flag<1)&&(!Table1->Eof))
     {
       Table1->Next();
     }

      }
      totalnum1=i-1;
     }
 //  }
 // }
  Table1->First();
  Table1->Close();
  fclose(fc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LA4Click(TObject *Sender)
{
    LA2Click(Sender);
    zdjzxjcjdysjk(Sender);   //自动加载新井沉积单元数据库
    N26Click(Sender);       //统层智能对比算法
    shujujiar073k(Sender); //数据加入073库
}
//---------------------------------------------------------------------------
void __fastcall TForm1::zdbccjdysjk(TObject *Sender)   //自动保存沉积单元数据库
{
 FILE *fp;short i1=2,i2=3,ii=40;float f=62;int i3; AnsiString cc;
    int is_open = 0;
    String File_name=ChangeFileExt(ccpdy2,"");

    is_open = 0;
   // TTable*newTable;
    newTable=new TTable(this);
    newTable->TableName="";             //或者Table1->TableName=cc;
    newTable->TableType=ttFoxPro;

    AnsiString Dir ="D:\\二厂统层对比有形化平台\\"+File_name+".dbf";
    AnsiString Dir3 = "D:\\二厂统层对比有形化平台\\"+File_name+".dbf";;
    AnsiString Dir2 = Dir.SubString(Dir.Length()-3,Dir.Length());
    Dir.Length();

    int temp = 0;
    for(int i = 1;i < Dir.Length();i++)
    {
        if(Dir[i] == '\\')
        temp = i;
    }
    if(Dir2 == ".DBF" || Dir2 == ".dbf")
    {
        Dir = Dir.Delete(Dir.Length()-3,Dir.Length());
    }
    if(temp > 0)
    {
        Dir = Dir.Delete(1,temp);
    }


  if(is_open == 0)
   {

   newTable=new TTable(this);
    newTable->TableName="";             //或者Table1->TableName=cc;
    newTable->TableType=ttFoxPro;
    newTable->DatabaseName=ExtractFilePath(Dir);
    newTable->TableName=Dir;
    newTable->FieldDefs->Clear();
    newTable->FieldDefs->Add("Xh",ftInteger,0,false);

    newTable->FieldDefs->Add("Jh",ftString,16,false);
    newTable->FieldDefs->Add("Yczmc",ftString,8,false);
    newTable->FieldDefs->Add("Dymc",ftString,8,false);
    newTable->FieldDefs->Add("Dyds",ftFloat,0,false);

    newTable->FieldDefs->Add("Bz",ftString,8,false);

    newTable->CreateTable();
    DataSource1->DataSet=newTable;
    newTable->TableName=Dir;
    newTable->Active=true;
    newTable->Insert();
    newTable->Open();

    newTable->DisableControls();
    newTable->First();
      for(int i=0;i<196;i++)
      {
          newTable->Insert();
          Jhc[i] = UpperCase(File_name);                                                                                           //3-18
          newTable->FieldByName("Xh")->Value=i+1;    //Xhc[i];
          newTable->FieldByName("Jh")->AsString=Jhc[i];
          newTable->FieldByName("Yczmc")->AsString=Yczmcc[i];
          newTable->FieldByName("Dymc")->AsString=Dymcc[i];
       if((Yczmcc[i]+Dymcc[i])==str6[i])
       {
         // PaintBox2->Canvas->TextOutA(170,15+i*15,mbdeep[i]);
          newTable->FieldByName("Dyds")->Value=FormatFloat("0.0",mbdeep[i]);
          if(mbdeep[i]<20)newTable->FieldByName("Bz")->AsString="F";

        }
        else
        {
          newTable->FieldByName("Bz")->AsString="W";
        }
          newTable->Next();

      }

        newTable->Active=false;
         newTable->EnableControls();
         newTable->Close();
        }
  //  }
 // }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::zdbccjdydbsjk(TObject *Sender)   //自动保存沉积单元对比数据库
{
    int i=0;AnsiString cc2;
   FILE *fp;

   fp=fopen("D:\\二厂统层对比有形化平台\\二厂单元顶深对比.DBF","r+");
   cc2="D:\\二厂统层对比有形化平台\\二厂单元顶深对比.DBF";
   if(fp)
   {
        Table1->TableName=cc2;
        Table1->Open();
        DBGrid1->DataSource=DataSource1;
        Table1->Active=true;
        Table1->First();
        while(!Table1->Eof)
        {

             Table1->FieldByName("XH")->Value;
             Table1->FieldByName("JH")->AsString;
             Table1->FieldByName("YCZMC")->AsString;
             Table1->FieldByName("DYMC")->AsString;
             Table1->FieldByName("DYDS")->AsString;
             Table1->FieldByName("DYDSPB")->AsString;       //单元顶深判别

             i++;
             Table1->Next();
        }
        for(i=0;i<=195;i++)
        {
                Table1->Insert();
                Table1->FieldByName("Xh")->Value=i+1;    //Xhc[i];
                Table1->FieldByName("Jh")->AsString=Jhc[i];
                Table1->FieldByName("Yczmc")->AsString=Yczmcc[i];
                Table1->FieldByName("Dymc")->AsString=Dymcc[i];
                Table1->FieldByName("Dyds")->Value=FormatFloat("0.0",Dyds1[i]);
                        if(mbdeep[i] != 0)
                        {
                                Table1->FieldByName("DYDSPB")->Value=FormatFloat("0.0",mbdeep[i]); //单元顶深判别
                                if(mbdeep[i] == -1)
                                {
                                        Table1->FieldByName("Bz")->AsString="F";
                                }
                                else
                                        Table1->FieldByName("Bz")->AsString=" ";

                        }
                        else
                        {
                                        Table1->FieldByName("DYDSPB")->Value= 0;
                                        Table1->FieldByName("Bz")->AsString="w";
                        }



                Table1->Next();
                totalnum11=i-1;

       }
   }

  //Table1->First();
  Table1->Close();
  fclose(fp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::dkzjlj073k(TObject *Sender) //打开追加累计073库
{
      int i=0;AnsiString cc1;
   FILE *fp1;

   fp1=fopen("D:\\二厂统层对比有形化平台\\二厂单元深度判别.DBF","r+");
   cc1="D:\\二厂统层对比有形化平台\\二厂单元深度判别.DBF";
   if(fp1)
   {
        Table1->TableName=cc1;
        Table1->Open();
        DBGrid1->DataSource=DataSource1;
        Table1->Active=true;
        Table1->First();
        while(!Table1->Eof)
        {

             Table1->FieldByName("XH")->Value;
             Table1->FieldByName("JH")->AsString;
             Table1->FieldByName("YCZMC")->AsString;
             Table1->FieldByName("DYMC")->AsString;
             Table1->FieldByName("DYDS")->AsString;

             i++;
             Table1->Next();
        }
        for(int i=0;i<=195;i++)
        {
                Table1->Insert();
                Table1->FieldByName("Xh")->Value=i+1;    //Xhc[i];
                Table1->FieldByName("Jh")->AsString=Jhc[i];
                Table1->FieldByName("Yczmc")->AsString=Yczmcc[i];
                Table1->FieldByName("Dymc")->AsString=Dymcc[i];

                if((Yczmcc[i]+Dymcc[i])==str6[i])
                {
                        if(mbdeep[i] != 0)
                        {
                                Table1->FieldByName("Dyds")->Value=FormatFloat("0.0",mbdeep[i]);
                                if(mbdeep[i] < 20)
                                        Table1->FieldByName("Bz")->AsString="F";
                                else
                                        Table1->FieldByName("Bz")->AsString=" ";
                        }
                        else
                        {
                                Table1->FieldByName("Dyds")->Value=FormatFloat("0.0",0);
                                Table1->FieldByName("Bz")->AsString="W";
                        }
                }
                else
                {
                        Table1->FieldByName("Dyds")->Value=FormatFloat("0.0",0);
                        Table1->FieldByName("Bz")->AsString="W";
                }
                Table1->Next();
                totalnum11=i-1;

       }
   }

  //Table1->First();
  Table1->Close();
  fclose(fp1);
//}

//}
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::zj073k(TObject *Sender) //追加073库
{
   this->BatchMove1->Source=this->newTable;
   this->BatchMove1->Destination=this->Table1;
   this->BatchMove1->Mappings->Clear();
   this->BatchMove1->Mode=batAppend;
  // this->BatchMove1->RecordCount=2;
   this->BatchMove1->Execute();
  // if(BatchMove1->Mode==batAppend)ShowMessage("数据追加完成");
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::shujujiar073k(TObject *Sender) //数据加入073库
{
   zdbccjdysjk(Sender);       //自动保存沉积单元数据库
  // dkzjlj073k(Sender);       //打开追加累计073库
 //  zdbccjdydbsjk(Sender);   //自动保存沉积单元对比数据库 (智能判别结果与人工划分结果比对)
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::pcldkckjLA(TObject *Sender)   //批处理打开参考井LA
{
    short i1,i2;float f;
   Top_deep=0.0;
   int flag,i3;

 FILE *fp;
  int Rd_valueGTzero=0;
  int RMN_valueGTzero=0;
  int AC_value=0;
     MN_pos=0;
     MK_pos=0;
     Rd_pos=0;
     Rs_pos=0;
     Ac_pos=0;
     Rxo_pos=0;
     GR_pos=0;
     SP_pos=0;
     DEN_pos=0;
   String fn="D:\\二厂统层对比有形化平台\\测井数据\\2018\\曲线\\"+Form6->ckjm+".la";
 //OpenDialog1->Filter="测井数据文件la(*.la)|*.la|LA文件（LA*)|LA*|所有文件(*.*)|*.*";
 //if(OpenDialog1->Execute()){
// for(int I=0;I<OpenDialog1->Files->Count;I++)
 // {
   fp=fopen(fn.c_str(),"rb");
  // cc1=OpenDialog1->Files->Strings[I].c_str();
   // ccp=ExtractFileName(OpenDialog1->FileName);
   // GetFileName(ccp);// PaintBox2->Canvas->TextOutA(50,350,ccp);
    cc1=fn.c_str();
    ccp=Form6->ckjm;
 if(fp){
 fread(str0,84,1,fp);
 fread(str1,80,1,fp);
 i2=getint(fp);
 i1=getint(fp);
 fread(str,80,1,fp);
//startdp
 stdp=getfloat(fp);
//endp
 endp=getfloat(fp);
//cyjj
 relv=getfloat(fp);
 i1=getint(fp);
 i2=getint(fp);
 f=getfloat(fp);
 fread(str11,80,1,fp);
 fread(str3,148,1,fp);
 for(int i7=0;i7<int(Top_deep/relv);i7++)
 {
   for(int j7=1;j7<41;j7++)
   {
      a[i7][j7]=1.0;
      data[i7][j7]=1.0;
   }
 }
   stdp=stdp-Top_deep;
 i1=0+int(Top_deep/relv);
 stedp=int((endp-stdp)/relv);
while(i1<stedp)
 {
    for(int j=1;j<41;j++)
    {
       for(int i=i1;i<i1+62;i++)
       {
          a[i][j]=getfloat(fp);
          data[i][j]=a[i][j];
       }
    }
       i1=i1+62;
  }
 }
// }
// }
 for(int i=0;i<3;i++)
    {
            for(int j=0;j<4;j++)
            {
               temp_index[i][j]=-1;
            }
    }
 for(int i0=0;i0<stedp;i0++)
  {
     a[i0][0]=stdp+i0*relv;
     data[i0][0]=stdp+i0*relv;
  }
  int i4,i,j,ip;
 cname3[0][5]="DEPT ";
 i4=1;
 for(i=0;i<80;i+=4)
 {
  i2=0;
  for(j=i;j<i+4;j++)
  {
      if(str[j]!=' ')i2++;
  }
   j=i;
  for(i3=0;i3<4;i3++)
   str2[i3]=0;
  for(i3=0;i3<i2;i3++)
  {
     str2[i3]=str[j];
     j++;
  }
   if((str2[0]!=' ')&&(str2[0]!='\0'))
   {
     cname3[i4][5]=str2;
     if(strcmp(str2,"RMN")==0||strcmp(str2,"MNOR")==0)
         {
             MN_pos=i4;
             temp_index[0][0]=i4;
         }
         if(strcmp(str2,"RML")==0||strcmp(str2,"RMK")==0||strcmp(str2,"RMM")==0||strcmp(str2,"RMG")==0)
         {
             MK_pos=i4;
             temp_index[1][0]=i4;
         }
         if(strcmp(str2,"RLLD")==0||strcmp(str2,"RL3D")==0||strcmp(str2,"LLD")==0)
         {
             Rd_pos=i4;
             temp_index[0][1]=i4;
         }
         if(strcmp(str2,"RLLS")==0||strcmp(str2,"RL3S")==0||strcmp(str2,"LLS")==0)
         {
             Rs_pos=i4;
             temp_index[1][1]=i4;
         }
         if(strcmp(str2,"AC")==0||strcmp(str2,"DT")==0)
         {
             Ac_pos=i4;
             temp_index[0][3]=i4;
         }
         if(strcmp(str2,"MSFL")==0||strcmp(str2,"RXO")==0)
         {
             Rxo_pos=i4;
             temp_index[2][1]=i4;
         }
         if(strcmp(str2,"GR")==0)
         {
             GR_pos=i4;
             temp_index[0][2]=i4;
         }
         if(strcmp(str2,"SP")==0)
         {
             SP_pos=i4;
             temp_index[1][2]=i4;
         }
         if(strcmp(str2,"R25")==0||strcmp(str2,"R250")==0||strcmp(str2,"R2.5")==0)
         {
             R25_pos=i4;
             temp_index[2][2]=i4;
         }
         if(strcmp(str2,"DEN")==0)
         {
             DEN_pos=i4;
             temp_index[1][3]=i4;
         }
        if(strcmp(str2,"HAC")==0)
         {
             HAC_pos=i4;
             temp_index[2][3]=i4;
         }
     i4++;
     }
   }

 stedp=int((endp-stdp)/relv);

 ip=i4;
 i4=i4-1;
 for(int i0=1;i0<(ip+1);i0++)
  {
   smaxmin(i0);
   ma[i0]=max;
   mi[i0]=min;
   }
   draw(temp_index,tracknum,data,stedp,stdp,relv);
   onpaint_switch=0;
   painthead(Sender);
   Form1->Caption=cc1+"                                            采 油 二 厂 储 层 自 动 对 比 技 术";
 //  paintdepth(stdp,stedp,relv);
   //StatusBar1->Panels->Items[0]->Text="LA文件名："+cc;

   fclose(fp); // PaintBox2->Canvas->TextOutA(50,400,newname);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::pcldkmbjLA(TObject *Sender)      //批处理打开目标井LA
{
       short i1,i2;float f;
     Top_deep1=0.0;
     int flag,i3;
     moveopen2=0;
 FILE *fp;
   int Rd_valueGTzero=0;
  int RMN_valueGTzero=0;
  int AC1_value=0,line6[6];
     MN1_pos=0;
     MK1_pos=0;
     Rd1_pos=0;
     Rs1_pos=0;
     Ac1_pos=0;
     Rxo1_pos=0;
     GR1_pos=0;
     SP1_pos=0;
     DEN1_pos=0;

// OpenDialog1->Filter="新井测井数据(*.la)|*.la|LA文件（LA*)|LA*|所有文件(*.*)|*.*";
// if(OpenDialog1->Execute()){

// for(int i0=0;i0<Form6->num;i0++)
//  {
    //  String fn1="D:\\二厂统层对比有形化平台\\测井数据\\2018\\曲线\\"+Form6->mbjm[i0]+".la";
      fp=fopen(fn1.c_str(),"rb");
      cc2=fn1.c_str();
      //ccp2=ExtractFileName(OpenDialog1->FileName);
      ccp2=ExtractFileName(fn1);
      //ccp2=fn1;

      PaintBox5->Canvas->TextOutA(80,700,"                                          ");
      PaintBox5->Canvas->Rectangle(78,680,390,780);
      PaintBox5->Canvas->TextOutA(80,700,ccp2);
   if(fp){
          fread(str0,84,1,fp);
          fread(str1,80,1,fp);
          i2=getint(fp);
          i1=getint(fp);
          fread(str,80,1,fp);
//startdp
          stdp1=getfloat(fp);
//endp
          endp1=getfloat(fp);
//cyjj
 relv1=getfloat(fp);
 i1=getint(fp);
 i2=getint(fp);
 f=getfloat(fp);
 fread(str11,80,1,fp);
 fread(str3,148,1,fp);
/*  for(int i7=0;i7<int(Top_deep1/relv1);i7++)
 {
  for(int j7=1;j7<41;j7++)
  {
   a1[i7][j7]=1.0;
   data1[i7][j7]=1.0;
   }
  } */
 stdp1=stdp1-Top_deep1;
 i1=0+int(Top_deep1/relv1);
 stedp1=int((endp1-stdp1)/relv1);
while(i1<stedp1)
 {
  for(int j=1;j<41;j++)
  {
  for(int i=i1;i<i1+62;i++)
  {
   a1[i][j]=getfloat(fp);
   if(fabs(a1[i][j])>999.0)
   {
      a1[i][j]=999.0;
   }
   data1[i][j]=a1[i][j];;
   }
   }
  i1=i1+62;
  }
 }
// }
// }
 for(int i=0;i<3;i++)
         for(int j=0;j<4;j++)
             temp_index1[i][j]=-1;

 for(int i0=0;i0<stedp1;i0++)
  {
   a1[i0][0]=stdp1+i0*relv1;
   data1[i0][0]=stdp1+i0*relv1;
   }
  int i4,i,j,ip;
 cname3[0][5]="DEPT ";
 i4=1;
 for(i=0;i<80;i+=4)
 {
  i2=0;
  for(j=i;j<i+4;j++)
  {
   if(str[j]!=' ')i2++;
   }
   j=i;
  for(i3=0;i3<4;i3++)
   str2[i3]=0;
  for(i3=0;i3<i2;i3++)
  {
   str2[i3]=str[j];
   j++;
   }
   if((str2[0]!=' ')&&(str2[0]!='\0'))
   {
     cname3[i4][5]=str2;
     if(strcmp(str2,"RMN")==0||strcmp(str2,"MNOR")==0)
         {
             MN1_pos=i4;
             line6[0] = i4;
             temp_index1[0][0]=i4;
         }
         if(strcmp(str2,"RML")==0||strcmp(str2,"RMK")==0||strcmp(str2,"RMM")==0||strcmp(str2,"RMG")==0)
         {
             MK1_pos=i4;
             temp_index1[1][0]=i4;
         }
         if(strcmp(str2,"RLLD")==0||strcmp(str2,"RL3D")==0||strcmp(str2,"LLD")==0)
         {
             Rd1_pos=i4;
             line6[1] = i4;
             temp_index1[0][1]=i4;
         }
         if(strcmp(str2,"RLLS")==0||strcmp(str2,"RL3S")==0||strcmp(str2,"LLS")==0)
         {
             Rs1_pos=i4;
             temp_index1[1][1]=i4;
         }
         if(strcmp(str2,"MSFL")==0||strcmp(str2,"RXO")==0)
         {
             Rxo1_pos=i4;
             line6[2] = i4;
             temp_index1[2][1]=i4;
         }
         if(strcmp(str2,"GR")==0)
         {
             GR1_pos=i4;
             line6[3] = i4;
             temp_index1[0][2]=i4;
         }
         if(strcmp(str2,"SP")==0)
         {
             SP1_pos=i4;
             temp_index1[1][2]=i4;
         }
         if(strcmp(str2,"R25")==0||strcmp(str2,"R250")==0||strcmp(str2,"R2.5")==0)
         {
             R251_pos=i4;
             temp_index1[2][2]=i4;
         }
         if(strcmp(str2,"AC")==0||strcmp(str2,"DT")==0)
         {
             Ac1_pos=i4;
             temp_index1[0][3]=i4;
         }
         if(strcmp(str2,"DEN")==0)
         {
             DEN1_pos=i4;
             line6[4] = i4;
             temp_index1[1][3]=i4;
         }
        if(strcmp(str2,"HAC")==0)
         {
             HAC1_pos=i4;
             line6[5] = i4;
             temp_index1[2][3]=i4;
         }
     i4++;
     }
   }


 //-----------------------------------------------------------
/*   if(fp)
   {
      fread(str0,84,1,fp);
      fread(str1,80,1,fp);
      i2=getint(fp);
      i1=getint(fp);
      fread(str,80,1,fp);
     //startdp
      stdp1=getfloat(fp);
     //endp
      endp1=getfloat(fp);
    //cyjj
   //  Top_deep1=endp1-stdp1;
     relv1=getfloat(fp);
     i1=getint(fp);
     i2=getint(fp);
     f=getfloat(fp);
     fread(str11,80,1,fp);
     fread(str3,148,1,fp);
 for(int i7=0;i7<int(Top_deep1/relv1);i7++)
 {
    for(int j7=1;j7<41;j7++)
    {
        a1[i7][j7]=1.0;
        data1[i7][j7]=1.0;
     }
  }
 stdp1=stdp1-Top_deep1;
 i1=0+int(Top_deep1/relv1);
 stedp1=int((endp1-stdp1)/relv1);
   while(i1<stedp1)
   {
       for(int j=1;j<41;j++)
       {
          for(int i=i1;i<i1+62;i++)
          {
             a1[i][j]=getfloat(fp);
             data1[i][j]=a1[i][j];;
          }
       }
       i1=i1+62;
   }
 }
// }
// }
 for(int i=0;i<3;i++)
 {
         for(int j=0;j<4;j++)
         {
             temp_index1[i][j]=-1;
         }
  }
 for(int i0=0;i0<stedp1;i0++)
  {
   a1[i0][0]=stdp1+i0*relv1;
   data1[i0][0]=stdp1+i0*relv1;
   }
  int i4,i,j,ip;
 cname3[0][5]="DEPT ";
 i4=1;
 for(i=0;i<80;i+=4)
 {
  i2=0;
  for(j=i;j<i+4;j++)
  {
   if(str[j]!=' ')i2++;
   }
   j=i;
  for(i3=0;i3<4;i3++)
   str2[i3]=0;
  for(i3=0;i3<i2;i3++)
  {
   str2[i3]=str[j];
   j++;
   }
   if((str2[0]!=' ')&&(str2[0]!='\0'))
   {
     cname3[i4][5]=str2;
     if(strcmp(str2,"RMN")==0||strcmp(str2,"MNOR")==0)
         {
             MN1_pos=i4;
             temp_index1[0][0]=i4;
         }
         if(strcmp(str2,"RML")==0||strcmp(str2,"RMK")==0||strcmp(str2,"RMM")==0||strcmp(str2,"RMG")==0)
         {
             MK1_pos=i4;
             temp_index1[1][0]=i4;
         }
         if(strcmp(str2,"RLLD")==0||strcmp(str2,"RL3D")==0||strcmp(str2,"LLD")==0)
         {
             Rd1_pos=i4;
             temp_index1[0][1]=i4;
         }
         if(strcmp(str2,"RLLS")==0||strcmp(str2,"RL3S")==0||strcmp(str2,"LLS")==0)
         {
             Rs1_pos=i4;
             temp_index1[1][1]=i4;
         }
         if(strcmp(str2,"MSFL")==0||strcmp(str2,"RXO")==0)
         {
             Rxo1_pos=i4;
             temp_index1[2][1]=i4;
         }
         if(strcmp(str2,"GR")==0)
         {
             GR1_pos=i4;
             temp_index1[0][2]=i4;
         }
         if(strcmp(str2,"SP")==0)
         {
             SP1_pos=i4;
             temp_index1[1][2]=i4;
         }
         if(strcmp(str2,"AC")==0||strcmp(str2,"DT")==0)
         {
             Ac1_pos=i4;
             temp_index1[0][3]=i4;
         }
         if(strcmp(str2,"DEN")==0)
         {
             DEN1_pos=i4;
             temp_index1[1][3]=i4;
         }
        if(strcmp(str2,"HAC")==0)
         {
             HAC1_pos=i4;
             temp_index1[2][3]=i4;
         }
     i4++;
     }
   } */
 /*fendp=0;
 stedp1=int((endp1-stdp1)/relv1); ip=i4;i4=i4-1;
 for(int i0=stedp1;i0>(stedp1-300);i0--)
 {
    fdp0=a1[i0][MN1_pos]*a1[i0][Rd1_pos]*a1[i0][Rxo1_pos]*a1[i0][GR1_pos]*a1[i0][DEN1_pos]*a1[i0][HAC1_pos];
    fdp01=(a1[i0][MN1_pos]-a1[i0+1][MN1_pos])*(a1[i0][Rd1_pos]-a1[i0+1][Rd1_pos])*(a1[i0][Rxo1_pos]-a1[i0+1][Rxo1_pos])*(a1[i0][GR1_pos]-a1[i0+1][GR1_pos])*(a1[i0][DEN1_pos]-a1[i0+1][DEN1_pos])*(a1[i0][HAC1_pos]-a1[i0+1][HAC1_pos]);
    if(((fdp01*fdp0)>1.0)&&(fendp==0))
    {
        fendp=stdp1+i0*relv1;
    }
 }
 for(int i0=1;i0<(ip+1);i0++)
  {
   smaxmin1(i0);
   ma[i0]=max;
   mi[i0]=min;
   }
   onpaint_switch1=0;
   draw1(temp_index1,tracknum,data1,stedp1,stdp1,relv1);
   painthead1(Sender);
  // paintdepth1(stdp1,stedp1,relv1);
 // StatusBar2->Panels->Items[0]->Text="LA文件名："+cc;
  Form1->Caption=cc1+"                                                             采 油 二 厂 储 层 自 动 对 比 技 术                                                         "+cc2;
   fclose(fp);  */
    int start = 0;
    int end = 0;
   for(int i = 0;i < 50000;i ++)
   {
        if(data1[i][line6[0]] * data1[i][line6[1]] * data1[i][line6[2]] * data1[i][line6[3]] * data1[i][line6[4]] * data1[i][line6[5]] == 0)
        {
                start = i;
        }
        else
        {
            int temp = 0;
            for(int j = 0;j < 6;j ++)
            {
                if(data1[i][line6[j]] < -2000)
                {
                        temp = 1;
                }
            }
            if(temp == 1)
            {
                start = i;
                continue;

            }
            else
                break;
        }

   }
   for(int i = 49999;i > start;i --)
   {
        if(data1[i][line6[0]] * data1[i][line6[1]] * data1[i][line6[2]] * data1[i][line6[3]] * data1[i][line6[4]] * data1[i][line6[5]] == 0)
                end = i;
        else
                break;
   }

  // int temp = 0;
   for(int i = start;i < end + 1;i ++)
   {
        for(int j = 0;j < 50;j ++)
        {
                a1[i - start][j] = a1[i][j];
                data1[i - start][j] = data1[i][j];
        }
   }
    endp1 = a1[end - start][0];
    stdp1 = a1[0][0];
    stedp1 = end - start;
   /////////////////////////////////////////////////


 fendp=0;
 //stedp1=int((endp1-stdp1)/relv1);
 ip=i4;i4=i4-1;
 for(int i0=stedp1;i0>(stedp1-300);i0--)
 {
    fdp0=a1[i0][MN1_pos]*a1[i0][Rd1_pos]*a1[i0][Rxo1_pos]*a1[i0][GR1_pos]*a1[i0][DEN1_pos]*a1[i0][HAC1_pos];
    fdp01=(a1[i0][MN1_pos]-a1[i0+1][MN1_pos])*(a1[i0][Rd1_pos]-a1[i0+1][Rd1_pos])*(a1[i0][Rxo1_pos]-a1[i0+1][Rxo1_pos])*(a1[i0][GR1_pos]-a1[i0+1][GR1_pos])*(a1[i0][DEN1_pos]-a1[i0+1][DEN1_pos])*(a1[i0][HAC1_pos]-a1[i0+1][HAC1_pos]);
    if(((fdp01*fdp0)>1.0)&&(fendp==0))
    {
        fendp=stdp1+i0*relv1;
    }
 }
 for(int i0=1;i0<(ip+1);i0++)
  {
   smaxmin1(i0);
   ma[i0]=max;
   mi[i0]=min;
   }
   onpaint_switch1=0;
   draw1(temp_index1,tracknum,data1,stedp1,stdp1,relv1);
   painthead1(Sender);
  // paintdepth1(stdp1,stedp1,relv1);
 // StatusBar2->Panels->Items[0]->Text="LA文件名："+cc;
  Form1->Caption=cc1+"                                                             采 油 二 厂 储 层 自 动 对 比 技 术                                                         "+cc2;
   fclose(fp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::pcl(TObject *Sender)      //批处理
{

          pcldkckjLA(Sender);   //批处理打开参考井LA
          zdjzcjdyljsjk(Sender); //自动加载老井沉积单元数据库
         /* for(int i1=0;i1<ljcgs;i1++)
          {
             PaintBox2->Canvas->TextOutA(80,23+14*i1,a2[i1][0]);
             PaintBox2->Canvas->TextOutA(30,23+14*i1,ljcgs);
          } */
      for(int i0=0;i0<Form6->num;i0++)
      {
          if(i0<40)
          {
                 PaintBox2->Canvas->TextOutA(120,15+i0*15,Form6->mbjm[i0]);
                 PaintBox2->Canvas->TextOutA(70,15+i0*15,i0);
          }
          else if((i0>=41)&&(i0<81))
          {
                 PaintBox2->Canvas->TextOutA(250,15+(i0-40)*15,Form6->mbjm[i0]);
                 PaintBox2->Canvas->TextOutA(230,15+(i0-40)*15,i0);
          }
          else if((i0>80)&&(i0<121))
          {
                 PaintBox2->Canvas->TextOutA(370,15+(i0-80)*15,Form6->mbjm[i0]);
                 PaintBox2->Canvas->TextOutA(350,15+(i0-80)*15,i0);
          }
          else if((i0>120)&&(i0<161))
          {
                 PaintBox2->Canvas->TextOutA(490,15+(i0-120)*15,Form6->mbjm[i0]);
                 PaintBox2->Canvas->TextOutA(470,15+(i0-120)*15,i0);
          }
          else if((i0>160)&&(i0<201))
          {
                 PaintBox2->Canvas->TextOutA(490,15+(i0-160)*15,Form6->mbjm[i0]);
                 PaintBox2->Canvas->TextOutA(470,15+(i0-160)*15,i0);
          }
          else if((i0>200)&&(i0<241))
          {
                 PaintBox2->Canvas->TextOutA(610,15+(i0-200)*15,Form6->mbjm[i0]);
                 PaintBox2->Canvas->TextOutA(590,15+(i0-200)*15,i0);
          }
          else if((i0>240)&&(i0<301))
          {
                 PaintBox2->Canvas->TextOutA(630,15+(i0-240)*15,Form6->mbjm[i0]);
                 PaintBox2->Canvas->TextOutA(610,15+(i0-240)*15,i0);
          }
         // PaintBox2Paint(Sender);
        //  pcldkckjLA(Sender);   //批处理打开参考井LA
         // zdjzcjdyljsjk(Sender); //自动加载老井沉积单元数据库
          fn1="D:\\二厂统层对比有形化平台\\测井数据\\2018\\曲线\\"+Form6->mbjm[i0]+".la";

          pcldkmbjLA(Sender);         //批处理打开目标井LA

          zdjzxjcjdysjk(Sender);   //自动加载新井沉积单元数据库
        /*  if(MOD != 1)
                N25Click(Sender);
          else
                N14Click(Sender);       //统层智能对比算法  */
           N26Click(Sender);       //统层智能对比算法
         /*  for(int i=0;i<196;i++)
           {
              PaintBox2->Canvas->TextOutA(170,15+i*15,ckdeep[i]);
           }  */
          shujujiar073k(Sender); //数据加入073库
          for(int i = 0;i < 200;i ++)
                mbdeep[i] =1.0;
      }


}
//----------------------------------------------------------------------------
void __fastcall TForm1::bzc0(TObject *Sender)       //标准层
{
         FILE *fJC,*SIII7,*pI561,*pII10GI1,*GI10,*GI20,*GII3Y4,*GII34YIII1;
      fJC=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\JC.dat","rt");
      SIII7=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\SIII7.dat","rt");
      pI561=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\pI5+61.dat","rt");
      pII10GI1=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\pII10-GI1.dat","rt");
      GI10=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\GI10.dat","rt");
      GI20=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\GI20.dat","rt");
      GII3Y4=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\GII3-4.dat","rt");
      GII34YIII1=fopen("D:\\二厂统层对比有形化平台\\标准层数据\\GII34-GIII1.dat","rt");

      String Dir[10];
      Dir[0] = "D:\\二厂统层对比有形化平台\\标准层数据\\JC.dat";
      Dir[1] = "D:\\二厂统层对比有形化平台\\标准层数据\\SIII7.dat";
      Dir[2] = "D:\\二厂统层对比有形化平台\\标准层数据\\pI5+61.dat";
      Dir[3] = "D:\\二厂统层对比有形化平台\\标准层数据\\pII10-GI1.dat";
      Dir[4] = "D:\\二厂统层对比有形化平台\\标准层数据\\GI10.dat";
      Dir[5] = "D:\\二厂统层对比有形化平台\\标准层数据\\GI20.dat";
      Dir[6] = "D:\\二厂统层对比有形化平台\\标准层数据\\GII3-4.dat";
      Dir[7] = "D:\\二厂统层对比有形化平台\\标准层数据\\GII34-GIII1.dat";
      for(int k = 0;k < 8;k ++)
      {
                TStringList *t = new TStringList();
                t->LoadFromFile(Dir[k]);
                int n1 = t->Count;
                for(int i = 0;i < n1;i ++)
                {
                        String st = "%8*s ";
                        String sst = "%6f";
                        for(int j = 0;j < 7;j ++)
                        {
                                if(k == 0)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&JCdata[i][j]);
                                if(k == 1)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&SIII7data[i][j]);
                                if(k == 2)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&pI561data[i][j]);
                                if(k == 3)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&pII10GI1data[i][j]);
                                if(k == 4)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&GI10data[i][j]);
                                if(k == 5)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&GI20data[i][j]);
                                if(k == 6)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&GII3Y4data[i][j]);
                                if(k == 7)
                                        sscanf(t->Strings[i].c_str(),sst.c_str(),&GII34YIII1data[i][j]);
                                sst = st + sst;
                        }
                }
                delete t;
      }
      /*



          for(int i0=0;i0<54;i0++)                   //  0--deep,  1-- MN_pos  2---Rd_pos      3---Rxo_pos       4---DEN_pos       5---HAC_pos      6---GR_pos
          {
              fscanf(fJC,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",JCdata[i0][0],JCdata[i0][1],JCdata[i0][2],JCdata[i0][3],JCdata[i0][4],JCdata[i0][5],JCdata[i0][6]);
          }
          for(int i0=0;i0<36;i0++)
          {
              fscanf(SIII7,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",SIII7data[i0][0],SIII7data[i0][1],SIII7data[i0][2],SIII7data[i0][3],SIII7data[i0][4],SIII7data[i0][5],SIII7data[i0][6]);
          }
          for(int i0=0;i0<38;i0++)
          {
              fscanf(pI561,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",pI561data[i0][0],pI561data[i0][1],pI561data[i0][2],pI561data[i0][3],pI561data[i0][4],pI561data[i0][5],pI561data[i0][6]);
          }
          for(int i0=0;i0<146;i0++)
          {
              fscanf(pII10GI1,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",pII10GI1data[i0][0],pII10GI1data[i0][1],pII10GI1data[i0][2],pII10GI1data[i0][3],pII10GI1data[i0][4],pII10GI1data[i0][5],pII10GI1data[i0][6]);
          }
          for(int i0=0;i0<70;i0++)
          {
              fscanf(GI10,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",GI10data[i0][0],GI10data[i0][1],GI10data[i0][2],GI10data[i0][3],GI10data[i0][4],GI10data[i0][5],GI10data[i0][6]);
          }
          for(int i0=0;i0<52;i0++)
          {
              fscanf(GI20,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",GI20data[i0][0],GI20data[i0][1],GI20data[i0][2],GI20data[i0][3],GI20data[i0][4],GI20data[i0][5],GI20data[i0][6]);
          }
          for(int i0=0;i0<30;i0++)
          {
              fscanf(GII3Y4,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",GII3Y4data[i0][0],GII3Y4data[i0][1],GII3Y4data[i0][2],GII3Y4data[i0][3],GII3Y4data[i0][4],GII3Y4data[i0][5],GII3Y4data[i0][6]);
          }
          for(int i0=0;i0<44;i0++)
          {
              fscanf(GII34YIII1,"%8.3f  %8.3f  %8.3f %8.3f  %8.3f  %8.3f %8.3f\n",GII34YIII1data[i0][0],GII34YIII1data[i0][1],GII34YIII1data[i0][2],GII34YIII1data[i0][3],GII34YIII1data[i0][4],GII34YIII1data[i0][5],GII34YIII1data[i0][6]);
          }
      */
         stedp1=int(fabs(fendp-stdp1)/relv1);
          float p1=99999999.0,p2=99999999.0,p3=999999999.0,p4=99999999.0,p5=999999999.0,p6=999999999.0,p7=99999999.0,p8=99999999.0;
         isb=50;
         do
         {
           isb=isb+1;
         }while(fabs(data1[isb+1][MN1_pos]-data1[isb][MN1_pos])<0.001);
         for(int i1=isb;i1<stedp1;i1++)
         {

             float sp1=0.0,sp2=0.0,sp3=0.0,sp4=0.0,sp5=0.0,sp6=0.0,sp7=0.0,sp8=0.0;
             for(int i=0;i<54;i++)
             {
                  sp1=sp1+JCdata[i][1]*fabs(JCdata[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp1<p1)
             {
                p1=sp1;
                deepJC=data1[i1+18][0];
             }
             for(int i=0;i<36;i++)
             {
                  sp2=sp2+SIII7data[i][1]*fabs(SIII7data[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp2<p2)
             {
                p2=sp2;
                deepSIII7=data1[i1+2][0];
             }
             for(int i=0;i<38;i++)
             {
                  sp3=sp3+pI561data[i][1]*fabs(pI561data[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp3<p3)
             {
                p3=sp3;
                deeppI561=data1[i1+6][0];
             }
             for(int i=0;i<146;i++)
             {
                  sp4=sp4+pII10GI1data[i][1]*fabs(pII10GI1data[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp4<p4)
             {
                p4=sp4;
                deeppII10=data1[i1+0][0];
                deepGI1=data1[i1+145][0];
             }
             for(int i=0;i<70;i++)
             {
                  sp5=sp5+GI10data[i][1]*fabs(GI10data[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp5<p5)
             {
                p5=sp5;
                deepGI10=data1[i1+0][0];
             }
             for(int i=0;i<52;i++)
             {
                  sp6=sp6+GI20data[i][1]*fabs(GI20data[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp6<p6)
             {
                p6=sp6;
                deepGI20=data1[i1+0][0];
             }
             for(int i=0;i<30;i++)
             {
                  sp7=sp7+GII3Y4data[i][1]*fabs(GII3Y4data[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp7<p7)
             {
                p7=sp7;
                deepGII3=data1[i1+0][0];
                deepGII4=data1[i1+29][0];
             }
             for(int i=0;i<44;i++)
             {
                  sp8=sp8+GII34YIII1data[i][1]*fabs(GII34YIII1data[i][1]-data1[i1+i][MN1_pos]);     //x*x-xy=x(x-y)
             }
             if(sp8<p8)
             {
                p8=sp8;
                deepGII34=data1[i1+0][0];
                deepGIII1=data1[i1+43][0];
             }
         }
     fclose(fJC);fclose(SIII7);fclose(pI561);fclose(pII10GI1);fclose(GI10);fclose(GI20);fclose(GII3Y4);fclose(GII34YIII1);
  //   bzcpaint(Sender);
}
//-----------------------------------------------------------------------------------------
void __fastcall TForm1::bzcpaint(TObject *Sender)       //标准层绘图
{
  PaintBox4->Canvas->Pen->Width=2;
  PaintBox4->Canvas->Pen->Style=psSolid;
  PaintBox4->Canvas->Pen->Color=clBlack;
  int ii0=0;
  float deep1;
  int tw;
  tw=Form1->Width/2.2-5;
 for(int i0=isb;i0<stedp1;i0++)
 {
    deep1=stdp1+i0*relv1;
    if(fabs(deep1-deepJC)<0.03)
    {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"JC");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepJC)));

     }
     if(fabs(deep1-deepSIII7)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"SIII7");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepSIII7)));
     }
     if(fabs(deep1-deeppI561)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"pI5+61");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deeppI561)));
     }
     if(fabs(deep1-deeppII10)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"pII10");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deeppII10)));
     }
     if(fabs(deep1-deepGI1)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"GI1");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepGI1)));
     }
     if(fabs(deep1-deepGI10)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"GI10");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepGI10)));
     }
     if(fabs(deep1-deepGI20)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"GI20");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepGI20)));
     }
     if(fabs(deep1-deepGII3)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"GII3");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepGII3)));
     }
     if(fabs(deep1-deepGII4)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"GII4");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepGII4)));
     }
     if(fabs(deep1-deepGII34)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"GII34");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepGII34)));
     }
     if(fabs(deep1-deepGIII1)<0.03)
     {
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(tw+30,i0);
          PaintBox4->Canvas->TextOut(tw-14,i0-14,"GIII1");
          PaintBox4->Canvas->TextOut(tw-14,i0+3,AnsiString(FormatFloat("0.0",deepGIII1)));
     }

  }





}
//--------------------------------------------------------------------------------------------
void __fastcall TForm1::N25Click(TObject *Sender)    //运用标准层进行统层智能对比
{
     Well_Name_1 = ccp;
     Well_Name_2 = ccp2;
     Well_Name_1_path = cc1;
     Well_Name_2_path = cc2;

   ljcw=0; icount=0; n=6;  //老井层位数
   cwjd=16+40+20+20;   //层位节点
   int totalnum;  float start,end;
 //  izz=0;      //最终层个数
   ljsdc=0.0;  //老井深度差
   zxcjj=9999.0;    //最小层间距
   int ljcw0=0;
   float a2lj0[500];
     //--------------------------------------
   for(int lj0=0;lj0<ljcgs-1;lj0++)
  {
    if(a2[lj0][0]>20.0)    //除掉0
    {
       if((str6[ljcw0]=="JC")||(str6[ljcw0]=="JCJC"))
       {

         // JCnum=ljcw0;
          JCljd=int(fabs(a2[lj0][0]-stdp)/relv);

       }
       a2lj0[ljcw0]=a2[lj0][0];
       cjmk[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]+0.5;
       cjmk0[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]-0.6;
       if(cjmk0[ljcw0]<0.2)cjmk0[ljcw0]=0.2;
       ljcw0=ljcw0+1;
    }

  }
  for(int ii1=0;ii1<ljcw0-1;ii1++)
  {
     if((zxcjj>fabs(a2lj0[ii1+1]-a2lj0[ii1]))&&(fabs(a2lj0[ii1+1]-a2lj0[ii1])>0.2))
     {
        zxcjj=fabs(a2lj0[ii1+1]-a2lj0[ii1]);
     }
  }
  zxcjj=zxcjj;    //最小层间距   2022-10-31以前

  for(lj=0;lj<ljcgs-1;lj++)    //2022-2-9早上修改  <  换成  <=
  {
    if(a2[lj][0]>20.0)     //&&((fendp-zzppsd[ljcw-2])>3.0))    //除掉0
    {
      start=a2[lj][0]-4.8;               //n7-4-sp2038   S11----941.5
      end=a2[lj][0]+4.8;                  //n7-4-sp2038   S12---end=a2[0][0]+0.8;
      totalnum=int((end-start)/relv);
      open_correct=0;//校正开关
    //  PaintBox2->Canvas->TextOutA(80,10+14*(ljcw+1),"处理层位  ");
      str8[ljcw]=str6[lj];   //非空层号
      a2lj[ljcw]=a2[lj][0];
      ljcw=ljcw+1;         //老井层位
      for(int i0=0;i0<stedp;i0++)
      {
            if((fabs(a[i0][0]-start)<0.005)&&((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P15+61")||(str8[ljcw-1]=="P210")||(str8[ljcw-1]=="G11")||(str8[ljcw-1]=="G120")||(str8[ljcw-1]=="G23")||(str8[ljcw-1]=="G234")))
            {
                 ie1=0;  // PaintBox2->Canvas->TextOutA(80,10+14*(4+1),"JC  ");
                 for(int i=i0;i<i0+totalnum+1;i++)
                 {
                      //   fprintf(fp1,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a[i][0],a[i][MN_pos],a[i][Rd_pos],a[i][DEN_pos],a[i][HAC_pos],a[i][Rxo_pos],a[i][GR_pos]);
                        xcsj[ie1][0]=StrToFloat(FormatFloat("0.0",a[i][0]));            //2021年11月2日修改原来深度保留2位小数
                        bzcsj[ie1][0]=xcsj[ie1][0];
                        xcsj[ie1][1]=StrToFloat(FormatFloat("0.00",a[i][MN_pos]));
                        bzcsj[ie1][1]=xcsj[ie1][1];
                        xcsj[ie1][2]=StrToFloat(FormatFloat("0.00",a[i][Rd_pos]));
                        bzcsj[ie1][2]=xcsj[ie1][2];
                        xcsj[ie1][3]=StrToFloat(FormatFloat("0.00",a[i][DEN_pos]));
                        bzcsj[ie1][3]=xcsj[ie1][3];
                        xcsj[ie1][4]=StrToFloat(FormatFloat("0.00",a[i][HAC_pos]));
                        bzcsj[ie1][4]=xcsj[ie1][4];
                        xcsj[ie1][5]=StrToFloat(FormatFloat("0.00",a[i][Rxo_pos]));
                        bzcsj[ie1][5]=xcsj[ie1][5];
                        xcsj[ie1][6]=StrToFloat(FormatFloat("0.00",a[i][GR_pos]));
                        bzcsj[ie1][6]=xcsj[ie1][6];


                        ie1++;
                 }
            }
      }
   //  cjmkz(Sender);
     PaintBox2->Canvas->TextOutA(230,300+14*6,"正在处理第            个小层;");
     PaintBox2->Canvas->TextOutA(306,300+14*6,AnsiString(ljcw));
     PaintBox2->Canvas->TextOutA(400,300+14*6,"共计           个小层!");
     PaintBox2->Canvas->TextOutA(434,300+14*6,AnsiString(ljcw0));
     if((ljcw-1)==(ljcw0-1))
     {
       PaintBox2->Canvas->TextOutA(230,350+14*6,"正在处理最后一个小层,请稍后");
     }
     if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P15+61")||(str8[ljcw-1]=="P210")||(str8[ljcw-1]=="G11")||(str8[ljcw-1]=="G120")||(str8[ljcw-1]=="G23")||(str8[ljcw-1]=="G234"))
     {
           dtsjglmdwqd2(Sender);    //动态时间概率密度弯曲度正式算法
     }


    }

   }
   int Error = 0;
   for(int i=0;i<ljcgs-1;i++)
   {
        if((str8[i]=="JC"||str8[i]=="JCJC") && zzppsd[i] < 10)
                Error = 1;
   }
   if(Error == 0)
   {
     //  paintfencengnew(Sender);
     //  for(int io=0;io<ljcgs-1;io++)
       {
       //    if(str6[io]=="JC")
           {
                xsjs(Sender);        //向上计算
                xxjs(Sender);        //向下计算
           }
       }



   //  paintfencengnew(Sender);



     //
     //
     //
     int JC = 0;
     for(int i = 0;i < 200;i ++)
     {
        if((str6[i] == "JC")||(str6[i] == "JCJC"))
                JC = i;
     }
     for(int i = JC;i < 200;i ++)
     {
        if(zzppsd[i] > 100)
                SentResult[i - JC] = zzppsd[i];
        else
                SentResult[i - JC] = 0;
     }

     if(DBF073_path.Length() > 5)
     {
        Form1->BitBtn6Click(Sender);
                int LastTemp = 0;
                        for(int i = 200 - JC;i > 1;i --)
                        {
                                if(zzppsd[i + JC] > 100)
                                {
                                        LastTemp = i;
                                        break;
                                }

                        }
                        //for(int i = 0;i < 100;i ++)
                        for(int i = 0;i < LastTemp + JC;i ++)
                        {
                                if(zzppsd[i + JC] < 100 && FinDepth[i] > 100)
                                {
                                        if(FinDepth[i] > 100 && FinDepth[i + 1] > 100 && FinDepth[i] > FinDepth[i + 1])
                                        {
                                                float swap = FinDepth[i];
                                                FinDepth[i] = FinDepth[i + 1];
                                                FinDepth[i + 1] = swap;
                                        }


                                        str8[i + JC] = FinUnitName[i];
                                        zzppsd[i + JC] = FinDepth[i];
                                        //ljcw ++;
                                }
                        }
     }
     //SentResult2[0];
     //paintfencengnew(Sender);
     }
     else
     {

          for(int i = 0;i < 300;i ++)
                zzppsd[i] = 0;
          N14Click(Sender);
     }



}
//----------------------------------------------------------------------------
void __fastcall TForm1::dtsjglmdwqd2(TObject *Sender)  //动态时间概率密度弯曲度正式算法
{
   float s0[30],s1[30],s3[30],s5[30],dfo[30],ds[30],df2[30],df3[30],ss1=0.0,ss2=0.0,ss3=0.0,ds1=0.0,ds2,ds3,dso=0.0,dist1[30],dist2[30];
   int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0;
   float xgxs=0.8,p1[30],p2[30];
   n=6;   open_correct=0;open_correct2=0;
    for(int j=1;j<=n;j++)
    {
      s0[j]=0.0;p1[j]=100000000.0;p2[j]=0.01; bedeep[j][0]=0.0;bedeep[j][1]=0.0;
      for(int i1=0;i1<ie1-1;i1++)
      {
       s0[j]=s0[j]+xcsj[i1][j];
      }
      s0[j]=s0[j]/float(ie1-1);

    }

 //--------------------------------------
         for(int i0=5;i0<stedp1-ie1-20;i0++)
         {
             for(int i=i0;i<i0+ie1+20;i++)
             {
                xssj[i-i0][0]=StrToFloat(FormatFloat("0.00",data1[i][0]));
                xssj[i-i0][1]=data1[i][MN1_pos];
                xssj[i-i0][2]=data1[i][Rd1_pos];
                xssj[i-i0][3]=data1[i][DEN1_pos];
                xssj[i-i0][4]=data1[i][HAC1_pos];
                xssj[i-i0][5]=data1[i][Rxo1_pos];
                xssj[i-i0][6]=data1[i][GR1_pos];
             }
             for(int j=1;j<=n;j++)
             {
                     //皮尔逊相似度
                     s1[j]=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                       s1[j]=s1[j]+xssj[i1][j];
                     }
                     s1[j]=s1[j]/float(ie1-1);
                     ss1=0.0;ss2=0.0;ss3=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                        ss1=ss1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                        ss2=ss2+pow((xcsj[i1][j]-s0[j]),2);
                        ss3=ss3+pow((xssj[i1][j]-s1[j]),2);
                     }
                     dist2[j]=(ss1/sqrt(ss2*ss3));       //皮尔逊相似度
                     if((i0<(stedp1-20))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {

                           if((p2[j]<dist2[j])&&(data1[i0+cwjd][0]>100.0))
                           {
                              p2[j]=dist2[j];
                              po2[j]=dist2[j];
                              deep2[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0])); //2021年11月2日修改原来深度保留2位小数
                              dp2MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                           }
                      }
                    //动态时间弯曲度
                    ds1=0.0;int ic;float sp=0.0,p;ds2=0.0;ds3=0.0,dso=0.0;
                    for(int i1=0;i1<ie1-1;i1++)
                    {
                       if(i1==0)
                       {
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                       else if(i1==1)
                       {
                         sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])      //是否可以使用dfo[i3]>dfo[i4]?
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if(i1==2)
                       {
                         sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                          for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if((i1>2)&&(i1<ie1-4))
                       {
                          sp=0.0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/7.0;
                          ic=0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-4))
                      {
                          sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                          for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-3))
                      {
                          sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                      }
                      else if(i1==(ie1-2))
                      {
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                     }
                      dist1[j]=(ds1/sqrt(ds2*ds3));       //皮尔逊相似度
                      if((i0<(stedp1-50))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {
                        if((p1[j]>dso)&&(data1[i0+cwjd*3][0]>100.0))
                        {
                            p1[j]=dso;
                            pdtsj1[j]=p1[j];
                            deep1[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0]));    //2021年11月2日修改原来深度保留2位小数
                            dp1MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                         }

                      }

             }

         }
//--------------------------------------------------------------------------------
   float bdp0[20],bdp1[20]; int ic0=0,ic=0;
    dtgmwqd2(Sender);   //动态概率密度弯曲度
    ljxjdb2(Sender); //老井新井对比





}
//---------------------------------------------------------------------------
void __fastcall TForm1::dtgmwqd2(TObject *Sender) //动态概率密度弯曲度
{
  float p,I[500][20],jz0[20],bcgm[20]; //均值、标准层概率密度
    int stdi=cwjd; n=6;
   for(int j=1;j<=n;j++)                   //取最大值、最小值
   {
       for(int i1=0;i1<ie1-2;i1++)
       {
           for(int i2=i1+1;i2<ie1-1;i2++)
           {
               if(bzcsj[i1][j]<bzcsj[i2][j])
               {
                   p=bzcsj[i1][j];
                   bzcsj[i1][j]=bzcsj[i2][j];
                   bzcsj[i2][j]=p;
               }
           }
       }
   }
   for(int j=1;j<=n;j++)
   {
       jz0[j]=0.0;
       bcgm[j]=0.0;
       bcgm[j+10]=0.0;
       for(int i1=0;i1<ie1-1;i1++)
       {                                          //归一化
          I[i1][j]=xcsj[i1][j]/bzcsj[0][j];
          jz0[j]=jz0[j]+I[i1][j];
       }
       jz0[j]=jz0[j]/float(ie1-1);
   }
   for(int j=1;j<=n;j++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float(iu)/float(stdi);                 //标准层各条曲线单独概率密度
        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float((ie1-1)-iu)/float(ie1-1-stdi);
        }
   }
 //----------------------------------------------------------------------------- //新井概率密度求取
   float sig[20],jz1[20],mdgm[20],mdgm1[30],dtgm[20]; float pp1[20],pp2[20],menkan[20];
   n=6;
   for(int j1=1;j1<=n;j1++)
   {
      pp1[j1]=99999.0;
      pp2[j1]=99999.0;
      menkan[j1]=99999.0;
   }
    pp1[11]=999999.0;
   for(int i=5;i<stedp1-ie1-20;i++)
   {
           for(int j1=0;j1<=n;j1++)
           {
             for(int i1=0;i1<ie1-1;i1++)
             {
               xsj[i1][j1]=0.0;
               I1[i1][j1]=0.0;
              }
            }
          for(int i1=i;i1<i+ie1-1;i1++)
          {
            xsj[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]));
              xsj[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]));
                xsj[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]));
                  xsj[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]));
                    xsj[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]));
                      xsj[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]));
          }
      float p1;
      for(int j1=1;j1<=n;j1++)
      {
       //sig[j1]=0.0;//计算各条曲线测量值总和，再求平均值
        for(int i1=0;i1<ie1-2;i1++)
         {
          for(int i2=i1+1;i2<ie1-1;i2++)
           {
             if(xsj[i1][j1]<xsj[i2][j1])
             {
               p1=xsj[i1][j1];
               xsj[i1][j1]=xsj[i2][j1];
               xsj[i2][j1]=p1;
              }
            }
         }

     }
     //RMNmin1=Cmin1[1];
     for(int i1=i;i1<i+ie1-1;i1++)
     {
       I1[i1-i][0]=StrToFloat(FormatFloat("0.00",a1[i1][0]));
       I1[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][1]));   //微电位归一化
       I1[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][2])); //深侧向归一化
       I1[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][3])); //密度归一化
       I1[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][4])); //声波归一化
       I1[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][5])); //微球归一化
       I1[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][6])); //伽马归一化
     }
      for(int j=1;j<=n;j++)
     {
         float s1=0.0;
         for(int i1=1;i1<ie1-1;i1++)      //时域及时域梯度  运行结果完美
         {
           s1=s1+0.5*fabs(I[i1][j]-I1[i1][j])+0.5*fabs((I[i1][j]-I[i1-1][j])-(I1[i1][j]-I1[i1-1][j]));
         }
          if(s1<menkan[j])
          {
             menkan[j]=s1;
             menkan3[j]=menkan[j];
             sytdu[j]=I1[stdi][0];
             sytdMN[j]=xsj[stdi][1];
          }
     }
     for(int j1=1;j1<=n;j1++)
     {
         jz1[j1]=0.0; mdgm[j1]=0.0;mdgm[j1+10]=0.0;mdgm1[j1]=0.0;
         for(int i1=0;i1<ie1-1;i1++)
         {
           jz1[j1]=jz1[j1]+I1[i1][j1];
         }
         jz1[j1]=jz1[j1]/float(ie1-1);
     }
   for(int j1=1;j1<=n;j1++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
         //   mdgm[j1]=mdgm[j1]+(I1[iu][j1]-jz1[j1])*I1[iu][j1]/(jz1[j1]*float(ie1-1));            //float(iu)/float(stdi);                 //目的层各条曲线单独概率密度
            if(iu==0)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
            }
            else if(iu==1)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                            //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
              mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==2)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if((iu>2)&&(iu<=stdi))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));            //       float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }

        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            if((iu>=stdi)&&(iu<ie1-4))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));          //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-4)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));       // float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-3)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                    //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-2)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                        //float((ie1-1)-iu)/float(ie1-1-stdi);
            }
        }
   }
        float menkan[20];
           for(int j1=1;j1<=n;j1++)
          {
             menkan[j1]=99999.0;
             if((mdgm1[j1]<pp2[j1])&&((a1[i+20][MN1_pos]*a1[i+20][Rd1_pos]*a1[i+20][DEN1_pos]*a1[i+20][HAC1_pos]*a1[i+20][Rxo1_pos]*a1[i+20][GR1_pos])>1.0))
             {
                pp2[j1]=mdgm1[j1];
                poGM[j1]=pp2[j1];
                GMdeep2[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][0]));
                GMMN[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][MN1_pos]));
             }
          }

    }



}
//--------------------------------------------------------------------------------------------------------------------------------

void __fastcall TForm1::ljxjdb2(TObject *Sender) //老井新井对比
{
     float s[30],dp[30],s2[30],s3[30],s4[30],p01=0.0,p02=0.0,p03=0.0,p04=0.0,p11=9999.0,p22=9999.0,p33=9999.0,p44=9999.0; //新老深度
     int dbnum=0;  //对比数
    // sdeep1=0.0;
   //  float dp1=0.0,dp2=0.0,dp3=0.0;
     n=6;
          int in=1,ic=0;
          if((zzppsd[ljcw-1-1]<20.0)&&(ljcw-1)>2)
          {
             for(int ij=1;ij<20;ij++)
             {
                if((zzppsd[ljcw-1-ij]<20.0)&&(ic==0))
                {
                    in=in+1;
                }
                else if(zzppsd[ljcw-1-ij]>20.0)
                {
                   ic=1;
                }
             }
          }
       //   PaintBox4->Canvas->TextOutA(80,50+14*6,"in   "+AnsiString(in));

          cjmk[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]+0.7;
          cjmk0[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]-0.6;
     for(int i1=-1;i1<29;i1++)
     {
        s[i1]=9999.0;
        s2[i1]=9999.0;
        s3[i1]=9999.0;
        s4[i1]=9999.0;
        xldeep[i1]=-1.0;    //新老深度
        dp[i1]=-1.0;
        xlzjdeep[i1]=-1.0;   // 新老最佳深度
     }
     for(int j=1;j<=n;j++)
     {
     // if(((ljcw-1)<2))
      {
         // if(((ljcw-1)==0))       //第一个层       2022-11-03            if((str8[iop]=="JC")||(str8[iop]=="S31")||(str8[iop]=="S37")||(str8[iop]=="P21"))
          {

            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(p01<dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p01=dp2MN[j];
               }
            }
            else
            {
               if((s[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(p11>dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p11=dp2MN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(p02<sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p02=sytdMN[j];
               }
            }
            else
            {
               if((s[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(p22>sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p22=sytdMN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(p03<dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
               }
            }
            else
            {
               if((s[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(p33>dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p33=dp1MN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(p04<GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
               }
            }
            else
            {
               if((s[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(p44>GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p44=GMMN[j];
               }
            }
          }

      }
     }
        int ip1[10],ip2[10],ik=0;
         float f22[10];

         for(int j0=0;j0<10;j0++)
         {
            f22[j0]=1.0;
         }                               //此处添加   2022-11-1晚上
        if(xldeep[1]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[1]=deep2[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[1]))&&(fabs(deep2[j0]-deep2[j1])<0.4)&&(deep2[j0]>zzppsd[ljcw-1-in])&&(deep2[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[1]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(deep2[ip1[iy]],deep2[ip2[iy]],ljcw-1);
               xldeep[1]=hfsd;
           }
        }
        ik=0;

        if(xldeep[2]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[2]=sytdu[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[2]))&&(fabs(sytdu[j0]-sytdu[j1])<0.4)&&(sytdu[j0]>zzppsd[ljcw-1-in])&&(sytdu[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f2[0]-f2[2]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(sytdu[ip1[iy]],sytdu[ip2[iy]],ljcw-1);
               xldeep[2]=hfsd;
           }
        }
        ik=0;

        if(xldeep[3]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[3]=deep1[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[3]))&&(fabs(deep1[j0]-deep1[j1])<0.4)&&(deep1[j0]>zzppsd[ljcw-1-in])&&(deep1[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[3]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
                xjwdjzxz(deep1[ip1[iy]],deep1[ip2[iy]],ljcw-1);
                xldeep[3]=hfsd;
           }
        }
        ik=0;

        if(xldeep[4]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];

                  f22[4]=GMdeep2[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[4]))&&(fabs(GMdeep2[j0]-GMdeep2[j1])<0.4)&&(GMdeep2[j0]>zzppsd[ljcw-1-in])&&(GMdeep2[j1]>zzppsd[ljcw-1-in]))
                  {
                   //  float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[4]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(GMdeep2[ip1[iy]],GMdeep2[ip2[iy]],ljcw-1);
               xldeep[4]=hfsd;
           }
        }
    if((ljcw-1)>55)
    {
       PaintBox4->Canvas->TextOutA(230+1*100,0+(ljcw-57)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
       PaintBox4->Canvas->TextOutA(230+2*100,0+(ljcw-57)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
       PaintBox4->Canvas->TextOutA(230+3*100,0+(ljcw-57)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
       PaintBox4->Canvas->TextOutA(230+4*100,0+(ljcw-57)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
    else
    {
        PaintBox2->Canvas->TextOutA(230+1*100,0+(ljcw-1)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
        PaintBox2->Canvas->TextOutA(230+2*100,0+(ljcw-1)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
        PaintBox2->Canvas->TextOutA(230+3*100,0+(ljcw-1)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
        PaintBox2->Canvas->TextOutA(230+4*100,0+(ljcw-1)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
     dbnum=0;

     f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
     int bzcjs=0;      //标准层计数
     float pmin=9999.0;
     int correct=0;
 // if((ljcw-1)<=2)
  {
     for(int i1=1;i1<=3;i1++)
     {
         for(int i2=i1+1;i2<=4;i2++)
         {

            if((fabs(xldeep[i1]-xldeep[i2])<0.42)&&(dbnum<4)&&(xldeep[i1]>20.0))     // 此处可以选取微电极最低值
            {

             //     float hfsd;       //回返深度
             //     xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

              //    xlzjdeep[0]=hfsd;
                  bzcjs=bzcjs+1;
                  xlzjdeep[0]=xldeep[i1];
                  open_correct=1;
                  dbnum=dbnum+1;
            }
         }
     }
  }
                bzckdjs[ljcw-1]=bzcjs;        //标准层卡点计数
                zzppsd[ljcw-1]=xlzjdeep[0];   //最终匹配深度
                PaintBox4->Canvas->TextOutA(80,10+(ljcw-0)*12,"bzckdjs   "+AnsiString(bzckdjs[ljcw-1]));   //计算四种方法一致性，如果四种方法计算深度相同，则认为该深度准确
                if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC"))
                {
                   deepJC=xlzjdeep[0]; //PaintBox2->Canvas->TextOutA(80+0*120,0+(ljcw-0)*12,"deepJC:    "+AnsiString(FormatFloat("0.0",deepJC)));
                   JCxjd=int((deepJC-stdp1)/relv1);  //JC数据点
                   JCnum=ljcw-1;
                }

              if((ljcw-1)>55)
              {
                PaintBox4->Canvas->TextOutA(80+0*120,0+(ljcw-57)*12,str8[ljcw-1]);
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=             ");
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw-1])));
              }
              else
              {
                 PaintBox2->Canvas->TextOutA(80+0*120,0+(ljcw-1)*12,str8[ljcw-1]);
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=             ");
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw-1])));
              }

}
//-----------------------------------------------------------------------------------
void __fastcall TForm1::xsjs(TObject *Sender)      //向上计算
{
   ljcw=0; icount=0; n=6;  //老井层位数
   cwjd=16+40;   //层位节点
   int totalnum;  float start,end;
 //  izz=0;      //最终层个数
   ljsdc=0.0;  //老井深度差
   zxcjj=9999.0;    //最小层间距
   int ljcw0=0;
   float a2lj0[500];
     //--------------------------------------
     for(int lj0=0;lj0<2*JCnum;lj0++)
     {
        if(a2[lj0][0]>20.0)    //除掉0
        {
           str8[ljcw0]=str6[lj0];   //非空层号
           a2lj0[ljcw0]=a2[lj0][0];
           cjmk[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]+0.5;
           cjmk0[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]-0.6;
           if(cjmk0[ljcw0]<0.2)cjmk0[ljcw0]=0.2;
           ljcw0=ljcw0+1;
        }
     }
  for(int ii1=0;ii1<2*JCnum;ii1++)
  {
     if((zxcjj>fabs(a2lj0[ii1+1]-a2lj0[ii1]))&&(fabs(a2lj0[ii1+1]-a2lj0[ii1])>0.2))
     {
        zxcjj=fabs(a2lj0[ii1+1]-a2lj0[ii1]);     //最小层间距
     }
  }
 // zxcjj=zxcjj;    //最小层间距   2022-10-31以前
  ljcw=JCnum-1;
  for(lj=JCnum-1;lj>=0;lj--)    //2022-2-9早上修改  <  换成  <=
  {
   // if(a2[lj][0]>20.0)     //&&((fendp-zzppsd[ljcw-2])>3.0))    //除掉0
    {
      start=a2lj0[lj]-2.8;               //n7-4-sp2038   S11----941.5
      end=a2lj0[lj]+2.8;                  //n7-4-sp2038   S12---end=a2[0][0]+0.8;
      totalnum=int((end-start)/relv);
      open_correct=0;//校正开关
    //  PaintBox4->Canvas->TextOutA(80,10+14*(ljcw+1),"处理层位  ");

      a2lj[ljcw]=a2lj0[lj];
      ljcw=ljcw-1;         //老井层位
      for(int i0=0;i0<JCljd;i0++)
      {
            if(fabs(a[i0][0]-start)<0.005)
            {
                 ie1=0;  // PaintBox2->Canvas->TextOutA(80,10+14*(4+1),"JC  ");
                 for(int i=i0;i<i0+totalnum+1;i++)
                 {
                      //   fprintf(fp1,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a[i][0],a[i][MN_pos],a[i][Rd_pos],a[i][DEN_pos],a[i][HAC_pos],a[i][Rxo_pos],a[i][GR_pos]);
                        xcsj[ie1][0]=StrToFloat(FormatFloat("0.0",a[i][0]));            //2021年11月2日修改原来深度保留2位小数
                        bzcsj[ie1][0]=xcsj[ie1][0];
                        xcsj[ie1][1]=StrToFloat(FormatFloat("0.00",a[i][MN_pos]));
                        bzcsj[ie1][1]=xcsj[ie1][1];
                        xcsj[ie1][2]=StrToFloat(FormatFloat("0.00",a[i][Rd_pos]));
                        bzcsj[ie1][2]=xcsj[ie1][2];
                        xcsj[ie1][3]=StrToFloat(FormatFloat("0.00",a[i][DEN_pos]));
                        bzcsj[ie1][3]=xcsj[ie1][3];
                        xcsj[ie1][4]=StrToFloat(FormatFloat("0.00",a[i][HAC_pos]));
                        bzcsj[ie1][4]=xcsj[ie1][4];
                        xcsj[ie1][5]=StrToFloat(FormatFloat("0.00",a[i][Rxo_pos]));
                        bzcsj[ie1][5]=xcsj[ie1][5];
                        xcsj[ie1][6]=StrToFloat(FormatFloat("0.00",a[i][GR_pos]));
                        bzcsj[ie1][6]=xcsj[ie1][6];


                        ie1++;
                 }
            }
      }
   //  cjmkz(Sender);
     PaintBox2->Canvas->TextOutA(230,300+14*6,"正在处理第            个小层;");
     PaintBox2->Canvas->TextOutA(306,300+14*6,AnsiString(ljcw));
     PaintBox2->Canvas->TextOutA(400,300+14*6,"共计           个小层!");
     PaintBox2->Canvas->TextOutA(434,300+14*6,AnsiString(ljcw0));
     if(ljcw==0)
     {
       PaintBox2->Canvas->TextOutA(230,350+14*6,"第一个小层,请稍后");
     }
    // if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P15+61")||(str8[ljcw-1]=="P210")||(str8[ljcw-1]=="G11")||(str8[ljcw-1]=="G120")||(str8[ljcw-1]=="G23")||(str8[ljcw-1]=="G234"))
     {
           dtsjglmdwqd3(Sender);    //动态时间概率密度弯曲度正式算法
     }


    }

   }



  //////     paintfencengnew(Sender);



}
//--------------------------------------------------------------------------------------
void __fastcall TForm1::dtsjglmdwqd3(TObject *Sender)  //动态时间概率密度弯曲度正式算法
{
   float s0[30],s1[30],s3[30],s5[30],dfo[30],ds[30],df2[30],df3[30],ss1=0.0,ss2=0.0,ss3=0.0,ds1=0.0,ds2,ds3,dso=0.0,dist1[30],dist2[30];
   int b1=0,b2=0;//,b3=0,b4=0,b5=0,b6=0;
   float xgxs=0.8,p1[30],p2[30];
   n=6;   open_correct=0;open_correct2=0;
    for(int j=1;j<=n;j++)
    {
        s0[j]=0.0;p1[j]=100000000.0;p2[j]=0.01; bedeep[j][0]=0.0;bedeep[j][1]=0.0;
        for(int i1=0;i1<ie1-1;i1++)
        {
           s0[j]=s0[j]+xcsj[i1][j];
        }
           s0[j]=s0[j]/float(ie1-1);

    }

 //--------------------------------------
         for(int i0=5;i0<JCxjd-ie1;i0++)
         {
             for(int i=i0;i<i0+ie1;i++)
             {
                xssj[i-i0][0]=StrToFloat(FormatFloat("0.00",data1[i][0]));
                xssj[i-i0][1]=data1[i][MN1_pos];
                xssj[i-i0][2]=data1[i][Rd1_pos];
                xssj[i-i0][3]=data1[i][DEN1_pos];
                xssj[i-i0][4]=data1[i][HAC1_pos];
                xssj[i-i0][5]=data1[i][Rxo1_pos];
                xssj[i-i0][6]=data1[i][GR1_pos];
             }
             for(int j=1;j<=n;j++)
             {
                     //皮尔逊相似度
                     s1[j]=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                       s1[j]=s1[j]+xssj[i1][j];
                     }
                     s1[j]=s1[j]/float(ie1-1);
                     ss1=0.0;ss2=0.0;ss3=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                        ss1=ss1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                        ss2=ss2+pow((xcsj[i1][j]-s0[j]),2);
                        ss3=ss3+pow((xssj[i1][j]-s1[j]),2);
                     }
                     dist2[j]=(ss1/sqrt(ss2*ss3));       //皮尔逊相似度
                     if((i0<(stedp1-20))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {

                           if((p2[j]<dist2[j])&&(data1[i0+cwjd][0]>100.0))
                           {
                              p2[j]=dist2[j];
                              po2[j]=dist2[j];
                              deep2[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0])); //2021年11月2日修改原来深度保留2位小数
                              dp2MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                           }
                      }
                    //动态时间弯曲度
                    ds1=0.0;int ic;float sp=0.0,p;ds2=0.0;ds3=0.0,dso=0.0;
                    for(int i1=0;i1<ie1-1;i1++)
                    {
                       if(i1==0)
                       {
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                       else if(i1==1)
                       {
                         sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])      //是否可以使用dfo[i3]>dfo[i4]?
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if(i1==2)
                       {
                         sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                         for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if((i1>2)&&(i1<ie1-4))
                       {
                          sp=0.0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/7.0;
                          ic=0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-4))
                      {
                          sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                          for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-3))
                      {
                          sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                      }
                      else if(i1==(ie1-2))
                      {
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                     }
                      dist1[j]=(ds1/sqrt(ds2*ds3));       //皮尔逊相似度
                      if((i0<(stedp1-50))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {
                        if((p1[j]>dso)&&(data1[i0+cwjd*3][0]>100.0))
                        {
                            p1[j]=dso;
                            pdtsj1[j]=p1[j];
                            deep1[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0]));    //2021年11月2日修改原来深度保留2位小数
                            dp1MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                         }

                      }

             }

         }
//--------------------------------------------------------------------------------
   float bdp0[20],bdp1[20]; int ic0=0,ic=0;
    dtgmwqd3(Sender);   //动态概率密度弯曲度
    ljxjdb3(Sender); //老井新井对比





}
//---------------------------------------------------------------------------
void __fastcall TForm1::dtgmwqd3(TObject *Sender) //动态概率密度弯曲度
{
  float p,I[500][20],jz0[20],bcgm[20]; //均值、标准层概率密度
    int stdi=cwjd; n=6;
   for(int j=1;j<=n;j++)                   //取最大值、最小值
   {
       for(int i1=0;i1<ie1-2;i1++)
       {
           for(int i2=i1+1;i2<ie1-1;i2++)
           {
               if(bzcsj[i1][j]<bzcsj[i2][j])
               {
                   p=bzcsj[i1][j];
                   bzcsj[i1][j]=bzcsj[i2][j];
                   bzcsj[i2][j]=p;
               }
           }
       }
   }
   for(int j=1;j<=n;j++)
   {
       jz0[j]=0.0;
       bcgm[j]=0.0;
       bcgm[j+10]=0.0;
       for(int i1=0;i1<ie1-1;i1++)
       {                                          //归一化
          I[i1][j]=xcsj[i1][j]/bzcsj[0][j];
          jz0[j]=jz0[j]+I[i1][j];
       }
       jz0[j]=jz0[j]/float(ie1-1);
   }
   for(int j=1;j<=n;j++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float(iu)/float(stdi);                 //标准层各条曲线单独概率密度
        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float((ie1-1)-iu)/float(ie1-1-stdi);
        }
   }
 //----------------------------------------------------------------------------- //新井概率密度求取
   float sig[20],jz1[20],mdgm[20],mdgm1[30],dtgm[20]; float pp1[20],pp2[20],menkan[20];
   n=6;
   for(int j1=1;j1<=n;j1++)
   {
      pp1[j1]=99999.0;
      pp2[j1]=99999.0;
      menkan[j1]=99999.0;
   }
    pp1[11]=999999.0;
   for(int i=5;i<JCxjd-ie1;i++)
   {
           for(int j1=0;j1<=n;j1++)
           {
             for(int i1=0;i1<ie1-1;i1++)
             {
               xsj[i1][j1]=0.0;
               I1[i1][j1]=0.0;
              }
            }
          for(int i1=i;i1<i+ie1-1;i1++)
          {
            xsj[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]));
              xsj[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]));
                xsj[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]));
                  xsj[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]));
                    xsj[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]));
                      xsj[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]));
          }
      float p1;
      for(int j1=1;j1<=n;j1++)
      {
       //sig[j1]=0.0;//计算各条曲线测量值总和，再求平均值
        for(int i1=0;i1<ie1-2;i1++)
         {
          for(int i2=i1+1;i2<ie1-1;i2++)
           {
             if(xsj[i1][j1]<xsj[i2][j1])
             {
               p1=xsj[i1][j1];
               xsj[i1][j1]=xsj[i2][j1];
               xsj[i2][j1]=p1;
              }
            }
         }

     }
     //RMNmin1=Cmin1[1];
     for(int i1=i;i1<i+ie1-1;i1++)
     {
       I1[i1-i][0]=StrToFloat(FormatFloat("0.00",a1[i1][0]));
       I1[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][1]));   //微电位归一化
       I1[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][2])); //深侧向归一化
       I1[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][3])); //密度归一化
       I1[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][4])); //声波归一化
       I1[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][5])); //微球归一化
       I1[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][6])); //伽马归一化
     }
      for(int j=1;j<=n;j++)
     {
         float s1=0.0;
         for(int i1=1;i1<ie1-1;i1++)      //时域及时域梯度  运行结果完美
         {
           s1=s1+0.5*fabs(I[i1][j]-I1[i1][j])+0.5*fabs((I[i1][j]-I[i1-1][j])-(I1[i1][j]-I1[i1-1][j]));
         }
          if(s1<menkan[j])
          {
             menkan[j]=s1;
             menkan3[j]=menkan[j];
             sytdu[j]=I1[stdi][0];
             sytdMN[j]=xsj[stdi][1];
          }
     }
     for(int j1=1;j1<=n;j1++)
     {
         jz1[j1]=0.0; mdgm[j1]=0.0;mdgm[j1+10]=0.0;mdgm1[j1]=0.0;
         for(int i1=0;i1<ie1-1;i1++)
         {
           jz1[j1]=jz1[j1]+I1[i1][j1];
         }
         jz1[j1]=jz1[j1]/float(ie1-1);
     }
   for(int j1=1;j1<=n;j1++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
         //   mdgm[j1]=mdgm[j1]+(I1[iu][j1]-jz1[j1])*I1[iu][j1]/(jz1[j1]*float(ie1-1));            //float(iu)/float(stdi);                 //目的层各条曲线单独概率密度
            if(iu==0)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
            }
            else if(iu==1)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                            //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
              mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==2)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if((iu>2)&&(iu<=stdi))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));            //       float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }

        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            if((iu>=stdi)&&(iu<ie1-4))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));          //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-4)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));       // float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-3)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                    //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-2)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                        //float((ie1-1)-iu)/float(ie1-1-stdi);
            }
        }
   }
        float menkan[20];
           for(int j1=1;j1<=n;j1++)
          {
             menkan[j1]=99999.0;
             if((mdgm1[j1]<pp2[j1])&&((a1[i+20][MN1_pos]*a1[i+20][Rd1_pos]*a1[i+20][DEN1_pos]*a1[i+20][HAC1_pos]*a1[i+20][Rxo1_pos]*a1[i+20][GR1_pos])>1.0))
             {
                pp2[j1]=mdgm1[j1];
                poGM[j1]=pp2[j1];
                GMdeep2[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][0]));
                GMMN[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][MN1_pos]));
             }
          }

    }



}
//--------------------------------------------------------------------------------------------------------------------------------

void __fastcall TForm1::ljxjdb3(TObject *Sender) //老井新井对比
{
     float s[30],dp[30],s2[30],s3[30],s4[30],p01=0.0,p02=0.0,p03=0.0,p04=0.0,p11=9999.0,p22=9999.0,p33=9999.0,p44=9999.0; //新老深度
     int dbnum=0;  //对比数
    // sdeep1=0.0;
    // float dp1=0.0,dp2=0.0,dp3=0.0;
     n=6;
          int in=0,ic=0;
          if((zzppsd[ljcw+2]<20.0)&&(ljcw+1)<JCnum)
          {
             for(int ij=0;ij<5;ij++)
             {
                if((zzppsd[ljcw+2+ij]<20.0)&&(ic==0))
                {
                    in=in+1;
                }
                else if(zzppsd[ljcw+2+ij]>20.0)
                {
                   ic=1;
                }
             }
          }
        //  PaintBox4->Canvas->TextOutA(80,100+14*6,"in3-:   "+AnsiString(in));

          cjmk[ljcw+1]=a2lj[ljcw+1+in]-a2lj[ljcw+1]+0.7;
          cjmk0[ljcw+1]=a2lj[ljcw+1+in]-a2lj[ljcw+1]-0.6;
     for(int i1=-1;i1<29;i1++)
     {
        s[i1]=9999.0;
        s2[i1]=9999.0;
        s3[i1]=9999.0;
        s4[i1]=9999.0;
        xldeep[i1]=-1.0;    //新老深度
        dp[i1]=-1.0;
        xlzjdeep[i1]=-1.0;   // 新老最佳深度
     }
     for(int j=1;j<=n;j++)
     {
     // if(((ljcw-1)<2))
      {
         // if(((ljcw-1)==0))       //第一个层       2022-11-03            if((str8[iop]=="JC")||(str8[iop]=="S31")||(str8[iop]=="S37")||(str8[iop]=="P21"))
          {

            if((str8[ljcw+1]=="JC")||(str8[ljcw+1]=="JCJC")||(str8[ljcw+1]=="S31")||(str8[ljcw+1]=="S37")||(str8[ljcw+1]=="P21"))
            {
               if((s[1]>fabs(a2lj[ljcw+1]-deep2[j]))&&(deep2[j]<zzppsd[ljcw+1+in])&&(p01<dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw+1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p01=dp2MN[j];
               }
            }
            else
            {
               if((s[1]>fabs(a2lj[ljcw+1]-deep2[j]))&&(deep2[j]<=zzppsd[ljcw+2+in])&&(fabs(zzppsd[ljcw+2+in]-deep2[j])<(fabs(a2lj[ljcw+2+in]-a2lj[ljcw+1])+1.0))&&(p11>dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw+1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p11=dp2MN[j];
               }
            }
            if((str8[ljcw+1]=="JC")||(str8[ljcw+1]=="JCJC")||(str8[ljcw+1]=="S31")||(str8[ljcw+1]=="S37")||(str8[ljcw+1]=="P21"))
            {
               if((s[2]>fabs(a2lj[ljcw+1]-sytdu[j]))&&(sytdu[j]<zzppsd[ljcw+1+in])&&(p02<sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw+1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p02=sytdMN[j];
               }
            }
            else
            {
               if((s[2]>fabs(a2lj[ljcw+1]-sytdu[j]))&&(sytdu[j]<=zzppsd[ljcw+2+in])&&(fabs(zzppsd[ljcw+2+in]-sytdu[j])<(fabs(a2lj[ljcw+2+in]-a2lj[ljcw+1])+1.0))&&(p22>sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw+1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p22=sytdMN[j];
               }
            }
            if((str8[ljcw+1]=="JC")||(str8[ljcw+1]=="JCJC")||(str8[ljcw+1]=="S31")||(str8[ljcw+1]=="S37")||(str8[ljcw+1]=="P21"))
            {
               if((s[3]>fabs(a2lj[ljcw+1]-deep1[j]))&&(deep1[j]<zzppsd[ljcw+1+in])&&(p03<dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw+1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
               }
            }
            else
            {
               if((s[3]>fabs(a2lj[ljcw+1]-deep1[j]))&&(deep1[j]<=zzppsd[ljcw+2+in])&&(fabs(zzppsd[ljcw+2+in]-deep1[j])<(fabs(a2lj[ljcw+2+in]-a2lj[ljcw+1])+1.0))&&(p33>dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw+1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p33=dp1MN[j];
               }
            }
            if((str8[ljcw+1]=="JC")||(str8[ljcw+1]=="JCJC")||(str8[ljcw+1]=="S31")||(str8[ljcw+1]=="S37")||(str8[ljcw+1]=="P21"))
            {
               if((s[4]>fabs(a2lj[ljcw+1]-GMdeep2[j]))&&(GMdeep2[j]<zzppsd[ljcw+1+in])&&(p04<GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw+1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
               }
            }
            else
            {
               if((s[4]>fabs(a2lj[ljcw+1]-GMdeep2[j]))&&(GMdeep2[j]<=zzppsd[ljcw+2+in])&&(fabs(zzppsd[ljcw+2+in]-GMdeep2[j])<(fabs(a2lj[ljcw+2+in]-a2lj[ljcw+1])+1.0))&&(p44>GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw+1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p44=GMMN[j];
               }
            }
          }
               }
     }
        int ip1[10],ip2[10],ik=0;
         float f22[10];

         for(int j0=0;j0<10;j0++)
         {
            f22[j0]=1.0;
         }                               //此处添加   2022-11-1晚上
        if(xldeep[1]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=fabs(a2lj[ljcw+1]-a2lj[ljcw+1+in]);
                  f22[1]=fabs(deep2[j1]-zzppsd[ljcw+1+in]);
                  if((ppo>fabs(f22[0]-f22[1]))&&(fabs(deep2[j0]-deep2[j1])<0.4)&&(deep2[j0]<zzppsd[ljcw+1+in])&&(deep2[j1]<zzppsd[ljcw+1+in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[1]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(deep2[ip1[iy]],deep2[ip2[iy]],ljcw+1);
               xldeep[1]=hfsd;
           }
        }
        ik=0;

        if(xldeep[2]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=fabs(a2lj[ljcw+1]-a2lj[ljcw+1+in]);
                  f22[2]=fabs(sytdu[j1]-zzppsd[ljcw+1+in]);
                  if((ppo>fabs(f22[0]-f22[2]))&&(fabs(sytdu[j0]-sytdu[j1])<0.4)&&(sytdu[j0]<zzppsd[ljcw+1+in])&&(sytdu[j1]<zzppsd[ljcw+1+in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f2[0]-f2[2]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(sytdu[ip1[iy]],sytdu[ip2[iy]],ljcw+1);
               xldeep[2]=hfsd;
           }
        }
        ik=0;

        if(xldeep[3]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=fabs(a2lj[ljcw+1]-a2lj[ljcw+1+in]);
                  f22[3]=fabs(deep1[j1]-zzppsd[ljcw+1+in]);
                  if((ppo>fabs(f22[0]-f22[3]))&&(fabs(deep1[j0]-deep1[j1])<0.4)&&(deep1[j0]<zzppsd[ljcw+1+in])&&(deep1[j1]<zzppsd[ljcw+1+in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[3]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
                xjwdjzxz(deep1[ip1[iy]],deep1[ip2[iy]],ljcw+1);
                xldeep[3]=hfsd;
           }
        }
        ik=0;

        if(xldeep[4]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=fabs(a2lj[ljcw+1]-a2lj[ljcw+1+in]);

                  f22[4]=fabs(GMdeep2[j1]-zzppsd[ljcw+1+in]);
                  if((ppo>fabs(f22[0]-f22[4]))&&(fabs(GMdeep2[j0]-GMdeep2[j1])<0.4)&&(GMdeep2[j0]<zzppsd[ljcw+1+in])&&(GMdeep2[j1]<zzppsd[ljcw+1+in]))
                  {
                   //  float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[4]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(GMdeep2[ip1[iy]],GMdeep2[ip2[iy]],ljcw+1);
               xldeep[4]=hfsd;
           }
        }
    if((ljcw-1)>55)
    {
       PaintBox4->Canvas->TextOutA(230+1*100,0+(ljcw-57)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
       PaintBox4->Canvas->TextOutA(230+2*100,0+(ljcw-57)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
       PaintBox4->Canvas->TextOutA(230+3*100,0+(ljcw-57)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
       PaintBox4->Canvas->TextOutA(230+4*100,0+(ljcw-57)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
    else
    {
        PaintBox2->Canvas->TextOutA(230+1*100,0+(ljcw+1)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
        PaintBox2->Canvas->TextOutA(230+2*100,0+(ljcw+1)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
        PaintBox2->Canvas->TextOutA(230+3*100,0+(ljcw+1)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
        PaintBox2->Canvas->TextOutA(230+4*100,0+(ljcw+1)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
     dbnum=0;

     f22[0]=fabs(a2lj[ljcw+1]-a2lj[ljcw+1+in]);

    // float pmin=9999.0;
   //  int correct=0;
 // if((ljcw-1)<=2)
  {
     for(int i1=1;i1<=3;i1++)
     {
         for(int i2=i1+1;i2<=4;i2++)
         {

            if((fabs(xldeep[i1]-xldeep[i2])<0.42)&&(dbnum<4)&&(xldeep[i1]>20.0))     // 此处可以选取微电极最低值
            {

             //     float hfsd;       //回返深度
             //     xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

              //    xlzjdeep[0]=hfsd;
                  xlzjdeep[0]=xldeep[i1];
                  open_correct=1;
                  dbnum=dbnum+1;
            }
         }
     }
  }
                zzppsd[ljcw+1]=xlzjdeep[0];   //最终匹配深度

              if((ljcw-1)>55)
              {
                PaintBox4->Canvas->TextOutA(80+0*120,0+(ljcw-57)*12,str8[ljcw+1]);
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=             ");
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw+1])));
              }
              else
              {
                 PaintBox2->Canvas->TextOutA(80+0*120,0+(ljcw+1)*12,str8[ljcw+1]);
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw+1)*12,"新老井最佳匹配深度=             ");
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw+1)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw+1])));
              }

}
//-----------------------------------------------------------------------------------
void __fastcall TForm1::xxjs(TObject *Sender)                   //动态时间概率密度弯曲度正式算法     向下计算
{
   ljcw=0; icount=0; n=6;  //老井层位数
   cwjd=16+40;   //层位节点
   int totalnum;  float start,end;
 //  izz=0;      //最终层个数
   ljsdc=0.0;  //老井深度差
   zxcjj=9999.0;    //最小层间距
   int ljcw0=0;
   float a2lj0[500];
  // float bzcsj[500][20];//标准层数据
   //--------------------------------------
   for(int lj0=0;lj0<ljcgs-1;lj0++)
  {
    if(a2[lj0][0]>20.0)    //除掉0
    {
       str8[ljcw0]=str6[lj0];   //非空层号
       a2lj0[ljcw0]=a2[lj0][0];
       cjmk[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]+0.5;
       cjmk0[ljcw0]=a2lj0[ljcw0]-a2lj0[ljcw0-1]-0.6;
       if(cjmk0[ljcw0]<0.2)cjmk0[ljcw0]=0.2;
       ljcw0=ljcw0+1;
    }
  //  cjmk[lj]=1.0+8.0*(1-1.0/float(xzkg));       //2022-10-31修改        严重错误  lj  至少应该改成lj0
   // cjmk0[lj]=1.0-2.0*(1-1.0/float(xzkg));

  }
  for(int ii1=0;ii1<ljcw0-1;ii1++)
  {
     if((zxcjj>fabs(a2lj0[ii1+1]-a2lj0[ii1]))&&(fabs(a2lj0[ii1+1]-a2lj0[ii1])>0.2))
     {
        zxcjj=fabs(a2lj0[ii1+1]-a2lj0[ii1]);
     }
  }
  zxcjj=zxcjj;    //最小层间距   2022-10-31以前
  ljcw=JCnum+1;
  for(lj=JCnum+1;lj<ljcw0-1;lj++)    //2022-2-9早上修改  <  换成  <=
  {
  //  if((a2[lj][0]>20.0)&&((fendp-zzppsd[ljcw-2])>3.0))    //除掉0
    {
      start=a2lj0[lj]-2.8;               //n7-4-sp2038   S11----941.5
      end=a2lj0[lj]+2.8;                  //n7-4-sp2038   S12---end=a2[0][0]+0.8;
      totalnum=int((end-start)/0.05);
      open_correct=0;//校正开关
    //  PaintBox2->Canvas->TextOutA(80,10+14*(ljcw+1),"处理层位  ");

      a2lj[ljcw]=a2lj0[lj];
      ljcw=ljcw+1;         //老井层位
      for(int i0=JCljd;i0<stedp;i0++)
      {
            if(fabs(a[i0][0]-start)<0.005)
            {
                 ie1=0;
                 for(int i=i0;i<i0+totalnum+1;i++)
                 {
                      //   fprintf(fp1,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a[i][0],a[i][MN_pos],a[i][Rd_pos],a[i][DEN_pos],a[i][HAC_pos],a[i][Rxo_pos],a[i][GR_pos]);
                        xcsj[ie1][0]=StrToFloat(FormatFloat("0.0",a[i][0]));            //2021年11月2日修改原来深度保留2位小数
                        bzcsj[ie1][0]=xcsj[ie1][0];
                        xcsj[ie1][1]=StrToFloat(FormatFloat("0.00",a[i][MN_pos]));
                        bzcsj[ie1][1]=xcsj[ie1][1];
                        xcsj[ie1][2]=StrToFloat(FormatFloat("0.00",a[i][Rd_pos]));
                        bzcsj[ie1][2]=xcsj[ie1][2];
                        xcsj[ie1][3]=StrToFloat(FormatFloat("0.00",a[i][DEN_pos]));
                        bzcsj[ie1][3]=xcsj[ie1][3];
                        xcsj[ie1][4]=StrToFloat(FormatFloat("0.00",a[i][HAC_pos]));
                        bzcsj[ie1][4]=xcsj[ie1][4];
                        xcsj[ie1][5]=StrToFloat(FormatFloat("0.00",a[i][Rxo_pos]));
                        bzcsj[ie1][5]=xcsj[ie1][5];
                        xcsj[ie1][6]=StrToFloat(FormatFloat("0.00",a[i][GR_pos]));
                        bzcsj[ie1][6]=xcsj[ie1][6];


                        ie1++;
                 }
            }
      }
   //  cjmkz(Sender);
     PaintBox2->Canvas->TextOutA(230,300+14*6,"正在处理第            个小层;");
     PaintBox2->Canvas->TextOutA(306,300+14*6,AnsiString(ljcw));
     PaintBox2->Canvas->TextOutA(400,300+14*6,"共计           个小层!");
     PaintBox2->Canvas->TextOutA(434,300+14*6,AnsiString(ljcw0));
     if((ljcw-1)==(ljcw0-1))
     {
       PaintBox2->Canvas->TextOutA(230,350+14*6,"正在处理最后一个小层,请稍后");
     }
     dtsjglmdwqd4(Sender);    //动态时间概率密度弯曲度正式算法

     zzbdp=0.0;
     int in=1,ic=0;
       if((zzppsd[ljcw-1-1]<20.0)&&(ljcw-1)>2)
       {
          for(int ij=1;ij<10;ij++)
          {
             if((zzppsd[ljcw-1-ij]<20.0)&&(ic==0))
             {
                 in=in+1;
             }
             else if(zzppsd[ljcw-1-ij]>20.0)
             {
                ic=1;
             }
          }
       }
          cjmk[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]+0.7;
          cjmk0[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]-0.6;
                if((zzppsd[ljcw-1]>10.0)&&(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1])&&(zzppsd[ljcw-1]>(zzppsd[ljcw-1-in]+zxcjj-0.5))&&((ljcw-1)>1))
                {
                   open_correct=1;
                }
                if(((zzppsd[ljcw-1]<10.0)||(zzppsd[ljcw-1]<zzppsd[ljcw-1-in])||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<zxcjj)||((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<cjmk0[ljcw-1])||((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>cjmk[ljcw-1]))&&(open_correct<3)&&((ljcw-1)>1)) //||(sdeep>0.4)   //&&(open_correct<2)
                {
                   open_correct=0;                 //izz   ->ljcw-1
                }
                if(((zzppsd[ljcw-1]<10.0)||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<zxcjj)||(zzppsd[ljcw-1]<zzppsd[ljcw-1-in])||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<cjmk0[ljcw-1])||(fabs(zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>cjmk[ljcw-1]))&&((ljcw-1)>1)&&(open_correct2<3)&&(open_correct==0))   //||(closefs[ljcw-1]==0)
                {
                   isname=ljcw-1;
                   yxz(Sender);
                }
                if((zzppsd[ljcw-1]<10.0)&&((ljcw-1)<2)&&(open_correct==0))
                {
                   isname=ljcw-1;
                   yxz(Sender);
                }
               if(zzppsd[ljcw-1]<20.0)
                {
                  if((ljcw-1)>55)
                  {
                     PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=             ");
                     PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=    此处层位可能断失 ");
                  }
                  else
                  {
                     PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=             ");
                     PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=    此处层位可能断失 ");
                  }
                }

               //if(zzppsd[ljcw-1]<20.0)zzppsd[ljcw-1]=0.0;
             /*  if(jgdb)
               {
                    fprintf(jgdb,"%s    %8.1f  %8.1f\n",str8[ljcw-1],xjcw9[ljcw-1],zzppsd[ljcw-1]);
               }  */

    }

   }

                            //整体检查yxz出错层及ljcw-1后置层

       PaintBox2->Canvas->TextOutA(230,350+14*6,"全部处理完成               请核查");
    //   ShowMessage("处理完毕！请核验保存！");
      // fclose(fd);fclose(fgm);fclose(fds);fclose(fsytd); fclose(jgdb);
   //    paintfencengnew(Sender);
}
//----------------------------------------------------------------------------
void __fastcall TForm1::dtsjglmdwqd4(TObject *Sender)  //动态时间概率密度弯曲度正式算法
{
   float s0[30],s1[30],s3[30],s5[30],dfo[30],ds[30],df2[30],df3[30],ss1=0.0,ss2=0.0,ss3=0.0,ds1=0.0,ds2,ds3,dso=0.0,dist1[30],dist2[30];
  // int b1=0,b2=0,b3=0,b4=0;    //,b5=0,b6=0
   float p1[30],p2[30];        //xgxs=0.8,
   n=6;   open_correct=0;open_correct2=0;
    for(int j=1;j<=n;j++)
    {
      s0[j]=0.0;p1[j]=100000000.0;p2[j]=0.01; bedeep[j][0]=0.0;bedeep[j][1]=0.0;
      for(int i1=0;i1<ie1-1;i1++)
      {
       s0[j]=s0[j]+xcsj[i1][j];
      }
      s0[j]=s0[j]/float(ie1-1);

    }

 //--------------------------------------
         for(int i0=JCxjd;i0<stedp1-ie1-20;i0++)
         {
             for(int i=i0;i<i0+ie1+20;i++)
             {
                xssj[i-i0][0]=StrToFloat(FormatFloat("0.00",data1[i][0]));
                xssj[i-i0][1]=data1[i][MN1_pos];
                xssj[i-i0][2]=data1[i][Rd1_pos];
                xssj[i-i0][3]=data1[i][DEN1_pos];
                xssj[i-i0][4]=data1[i][HAC1_pos];
                xssj[i-i0][5]=data1[i][Rxo1_pos];
                xssj[i-i0][6]=data1[i][GR1_pos];
             }
             for(int j=1;j<=n;j++)
             {
                     //皮尔逊相似度
                     s1[j]=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                       s1[j]=s1[j]+xssj[i1][j];
                     }
                     s1[j]=s1[j]/float(ie1-1);
                     ss1=0.0;ss2=0.0;ss3=0.0;
                     for(int i1=0;i1<ie1-1;i1++)
                     {
                        ss1=ss1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                        ss2=ss2+pow((xcsj[i1][j]-s0[j]),2);
                        ss3=ss3+pow((xssj[i1][j]-s1[j]),2);
                     }
                     dist2[j]=(ss1/sqrt(ss2*ss3));       //皮尔逊相似度
                     if((i0<(stedp1-20))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {

                           if((p2[j]<dist2[j])&&(data1[i0+cwjd][0]>100.0))
                           {
                              p2[j]=dist2[j];
                              po2[j]=dist2[j];
                              deep2[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0])); //2021年11月2日修改原来深度保留2位小数
                              dp2MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                           }
                      }
                    //动态时间弯曲度
                    ds1=0.0;int ic;float sp=0.0,p;ds2=0.0;ds3=0.0,dso=0.0;
                    for(int i1=0;i1<ie1-1;i1++)
                    {
                       if(i1==0)
                       {
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                       else if(i1==1)
                       {
                         sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])      //是否可以使用dfo[i3]>dfo[i4]?
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if(i1==2)
                       {
                         sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                          for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                       }
                       else if((i1>2)&&(i1<ie1-4))
                       {
                          sp=0.0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/7.0;
                          ic=0;
                          for(int i2=i1-3;i2<=i1+3;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-4))
                      {
                          sp=0.0;
                         for(int i2=i1-2;i2<i1+3;i2++)
                          {
                            sp=sp+xssj[i2][j];
                          }
                          sp=sp/5.0;
                          ic=0;
                          for(int i2=i1-2;i2<=i1+2;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];
                         dso=dso+dfo[0];

                      }
                      else if(i1==(ie1-3))
                      {
                          sp=0.0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           sp=sp+xssj[i2][j];
                         }
                         sp=sp/3.0;
                         ic=0;
                         for(int i2=i1-1;i2<=i1+1;i2++)
                         {
                           dfo[ic]=(xcsj[i1][j]-xssj[i2][j])*(xcsj[i1][j]-xssj[i2][j]);
                           ds[ic]=(xcsj[i1][j]-s0[j])*(xssj[i2][j]-sp);
                           df2[ic]=(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                           df3[ic]=(xssj[i1][j]-sp)*(xssj[i1][j]-sp);

                           ic=ic+1;
                         }
                         for(int i3=0;i3<ic-2;i3++)
                         {
                            for(int i4=i3+1;i4<ic-1;i4++)
                            {
                              if(dfo[i3]>dfo[i4])
                              {
                                p=ds[i3];
                                ds[i3]=ds[i4];
                                ds[i4]=p;
                                p=df2[i3];
                                df2[i3]=df2[i4];
                                df2[i4]=p;
                                p=df3[i3];
                                df3[i3]=df3[i4];
                                df3[i4]=p;
                                p=dfo[i3];
                                dfo[i3]=dfo[i4];
                                dfo[i4]=p;
                              }

                            }
                         }
                         dso=dso+dfo[0];
                         ds1=ds1+ds[0];
                         ds2=ds2+df2[0];
                         ds3=ds3+df3[0];

                      }
                      else if(i1==(ie1-2))
                      {
                         dso=dso+(xcsj[i1][j]-xssj[i1][j])*(xcsj[i1][j]-xssj[i1][j]);
                         ds1=ds1+(xcsj[i1][j]-s0[j])*(xssj[i1][j]-s1[j]);
                         ds2=ds2+(xcsj[i1][j]-s0[j])*(xcsj[i1][j]-s0[j]);
                         ds3=ds3+(xssj[i1][j]-s1[j])*(xssj[i1][j]-s1[j]);

                       }
                     }
                      dist1[j]=(ds1/sqrt(ds2*ds3));       //皮尔逊相似度
                      if((i0<(stedp1-50))&&(data1[i0+ie1+20][MN1_pos]*data1[i0+ie1+20][Rd1_pos]*data1[i0+ie1+20][DEN1_pos]*data1[i0+ie1+20][HAC1_pos]*data1[i0+ie1+20][Rxo1_pos]*data1[i0+ie1+20][GR1_pos]>1.0))
                      {
                        if((p1[j]>dso)&&(data1[i0+cwjd*3][0]>100.0))
                        {
                            p1[j]=dso;
                            pdtsj1[j]=p1[j];
                            deep1[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][0]));    //2021年11月2日修改原来深度保留2位小数
                            dp1MN[j]=StrToFloat(FormatFloat("0.0",data1[i0+cwjd][MN1_pos]));
                         }

                      }

             }

         }
//--------------------------------------------------------------------------------
 //  float bdp0[20],bdp1[20]; int ic0=0,ic=0;
    dtgmwqd4(Sender);   //动态概率密度弯曲度
    ljxjdb4(Sender); //老井新井对比





}
//---------------------------------------------------------------------------
void __fastcall TForm1::dtgmwqd4(TObject *Sender) //动态概率密度弯曲度
{
  float p,I[500][20],jz0[20],bcgm[20]; //均值、标准层概率密度
    int stdi=cwjd; n=6;
   for(int j=1;j<=n;j++)                   //取最大值、最小值
   {
       for(int i1=0;i1<ie1-2;i1++)
       {
           for(int i2=i1+1;i2<ie1-1;i2++)
           {
               if(bzcsj[i1][j]<bzcsj[i2][j])
               {
                   p=bzcsj[i1][j];
                   bzcsj[i1][j]=bzcsj[i2][j];
                   bzcsj[i2][j]=p;
               }
           }
       }
   }
   for(int j=1;j<=n;j++)
   {
       jz0[j]=0.0;
       bcgm[j]=0.0;
       bcgm[j+10]=0.0;
       for(int i1=0;i1<ie1-1;i1++)
       {                                          //归一化
          I[i1][j]=xcsj[i1][j]/bzcsj[0][j];
          jz0[j]=jz0[j]+I[i1][j];
       }
       jz0[j]=jz0[j]/float(ie1-1);
   }
   for(int j=1;j<=n;j++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float(iu)/float(stdi);                 //标准层各条曲线单独概率密度
        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            bcgm[j]=bcgm[j]+(I[iu][j]-jz0[j])*I[iu][j]/(jz0[j]*float(ie1-1));                //float((ie1-1)-iu)/float(ie1-1-stdi);
        }
   }
 //----------------------------------------------------------------------------- //新井概率密度求取
   float sig[20],jz1[20],mdgm[20],mdgm1[30],dtgm[20]; float pp1[20],pp2[20],menkan[20];
   n=6;
   for(int j1=1;j1<=n;j1++)
   {
      pp1[j1]=99999.0;
      pp2[j1]=99999.0;
      menkan[j1]=99999.0;
   }
    pp1[11]=999999.0;
   for(int i=JCxjd;i<stedp1-ie1-20;i++)
   {
           for(int j1=0;j1<=n;j1++)
           {
             for(int i1=0;i1<ie1-1;i1++)
             {
               xsj[i1][j1]=0.0;
               I1[i1][j1]=0.0;
              }
            }
          for(int i1=i;i1<i+ie1-1;i1++)
          {
            xsj[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]));
              xsj[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]));
                xsj[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]));
                  xsj[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]));
                    xsj[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]));
                      xsj[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]));
          }
      float p1;
      for(int j1=1;j1<=n;j1++)
      {
       //sig[j1]=0.0;//计算各条曲线测量值总和，再求平均值
        for(int i1=0;i1<ie1-2;i1++)
         {
          for(int i2=i1+1;i2<ie1-1;i2++)
           {
             if(xsj[i1][j1]<xsj[i2][j1])
             {
               p1=xsj[i1][j1];
               xsj[i1][j1]=xsj[i2][j1];
               xsj[i2][j1]=p1;
              }
            }
         }

     }
     //RMNmin1=Cmin1[1];
     for(int i1=i;i1<i+ie1-1;i1++)
     {
       I1[i1-i][0]=StrToFloat(FormatFloat("0.00",a1[i1][0]));
       I1[i1-i][1]=StrToFloat(FormatFloat("0.00",a1[i1][MN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][1]));   //微电位归一化
       I1[i1-i][2]=StrToFloat(FormatFloat("0.00",a1[i1][Rd1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][2])); //深侧向归一化
       I1[i1-i][3]=StrToFloat(FormatFloat("0.00",a1[i1][DEN1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][3])); //密度归一化
       I1[i1-i][4]=StrToFloat(FormatFloat("0.00",a1[i1][HAC1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][4])); //声波归一化
       I1[i1-i][5]=StrToFloat(FormatFloat("0.00",a1[i1][Rxo1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][5])); //微球归一化
       I1[i1-i][6]=StrToFloat(FormatFloat("0.00",a1[i1][GR1_pos]))/StrToFloat(FormatFloat("0.00",xsj[0][6])); //伽马归一化
     }
      for(int j=1;j<=n;j++)
     {
         float s1=0.0;
         for(int i1=1;i1<ie1-1;i1++)      //时域及时域梯度  运行结果完美
         {
           s1=s1+0.5*fabs(I[i1][j]-I1[i1][j])+0.5*fabs((I[i1][j]-I[i1-1][j])-(I1[i1][j]-I1[i1-1][j]));
         }
          if(s1<menkan[j])
          {
             menkan[j]=s1;
             menkan3[j]=menkan[j];
             sytdu[j]=I1[stdi][0];
             sytdMN[j]=xsj[stdi][1];
          }
     }
     for(int j1=1;j1<=n;j1++)
     {
         jz1[j1]=0.0; mdgm[j1]=0.0;mdgm[j1+10]=0.0;mdgm1[j1]=0.0;
         for(int i1=0;i1<ie1-1;i1++)
         {
           jz1[j1]=jz1[j1]+I1[i1][j1];
         }
         jz1[j1]=jz1[j1]/float(ie1-1);
     }
   for(int j1=1;j1<=n;j1++)
   {
        for(int iu=0;iu<=stdi;iu++)
        {
         //   mdgm[j1]=mdgm[j1]+(I1[iu][j1]-jz1[j1])*I1[iu][j1]/(jz1[j1]*float(ie1-1));            //float(iu)/float(stdi);                 //目的层各条曲线单独概率密度
            if(iu==0)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
            }
            else if(iu==1)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                            //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
              mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==2)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                 //float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if((iu>2)&&(iu<=stdi))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));            //       float(iu)/float(stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }

        }
        for(int iu=stdi+1;iu<ie1-1;iu++)
        {
            if((iu>=stdi)&&(iu<ie1-4))
            {
               int ic=0;
              for(int iu1=iu-3;iu1<=iu+3;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));          //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-4)
            {
              int ic=0;
              for(int iu1=iu-2;iu1<=iu+2;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));       // float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-3)
            {
              int ic=0;
              for(int iu1=iu-1;iu1<=iu+1;iu1++)
              {
                 dtgm[ic]=fabs((I1[iu1][j1]-jz1[j1])-(I[iu1][j1]-jz0[j1]))*I1[iu1][j1]/(jz1[j1]*float(ie1-1));                    //float((ie1-1)-iu)/float(ie1-1-stdi);
                 ic=ic+1;
              }
              float p;
              for(int iu2=0;iu2<ic-2;iu2++)
              {
                 for(int iu3=iu2+1;iu3<ic-1;iu3++)
                 {
                    if(dtgm[iu2]>dtgm[iu3])
                    {
                       p=dtgm[iu2];
                       dtgm[iu2]=dtgm[iu3];
                       dtgm[iu3]=p;
                    }
                 }
              }
             mdgm1[j1]=mdgm1[j1]+dtgm[0];
            }
            else if(iu==ie1-2)
            {
               mdgm1[j1]=mdgm1[j1]+fabs((I1[iu][j1]-jz1[j1])-(I[iu][j1]-jz0[j1]))*I1[iu][j1]/(jz1[j1]*float(ie1-1));                        //float((ie1-1)-iu)/float(ie1-1-stdi);
            }
        }
   }
        float menkan[20];
           for(int j1=1;j1<=n;j1++)
          {
             menkan[j1]=99999.0;
             if((mdgm1[j1]<pp2[j1])&&((a1[i+20][MN1_pos]*a1[i+20][Rd1_pos]*a1[i+20][DEN1_pos]*a1[i+20][HAC1_pos]*a1[i+20][Rxo1_pos]*a1[i+20][GR1_pos])>1.0))
             {
                pp2[j1]=mdgm1[j1];
                poGM[j1]=pp2[j1];
                GMdeep2[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][0]));
                GMMN[j1]=StrToFloat(FormatFloat("0.00",a1[i+stdi][MN1_pos]));
             }
          }

    }



}
//--------------------------------------------------------------------------------------------------------------------------------

void __fastcall TForm1::ljxjdb4(TObject *Sender) //老井新井对比
{
     float s[30],dp[30],s2[30],s3[30],s4[30],p01=0.0,p02=0.0,p03=0.0,p04=0.0,p11=9999.0,p22=9999.0,p33=9999.0,p44=9999.0; //新老深度
     int dbnum=0;  //对比数
    // sdeep1=0.0;
   //  float dp1=0.0,dp2=0.0,dp3=0.0;
     n=6;
          int in=1,ic=0;
          if((zzppsd[ljcw-1-1]<20.0)&&(ljcw-1)>2)
          {
             for(int ij=1;ij<20;ij++)
             {
                if((zzppsd[ljcw-1-ij]<20.0)&&(ic==0))
                {
                    in=in+1;
                }
                else if(zzppsd[ljcw-1-ij]>20.0)
                {
                   ic=1;
                }
             }
          }


          cjmk[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]+0.7;
          cjmk0[ljcw-1]=a2lj[ljcw-1]-a2lj[ljcw-1-in]-0.6;
     for(int i1=-1;i1<29;i1++)
     {
        s[i1]=9999.0;
        s2[i1]=9999.0;
        s3[i1]=9999.0;
        s4[i1]=9999.0;
        xldeep[i1]=-1.0;    //新老深度
        dp[i1]=-1.0;
        xlzjdeep[i1]=-1.0;   // 新老最佳深度
     }
     for(int j=1;j<=n;j++)
     {
      if(((ljcw-1)<2))
      {
          if(((ljcw-1)==0))       //第一个层       2022-11-03            if((str8[iop]=="JC")||(str8[iop]=="S31")||(str8[iop]=="S37")||(str8[iop]=="P21"))
          {

            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(p01<dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p01=dp2MN[j];
               }
            }
            else
            {
               if((s[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(p11>dp2MN[j]))
               {
                 s[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                 xldeep[1]=deep2[j];
                 p11=dp2MN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(p02<sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p02=sytdMN[j];
               }
            }
            else
            {
               if((s[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(p22>sytdMN[j]))
               {
                 s[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                 xldeep[2]=sytdu[j];
                 p22=sytdMN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(p03<dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
               }
            }
            else
            {
               if((s[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(p33>dp1MN[j]))
               {
                 s[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                 xldeep[3]=deep1[j];
                 p33=dp1MN[j];
               }
            }
            if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
            {
               if((s[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(p04<GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
               }
            }
            else
            {
               if((s[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(p44>GMMN[j]))
               {
                 s[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                 xldeep[4]=GMdeep2[j];
                 p44=GMMN[j];
               }
            }
          }

          if((ljcw-1)==1)                                            //第二个层
          {
              ljsdc=0.0;p01=0.0;p02=0.0;p03=0.0;p04=0.0;p11=9999.0;p22=9999.0;p33=9999.0;p44=9999.0;
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
              {
                 if((p01<dp1MN[j])&&(s2[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                 {
                    s2[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                    xldeep[1]=deep2[j];
                    p01=dp2MN[j];
                 }
              }
              else
              {
                 if((p11>dp1MN[j])&&(s2[1]>fabs(a2lj[ljcw-1]-deep2[j]))&&(deep2[j]>zzppsd[ljcw-1-in])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                 {
                    s2[1]=fabs(a2lj[ljcw-1]-deep2[j]);
                    xldeep[1]=deep2[j];
                    p11=dp2MN[j];
                 }
              }
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
              {
                  if((p02<sytdMN[j])&&(s2[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                    s2[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                    xldeep[2]=sytdu[j];
                    p02=sytdMN[j];
                  }
              }
              else
              {
                  if((p22>sytdMN[j])&&(s2[2]>fabs(a2lj[ljcw-1]-sytdu[j]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                    s2[2]=fabs(a2lj[ljcw-1]-sytdu[j]);
                    xldeep[2]=sytdu[j];
                    p22=sytdMN[j];
                  }
              }
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
              {
                  if((p03<dp1MN[j])&&(s2[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                     xldeep[3]=deep1[j];
                     p03=dp1MN[j];
                  }
              }
              else
              {
                  if((p33>dp1MN[j])&&(s2[3]>fabs(a2lj[ljcw-1]-deep1[j]))&&(deep1[j]>zzppsd[ljcw-1-in])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[3]=fabs(a2lj[ljcw-1]-deep1[j]);
                     xldeep[3]=deep1[j];
                     p33=dp1MN[j];
                  }
              }
              if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
              {
                  if((p04<GMMN[j])&&(s2[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                     xldeep[4]=GMdeep2[j];
                     p04=GMMN[j];
                  }
              }
              else
              {
                  if((p44>GMMN[j])&&(s2[4]>fabs(a2lj[ljcw-1]-GMdeep2[j]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&(fabs(GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
                  {
                     s2[4]=fabs(a2lj[ljcw-1]-GMdeep2[j]);
                     xldeep[4]=GMdeep2[j];
                     p44=GMMN[j];
                  }
              }
          }
      }
      else                                         //第三个层及以后的层
      {

          float f1[10];p01=0.0;p02=0.0;p03=0.0;p04=0.0;p11=9999.0;p22=9999.0;p33=9999.0;p44=9999.0;
          f1[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
          f1[1]=deep2[j]-zzppsd[ljcw-1-in];
          f1[2]=sytdu[j]-zzppsd[ljcw-1-in];
          f1[3]=deep1[j]-zzppsd[ljcw-1-in];
          f1[4]=GMdeep2[j]-zzppsd[ljcw-1-in];
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
             if((p01<dp2MN[j])&&(s3[1]>fabs(f1[0]-f1[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                s3[1]=fabs(f1[0]-f1[1]);
                xldeep[1]=deep2[j];
                p01=dp2MN[j];
             }
          }
          else
          {
              if((p11>dp2MN[j])&&(s3[1]>fabs(f1[0]-f1[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                 s3[1]=fabs(f1[0]-f1[1]);
                 xldeep[1]=deep2[j];
                 p11=dp2MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
             if((p02<sytdMN[j])&&(s3[2]>fabs(f1[0]-f1[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                 s3[2]=fabs(f1[0]-f1[2]);
                 xldeep[2]=sytdu[j];
                 p02=sytdMN[j];
             }
          }
          else
          {
              if((p22>sytdMN[j])&&(s3[2]>fabs(f1[0]-f1[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((sytdu[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                  s3[2]=fabs(f1[0]-f1[2]);
                  xldeep[2]=sytdu[j];
                  p22=sytdMN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
             if((p03<dp1MN[j])&&(s3[3]>fabs(f1[0]-f1[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                 s3[3]=fabs(f1[0]-f1[3]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
             }
          }
          else
          {
              if((p33>dp1MN[j])&&(s3[3]>fabs(f1[0]-f1[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((deep1[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                  s3[3]=fabs(f1[0]-f1[3]);
                  xldeep[3]=deep1[j];
                  p33=dp1MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
             if((p04<GMMN[j])&&(s3[4]>fabs(f1[0]-f1[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
             {
                 s3[4]=fabs(f1[0]-f1[4]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
             }
          }
          else
          {
              if((p44>GMMN[j])&&(s3[4]>fabs(f1[0]-f1[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<cjmk[ljcw-1])&&((GMdeep2[j]-zzppsd[ljcw-1-in])>cjmk0[ljcw-1]))
              {
                  s3[4]=fabs(f1[0]-f1[4]);
                  xldeep[4]=GMdeep2[j];
                  p44=GMMN[j];
              }
          }

       if((zzppsd[ljcw-1-1]<20.0)&&((ljcw-1)>1))   //上层判别无结果
       {

          float f2[10];p01=0.0;p02=0.0;p03=0.0;p04=0.0;p11=9999.0;p22=9999.0;p33=9999.0;p44=9999.0;
          f2[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
          f2[1]=deep2[j]-zzppsd[ljcw-1-in];
          f2[2]=sytdu[j]-zzppsd[ljcw-1-in];
          f2[3]=deep1[j]-zzppsd[ljcw-1-in];
          f2[4]=GMdeep2[j]-zzppsd[ljcw-1-in];
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
              if((p01<dp2MN[j])&&(s4[1]>fabs(f2[0]-f2[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[1]=fabs(f2[0]-f2[1]);
                  xldeep[1]=deep2[j];
                  p01=dp2MN[j];
              }
          }
          else
          {
              if((p11>dp2MN[j])&&(s4[1]>fabs(f2[0]-f2[1]))&&(deep2[j]>zzppsd[ljcw-1-in])&&((deep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[1]=fabs(f2[0]-f2[1]);
                  xldeep[1]=deep2[j];
                  p11=dp2MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
              if((p02<sytdMN[j])&&(s4[2]>fabs(f2[0]-f2[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((sytdu[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[2]=fabs(f2[0]-f2[2]);
                  xldeep[2]=sytdu[j];
                  p02=sytdMN[j];
              }
          }
          else
          {
              if((p22>sytdMN[j])&&(s4[2]>fabs(f2[0]-f2[2]))&&(sytdu[j]>zzppsd[ljcw-1-in])&&((sytdu[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((sytdu[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                  s4[2]=fabs(f2[0]-f2[2]);
                  xldeep[2]=sytdu[j];
                  p22=sytdMN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
              if((p03<dp1MN[j])&&(s4[3]>fabs(f2[0]-f2[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep1[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[3]=fabs(f2[0]-f2[3]);
                 xldeep[3]=deep1[j];
                 p03=dp1MN[j];
              }
          }
          else
          {
              if((p33>dp1MN[j])&&(s4[3]>fabs(f2[0]-f2[3]))&&(deep1[j]>zzppsd[ljcw-1-in])&&((deep1[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((deep1[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[3]=fabs(f2[0]-f2[3]);
                 xldeep[3]=deep1[j];
                 p33=dp1MN[j];
              }
          }
          if((str8[ljcw-1]=="JC")||(str8[ljcw-1]=="JCJC")||(str8[ljcw-1]=="S31")||(str8[ljcw-1]=="S37")||(str8[ljcw-1]=="P21"))
          {
              if((p04<GMMN[j])&&(s4[4]>fabs(f2[0]-f2[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((GMdeep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[4]=fabs(f2[0]-f2[4]);
                 xldeep[4]=GMdeep2[j];
                 p04=GMMN[j];
              }
          }
          else
          {
              if((p44>GMMN[j])&&(s4[4]>fabs(f2[0]-f2[4]))&&(GMdeep2[j]>zzppsd[ljcw-1-in])&&((GMdeep2[j]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((GMdeep2[j]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
              {
                 s4[4]=fabs(f2[0]-f2[4]);
                 xldeep[4]=GMdeep2[j];
                 p44=GMMN[j];
              }
          }
       }
      }
     }
        int ip1[10],ip2[10],ik=0;
         float f22[10];

         for(int j0=0;j0<10;j0++)
         {
            f22[j0]=1.0;
         }                               //此处添加   2022-11-1晚上
        if(xldeep[1]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[1]=deep2[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[1]))&&(fabs(deep2[j0]-deep2[j1])<0.4)&&(deep2[j0]>zzppsd[ljcw-1-in])&&(deep2[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[1]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(deep2[ip1[iy]],deep2[ip2[iy]],ljcw-1);
               xldeep[1]=hfsd;
           }
        }
        ik=0;

        if(xldeep[2]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[2]=sytdu[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[2]))&&(fabs(sytdu[j0]-sytdu[j1])<0.4)&&(sytdu[j0]>zzppsd[ljcw-1-in])&&(sytdu[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f2[0]-f2[2]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(sytdu[ip1[iy]],sytdu[ip2[iy]],ljcw-1);
               xldeep[2]=hfsd;
           }
        }
        ik=0;

        if(xldeep[3]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];
                  f22[3]=deep1[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[3]))&&(fabs(deep1[j0]-deep1[j1])<0.4)&&(deep1[j0]>zzppsd[ljcw-1-in])&&(deep1[j1]>zzppsd[ljcw-1-in]))
                  {
                    // float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[3]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
                xjwdjzxz(deep1[ip1[iy]],deep1[ip2[iy]],ljcw-1);
                xldeep[3]=hfsd;
           }
        }
        ik=0;

        if(xldeep[4]<0.0)
        {
           float ppo=9999.0;
           for(int iu=0;iu<=n;iu++)
           {
               ip1[iu]=-1;
               ip2[iu]=-1;
           }
           for(int j0=1;j0<n;j0++)
           {
               for(int j1=j0+1;j1<=n;j1++)
               {
                  f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];

                  f22[4]=GMdeep2[j1]-zzppsd[ljcw-1-in];
                  if((ppo>fabs(f22[0]-f22[4]))&&(fabs(GMdeep2[j0]-GMdeep2[j1])<0.4)&&(GMdeep2[j0]>zzppsd[ljcw-1-in])&&(GMdeep2[j1]>zzppsd[ljcw-1-in]))
                  {
                   //  float hfsd;       //回返深度
                     ip1[ik]=j0;
                     ip2[ik]=j1;
                     ik=ik+1;
                     ppo=fabs(f22[0]-f22[4]);

                  }
               }
           }
           for(int iy=0;iy<ik;iy++)
           {
               xjwdjzxz(GMdeep2[ip1[iy]],GMdeep2[ip2[iy]],ljcw-1);
               xldeep[4]=hfsd;
           }
        }
    if((ljcw-1)>55)
    {
       PaintBox4->Canvas->TextOutA(230+1*100,0+(ljcw-57)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
       PaintBox4->Canvas->TextOutA(230+2*100,0+(ljcw-57)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
       PaintBox4->Canvas->TextOutA(230+3*100,0+(ljcw-57)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
       PaintBox4->Canvas->TextOutA(230+4*100,0+(ljcw-57)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
    else
    {
        PaintBox2->Canvas->TextOutA(230+1*100,0+(ljcw-1)*12,"Pearson  "+AnsiString(FormatFloat("0.0",xldeep[1])));
        PaintBox2->Canvas->TextOutA(230+2*100,0+(ljcw-1)*12,"时域梯度  "+AnsiString(FormatFloat("0.0",xldeep[2])));
        PaintBox2->Canvas->TextOutA(230+3*100,0+(ljcw-1)*12,"动态时间  "+AnsiString(FormatFloat("0.0",xldeep[3])));
        PaintBox2->Canvas->TextOutA(230+4*100,0+(ljcw-1)*12,"动态概密  "+AnsiString(FormatFloat("0.0",xldeep[4])));
    }
     dbnum=0;

     f22[0]=a2lj[ljcw-1]-a2lj[ljcw-1-in];

     float pmin=9999.0;
     int correct=0;
  if((ljcw-1)<=2)
  {
     for(int i1=1;i1<=3;i1++)
     {
         for(int i2=i1+1;i2<=4;i2++)
         {

            if((fabs(xldeep[i1]-xldeep[i2])<0.42)&&(dbnum<4)&&(xldeep[i1]>20.0))     // 此处可以选取微电极最低值
            {

             //     float hfsd;       //回返深度
                  xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

                  xlzjdeep[0]=hfsd;
                  open_correct=1;
                  dbnum=dbnum+1;
            }
         }
     }
  }
  else if((ljcw-1)>2)
  {
     for(int i1=1;i1<=3;i1++)
     {
         for(int i2=i1+1;i2<=4;i2++)
         {
            f22[5]=xldeep[i1]-zzppsd[ljcw-1-in];
            f22[6]=xldeep[i2]-zzppsd[ljcw-1-in];
            if((correct==0)&&(fabs(xldeep[i1]-xldeep[i2])<0.42)&&(dbnum<4)&&(xldeep[i1]>20.0)&&(fabs(f22[0]-f22[5])<cjmk[ljcw-1])&&(pmin>fabs(f22[0]-f22[5])))     // 此处可以选取微电极最低值
            {
                  pmin=fabs(f22[0]-f22[5]);
             //     float hfsd;       //回返深度
                  xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

                  xlzjdeep[0]=hfsd;
                  open_correct=1;
                  correct=1;
                  dbnum=dbnum+1;
            }
            else if((correct==0)&&(fabs(f22[0]-f22[5])<0.42))
            {
                 // xjwdjzxz(xldeep[i1],xldeep[i2],ljcw-1);     //新井微电极最小值

                  xlzjdeep[0]=xldeep[i1];
                  open_correct=1;
                  correct=1;
                  dbnum=dbnum+1;
            }
            else if((correct==0)&&(fabs(f22[0]-f22[6])<0.42))
            {

                  xlzjdeep[0]=xldeep[i2];
                  open_correct=1;
                  correct=1;
                  dbnum=dbnum+1;
            }
         }
     }
  }
                zzppsd[ljcw-1]=xlzjdeep[0];   //最终匹配深度
                if(zzppsd[ljcw-1]>20.0)
                {
                   open_correct=1;
                }
                if((zzppsd[ljcw-1-1]<20.0)&&(zzppsd[ljcw-1]>20.0)&&(zzppsd[ljcw-1]>zzppsd[ljcw-1-in])&&((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])<(cjmk[ljcw-1]))&&((zzppsd[ljcw-1]-zzppsd[ljcw-1-in])>(cjmk0[ljcw-1])))
                {
                   open_correct2=3;
                }
              if((ljcw-1)>55)
              {
                PaintBox4->Canvas->TextOutA(80+0*120,0+(ljcw-57)*12,str8[ljcw-1]);
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=             ");
                PaintBox4->Canvas->TextOutA(118+0*120,0+(ljcw-57)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw-1])));
              }
              else
              {
                 PaintBox2->Canvas->TextOutA(80+0*120,0+(ljcw-1)*12,str8[ljcw-1]);
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=             ");
                 PaintBox2->Canvas->TextOutA(118+0*120,0+(ljcw-1)*12,"新老井最佳匹配深度=  "+AnsiString(FormatFloat("0.0",zzppsd[ljcw-1])));
              }

}
//-----------------------------------------------------------------------------------

//========================================井结构
   struct Well
   {
	  int Number;				//数据点个数
	  int Start_Depth;          //起始深度
	  int End_Depth;            //终止深度
	  float SI;                //采样间距
	  String Line_Name[20];     //测井曲线名称
	  float Depth[20000];      //深度值
	  float GR[20000];      	//GR值
	  float DEN[20000];      	//DEN值
          float HAC[20000];
	  float RMN[20000];
          float RLLD[20000];
	  float RXO[20000];
   };
   Well w1,w2;
   //Well *w1 = new Well;
//========================================小层结构
struct Unit
{
   int UnitCount;       //小层个数
   String UnitName[200];//小层名
   float Depth[200];   //深度
   int Pos[200];        //序号
};
Unit Old;
//Unit *Old = new Unit;
Unit New;
struct STANDARD
{
   String UnitName;//小层名
   int DataCount;
   float Depth[200];
   float GRValue[200];
   float HACValue[200];
   float RXOValue[200];
};
STANDARD Standard[10];

String LName = "GR";

float NormalDistribution(float x);
float LastDepth = 0;   //上一匹配深度
float Drop = 0;        //落差值
int fall = 0;           //落差开关
//========================================结果结构
//////////////////////////////////////////
int ScreenSwitch = 0;
int TempNumber = -1;
float DistValue = 0;
float StandardValue[200];
String LA01,LA02,DBF01,DBF02;
void OpenDBF(String DBF0);
int JCResult = 0;
void Func2();
//
void Reset1();
void Reset2();
//
struct RESULT_SINGLE
{

   String StandardWellName;//小层名
   String UnitName[10];//小层名
   float ResultDepth[10][10];
   float ResultValue[10][10];
};
struct RESULT
{
   String WellName;//小层名
   RESULT_SINGLE Group[3];
   int Group_Count;
};
struct FinRESULT
{
   String WellName;//小层名
   float result[10];
};
FinRESULT FR[200];
int TEMP = 0;

RESULT ResultList[300];
float NewStandardDepth[10];
String Selected[20];
String SaveFileName;
//最终结果RMN匹配
void FinFunc();
float ResultNow[10];//当前计算结果【】
//邻井筛选
int SelCount = 0;//已筛选出邻井个数
//沉积单元数据库打开
String daa073_auto_open_path = "";//073路径
String flag073 = "";//073模式(S、T)
//标志层预处理
void SearchStandard();
String NameListOne[20];//标志层名称列表
int LAfound = 0;
//结果处理
void Deal(int seq);
//
struct CONTROLVALUE
{
   String StandardGroup;
   String LineGroup;

};
CONTROLVALUE CtrlValue;
void LoadAnswer();
int StandardNum = 0;
float Euclidean(float dep,int rag);
float Euclidean_Standard(float dep,int rag);
float DepthAll[200][20];
int FuncTimes = 0;
float TOP = 0;
float BOT = 0;
void Func();


String StandardUnitName[200];
//结果记录
struct RESULTGROUP
{
   String UnitName[200];
   float ResultDepth[200][3];
};
int GroupCount = 0;
RESULTGROUP ResultGroup[3];
//最终结果

//---------------------------------------------------------------------------
float getfloat(FILE *fp)
{
   char *s;
   float f;
   (float *)s=&f;
   s[3]=getc(fp);s[2]=getc(fp);s[1]=getc(fp);s[0]=getc(fp);
   return(f);
}
//---------------------------------------------------------------------------
int getint(FILE *fp)
{
   char *s;short i;
   (short *)s=&i;
   s[1]=getc(fp);s[0]=getc(fp);
   return(i);
}
//---------------------------------------------------------------------------
float NormalDistribution(float x)//生成标准正态分布，输入X值返回对应Y值
{
   float m1 = 1/sqrt(3.1415926535/2);
   float m2 = exp(-1*(x*x)/2);
   float nd = m1*m2;
   return nd;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
 short i1,i2;float f;
   Top_deep=0.0;
   int flag,i3;

   FILE *fp;
   int Rd_valueGTzero=0;
   int RMN_valueGTzero=0;
   int AC_value=0;
         MN_pos=0;
         MK_pos=0;
         Rd_pos=0;
         Rs_pos=0;
         Ac_pos=0;
         Rxo_pos=0;
         GR_pos=0;
         SP_pos=0;
         DEN_pos=0;
   TOpenDialog* OpenDialog1 = new TOpenDialog(this);
   OpenDialog1->Filter="测井数据文件la(*.la)|*.la|LA文件（LA*)|LA*|所有文件(*.*)|*.*";

   if(Well_Name_2 == NULL || Well_Name_2 == "")
   {
        OpenDialog1->Execute();
   }
   for(int I=0;I<1;I++)
   {
        if(Well_Name_2 == NULL || Well_Name_2 == "")
        {
                fp=fopen(OpenDialog1->Files->Strings[I].c_str(),"rb");
                cc1 = OpenDialog1->Files->Strings[I].c_str();
                Well_Name_2 = cc1;
                DBF02 = cc1;
                DBF02.SetLength(DBF02.Length()-3);
                DBF02 += ".DBF";
        }
        else
        {
                String temps = Well_Name_2_path;
                fp = fopen(temps .c_str(),"rb");
                cc1 = Well_Name_2.c_str();
                DBF02 = "D:\\测井数据\\测井任务  第一次\\" + LowerCase(Well_Name_2) + "\\" + LowerCase(Well_Name_2) + ".DBF";
        }
        if(fp)
        {
                fread(str0,84,1,fp);
                fread(str1,80,1,fp);
                i2=getint(fp);
                i1=getint(fp);
                fread(str,80,1,fp);
                stdp=getfloat(fp);
                endp=getfloat(fp);
                relv=getfloat(fp);
                i1=getint(fp);
                i2=getint(fp);
                f=getfloat(fp);
                fread(str11,80,1,fp);
                fread(str3,148,1,fp);
                for(int i7=0;i7<int(Top_deep/relv);i7++)
                {
                        for(int j7=1;j7<41;j7++)
                        {
                                a1[i7][j7]=1.0;
                                data1[i7][j7]=1.0;
                        }
                }
                stdp=stdp-Top_deep;
                i1=0+int(Top_deep/relv);
                stedp=int((endp-stdp)/relv);
                while(i1<stedp)
                {
                        for(int j=1;j<41;j++)
                        {
                                for(int i=i1;i<i1+62;i++)
                                {
                                        a1[i][j]=getfloat(fp);
                                        data1[i][j]=a1[i][j];
                                        //data_01[i][j] = data[i][j];
                                }
                        }
                i1=i1+62;
                }
        }

   }
   for(int i=0;i<3;i++)
   {
        for(int j=0;j<4;j++)
        {
                temp_index[i][j]=-1;
        }
   }
   for(int i0=0;i0<stedp;i0++)
   {
        a1[i0][0]=stdp+i0*relv;
        data1[i0][0]=stdp+i0*relv;
   }
   int i4,i,j,ip;
   cname3[0][5]="DEPT ";
   i4=1;
   for(i=0;i<80;i+=4)
   {
        i2=0;
        for(j=i;j<i+4;j++)
        {
                if(str[j]!=' ') i2++;
        }
        j=i;
        for(i3=0;i3<4;i3++)
        str2[i3]=0;
        for(i3=0;i3<i2;i3++)
        {
                str2[i3]=str[j];
                j++;
        }
        if((str2[0]!=' ')&&(str2[0]!='\0'))
        {
                cname3[i4][5]=str2;
                if(strcmp(str2,"RMN")==0||strcmp(str2,"MNOR")==0)
                {
                        MN_pos=i4;
                        temp_index[0][0]=i4;
                }
                if(strcmp(str2,"RML")==0||strcmp(str2,"RMK")==0||strcmp(str2,"RMM")==0||strcmp(str2,"RMG")==0)
                {
                        MK_pos=i4;
                        temp_index[1][0]=i4;
                }
                if(strcmp(str2,"RLLD")==0||strcmp(str2,"RL3D")==0||strcmp(str2,"LLD")==0)
                {
                        Rd_pos=i4;
                        temp_index[0][1]=i4;
                }
                if(strcmp(str2,"RLLS")==0||strcmp(str2,"RL3S")==0||strcmp(str2,"LLS")==0)
                {
                        Rs_pos=i4;
                        temp_index[1][1]=i4;
                }
                if(strcmp(str2,"AC")==0||strcmp(str2,"DT")==0)
                {
                        Ac_pos=i4;
                        temp_index[0][3]=i4;
                }
                if(strcmp(str2,"MSFL")==0||strcmp(str2,"RXO")==0)
                {
                        Rxo_pos=i4;
                        temp_index[2][1]=i4;
                }
                if(strcmp(str2,"GR")==0)
                {
                        GR_pos=i4;
                        temp_index[0][2]=i4;
                }
                if(strcmp(str2,"SP")==0)
                {
                        SP_pos=i4;
                temp_index[1][2]=i4;
                }
                if(strcmp(str2,"DEN")==0)
                {
                        DEN_pos=i4;
                        temp_index[1][3]=i4;
                }
                if(strcmp(str2,"HAC")==0)
                {
                        HAC_pos=i4;
                        temp_index[2][3]=i4;
                }
                i4++;
        }
   }
   stedp=int((endp-stdp)/relv);
   ip=i4;
   i4=i4-1;
   for(int i = 0,j = 0;i < 20000;i++)
   {
        AnsiString temp0;
        for(j = 0;j < 14;j ++)
        {
                AnsiString temp;
                if(j == 0)
                {
                   if(data1[i][j] != NULL)
                   {
                        temp = data1[i][j];
                        float tempf = StrToFloat(temp);
                        temp = FormatFloat("0.00",tempf);
                        float tempd = StrToFloat(temp);
                        data_02[i][j] = tempd;
                        LA_count2 ++;
                   }
                }
                else
                {
                   if(data1[i][j] != NULL)
                   {
                        float tempf2 = StrToFloat(data1[i][j]);
                        temp = FormatFloat("0.0000",tempf2);
                        float tempd2 = StrToFloat(temp);
                        data_02[i][j] = tempd2;
                   }
                }
                temp = temp + '\t';
                temp0 = temp0 + temp;
        }
        j = 0;
        if(data1[i+1][j] == NULL) break;
   }

   for(i = 0;i < 20;i ++)
   {
        new_order[i] = cname3[i][5];

   }
   w2.Number = i1;
   w2.SI = StrToFloat(FormatFloat("0.000",relv));
   w2.Start_Depth = a1[0][0];
   w2.End_Depth = a1[i1][0];
   for(int i = 0;i < 20;i ++)
   {
	   w2.Line_Name[i] = NULL;
   }
   int gr1_pos = 0,RLLD1_pos = 0,RMN1_pos = 0,HAC1_pos = 0,RXO1_pos = 0;
   for(int i = 0;i < 20;i ++)
   {
		if(new_order[i] == "GR")
				gr1_pos = i;
		if(new_order[i] == "HAC")
				HAC1_pos = i;
                if(new_order[i] == "RLLD")
				RLLD1_pos = i;
                if(new_order[i] == "RMN")
				RMN1_pos = i;
                if(new_order[i] == "RXO")
				RXO1_pos = i;
   }
   for(int i = 0;i < w2.Number;i ++)
   {
		w2.Depth[i] = StrToFloat(FormatFloat("0.00",a1[i][0]));
		w2.GR[i] = a1[i][gr1_pos];
		w2.HAC[i] = a1[i][HAC1_pos];
                w2.RLLD[i] = a1[i][RLLD1_pos];
                w2.RMN[i] = a1[i][RMN1_pos];
                w2.RXO[i] = a1[i][RXO1_pos];
   }
   w2;
   fclose(fp);
   //BitBtn5Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
   short i1,i2;
   float f = 0;
   Top_deep=0.0;
   int flag,i3;
   LAfound = 0;
   FILE *fp;
   int AC_value=0;
         MN_pos=0;
         MK_pos=0;
         Rd_pos=0;
         Rs_pos=0;
         Ac_pos=0;
         Rxo_pos=0;
         GR_pos=0;
         SP_pos=0;
         DEN_pos=0;
   TOpenDialog* OpenDialog1 = new TOpenDialog(this);
   OpenDialog1->Filter="测井数据文件la(*.la)|*.la|LA文件（LA*)|LA*|所有文件(*.*)|*.*";
   if(Well_Name_1 == NULL || Well_Name_1 == "")
   {
        OpenDialog1->Execute();
   }
   for(int I=0;I<1;I++)
   {
        if(Well_Name_1 == NULL || Well_Name_1 == "")
        {
                fp=fopen(OpenDialog1->Files->Strings[I].c_str(),"rb");
                cc1 = OpenDialog1->Files->Strings[I].c_str();
                Well_Name_1 = cc1;
                DBF01 = cc1;
                DBF01.SetLength(DBF01.Length()-3);
                DBF01 += ".DBF";
        }
        else
        {
                Well_Name_1_path = "D:\\二厂统层对比有形化平台\\曲线\\" + LowerCase(Well_Name_1) + ".la";
                String temps = Well_Name_1_path;
                fp = fopen(temps .c_str(),"rb");
                cc1 = Well_Name_1.c_str();
                DBF01 = DBF073_path;
        }

        if(fp)
        {
                LAfound = 1;
                fread(str0,84,1,fp);
                fread(str1,80,1,fp);
                i2=getint(fp);
                i1=getint(fp);
                fread(str,80,1,fp);
                stdp=getfloat(fp);
                endp=getfloat(fp);
                relv=getfloat(fp);
                i1=getint(fp);
                i2=getint(fp);
                f=getfloat(fp);
                fread(str11,80,1,fp);
                fread(str3,148,1,fp);
                for(int i7=0;i7<int(Top_deep/relv);i7++)
                {
                        for(int j7=1;j7<41;j7++)
                        {
                                a[i7][j7]=1.0;
                                data[i7][j7]=1.0;
                        }
                }
                stdp=stdp-Top_deep;
                i1=0+int(Top_deep/relv);
                stedp=int((endp-stdp)/relv);
                while(i1<stedp)
                {
                        for(int j=1;j<41;j++)
                        {
                                for(int i=i1;i<i1+62;i++)
                                {
                                        a[i][j]=getfloat(fp);
                                        data[i][j]=a[i][j];
                                        //data_01[i][j] = data[i][j];
                                }
                        }
                i1=i1+62;
                }
        }
   }
   for(int i=0;i<3;i++)
   {
        for(int j=0;j<4;j++)
                temp_index[i][j]=-1;
   }
   for(int i0=0;i0<stedp;i0++)
   {
        a[i0][0]=stdp+i0*relv;
        data[i0][0]=stdp+i0*relv;
   }
   int i4,i,j,ip;
   cname3[0][5]="DEPT ";
   i4=1;
   for(i=0;i<80;i+=4)
   {
        i2=0;
        for(j=i;j<i+4;j++)
        {
                if(str[j]!=' ') i2++;
        }
        j=i;
        for(i3=0;i3<4;i3++)
        str2[i3]=0;
        for(i3=0;i3<i2;i3++)
        {
                str2[i3]=str[j];
                j++;
        }
        if((str2[0]!=' ')&&(str2[0]!='\0'))
        {
                cname3[i4][5]=str2;
                if(strcmp(str2,"RMN")==0||strcmp(str2,"MNOR")==0)
                {
                        MN_pos=i4;
                        temp_index[0][0]=i4;
                }
                if(strcmp(str2,"RML")==0||strcmp(str2,"RMK")==0||strcmp(str2,"RMM")==0||strcmp(str2,"RMG")==0)
                {
                        MK_pos=i4;
                        temp_index[1][0]=i4;
                }
                if(strcmp(str2,"RLLD")==0||strcmp(str2,"RL3D")==0||strcmp(str2,"LLD")==0)
                {
                        Rd_pos=i4;
                        temp_index[0][1]=i4;
                }
                if(strcmp(str2,"RLLS")==0||strcmp(str2,"RL3S")==0||strcmp(str2,"LLS")==0)
                {
                        Rs_pos=i4;
                        temp_index[1][1]=i4;
                }
                if(strcmp(str2,"AC")==0||strcmp(str2,"DT")==0)
                {
                        Ac_pos=i4;
                        temp_index[0][3]=i4;
                }
                if(strcmp(str2,"MSFL")==0||strcmp(str2,"RXO")==0)
                {
                        Rxo_pos=i4;
                        temp_index[2][1]=i4;
                }
                if(strcmp(str2,"GR")==0)
                {
                        GR_pos=i4;
                        temp_index[0][2]=i4;
                }
                if(strcmp(str2,"SP")==0)
                {
                        SP_pos=i4;
                temp_index[1][2]=i4;
                }
                if(strcmp(str2,"DEN")==0)
                {
                        DEN_pos=i4;
                        temp_index[1][3]=i4;
                }
                if(strcmp(str2,"HAC")==0)
                {
                        HAC_pos=i4;
                        temp_index[2][3]=i4;
                }
                i4++;
        }
   }
   stedp=int((endp-stdp)/relv);
   ip=i4;
   i4=i4-1;
   for(int i = 0,j = 0;i < 20000;i++)
   {
        AnsiString temp0;
        for(j = 0;j < 14;j ++)
        {
                AnsiString temp;
                if(j ==0)
                {
                   if(data[i][j] != NULL)
                   {
                        temp = data[i][j];
                        float tempf = StrToFloat(temp);
                        temp = FormatFloat("0.00",tempf);
                        float tempd = StrToFloat(temp);
                        data_01[i][j] = tempd;
                        LA_count1 ++;
                   }
                }
                else
                {
                   if(data[i][j] != NULL)
                   {
                        float tempf2 = StrToFloat(data[i][j]);
                        temp = FormatFloat("0.0000",tempf2);
                        float tempd2 = StrToFloat(temp);
                        data_01[i][j] = tempd2;
                   }
                }
                temp = temp + '\t';
                temp0 = temp0 + temp;
        }
        j = 0;
        if(data[i+1][j] == NULL) break;
   }
   for(i = 0;i < 20;i ++)
   {
        old_order[i] = cname3[i][5];

   }

   w1.Number = i1;
   w1.SI = StrToFloat(FormatFloat("0.000",relv));
   w1.Start_Depth = data_01[0][0];
   w1.End_Depth = data_01[i1][0];
   for(int i = 0;i < 20;i ++)
   {
	   w1.Line_Name[i] = NULL;
   }
   int gr1_pos = 0,RLLD1_pos = 0,RMN1_pos = 0,HAC1_pos = 0,RXO1_pos = 0;
   for(int i = 0;i < 20;i ++)
   {
		if(old_order[i] == "GR")
				gr1_pos = i;
		if(old_order[i] == "HAC")
				HAC1_pos = i;
                //if(old_order[i] == "DEN")
				//gr1_pos = i;
		if(old_order[i] == "RLLD")
				RLLD1_pos = i;
                if(old_order[i] == "RMN")
				RMN1_pos = i;
                if(old_order[i] == "RXO")
				RXO1_pos = i;
   }
   for(int i = 0;i < w1.Number;i ++)
   {
		w1.Depth[i] = data_01[i][0];
		w1.GR[i] = data_01[i][gr1_pos];
		w1.HAC[i] = data_01[i][HAC1_pos];
                w1.RLLD[i] = data_01[i][RLLD1_pos];
		w1.RMN[i] = data_01[i][RMN1_pos];
                w1.RXO[i] = data_01[i][RXO1_pos];
   }
   fclose(fp);
   //BitBtn3Click(Sender);
}
//---------------------------------------------------------------------------
void Reset1()
{
   w1.Number = 0;
   //w1.SI = StrToFloat(FormatFloat("0.000",relv));
   w1.Start_Depth = NULL;
   w1.End_Depth = NULL;
   for(int i = 0;i < 20;i ++)
   {
	   w1.Line_Name[i] = NULL;
   }
   for(int i = 0;i < 20000;i ++)
   {
		w1.Depth[i] = 0;
		w1.GR[i] = 0;
		w1.HAC[i] = 0;
                w1.RLLD[i] = 0;
		w1.RMN[i] = 0;
                w1.RXO[i] = 0;
   }
   for(int i = 0;i < 200;i ++)
   {
        Old.Pos[i] = NULL;
        Old.UnitName[i] = NULL;
        Old.Depth[i] = NULL;
        Old.UnitCount = 0;
   }

   LA_count1 = 0;
   for(int i = 0;i < 50000;i ++)
   {
        for(int j = 0;j < 50;j ++)
                data[i][j] = NULL;
        for(int j = 0;j < 20;j ++)
                data_01[i][j] = NULL;
   }

}
//---------------------------------------------------------------------------
void Reset2()
{
   w2.Number = 0;
   //w1.SI = StrToFloat(FormatFloat("0.000",relv));
   w2.Start_Depth = NULL;
   w2.End_Depth = NULL;
   for(int i = 0;i < 20;i ++)
   {
	   w2.Line_Name[i] = NULL;
   }
   for(int i = 0;i < 20000;i ++)
   {
		w2.Depth[i] = 0;
		w2.GR[i] = 0;
		w2.HAC[i] = 0;
                w2.RLLD[i] = 0;
		w2.RMN[i] = 0;
                w2.RXO[i] = 0;
   }
   for(int i = 0;i < 200;i ++)
   {
        New.Pos[i] = NULL;
        New.UnitName[i] = NULL;
        New.Depth[i] = NULL;
        New.UnitCount = 0;
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn8Click(TObject *Sender)
{

   FILE *fp, *fp2;
   String WellNameList[1000];
   int Task = 0;
   float ResultTri[1000][3];
   //
   int Batch = 0;//批量开关
   if(Batch == 1)//批量
   {
   }

   else if(Batch == 0)//单次

   {

        WellNameList[Task] = Well_Name_2;

        Task = 1;//任务数=1

   }

   //

   for(int i = 0;i < Task;i ++)

   {
        Well_Name_2 = WellNameList[i];//////////////////////////////////////////
        Reset2();//重置新井变量
        //Well_Name_1 = "N8-2-P2041";
        BitBtn2Click(Sender);//读取新井
        JCResult = 0;//是否识别JC层
        flag073 = "T";
        daa073_auto_open_path = DBF073_path;
        OpenDBS();
        //
        ResultList[i].WellName = Well_Name_2;
        TEMP = i;
        ResultList[TEMP].Group_Count = 0;
        //if(Well_Name_2 != "" && Well_Name_2 != NULL)
        SelCount = 1;
                //SelectWell();//筛选/////////////////////////////////////////////
        //计算
        CtrlValue.LineGroup = "GR+HAC";
        //CtrlValue.StandardGroup = "1";
        for(int j = 0;j < SelCount;j ++)        //SelCount个数
        {
                Reset1();
                //Well_Name_1 = Selected[j];//////////////////////////////////////
                BitBtn1Click(Sender);
                flag073 = "S";
                   OpenDBS();
                //
                if(LAfound == 0)
                        continue;
                //
                CtrlValue.LineGroup = "GR+HAC";
                Func2();
                /*
                FuncTimes ++;
                CtrlValue.LineGroup = "RMN+HAC";
                Func2();
                FuncTimes ++;
                CtrlValue.LineGroup = "RXO+GR";
                Func2();
                FuncTimes ++;
                CtrlValue.LineGroup = "RMN+GR";
                Func2();
                FuncTimes ++;
                */
                //
                /*
                if(ResultList[i].Group_Count == 3)
                {
                        Deal(i);
                        FR[0];

                        //Memo1数据库结果
                        int temp0 = 0;
                        for(int i = 0;i < New.UnitCount;i ++)
                        {
                                if(temp0 > StandardNum)
                                {
                                        temp0 = 0;
                                        break;
                                }
                                String Strtemp = NameListOne[temp0];
                                if(New.UnitName[i] == Strtemp && Strtemp != "" && New.UnitName[i] != "")
                                {
                                        NewStandardDepth[temp0] = New.Depth[i];
                                        temp0 ++;
                                }
                        }
                        for(int k = 0;k < StandardNum;k ++)
                                ResultTri[i*StandardNum + k][0] = FR[i].result[k];
                        break;
                }
                */
        }
        for(int j = 1;j < 200;j ++)
        {
                //int count = 0;
                //int pos = 0;
                //int same = 0;
                if(SentResult[j] > 100)
                        continue;
                if(SentResult2[j] < 100)
                {
                        //float dt = 0;
                        //pos = 0;
                        //same = 0;
                        float min = 9999;
                        float max = -999;
                        for(int k = 0;k < 2;k ++)
                        {
                                if(DepthAll[j][k] < min)
                                        min = DepthAll[j][k];
                                if(DepthAll[j][k] > max)
                                        max = DepthAll[j][k];
                        }
                        if(DepthAll[j][0] < 100 || DepthAll[j][1] < 100 || DepthAll[j][2] < 100)
                                continue;
                        if(max - min < 0.5 && max - min >= 0)
                        {
                                SentResult2[j] = DepthAll[j][0];
                        }
                        else if((fabs(DepthAll[j][0] - DepthAll[j][1]) < 0.5) && (fabs(DepthAll[j][0] - DepthAll[j][1]) >= 0))
                        {
                                SentResult2[j] = DepthAll[j][0];
                        }
                        else if((fabs(DepthAll[j][0] - DepthAll[j][2]) < 0.5) && (fabs(DepthAll[j][0] - DepthAll[j][2]) >= 0))
                        {
                                SentResult2[j] = DepthAll[j][2];
                        }
                        else if((fabs(DepthAll[j][1] - DepthAll[j][2]) < 0.5) && (fabs(DepthAll[j][1] - DepthAll[j][2]) >= 0))
                        {
                                SentResult2[j] = DepthAll[j][2];
                        }
                }
        }
        for(int j = 1;j < 200;j ++)
        {
                if(SentResult2[j] > 100)
                {
                        if(SentResult[j - 1] > 100 && SentResult2[j] > SentResult[j - 1] && SentResult2[j] < SentResult[j - 1] + 15)
                                SentResult[j] = SentResult2[j];
                        if(SentResult[j + 1] > 100 && SentResult2[j] < SentResult[j + 1] && SentResult2[j] > SentResult[j + 1] - 15)
                                SentResult[j] = SentResult2[j];
                }
        }




   }
}
//---------------------------------------------------------------------------
void SearchStandard()
{
   StandardNum  = 0;
   int JC = 0;
   for(int i = 0;i < Old.UnitCount - 1;i ++)
   {
        if((UpperCase(Old.UnitName[i]) == "JC")||(UpperCase(Old.UnitName[i]) == "JCJC"))
        {
                JC = i;
                break;
        }
   }
   for(int i = JC;i < Old.UnitCount - 1;i ++)
   {
        StandardValue[i - JC] = Old.Depth[i];
        StandardUnitName[i - JC] = Old.UnitName[i];
        StandardNum ++;
   }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::SelectWell()
{
   String wellname = Well_Name_2;
   int j,i3,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   FILE *fc,*fp;
   AnsiString File_name;
   int path = 0;
   //
   String Jhc[300];
   //
   //
   if(daa073_auto_open_path == NULL || daa073_auto_open_path == "")
   {

        OpenDialog1->Filter="daa073（*.DBF)|*.DBF|所有文件(*.*)|*.*";
        OpenDialog1->Execute();
        daa073_auto_open_path = OpenDialog1->Files->Strings[0].c_str();
        File_name = ChangeFileExt(daa073_auto_open_path,"");
        path = 2;
   }

   if(path == 2 || daa073_auto_open_path != NULL)
   {
        for(int I=0;I<1;I++)
        {
                fc = fopen(daa073_auto_open_path.c_str(),_T("r"));
                cc = daa073_auto_open_path.c_str();
                String strtemp = "";
                if(fc)
                {
                        Table1->TableName = cc;
                        Table1->Open();
                        Table1->Active=true;
                        Table1->First();
                        //
                        String Wrong = "";
                        SelCount = 0;
                        Table1->Last();
                        for(int t = 0;t < 200;t ++)
                                Table1->Prior();
                        String LastName = Table1->FieldByName("JH")->AsString;
                        Table1->First();
                        String sc0 = "";
                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("JH")->AsString;
                                jjhh = LowerCase(jjhh); //

                                Table1->FieldByName("YCZMC")->AsString;  //油层组名称
                                Table1->FieldByName("DYMC")->AsString;  //单元名称
                                Table1->FieldByName("DYDS")->AsString;
                                /*
                                //if(LowerCase(jjhh) == "n8-d4-sp33")
                                        //sc0 = "1";
                                if(LowerCase(jjhh) == "s195")
                                        sc0 = "2";
                                if(LowerCase(jjhh) == "x1-d1-142")
                                        sc0 = "3";

                                */

                                if(Table1->Eof || LowerCase(Wrong) == LowerCase(LastName) || LowerCase(jjhh) == LowerCase(LastName))
                                {
                                        Table1->First();
                                        break;
                                }

                                if(LowerCase(jjhh) == LowerCase(Wrong) || jjhh.Length() < 7)
                                {
                                        Table1->Next();
                                        continue;
                                }


                                std::auto_ptr<TStringList>sl1(new TStringList);
                                sl1->Delimiter = '-';
                                sl1->DelimitedText = LowerCase(jjhh);
                                AnsiString NameS1 = sl1->Strings[0].c_str();
                                AnsiString NameS2 = sl1->Strings[1].c_str();
                                AnsiString NameS3 = sl1->Strings[2].c_str();

                                std::auto_ptr<TStringList>sl2(new TStringList);
                                sl2->Delimiter = '-';
                                sl2->DelimitedText = LowerCase(Well_Name_2);
                                AnsiString NameT1 = sl2->Strings[0].c_str();
                                AnsiString NameT2 = sl2->Strings[1].c_str();
                                AnsiString NameT3 = sl2->Strings[2].c_str();


                                //if(jjhh == LowerCase(File_name) && Table1->FieldByName("YCZMC")->AsString == "S1" && Table1->FieldByName("DYMC")->AsString == "1" && Table1->FieldByName("DYDS")->AsString != "")
                                if((NameS1 == NameT1 && NameS2 == NameT2 && LowerCase(jjhh) != LowerCase(Well_Name_2)) || (NameS1 == NameT1 && NameS3 == NameT3 && LowerCase(jjhh) != LowerCase(Well_Name_2)))
                                {
                                        String temps = "D:\\二厂统层对比有形化平台\\曲线\\" + LowerCase(jjhh) + ".la";
                                        //String temps = "D:\\测井数据\\测井任务  第一次\\" + LowerCase(jjhh) + "\\" + LowerCase(jjhh) + ".la";
                                        fp = fopen(temps .c_str(),"rb");
                                        if(!fp)
                                        {
                                                Wrong = jjhh;
                                                continue;
                                        }
                                        else
                                                fclose(fp);


                                        int temp1 = 0;
                                        for(int k = 0;k < SelCount;k ++)
                                        {
                                                if(LowerCase(Selected[k]) == LowerCase(jjhh))
                                                        temp1 = 1;
                                        }
                                        if(temp1 == 1)
                                        {
                                                Table1->Next();
                                                continue;
                                        }
                                        if(SelCount >= 20)
                                                break;

                                        strtemp = Table1->FieldByName("JH")->AsString;

                                        Selected[SelCount] = UpperCase(strtemp);
                                        SelCount ++;
                                        Table1->Next();
                                        continue;


                                }
                                else
                                {
                                        Wrong = jjhh;

                                }
                        }
                Table1->First();
                Table1->Close();
                fclose(fc);
                }
        }
   }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenDBS()
{
   int ia=0,j,i3,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   FILE *fc,*fo;

   AnsiString File_name;
   int path = 0;
   //
   String Jhc[300];
   String Yczmcc[300];
   String Dymcc[300];
   String Bzc[300];
   String Dydsc[300];
   //
   if(daa073_auto_open_path == NULL || daa073_auto_open_path == "")
   {

        OpenDialog1->Filter="daa073（*.DBF)|*.DBF|所有文件(*.*)|*.*";
        OpenDialog1->Execute();
        daa073_auto_open_path = OpenDialog1->Files->Strings[0].c_str();
        File_name = ChangeFileExt(daa073_auto_open_path,"");
        path = 2;
   }

   if(path == 2 || daa073_auto_open_path != NULL)
   {
        for(int I=0;I<1;I++)
        {
                if(flag073 == "S")
                        File_name = Well_Name_1;
                else if(flag073 == "T")
                        File_name = Well_Name_2;
                else
                        break;

                fc = fopen(daa073_auto_open_path.c_str(),_T("r"));
                cc = daa073_auto_open_path.c_str();

                if(fc)
                {
                        Table1->TableName = cc;
                        Table1->Open();
                        Table1->Active=true;
                        Table1->First();
                        //
                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("JH")->AsString;
                                jjhh = LowerCase(jjhh); //
                                if(jjhh == LowerCase(File_name))
                                {
                                        do{
                                                jjhh = Table1->FieldByName("JH")->AsString;
                                                jjhh = LowerCase(jjhh);flag1 = 1;
                                                Jhc[ia]      = Table1->FieldByName("JH")->AsString;      //加新井井名
                                                Yczmcc[ia]   = Table1->FieldByName("YCZMC")->AsString;  //油层组名称
                                                Dymcc[ia]    = Table1->FieldByName("DYMC")->AsString;  //单元名称
                                                Bzc[ia]      = Table1->FieldByName("BZ")->AsString;
                                                Dydsc[ia]    = Table1->FieldByName("DYDS")->AsString;
                                                ia ++;
                                                Table1->Next();
                                        }while((jjhh == LowerCase(File_name))&&(!Table1->Eof));
                                        //totalnum[js]=count-1;
                                }
                                if((flag1<1)&&(!Table1->Eof))
                                        Table1->Next();
                        }
                        Table1->First();
                        //层位导入结构体
                        String ts = "";
                        int count = 0;
                        int pointer = 0;
                        //
                        if(flag1 != 1)
                                break;//未识别，跳出结构体写入
                        //标准井层位结构体写入
                        if(flag073 == "S")
                        {
                            for(int j = 0;j <= ia - 1;j ++)
                            {
                                if(Yczmcc[j] != NULL && Yczmcc[j] + Dymcc[j]  != ts && Dydsc[j] != "0" && Dydsc[j] != ts && Dydsc[j] != NULL)
                                {
                                        ts = Yczmcc[j] + Dymcc[j];
                                        for(int k = pointer;k < 10000;k ++)
                                        {
                                                if(Jhc[j] == w1.Depth[k])
                                                {
                                                        Old.Pos[count] = k;
                                                        pointer = k;
                                                        break;
                                                }
                                        }
                                        Old.UnitName[Old.UnitCount] = ts;
                                        Old.Depth[Old.UnitCount] = StrToFloat(Dydsc[j]);
                                        Old.UnitCount ++;
                                }
                            }
                        }
                        //目标井层位结构体写入
                        else if(flag073 == "T")
                        {
                            for(int j = 0;j <= ia - 1;j ++)
                            {
                                if(Yczmcc[j] != NULL && Yczmcc[j] + Dymcc[j]  != ts && Dydsc[j] != "0" && Dydsc[j] != ts && Dydsc[j] != NULL)
                                {
                                        ts = Yczmcc[j] + Dymcc[j];
                                        for(int k = pointer;k < 10000;k ++)
                                        {
                                                if(Jhc[j] == w1.Depth[k])
                                                {
                                                        New.Pos[count] = k;
                                                        pointer = k;
                                                        break;
                                                }
                                        }
                                        New.UnitName[New.UnitCount] = ts;
                                        New.Depth[New.UnitCount] = StrToFloat(Dydsc[j]);
                                        New.UnitCount ++;
                                }
                            }
                        }
                }
                Table1->First();
                Table1->Close();
                fclose(fc);
        }


   }


}
//---------------------------------------------------------------------------
void Func2()
{

}
//---------------------------------------------------------------------------
float Euclidean(float dep,int rag)
{
   float Operate1[200],Operate2[200];
   float Operate1X[200],Operate2X[200];
   float Operate1Z[200],Operate2Z[200];
   float Operate1U[200],Operate2U[200];
   float Operate1V[200],Operate2V[200];
   float Result[10000];
   //int Range = 40;
   int Range = rag;
   int temp = 0;
   int Pos1 = 0;
   for(int j = 0;j < 1000;j ++)
        Result[j] = 999;
   //在W1中找到对应深度点Pos1
   float td = dep;
   for(int t = 0;t < w1.Number;t ++)
   {
        if(td == w1.Depth[t] || (w1.Depth[t] - td < 0.03 && w1.Depth[t] - td >= 0))
        {
                Pos1 = t;
                break;
        }
   }
   for(int i = Pos1 - Range;i < Pos1 + Range;i ++)
   {
                Operate1[temp] = w1.GR[i];
                Operate1Z[temp] = w1.HAC[i];
                Operate1U[temp] = w1.RXO[i];
                Operate1V[temp] = w1.RMN[i];
                Operate1X[temp] = temp;
                temp ++;
   }
   //操作数组1归一化
   float tmax1 = -9999,tmax1Z = -9999,tmax1U = -9999,tmax1V = -9999;
   float tmin1 = 9999,tmin1Z = 9999,tmin1U = 9999,tmin1V = 9999;
   for(int i = 0;i < 2*Range;i ++)
   {
        if(Operate1[i] > tmax1)         tmax1 = Operate1[i];
        if(Operate1Z[i] > tmax1Z)       tmax1Z = Operate1Z[i];
        if(Operate1U[i] > tmax1U)       tmax1U = Operate1U[i];
        if(Operate1V[i] > tmax1V)       tmax1V = Operate1V[i];
        if(Operate1[i] < tmin1)         tmin1 = Operate1[i];
        if(Operate1Z[i] < tmin1Z)       tmin1Z = Operate1Z[i];
        if(Operate1U[i] < tmin1U)       tmin1U = Operate1U[i];
        if(Operate1V[i] < tmin1V)       tmin1V = Operate1V[i];
   }
   for(int i = 0;i < 2*Range;i ++)
   {
        Operate1[i] = (Operate1[i] - tmin1)/(tmax1 - tmin1);
        Operate1Z[i] = (Operate1Z[i] - tmin1Z)/(tmax1Z - tmin1Z);
        Operate1U[i] = (Operate1U[i] - tmin1U)/(tmax1U - tmin1U);
        Operate1V[i] = (Operate1V[i] - tmin1V)/(tmax1V - tmin1V);
   }

   int top = 200;
   int bottom = w2.Number - 100;
   //
   for(int i = top;i < bottom;i ++)
   {
        float dist = 0;
        float tempmin[200];
        float tempmax[200];
        for(int j = 0;j < 200;j ++)
        {
            tempmin[j] = 0;
            tempmax[j] = 0;
        }
        int temp = 0;
        float X1 = 0,Y1 = 0,Z1 = 0,U1 = 0,V1 = 0,X2 = 0,Y2 = 0,Z2 = 0,U2 = 0,V2 = 0,dX = 0,dY = 0,dZ = 0,dU = 0,dV = 0;
        for(int j = i - Range;j < i + Range;j ++)
        {
                Operate2[temp] = w2.GR[j];
                Operate2Z[temp] = w2.HAC[j];
                Operate2U[temp] = w2.RXO[j];
                Operate2V[temp] = w2.RMN[j];
                Operate2X[temp] = temp;
                temp ++;
        }
        //操作数组2归一化
        float tmax2 = -9999,tmax2Z = -9999,tmax2U = -9999,tmax2V = -9999;
        float tmin2 = 9999,tmin2Z = 9999,tmin2U = 9999,tmin2V = 9999;
        for(int q = 0;q < 2*Range;q ++)
        {
            if(Operate2[q] > tmax2)     tmax2 = Operate2[q];
            if(Operate2Z[q] > tmax2Z)   tmax2Z = Operate2Z[q];
            if(Operate2U[q] > tmax2U)   tmax2U = Operate2U[q];
            if(Operate2V[q] > tmax2V)   tmax2V = Operate2V[q];
            if(Operate2[q] < tmin2)     tmin2 = Operate2[q];
            if(Operate2Z[q] < tmin2Z)   tmin2Z = Operate2Z[q];
            if(Operate2U[q] < tmin2U)   tmin2U = Operate2U[q];
            if(Operate2V[q] < tmin2V)   tmin2V = Operate2V[q];
        }

        for(int q = 0;q < 2*Range;q ++)
        {
            Operate2[q] = (Operate2[q] - tmin2)/(tmax2 - tmin2);
            Operate2Z[q] = (Operate2Z[q] - tmin2Z)/(tmax2Z - tmin2Z);
            Operate2U[q] = (Operate2U[q] - tmin2U)/(tmax2U - tmin2U);
            Operate2V[q] = (Operate2V[q] - tmin2V)/(tmax2V - tmin2V);
        }
        //

        dist = -1;
        if(CtrlValue.LineGroup == "HAC+RMN" || CtrlValue.LineGroup == "RMN+HAC")
        {
            for(int k = 0;k < 2*Range;k ++)
            {
                X1 = Operate1X[k];Y1 = Operate1[k];Z1 = Operate1Z[k];U1 = Operate1U[k];V1 = Operate1V[k];
                X2 = Operate2X[k];Y2 = Operate2[k];Z2 = Operate2Z[k];U2 = Operate2U[k];V2 = Operate2V[k];
                dZ = (Z1 - Z2)*(Z1 - Z2);
                dV = (V1 - V2)*(V1 - V2);
                dist =  dZ * dV;
                tempmin[k] = dist*NormalDistribution((Range - k)*3/Range);
            }
        }
        else if(CtrlValue.LineGroup == "GR+HAC" || CtrlValue.LineGroup == "HAC+GR")
        {
            for(int k = 0;k < 2*Range;k ++)
            {
                X1 = Operate1X[k];Y1 = Operate1[k];Z1 = Operate1Z[k];U1 = Operate1U[k];V1 = Operate1V[k];
                X2 = Operate2X[k];Y2 = Operate2[k];Z2 = Operate2Z[k];U2 = Operate2U[k];V2 = Operate2V[k];
                dY = (Y1 - Y2)*(Y1 - Y2);
                dZ = (Z1 - Z2)*(Z1 - Z2);
                dist =  dY * dZ;
                tempmin[k] = dist*NormalDistribution((Range - k)*3/Range);
            }
        }
        else if(CtrlValue.LineGroup == "RXO+RMN" || CtrlValue.LineGroup == "RMN+RXO")
        {
            for(int k = 0;k < 2*Range;k ++)
            {
                X1 = Operate1X[k];Y1 = Operate1[k];Z1 = Operate1Z[k];U1 = Operate1U[k];V1 = Operate1V[k];
                X2 = Operate2X[k];Y2 = Operate2[k];Z2 = Operate2Z[k];U2 = Operate2U[k];V2 = Operate2V[k];
                dU = (U1 - U2)*(U1 - U2);
                dV = (V1 - V2)*(V1 - V2);
                dist =  dU * dV;
                tempmin[k] = dist*NormalDistribution((Range - k)*3/Range);
            }
        }
        else if(CtrlValue.LineGroup == "RXO+GR" || CtrlValue.LineGroup == "GR+RXO")
        {
            for(int k = 0;k < 2*Range;k ++)
            {
                X1 = Operate1X[k];Y1 = Operate1[k];Z1 = Operate1Z[k];U1 = Operate1U[k];V1 = Operate1V[k];
                X2 = Operate2X[k];Y2 = Operate2[k];Z2 = Operate2Z[k];U2 = Operate2U[k];V2 = Operate2V[k];
                dY = (Y1 - Y2)*(Y1 - Y2);
                dU = (U1 - U2)*(U1 - U2);
                dist =  dU * dY;
                tempmin[k] = dist*NormalDistribution((Range - k)*3/Range);
            }
        }
        else if(CtrlValue.LineGroup == "RMN+GR" || CtrlValue.LineGroup == "GR+RMN")
        {
            for(int k = 0;k < 2*Range;k ++)
            {
                X1 = Operate1X[k];Y1 = Operate1[k];Z1 = Operate1Z[k];U1 = Operate1U[k];V1 = Operate1V[k];
                X2 = Operate2X[k];Y2 = Operate2[k];Z2 = Operate2Z[k];U2 = Operate2U[k];V2 = Operate2V[k];
                dY = (Y1 - Y2)*(Y1 - Y2);
                dV = (V1 - V2)*(V1 - V2);
                dist =  dV * dY;
                tempmin[k] = dist*NormalDistribution((Range - k)*3/Range);
            }
        }
        else
        {
            for(int k = 0;k < 2*Range;k ++)
            {
                X1 = Operate1X[k];Y1 = Operate1[k];Z1 = Operate1Z[k];U1 = Operate1U[k];V1 = Operate1V[k];
                X2 = Operate2X[k];Y2 = Operate2[k];Z2 = Operate2Z[k];U2 = Operate2U[k];V2 = Operate2V[k];
                dX = (X1 - X2)*(X1 - X2);
                dY = (Y1 - Y2)*(Y1 - Y2);
                dZ = (Z1 - Z2)*(Z1 - Z2);
                dU = (U1 - U2)*(U1 - U2);
                dV = (V1 - V2)*(V1 - V2);
                dist =  dY * dZ;
                tempmin[k] = dist*NormalDistribution((Range - k)*3/Range);
            }
        }
        float tmin = 0;
        for(int m = 0;m < 2*Range;m ++)
                tmin += tempmin[m];
        Result[i - top] = tmin;

   }

   float tempf = 9999999 + Result[0];
   int p = 0;
   DistValue = 0;
   for(int i = 0;i < bottom - top;i ++)
   {


        if(Result[i] < tempf && Result[i] > 0)
        {
                if(TempNumber >= 1)
                {
                        float SDist = StandardValue[TempNumber] - StandardValue[TempNumber - 1];
                        float QDist = StandardValue[TempNumber + 1] - StandardValue[TempNumber - 1];
                        //if(w2.Depth[i + top] < LastDepth + SDist + 20 && w2.Depth[i + top] > LastDepth + SDist - 20 && w2.Depth[i + top] > LastDepth + 0.5)
                        if(TOP*BOT > 0)
                        {
                                if(w2.Depth[i + top] < BOT && w2.Depth[i + top] > TOP)
                                {
                                        tempf = Result[i];
                                        p = i;
                                }

                        }
                        else
                        {
                                if(w2.Depth[i + top] < LastDepth + QDist*0.8 && w2.Depth[i + top] > LastDepth + SDist*0.3)
                                {
                                        tempf = Result[i];
                                        p = i;
                                }
                        }
                }
                if(TempNumber == 0 && LastDepth < 100)
                {
                        float rxovalue = 0;
                        for(int k = 0;k < 5;k ++)
                                rxovalue += w2.RXO[i + top + k - 2];

                        if(w2.Depth[i + top] < 1050)
                        //if(w2.Depth[i + top] < 1100 && w2.Depth[i + top] > 900 && rxovalue/5 > 20)
                        {
                                if(SentResult[0] > 100 && w2.Depth[i + top] < SentResult[0] + 5 && w2.Depth[i + top] > SentResult[0] - 5)
                                {
                                        tempf = Result[i];
                                        p = i;
                                }
                                else if(SentResult[0] < 100)
                                {
                                        tempf = Result[i];
                                        p = i;
                                }
                        }
                }
        }
   }

   float ResultDepth = w2.Depth[p + top];
   LastDepth = ResultDepth;
   DistValue = (10000*tempf)/Range;

   return ResultDepth;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn6Click(TObject *Sender)
{
   Well_Name_1.SetLength(Well_Name_1.Length()-3);
   Well_Name_2.SetLength(Well_Name_2.Length()-3);
   daa073_auto_open_path = DBF073_path;
   BitBtn9Click(Sender);
   //BitBtn8Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn9Click(TObject *Sender)
{
   FILE *fp, *fp2;
   String WellNameList[1000];
   int Task = 0;
   float ResultTri[1000][3];
   //
   Task = 1;//任务数=1

   //

   for(int i = 0;i < Task;i ++)

   {
        Reset2();//重置新井变量
        BitBtn2Click(Sender);//读取新井
        JCResult = 0;//是否识别JC层
        flag073 = "T";
        OpenDBS();
        //
        ResultList[i].WellName = Well_Name_2;
        TEMP = i;
        ResultList[TEMP].Group_Count = 0;
        if(Well_Name_2 != "" && Well_Name_2 != NULL)
                SelectWell();//筛选/////////////////////////////////////////////
        //计算
        Selected[0] = Well_Name_1;
        CtrlValue.LineGroup = "GR+HAC";
        CtrlValue.StandardGroup = "1";
        for(int j = 0;j < SelCount;j ++)        //SelCount个数
        {
                if(j == 0)
                        CtrlValue.LineGroup = "GR+RXO";
                else
                        CtrlValue.LineGroup = "GR+HAC";
                Reset1();
                Well_Name_1 = Selected[j];//////////////////////////////////////
                BitBtn1Click(Sender);
                flag073 = "S";
                   OpenDBS073();
                //
                if(LAfound == 0)
                        continue;
                //
                Func();
                //

                float TempFinDepth[200][10];
                if(GroupCount >= 3)
                {
                        for(int m = 0;m < 200;m ++)
                        {
                                String TName = ResultGroup[0].UnitName[m];
                                {
                                        for(int n = 0;n < 3;n ++)
                                        {
                                                TempFinDepth[m][n] = ResultGroup[0].ResultDepth[m][n];
                                        }
                                }
                                for(int m2 = 0;m2 < 200;m2 ++)
                                {
                                        if(ResultGroup[1].UnitName[m2] == TName)
                                        {
                                                for(int n = 0;n < 3;n ++)
                                                {
                                                        TempFinDepth[m][3 + n] = ResultGroup[1].ResultDepth[m][n];
                                                }
                                                break;
                                        }
                                }
                                for(int m3 = 0;m3 < 200;m3 ++)
                                {
                                        if(ResultGroup[2].UnitName[m3] == TName)
                                        {
                                                for(int n = 0;n < 3;n ++)
                                                {
                                                        TempFinDepth[m][6 + n] = ResultGroup[2].ResultDepth[m][n];
                                                }
                                                break;
                                        }
                                }

                        }
                        for(int m = 0;m < 200;m ++)
                        {
                                FinUnitName[m] = ResultGroup[0].UnitName[m];
                        }
                        for(int m = 0;m < 200;m ++)
                        {
                                int count = 0;
                                int count3 = 3;
                                for(int n = 0;n < 10;n ++)
                                {
                                        count = 0;
                                        if(TempFinDepth[m][n] > 100 && SentResult[m] < 100)
                                        //if(TempFinDepth[m][n] > 100)
                                        {

                                                float tempdepth = TempFinDepth[m][n];
                                                for(int p = 0;p < 10;p ++)
                                                {
                                                        if(p != n && TempFinDepth[m][p] > 100 && fabs(TempFinDepth[m][p] - TempFinDepth[m][n]) < 0.5)
                                                                count ++;
                                                }
                                                if(count > count3)
                                                {
                                                        count3 = count;
                                                        FinDepth[m] = TempFinDepth[m][n];
                                                        //break;
                                                }
                                        }

                                }

                        }
                        /*
                        int LastTemp = 0;
                        for(int i = 200;i < 1;i --)
                        {
                                if(zzppsd[i] < 100)
                                {
                                        LastTemp = i;
                                        break;
                                }

                        }
                        for(int i = 0;i < LastTemp;i ++)
                        {
                                if(zzppsd[i] < 100 && FinDepth[i] > 100)
                                        zzppsd[i] = FinDepth[i];
                        }
                        */
                        //paintfencengnew(Sender);
                        FinDepth[200] = 0;
                        break;

                                                }
        }
   }

}
//---------------------------------------------------------------------------
void Func()
{
   int range = 30;

   float result[200][5];
   float resultValue[200][5];


   for(int i = 0;i < 10;i ++)
   {
        for(int j = 0;j < 5;j ++)
        resultValue[i][j] = 999;
   }
   //

   for(int i = 0;i < 200;i ++)
        StandardUnitName[i] = NULL;
        SearchStandard();//导入标准层
   //int StandardNum = 5;
   //
   int temp = 0;
   LastDepth = 0;
   temp = 0;

   for(int i = 0;i < StandardNum;i ++)
   {
        TempNumber = i;
        TOP = 0;
        BOT = 0;
        if(i > 0 && SentResult[i + 1] > 100 && SentResult[i - 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i - 1] + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        else if(i > 0 && SentResult[i + 1] <= 100 && SentResult[i - 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i - 1] + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i - 1] + (StandardValue[i + 1] - StandardValue[i - 1]) - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        else if(i > 0 && SentResult[i - 1] <= 100 && SentResult[i + 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i - 1]) + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        result[i][0] = Euclidean(StandardValue[i],range);
        resultValue[i][0] = DistValue;
   }
   //
   LastDepth = 0;
   range = 50;
   temp = 0;
   for(int i = 0;i < StandardNum;i ++)
   {
        TempNumber = i;
        TOP = 0;
        BOT = 0;
        if(i > 0 && SentResult[i + 1] > 100 && SentResult[i - 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i - 1] + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        else if(i > 0 && SentResult[i + 1] <= 100 && SentResult[i - 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i - 1] + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i - 1] + (StandardValue[i + 1] - StandardValue[i - 1]) - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        else if(i > 0 && SentResult[i - 1] <= 100 && SentResult[i + 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i - 1]) + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        result[i][1] = Euclidean(StandardValue[i],range);
        resultValue[i][1] = DistValue;
   }

   LastDepth = 0;
   range = 70;
   temp = 0;
   Drop = 0;
   float MinDist[200];
   for(int i = 0;i < StandardNum;i ++)
   {
        TempNumber = i;
        TOP = 0;
        BOT = 0;
        if(i > 0 && SentResult[i + 1] > 100 && SentResult[i - 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i - 1] + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        else if(i > 0 && SentResult[i + 1] <= 100 && SentResult[i - 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i - 1] + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i - 1] + (StandardValue[i + 1] - StandardValue[i - 1]) - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        else if(i > 0 && SentResult[i - 1] <= 100 && SentResult[i + 1] > 100 && SentResult[i] < 100)
        {
                TOP = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i - 1]) + (StandardValue[i] - StandardValue[i - 1])*0.5;
                BOT = SentResult[i + 1] - (StandardValue[i + 1] - StandardValue[i])*0.5;
        }
        result[i][2] = Euclidean(StandardValue[i],range);
        resultValue[i][2] = DistValue;
        //取3次结果距离最小值
        float fd = 999;
        for(int m = 0;m < 3;m ++)
        {

                if(resultValue[i][m] < fd)
                {
                        fd = resultValue[temp][m];
                        MinDist[i] = result[i][m];
                }
        }
        //Memo2->Lines->Add(result[i][tempint]);
        temp ++;
   }


   //JC层三次计算误差<5
   if(fabs(result[0][0] - result[0][1]) > 2 || fabs(result[0][0] - result[0][2]) > 2 || fabs(result[0][2] - result[0][1]) > 2)
        JCResult = 1;
   else
   {
        for(int i = 0;i < StandardNum;i ++)
        {
                for(int m = 0;m < 3;m ++)
                {
                        ResultGroup[GroupCount].UnitName[i] = StandardUnitName[i];
                        ResultGroup[GroupCount].ResultDepth[i][m] = result[i][m];
                }
        }
        GroupCount ++;

   }
}
//---------------------------------------------------------------------------
float Euclidean_Standard(float dep,int rag)
{

}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenDBS073()
{
   int ia=0,j,i1,i3,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   FILE *fc,*fo;
   AnsiString File_name;
   int path = 0;
   //
   String Jhc[300];
   String Yczmcc[300];
   String Dymcc[300];
   String Bzc[300];
   String Dydsc[300];
   //
   if(daa073_auto_open_path == NULL || daa073_auto_open_path == "")
   {

        OpenDialog1->Filter="daa073(*.DBF)|*.DBF|????(*.*)|*.*";
        OpenDialog1->Execute();
        daa073_auto_open_path = OpenDialog1->Files->Strings[0].c_str();
        File_name = ChangeFileExt(daa073_auto_open_path,"");
        path = 2;
   }

   if(path == 2 || daa073_auto_open_path != NULL)
   {
        for(int I=0;I<1;I++)
        {
                if(flag073 == "S")
                        File_name = Well_Name_1;
                else if(flag073 == "T")
                        File_name = Well_Name_2;
                else
                        break;

                fc = fopen(daa073_auto_open_path.c_str(),_T("r"));
                cc = daa073_auto_open_path.c_str();

                if(fc)
                {
                        Table1->TableName = cc;
                        Table1->Open();
                        Table1->Active=true;
                        Table1->First();
                        //
                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("JH")->AsString;
                                jjhh = LowerCase(jjhh); //
                                if(jjhh == LowerCase(File_name))
                                {
                                        do{
                                                jjhh = Table1->FieldByName("JH")->AsString;
                                                jjhh = LowerCase(jjhh);flag1 = 1;
                                                Jhc[ia]      = Table1->FieldByName("JH")->AsString;      //?????
                                                Yczmcc[ia]   = Table1->FieldByName("YCZMC")->AsString;  //?????
                                                Dymcc[ia]    = Table1->FieldByName("DYMC")->AsString;  //????
                                                Bzc[ia]      = Table1->FieldByName("BZ")->AsString;
                                                Dydsc[ia]    = Table1->FieldByName("DYDS")->AsString;
                                                ia ++;
                                                Table1->Next();
                                        }while((jjhh == LowerCase(File_name))&&(!Table1->Eof));
                                        //totalnum[js]=count-1;
                                }
                                if((flag1<1)&&(!Table1->Eof))
                                        Table1->Next();
                        }
                        Table1->First();
                        //???????
                        String ts = "";
                        float tf = 0;
                        int count = 0;
                        int pointer = 0;
                        //
                        if(flag1 != 1)
                                break;//???,???????
                        //??????????
                        if(flag073 == "S")
                        {
                            for(int j = 0;j <= ia - 1;j ++)
                            {
                                if(Yczmcc[j] != NULL && Yczmcc[j] + Dymcc[j]  != ts && Dydsc[j] != "0" && Dydsc[j] != ts && Dydsc[j] != NULL)
                                {
                                        ts = Yczmcc[j] + Dymcc[j];
                                        for(int k = pointer;k < 10000;k ++)
                                        {
                                                if(Jhc[j] == w1.Depth[k])
                                                {
                                                        Old.Pos[count] = k;
                                                        pointer = k;
                                                        break;
                                                }
                                        }
                                        Old.UnitName[Old.UnitCount] = ts;
                                        Old.Depth[Old.UnitCount] = StrToFloat(Dydsc[j]);
                                        Old.UnitCount ++;
                                }
                            }
                        }
                        //??????????
                        else if(flag073 == "T")
                        {
                            for(int j = 0;j <= ia - 1;j ++)
                            {
                                if(Yczmcc[j] != NULL && Yczmcc[j] + Dymcc[j]  != ts && Dydsc[j] != "0" && Dydsc[j] != ts && Dydsc[j] != NULL)
                                {
                                        ts = Yczmcc[j] + Dymcc[j];
                                        for(int k = pointer;k < 10000;k ++)
                                        {
                                                if(Jhc[j] == w1.Depth[k])
                                                {
                                                        New.Pos[count] = k;
                                                        pointer = k;
                                                        break;
                                                }
                                        }
                                        New.UnitName[New.UnitCount] = ts;
                                        New.Depth[New.UnitCount] = StrToFloat(Dydsc[j]);
                                        New.UnitCount ++;
                                }
                            }
                        }
                }
                Table1->First();
                Table1->Close();
                fclose(fc);
        }


   }


}
//---------------------------------------------------------------------------
void __fastcall TForm1::N111Click(TObject *Sender)
{
   FILE *fp;
   if(DBF055.Length() > 3)
   {
        String A = DBF055;
        String B = DBF055_NEW;
        CopyFile(A.c_str(),B.c_str(),false);

        fp=fopen(B.c_str(),_T("r"));
        if(fp)
        {
                TTable*newTable2;
                newTable2=new TTable(this);
                newTable2->TableName="";             //或者Table1->TableName=cc;
                newTable2->TableType=ttFoxPro;
                newTable2->TableName=B.c_str();
                newTable2->Open();
                DBGrid1->DataSource=DataSource1;
                newTable2->Active=true;
                newTable2->First();
                //newTable2->Edit();
                while(!newTable2->Eof)
                {
                //newTable2->ClearFields();
                        newTable2->Delete();
                }
                ////
                newTable2->First();
                String TS = "";

                //str8[0] = "S11";
                //str8[1] = "S12";
                //str8[2] = "S13";
                //zzppsd[0] = 900;
                //zzppsd[1] = 920;
                //zzppsd[2] = 940;
                for(int i=0;i<300;i++)
                {
                        newTable2->Insert();
                        //String File_name = ChangeFileExt(ccp2,"");
                        //Jhc[i] = UpperCase(File_name).c_str();
                        if(str8[i] != TS && str8[i] != "" && str8[i] != NULL)
                        {
                                newTable2->FieldByName("井号外")->AsString=str8[i];
                                TS = str8[i];
                                newTable2->FieldByName("小层界限外")->Value=FormatFloat("0.0",mbdeep[i]);
                        }
                        else if(str8[i] == "" || str8[i] == NULL)
                        {
                                //newTable->FieldByName("Bz")->AsString="W";
                                break;
                        }
                        newTable2->Next();
                }
                ////

                newTable2->Refresh();
                newTable2->Active=false;
                newTable2->EnableControls();
                newTable2->Close();
        }


   }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::N26Click(TObject *Sender)
{
   dc=0;  //断层
   wincu1=2.4;wincd1=2.5;jdmk=0.3;fdmk=0.3;     //G112a
   Tmbj=1; //ite=1;
   ljcw=0; icount=0; n=6;  //老井层位数
   float ms37=99999.0,mp27a=999999.0,mg110b=999999.0,mg120=9999999.0;
   xzc=0;    //修正开关  0为正常运行   1为调用邻井数据文件
   zdz=999999.0;   //最大值
   open_correct=1;  //校正开关
 //  cjjmkz[0]=2.5;  cjjmkz[1]=6.5;  cjjmkz[2]=3.2;                //层间距门槛值  0萨尔图油层组  1葡萄花油层组   2高台子油层组
     cjjmkz[0]=5.5;  cjjmkz[1]=4.5;  cjjmkz[2]=4.2;               //层间距门槛值  0萨尔图油层组  1葡萄花油层组   2高台子油层组
    // cjjxfmkz[0]=1.8; cjjxfmkz[1]=1.6;cjjxfmkz[2]=1.0;
     cjjxfmkz[0]=0.6; cjjxfmkz[1]=0.6;cjjxfmkz[2]=0.4;
     mbjbzcmkz=0.5;      //目标井标志层门槛值
     mbjxfcmkz=0.15; mbjxfcxzmkz=0.2;  //目标井细分层选择门槛值
   for(int j1=0;j1<ljcgs;j1++)
   {
       ckdeep[j1]=a2[j1][0];
      // PaintBox2->Canvas->TextOutA(60,24+j1*15,ckdeep[j1]);
   }

  //  st[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)-int((ckja2[isname]-start2[isname])/relvc)-int(cjjmkz[itz]/relvc); //-stpinsjk[isname]
 //   en[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjmkz[itz]/relvc);

   ljcw=0;
   lj=0;
   prc=5;             //应用到处理曲线
   AIBZC(Sender);
  /* for(int i1=0;i1<ljcgs;i1++)
   {
      // PaintBox2->Canvas->TextOutA(60,24+i1*15,str6[i1]);
       if((str6[i1]=="JC")||(str6[i1]=="JCJC"))
       {
           lj=i1;
           prc=5;
          // AIBZC(Sender);
           JCxzcorrect(Sender);
           JClj=i1;
          // PaintBox2->Canvas->TextOutA(60,244,"JC= ");
          // PaintBox2->Canvas->TextOutA(120,244,mbdeep[JClj]);
          // PaintBox2->Canvas->TextOutA(120,264,mbJCdeep);
       }
   }  */
   isname=JClj;
   xzc=1;
   JCxzcorrect(Sender);    //JCj夹层修正 2025-7-12日增加
   prc=5;
   mbJCdeep=CDeep[JClj];
   isname=S11lj;
   xzc=1;
   JCxzcorrect(Sender);    //S11判别 2025-7-17日增加
   prc=5;
   mbS11deep=CDeep[S11lj];
   isname=S37lj;
   xzc=1;
   JCxzcorrect(Sender);    //S37判别 2025-7-17日增加
   prc=5;
   mbS37deep=CDeep[S37lj];
   isname=P27alj;
   xzc=1;
   JCxzcorrect(Sender);    //P27a判别 2025-7-17日增加
   prc=5;
   mbP27adeep=CDeep[P27alj];
   isname=G110blj;
   xzc=1;
   JCxzcorrect(Sender);    //G110b判别 2025-7-17日增加
   prc=5;
   mbG110bdeep=CDeep[G110blj];
   isname=G120lj;
   xzc=1;
   JCxzcorrect(Sender);    //G120判别 2025-7-17日增加
   prc=5;
   mbG120deep=CDeep[G120lj];
   

             /* PaintBox2->Canvas->TextOutA(420,204,mbdeep[S11lj]);
              PaintBox2->Canvas->TextOutA(420,224,mbS11deep);
              PaintBox2->Canvas->TextOutA(420,244,mbdeep[JClj]);
              PaintBox2->Canvas->TextOutA(420,264,mbJCdeep);   */
   xzc=0;    //修正开关  0为正常运行   1为调用邻井数据文件
   zdz=999999.0;   //最大值
   zdzS37=0.0;
   open_correct=1;  //校正开关
   itz=0;             //油层组标识
   xzkg=2;
 for(int l0=0;l0<ljcgs;l0++)    //2022-2-9早上修改  <  换成  <=
 {
    if(str6[l0]=="P11b")
    {
       P11blj=l0;
    }
    if(str6[l0]=="G11")
    {
       G11lj=l0;
    }
 }
 //  PaintBox2->Canvas->TextOutA(20+54,14,JClj);
            /*  PaintBox2->Canvas->TextOutA(420,204,mbdeep[S11lj]);
              PaintBox2->Canvas->TextOutA(420,224,mbS11deep);
              PaintBox2->Canvas->TextOutA(420,244,mbdeep[JClj]);
              PaintBox2->Canvas->TextOutA(420,264,mbJCdeep); */

   for(lj=0;lj<ljcgs;lj++)
   {

       if(lj<P11blj)
       {
           itz=0;     //油层组标识
       }
       else if((lj>P11blj)&&(lj<G11lj))
       {
           itz=1;    //油层组标识
       }
       else  if(lj>=G11lj)
       {
           itz=2;     //油层组标识
       }
            /*  PaintBox2->Canvas->TextOutA(420,104,mbdeep[S11lj]);
              PaintBox2->Canvas->TextOutA(420,124,mbS11deep);
              PaintBox2->Canvas->TextOutA(420,144,mbdeep[JClj]);
              PaintBox2->Canvas->TextOutA(420,164,mbJCdeep);  */
      if((lj>S11lj)&&(lj<JClj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[S11lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[S11lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[JClj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[JClj];
          ckjdjxlc[lj]=ckdeep[JClj]-ckdeep[lj];         //参考井底界限落差
        //  ckcwlj=S11lj;     //参考层位
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
        /*  if(str6[lj]=="S13")
          {
             PaintBox2->Canvas->TextOutA(520,14,"S13=");
             PaintBox2->Canvas->TextOutA(520+54,14,mbdeep[lj]);
          } */
        /*  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             open_correct=1;  //校正开关
             ckjcjlcxz[lj]=ckjcjlcxfc[lj];             //参考井层间落差细分层
             mbjdcjx[lj]=mbjckcw[lj];       //目标井顶层界限
             isname=lj;
             sname=str6[lj];
             xzc=1;
             ljsjkxfccorrect(Sender);    //邻井数据库细分层修正
             mbdeep[lj]=CDeep[isname];
          }    */
      }
           /*   PaintBox2->Canvas->TextOutA(420,204,mbdeep[S11lj]);
              PaintBox2->Canvas->TextOutA(420,224,mbS11deep);
              PaintBox2->Canvas->TextOutA(420,244,mbdeep[JClj]);
              PaintBox2->Canvas->TextOutA(420,264,mbJCdeep);  */
      if((lj>JClj)&&(lj<S37lj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[JClj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[JClj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[S37lj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[S37lj];
          ckjdjxlc[lj]=ckdeep[S37lj]-ckdeep[lj];         //参考井底界限落差
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
        /*  if(str6[lj]=="S222+3b")
          {
             PaintBox2->Canvas->TextOutA(30,34,"1S222+3b="+str6[lj]);
             PaintBox2->Canvas->TextOutA(100+54,34,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(100+54,54,mbdeepc[lj]);
             PaintBox2->Canvas->TextOutA(100+54,74,CDeep[lj]);
          }   */

        /*  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             open_correct=1;  //校正开关
             ckjcjlcxz[lj]=ckjcjlcxfc[lj];             //参考井层间落差细分层
             mbjdcjx[lj]=mbjckcw[lj];       //目标井顶层界限
             isname=lj;
             sname=str6[lj];
             xzc=1;
             ljsjkxfccorrect(Sender);    //邻井数据库细分层修正
             mbdeep[lj]=CDeep[isname];
          }  */
      }
            /*  PaintBox2->Canvas->TextOutA(420,204,mbdeep[S11lj]);
              PaintBox2->Canvas->TextOutA(420,224,mbS11deep);
              PaintBox2->Canvas->TextOutA(420,244,mbdeep[JClj]);
              PaintBox2->Canvas->TextOutA(420,264,mbJCdeep); */
      if((S37lj>1)&&(P27alj>S37lj)&&(lj>S37lj)&&(lj<P27alj))   // if((lj>S37lj)&&(lj<P27alj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[S37lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[S37lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[P27alj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[P27alj];
          ckjdjxlc[lj]=ckdeep[P27alj]-ckdeep[lj];         //参考井底界限落差
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
        /*  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             open_correct=1;  //校正开关
             ckjcjlcxz[lj]=ckjcjlcxfc[lj];             //参考井层间落差细分层
             mbjdcjx[lj]=mbjckcw[lj];       //目标井顶层界限
             isname=lj;
             sname=str6[lj];
             xzc=1;
             ljsjkxfccorrect(Sender);    //邻井数据库细分层修正
             mbdeep[lj]=CDeep[isname];
          }   */
      }
      else if((S37lj>1)&&(P27alj<S37lj)&&(lj>S37lj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[S37lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[S37lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[S37lj]+(ckdeep[ljcgs-1]-ckdeep[S37lj]);                   //目标井底界限
          ckjdjx[lj]=ckdeep[ljcgs-1];
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
      }
      if((P27alj>1)&&(G110blj>P27alj)&&(lj>P27alj)&&(lj<G110blj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[P27alj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[P27alj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G110blj];                   //目标井底界限
          ckjdjxlc[lj]=ckdeep[G110blj]-ckdeep[lj];         //参考井底界限落差
          ckjdjx[lj]=ckdeep[G110blj];
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
        /*  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             open_correct=1;  //校正开关
             ckjcjlcxz[lj]=ckjcjlcxfc[lj];             //参考井层间落差细分层
             mbjdcjx[lj]=mbjckcw[lj];       //目标井顶层界限
             isname=lj;
             sname=str6[lj];
             xzc=1;
             ljsjkxfccorrect(Sender);    //邻井数据库细分层修正
             mbdeep[lj]=CDeep[isname];
          }   */
      }
      else if((P27alj>1)&&(G110blj<1)&&(lj>P27alj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[P27alj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[P27alj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[P27alj]+(ckdeep[ljcgs-1]-ckdeep[P27alj]);                   //目标井底界限
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          ckjdjx[lj]=ckdeep[ljcgs-1];
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
      }
      if((G110blj>1)&&(G120lj>G110blj)&&(lj>G110blj)&&(lj<G120lj))   // if((lj>G110blj)&&(lj<G120lj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[G110blj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[G110blj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G120lj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[G120lj];
          ckjdjxlc[lj]=ckdeep[G120lj]-ckdeep[lj];         //参考井底界限落差
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
        /*  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             open_correct=1;  //校正开关
             ckjcjlcxz[lj]=ckjcjlcxfc[lj];             //参考井层间落差细分层
             mbjdcjx[lj]=mbjckcw[lj];       //目标井顶层界限
             isname=lj;
             sname=str6[lj];
             xzc=1;
             ljsjkxfccorrect(Sender);    //邻井数据库细分层修正
             mbdeep[lj]=CDeep[isname];
          }     */
      }
      else if((G110blj>1)&&(G120lj<1)&&(lj>G110blj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[G110blj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[G110blj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G110blj]+(ckdeep[ljcgs-1]-ckdeep[G110blj]);                    //目标井底界限
          ckjdjx[lj]=ckdeep[ljcgs-1];
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
      }
      if((lj>G120lj)&&(G120lj>1))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[G120lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[G120lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G120lj]+(ckdeep[ljcgs-1]-ckdeep[G120lj]);                   //目标井底界限
          ckjdjx[lj]=ckdeep[ljcgs-1];
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          XFC(Sender);
          mbdeepc[lj]=mbdeep[lj];
        /*  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             open_correct=1;  //校正开关
             ckjcjlcxz[lj]=ckjcjlcxfc[lj];             //参考井层间落差细分层
             mbjdcjx[lj]=mbjckcw[lj];       //目标井顶层界限
             isname=lj;
             sname=str6[lj];
             xzc=1;
             ljsjkxfccorrect(Sender);    //邻井数据库细分层修正
             mbdeep[lj]=CDeep[isname];
          }   */
      }

   }
  //  PaintBox2->Canvas->TextOutA(454,24,G110blj);
  //  PaintBox2->Canvas->TextOutA(500+54,24,G120lj);
    for(int iw=0;iw<ljcgs;iw++)
    {
       mbdeepc[iw]=mbdeep[iw];
    }
//   由底界面向上判别

 /*  for(lj=0;lj<ljcgs;lj++)
   {
       if(lj<P11blj)
       {
           itz=0;     //油层组标识
           mbjcjjzxz[itz]=0.6;        //目标井层间距最小值
       }
       else if((lj>P11blj)&&(lj<G11lj))
       {
           itz=1;    //油层组标识
           mbjcjjzxz[itz]=0.5;       //目标井层间距最小值
       }
       else  if(lj>=G11lj)
       {
           itz=2;     //油层组标识
           mbjcjjzxz[itz]=0.3;        //目标井层间距最小值
       }  */
      /* if(str6[lj]=="S32b")
          {
             PaintBox2->Canvas->TextOutA(100,34,"1S32b=");
             PaintBox2->Canvas->TextOutA(100+54,34,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(154,54,str6[lj]);
             PaintBox2->Canvas->TextOutA(154,74,fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj])));
             PaintBox2->Canvas->TextOutA(154,94,mbdeep[lj]-mbjckcw[lj]);
             PaintBox2->Canvas->TextOutA(100+54,114,mbdeepc[lj]);
          }   */
  //   if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
 /*    {

      if((lj>S11lj)&&(lj<JClj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[S11lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[S11lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[JClj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[JClj];                      //参考井底界限
          ckjdjxlc[lj]=ckdeep[JClj]-ckdeep[lj];         //参考井底界限落差
        //  ckcwlj=S11lj;     //参考层位
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])   // if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
              XFCPearsonSYTD(Sender);
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }    */
         // CDeep[lj]=mbdeep[lj];
       /*  if(str6[lj]=="S26")
          {
             PaintBox2->Canvas->TextOutA(200,334,"2S26=");
             PaintBox2->Canvas->TextOutA(220+54,334,mbdeep[lj]);
          }     */
   /*   }
      if((lj>JClj)&&(lj<S37lj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[JClj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[JClj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[S37lj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[S37lj];                      //参考井底界限
          ckjdjxlc[lj]=ckdeep[S37lj]-ckdeep[lj];  */       //参考井底界限落差
         /* if(str6[lj]=="S222+3b")
          {
            PaintBox2->Canvas->TextOutA(20,14+(lj-1)*12,str6[lj]);
            PaintBox2->Canvas->TextOutA(20+74,14+(lj-1)*12,ckjcjlcxfc[lj]);
            PaintBox2->Canvas->TextOutA(190+74,14+(lj-1)*12,fabs(ckdeep[lj]));
            PaintBox2->Canvas->TextOutA(390+74,14+(lj-1)*12,fabs(mbjckcw[lj]));
            PaintBox2->Canvas->TextOutA(590+74,14+(lj-1)*12,fabs(mbdeep[lj]));
          }*/
      /*    if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])   // if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
              XFCPearsonSYTD(Sender);
          }
          if((fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])&&(mbdeep[lj]>mbdeep[lj-1]))
          {
              mbdeepc[lj]=mbdeep[lj];
          }   */
        /*  if(str6[lj]=="S26")
          {
             PaintBox2->Canvas->TextOutA(200,334,"2S26=");
             PaintBox2->Canvas->TextOutA(220+54,334,mbdeep[lj]);
          }    */
  /*    }

      if((lj>S37lj)&&(lj<P27alj)&&(P27alj>S37lj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[S37lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[S37lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[P27alj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[P27alj];
          ckjdjxlc[lj]=ckdeep[P27alj]-ckdeep[lj];         //参考井底界限落差
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])      // if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             XFCPearsonSYTD(Sender);
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }   */
                 /*  if(str6[lj]=="S310b")
                   {
                       PaintBox2->Canvas->TextOutA(330,14+prc*120,prc);
                       PaintBox2->Canvas->TextOutA(380,14+prc*120,mbdeep[lj]);
                       PaintBox2->Canvas->TextOutA(480,14+prc*120,str6[lj]);
                      // PaintBox2->Canvas->TextOutA(280,14+prc*120,deep[1]);

                   }   */
   /*   }
      else if((lj>S37lj)&&(lj<P27alj)&&(P27alj<S37lj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[S37lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[S37lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[S37lj]+(ckdeep[ljcgs-1]-ckdeep[S37lj]);                   //目标井底界限
          ckjdjx[lj]=ckdeep[ljcgs-1];
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])    // if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             XFCPearsonSYTD(Sender);
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }   */
                 /*  if(str6[lj]=="S310b")
                   {
                       PaintBox2->Canvas->TextOutA(330,14+prc*120,prc);
                       PaintBox2->Canvas->TextOutA(380,14+prc*120,mbdeep[lj]);
                       PaintBox2->Canvas->TextOutA(480,14+prc*120,str6[lj]);
                      // PaintBox2->Canvas->TextOutA(280,14+prc*120,deep[1]);

                   }   */
   /*   }

      if((lj>P27alj)&&(lj<G110blj)&&(G110blj>P27alj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[P27alj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[P27alj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G110blj];                   //目标井底界限
          ckjdjxlc[lj]=ckdeep[G110blj]-ckdeep[lj];         //参考井底界限落差
          ckjdjx[lj]=ckdeep[G110blj];
         if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])
         // if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
              XFCPearsonSYTD(Sender);
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }   */
                /*   if(str6[lj]=="G16+7a")
                   {
                       PaintBox2->Canvas->TextOutA(30,14+prc*120,prc);
                       PaintBox2->Canvas->TextOutA(80,14+prc*120,mbdeep[lj]);
                       PaintBox2->Canvas->TextOutA(180,14+prc*120,str6[lj]);
                      // PaintBox2->Canvas->TextOutA(280,14+prc*120,deep[1]);

                   }   */
  /*    }
      else if((lj>P27alj)&&(lj<G110blj)&&(G110blj<P27alj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[P27alj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[P27alj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[P27alj]+(ckdeep[ljcgs-1]-ckdeep[P27alj]);                   //目标井底界限
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          ckjdjx[lj]=ckdeep[ljcgs-1];
         if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])
         // if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
              XFCPearsonSYTD(Sender);
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }   */
                /*   if(str6[lj]=="G16+7a")
                   {
                       PaintBox2->Canvas->TextOutA(30,14+prc*120,prc);
                       PaintBox2->Canvas->TextOutA(80,14+prc*120,mbdeep[lj]);
                       PaintBox2->Canvas->TextOutA(180,14+prc*120,str6[lj]);
                      // PaintBox2->Canvas->TextOutA(280,14+prc*120,deep[1]);

                   }   */
 /*     }

      if((lj>G110blj)&&(lj<G120lj)&&(G120lj>G110blj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[G110blj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[G110blj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G120lj];                   //目标井底界限
          ckjdjx[lj]=ckdeep[G120lj];
          ckjdjxlc[lj]=ckdeep[G120lj]-ckdeep[lj];         //参考井底界限落差
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])
        //  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
              XFCPearsonSYTD(Sender);
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }

      }
      else if((lj>G110blj)&&(lj<G120lj)&&(G120lj<G110blj))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[G110blj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[G110blj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G110blj]+(ckdeep[ljcgs-1]-ckdeep[G110blj]);                   //目标井底界限
          ckjdjx[lj]=ckdeep[ljcgs-1];
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])
        //  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
              XFCPearsonSYTD(Sender);
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }
      }
      if((lj>G120lj)&&(G120lj>1))
      {
          sname=str6[lj];
          isname=lj;
          ckjcjlcxfc[lj]=ckdeep[lj]-ckdeep[G120lj];         //参考井层间落差
          mbjckcw[lj]=mbdeep[G120lj];                  //目标井参考层位
          mbjdjx[lj]=mbdeep[G120lj]+(ckdeep[ljcgs-1]-ckdeep[G120lj]);                   //目标井底界限
          ckjdjx[lj]=ckdeep[ljcgs-1];
          ckjdjxlc[lj]=ckdeep[ljcgs-1]-ckdeep[lj];         //参考井底界限落差
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz])                                      //2025年10月23日注释掉，意义不大
        //  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
          {
             XFCPearsonSYTD(Sender);         //细分层皮尔森时域梯度
          }
          if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz])
          {
              mbdeepc[lj]=mbdeep[lj];
          }
      }
     }
    // PaintBox2->Canvas->TextOutA(20,14+(lj-1)*14,str16[lj]);
    // PaintBox2->Canvas->TextOutA(20+154,14+(lj-1)*14,mbdeep[lj]);

   }  */
  //底界面向上逐层校正
/*  for(int l1=0;l1<ljcgs;l1++)
  {
      mbdeepc[l1]=mbdeep[l1];

  } */
       /*   if(str6[lj]=="S13")
          {
             PaintBox2->Canvas->TextOutA(120,84,"7S13=");
             PaintBox2->Canvas->TextOutA(150+64,84,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(250+94,84,CDeep[lj]);
          }  */
    itz=0;
    for(lj=JClj-1;lj>S11lj;lj--)
    {

        if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
        {
            XFCDJMXZ(Sender);
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
            {
                mbdeepc[lj]=mbdeep[lj];
            }
        }
        /* if(str6[lj]=="S13")
          {
             PaintBox2->Canvas->TextOutA(120,84,"7S13=");
             PaintBox2->Canvas->TextOutA(150+64,84,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(250+94,84,CDeep[lj]);

          }   */

    }
    for(lj=S37lj-1;lj>JClj;lj--)
    {
     /*  if(str6[lj]=="S222+3b")
       {
        PaintBox2->Canvas->TextOutA(20,14+(lj-1)*14,str6[lj]);
        PaintBox2->Canvas->TextOutA(20+154,14+(lj-1)*14,mbdeep[lj]);
        PaintBox2->Canvas->TextOutA(20+354,14+(lj-1)*14,mbdeep[lj+1]);
        }    */
        if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
        {
            XFCDJMXZ(Sender);
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
            {
                mbdeepc[lj]=mbdeep[lj];
            }

         /*   PaintBox2->Canvas->TextOutA(20,14+(lj-1)*14,str16[lj]);
            PaintBox2->Canvas->TextOutA(20+154,14+(lj-1)*14,mbdeep[lj]);
            PaintBox2->Canvas->TextOutA(20+304,14+(lj-1)*14,mbdeep[lj+1]);
            PaintBox2->Canvas->TextOutA(20+454,14+(lj-1)*14,(ckdeep[lj+1]-ckdeep[lj]));
            PaintBox2->Canvas->TextOutA(20+604,14+(lj-1)*14,(mbdeep[lj+1]-mbdeep[lj]));  */
        }
    }
    itz=1;
    if((P27alj>S37lj)&&(S37lj>1))
    {
      for(lj=P27alj-1;lj>S37lj;lj--)
      {

        if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
        {

            XFCDJMXZ(Sender);
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
            {
                mbdeepc[lj]=mbdeep[lj];
            }
        }
      }
    }
    else if((P27alj<1)&&(S37lj>1))
    {
       for(lj=ljcgs-1;lj>S37lj;lj--)
      {

        if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
        {

            XFCDJMXZ(Sender);
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
            {
                mbdeepc[lj]=mbdeep[lj];
            }
        }
      }
    }
    itz=2;
    if((G110blj>P27alj)&&(P27alj>1))
    {
      for(lj=G110blj-1;lj>P27alj;lj--)
      {
          if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
          {
              XFCDJMXZ(Sender);
              if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
              {
                  mbdeepc[lj]=mbdeep[lj];
              }
          }
      }
    }
    else if((G110blj<1)&&(P27alj>1))
    {
       for(lj=ljcgs-1;lj>P27alj;lj--)
      {
          if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
          {
              XFCDJMXZ(Sender);
              if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
              {
                  mbdeepc[lj]=mbdeep[lj];
              }
          }
      }
    }
    if((G120lj>G110blj)&&(G110blj>1))
    {
       for(lj=G120lj-1;lj>G110blj;lj--)
       {
          if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
          {
              XFCDJMXZ(Sender);
              if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
              {
                  mbdeepc[lj]=mbdeep[lj];
              }
          }
       }
    }
    else if((G120lj<1)&&(G110blj>1))
    {
       for(lj=ljcgs-1;lj>G110blj;lj--)
       {
          if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
          {
              XFCDJMXZ(Sender);
              if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
              {
                  mbdeepc[lj]=mbdeep[lj];
              }
          }
       }
    }
    if(G120lj>1)
    {
       for(lj=ljcgs-1;lj>G120lj;lj--)
       {
          if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeepc[lj]))>cjjxfmkz[itz])||((mbdeepc[lj+1]-mbdeepc[lj])<mbjcjjzxz[itz])||((mbdeepc[lj]-mbdeepc[lj-1])<mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeepc[lj]))>cjjxfmkz[itz]))
          {
              XFCDJMXZ(Sender);
              if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&((mbdeepc[lj+1]-mbdeepc[lj])>mbjcjjzxz[itz])&&((mbdeepc[lj]-mbdeepc[lj-1])>mbjcjjzxz[itz]))  //&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))
              {
                  mbdeepc[lj]=mbdeep[lj];
              }
          }
       }
    }
  /*  for(int i9=0;i9<ljcgs;i9++)
    {
        mbdeep[i9]=mbdeepc[i9];
        if(i9<=45)
        {
            PaintBox2->Canvas->TextOutA(80,24+i9*14,i9);
            PaintBox2->Canvas->TextOutA(120,24+i9*14,str6[i9]);
        }
        else if((i9<=90)&&(i9>45))
        {
            PaintBox2->Canvas->TextOutA(180,24+(i9-45)*14,i9);
            PaintBox2->Canvas->TextOutA(220,24+(i9-45)*14,str6[i9]);
        }
        else if((i9<=135)&&(i9>90))
        {
           PaintBox2->Canvas->TextOutA(280,24+(i9-90)*14,i9);
           PaintBox2->Canvas->TextOutA(320,24+(i9-90)*14,str6[i9]);
        }
        else if((i9<=180)&&(i9>135))
        {
           PaintBox2->Canvas->TextOutA(380,24+(i9-135)*14,i9);
           PaintBox2->Canvas->TextOutA(420,24+(i9-135)*14,str6[i9]);
        }
        else if(i9>180)
        {
           PaintBox2->Canvas->TextOutA(480,24+(i9-180)*14,i9);
           PaintBox2->Canvas->TextOutA(520,24+(i9-180)*14,str6[i9]);
        }

    }  */
       /* if(str6[i9]=="S29")
        {
            PaintBox2->Canvas->TextOutA(120,84,"7S29=");
            PaintBox2->Canvas->TextOutA(150+64,84,mbdeep[i9]);
            PaintBox2->Canvas->TextOutA(250+94,84,CDeep[i9]);

        }  */
          //  PaintBox2->Canvas->TextOutA(120,154,mbdeep[S11lj]);
          //  PaintBox2->Canvas->TextOutA(120,174,mbS11deep);
  /*  itz=0;
    xfcpss=S11lj+1;       //细分层皮时起始点
    xfcpse=JClj;   */       //细分层皮时终止点
    /*  PaintBox2->Canvas->TextOutA(120,114,xfcpss);
      PaintBox2->Canvas->TextOutA(120,134,xfcpse);
      PaintBox2->Canvas->TextOutA(120,154,a2[xfcpss][0]);
      PaintBox2->Canvas->TextOutA(120,174,a2[xfcpse][0]);  */
 /*   xfcpsxz(Sender);    //细分层皮时校正
    xfcpss=JClj+1;       //细分层皮时起始点
    xfcpse=S37lj;
    xfcpsxz(Sender);    //细分层皮时校正
    if((P27alj>S37lj)&&(S37lj>1))
    {
       xfcpss=S37lj+1;     //细分层皮时起始点
       itz=1;
       xfcpse=P27alj;
       xfcpsxz(Sender);    //细分层皮时校正
    }
    else if((P27alj<1)&&(S37lj>1))
    {
       xfcpss=S37lj+1;     //细分层皮时起始点
       itz=1;
       xfcpse=ljcgs;
       xfcpsxz(Sender);    //细分层皮时校正
    }
    if((G110blj>P27alj)&&(P27alj>1))
    {
       xfcpss=P27alj+1;
       itz=2;
       xfcpse=G110blj;
       xfcpsxz(Sender);    //细分层皮时校正
    }
    else if((G110blj<1)&&(P27alj>1))
    {
       xfcpss=P27alj+1;
       itz=2;
       xfcpse=ljcgs;
       xfcpsxz(Sender);    //细分层皮时校正
    }
    if((G120lj>G110blj)&&(G110blj>1))
    {
       itz=2;
       xfcpss=G110blj+1;
       xfcpse=G120lj;
       xfcpsxz(Sender);    //细分层皮时校正
    }
    else if((G120lj<1)&&(G110blj>1))
    {
       itz=2;
       xfcpss=G110blj+1;
       xfcpse=ljcgs;
       xfcpsxz(Sender);    //细分层皮时校正
    }                                                                 //2025年10月23日注释掉，认为作用不大
    if(G120lj>1)
    {
       itz=2;
       xfcpss=G120lj+1;
       xfcpse=ljcgs;
       xfcpsxz(Sender);    //细分层皮时校正
    }     */
  /*  for(int i9=0;i9<ljcgs;i9++)
    {
       // mbdeep[i9]=mbdeepc[i9];
        if(str6[i9]=="S29")
        {
            PaintBox2->Canvas->TextOutA(120,84,"7S29=");
            PaintBox2->Canvas->TextOutA(150+64,84,mbdeep[i9]);
            PaintBox2->Canvas->TextOutA(250+94,84,CDeep[i9]);

        }
    }  */

        //    PaintBox2->Canvas->TextOutA(120,254,mbdeep[S11lj]);
        //    PaintBox2->Canvas->TextOutA(120,274,mbS11deep);
        nn=0;
        itz=0;
        xzkg=2;
        ljsjks=S11lj+1;
        ljsjke=JClj;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
           /*  if(str6[i7]=="S13")
             {
                 PaintBox2->Canvas->TextOutA(120,84,"7S29=");
                 PaintBox2->Canvas->TextOutA(150+64,84,mbdeep[i7]);
                 PaintBox2->Canvas->TextOutA(250+94,84,CDeep[i7]);
             }  */
            //if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
              /* if(str6[i7]=="S13")
               {
                   PaintBox2->Canvas->TextOutA(120,84,"7S29=");
                   PaintBox2->Canvas->TextOutA(150+64,84,mbdeep[i7]);
                   PaintBox2->Canvas->TextOutA(250+94,84,CDeep[i7]);
               }  */
            }
        }
        ljsjks=JClj+1;
        ljsjke=S37lj;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {

           // if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
     if((P27alj>S37lj)&&(S37lj>1))
     {
        ljsjks=S37lj+1;
        itz=1;
        ljsjke=P27alj;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
           // if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
     }
     else if((P27alj<1)&&(S37lj>1))
     {
        ljsjks=S37lj+1;
        itz=1;
        ljsjke=ljcgs;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
           // if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))       // ||(fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz])
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
     }
    if((G110blj>P27alj)&&(P27alj>1))
    {
        ljsjks=P27alj+1;
        ljsjke=G110blj;
        itz=2;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
            //if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))                 //||(fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz])
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
    }
    else if((G110blj<1)&&(P27alj>1))
    {
        ljsjks=P27alj+1;
        ljsjke=ljcgs;
        itz=2;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
            //if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))           // ||(fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz])
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
    }
    if((G120lj>G110blj)&&(G110blj>1))
    {
        ljsjks=G110blj+1;
        ljsjke=G120lj;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
            //if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))           //||(fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz])
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
    }
    else if((G120lj<1)&&(G110blj>1))
    {
        ljsjks=G110blj+1;
        ljsjke=ljcgs;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
            //if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))           //||(fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz])
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
    }
    if(G120lj>1)
    {
        ljsjks=G120lj+1;
        ljsjke=ljcgs;
        xzkg=2;
        ljsjkxfcxz(Sender);    //邻井数据库细分层校正
        for(int i7=ljsjks;i7<ljsjke;i7++)
        {
            //if((fabs(Rmnck[i7]-Rmnmb[i7])>0.2)||(mbdeep[i7]<mbdeep[i7-1])||(fabs((ckdeep[i7]-ckdeep[i7-1])-(mbdeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]))
           // if((fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz]/2.0)||(CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||(fabs(Rmnck[i7]-Rmnmb[i7])>0.2))
            if((CDeep[i7]<mbdeep[i7-1])||(CDeep[i7]>mbdeep[i7+1])||((CDeep[i7]-mbdeep[i7-1])<mbjxfcmkz))           //||(fabs(fabs(ckdeep[i7]-ckdeep[i7-1])-fabs(CDeep[i7]-mbdeep[i7-1]))>cjjxfmkz[itz])
            {
                isname=i7;
                xzkg=2;
                ljsjkxfczxz(Sender);    //邻井数据库细分层总修正
            }
        }
    }
    for(int ij=0;ij<ljcgs;ij++)
    {
        if(mbdeep[ij]<mbdeep[0])                 //此处不够完美
        {
            mbdeep[ij]=-1.0;
        }
    }
  /*  for(int i9=0;i9<ljcgs;i9++)
    {
       // mbdeep[i9]=mbdeepc[i9];
        if(str6[i9]=="S29")
        {
            PaintBox2->Canvas->TextOutA(120,84,"7S29=");
            PaintBox2->Canvas->TextOutA(150+64,84,mbdeep[i9]);
            PaintBox2->Canvas->TextOutA(250+94,84,CDeep[i9]);

        }
    }   */
   PaintBox5Click(Sender);


   paintfencengnewDice(Sender);




//  PaintBox5Paint(Sender);

 //  fclose(fp2);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::xfcpsxz(TObject *Sender)    //细分层皮时校正
{
  for(int l1=xfcpss;l1<xfcpse;l1++)
    {

         if((fabs((ckdeep[l1+1]-ckdeep[l1])-(mbdeepc[l1+1]-mbdeepc[l1]))>cjjxfmkz[itz])||((mbdeepc[l1]-mbdeepc[l1-1])<mbjcjjzxz[itz])\
         ||(fabs((ckdeep[l1]-ckdeep[l1-1])-(mbdeepc[l1]-mbdeepc[l1-1]))>cjjxfmkz[itz])||((mbdeepc[l1+1]-mbdeepc[l1])<mbjcjjzxz[itz])||(mbdeepc[l1]>mbdeepc[l1+1]))
         {
             lj=l1;
             XFCPearsonSYTDdcxz(Sender);       //细分层皮尔森时域梯度单层修正
         /* if(str6[l1]=="S32b")
          {
             PaintBox2->Canvas->TextOutA(50,34,"S32b=");
             PaintBox2->Canvas->TextOutA(50+54,34,mbdeep[l1]);
             PaintBox2->Canvas->TextOutA(50+54,54,mbdeepc[l1]);
             PaintBox2->Canvas->TextOutA(50+54,74,ckdeep[l1+1]-ckdeep[l1]);
             PaintBox2->Canvas->TextOutA(50+54,94,mbdeepc[l1+1]-mbdeep[l1]);
             PaintBox2->Canvas->TextOutA(50+54,114,mbdeepc[l1+1]-mbdeepc[l1]);
             PaintBox2->Canvas->TextOutA(50+54,134,a1[xfcpss][0]);
             PaintBox2->Canvas->TextOutA(50+54,154,a1[xfcpse][0]);
          }    */
         }

         if((fabs((ckdeep[l1+1]-ckdeep[l1])-(mbdeepc[l1+1]-mbdeep[l1]))<cjjxfmkz[itz])&&((mbdeepc[l1]-mbdeep[l1-1])>mbjcjjzxz[itz])\
         &&(fabs((ckdeep[l1]-ckdeep[l1-1])-(mbdeepc[l1]-mbdeepc[l1-1]))<cjjxfmkz[itz])&&((mbdeepc[l1+1]-mbdeep[l1])>mbjcjjzxz[itz])&&(mbdeep[l1]<mbdeepc[l1+1]))
         {
            mbdeepc[l1]=mbdeep[l1];

         }
        /*  if(str6[l1]=="S213")
          {
             PaintBox2->Canvas->TextOutA(350,34,"4S213=");
             PaintBox2->Canvas->TextOutA(350+54,34,mbdeep[l1]);
             PaintBox2->Canvas->TextOutA(350+54,54,mbdeepc[l1]);
          }  */
    }


}
//---------------------------------------------------------------------------
void __fastcall TForm1::ljsjkxfcxz(TObject *Sender)    //邻井数据库细分层校正
{
    PaintBox5->Canvas->Font->Height=60;
   PaintBox5->Canvas->Font->Color=RGB(210,20,20);
    for(int l1=ljsjks;l1<ljsjke;l1++)
    {

        PaintBox5->Canvas->TextOutA(305,30,"       ");
        PaintBox5->Canvas->TextOutA(50,30,"正在处理第         层，共计        层");
        PaintBox5->Canvas->TextOutA(305,30,l1);
        PaintBox5->Canvas->TextOutA(590,30,ljcgs);
       /*   if(str6[l1]=="S12a")
          {
             PaintBox2->Canvas->TextOutA(450,34,"1S28a=");
             PaintBox2->Canvas->TextOutA(450+54,34,mbdeep[l1]);
             PaintBox2->Canvas->TextOutA(450+54,54,mbdeepc[l1]);
             PaintBox2->Canvas->TextOutA(450+54,74,fabs((ckdeep[l1]-ckdeep[l1-1])-(mbdeepc[l1]-mbdeepc[l1-1])));
             PaintBox2->Canvas->TextOutA(450+54,94,cjjxfmkz[itz]);
          }   */
     //    if((fabs((ckdeep[l1]-ckdeep[l1-1])-(mbdeepc[l1]-mbdeepc[l1-1]))>cjjxfmkz[itz])||((mbdeepc[l1]-mbdeepc[l1-1])<mbjcjjzxz[itz])\
      //    ||((mbdeepc[l1+1]-mbdeepc[l1])<mbjcjjzxz[itz])||(mbdeepc[l1]>mbdeepc[l1+1])||(fabs((ckdeep[l1+1]-ckdeep[l1])-(mbdeepc[l1+1]-mbdeepc[l1]))>cjjxfmkz[itz]))
          {

             lj=l1;
             open_correct=1;  //校正开关
             ckjcjlcxz[lj]=ckdeep[lj]-ckdeep[lj-1];             //参考井层间落差细分层
             mbjdcjx[lj]=mbdeepc[lj-1];       //目标井顶层界限
             mbjckcw[lj]=mbdeepc[lj-1];      //目标井参考层位
            // mbjdjxzc[lj]=mbdeepc[lj+1];   //目标井底界限逐层
             mbjdjxzc[lj]=mbdeepc[lj-1]+(ckdeep[lj+1]-ckdeep[lj-1]);   //目标井底界限逐层
             isname=lj;
             sname=str6[lj];
             xzc=1;
             ljsjkxfccorrect(Sender);    //邻井数据库细分层修正
            // mbdeep[lj]=CDeep[lj];
         /*  if(str6[l1]=="S221b")
           {
               PaintBox2->Canvas->TextOutA(50,134,"1S29=");
               PaintBox2->Canvas->TextOutA(50+54,134,mbdeep[l1]);
               PaintBox2->Canvas->TextOutA(50+54,154,mbdeepc[l1]);
               PaintBox2->Canvas->TextOutA(50+54,174,mbdeepc[l1-1]);
               PaintBox2->Canvas->TextOutA(150+54,174,mbdeepc[l1+1]);
               PaintBox2->Canvas->TextOutA(50+54,194,fabs((ckdeep[l1]-ckdeep[l1-1])-(mbdeep[lj]-mbdeepc[l1-1])));
               PaintBox2->Canvas->TextOutA(50+54,214,mbjdjxzc[lj]);
               PaintBox2->Canvas->TextOutA(50+54,234,(mbdeep[lj]-mbdeepc[l1-1]));
               PaintBox2->Canvas->TextOutA(50+54,254,(mbdeepc[l1+1]-mbdeep[lj]));
               PaintBox2->Canvas->TextOutA(50+54,274,fabs((ckdeep[l1+1]-ckdeep[l1])-(mbdeepc[l1+1]-mbdeep[lj])));
               PaintBox2->Canvas->TextOutA(50+54,294,cjjxfmkz[itz]);
            }  */

             if((fabs((ckdeep[l1]-ckdeep[l1-1])-(mbdeep[lj]-mbdeepc[l1-1]))<cjjxfmkz[itz])&&((mbdeep[lj]-mbdeepc[l1-1])>mbjcjjzxz[itz])\
             &&((mbdeep[l1-1]+(ckdeep[l1+1]-ckdeep[l1-1])-mbdeep[lj])>mbjcjjzxz[itz])&&(mbdeep[lj]<(mbdeep[l1-1]+(ckdeep[l1+1]-ckdeep[l1-1]))))   //&&(fabs((ckdeep[l1+1]-ckdeep[l1])-(mbdeepc[l1+1]-mbdeep[lj]))<cjjxfmkz[itz]))
             {
                   mbdeepc[lj]=mbdeep[lj];
             }
             else
             {
                   pbcw[nn]=str6[l1];
                   nn=nn+1;
             }
          }
         mbdeep[l1]=mbdeepc[l1];
       /*  if(str6[l1]=="G36")
          {
             PaintBox2->Canvas->TextOutA(350,234,"2S38a=");
             PaintBox2->Canvas->TextOutA(350+54,234,mbdeep[l1]);
             PaintBox2->Canvas->TextOutA(350+54,254,mbdeepc[l1]);
             PaintBox2->Canvas->TextOutA(350+54,274,mbdeepc[l1+1]);
          }  */
    }
}
//------------------------------------------------------------------------------
void __fastcall TForm1::XFCPearsonSYTDdcxz(TObject *Sender)     //细分层皮尔森时域梯度单层修正
{
         //利用底界线向上进行标定

              float p11,p22;
              float xfcmkz=99999999.0,mbdeep2=0.1;   Rmnselect=0.0; Rm1=999999.0;
       //  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
         {
            // ckjdjxlc[lj]=ckjdjx[lj]-ckdeep[lj];         //参考井层间落差
            p11=mbdeepc[lj-1]-wincu[lj];
            p22=mbdeepc[lj-1]+(ckdeep[lj+1]-ckdeep[lj-1])+cjjxfmkz[itz]*1.5;
          /*  if(str6[lj]=="S214b")
            {

                PaintBox2->Canvas->TextOut(220,524+14,ckjdjxlc[lj]);
                PaintBox2->Canvas->TextOut(220,524+34,p11);
                PaintBox2->Canvas->TextOut(220,524+54,p22);
                PaintBox2->Canvas->TextOut(220,524+74,wincu[lj]);
            }  */
            for(int i1=20;i1<stedp1;i1++)
            {
               if(fabs(a1[i1][0]-p11)<0.02)
               {
                  stmb2[lj]=i1;
               }
               if(fabs(a1[i1][0]-p22)<0.02)
               {
                  enmb2[lj]=i1;                                         
               }
            }
          /*  if(str6[lj]=="S222+3b")
            {
               PaintBox2->Canvas->TextOutA(220,34,"1="+str6[lj]);
               PaintBox2->Canvas->TextOutA(220,54,mbdeepc[lj-1]);
               PaintBox2->Canvas->TextOutA(220,74,p11);
               PaintBox2->Canvas->TextOutA(220,94,p22);
               PaintBox2->Canvas->TextOutA(220,114,mbjdjx[lj]);
               PaintBox2->Canvas->TextOutA(220,134,ckdeep[lj+1]-ckdeep[lj-1]);
            }   */
            sname=str6[lj];
            xzc=0;
            prc=5;      //应用到处理曲线
            AICXFCPearsonSYTD(Sender);    //智能细分层 皮尔森时域梯度
            mbdeep[lj]=CDeep[lj];
            mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];
          /*  if(str6[lj]=="S222+3b")
            {
               PaintBox2->Canvas->TextOutA(50,34,"1S222+3b=");
               PaintBox2->Canvas->TextOutA(50+54,34,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(50+54,54,mbdeepc[lj]);
               PaintBox2->Canvas->TextOutA(50+54,74,mbjdjx[lj]);
               PaintBox2->Canvas->TextOutA(50+54,94,mbjdjxlc[lj]);
            }  */
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22)&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)\
            &&(fabs((ckdeep[lj]-ckdeep[lj-1])-(mbdeepc[lj]-mbdeepc[lj-1]))<cjjxfmkz[itz])&&((mbdeepc[lj]-mbdeep[lj-1])>mbjcjjzxz[itz])&&((mbdeepc[lj+1]-mbdeep[lj])>mbjcjjzxz[itz])&&(mbdeep[lj]<mbdeepc[lj+1]))
          // if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22))       //参考井层间落差细分层
            {
                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);   //细分层门槛值
                mbdeep2=CDeep[lj];
            }
            prc=2;      //应用到处理曲线
            AICXFCPearsonSYTD(Sender);    //智能细分层
            mbdeep[lj]=CDeep[lj];
            mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];
           /* if(str6[lj]=="S222+3b")
            {
               PaintBox2->Canvas->TextOutA(50,134,"2S222+3b=");
               PaintBox2->Canvas->TextOutA(50+54,134,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(50+54,154,mbdeepc[lj]);
               PaintBox2->Canvas->TextOutA(50+54,174,mbjdjx[lj]);
               PaintBox2->Canvas->TextOutA(50+54,194,mbjdjxlc[lj]);
            }  */
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22)&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)\
            &&(fabs((ckdeep[lj]-ckdeep[lj-1])-(mbdeepc[lj]-mbdeepc[lj-1]))<cjjxfmkz[itz])&&((mbdeepc[lj]-mbdeep[lj-1])>mbjcjjzxz[itz])&&((mbdeepc[lj+1]-mbdeep[lj])>mbjcjjzxz[itz])&&(mbdeep[lj]<mbdeepc[lj+1]))
           // if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22))       //参考井层间落差细分层
            {
                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);
                mbdeep2=CDeep[lj];
            }
            prc=1;      //应用到处理曲线
            AICXFCPearsonSYTD(Sender);    //智能细分层
            mbdeep[lj]=CDeep[lj];
            mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];
           /* if(str6[lj]=="S222+3b")
            {
               PaintBox2->Canvas->TextOutA(50,234,"3S222+3b=");
               PaintBox2->Canvas->TextOutA(50+54,234,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(50+54,254,mbdeepc[lj]);
               PaintBox2->Canvas->TextOutA(50+54,274,mbjdjx[lj]);
               PaintBox2->Canvas->TextOutA(50+54,294,mbjdjxlc[lj]);
            } */
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22)&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)\
            &&(fabs((ckdeep[lj]-ckdeep[lj-1])-(mbdeepc[lj]-mbdeepc[lj-1]))<cjjxfmkz[itz])&&((mbdeepc[lj]-mbdeep[lj-1])>mbjcjjzxz[itz])&&((mbdeepc[lj+1]-mbdeep[lj])>mbjcjjzxz[itz])&&(mbdeep[lj]<mbdeepc[lj+1]))
           // if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22))       //参考井层间落差细分层
            {
                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);
                mbdeep2=CDeep[lj];
            }
            prc=4;      //应用到处理曲线
            AICXFCPearsonSYTD(Sender);    //智能细分层
            mbdeep[lj]=CDeep[lj];
            mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];
           /* if(str6[lj]=="S222+3b")
            {
               PaintBox2->Canvas->TextOutA(50,334,"4S222+3b=");
               PaintBox2->Canvas->TextOutA(50+54,334,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(50+54,354,mbdeepc[lj]);
               PaintBox2->Canvas->TextOutA(50+54,374,mbjdjx[lj]);
               PaintBox2->Canvas->TextOutA(50+54,394,mbjdjxlc[lj]);
            }  */
            if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeepc[lj+1]-mbdeep[lj]))<cjjxfmkz[itz])&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22)&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)\
            &&(fabs((ckdeep[lj]-ckdeep[lj-1])-(mbdeepc[lj]-mbdeepc[lj-1]))<cjjxfmkz[itz])&&((mbdeepc[lj]-mbdeep[lj-1])>mbjcjjzxz[itz])&&((mbdeepc[lj+1]-mbdeep[lj])>mbjcjjzxz[itz])&&(mbdeep[lj]<mbdeepc[lj+1]))
           // if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22))       //参考井层间落差细分层
            {
                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);
                mbdeep2=CDeep[lj];
            }
            prc=5;
           if(mbdeep2>100.0)
           {
              mbdeep[lj]=mbdeep2;
              CDeep[lj]=mbdeep2;
           }
            xfcmkz=99999999.0;
          /* if(str6[lj]=="S222+3b")
            {
               PaintBox2->Canvas->TextOutA(50,434,"5S222+3b=");
               PaintBox2->Canvas->TextOutA(50+54,434,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(50+54,454,mbdeepc[lj]);
               PaintBox2->Canvas->TextOutA(50+54,474,mbjdjx[lj]);
               PaintBox2->Canvas->TextOutA(50+54,494,mbjdjxlc[lj]);
            }
               */
         }








}
//-------------------------------------------------------------------------------
void __fastcall TForm1::ljsjkxfczxz(TObject *Sender)    //邻井数据库细分层总修正
{
        zxz1=9999999.0; zxz2=9999999.0; zxz3=9999999.0;zxz4=9999999.0; zxz5=9999999.0;
    Rmnselect=0.0;selectxfcdeep=0.0;Rm1=999999.0;
      Rm2=999999.0; sd2=9999.0;
   deeplast=0.0; selectxfcdp=9999999.0;   float cjlczxz=9999999.0,xfcljsjkdeep=0.0;
   float dp2=0.0; cjjxfDJXmkz[0]=1.6;cjjxfDJXmkz[1]=3.5;cjjxfDJXmkz[2]=1.2;    //层间距细分底界线门槛值
   n=6;i09=0;int it;//open_switch=1;
   lj=isname;
   ic1=0;

   FILE *fp; int i2=n+1;ie1=0;AnsiString Dir;
   if(xzkg==1)
   {          // xzkg;  //选择开关
       Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\"+str16[isname]+"\\";
   }
   else if(xzkg==2)
   {
      Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\沉积单元数据库\\"+str16[isname]+"\\";
   }
   TSearchRec sr;
   TStringList *FileList = new TStringList();


   ccp2.SetLength(ccp2.Length()-3);
   AnsiString filename = ccp2;                 //文件名
   ccp2.SetLength(ccp2.Length()+3);
   int count = filename.Length();              //文件名字符数
   AnsiString s1;
   AnsiString s2;
   AnsiString s4;
   AnsiString s6;
   AnsiString s9;

   char * filename1 = filename.c_str();
   for(int i = 0;i < count-1;i++)
   {
        Ps[i]=0.0;
        s1 = s1 + filename1[i];
   }
   for(int i = 0;i < count-2;i++)
   {
        s2 = s2 + filename1[i];
   }
   for(int i = 0;i < count-4;i++)
   {
        s4 = s4 + filename1[i];
   }
   for(int i = 0;i < count-6;i++)
   {
        s6 = s6 + filename1[i];
   }
   for(int i = 0;i < 2;i++)
   {
        s9 = s9 + filename1[i];
   }

   AnsiString Dir00 = Dir + "n*.*" + '.';      //n开头文件
   AnsiString Dir1 = Dir + s1 + "*.*" + '.';   //前count-1个字符相同文件
   AnsiString Dir2 = Dir + s2 + "*.*" + '.';   //前count-2个字符相同文件
   AnsiString Dir4 = Dir + s4 + "*.*" + '.';   //前count-4个字符相同文件
   AnsiString Dir6 = Dir + s6 + "*.*" + '.';   //前count-6个字符相同文件
   AnsiString Dir99 = Dir + s9 + "*.*" + '.';   //前count-6个字符相同文件

   int same = 0;                               //重复文件名判断
   vector<AnsiString> temp;                    //操作数组
   vector<AnsiString> fil;                     //文件名序列数组
   vector<AnsiString> fil2;                    //文件名数组


   FindFirst(Dir1, faAnyFile, sr);             //前count-1个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir2, faAnyFile, sr);            //前count-2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir4, faAnyFile, sr);            //前count-4个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
////                                          //前count-6个字符相同文件加入FileList和fil数组
   FindFirst(Dir6, faAnyFile, sr);
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir99, faAnyFile, sr);            //前2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));

////                                           ////n开头文件加入FileList和fil数组
     FileList->Clear();
     fil.clear();
     fil2.clear();
     String temp2[2000];
     int checked = 0;
     int checked2 = 0;


////                                           ////剔除重复
     for(int i = 0;i < temp.size();i ++)
     {
        //String TempWell0 = temp[i];
        for(int j = 0;j < 2000;j ++)
        {
                if(temp2[checked] == temp2[j] && checked > 0)
                        break;
                checked2 = 0;
                for(int k = 0;k < i;k ++)
                {
                        if(temp[k] == temp[i])
                                checked2 = 1;
                }
                if(checked2 != 0)
                        break;
                else
                {
                        temp2[checked] = temp[i];
                        FileList->Add(temp2[checked]);
                        fil.push_back(temp2[checked]);
                        fil2.push_back(ExtractFileName(temp2[checked]));
                        checked ++;
                        break;
                }
        }

     }

   temp.clear();
   FileList->Count;                           //文件名列表计数
   AnsiString o1 = FileList->Text;
   FileList->SaveToFile("D:\\001.txt");     //输出文件名到txt

   string fname[20];                         //文件路径数组
   string fn[20];                         //文件名数组
   int file_count = 0;
   for(int i = 0;i < 20;i ++)                //前20个文件
   {

        fname[i] = fil[i].c_str();
                 //   PaintBox2->Canvas->TextOutA(70,440+i*14,"name=");
                 //   PaintBox2->Canvas->TextOutA(70+54,440+i*14,fil[i].c_str());
        fn[i] = fil2[i].c_str();
        file_count ++;
        if(file_count == fil.size())
        break;

   }
float relvc;
int num = 0;

    xzc=1;
    open_correct=1;
   // lj=isname;
   ic2=file_count;
   ic3=15;
if (file_count >3)
{
do{
      if (num == file_count)
      break;
      //FileList->Add(Dir + sr.Name);
     // PaintBox2->Canvas->TextOut(120,2+(i01+1)*14,fn[num].c_str());
      /* if(str6[isname]=="G25")
       {
           PaintBox2->Canvas->TextOut(120,2+(i09+1)*14,file_count);
       }  */
       btn=num;

    //  if((CDeep[isname]<10.0)&&(open_correct==0)&&(isname<=2))
      {
        fp=fopen(fname[num].c_str(),"r");
        if(fp)
        {
           ie1=0; i09=i09+1;                //计算打开非零文件个数
           fscanf(fp,"%f %f %f %f %d",&start2[isname],&end2[isname],&ckja2[isname],&relvc,&totalnumb[isname]);

     /*   if(str6[isname]=="G25")
       {
           PaintBox2->Canvas->TextOut(120,2+(i09+1)*14,file_count);
           PaintBox2->Canvas->TextOut(220,2+(i09+1)*14,i09);
           PaintBox2->Canvas->TextOut(320,2+(i09+1)*14,ic3);
       }    */
           chcsh2[isname]=totalnumb[isname];
           stpinsjk[isname]=int((ckja2[isname]-start2[isname])/relvc);                  //数据库节点
           prc=5;
           while(feof(fp)==0)
           {
                for(int j=0;j<i2;j++)
                {
                        fscanf(fp,"%f",&xcsj[ie1][j]);
                        xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
                        //bzcsj[ie1][j]=xcsj[ie1][j];
                }
                Rmn[ie1]=xcsj[ie1][prc];
                ie1++;
           }
         /*  if(isname==0)
           {
               st[isname]=jdcw[JClj]-int(ckjcjlcxz[isname]/relvc)-int(cjjxfmkz[itz]/relvc);    //-stpinsjk[isname]
               en[isname]=jdcw[JClj]-int(ckjcjlcxz[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjxfmkz[itz]/relvc);

           }
           else
           {
               st[isname]=ckjjd[isname]+int(ckjcjlcxz[isname]/relvc)-int((ckja2[isname]-start2[isname])/relvc)-int(cjjxfmkz[itz]/relvc); //-stpinsjk[isname]
               en[isname]=ckjjd[isname]+int(ckjcjlcxz[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjxfmkz[itz]/relvc);
           }    */
           int i5=0;
           i5=int((ckja2[isname]-start2[isname])/relvc);
           Rmnck[isname]=xcsj[i5][1];
            float p1,p2;

          //  p1=mbjckcw[isname]-wincu[isname]*2.4;
           // p2=mbjckcw[isname]+(end2[isname]-start2[isname])*2.0;
           p1=mbdeep[isname-1];//-(ckja2[isname]-start2[isname]);
           p2=mbdeep[isname-1]+(end2[isname]-start2[isname])*2.0;
            for(int i1=20;i1<stedp1;i1++)
            {
               if(fabs(a1[i1][0]-p1)<0.02)
               {
                  stmbzxz[isname]=i1;
               }
               if(fabs(a1[i1][0]-p2)<0.02)
               {
                  enmbzxz[isname]=i1;
               }
            }
           /* if(str6[isname]=="S31a")
            {
               // PaintBox2->Canvas->TextOut(60,122+(i09+1)*14,fn[num].c_str());
                PaintBox2->Canvas->TextOut(160,224+(i09+1)*14,mbjckcw[isname]);
                PaintBox2->Canvas->TextOut(260,224+(i09+1)*14,p1);
                PaintBox2->Canvas->TextOut(360,224+(i09+1)*14,p2);
                PaintBox2->Canvas->TextOut(460,224+(i09+1)*14,mbdeep[isname]);
                PaintBox2->Canvas->TextOut(560,224+(i09+1)*14,mbdeep[isname-1]);
            }    */
         /*   if(str6[isname]=="S28b")
            {
                PaintBox2->Canvas->TextOut(120,222+(i09+1)*14,i09);
            }    */
     // if((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz]/2.0)||(CDeep[isname]<p1)||(CDeep[isname]>p2))
      if((CDeep[isname]<p1)||(CDeep[isname]>p2)||(CDeep[isname]<mbdeep[isname-1])||(CDeep[isname]>mbdeep[isname+1])||((CDeep[isname]-mbdeep[isname-1])<mbjxfcmkz)||(fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz]))
      {
           StdCw=str6[isname];
           AICXFCljsjkzxz(Sender);
           CDeep[isname]=mbdeep[isname];
          /*  if(str6[isname]=="S31a")
            {
                PaintBox2->Canvas->TextOut(60,22+(i09+1)*14,i09);
                PaintBox2->Canvas->TextOut(220,124+(i09+1)*14,mbdeep[isname]);
                PaintBox2->Canvas->TextOut(320,124+(i09+1)*14,CDeep[isname]);
                PaintBox2->Canvas->TextOut(420,124+(i09+1)*14,fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(mbdeep[isname]-mbdeep[isname-1])));
                PaintBox2->Canvas->TextOut(520,124+(i09+1)*14,fabs(ckjdjxlc[isname]-(mbjdjx[isname]-mbdeep[isname])));
                PaintBox2->Canvas->TextOut(220,124+74,cjjxfDJXmkz[itz]);
                PaintBox2->Canvas->TextOut(220,324+34,p1);
                PaintBox2->Canvas->TextOut(220,324+54,p2);
                PaintBox2->Canvas->TextOut(220,324+74,cjlczxz);

            }   */

              // if((mbdeep[isname]>p1)&&(mbdeep[isname]<p2)&&(fabs(ckdeep[isname]-mbdeep[isname])<cjlczxz)&&(open_correct==1))
             if((CDeep[isname]>p1)&&(CDeep[isname]<p2)&&(CDeep[isname]>(CDeep[isname-1]+mbjxfcmkz))&&(fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]))<cjlczxz)&&(open_correct==1))
             {
                 cjlczxz=fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]));
                 //cjlczxz=fabs(ckjdjxlc[isname]-(mbjdjx[isname]-mbdeep[isname]));
                // cjlczxz=fabs(ckdeep[isname]-mbdeep[isname]);
                 xfcljsjkdeep=mbdeep[isname];
                /* if(str6[isname]=="S222+3b")
                 {
                      PaintBox2->Canvas->TextOut(120,22,str6[isname]);
                      PaintBox2->Canvas->TextOut(100+i09*20,42,i01);
                     PaintBox2->Canvas->TextOut(120,22+(i09+1)*14,mbdeep[isname]);
                     PaintBox2->Canvas->TextOut(240,24+(i09+1)*14,CDeep[isname]);
                     PaintBox2->Canvas->TextOut(120,124+34,p1);
                     PaintBox2->Canvas->TextOut(120,124+54,p2);
                 }   */
             }
           // if(((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz])||(CDeep[isname]<p1)||(CDeep[isname]>p2)||(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))>cjjxfDJXmkz[itz]))&&(open_correct==1))  //校正开关    //层间距细分层门槛值
            {
                 prc=1;
                 for(int io=0;io<ie1;io++)
                 {
                     Rmn[io]=xcsj[io][prc];
                 }
                 StdCw=str6[isname];
                 AICXFCljsjkzxz(Sender);
                 CDeep[isname]=mbdeep[isname];
          /*  if(str6[isname]=="G217")
            {
                PaintBox2->Canvas->TextOut(60,222+(i09+1)*14,i09);
                PaintBox2->Canvas->TextOut(120,222+(i09+1)*14,open_correct);
                PaintBox2->Canvas->TextOut(220,324+(i09+1)*14,mbdeep[isname]);
                PaintBox2->Canvas->TextOut(320,324+(i09+1)*14,CDeep[isname]);
                PaintBox2->Canvas->TextOut(420,324+(i09+1)*14,fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(mbdeep[isname]-mbdeep[isname-1])));
                PaintBox2->Canvas->TextOut(520,324+(i09+1)*14,fabs(ckjdjxlc[isname]-(mbjdjx[isname]-mbdeep[isname])));
                PaintBox2->Canvas->TextOut(220,324+74,cjjxfDJXmkz[itz]);
                PaintBox2->Canvas->TextOut(220,524+34,p1);
                PaintBox2->Canvas->TextOut(220,524+54,p2);
                PaintBox2->Canvas->TextOut(220,524+74,cjlczxz);

            }   */
                 if((CDeep[isname]>p1)&&(CDeep[isname]<p2)&&(CDeep[isname]>(CDeep[isname-1]+mbjxfcmkz))&&(fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]))<cjlczxz)&&(open_correct==1))
                // if((mbdeep[isname]>p1)&&(mbdeep[isname]<p2)&&(fabs(ckdeep[isname]-mbdeep[isname])<cjlczxz)&&(open_correct==1))
                 {
                     cjlczxz=fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]));
                    // cjlczxz=fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]));
                   //  cjlczxz=fabs(ckdeep[isname]-mbdeep[isname]);
                     xfcljsjkdeep=CDeep[isname];
                 }
         /*   if(str6[isname]=="S32b")
            {
                PaintBox2->Canvas->TextOut(60,522+(i09+1)*14,mbdeep[isname-1]);
                PaintBox2->Canvas->TextOut(220,524+14,CDeep[isname]);
                PaintBox2->Canvas->TextOut(220,524+34,p1);
                PaintBox2->Canvas->TextOut(220,524+54,p2);
            }    */
                // if(((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz])||(CDeep[isname]<p1)||(CDeep[isname]>p2)||(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))>cjjxfDJXmkz[itz]))&&(open_correct==1))
                 {
                     prc=2;
                     for(int io=0;io<ie1;io++)
                     {
                        Rmn[io]=xcsj[io][prc];
                     }
                     StdCw=str6[isname];
                     AICXFCljsjkzxz(Sender);
                     CDeep[isname]=mbdeep[isname];
          /*  if(str6[isname]=="S221a")
            {
                PaintBox2->Canvas->TextOut(60,222+(i09+1)*14,i09);
                PaintBox2->Canvas->TextOut(120,222+(i09+1)*14,open_correct);
                PaintBox2->Canvas->TextOut(220,324+(i09+1)*14,mbdeep[isname]);
                PaintBox2->Canvas->TextOut(320,324+(i09+1)*14,CDeep[isname]);
                PaintBox2->Canvas->TextOut(420,324+(i09+1)*14,fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(mbdeep[isname]-mbdeep[isname-1])));
                PaintBox2->Canvas->TextOut(520,324+(i09+1)*14,fabs(ckjdjxlc[isname]-(mbjdjx[isname]-mbdeep[isname])));
                PaintBox2->Canvas->TextOut(220,324+74,cjjxfDJXmkz[itz]);
                PaintBox2->Canvas->TextOut(220,524+34,p1);
                PaintBox2->Canvas->TextOut(220,524+54,p2);
                PaintBox2->Canvas->TextOut(220,524+74,cjlczxz);

            }   */
                   /*  if(str6[isname]=="S32b")
                     {
                         PaintBox2->Canvas->TextOut(60,522+(i09+1)*14,mbdeep[isname]);
                         PaintBox2->Canvas->TextOut(220,524+14,CDeep[isname]);
                         PaintBox2->Canvas->TextOut(220,524+34,p1);
                         PaintBox2->Canvas->TextOut(220,524+54,p2);
                     } */
                       if((CDeep[isname]>p1)&&(CDeep[isname]<p2)&&(CDeep[isname]>(CDeep[isname-1]+mbjxfcmkz))&&(fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]))<cjlczxz)&&(open_correct==1))
                      // if((mbdeep[isname]>p1)&&(mbdeep[isname]<p2)&&(fabs(ckdeep[isname]-mbdeep[isname])<cjlczxz)&&(open_correct==1))
                       {
                        //  cjlczxz=fabs(ckdeep[isname]-mbdeep[isname]);
                         // cjlczxz=fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]));
                          cjlczxz=fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]));
                          xfcljsjkdeep=CDeep[isname];
                       }
                    //  if(((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz])||(CDeep[isname]<p1)||(CDeep[isname]>p2)||(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))>cjjxfDJXmkz[itz]))&&(open_correct==1))
                      {
                          prc=4;
                          for(int io=0;io<ie1;io++)
                          {
                             Rmn[io]=xcsj[io][prc];
                          }
                          StdCw=str6[isname];
                          AICXFCljsjkzxz(Sender);
                          CDeep[isname]=mbdeep[isname];
                    /*  if(str6[isname]=="S212a")
                     {
                         PaintBox2->Canvas->TextOut(60,22+(i09+1)*14,mbdeep[isname]);
                         PaintBox2->Canvas->TextOut(220,24+(i09+1)*14,CDeep[isname]);
                         PaintBox2->Canvas->TextOut(320,24,p1);
                         PaintBox2->Canvas->TextOut(420,24,p2);
                     }   */
                          if((CDeep[isname]>p1)&&(CDeep[isname]<p2)&&(CDeep[isname]>(CDeep[isname-1]+mbjxfcmkz))&&(fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]))<cjlczxz)&&(open_correct==1))
                        //  if((mbdeep[isname]>p1)&&(mbdeep[isname]<p2)&&(fabs(ckdeep[isname]-mbdeep[isname])<cjlczxz)&&(open_correct==1))
                          {
                            //  cjlczxz=fabs(ckdeep[isname]-mbdeep[isname]);
                               //cjlczxz=fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]));
                               cjlczxz=fabs((ckja2[isname]-start2[isname])-(CDeep[isname]-mbdeep[isname-1]));
                               xfcljsjkdeep=CDeep[isname];
                          }
         /*   if(str6[isname]=="S212a")
            {
               PaintBox2->Canvas->TextOutA(40,34+i09*104,"5S212a=");
               PaintBox2->Canvas->TextOutA(50+54,34+i09*104,mbdeep[isname]);
               PaintBox2->Canvas->TextOutA(50+54,54+i09*104,mbdeepc[isname]);
               PaintBox2->Canvas->TextOutA(50+54,74+i09*104,p1);
               PaintBox2->Canvas->TextOutA(50+54,94+i09*104,p2);
            }  */
                       //   if((((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))<cjjxfmkz[itz])&&(CDeep[isname]>p1)&&(CDeep[isname]<p2))&&(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))<cjjxfDJXmkz[itz]))&&(open_correct==1))
                          if((((fabs(fabs(ckja2[isname]-start2[isname])-fabs(xfcljsjkdeep-mbdeep[isname-1]))<cjjxfmkz[itz])&&(xfcljsjkdeep>(CDeep[isname-1]+mbjxfcmkz))&&(xfcljsjkdeep>p1)&&(xfcljsjkdeep<p2))&&(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-xfcljsjkdeep))<cjjxfDJXmkz[itz]))&&(open_correct==1))
                          {
                             open_correct=3;  //校正开关
                             dp2=xfcljsjkdeep;
                          }
                      }
                    /*  else
                      {
                         open_correct=3;  //校正开关
                         dp2=xfcljsjkdeep;
                      }   */
                 }
               /*  else
                 {
                     open_correct=3;  //校正开关
                     dp2=xfcljsjkdeep;
                 }  */
            }
          /*  else
            {
               open_correct=3;  //校正开关
               dp2=CDeep[isname];
            }    */
        }
       }
      }
      fclose(fp);
      num ++;

     }while(i09 < ic3);    //while((i09 < 20));   2023-08-13  改为循环5口井    &&(open_correct<2))

    FindClose(sr);

    open_correct2=3;
    if(dp2>100)
    {
       CDeep[isname]=dp2;
       mbdeep[isname]=CDeep[isname];
       mbdeepc[isname]=CDeep[isname];
    }
           /* if(str6[isname]=="S222+3b")
            {
               PaintBox2->Canvas->TextOutA(240,34+4*104,"5S222+3b=");
               PaintBox2->Canvas->TextOutA(250+54,34+4*104,mbdeep[isname]);
               PaintBox2->Canvas->TextOutA(250+54,54+4*104,mbdeepc[isname]);
              // PaintBox2->Canvas->TextOutA(250+54,74+4*104,p1);
             //  PaintBox2->Canvas->TextOutA(250+54,94+4*104,p2);
               PaintBox2->Canvas->TextOutA(250+54,74+4*104,CDeep[isname]);
            }    */
   }

}
//-----------------------------------------------------------------------------------

void __fastcall TForm1::AICXFCljsjkzxz(TObject *Sender)       //智能计算细分层 邻井数据库总修正
{
/* zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0;zdz4=9999999.0; zdz5=9999999.0;
    Rmnselect=0.0;selectxfcdeep=0.0;Rm1=999999.0;
      Rm2=999999.0;  */
      int icc1=0;float PPS[5000];
      if(xzc==1)        //修正correct
      {

         stpin=stpinsjk[lj];    //节点输入

      }
      else if(xzc==0)
      {
          inputckj(Sender);
          stpin=int(wincu[lj]/relv1);
      }
             /*  PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-3*20,a1[stmb[lj]][0]);
               PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-2*20,a1[enmb[lj]][0]);
               PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-1*20,totalnumb[lj]);  */
        /*  if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(130,244+i09*20,i09);
          }  */
               if(str6[lj]==StdCw)
                 {

                    ljcw0=lj;
                    Dice(Sender);
                    for(int i1=stmbzxz[lj];i1<enmbzxz[lj]-stpin;i1++)
                    {
                      ie2=0;
                      if((a1[i1+chcsh[lj]][MN1_pos]>0.85)&&(a1[i1+chcsh[lj]][Rxo1_pos]>0.85)&&(a1[i1][MN1_pos]>0.1)&&(a1[i1][Rd1_pos]>0.1)&&(a1[i1][Rxo1_pos]>0.1))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[lj];

                       // itz=i1;//检测用
                        for(int i0=i1;i0<stp1;i0++)
                        {
                              Tmbjsj[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                              Tmbjsj[ie2][0]=a1[i0][0];
                              Tmbjsj[ie2][2]=a1[i0][Rd1_pos];
                              Tmbjsj[ie2][3]=a1[i0][DEN1_pos];
                              Tmbjsj[ie2][4]=a1[i0][HAC1_pos];
                              Tmbjsj[ie2][5]=a1[i0][Rxo1_pos];
                              Tmbjsj[ie2][6]=a1[i0][GR1_pos];
                              if(Tmbjsj[ie2][1]<1.0)
                              {
                                 Tmbj=0;
                              }
                              Rmn1[ie2]=Tmbjsj[ie2][prc];
                              ie2++;
                        }
                        Filter(Tmbjsj,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);

                       // if(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice(Sender);
                        }
                       // if((v[1]<zdz1)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0]))
                      //  if((v[1]<zdz1)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname+1]-mbjxfcmkz)))
                        if((v[1]<=zxz1)&&(a1[stp][0]>mbdeep[isname-1]))
                        {
                           zxz1=v[1];
                           deepp[1]=a1[stp][0];
                         //  xuanze[i09][prc][1]=a1[stp][0];
                           //jdcw[lj]=stp;          //测井数据数据节点
                           ip[1]=stp;


                        }
        /*  if(str6[lj]=="G25")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*120,i09);
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*120,prc);
             PaintBox2->Canvas->TextOutA(100+54,14+i09*15+(prc-1)*120,deepp[1]);
             PaintBox2->Canvas->TextOutA(200+54,14+i09*15+(prc-1)*120,a1[stmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(300+54,14+i09*15+(prc-1)*120,a1[enmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(400+54,14+i09*15+(prc-1)*120,zxz1);
          }   */

                       // if((v[2]<zdz2)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname+1]-mbjxfcmkz)))
                        if((v[2]<=zxz2)&&(a1[stp][0]>mbdeep[isname-1]))
                        {
                           zxz2=v[2];
                           deepp[2]=a1[stp][0];
                         //  xuanze[i09][prc][2]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[2]=stp;
                        }
       /*   if(str6[lj]=="G25")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*120,i09);
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*120,prc);
             PaintBox2->Canvas->TextOutA(100+54,14+i09*15+(prc-1)*120,deepp[2]);
             PaintBox2->Canvas->TextOutA(200+54,14+i09*15+(prc-1)*120,a1[stmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(300+54,14+i09*15+(prc-1)*120,a1[enmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(400+54,14+i09*15+(prc-1)*120,zxz2);
          }    */

                      //  if((v[3]<zdz3)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname+1]-mbjxfcmkz)))
                        if((v[3]<=zxz3)&&(a1[stp][0]>mbdeep[isname-1]))
                        {
                           zxz3=v[3];
                           deepp[3]=a1[stp][0];
                          // xuanze[i09][prc][3]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[3]=stp;

                        }
       /*  if(str6[lj]=="G25")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*20,i09);
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*20,prc);
             PaintBox2->Canvas->TextOutA(100+54,14+i09*15+(prc-1)*20,deepp[3]);
             PaintBox2->Canvas->TextOutA(200+54,14+i09*15+(prc-1)*20,a1[stmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(300+54,14+i09*15+(prc-1)*20,a1[enmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(400+54,14+i09*15+(prc-1)*20,zxz3);
          }   */

                     //   if((v[4]<zdz4)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname+1]-mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname+1]-mbjxfcmkz)))
                        if((v[4]<=zxz4)&&(a1[stp][0]>mbdeep[isname-1]))
                        {
                           zxz4=v[4];
                           deepp[4]=a1[stp][0];
                          // xuanze[i09][prc][4]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[4]=stp;
        /*  if(str6[lj]=="G217")
          {
             PaintBox2->Canvas->TextOutA(110,84+i09*15+(prc-1)*80,i09);
             PaintBox2->Canvas->TextOutA(140,84+i09*15+(prc-1)*80,"                                              ");
             PaintBox2->Canvas->TextOutA(140,84+i09*15+(prc-1)*80,zdz4);
             PaintBox2->Canvas->TextOutA(200+54,84+i09*15+(prc-1)*80,deepp[4]);
          }   */

                        }

        /* if(str6[lj]=="G36")
          {
             PaintBox2->Canvas->TextOutA(40,24+i09*15+(prc-1)*20,"zxz4 ");
             PaintBox2->Canvas->TextOutA(80,24+i09*15+(prc-1)*20,prc);
             PaintBox2->Canvas->TextOutA(100+54,24+i09*15+(prc-1)*20,deepp[4]);
             PaintBox2->Canvas->TextOutA(200+54,24+i09*15+(prc-1)*20,a1[stmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(300+54,24+i09*15+(prc-1)*20,a1[enmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(400+54,24+i09*15+(prc-1)*20,zxz4);

          }    */
                      //if((v[5]<zdz5)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname+1]-mbjxfcmkz)))
                        if((v[5]<=zxz5)&&(a1[stp][0]>mbdeep[isname-1]))
                        {
                           zxz5=v[5];
                           deepp[5]=a1[stp][0];
                         //  xuanze[i09][prc][5]=a1[stp][0];
                         //  jdcw[lj]=stp;          //测井数据数据节点
                           ip[5]=stp;
        /*   if(str6[lj]=="G36")
          {
             PaintBox2->Canvas->TextOutA(110,104+(prc-1)*110,"v5 ");
             PaintBox2->Canvas->TextOutA(140,104+(prc-1)*110,"                                                             ");
             PaintBox2->Canvas->TextOutA(140,104+(prc-1)*110,v[5]);
             PaintBox2->Canvas->TextOutA(200+54,104+(prc-1)*110,deepp[5]);
             PaintBox2->Canvas->TextOutA(300+54,104+(prc-1)*110,prc);
          }    */

                        }


      /*   if(str6[lj]=="G25")
          {
             PaintBox2->Canvas->TextOutA(40,24+i09*15+(prc-1)*20,"zxz5 ");
             PaintBox2->Canvas->TextOutA(80,24+i09*15+(prc-1)*20,prc);
             PaintBox2->Canvas->TextOutA(100+54,24+i09*15+(prc-1)*20,deepp[5]);
             PaintBox2->Canvas->TextOutA(200+54,24+i09*15+(prc-1)*20,a1[stmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(300+54,24+i09*15+(prc-1)*20,a1[enmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(400+54,24+i09*15+(prc-1)*20,zxz5);
          }   */

                       }


                     }

                   }
        /*  if(str6[lj]=="S222+3b")
          {
             PaintBox2->Canvas->TextOutA(50,14+i09*14+(prc-1)*120,i09);
             PaintBox2->Canvas->TextOutA(80,14+i09*14+(prc-1)*120,prc);
             PaintBox2->Canvas->TextOutA(50+64,14+i09*14+(prc-1)*120,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(150+94,14+i09*14+(prc-1)*120,CDeep[lj]);
             PaintBox2->Canvas->TextOutA(250+94,14+i09*14+(prc-1)*120,deepp[1]);
             PaintBox2->Canvas->TextOutA(350+94,14+i09*14+(prc-1)*120,deepp[2]);
             PaintBox2->Canvas->TextOutA(450+94,14+i09*14+(prc-1)*120,deepp[3]);
             PaintBox2->Canvas->TextOutA(550+94,14+i09*14+(prc-1)*120,deepp[4]);
             PaintBox2->Canvas->TextOutA(650+94,14+i09*14+(prc-1)*120,deepp[5]);
             PaintBox2->Canvas->TextOutA(100,14,a1[stmbzxz[lj]][0]);
             PaintBox2->Canvas->TextOutA(250,14,a1[enmbzxz[lj]][0]);
            // PaintBox2->Canvas->TextOutA(50,184+i09*20+(prc-1)*20,zxz1);
           //  PaintBox2->Canvas->TextOutA(150+14,184+i09*20+(prc-1)*20,zxz2);
            // PaintBox2->Canvas->TextOutA(250+24,184+i09*20+(prc-1)*20,zxz3);
            // PaintBox2->Canvas->TextOutA(350+34,184+i09*20+(prc-1)*20,zxz4);
           //  PaintBox2->Canvas->TextOutA(450+44,184+i09*20+(prc-1)*20,zxz5);
          }  */
               /*    float bestdeep=0.0;
                   for(int u0=1;u0<=i09;u0++)
                   {
                       if((fabs(Rmnselect1[u0][1][1]-Rmnselect1[u0][2][1])<0.02)&&(fabs(Rmnselect1[u0][1][1]-Rmnselect1[u0][3][1])<0.02)&&(fabs(Rmnselect1[u0][1][1]-Rmnselect1[u0][3][1])<0.02)\
                       &&(fabs(Rmnselect1[u0][1][1]-Rmnselect1[u0][4][1])<0.02)&&(fabs(Rmnselect1[u0][1][1]-Rmnselect1[u0][5][1])<0.02))
                       {
                            bestdeep=Rmnselect1[u0][1][1];
                       }
                   }
                 stmb2[lj]=stmb[lj];
                enmb2[lj]=enmb[lj];
               AICXFCPearsonSYTD2(Sender);    //智能细分层
               se2[prc]=psmbdp[lj];
                 Rse1[prc]=Rmnselect;
                 se1[prc]=selectxfcdeep;     */
           /*   if(str6[lj]=="S28b")
              {
                 for(int i1=1;i1<6;i1++)
                 {
                     for(int i2=1;i2<6;i2++)
                     {
                         PaintBox2->Canvas->TextOutA(50,(i2+1)*20+18+140*i1,Rmnselect2[i09][i1][i2]);
                         PaintBox2->Canvas->TextOutA(150,(i2+1)*20+18+140*i1,deepp[i1]);
                     }
                 }

              }   */

           // deepp[6]=Rmnselect;
           int is=0;float psdeep=0.0;
           if(ic2<ic3)
           {
               is=ic2;
           }
           else
           {
              is=ic3;
           }
           if(i09<=is)
           {

                  for(int i1=1;i1<=5;i1++)
                  {
                     if((deepp[i1]>100.0)&&(deepp[i1]>a1[stmbzxz[lj]][0])&&(deepp[i1]<a1[enmbzxz[lj]][0]))
                     {
                         Ps[ic1+i1-1]=deepp[i1];
                       /*  if(str6[lj]=="S28c")
                         {
                            PaintBox2->Canvas->TextOutA(50,14+i09*14+(prc-1)*120,i09);
                            PaintBox2->Canvas->TextOutA(80,14+i09*14+(prc-1)*120,prc);
                            PaintBox2->Canvas->TextOutA(50+64,14+i09*14+(prc-1)*120,ic1);
                            PaintBox2->Canvas->TextOutA(150+94,14+i09*14+(prc-1)*120,Ps[ic1+i1-1]);
                         }   */
                     }
                  }
                  ic1=ic1+5;
           }
           if(i09==is)
           {

              /* for(int i1=0;i1<ic1;i1++)
               {
                   if(Ps[i1]>100.0)
                   {
                       PPS[icc1]=Ps[i1];
                       icc1++;
                   }
               }  */
               for(int i1=0;i1<ic1-1;i1++)
               {
                  int inu=0;
                  for(int i2=i1+1;i2<ic1;i2++)
                  {
                      if((fabs(Ps[i1]-Ps[i2])<0.2)&&(Ps[i1]>100.0)&&(Ps[i2]>100.0))
                      {
                          inu++;
                          if(inu>int(icc1/3))
                          {
                              psdeep=Ps[i2];
                          }

                      }
                  }
               }
           }
               /*  if(str6[isname]=="G25")
                 {      int iu1,iu2;
                     for(int i1=0;i1<icc1;i1++)
                     {
                       iu1=300*int((i1-21)/42);
                       iu2=i1-42*int((i1-21)/42);
                       PaintBox2->Canvas->TextOutA(50+iu1,(iu2+1)*15+18,i1);
                       PaintBox2->Canvas->TextOutA(100+iu1,(iu2+1)*15+18,PPS[i1]);
                       PaintBox2->Canvas->TextOutA(200+iu1,(iu2+1)*15+18,icc1);
                       PaintBox2->Canvas->TextOutA(300+iu1,(iu2+1)*15+18,psdeep);
                     }
                 }  */
                    /* if(str6[isname]=="S28c")
                     {
                         PaintBox2->Canvas->TextOutA(50,(i09+1)*15+18,i09);
                         PaintBox2->Canvas->TextOutA(150,(i09+1)*15+18,is);
                         PaintBox2->Canvas->TextOutA(250,(i09+1)*15+18,ic1);
                         PaintBox2->Canvas->TextOutA(350,(i09+1)*15+18,psdeep);

                     }  */
             //  for(int i2=i1+1;i2<6;i2++)
           if((i09==is)&&(psdeep>100.0))
           {
              CDeep[lj]=psdeep;
              mbdeep[lj]=CDeep[lj];
                   /*  if(str6[isname]=="G25")
                     {
                         PaintBox2->Canvas->TextOutA(50,(i09+1)*20+18,i09);
                         PaintBox2->Canvas->TextOutA(150,(i09+1)*20+18,is);
                         PaintBox2->Canvas->TextOutA(250,(i09+1)*20+18,psdeep);
                     }   */
           }
           else
           {
               for(int i2=1;i2<6;i2++)
               {
                  // if((fabs(deepp[i2]-deepp[i1])<0.02)&&(deepp[i1]>100.0)&&(deepp[i2]>100.0))
                  if((prc==5)&&(zxz5>20.0))
                  {
                     if((fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i2]-mbdeep[lj-1]))<sd2)&&(deepp[i2]>100.0))
                     {
                        sd2=fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i2]-mbdeep[lj-1]));
                        CDeep[lj]=deepp[i2];
                        mbdeep[lj]=CDeep[lj];
                     }
                  }
               }
          //  }
              if((zxz1<380.0)&&(zxz2<4.5)&&(zxz3<45.0)&&(fabs(deepp[1]-deepp[2])<0.02)&&(fabs(deepp[1]-deepp[3])<0.02))
              {
                 CDeep[lj]=deepp[1];
                 mbdeep[lj]=CDeep[lj];
              }
          }
        /*  if(str6[lj]=="S28c")
          {
             PaintBox2->Canvas->TextOutA(80,54+i09*20+(prc-1)*80,"7S28c=");
             PaintBox2->Canvas->TextOutA(150,54+i09*20+(prc-1)*80,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(250,54+i09*20+(prc-1)*80,CDeep[lj]);
             PaintBox2->Canvas->TextOutA(350,54+i09*20+(prc-1)*80,i09);
             PaintBox2->Canvas->TextOutA(450,54+i09*20+(prc-1)*80,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(550,54+i09*20+(prc-1)*80,a1[enmb[lj]][0]);
          }   */
        /*     if(fabs((ckdeep[lj]-ckdeep[lj-1])-(Rmnselect-mbdeep[lj-1]))<fabs((ckdeep[lj]-ckdeep[lj-1])-(selectxfcdeep-mbdeep[lj-1])))   //  2025-6-8
            // if(fabs(ckdeep[lj]-Rmnselect)<fabs(ckdeep[lj]-selectxfcdeep))
             {
                 CDeep[lj]=Rmnselect;
                 mbdeep[lj]=CDeep[lj];   // 2025-6-7
             }
             else
             {
                CDeep[lj]=selectxfcdeep;
                mbdeep[lj]=CDeep[lj];
             }  */

      /*   xuanze[i09][1][1]=zdz1; xuanze[i09][1][2]=deepp[1];
         xuanze[i09][2][1]=zdz2; xuanze[i09][2][2]=deepp[2];
         xuanze[i09][3][1]=zdz3; xuanze[i09][3][2]=deepp[3];
         xuanze[i09][4][1]=zdz4; xuanze[i09][4][2]=deepp[4];
         xuanze[i09][5][1]=zdz5; xuanze[i09][5][2]=deepp[5]; */
 /*     if(fabs((ckdeep[lj]-ckdeep[lj-1])-(mbdeep[lj]-mbdeep[lj-1]))>mbjxfcxzmkz)
      {
             if(prc==4)   //计算到最后一条曲线
             {
               float sdp[100];
               sdp[1]=Rse1[1];sdp[2]=Rse1[2];sdp[3]=Rse1[5];sdp[4]=Rse1[4];
               sdp[5]=se1[1];sdp[6]=se1[2];sdp[7]=se1[5];sdp[8]=se1[4];
               sdp[9]=se2[1];sdp[10]=se2[2];sdp[11]=se2[5];sdp[12]=se2[4];
               for(int i0=1;i0<6;i0++)
               {
                   Rse1[i0]=0.0;
                   se1[i0]=0.0;
               }
               int imk=0;  int io=0; deeplast=0.0;
            for(int i1=1;i1<=11;i1++)
            {

               for(int i2=i1+1;i2<=12;i2++)
               {
                  if(fabs(sdp[i1]-sdp[i2])<0.3)
                  {
                    // deeplast=deep[i1];
                    // jdcw[lj]=ip[i1];
                     io=io+1;
                  }

               }
               if(io>imk)                                            //2025年5月27日 修改前完美
               {
                  imk=io;
                  deeplast=sdp[i1];
                  jdcw[lj]=ip[i1];
               }
            }

            if(deeplast>100.0)
            {
               CDeep[lj]=deeplast;
               mbdeep[lj]=CDeep[lj];
             // deeplast=Rmnselect;
             // jdcw[lj]=ip[1];
            }
            else
            {
                float fcdp=99999.0,fcdeep=0.0;
                for(int i1=1;i1<=8;i1++)
                {
                    if(fabs(ckdeep[lj]-sdp[i1])<fcdp)
                               {
                                   fcdp=fabs(ckdeep[lj]-sdp[i1]);
                                   fcdeep=sdp[i1];
                               }


                }
                CDeep[lj]=fcdeep;
                mbdeep[lj]=CDeep[lj];

            }

             float gp=99999999999999.0,dplast=0.0;
             for(int u0=1;u0<=i09;u0++)
             {
                 for(int u1=1;u1<6;u1++)
                 {
                     for(int u2=1;u2<6;u2++)
                     {
                       if(fabs(ckdeep[lj]-Rmnselect2[u0][u1][u2])<gp)
                       {
                          gp=Rmnselect2[u0][u1][u2];
                          dplast=Rmnselect2[u0][u1][u2];
                       }
                     }
                 }
             }
                if(fabs(ckdeep[lj]-dplast)<fabs(ckdeep[lj]-CDeep[lj]))
                {
                    CDeep[lj]=dplast;
                    mbdeep[lj]=CDeep[lj];
                }
             }
      }   */
        /*  if(Rmnselect>100.0)
          {
               CDeep[lj]=Rmnselect;
               mbdeep[lj]=CDeep[lj];
          }  */
 /*         int op=0;
          for(int i5=1;i5<=i09;i5++)
          {
              if((fabs(xuanze[i5][2][1]-xuanze[i5][5][1])<0.2)&&(op==0))
              {
                   CDeep[lj]=xuanze[i5][2][1];
                   mbdeep[lj]=CDeep[lj];
                   op=1;
              }
              else if((fabs(xuanze[i5][1][1]-Rmnselect)<0.01)&&(fabs(xuanze[i5][2][1]-Rmnselect)<0.01)&&(fabs(xuanze[i5][5][1]-Rmnselect)<0.01))
              {
                  CDeep[lj]=Rmnselect;
                  mbdeep[lj]=CDeep[lj];
              }
          }
            if(bestdeep>100.0)
            {
                CDeep[lj]=bestdeep;
                mbdeep[lj]=CDeep[lj];
            }
            for(int i4=100;i4<ljcgs;i4++)
            {
                if(fabs(a1[i4][0]-CDeep[lj])<0.02)
                {
                    Rmnmb[lj]=a1[i4][MN1_pos];
                }
            }    */
        /*  if(str6[lj]=="S32b")
          {
             PaintBox2->Canvas->TextOutA(120,584,"7S32b=");
             PaintBox2->Canvas->TextOutA(150+64,584,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(250+94,584,CDeep[lj]);
             PaintBox2->Canvas->TextOutA(350+94,584,bestdeep);
          }  */


       /*     for(int i1=1;i1<6;i1++)
              {
                 if(fabs(ckdeep[lj]-deep[i1])<selectbzcdp)
                 {
                     selectbzcdp=fabs(ckdeep[lj]-deep[i1]);
                     selectbzcdeep=deep[i1];
                 }

              }
              CDeep[lj]=selectbzcdeep;  */









   /*        int imk=0;  int io=0;
            for(int i1=1;i1<=4;i1++)
            {

               for(int i2=i1+1;i2<=5;i2++)
               {
                  if(fabs(Rmnselect2[i1]-Rmnselect2[i2])<0.3)
                  {
                    // deeplast=deep[i1];
                    // jdcw[lj]=ip[i1];
                     io=io+1;
                  }

               }
               if(io>imk)                                            //2025年5月27日 修改前完美
               {
                  imk=io;
                  deeplast=Rmnselect2[i1];
                  jdcw[lj]=ip[i1];
               }
            }

            if(deeplast>100.0)
            {
               CDeep[lj]=deeplast;
               mbdeep[lj]=CDeep[lj];
             // deeplast=Rmnselect;
             // jdcw[lj]=ip[1];
            }
               */
         /*   float sd2=9999.0,sd1;
            deep[6]=Rmnselect;
            for(int i1=0;i1<7;i1++)
            {
              if(str6[lj]=="S213")
              {
                 PaintBox2->Canvas->TextOutA(50+44,(i1+1)*20+164,Rmnselect);
                 PaintBox2->Canvas->TextOutA(150+84,(i1+1)*20+164,deep[i1]);
              }
                sd1=fabs(ckjcjlcxz[lj]-(deep[i1]-mbjdcjx[lj]));
                if(sd1<sd2)
                {
                   sd2=sd1;
                   Rmnselect=deep[i1];
                }
            }
             if(Rmnselect>100.0)
             {
               CDeep[lj]=Rmnselect;
               mbdeep[lj]=CDeep[lj];
             }
                                   */

         //   PaintBox2->Canvas->TextOutA(40,20+(lj-1)*14,str6[lj]);
         //   PaintBox2->Canvas->TextOutA(80,20+(lj-1)*14,Rmnselect);
        /*    PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+14*20,wincu[lj]+wincd[lj]);
            PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+15*20,mbdeep[lj]);
            PaintBox2->Canvas->TextOutA(20+(lj-1)*120,204+16*20,"ie1=");
            PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+16*20,ie1);
            PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+17*20,ie2);
            PaintBox2->Canvas->TextOutA(20+(lj-1)*120,204+17*20,"ie2=");   */
           /* if(str6[lj]=="G26")
            {
            PaintBox2->Canvas->TextOutA(80,204+0*20,str6[lj]);
            PaintBox2->Canvas->TextOutA(80,204+1*20,deep[1]);
            PaintBox2->Canvas->TextOutA(80,204+2*20,deep[2]);
            PaintBox2->Canvas->TextOutA(80,204+3*20,deep[3]);
            PaintBox2->Canvas->TextOutA(80,204+4*20,deep[4]);
            PaintBox2->Canvas->TextOutA(80,204+5*20,deep[5]);
            PaintBox2->Canvas->TextOutA(80,204+6*20,a1[stmb[lj]][0]);
            PaintBox2->Canvas->TextOutA(80,204+7*20,a1[enmb[lj]][0]);
            PaintBox2->Canvas->TextOutA(80,204+8*20,CDeep[lj]);
            PaintBox2->Canvas->TextOutA(80,204+9*20,stmb[lj]);
            PaintBox2->Canvas->TextOutA(80,204+10*20,enmb[lj]);
            }    */
}
//------------------------------------------------------------------------------------

void __fastcall TForm1::ljsjkxfccorrect(TObject *Sender)    //邻井数据库细分层修正
{
        float relvc;   float p1,p2;
        int num = 0;  i08=0; i07=0;tnum=15;
        zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0;zdz4=9999999.0; zdz5=9999999.0;
    Rmnselect=0.0;selectxfcdeep=0.0;Rm1=999999.0;
      Rm2=999999.0;float cjlczxz=9999999.0,xfcljsjkdeep=0.0,pk1=0.0;
   deeplast=0.0; selectxfcdp=9999999.0;
   float ps1[40],ps2[40],ps3[40],ps4[40];
   float dp2=0.0; cjjxfDJXmkz[0]=1.6;cjjxfDJXmkz[1]=3.5;cjjxfDJXmkz[2]=1.2;    //层间距细分底界线门槛值
   n=6;i09=0;int it,nsa=0;//open_switch=1;
   lj=isname;
   FILE *fp; int i2=n+1;ie1=0;AnsiString Dir;
   if(xzkg==1)
   {          // xzkg;  //选择开关
       Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\"+str16[isname]+"\\";
   }
   else if(xzkg==2)
   {
      Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\沉积单元数据库\\"+str16[isname]+"\\";
   }
   TSearchRec sr;
   TStringList *FileList = new TStringList();


   ccp2.SetLength(ccp2.Length()-3);
   AnsiString filename = ccp2;                 //文件名
   ccp2.SetLength(ccp2.Length()+3);
   int count = filename.Length();              //文件名字符数
   AnsiString s1;
   AnsiString s2;
   AnsiString s4;
   AnsiString s6;
   AnsiString s9;

   char * filename1 = filename.c_str();
   for(int i = 0;i < count-1;i++)
   {
        s1 = s1 + filename1[i];
   }
   for(int i = 0;i < count-2;i++)
   {
        s2 = s2 + filename1[i];
   }
   for(int i = 0;i < count-4;i++)
   {
        s4 = s4 + filename1[i];
   }
   for(int i = 0;i < count-6;i++)
   {
        s6 = s6 + filename1[i];
   }
   for(int i = 0;i < 2;i++)
   {
        s9 = s9 + filename1[i];
   }

   AnsiString Dir00 = Dir + "n*.*" + '.';      //n开头文件
   AnsiString Dir1 = Dir + s1 + "*.*" + '.';   //前count-1个字符相同文件
   AnsiString Dir2 = Dir + s2 + "*.*" + '.';   //前count-2个字符相同文件
   AnsiString Dir4 = Dir + s4 + "*.*" + '.';   //前count-4个字符相同文件
   AnsiString Dir6 = Dir + s6 + "*.*" + '.';   //前count-6个字符相同文件
   AnsiString Dir99 = Dir + s9 + "*.*" + '.';   //前count-6个字符相同文件

   int same = 0;                               //重复文件名判断
   vector<AnsiString> temp;                    //操作数组
   vector<AnsiString> fil;                     //文件名序列数组
   vector<AnsiString> fil2;                    //文件名数组


   FindFirst(Dir1, faAnyFile, sr);             //前count-1个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir2, faAnyFile, sr);            //前count-2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir4, faAnyFile, sr);            //前count-4个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
////                                          //前count-6个字符相同文件加入FileList和fil数组
   FindFirst(Dir6, faAnyFile, sr);
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir99, faAnyFile, sr);            //前2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));

////                                           ////n开头文件加入FileList和fil数组
     FileList->Clear();
     fil.clear();
     fil2.clear();
     String temp2[2000];
     int checked = 0;
     int checked2 = 0;


////                                           ////剔除重复
     for(int i = 0;i < temp.size();i ++)
     {
        //String TempWell0 = temp[i];
        for(int j = 0;j < 2000;j ++)
        {
                if(temp2[checked] == temp2[j] && checked > 0)
                        break;
                checked2 = 0;
                for(int k = 0;k < i;k ++)
                {
                        if(temp[k] == temp[i])
                                checked2 = 1;
                }
                if(checked2 != 0)
                        break;
                else
                {
                        temp2[checked] = temp[i];
                        FileList->Add(temp2[checked]);
                        fil.push_back(temp2[checked]);
                        fil2.push_back(ExtractFileName(temp2[checked]));
                        checked ++;
                        break;
                }
        }

     }

   temp.clear();
   FileList->Count;                           //文件名列表计数
   AnsiString o1 = FileList->Text;
   FileList->SaveToFile("D:\\001.txt");     //输出文件名到txt

   string fname[20];                         //文件路径数组
   string fn[20];                         //文件名数组
   int file_count = 0;
   for(int i = 0;i < 20;i ++)                //前20个文件
   {

        fname[i] = fil[i].c_str();
                 //   PaintBox2->Canvas->TextOutA(70,440+i*14,"name=");
                  /*  if(str6[isname]=="S213")
                    {
                       PaintBox2->Canvas->TextOutA(70,40+i*14,file_count);

                       PaintBox2->Canvas->TextOutA(70+54,40+i*14,fname[i].c_str());

                    } */
        fn[i] = fil2[i].c_str();
                  /*  if(str6[isname]=="S213")
                    {
                       PaintBox2->Canvas->TextOutA(70,340+i*14,file_count);
                       PaintBox2->Canvas->TextOutA(70+54,340+i*14,fil2[i].c_str());
                    }  */
        file_count ++;
        if(file_count == fil.size())
        break;

   }
    if(file_count<tnum)
    {
      tnum=file_count;
    }
    else
    {
       tnum=15;
    }
    xzc=1;
    open_correct=1;
   // lj=isname;
 /*  if(str6[isname]=="S213")
   {
       PaintBox2->Canvas->TextOutA(100,440,"file_count=   ");
       PaintBox2->Canvas->TextOutA(200,440,file_count);
   }  */
if (file_count >3)
{
do{
      if (num == file_count)
      break;
       btn=num;

    //  if((CDeep[isname]<10.0)&&(open_correct==0)&&(isname<=2))
      {
        fp=fopen(fname[num].c_str(),"r");
        if(fp)
        {
           ie1=0;                 //计算打开非零文件个数
           fscanf(fp,"%f %f %f %f %d",&start2[isname],&end2[isname],&ckja2[isname],&relvc,&totalnumb[isname]);

           chcsh2[isname]=totalnumb[isname];
           stpinsjk[isname]=int((ckja2[isname]-start2[isname])/relvc);                  //数据库节点
           prc=5;
           while(feof(fp)==0)
           {
                for(int j=0;j<i2;j++)
                {
                        fscanf(fp,"%f",&xcsj[ie1][j]);
                        xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
                        //bzcsj[ie1][j]=xcsj[ie1][j];
                }
                Rmn[ie1]=xcsj[ie1][prc];
                ie1++;
           }

           int i5=0;
           i5=int((ckja2[isname]-start2[isname])/relvc);
           Rmnck[isname]=xcsj[i5][1];

            p1=mbjckcw[isname];
            p2=mbjckcw[isname]+(end2[isname]-start2[isname])*2.0;
           // p1=mbjckcw[isname]-wincu[isname]*2.4;
           // p2=mbjckcw[isname]+(end2[isname]-start2[isname])*2.0;

            for(int i1=20;i1<stedp1;i1++)
            {
               if(fabs(a1[i1][0]-p1)<0.02)
               {
                  stmb[isname]=i1;
               }
               if(fabs(a1[i1][0]-p2)<0.02)
               {
                  enmb[isname]=i1;
               }
            }
            ps2[num]=mbdeep[isname];

           StdCw=str6[isname];
           AICXFCljsjk(Sender);
           f1[i09][4]=mbdeep[isname];

                 prc=1;
                 for(int io=0;io<ie1;io++)
                 {
                     Rmn[io]=xcsj[io][prc];
                 }
                 StdCw=str6[isname];
                 AICXFCljsjk(Sender);
                 f1[i09][1]=mbdeep[isname];

                     prc=2;
                     for(int io=0;io<ie1;io++)
                     {
                        Rmn[io]=xcsj[io][prc];
                     }
                     StdCw=str6[isname];
                     AICXFCljsjk(Sender);
                     f1[i09][2]=mbdeep[isname];

                          prc=4;
                          for(int io=0;io<ie1;io++)
                          {
                             Rmn[io]=xcsj[io][prc];
                          }
                          StdCw=str6[isname];
                          AICXFCljsjk(Sender);
                          f1[i09][3]=mbdeep[isname];

       }
      }
      fclose(fp);
      num ++;
      i09=i09+1;
     }while((i09 <tnum));    //while((i09 < 20)&&(open_correct<2));   2025-08-13  改为循环5口井

    FindClose(sr);
 }
        /*   if(str6[isname]=="S211a")
            {
               PaintBox2->Canvas->TextOutA(250+54,54+4*104,mbdeep[isname]);
               PaintBox2->Canvas->TextOutA(350+54,54+4*104,mbdeepc[isname]);
               PaintBox2->Canvas->TextOutA(450+54,54+4*104,p1);
               PaintBox2->Canvas->TextOutA(550+54,54+4*104,p2);
            }   */
   // mbdeepc[isname]=mbdeep[isname];

          int i20=0,i6=0; float sb=0.0;
          for(int i1=1;i1<=i09;i1++)
          {
             Fi[i20]=f1[i1][1];i20=i20+1;
             Fi[i20]=f1[i1][2];i20=i20+1;
             Fi[i20]=f1[i1][3];i20=i20+1;
             Fi[i20]=f1[i1][4];i20=i20+1;
          }
          for(int i3=0;i3<=i20-2;i3++)
          {
                  /*   if(str6[isname]=="G13b")
                      {
                          if(i3<=42)
                          {
                              PaintBox2->Canvas->TextOutA(50,14+14*i3,i3);
                              PaintBox2->Canvas->TextOutA(50+54,14+14*i3,Fi[i3]);
                          }
                          else if((i3>42)&&(i3<=84))
                          {
                              PaintBox2->Canvas->TextOutA(220,14+14*(i3-42),i3);
                              PaintBox2->Canvas->TextOutA(200+54,14+14*(i3-42),Fi[i3]);
                          }
                          else if((i3>84)&&(i3<=128))
                          {
                              PaintBox2->Canvas->TextOutA(350,14+14*(i3-84),i3);
                              PaintBox2->Canvas->TextOutA(350+54,14+14*(i3-84),Fi[i3]);
                          }
                          else
                          {
                              PaintBox2->Canvas->TextOutA(520,14+14*(i3-128),i3);
                              PaintBox2->Canvas->TextOutA(520+54,14+14*(i3-128),Fi[i3]);
                          }
                      }  */
             int i5=0;
             for(int i4=i3+1;i4<=i20-1;i4++)
             {
                 if((fabs(Fi[i3]-Fi[i4])<0.1)&&(Fi[i3]>100.0)&&(Fi[i4]>100.0))    //<0.15不可以再改 大
                 {
                     i5++;
                     if(i5>i6)
                     {
                        i6=i5;
                      //  if(fabs((ckdeep[lj]-ckdeep[lj-1])-(Fi[i4]-mbdeep[lj-1]))<fabs((ckdeep[lj]-ckdeep[lj-1])-(Fi[i3]-mbdeep[lj-1])))
                        {
                            sb=Fi[i4];
                        }
                      /*  else
                        {
                           sb=Fi[i3];
                        }  */
                     }
                 }
             }
          }
          if(sb>100.0)
          {
             CDeep[isname]=sb;
             mbdeep[isname]=CDeep[isname];
             mbdeepc[isname]=CDeep[isname];
          }
           /* if(str6[isname]=="S310b")
            {
               PaintBox2->Canvas->TextOutA(240,34+4*104,"5S29=");
               PaintBox2->Canvas->TextOutA(250+54,34+4*104,mbdeep[isname]);
               PaintBox2->Canvas->TextOutA(250+54,54+4*104,sb);
              // PaintBox2->Canvas->TextOutA(250+54,74+4*104,p1);
             //  PaintBox2->Canvas->TextOutA(250+54,94+4*104,p2);
               PaintBox2->Canvas->TextOutA(250+54,74+4*104,CDeep[isname]);
            }   */
  // }

}
//-----------------------------------------------------------------------------------
void __fastcall TForm1::XFCDJMXZ(TObject *Sender)     //细分层底界面修正
{
      float xfcmkz=99999999.0,mbdeep2; Rm1=999999.0;
      zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0;zdz4=9999999.0; zdz5=9999999.0;
    Rmnselect=0.0;selectxfcdp=99999.0;selectxfcdeep=0.0;Rm1=999999.0;
      Rm2=999999.0;deeplast=0.0;
       float p1,p2;
        p1=mbdeep[lj+1]-(ckdeep[lj+1]-ckdeep[lj-1])-wincu[lj];
        p2=mbdeep[lj+1];
        sname=str6[lj];
        isname=lj;
        for(int i1=0;i1<10;i1++)
        {
           for(int j2=1;j2<6;j2++)
           {
              for(int i3=1;i3<30;i3++)
              {
                   Rmnselect2[i3][j2][i1]=0.0;
              }
           }
        }
        for(int i1=20;i1<stedp1;i1++)
        {
           if(fabs(a1[i1][0]-p1)<0.02)
           {
              stmb[lj]=i1;
           }
           if(fabs(a1[i1][0]-p2)<0.02)
           {
              enmb[lj]=i1;
           }
        }
        prc=5;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
      // mbdeep[lj]=CDeep[isname];
      /*   PaintBox2->Canvas->TextOutA(20,14+(lj-1)*14,str16[lj]);
         PaintBox2->Canvas->TextOutA(20+154,14+(lj-1)*14,mbdeep[lj]);
         PaintBox2->Canvas->TextOutA(20+354,14+(lj-1)*14,p1);
         PaintBox2->Canvas->TextOutA(20+504,14+(lj-1)*14,mbdeep[lj+1]);  */
       if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2)&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层
       {
           xfcmkz=fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]));   //细分层门槛值
           mbdeep2=CDeep[isname];
       }
       prc=2;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
     //  mbdeep[lj]=CDeep[isname];

      if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2)&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层
       {
           xfcmkz=fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]));
           mbdeep2=CDeep[isname];
       }
       prc=1;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
      // mbdeep[lj]=CDeep[isname];

      if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2)&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层
       {
           xfcmkz=fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]));
           mbdeep2=CDeep[isname];
       }
       prc=4;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
      // mbdeep[lj]=CDeep[isname];

      if((fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2)&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层
       {
           xfcmkz=fabs((ckdeep[lj+1]-ckdeep[lj])-(mbdeep[lj+1]-mbdeep[lj]));
           mbdeep2=CDeep[isname];
       }
       prc=5;
       if(mbdeep2>100.0)
       {
           mbdeep[lj]=mbdeep2;
           CDeep[lj]=mbdeep2;
       }
        xfcmkz=99999999.0;

}
//-----------------------------------------------------------------------------
void __fastcall TForm1::XFC(TObject *Sender)     //细分层
{
       float xfcmkz=99999999.0,mbdeep2=0.0,mdeep[10];
       float p1,p2,sel=999999.0,sele=0.0;
        zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0;zdz4=9999999.0; zdz5=9999999.0;
    Rmnselect=0.0;selectxfcdp=99999.0;selectxfcdeep=0.0;Rm1=999999.0;
      Rm2=999999.0;deeplast=0.0;
       sname=str6[lj];
        p1=mbjckcw[lj]+ckjcjlcxfc[lj]-(ckdeep[lj]-ckdeep[lj-1])-wincu[lj];
        p2=mbjckcw[lj]+ckjcjlcxfc[lj]+(ckdeep[lj+1]-ckdeep[lj]);
       /* if(str6[lj]=="S214b")
          {
             PaintBox2->Canvas->TextOutA(50,204,"3S214b=");
             PaintBox2->Canvas->TextOutA(50+54,204,mbjckcw[lj]);
             PaintBox2->Canvas->TextOutA(50+54,224,ckjcjlcxfc[lj]);
             PaintBox2->Canvas->TextOutA(50+54,244,p1);
             PaintBox2->Canvas->TextOutA(50+54,264,p2);
          }    */
        for(int i1=20;i1<stedp1;i1++)
        {
           if(fabs(a1[i1][0]-p1)<0.02)
           {
              stmb[lj]=i1;
           }
           if(fabs(a1[i1][0]-p2)<0.02)
           {
              enmb[lj]=i1;
           }
        }
        for(int i0=0;i0<10;i0++)
        {
           mdeep[i0]=0.0;
           for(int j0=1;j0<6;j0++)
           {
               for(int i3=1;i3<30;i3++)
               {
                   Rmnselect2[i3][j0][i0]=0.0;
               }
           }
        }
       prc=5;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
       mdeep[0]=CDeep[lj];
         /*  if(str6[lj]=="S214b")
          {
             PaintBox2->Canvas->TextOutA(50,204,"1S214b=");
             PaintBox2->Canvas->TextOutA(50+54,204,mdeep[0]);
          }  */
       if((fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2))       //参考井层间落差细分层
       {
           xfcmkz=fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]));   //细分层门槛值
           mbdeep2=CDeep[lj];
       }
       prc=2;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
       mdeep[1]=CDeep[lj];
        /*  if(str6[lj]=="S214b")
          {
             PaintBox2->Canvas->TextOutA(50,224,"2S214b=");
             PaintBox2->Canvas->TextOutA(50+54,224,mdeep[1]);
          }  */
      if((fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2))       //参考井层间落差细分层
       {
           xfcmkz=fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]));
           mbdeep2=CDeep[lj];
       }
       prc=1;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
       mdeep[2]=CDeep[lj];
        /*  if(str6[lj]=="S214b")
          {
             PaintBox2->Canvas->TextOutA(50,244,"3S214b=");
             PaintBox2->Canvas->TextOutA(50+54,244,mdeep[2]);
          }  */

      if((fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2))       //参考井层间落差细分层
       {
           xfcmkz=fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]));
           mbdeep2=CDeep[lj];
       }
       prc=4;      //应用到处理曲线
       AIXFC(Sender);    //智能细分层
       mdeep[3]=CDeep[lj];
         /* if(str6[lj]=="S214b")
          {
             PaintBox2->Canvas->TextOutA(50,264,"4S214b=");
             PaintBox2->Canvas->TextOutA(50+54,264,mdeep[3]);
          }   */
      if((fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))<xfcmkz)&&(mbdeep[lj]>p1)&&(mbdeep[lj]<p2))       //参考井层间落差细分层
       {
           xfcmkz=fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]));
           mbdeep2=CDeep[lj];
       }
       prc=5;
     /* if(mbdeep2>100.0)
      {
          mbdeep[lj]=mbdeep2;
      }        */
      int p10=0;
      for(int i1=0;i1<3;i1++)
      {
         for(int i2=i1+1;i2<4;i2++)
         {

             if(fabs(mdeep[i1]-mdeep[i2])<mbjxfcmkz)
             {
                 mbdeep[lj]=mdeep[i1]; p10=p10+1;
             }
         }
      }

        xfcmkz=99999999.0;
      for(int i1=0;i1<5;i1++)
      {
         if(fabs(ckdeep[lj]-mdeep[i1])<sel)
         {
            sel=fabs(ckdeep[lj]-mdeep[i1]);
            sele=mdeep[i1];
         }
      }
      if(p10<1)
      {
         mbdeep[lj]=sele;
         CDeep[lj]=sele;

      }

     /*  if(str6[lj]=="S214b")
          {
             PaintBox2->Canvas->TextOutA(250,284,"5S214b=");
             PaintBox2->Canvas->TextOutA(250+54,284,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(304,304,str6[lj]);
             PaintBox2->Canvas->TextOutA(304,324,ckjcjlcxfc[lj]);
             PaintBox2->Canvas->TextOutA(304,344,mbdeep[lj]-mbjckcw[lj]);
             PaintBox2->Canvas->TextOutA(250+54,364,mbdeepc[lj]);
          }   */



}
//---------------------------------------------------------------------------
void __fastcall TForm1::XFCPearsonSYTD(TObject *Sender)     //细分层皮尔森时域梯度
{
         //利用底界线向上进行标定

              float p11,p22;
              float xfcmkz=99999999.0,mbdeep2=0.1; Rm1=9999.0,Rmnselect=0.0;
       //  if(fabs(ckjcjlcxfc[lj]-(mbdeep[lj]-mbjckcw[lj]))>cjjxfmkz[itz])
         {
            // ckjdjxlc[lj]=ckjdjx[lj]-ckdeep[lj];         //参考井层间落差
            p11=mbjdjx[lj]-ckjdjxlc[lj]-((ckdeep[lj]-ckdeep[lj-1])*2.0+wincu[lj]);
            p22=mbjdjx[lj]-ckjdjxlc[lj]+(ckdeep[lj+1]-ckdeep[lj])+cjjxfmkz[itz]*1.5;

            for(int i1=20;i1<stedp1;i1++)
            {
               if(fabs(a1[i1][0]-p11)<0.02)
               {
                  stmb2[lj]=i1;
               }
               if(fabs(a1[i1][0]-p22)<0.02)
               {
                  enmb2[lj]=i1;                                         
               }
            }
          /*  if(str6[lj]=="S32b")
            {
               PaintBox2->Canvas->TextOutA(120,42,str6[lj]);
               PaintBox2->Canvas->TextOutA(120,62,p11);
               PaintBox2->Canvas->TextOutA(120,82,p22);
               PaintBox2->Canvas->TextOutA(120,102,mbjdjx[lj]);
               PaintBox2->Canvas->TextOutA(120,122,ckjdjxlc[lj]);
               PaintBox2->Canvas->TextOutA(120,142,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(120,162,cjjxfmkz[itz]);
            }  */
            sname=str6[lj];
            if(((mbdeep[lj]<mbdeep[lj-1])||(mbdeep[lj]>p22))&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz))       //参考井层间落差细分层
            {
               xzc=0;
               prc=5;      //应用到处理曲线
               AICXFCPearsonSYTD(Sender);    //智能细分层 皮尔森时域梯度
               mbdeep[lj]=CDeep[lj];
               mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];

        //   if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)||(mbdeep[lj]<p11)||(mbdeep[lj]>p22)||(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层     备份2025年7月10日

                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);   //细分层门槛值
                mbdeep2=CDeep[lj];
           /* if(str6[lj]=="S26")
            {
               PaintBox2->Canvas->TextOutA(120,42,str6[lj]);
               PaintBox2->Canvas->TextOutA(120,62,p11);
               PaintBox2->Canvas->TextOutA(120,82,p22);
               PaintBox2->Canvas->TextOutA(120,102,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(120,122,prc);

            }   */
            }
            if(((mbdeep[lj]<mbdeep[lj-1])||(mbdeep[lj]>p22))&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz))       //参考井层间落差细分层
            {
               prc=2;      //应用到处理曲线
               AICXFCPearsonSYTD(Sender);    //智能细分层
               mbdeep[lj]=CDeep[lj];
               mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];
          /*   if(str6[lj]=="S26")
            {
               PaintBox2->Canvas->TextOutA(120,142,str6[lj]);
               PaintBox2->Canvas->TextOutA(120,162,p11);
               PaintBox2->Canvas->TextOutA(120,182,p22);
               PaintBox2->Canvas->TextOutA(120,202,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(120,222,prc);

            }   */
          //  if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)||(mbdeep[lj]<p11)||(mbdeep[lj]>p22)||(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层  备份2025年7月10日

                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);
                mbdeep2=CDeep[lj];
            }
            if(((mbdeep[lj]<mbdeep[lj-1])||(mbdeep[lj]>p22))&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz))       //参考井层间落差细分层
            {
               prc=1;      //应用到处理曲线
               AICXFCPearsonSYTD(Sender);    //智能细分层
               mbdeep[lj]=CDeep[lj];
               mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];
          /*  if(str6[lj]=="S26")
            {
               PaintBox2->Canvas->TextOutA(120,242,str6[lj]);
               PaintBox2->Canvas->TextOutA(120,262,p11);
               PaintBox2->Canvas->TextOutA(120,282,p22);
               PaintBox2->Canvas->TextOutA(120,302,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(120,322,prc);

            }   */
         //   if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)||(mbdeep[lj]<p11)||(mbdeep[lj]>p22)||(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层    if((mbdeep[lj]<p11)||(mbdeep[lj]>p22))       //参考井层间落差细分层



                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);
                mbdeep2=CDeep[lj];
            }
            if(((mbdeep[lj]<mbdeep[lj-1])||(mbdeep[lj]>p22))&&(fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz))       //参考井层间落差细分层
            {
                prc=4;      //应用到处理曲线
                AICXFCPearsonSYTD(Sender);    //智能细分层
                mbdeep[lj]=CDeep[lj];
                mbjdjxlc[lj]=mbjdjx[lj]-mbdeep[lj];
         /*   if(str6[lj]=="S310b")
            {
               PaintBox2->Canvas->TextOutA(120,442,str6[lj]);
               PaintBox2->Canvas->TextOutA(120,462,p11);
               PaintBox2->Canvas->TextOutA(120,482,p22);
               PaintBox2->Canvas->TextOutA(120,502,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(120,522,prc);

            }  */
           // if((fabs(ckjdjxlc[lj]-mbjdjxlc[lj])<xfcmkz)&&(mbdeep[lj]>p11)&&(mbdeep[lj]<p22)&&(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-mbdeep[lj]))<cjjxfmkz[itz]))       //参考井层间落差细分层  if((mbdeep[lj]<p11)||(mbdeep[lj]>p22))       //参考井层间落差细分层

          //  {
                xfcmkz=fabs(ckjdjxlc[lj]-mbjdjxlc[lj]);
                mbdeep2=CDeep[lj];
            }
            prc=5;
          if((mbdeep2>100.0)&&(mbdeep[lj]>mbdeep[lj-1])&&(mbdeep[lj]<p22))
          {
              mbdeep[lj]=mbdeep2;
              CDeep[lj]=mbdeep2;
          }
            xfcmkz=99999999.0;

           /*  if(str6[lj]=="S32b")
            {
               PaintBox2->Canvas->TextOutA(120,442,str6[lj]);
               PaintBox2->Canvas->TextOutA(120,462,p11);
               PaintBox2->Canvas->TextOutA(120,482,p22);
               PaintBox2->Canvas->TextOutA(120,502,mbdeep[lj]);
               PaintBox2->Canvas->TextOutA(120,522,prc);

            }   */
         }








}
//-------------------------------------------------------------------------------
void __fastcall TForm1::AIXFC(TObject *Sender)     //智能细分层
{

    xzc=0;   //selectxfcdp=9999999.0;selectxfcdeep=0.0;
    if(a2[lj][0]>20.0)//&&((fendp-zzppsd[ljcw0-2])>3.0))    //除掉0
    {

        open_correct=0;//校正开关
         if(str6[lj]==sname)
         {
            StdCw=str6[lj];
            AICXFC(Sender);           //智能计算细分层
            mbdeep[lj]=CDeep[lj];   //目标井S37深度
            ckdeep[lj]=a2[lj][0];   //参考井S37深度
            ckjjd[lj]=jdcw[lj-1];
         }

    }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::AIBZC(TObject *Sender)     //智能标准层
{
  float dp[500];
  float sxdeep[10];               //筛选深度
  for(int i1=0;i1<ljcgs;i1++)
  {
     dp[i1]=0.0;
  }
  for(lj=0;lj<ljcgs;lj++)    //2022-2-9早上修改  <  换成  <=
  {
      float dpmkz=999999.0,mbdeep2=0.0; selectbzcdp=9999999.0; selectbzcdeep=0.0;
        xzc=0;
        for(int i1=0;i1<4;i1++)
        {
            sxdeep[i1]=0.0;   //筛选深度
        }
    if(a2[lj][0]>20.0)//&&((fendp-zzppsd[ljcw0-2])>3.0))    //除掉0
    {
        if((lj==0)||(str6[lj]=="S11"))          //JC上下邻层间距过大     ||(str6[lj]=="JC")
        {
           startt[lj]=a2[lj][0]-wincu1;
           wincu[lj]=wincu1;
        }
        else
        {
           startt[lj]=a2[lj-1][0];//-wincu;
           wincu[lj]=a2[lj][0]-a2[lj-1][0];
        }
        if((lj==(ljcgs-1))||(lj==0))  // ||(str6[lj]=="JC")
        {
          endt[lj]=a2[lj][0]+wincd1;
          wincd[lj]=wincd1;
        }
        else
        {
           endt[lj]=a2[lj+1][0];//+wincd;
           wincd[lj]=a2[lj+1][0]-a2[lj][0];
        }
        totalnumb[lj]=int((endt[lj]-startt[lj])/relv);
        chcsh[lj]=int((wincu[lj]+wincd[lj])/relv1);   //窗长数
        open_correct=0;//校正开关

        if(((str6[lj]=="S11"))||(lj==0))
        {
            prc=5;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS11deep=CDeep[lj];   //目标井S11深度
            ckS11deep=a2[lj][0];   //参考井S11深度
            S11lj=lj;
            sxdeep[0]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[S11lj]-mbS11deep)<dpmkz)  
            {
                dpmkz=fabs(ckdeep[S11lj]-mbS11deep);
                mbdeep2=mbS11deep;
            }
            prc=1;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS11deep=CDeep[lj];   //目标井S11深度
            sxdeep[1]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[S11lj]-mbS11deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[S11lj]-mbS11deep);
                mbdeep2=mbS11deep;
            }
            prc=2;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS11deep=CDeep[lj];   //目标井S11深度
            sxdeep[2]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[S11lj]-mbS11deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[S11lj]-mbS11deep);
                mbdeep2=mbS11deep;
            }
            prc=4;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS11deep=CDeep[lj];   //目标井S11深度
            sxdeep[3]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[S11lj]-mbS11deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[S11lj]-mbS11deep);
                mbdeep2=mbS11deep;
            }
             prc=5;
             mbS11deep=mbdeep2;
             CDeep[S11lj]=mbS11deep;
             mbdeep[S11lj]=mbS11deep;

             for(int i5=0;i5<3;i5++)
             {
                 for(int i6=i5+1;i6<4;i6++)
                 {
                      if(fabs(sxdeep[i5]-sxdeep[i6])<mbjbzcmkz)      //目标井标志层门槛值
                      {
                          dp[S11lj]=sxdeep[i5];
                      }
                 }
             }
            if(( mbS11deep<100)&&(dp[S11lj]>100))
            {
               CDeep[S11lj]=dp[S11lj];
               mbdeep[S11lj]=dp[S11lj];
            }
         /*   PaintBox2->Canvas->TextOutA(120+120,34,str6[lj]);
            PaintBox2->Canvas->TextOutA(120+120,54,sxdeep[0]);
            PaintBox2->Canvas->TextOutA(120+120,74,sxdeep[1]);
            PaintBox2->Canvas->TextOutA(120+120,94,sxdeep[2]);
            PaintBox2->Canvas->TextOutA(120+120,114,sxdeep[3]);
            PaintBox2->Canvas->TextOutA(120+120,134,dp[S11lj]);
            PaintBox2->Canvas->TextOutA(120+120,154,mbdeep[S11lj]);
            PaintBox2->Canvas->TextOutA(120+120,174,mbS11deep);  */
         }

         dpmkz=999999.0;
         if((str6[lj]=="JC")||(str6[lj]=="JCJC"))
         {
            prc=5;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbJCdeep=CDeep[lj];   //目标井S11深度
            ckJCdeep=a2[lj][0];   //参考井S11深度
            sxdeep[0]=CDeep[lj];   //筛选深度
            JClj=lj;
            ckjjd[S11lj]=jdcw[JClj];

            if(fabs(ckdeep[JClj]-mbJCdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[JClj]-mbJCdeep);
                mbdeep2=mbJCdeep;
            }
            prc=1;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbJCdeep=CDeep[lj];   //目标井S11深度
            sxdeep[1]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[JClj]-mbJCdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[JClj]-mbJCdeep);
                mbdeep2=mbJCdeep;
            }
            prc=2;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbJCdeep=CDeep[lj];   //目标井S11深度
            sxdeep[2]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[JClj]-mbJCdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[JClj]-mbJCdeep);
                mbdeep2=mbJCdeep;
            }
            prc=4;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbJCdeep=CDeep[lj];   //目标井S11深度
            sxdeep[3]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[JClj]-mbJCdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[JClj]-mbJCdeep);
                mbdeep2=mbJCdeep;
            }
             prc=5;
             mbJCdeep=mbdeep2;
             CDeep[JClj]=mbJCdeep;
             mbdeep[JClj]=mbJCdeep;
             for(int i5=0;i5<3;i5++)
             {
                 for(int i6=i5+1;i6<4;i6++)
                 {
                      if(fabs(sxdeep[i5]-sxdeep[i6])<mbjbzcmkz)      //目标井标志层门槛值
                      {
                          dp[JClj]=sxdeep[i5];
                      }
                 }
             }
             if(fabs((ckdeep[JClj]-ckdeep[S11lj])-(mbdeep[JClj]-mbdeep[S11lj]))>fabs((ckdeep[JClj]-ckdeep[S11lj])-(dp[JClj]-dp[S11lj]))&&(dp[S11lj]>100.0)&&(dp[JClj]>100.0))
             {
                 CDeep[JClj]=dp[JClj];
                 mbdeep[JClj]=dp[JClj];
                 mbJCdeep=dp[JClj];
                 CDeep[S11lj]=dp[S11lj];
                 mbdeep[S11lj]=dp[S11lj];
                 mbS11deep=dp[S11lj];

             }
          /*   PaintBox2->Canvas->TextOutA(320+120,34,str6[lj]);
            PaintBox2->Canvas->TextOutA(320+120,54,sxdeep[0]);
            PaintBox2->Canvas->TextOutA(320+120,74,sxdeep[1]);
            PaintBox2->Canvas->TextOutA(320+120,94,sxdeep[2]);
            PaintBox2->Canvas->TextOutA(320+120,114,sxdeep[3]);
            PaintBox2->Canvas->TextOutA(320+120,134,mbdeep[S11lj]);
            PaintBox2->Canvas->TextOutA(320+120,154,mbdeep[JClj]);
            PaintBox2->Canvas->TextOutA(320+120,174,dp[S11lj]);
            PaintBox2->Canvas->TextOutA(320+120,194,dp[JClj]);  */
         }
          dpmkz=999999.0;
          if((str6[lj]=="S37"))
         {
            prc=5;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS37deep=CDeep[lj];   //目标井S37深度
            ckS37deep=a2[lj][0];   //参考井S37深度
            S37lj=lj;
            sxdeep[0]=CDeep[lj];
            ckjjd[S37lj]=jdcw[JClj];
          /*  if(str6[lj]=="S37")
            {
                PaintBox2->Canvas->TextOutA(280,24,"1S37=");
                PaintBox2->Canvas->TextOutA(280+54,24,CDeep[lj]);
            }    */
            if(fabs(ckdeep[S37lj]-mbS37deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[S37lj]-mbS37deep);
                mbdeep2=mbS37deep;
            }
            prc=1;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS37deep=CDeep[lj];   //目标井S11深度
            sxdeep[1]=CDeep[lj];
           /* if(str6[lj]=="S37")
            {
                PaintBox2->Canvas->TextOutA(280,44,"2S37=");
                PaintBox2->Canvas->TextOutA(280+54,44,CDeep[lj]);
            }  */
            if(fabs(ckdeep[S37lj]-mbS37deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[S37lj]-mbS37deep);
                mbdeep2=mbS37deep;
            }
            prc=2;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS37deep=CDeep[lj];   //目标井S11深度
            sxdeep[2]=CDeep[lj];
          /*  if(str6[lj]=="S37")
            {
                PaintBox2->Canvas->TextOutA(280,64,"3S37=");
                PaintBox2->Canvas->TextOutA(280+54,64,CDeep[lj]);
            }    */
            if(fabs(ckdeep[S37lj]-mbS37deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[S37lj]-mbS37deep);
                mbdeep2=mbS37deep;
            }
            prc=4;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbS37deep=CDeep[lj];   //目标井S11深度
            sxdeep[3]=CDeep[lj];
           /* if(str6[lj]=="S37")
            {
                PaintBox2->Canvas->TextOutA(280,84,"4S37=");
                PaintBox2->Canvas->TextOutA(280+54,84,CDeep[lj]);
            }  */
            if(fabs(ckdeep[S37lj]-mbS37deep)<dpmkz)
            {
                dpmkz=fabs(ckS37deep-mbS37deep);
                mbdeep2=mbS37deep;
            }
             prc=5;
             mbS37deep=mbdeep2;
             CDeep[S37lj]=mbS37deep;
             mbdeep[S37lj]=mbS37deep;
             for(int i5=0;i5<3;i5++)
             {
                 for(int i6=i5+1;i6<4;i6++)
                 {
                      if(fabs(sxdeep[i5]-sxdeep[i6])<mbjbzcmkz)      //目标井标志层门槛值
                      {
                          dp[S37lj]=sxdeep[i5];
                      }
                 }
             }
             if(fabs((ckdeep[S37lj]-ckdeep[JClj])-(mbdeep[S37lj]-mbdeep[JClj]))>fabs((ckdeep[S37lj]-ckdeep[JClj])-(dp[S37lj]-dp[JClj])))
             {

                 CDeep[S37lj]=dp[S37lj];
                 mbdeep[S37lj]=dp[S37lj];
                 mbS37deep=dp[S37lj];
             }
         }
         dpmkz=999999.0;

       /*    if(str6[lj]=="S37")
        {

           PaintBox2->Canvas->TextOutA(280,94,"S37=");
           PaintBox2->Canvas->TextOutA(280+54,94,CDeep[lj]);
           PaintBox2->Canvas->TextOutA(280+54,114,mbS37deep);
            PaintBox2->Canvas->TextOutA(280+54,134,S37lj);
            PaintBox2->Canvas->TextOutA(280+54,154,lj);
            PaintBox2->Canvas->TextOutA(280+54,174,CDeep[lj]);
        }   */
         if((str6[lj]=="P27a"))
         {
            prc=5;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbP27adeep=CDeep[lj];   //目标井S11深度
            ckP27adeep=a2[lj][0];   //参考井S11深度
            sxdeep[0]=CDeep[lj];   //筛选深度
            P27alj=lj;
            ckjjd[P27alj]=jdcw[S37lj];
            if(fabs(ckdeep[P27alj]-mbP27adeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[P27alj]-mbP27adeep);
                mbdeep2=mbP27adeep;
            }
            prc=1;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbP27adeep=CDeep[lj];   //目标井S11深度
            sxdeep[1]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[P27alj]-mbP27adeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[P27alj]-mbP27adeep);
                mbdeep2=mbP27adeep;
            }
            prc=2;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbP27adeep=CDeep[lj];   //目标井S11深度
            sxdeep[2]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[P27alj]-mbP27adeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[P27alj]-mbP27adeep);
                mbdeep2=mbP27adeep;
            }
            prc=4;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbP27adeep=CDeep[lj];   //目标井S11深度
            sxdeep[3]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[P27alj]-mbP27adeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[P27alj]-mbP27adeep);
                mbdeep2=mbP27adeep;
            }
             prc=5;
             mbP27adeep=mbdeep2;
             CDeep[P27alj]=mbP27adeep;
             mbdeep[P27alj]=mbP27adeep;
             for(int i5=0;i5<3;i5++)
             {
                 for(int i6=i5+1;i6<4;i6++)
                 {
                      if(fabs(sxdeep[i5]-sxdeep[i6])<mbjbzcmkz)      //目标井标志层门槛值
                      {
                          dp[P27alj]=sxdeep[i5];
                      }
                 }
             }
             if(fabs((ckdeep[P27alj]-ckdeep[S37lj])-(mbdeep[P27alj]-mbdeep[S37lj]))>fabs((ckdeep[P27alj]-ckdeep[S37lj])-(dp[P27alj]-dp[S37lj])))
             {

                 CDeep[P27alj]=dp[P27alj];
                 mbdeep[P27alj]=dp[P27alj];
                 mbP27adeep=dp[P27alj];
             }
         }
         dpmkz=999999.0;
      /*   if(str6[lj]=="P27a")
        {
           PaintBox2->Canvas->TextOutA(80,94,"P27a=");
           PaintBox2->Canvas->TextOutA(80+54,94,CDeep[P27alj]);
           PaintBox2->Canvas->TextOutA(80+54,114,P27alj);
            PaintBox2->Canvas->TextOutA(80+54,134,lj);
        }   */
         if((str6[lj]=="G110b"))
         {
            prc=5;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG110bdeep=CDeep[lj];   //目标井S11深度
            ckG110bdeep=a2[lj][0];   //参考井S11深度
            sxdeep[0]=CDeep[lj];   //筛选深度
            G110blj=lj;
            ckjjd[G110blj]=jdcw[P27alj];
            if(fabs(ckdeep[G110blj]-mbG110bdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G110blj]-mbG110bdeep);
                mbdeep2=mbG110bdeep;
            }
            prc=1;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG110bdeep=CDeep[lj];   //目标井S11深度
            sxdeep[1]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[G110blj]-mbG110bdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G110blj]-mbG110bdeep);
                mbdeep2=mbG110bdeep;
            }
            prc=2;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG110bdeep=CDeep[lj];   //目标井S11深度
            sxdeep[2]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[G110blj]-mbG110bdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G110blj]-mbG110bdeep);
                mbdeep2=mbG110bdeep;
            }
            prc=4;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG110bdeep=CDeep[lj];   //目标井S11深度
            sxdeep[3]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[G110blj]-mbG110bdeep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G110blj]-mbG110bdeep);
                mbdeep2=mbG110bdeep;
            }
             prc=5;
             mbG110bdeep=mbdeep2;
             CDeep[G110blj]=mbG110bdeep;
             mbdeep[G110blj]=mbG110bdeep;
             for(int i5=0;i5<3;i5++)
             {
                 for(int i6=i5+1;i6<4;i6++)
                 {
                      if(fabs(sxdeep[i5]-sxdeep[i6])<mbjbzcmkz)      //目标井标志层门槛值
                      {
                          dp[G110blj]=sxdeep[i5];
                      }
                 }
             }
             if(fabs((ckdeep[G110blj]-ckdeep[P27alj])-(mbdeep[G110blj]-mbdeep[P27alj]))>fabs((ckdeep[G110blj]-ckdeep[P27alj])-(dp[G110blj]-dp[P27alj])))
             {

                 CDeep[G110blj]=dp[G110blj];
                 mbdeep[G110blj]=dp[G110blj];
                 mbG110bdeep=dp[G110blj];
             }
         }
         dpmkz=999999.0;
         if((str6[lj]=="G120"))
         {
            prc=5;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG120deep=CDeep[lj];   //目标井S11深度
            ckG120deep=a2[lj][0];   //参考井S11深度
            sxdeep[0]=CDeep[lj];   //筛选深度
            G120lj=lj;
            ckjjd[G120lj]=jdcw[G110blj];
            if(fabs(ckdeep[G120lj]- mbG120deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G120lj]- mbG120deep);
                mbdeep2= mbG120deep;
            }
            prc=1;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG120deep=CDeep[lj];   //目标井S11深度
            sxdeep[1]=CDeep[lj];   //筛选深度
            if(fabs(ckdeep[G120lj]- mbG120deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G120lj]- mbG120deep);
                mbdeep2= mbG120deep;
            }
            prc=2;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG120deep=CDeep[lj];   //目标井S11深度
            sxdeep[2]=CDeep[lj];   //筛选深度

            if(fabs(ckdeep[G120lj]- mbG120deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G120lj]- mbG120deep);
                mbdeep2= mbG120deep;
            }
            prc=4;
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbG120deep=CDeep[lj];   //目标井S11深度
            sxdeep[3]=CDeep[lj];   //筛选深度

            if(fabs(ckdeep[G120lj]- mbG120deep)<dpmkz)
            {
                dpmkz=fabs(ckdeep[G120lj]- mbG120deep);
                mbdeep2= mbG120deep;
            }
             prc=5;
             mbG120deep=mbdeep2;
             CDeep[G120lj]=mbG120deep;

             for(int i5=0;i5<3;i5++)
             {
                 for(int i6=i5+1;i6<4;i6++)
                 {
                      if(fabs(sxdeep[i5]-sxdeep[i6])<mbjbzcmkz)      //目标井标志层门槛值
                      {
                          dp[G120lj]=sxdeep[i5];
                      }
                 }
             }
             if(fabs((ckdeep[G120lj]-ckdeep[G110blj])-(mbdeep[G120lj]-mbdeep[G110blj]))>fabs((ckdeep[G120lj]-ckdeep[G110blj])-(dp[G120lj]-dp[G110blj])))
             {

                 CDeep[G120lj]=dp[G120lj];
                 mbdeep[G120lj]=dp[G120lj];
                 mbG120deep=dp[G120lj];
             }
         }
         dpmkz=999999.0;

    }


   }

}
//----------------------------------------------------------------------------
/*void __fastcall TForm1::PDCWJD(float qq[15000][50],float py[500],int mbcw,int up2) //判断层位节点
{
     for(int i1=50;i1<stedp1;i1++)
     {
         if(fabs(qq[i1][0]-py[mbcw])<0.02)
         {
             up2=i1;
         }
     }
       PaintBox2->Canvas->TextOutA(60,27+mbcw*5,str6[mbcw]);
       PaintBox2->Canvas->TextOutA(40+74,27+mbcw*5,up2);
       PaintBox2->Canvas->TextOutA(120+74,27+mbcw*5,mbcw);
       PaintBox2->Canvas->TextOutA(220+74,27+mbcw*5,py[mbcw]);
}   */
//----------------------------------------------------------------------------
void __fastcall TForm1::AIBZC2(TObject *Sender)     //智能标准层
{
//  for(lj=0;lj<ljcgs;lj++)    //2022-2-9早上修改  <  换成  <=
  {
    xzc=0;  selectbzcdp=9999999.0; selectbzcdeep=0.0;
    if((a2[lj][0]>20.0))//&&((fendp-zzppsd[ljcw0-2])>3.0))    //除掉0
    {

        open_correct=0;//校正开关
        if(((str6[lj]=="S11")&&(sname=="S11")))
        {
            BZCcks[lj]=mbJCdeep-(ckdeep[JClj]-ckdeep[S11lj])-wincu1*1.2;
            BZCcke[lj]=mbJCdeep-(ckdeep[JClj]-ckdeep[S11lj])+wincu1*1.2;
            StdCw=str6[lj];
            AIC2(Sender);           //智能计算
            mbS11deep=CDeep[lj];   //目标井S11深度
            ckS11deep=a2[lj][0];   //参考井S11深度
            S11lj=lj;
            mbdeep[lj]=CDeep[lj];

         }

        /* if(str6[lj]=="JC")
         {
            StdCw=str6[lj];
            AIC(Sender);           //智能计算
            mbJCdeep=CDeep[lj];   //目标井S11深度
            ckJCdeep=a2[lj][0];   //参考井S11深度
            JClj=lj;
            ckjjd[S11lj]=jdcw[JClj];
         }    */
          if((str6[lj]=="S37")&&(sname=="S37"))
         {
            StdCw=str6[lj];
            BZCcks[lj]=mbJCdeep+(ckdeep[S37lj]-ckdeep[JClj])-wincu1*2.0;
            BZCcke[lj]=mbJCdeep+(ckdeep[S37lj]-ckdeep[JClj])+wincu1*2.0;
            AIC2(Sender);           //智能计算
            mbS37deep=CDeep[lj];   //目标井S37深度
            ckS37deep=a2[lj][0];   //参考井S37深度
            S37lj=lj;
            ckjjd[S37lj]=jdcw[JClj];
            ite=ite+1;
           // PaintBox2->Canvas->TextOutA(120,ite*20+114,"mbS37AIC2deep=");
           /* PaintBox2->Canvas->TextOutA(120+54,ite*120+34,mbS37deep);
            PaintBox2->Canvas->TextOutA(120+54,ite*120+54,CDeep[lj]);
            PaintBox2->Canvas->TextOutA(120+54,ite*120+74,str6[lj]);
            PaintBox2->Canvas->TextOutA(120+54,ite*120+94,sname);
            PaintBox2->Canvas->TextOutA(120+54,ite*120+114,lj);  */
         }
      /*  if(str6[lj]=="S37")
        {

            PaintBox2->Canvas->TextOutA(280,24+prc*120,"S37=");
            PaintBox2->Canvas->TextOutA(280+54,24+prc*120,CDeep[lj]);
            PaintBox2->Canvas->TextOutA(280+54,44+prc*120,mbS37deep);
            PaintBox2->Canvas->TextOutA(280+54,64+prc*120,S37lj);
            PaintBox2->Canvas->TextOutA(280+54,84+prc*120,lj);
            PaintBox2->Canvas->TextOutA(280+54,104+prc*120,CDeep[lj]);
            PaintBox2->Canvas->TextOutA(280+54,124+prc*120,jdcw[JClj]);
            PaintBox2->Canvas->TextOutA(280+54,24+prc*120,BZCcks[lj]);
            PaintBox2->Canvas->TextOutA(280+54,44+prc*120,BZCcke[lj]);
        }  */
         if((str6[lj]=="P27a")&&(sname=="P27a"))
         {
            StdCw=str6[lj];
            BZCcks[lj]=mbS37deep+(ckdeep[P27alj]-ckdeep[S37lj])-wincu1*2.0;
            BZCcke[lj]=mbS37deep+(ckdeep[P27alj]-ckdeep[S37lj])+wincu1*2.0;
            AIC2(Sender);           //智能计算
            mbP27adeep=CDeep[lj];   //目标井S11深度
            ckP27adeep=a2[lj][0];   //参考井S11深度
            P27alj=lj;
            ckjjd[P27alj]=jdcw[S37lj];
         }
      /*   if(str6[lj]=="P27a")
        {
           PaintBox2->Canvas->TextOutA(80,94,"P27a=");
           PaintBox2->Canvas->TextOutA(80+54,94,CDeep[P27alj]);
           PaintBox2->Canvas->TextOutA(80+54,114,P27alj);
            PaintBox2->Canvas->TextOutA(80+54,134,lj);
        }   */
         if((str6[lj]=="G110b")&&(sname=="G110b"))
         {
            StdCw=str6[lj];
            BZCcks[lj]=mbP27adeep+(ckdeep[G110blj]-ckdeep[P27alj])-wincu1*2.0;
            BZCcke[lj]=mbP27adeep+(ckdeep[G110blj]-ckdeep[P27alj])+wincu1*2.0;
            AIC2(Sender);           //智能计算
            mbG110bdeep=CDeep[lj];   //目标井S11深度
            ckG110bdeep=a2[lj][0];   //参考井S11深度
            G110blj=lj;
            ckjjd[G110blj]=jdcw[P27alj];
         }
       /*  if(str6[lj]=="G110b")
        {
           PaintBox2->Canvas->TextOutA(80,94,"G110b=");
           PaintBox2->Canvas->TextOutA(80+54,94,CDeep[G110blj]);
           PaintBox2->Canvas->TextOutA(80+54,114,G110blj);
            PaintBox2->Canvas->TextOutA(80+54,134,ckjjd[G110blj]);
        }   */
         if((str6[lj]=="G120")&&(sname=="G120"))
         {
            StdCw=str6[lj];
            BZCcks[lj]=mbG110bdeep+(ckdeep[G120lj]-ckdeep[G110blj])-wincu1*2.0;
            BZCcke[lj]=mbG110bdeep+(ckdeep[G120lj]-ckdeep[G110blj])+wincu1*2.0;
            AIC2(Sender);           //智能计算
            mbG120deep=CDeep[lj];   //目标井S11深度
            ckG120deep=a2[lj][0];   //参考井S11深度
            G120lj=lj;
            ckjjd[G120lj]=jdcw[G110blj];
         }

    }


   }

}
//----------------------------------------------------------------------------

void __fastcall TForm1::inputckj(TObject *Sender)       //输入参考井
{
      for(int i0=100;i0<stedp;i0++)    //去除井顶伪数据
      {

            if((fabs(a[i0][0]-startt[lj])<0.005)&&(str6[lj]==StdCw))        //S11  、JC   S37 G11  G110b
            {

                 ie1=0;

                 for(int i=i0;i<i0+totalnumb[lj];i++)
                 {
                        xcsj[ie1][0]=a[i][0];            //2021年11月2日修改原来深度保留2位小数

                        xcsj[ie1][1]=a[i][MN_pos];
                        xcsj[ie1][2]=a[i][Rd_pos];
                        xcsj[ie1][3]=a[i][DEN_pos];
                        xcsj[ie1][4]=a[i][HAC_pos];
                        xcsj[ie1][5]=a[i][Rxo_pos];
                        xcsj[ie1][6]=a[i][GR_pos];
                        Rmn[ie1]=xcsj[ie1][prc];
                        ie1++;
                 }

            }
      }

              Filter(xcsj,ie1,Rmn);




}
//-----------------------------------------------------------------------------
void __fastcall TForm1::AIC(TObject *Sender)       //智能计算
{
      float zdz1,zdz2,zdz3,zdz4,zdz5,deep[10],deeplast=0.0;
      int ip[10]; selectbzcdp=99999999.0;
      zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0; zdz4=9999999.0; zdz5=9999999.0;
      if(xzc==1)        //修正correct
      {

         stpin=stpinsjk[lj];    //节点输入

      }
      else if(xzc==0)
      {
          inputckj(Sender);
          stpin=int(wincu[lj]/relv1);
      }
               if(str6[lj]==StdCw)
                 {

                    ljcw0=lj;
                    Dice(Sender);
                    for(int i1=10;i1<stedp1-chcsh[lj]*2;i1++)
                    {
                      ie2=0;
                      if((a1[i1+chcsh[lj]][MN1_pos]>0.85)&&(a1[i1+chcsh[lj]][Rxo1_pos]>0.85))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[lj];

                       // itz=i1;//检测用
                        for(int i0=i1;i0<stp1;i0++)
                        {
                              Tmbjsj[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                              Tmbjsj[ie2][0]=a1[i0][0];
                              Tmbjsj[ie2][2]=a1[i0][Rd1_pos];
                              Tmbjsj[ie2][3]=a1[i0][DEN1_pos];
                              Tmbjsj[ie2][4]=a1[i0][HAC1_pos];
                              Tmbjsj[ie2][5]=a1[i0][Rxo1_pos];
                              Tmbjsj[ie2][6]=a1[i0][GR1_pos];
                              if(Tmbjsj[ie2][1]<1.0)
                              {
                                 Tmbj=0;
                              }
                              Rmn1[ie2]=Tmbjsj[ie2][prc];
                              ie2++;
                        }
                        Filter(Tmbjsj,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);

                       // if(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice(Sender);
                        }
                        if(v[1]<zdz1)
                        {
                           zdz1=v[1];
                           deep[1]=a1[stp][0];
                           //jdcw[lj]=stp;          //测井数据数据节点
                           ip[1]=stp;
                           xzJC[prc][1]=deep[1];
                         /*  if(str6[lj]=="G110b")
                           {

                              PaintBox2->Canvas->TextOutA(50,24+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100,24+(prc-1)*110,str6[lj]);
                              PaintBox2->Canvas->TextOutA(100+54,24+(prc-1)*110,deep[1]);

                           }     */
                        }
                        if(v[2]<zdz2)
                        {
                           zdz2=v[2];
                           deep[2]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[2]=stp;
                            xzJC[prc][2]=deep[2];
                         /* if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,44+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,44+(prc-1)*110,deep[2]);
                           }  */
                        }
                        if(v[3]<zdz3)
                        {
                           zdz3=v[3];
                           deep[3]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[3]=stp;
                           xzJC[prc][3]=deep[3];
                       /*    if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,64+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,64+(prc-1)*110,deep[3]);
                           }    */
                        }
                        if(v[4]<zdz4)
                        {
                           zdz4=v[4];
                           deep[4]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[4]=stp;
                           xzJC[prc][4]=deep[4];
                         /*  if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,84+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,84+(prc-1)*110,deep[4]);
                           }  */
                        }
                        if(v[5]<zdz5)
                        {
                           zdz5=v[5];
                           deep[5]=a1[stp][0];
                         //  jdcw[lj]=stp;          //测井数据数据节点
                           ip[5]=stp;
                           xzJC[prc][5]=deep[5];
                         /*  if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,104+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,104+(prc-1)*110,deep[5]);
                           }  */
                        }
                       }
                     }

                   }
         /*   for(int i1=1;i1<=4;i1++)
            {
               for(int i2=i1+1;i2<=5;i2++)
               {
                  if(fabs(deep[i1]-deep[i2])<0.2)
                  {
                     deeplast=deep[i1];
                     jdcw[lj]=ip[i1];
                  }
               }
            }
            if(deeplast<1.0)
            {
              deeplast=deep[1];
              jdcw[lj]=ip[1];
            }
            CDeep[lj]=deeplast;  */
            for(int i1=1;i1<6;i1++)
              {
                 if(fabs(ckdeep[lj]-deep[i1])<selectbzcdp)
                 {
                     selectbzcdp=fabs(ckdeep[lj]-deep[i1]);
                     selectbzcdeep=deep[i1];
                 }
                        
              }
              CDeep[lj]=selectbzcdeep;
              mbdeep[lj]=CDeep[lj];
                       /* if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,600,prc);
                              PaintBox2->Canvas->TextOutA(100+54,600,CDeep[lj]);

                           }  */
            if(prc==4)
              {
                if((str6[lj]=="JC")||(str6[lj]=="JCJC"))
                {
                    if((fabs(xzJC[5][1]-xzJC[4][1])<0.06)&&(fabs(xzJC[5][1]-xzJC[2][1])<0.06))
                    {
                       CDeep[lj]=xzJC[5][1];
                    }
                }
              }
             float p1=0.0;

            if(prc==4)
            {

                  if((fabs(xzJC[1][1]-xzJC[1][3])<0.08)&&(fabs(xzJC[2][1]-xzJC[1][1])<0.2))
                  {
                       CDeep[lj]=xzJC[1][1];
                       p1=xzJC[1][1];
                  }
              
                        /*   if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,630,prc);
                              PaintBox2->Canvas->TextOutA(100+54,630,CDeep[lj]);
                              PaintBox2->Canvas->TextOutA(200+54,630,xzJC[1][1]);
                              PaintBox2->Canvas->TextOutA(300+54,630,xzJC[1][3]);

                           }  */

            }

            if(p1>100.0)
            {

                CDeep[lj]=p1;
                mbdeep[lj]=CDeep[lj];
               /* if(str6[lj]=="G110b")
                {
                   PaintBox2->Canvas->TextOutA(400+54,580,p1);
                   PaintBox2->Canvas->TextOutA(400+54,600,str6[lj]);
                   PaintBox2->Canvas->TextOutA(400+54,620,mbdeep[lj]);
                }  */
            }

                         /*  if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(350,650,prc);
                              PaintBox2->Canvas->TextOutA(400+54,650,CDeep[lj]);
                              PaintBox2->Canvas->TextOutA(500+84,650,"                                ");
                              PaintBox2->Canvas->TextOutA(500+84,650,p1);
                           }      */
}
//------------------------------------------------------------------------------------
void __fastcall TForm1::AIC2(TObject *Sender)       //智能计算
{
      float zdz1,zdz2,zdz3,zdz4,zdz5,deep[10],deeplast=0.0;//,Rmnmax=0.0,dpmax;
      int ip[10],s1,e1; selectbzcdp=99999999.0;
      zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0; zdz4=9999999.0; zdz5=9999999.0;
      if(xzc==1)        //修正correct
      {

         stpin=stpinsjk[lj];    //节点输入

      }
      else if(xzc==0)
      {
          inputckj(Sender);
          stpin=int(wincu[lj]/relv1);
      }
               for(int i1=100;i1<stedp1;i1++)
               {
                  if(fabs(a1[i1][0]-BZCcks[lj])<0.02)
                  {
                      s1=i1;
                  }
                  if(fabs(a1[i1][0]-BZCcke[lj])<0.02)
                  {
                      e1=i1;
                  }
               }
               if(str6[lj]==StdCw)
                 {

                    ljcw0=lj;
                    Dice(Sender);
                    for(int i1=s1;i1<e1;i1++)
                    {
                      ie2=0;
              //        if((a1[i1+chcsh[lj]][MN1_pos]>0.85)&&(a1[i1+chcsh[lj]][Rxo1_pos]>0.85))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[lj];

                       // itz=i1;//检测用
                        for(int i0=i1;i0<stp1;i0++)
                        {
                              Tmbjsj[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                              Tmbjsj[ie2][0]=a1[i0][0];
                              Tmbjsj[ie2][2]=a1[i0][Rd1_pos];
                              Tmbjsj[ie2][3]=a1[i0][DEN1_pos];
                              Tmbjsj[ie2][4]=a1[i0][HAC1_pos];
                              Tmbjsj[ie2][5]=a1[i0][Rxo1_pos];
                              Tmbjsj[ie2][6]=a1[i0][GR1_pos];
                              if(Tmbjsj[ie2][1]<1.0)
                              {
                                 Tmbj=0;
                              }
                              Rmn1[ie2]=Tmbjsj[ie2][prc];
                              ie2++;
                        }
                        Filter(Tmbjsj,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);
                      /*  if(str6[lj]=="S37")
                        {
                            PaintBox2->Canvas->TextOutA(50,44,"st ");
                            PaintBox2->Canvas->TextOutA(100,44,BZCcks[lj]);
                            PaintBox2->Canvas->TextOutA(50,64,"en ");
                            PaintBox2->Canvas->TextOutA(100,64,BZCcke[lj]);
                        }  */
                       // if(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice(Sender);
                        }
                        if(v[1]<zdz1)
                        {
                           zdz1=v[1];
                           deep[1]=a1[stp][0];
                           //jdcw[lj]=stp;          //测井数据数据节点
                           ip[1]=stp;
                           xzJC[prc][1]=deep[1];
                           Rmnsz[1]=a1[stp][MN1_pos];
                           if((str6[lj]=="S37")||(str6[lj]=="JC")||(str6[lj]=="JCJC"))
                           {
                            /*  if(a1[stp][MN1_pos]>Rmnmax)
                              {
                                 Rmnmax=a1[stp][MN1_pos];
                                 dpmax=a1[stp][0];
                              }  */
                              if(Rmnsz[1]>zdzS37)
                              {
                                  zdzS37=Rmnsz[1];
                                  dpmax=a1[stp][0];
                              }
                          //    PaintBox2->Canvas->TextOutA(250,44+(prc-1)*110,prc);
                          //    PaintBox2->Canvas->TextOutA(300,44+(prc-1)*110,str6[lj]);
                           //   PaintBox2->Canvas->TextOutA(300+104,44+(prc-1)*110,deep[1]);
                           //   PaintBox2->Canvas->TextOutA(300+204,44+(prc-1)*110,Rmnsz[1]);
                           }
                         /*  if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,44+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100,44+(prc-1)*110,str6[lj]);
                              PaintBox2->Canvas->TextOutA(100+104,44+(prc-1)*110,deep[1]);
                              PaintBox2->Canvas->TextOutA(100+204,44+(prc-1)*110,Rmnsz[1]);
                           }  */
                        }
                        if(v[2]<zdz2)
                        {
                           zdz2=v[2];
                           deep[2]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[2]=stp;
                            xzJC[prc][2]=deep[2];
                            Rmnsz[2]=a1[stp][MN1_pos];
                          if((str6[lj]=="S37")||(str6[lj]=="JC")||(str6[lj]=="JCJC"))
                           {
                            /*  if(a1[stp][MN1_pos]>Rmnmax)
                              {
                                 Rmnmax=a1[stp][MN1_pos];
                                 dpmax=a1[stp][0];
                              } */
                              if(Rmnsz[2]>zdzS37)
                              {
                                  zdzS37=Rmnsz[2];
                                  dpmax=a1[stp][0];
                              }
                           //   PaintBox2->Canvas->TextOutA(250,64+(prc-1)*110,prc);
                           //   PaintBox2->Canvas->TextOutA(300+54,64+(prc-1)*110,deep[2]);
                           //   PaintBox2->Canvas->TextOutA(300+154,64+(prc-1)*110,Rmnsz[2]);
                           }
                          /* if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,64+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,64+(prc-1)*110,deep[2]);
                               PaintBox2->Canvas->TextOutA(100+154,64+(prc-1)*110,Rmnsz[2]);
                           }   */
                        }
                        if(v[3]<zdz3)
                        {
                           zdz3=v[3];
                           deep[3]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[3]=stp;
                           xzJC[prc][3]=deep[3];
                           Rmnsz[3]=a1[stp][MN1_pos];
                           if((str6[lj]=="S37")||(str6[lj]=="JC")||(str6[lj]=="JCJC"))
                           {
                             /* if(a1[stp][MN1_pos]>Rmnmax)
                              {
                                 Rmnmax=a1[stp][MN1_pos];
                                 dpmax=a1[stp][0];
                              }   */
                              if(Rmnsz[3]>zdzS37)
                              {
                                  zdzS37=Rmnsz[3];
                                  dpmax=a1[stp][0];
                              }
                           //   PaintBox2->Canvas->TextOutA(250,84+(prc-1)*110,prc);
                            //  PaintBox2->Canvas->TextOutA(300+54,84+(prc-1)*110,deep[3]);
                            //  PaintBox2->Canvas->TextOutA(300+154,84+(prc-1)*110,Rmnsz[3]);
                           }
                          /* if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,84+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,84+(prc-1)*110,deep[3]);
                              PaintBox2->Canvas->TextOutA(100+154,84+(prc-1)*110,Rmnsz[3]);
                           }  */
                        }
                        if(v[4]<zdz4)
                        {
                           zdz4=v[4];
                           deep[4]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[4]=stp;
                           xzJC[prc][4]=deep[4];
                           Rmnsz[4]=a1[stp][MN1_pos];
                           if((str6[lj]=="S37")||(str6[lj]=="JC")||(str6[lj]=="JCJC"))
                           {
                             /* if(a1[stp][MN1_pos]>Rmnmax)
                              {
                                 Rmnmax=a1[stp][MN1_pos];
                                 dpmax=a1[stp][0];
                              }  */
                              if(Rmnsz[4]>zdzS37)
                              {
                                  zdzS37=Rmnsz[4];
                                  dpmax=a1[stp][0];
                              }
                            //  PaintBox2->Canvas->TextOutA(250,104+(prc-1)*110,prc);
                           //   PaintBox2->Canvas->TextOutA(300+54,104+(prc-1)*110,deep[4]);
                           //   PaintBox2->Canvas->TextOutA(300+154,104+(prc-1)*110,Rmnsz[4]);
                           }
                          /* if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,104+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,104+(prc-1)*110,deep[4]);
                              PaintBox2->Canvas->TextOutA(100+154,104+(prc-1)*110,Rmnsz[4]);
                           }  */
                        }
                        if(v[5]<zdz5)
                        {
                           zdz5=v[5];
                           deep[5]=a1[stp][0];
                         //  jdcw[lj]=stp;          //测井数据数据节点
                           ip[5]=stp;
                           xzJC[prc][5]=deep[5];
                           Rmnsz[5]=a1[stp][MN1_pos];
                           if((str6[lj]=="S37")||(str6[lj]=="JC")||(str6[lj]=="JCJC"))
                           {
                            /*  if(a1[stp][MN1_pos]>Rmnmax)
                              {
                                 Rmnmax=a1[stp][MN1_pos];
                                 dpmax=a1[stp][0];
                              }  */
                              if(Rmnsz[5]>zdzS37)
                              {
                                  zdzS37=Rmnsz[5];
                                  dpmax=a1[stp][0];
                              }
                            //  PaintBox2->Canvas->TextOutA(250,124+(prc-1)*110,prc);
                            //  PaintBox2->Canvas->TextOutA(300+54,124+(prc-1)*110,deep[5]);
                            //  PaintBox2->Canvas->TextOutA(300+154,124+(prc-1)*110,Rmnsz[5]);
                           }
                         /*  if(str6[lj]=="G110b")
                           {
                              PaintBox2->Canvas->TextOutA(50,124+(prc-1)*110,prc);
                              PaintBox2->Canvas->TextOutA(100+54,124+(prc-1)*110,deep[5]);
                              PaintBox2->Canvas->TextOutA(100+154,124+(prc-1)*110,Rmnsz[5]);
                           }   */
                        }
                       }
                     }

                   }
             // int i3=0,i4=0;
            for(int i1=1;i1<=4;i1++)
            {
               for(int i2=i1+1;i2<=5;i2++)
               {
                  if(fabs(deep[i1]-deep[i2])<0.2)
                  {
                      // i3=ip[i1];
                      // i4=ip[i2];
                     if(( Rmnsz[i1]> Rmnsz[i2])&&(str6[lj]=="S37"))
                     {
                        deeplast=deep[i1];
                        jdcw[lj]=ip[i1];
                     }
                     else
                     {
                        deeplast=deep[i2];
                        jdcw[lj]=ip[i2];
                     }
                  }
               }
            }
           // i3=ip[1];i4=ip[2];
            if(deeplast<1.0)
            {

                     if((Rmnsz[1]>Rmnsz[2])&&(str6[lj]=="S37")&&(deep[1]>100.0))
                     {
                        deeplast=deep[1];
                        jdcw[lj]=ip[1];
                     }
                     else
                     {
                        deeplast=deep[2];
                        jdcw[lj]=ip[2];
                     }
            }
            CDeep[lj]=deeplast;
          /*  for(int i1=1;i1<6;i1++)
              {
                 if(fabs(ckdeep[lj]-deep[i1])<selectbzcdp)
                 {
                     selectbzcdp=fabs(ckdeep[lj]-deep[i1]);
                     selectbzcdeep=deep[i1];
                 }

              }
            if(fabs(ckdeep[lj]-selectbzcdeep)<fabs(ckdeep[lj]-CDeep[lj]))
            {
                CDeep[lj]=selectbzcdeep;
                mbdeep[lj]=CDeep[lj];
            }     */
                           if((str6[lj]=="S37")||(str6[lj]=="JC")||(str6[lj]=="JCJC"))
                           {
                              CDeep[lj]=dpmax;
                              mbdeep[lj]=CDeep[lj];
                          //    PaintBox2->Canvas->TextOutA(50,104+(prc-1)*110,prc);
                          //    PaintBox2->Canvas->TextOutA(50,124+(prc-1)*110,"dla ");
                          //    PaintBox2->Canvas->TextOutA(50+54,124+(prc-1)*110,deeplast);
                             // PaintBox2->Canvas->TextOutA(50,144+(prc-1)*110,"sdeep ");
                          //    PaintBox2->Canvas->TextOutA(50+54,144+(prc-1)*110,selectbzcdeep);
                          //    PaintBox2->Canvas->TextOutA(50,164+(prc-1)*110,"dpmax ");
                           //   PaintBox2->Canvas->TextOutA(50+54,164+(prc-1)*110,CDeep[lj]);
                           }

}
//------------------------------------------------------------------------------------
void __fastcall TForm1::AICXFC(TObject *Sender)       //智能计算细分层
{

      if(xzc==1)        //修正correct
      {

         stpin=stpinsjk[lj];    //节点输入

      }
      else if(xzc==0)
      {
          inputckj(Sender);
          stpin=int(wincu[lj]/relv1);
      }
             /*  PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-3*20,a1[stmb[lj]][0]);
               PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-2*20,a1[enmb[lj]][0]);
               PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-1*20,totalnumb[lj]);  */

               if(str6[lj]==StdCw)
                 {

                    ljcw0=lj;
                    Dice(Sender);
                    for(int i1=stmb[lj];i1<enmb[lj];i1++)
                    {
                      ie2=0;
                      if((a1[i1+chcsh[lj]][MN1_pos]>0.85)&&(a1[i1+chcsh[lj]][Rxo1_pos]>0.85)&&(a1[i1][MN1_pos]>0.1)&&(a1[i1][Rd1_pos]>0.1)&&(a1[i1][Rxo1_pos]>0.1))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[lj];

                       // itz=i1;//检测用
                        for(int i0=i1;i0<stp1;i0++)
                        {
                              Tmbjsj[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                              Tmbjsj[ie2][0]=a1[i0][0];
                              Tmbjsj[ie2][2]=a1[i0][Rd1_pos];
                              Tmbjsj[ie2][3]=a1[i0][DEN1_pos];
                              Tmbjsj[ie2][4]=a1[i0][HAC1_pos];
                              Tmbjsj[ie2][5]=a1[i0][Rxo1_pos];
                              Tmbjsj[ie2][6]=a1[i0][GR1_pos];
                              if(Tmbjsj[ie2][1]<1.0)
                              {
                                 Tmbj=0;
                              }
                              Rmn1[ie2]=Tmbjsj[ie2][prc];
                              ie2++;
                        }
                        Filter(Tmbjsj,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);

                       // if(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice(Sender);
                        }
                        if((v[1]<zdz1)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0]))
                        {
                           zdz1=v[1];
                           deepp[1]=a1[stp][0];
                           Rmnselect20[prc][1]=a1[stp][0];
                           //jdcw[lj]=stp;          //测井数据数据节点
                           ip[1]=stp;
       /*  if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(30,24+(prc-1)*110,"v1 ");
             PaintBox2->Canvas->TextOutA(60,24+(prc-1)*110,"                                    ");
             PaintBox2->Canvas->TextOutA(60,24+(prc-1)*110,v[1]);
             PaintBox2->Canvas->TextOutA(130+54,24+(prc-1)*110,deepp[1]);
              PaintBox2->Canvas->TextOutA(230+54,24+(prc-1)*110,prc);
          }   */
                        /*   if(a1[stp][MN1_pos]<Rm1)
                           {
                               Rm1=a1[stp][MN1_pos];
                               Rmnselect=a1[stp][0];
                             //  if(fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]))<Rm2)
                               if(fabs(ckdeep[lj]-a1[stp][0])<Rm2)
                             //  if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]))<Rm2)
                               {
                                //  Rm2=fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]));
                                  Rm2=fabs(ckdeep[lj]-a1[stp][0]);
                                //  Rm2=fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]));
                                  Rmnselect2[prc][1]=a1[stp][0];
                               }
                               if(fabs(ckdeep[lj]-deepp[1])<selectxfcdp)
                               {
                                   selectxfcdp=fabs(ckdeep[lj]-deepp[1]);
                                   selectxfcdeep=deepp[1];
                               }
                           }    */
                        }

         // if(str6[lj]=="S28b")
          {
           //  PaintBox2->Canvas->TextOutA(30,24+(prc-1)*110,"1 ");
           //  PaintBox2->Canvas->TextOutA(60,24+(prc-1)*110,v[1]);
           //  PaintBox2->Canvas->TextOutA(40,24+(prc-1)*110,Rm2);
           //  PaintBox2->Canvas->TextOutA(130+54,24+(prc-1)*110,deepp[1]);
           //  PaintBox2->Canvas->TextOutA(200+54,24+(prc-1)*110,Rmnselect);
           //  PaintBox2->Canvas->TextOutA(300+54,24+(prc-1)*110,Rmnselect2[1]);
           //  PaintBox2->Canvas->TextOutA(400+54,24+(prc-1)*110,a1[stmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(500+54,24+(prc-1)*110,a1[enmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(600+54,24+(prc-1)*110,selectxfcdeep);
          }
                       // PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+14*20,deep[1]);
                        if((v[2]<zdz2)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0]))
                        {
                           zdz2=v[2];
                           deepp[2]=a1[stp][0];
                           Rmnselect20[prc][2]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[2]=stp;
       /*   if(str6[lj]=="S13")
          {
             PaintBox2->Canvas->TextOutA(110,44+(prc-1)*110,"v2 ");
             PaintBox2->Canvas->TextOutA(180,44+(prc-1)*110,"                                                  ");
             PaintBox2->Canvas->TextOutA(180,44+(prc-1)*110,v[2]);
             PaintBox2->Canvas->TextOutA(250+54,44+(prc-1)*110,deepp[2]);
             PaintBox2->Canvas->TextOutA(350+54,44+(prc-1)*110,prc);
           }   */

                        /*   if(a1[stp][MN1_pos]<Rm1)
                           {
                               Rm1=a1[stp][MN1_pos];
                               Rmnselect=a1[stp][0];
                               //if(fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]))<Rm2)
                               if(fabs(ckdeep[lj]-a1[stp][0])<Rm2)
                             //  if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]))<Rm2)
                               {
                                //  Rm2=fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]));
                                  Rm2=fabs(ckdeep[lj]-a1[stp][0]);
                                 //  Rm2=fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]));
                                  Rmnselect2[prc][2]=a1[stp][0];
                               }
                               if(fabs(ckdeep[lj]-deepp[2])<selectxfcdp)
                               {
                                   selectxfcdp=fabs(ckdeep[lj]-deepp[2]);
                                   selectxfcdeep=deepp[2];
                               }
                           }    */
                        }

        // if(str6[lj]=="S13")
          {
          //   PaintBox2->Canvas->TextOutA(110,44+(prc-1)*110,"2 ");
           //  PaintBox2->Canvas->TextOutA(180,44+(prc-1)*110,v[2]);
          //   PaintBox2->Canvas->TextOutA(250+54,44+(prc-1)*110,deepp[2]);
           //  PaintBox2->Canvas->TextOutA(200+54,44+(prc-1)*110,Rmnselect);
           //  PaintBox2->Canvas->TextOutA(300+54,44+(prc-1)*110,Rmnselect2[2]);
           //  PaintBox2->Canvas->TextOutA(400+54,44+(prc-1)*110,a1[stmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(500+54,44+(prc-1)*110,a1[enmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(600+54,44+(prc-1)*110,selectxfcdeep);
          }
                        if((v[3]<zdz3)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0]))
                        {
                           zdz3=v[3];
                           deepp[3]=a1[stp][0];
                           Rmnselect20[prc][3]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[3]=stp;
        /*  if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(110,64+(prc-1)*110,"v3 ");
             PaintBox2->Canvas->TextOutA(140,64+(prc-1)*110,"                                                           ");
             PaintBox2->Canvas->TextOutA(140,64+(prc-1)*110,v[3]);
             PaintBox2->Canvas->TextOutA(200+54,64+(prc-1)*110,deepp[3]);
           }   */
                         /*  if(a1[stp][MN1_pos]<Rm1)
                           {
                               Rm1=a1[stp][MN1_pos];
                               Rmnselect=a1[stp][0];
                              // if(fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]))<Rm2)
                              if(fabs(ckdeep[lj]-a1[stp][0])<Rm2)
                             //  if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]))<Rm2)
                               {
                                 // Rm2=fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]));
                                  Rm2=fabs(ckdeep[lj]-a1[stp][0]);
                                 // Rm2=fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]));
                                  Rmnselect2[prc][3]=a1[stp][0];
                               }
                               if(fabs(ckdeep[lj]-deepp[3])<selectxfcdp)
                               {
                                   selectxfcdp=fabs(ckdeep[lj]-deepp[3]);
                                   selectxfcdeep=deepp[3];
                               }
                           }    */
                        }

      //    if(str6[lj]=="S28b")
          {
           //  PaintBox2->Canvas->TextOutA(10,64+(prc-1)*110,prc);
           //  PaintBox2->Canvas->TextOutA(40,64+(prc-1)*110,v[3]);
           //  PaintBox2->Canvas->TextOutA(100+54,64+(prc-1)*110,deepp[3]);
            // PaintBox2->Canvas->TextOutA(200+54,64+(prc-1)*110,Rmnselect);
            // PaintBox2->Canvas->TextOutA(300+54,64+(prc-1)*110,Rmnselect2[3]);
            // PaintBox2->Canvas->TextOutA(400+54,64+(prc-1)*110,a1[stmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(500+54,64+(prc-1)*110,a1[enmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(600+54,64+(prc-1)*110,selectxfcdeep);
          }
                        if((v[4]<zdz4)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0]))
                        {
                           zdz4=v[4];
                           deepp[4]=a1[stp][0];
                           Rmnselect20[prc][4]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[4]=stp;
       /*   if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(110,84+(prc-1)*110,"v4 ");
             PaintBox2->Canvas->TextOutA(140,84+(prc-1)*110,"                                              ");
             PaintBox2->Canvas->TextOutA(140,84+(prc-1)*110,v[4]);
             PaintBox2->Canvas->TextOutA(200+54,84+(prc-1)*110,deepp[4]);
          }   */
                        /*   if(a1[stp][MN1_pos]<Rm1)
                           {
                               Rm1=a1[stp][MN1_pos];
                               Rmnselect=a1[stp][0];
                              // if(fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]))<Rm2)
                              if(fabs(ckdeep[lj]-a1[stp][0])<Rm2)
                             // if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]))<Rm2)
                               {
                                 // Rm2=fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]));
                                  Rm2=fabs(ckdeep[lj]-a1[stp][0]);
                                 // Rm2=fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]));
                                  Rmnselect2[prc][4]=a1[stp][0];
                               }
                               if(fabs(ckdeep[lj]-deepp[4])<selectxfcdp)
                               {
                                   selectxfcdp=fabs(ckdeep[lj]-deepp[4]);
                                   selectxfcdeep=deepp[4];
                               }
                           }   */
                        }

        // if(str6[lj]=="S28b")
          {
           //  PaintBox2->Canvas->TextOutA(10,84+(prc-1)*110,prc);
          //   PaintBox2->Canvas->TextOutA(40,84+(prc-1)*110,v[4]);
          //   PaintBox2->Canvas->TextOutA(100+54,84+(prc-1)*110,deepp[4]);
           //  PaintBox2->Canvas->TextOutA(200+54,84+(prc-1)*110,Rmnselect);
           //  PaintBox2->Canvas->TextOutA(300+54,84+(prc-1)*110,Rmnselect2[4]);
            // PaintBox2->Canvas->TextOutA(400+54,84+(prc-1)*110,a1[stmb[lj]][0]);
          //   PaintBox2->Canvas->TextOutA(500+54,84+(prc-1)*110,a1[enmb[lj]][0]);
          //   PaintBox2->Canvas->TextOutA(600+54,84+(prc-1)*110,selectxfcdeep);

          }
                        if((v[5]<zdz5)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0]))
                        {
                           zdz5=v[5];
                           deepp[5]=a1[stp][0];
                           Rmnselect20[prc][5]=a1[stp][0];
                         //  jdcw[lj]=stp;          //测井数据数据节点
                           ip[5]=stp;
        /*   if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(110,104+(prc-1)*110,"v5 ");
             PaintBox2->Canvas->TextOutA(140,104+(prc-1)*110,"                                                             ");
             PaintBox2->Canvas->TextOutA(140,104+(prc-1)*110,v[5]);
             PaintBox2->Canvas->TextOutA(200+54,104+(prc-1)*110,deepp[5]);
             PaintBox2->Canvas->TextOutA(300+54,104+(prc-1)*110,prc);
          }     */
                      /*     if(a1[stp][MN1_pos]<Rm1)
                           {
                               Rm1=a1[stp][MN1_pos];
                               Rmnselect=a1[stp][0];
                              // if(fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]))<Rm2)
                               if(fabs(ckdeep[lj]-a1[stp][0])<Rm2)
                               //if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]))<Rm2)
                               {
                                 // Rm2=fabs((ckdeep[lj]-ckdeep[lj-1])-(a1[stp][0]-mbdeep[lj-1]));
                                  Rm2=fabs(ckdeep[lj]-a1[stp][0]);
                                 // Rm2=fabs(ckjdjxlc[lj]-(mbjdjx[lj]-a1[stp][0]));
                                  Rmnselect2[prc][5]=a1[stp][0];
                               }
                               if(fabs(ckdeep[lj]-deepp[5])<selectxfcdp)
                               {
                                   selectxfcdp=fabs(ckdeep[lj]-deepp[5]);
                                   selectxfcdeep=deepp[5];
                               }
                           }  */
                        }


        //  if(str6[lj]=="S28b")
          {
           //  PaintBox2->Canvas->TextOutA(10,104+(prc-1)*110,prc);
          //   PaintBox2->Canvas->TextOutA(40,104+(prc-1)*110,v[5]);
          //   PaintBox2->Canvas->TextOutA(100+54,104+(prc-1)*110,deepp[5]);
           //  PaintBox2->Canvas->TextOutA(200+54,104+(prc-1)*110,Rmnselect);
           //  PaintBox2->Canvas->TextOutA(300+54,104+(prc-1)*110,Rmnselect2[5]);
           //  PaintBox2->Canvas->TextOutA(400+54,104+(prc-1)*110,a1[stmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(500+54,104+(prc-1)*110,a1[enmb[lj]][0]);
           //  PaintBox2->Canvas->TextOutA(600+54,104+(prc-1)*110,selectxfcdeep);
          }

                       }


                     }

                   }
        /*  if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(104,24+(prc-1)*100,prc);
             PaintBox2->Canvas->TextOutA(100+54,24+(prc-1)*100,deepp[1]);
             PaintBox2->Canvas->TextOutA(100+54,44+(prc-1)*100,Rmnselect2[prc][1]);
             PaintBox2->Canvas->TextOutA(200+54,24+(prc-1)*100,deepp[2]);
             PaintBox2->Canvas->TextOutA(200+54,44+(prc-1)*100,Rmnselect2[prc][2]);
             PaintBox2->Canvas->TextOutA(300+54,24+(prc-1)*100,deepp[3]);
             PaintBox2->Canvas->TextOutA(300+54,44+(prc-1)*100,Rmnselect2[prc][3]);
             PaintBox2->Canvas->TextOutA(400+54,24+(prc-1)*100,deepp[4]);
             PaintBox2->Canvas->TextOutA(400+54,44+(prc-1)*100,Rmnselect2[prc][4]);
             PaintBox2->Canvas->TextOutA(500+54,24+(prc-1)*100,deepp[5]);
             PaintBox2->Canvas->TextOutA(500+54,44+(prc-1)*100,Rmnselect2[prc][5]);
             PaintBox2->Canvas->TextOutA(600+54,24+(prc-1)*100,Rmnselect);
          }   */
          //       stmb2[lj]=stmb[lj];
          //      enmb2[lj]=enmb[lj];
          //     AICXFCPearsonSYTD2(Sender);    //智能细分层
          //     se2[prc]=psmbdp[lj];
          //       Rse1[prc]=Rmnselect;
          //       se1[prc]=selectxfcdeep;
          //    if(str6[lj]=="S28b")
          //    {
          //       PaintBox2->Canvas->TextOutA(100+54,24+(prc-1)*100,se1[prc]);
          //       PaintBox2->Canvas->TextOutA(100+54,44+(prc-1)*100,se2[prc]);
          //    }
             /*    for(int i1=1;i1<6;i1++)
                 {
                     for(int i2=1;i2<6;i2++)
                     {
                         PaintBox2->Canvas->TextOutA(50,(i2+1)*20+18+140*i1,Rmnselect2[i1][i2]);
                         PaintBox2->Canvas->TextOutA(150,(i2+1)*20+18+140*i1,deepp[i1]);
                     }
                 }

              }   */
                float sd2=9999.0,sd1;
           // deepp[6]=Rmnselect;
            for(int i1=1;i1<6;i1++)
            {

             /*  if(fabs(ckdeep[lj]-deepp[i1])<selectxfcdp)
                 {
                     selectxfcdp=fabs(ckdeep[lj]-deepp[i1]);
                     selectxfcdeep=deepp[i1];
                 }  */
                sd1=fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i1]-mbdeep[lj-1]));
                if(sd1<sd2)
                {
                   sd2=sd1;
                   Rmnselect=deepp[i1];
                }
            }
             if(fabs((ckdeep[lj]-ckdeep[lj-1])-(Rmnselect-mbdeep[lj-1]))<fabs((ckdeep[lj]-ckdeep[lj-1])-(selectxfcdeep-mbdeep[lj-1])))   //  2025-6-8
            // if(fabs(ckdeep[lj]-Rmnselect)<fabs(ckdeep[lj]-selectxfcdeep))
             {
                 CDeep[lj]=Rmnselect;
                 mbdeep[lj]=CDeep[lj];   // 2025-6-7
             }
             else
             {
                CDeep[lj]=selectxfcdeep;
                mbdeep[lj]=CDeep[lj];
             }

   /*   if(fabs((ckdeep[lj]-ckdeep[lj-1])-(mbdeep[lj]-mbdeep[lj-1]))>mbjxfcxzmkz)
      {
             if(prc==4)   //计算到最后一条曲线
             {
               float sdp[100];
               sdp[1]=Rse1[1];sdp[2]=Rse1[2];sdp[3]=Rse1[5];sdp[4]=Rse1[4];
               sdp[5]=se1[1];sdp[6]=se1[2];sdp[7]=se1[5];sdp[8]=se1[4];
               sdp[9]=se2[1];sdp[10]=se2[2];sdp[11]=se2[5];sdp[12]=se2[4];
               for(int i0=1;i0<6;i0++)
               {
                   Rse1[i0]=0.0;
                   se1[i0]=0.0;
               }
               int imk=0;  int io=0; deeplast=0.0;
            for(int i1=1;i1<=11;i1++)
            {

               for(int i2=i1+1;i2<=12;i2++)
               {
                  if(fabs(sdp[i1]-sdp[i2])<0.3)
                  {
                    // deeplast=deep[i1];
                    // jdcw[lj]=ip[i1];
                     io=io+1;
                  }

               }
               if(io>imk)                                            //2025年5月27日 修改前完美
               {
                  imk=io;
                  deeplast=sdp[i1];
                  jdcw[lj]=ip[i1];
               }
            }

            if(deeplast>100.0)
            {
               CDeep[lj]=deeplast;
               mbdeep[lj]=CDeep[lj];
             // deeplast=Rmnselect;
             // jdcw[lj]=ip[1];
            }
            else
            {
                float fcdp=99999.0,fcdeep=0.0;
                for(int i1=1;i1<=8;i1++)
                {
                    if(fabs(ckdeep[lj]-sdp[i1])<fcdp)
                               {
                                   fcdp=fabs(ckdeep[lj]-sdp[i1]);
                                   fcdeep=sdp[i1];
                               }


                }
                CDeep[lj]=fcdeep;
                mbdeep[lj]=CDeep[lj];

            }

             float gp=99999999999999.0,dplast=0.0;
                 for(int u1=1;u1<6;u1++)
                 {
                     for(int u2=1;u2<6;u2++)
                     {
                       if(fabs(ckdeep[lj]-Rmnselect2[u1][u2])<gp)
                       {
                          gp=Rmnselect2[u1][u2];
                          dplast=Rmnselect2[u1][u2];
                       }
                     }
                 }
                if(fabs(ckdeep[lj]-dplast)<fabs(ckdeep[lj]-CDeep[lj]))
                {
                    CDeep[lj]=dplast;
                    mbdeep[lj]=CDeep[lj];
                }
             }
      }
               */
           if((fabs(Rmnselect20[2][1]-Rmnselect20[5][1])<0.3)&&(Rmnselect20[2][1]>100.0)&&(Rmnselect20[5][1]>100.0))
           {
                CDeep[lj]=Rmnselect20[2][1];
                mbdeep[lj]=CDeep[lj];
           }

        /*   if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(420,584,"7S28b=");
             PaintBox2->Canvas->TextOutA(450+64,584,mbdeep[lj]);
             PaintBox2->Canvas->TextOutA(550+94,584,CDeep[lj]);

          }  */


       /*     for(int i1=1;i1<6;i1++)
              {
                 if(fabs(ckdeep[lj]-deep[i1])<selectbzcdp)
                 {
                     selectbzcdp=fabs(ckdeep[lj]-deep[i1]);
                     selectbzcdeep=deep[i1];
                 }

              }
              CDeep[lj]=selectbzcdeep;  */









   /*        int imk=0;  int io=0;
            for(int i1=1;i1<=4;i1++)
            {

               for(int i2=i1+1;i2<=5;i2++)
               {
                  if((fabs(Rmnselect2[i1]-Rmnselect2[i2])<0.3)&&(Rmnselect2[i1]>100.0)&&(Rmnselect2[i2]>100.0))
                  {
                    // deeplast=deep[i1];
                    // jdcw[lj]=ip[i1];
                     io=io+1;
                  }

               }
               if((io>imk)&& &&(Rmnselect2[i1]>100.0))                                           //2025年5月27日 修改前完美
               {
                  imk=io;
                  deeplast=Rmnselect2[i1];
                  jdcw[lj]=ip[i1];
               }
            }

            if(deeplast>100.0)
            {
               CDeep[lj]=deeplast;
               mbdeep[lj]=CDeep[lj];
             // deeplast=Rmnselect;
             // jdcw[lj]=ip[1];
            }
               */
         /*   float sd2=9999.0,sd1;
            deep[6]=Rmnselect;
            for(int i1=0;i1<7;i1++)
            {
              if(str6[lj]=="S213")
              {
                 PaintBox2->Canvas->TextOutA(50+44,(i1+1)*20+164,Rmnselect);
                 PaintBox2->Canvas->TextOutA(150+84,(i1+1)*20+164,deep[i1]);
              }
                sd1=fabs(ckjcjlcxz[lj]-(deep[i1]-mbjdcjx[lj]));
                if(sd1<sd2)
                {
                   sd2=sd1;
                   Rmnselect=deep[i1];
                }
            }
             if(Rmnselect>100.0)
             {
               CDeep[lj]=Rmnselect;
               mbdeep[lj]=CDeep[lj];
             }
                                   */

         //   PaintBox2->Canvas->TextOutA(40,20+(lj-1)*14,str6[lj]);
         //   PaintBox2->Canvas->TextOutA(80,20+(lj-1)*14,Rmnselect);
        /*    PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+14*20,wincu[lj]+wincd[lj]);
            PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+15*20,mbdeep[lj]);
            PaintBox2->Canvas->TextOutA(20+(lj-1)*120,204+16*20,"ie1=");
            PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+16*20,ie1);
            PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204+17*20,ie2);
            PaintBox2->Canvas->TextOutA(20+(lj-1)*120,204+17*20,"ie2=");   */
           /* if(str6[lj]=="G26")
            {
            PaintBox2->Canvas->TextOutA(80,204+0*20,str6[lj]);
            PaintBox2->Canvas->TextOutA(80,204+1*20,deep[1]);
            PaintBox2->Canvas->TextOutA(80,204+2*20,deep[2]);
            PaintBox2->Canvas->TextOutA(80,204+3*20,deep[3]);
            PaintBox2->Canvas->TextOutA(80,204+4*20,deep[4]);
            PaintBox2->Canvas->TextOutA(80,204+5*20,deep[5]);
            PaintBox2->Canvas->TextOutA(80,204+6*20,a1[stmb[lj]][0]);
            PaintBox2->Canvas->TextOutA(80,204+7*20,a1[enmb[lj]][0]);
            PaintBox2->Canvas->TextOutA(80,204+8*20,CDeep[lj]);
            PaintBox2->Canvas->TextOutA(80,204+9*20,stmb[lj]);
            PaintBox2->Canvas->TextOutA(80,204+10*20,enmb[lj]);
            }    */
}
//------------------------------------------------------------------------------------
void __fastcall TForm1::AICXFCljsjk(TObject *Sender)       //智能计算细分层 邻井数据库
{
 /* zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0;zdz4=9999999.0; zdz5=9999999.0;
    Rmnselect=0.0;selectxfcdeep=0.0;Rm1=999999.0;
      Rm2=999999.0;  */
     mbjxfcmkz=(ckdeep[lj]-ckdeep[lj-1])/8.0;
     float mbjxfcmkz1=(ckdeep[lj+1]-ckdeep[lj])/8.0;
      if(xzc==1)        //修正correct
      {

         stpin=stpinsjk[lj];    //节点输入

      }
      else if(xzc==0)
      {
          inputckj(Sender);
          stpin=int(wincu[lj]/relv1);
      }
             /*  PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-3*20,a1[stmb[lj]][0]);
               PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-2*20,a1[enmb[lj]][0]);
               PaintBox2->Canvas->TextOutA(80+(lj-1)*120,204-1*20,totalnumb[lj]);  */
        /*  if(str6[lj]=="S28b")
          {
             PaintBox2->Canvas->TextOutA(130,244+i09*20,i09);
          }  */
               if(str6[lj]==StdCw)
                 {

                    ljcw0=lj;
                    Dice(Sender);
                    for(int i1=stmb[lj];i1<enmb[lj];i1++)
                    {
                      ie2=0;
                      if((a1[i1+chcsh[lj]][MN1_pos]>0.85)&&(a1[i1+chcsh[lj]][Rxo1_pos]>0.85)&&(a1[i1][MN1_pos]>0.1)&&(a1[i1][Rd1_pos]>0.1)&&(a1[i1][Rxo1_pos]>0.1))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[lj];

                       // itz=i1;//检测用
                        for(int i0=i1;i0<stp1;i0++)
                        {
                              Tmbjsj[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                              Tmbjsj[ie2][0]=a1[i0][0];
                              Tmbjsj[ie2][2]=a1[i0][Rd1_pos];
                              Tmbjsj[ie2][3]=a1[i0][DEN1_pos];
                              Tmbjsj[ie2][4]=a1[i0][HAC1_pos];
                              Tmbjsj[ie2][5]=a1[i0][Rxo1_pos];
                              Tmbjsj[ie2][6]=a1[i0][GR1_pos];
                              if(Tmbjsj[ie2][1]<1.0)
                              {
                                 Tmbj=0;
                              }
                              Rmn1[ie2]=Tmbjsj[ie2][prc];
                              ie2++;
                        }
                        Filter(Tmbjsj,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);

                       // if(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice(Sender);
                        }
                       // if((v[1]<zdz1)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0]))
                      //if(v[1]<zdz1)
                        if((v[1]<zdz1)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname-1]+(ckdeep[isname+1]-ckdeep[isname-1])-mbjxfcmkz1)))
                        {
                           zdz1=v[1];
                           deepp[1]=a1[stp][0];
                         //  xuanze[i09][prc][1]=a1[stp][0];
                           //jdcw[lj]=stp;          //测井数据数据节点
                           ip[1]=stp;


                        }
        /*  if(str6[lj]=="P162")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*110,"zdz1 ");
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*110,prc);
             PaintBox2->Canvas->TextOutA(100+54,14+i09*15+(prc-1)*110,deepp[1]);
             PaintBox2->Canvas->TextOutA(200+54,14+i09*15+(prc-1)*110,zdz1);
             PaintBox2->Canvas->TextOutA(400+54,14+i09*15+(prc-1)*110,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(500+54,14+i09*15+(prc-1)*110,a1[enmb[lj]][0]);
          }  */

                       //if(v[2]<zdz2)
                        if((v[2]<zdz2)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname-1]+(ckdeep[isname+1]-ckdeep[isname-1])-mbjxfcmkz1)))
                        {
                           zdz2=v[2];
                           deepp[2]=a1[stp][0];
                         //  xuanze[i09][prc][2]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[2]=stp;
                        }
         /* if(str6[lj]=="P162")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*110,"zdz2 ");
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*110,prc);
             PaintBox2->Canvas->TextOutA(100+54,14+i09*15+(prc-1)*110,deepp[2]);
             PaintBox2->Canvas->TextOutA(200+54,14+i09*15+(prc-1)*110,zdz2);
             PaintBox2->Canvas->TextOutA(400+54,14+i09*15+(prc-1)*110,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(500+54,14+i09*15+(prc-1)*110,a1[enmb[lj]][0]);
          }  */

                      //if(v[3]<zdz3)
                        if((v[3]<zdz3)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname-1]+(ckdeep[isname+1]-ckdeep[isname-1])-mbjxfcmkz1)))
                        {
                           zdz3=v[3];
                           deepp[3]=a1[stp][0];
                          // xuanze[i09][prc][3]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[3]=stp;

                        }

         /* if(str6[lj]=="P162")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*110,"zdz3 ");
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*110,prc);
             PaintBox2->Canvas->TextOutA(100+54,14+i09*15+(prc-1)*110,deepp[3]);
             PaintBox2->Canvas->TextOutA(200+54,14+i09*15+(prc-1)*110,zdz3);
             PaintBox2->Canvas->TextOutA(400+54,14+i09*15+(prc-1)*110,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(500+54,14+i09*15+(prc-1)*110,a1[enmb[lj]][0]);
          }  */
                     //if(v[4]<zdz4)
                        if((v[4]<zdz4)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname-1]+(ckdeep[isname+1]-ckdeep[isname-1])-mbjxfcmkz1)))
                        {
                           zdz4=v[4];
                           deepp[4]=a1[stp][0];
                          // xuanze[i09][prc][4]=a1[stp][0];
                          // jdcw[lj]=stp;          //测井数据数据节点
                           ip[4]=stp;
       /*   if(str6[lj]=="S222+3b")
          {
             PaintBox2->Canvas->TextOutA(110,84+i09*20+(prc-1)*80,i09);
             PaintBox2->Canvas->TextOutA(140,84+i09*20+(prc-1)*80,"                                              ");
             PaintBox2->Canvas->TextOutA(140,84+i09*20+(prc-1)*80,zdz4);
             PaintBox2->Canvas->TextOutA(200+54,84+i09*20+(prc-1)*80,deepp[4]);
          }    */

                        }

        /* if(str6[lj]=="P162")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*110,"zdz4 ");
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*110,prc);
             PaintBox2->Canvas->TextOutA(100+14,14+i09*15+(prc-1)*110,deepp[4]);
             PaintBox2->Canvas->TextOutA(200+24,14+i09*15+(prc-1)*110,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(300+34,14+i09*15+(prc-1)*110,a1[enmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(400+44,14+i09*15+(prc-1)*110,zdz4);
          }  */
                      //if(v[5]<zdz5)
                         if((v[5]<zdz5)&&(a1[stp][0]>a1[stmb[lj]][0])&&(a1[stp][0]<a1[enmb[lj]][0])&&(a1[stp][0]>(CDeep[isname-1]+mbjxfcmkz))&&(a1[stp][0]<(CDeep[isname-1]+(ckdeep[isname+1]-ckdeep[isname-1])-mbjxfcmkz1)))
                         {
                           zdz5=v[5];
                           deepp[5]=a1[stp][0];
                         //  xuanze[i09][prc][5]=a1[stp][0];
                         //  jdcw[lj]=stp;          //测井数据数据节点
                           ip[5]=stp;
         /*  if(str6[lj]=="S310b")
          {
             PaintBox2->Canvas->TextOutA(110,14+i09*15+(prc-1)*110,"v5 ");
             PaintBox2->Canvas->TextOutA(140,14+i09*15+(prc-1)*110,"                                                             ");
             PaintBox2->Canvas->TextOutA(140,14+i09*15+(prc-1)*110,v[5]);
             PaintBox2->Canvas->TextOutA(200+54,14+i09*15+(prc-1)*110,deepp[5]);
             PaintBox2->Canvas->TextOutA(300+54,14+i09*15+(prc-1)*110,zdz5);
             PaintBox2->Canvas->TextOutA(400+54,14+i09*15+(prc-1)*110,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(500+54,14+i09*15+(prc-1)*110,a1[enmb[lj]][0]);
          }  */

                        }


        /*  if(str6[lj]=="P162")
          {
             PaintBox2->Canvas->TextOutA(40,14+i09*15+(prc-1)*110,"zdz5 ");
             PaintBox2->Canvas->TextOutA(80,14+i09*15+(prc-1)*110,prc);
             PaintBox2->Canvas->TextOutA(100+14,14+i09*15+(prc-1)*110,deepp[5]);
             PaintBox2->Canvas->TextOutA(200+24,14+i09*15+(prc-1)*110,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(300+34,14+i09*15+(prc-1)*110,a1[enmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(400+44,14+i09*15+(prc-1)*110,zdz5);
          }  */

                       }


                     }

                   }
        /*  if(str6[lj]=="G13b")
          {
             PaintBox2->Canvas->TextOutA(50,104*(prc-1)+i09*15,i09);
             PaintBox2->Canvas->TextOutA(50+24,104*(prc-1)+i09*15,tnum);
           //  PaintBox2->Canvas->TextOutA(100+94,104*(prc-1)+i09*15,CDeep[lj]);
             PaintBox2->Canvas->TextOutA(200+94,104*(prc-1)+i09*15,deepp[1]);
             PaintBox2->Canvas->TextOutA(300+94,104*(prc-1)+i09*15,deepp[2]);
             PaintBox2->Canvas->TextOutA(400+94,104*(prc-1)+i09*15,deepp[3]);
             PaintBox2->Canvas->TextOutA(500+94,104*(prc-1)+i09*15,deepp[4]);
             PaintBox2->Canvas->TextOutA(600+94,104*(prc-1)+i09*15,deepp[5]);
             PaintBox2->Canvas->TextOutA(90,15+i09*15,a1[stmb[lj]][0]);
             PaintBox2->Canvas->TextOutA(180,15+i09*15,a1[enmb[lj]][0]);
            // PaintBox2->Canvas->TextOutA(50,184+i09*20,zdz1);
            // PaintBox2->Canvas->TextOutA(150+14,184+i09*20,zdz2);
            // PaintBox2->Canvas->TextOutA(250+24,184+i09*20,zdz3);
            // PaintBox2->Canvas->TextOutA(350+34,184+i09*20,zdz4);
            // PaintBox2->Canvas->TextOutA(450+44,184+i09*20,zdz5);
          }   */
               int i4=0;float sd=0.0;
              for(int i1=1;i1<4;i1++)
              {
                  int i3=0;
                 for(int i2=i1+1;i2<=5;i2++)
                 {
                     if(fabs(deepp[i1]-deepp[i2])<0.2)
                     {
                          i3++;
                          if(i3>i4)
                          {
                             i4=i3;
                             if(fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i2]-mbdeep[lj-1]))<fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i1]-mbdeep[lj-1])))
                             {
                                sd=deepp[i2];
                             }
                             else
                             {
                                sd=deepp[i1];
                             }
                          }

                     }
                 }
              }
              if(sd>100.0)
              {

                CDeep[lj]=sd;
                mbdeep[lj]=CDeep[lj];
              }
           /*   if(str6[lj]=="G13b")
              {
                 if((prc==1)||(prc==2))
                 {
                     PaintBox2->Canvas->TextOutA(50,304*(prc-1)+i09*15,i09);
                     PaintBox2->Canvas->TextOutA(50+44,304*(prc-1)+i09*15,sd);
                 }
                 else if((prc==4)||(prc==5))
                 {
                     PaintBox2->Canvas->TextOutA(250,304*(prc-4)+i09*15,i09);
                     PaintBox2->Canvas->TextOutA(250+44,304*(prc-4)+i09*15,sd);
                 }
              }  */
            /*  if(lj>G120lj)
              {
                   float dp[10];int i11=0;
                  if(fabs((ckdeep[lj]-ckdeep[lj-1])-(sd-mbdeep[lj-1]))>=2.5)
                  {
                      sd=0.0;
                      for(int i10=1;i10<=5;i10++)
                      {
                         if(fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i10]-mbdeep[lj-1]))<2.5)
                         {
                             dp[i11]=deepp[i10];
                             if((fabs(dp[i11]-dp[i11-1])<0.3)&&(dp[i11]>100.0))
                             {
                               sd=dp[i11];

                             }
                             i11++;
                         }
                      }
                      if(sd<100.0)
                      {
                         float ph=9999.0;
                         for(int i12=1;i12<=5;i12++)
                         {
                            if(fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i12]-mbdeep[lj-1]))<ph)
                           {
                               ph=fabs((ckdeep[lj]-ckdeep[lj-1])-(deepp[i12]-mbdeep[lj-1]));
                               sd=deepp[i12];
                                   if(str6[lj]=="G24")
                                   {
                                          PaintBox2->Canvas->TextOutA(50,104*(prc-1)+i09*15,i09);
                                          PaintBox2->Canvas->TextOutA(50+44,104*(prc-1)+i09*15,ph);
                                          PaintBox2->Canvas->TextOutA(100+94,104*(prc-1)+i09*15,sd);
                                   }
                           }
                         }
                      }
                  }
              }
                         */
             /* if(str6[lj]=="S13")
              {
                  PaintBox2->Canvas->TextOutA(50,104*(prc-1)+i09*15,i09);
                  PaintBox2->Canvas->TextOutA(50+44,104*(prc-1)+i09*15,tnum);
                  PaintBox2->Canvas->TextOutA(100+94,104*(prc-1)+i09*15,CDeep[lj]);
                  PaintBox2->Canvas->TextOutA(200+94,104*(prc-1)+i09*15,sd);
               //   PaintBox2->Canvas->TextOutA(300+94,104*(prc-1)+i09*15,deepp[2]);
              }  */

           /*   else
              {
                 int yes=0;
                 for(int i1=1;i1<=5;i1++)
                 {
                     if((deepp[i1]>mbdeep[lj-1])&&(deepp[i1]<(mbdeep[lj-1]+(ckdeep[lj+1]-ckdeep[lj-1]))))
                     {
                         CDeep[lj]=deepp[i1];
                         mbdeep[lj]=CDeep[lj];
                         yes=1;
                     }
                 }
                 if(yes==0)
                 {
                    CDeep[lj]=0.0;
                    mbdeep[lj]=CDeep[lj];
                 }
              }    */
             /* if(str6[lj]=="G11")
              {
                  PaintBox2->Canvas->TextOutA(50,104*(prc-1)+i09*15,i09);
                  PaintBox2->Canvas->TextOutA(50+44,104*(prc-1)+i09*15,tnum);
                  PaintBox2->Canvas->TextOutA(100+94,104*(prc-1)+i09*15,CDeep[lj]);
                  PaintBox2->Canvas->TextOutA(200+94,104*(prc-1)+i09*15,sd);
               //   PaintBox2->Canvas->TextOutA(300+94,104*(prc-1)+i09*15,deepp[2]);
              }  */
         /*  if(prc==1)
           {
              i08=(tnum*(prc-1)+i09)*5;
              se1[i08+1]=deepp[5];se1[i08+2]=deepp[4]; se1[i08+3]=deepp[3];se1[i08+4]=deepp[2];se1[i08+5]=deepp[1];
           }
           else if(prc==2)                                                                                               //2025年10月30日注释掉
           {
              i08=(tnum*(prc-1)+i09)*5;
              se1[i08+1]=deepp[5];se1[i08+2]=deepp[4]; se1[i08+3]=deepp[3];se1[i08+4]=deepp[2];se1[i08+5]=deepp[1];
           }
           else if(prc==4)
           {
              i08=(tnum*(prc-2)+i09)*5;
              se1[i08+1]=deepp[5];se1[i08+2]=deepp[4]; se1[i08+3]=deepp[3];se1[i08+4]=deepp[2];se1[i08+5]=deepp[1];
           }
           else if(prc==5)
           {
              i08=(tnum*(prc-2)+i09)*5;
              se1[i08+1]=deepp[5];se1[i08+2]=deepp[4]; se1[i08+3]=deepp[3];se1[i08+4]=deepp[2];se1[i08+5]=deepp[1];
           }    */
           /* if(str6[lj]=="S221b")
            {
               PaintBox2->Canvas->TextOutA(100,(prc-1)*140+18+14*i09,i09);
               PaintBox2->Canvas->TextOutA(150,(prc-1)*140+18+14*i09,prc);
               PaintBox2->Canvas->TextOutA(250,(prc-1)*140+18+14*i09,i08);
            }  */
          /*  if((i09==(tnum-1))&&(str6[lj]=="S12a"))
            {
                FILE *fp1;
                fp1=fopen("D:\\LP1.dat","wt");
                for(int i1=1;i1<=i08+5;i1++)
                {
                   fprintf(fp1,"%8.2f\n",se1[i1]);
                }
                fclose(fp1);
            }  */
         /*  if(i09==(tnum-1))
           {

                for(int i1=1;i1<=i08+4;i1++)
                {
                     i07=0;

                    for(int i2=i1+1;i2<=i08+5;i2++)
                    {
                        if((fabs(se1[i1]-se1[i2])<0.25)&&(se1[i1]>100.0)&&(se1[i2]>100.0))
                        {
                            i07=i07+1;
                            if(i07>=int(i08/3))
                            {
                               selectxfcdeep=se1[i2];
                                   if((str6[lj]=="S222+3a")&&(i09==(tnum-1)))
                                   {
                                      PaintBox2->Canvas->TextOutA(100,140+prc*20,i09);                                  //2025年10月30日注释掉
                                      PaintBox2->Canvas->TextOutA(130,140+prc*20,selectxfcdeep);
                                      PaintBox2->Canvas->TextOutA(200,140+prc*20,i08);
                                    }
                            }
                        }
                    }
                }

           }      */
        /*   if((str6[lj]=="S28c")&&(i09==(tnum-1)))
            {
               PaintBox2->Canvas->TextOutA(100,140+prc*20,i09);
               PaintBox2->Canvas->TextOutA(130,140+prc*20,selectxfcdeep);
               PaintBox2->Canvas->TextOutA(200,140+prc*20,CDeep[lj]);
            } */

          /* if((selectxfcdeep>100.0)&&(i09==(tnum-1)))
           {
                CDeep[lj]=selectxfcdeep;
                mbdeep[lj]=CDeep[lj];
           }
           else if(i09==(tnum-1))
           {
              float sum1=99999.0; float sdp=0.0;
              for(int i1=1;i1<=i08+5;i1++)
              {
                 if((fabs((ckdeep[lj]-ckdeep[lj-1])-(se1[i1]-mbdeep[lj-1]))<sum1)&&(se1[i1]>100.0)&&(se1[i1]>a1[stmb[lj]][0])&&(se1[i1]<a1[enmb[lj]][0]))
                 {
                      sum1=fabs((ckdeep[lj]-ckdeep[lj-1])-(se1[i1]-mbdeep[lj-1]));
                      sdp=se1[i1];                                                                                //2025年10月30日注释掉
                 }
              }
              if(sdp>100.0)
              {
                CDeep[lj]=sdp;
                mbdeep[lj]=CDeep[lj];
              }  */
            /*  if(str6[lj]=="S222+3a")
              {
                 PaintBox2->Canvas->TextOutA(100,140+prc*20,i09);
                 PaintBox2->Canvas->TextOutA(150,140+prc*20,sdp);
                 PaintBox2->Canvas->TextOutA(250,140+prc*20,mbdeep[lj]);
              } */
         //  }
         /*  if((str6[lj]=="S221b")&&(i09==(tnum-1)))
            {
               PaintBox2->Canvas->TextOutA(100,140+prc*20,i09);
               PaintBox2->Canvas->TextOutA(150,140+prc*20,selectxfcdeep);
               PaintBox2->Canvas->TextOutA(250,140+prc*20,mbdeep[lj]);
            }   */

}
//------------------------------------------------------------------------------------


//-----------------------------------------------------------------------------------------
void __fastcall TForm1::AICXFCPearsonSYTD2(TObject *Sender)       //智能计算细分层 皮尔森时域梯度
{
      float s0=0.0,s1=0.0,mkzs2=999999999.0,zdzmkz=0.0,xgxs,deep[10];
      int ip[10];
    //  zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0; zdz4=9999999.0; zdz5=9999999.0;
      if(xzc==1)        //修正correct
      {

         stpin=stpinsjk[lj];    //节点输入

      }
      else if(xzc==0)
      {
          inputckj(Sender);
          stpin=int(wincu[lj]/relv1);
      }
       /*     if(str6[lj]=="S13")
            {
               PaintBox2->Canvas->TextOutA(140,304+(lj-1)*12,"ie1=");
               PaintBox2->Canvas->TextOutA(180,304+(lj-1)*12,ie1);
               PaintBox2->Canvas->TextOutA(180,404+(lj-1)*12,a1[stmb2[lj]][0]);
               PaintBox2->Canvas->TextOutA(280,404+(lj-1)*12,a1[enmb2[lj]][0]);
               PaintBox2->Canvas->TextOutA(380,404+(lj-1)*12,totalnumb[lj]);
            }  */
            if(ie1==1)
            {
               totalnumb[lj]=int((ckdeep[lj]-ckdeep[lj-1])/relv);
             /*  PaintBox2->Canvas->TextOutA(140,304,"ie1=");
               PaintBox2->Canvas->TextOutA(180,304,ie1);
               PaintBox2->Canvas->TextOutA(180,324,a1[stmb2[lj]][0]);
               PaintBox2->Canvas->TextOutA(180,344,str6[lj]);
               PaintBox2->Canvas->TextOutA(180,364,startt[lj]);
               PaintBox2->Canvas->TextOutA(180,384,totalnumb[lj]); */


      for(int i0=100;i0<stedp;i0++)    //去除井顶伪数据
      {

            if((fabs(a[i0][0]-ckdeep[lj-1])<0.005))        //S11  、JC   S37 G11  G110b
            {

                 ie1=0;

                 for(int i=i0;i<i0+totalnumb[lj];i++)
                 {
                        xcsj[ie1][0]=a[i][0];            //2021年11月2日修改原来深度保留2位小数

                        xcsj[ie1][1]=a[i][MN_pos];
                        xcsj[ie1][2]=a[i][Rd_pos];
                        xcsj[ie1][3]=a[i][DEN_pos];
                        xcsj[ie1][4]=a[i][HAC_pos];
                        xcsj[ie1][5]=a[i][Rxo_pos];
                        xcsj[ie1][6]=a[i][GR_pos];
                        Rmn[ie1]=xcsj[ie1][prc];
                        ie1++;
                 }

            }
      }

              Filter(xcsj,ie1,Rmn);
            }
              // if(str6[lj]==StdCw)
                 {
                    Dsmaxmin(Rmn,RMNmax,RMNmin);
                    if(RMNmax<0.01)
                    {
                       RMNmax=1.0;
                    }
                    for(int i0=0;i0<ie1;i0++)
                    {
                        s0=s0+Rmn[i0];
                        I4[i0]=Rmn[i0]/RMNmax;
                    }
                    s0=s0/float(ie1-1);
                  /*  if(str6[lj]=="S222+3b")
                   {
                      PaintBox2->Canvas->TextOutA(180,520,"2="+str6[lj]);
                      PaintBox2->Canvas->TextOutA(180,540,a1[stmb2[lj]][0]);
                      PaintBox2->Canvas->TextOutA(180,560,a1[enmb2[lj]][0]);
                   }  */
                    for(int i1=stmb2[lj];i1<enmb2[lj];i1++)
                    {
                      ie2=0;
                      if((a1[i1+chcsh[lj]][MN1_pos]>0.85)&&(a1[i1+chcsh[lj]][Rxo1_pos]>0.85))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[lj];

                       // itz=i1;//检测用
                        for(int i0=i1;i0<stp1;i0++)
                        {
                              Tmbjsj[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                              Tmbjsj[ie2][0]=a1[i0][0];
                              Tmbjsj[ie2][2]=a1[i0][Rd1_pos];
                              Tmbjsj[ie2][3]=a1[i0][DEN1_pos];
                              Tmbjsj[ie2][4]=a1[i0][HAC1_pos];
                              Tmbjsj[ie2][5]=a1[i0][Rxo1_pos];
                              Tmbjsj[ie2][6]=a1[i0][GR1_pos];
                              if(Tmbjsj[ie2][1]<1.0)
                              {
                                 Tmbj=0;
                              }
                              Rmn1[ie2]=Tmbjsj[ie2][prc];

                              ie2++;
                        }
                        Filter(Tmbjsj,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);
                        for(int i0=0;i0<ie1;i0++)
                        {
                            s1=s1+Rmn1[i0];
                            I5[i0]=Rmn1[i0]/RMNmax1;
                        }
                        s1=s1/float(ie1-1);
                        float ss1=0.0,ss2=0.0,ss3=0.0,s3=0.0;
                        for(int i0=0;i0<ie1-1;i0++)
                        {
                            ss1=ss1+fabs((Rmn[i0]-s0)*(Rmn1[i0]-s1));
                            ss2=ss2+pow((Rmn[i0]-s0),2);
                            ss3=ss3+pow((Rmn1[i0]-s1),2);
                            s3=s3+fabs(I4[i0]-I5[i0])+fabs((I4[i0+1]-I4[i0])-(I5[i0+1]-I5[i0]));
                        }
                           xgxs=ss1/sqrt(ss2*ss3);
                           if((xgxs>zdzmkz)&&(a1[stp][0]>a1[stmb2[lj]][0])&&(a1[stp][0]<a1[enmb2[lj]][0]))
                           {
                               zdzmkz=xgxs;

                               deep[0]=StrToFloat(FormatFloat("0.0",a1[stp][0]));
                               if(a1[stp][MN1_pos]<Rm1)
                               {
                                   Rm1=a1[stp][MN1_pos];
                                   Rmnselect=a1[stp][0];
                               }
                           }
                           if((fabs(s3)<mkzs2)&&(a1[stp][0]>a1[stmb2[lj]][0])&&(a1[stp][0]<a1[enmb2[lj]][0]))
                           {
                              mkzs2=fabs(s3);
                              deep[1]=StrToFloat(FormatFloat("0.0",a1[stp][0]));
                              if(a1[stp][MN1_pos]<Rm1)
                              {
                                  Rm1=a1[stp][MN1_pos];
                                  Rmnselect=a1[stp][0];
                              }
                           }

                       }
                     }

                   }
                 /*  if(str6[lj]=="S13")
                   {
                       PaintBox2->Canvas->TextOutA(80,14+prc*120,deep[0]);
                       PaintBox2->Canvas->TextOutA(180,14+prc*120,deep[1]);
                       PaintBox2->Canvas->TextOutA(280,14+prc*120,Rmnselect);
                   }   */

        /*    if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-deep[0]))<=fabs(ckjdjxlc[lj]-(mbjdjx[lj]-deep[1])))
            {
                CDeep[lj]=deep[0];
                mbdeep[lj]=CDeep[lj];
            }                                            // 2025年5月27日完美版
            else
            {
                CDeep[lj]=deep[1];
                mbdeep[lj]=CDeep[lj];
            }                                 */
              // CDeep[lj]=Rmnselect;
              //  mbdeep[lj]=CDeep[lj];
                psmbdp[lj]=Rmnselect;
               /* if(str6[lj]=="S222+3b")
                {
                    PaintBox2->Canvas->TextOutA(80,14+12,CDeep[lj]);
                }   */
}
//------------------------------------------------------------------------------------
void __fastcall TForm1::AICXFCPearsonSYTD(TObject *Sender)       //智能计算细分层 皮尔森时域梯度
{
      float s0=0.0,s1=0.0,mkzs2=999999999.0,zdzmkz=0.0,xgxs,deep[10],deeplast=0.0;
      int ip[10];
    //  zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0; zdz4=9999999.0; zdz5=9999999.0;
      if(xzc==1)        //修正correct
      {

         stpin=stpinsjk[lj];    //节点输入

      }
      else if(xzc==0)
      {
          inputckj(Sender);
          stpin=int(wincu[lj]/relv1);
      }
          //     PaintBox2->Canvas->TextOutA(180,404+(lj-1)*12,stmb2[lj]);
          //     PaintBox2->Canvas->TextOutA(280,404+(lj-1)*12,enmb2[lj]);
           //    PaintBox2->Canvas->TextOutA(380,404+(lj-1)*12,totalnumb[lj]);
              // if(str6[lj]==StdCw)
                 {
                    Dsmaxmin(Rmn,RMNmax,RMNmin);
                    for(int i0=0;i0<ie1;i0++)
                    {
                        s0=s0+Rmn[i0];
                        I4[i0]=Rmn[i0]/RMNmax;
                    }
                    s0=s0/float(ie1-1);
                  /*  if(str6[lj]=="S222+3b")
                   {
                      PaintBox2->Canvas->TextOutA(180,520,"2="+str6[lj]);
                      PaintBox2->Canvas->TextOutA(180,540,a1[stmb2[lj]][0]);
                      PaintBox2->Canvas->TextOutA(180,560,a1[enmb2[lj]][0]);
                   }  */
                    for(int i1=stmb2[lj];i1<enmb2[lj];i1++)
                    {
                      ie2=0;
                      if((a1[i1+chcsh[lj]][MN1_pos]>0.85)&&(a1[i1+chcsh[lj]][Rxo1_pos]>0.85))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[lj];

                       // itz=i1;//检测用
                        for(int i0=i1;i0<stp1;i0++)
                        {
                              Tmbjsj[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                              Tmbjsj[ie2][0]=a1[i0][0];
                              Tmbjsj[ie2][2]=a1[i0][Rd1_pos];
                              Tmbjsj[ie2][3]=a1[i0][DEN1_pos];
                              Tmbjsj[ie2][4]=a1[i0][HAC1_pos];
                              Tmbjsj[ie2][5]=a1[i0][Rxo1_pos];
                              Tmbjsj[ie2][6]=a1[i0][GR1_pos];
                              if(Tmbjsj[ie2][1]<1.0)
                              {
                                 Tmbj=0;
                              }
                              Rmn1[ie2]=Tmbjsj[ie2][prc];

                              ie2++;
                        }
                        Filter(Tmbjsj,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);
                        for(int i0=0;i0<ie1;i0++)
                        {
                            s1=s1+Rmn1[i0];
                            I5[i0]=Rmn1[i0]/RMNmax1;
                        }
                        s1=s1/float(ie1-1);
                        float ss1=0.0,ss2=0.0,ss3=0.0,s3=0.0;
                        for(int i0=0;i0<ie1-1;i0++)
                        {
                            ss1=ss1+fabs((Rmn[i0]-s0)*(Rmn1[i0]-s1));
                            ss2=ss2+pow((Rmn[i0]-s0),2);
                            ss3=ss3+pow((Rmn1[i0]-s1),2);
                            s3=s3+fabs(I4[i0]-I5[i0])+fabs((I4[i0+1]-I4[i0])-(I5[i0+1]-I5[i0]));
                        }
                           xgxs=ss1/sqrt(ss2*ss3);
                           if((xgxs>zdzmkz)&&(a1[stp][0]>mbdeep[lj-1])&&(a1[stp][0]<a1[enmb2[lj]][0]))
                           {
                               zdzmkz=xgxs;

                               deep[0]=StrToFloat(FormatFloat("0.0",a1[stp][0]));
                               if(a1[stp][MN1_pos]<Rm1)
                               {
                                   Rm1=a1[stp][MN1_pos];
                                   Rmnselect=a1[stp][0];
                               }
                           }
                           if((fabs(s3)<mkzs2)&&(a1[stp][0]>mbdeep[lj-1])&&(a1[stp][0]<a1[enmb2[lj]][0]))
                           {
                              mkzs2=fabs(s3);
                              deep[1]=StrToFloat(FormatFloat("0.0",a1[stp][0]));
                              if(a1[stp][MN1_pos]<Rm1)
                              {
                                  Rm1=a1[stp][MN1_pos];
                                  Rmnselect=a1[stp][0];
                              }
                           }

                       }
                     }

                   }
                /*  if(str6[lj]=="S26")
                   {
                       PaintBox2->Canvas->TextOutA(30,14+prc*120,prc);
                       PaintBox2->Canvas->TextOutA(80,14+prc*120,deep[0]);
                       PaintBox2->Canvas->TextOutA(180,14+prc*120,deep[1]);
                       PaintBox2->Canvas->TextOutA(280,14+prc*120,Rmnselect);
                       PaintBox2->Canvas->TextOutA(380,14+prc*120,str6[lj]);
                        PaintBox2->Canvas->TextOutA(80,34+prc*120,a1[stmb2[lj]][0]);
                        PaintBox2->Canvas->TextOutA(180,34+prc*120,a1[enmb2[lj]][0]);
                   }  */

        /*    if(fabs(ckjdjxlc[lj]-(mbjdjx[lj]-deep[0]))<=fabs(ckjdjxlc[lj]-(mbjdjx[lj]-deep[1])))
            {
                CDeep[lj]=deep[0];
                mbdeep[lj]=CDeep[lj];
            }                                            // 2025年5月27日完美版
            else
            {
                CDeep[lj]=deep[1];
                mbdeep[lj]=CDeep[lj];
            }                                 */
               CDeep[lj]=Rmnselect;
                mbdeep[lj]=CDeep[lj];
              /*  if(str6[lj]=="S26")
                {
                    PaintBox2->Canvas->TextOutA(480,14+12,CDeep[lj]);
                }   */
}
//------------------------------------------------------------------------------------
void __fastcall TForm1::Filter(float Filt[1500][15],int ie,float RMM[1500])  //滤波
{
      RMM[0]=Filt[0][prc];
      RMM[1]=Filt[1][prc];
      for(int i=2;i<ie-2;i++)
      {
         RMM[i]=(Filt[i-2][prc]+Filt[i-1][prc]+Filt[i][prc]+Filt[i+1][prc]+Filt[i+2][prc])/5.0;
      }
      for(int i=0;i<ie;i++)
      {
         Filt[i][prc]=RMM[i];
      }

}
//  float atan(float x)   反正切
//---------------------------------------------------------------------------------
void __fastcall TForm1::Dice(TObject *Sender)
{

   Dsmaxmin(Rmn,RMNmax,RMNmin);
   if(RMNmax<0.1)RMNmax=0.1;
   for(int i=0;i<ie1;i++)
   {        
      jd[i]=atan((xcsj[i+1][prc]-xcsj[i][prc])*100.0/(RMNmax*relv));//relv);           //角度
   }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Dsmaxmin(float D[1500],float Dmax,float Dmin)
{
   Dmax=D[0];Dmin=D[0]; float sp=0.0;
   for(int i=0;i<ie1-1;i++)
   {
      if(D[i]>Dmax)           //角度
      {
        Dmax=D[i];
      }
      if(D[i]<Dmin)
      {
         Dmin=D[i]*(D[i+1]-D[i]);
      }
      sp=sp+D[i];
   }
   ljpj=sp/float(ie1);
   RMNmax=Dmax;
   RMNmin=Dmin;

}
//----------------------------------------------------------------------------------
void __fastcall TForm1::JDsmaxmin(float D[1500],int ie)
{
   JDmax=D[0];JDmin=D[0];
   for(int i=0;i<ie;i++)
   {
      if(D[i]>JDmax)           //角度
      {
        JDmax=D[i];
      }
      if(D[i]<JDmin)
      {
         JDmin=D[i];
      }
   }

}
//----------------------------------------------------------------------------------
void __fastcall TForm1::JDsmaxminint(int JD[1500],int ie)
{
   JDSmax=JD[0];JDSmin=JD[0];
   for(int i=0;i<ie;i++)
   {
      if(JD[i]>JDSmax)           //角度
      {
        JDSmax=JD[i];
      }
      if(JD[i]<JDSmin)
      {
         JDSmin=JD[i];
      }
   }

}
//----------------------------------------------------------------------------------
void __fastcall TForm1::Tice(TObject *Sender)
{

   ojd=0.0;ofd=0.0;
   osm1=0.0,jdsm2=0.0;
   float v2=0,v3=0.0;float osm2=0.0,jdsm3=0.0;
   for(int i=0;i<ie2;i++)
   {
      jd1[i]=atan((Tmbjsj[i+1][prc]-Tmbjsj[i][prc])*100.0/(RMNmax*relv1));//relv1);           //角度
      osm1=osm1+fabs(Tmbjsj[i][prc]-xcsj[i][prc]);    //*(Tmbjsj[i][prc]-xcsj[i][prc]);    欧式距离
      osm2=osm2+(Tmbjsj[i][prc]-xcsj[i][prc]);
      jdsm2=jdsm2+fabs(jd[i]-jd1[i]);                //*(jd[i]-jd1[i]);  角度距离
      jdsm3=jdsm3+(jd[i]-jd1[i]);
      v2=v2+fabs(Tmbjsj[i][prc]-xcsj[i][prc])*fabs(jd[i]-jd1[i]);
      v3=v3+fabs(Tmbjsj[i][prc]-xcsj[i][prc])+fabs(jd[i]-jd1[i]);
   }


    v[1]=osm1*jdsm2;  //较完美
    v[2]=v2;
    v[3]=v3;
    v[4]=fabs(osm2*jdsm3);
    v[5]=fabs(osm2+jdsm3);
   // v[4]=(v[2]+v[3])/2.0;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Tice2(TObject *Sender)
{

   ojd=0.0;ofd=0.0;
   osm1=0.0,jdsm2=0.0;
   float v2=0,v3=0.0;
   float osm2=0.0,jdsm3=0.0;
   for(int i=0;i<ie2;i++)
   {
      jd1[i]=atan((Tmbjsj2[i+1][prc]-Tmbjsj2[i][prc])*100.0/(RMNmax*relv1));//relv1);           //角度
      osm1=osm1+fabs(Tmbjsj2[i][prc]-xcsj[i][prc]);    //*(Tmbjsj[i][prc]-xcsj[i][prc]);    欧式距离
      osm2=osm2+(Tmbjsj[i][prc]-xcsj[i][prc]);        //去掉绝对值
      jdsm2=jdsm2+fabs(jd[i]-jd1[i]);                //*(jd[i]-jd1[i]);  角度距离
      jdsm3=jdsm3+(jd[i]-jd1[i]);                    //去掉绝对值
      v2=v2+fabs(Tmbjsj2[i][prc]-xcsj[i][prc])*fabs(jd[i]-jd1[i]);
      v3=v3+fabs(Tmbjsj2[i][prc]-xcsj[i][prc])+fabs(jd[i]-jd1[i]);
   }


    v[1]=osm1*jdsm2;  //较完美
    v[2]=v2;
    v[3]=v3;
    v[4]=fabs(osm2*jdsm3);
    v[5]=fabs(osm2+jdsm3);
   // v[4]=(v[2]+v[3])/2.0;


}
//---------------------------------------------------------------------------


void __fastcall TForm1::Dsmaxmin1(float D[1500],float Dmax,float Dmin)
{
   Dmax=D[0];Dmin=D[0]; float sp1=0.0;
   for(int i=0;i<ie2-1;i++)                                           
   {
      //   PaintBox2->Canvas->TextOutA(80,14+i*12,D[i]);
       //  PaintBox2->Canvas->TextOutA(180,14+i*12,Dmax);
      if((D[i]>Dmax)&&(D[i]>0))           //角度
      {
        Dmax=D[i];
      }                                                   
      if((D[i]<Dmin)&&(D[i]>0))
      {
         Dmin=D[i];
      }
      sp1=sp1+D[i]*(D[i+1]-D[i]);
   }
   xjpj=sp1/float(ie2);      //新井平均
   RMNmax1=Dmax;
   RMNmin1=Dmin;

}
//----------------------------------------------------------------------------------
void __fastcall TForm1::JDsmaxmin1(float D[1500],int ie)
{
   JDmax1=D[0];JDmin1=D[0];
   for(int i=0;i<ie;i++)
   {
      if(D[i]>JDmax1)           //角度
      {
        JDmax1=D[i];
      }
      if(D[i]<JDmin1)
      {
         JDmin1=D[i];
      }
   }

}
//----------------------------------------------------------------------------------
void __fastcall TForm1::JDsmaxminint1(int JD[1500],int ie)
{
   JDSmax1=JD[0];JDSmin1=JD[0];
   for(int i=0;i<ie;i++)
   {
      if(JD[i]>JDSmax1)           //角度
      {
        JDSmax1=JD[i];
      }
      if(JD[i]<JDSmin)
      {
         JDSmin1=JD[i];
      }
   }

}
//----------------------------------------------------------------------------------
void __fastcall TForm1::paintfencengnewDice(TObject *Sender)
{
  int trackwidth;
  PaintBox4->Canvas->Font->Height=10;
  PaintBox4->Canvas->Pen->Width=1;
  PaintBox4->Canvas->Pen->Style=psSolid;
  float deep1;
  int tw;
  tw=Form1->Width/2.2-5;
 for(int ii0=0;ii0<ljcgs;ii0++)
 {
    for(int i0=100;i0<stedp1;i0++)
    {
      deep1=stdp1+i0*relv1;
      if(fabs(deep1-mbdeep[ii0])<0.01)
      {
          PaintBox4->Canvas->Pen->Color=RGB(210,20,ii0);
          PaintBox4->Canvas->MoveTo(4+0,i0);
          PaintBox4->Canvas->LineTo(40+tw+30,i0);
          if(moveopen==0)
          {
             PaintBox4->Canvas->TextOut(40+tw-14,i0-14,str6[ii0]);
             PaintBox4->Canvas->TextOut(40+tw-14,i0+3,AnsiString(FormatFloat("0.0",mbdeep[ii0])));
          }
       }
    }
                       
  }

   // hdhf(Sender);  //厚度划分
}
//-----------------------------------------------------------------------------------
void __fastcall TForm1::xzxfccorrect(TObject *Sender)    //修正细分层
{
    xfcmkz=99999999.0,mbdeep2=0.0;selectxfcdp2=9999999.0;
      // float p1,p2,sel=999999.0,sele=0.0;
        zdz1=9999999.0; zdz2=9999999.0; zdz3=9999999.0;zdz4=9999999.0; zdz5=9999999.0;
    Rmnselect=0.0;selectxfcdp=99999.0;selectxfcdeep=0.0;Rm1=999999.0;
      Rm2=999999.0;deeplast=0.0;
  /* PaintBox2->Canvas->TextOutA(20,84,"isname=");
   PaintBox2->Canvas->TextOutA(20+54,84+isname*14,isname);
   PaintBox2->Canvas->TextOutA(20,104,"str16[isname]=");
   PaintBox2->Canvas->TextOutA(20+54,104+isname*14,str16[isname]);   */
   n=6;int i01=0,it;//open_switch=1;
   FILE *fp; int i2=n+1;ie1=0;AnsiString Dir;
   if(xzkg==1)
   {          // xzkg;  //选择开关
       Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\"+str16[isname]+"\\";
   }
   else if(xzkg==2)
   {
      Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\沉积单元数据库\\"+str16[isname]+"\\";
   }
   TSearchRec sr;
   TStringList *FileList = new TStringList();


   ccp2.SetLength(ccp2.Length()-3);
   AnsiString filename = ccp2;                 //文件名
   ccp2.SetLength(ccp2.Length()+3);
   int count = filename.Length();              //文件名字符数
   AnsiString s1;
   AnsiString s2;
   AnsiString s4;
   AnsiString s6;
   AnsiString s9;

   char * filename1 = filename.c_str();
   for(int i = 0;i < count-1;i++)
   {
        s1 = s1 + filename1[i];
   }
   for(int i = 0;i < count-2;i++)
   {
        s2 = s2 + filename1[i];
   }
   for(int i = 0;i < count-4;i++)
   {
        s4 = s4 + filename1[i];
   }
   for(int i = 0;i < count-6;i++)
   {
        s6 = s6 + filename1[i];
   }
   for(int i = 0;i < 2;i++)
   {
        s9 = s9 + filename1[i];
   }

   AnsiString Dir00 = Dir + "n*.*" + '.';      //n开头文件
   AnsiString Dir1 = Dir + s1 + "*.*" + '.';   //前count-1个字符相同文件
   AnsiString Dir2 = Dir + s2 + "*.*" + '.';   //前count-2个字符相同文件
   AnsiString Dir4 = Dir + s4 + "*.*" + '.';   //前count-4个字符相同文件
   AnsiString Dir6 = Dir + s6 + "*.*" + '.';   //前count-6个字符相同文件
   AnsiString Dir99 = Dir + s9 + "*.*" + '.';   //前count-6个字符相同文件

   int same = 0;                               //重复文件名判断
   vector<AnsiString> temp;                    //操作数组
   vector<AnsiString> fil;                     //文件名序列数组
   vector<AnsiString> fil2;                    //文件名数组


   FindFirst(Dir1, faAnyFile, sr);             //前count-1个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir2, faAnyFile, sr);            //前count-2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir4, faAnyFile, sr);            //前count-4个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
////                                          //前count-6个字符相同文件加入FileList和fil数组
   FindFirst(Dir6, faAnyFile, sr);
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir99, faAnyFile, sr);            //前2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));

////                                           ////n开头文件加入FileList和fil数组
     FileList->Clear();
     fil.clear();
     fil2.clear();
     String temp2[2000];
     int checked = 0;
     int checked2 = 0;


////                                           ////剔除重复
     for(int i = 0;i < temp.size();i ++)
     {
        //String TempWell0 = temp[i];
        for(int j = 0;j < 2000;j ++)
        {
                if(temp2[checked] == temp2[j] && checked > 0)
                        break;
                checked2 = 0;
                for(int k = 0;k < i;k ++)
                {
                        if(temp[k] == temp[i])
                                checked2 = 1;
                }
                if(checked2 != 0)
                        break;
                else
                {
                        temp2[checked] = temp[i];
                        FileList->Add(temp2[checked]);
                        fil.push_back(temp2[checked]);
                        fil2.push_back(ExtractFileName(temp2[checked]));
                        checked ++;
                        break;
                }
        }

     }

   temp.clear();
   FileList->Count;                           //文件名列表计数
   AnsiString o1 = FileList->Text;
   FileList->SaveToFile("D:\\001.txt");     //输出文件名到txt

   string fname[20];                         //文件路径数组
   string fn[20];                         //文件名数组
   int file_count = 0;
   for(int i = 0;i < 20;i ++)                //前20个文件
   {

        fname[i] = fil[i].c_str();
                 //   PaintBox2->Canvas->TextOutA(70,440+i*14,"name=");
                 //   PaintBox2->Canvas->TextOutA(70+54,440+i*14,fil[i].c_str());
        fn[i] = fil2[i].c_str();
        file_count ++;
        if(file_count == fil.size())
        break;
      
   }
float relvc,dp2=0.0;
int num = 0;
    xzc=1;


   // lj=isname;
if (file_count >3)
{
do{
      if (num == file_count)
      break;
      //FileList->Add(Dir + sr.Name);
     // PaintBox2->Canvas->TextOut(120,2+(i01+1)*14,fn[num].c_str());
       btn=num;

    //  if((CDeep[isname]<10.0)&&(open_correct==0)&&(isname<=2))
      {
        fp=fopen(fname[num].c_str(),"r");
        if(fp)
        {
           ie1=0; i01=i01+1;  //计算打开非零文件个数
           fscanf(fp,"%f %f %f %f %d",&start2[isname],&end2[isname],&ckja2[isname],&relvc,&totalnumb[isname]);


           chcsh2[isname]=totalnumb[isname];
           stpinsjk[isname]=int((ckja2[isname]-start2[isname])/relvc);                  //数据库节点
           prc=5;
           while(feof(fp)==0)
           {
                for(int j=0;j<i2;j++)
                {
                        fscanf(fp,"%f",&xcsj[ie1][j]);
                        xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
                        //bzcsj[ie1][j]=xcsj[ie1][j];
                }
                Rmn[ie1]=xcsj[ie1][prc];
                ie1++;
           }
           if(isname==0)
           {
               st[isname]=jdcw[JClj]-int(ckjcjlcxz[isname]/relvc)-int(cjjxfmkz[itz]/relvc);    //-stpinsjk[isname]
               en[isname]=jdcw[JClj]-int(ckjcjlcxz[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjxfmkz[itz]/relvc);

           }
           else
           {
               st[isname]=ckjjd[isname]+int(ckjcjlcxz[isname]/relvc)-int((ckja2[isname]-start2[isname])/relvc)-int(cjjxfmkz[itz]/relvc); //-stpinsjk[isname]
               en[isname]=ckjjd[isname]+int(ckjcjlcxz[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjxfmkz[itz]/relvc);
           }


           AICXFCcorrect(Sender);

            if(((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz])|(CDeep[isname]<mbjdcjx[isname])||(CDeep[isname]>mbjdjx[isname])||(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))>cjjxfmkz[itz]))&&(open_correct==1))  //校正开关    //层间距细分层门槛值
            {
                 prc=1;
                 for(int io=0;io<ie1;io++)
                 {
                     Rmn[io]=xcsj[io][prc];
                 }
                 AICXFCcorrect(Sender);

                 if(((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz])|(CDeep[isname]<mbjdcjx[isname])||(CDeep[isname]>mbjdjx[isname])||(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))>cjjxfmkz[itz]))&&(open_correct==1))
                 {
                     prc=2;
                     for(int io=0;io<ie1;io++)
                     {
                        Rmn[io]=xcsj[io][prc];
                     }

                     AICXFCcorrect(Sender);
                  /*   if(str6[isname]=="S37")
                     {
                        PaintBox2->Canvas->TextOutA(20,14,"S37st=");
                        PaintBox2->Canvas->TextOutA(20+54,14+i01*20,st[isname]);
                        //PaintBox2->Canvas->TextOutA(80+54,14+num*20,fname[num].c_str());
                        PaintBox2->Canvas->TextOutA(150,14,"en=");
                        PaintBox2->Canvas->TextOutA(150+54,14+i01*20,en[isname]);

                     }   */
                        if(((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))>cjjxfmkz[itz])|(CDeep[isname]<mbjdcjx[isname])||(CDeep[isname]>mbjdjx[isname])||(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))>cjjxfmkz[itz]))&&(open_correct==1))
                        {
                            prc=4;
                            for(int io=0;io<ie1;io++)
                            {
                               Rmn[io]=xcsj[io][prc];
                            }

                            AICXFCcorrect(Sender);
                            if((((fabs(fabs(ckdeep[isname]-ckdeep[isname-1])-fabs(CDeep[isname]-mbdeep[isname-1]))<cjjxfmkz[itz])&&(CDeep[isname]>mbjdcjx[isname])&&(CDeep[isname]<mbjdjx[isname]))||(fabs(ckjdjxlc[isname]-(mbjdjx[isname]-CDeep[isname]))<cjjxfmkz[itz]))&&(open_correct==1))
                            {
                               open_correct=3;  //校正开关
                               dp2=CDeep[isname];
                            }
                        }
                        else
                        {
                            open_correct=3;
                            dp2=CDeep[isname];
                        }
                 }
                 else
                 {
                     open_correct=3;  //校正开关
                     dp2=CDeep[isname];
                 }
            }
            else
            {
               open_correct=3;  //校正开关
               dp2=CDeep[isname];
            }
        }

      }
      fclose(fp);
      num ++;

     }while((i01 < 5)&&(open_correct<2));    //while((i01 < 20));   2023-08-13  改为循环5口井

    FindClose(sr);

    open_correct2=3;

   }
    CDeep[isname]=dp2;

}
//-----------------------------------------------------------------------------------
void __fastcall TForm1::JCxzcorrect(TObject *Sender)    //JCj夹层修正 2025-7-12日增加
{
   JCdz1=9999999.0;JCdz2=99999999.0;JCdz3=999999.9;JCdz4=9999999.9;JCdz5=99999999.0; ib1=0;ib2=0;sos=0.0;
 //  PaintBox2->Canvas->TextOutA(120,184+isname*14,"isname=");
 //  PaintBox2->Canvas->TextOutA(120+54,184+isname*14,isname);
 //  PaintBox2->Canvas->TextOutA(80,204+isname*14,"str16=");
 //  PaintBox2->Canvas->TextOutA(120+54,204+isname*14,str16[isname]);
   n=6;int i01=0,it,itum=0;//open_switch=1;
   float ps1[50],ps2[2000]; RSE=9999.0,Rlast=0.0; op1=0;   op=0;
   FILE *fp; int i2=n+1;ie1=0;AnsiString Dir; open_correct=1;
   if(xzkg==1)
   {          // xzkg;  //选择开关
       Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\"+str16[isname]+"\\";
   }
   else if(xzkg==2)
   {
      Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\沉积单元数据库\\"+str16[isname]+"\\";
   }
   TSearchRec sr;
   TStringList *FileList = new TStringList();


   ccp2.SetLength(ccp2.Length()-3);
   AnsiString filename = ccp2;                 //文件名
   ccp2.SetLength(ccp2.Length()+3);
   int count = filename.Length();              //文件名字符数
   AnsiString s1;
   AnsiString s2;
   AnsiString s4;
   AnsiString s6;
   AnsiString s9;

   char * filename1 = filename.c_str();
   for(int i = 0;i < count-1;i++)
   {
        s1 = s1 + filename1[i];
   }
   for(int i = 0;i < count-2;i++)
   {
        s2 = s2 + filename1[i];
   }
   for(int i = 0;i < count-4;i++)
   {
        s4 = s4 + filename1[i];
   }
   for(int i = 0;i < count-6;i++)
   {
        s6 = s6 + filename1[i];
   }
   for(int i = 0;i < 2;i++)
   {
        s9 = s9 + filename1[i];
   }

   AnsiString Dir00 = Dir + "n*.*" + '.';      //n开头文件
   AnsiString Dir1 = Dir + s1 + "*.*" + '.';   //前count-1个字符相同文件
   AnsiString Dir2 = Dir + s2 + "*.*" + '.';   //前count-2个字符相同文件
   AnsiString Dir4 = Dir + s4 + "*.*" + '.';   //前count-4个字符相同文件
   AnsiString Dir6 = Dir + s6 + "*.*" + '.';   //前count-6个字符相同文件
   AnsiString Dir99 = Dir + s9 + "*.*" + '.';   //前count-6个字符相同文件

   int same = 0;                               //重复文件名判断
   vector<AnsiString> temp;                    //操作数组
   vector<AnsiString> fil;                     //文件名序列数组
   vector<AnsiString> fil2;                    //文件名数组


   FindFirst(Dir1, faAnyFile, sr);             //前count-1个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir2, faAnyFile, sr);            //前count-2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir4, faAnyFile, sr);            //前count-4个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
////                                          //前count-6个字符相同文件加入FileList和fil数组
   FindFirst(Dir6, faAnyFile, sr);
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir99, faAnyFile, sr);            //前2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));

////                                           ////n开头文件加入FileList和fil数组
     FileList->Clear();
     fil.clear();
     fil2.clear();
     String temp2[2000];
     int checked = 0;
     int checked2 = 0;


////                                           ////剔除重复
     for(int i = 0;i < temp.size();i ++)
     {
        //String TempWell0 = temp[i];
        for(int j = 0;j < 2000;j ++)
        {
                if(temp2[checked] == temp2[j] && checked > 0)
                        break;
                checked2 = 0;
                for(int k = 0;k < i;k ++)
                {
                        if(temp[k] == temp[i])
                                checked2 = 1;
                }
                if(checked2 != 0)
                        break;
                else
                {
                        temp2[checked] = temp[i];
                        FileList->Add(temp2[checked]);
                        fil.push_back(temp2[checked]);
                        fil2.push_back(ExtractFileName(temp2[checked]));
                        checked ++;
                        break;
                }
        }

     }

   temp.clear();
   FileList->Count;                           //文件名列表计数
   AnsiString o1 = FileList->Text;
   FileList->SaveToFile("D:\\001.txt");     //输出文件名到txt

   string fname[20];                         //文件路径数组
   string fn[20];                         //文件名数组
   int file_count = 0;
   for(int i = 0;i < 20;i ++)                //前20个文件
   {

        fname[i] = fil[i].c_str();
                  //  PaintBox2->Canvas->TextOutA(70,140+isname*20+i*14,"name=");
                  //  PaintBox2->Canvas->TextOutA(70+54,140+isname*20+i*14,fil[i].c_str());
        fn[i] = fil2[i].c_str();
        file_count ++;
        if(file_count == fil.size())
        break;

   }
float relvc,dp2=0.0,JCdeep;  float RJC=99999.0;
int num = 0;
    xzc=1;
   // lj=isname;
if (file_count >3)
{
   if(file_count >11)
   {
      fnum=12;
   }
   else
   {
      fnum=file_count;
   }
do{
      if (num == file_count)
      break;
      //FileList->Add(Dir + sr.Name);
     // PaintBox2->Canvas->TextOut(120,2+(i01+1)*14,fn[num].c_str());
       btn=num;

    //  if((CDeep[isname]<10.0)&&(open_correct==0)&&(isname<=2))
      {
        fp=fopen(fname[num].c_str(),"r");
        if(fp)
        {
           ie1=0; i01=i01+1;  //计算打开非零文件个数
           fscanf(fp,"%f %f %f %f %d",&start2[isname],&end2[isname],&ckja2[isname],&relvc,&totalnumb[isname]);


           chcsh2[isname]=totalnumb[isname];
           stpinsjk[isname]=int((ckja2[isname]-start2[isname])/relvc);                  //数据库节点
           prc=5;
           while(feof(fp)==0)
           {
                for(int j=0;j<i2;j++)
                {
                        fscanf(fp,"%f",&xcsj[ie1][j]);
                        xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
                        //bzcsj[ie1][j]=xcsj[ie1][j];
                }
                Rmn[ie1]=xcsj[ie1][prc];
                ie1++;
           }
       /*    if(isname==0)
           {
               st[isname]=jdcw[JClj]-int(ckjcjlc[isname]/relvc)-int(cjjmkz[itz]/relvc);    //-stpinsjk[isname]
               en[isname]=jdcw[JClj]-int(ckjcjlc[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjmkz[itz]/relvc);

           }
           else
           {
               st[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)-int((ckja2[isname]-start2[isname])/relvc)-int(cjjmkz[itz]/relvc); //-stpinsjk[isname]
               en[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjmkz[itz]/relvc);
           }
              */
          /*  PaintBox2->Canvas->TextOutA(90,40+i01*24,num);
            PaintBox2->Canvas->TextOutA(140,40+i01*24,fnum);
            PaintBox2->Canvas->TextOutA(180,40+i01*24,i01);  */
            lj=isname;
              if((str6[isname]=="JC")||(str6[isname]=="JCJC"))
              {
                  st[isname]=100;
                  en[isname]=stedp1-totalnumb[isname];
              }
              else if(str6[isname]=="S11")
              {
                  for(int i8=100;i8<stedp1;i8++)
                  {
                        if(fabs(a1[i8][0]-mbdeep[JClj])<0.02)
                        {
                            jdcw[JClj]=i8;
                        }
                  }
                  ckjcjlc[isname]=ckdeep[JClj]-ckdeep[S11lj];
                  st[isname]=jdcw[JClj]-int(ckjcjlc[isname]/relvc)-int(wincu1*2.0/relvc);    //-stpinsjk[isname]
                  en[isname]=jdcw[JClj]-int(ckjcjlc[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(wincd1*2.0/relvc);
                 // PaintBox2->Canvas->TextOutA(i01*100,93+prc*60,a1[st[isname]][0]);
                //  PaintBox2->Canvas->TextOutA(i01*100,113+prc*60,a1[en[isname]][0]);
              }
              else
              {
                    if(str6[isname]=="S37")
                    {
                       ckjjd[isname]=jdcw[JClj];
                       ckjcjlc[isname]=ckdeep[S37lj]-ckdeep[JClj];
                    }
                    else if(str6[isname]=="P27a")
                    {
                       for(int i8=100;i8<stedp1;i8++)
                       {
                          if(fabs(a1[i8][0]-mbdeep[S37lj])<0.02)
                          {
                              ckjjd[isname]=i8;
                          }
                       }
                       ckjcjlc[isname]=ckdeep[P27alj]-ckdeep[S37lj];
                    }
                    else if(str6[isname]=="G110b")
                    {
                       for(int i8=100;i8<stedp1;i8++)
                       {
                          if(fabs(a1[i8][0]-mbdeep[P27alj])<0.02)
                          {
                              ckjjd[isname]=i8;
                          }
                       }
                       ckjcjlc[isname]=ckdeep[G110blj]-ckdeep[P27alj];
                    }
                    else if(str6[isname]=="G120")
                    {
                       for(int i8=100;i8<stedp1;i8++)
                       {
                          if(fabs(a1[i8][0]-mbdeep[G110blj])<0.02)
                          {
                              ckjjd[isname]=i8;
                          }
                       }
                       ckjcjlc[isname]=ckdeep[G120lj]-ckdeep[G110blj];
                    }
                  st[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)-int((ckja2[isname]-start2[isname])*2.0/relvc)-int(wincu1/relvc); //-stpinsjk[isname]
                  en[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)+int((end2[isname]-ckja2[isname])*2.0/relvc)+int(wincd1/relvc);
              }
              if(a1[en[isname]][0]<100.0)
              {
                 en[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)+int(wincd1/relvc);
                  if(a1[en[isname]][0]<100.0)
                  {
                     en[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)+1.0;
                     if(a1[en[isname]][0]<100.0)
                     {
                        en[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)+0.5;
                     }
                  }
              }
           JCAICcorrect(Sender);
           ps1[num]=CDeep[isname];
           ps2[itum]=CDeep[isname];
           itum++;
             /* if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(50,33+num*20,num);
                 PaintBox2->Canvas->TextOutA(100,33+i01*20,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(200,33+i01*20,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(300,33+i01*20,a1[en[isname]][0]);
                 PaintBox2->Canvas->TextOutA(400,33+i01*20,ckjjd[isname]);
                 PaintBox2->Canvas->TextOutA(500,33+i01*20,ckjcjlc[isname]);
                 PaintBox2->Canvas->TextOutA(600,33+i01*20,(end2[isname]-ckja2[isname])*2.0);
                 PaintBox2->Canvas->TextOutA(700,33+i01*20,ps1[num]);
                // PaintBox2->Canvas->TextOutA(i01*100,193,ckjcjlc[isname]+(end2[isname]-ckja2[isname])*2.0+wincd1);
              }  */

           // if((fabs(ckjcjlc[isname]-(CDeep[isname]-mbjdcjx[isname]))>cjjmkz[itz])&&(open_correct==1)||(S11lj>JClj))  //校正开关    //层间距门槛值
           // if((fabs(ckja2[isname]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))            //&&(open_correct==1)    *fabs(ckdeep[isname]-CDeep[isname])
            if((fabs(a2[isname][0]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))
            {
                 RJC=fabs(a2[isname][0]-CDeep[isname]);
                 JCdeep=CDeep[isname];
                 CDJC1[i01][prc]=JCdeep;
                /* prc=1;
                 for(int io=0;io<ie1;io++)
                 {
                     Rmn[io]=xcsj[io][prc];
                 }
                 JCAICcorrect(Sender);   */
            /*  if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(60,33+i01*20,prc);
                 PaintBox2->Canvas->TextOutA(160,33+i01*20,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(260,33+i01*20,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(360,33+i01*20,a1[en[isname]][0]);

              }   */
                /* if(str6[isname]=="S11")
                 {
                     PaintBox2->Canvas->TextOutA(i01*100,53+prc*60,prc);
                     PaintBox2->Canvas->TextOutA(i01*100,73+prc*60,CDeep[isname]);
                 }   */
            }
                 prc=1;
                 for(int io=0;io<ie1;io++)
                 {
                     Rmn[io]=xcsj[io][prc];
                 }
                 JCAICcorrect(Sender);
                 ps2[itum]=CDeep[isname];
                 itum++;
                // if((fabs(ckjcjlc[isname]-(CDeep[isname]-mbjdcjx[isname]))>cjjmkz[itz])&&(open_correct==1)||(S11lj>JClj))
                // if((fabs(ckja2[isname]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))           //&&(open_correct==1)     *fabs(ckdeep[isname]-CDeep[isname])
                 if((fabs(a2[isname][0]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))
                 {
                     RJC=fabs(a2[isname][0]-CDeep[isname]);
                     JCdeep=CDeep[isname];
                     CDJC1[i01][prc]=JCdeep;
                   /*  prc=2;
                     for(int io=0;io<ie1;io++)
                     {
                        Rmn[io]=xcsj[io][prc];
                     }

                     JCAICcorrect(Sender); */
            /* if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(60,33+i01*20,prc);
                 PaintBox2->Canvas->TextOutA(160,33+i01*20,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(260,33+i01*20,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(360,33+i01*20,a1[en[isname]][0]);
               //  PaintBox2->Canvas->TextOutA(460,33+i01*20,a1[en[isname]][0]);
              }  */
                      /*   if(str6[isname]=="S11")
                         {
                             PaintBox2->Canvas->TextOutA(i01*100,93+prc*60,prc);
                             PaintBox2->Canvas->TextOutA(i01*100,113+prc*60,CDeep[isname]);
                           }   */
                 }
                     prc=2;
                     for(int io=0;io<ie1;io++)
                     {
                        Rmn[io]=xcsj[io][prc];
                     }

                     JCAICcorrect(Sender);
                     ps2[itum]=CDeep[isname];
                     itum++;
                       // if((fabs(ckjcjlc[isname]-(CDeep[isname]-mbjdcjx[isname]))>cjjmkz[itz])&&(open_correct==1)||(S11lj>JClj))
                      //  if((fabs(ckja2[isname]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))       //  &&(open_correct==1)        *fabs(ckdeep[isname]-CDeep[isname])
                        if((fabs(a2[isname][0]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))
                        {
                            RJC=fabs(a2[isname][0]-CDeep[isname]);
                            JCdeep=CDeep[isname];
                            CDJC1[i01][prc]=JCdeep;
                          /*  prc=4;
                            for(int io=0;io<ie1;io++)
                            {
                                 Rmn[io]=xcsj[io][prc];
                            }

                            JCAICcorrect(Sender); */
            /*  if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(50,33+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(150,53+prc*60,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(250,73+prc*60,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(350,93+prc*60,a1[en[isname]][0]);

              }  */
                                 /*   if(str6[isname]=="S11")
                                    {
                                           PaintBox2->Canvas->TextOutA(i01*100,133+prc*60,prc);
                                           PaintBox2->Canvas->TextOutA(i01*100,153+prc*60,CDeep[isname]);
                                   }   */
                        }
                            prc=4;
                            for(int io=0;io<ie1;io++)
                            {
                                 Rmn[io]=xcsj[io][prc];
                            }

                            JCAICcorrect(Sender);
                            ps2[itum]=CDeep[isname];
                            itum++;
                           // if((fabs(ckjcjlc[isname]-(CDeep[isname]-mbjdcjx[isname]))<cjjmkz[itz])&&(open_correct==1))
                          //  if((fabs(ckja2[isname]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))            //&&(open_correct==1)      *fabs(ckdeep[isname]-CDeep[isname])
                            if((fabs(a2[isname][0]-CDeep[isname])<=RJC+0.01)&&(CDeep[isname]>a1[st[isname]][0])&&(CDeep[isname]<a1[en[isname]][0]))
                            {
                              RJC=fabs(a2[isname][0]-CDeep[isname]);
                              JCdeep=CDeep[isname];
                              CDJC1[i01][prc]=JCdeep;
             /* if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(60,33+i01*20,prc);
                 PaintBox2->Canvas->TextOutA(160,33+i01*20,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(260,33+i01*20,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(360,33+i01*20,a1[en[isname]][0]);

              }  */
                            }

                      



        }

      }
    //  CDJC[i01]=JCdeep;

      fclose(fp);
      num ++;

     }while((i01 <fnum));    //while((i01 < 20));   2023-08-13  改为循环5口井    &&(open_correct<2)

    FindClose(sr);

  //  open_correct2=3;

   }
           /*  if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(1*100,33+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(1*100,53+prc*60,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(1*100,73+prc*60,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(1*100,93+prc*60,a1[en[isname]][0]);
                 PaintBox2->Canvas->TextOutA(1*100,113+prc*60,JCdeep);

              }   */
    float ps3[2000]; int i4=0;
    for(int i1=0;i1<itum;i1++)
    {
       if(ps2[i1]>100.0)
       {
          ps3[i4]=ps2[i1];
            /*  if(str6[isname]=="G120")
              {
                 if(i4<=42)
                 {
                    PaintBox2->Canvas->TextOutA(100,23+i4*14,i4);
                    PaintBox2->Canvas->TextOutA(150,23+i4*14,ps3[i4]);
                 }
                 else if((i4>42)&&(i4<=84))
                 {
                    PaintBox2->Canvas->TextOutA(300,23+(i4-42)*14,i4);
                    PaintBox2->Canvas->TextOutA(350,23+(i4-42)*14,ps3[i4]);
                 }
                 else if((i4>84)&&(i4<=126))
                 {
                    PaintBox2->Canvas->TextOutA(500,23+(i4-84)*14,i4);
                    PaintBox2->Canvas->TextOutA(550,23+(i4-84)*14,ps3[i4]);
                 }
              } */
          i4++;
       }
    }
     int i6=0;float sdp=0.0;
    for(int i1=0;i1<i4-1;i1++)
    {
       int i5=0;
       for(int i2=i1+1;i2<i4;i2++)
       {
          if(fabs(ps3[i1]-ps3[i2])<0.2)
          {
             i5++;
             if(i5>i6)
             {
                i6=i5;
                sdp=ps3[i2];
             }
          }
       }
    }
    if(sdp>100.0)
    {
       CDeep[isname]=sdp;
       mbdeep[isname]=sdp;
             /* if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(1*100,33+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(1*100,53+prc*60,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(1*100,73+prc*60,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(1*100,93+prc*60,a1[en[isname]][0]);
                 PaintBox2->Canvas->TextOutA(1*100,113+prc*60,JCdeep);

              }  */
    }
    else
    {
        int iu=0;
        for(int i1=1;i1<fnum;i1++)
        {
            prc=1;
            if((CDJC1[i1][prc]>100.0)&&(CDJC1[i1][prc]>a1[st[isname]][0])&&(CDJC1[i1][prc]<a1[en[isname]][0]))
            {
               CDJC[iu]=CDJC1[i1][prc];
               iu=iu+1;
            }
            prc=2;
            if((CDJC1[i1][prc]>100.0)&&(CDJC1[i1][prc]>a1[st[isname]][0])&&(CDJC1[i1][prc]<a1[en[isname]][0]))
            {
               CDJC[iu]=CDJC1[i1][prc];
               iu=iu+1;
            }
            prc=4;
            if((CDJC1[i1][prc]>100.0)&&(CDJC1[i1][prc]>a1[st[isname]][0])&&(CDJC1[i1][prc]<a1[en[isname]][0]))
            {
               CDJC[iu]=CDJC1[i1][prc];
               iu=iu+1;
            }
            prc=5;
            if((CDJC1[i1][prc]>100.0)&&(CDJC1[i1][prc]>a1[st[isname]][0])&&(CDJC1[i1][prc]<a1[en[isname]][0]))
            {
               CDJC[iu]=CDJC1[i1][prc];
               iu=iu+1;
            }
        }
        int nui;
        for(int i1=0;i1<iu-1;i1++)
        {
            nui=0;
           /*   if(str6[isname]=="S37")
              {
                 PaintBox2->Canvas->TextOutA(60,53+i1*20,prc);
                 PaintBox2->Canvas->TextOutA(100,53+i1*20,CDJC[i1]);
                 PaintBox2->Canvas->TextOutA(200,53+i1*20,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(300,53+i1*20,a1[en[isname]][0]);
              }  */
           for(int i2=i1+1;i2<iu;i2++)
           {
             if(isname==S11lj)
             {
                 if((fabs(CDJC[i1]-CDJC[i2])<0.2)&&(CDJC[i1]<a1[ckjjd[isname]][0])&&(CDJC[i2]<a1[ckjjd[isname]][0])&&(CDJC[i1]>100.0)&&(CDJC[i2]>100.0))
                 {
                     nui=nui+1;
                     if(nui>int(iu/3))
                     {
                        dp2=CDJC[i1];
                     }
                 }
             }
             else if(isname==JClj)
             {
                 if(fabs(CDJC[i1]-CDJC[i2])<0.2)  //&&(CDJC[i1]<a1[ckjjd[isname]][0])&&(CDJC[i2]<a1[ckjjd[isname]][0]))
                 {
                     nui=nui+1;
                     if(nui>int(iu/3))
                     {
                         dp2=CDJC[i1];
                     }
                 }

             }
             else if(isname>JClj)
             {
            /* if(str6[isname]=="G120")
              {
                 PaintBox2->Canvas->TextOutA(60,53+i1*20,prc);
                 PaintBox2->Canvas->TextOutA(100,53+i1*20,CDJC[i1]);
                 PaintBox2->Canvas->TextOutA(200,53+i1*20,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(300,53+i1*20,a1[en[isname]][0]);
                 PaintBox2->Canvas->TextOutA(400,53+i1*20,int(iu/2));
                 PaintBox2->Canvas->TextOutA(500,53+i1*20,fnum);
                 PaintBox2->Canvas->TextOutA(600,53+i1*20,num);
              }   */
           //  if((fabs(CDJC[i1]-CDJC[i2])<0.2)&&(CDJC[i1]>a1[ckjjd[isname]][0])&&(CDJC[i2]>a1[ckjjd[isname]][0]))
                 if(fabs(CDJC[i1]-CDJC[i2])<0.2)//&&(CDJC[i1]>a1[ckjjd[isname]][0])&&(CDJC[i2]>a1[ckjjd[isname]][0]))
                 {
                     nui=nui+1;
                     if(nui>=int(iu/3))
                     {
                        dp2=CDJC[i2];
                  /* if(str6[isname]=="S37")
                   {
                       PaintBox2->Canvas->TextOutA(60,53+i1*20,prc);
                       PaintBox2->Canvas->TextOutA(100,53+i1*20,CDJC[i1]);
                       PaintBox2->Canvas->TextOutA(200,53+i1*20,"                            ");
                       PaintBox2->Canvas->TextOutA(200,53+i1*20,dp2);
                       PaintBox2->Canvas->TextOutA(300,53+i1*20,"                                ");
                       PaintBox2->Canvas->TextOutA(300,53+i1*20,nui);
                       PaintBox2->Canvas->TextOutA(400,53+i1*20,int(iu/2));
                   }   */
                     }

                 }
             }
           }
        }
          float dp1=0.0;
      for(int i0=0;i0<num-1;i0++)
      {
         nui=0;
         for(int i1=i0+1;i1<num;i1++)
         {
             if(fabs(ps1[i0]-ps1[i1])<0.2)
             {
                  nui=nui+1;
                  if(nui>int(num/2))
                  {
                     dp1=ps1[i1];
                  }
             }
         }
      }

   if(dp1>100.0)
   {
      CDeep[isname]=dp1;
      mbdeep[isname]=dp1;
   }
   else if(dp2>100.0)
   {
      CDeep[isname]=dp2;
      mbdeep[isname]=dp2;
    /*  if(str6[isname]=="S37")
      {
          PaintBox2->Canvas->TextOutA(80,224,"G120 ");
          PaintBox2->Canvas->TextOutA(120,224,str6[isname]);
          PaintBox2->Canvas->TextOutA(120,244,mbdeep[isname]);
          PaintBox2->Canvas->TextOutA(120,264,dp2);
          PaintBox2->Canvas->TextOutA(120,284,RJC);
      }  */
   }
   else if(JCdeep>100.0)            //&&(open_correct==1)      *fabs(ckdeep[isname]-CDeep[isname])
   {
      CDeep[isname]=JCdeep;
      mbdeep[isname]=JCdeep;
     /* if(str6[isname]=="S37")
      {
          PaintBox2->Canvas->TextOutA(80,224,"S37 ");
          PaintBox2->Canvas->TextOutA(120,224,str6[isname]);
          PaintBox2->Canvas->TextOutA(120,244,mbdeep[isname]);
          PaintBox2->Canvas->TextOutA(120,264,dp2);
      }   */
   }
   else
   {
      if(isname==S11lj)
      {
         if((CDJC[0]<a1[ckjjd[isname]][0])&&(CDJC[0]>100.0))
         {
             CDeep[isname]=CDJC[0];
             mbdeep[isname]=CDJC[0];
         }
         else if((CDJC[1]<a1[ckjjd[isname]][0])&&(CDJC[1]>100.0))
         {
             CDeep[isname]=CDJC[1];
             mbdeep[isname]=CDJC[1];
         }
         else if((CDJC[2]<a1[ckjjd[isname]][0])&&(CDJC[2]>100.0))
         {
             CDeep[isname]=CDJC[2];
             mbdeep[isname]=CDJC[2];
         }
      }
      else if(isname==JClj)
      {
          if(CDJC[0]>100.0)
         {
             CDeep[isname]=CDJC[0];
             mbdeep[isname]=CDJC[0];
         }
         else if(CDJC[1]>100.0)
         {
             CDeep[isname]=CDJC[1];
             mbdeep[isname]=CDJC[1];
         }
         else if(CDJC[2]>100.0)
         {
             CDeep[isname]=CDJC[2];
             mbdeep[isname]=CDJC[2];
         }
      }
      else
      {
          if(CDJC[0]>a1[ckjjd[isname]][0])
         {
             CDeep[isname]=CDJC[0];
             mbdeep[isname]=CDJC[0];
         }
         else if(CDJC[1]>a1[ckjjd[isname]][0])
         {
             CDeep[isname]=CDJC[1];
             mbdeep[isname]=CDJC[1];
         }
         else if(CDJC[2]>a1[ckjjd[isname]][0])
         {
             CDeep[isname]=CDJC[2];
             mbdeep[isname]=CDJC[2];
         }
      }

   }
   }
          /*    if(str6[isname]=="S11")
              {
                 PaintBox2->Canvas->TextOutA(1*100,33+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(1*100,53+prc*60,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(1*100,73+prc*60,a1[st[isname]][0]);
                 PaintBox2->Canvas->TextOutA(1*100,93+prc*60,a1[en[isname]][0]);

              }   */

        /*     if(prc==1)
             {
                ib2=(btn+1)*(prc)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }
             else if(prc==2)
             {
                ib2=(btn+1)*(prc)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }
             else if(prc==4)
             {
                ib2=(btn+1)*(prc-1)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }
             else if(prc==5)
             {
                ib2=(btn+1)*(prc-1)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }
             int so1=0; float so[800];
             if((btn==(fnum-1)))
             {
                 so1=0;
                for(int i3=1;i3<=ib2+5;i3++)
                {    */
                 /*  if(str6[isname]=="S37")
                   {
                       PaintBox2->Canvas->TextOutA(50,14+i3*14,i3);
                       PaintBox2->Canvas->TextOutA(150,14+i3*14,bzcpb[i3]);
                       PaintBox2->Canvas->TextOutA(300,14+i3*14,ib2+5);
                       PaintBox2->Canvas->TextOutA(400,14+i3*14,prc);
                   }  */
            /*        if(bzcpb[i3]>100.0)
                    {

                       so[so1]=bzcpb[i3];
                     //  PaintBox2->Canvas->TextOutA(400,14+so1*14,so1);
                     //  PaintBox2->Canvas->TextOutA(450,14+so1*14,so[so1]);
                       so1++;
                    }
                }
                for(int i1=0;i1<so1-1;i1++)
                {
                     ib1=0;
                    for(int i2=i1+1;i2<=so1-1;i2++)
                    {
                       if(fabs(so[i1]-so[i2])<0.05)
                       {
                          ib1++;
                          if(ib1>=int((so1-1)/3))
                          {
                             sos=so[i2];
                          }
                       }
                    }
                }
              }

                  */








   /*  if(str6[isname]=="S37")
      {
          PaintBox2->Canvas->TextOutA(80,224,"S37 ");
          PaintBox2->Canvas->TextOutA(120,224,str6[isname]);
          PaintBox2->Canvas->TextOutA(120,244,mbdeep[isname]);
          PaintBox2->Canvas->TextOutA(120,264,dp2);
          PaintBox2->Canvas->TextOutA(120,284,RJC);
      }   */

 /*  if(str6[isname]=="S37")
  {
    PaintBox2->Canvas->TextOutA(80,224,"S37 ");
    PaintBox2->Canvas->TextOutA(120,224,str6[isname]);
    PaintBox2->Canvas->TextOutA(120,244,mbdeep[isname]);
    PaintBox2->Canvas->TextOutA(120,264,CDeep[isname]);
    PaintBox2->Canvas->TextOutA(120,284,a1[st[isname]][0]);
    PaintBox2->Canvas->TextOutA(120,304,a1[en[isname]][0]);
  }   */
  // mbJCdeep=dp2;
 /* if(str6[isname]=="S11")
  {
    PaintBox2->Canvas->TextOutA(80,24,"S11 ");
    PaintBox2->Canvas->TextOutA(120,24,str6[isname]);
    PaintBox2->Canvas->TextOutA(120,44,mbdeep[isname]);
    PaintBox2->Canvas->TextOutA(120,64,CDeep[isname]);
    PaintBox2->Canvas->TextOutA(120,84,a1[st[isname]][0]);
    PaintBox2->Canvas->TextOutA(120,104,a1[en[isname]][0]);
  }
  if((str6[isname]=="JC")||(str6[isname]=="JCJC"))
  {
    PaintBox2->Canvas->TextOutA(80,124,"JC ");
    PaintBox2->Canvas->TextOutA(120,124,str6[isname]);
    PaintBox2->Canvas->TextOutA(120,144,mbdeep[isname]);
    PaintBox2->Canvas->TextOutA(120,164,CDeep[isname]);
    PaintBox2->Canvas->TextOutA(120,184,a1[st[isname]][0]);
    PaintBox2->Canvas->TextOutA(120,204,a1[en[isname]][0]);
  }
  if(str6[isname]=="S37")
  {
    PaintBox2->Canvas->TextOutA(80,224,"S37 ");
    PaintBox2->Canvas->TextOutA(120,224,str6[isname]);
    PaintBox2->Canvas->TextOutA(120,244,mbdeep[isname]);
    PaintBox2->Canvas->TextOutA(120,264,CDeep[isname]);
    PaintBox2->Canvas->TextOutA(120,284,a1[st[isname]][0]);
    PaintBox2->Canvas->TextOutA(120,304,a1[en[isname]][0]);
  }
  if(str6[isname]=="G110b")
  {
    PaintBox2->Canvas->TextOutA(80,324,"G110b ");
    PaintBox2->Canvas->TextOutA(120,324,str6[isname]);
    PaintBox2->Canvas->TextOutA(120,344,mbdeep[isname]);
    PaintBox2->Canvas->TextOutA(120,364,CDeep[isname]);
    PaintBox2->Canvas->TextOutA(120,384,a1[st[isname]][0]);
    PaintBox2->Canvas->TextOutA(120,404,a1[en[isname]][0]);
  }    */
}
//--------------------------------------------------------------------
void __fastcall TForm1::JCAICcorrect(TObject *Sender)       //JC智能计算校正
{
      float deep[10],mxz=999999.0,mbjcjlc=0.0; //门限值     ckjcjlc[isname]=ckdeep[S37lj]-ckdeep[JClj];
     // zdz1=9999999.0; zdz2=9999999.0;zdz3=9999999.0; zdz4=9999999.0;zdz5=9999999.0;
              stpin=stpinsjk[isname];    //节点输入
              int ip[10];

                 /*  if(str6[isname]=="S37")
                    {
                       PaintBox2->Canvas->TextOutA(50,314+btn*14,"st-2=");
                       PaintBox2->Canvas->TextOutA(50+54,314+btn*14,a1[st[isname]][0]);
                      // PaintBox2->Canvas->TextOutA(170+54,314+btn*14,st[isname]);
                       PaintBox2->Canvas->TextOutA(250,314+btn*14,"en-2=");
                       PaintBox2->Canvas->TextOutA(250+54,314+btn*14,a1[en[isname]][0]);
                     //  PaintBox2->Canvas->TextOutA(370+54,314+btn*14,en[isname]);
                    }  */
              // if(str6[lj]==StdCw)
                 {

                    ljcw0=isname;
                    Dice(Sender);
                   /* if((str6[isname]=="JC")||||(str6[isname]=="JCJC"))
                    {
                        PaintBox2->Canvas->TextOutA(50,14+btn*14,"stpin=");
                        PaintBox2->Canvas->TextOutA(50+54,14+btn*14,stpin);
                        PaintBox2->Canvas->TextOutA(250,14+btn*14,"btn=");
                        PaintBox2->Canvas->TextOutA(250+54,14+btn*14,btn);
                        PaintBox2->Canvas->TextOutA(450,14+btn*14,"totalnumb=");     // +btn*14
                        PaintBox2->Canvas->TextOutA(450+94,14+btn*14,totalnumb[isname]);
                     }   */
                    for(int i1=st[isname];i1<en[isname];i1++)
                    {

                      ie2=0;
                      if((a1[i1+chcsh2[isname]][MN1_pos]>0.85)&&(a1[i1+chcsh2[isname]][Rxo1_pos]>0.85))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[isname];
                       // itz=i1;//检测用
                          for(int i0=i1;i0<stp1;i0++)
                          {
                                Tmbjsj2[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                                Tmbjsj2[ie2][0]=a1[i0][0];
                                Tmbjsj2[ie2][2]=a1[i0][Rd1_pos];
                                Tmbjsj2[ie2][3]=a1[i0][DEN1_pos];
                                Tmbjsj2[ie2][4]=a1[i0][HAC1_pos];
                                Tmbjsj2[ie2][5]=a1[i0][Rxo1_pos];
                                Tmbjsj2[ie2][6]=a1[i0][GR1_pos];
                                if(Tmbjsj2[ie2][1]<1.0)
                                {
                                   Tmbj=0;
                                }
                                Rmn1[ie2]=Tmbjsj2[ie2][prc];
                                ie2++;
                          }
                         /* PaintBox2->Canvas->TextOutA(150,14+btn*14,"ie2=");     // +btn*14
                          PaintBox2->Canvas->TextOutA(150+54,14+btn*14,ie2);  */      // +btn*14
                        Filter(Tmbjsj2,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);
                      /*  PaintBox2->Canvas->TextOutA(50,14+i1*14,"ie1=");
                       PaintBox2->Canvas->TextOutA(50+54,14+i1*14,ie1);
                        PaintBox2->Canvas->TextOutA(150,14+i1*14,"ie2=");
                       PaintBox2->Canvas->TextOutA(150+54,14+i1*14,ie2);   */
                        //(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice2(Sender);
                        }
               /*     if((str6[isname]=="JC")||(str6[isname]=="JCJC"))
                    {
                       PaintBox2->Canvas->TextOutA(100,114+btn*14,btn);
                       PaintBox2->Canvas->TextOutA(150,114+btn*14,ckja2[isname]);
                       PaintBox2->Canvas->TextOutA(150+104,114+btn*14,start2[isname]);
                       PaintBox2->Canvas->TextOutA(150+204,114+btn*14,end2[isname]);
                    }        */


                        if((v[1]<JCdz1)&&(a1[stp][0]>a1[st[isname]][0])&&(a1[stp][0]<a1[en[isname]][0]))
                        {
                           JCdz1=v[1];
                           deep[1]=a1[stp][0];
                           ip[1]=stp;
                            /* if(str6[isname]=="S37")
                             {
                                PaintBox2->Canvas->TextOutA(btn*120,14+prc*104,"1  ");
                               // PaintBox2->Canvas->TextOutA(50+btn*120,14+prc*104,JCdz1);
                                PaintBox2->Canvas->TextOutA(50+btn*120,34+prc*104,deep[1]);
                             }  */
                        }
                        if((v[2]<JCdz2)&&(a1[stp][0]>a1[st[isname]][0])&&(a1[stp][0]<a1[en[isname]][0]))
                        {
                           JCdz2=v[2];
                           deep[2]=a1[stp][0];
                           ip[2]=stp;
                            /* if(str6[isname]=="S37")
                             {
                                PaintBox2->Canvas->TextOutA(btn*120,54+prc*104,"2  ");
                               // PaintBox2->Canvas->TextOutA(50+btn*100,54+prc*104,JCdz2);
                                PaintBox2->Canvas->TextOutA(50+btn*120,74+prc*104,deep[2]);
                             }  */
                        }
                        if((v[3]<JCdz3)&&(a1[stp][0]>a1[st[isname]][0])&&(a1[stp][0]<a1[en[isname]][0]))
                        {
                           JCdz3=v[3];
                           deep[3]=a1[stp][0];
                           ip[3]=stp;
                            /* if((str6[isname]=="JC")||(str6[isname]=="JCJC"))
                             {
                                PaintBox2->Canvas->TextOutA(btn*100,94+prc*104,"3  ");
                                PaintBox2->Canvas->TextOutA(50+btn*100,94+prc*104,JCdz3);
                                PaintBox2->Canvas->TextOutA(50+btn*100,114+prc*104,deep[3]);
                             }  */
                        }
                        if((v[4]<JCdz4)&&(a1[stp][0]>a1[st[isname]][0])&&(a1[stp][0]<a1[en[isname]][0]))
                        {
                           JCdz4=v[4];
                           deep[4]=a1[stp][0];
                           ip[4]=stp;
                           /*  if((str6[isname]=="JC")||(str6[isname]=="JCJC"))
                             {
                                PaintBox2->Canvas->TextOutA(btn*100,134+prc*104,"4  ");
                                PaintBox2->Canvas->TextOutA(50+btn*100,134+prc*104,JCdz4);
                                PaintBox2->Canvas->TextOutA(50+btn*100,154+prc*104,deep[4]);
                             }   */
                        }
                        if((v[5]<JCdz5)&&(a1[stp][0]>a1[st[isname]][0])&&(a1[stp][0]<a1[en[isname]][0]))
                        {
                           JCdz5=v[5];
                           deep[5]=a1[stp][0];
                           ip[5]=stp;
                           /*  if((str6[isname]=="JC")||(str6[isname]=="JCJC"))
                             {
                                PaintBox2->Canvas->TextOutA(btn*100,174+prc*104,"5  ");
                                PaintBox2->Canvas->TextOutA(50+btn*100,174+prc*104,JCdz5);
                                PaintBox2->Canvas->TextOutA(50+btn*100,194+prc*104,deep[5]);
                             }   */
                        }
                       }
                     }

                   }
            /*      int op=0;
                 for(int iu=1;iu<=5;iu++)
                 {
                   if(str6[isname]=="S11")
                    {

                        if(fabs(ckjcjlc[isname]-(mbjdcjx[isname]-deep[iu]))<mxz)
                        {
                            mxz=fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]));
                            CDeep[isname]=deep[iu];
                            jdcw[isname]=ip[iu];
                            op=1;
                        }
                    }
                    else
                    {

                        if(fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]))<mxz)
                        {
                            mxz=fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]));
                            CDeep[isname]=deep[iu];
                            jdcw[isname]=ip[iu];
                            op=1;
                        }
                    }
                 }
                 if(op==0)
                 {
                    CDeep[isname]=deep[1];
                    jdcw[isname]=ip[1];
                 }     */
                /*  if(str6[isname]=="G120")
                  {
                       PaintBox2->Canvas->TextOutA(50+prc*120,14+btn*110,"deep1=");
                       PaintBox2->Canvas->TextOutA(100+prc*120,14+btn*110,deep[1]);
                       PaintBox2->Canvas->TextOutA(50+prc*120,34+btn*110,"deep2=");
                       PaintBox2->Canvas->TextOutA(100+prc*120,34+btn*110,deep[2]);
                       PaintBox2->Canvas->TextOutA(50+prc*120,54+btn*110,"deep3=");
                       PaintBox2->Canvas->TextOutA(100+prc*120,54+btn*110,deep[3]);
                       PaintBox2->Canvas->TextOutA(50+prc*120,74+btn*110,"deep4=");
                       PaintBox2->Canvas->TextOutA(100+prc*120,74+btn*110,deep[4]);
                       PaintBox2->Canvas->TextOutA(50+prc*120,94+btn*110,"deep5=");
                       PaintBox2->Canvas->TextOutA(100+prc*120,94+btn*110,deep[5]);
                     //  PaintBox2->Canvas->TextOutA(50,14+6*14,"JCdp=");
                    //   PaintBox2->Canvas->TextOutA(50+54,14+6*14,JCdp);
                  } */
          /*    for(int i1=1;i1<6;i1++)
              {
                 if((fabs(ckdeep[isname]-deep[i1])<selectbzcdp)&&(deep[i1]>100.0))
                 {
                     selectbzcdp=fabs(ckdeep[isname]-deep[i1]);         //  2025年6月6号
                     selectbzcdeep=deep[i1];
                 }

              }
              CDeep[isname]=selectbzcdeep;

              PaintBox2->Canvas->TextOutA(150,314+btn*14,"                    ");
              PaintBox2->Canvas->TextOutA(150,314+btn*14,CDeep[isname]);

                  */

          /*    if(selectbzcdeep <100.0)
              {
                 CDeep[isname]=JCdp;
              }
              PaintBox2->Canvas->TextOutA(150,314+btn*14,"                    ");
              PaintBox2->Canvas->TextOutA(150,314+btn*14,CDeep[isname]);
              PaintBox2->Canvas->TextOutA(150+104,314+btn*14,"               ");
              PaintBox2->Canvas->TextOutA(150+104,314+btn*14,JCdp);   */
            /*  if((fabs(deep[1]-deep[2])<0.02)&&(fabs(deep[1]-deep[3])<0.02))
              {
                 CDeep[lj]=deep[1];
              }  */
       /*    if(prc==1)
             {
                ib2=(btn+1)*(prc)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }
             else if(prc==2)
             {
                ib2=(btn+1)*(prc)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }
             else if(prc==4)
             {
                ib2=(btn+1)*(prc-1)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }
             else if(prc==5)
             {
                ib2=(btn+1)*(prc-1)*5;
                bzcpb[ib2+1]=deep[5];bzcpb[ib2+2]=deep[4];bzcpb[ib2+3]=deep[3]; bzcpb[ib2+4]=deep[2];bzcpb[ib2+5]=deep[1];
             }

           //  if((btn==(fnum-1)))
             {
                 so1=0;
                for(int i3=1;i3<=ib2+5;i3++)
                {
                   if(str6[isname]=="S37")
                   {
                       PaintBox2->Canvas->TextOutA(50,14+i3*14,i3);
                       PaintBox2->Canvas->TextOutA(80,14+i3*14,btn);
                       PaintBox2->Canvas->TextOutA(110,14+i3*14,fnum);
                       PaintBox2->Canvas->TextOutA(150,14+i3*14,bzcpb[i3]);
                       PaintBox2->Canvas->TextOutA(300,14+i3*14,ib2+5);
                       PaintBox2->Canvas->TextOutA(400,14+i3*14,prc);
                   }
                    if(bzcpb[i3]>100.0)
                    {

                       so[so1]=bzcpb[i3];
                        if(str6[isname]=="S37")
                        {
                            PaintBox2->Canvas->TextOutA(40,14+so1*14,btn);
                            PaintBox2->Canvas->TextOutA(80,14+so1*14,fnum-1);
                            PaintBox2->Canvas->TextOutA(140,14+so1*14,so1);
                            PaintBox2->Canvas->TextOutA(250,14+so1*14,so[so1]);
                            PaintBox2->Canvas->TextOutA(354,14+so1*14,a1[st[isname]][0]);
                            PaintBox2->Canvas->TextOutA(500,14+so1*14,a1[en[isname]][0]);
                        }
                       so1++;
                    }
                }  */
                int ib5=0;
                for(int i1=0;i1<5-1;i1++)
                {
                     ib1=0;
                    for(int i2=i1+1;i2<=5;i2++)
                    {
                       if((fabs(deep[i1]-deep[i2])<0.15)&&(deep[i1]>a1[st[isname]][0])&&(deep[i1]<a1[en[isname]][0])&&(deep[i2]>a1[st[isname]][0])&&(deep[i2]<a1[en[isname]][0]))
                       {                                       //0.15为最大值，不可改小
                          ib1++;
                          //if(ib1>=int((so1-1)/3))
                          if(ib1>ib5)
                          {
                             ib5=ib1;
                             sos=deep[i2];
                           /*  if(str6[isname]=="G120")
                             {
                                PaintBox2->Canvas->TextOutA(40,14+btn*80+so1*14,btn);
                                PaintBox2->Canvas->TextOutA(80,14+btn*80+so1*14,fnum-1);
                                PaintBox2->Canvas->TextOutA(140,14+btn*80+so1*14,so1);
                                PaintBox2->Canvas->TextOutA(250,14+btn*80+so1*14,sos);
                             }  */
                          }
                       }
                    }
                }
             // }
             if(sos>100.0) //&&(btn==(fnum-1))
             {
                  CDeep[isname]=sos;
                  mbdeep[isname]=sos;
                           /*  if(str6[isname]=="S37")
                             {
                                PaintBox2->Canvas->TextOutA(40,14+so1*14,btn);
                                PaintBox2->Canvas->TextOutA(80,14+so1*14,fnum-1);
                                PaintBox2->Canvas->TextOutA(140,14+so1*14,so1);
                                PaintBox2->Canvas->TextOutA(250,14+so1*14,sos);
                             }  */
             }
                       /* if(str6[isname]=="P27a")
                        {
                            PaintBox2->Canvas->TextOutA(100,240+so1*14,ib1);
                            PaintBox2->Canvas->TextOutA(120,240+so1*14,prc);
                            PaintBox2->Canvas->TextOutA(180,240+so1*14,sos);
                            PaintBox2->Canvas->TextOutA(280,240+so1*14,mbdeep[isname]);
                        }  */

     /*    {

            float deeplast[500];
            for(int i1=1;i1<=4;i1++)
            {

               for(int i2=i1+1;i2<=5;i2++)
               {
                //  if((op==0)&&(fabs(deep[i1]-deep[i2])<0.2)&&(deep[i1]>100.0)&&(deep[i2]>100.0)&&(deep[i1]>a1[st[isname]][0])&&(deep[i1]<a1[en[isname]][0])&&(deep[i2]>a1[st[isname]][0])&&(deep[i2]<a1[en[isname]][0]))
                 if((fabs(deep[i1]-deep[i2])<0.2)&&(deep[i1]>100.0)&&(deep[i2]>100.0)&&(deep[i1]>a1[st[isname]][0])&&(deep[i1]<a1[en[isname]][0])&&(deep[i2]>a1[st[isname]][0])&&(deep[i2]<a1[en[isname]][0]))
                  {
                     deeplast[op]=deep[i1];
                     jdcw[isname]=ip[i1];
                     op=op+1;
                    // op=1;
                     if(str6[isname]=="S37")
                     {
                        // PaintBox2->Canvas->TextOutA(50+i1*100,14+btn*14,"                    ");
                         PaintBox2->Canvas->TextOutA(50+i1*100,14+btn*14,"S11 ");
                         PaintBox2->Canvas->TextOutA(150+i1*100,14+btn*14,deep[i1]);
                         PaintBox2->Canvas->TextOutA(350+i1*100,14+btn*14,deeplast[op-1]);
                     }
                  }
               }
            }

            for(int i1=0;i1<op-1;i1++)
            {
               for(int i2=i1+1;i2<op;i2++)
               {
                   if((fabs(deeplast[i1]-deeplast[i2])<0.02)&&(deeplast[i1]>100.0)&&(deeplast[i2]>100.0))
                   {
                       op1=op1+1;
                       if(op1>=int(op/4))
                       {
                           CDeep[isname]=deeplast[i2];
                           mbdeep[isname]=deeplast[i2];

                       }
                   }
               }
            }
         }     */


                  /*   if(str6[isname]=="S37")
                     {
                        // PaintBox2->Canvas->TextOutA(50+i1*100,14+btn*14,"                    ");
                         PaintBox2->Canvas->TextOutA(50,14+btn*14,op1);
                         PaintBox2->Canvas->TextOutA(150,14+btn*14,CDeep[isname]);
                         PaintBox2->Canvas->TextOutA(350,14+btn*14,mbdeep[isname]);
                     }    */
              /* if(str6[isname]=="S11")
               {
                  mbjcjlc=mbdeep[JClj]-deeplast[i1];
               }
               else if(str6[isname]=="S37")
               {
                  mbjcjlc=deeplast[i1]-mbdeep[JClj];
               }
               else if(str6[isname]=="P27a")
               {
                  mbjcjlc=deeplast[i1]-mbdeep[S37lj];
               }
               else if(str6[isname]=="G110b")
               {
                  mbjcjlc=deeplast[i1]-mbdeep[P27alj];
               }
               else if(str6[isname]=="G120")
               {
                  mbjcjlc=deeplast[i1]-mbdeep[G110blj];
               }   */
                  /*  if(str6[isname]=="S11")
                    {
                       PaintBox2->Canvas->TextOutA(50,314+btn*14,mbdeep[isname]);
                       PaintBox2->Canvas->TextOutA(50+104,314+btn*14,CDeep[isname]);
                       PaintBox2->Canvas->TextOutA(150+104,314+btn*14,Rlast);
                       PaintBox2->Canvas->TextOutA(250+104,314+btn*14,fabs(ckjcjlc[isname]-mbjcjlc));
                       PaintBox2->Canvas->TextOutA(350+104,314+btn*14,deeplast[i1]);
                    }   */
              // if((fabs(ckja2[isname]-deeplast[i1])<=RSE)&&(deeplast[i1]>a1[st[isname]][0])&&(deeplast[i1]<a1[en[isname]][0]))
              // if((fabs(a2[isname][0]-deeplast[i1])<=RSE)&&(deeplast[i1]>a1[st[isname]][0])&&(deeplast[i1]<a1[en[isname]][0]))
              /* if((fabs(ckjcjlc[isname]-mbjcjlc)<=RSE+0.02)&&(deeplast[i1]>a1[st[isname]][0])&&(deeplast[i1]<a1[en[isname]][0]))
               {
                 // RSE=fabs(a2[isname][0]-deeplast[i1]);
                  RSE=fabs(ckjcjlc[isname]-mbjcjlc);
                  Rlast=deeplast[i1];
                  CDeep[isname]=Rlast;
                  mbdeep[isname]=Rlast;
                     if(str6[isname]=="S11")
                    {
                       PaintBox2->Canvas->TextOutA(50,14+btn*14,mbdeep[isname]);
                       PaintBox2->Canvas->TextOutA(50+104,14+btn*14,CDeep[isname]);
                       PaintBox2->Canvas->TextOutA(150+104,14+btn*14,Rlast);
                       PaintBox2->Canvas->TextOutA(250+104,14+btn*14,fabs(ckjcjlc[isname]-mbjcjlc));
                       PaintBox2->Canvas->TextOutA(350+104,14+btn*14,deeplast[i1]);
                    }
               }  */
          //  }
          /*  if((deeplast<1.0)&&(deep[1]>100.0))
            {
              deeplast=deep[1];
              jdcw[isname]=ip[1];
            }  */
        //    if(Rlast>100.0)
         //   {
        //        CDeep[isname]=Rlast;
         //       mbdeep[isname]=Rlast;
        //    }
            //  PaintBox2->Canvas->TextOutA(150,314+btn*14,"                    ");
            //  PaintBox2->Canvas->TextOutA(150,314+btn*14,CDeep[isname]);
                  /*  if(str6[isname]=="S11")
                    {
                       PaintBox2->Canvas->TextOutA(150,314+btn*14,mbdeep[isname]);
                       PaintBox2->Canvas->TextOutA(150+104,314+btn*14,CDeep[isname]);
                        PaintBox2->Canvas->TextOutA(250+104,314+btn*14,Rlast);
                    }  */
}
//------------------------------------------------------------------------------------
void __fastcall TForm1::xzcorrect(TObject *Sender)    //修正 2025-2-4日增加
{
   dz1=9999999.0;dz2=99999999.0;dz3=999999.9;dz4=9999999.9;dz5=99999999.0;
  /* PaintBox2->Canvas->TextOutA(20,84,"isname=");
   PaintBox2->Canvas->TextOutA(20+54,84+isname*14,isname);
   PaintBox2->Canvas->TextOutA(20,104,"str16[isname]=");
   PaintBox2->Canvas->TextOutA(20+54,104+isname*14,str16[isname]);   */
   n=6;int i01=0,it;//open_switch=1;
   FILE *fp; int i2=n+1;ie1=0;AnsiString Dir;
   if(xzkg==1)
   {          // xzkg;  //选择开关
       Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\小层数据库\\"+str16[isname]+"\\";
   }
   else if(xzkg==2)
   {
      Dir="D:\\二厂统层对比有形化平台\\测井数据及分层数据库\\沉积单元数据库\\"+str16[isname]+"\\";
   }
   TSearchRec sr;
   TStringList *FileList = new TStringList();


   ccp2.SetLength(ccp2.Length()-3);
   AnsiString filename = ccp2;                 //文件名
   ccp2.SetLength(ccp2.Length()+3);
   int count = filename.Length();              //文件名字符数
   AnsiString s1;
   AnsiString s2;
   AnsiString s4;
   AnsiString s6;
   AnsiString s9;

   char * filename1 = filename.c_str();
   for(int i = 0;i < count-1;i++)
   {
        s1 = s1 + filename1[i];
   }
   for(int i = 0;i < count-2;i++)
   {
        s2 = s2 + filename1[i];
   }
   for(int i = 0;i < count-4;i++)
   {
        s4 = s4 + filename1[i];
   }
   for(int i = 0;i < count-6;i++)
   {
        s6 = s6 + filename1[i];
   }
   for(int i = 0;i < 2;i++)
   {
        s9 = s9 + filename1[i];
   }

   AnsiString Dir00 = Dir + "n*.*" + '.';      //n开头文件
   AnsiString Dir1 = Dir + s1 + "*.*" + '.';   //前count-1个字符相同文件
   AnsiString Dir2 = Dir + s2 + "*.*" + '.';   //前count-2个字符相同文件
   AnsiString Dir4 = Dir + s4 + "*.*" + '.';   //前count-4个字符相同文件
   AnsiString Dir6 = Dir + s6 + "*.*" + '.';   //前count-6个字符相同文件
   AnsiString Dir99 = Dir + s9 + "*.*" + '.';   //前count-6个字符相同文件

   int same = 0;                               //重复文件名判断
   vector<AnsiString> temp;                    //操作数组
   vector<AnsiString> fil;                     //文件名序列数组
   vector<AnsiString> fil2;                    //文件名数组


   FindFirst(Dir1, faAnyFile, sr);             //前count-1个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir2, faAnyFile, sr);            //前count-2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir4, faAnyFile, sr);            //前count-4个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
////                                          //前count-6个字符相同文件加入FileList和fil数组
   FindFirst(Dir6, faAnyFile, sr);
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));
   FindFirst(Dir99, faAnyFile, sr);            //前2个字符相同文件加入FileList和fil数组
   do{
      FileList->Add(Dir + sr.Name);
      temp.push_back(Dir + sr.Name) ;
      fil.push_back(Dir + sr.Name);
      fil2.push_back(sr.Name);
      }while((FindNext(sr) == 0));

////                                           ////n开头文件加入FileList和fil数组
     FileList->Clear();
     fil.clear();
     fil2.clear();
     String temp2[2000];
     int checked = 0;
     int checked2 = 0;


////                                           ////剔除重复
     for(int i = 0;i < temp.size();i ++)
     {
        //String TempWell0 = temp[i];
        for(int j = 0;j < 2000;j ++)
        {
                if(temp2[checked] == temp2[j] && checked > 0)
                        break;
                checked2 = 0;
                for(int k = 0;k < i;k ++)
                {
                        if(temp[k] == temp[i])
                                checked2 = 1;
                }
                if(checked2 != 0)
                        break;
                else
                {
                        temp2[checked] = temp[i];
                        FileList->Add(temp2[checked]);
                        fil.push_back(temp2[checked]);
                        fil2.push_back(ExtractFileName(temp2[checked]));
                        checked ++;
                        break;
                }
        }

     }

   temp.clear();
   FileList->Count;                           //文件名列表计数
   AnsiString o1 = FileList->Text;
   FileList->SaveToFile("D:\\001.txt");     //输出文件名到txt

   string fname[20];                         //文件路径数组
   string fn[20];                         //文件名数组
   int file_count = 0;
   for(int i = 0;i < 20;i ++)                //前20个文件
   {

        fname[i] = fil[i].c_str();
                 //   PaintBox2->Canvas->TextOutA(70,440+i*14,"name=");
                 //   PaintBox2->Canvas->TextOutA(70+54,440+i*14,fil[i].c_str());
        fn[i] = fil2[i].c_str();
        file_count ++;
        if(file_count == fil.size())
        break;
      
   }
float relvc,dp2=0.0;
int num = 0;
    xzc=1;
   // lj=isname;
if (file_count >3)
{
do{
      if (num == file_count)
      break;
      //FileList->Add(Dir + sr.Name);
     // PaintBox2->Canvas->TextOut(120,2+(i01+1)*14,fn[num].c_str());
       btn=num;

    //  if((CDeep[isname]<10.0)&&(open_correct==0)&&(isname<=2))
      {
        fp=fopen(fname[num].c_str(),"r");
        if(fp)
        {
           ie1=0; i01=i01+1;  //计算打开非零文件个数
           fscanf(fp,"%f %f %f %f %d",&start2[isname],&end2[isname],&ckja2[isname],&relvc,&totalnumb[isname]);
            /*  if(str6[isname]=="S11")
              {
                PaintBox2->Canvas->TextOutA(btn*120+60,214,start2[isname]);
                PaintBox2->Canvas->TextOutA(btn*120+60,234,end2[isname]);
                PaintBox2->Canvas->TextOutA(btn*120+60,254,ckja2[isname]);
                PaintBox2->Canvas->TextOutA(btn*120+60,274,totalnumb[isname]);
                PaintBox2->Canvas->TextOutA(btn*120+60,294,str6[isname]);
              }         */
           chcsh2[isname]=totalnumb[isname];
           stpinsjk[isname]=int((ckja2[isname]-start2[isname])/relvc);                  //数据库节点
           prc=5;
           while(feof(fp)==0)
           {
                for(int j=0;j<i2;j++)
                {
                        fscanf(fp,"%f",&xcsj[ie1][j]);
                        xcsj[ie1][j]=StrToFloat(FormatFloat("0.00",xcsj[ie1][j]));
                        //bzcsj[ie1][j]=xcsj[ie1][j];
                }
                Rmn[ie1]=xcsj[ie1][prc];
                ie1++;
           }
           if(isname==0)
           {
               st[isname]=jdcw[JClj]-int(ckjcjlc[isname]/relvc)-int(wincu1/relvc);    //-stpinsjk[isname]
               en[isname]=jdcw[JClj]-int(ckjcjlc[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjmkz[itz]/relvc);

           }
           else
           {
               st[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)-int((ckja2[isname]-start2[isname])/relvc)-int(cjjmkz[itz]/relvc); //-stpinsjk[isname]
               en[isname]=ckjjd[isname]+int(ckjcjlc[isname]/relvc)+int((end2[isname]-ckja2[isname])/relvc)+int(cjjmkz[itz]/relvc);
           }


           AICcorrect(Sender);
           /* if(str6[isname]=="S11")
              {
                PaintBox2->Canvas->TextOutA(btn*150+60,414,"jdcw=");
                PaintBox2->Canvas->TextOutA(btn*150+60+64,414,a1[jdcw[JClj]][0]);
                PaintBox2->Canvas->TextOutA(btn*150+60,434,"ckjcjlc=");
                PaintBox2->Canvas->TextOutA(btn*150+60+64,434,ckjcjlc[isname]);
                PaintBox2->Canvas->TextOutA(btn*150+60,454,"cjjmkz ");
                PaintBox2->Canvas->TextOutA(btn*150+60+84,454,cjjmkz[itz]);
                 PaintBox2->Canvas->TextOutA(btn*150+70,474,"st");
                PaintBox2->Canvas->TextOutA(btn*150+60+34,474,a1[st[isname]][0]);
                PaintBox2->Canvas->TextOutA(btn*150+60+54,494,end2[isname]-ckja2[isname]);
              //  PaintBox2->Canvas->TextOutA(btn*150+60+54,514,cjjmkz[itz]);
                 PaintBox2->Canvas->TextOutA(btn*150+60,534,"CDeep ");
                PaintBox2->Canvas->TextOutA(btn*150+60+54,534,CDeep[isname]);
                PaintBox2->Canvas->TextOutA(btn*150+60+64,554,a1[en[isname]][0]);
                PaintBox2->Canvas->TextOutA(btn*150+60,554,"en=");
                PaintBox2->Canvas->TextOutA(btn*150+60,574,ckja2[isname]);
               // PaintBox2->Canvas->TextOutA(btn*150+60+64,574,a1[st[isname]][0]);
                PaintBox2->Canvas->TextOutA(btn*150+60+64,594,end2[isname]);
              }   */
            /*  if(str6[isname]=="S11")
              {
                 PaintBox2->Canvas->TextOutA(i01*120,33+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(i01*120,53+prc*60,CDeep[isname]);
                 PaintBox2->Canvas->TextOutA(i01*120,73+prc*60,ckjcjlc[isname]);
                 PaintBox2->Canvas->TextOutA(i01*120,93+prc*60,CDeep[isname]-mbjdcjx[isname]);
                 PaintBox2->Canvas->TextOutA(i01*120,113+prc*60,cjjmkz[itz]);
                 PaintBox2->Canvas->TextOutA(i01*120,133+prc*60,mbjdcjx[isname]);

              }    */
              float lc=0;

            if(isname==0)
            {
               lc=mbjdcjx[isname]-CDeep[isname];
            }
            else
            {
               lc=CDeep[isname]-mbjdcjx[isname];
            }

               if((fabs(ckjcjlc[isname]-lc)>cjjmkz[itz])&&(open_correct==1)||(S11lj>JClj))  //校正开关    //层间距门槛值
               {
                 prc=1;
                 for(int io=0;io<ie1;io++)
                 {
                     Rmn[io]=xcsj[io][prc];
                 }
                 AICcorrect(Sender);
           /* if(str6[isname]=="S11")
              {
                 PaintBox2->Canvas->TextOutA(i01*120,93+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(i01*120,113+prc*60,CDeep[isname]);
              }   */
           if(isname==0)
            {
               lc=mbjdcjx[isname]-CDeep[isname];
            }
            else
            {
               lc=CDeep[isname]-mbjdcjx[isname];
            }

                    if((fabs(ckjcjlc[isname]-lc)>cjjmkz[itz])&&(open_correct==1)||(S11lj>JClj))  //校正开关    //层间距门槛值
                    {
                     prc=2;
                     for(int io=0;io<ie1;io++)
                     {
                        Rmn[io]=xcsj[io][prc];
                     }

                     AICcorrect(Sender);
           /*   if(str6[isname]=="S11")
              {
                 PaintBox2->Canvas->TextOutA(i01*120,153+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(i01*120,173+prc*60,CDeep[isname]);
              }  */
               if(isname==0)
               {
                   lc=mbjdcjx[isname]-CDeep[isname];
               }
               else
               {
                  lc=CDeep[isname]-mbjdcjx[isname];
               }

                       if((fabs(ckjcjlc[isname]-lc)>cjjmkz[itz])&&(open_correct==1)||(S11lj>JClj))  //校正开关    //层间距门槛值
                        {
                            prc=4;
                            for(int io=0;io<ie1;io++)
                            {
                                 Rmn[io]=xcsj[io][prc];
                            }

                            AICcorrect(Sender);
            /*  if(str6[isname]=="S11")
              {
                 PaintBox2->Canvas->TextOutA(i01*120,213+prc*60,prc);
                 PaintBox2->Canvas->TextOutA(i01*120,233+prc*60,CDeep[isname]);
              }  */
               if(isname==0)
               {
                   lc=mbjdcjx[isname]-CDeep[isname];
               }
               else
               {
                  lc=CDeep[isname]-mbjdcjx[isname];
               }

                            if((fabs(ckjcjlc[isname]-lc)<cjjmkz[itz])&&(CDeep[isname]>100.0)&&(open_correct==1))
                            {
                              open_correct=3;  //校正开关
                              dp2=CDeep[isname];
                             /* if(str6[isname]=="S11")
                              {
                                  PaintBox2->Canvas->TextOutA(i01*120,113+prc*60,prc);
                                  PaintBox2->Canvas->TextOutA(i01*120,133+prc*60,CDeep[isname]);
                              }  */
                            }
                        }
                        else if((fabs(ckjcjlc[isname]-lc)<cjjmkz[itz])&&(CDeep[isname]>100.0)&&(open_correct==1))
                        {
                            open_correct=3;  //校正开关
                            dp2=CDeep[isname];
                           /* if(str6[isname]=="S11")
                              {
                                  PaintBox2->Canvas->TextOutA(i01*120,113+prc*60,prc);
                                  PaintBox2->Canvas->TextOutA(i01*120,133+prc*60,CDeep[isname]);
                              } */
                        }
                     if(S11lj>JClj)
                     {
                        open_correct=1;
                     }
                 }
                 else if((fabs(ckjcjlc[isname]-lc)<cjjmkz[itz])&&(CDeep[isname]>100.0)&&(open_correct==1))
                 {
                     open_correct=3;  //校正开关
                     dp2=CDeep[isname];
                           /*   if(str6[isname]=="S11")
                              {
                                  PaintBox2->Canvas->TextOutA(i01*120,113+prc*60,prc);
                                  PaintBox2->Canvas->TextOutA(i01*120,133+prc*60,CDeep[isname]);
                              }  */
                 }
            }
            else if((fabs(ckjcjlc[isname]-lc)<cjjmkz[itz])&&(CDeep[isname]>100.0)&&(open_correct==1))
            {
               open_correct=3;  //校正开关
               dp2=CDeep[isname];
                           /*  if(str6[isname]=="S11")
                              {
                                  PaintBox2->Canvas->TextOutA(i01*120,113+prc*60,prc);
                                  PaintBox2->Canvas->TextOutA(i01*120,133+prc*60,CDeep[isname]);
                              }   */
            }
        }

      }
      fclose(fp);
      num ++;

     }while((i01 < 5)&&(open_correct<2));    //while((i01 < 20));   2023-08-13  改为循环5口井

    FindClose(sr);

    open_correct2=3;

   }
   CDeep[isname]=dp2;
 /*  if(str6[isname]=="S11")
   {
       PaintBox2->Canvas->TextOutA(120,113,str6[isname]);
       PaintBox2->Canvas->TextOutA(120,133,CDeep[isname]);
   }  */
}
//--------------------------------------------------------------------

void __fastcall TForm1::PaintBox5Click(TObject *Sender)
{
 //  xc_switch=8;

   PaintBox5->Canvas->Font->Height=60;
   PaintBox5->Canvas->Font->Color=RGB(210,20,20);
   PaintBox5->Canvas->TextOutA(50,30," 处理完毕! 请核查以下层界面：    ");
   if(dc>0)
   {
      PaintBox5->Canvas->TextOutA(220,90,"              可能断失");
      PaintBox5->Canvas->TextOutA(240,90,str6[dc]);
   }
   if(nn<=10)
   {
     for(int i0=0;i0<nn;i0++)
     {
         PaintBox5->Canvas->TextOutA(50,100+i0*50,"                                  ");
         PaintBox5->Canvas->TextOutA(50,100+i0*50,pbcw[i0]);
     }
   }
   else
   {
      for(int i0=0;i0<=10;i0++)
      {
          PaintBox5->Canvas->TextOutA(50,100+i0*50,pbcw[i0]);
      }
      for(int i0=11;i0<=20;i0++)
      {
          PaintBox5->Canvas->TextOutA(250,100+(i0-10)*50,pbcw[i0]);
      }
      for(int i0=21;i0<=nn;i0++)
      {
          PaintBox5->Canvas->TextOutA(450,100+(i0-20)*50,pbcw[i0]);
      }
   }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox5Paint(TObject *Sender)
{
 // if(xc_switch==8)
  {

   //  PaintBox5Click(Sender);
  }
  paintfencengnewDice(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AICcorrect(TObject *Sender)       //智能计算校正
{
      float deep[10],mxz=999999.0; //门限值
     // zdz1=9999999.0; zdz2=9999999.0;zdz3=9999999.0; zdz4=9999999.0;zdz5=9999999.0;
              stpin=stpinsjk[isname];    //节点输入
              int ip[10];
                 /*  if(str6[isname]=="S37")
                    {
                       PaintBox2->Canvas->TextOutA(50,314+btn*14,"st-2=");
                       PaintBox2->Canvas->TextOutA(50+54,314+btn*14,a1[st[isname]][0]);
                      // PaintBox2->Canvas->TextOutA(170+54,314+btn*14,st[isname]);
                       PaintBox2->Canvas->TextOutA(250,314+btn*14,"en-2=");
                       PaintBox2->Canvas->TextOutA(250+54,314+btn*14,a1[en[isname]][0]);
                     //  PaintBox2->Canvas->TextOutA(370+54,314+btn*14,en[isname]);
                    }  */
              // if(str6[lj]==StdCw)
                 {

                    ljcw0=isname;
                    Dice(Sender);
                  /*   PaintBox2->Canvas->TextOutA(50,14+btn*14,"ie1=");
                     PaintBox2->Canvas->TextOutA(50+54,14+btn*14,ie1);
                     PaintBox2->Canvas->TextOutA(250,14+btn*14,"btn=");
                     PaintBox2->Canvas->TextOutA(250+54,14+btn*14,btn);
                     PaintBox2->Canvas->TextOutA(450,14+btn*14,"totalnumb[isname]=");     // +btn*14
                     PaintBox2->Canvas->TextOutA(450+94,14+btn*14,totalnumb[isname]);  */
                    for(int i1=st[isname];i1<en[isname];i1++)
                    {

                      ie2=0;
                      if((a1[i1+chcsh2[isname]][MN1_pos]>0.85)&&(a1[i1+chcsh2[isname]][Rxo1_pos]>0.85))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[isname];
                       // itz=i1;//检测用
                          for(int i0=i1;i0<stp1;i0++)
                          {
                                Tmbjsj2[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                                Tmbjsj2[ie2][0]=a1[i0][0];
                                Tmbjsj2[ie2][2]=a1[i0][Rd1_pos];
                                Tmbjsj2[ie2][3]=a1[i0][DEN1_pos];
                                Tmbjsj2[ie2][4]=a1[i0][HAC1_pos];
                                Tmbjsj2[ie2][5]=a1[i0][Rxo1_pos];
                                Tmbjsj2[ie2][6]=a1[i0][GR1_pos];
                                if(Tmbjsj2[ie2][1]<1.0)
                                {
                                   Tmbj=0;
                                }
                                Rmn1[ie2]=Tmbjsj2[ie2][prc];
                                ie2++;
                          }
                         /* PaintBox2->Canvas->TextOutA(150,14+btn*14,"ie2=");     // +btn*14
                          PaintBox2->Canvas->TextOutA(150+54,14+btn*14,ie2);  */      // +btn*14
                        Filter(Tmbjsj2,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);
                      /*  PaintBox2->Canvas->TextOutA(50,14+i1*14,"ie1=");
                       PaintBox2->Canvas->TextOutA(50+54,14+i1*14,ie1);
                        PaintBox2->Canvas->TextOutA(150,14+i1*14,"ie2=");
                       PaintBox2->Canvas->TextOutA(150+54,14+i1*14,ie2);   */
                        //(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice2(Sender);
                        }
                        if(v[1]<dz1)
                        {
                           dz1=v[1];
                           deep[1]=a1[stp][0];
                           ip[1]=stp;
                        }
                        if(v[2]<dz2)
                        {
                           dz2=v[2];
                           deep[2]=a1[stp][0];
                           ip[2]=stp;
                        }
                        if(v[3]<dz3)
                        {
                           dz3=v[3];
                           deep[3]=a1[stp][0];
                           ip[3]=stp;
                        }
                        if(v[4]<dz4)
                        {
                           dz4=v[4];
                           deep[4]=a1[stp][0];
                           ip[4]=stp;
                        }
                        if(v[5]<dz5)
                        {
                           dz5=v[5];
                           deep[5]=a1[stp][0];
                           ip[5]=stp;
                        }
                       }
                     }

                   }
            /*      int op=0;
                 for(int iu=1;iu<=5;iu++)
                 {
                   if(str6[isname]=="S11")
                    {

                        if(fabs(ckjcjlc[isname]-(mbjdcjx[isname]-deep[iu]))<mxz)
                        {
                            mxz=fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]));
                            CDeep[isname]=deep[iu];
                            jdcw[isname]=ip[iu];
                            op=1;
                        }
                    }
                    else
                    {

                        if(fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]))<mxz)
                        {
                            mxz=fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]));
                            CDeep[isname]=deep[iu];
                            jdcw[isname]=ip[iu];
                            op=1;
                        }
                    }
                 }
                 if(op==0)
                 {
                    CDeep[isname]=deep[1];
                    jdcw[isname]=ip[1];
                 }     */
                /*  if(str6[isname]=="G120")
                  {
                       PaintBox2->Canvas->TextOutA(50,14+1*14,"deep1=");
                       PaintBox2->Canvas->TextOutA(50+54,14+1*14,deep[1]);
                        PaintBox2->Canvas->TextOutA(50,14+2*14,"deep2=");
                       PaintBox2->Canvas->TextOutA(50+54,14+2*14,deep[2]);
                       PaintBox2->Canvas->TextOutA(50,14+3*14,"deep3=");
                       PaintBox2->Canvas->TextOutA(50+54,14+3*14,deep[3]);
                       PaintBox2->Canvas->TextOutA(50,14+4*14,"deep4=");
                       PaintBox2->Canvas->TextOutA(50+54,14+4*14,deep[4]);
                       PaintBox2->Canvas->TextOutA(50,14+5*14,"deep5=");
                       PaintBox2->Canvas->TextOutA(50+54,14+5*14,deep[5]);
                  }     */
              for(int i1=1;i1<6;i1++)
              {
                 if(fabs(ckdeep[lj]-deep[i1])<selectbzcdp)
                 {
                     selectbzcdp=fabs(ckdeep[lj]-deep[i1]);         //  2025年6月6号
                     selectbzcdeep=deep[i1];
                 }

              }
              CDeep[lj]=selectbzcdeep;
              if((fabs(deep[1]-deep[2])<0.02)&&(fabs(deep[1]-deep[3])<0.02))
              {
                 CDeep[lj]=deep[1];
              }



          /*  float deeplast=0.0;
            for(int i1=1;i1<=4;i1++)
            {
               for(int i2=i1+1;i2<=5;i2++)
               {
                  if(fabs(deep[i1]-deep[i2])<0.2)
                  {
                     deeplast=deep[i1];
                     jdcw[lj]=ip[i1];
                  }
               }
            }
            if(deeplast<1.0)
            {
              deeplast=deep[1];
              jdcw[lj]=ip[1];
            }
            CDeep[lj]=deeplast;  */
                  /*  if(str6[isname]=="P27a")
                    {
                       PaintBox2->Canvas->TextOutA(450,314+btn*14,"P27aCDeep[isname]=");
                       PaintBox2->Canvas->TextOutA(450+104,314+btn*14,CDeep[isname]);
                    } */
}
//------------------------------------------------------------------------------------
void __fastcall TForm1::AICXFCcorrect(TObject *Sender)       //智能计算细分层校正
{
    /*  float zdz2,zdz3,zdz4,zdz5,,mxz=999999.0; //门限值
      float Rm1=99999.0,Rmnselect=0.0,selectxfcdp2=9999999.0,selectxfcdeep2=0.0;
      zdz=9999999.0; zdz2=9999999.0;zdz3=9999999.0; zdz4=9999999.0;zdz5=9999999.0; */
             float deep[10];
              stpin=stpinsjk[isname];    //节点输入
              int ip[10];
                  /* if(str6[isname]=="P27a")
                    {
                       PaintBox2->Canvas->TextOutA(50,314+btn*14,"st-2=");
                       PaintBox2->Canvas->TextOutA(50+54,314+btn*14,a1[st[isname]][0]);
                       PaintBox2->Canvas->TextOutA(170+54,314+btn*14,st[isname]);
                       PaintBox2->Canvas->TextOutA(250,314+btn*14,"en-2=");
                       PaintBox2->Canvas->TextOutA(250+54,314+btn*14,a1[en[isname]][0]);
                       PaintBox2->Canvas->TextOutA(370+54,314+btn*14,en[isname]);
                    }  */
              // if(str6[lj]==StdCw)
                 {

                    ljcw0=isname;
                    Dice(Sender);
                  /*   PaintBox2->Canvas->TextOutA(50,14+btn*14,"ie1=");
                     PaintBox2->Canvas->TextOutA(50+54,14+btn*14,ie1);
                     PaintBox2->Canvas->TextOutA(250,14+btn*14,"btn=");
                     PaintBox2->Canvas->TextOutA(250+54,14+btn*14,btn);
                     PaintBox2->Canvas->TextOutA(450,14+btn*14,"totalnumb[isname]=");     // +btn*14
                     PaintBox2->Canvas->TextOutA(450+94,14+btn*14,totalnumb[isname]);  */
                    for(int i1=st[isname];i1<en[isname];i1++)
                    {

                      ie2=0;
                      if((a1[i1+chcsh2[isname]][MN1_pos]>0.85)&&(a1[i1+chcsh2[isname]][Rxo1_pos]>0.85))  ////窗长数 判断尾部直线
                      {

                        stp=i1+stpin;

                        stp1=i1+totalnumb[isname];
                       // itz=i1;//检测用
                          for(int i0=i1;i0<stp1;i0++)
                          {
                                Tmbjsj2[ie2][1]=a1[i0][MN1_pos];      //目标井数据
                                Tmbjsj2[ie2][0]=a1[i0][0];
                                Tmbjsj2[ie2][2]=a1[i0][Rd1_pos];
                                Tmbjsj2[ie2][3]=a1[i0][DEN1_pos];
                                Tmbjsj2[ie2][4]=a1[i0][HAC1_pos];
                                Tmbjsj2[ie2][5]=a1[i0][Rxo1_pos];
                                Tmbjsj2[ie2][6]=a1[i0][GR1_pos];
                                if(Tmbjsj2[ie2][1]<1.0)
                                {
                                   Tmbj=0;
                                }
                                Rmn1[ie2]=Tmbjsj2[ie2][prc];
                                ie2++;
                          }
                         /* PaintBox2->Canvas->TextOutA(150,14+btn*14,"ie2=");     // +btn*14
                          PaintBox2->Canvas->TextOutA(150+54,14+btn*14,ie2);  */      // +btn*14
                        Filter(Tmbjsj2,ie2,Rmn1);               //滤波
                        Dsmaxmin1(Rmn1,RMNmax1,RMNmin1);
                      /*  PaintBox2->Canvas->TextOutA(50,14+i1*14,"ie1=");
                       PaintBox2->Canvas->TextOutA(50+54,14+i1*14,ie1);
                        PaintBox2->Canvas->TextOutA(150,14+i1*14,"ie2=");
                       PaintBox2->Canvas->TextOutA(150+54,14+i1*14,ie2);   */
                        //(ie2==ie1)  //老井平均与新井平均    注意门槛值   &&(fabs(ljpj-xjpj)<50.0)
                        {
                            Tice2(Sender);
                        }
                        if(v[1]<zdz)
                        {
                           zdz=v[1];
                           deep[1]=a1[stp][0];
                           ip[1]=stp;
                           if(fabs(ckdeep[lj]-deep[1])<selectxfcdp2)
                           {
                               selectxfcdp2=fabs(ckdeep[lj]-deep[1]);
                               selectxfcdeep2=deep[1];
                           }
                           if(a1[stp][MN1_pos]<Rm1)
                           {
                                Rm1=a1[stp][MN1_pos];
                                Rmnselect=a1[stp][0];
                           }
                          /* if(str6[isname]=="S213")
                           {
                              PaintBox2->Canvas->TextOutA(50,314+14,"v[1]=");
                              PaintBox2->Canvas->TextOutA(50+54,314+14,v[1]);
                           } */
                        }
                        if(v[2]<zdz2)
                        {
                           zdz2=v[2];
                           deep[2]=a1[stp][0];
                           ip[2]=stp;
                           if(fabs(ckdeep[lj]-deep[2])<selectxfcdp2)
                           {
                               selectxfcdp2=fabs(ckdeep[lj]-deep[2]);
                               selectxfcdeep2=deep[2];
                           }
                           if(a1[stp][MN1_pos]<Rm1)
                           {
                                Rm1=a1[stp][MN1_pos];
                                Rmnselect=a1[stp][0];
                           }
                          /* if(str6[isname]=="S213")
                           {
                              PaintBox2->Canvas->TextOutA(50,314+34,"v[2]=");
                              PaintBox2->Canvas->TextOutA(50+54,34+314,v[2]);
                           }  */
                        }
                        if(v[3]<zdz3)
                        {
                           zdz3=v[3];
                           deep[3]=a1[stp][0];
                           ip[3]=stp;
                           if(fabs(ckdeep[lj]-deep[3])<selectxfcdp2)
                           {
                               selectxfcdp2=fabs(ckdeep[lj]-deep[3]);
                               selectxfcdeep2=deep[3];
                           }
                           if(a1[stp][MN1_pos]<Rm1)
                           {
                                Rm1=a1[stp][MN1_pos];
                                Rmnselect=a1[stp][0];
                           }
                         /*  if(str6[isname]=="S213")
                           {
                              PaintBox2->Canvas->TextOutA(50,314+54,"v[3]=");
                              PaintBox2->Canvas->TextOutA(50+54,54+314,v[3]);
                           }   */
                        }
                        if(v[4]<zdz4)
                        {
                           zdz4=v[4];
                           deep[4]=a1[stp][0];
                           ip[4]=stp;
                           if(fabs(ckdeep[lj]-deep[4])<selectxfcdp2)
                           {
                               selectxfcdp2=fabs(ckdeep[lj]-deep[4]);
                               selectxfcdeep2=deep[4];
                           }
                           if(a1[stp][MN1_pos]<Rm1)
                           {
                                Rm1=a1[stp][MN1_pos];
                                Rmnselect=a1[stp][0];
                           }
                         /*  if(str6[isname]=="S213")
                           {
                              PaintBox2->Canvas->TextOutA(50,314+74,"v[4]=");
                              PaintBox2->Canvas->TextOutA(50+54,74+314,v[4]);
                           }  */
                        }
                        if(v[5]<zdz5)
                        {
                           zdz5=v[5];
                           deep[5]=a1[stp][0];
                           ip[5]=stp;
                           if(fabs(ckdeep[lj]-deep[5])<selectxfcdp2)
                           {
                               selectxfcdp2=fabs(ckdeep[lj]-deep[5]);
                               selectxfcdeep2=deep[5];
                           }
                           if(a1[stp][MN1_pos]<Rm1)
                           {
                                Rm1=a1[stp][MN1_pos];
                                Rmnselect=a1[stp][0];
                           }
                         /*  if(str6[isname]=="S213")
                           {
                              PaintBox2->Canvas->TextOutA(50,314+94,"v[5]=");
                              PaintBox2->Canvas->TextOutA(50+54,94+314,v[5]);
                           }   */
                        }
                       }
                     }

                   }

                  float sd2=9999.0,sd1;
            deep[6]=Rmnselect;
            for(int i1=1;i1<7;i1++)
            {
            /*  if(str6[lj]=="S24a")
              {
                 PaintBox2->Canvas->TextOutA(50+44,(i1+1)*20+184,Rmnselect);
                 PaintBox2->Canvas->TextOutA(150+84,(i1+1)*20+184,deepp[i1]);
              }   */
             /*  if(fabs(ckdeep[lj]-deepp[i1])<selectxfcdp)
                 {
                     selectxfcdp=fabs(ckdeep[lj]-deepp[i1]);
                     selectxfcdeep=deepp[i1];
                 }  */
                sd1=fabs((ckdeep[lj]-ckdeep[lj-1])-(deep[i1]-mbdeep[lj-1]));
                if(sd1<sd2)
                {
                   sd2=sd1;
                   Rmnselect=deep[i1];
                }
            }
             if(fabs(fabs(ckdeep[lj]-ckdeep[lj-1])-fabs(Rmnselect-mbdeep[lj-1]))<fabs(fabs(ckdeep[lj]-ckdeep[lj-1])-fabs(selectxfcdeep-mbdeep[lj-1])))   //  2025-6-8
            // if(fabs(ckdeep[lj]-Rmnselect)<fabs(ckdeep[lj]-selectxfcdeep))
             {
                 CDeep[lj]=Rmnselect;
                 mbdeep[lj]=CDeep[lj];   // 2025-6-7
             }
             else
             {
                CDeep[lj]=selectxfcdeep;
                mbdeep[lj]=CDeep[lj];
             }




            /*      int op=0;
                 for(int iu=1;iu<=5;iu++)
                 {
                   if(str6[isname]=="S11")
                    {

                        if(fabs(ckjcjlc[isname]-(mbjdcjx[isname]-deep[iu]))<mxz)
                        {
                            mxz=fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]));
                            CDeep[isname]=deep[iu];
                            jdcw[isname]=ip[iu];
                            op=1;
                        }
                    }
                    else
                    {

                        if(fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]))<mxz)
                        {
                            mxz=fabs(ckjcjlc[isname]-(deep[iu]-mbjdcjx[isname]));
                            CDeep[isname]=deep[iu];
                            jdcw[isname]=ip[iu];
                            op=1;
                        }
                    }
                 }
                 if(op==0)
                 {
                    CDeep[isname]=deep[1];
                    jdcw[isname]=ip[1];
                 }     */
                 /* if(str6[isname]=="P27a")
                  {
                       PaintBox2->Canvas->TextOutA(50,14+1*14,"deep1=");
                       PaintBox2->Canvas->TextOutA(50+54,14+1*14,deep[1]);
                        PaintBox2->Canvas->TextOutA(50,14+2*14,"deep2=");
                       PaintBox2->Canvas->TextOutA(50+54,14+2*14,deep[2]);
                       PaintBox2->Canvas->TextOutA(50,14+3*14,"deep3=");
                       PaintBox2->Canvas->TextOutA(50+54,14+3*14,deep[3]);
                       PaintBox2->Canvas->TextOutA(50,14+4*14,"deep4=");
                       PaintBox2->Canvas->TextOutA(50+54,14+4*14,deep[4]);
                       PaintBox2->Canvas->TextOutA(50,14+5*14,"deep5=");
                       PaintBox2->Canvas->TextOutA(50+54,14+5*14,deep[5]);
                  }  */
         /*   float deeplast=0.0;
            for(int i1=1;i1<=4;i1++)
            {
               for(int i2=i1+1;i2<=5;i2++)
               {
                  if(fabs(deep[i1]-deep[i2])<0.2)
                  {
                     deeplast=deep[i1];
                     jdcw[lj]=ip[i1];
                  }
               }
            }
            if(deeplast<1.0)
            {
              deeplast=deep[1];
              jdcw[lj]=ip[1];
            }
            CDeep[lj]=deeplast;
                                     */
           // CDeep[lj]=Rmnselect;
            



                  /*  if(str6[isname]=="P27a")
                    {
                       PaintBox2->Canvas->TextOutA(450,314+btn*14,"P27aCDeep[isname]=");
                       PaintBox2->Canvas->TextOutA(450+104,314+btn*14,CDeep[isname]);
                    } */
}
//------------------------------------------------------------------------------------



