#include "sub.h" extern float rlev,dep,sdep,edep; extern char curvnms[3000][5],units[3000][5],depunit[5],levunit[5]; extern int ircodes[3000],npoints[3000],nsamps[3000],ipost[3000],iexst[3000],ndim[3000]; extern int ncurvs,lframe,nframe,modep; extern WELL_DYNAMIC_INFO *mWellDynamicInfo; void lrcls(unsigned char ctype,int *idrt,int *lrtype) { int ityp[11]={0,34,47,64,128,129,130,131,132,133,232}; *lrtype=ctype; *idrt=-1; for(int i=0;i<10;i++) { if(*lrtype!=ityp[i]) continue; *idrt=i; break; } if(*idrt<0)*idrt=12; } void pratr(unsigned char chatr1,unsigned char chatr2,int *pmatr) { int matr[16]; int icha1=chatr1; int icha2=chatr2; for(int i=0;i<8;i++) { int imx=pow(2.f,(8-i-1)); matr[i]=0; if(icha1>=imx) { matr[i]=1; icha1=icha1-imx; } matr[i+8]=0; if(icha2>=imx) { matr[i+8] = 1; icha2=icha2-imx; } } memcpy(pmatr,&matr[0],16*sizeof(int)); } void rdbufp(FILE *fp,unsigned char *buff,int lbuff,int lrtype,int istats,int maxrl,int nbyte,int ngpbyte) { unsigned char buft[90000]; char buf4[4]; int fd[2],bread[2]; int matr[16]; //-------------------------------------------------------------------- //- nlrs, number of segments of each logical record. ///////let's begin int nlrs=0; lbuff=0; nbyte=0; int len=40000; istats=0; int lprl; while(1) { // read a physical record. int istat=fread(buft,1,len,fp); if(istat==0) { if(istats==0) { istats=-1; return; } istats=0; return; } istats=istat; nbyte=nbyte+istat; for(int i=0;i<4;i++){ buf4[i]=buft[i]; } lprl=buf4[0]*256+buf4[1]; if(lprl<=0) { CString str; str.Format(" logical record length error!lprl < 0",lprl); AfxMessageBox(str); } if(lprl>maxrl) { CString str; str.Format(" logical record length error!lprl > maxrl %d %d",lprl,maxrl); AfxMessageBox(str); } //- get logical record segment attributions int matr[16]; pratr(buf4[2],buf4[3],&matr[0]); // write(0,*)(matr[i],i=1,16) //- cut bytes of logical record trail int npad=0; if(matr[2]==0&&matr[3]==1) { npad=npad+2; } if(matr[5]==1) { npad=npad+2; } if(matr[6]==1) { npad=npad+2; } for(int i=0;imaxrl) { CString str; str.Format(" lrtype=%d",lrtype); //AfxMessageBox(str); } if(idrt>=12) { // istats=0; // stop 9999; // write(0,*) // write(0,*)" idrt > 12"; // write(0,*)" lrtype=",lrtype; } } // //- read a logical record length from disk file. // static int RecNum=0; void rdbuf(FILE *fp,unsigned char *buff,int *lbuff,int *lrtype,int *istats,int maxrl,int *nbyte,int ngpbyte) { unsigned char buft[90000]; unsigned char buf4[4],buf2[2]; int matr[16]; *istats=1; *nbyte=0; //- nlrs, number of segments of each logical record. int nlrs=0 ; *lbuff=0; int lprl; int pos,type; while(1) { // skip gap bytes. int len=ngpbyte; if(len>0) { int istat=fread(buft,len,1,fp); if(istat<=0) goto L100; } *nbyte=*nbyte+ngpbyte; // read physical record header. len=4; int istat=fread(buf4,len,1,fp); if(istat<=0) goto L100; *nbyte=*nbyte+4; lprl=buf4[0]*256+buf4[1]; if(lprl==0) { len=2; istat=fread(buf2,len,1,fp); if(istat<=0) goto L100; *nbyte=*nbyte+2; buf4[0]=buf4[2]; buf4[1]=buf4[3]; buf4[2]=buf2[0]; buf4[3]=buf2[1]; lprl=buf4[0]*256+buf4[1]; } if(lprl<=0) { CString str; str.Format(" logical record length error!lprl < 0",lprl); // AfxMessageBox(str); } if(lprl>maxrl) { CString str; str.Format(" logical record length error!lprl > maxrl %d %d",lprl,maxrl); //AfxMessageBox(str); } //- get logical record segment attributions int matr[16]; pratr(buf4[2],buf4[3],matr);//&matr[0]); // write(0,*)(matr[i],i=1,16); // read a physical record. len=lprl-4 ; //2???解文件m5_DIL.dat时,读到第三个类型为42的记录后,运行到此处,lprl=4,此时会引起len=0,istat<=0,在主程序中break,读不到曲线信息,无法正确扫描 pos=ftell(fp); istat=fread(buft,len,1,fp); if(istat<=0) goto L100; *nbyte=*nbyte+lprl-4; //- cut bytes of logical record trail int npad=0; if(matr[2]==0&&matr[3]==1) { npad=npad+2; } if(matr[5]==1) { npad=npad+2; } if(matr[6]==1) { npad=npad+2; } for(int i=0;imaxrl) { CString str; str.Format(" lrtype=%d",*lrtype); //AfxMessageBox(str); } if(idrt>=12) { // istats=0; // stop 9999; // write(0,*) // write(0,*)" idrt > 12"; // write(0,*)" lrtype=",lrtype; } // write(0,"(5x,a,i5)")"successive segments total sum :",nlrs; return; L100: *istats=-1; } // output vol.(reel) header information // CString reelhd(char *buff) { /*char cvalue[10000]; for(int i=0;i<500;i++) { cvalue[i]=buff[i]; }*/ char buffer[5000]; char mes[128]; char sn[8],crdate[8],ds[8],vn[8],ln[8]; int nele[6],value[100],lcval[1000]; CString smes,str=" *** vol. header ***\r\n-----------------------------------\r\n"; sprintf(buffer," *** vol. header ***\r\n-----------------------------------\r\n"); strncpy(mes,&buff[2],6);mes[6]=0; sprintf(buffer,"%ssevice name: %s\r\n",buffer,mes); //str.Format("%ssevice name: %s\r\n",str,mes); strncpy(mes,&buff[14],22-15+1);mes[22-15+1]=0; //str.Format("%screate datee: %s\r\n",str,mes); sprintf(buffer,"%screate datee: %s\r\n",buffer,mes); strncpy(mes,&buff[24],4);mes[4]=0; //str.Format("%sdata source: %s\r\n",str,mes); sprintf(buffer,"%sdata source: %s\r\n",buffer,mes); strncpy(mes,&buff[30],8);mes[8]=0; //str.Format("%svolumn name: %s\r\n",str,mes); sprintf(buffer,"%svolumn name: %s\r\n",buffer,mes); strncpy(mes,&buff[42],2);mes[2]=0; //str.Format("%slink number: %s\r\n",str,mes); sprintf(buffer,"%slink number: %s\r\n",buffer,mes); strncpy(mes,&buff[44],8);mes[8]=0; //str.Format("%sbefore vol.: %s\r\n",str,mes); sprintf(buffer,"%sbefore vol.: %s\r\n",buffer,mes); strncpy(mes,&buff[54],128-55+1);mes[128-55+1]=0; //str.Format("%scomment: %s\r\n",str,mes); sprintf(buffer,"%scomment: %s\r\n",buffer,mes); str.Format("%s",buffer); int ndim=1; nele[0]=1; int ivorg=0; int ivcopy=0; //strcpy(cvalue," "); strncpy(sn,&buff[2],6);sn[6]=0; lcval[0]=strlen(sn);//lenstr(sn,8); // wparfl("sn","sevice name","asci",ndim,nele,ivorg,ivcopy," ",value,sn,lcval); smes.Format("sn sevice name","asci",ndim,nele,ivorg,ivcopy," ",value,sn,lcval); strcpy(crdate,""); for(int l=0;l<8;l++) { crdate[l]=buff[l+14]; } lcval[0]=strlen(crdate); // wparfl("crdate","create date","asci",ndim,nele,ivorg, //$ ivcopy," ",value,crdate,lcval); strcpy(ds,""); for(int l=0;l<4;l++)ds[l]=buff[l+24]; lcval[0]=strlen(ds); // wparfl("ds","data source","asci",ndim,nele,ivorg, // $ ivcopy," ",value,ds,lcval); strcpy(vn,""); for(int l=0;l<8;l++){ vn[l]=buff[l+30]; } lcval[0]=strlen(vn); // wparfl("vn","volumn name","asci",ndim,nele,ivorg, // $ ivcopy," ",value,vn,lcval); strcpy(ln,""); for(int l=0;l<2;l++){ ln[l]=buff[l+40]; } lcval[0]=strlen(ln); // wparfl("ln","link number","asci",ndim,nele,ivorg, // $ ivcopy," ",value,ln,lcval); return str;//mes; } // // output tape header information // CString tapehd(char *buff) { char mes[128]; char buffer[5000]; //char cvalue[10000]; char sn[8],crdate[8],ds[8],tn[8],ln[8]; int nele[6],lcval[1000]; float value[100]; CString smes,str=" *** tape header ***\r\n-----------------------------------\r\n"; sprintf(buffer," *** tape header ***\r\n-----------------------------------\r\n"); strncpy(mes,&buff[2],6);mes[6]=0; //str.Format("%ssevice name: %s\r\n",str,mes); sprintf(buffer,"%ssevice name: %s\r\n",buffer,mes); strncpy(mes,&buff[14],22-15+1);mes[22-15+1]=0; //str.Format("%screate datee: %s\r\n",str,mes); sprintf(buffer,"%screate datee: %s\r\n",buffer,mes); strncpy(mes,&buff[24],4);mes[4]=0; // str.Format("%sdata source: %s\r\n",str,mes); sprintf(buffer,"%ssdata source: %s\r\n",buffer,mes); strncpy(mes,&buff[30],8);mes[8]=0; //str.Format("%svolumn name: %s\r\n",str,mes); sprintf(buffer,"%svolumn name: %s\r\n",buffer,mes); strncpy(mes,&buff[42],2);mes[2]=0; //str.Format("%slink number: %s\r\n",str,mes); sprintf(buffer,"%slink number: %s\r\n",buffer,mes); strncpy(mes,&buff[44],8);mes[8]=0; //str.Format("%sbefore vol.: %s\r\n",str,mes); sprintf(buffer,"%sbefore vol.: %s\r\n",buffer,mes); strncpy(mes,&buff[54],128-55+1);mes[128-55+1]=0; //str.Format("%scomment: %s\r\n",str,mes); sprintf(buffer,"%scomment: %s\r\n",buffer,mes); str.Format("%s",buffer); int ndim=1; nele[0]=1; int ivorg=0; int ivcopy=1; //strcpy(cvalue," "); strncpy(sn,&buff[2],6);sn[6]=0; lcval[0]=strlen(sn);//lenstr(sn,8); // wparfl("sn","sevice name","asci",ndim,nele,ivorg,ivcopy," ",value,sn,lcval); smes.Format("sn sevice name","asci",ndim,nele,ivorg,ivcopy," ",value,sn,lcval); strcpy(crdate,""); for(int l=0;l<8;l++) { crdate[l]=buff[l+14]; } lcval[0]=strlen(crdate); // wparfl("crdate","create date","asci",ndim,nele,ivorg, //$ ivcopy," ",value,crdate,lcval); strcpy(ds,""); for(int l=0;l<4;l++)ds[l]=buff[l+24]; lcval[0]=strlen(ds); // wparfl("ds","data source","asci",ndim,nele,ivorg, // $ ivcopy," ",value,ds,lcval); strcpy(tn,""); for(int l=0;l<8;l++){ tn[l]=buff[l+30]; } lcval[0]=strlen(tn); // wparfl("vn","volumn name","asci",ndim,nele,ivorg, // $ ivcopy," ",value,tn,lcval); strcpy(ln,""); for(int l=0;l<2;l++){ ln[l]=buff[l+40]; } lcval[0]=strlen(ln); // wparfl("ln","link number","asci",ndim,nele,ivorg, // $ ivcopy," ",value,ln,lcval); return str;//mes; } CString CharToCstring(char *buf,int len) { char *mes; mes=new char[len+1]; strncpy(mes,buf,len); for(int i=0;iDate,&buff[28],36-29+1); smes=CString("MAX. RECORD LENGTH :")+CharToCstring(&buff[37],42-38+1);str+=smes+"\r\n"; smes=CString("FILE TYPE :")+CharToCstring(&buff[43],3);str+=smes+"\r\n";//smes="FILE TYPE :"+CharToCstring(&buff[43],2);str+=smes+"\r\n"; smes=CString("BEFORE FILE NAME :")+CharToCstring(&buff[45],55-46+1);str+=smes+"\r\n"; // get maximum logical record length(maxrl). for(int i=0;i<5;i++) { buft[i]=buff[37+i]; } sscanf(buft,"%d",maxrl); //read(buft,*) /* int ndim=1; nele[0]=1; int ivorg=0; int ivcopy=0; strcpy(cvalue," "); strcpy(fileid,""); for(int l=0;l<8;l++) { fileid[l]=buff[l+2]; } lcval[0]=strlen(fileid); // wparfl("fileid","file name","asci",ndim,nele,ivorg, // $ ivcopy," ",value,fileid,lcval); strcpy(ssn,""); for(int l=0;l<6;l++){ ssn[l]=buff[l+14]; } lcval[0]=strlen(ssn); // wparfl("ssn","second sevice name","asci",ndim,nele,ivorg, // $ ivcopy," ",value,ssn,lcval); strcpy(fileno,""); for(int l=0;l<6;l++) { fileno[l]=buff[l+21]; } lcval[0]=strlen(fileno); // wparfl("fileno","file number","asci",ndim,nele,ivorg, // $ ivcopy," ",value,fileno,lcval); strcpy(date,""); for(int l=0;l<8;l++){ date[l]=buff[l+28]; } lcval[1]=strlen(date); //wparfl("date","create date","asci",ndim,nele,ivorg, // $ ivcopy," ",value,date,lcval); strcpy(filety,""); for(int l=0;l<2;l++){ filety[l]=buff[l+43]; } lcval[0]=strlen(filety);*/ // wparfl("filety","file type","asci",ndim,nele,ivorg, // $ ivcopy," ",value,filety,lcval); return str; } float unitfactor(char *depunit,int len) { char unit[8]; float unitfactor=1.; int i; for(i=0;i=128) { is=-1; ie=(iv1-128)*2+iv/128; } else { is=1 ; ie=iv1*2+iv/128 ; } v4.cha4[3]=buff[ips+(i)*4]; v4.cha4[2]=buff[ips+(i)*4+1]; v4.cha4[1]=buff[ips+(i)*4+2]; v4.cha4[0]=buff[ips+(i)*4+3]; if(is>0) value[i]=0.5*v4.vg4-pow(2.f,(ie-128)); else value[i]=-v4.vg4*pow(2.f,(254-2*ie))-pow(2.f,(128-ie)); } // write(0,*)"value=",value[i],vals,vg4,ie; } else if(irecod==70) { for(int i=0;i0&&spacing-0.099999994<0.000000006) spacing=0.1; else if(spacing-0.0024>0&&spacing-0.0024<0.0001) spacing=0.0025; } else if(itype==9) { notes="level unit."; for(int i=0;i=lbuff-2) break ; }//while end str+=CString("-----------------------------------\r\n"); if(iswitab==0)str+=CString("no. curve_nm tool_nm sevice unit log_typ cv_typ cv_lev cv_mod fn len_smp 0_1 proc num_smp re_code 0_2 0_3 ndim\r\n"); else str+=CString("no. curve_nm unit cv_mod len_smp num_smp re_code ndim Process Indicators\r\n"); for(int i=0;i>m)&0x1)CIndicators[24-m-1]='1'; else CIndicators[24-m-1]='0'; } if(iswitab==0)ss.Format(("%5d,%4s %8s %8s %4s %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d\r\n"), ncurv, curvnm,toolnm,sevice,unit,itylog,itycuv,icvlev,icvmod,ifn,lensmp,i1l0,ipclev,nsmap,ircode,i2l0,i3l0,lensmp/lbytes(ircode)/nsmap); else ss.Format(("%5d,%4s %4s %6d %6d %6d %6d %6d %s\r\n"),ncurv,curvnm,unit,icvmod,lensmp,nsmap,ircode,lensmp/lbytes(ircode)/nsmap,CIndicators ); if(ncurvs==0) { strcpy(curvnms[ncurv],curvnm); iexst[ncurv]=1; strcpy(units[ncurv],unit) ; ircodes[ncurv]=ircode; nsamps[ncurv]=nsmap; npoints[ncurv]=lensmp/lbytes(ircode) ; if(npoints[ncurv]>1) { int a=1; } ipost[ncurv]=nfbyte+1; ndim[ncurv]=lensmp/lbytes(ircode)/nsmap; } else { for(int i=0;i0) { iexst[i]=1; strcpy(units[i],unit); ircodes[i]=ircode; nsamps[i]=nsmap; npoints[i]=lensmp/lbytes(ircode); ipost[i]=nfbyte+1; ndim[ncurv]=lensmp/lbytes(ircode)/nsmap; } } } if(modep ==0) { if(strcmp(curvnm,"dept")==0||strcmp(curvnm,"DEPT")==0) { if(ncurvs==0) { strcpy(curvnms[2999],"DEPT"); iexst[2999]=1; strcpy(units[2999],unit); strcpy(depunit,unit); ircodes[2999]=ircode; nsamps[2999]=nsmap; npoints[2999]=lensmp/lbytes(ircode); ipost[2999]=nfbyte+1; ndim[ncurv]=lensmp/lbytes(ircode)/nsmap; } else { strcpy(curvnms[ncurvs],"DEPT"); iexst[ncurvs]=1; strcpy(units[ncurvs],unit); strcpy(depunit,unit); ircodes[ncurvs]=ircode; nsamps[ncurvs]=nsmap; npoints[ncurvs]=lensmp/lbytes(ircode) ; ipost[ncurvs]=nfbyte+1; ndim[ncurv]=lensmp/lbytes(ircode)/nsmap; } } } nfbyte=nfbyte+abs(lensmp); str+=ss; if(ip>=lbuff-2)break; } CString sys[18]={ " 0 23456789012345 23", "0 Original logging direction ________________| |||||||||||||| ||", "2 TRUE vertical depth correction ______________|||||||||||||| ||", "3 Data channel not on depth ____________________||||||||||||| ||", "4 Data channel is filtered ______________________|||||||||||| ||", "5 Data channel is calibrated _____________________||||||||||| ||", "6 Computed (processed through a function former)___|||||||||| ||", "7 Derived (computed from more than one tool) _______||||||||| ||", "8 Tool defined correction 2 _________________________|||||||| ||", "9 Tool defined correction 1 __________________________||||||| ||", "0 Mudcake correction __________________________________|||||| ||", "1 Lithology correction _________________________________||||| ||", "2 Inclinometry correction _______________________________|||| ||", "3 Pressure correction ____________________________________||| ||", "4 Borehole correction _____________________________________|| ||", "5 Temperature correction ___________________________________| ||", "2 Auxiliary data flag _____________________________________________||", "3 Schlumberger proprietary _________________________________________|"}; for(int m=0;m<18;m++){ str+=CString(" ")+sys[m]; str+=CString("\r\n"); } rlev=ldir*abs(spacing); lframe=nfbyte; if(ncurvs==0) { ncurvs=ncurv+1; if(modep==0) { strcpy(curvnms[ncurv+1],curvnms[2999]); iexst[ncurv+1]=iexst[2999]; strcpy(units[ncurv+1],units[2999]); ircodes[ncurv+1]=ircodes[2999]; nsamps[ncurv+1]=nsamps[2999]; npoints[ncurv+1]=npoints[2999]; ipost[ncurv+1]=ipost[2999]; } } if(modep==1) { strcpy(curvnms[ncurvs],"dept"); iexst[ncurvs]=1; ipost[ncurvs]=1; ircodes[ncurvs]=icodep; strcpy(units[ncurvs],depunit); } //AfxMessageBox(str); int len=str.GetLength(); return str; } // output information record. // // iswitab, output information table switch. // =0, vertical table. // >0, horizontal table. // <0, not output // CString infrec(char *buff,int lbuff,int iswitab) { CString str,mstr;; char title[5]; char name[5],unit[5]; char titls[40][4],cval[40][20],cvtem[200]; // char cvalue[200]; float value[100]; float vcv[40]; int ircd[40],lcv[40]; char ccv[40][200]; str=" *** information record ***\r\n-----------------------------------\r\n"; int ip=2,ncos=0,nlis=0; while(1) { int itype= (unsigned char)(buff[ip+0]); int icode= (unsigned char)(buff[ip+1]); int len= (unsigned char)(buff[ip+2]); int numb= (unsigned char)(buff[ip+3]); if(itype==73) { char *ss; ss=new char[len+1]; strncpy(ss,&buff[ip+12],len); pchar(ss,len); str+=CString("information type: ")+CharToCstring(ss,len)+"\r\n"+"-----------------------------------\r\n"; delete ss; for(int i=0;i<4;i++)title[i]=buff[ip+12+i]; pchar(title,4); mstr.Format("title=%s\r\n",title); str+=mstr; if(iswitab==0) { str+=CString("type code len number name unit value\r\n"); } nlis=0; } else if(itype==0) { if(ncos>0) { str+=CString("ww\r\n"); for(int k=0;k=1) { if(nlis==2) { for(int i=0;i=2) { for(int i=0;i20) { for(int i=0;i<19;i++)cval[ncos][i]=buff[ip+12+i]; cval[ncos][19]='-'; } else { strcpy(cval[ncos]," "); for(int i=0;i=lbuff-4)break; } if(iswitab>=0) { for(int i=0;i