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

#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 "Unit2.h"
//#include "stdafx.h"
#include <cstring>
#include <algorithm>
#include <Dialogs.hpp>
#include "string.h"
#include "iostream.h"
#include "stdlib.h"
#include "ctype.h"
#include "conio.h"
#include "Unit2.h"
#include "Unit5.h"
#include "Unit3.h"



//

#include <Graphics.hpp>
#include <jpeg.hpp>
#include <windows.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//AnsiString la_Location[300] ;
//AnsiString la_Name[300];
//AnsiString dbf_Name[300];

int Mod = 0;
int ss = 0;
int Switch_js = 0;
int Switch_ss = 0;
int Switch_print = 0;
int print_fault[200][20];
int print_fault_B[200][20];
int print_line[200][40];

AnsiString change_name(AnsiString s);
AnsiString change_well_name(AnsiString s);



//AnsiString data_074[]
AnsiString Dynscxh[300];
AnsiString Yx[300];
AnsiString Elsyds[300];
AnsiString Elsyhd[300];
AnsiString Ylsyds[300];

void clean_data();


int lines[200][200];
AnsiString lines_text[200][100];
int lines_text_px[200][100];
//生成图片
Graphics::TBitmap* bmp=new Graphics::TBitmap;
TCanvas* canvas=new TCanvas;
//int space = -1700;      //
int space = 0;

//批量处理变量
AnsiString Main_Name;                    //中心井名称接口
AnsiString Other_Name[100];              //对比井名称数组接口
AnsiString OpenDB_Name;
int DB_Mod = 1;
AnsiString Auto_DBF_Loaction = "";
int ajs = 0;
AnsiString str20[60][500];                      //已读取井数；
AnsiString str21[60][500];
AnsiString str22[60][500];
AnsiString str23[60][500];
AnsiString wx[60][200];
AnsiString elsyhd[60][200];
AnsiString yxhd[60][200];

AnsiString daa074_auto_open_path;

