logplus/tran/LISConvertor/src/sub.cpp

1362 lines
33 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;i<lprl-4-npad;i++)
{
buff[i+lbuff]=buft[i+4];
}
if(lbuff!=.0&&matr[14]==0)
{
AfxMessageBox("logical link error!");
exit(0);
}
lbuff=lbuff+lprl-4-npad;
nlrs=nlrs+1;
if(matr[15]!=1) break;
}
//- get and output logical record type
int idrt,rdbufp;
lrcls(buff[0],&idrt,&lrtype);
if(lprl>maxrl)
{
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???<3F><><EFBFBD>ļ<EFBFBD>m5_DIL.datʱ<74><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ42<34>ļ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>˴<EFBFBD><CBB4><EFBFBD>lprl=4<><34><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>len=0<><30>istat<=0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>break<61><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>޷<EFBFBD><DEB7><EFBFBD>ȷɨ<C8B7><C9A8>
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;i<lprl-4-npad;i++)
{
buff[i+*lbuff]=buft[i];
}
if(*lbuff!=0&&matr[14]==0)
{
AfxMessageBox("logical link error!");
return;
}
*lbuff=*lbuff+lprl-4-npad;
nlrs=nlrs+1;
if(matr[15]!=1) break;
}
//- get and output logical record type
int idrt,rdbufp;
lrcls(buff[0],&idrt,lrtype);
type=*lrtype;RecNum++;
if(lprl>maxrl)
{
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;i<len;i++)
{
if(mes[i]==0)
{
len=i;
break;
}
}
mes[len]=0;
CString str;
str.Format("%s",mes);
delete mes;
return str;
}
// output file header information
//
CString filehd(char *buff,int *maxrl)
{
char mes[128];
char buft[5];
//char cvalue[10000];
char fileid[8],ssn[8],fileno[8],date[8],filety[8];
int nele[6],lcval[1000];
float value[100];
//---------------------------------------------------
CString smes,str="";
smes=CString("FILE NAME :")+CharToCstring(&buff[2],12-3+1);str+=smes+"\r\n";
smes=CString("SECOND SEVICE NAME :")+CharToCstring(&buff[14],27-22+1);str+=smes+"\r\n";
smes=CString("VERSION :")+CharToCstring(&buff[21],6);str+=smes+"\r\n";//smes="FILE NUMBER :"+CharToCstring(&buff[21],6);str+=smes+"\r\n";
smes=CString("CREATE DATE :")+CharToCstring(&buff[28],36-29+1);str+=smes+"\r\n";
strncpy(mWellDynamicInfo->Date,&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<len;i++)
{
if(depunit[i]==' '||depunit[i]==0)break;
}
if(i==0)return unitfactor;
/*for(int j=i-1;j<len;j++)
{
int k=j-i+1;
unit[k]=depunit[j];
}*/
depunit[i]=0;
CString str=CharToCstring(depunit,4);
if(str==(".1IN")||str==(".1in"))unitfactor=0.00254;
else if(str==("FT")||str==("ft")||str==("F")||str==("f"))unitfactor=0.0254*12;
else if(str==("M")||str==("m"))unitfactor=1;
else if(str==("DM")||str==("dm"))unitfactor=0.1;
else if(str==("CM")||str==("cm"))unitfactor=0.01;
else if(str==("MM")||str==("mm"))unitfactor=0.001;
else if(str==(".5MM")||str==(".5mm"))unitfactor=0.000500;
else unitfactor=1;
return unitfactor;
}
// this subroutine converts data with various format into a 32-bit
// floating point number
//
// value[nsamp] - array, convert values.
// nsamp - number of samples points.
// irecod - data representation code.
// buff - record body [include lrh(2 bytes).
// lbuff - length of record body buff.
// ips - start positon of string being converted.
//
void convrt(float *value,unsigned char *buff,int lbuff,int ips,int irecod,int nsamp)
{
ips--;
unsigned char cha2[2],cha4[4];
//short ivg2;
/* equivalence (cha2,ivg2);
equivalence (cha4,ivg4);
equivalence (cha4,vg4);*/
union UVAL2
{
unsigned char cha2[2];
ushort ivg2;
}uv2;
union VAL2
{
unsigned char cha2[2];
short ivg2;
}v2;
union VAL4
{
unsigned char cha4[4];
int ivg4;
float vg4;
}v4;
//----------------------------------------------------------------
int iv,iv1,iv2,ie;
if(irecod==49)
{
for(int i=0;i<nsamp;i++)
{
v2.cha2[0]=buff[ips+(i)*2];
v2.cha2[1]=buff[ips+(i)*2+1];
iv1=buff[ips+(i)*2];
iv2=buff[ips+(i)*2+1];
ie=iv2%16;
value[i]=float(iv1*16+iv2/16)*pow(2.f,(ie-11));
}
}
else if(irecod==50)
{
for(int i=0;i<nsamp;i++)
{
v2.cha2[0]=buff[ips+(i)*4];
v2.cha2[1]=buff[ips+(i)*4+1];
iv1=v2.ivg2;
v2.cha2[0]=buff[ips+(i)*4+2];
v2.cha2[1]=buff[ips+(i)*4+3];
iv2=v2.ivg2;
value[i]=float(iv2)*pow(2.f,(iv1-15));
}
}
else if(irecod==56) //<2F>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>ַ<EFBFBD>
{
for(int i=0;i<nsamp;i++)
{
iv1=buff[ips+i];
value[i]=float(iv1);
}
}
else if(irecod==66) //<2F>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>ַ<EFBFBD>
{
for(int i=0;i<nsamp;i++)
{
iv1=(unsigned char)buff[ips+i];
value[i]=float(iv1);
}
}
else if(irecod==68) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
for(int i=0;i<nsamp;i++)
{
iv1=(unsigned char)buff[ips+(i)*4];
iv2=(unsigned char)buff[ips+(i)*4+1];
iv=iv2;
int is;
if(iv1>=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;i<nsamp;i++)
{
v2.cha2[0]=buff[ips+(i)*4];//why is 4
v2.cha2[1]=buff[ips+(i)*4+1];
int im=(buff[ips+(i)*4+2])*256+(buff[ips+(i)*4+3]);
value[i]=float(v2.ivg2)+float(im)*pow(2.f,-16);
}
}
else if(irecod==73) //<2F><><EFBFBD><EFBFBD>
{
for(int i=0;i<nsamp;i++)
{
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];
value[i]=float(v4.ivg4);
}
}
else if(irecod==79)//<2F>޷<EFBFBD><DEB7><EFBFBD>2<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
{
for(int i=0;i<nsamp;i++)
{
v2.cha2[1]=buff[ips+(i)*2];
v2.cha2[0]=buff[ips+(i)*2+1];
value[i]=float(v2.ivg2);
}
}
else if(irecod==234)//<2F>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
{
for(int i=0;i<nsamp;i++)
{
value[i]=float((unsigned char)(buff[ips+i]));
}
}
}
void pchar(char *cval,int len)
{
int i;
for(i=0;i<len;i++)
{
int ich=cval[i];
if(ich<33) cval[i]=' ';
}
for(i=0;i<len;i++)if(cval[i]==' ')break;
cval[i]=0;
}
int lbytes(int ircode)
{
int lbytes;
if(ircode==49) lbytes=2;
else if(ircode==50)
lbytes=4;
else if(ircode==56)
lbytes=1;
else if(ircode==65)
lbytes=1;
else if(ircode==66)
lbytes=1;
else if(ircode==68)
lbytes=4;
else if(ircode==70)
lbytes=4;
else if(ircode==73)
lbytes=4;
else if(ircode==77)
lbytes=1;
else if(ircode==79)
lbytes=2;
else if(ircode==128)
lbytes=1;
else if(ircode==234)
lbytes=1;
return lbytes;
}
int lwbytes(int ircode)
{
int lwbytes;
if(ircode==49)
lwbytes=4;
else if(ircode==50)
lwbytes=4;
else if(ircode==56)
lwbytes=2;
else if(ircode==65)
lwbytes=1;
else if(ircode==66)
lwbytes=2;
else if(ircode==68)
lwbytes=4;
else if(ircode==70)
lwbytes=4;
else if(ircode==73)
lwbytes=4;
else if(ircode==77)
lwbytes=1;
else if(ircode==79)
lwbytes=2;
else if(ircode==128)
lwbytes=1;
else if(ircode==234)
lwbytes=4;
return lwbytes;
}
//
// function idtype(ircode)
//
int idtype(int ircode)
{
int idtype;
if(ircode==49)
idtype=0;
else if(ircode==50)
idtype=0;
else if(ircode==56)
idtype=1;
else if(ircode==65)
idtype=2;
else if(ircode==66)
idtype=1;
else if(ircode==68)
idtype=0;
else if(ircode==70)
idtype=0;
else if(ircode==73)
idtype=1;
else if(ircode==77)
idtype=2;
else if(ircode==79)
idtype=1;
else if(ircode==128)
idtype=2;
else if(ircode==234)
idtype=0;
return idtype;
}
//
// function cdtype(ircode);
//
void scdtype(char *cdtype,int ircode)
{
if(ircode==49)
strcpy(cdtype,"real");
else if(ircode==50)
strcpy(cdtype,"real");
else if(ircode==56)
strcpy(cdtype,"int2");
else if(ircode==65)
strcpy(cdtype,"char");
else if(ircode==66)
strcpy(cdtype,"int2");
else if(ircode==68)
strcpy(cdtype,"real");
else if(ircode==70)
strcpy(cdtype,"real");
else if(ircode==73)
strcpy(cdtype,"int4");
else if(ircode==77)
strcpy(cdtype,"char");
else if(ircode==79)
strcpy(cdtype,"int2");
else if(ircode==128)
strcpy(cdtype,"char");
else if(ircode==234)
strcpy(cdtype,"real");
}
// output format specification record information.
//
// iswittab, output table control switch
// = 0, all content output
// = 1, simple output
//
CString formsp(char *buff,int lbuff,int iswitab)
{
float value[100000];
char curvnm[5],toolnm[7],sevice[9],unit[5];
char deprcunit[5];
int icodep,lensmp,ircode;
CString str=(" \r\n*** format specification: ***\r\n-----------------------------------\r\n\r\ntype len code value comment\r\n");
int ldir=-1;
int ip=2;
CString notes,ss;
float spacing;
while(1)
{
int itype= (unsigned char)buff[ip+0];
int len= (unsigned char)buff[ip+1];
int icode= (unsigned char)buff[ip+2];
int ips=ip+4;
int nsamp=1;
convrt(&value[0],(unsigned char *)buff,lbuff,ips,icode,nsamp);
notes=(" ") ;
if(itype==0)notes="item block end!";
else if(itype==1)notes="type number of data record.";
else if(itype==2)notes="type number of data spec_block.";
else if(itype==3)
{
notes="maximum length(bytes) of a frame.";
}
else if(itype==4)
{
notes="";
if(int(value[0])==255)
{
notes="log_direction: up - bottom (go down)";
ldir=1;
}
else if(int(value[0])==1)
{
notes="log_direction: bottom - up (go up)";
ldir=-1;
}
}
else if(itype==5)
{
notes="depth record unit: ft";
strcpy(deprcunit,"ft");
if(int(value[0])==0)
{
notes="depth record unit: time" ;
strcpy(deprcunit,"time");
}
else if(int(value[0])==255)
{
notes="depth record unit: m";
strcpy(deprcunit,"m");
}
}
else if(itype==6)
{
notes="reference point distant.";//1???<3F><><EFBFBD><EFBFBD>:Csu.cn_den.dat<61>ļ<EFBFBD><C4BC><EFBFBD>forwardɨ<64><C9A8><EFBFBD><EFBFBD>ֵΪ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ-11<31><31>why?
}
else if(itype==7) notes="distant unit";
else if(itype==8)
{
notes="level spacing.";
spacing=value[0];
if(spacing-0.099999994>0&&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<len;i++)levunit[i]=buff[ip+3+i];
pchar(levunit,len);
}
else if(itype==10) notes=" ";
else if(itype==11)
{
notes="number of frames a data record.";
nframe=int(value[0]);
}
else if(itype==12) notes="absent value." ;
else if(itype==13)
{
notes="depth mode(0/1), 0 -depth is a curve.";
modep=int(value[0]);
}
else if(itype==14)
{
notes="depth unit.";
for(int i=0;i<len;i++)depunit[i]=buff[ip+i+3] ;
pchar(depunit,len);
}
else if(itype==15)
{
notes="depth re_code.";
icodep=int(value[0]);
}
else if(itype==16)
{
notes="sub_type number of data spec_block.";
}
if(icode==49||icode==50||icode==68||icode==70)ss.Format(("%4d,%4d,%4d,%12.4f "),itype,len,icode,value[0]);
else if(icode==56||icode==66||icode==73||icode==79)ss.Format(("%4d,%4d,%4d,%12d "),itype,len,icode,int(value[0]));
else
{
char ttt[100];
strncpy(ttt,&buff[4+ip-1],len);
pchar(ttt,len);
ss.Format(("%4d,%4d,%4d, %4s "),itype,len,icode,ttt);
}
ss+=notes;
str+=ss+("\r\n");
ip=ip+3+len;
if(itype==0) break;
if(ip>=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<ncurvs+1;i++)
{
iexst[i]=0;
}
int ncurv=-1;
int nfbyte=0;
//AfxMessageBox(str);
while(1)
{
ncurv=ncurv+1 ;
// -curve name, (buff[ip+i],i=1,4)
for(int i=0;i<4;i++)curvnm[i]=buff[ip+i];
pchar(curvnm,4);
ip=ip+4;
// -tool name ,(buff[ip+i],i=1,6)
for(int i=0;i<6;i++) toolnm[i]=buff[ip+i];
pchar(toolnm,6);
ip=ip+6;
for(int i=0;i<8;i++) sevice[i]=buff[ip+i] ;
pchar(sevice,8);
ip=ip+8;
for(int i=0;i<4;i++)unit[i]=buff[ip+i] ;
pchar(unit,4);
ip=ip+4;
int itylog=(unsigned char)(buff[ip+0]);
int itycuv=(unsigned char)(buff[ip+1]);
int icvlev=(unsigned char)(buff[ip+2]);
int icvmod=(unsigned char)(buff[ip+3]);
ip=ip+4;
int ips=ip+1;
int nsamp=1;
int icode=79;
convrt(&value[0],(unsigned char *)buff,lbuff,ips,icode,nsamp);
int ifn=int(value[0]);
ip=ip+2;
ips=ip+1;
nsamp=1;
icode=79;
convrt(&value[0],(unsigned char *)buff,lbuff,ips,icode,nsamp);
lensmp=int(value[0]);
ip=ip+2;
ips=ip+1;
nsamp=1;
icode=79;
convrt(&value[0],(unsigned char *)buff,lbuff,ips,icode,nsamp);
int i1l0=int(value[0]);
ip=ip+2;
int ipclev=(unsigned char)(buff[ip+0]);
int nsmap=((unsigned char)buff[ip+1]);
ircode=(unsigned char)(buff[ip+2]);
int i2l0=(unsigned char)(buff[ip+3]);
ip=ip+4;
ips=ip+1;
nsamp=1;
icode=79;
convrt(&value[0],(unsigned char *)buff,lbuff,ips,icode,nsamp);
int i3l0=int(value[0]) ;
ip=ip+4;
char CIndicators[25];
int ic=((i2l0<<16)&0xff0000)+i3l0;
//ic+=i3l0;
//int hh=(i2l0<<16)&0xff0000+i3l0; hh!=ic why?
CIndicators[24]=0;
for(int m=0;m<24;m++)
{
if((ic>>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;i<ncurvs;i++)
{
if(curvnms[i]==curvnm&&iexst[i]!=1&&lensmp>0)
{
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<ncos;k++)
{
mstr.Format("%d %s ",k,cval[k]);str+=mstr;
}
str+=CString("\r\n");
}
nlis=nlis+1;
if(iswitab>=1)
{
if(nlis==2)
{
for(int i=0;i<ncos;i++)
{
mstr.Format("%s ",titls[i]);
str+=mstr;
}
str+=CString("\r\n");
}
if(nlis>=2)
{
for(int i=0;i<ncos;i++)
{
pchar(cval[i],20);
mstr.Format("%s ",titls[i]);
str+=mstr;
}
str+=CString("\r\n");
}
}
ncos=1;
}
else if(itype==69)ncos=ncos+1;
for(int i=0;i<4;i++)name[i]=buff[ip+4+i];name[4]=0;
if(nlis==1)strcpy(titls[ncos],name);
pchar(titls[ncos],4);
for(int i=0;i<4;i++)unit[i]=buff[ip+8+i];unit[4]=0;
pchar(unit,4);
int ips=ip+12+1;
int nsamp=1;
if(icode==49||icode==50||icode==68||icode==70)
{
convrt(&value[0],(unsigned char *)buff,lbuff,ips,icode,nsamp);
if(iswitab==0)
{
mstr.Format("%4d %4d %4d %4d %4s %4s %12.4f\r\n",itype,icode,len,numb,name,unit,value[0]);
}
sprintf(cvtem,"%f",value[0]);
strcpy(cval[ncos],cvtem);
if(strcmp(title,"cons")==0)
{
ircd[ncos]=0;
vcv[ncos]=value[0];
}
}
else if(icode==56||icode==66||icode==73||icode==79)
{
convrt(&value[0],(unsigned char *)buff,lbuff,ips,icode,nsamp);
if(iswitab==0)
{
mstr.Format("%4d %4d %4d %4d %4s %4s %12d\r\n",itype,icode,len,numb,name,unit,(int)value[0]);
}
sprintf(cvtem,"%12d ",int(value[0]));
strcpy(cval[ncos],cvtem);
if(strcmp(title,"cons")==0)
{
ircd[ncos]=1;
vcv[ncos]=value[0];
}
}
else
{
if(iswitab==0)
{
if(len<1)
{
//len=1;
}
char *ss;
ss=new char[len+1];
strncpy(ss,&buff[ip+12],len);ss[len]=0;
mstr.Format("%4d %4d %4d %4d %s %s %s\r\n",itype,icode,len,numb,name,unit,ss);
delete ss;
}
if(len>20)
{
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<len;i++)cval[ncos][i]=buff[ip+12+i];
pchar(cval[ncos],len);
}
if(strcmp(title,"cons")==0)
{
ircd[ncos]=2;
lcv[ncos]=len;
for(int i=0;i<len;i++)ccv[ncos][i]=buff[ip+12+i ];
}
}
ip=ip+12+len;
str+=mstr;
if(ip>=lbuff-4)break;
}
if(iswitab>=0)
{
for(int i=0;i<ncos;i++)
{
pchar(cval[i],20);
mstr.Format("%s \r\n",cval[i]);
str+=mstr;
}
}
return str;
}
//
//Translate value (Real, Integer, ASCII) to string(binary).
// code 2
//--fsingl, ieee single precision floating point( 4 bytes).
void fsinglc(char *cha,float value,int *nbyte)
{
char buf4[4];
union A
{
char buf4[4];
float vv;
}a;
*nbyte=4;
a.vv=value;
strcpy(cha,a.buf4);
}
void fsinglb(char *cha,float *value,int npoints,int *nbyte)
{
char buf4[4];
union A
{
char buf4[4];
float vv;
}a;
*nbyte=4*npoints;
for(int i=0;i<npoints;i++)
{
a.vv=value[i];
memcpy(&cha[i*4],a.buf4,4);
}
}
//code 13
//--snorm, normal signed integer( 2 bytes).
void snormb(char *cha,short *ivalue,int npoints,int *nbyte)
{
union A
{
char buf2[2];
short iv;
}a;
*nbyte=2*npoints;
for(int i=0;i<npoints;i++)
{
a.iv=ivalue[i];
memcpy(&cha[i*2],a.buf2,2);
}
}
void snormb(uchar *cha,ushort *ivalue,int npoints,int *nbyte)
{
union A
{
unsigned char buf2[2];
ushort iv;
}a;
*nbyte=2*npoints;
for(int i=0;i<npoints;i++)
{
a.iv=ivalue[i];
memcpy(&cha[i*2],a.buf2,2);
}
}
// code 14
//--slong, long signed integer( 4 bytes).
void slongb(char *cha,int *ivalue,int npoints,int *nbyte)
{
char buf4[4];
union A
{
char buf4[4];
int iv;
}a;
*nbyte=4*npoints;
for(int i=0;i<npoints;i++)
{
a.iv=ivalue[i];
memcpy(&cha[i*4],a.buf4,4);
}
}