AnsiString change_well_name6(AnsiString s);
AnsiString change_name6(AnsiString s);
int out_put_mod = 1;
AnsiString change_name_single(AnsiString s);
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm3::FormCreate(TObject *Sender)
{
  Name_Height=113;
  Switch=2;
  Form3->WindowState=wsMaximized;
  ScrollBox1->Top=0;
  ScrollBox1->Left=0;
  ScrollBox1->Height=Form3->Height-80;//stedp[js]+Name_Height+85;
  PaintBox2->Top=-ScrollBox1->VertScrollBar->Position;//ScrollBox1->Top;
  PaintBox2->Left=0;
  PaintBox2->Width=ScrollBox1->Width;
  PaintBox2->Canvas->Pen->Style=psSolid;
  PaintBox2->Canvas->Pen->Color=clGreen;
  PaintBox2->Canvas->Pen->Width=4;
  Form3->VertScrollBar->Visible=False;
  ScrollBox1->VertScrollBar->Visible=true;
  js=0;
  DBGrid1->Visible=false;
  jxdb=0;    //精细对比
  lpdq=0;   //拉平对齐
  for(int i1=0;i1<300;i1++)
  {
    totalnum[i1]=0;
  }
  totaldpnum=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm3::lthead(TObject *Sender)   //连通头文件
{
      for(j=0;j<js;j++)
    {
      PaintBox2->Canvas->Font->Color=clBlack;
      PaintBox2->Canvas->Pen->Style=psSolid;
      PaintBox2->Canvas->Pen->Color=clGreen;
      PaintBox2->Canvas->Pen->Width=2;
      PaintBox2->Canvas->MoveTo(dj*j+2,2);
      PaintBox2->Canvas->LineTo(dj*j+2,80);
      PaintBox2->Canvas->MoveTo(dj*j+2+150+trackwidth*2,80);
      PaintBox2->Canvas->LineTo(dj*j+2+150+trackwidth*2,2);
      PaintBox2->Canvas->LineTo(dj*j+2,2);
      PaintBox2->Canvas->Font->Size=36;
      PaintBox2->Canvas->TextOutA(dj*j-80+trackwidth,30/2,AnsiString(ccp[j+1]));    // "井名"+AnsiString(j+1)
      PaintBox2->Canvas->Font->Size=12;
      PaintBox2->Canvas->MoveTo(dj*j+2,2+80);
      PaintBox2->Canvas->LineTo(dj*j+2,Name_Height+80);
      PaintBox2->Canvas->LineTo(dj*j+2+150+trackwidth*2,Name_Height+80);
      PaintBox2->Canvas->LineTo(dj*j+2+150+trackwidth*2,2+80);
      PaintBox2->Canvas->LineTo(dj*j+2,2+80);
      PaintBox2->Canvas->MoveTo(dj*j+2+50+trackwidth,2+80);
      PaintBox2->Canvas->LineTo(dj*j+2+50+trackwidth,Name_Height+80);
      PaintBox2->Canvas->MoveTo(dj*j+2+50*2+trackwidth,2+80);
      PaintBox2->Canvas->LineTo(dj*j+2+50*2+trackwidth,Name_Height+80);
      PaintBox2->Canvas->MoveTo(dj*j+12+50+trackwidth,Name_Height/2-20+80);
      PaintBox2->Canvas->TextOutA(dj*j+10+50+trackwidth,Name_Height/2-20+80,"深度");
      PaintBox2->Canvas->Pen->Width=1;
      PaintBox2->Canvas->Pen->Style=psSolid;
      PaintBox2->Canvas->Pen->Color=clBlack;
      PaintBox2->Canvas->Font->Color=clBlack;
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5+50+trackwidth,Name_Height/3-15+80,"0");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5+50+trackwidth+trackwidth/2,Name_Height/3-15+80,"RMN");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5+50+trackwidth+trackwidth,Name_Height/3-15+80,"40");
      PaintBox2->Canvas->MoveTo(dj*j+2+trackwidth/3+50+trackwidth,Name_Height/3+80);
      PaintBox2->Canvas->LineTo(dj*j+2+trackwidth*1.2+50+(trackwidth)*(1)+trackwidth/3,Name_Height/3+80);
      PaintBox2->Canvas->Pen->Style=psDot;
      PaintBox2->Canvas->Pen->Color=clRed;
      PaintBox2->Canvas->Font->Color=clRed;
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5+50+trackwidth,Name_Height/3*2-15+80,"0");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5+50+trackwidth+trackwidth/2,Name_Height/3*2-15+80,"RML");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5+50+trackwidth+trackwidth,Name_Height/3*2-15+80,"40");
      PaintBox2->Canvas->MoveTo(dj*j+2+trackwidth/3+50+trackwidth,Name_Height/3*2+80);
      PaintBox2->Canvas->LineTo(dj*j+2+trackwidth*1.2+50+(trackwidth)*(1)+trackwidth/3,Name_Height/3*2+80);
      PaintBox2->Canvas->Pen->Style=psSolid;
      PaintBox2->Canvas->Pen->Color=clBlack;
      PaintBox2->Canvas->Font->Color=clBlack;
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5-50,Name_Height/3-15+80,"20");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5-50+trackwidth/2,Name_Height/3-15+80,"GR");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5-50+trackwidth,Name_Height/3-15+80,"150");
      PaintBox2->Canvas->MoveTo(dj*j+2+trackwidth/3-50,Name_Height/3+80);
      PaintBox2->Canvas->LineTo(dj*j+2+trackwidth*1.2-50+trackwidth/3,Name_Height/3+80);
      PaintBox2->Canvas->Pen->Style=psDot;
      PaintBox2->Canvas->Pen->Color=clRed;
      PaintBox2->Canvas->Font->Color=clRed;
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5-50,Name_Height/3*2-15+80,"-50");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5-50+trackwidth/2,Name_Height/3*2-15+80,"SP");
      PaintBox2->Canvas->TextOutA(dj*j+2+trackwidth/2.5-50+trackwidth,Name_Height/3*2-15+80,"50");
      PaintBox2->Canvas->MoveTo(dj*j+2+trackwidth/3-50,Name_Height/3*2+80);
      PaintBox2->Canvas->LineTo(dj*j+2+trackwidth*1.2-50+trackwidth/3,Name_Height/3*2+80);
      draw(temp_index,tracknum,a,stedp,stdp,relv,j+1);
     }
}
//----------------------------------------------------------------------------
void __fastcall TForm3::N4Click(TObject *Sender)
{
       Switch=1;
       tracknum=2;Name_Height=113;float relv1=0.05;
       trackwidth=Form3->Width/(tracknum*(4+1.5));
       dj=trackwidth/2+2+150+trackwidth*2;
       ScrollBox1->Width=Form3->Width-25;
       ScrollBox1->HorzScrollBar->Range=ScrollBox1->Width*js/3+200;
       ScrollBox1->Left=0;
       ScrollBox1->Top=0;
       ScrollBox1->Height=Form3->Height-80;
       ScrollBox1->VertScrollBar->Visible=true;
       Form3->VertScrollBar->Visible=false;
       PaintBox2->Top=-ScrollBox1->VertScrollBar->Position;
       PaintBox2->Width=(Form3->Width-5)/3*js-50;
       PaintBox2->Height=maxp1[js]+Name_Height+85+600;
    lthead(Sender);

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

void __fastcall TForm3::N2Click(TObject *Sender)    //打开LA文件
{
   short i1,i2;float f;
   js=js+1;
   ss++;
   Top_deep[js]=0.0;
   int flag,i3;
   Switch=1;
   FILE *fp;
   int Rd_valueGTzero=0;
   int RMN_valueGTzero=0;
   int AC_value=0;
     MN_pos[js]=0;
     MK_pos[js]=0;
     Rd_pos[js]=0;
     Rs_pos[js]=0;
     Ac_pos[js]=0;
     Rxo_pos[js]=0;
     GR_pos[js]=0;
     SP_pos[js]=0;
     DEN_pos[js]=0;

 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[js]=OpenDialog1->Files->Strings[I].c_str();
         ccp[js]=ExtractFileName(OpenDialog1->FileName);
         GetFileName(ccp[js]);
      // PaintBox2->Canvas->TextOutA(250,50,newname[js]);


         AnsiString la_location[30],la_name[30],dbf_name[30];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////  添加
         la_location[js] = OpenDialog1->FileName;
         la_name[js] = ccp[js];
         int length = la_name[js].Length();
         dbf_name[js] = la_name[js].SubString(1,length-2) ;
         dbf_name[js] += "dbf";

         length = la_location[js].Length();
         length = length - la_name[js].Length();
         AnsiString temp = la_location[js].SubString(1,length);
         la_location[js] = temp;

         la_Location[js] = la_location[js];
         la_Name[js] = la_name[js];
         dbf_Name[js] = dbf_name[js];
////////////////////////////////////////////////////////////////////////////////////////////////////////////////





       if(fp){
               fread(str0[js],84,1,fp);
               fread(str1[js],80,1,fp);
               i2=getint(fp);
               i1=getint(fp);
               fread(str[js],80,1,fp);
               //startdp
               stdp[js]=getfloat(fp);
               //endp
               endp[js]=getfloat(fp);
                //cyjj
               relv[js]=getfloat(fp);
               i1=getint(fp);
               i2=getint(fp);
               f=getfloat(fp);
               fread(str11[js],80,1,fp);
               fread(str3[js],148,1,fp);
               for(int i7=0;i7<5000;i7++)
               {
                   for(int j7=1;j7<41;j7++)
                   {
                       a[js][i7][j7]=1.0;
                   }
               }
               // i1=0+int(Top_deep[js]/relv[js]);
               i1=0;
               stedp[js]=int((endp[js]-stdp[js])/relv[js]);
               while(i1<stedp[js])
               {
                    for(int j=1;j<41;j++)
                    {
                        for(int i=i1;i<i1+62;i++)
                        {
                             a[js][i][j]=getfloat(fp);
                        }
                    }
                    i1=i1+62;
               }
             }
     }
 }
    for(int i=0;i<3;i++)
    {
           for(int j=0;j<4;j++)
             {
               temp_index[js][i][j]=-1;
             }
    }
    for(int i0=0;i0<stedp[js];i0++)
    {
         a[js][i0][0]=stdp[js]+i0*relv[js];

    }
  int i4,i,j,ip;
 cname3[js][0][5]="DEPT ";
 i4=1;
 for(i=0;i<80;i+=4)
 {
      i2=0;
      for(j=i;j<i+4;j++)
      {
          if(str[js][j]!=' ')i2++;
      }
      j=i;
      for(i3=0;i3<4;i3++)
      {
          str2[js][i3]=0;
      }
      for(i3=0;i3<i2;i3++)
      {
          str2[js][i3]=str[js][j];
          j++;
      }
      if((str2[js][0]!=' ')&&(str2[js][0]!='\0'))
      {
          cname3[js][i4][5]=str2[js];
          if(strcmp(str2[js],"RMN")==0||strcmp(str2[js],"MNOR")==0)
          {
              MN_pos[js]=i4;
              temp_index[js][0][0]=i4;
          }
          if(strcmp(str2[js],"RML")==0||strcmp(str2[js],"RMK")==0||strcmp(str2[js],"RMM")==0||strcmp(str2[js],"RMG")==0)
          {
               MK_pos[js]=i4;
               temp_index[js][1][0]=i4;
          }
         if(strcmp(str2[js],"RLLD")==0||strcmp(str2[js],"RL3D")==0||strcmp(str2[js],"LLD")==0)
         {
             Rd_pos[js]=i4;
             temp_index[js][0][1]=i4;
         }
         if(strcmp(str2[js],"RLLS")==0||strcmp(str2[js],"RL3S")==0||strcmp(str2[js],"LLS")==0)
         {
             Rs_pos[js]=i4;
             temp_index[js][1][1]=i4;
         }
         if(strcmp(str2[js],"AC")==0||strcmp(str2[js],"DT")==0)
         {
             Ac_pos[js]=i4;
             temp_index[js][0][3]=i4;
         }
         if(strcmp(str2[js],"MSFL")==0||strcmp(str2[js],"RXO")==0)
         {
             Rxo_pos[js]=i4;
             temp_index[js][2][1]=i4;
         }
         if(strcmp(str2[js],"GR")==0)
         {
             GR_pos[js]=i4;
             temp_index[js][0][2]=i4;
         }
         if(strcmp(str2[js],"SP")==0)
         {
             SP_pos[js]=i4;
             temp_index[js][1][2]=i4;
         }
         if(strcmp(str2[js],"DEN")==0)
         {
             DEN_pos[js]=i4;
             temp_index[js][1][3]=i4;
         }
        if(strcmp(str2[js],"HAC")==0)
         {
             HAC_pos[js]=i4;
             temp_index[js][2][3]=i4;
         }
         i4++;
     }
   }
    ip=i4;
    i4=i4-1;
    for(int i0=1;i0<(ip+1);i0++)
    {
          smaxmin(i0);
          ma[js][i0]=max;
          mi[js][i0]=min;
    }
     int po1;
     for(int j1=1;j1<=js;j1++)
     {
          maxp1[j1]=stedp[j1];
     }
     for(int j1=1;j1<=js-1;j1++)
     {
         for(int j2=j1+1;j2<=js;j2++)
         {
             if(maxp1[j1]>maxp1[j2])
             {
                po1=maxp1[j1];
                maxp1[j1]=maxp1[j2];
                maxp1[j2]=po1;
             }
          }
      }
      ScrollBox1->VertScrollBar->Range=maxp1[js]+1200;
      N4Click(Sender);
      PaintBox2->Height=maxp1[1]+113+85+1000;
      Form3->Caption= ccp[js]+"                                       采 油 二 厂 储 层 连 通 性 对 比 技 术";

      dkcwsjk(Sender);
      for(int i1=0;i1<totalnum[js]+1;i1++)
      {
          str5[js][i1]=jhw[js][i1].c_str();
          str6[js][i1]=jhw[js][i1].c_str();
          a2[js][i1][0]=xcw[js][i1];
      }
      paintfenceng(Sender);
      fclose(fp); // PaintBox2->Canvas->TextOutA(50,400,newname[js]);

      Form3->ScrollBox1->VertScrollBar->Position = 0;
      Form3->d1->Enabled = false;

}
//---------------------------------------------------------------------------
void __fastcall TForm3::dkcwsjk(TObject *Sender)  //打开层位数据库 （小层）
{
 FILE *fp;
 int i=0,j,i1,i2=0,i3,flag=0,n;AnsiString cc;
   fp=fopen(newname[js].c_str(),_T("r"));
   cc=newname[js].c_str();
  // ccp0=ExtractFileName(OpenDialog1->FileName);
  //  GetFileName1(ccp0);
  if(fp)
   {


////////////////////////////////////////////////////////////////////////////////////////////////////////////////添加
   
   Table1->DatabaseName = la_Location[js] ;
   Table1->TableName = dbf_Name[js];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////



   Table1->Open();
   DBGrid1->DataSource=DataSource1;

   Table1->Active=true;
   Table1->First();
   while(!Table1->Eof)
   {
       if(Table1->FieldByName("井号外")->Value.IsEmpty())
       {
           jhw[js][i]=NULL;
       }
       else
       {
           jhw[js][i]=Table1->FieldByName("井号外")->AsString;
       }
       xcw[js][i]=Table1->FieldByName("小层界限外")->Value; //读取分层数据信息
       dsw[js][i]=Table1->FieldByName("顶部深度外")->Value;
       hdw[js][i]=Table1->FieldByName("厚度外")->Value;
       dbsd[js][i]=Table1->FieldByName("顶部深度")->Value;
       syhd[js][i]=Table1->FieldByName("砂岩厚度")->Value;
       yxhdd[js][i]=Table1->FieldByName("有效厚度顶")->Value;
       yx[js][i]=Table1->FieldByName("有效")->Value;
       if(Table1->FieldByName("类别")->Value.IsEmpty())
       {
           lb[js][i]=NULL;
       }
       else
       {
           lb[js][i]=Table1->FieldByName("类别")->AsString;
       }
       jcs[js][i]=Table1->FieldByName("夹层数")->Value;
       jsxh[js][i]=Table1->FieldByName("解释序号")->Value;
       kxd[js][i]=Table1->FieldByName("孔隙度")->Value;
       if(Table1->FieldByName("渗透率特征")->Value.IsEmpty())
       {
            stltz[js][i]=NULL;
       }
       else
       {
            stltz[js][i]=Table1->FieldByName("渗透率特征")->AsString;
       }
       zstl[js][i]=Table1->FieldByName("自渗透率")->Value;
       zdcxs[js][i]=Table1->FieldByName("自地层系数")->Value;
       hsbhd[js][i]=Table1->FieldByName("含水饱和度")->Value;
       sfsbh[js][i]=Table1->FieldByName("束缚水饱和")->Value;
       if(Table1->FieldByName("水淹解释结")->Value.IsEmpty())
       {
            syjs[js][i]=NULL;
       }
       else
       {
            syjs[js][i]=Table1->FieldByName("水淹解释结")->AsString;
       }
       if(Table1->FieldByName("电测解释结")->Value.IsEmpty())
       {
            dcjs[js][i]=NULL;
       }
       else
       {
            dcjs[js][i]=Table1->FieldByName("电测解释结")->AsString;
       }
       if(Table1->FieldByName("射孔")->Value.IsEmpty())
       {
            sk[js][i]=NULL;
       }
       else
       {
            sk[js][i]=Table1->FieldByName("射孔")->AsString;
       }
       if(Table1->FieldByName("补孔")->Value.IsEmpty())
       {
            bk[js][i]=NULL;
       }
       else
       {
            bk[js][i]=Table1->FieldByName("补孔")->AsString;
       }
       i++;
       Table1->Next();
   }
       totalnum[js]=i-1;
    }
 //  }
 // }
  Table1->First();
  Table1->Close();
  fclose(fp);
}
//---------------------------------------------------------------------------
void __fastcall TForm3::paintfenceng(TObject *Sender)
{
    PaintBox2->Canvas->Pen->Width=1;
  PaintBox2->Canvas->Pen->Style=psSolid;
  PaintBox2->Canvas->Pen->Color=clBlack;
  int ii0=0;
  ljcs[jsi]=0;//老井层数
  float deep1;
  int tw;
  //tw=Form1->Width/2.2;
  tw=dj*(jsi-1)+2+trackwidth+50+trackwidth;
 for(int i0=0;i0<stedp[jsi];i0++)
 {
     deep1=stdp[jsi]+i0*relv[jsi];
     if(fabs(a2[jsi][ii0][0]-deep1)<0.001)
     {
          PaintBox2->Canvas->MoveTo(dj*(jsi-1)+4+0,i0+Name_Height+81);
          PaintBox2->Canvas->LineTo(tw+10+trackwidth/2,i0+Name_Height+81);
          PaintBox2->Canvas->TextOut(tw+30+4,i0-14+Name_Height+81,str6[jsi][ii0]);
          PaintBox2->Canvas->TextOut(tw+30+4,i0+3+Name_Height+81,AnsiString(FormatFloat("0.0",a2[jsi][ii0][0])));
          str16[jsi][ljcs[jsi]]=str6[jsi][ii0];
          a21lj[jsi][ljcs[jsi]]=a2[jsi][ii0][0];
          ccltwz[jsi][ljcs[jsi]]=i0+Name_Height+81;  //  储层连通位置
          ljcs[jsi]=ljcs[jsi]+1;
          if(ii0<totalnum[jsi])ii0=ii0+1;
          while((a2[jsi][ii0][0]<0.1)&&(ii0<totalnum[jsi]))
          {
             ii0=ii0+1;
          }
      }
   }
   if(jsi>=2)
   {
        cclt(Sender);     //储层连通
   }
  // hdhf(Sender);   2022-12-2注销
   if((jsi>=2)&&(jxdb==1))
   {
        lthd(Sender);
   }
}
//-----------------------------------------------------------------------------------
void __fastcall TForm3::cclt(TObject *Sender)    //储层连通   断层识别
{
   int tw,dc,dcs=0,last=0,dcpd=0,flag=0,i7=0,tm=-1; //断层、断层数 、最后层 、断层判断    题目
   int t1=0,t2=0,countdc=0,to=0,to2=0,ts=0,ts2=0;  float fdeep1[400],fdeep2[400],fdeep3[400];
   FILE *fpdc,*fp1;
   String Dir="D:\\二厂储层对比项目\\断层识别\\";

   float dp1=0.0;
   String st1[200],st2[200];

   //
   int max = 0,min = 0;
   int Count_Max = 0;
   int Count_Min = 0;
   int Count_A = 0;                     //
   int Count_B = 0;                     //
   int result[200][20];                 //断层对比结果
   int Count_Num[10];                   //已加载井层位计数，上限[10]
   int Count_Fault[10];                 //已加载井断层计数，上限[10]
   int Fault_A = 0;                     //A井相对B井断层数
   int Fault_B = 0;                     //B井相对A井断层数
   int Last_A = 0;                      //A井最后一层在B井中的位置
   int Last_B = 0;                      //B井最后一层在A井中的位置
   int Count_Ex = 0;                    //额外层数差
   int Switch_Fault = 0;                //断层存在情况：1A,2B,3AB
   //
   int left_px[10];
   for(int i1=1;i1<js;i1++)
   {
        tw=dj*(i1-1)+2+trackwidth+50+trackwidth;
        left_px[i1] = dj*(i1-1)+2+trackwidth+50+trackwidth;
        int i2=0;
   }

   if(js >= 2 && Switch_print != js && ss >= 2 && js == ss)
   {
        //连线
        for(int k = 2;k <= js;k ++)
        {
                for(int i = 0;i < 200;i ++)
                {
                        for(int j = 0;j < 200;j ++)
                        {
                                        if(str16[k][i] == str16[k - 1][j])
                                        {
                                                PaintBox2->Canvas->MoveTo(left_px[k - 1] + trackwidth/2 + 10,ccltwz[k - 1][j]);
                                                PaintBox2->Canvas->LineTo(dj*(k - 1) + 4,ccltwz[k][i]);
                                                print_line[i][k] = left_px[k - 1] + trackwidth/2 + 10;
                                                print_line[i][k + 10] = ccltwz[k - 1][j];
                                                print_line[i][k + 20] = dj*(k - 1) + 4;
                                                print_line[i][k + 30] = ccltwz[k][i];
                                                if(str16[k][j + 1] == "")
                                                        print_line[i + 1][k] = -1;
                                        }
                        }

                }
                /*
                for(int i = 0;i < 200;i ++)
                {
                        if(print_line[i][k] > 10 || print_line[i][k + 10] > 10 || print_line[i][k + 20] > 10 || print_line[i][k + 30] > 10)
                                continue;
                        for(int j = 0;j < 200;j ++)
                        {
                                        if(str16[k][j] == str16[k - 1][i])
                                        {
                                                PaintBox2->Canvas->MoveTo(left_px[k - 1] + trackwidth/2 + 10,ccltwz[k - 1][j]);
                                                PaintBox2->Canvas->LineTo(dj*(k - 1) + 4,ccltwz[k][i]);
                                                print_line[i][k] = left_px[k - 1] + trackwidth/2 + 10;
                                                print_line[i][k + 10] = ccltwz[k - 1][j];
                                                print_line[i][k + 20] = dj*(k - 1) + 4;
                                                print_line[i][k + 30] = ccltwz[k][i];
                                                if(str16[k][j + 1] == "")
                                                        print_line[i + 1][k] = -1;
                                        }
                        }

                }
                */
                int end = 0;
                for(int j = 199;j > 0;j --)
                {
                        if(print_line[j][k] == -1)
                        {
                                print_line[j][k] = -2;
                                end = j;
                                break;
                        }
                }
        }
        Switch_print = js;
   }
   AnsiString temp_s = "";
   if(js >= 2 && Switch_print == js)
   {
        for(int k = 1;k <= js;k ++)
        {
                for(int i = 0;i < 200;i ++)
                {
                        if(print_line[i][k] == 0 || print_line[i][k + 10] == 0 || print_line[i][k + 20] == 0 || print_line[i][k + 30] == 0)
                                continue;

                        if(print_line[i][k] == -2)
                                break;

                        PaintBox2->Canvas->Pen->Color = clBlack;
                        PaintBox2->Canvas->MoveTo(print_line[i][k],print_line[i][k + 10]);
                        PaintBox2->Canvas->LineTo(print_line[i][k + 20],print_line[i][k + 30]);



                }
        }
        //断层标注
        for(int k = 1;k <= js;k ++)
        {
                for(int i = 1;i <= 200;i ++)
                {
                        if(print_fault_B[i][k] == -1)
                        {
                                temp_s = str16[k][i - 1];
                                PaintBox2->Canvas->Font->Color = clRed;
                                PaintBox2->Canvas->TextOutA(left_px[k] + trackwidth/2,ccltwz[k][i - 1] ,  temp_s + "层位断失");
                        }
                        if(print_fault_B[i][k + 10] == -1)
                        {
                                temp_s = str16[k + 1][i - 1];
                                PaintBox2->Canvas->Font->Color = clBlue;
                                PaintBox2->Canvas->TextOutA(left_px[k] + trackwidth/2,ccltwz[k + 1][i - 1] ,  temp_s +  "层位断失");
                        }
                }
        }
   }
//======================================================================================

   if(js >= 2 && js != Switch_js && ss >= 2 && js == ss)
   {
                Switch_js = js;
                int i1 = js - 1;
                int BR = 0;
                for(int i = 0;i < 10;i ++)      Count_Num[i] = Count_Fault[i] = 0;
                for(int i = 0;i < 200;i ++)
                {
                        if(str16[js - 1][i] != "")
                                Count_Num[js - 1] ++;
                        if(str16[js][i] != "")
                                Count_Num[js] ++;
                }
                for(int i = 200;i > 1;i --)
                {
                        if(str16[js - 1][i] != "" && str16[js - 1][i] != NULL)
                        {
                                for(int j = 200;j > 1;j --)
                                {
                                        if(str16[js - 1][i] == str16[js][j])
                                        {
                                               Count_Num[js - 1] = i;
                                               Count_Num[js] = j;
                                               BR = 1;
                                        }
                                        if(BR == 1)
                                                break;
                                }
                        }
                        if(BR == 1)
                                break;

                }
                max = Count_Num[js];
                min = Count_Num[js - 1];
                if(Count_Num[js - 1] > max)
                {
                        max = Count_Num[js - 1];
                        min = Count_Num[js];
                }
                for(int i = 0;i < 200;i ++)
                {
                        for(int j = 0;j < 20;j ++)
                        result[i][j] = 0;
                }
                Count_Fault[js] = Count_Num[js];
                Count_Fault[js - 1] = Count_Num[js - 1];
                for(int i = 0;i <= Count_Num[js];i ++)
                {
                        result[i][js] = i;
                        for(int j = 0;j <= Count_Num[js - 1];j ++)
                        {
                                if(str16[js][i] == str16[js - 1][j])
                                {
                                        result[i][js - 1] = j;
                                        result[i][0] = 1;
                                        Count_Fault[js] --;
                                        break;
                                }
                                //if(str16[js][180])
                        }
                }
                Count_Fault[js] ++;
                //
                for(int i = 0;i <= Count_Num[js - 1];i ++)
                {
                        result[i][js - 1 + 10] = i;
                        for(int j = 0;j <= Count_Num[js];j ++)
                        {
                                if(str16[js - 1][i] == str16[js][j])
                                {
                                        result[i][js + 10] = j;
                                        result[i][10] = 1;
                                        Count_Fault[js - 1] --;
                                        break;
                                }
                        }

                }
                Count_Fault[js - 1] ++;
                //
                for(int j = 0;j < 200;j ++)
                {
                        int temp = 0;
                        Last_A = j;
                        for(int i = Count_Num[js];i > 0;i --)
                        {

                                if(str16[js - 1][Count_Num[js - 1] - j] == str16[js][i] && str16[js][i] != "")
                                {
                                        temp = 1;
                                        Last_A = j;
                                        break;
                                }
                                if(str16[js - 1][Count_Num[js - 1] - j] != str16[js][i] && str16[js][i] != "")
                                        Last_A ++;
                        }
                        if(temp == 1)
                                break;

                }
                for(int j = 0;j < 200;j ++)
                {
                        int temp = 0;
                        Last_B = j;
                        for(int i = Count_Num[js - 1];i > 0;i --)
                        {

                                if(str16[js][Count_Num[js] - j] == str16[js - 1][i] && str16[js - 1][i] != "")
                                {
                                        temp = 1;
                                        Last_B = j;
                                        break;
                                }
                                if(str16[js][Count_Num[js] - j] != str16[js - 1][i] && str16[js - 1][i] != "")
                                        Last_B ++;
                        }
                        if(temp == 1)
                                break;
                }
                Count_Ex = Last_A;
                Count_Fault[js - 1] = Count_Fault[js - 1] - Last_A;
                Count_Fault[js] = Count_Fault[js] - Last_B;
                /*
                if(Last_A > Last_B + 20)     //A最后层位深度>B最后层位深度 Last_B = 额外层位数差 , A更深
                {
                        Count_Ex = Last_B;
                        Count_Fault[js - 1] = Count_Fault[js - 1] - Count_Ex;
                }
                else if(Last_B > Last_A + 20)     //B最后层位深度>A最后层位深度 Last_A = 额外层位数差 , B更深
                {
                        Count_Ex = Last_A;
                        Count_Fault[js] = Count_Fault[js] - Count_Ex;
                }
                else     //B最后层位深度>A最后层位深度 Last_A = 额外层位数差 , B更深
                {
                        Count_Ex = Last_A;
                        Count_Fault[js - 1] = Count_Fault[js - 1] - Last_A;
                        Count_Fault[js] = Count_Fault[js] - Last_B;
                }
                */
                //
                if(js >= 2 && Count_Fault[js] > 0 && Count_Fault[js - 1] > 0)   //A、B都存在断层
                        Switch_Fault = 3;
                if(js >= 2 && Count_Fault[js] > 0 && Count_Fault[js - 1] == 0)  //A都存在断层
                        Switch_Fault = 1;
                if(js >= 2 && Count_Fault[js] == 0 && Count_Fault[js - 1] > 0)  //B都存在断层
                        Switch_Fault = 2;
                //JS == 2 计数真断层
                        int fA = Count_Fault[js - 1];
                        int fB = Count_Fault[js];
                        int temp = fB;
                        for(int i = 0;i <= Count_Num[js];i ++)
                        {
                                for(int j = 0;j <= Count_Num[js - 1];j ++)
                                {
                                        if(str16[js][i] == str16[js - 1][j])
                                                print_fault[i + 1][js] = 1;
                                }
                        }
                        for(int i = 0;i <= Count_Num[js];i ++)
                        {
                                if(print_fault[i + 1][js] != 1 && temp > 0)
                                {
                                        print_fault[i + 1][js] = -1;
                                        temp --;
                                }
                        }

                        temp = fA;
                        for(int i = 0;i <= Count_Num[js - 1];i ++)
                        {
                                for(int j = 0;j <= Count_Num[js];j ++)
                                {
                                        if(str16[js - 1][i] == str16[js][j])
                                                print_fault[i + 1][js - 1] = 1;
                                }
                        }
                        for(int i = 0;i <= Count_Num[js - 1];i ++)
                        {
                                if(print_fault[i + 1][js - 1] != 1 && temp > 0)
                                {
                                        print_fault[i + 1][js - 1] = -1;
                                        temp --;
                                }
                        }
                        for(int i = 0;i < 200;i ++)
                        {

                                        if(print_fault[i][js - 1] == -1)
                                                print_fault_B[i][js - 1] = -1;
                                        if(print_fault[i][js] == -1)
                                                print_fault_B[i][js - 1 + 10] = -1;

                        }
                        for(int i = 0;i < 200;i ++)
                        {
                                for(int j = 0;j < 20;j ++)
                                        print_fault[i][j] = 0;
                        }
                //连续断层计数处理
                int end_A = Count_Num[js - 1];
                int end_B = Count_Num[js];
                for(int i = 199 ;i > 0; i --)
                {
                        if(result[i][js - 1] != 0)
                        {
                                end_A = i;
                                break;
                        }
                }
                for(int i = 199 ;i > 0; i --)
                {
                        if(result[i][js + 10] != 0)
                        {
                                end_B = i;
                                break;
                        }
                }
                if(Count_Fault[js] > 0)
                {
                        for(int j = 0;j < end_A;j ++)
                        {
                                if(result[j][0] == 0 && result[j + 1][0] == 0 && result[j][js] > 0 && Count_Fault[js] > 0)//连续断层
                                        Count_Fault[js] --;
                        }

                }
                if(Count_Fault[js - 1] > 0)
                {
                        for(int j = 0;j < end_B ;j ++)
                        {
                                if(result[j][10] == 0 && result[j + 1][10] == 0 && result[j][10 + js - 1] > 0 && Count_Fault[js - 1] > 0)//连续断层
                                        Count_Fault[js - 1] --;
                        }
                }
                //output
                if(Switch_Fault != 0 && js >= 2 && Switch_Fault != 2)
                {
                        String File_name_A = ChangeFileExt(newname[js - 1],"");
                        String File_name_B = ChangeFileExt(newname[js],"");
                        String d1 = "";
                        if(out_put_mod == 2)
                        {
                                d1 = File_name_A + " - " + File_name_B + ".txt";
                        }
                        else if(out_put_mod == 3)
                        {
                                TDateTime date;
                                date = Now();
                                AnsiString st = date.DateTimeString();
                                st = StringReplace(st,"/","-", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                st = StringReplace(st,":","'", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                d1 = File_name_A + " - " + st + ".txt";
                        }
                        else
                        {
                                d1 = File_name_A + ".txt";
                        }
                        String fname_A = Dir + d1;
                        //A========================================================================================================
                        fpdc = fopen(fname_A.c_str(),"w+t");
                        fprintf(fpdc,"%d\n",Count_Fault[js]);
                        int last_pos = 0;
                        for(int ic = 0;ic < Count_Fault[js];ic ++)
                        {
                                //int LastOne = (Count_Num[js - 1] > Count_Num[js])? Count_Num[js - 1]:Count_Num[js];
                                for(int j = 0;j <= (Count_Num[js - 1] > Count_Num[js])? Count_Num[js - 1]:Count_Num[js];j ++)
                                {
                                        if(result[j][0] == 0 && result[j + 1][0] > 0 && j > last_pos)//单断层
                                        {
                                                float A = 0;
                                                float B = 0;
                                                float fault_depth = a21lj[js - 1][result[j - 1][js - 1]] + (a21lj[js][result[j][js]] - a21lj[js][result[j - 1][js]]);
                                                if(fault_depth > a21lj[js - 1][result[j - 1][js - 1] + 1])
                                                        fault_depth = (a21lj[js - 1][result[j - 1][js - 1] + 1] + a21lj[js - 1][result[j - 1][js - 1]])/2;
                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js]));
                                                for(int k = 0;k < 200;k ++)
                                                {
                                                        if(str16[js][j] == jhw[js][k])
                                                        {
                                                                A = xcw[js][k];
                                                                B = xcw[js][k + 1];
                                                                break;
                                                        }
                                                }
                                                if(A == 0)
                                                {
                                                        A = a21lj[js][result[j][js] + 1];
                                                        B = a21lj[js][result[j][js] + 1];
                                                }
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str16[js][j];
                                                str_temp = change_name_single(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%4.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos = j;
                                                j++;
                                                break;
                                        }
                                        else if(result[j][0] == 0 && result[j + 1][0] == 0 && result[j + 1][js] > 0 && j > last_pos)//连续断层
                                        {
                                                float A = 0;
                                                float B = 0;
                                                int topA = j;
                                                int k = j;
                                                for(;k < Count_Num[js];k ++)
                                                {
                                                        if(result[k + 1][0] == 0)
                                                                j++;
                                                        else if(result[k + 1][0] == 1)
                                                                break;
                                                }
                                                float fault_depth = 0;
                                                fault_depth = a21lj[js - 1][result[topA - 1][js - 1]] + (a21lj[js][result[topA][js]] - a21lj[js][result[topA - 1][js]]);
                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js]));
                                                A = a21lj[js][result[topA][js]];
                                                B = a21lj[js][result[j][js]];
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str16[js][topA];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s - ",str_temp);
                                                str_temp = str16[js][j];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%4.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos = j;
                                                j++;
                                                break;
                                        }
                                }
                        }
                        fclose(fpdc);
                }
                if(Switch_Fault >= 2 && js >= 2)//B========================================================================================================
                {

                        String File_name_A = ChangeFileExt(newname[js - 1],"");
                        String File_name_B = ChangeFileExt(newname[js],"");
                        String d1 = "";
                        if(out_put_mod == 2)
                        {
                                d1 = File_name_B + " - " + File_name_A + ".txt";
                        }
                        else if(out_put_mod == 3)
                        {
                                TDateTime date;
                                date = Now();
                                AnsiString st = date.DateTimeString();
                                st = StringReplace(st,"/","-", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                st = StringReplace(st,":","'", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                d1 = File_name_B + " - " + st + ".txt";
                        }
                        else
                        {
                                d1 = File_name_B + ".txt";
                        }
                        String fname_B = Dir + d1;
                        int last_pos2 = 0;
                        fpdc = fopen(fname_B.c_str(),"w+t");
                        fprintf(fpdc,"%d\n",Count_Fault[js - 1]);
                        for(int ic = 0;ic < Count_Fault[js - 1];ic ++)
                        {
                                for(int j = 0;j <= (Count_Num[js - 1] > Count_Num[js])? Count_Num[js - 1]:Count_Num[js];j ++)
                                {
                                        if(result[j][10] == 0 && result[j + 1][10] > 0 && j > last_pos2)//单断层
                                        {
                                                float A = 0;
                                                float B = 0;
                                                float fault_depth = a21lj[js][result[j - 1][js + 10]] + (a21lj[js - 1][result[j][js + 10 - 1]] - a21lj[js - 1][result[j - 1][js + 10 - 1]]);
                                                if(fault_depth > a21lj[js][result[j - 1][js + 10] + 1])
                                                        fault_depth = (a21lj[js][result[j - 1][js + 10]] + a21lj[js][result[j - 1][js + 10] + 1])/2;


                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js - 1]));
                                                for(int k = 0;k < 200;k ++)
                                                {
                                                        if(str16[js - 1][j] == jhw[js - 1][k])
                                                        {
                                                                A = xcw[js - 1][k];
                                                                B = xcw[js - 1][k + 1];
                                                                break;
                                                        }
                                                }
                                                if(A == 0)
                                                {
                                                        A = a21lj[js][result[j][js] + 1];
                                                        B = a21lj[js][result[j][js] + 1];
                                                }
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str16[js - 1][j];
                                                str_temp = change_name_single(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%3.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos2 = j;
                                                j++;
                                                break;
                                        }
                                        else if(result[j][10] == 0 && result[j + 1][10] == 0 && result[j + 1][js - 1 + 10] > 0 && j > last_pos2)//连续断层
                                        {
                                                int topB = j;
                                                float A = 0;
                                                float B = 0;
                                                for(int k = j;k < Count_Num[js - 1];k ++)
                                                {
                                                        if(result[k + 1][10] == 0)
                                                                j++;
                                                        if(result[k + 1][10] == 1)
                                                                break;
                                                }
                                                //
                                                float fault_depth = a21lj[js][result[topB - 1][js + 10]] + (a21lj[js - 1][result[topB][js + 10 - 1]] - a21lj[js - 1][result[topB - 1][js + 10 - 1]]);
                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js - 1]));
                                                A = a21lj[js - 1][result[topB][js - 1 + 10]];
                                                B = a21lj[js - 1][result[j][js - 1 + 10]];
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str16[js - 1][topB];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s - ",str_temp);
                                                str_temp = str16[js - 1][j];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%4.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos2 = j;
                                                j++;
                                                break;
                                        }

                                }
                        }
                        fclose(fpdc);
                }
   }

}
//-----------------------------------------------------------------------------------
void __fastcall TForm3::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"); //更换扩展名
  str=ChangeFileExt(x,".DBF");
  int length = str.Length();
  AnsiString well_name = s;
  str = StringReplace(str,".DBF","", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
  str = StringReplace(str,".dbf","", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
  newname[js]=str;
 //  PaintBox2->Canvas->TextOutA(20,200,newname);
}
//---------------------------------------------------------------------------
__fastcall TForm3::getint(FILE *fp)
{

 char *s;short i;
 (short *)s=&i;
 s[1]=getc(fp);s[0]=getc(fp);
 return(i);
 }
//---------------------------------------------------------------------------
float __fastcall TForm3::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 TForm3::putint(short ii,FILE *fp)
{

 char *s;
 (short *)s=&ii;
 putc(s[1],fp);putc(s[0],fp);
  }
//---------------------------------------------------------------------------
__fastcall TForm3::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 TForm3::smaxmin(int i0)
{
 float ma0[50000],min0;
 int i9,ij=0;
 Top_deep[js]=0.0;
 i9=int(Top_deep[js]/relv[js]);
 for(int l=i9+10;l<stedp[js];l++)
 {
  ma0[ij]=a[js][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 TForm3::draw(int temp[30][3][4],int tracknum,float data[30][40000][50],int index[30],float stdp0[30],float relv0[30],int jss)
{
     int po1=0;
     TColor a8[2]={clBlack,clRed};
     TPenStyle b[2]={psSolid,psDot};
     po1=int((endp[jss]-stdp[jss])/relv[jss]);
     if(po1>totaldpnum)
     {
         totaldpnum=po1;
     }
     totaldpnum=totaldpnum+200;
//////////////////////////////////////////////////////////////////////
        relv[jss]=0.05;
        index[jss]=totaldpnum;   //index[jss]+50;//starti1=0;
        starti1[jss]=0;
        sdc[jss]=int((stdp0[jss]-data[jss][0][0])/relv0[jss]);
        PaintBox2->Canvas->Pen->Style=psSolid;
      PaintBox2->Canvas->Pen->Color=clGreen;
     PaintBox2->Canvas->Pen->Width=2;
     PaintBox2->Canvas->MoveTo(dj*(jss-1)+2,starti1[jss]+Name_Height+81);
     PaintBox2->Canvas->LineTo(dj*(jss-1)+2,index[jss]+20);
     //first trace
   //  PaintBox2->Canvas->MoveTo(2+50+trackwidth*2,0);

    // PaintBox2->Canvas->MoveTo(2+50+dj*(jss-1)+trackwidth*2,starti1[jss]+ScrollBox1->VertScrollBar->Position+Name_Height+81);
     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<1;j++)
     {
        if(j==0)
        {
            value_range_left=0;
            value_range_right=25;
        }
        for(int i=0;i<2;i++)
        {

            if(temp[jss][i][j]!=-1)
            {
                 PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+trackwidth/3+50+trackwidth,starti1[jss]+Name_Height+81);
                 PaintBox2->Canvas->Pen->Color=a8[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[jss];k<totaldpnum;k++)
                 {
                      int temppos=0;  int twidth=trackwidth+(trackwidth)*(j*1.1)+60;
                      temppos=dj*(jss-1)+2+trackwidth/3+50+trackwidth+floor((data[jss][k+sdc[jss]][temp[jss][i][j]]-value_range_left)/(value_range_right-value_range_left)*twidth);
                      PaintBox2->Canvas->LineTo(temppos,k+Name_Height+81);
                      PaintBox2->Canvas->MoveTo(temppos,k+Name_Height+81);
                 }
            }
        }
     }
     //---------------------------------------------------------draw GR curve
     PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+trackwidth/3-50,starti1[jss]+Name_Height+81);
     if(temp[jss][0][2]!=-1)
     {
          for(int i=starti1[jss];i<totaldpnum;i++)
          {

                 int temppos=0;
                 PaintBox2->Canvas->Pen->Style=psSolid;
                 PaintBox2->Canvas->Pen->Color=clBlack;
                 PaintBox2->Canvas->Pen->Width=1;
                 temppos=dj*(jss-1)+2+trackwidth/3-50+floor((data[jss][i+sdc[jss]][temp[jss][0][2]]-20)/(150-20)*trackwidth);
                 PaintBox2->Canvas->LineTo(temppos,i+Name_Height+81);

          }
     }
 //-------------------------------------------------------------draw  SP  curve

     float datsp[50000];
     for(int in=starti1[jss];in<totaldpnum;in++)
     {
      datsp[in]=data[jss][in+sdc[jss]][temp[jss][1][2]];
     }
     PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+trackwidth/3-50,starti1[jss]+Name_Height+81);
     PaintBox2->Canvas->Pen->Style=psDot;
     PaintBox2->Canvas->Pen->Color=clRed;
     if(temp[jss][1][2]!=-1)
     {
          for(int i=starti1[jss];i<totaldpnum;i++)
          {
                 int temppos=0;
                 temppos=dj*(jss-1)+2+trackwidth/3-50+floor((datsp[i]-(-50.))/(50.0-(-50.))*trackwidth);
                 PaintBox2->Canvas->LineTo(temppos,i+Name_Height+81);
          }
     }
//---------------------------------------------------------------------Draw Depth
int deep,deep1,deep2,ip,ip1,sti,linelength=20;
  PaintBox2->Canvas->Pen->Color=clGreen;
 PaintBox2->Canvas->Pen->Style=psSolid;
 PaintBox2->Canvas->Pen->Width=2;
  PaintBox2->Top=-ScrollBox1->VertScrollBar->Position;

 //stdp0[jss]=stdp0[jss]+ScrollBox1->VertScrollBar->Position*relv0[jss];

 PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+50*2+trackwidth,starti1[jss]+Name_Height+81);
 PaintBox2->Canvas->LineTo(dj*(jss-1)+2+50*2+trackwidth,starti1[jss]+Name_Height+81+PaintBox2->Height);
 PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+50+trackwidth,starti1[jss]+Name_Height+81);
 PaintBox2->Canvas->LineTo(dj*(jss-1)+2+50+trackwidth,starti1[jss]+Name_Height+81+PaintBox2->Height);
 ip=(int)(stdp0[jss]*10);
 ip1=(int)(ip/2);
 if(ip1*2==ip)
 {
  sti=0;
  }
  else
  {
   ip=(int)((stdp0[jss]+relv0[jss])*10);
   ip1=(int)(ip/2);
   if(ip1*2==ip)
   {
    sti=1;
     }
    else
    {
     sti=2;
     }
   }
 deep=int(stdp0[jss]/100.);
 deep=deep*100;
 deep2=int(stdp0[jss]/2.);
 deep2=deep2*2;
 PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+150+trackwidth*2,starti1[jss]+Name_Height+81);
 PaintBox2->Canvas->LineTo(dj*(jss-1)+2+150+trackwidth*2,starti1[jss]+Name_Height+81+PaintBox2->Height);
 for(int i0=sti;i0<index[jss];i0+=4)
 {
  deep1=int(stdp0[jss]+i0*relv0[jss]);
  if(deep1==(deep2+2))
  {
   PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+50+trackwidth,starti1[jss]+Name_Height+81+i0);
   PaintBox2->Canvas->LineTo(dj*(jss-1)+2+50+trackwidth+10,starti1[jss]+Name_Height+81+i0);
   PaintBox2->Canvas->TextOut(dj*(jss-1)+2+50+trackwidth+14,starti1[jss]+Name_Height+81+i0-5,AnsiString(deep2+2));
   deep2=deep2+2;
   }
   else
   {
    PaintBox2->Canvas->MoveTo(dj*(jss-1)+2+50+trackwidth+0,starti1[jss]+Name_Height+81+i0);
    PaintBox2->Canvas->LineTo(dj*(jss-1)+2+50+trackwidth+5,starti1[jss]+Name_Height+81+i0);
    }
   }
}
//------------------------------------------------------------------------------------


void __fastcall TForm3::PaintBox2Paint(TObject *Sender)
{
   // lthead(Sender);
/*   if(Switch==2)
   {
     dklawj(Sender);
   }
   else if(Switch==1)    */
   {
       N4Click(Sender);
       for(jsi=1;jsi<=js;jsi++)
       {
           if(Mod > 0)
                paintfenceng_074(Sender);
           else
                paintfenceng(Sender);
       }
       cclt(Sender);
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm3::N5Click(TObject *Sender)   //深度对齐
{
   float startdeep=0.0;
   for(int isd=1;isd<=js;isd++)
   {
      if(stdp[isd]>startdeep)
      {
        startdeep=stdp[isd];
      }
   }
   for(int isd=1;isd<=js;isd++)
   {
      stdp[isd]=startdeep;
   }
   N4Click(Sender);
   for(jsi=1;jsi<=js;jsi++)
   {
        paintfenceng(Sender);
   }
  PaintBox2->Canvas->Refresh();
  PaintBox2->Repaint();
  PaintBox2Paint(Sender);

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

void __fastcall TForm3::N6Click(TObject *Sender)       //层位对齐
{
    float startdeep=999999.0;

    for(int isd=1;isd<=js;isd++)
    {
      stdp[isd]=a2[isd][0][0]-300.0*relv[isd];

    }
     N4Click(Sender);
   for(jsi=1;jsi<=js;jsi++)
   {
        paintfenceng(Sender);
   }

   PaintBox2->Canvas->Refresh();
   PaintBox2->Repaint();
   PaintBox2Paint(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm3::hdhf(TObject *Sender)  //厚度划分
{
       float deep1,deep2,deep3,MNmkz,HACmkz;    //MN门槛值、HAC门槛值
      MNmkz=3.5;  //4.0;
      HACmkz=220.0;
      int tw,sw1=0;
      tw=dj*(jsi-1)+2+trackwidth/3+65+trackwidth;    //Form1->Width/19.0;
       //     PaintBox2->Canvas->Pen->Width=2;
        //    PaintBox2->Canvas->Pen->Style=psSolid;
        //    PaintBox2->Canvas->Pen->Color=clRed;
      int ihd0[500],ihd[500];
      ihd0[jsi]=0;
      ihd[jsi]=0;
 for(int i0=0;i0<stedp[jsi];i0++)
 {
    deep1=stdp[jsi]+i0*relv[jsi];
    for(int ii0=0;ii0<(ljcs[jsi]-1-1);ii0++)
    {
      if((fabs(deep1-a21lj[jsi][ii0])<0.01))     
      {
          for(int i1=i0;i1<=i0+int((a21lj[jsi][ii0+1]-a21lj[jsi][ii0])/relv[jsi]);i1++)
          {
                if((a[jsi][i1+sdc[jsi]][MN_pos[jsi]]>MNmkz)&&(a[jsi][i1+sdc[jsi]][HAC_pos[jsi]]>HACmkz)&&(sw1==0))
                {
                  //      PaintBox2->Canvas->MoveTo(tw[jsi],i1+Name_Height+81);
                   //     PaintBox2->Canvas->LineTo(tw[jsi]+7,i1+Name_Height+81);
                        ljbwhd0[jsi][ihd0[jsi]][0]=stdp[jsi]+i1*relv[jsi];

                    //    PaintBox2->Canvas->MoveTo(tw[jsi],i1+Name_Height+81);
                        sw1=1;

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

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

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

           }
           if(fabs(deep3-ljbwhd[jsi][ih[jsi]][1])<0.01)
           {
              PaintBox2->Canvas->LineTo(tw-5,i0+Name_Height+81);
              PaintBox2->Canvas->MoveTo(tw-5,i0+Name_Height+81);
              PaintBox2->Canvas->LineTo(tw+7-5,i0+Name_Height+81);
              ih[jsi]=ih[jsi]+1;
           }
      }
      int ih1[30];
      ih1[jsi]=0;
      PaintBox2->Canvas->Pen->Width=1;
      PaintBox2->Canvas->Pen->Style=psSolid;
      PaintBox2->Canvas->Pen->Color=clBlue;
      for(int i0=0;i0<stedp[jsi];i0++)
      {
           deep3=stdp[jsi]+i0*relv[jsi];
           if(fabs(deep3-ljbwhd[jsi][ih1[jsi]][0])<0.01)
           {

              PaintBox2->Canvas->MoveTo(dj*(jsi-1)+4+0,i0+Name_Height+81);
              PaintBox2->Canvas->LineTo(tw+10+trackwidth/1+15,i0+Name_Height+81);
           }
           if(fabs(deep3-ljbwhd[jsi][ih1[jsi]][1])<0.01)
           {
              PaintBox2->Canvas->MoveTo(dj*(jsi-1)+4+0,i0+Name_Height+81);
              PaintBox2->Canvas->LineTo(tw+10+trackwidth/1+15,i0+Name_Height+81);
              ih1[jsi]=ih1[jsi]+1;

           }
      }
}
//-----------------------------------------------------------------------------
void __fastcall TForm3::lthd(TObject *Sender)  //连通厚度
{
//test----------------------------------
   /* FILE *fp1,*fp2;
    fp1=fopen("D:\\liqh1.dat","wt");
    fp2=fopen("D:\\liqh2.dat","wt");  */
   // fprintf(fp,"井1层界   井2层界 井1小层顶  井2小层顶 距离差  井1层界  井2层界  井1小层底 井2小层底 距离差");
//test-----------------------------------------------------------------------
 PaintBox2->Canvas->Pen->Width=1;
  PaintBox2->Canvas->Pen->Style=psSolid;
 // PaintBox2->Canvas->Pen->Color=clBlue;
 // PaintBox2->Canvas->Pen->Color=RGB(0,0,255);
   int tw,tw1,sw=0;
 //  tw=dj*(jsi-1)+2+trackwidth+50+trackwidth;
   for(int i1=1;i1<js;i1++)
   {
      tw=dj*(i1-1)+2+trackwidth+50+trackwidth;
      tw1=dj*(i1)+2+trackwidth+50+trackwidth;
      for(int i2=0;i2<ljcs[i1];i2++)
      {
         for(int i3=0;i3<ljcs[i1+1];i3++)
         {
             if(str16[i1][i2]==str16[i1+1][i3])
             {
                if(str16[i1][i2+1]==str16[i1+1][i3+1])
                {
                   for(int i4=0;i4<ih[i1];i4++)
                   {
                      for(int i5=0;i5<ih[i1+1];i5++)
                      {
                          PaintBox2->Canvas->Pen->Color=RGB(0,0,255-i4);
                          if(((fabs((ljbwhd[i1][i4][0]-a21lj[i1][i2])-(ljbwhd[i1+1][i5][0]-a21lj[i1+1][i3]))<0.4)||(fabs((a21lj[i1][i2+1]-ljbwhd[i1][i4][0])-(a21lj[i1+1][i3+1]-ljbwhd[i1+1][i5][0]))<0.4))&&(ljbwhd[i1][i4][0]>=a21lj[i1][i2])&&(ljbwhd[i1][i4][0]<=a21lj[i1][i2+1])&&(ljbwhd[i1+1][i5][0]>=a21lj[i1+1][i3])&&(ljbwhd[i1+1][i5][0]<=a21lj[i1+1][i3+1])&&(sw==0))   //&&((ljbwhd[i1][i4][0]-ljbwhd[i1][i4-1][1])>0.1)
                          {
                             int il11=int((ljbwhd[i1][i4][0]-stdp[i1])/relv[i1]);
                             int il21=int((ljbwhd[i1+1][i5][0]-stdp[i1+1])/relv[i1+1]); 
                            // PaintBox2->Canvas->MoveTo(dj*(i1-1)+4+0,il11+Name_Height+81);
                            // PaintBox2->Canvas->LineTo(tw+10+trackwidth/2,il11+Name_Height+81);
                             PaintBox2->Canvas->MoveTo(tw+10+trackwidth/2,il11+Name_Height+81);
                             PaintBox2->Canvas->LineTo(dj*(i1)+4+0,il21+Name_Height+81);
                             sw=1;
                            // PaintBox2->Canvas->LineTo(tw1+10+trackwidth/2,il21+Name_Height+81);
                           /*  //test---------------------
                             if(fp1)
                             {
                                fprintf(fp1,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a21lj[i1][i2],a21lj[i1+1][i3],ljbwhd[i1][i4][0],ljbwhd[i1+1][i5][0],(ljbwhd[i1][i4][0]-a21lj[i1][i2])-(ljbwhd[i1+1][i5][0]-a21lj[i1+1][i3]));
                             }
                            //test----------------------------
                            */
                          }
                          if(((fabs((ljbwhd[i1][i4][1]-a21lj[i1][i2])-(ljbwhd[i1+1][i5][1]-a21lj[i1+1][i3]))<0.4)||(fabs((a21lj[i1][i2+1]-ljbwhd[i1][i4][1])-(a21lj[i1+1][i3+1]-ljbwhd[i1+1][i5][1]))<0.4))&&(ljbwhd[i1][i4][1]>=a21lj[i1][i2])&&(ljbwhd[i1][i4][1]<=a21lj[i1][i2+1])&&(ljbwhd[i1+1][i5][1]>=a21lj[i1+1][i3])&&(ljbwhd[i1+1][i5][1]<=a21lj[i1+1][i3+1])&&(sw==1))     //&&((ljbwhd[i1][i4+1][0]-ljbwhd[i1][i4][1])>0.1)
                          {
                           //  float p1=(ljbwhd[i1][i4][1]-a21lj[i1][i2])-(ljbwhd[i1+1][i5][1]-a21lj[i1+1][i3]);
                             int il12=int((ljbwhd[i1][i4][1]-stdp[i1])/relv[i1]);
                             int il22=int((ljbwhd[i1+1][i5][1]-stdp[i1+1])/relv[i1+1]);
                            // PaintBox2->Canvas->MoveTo(dj*(i1-1)+4+0,il12+Name_Height+81);
                            // PaintBox2->Canvas->LineTo(tw+10+trackwidth/2,il12+Name_Height+81);
                             PaintBox2->Canvas->MoveTo(tw+10+trackwidth/2,il12+Name_Height+81);
                             PaintBox2->Canvas->LineTo(dj*(i1)+4+0,il22+Name_Height+81);
                             sw=0;
                            // PaintBox2->Canvas->LineTo(tw1+10+trackwidth/2,il22+Name_Height+81);
                             //test---------------------
                            /* if(fp2)
                             {
                                fprintf(fp2,"%8.2f  %8.2f  %8.2f  %8.2f  %8.2f  %8.2f\n",a21lj[i1][i2],a21lj[i1+1][i3],ljbwhd[i1][i4][1],ljbwhd[i1+1][i5][1],fabs((ljbwhd[i1][i4][1]-a21lj[i1][i2])-(ljbwhd[i1+1][i5][1]-a21lj[i1+1][i3])),fabs((a21lj[i1][i2+1]-ljbwhd[i1][i4][1])-(a21lj[i1+1][i3+1]-ljbwhd[i1+1][i5][1])));
                             }
                            //test----------------------------
                                */
                          }
                      }
                   }
                }
                else
                {   //尖灭
                 //  PaintBox2->Canvas->MoveTo(tw+10+trackwidth/2+4+0,ccltwz[i1][i2]);
                  // PaintBox2->Canvas->LineTo(dj*(i1)+4+0,ccltwz[i1+1][i3]);
                }
             }
         }
      }
   }
 //  fclose(fp1);  fclose(fp2);
}
//-------------------------------------------------------------------------------
void __fastcall TForm3::N7Click(TObject *Sender)     //拉平对齐
{
   lpdq=1;
 /* for(int isd=1;isd<=js;isd++)
    {
      //stdp[isd]=a2[isd][0][0]-300.0*relv[isd];
      stdp[isd]=ljbwhd[isd][ic][0]-300.0*relv[isd];

    }
     N4Click(Sender);
   for(jsi=1;jsi<=js;jsi++)
   {
        paintfenceng(Sender);
   }

   PaintBox2->Canvas->Refresh();
   PaintBox2->Repaint();
   PaintBox2Paint(Sender);   */
}
//---------------------------------------------------------------------------

void __fastcall TForm3::N8Click(TObject *Sender)   //沉积单元对比
{

       dklawj(Sender);

        jxdb=1;

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

void __fastcall TForm3::PaintBox2MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if(lpdq==1)
  {
     ic=-2;
     for(int i1=1;i1<=js;i1++)
     {
       for(int ii0=0;ii0<ih[i1];ii0++)
       {

          if((PaintBox2->Canvas->Pixels[X][Y]==RGB(0,0,255-ii0))||(PaintBox2->Canvas->Pixels[X][Y-1]==RGB(0,0,255-ii0))||(PaintBox2->Canvas->Pixels[X][Y+1]==RGB(0,0,255-ii0))||(PaintBox2->Canvas->Pixels[X][Y+2]==RGB(0,0,255-ii0))||(PaintBox2->Canvas->Pixels[X][Y-2]==RGB(0,0,255-ii0)))
          {

                ic=ii0;

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

void __fastcall TForm3::PaintBox2MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
 if((ic>=0)&&(lpdq==1))
 {
    for(int isd=1;isd<=js;isd++)
    {
      //stdp[isd]=a2[isd][0][0]-300.0*relv[isd];
      stdp[isd]=ljbwhd[isd][ic][0]-300.0*relv[isd];

    }
     N4Click(Sender);
    for(jsi=1;jsi<=js;jsi++)
    {
        if(Mod > 0)
                paintfenceng_074(Sender);
        else
                paintfenceng(Sender);
    }

    PaintBox2->Canvas->Refresh();
    PaintBox2->Repaint();
    PaintBox2Paint(Sender);
   // ic=0;
 }
}
//---------------------------------------------------------------------------
void __fastcall TForm3::dklawj(TObject *Sender)     //打开la文件
{

   AnsiString Dir;
   Switch=2;
   short i1,i2;float f;
   for(i9=0;i9<Form5->inum;i9++)
   {
     //  js=js+1;
       js=i9+1;
      // str16[Form5->ic[i9]]=Form5->Jh1[Form5->ic[i9]];
       Dir="D:\\二厂储层对比项目\\测井数据\\测井数据\\"+LowerCase(Form5->Jh1[Form5->ic[i9]])+"\\";
       Top_deep[js]=0.0;
       int flag,i3;

       FILE *fp;
       int Rd_valueGTzero=0;
       int RMN_valueGTzero=0;
       int AC_value=0;
       MN_pos[js]=0;
       MK_pos[js]=0;
       Rd_pos[js]=0;
       Rs_pos[js]=0;
       Ac_pos[js]=0;
       Rxo_pos[js]=0;
       GR_pos[js]=0;
       SP_pos[js]=0;
       DEN_pos[js]=0;
       AnsiString fn=Dir+LowerCase(Form5->Jh1[Form5->ic[i9]])+".la";
       fp=fopen(fn.c_str(),"rb");
       ccp[js]=LowerCase(Form5->Jh1[Form5->ic[i9]]);
 /*      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[js]=OpenDialog1->Files->Strings[I].c_str();
          ccp[js]=ExtractFileName(OpenDialog1->FileName);
          GetFileName(ccp[js]);
   // PaintBox2->Canvas->TextOutA(250,50,newname[js]);


          AnsiString la_location[30],la_name[30],dbf_name[30]; */

////////////////////////////////////////////////////////////////////////////////////////////////////////////////  添加
        /*  la_location[js] = OpenDialog1->FileName;
          la_name[js] = ccp[js];
          int length = la_name[js].Length();
          dbf_name[js] = la_name[js].SubString(1,length-2) ;
          dbf_name[js] += "dbf";

          length = la_location[js].Length();
          length = length - la_name[js].Length();
          AnsiString temp = la_location[js].SubString(1,length);
          la_location[js] = temp;

          la_Location[js] = la_location[js];
          la_Name[js] = la_name[js];
          dbf_Name[js] = dbf_name[js];   */
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

     if(fp)
     {
          fread(str0[js],84,1,fp);
          fread(str1[js],80,1,fp);
          i2=getint(fp);
          i1=getint(fp);
          fread(str[js],80,1,fp);
          //startdp
          stdp[js]=getfloat(fp);
          //endp
          endp[js]=getfloat(fp);
          //cyjj
          relv[js]=getfloat(fp);
          i1=getint(fp);
          i2=getint(fp);
          f=getfloat(fp);
          fread(str11[js],80,1,fp);
          fread(str3[js],148,1,fp);
          for(int i7=0;i7<5000;i7++)
          {
               for(int j7=1;j7<41;j7++)
               {
                  a[js][i7][j7]=1.0;
               }
          }
           // i1=0+int(Top_deep[js]/relv[js]);
          i1=0;
          stedp[js]=int((endp[js]-stdp[js])/relv[js]);
          while(i1<stedp[js])
          {
              for(int j=1;j<41;j++)
              {
                  for(int i=i1;i<i1+62;i++)
                  {
                      a[js][i][j]=getfloat(fp);
                  }
              }
              i1=i1+62;
           }
       }
  //   }
  // }
       for(int i=0;i<3;i++)
       {
              for(int j=0;j<4;j++)
              {
                  temp_index[js][i][j]=-1;
              }
       }
       for(int i0=0;i0<stedp[js];i0++)
       {
           a[js][i0][0]=stdp[js]+i0*relv[js];

       }
       int i4,i,j,ip;
       cname3[js][0][5]="DEPT ";
       i4=1;
       for(i=0;i<80;i+=4)
       {
            i2=0;
            for(j=i;j<i+4;j++)
            {
               if(str[js][j]!=' ')i2++;
            }
            j=i;
            for(i3=0;i3<4;i3++)
            {
               str2[js][i3]=0;
            }
            for(i3=0;i3<i2;i3++)
            {
                str2[js][i3]=str[js][j];
                j++;
            }
           if((str2[js][0]!=' ')&&(str2[js][0]!='\0'))
           {
                cname3[js][i4][5]=str2[js];
                if(strcmp(str2[js],"RMN")==0||strcmp(str2[js],"MNOR")==0)
                {
                    MN_pos[js]=i4;
                    temp_index[js][0][0]=i4;
                }
                if(strcmp(str2[js],"RML")==0||strcmp(str2[js],"RMK")==0||strcmp(str2[js],"RMM")==0||strcmp(str2[js],"RMG")==0)
                {
                    MK_pos[js]=i4;
                    temp_index[js][1][0]=i4;
                }
                if(strcmp(str2[js],"RLLD")==0||strcmp(str2[js],"RL3D")==0||strcmp(str2[js],"LLD")==0)
                {
                    Rd_pos[js]=i4;
                    temp_index[js][0][1]=i4;
                }
                if(strcmp(str2[js],"RLLS")==0||strcmp(str2[js],"RL3S")==0||strcmp(str2[js],"LLS")==0)
                {
                     Rs_pos[js]=i4;
                     temp_index[js][1][1]=i4;
                }
                if(strcmp(str2[js],"AC")==0||strcmp(str2[js],"DT")==0)
                {
                     Ac_pos[js]=i4;
                     temp_index[js][0][3]=i4;
                }
                 if(strcmp(str2[js],"MSFL")==0||strcmp(str2[js],"RXO")==0)
                 {
                     Rxo_pos[js]=i4;
                     temp_index[js][2][1]=i4;
                 }
                 if(strcmp(str2[js],"GR")==0)
                 {
                     GR_pos[js]=i4;
                     temp_index[js][0][2]=i4;
                 }
                 if(strcmp(str2[js],"SP")==0)
                 {
                     SP_pos[js]=i4;
                     temp_index[js][1][2]=i4;
                 }
                 if(strcmp(str2[js],"DEN")==0)
                 {
                      DEN_pos[js]=i4;
                      temp_index[js][1][3]=i4;
                 }
                 if(strcmp(str2[js],"HAC")==0)
                 {
                      HAC_pos[js]=i4;
                      temp_index[js][2][3]=i4;
                 }
                 i4++;
           }
       }
           ip=i4;
           i4=i4-1;
           for(int i0=1;i0<(ip+1);i0++)
           {
                smaxmin(i0);
                ma[js][i0]=max;
                mi[js][i0]=min;
           }
           int po1;
           for(int j1=1;j1<=js;j1++)
           {
                maxp1[j1]=stedp[j1];
           }
           for(int j1=1;j1<=js-1;j1++)
           {
               for(int j2=j1+1;j2<=js;j2++)
               {
                   if(maxp1[j1]>maxp1[j2])
                   {
                       po1=maxp1[j1];
                       maxp1[j1]=maxp1[j2];
                       maxp1[j2]=po1;
                   }
               }
           }
            ScrollBox1->VertScrollBar->Range=maxp1[js]+1200;
            N4Click(Sender);
            PaintBox2->Height=maxp1[1]+113+85+1000;
            Form3->Caption= ccp[js]+"                                       采 油 二 厂 储 层 连 通 性 对 比 技 术";
   
            ljcjdysjk0(Sender);
            for(int i1=0;i1<totalnum[js]+1;i1++)
            {
                str5[js][i1]=jhw[js][i1].c_str();                  
                str6[js][i1]=jhw[js][i1].c_str();
                a2[js][i1][0]=xcw[js][i1];
            }
            paintfenceng(Sender);
            fclose(fp); // PaintBox2->Canvas->TextOutA(50,400,newname[js]);
   }
}
//----------------------------------------------------------------------------
void __fastcall TForm3::ljcjdysjk0(TObject *Sender)      //老井沉积单元数据库
{
   AnsiString Dir,fn,jjhh;
   FILE *fc,*fo;

  // for(int i9=0;i9<Form5->inum;i9++)
   {

             // js=i9+1;

               Dir="D:\\二厂储层对比项目\\测井数据\\测井数据\\";
               int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;
               AnsiString cc,Bzz;
               totalnum[js]=0;

               fn=Dir+"daa073.dbf";

               fc=fopen(fn.c_str(),_T("r"));
               cc=fn;
               File_name=Form5->Jh1[Form5->ic[i9]];
               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)
                       {
                            flag1=3;
                            do{                                                   //读取全部沉积单元
                                  jjhh=Table1->FieldByName("Jh")->AsString;
                                  jjhh=LowerCase(jjhh);flag1=1;
                                  Xhc[ia]=Table1->FieldByName("Xh")->Value;

                                  Yczmcc[ia]=Table1->FieldByName("Yczmc")->AsString;  //油层组名称
                                  Dymcc[ia]=Table1->FieldByName("Dymc")->AsString;  //单元名称
                                  Bzc[ia]=Table1->FieldByName("Bz")->AsString;

                                    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;
                                 jhw[js][i]=Yczmc[i]+Dymc[i];
                                 xcw[js][i]=Dyds[i];
                                 i++;
                                 Table1->Next();

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

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

                  }
                  totalnum[js]=i-1;

               }
               Table1->First();

   }

  Table1->Close();
  fclose(fc);
}
//---------------------------------------------------------------------------
void __fastcall TForm3::N22Click(TObject *Sender)
{
   short i1,i2;float f;
   js=js+1;
   Mod ++;
   Top_deep[js]=0.0;
   int flag,i3;
   Switch=1;
   FILE *fp;
   int Rd_valueGTzero=0;
   int RMN_valueGTzero=0;
   int AC_value=0;
     MN_pos[js]=0;
     MK_pos[js]=0;
     Rd_pos[js]=0;
     Rs_pos[js]=0;
     Ac_pos[js]=0;
     Rxo_pos[js]=0;
     GR_pos[js]=0;
     SP_pos[js]=0;
     DEN_pos[js]=0;

 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[js]=OpenDialog1->Files->Strings[I].c_str();
         ccp[js]=ExtractFileName(OpenDialog1->FileName);
         GetFileName(ccp[js]);

         AnsiString la_location[30],la_name[30],dbf_name[30];
         la_location[js] = OpenDialog1->FileName;
         la_name[js] = ccp[js];
         int length = la_name[js].Length();
         dbf_name[js] = la_name[js].SubString(1,length-2) ;
         dbf_name[js] += "dbf";

         length = la_location[js].Length();
         length = length - la_name[js].Length();
         AnsiString temp = la_location[js].SubString(1,length);
         la_location[js] = temp;

         la_Location[js] = la_location[js];
         la_Name[js] = la_name[js];
         dbf_Name[js] = dbf_name[js];
         daa074_auto_open_path = la_location[js] + "daa073.DBF";

       if(fp){
               fread(str0[js],84,1,fp);
               fread(str1[js],80,1,fp);
               i2=getint(fp);
               i1=getint(fp);
               fread(str[js],80,1,fp);
               //startdp
               stdp[js]=getfloat(fp);
               //endp
               endp[js]=getfloat(fp);
                //cyjj
               relv[js]=getfloat(fp);
               i1=getint(fp);
               i2=getint(fp);
               f=getfloat(fp);
               fread(str11[js],80,1,fp);
               fread(str3[js],148,1,fp);
               for(int i7=0;i7<5000;i7++)
               {
                   for(int j7=1;j7<41;j7++)
                   {
                       a[js][i7][j7]=1.0;
                   }
               }
               // i1=0+int(Top_deep[js]/relv[js]);
               i1=0;
               stedp[js]=int((endp[js]-stdp[js])/relv[js]);
               while(i1<stedp[js])
               {
                    for(int j=1;j<41;j++)
                    {
                        for(int i=i1;i<i1+62;i++)
                        {
                             a[js][i][j]=getfloat(fp);
                        }
                    }
                    i1=i1+62;
               }
             }
     }
 }
    for(int i=0;i<3;i++)
    {
           for(int j=0;j<4;j++)
             {
               temp_index[js][i][j]=-1;
             }
    }
    for(int i0=0;i0<stedp[js];i0++)
    {
         a[js][i0][0]=stdp[js]+i0*relv[js];

    }
  int i4,i,j,ip;
 cname3[js][0][5]="DEPT ";
 i4=1;
 for(i=0;i<80;i+=4)
 {
      i2=0;
      for(j=i;j<i+4;j++)
      {
          if(str[js][j]!=' ')i2++;
      }
      j=i;
      for(i3=0;i3<4;i3++)
      {
          str2[js][i3]=0;
      }
      for(i3=0;i3<i2;i3++)
      {
          str2[js][i3]=str[js][j];
          j++;
      }
      if((str2[js][0]!=' ')&&(str2[js][0]!='\0'))
      {
          cname3[js][i4][5]=str2[js];
          if(strcmp(str2[js],"RMN")==0||strcmp(str2[js],"MNOR")==0)
          {
              MN_pos[js]=i4;
              temp_index[js][0][0]=i4;
          }
          if(strcmp(str2[js],"RML")==0||strcmp(str2[js],"RMK")==0||strcmp(str2[js],"RMM")==0||strcmp(str2[js],"RMG")==0)
          {
               MK_pos[js]=i4;
               temp_index[js][1][0]=i4;
          }
         if(strcmp(str2[js],"RLLD")==0||strcmp(str2[js],"RL3D")==0||strcmp(str2[js],"LLD")==0)
         {
             Rd_pos[js]=i4;
             temp_index[js][0][1]=i4;
         }
         if(strcmp(str2[js],"RLLS")==0||strcmp(str2[js],"RL3S")==0||strcmp(str2[js],"LLS")==0)
         {
             Rs_pos[js]=i4;
             temp_index[js][1][1]=i4;
         }
         if(strcmp(str2[js],"AC")==0||strcmp(str2[js],"DT")==0)
         {
             Ac_pos[js]=i4;
             temp_index[js][0][3]=i4;
         }
         if(strcmp(str2[js],"MSFL")==0||strcmp(str2[js],"RXO")==0)
         {
             Rxo_pos[js]=i4;
             temp_index[js][2][1]=i4;
         }
         if(strcmp(str2[js],"GR")==0)
         {
             GR_pos[js]=i4;
             temp_index[js][0][2]=i4;
         }
         if(strcmp(str2[js],"SP")==0)
         {
             SP_pos[js]=i4;
             temp_index[js][1][2]=i4;
         }
         if(strcmp(str2[js],"DEN")==0)
         {
             DEN_pos[js]=i4;
             temp_index[js][1][3]=i4;
         }
        if(strcmp(str2[js],"HAC")==0)
         {
             HAC_pos[js]=i4;
             temp_index[js][2][3]=i4;
         }
         i4++;
     }
   }
    ip=i4;
    i4=i4-1;
    for(int i0=1;i0<(ip+1);i0++)
    {
          smaxmin(i0);
          ma[js][i0]=max;
          mi[js][i0]=min;
    }
     int po1;
     for(int j1=1;j1<=js;j1++)
     {
          maxp1[j1]=stedp[j1];
     }
     for(int j1=1;j1<=js-1;j1++)
     {
         for(int j2=j1+1;j2<=js;j2++)
         {
             if(maxp1[j1]>maxp1[j2])
             {
                po1=maxp1[j1];
                maxp1[j1]=maxp1[j2];
                maxp1[j2]=po1;
             }
          }
      }
      ScrollBox1->VertScrollBar->Range=maxp1[js]+1200;
      N4Click(Sender);
      PaintBox2->Height=maxp1[1]+113+85+1000;
      Form3->Caption= ccp[js]+"                                       采 油 二 厂 储 层 连 通 性 对 比 技 术";

      //dkcjsjk(Sender);
      open_074(Sender);


      str16[js][10];
      a21lj[js][10];


      for(int i1=0;i1<totalnum[js]+1;i1++)
      {
          str5[js][i1]=jhw[js][i1].c_str();
          str6[js][i1]=jhw[js][i1].c_str();
          a2[js][i1][0]=xcw[js][i1];
      }
      paintfenceng_074(Sender);
      int ooo = ccltwz[js][0];
      fclose(fp); // PaintBox2->Canvas->TextOutA(50,400,newname[js]);

      Form3->ScrollBox1->VertScrollBar->Position = 0;
      Form3->N2->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm3::dkcjsjk(TObject *Sender)  //打开层位数据库 （沉积单元）////////////////////////////////////074daa
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::open_074(TObject *Sender)      //074沉积单元数据库
{
   int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   //int totalnum = 0;
   FILE *fc,*fo;
   int count = 0;
   AnsiString File_name;

   int path = 0;
   if(daa074_auto_open_path != NULL)
   {
        TStringList *lst = new TStringList();
        TSearchRec sr;
        int iAttributes = 0;
        if(FindFirst(daa074_auto_open_path,iAttributes,sr) == 0)
        {
                path = 1;
                File_name = ChangeFileExt(la_Name[js],"");
        }
        FindClose(sr);
   }
   if(path != 1)
   {
        File_name = ChangeFileExt(la_Name[js],"");
        OpenDialog1->Filter="daa074（*.DBF)|*.DBF|所有文件(*.*)|*.*";
        OpenDialog1->Execute();
        path = 2;
   }


   if(path == 2 || path == 1)
   {
        for(int I=0;I<1;I++)
        {
                if(path == 1)
                {
                        fc=fopen(daa074_auto_open_path.c_str(),_T("r"));
                        cc= daa074_auto_open_path.c_str();
                }
                else
                {
                        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();

                        AnsiString Dynscxhc[300];
                        AnsiString Yxc[300];
                        AnsiString Elsydsc[300];
                        AnsiString Elsyhdc[300];
                        AnsiString Ylsydsc[300];
                        AnsiString Dydsc[300];
                        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;
                                                Dydsc[ia]    = Table1->FieldByName("DYDS")->AsString;
                                                ia++;
                                                count ++;
                                                Table1->Next();
                                        }while((jjhh==File_name)&&(!Table1->Eof));
                                        totalnum[js]=count-1;
                                }
                                if((flag1<1)&&(!Table1->Eof))
                                        Table1->Next();
                        }
                        Table1->First();
                        //totalnum=i-1;
                        int temp = 0;
                        for(int i = 0;i < count - 1;i ++)
                        {
                                if(Dydsc[i] == "0" || Dydsc[i] == "")
                                        continue;

                                str16[js][temp] = Yczmcc[i] + Dymcc[i];
                                a21lj[js][temp] = StrToFloat(Dydsc[i]);
                                jhw[js][temp] = str16[js][temp];
                                xcw[js][temp] = a21lj[js][temp];
                                temp ++;
                        }


                }
        }
   ss++;
   }

   Table1->First();
   Table1->Close();
   fclose(fc);
}
//---------------------------------------------------------------------------
void __fastcall TForm3::paintfenceng_074(TObject *Sender)
{
   int max_lines_num = 200;     //最大层数变量


   PaintBox2->Canvas->Pen->Width=1;
   PaintBox2->Canvas->Pen->Style=psSolid;
   PaintBox2->Canvas->Pen->Color=clBlack;
   int ii0=0;
   ljcs[jsi]=0;//老井层数
   float deep1;
   int tw;
   //tw=Form1->Width/2.2;
   int count = 0;

   if(Switch_ss != ss && ss > 0)
   {
        for(int i0=0;i0<stedp[js];i0++)
        {

                deep1=stdp[js]+i0*relv[js];
                if(fabs(a2[js][ii0][0]-deep1)<0.001)
                {
                        tw=dj*(js-1)+2+trackwidth+50+trackwidth;
                        lines[count][js] = dj*(js-1)+4+0;
                        lines[count][js + 50] = i0+Name_Height+81;
                        lines[count][js + 100] = tw+10+trackwidth/2;
                        //lines[count][js + 150] = i0+Name_Height+81;
                        //PaintBox2->Canvas->MoveTo(dj*(jsi-1)+4+0,i0+Name_Height+81);
                        //PaintBox2->Canvas->LineTo(tw+10+trackwidth/2,i0+Name_Height+81);
                        lines_text[count][js] = str6[js][ii0];
                        lines_text[count][js + 50] = AnsiString(FormatFloat("0.0",xcw[js][ii0]));
                        //a2[js][i1][0]=xcw[js][i1];
                        lines_text_px[count][js] = tw+30+4;
                        lines_text_px[count][js + 50] = i0-14+Name_Height+8;
                        //PaintBox2->Canvas->TextOut(tw+30+4, i0- 14 +Name_Height +81,    str6[jsi][ii0]);
                        //PaintBox2->Canvas->TextOut(tw+30+4, i0+ 3  +Name_Height  +81,   AnsiString(FormatFloat("0.0",a2[jsi][ii0][0])));
                        //str16[js][ljcs[js]]=str6[js][ii0];
                        //a21lj[js][ljcs[js]]=a2[js][ii0][0];
                        ccltwz[js][count] = lines[count][js + 50];  //  储层连通位置
                        ljcs[js]=ljcs[jsi]+1;
                        if(ii0<totalnum[js])ii0=ii0+1;
                        while((a2[js][ii0][0]<0.1)&&(ii0<totalnum[js]))
                        {
                        ii0=ii0+1;
                        }
                        count ++;
                        if(str16[js][count] == "")
                        lines[count][js] = -1;
                }
        }
        Switch_ss ++;
   }
   if(Switch_ss == ss && ss > 0)
   {

        for(int i = 0;i < max_lines_num;i ++)
        {
                for(int j = 1;j <= js ;j ++)
                {
                        //if(lines[i][j] == -1)
                                //break;


                        PaintBox2->Canvas->MoveTo(lines[i][j],lines[i][j + 50]);
                        PaintBox2->Canvas->LineTo(lines[i][j + 100],lines[i][j + 50]);
                        PaintBox2->Canvas->Font->Color = clRed;
                        PaintBox2->Canvas->TextOut(lines_text_px[i][j], lines[i][j + 50] - 10,      lines_text[i][j]);
                        PaintBox2->Canvas->TextOut(lines_text_px[i][j], lines[i][j + 50] + 10, lines_text[i][j + 50]);

                }

        }

   }

   if(jsi>=2 && ss > 0)
   {
        cclt(Sender);     //储层连通
   }
  // hdhf(Sender);   2022-12-2注销
   if((jsi>=2)&&(jxdb==1) && ss > 0)
   {
        lthd(Sender);
   }
}
//---------------------------------------------------------------------------
AnsiString change_name6(AnsiString s)
{
        //AnsiString full_name = AnsiString s;
        int length = s.Length();
        AnsiString full_name = s.SubString(1,2);
        AnsiString str0 = "";
        int sw = 0;
        if(s.SubString(length,length) == "a")
        {
                str0 = "顶";
                sw = 1;
        }
        else if(s.SubString(length,length) == "b")
        {
                str0 = "中";
                sw = 2;
        }
        else if(s.SubString(length,length) == "c" || s.SubString(length,length) == "d")
        {
                str0 = "底";
                sw = 3;
        }
        else
        {
                str0 = "顶";
                sw = 4;
        }

        if(full_name == "S1" || full_name == "s1")
                full_name = "萨Ⅰ";
        if(full_name == "S2" || full_name == "s2")
                full_name = "萨Ⅱ";
        if(full_name == "S3" || full_name == "s3")
                full_name = "萨Ⅲ";
        if(full_name == "P1" || full_name == "p1")
                full_name = "葡Ⅰ";
        if(full_name == "P2" || full_name == "p2")
                full_name = "葡Ⅱ";
        if(full_name == "P3" || full_name == "p3")
                full_name = "葡Ⅲ";
        if(full_name == "G1" || full_name == "g1")
                full_name = "高Ⅰ";
        if(full_name == "G2" || full_name == "g2")
                full_name = "高Ⅱ";
        if(full_name == "G3" || full_name == "g3")
                full_name = "高Ⅲ";
        if(full_name == "G4" || full_name == "g4")
                full_name = "高Ⅳ";
        AnsiString temp = s.c_str();
        length = temp.Length();
        if(sw == 1)
        {
                temp =  temp.SubString(3,int(length - 1));
                full_name = full_name + temp;
                full_name = StringReplace(full_name,"a","顶", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 2)
        {
                temp =  s.SubString(3,length - 1);
                full_name = full_name + temp;
                full_name = StringReplace(full_name,"b","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 3)
        {
                temp =  s.SubString(3,length - 1);
                full_name = full_name + temp;
                full_name = StringReplace(full_name,"c","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = StringReplace(full_name,"d","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 4)
                full_name = full_name + s.SubString(3,length) + "顶";
        //String sNewStr1 =StringReplace(wj,"n","南", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        return full_name;
}
//---------------------------------------------------------------------------
AnsiString change_name_single(AnsiString s)
{
        //AnsiString full_name = AnsiString s;
        int length = s.Length();
        AnsiString full_name = s.SubString(1,2);
        AnsiString str0 = "";
        int sw = 0;
        if(s.SubString(length,length) == "a")
        {
                str0 = "顶";
                sw = 1;
        }
        else if(s.SubString(length,length) == "b")
        {
                str0 = "中";
                sw = 2;
        }
        else if(s.SubString(length,length) == "c" || s.SubString(length,length) == "d")
        {
                str0 = "底";
                sw = 3;
        }
        else
        {
                str0 = "顶";
                sw = 4;
        }

        if(full_name == "S1" || full_name == "s1")
                full_name = "萨Ⅰ";
        if(full_name == "S2" || full_name == "s2")
                full_name = "萨Ⅱ";
        if(full_name == "S3" || full_name == "s3")
                full_name = "萨Ⅲ";
        if(full_name == "P1" || full_name == "p1")
                full_name = "葡Ⅰ";
        if(full_name == "P2" || full_name == "p2")
                full_name = "葡Ⅱ";
        if(full_name == "P3" || full_name == "p3")
                full_name = "葡Ⅲ";
        if(full_name == "G1" || full_name == "g1")
                full_name = "高Ⅰ";
        if(full_name == "G2" || full_name == "g2")
                full_name = "高Ⅱ";
        if(full_name == "G3" || full_name == "g3")
                full_name = "高Ⅲ";
        if(full_name == "G4" || full_name == "g4")
                full_name = "高Ⅳ";
        //full_name = full_name + s.SubString(3,length) + str0;

        AnsiString temp = s.c_str();
        length = temp.Length();

        if(sw == 1)
        {
                AnsiString ts = full_name;
                full_name = full_name + s.SubString(3,length) + " - ";
                full_name = StringReplace(full_name,"a","顶", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = full_name + ts + s.SubString(3,length);
                full_name = StringReplace(full_name,"a","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 2)
        {
                AnsiString ts = full_name;
                full_name = full_name + s.SubString(3,length) + " - ";
                full_name = StringReplace(full_name,"b","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = full_name + ts + s.SubString(3,length);
                full_name = StringReplace(full_name,"b","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 3)
        {
                AnsiString ts = full_name;
                full_name = full_name + s.SubString(3,length) + " - ";
                full_name = StringReplace(full_name,"c","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = StringReplace(full_name,"d","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = full_name + ts + s.SubString(3,length);
                full_name = StringReplace(full_name,"d","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = StringReplace(full_name,"c","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 4)
                full_name = full_name + s.SubString(3,length) + "顶 - " + full_name + s.SubString(3,length) + "底";
        //String sNewStr1 =StringReplace(wj,"n","南", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        return full_name;
}
//---------------------------------------------------------------------------
AnsiString change_well_name6(AnsiString s)
{
        int length = s.Length();
        AnsiString well_name = s;
        well_name = StringReplace(well_name,"n","南", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-p","-P", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-sp","-斜P", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-d","-丁", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-f","-更", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        return well_name;
}


