Beispiel #1
0
//得到弹簧的工作荷载和安装荷载
//没有经过单位转换的荷载值
BOOL CAESARIIToPHS::GetHangerLoad( int iNode,const CString& strFileName, double& dWorkLoad,double& dInsLoad ) //得到弹簧的工作荷载和安装荷载
{
	_RecordsetPtr pHangerRs;
	pHangerRs.CreateInstance( __uuidof(Recordset) );
	
	try
	{
		CString strSQL;
		strSQL.Format(_T("SELECT * FROM OUTPUT_HANGERS WHERE [NODE] = %d AND [JOBNAME] = '%s'"),iNode,strFileName);
		pHangerRs->Open(_variant_t(strSQL),(IDispatch *)m_pConnSourceDB,adOpenDynamic,adLockOptimistic,adCmdText);
		if(pHangerRs->adoEOF && pHangerRs->BOF)
		{
			pHangerRs->Close();
			return FALSE;
		}
		else
		{
			dWorkLoad = vtoi ( pHangerRs->GetCollect( _T("NUMREQ") ) ) * vtof( pHangerRs->GetCollect( _T("HOT_LOAD") ) ); //工作荷载
			dInsLoad = vtoi ( pHangerRs->GetCollect( _T("NUMREQ") ) ) * vtof( pHangerRs->GetCollect( _T("TH_INSTALL_LOAD") ) ); //安装荷载
		}
	}
	catch (_com_error &e)
	{
		CString strMsg;
		strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
		AfxMessageBox(strMsg);
	}
	if(pHangerRs->State==adStateOpen)
	{
		pHangerRs->Close();
	}
	return TRUE;
}
Beispiel #2
0
int
main(int argc, char **argv)
{
	cwp_String key1,  key2;	/* x and y key header words	*/
	Value  val1,  val2;	/* ... their values		*/
	cwp_String type1, type2;/* ... their types		*/
	int index1, index2;	/* ... their indices in hdr.h	*/
	float x, y;		/* temps to hold current x & y 	*/
	cwp_String outpar;	/* name of par file		*/
	register int npairs;	/* number of pairs found	*/


	/* Hook up getpars */
	initargs(argc, argv);
	requestdoc(1);


	/* Prevent byte codes from spilling to screen */
	if (isatty(STDOUT)) err("must redirect or pipe binary output");


	/* Get parameters */
	if (!getparstring("key1", &key1))	key1 = "sx";
	if (!getparstring("key2", &key2))	key2 = "gx";

	type1 = hdtype(key1);
	type2 = hdtype(key2);

	index1 = getindex(key1);
	index2 = getindex(key2);


	/* Loop over traces */
	npairs = 0;
	while(gettr(&tr)) {

		gethval(&tr, index1, &val1);
		gethval(&tr, index2, &val2);

		x = vtof(type1, val1);
		y = vtof(type2, val2);

		efwrite(&x, FSIZE, 1, stdout);
		efwrite(&y, FSIZE, 1, stdout);

		++npairs;
	}


	/* Make parfile if needed */
	if (getparstring("outpar", &outpar))
		fprintf(efopen(outpar, "w"),
			"n=%d label1=%s label2=%s\n",
			npairs, key1, key2);

	return(CWP_Exit());
}
Beispiel #3
0
//单位换算
//SourceUnits 被转换的单位
//UeUnits 转换后的单位
//返回单位换算因子
//dOffset 偏移值
double CAESARIIToPHS::UnitsToUeUnits(_RecordsetPtr rsData,CString SourceUnits,CString UeUnits,double &dOffset)
{
	double x;//单位换算因子
	CString strSQL;                                            
	_RecordsetPtr pRs;
	_ConnectionPtr pCon;
	pCon.CreateInstance(__uuidof(Connection));
	pRs.CreateInstance(__uuidof(Recordset));
	strSQL="select * from UnitsToUeUnits ";//删除了pfg20050629where Units='"+SourceUnits+"' and UeUnits='"+UeUnits+"'
	try
	{
		pCon=rsData->GetActiveConnection();
		pRs->Open(_variant_t(strSQL),(IDispatch*)pCon,adOpenStatic,adLockOptimistic,adCmdText);
		pRs->Filter=_variant_t("Units='"+SourceUnits+"' and UeUnits='"+UeUnits+"'");//pfg20050629
		if(pRs->GetRecordCount()>0)
		{
			x=vtof(pRs->GetCollect(_T("value")));
			dOffset=vtof(pRs->GetCollect(_T("offset")));//pfg20050701
			return x;
		}
		else if(pRs->GetRecordCount()==0)
		{
			//pfg20050629弹出增加单位转换关系对话框(statr)
			CUnitsTransformDlg dlg;
			pRs->Filter="";
			dlg.m_pRsUnits=pRs;
			dlg.m_strDestinationUnits=UeUnits;
			dlg.m_strSourceUnits=SourceUnits;
			if((dlg.DoModal())==IDOK)
			{
				pRs=dlg.m_pRsUnits;//pfg20050630
				pRs->Filter=_variant_t("Units='"+SourceUnits+"' and UeUnits='"+UeUnits+"'");//pfg20050629
				if(pRs->GetRecordCount()>0)
				{
					dOffset=vtof(pRs->GetCollect("Offset"));//pfg20050701
					x=vtof(pRs->GetCollect(_T("value")));
					return x;
				}
				else
					return 1.0;
			}
			else
			{
				m_IsCaesarError=TRUE;//增加了一个条件pfg20050627				
			}
			//pfg20050629弹出增加单位转换关系对话框(end)
		}
	}
	catch(_com_error &e)
	{
		if(AfxMessageBox("错误:当前单位不能转换,请更换单位后重试(仔细阅读使用说明)!",MB_YESNO)==IDYES)
		{
			m_IsCaesarError=TRUE;//增加了一个条件pfg20050627
		}
	}
	return 1.0;
}
Beispiel #4
0
float n_distance(segy **rec_o,int *index,cwp_String *type,float *dx,unsigned int nd,unsigned int imx,unsigned int itr)
{

	float du;
	float o,x;
	int i;
	double dist=0;
	Value val;
	
	for(i=0;i<nd;i++) {
 		gethval(rec_o[imx], index[i],&val);
		o = vtof(type[i],val);
 		gethval(rec_o[itr], index[i],&val);
		x = vtof(type[i],val);
		du = (o-x)/dx[i];
		dist += du*du;
	}
	return((float)sqrt(dist));	
}
Beispiel #5
0
main(int argc, char **argv)
{
	String output;
	bool asciiout = true;


	/* Initialize */
	initargs(argc, argv);
	askdoc(1);

	file2g(stdin);


	/* Argument count check */
	if (argc == 1)  err("must specify key(s) as command line arguments");


	/* Set and check output disposition (ascii or binary) */
	if (!getparstring("output", &output))   output = "ascii";
	if ((!STREQ(output, "ascii")) && (!STREQ(output, "binary")))
		err("output parameter=%s, must be ascii or binary", output);
	if (STREQ(output, "binary"))  asciiout = false;


	/* Loop over traces writing selected header field values */
	while (gettr(&tr)) {
		register int i;

		for (i = 1; i < argc; ++i) {
			String key = argv[i];
			Value val;

			/* discard command line parameter strings */
			if (STREQ(key, "output=ascii") ||
			    STREQ(key, "output=binary"))
				continue;

			gethdval(&tr, key, &val);
			if (asciiout) {  /* ascii output */
				printf("%6s=", key);
				printfval(hdtype(key), val);
				putchar('\t');
			} else {  /* binary output */
				float fval = vtof(hdtype(key), val);
				efwrite((char *) &fval, FSIZE, 1, stdout);
			}
		}

		if (asciiout)  printf("\n\n");
	}

	return EXIT_SUCCESS;
}
//------------------------------------------------------------------
// DATE         : [2006/02/17]
// Author       : ZSY 
// Parameter(s) : nID[in] 显示当前记录的序号
// Return       : 读取成功返回1,否则返回0
// Remark       : 读取埋地管道的保温数据到输入窗口中
//------------------------------------------------------------------
short CDlgParameterSubterranean::GetDataToSubterraneanControl(long nID)
{
	CString strSQL;
	int nSelect;
	try
	{
		if ( m_pRsSubterranean == NULL || ( m_pRsSubterranean->GetState() != adStateOpen ) )
		{
			return 1;
		}
		if ( !m_pRsSubterranean->adoEOF || !m_pRsSubterranean->BOF )
		{
			m_pRsSubterranean->MoveFirst();
			strSQL.Format("ID=%d", nID );
			m_pRsSubterranean->Find( _bstr_t( strSQL ), NULL, adSearchForward );
		}
		if ( m_pRsSubterranean->adoEOF || m_pRsSubterranean->BOF )// 没有找到当前工程指定序号的记录则新增一条
		{
			m_pRsSubterranean->AddNew();//
			m_pRsSubterranean->PutCollect( _variant_t("ID"), _variant_t(nID) );
			m_pRsSubterranean->PutCollect( _variant_t("EnginID"), _variant_t(m_strProjectID));
			m_pRsSubterranean->Update();

			m_ctlPipeCount.SetCurSel(0);
		}
		else
		{
			nSelect = vtoi( m_pRsSubterranean->GetCollect( _variant_t("c_Pipe_Count") ) );
			nSelect = (nSelect > 0) ? nSelect -1 : 0;
			m_ctlPipeCount.SetCurSel(nSelect);
		}
		m_nID = nID;	//保存当前记录的序号		
		m_nPipeLay		= vtoi( m_pRsSubterranean->GetCollect( _variant_t("c_lay_mark") ) );	// 管道敷设状态
		m_dPipeSubDepth	= vtof( m_pRsSubterranean->GetCollect( _variant_t("c_Pipe_Sub_Depth")));// 管道的埋设深度(地表面到管道中心的距离)
		m_dEdaphicTemp	= vtof( m_pRsSubterranean->GetCollect( _variant_t("c_Edaphic_Temp") ));	// 土壤的温度℃
		m_dPipeSpan		= vtof( m_pRsSubterranean->GetCollect( _variant_t("c_Pipe_Span") ) );	// 两根管道之间的当量间距
		m_dEdaphicLamda = vtof( m_pRsSubterranean->GetCollect( _variant_t("c_Edaphic_Lamda")));	// 土壤的导热系数
		m_dSupportK     = vtof( m_pRsSubterranean->GetCollect( _variant_t("c_Support_K") ) );	// 支吊架的热损失校正系数
		m_dPipeDag		= vtof( m_pRsSubterranean->GetCollect( _variant_t("c_Pipe_Dag") ) );	// 管沟当量直径
		m_dCanalDepth   = vtof( m_pRsSubterranean->GetCollect( _variant_t("c_Canal_Depth") ) ); // 管沟深度

	}
	catch (_com_error& e)
	{
		AfxMessageBox( e.Description() );
		return 0;
	}
	UpdateData( FALSE );
	// 更新控件的状态
	UpdateControlState();

	
	return 1;
}
Beispiel #7
0
double CAESARIIToPHS::GetMaxLoad( int iNode,const CString& strFileName ) //得到支吊点最大的荷载值
{
	double dRtMaxLoad = 0.0;
	_RecordsetPtr pMaxLoadRs;
	pMaxLoadRs.CreateInstance( __uuidof(Recordset) );
	//导入工作荷载(start)
	CString strSQL;
	strSQL.Format(_T("SELECT DISTINCT [NODE] ,max([RESULTANTF]) AS PJG FROM [OUTPUT_RESTRAINTS] WHERE [NODE] = %d AND [JOBNAME] = '%s' GROUP BY [NODE] "),iNode,strFileName);
	pMaxLoadRs->Open(_variant_t(strSQL),(IDispatch *)m_pConnSourceDB,adOpenDynamic,adLockOptimistic,adCmdText);
	//prsOutputRestraints = gpconCaesar->Execute(_bstr_t(strSQL),NULL,adCmdText);
	if(pMaxLoadRs->adoEOF && pMaxLoadRs->BOF)
	{
	}
	else
	{	
		dRtMaxLoad = vtof( pMaxLoadRs->GetCollect("PJG") );
	}
	if(pMaxLoadRs->State==adStateOpen)
	{
		pMaxLoadRs->Close();
	}
	return dRtMaxLoad;
}
Beispiel #8
0
int
main(int argc, char **argv)
{
	cwp_String key[SU_NKEYS];	/* array of keywords		*/
	cwp_String type[SU_NKEYS];	/* array of types for key	*/
	int index[SU_NKEYS];		/* array of indexes for key	*/
	int ikey;		/* key counter				*/
	int nkeys;		/* number of header fields set		*/
	int n;			/* number of min,max values   		*/
	Value val;		/* value of key field			*/
	double fval;		/* value of key field			*/
	float *min=NULL;	/* array of "min" values		*/
	float *max=NULL;	/* array of "max" values		*/

	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);

	/* Get "key" values */
	if ((nkeys=countparval("key"))!=0) {
		getparstringarray("key",key);

	} else {
		key[0]="cdp";
	}

	/* get types and indexes corresponding to the keys */
	for (ikey=0; ikey<nkeys; ++ikey) {
		type[ikey]=hdtype(key[ikey]);
		index[ikey]=getindex(key[ikey]);
	}

	/* get "min" values */
	if ((n=countparval("min"))!=0) { 
		if (n!=nkeys)
		err("number of a values not equal to number of keys");
		min=ealloc1float(n);
		getparfloat("min",min);
	} else {
		min=ealloc1float(nkeys);
		for (ikey=0; ikey<nkeys; ++ikey) min[ikey]=0.;
	}

	/* get "max" values */
	if ((n=countparval("max"))!=0) { 
		if (n!=nkeys)
		err("number of a values not equal to number of keys");
		max=ealloc1float(n);
		getparfloat("max",max);
	} else {
		max=ealloc1float(nkeys);
		for (ikey=0; ikey<nkeys; ++ikey) max[ikey]=ULONG_MAX;
	}

	/* get types and index values */
	for (ikey=0; ikey<nkeys; ++ikey) {
		type[ikey] = hdtype(key[ikey]);
		index[ikey] = getindex(key[ikey]);
	}

	while (gettr(&tr)) {
		for (ikey=0; ikey<nkeys; ++ikey) {
			gethval(&tr, index[ikey], &val);
			fval = vtof(type[ikey], val);
			if (fval < min[ikey]) {
				changeval(type[ikey], &val, min[ikey]);
				puthval(&tr, index[ikey], &val);
			} else if (fval > max[ikey]) {
				changeval(type[ikey], &val, max[ikey]);
				puthval(&tr, index[ikey], &val);
			}
		}
		puttr(&tr);
	}

	return(CWP_Exit());
}
Beispiel #9
0
//导入弹簧数据(变力弹簧)
void CAESARIIToPHS::ImportHanger(_RecordsetPtr rsData,long node,CString strJOBNAME_P)
{
	CString strSQL;
	_RecordsetPtr pRs;
	double dLoadx=1.0;//力的单位转换因子
	double dFOffset=0.0;//力的偏移量
	_variant_t tmpvar;
	CString str;
	CString strSize;
	CString strPHSType;
	try
	{
		strSQL.Format(_T("SELECT * FROM [OUTPUT_HANGERS] WHERE [NODE] = %d AND [JOBNAME] =  '%s'" ),
			node,strJOBNAME_P);
		pRs = m_pConnSourceDB->Execute(_bstr_t(strSQL),NULL,adCmdText);
		if(!(pRs->BOF&&pRs->adoEOF))
		{
			pRs->MoveFirst();
			//力的单位转换
		/*
			str=vtos(pRs->GetCollect(_T("LOAD_UNITS")));
			str.TrimLeft();
			str.TrimRight();
			str.MakeLower();
			dLoadx=UnitsToUeUnits(rsData,str,m_strUNITFORCE,dFOffset);
			if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据
		*/	
			//pgz1工作荷载已经在表:OUTPUT_RESTRAINTS中导入了
			//	rsData->PutCollect("pgz1",_variant_t(vtof(pRs->GetCollect("HOT_LOAD"))*dLoadx));
		//	rsData->PutCollect("paz0",_variant_t(vtof(pRs->GetCollect("TH_INSTALL_LOAD"))*dLoadx+dFOffset));
		//	rsData->PutCollect("paz1",_variant_t(vtof(pRs->GetCollect("AC_INSTALL_LOAD"))*dLoadx+dFOffset));
			
			double dLoadVariation = 0.0;
			dLoadVariation = vtof( pRs->GetCollect("LOAD_VARIATION") );
			if ( dLoadVariation < 1E-6 )
			{
				strPHSType = _T("9999"); //恒力弹簧
			}
			else //变力弹簧
			{
				rsData->PutCollect("CoefOfVarLoad",_variant_t( dLoadVariation /100 ) );
				tmpvar = pRs->GetCollect("SIZE");
				strSize.Format(_T("%02d"),vtoi(tmpvar));
				
				//并联数
				int iParalNum = vtoi( pRs->GetCollect( _T("NUMREQ") ) );
				CString strHangerType = vtos( pRs->GetCollect( _T("FIGNUM") ) );
				//串联数
				int iSeriesNum = 0;
				if ( !GetHangerSeriesNum(strHangerType,iSeriesNum) ) //得到弹簧不成功
				{
					CString strError;
					strError.Format( _T("无法通过弹簧类型%s获得弹簧的串联数,串联数默认为1"),strHangerType );
					AfxMessageBox( strError );
					iSeriesNum = 1;
				}
				
				//形成类似GLIF定义的支吊架类型号								
				strPHSType.Format( _T("%d%d%s"),iSeriesNum,iParalNum,strSize );
				
			}
			rsData->PutCollect("TYPE",_variant_t(strPHSType));
			rsData->PutCollect("psaTYPE",_variant_t(strPHSType));
		}
	}
	catch (_com_error &e)
	{
		CString strMsg;
		strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
		AfxMessageBox(strMsg);
	}
	if ( pRs->State == adStateOpen )
	{
		pRs->Close();
	}
}
Beispiel #10
0
//导入管道外径、介质温度
void CAESARIIToPHS::ImportDiameter(_RecordsetPtr rsData,long node,CString strJOBNAME_A)
{
	CString strSQL;
	_RecordsetPtr pRs;
	double dDiameterx=1.0;//直径的换算因子
	double dDOffset=0.0;//直径偏移量
	double dT01x=1.0;//温度的换算因子
	double dTOffset=0.0;//温度偏移量
	CString str;
	pRs.CreateInstance(__uuidof(Recordset));
	try
	{
		strSQL.Format(_T("select * from input_units where jobname='%s'"),strJOBNAME_A);
		pRs=m_pConnSourceDB->Execute(_bstr_t(strSQL),NULL,adCmdText);
		str=vtos(pRs->GetCollect(_T("LENGTH")));
		str.TrimLeft();
		str.TrimRight();
		str.MakeUpper();
		if(!(str=="MM"))
		{
			dDiameterx=UnitsToUeUnits(rsData,str,"MM",dDOffset);
			if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据
			
		}
		str=vtos(pRs->GetCollect(_T("TEMP")));
		str.TrimLeft();
		str.TrimRight();
		str.MakeUpper();
		//pfg20050630
		dT01x=UnitsToUeUnits(rsData,str,"C",dTOffset);
		if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据

//chenbl 2010.05.15
		
	//找出单元记录
		//先找起点号
		pRs->Close();
		strSQL.Format(_T("SELECT * FROM [INPUT_BASIC_ELEMENT_DATA] WHERE [JOBNAME] =  '%s' AND [FROM_NODE] = %d"),strJOBNAME_A,node);
		pRs->Open(_variant_t(strSQL),(IDispatch*)m_pConnSourceDB,adOpenStatic,adLockOptimistic,adCmdText);
		if ( pRs->BOF && pRs->adoEOF ) //没有找到记录
		{
			pRs->Close();
			//找末点
			strSQL.Format(_T("SELECT * FROM [INPUT_BASIC_ELEMENT_DATA] WHERE [JOBNAME] =  '%s' AND [TO_NODE] = %d"),strJOBNAME_A,node);
			pRs->Open(_variant_t(strSQL),(IDispatch*)m_pConnSourceDB,adOpenStatic,adLockOptimistic,adCmdText);
			if ( pRs->BOF && pRs->adoEOF ) //没有找到记录
			{
				pRs->Close();
				strSQL.Format(_T("SELECT * FROM [INPUT_BASIC_ELEMENT_DATA],[INPUT_BENDS] WHERE [INPUT_BENDS].[JOBNAME] =  '%s' AND  ( [INPUT_BENDS].NODE1 = %d OR [INPUT_BENDS].NODE2 = %d OR [INPUT_BENDS].NODE3 = %d ) AND [INPUT_BASIC_ELEMENT_DATA].BEND_PTR = [INPUT_BENDS].BEND_PTR"),
					strJOBNAME_A,node,node,node);
				pRs->Open(_variant_t(strSQL),(IDispatch*)m_pConnSourceDB,adOpenStatic,adLockOptimistic,adCmdText);
				if ( pRs->BOF && pRs->adoEOF ) //没有找到记录
				{
					pRs->Close();
					return;
				}
			}
		}
		rsData->PutCollect("DJ1",_variant_t(vtof(pRs->GetCollect("DIAMETER"))*dDiameterx+dDOffset));
		rsData->PutCollect("T01",_variant_t(vtof(pRs->GetCollect("TEMP_EXP_C1"))*dT01x+dTOffset));
		
		if(pRs->State==adStateOpen)
		{
			pRs->Close();
		}
	}
	catch (_com_error &e)
	{
		CString strMsg;
		strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
		AfxMessageBox(strMsg);
	}
}
Beispiel #11
0
//导入支吊架的线位移、角位移
//rsData 结果表(ZA)记录集、strLGkname 工况名称、strJDBNAME_P 工程名称
//flag =1 热态 、flag=0为冷态
void CAESARIIToPHS::ImportDisplacements(_RecordsetPtr rsData,long node, CString strLGKname,CString strJOBNAME_P,int flag)
{
	double x= 1.0;//单位换算因子
	double dLOffset=0.0;//长度的偏移
	double dROffset=0.0;//角度的偏移
	CString strSQL,strError;
	CString strUnits;
	_RecordsetPtr prsDisplacements;
	prsDisplacements.CreateInstance(__uuidof(Recordset));
	try
	{
		if(flag)
		{
			//热态
			strSQL.Format(_T("SELECT * FROM [OUTPUT_DISPLACEMENTS] WHERE [NODE] = %d AND [CASE] = '%s' AND [JOBNAME] =  '%s' "),node,strLGKname,strJOBNAME_P);						
			prsDisplacements = m_pConnSourceDB->Execute(_bstr_t(strSQL),NULL,adCmdText);
			if ( prsDisplacements->adoEOF && prsDisplacements->BOF )
			{
				strError.Format( _T("OUTPUT_DISPLACEMENTS表中没有点号为%d用工况号为%s的数据"),node,strLGKname );
				AfxMessageBox( strError );
				prsDisplacements->Close();
				return;
			}
			
			//长度单位换算
			strUnits=vtos(prsDisplacements->GetCollect(_T("DUNITS")));
			strUnits.TrimLeft();
			strUnits.TrimRight();
			strUnits.MakeLower();
			if (strUnits == "mm")
			{
				x=1.0;
			}
			else
			{
				x=UnitsToUeUnits(rsData,strUnits,"mm",dLOffset);
				if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据

			}
			//热态线位移
			rsData->PutCollect("xr1",_variant_t(vtof(prsDisplacements->GetCollect("dX"))*x+dLOffset));
			rsData->PutCollect("yr1",_variant_t(vtof(prsDisplacements->GetCollect("dY"))*x+dLOffset));					 
			rsData->PutCollect("zr1",_variant_t(vtof(prsDisplacements->GetCollect("dZ"))*x+dLOffset));	
			rsData->PutCollect("UNIT_Displacement",_T("mm"));

			//角度单位换算
			strUnits=vtos(prsDisplacements->GetCollect(_T("RUNITS")));
			strUnits.TrimLeft();
			strUnits.TrimRight();
			if(strUnits=="弧度")
			{
				x=1.0;
			}
			else
			{
				x=UnitsToUeUnits(rsData,strUnits,"弧度",dROffset);
				if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据

			}
			//热态角位移
			rsData->PutCollect("rxR1",_variant_t(vtof(prsDisplacements->GetCollect("RX"))*x+dROffset));
			rsData->PutCollect("ryR1",_variant_t(vtof(prsDisplacements->GetCollect("RY"))*x+dROffset));					 
			rsData->PutCollect("rzR1",_variant_t(vtof(prsDisplacements->GetCollect("RZ"))*x+dROffset));	
		}
		else
		{
			//冷态
			strSQL.Format(_T("SELECT * FROM [OUTPUT_DISPLACEMENTS] WHERE [NODE] = %d AND [CASE] = '%s' AND [JOBNAME] =  '%s' "),node,strLGKname,strJOBNAME_P);						
			prsDisplacements = m_pConnSourceDB->Execute(_bstr_t(strSQL),NULL,adCmdText);

			if ( prsDisplacements->adoEOF && prsDisplacements->BOF )
			{
				strError.Format( _T("OUTPUT_DISPLACEMENTS表中没有点号为%d用工况号为%s的数据"),node,strLGKname );
				AfxMessageBox( strError );
				prsDisplacements->Close();
				return;
			}
			
			//长度单位换算
			strUnits=vtos(prsDisplacements->GetCollect(_T("DUNITS")));
			strUnits.TrimLeft();
			strUnits.TrimRight();
			strUnits.MakeLower();
			if (strUnits == "mm")
			{
				x=1.0;
			}
			else
			{
				x=UnitsToUeUnits(rsData,strUnits,"mm",dLOffset);
				if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据

			}
			//冷态线位移
			rsData->PutCollect("xL1",_variant_t(vtof(prsDisplacements->GetCollect("dX"))*x+dLOffset));
			rsData->PutCollect("yL1",_variant_t(vtof(prsDisplacements->GetCollect("dY"))*x+dLOffset));					 
			rsData->PutCollect("zL1",_variant_t(vtof(prsDisplacements->GetCollect("dZ"))*x+dLOffset));	

			//角度单位换算
			strUnits=vtos(prsDisplacements->GetCollect(_T("RUNITS")));
			strUnits.TrimLeft();
			strUnits.TrimRight();
			if(strUnits=="弧度")
			{
				x=1.0;
			}
			else
			{
				x=UnitsToUeUnits(rsData,strUnits,"弧度",dROffset);
				if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据

			}
			//冷态角位移
			rsData->PutCollect("rxL1",_variant_t(vtof(prsDisplacements->GetCollect("RX"))*x+dROffset));
			rsData->PutCollect("ryL1",_variant_t(vtof(prsDisplacements->GetCollect("RY"))*x+dROffset));					 
			rsData->PutCollect("rzL1",_variant_t(vtof(prsDisplacements->GetCollect("RZ"))*x+dROffset));	
		}
	}
	catch (_com_error &e)
	{
		CString strMsg;
		strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
		AfxMessageBox(strMsg);
	}
}
Beispiel #12
0
//导入支架、吊架中的单位,各个方向的推力(冷态、热态)
//rsData为结果数据库	m_strLGKname为冷态、m_strRGKname为热态
//m_strJOBNAME_P 工程名称
void CAESARIIToPHS::importUnitsForces(_RecordsetPtr rsData,long node,CString m_strJOBNAME_P,CString PSA_OutDataFUnit,CString PSA_OutDataMUnit,CString m_strRGKname,CString m_strLGKname)
{
	CString strSQL;
	CString strMessage;
	_RecordsetPtr prsOutputRestraints;
	int i=0;
	int IsXYZ=0;//是否在x,y,z方向已经导入了数据,因为约束类型很多,对于同一方向有多
				//个约束时,需要提示用户我们还没有对这一种情况进行处理 当百位为1
				//表示x方向已经导入了数据,依此类推
	int IsmXYZ=0;//表示力矩,含义与IsXYZ类似
	double tmpVar;
	double dFx=1.0;//力的转换因子
	double dFOffset=0.0;//力的偏移量
	double dMx=1.0;//力矩的转换因子
	double dMOffset=0.0;//力矩的偏移量
	CString strFUnits;//力的单位;
	CString strMUnits;//力矩的单位

	double dICCWorkLoad = 0.0,dICCIncLoad = 0.0; //向上轴热态、冷态荷载

	strFUnits=PSA_OutDataFUnit;
	strMUnits=PSA_OutDataMUnit;
	CString strTmp;
	prsOutputRestraints.CreateInstance(__uuidof(Recordset));
	try
	{
		//转换后力的单位:kgf;力矩的单位:kgf.m写入ZA表中(start)			 				 
		rsData->PutCollect("Unit_Force",_variant_t(m_strUNITFORCE));
		rsData->PutCollect("Unit_Momental",_variant_t(m_strUNITMOMENTAL));
		//转换后力的单位:kgf;力矩的单位:kgf.m写入ZA表中(end)

		//导入热态的荷载、力矩(start)
		strSQL.Format(_T("SELECT * FROM [OUTPUT_RESTRAINTS] WHERE [NODE] = %d AND [CASE] = '%s' and JOBNAME='%s' "),node,m_strRGKname,m_strJOBNAME_P);
		prsOutputRestraints = m_pConnSourceDB->Execute(_bstr_t(strSQL),NULL,adCmdText);
		if(!(prsOutputRestraints->BOF&&prsOutputRestraints->adoEOF))
		{
			//pfg20050622(start)
			strTmp=vtos(prsOutputRestraints->GetCollect(_T("FUNITS")));
			strFUnits=(strTmp!="")?strTmp:strFUnits;
			//单位换算
			dFx=UnitsToUeUnits(rsData,strFUnits,m_strUNITFORCE,dFOffset);
			if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据
			strTmp=vtos(prsOutputRestraints->GetCollect(_T("MUNITS")));
			strMUnits=(strTmp!="")?strTmp:strMUnits;
			dMx=UnitsToUeUnits(rsData,strMUnits,m_strUNITMOMENTAL,dMOffset);
			if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据
			//pfg20050622(end)
			prsOutputRestraints->MoveFirst();
			while(!prsOutputRestraints->adoEOF)
			{
				tmpVar=vtof(prsOutputRestraints->GetCollect("FX"));
				if( (tmpVar!=0) && (IsXYZ/100==0) || i==0 )
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("pxr1",_variant_t(tmpVar*dFx+dFOffset));
					IsXYZ=(tmpVar!=0)?(IsXYZ+100):IsXYZ;
					if ( m_iUPxyz == 1 ) //X轴向上
					{
						dICCWorkLoad = tmpVar*dFx+dFOffset;
					}
				}
				else if((tmpVar!=0)&&(IsXYZ/100))
				{
					strMessage.Format("警告:节点号为%d的支吊点在X方向上有几个荷载(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}

				tmpVar=vtof(prsOutputRestraints->GetCollect("FY"));
				if(((tmpVar!=0)&&(((IsXYZ%100)/10)==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("pyr1",_variant_t(tmpVar*dFx+dFOffset));
					IsXYZ=(tmpVar!=0)?(IsXYZ+10):IsXYZ;
					if ( m_iUPxyz == 2 ) //Y轴向上
					{
						dICCWorkLoad = tmpVar*dFx+dFOffset;
					}
				}
				else if((tmpVar!=0)&&((IsXYZ%100)/10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Y方向上有几个荷载(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("FZ"));
				if(((tmpVar!=0)&&(IsXYZ%10==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("pzr1",_variant_t(tmpVar*dFx+dFOffset));
					IsXYZ=(tmpVar!=0)?(IsXYZ+1):IsXYZ;
					if ( m_iUPxyz == 3 ) //Z轴向上
					{
						dICCWorkLoad = tmpVar*dFx+dFOffset;
					}
				}
				else if((tmpVar!=0)&&(IsXYZ%10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Z方向上有几个荷载(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("MX"));
				if((tmpVar!=0)&&(IsmXYZ/100==0)||i==0)
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("mxr1",_variant_t(tmpVar*dMx+dMOffset));
					IsmXYZ=(tmpVar!=0)?(IsmXYZ+100):IsmXYZ;
				}
				else if((tmpVar!=0)&&(IsmXYZ/100))
				{
					strMessage.Format("警告:节点号为%d的支吊点在X方向上有几个力矩(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("MY"));
				if(((tmpVar!=0)&&(((IsmXYZ%100)/10)==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("myr1",_variant_t(tmpVar*dMx+dMOffset));
					IsmXYZ=(tmpVar!=0)?(IsmXYZ+10):IsmXYZ;
				}
				else if((tmpVar!=0)&&((IsmXYZ%100)/10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Y方向上有几个力矩(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("MZ"));
				if(((tmpVar!=0)&&(IsmXYZ%10==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("mzr1",_variant_t(tmpVar*dMx+dMOffset));
					IsmXYZ=(tmpVar!=0)?(IsmXYZ+1):IsmXYZ;
				}
				else if((tmpVar!=0)&&(IsmXYZ%10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Z方向上有几个力矩(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				i++;
				prsOutputRestraints->MoveNext();
			}
		}
		if(prsOutputRestraints->State==adStateOpen)
		{
			prsOutputRestraints->Close();
		}
		//导入热态的荷载、力矩(end)

		//导入冷态的荷载、力矩(start)
		IsXYZ=0;
		IsmXYZ=0;
		i=0;
		strSQL.Format(_T("SELECT * FROM [OUTPUT_RESTRAINTS] WHERE [NODE] = %d AND [CASE] = '%s' and JOBNAME='%s' "),node,m_strLGKname,m_strJOBNAME_P);
		prsOutputRestraints = m_pConnSourceDB->Execute(_bstr_t(strSQL),NULL,adCmdText);
		if(!(prsOutputRestraints->BOF&&prsOutputRestraints->adoEOF))
		{
			//pfg20050622(start)
			strTmp=vtos(prsOutputRestraints->GetCollect(_T("FUNITS")));
			strFUnits=(strTmp!="")?strTmp:strFUnits;
			//单位换算
			dFx=UnitsToUeUnits(rsData,strFUnits,m_strUNITFORCE,dFOffset);
			if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据
			strTmp=vtos(prsOutputRestraints->GetCollect(_T("MUNITS")));
			strMUnits=(strTmp!="")?strTmp:strMUnits;
			dMx=UnitsToUeUnits(rsData,strMUnits,m_strUNITMOMENTAL,dMOffset);
			if(m_IsCaesarError) return;//pfg20050629当单位转换出错、终止导入数据
			//pfg20050622(end)
			prsOutputRestraints->MoveFirst();
			while(!prsOutputRestraints->adoEOF)
			{
				tmpVar=vtof(prsOutputRestraints->GetCollect("FX"));
				if((tmpVar!=0)&&(IsXYZ/100==0)||i==0)
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("pxl1",_variant_t(tmpVar*dFx+dFOffset));
					IsXYZ=(tmpVar!=0)?(IsXYZ+100):IsXYZ;

					if ( m_iUPxyz == 1 ) //X轴向上
					{
						dICCIncLoad = tmpVar*dFx+dFOffset;
					}
				}
				else if((tmpVar!=0)&&(IsXYZ/100))
				{
					strMessage.Format("警告:节点号为%d的支吊点在X方向上有几个荷载(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}

				tmpVar=vtof(prsOutputRestraints->GetCollect("FY"));
				if(((tmpVar!=0)&&(((IsXYZ%100)/10)==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("pyl1",_variant_t(tmpVar*dFx+dFOffset));
					IsXYZ=(tmpVar!=0)?(IsXYZ+10):IsXYZ;
					if ( m_iUPxyz == 2 ) //Y轴向上
					{
						dICCIncLoad = tmpVar*dFx+dFOffset;
					}
				}
				else if((tmpVar!=0)&&((IsXYZ%100)/10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Y方向上有几个荷载(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("FZ"));
				if(((tmpVar!=0)&&(IsXYZ%10==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("pzl1",_variant_t(tmpVar*dFx+dFOffset));
					IsXYZ=(tmpVar!=0)?(IsXYZ+1):IsXYZ;
					if ( m_iUPxyz == 3 ) //Z轴向上
					{
						dICCIncLoad = tmpVar*dFx+dFOffset;
					}
				}
				else if((tmpVar!=0)&&(IsXYZ%10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Z方向上有几个荷载(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("MX"));
				if((tmpVar!=0)&&(IsmXYZ/100==0)||i==0)
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("mxl1",_variant_t(tmpVar*dMx+dMOffset));
					IsmXYZ=(tmpVar!=0)?(IsmXYZ+100):IsmXYZ;
				}
				else if((tmpVar!=0)&&(IsmXYZ/100))
				{
					strMessage.Format("警告:节点号为%d的支吊点在X方向上有几个力矩(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("MY"));
				if(((tmpVar!=0)&&(((IsmXYZ%100)/10)==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("myl1",_variant_t(tmpVar*dMx+dMOffset));
					IsmXYZ=(tmpVar!=0)?(IsmXYZ+10):IsmXYZ;
				}
				else if((tmpVar!=0)&&((IsmXYZ%100)/10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Y方向上有几个力矩(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				tmpVar=vtof(prsOutputRestraints->GetCollect("MZ"));
				if(((tmpVar!=0)&&(IsmXYZ%10==0))||(i==0))
				{//当它是第一次导入或者以前在这一方向没有荷载
					rsData->PutCollect("mzl1",_variant_t(tmpVar*dMx+dMOffset));
					IsmXYZ=(tmpVar!=0)?(IsmXYZ+1):IsmXYZ;
				}
				else if((tmpVar!=0)&&(IsmXYZ%10))
				{
					strMessage.Format("警告:节点号为%d的支吊点在Z方向上有几力矩(请阅读使用说明)!",node);
					AfxMessageBox(strMessage);
				}
				i++;
				prsOutputRestraints->MoveNext();
			}
		}
		if(prsOutputRestraints->State==adStateOpen)
		{
			prsOutputRestraints->Close();
		}

		//先按默认的值设置工作荷载和安装荷载
		rsData->PutCollect("PGZ1",_variant_t( dICCWorkLoad) ); //工作荷载
		rsData->PutCollect("paz0", _variant_t( dICCIncLoad ) ); //安装荷载
		rsData->PutCollect("paz1", _variant_t( dICCIncLoad ) ); 

		double dMaxLoad = 0.0;
		//导入冷态的荷载、力矩(end)
		if ( IsHanger( node,m_strJOBNAME_P ) )
		{
			if ( m_iSpringLoadType == 1 ) //弹簧荷载提取工况方式(0:按上述选择的冷/热态提取荷载值 1按CAESARII弹簧表中的荷载值提取)
			{
				double dWorkLoad = 0.0,dInsLoad = 0.0;
				if ( GetHangerLoad( node,m_strJOBNAME_P,dWorkLoad,dInsLoad ) ) //得到弹簧荷载
				{
					rsData->PutCollect("PGZ1",_variant_t( dWorkLoad*dFx+dFOffset) );
					rsData->PutCollect("paz0", _variant_t( dInsLoad*dFx+dFOffset )); //冷态
					rsData->PutCollect("paz1", _variant_t( dInsLoad*dFx+dFOffset ));

					//改变向上轴的荷载值
					if ( m_iUPxyz == 1 )
					{
						rsData->PutCollect("pxl1", _variant_t( dInsLoad*dFx+dFOffset ));//冷态推力
						rsData->PutCollect("pxr1", _variant_t( dWorkLoad*dFx+dFOffset ));//热态推力
					}
					else if ( m_iUPxyz == 2 )
					{
						rsData->PutCollect("pyl1", _variant_t( dInsLoad*dFx+dFOffset ));//冷态推力
						rsData->PutCollect("pyr1", _variant_t( dWorkLoad*dFx+dFOffset ));//热态推力
					}
					else if ( m_iUPxyz == 3 )
					{
						rsData->PutCollect("pzl1", _variant_t( dInsLoad*dFx+dFOffset ));//冷态推力
						rsData->PutCollect("pzr1", _variant_t( dWorkLoad*dFx+dFOffset ));//热态推力
					}
				}
			}
		}
		
	}
	catch (_com_error &e)
	{
		CString strMsg;
		strMsg.Format("%s:%d %s", __FILE__, __LINE__, (LPSTR)e.Description());
		AfxMessageBox(strMsg);
	}
}
Beispiel #13
0
double HDCrude::GetPP()
{
	return vtof( m_pRs.GetFieldValue(m_strPPField) );
}
Beispiel #14
0
double HDCrude::GetT()
{
	return vtof( m_pRs.GetFieldValue(m_strTField) );
}
Beispiel #15
0
int main(int argc, char **argv)
{
	char *plotcmd;		/* build pswigb command for popen	*/
	float *trbuf;		/* trace buffer				*/
	FILE *plotfp;		/* fp for plot data			*/
	int nt;			/* number of samples on trace	  	*/
	int ntr;		/* number of traces			*/
	int verbose;		/* verbose flag				*/
	float d1;		/* time/depth sample rate		*/
	float d2;		/* trace/dx sample rate			*/
	float f1;		/* tmin/zmin			   	*/
	float f2;		/* tracemin/xmin			*/
	cwp_Bool seismic;	/* is this seismic data?		*/
	cwp_Bool have_ntr=cwp_false;/* is ntr known from header or user?	*/
	char *tmpdir;		/* directory path for tmp files		*/
	cwp_Bool istmpdir=cwp_false;/* true for user given path		*/

	char *cwproot;		/* value of CWPROOT environment variable*/
	char *bindir;		/* directory path for tmp files		*/

	/* Support for irregularly spaced data */
	cwp_String key;		/* header key word with x2 information  */
	cwp_String type1=NULL;	/* ... its type				*/
	int index1=0;		/* ... its index			*/
	Value val;		/* value of key				*/
	Value scale;		/* Value of scaler			*/
	cwp_String type2=NULL;	/* ... its type				*/
	int index2=0;		/* ... its index			*/
	cwp_Bool isDepth=cwp_false;	/* Is this key a type of depth?		*/
	cwp_Bool isCoord=cwp_false;	/* Is this key a type of coordinate?	*/
	cwp_Bool irregular=cwp_false;  /* if true, reading x2 from header	*/ 
	cwp_String x2string;	/* string of x2 values			*/
	off_t x2len;		/* ... its length 			*/
	cwp_String style;	/* style parameter			*/


	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);
	
	/* Get info from first trace */
	if (!gettr(&tr)) err("can't get first trace");
	seismic = ISSEISMIC(tr.trid); 
	nt = tr.ns;
	ntr = tr.ntr;
	if (ntr) have_ntr = cwp_true; 

	if (!getparint("verbose", &verbose))    verbose=0;
	if (!getparfloat("d1", &d1)) {
		if      (tr.d1)  d1 = tr.d1;
		else if (tr.dt)  d1 = ((double) tr.dt)/1000000.0;
		else {
			if (seismic) {
				d1 = 0.004;
				warn("tr.dt not set, assuming dt=0.004");
			} else { /* non-seismic data */
				d1 = 1.0;
				warn("tr.d1 not set, assuming d1=1.0");
			}
		}
	}


	if (!getparfloat("f1", &f1)) {
		if      (tr.f1)     f1 = tr.f1;
		else if (tr.delrt)  f1 = (float) tr.delrt/1000.0;
		else		f1 = 0.0;
	}

	/* Get or set ntr */
	if (getparint("n2", &ntr) || getparint("ntr", &ntr)) have_ntr = cwp_true;
	if (!getparfloat("d2", &d2)) d2 = (tr.d2) ? tr.d2 : 1.0;


	if (!getparfloat("f2", &f2)) {
		if	(tr.f2)	f2 = tr.f2;
		else if (tr.tracr)  f2 = (float) tr.tracr;
		else if (tr.tracl)  f2 = (float) tr.tracl;
		else if (seismic)   f2 = 1.0;
		else		    f2 = 0.0;
	}

	if (!getparstring("style", &style)) style = "seismic";
	 	
	if (getparstring("key", &key)) {
		type1 = hdtype(key);
		if ( (index1 = getindex(key)) == -1 )
			err("%s: keyword not in segy.h: '%s'", __FILE__, key);
		irregular = cwp_true;
		isDepth = IS_DEPTH(key);
		isCoord = IS_COORD(key);
		if (isDepth) {
		   index2 = getindex("scalel");
		   type2 = hdtype("scalel");
		} else if (isCoord) {
		   index2 = getindex("scalco");
		   type2 = hdtype("scalco");
		}
	}


	/* Look for user-supplied tmpdir */
	if (!getparstring("tmpdir",&tmpdir) &&
	    !(tmpdir = getenv("CWP_TMPDIR"))) tmpdir="";
	if (!STREQ(tmpdir, "") && access(tmpdir, WRITE_OK))
		err("you can't write in %s (or it doesn't exist)", tmpdir);

	/* See if CWPBIN environment variable is not set */
	if (!(bindir = getenv("CWPBIN"))) { /* construct bindir from CWPROOT */

		bindir = (char *) emalloc(BUFSIZ);

		/* Get value of CWPROOT environment variable */
		if (!(cwproot = getenv("CWPROOT"))) cwproot ="" ;
		if (STREQ(cwproot, "")) {
			warn("CWPROOT environment variable is not set! ");
			err("Set CWPROOT in shell environment as per instructions in CWP/SU Installation README files");
		}
		/* then bindir = $CWPROOT/bin */
		sprintf(bindir, "%s/bin", cwproot);
	}
	strcat(bindir,"/");   /* put / at the end of bindir */


	/* Allocate trace buffer */
	trbuf = ealloc1float(nt);


	if (!have_ntr || irregular ) { /* count traces */
		if (verbose) {
			if (irregular) {
				warn("trace spacing from header field %s",key);
				warn("... getting positions");

			} else {
				warn("n2 not getparred and "
				     "ntr header field not set");
				warn("....  counting traces");
			}
		}

		/* Create temporary "file" to hold data */
		if (STREQ(tmpdir,"")) {
			datafp = etmpfile();
			if (irregular) x2fp = etmpfile();
			if (verbose) warn("using tmpfile() call");
		} else { /* user-supplied tmpdir */
			char directory[BUFSIZ];
			strcpy(directory, tmpdir);
			strcpy(datafile, temporary_filename(directory));
			strcpy(x2file, temporary_filename(directory));
			/* Handle user interrupts */
			signal(SIGINT, (void (*) (int)) closefiles);
			signal(SIGQUIT, (void (*) (int)) closefiles);
			signal(SIGHUP,  (void (*) (int)) closefiles);
			signal(SIGTERM, (void (*) (int)) closefiles);
			datafp = efopen(datafile, "w+");
			if (irregular) x2fp = efopen(x2file, "w+");
			istmpdir=cwp_true;		
			if (verbose)
			      warn("putting temporary files in %s", directory);
		}

		/* Loop over input data and read to temporary file */
		ntr = 0;
		if(irregular ) {
		     float x,xmin=FLT_MAX,xmax=-FLT_MAX;

		     fprintf(x2fp,"x2=");
		     do {
			if(ntr) fprintf(x2fp,",");
			++ntr;
			gethval(&tr,index1,&val);
			if (isDepth || isCoord) {
			   gethval(&tr,index2,&scale);
			   x = (float) (vtod(type1,val) *
				 pow(10.0,vtod(type2,scale)));
			} else
			   x = vtof(type1,val);
			fprintf(x2fp,"%g",x);
			xmin = MIN(xmin,x);
			xmax = MAX(xmax,x);
			if (isDepth && STREQ(style,"vsp")) {
				int i;
				for (i = 0; i < nt; ++i) tr.data[i] *= -1.0;
			}
			efwrite(tr.data, FSIZE, nt, datafp);
		     } while (gettr(&tr));

		     /* Flip vertical axis if style = vsp */
		     if (isDepth && STREQ(style,"vsp")) {
			fprintf(x2fp," x2beg=%g x2end=%g",xmax,xmin);
			style = "normal";
		     }

		     if(xmin==xmax) {
			warn("values in header %s all equal,",key);
			warn("using f2=%f d2=%f",f2,d2);
			irregular=cwp_false;
			have_ntr=cwp_false;
			efclose(x2fp);
			if (istmpdir) eremove(x2file);
		     }

		} else {
			do {
				++ntr;
				efwrite(tr.data, FSIZE, nt, datafp);
			} while (gettr(&tr));
			/* Save naive user */
			if (STREQ(style,"vsp")) {
				style = "normal";
				warn("style=vsp requires key= to be set");
			}
		}


	}

	/* Set up pswigb command line */
	if (irregular ) {
		x2len = (off_t) eftell( x2fp );
		x2string = (char *) emalloc( ++x2len );
		rewind(x2fp);
		fread(x2string,sizeof(char),x2len,x2fp);
		plotcmd = (char *) emalloc(x2len+BUFSIZ);
		if (STREQ(style,"vsp")) {
			style = "normal";
		}
		sprintf(plotcmd, "%spswigb n1=%d d1=%f f1=%f %s style=%s", bindir,
			   nt, d1, f1, x2string, style);
		free(x2string);
	} else {
		if (STREQ(style,"vsp")) {
			style = "normal";
		}
		plotcmd = (char *) emalloc(BUFSIZ);
		sprintf(plotcmd,
			"%spswigb n1=%d n2=%d d1=%f d2=%f f1=%f f2=%f style=%s", bindir,
			   nt, ntr, d1, d2, f1, f2, style);
	}


	for (--argc, ++argv; argc; --argc, ++argv) {
		if (strncmp(*argv, "d1=", 3) && /* skip those already set */
		    strncmp(*argv, "d2=", 3) &&
		    strncmp(*argv, "f1=", 3) &&
		    strncmp(*argv, "f2=", 3) &&
		    strncmp(*argv, "style=", 6)){
		    
			strcat(plotcmd, " ");   /* put a space between args */
			strcat(plotcmd, "\"");  /* user quotes are stripped */
			strcat(plotcmd, *argv); /* add the arg */
			strcat(plotcmd, "\"");  /* user quotes are stripped */
		}
	}


	/* Open pipe to pswigb and send the traces */
	plotfp = epopen(plotcmd, "w");
	free(plotcmd);

	if (!have_ntr || irregular) { /* send out stored traces one by one */
		rewind(datafp);
		{ register int itr;
			for (itr = 0; itr < ntr; ++itr) {
				efread (trbuf, FSIZE, nt, datafp);
				efwrite(trbuf, FSIZE, nt, plotfp);
			}
		}
	} else { /* just pump out traces and let pswigb do the work */
		do {
			efwrite(tr.data, FSIZE, nt, plotfp);
		} while (gettr(&tr));
	}


	/* Clean up */
	epclose(plotfp);
	if (!have_ntr) {
		efclose(datafp);
		if (istmpdir) eremove(datafile);
	}
	if (irregular) {
		efclose(x2fp);
		if (istmpdir) eremove(x2file);
	}

	return EXIT_SUCCESS;
}
Beispiel #16
0
int
main(int argc, char **argv)
{
   char *tmpdir ;                 /* directory path for tmp files */
   cwp_Bool istmpdir=cwp_false ;  /* true for user given path */
   float *hedr ;                  /* the headers */
   float *data ;                  /* the data */

   int nt ;                       /* number of trace samples */
   float dt ;                     /* sample interval, sec */
   float delrt ;                  /* delay recording time, sec */
   cwp_String key[SU_NKEYS] ;     /* array of keywords */
   cwp_String type ;              /* key string type */
   int nkeys ;                    /* number of keywords */
   int ikey,ntr = 0 ;	          /* counters */
   int num ;                      /* number of traces to dump */
   int numtr = 4 ;                /* number of traces to dump */
   int hpf ;                      /* header print format */

   /* Initialize */
   initargs(argc, argv) ;
   requestdoc(1) ;

   /* Look for user-supplied tmpdir */
   if (!getparstring("tmpdir",&tmpdir) &&
       !(tmpdir = getenv("CWP_TMPDIR"))) tmpdir="";
   if (!STREQ(tmpdir, "") && access(tmpdir, WRITE_OK))
       err("you can't write in %s (or it doesn't exist)", tmpdir);

   /* Get values from first trace */
   if (!gettr(&tr)) err("can't get first trace");
   nt = (int) tr.ns ;                  /* Get nt */
   dt = ((double) tr.dt)/1000000.0 ;   /* microsecs to secs */
   if (!dt) getparfloat("dt", &dt) ;
   if (!dt) MUSTGETPARFLOAT("dt", &dt) ;
   delrt = ((double) tr.delrt)/1000.0 ; /* millisecs to secs */

   /* Get parameters */
   if (getparint ("num", &num)) numtr = num ;
   if ((nkeys=countparval("key"))!=0) getparstringarray("key",key) ;
   hedr = ealloc1float(nkeys*numtr) ;  /* make space for headers */
   if (!getparint ("hpf", &hpf)) hpf = 0 ;

   /* Store traces, headers in tempfiles */
   if (STREQ(tmpdir,""))
   {
      tracefp = etmpfile();
      headerfp = etmpfile();

      do
      {
         ++ntr;
         efwrite(&tr, HDRBYTES, 1, headerfp);
         efwrite(tr.data, FSIZE, nt, tracefp);

         /* Get header values */
         for (ikey=0; ikey<nkeys; ++ikey)
         {
            Value val;
            float fval;

            gethdval(&tr, key[ikey], &val) ;
            type = hdtype(key[ikey]) ;
            fval = vtof(type,val) ;
            hedr[(ntr-1)*nkeys+ikey] = fval ;
         }

      }
      while (ntr<numtr  &&  gettr(&tr)) ;

   }
   else  /* user-supplied tmpdir */
   {
      char directory[BUFSIZ];
      strcpy(directory, tmpdir);
      strcpy(tracefile, temporary_filename(directory));
      strcpy(headerfile, temporary_filename(directory));
      /* Handle user interrupts */
      signal(SIGINT, (void (*) (int)) closefiles);
      signal(SIGQUIT, (void (*) (int)) closefiles);
      signal(SIGHUP,  (void (*) (int)) closefiles);
      signal(SIGTERM, (void (*) (int)) closefiles);
      tracefp = efopen(tracefile, "w+");
      headerfp = efopen(headerfile, "w+");
      istmpdir=cwp_true;      

      do
      {
         ++ntr;
         efwrite(&tr, HDRBYTES, 1, headerfp);
         efwrite(tr.data, FSIZE, nt, tracefp);

         /* Get header values */
         for (ikey=0; ikey<nkeys; ++ikey)
         {
            Value val;
            float fval;

            gethdval(&tr, key[ikey], &val) ;
            type = hdtype(key[ikey]) ;
            fval = vtof(type,val) ;
            hedr[(ntr-1)*nkeys+ikey] = fval ;
         }

      }
      while (ntr<numtr  &&  gettr(&tr)) ;

   }

   /* Rewind after read, allocate space */
   erewind(tracefp);
   erewind(headerfp);
   data = ealloc1float(nt*ntr);

   /* Load traces into data and close tmpfile */
   efread(data, FSIZE, nt*ntr, tracefp);
   efclose(tracefp);
   if (istmpdir) eremove(tracefile);

   rewind(headerfp);
   rewind(tracefp);

   /* Do trace work */
   dump(data, dt, hedr, key, delrt, nkeys, ntr, nt, hpf) ;

   /* close */
   efclose(headerfp);
   if (istmpdir) eremove(headerfile);

   free1(hedr) ;
   free1(data) ;

   return(CWP_Exit()) ;
}
Beispiel #17
0
double HDCrude::GetfBmax()
{
	return vtof( m_pRs.GetFieldValue(m_strfBmaxField) );
}
Beispiel #18
0
//得到头部件伸入下一部件的长度
double Connect::GetCNTBextlenFLD() 
{
	return vtof( m_pRs.GetFieldValue(m_strCNTBextlenFLDField) );
}
Beispiel #19
0
int
main(int argc, char **argv)
{
	FILE *headerfp=NULL;	/* temporary file for trace header	*/
				/*  ... (1st trace of ensemble);	*/
	char *key=NULL;		/* header key word from segy.h		*/
	char *type=NULL;	/* ... its type				*/
	int index;		/* ... its index			*/
	Value val;		/* ... its value			*/
	float fval = 0;		/* ... its value cast to float		*/
	float prevfval;		/* ... its value of the previous trace	*/

	complex *ct=NULL;	/* complex trace			*/
	complex *psct=NULL;	/* phase-stack data array		*/

	float *data=NULL;	/* input data array			*/
	float *hdata=NULL;	/* array of Hilbert transformed input data */
	float *stdata=NULL;	/* stacked data ("ordinary" stack)	*/
	float *psdata;	/* phase-stack data array (real weights for PWS)*/
	float a;	/* inst. amplitude				*/
	float dt;	/* time sample spacing in seconds		*/
	float pwr;	/* raise  phase stack to power pwr		*/
	float sl;	/* smoothing window length in seconds		*/

	int gottrace;	/* flag: set to 1, if trace is read from stdin	*/

	int i;		/* loop index					*/
	int isl;	/* smoothing window length in samples		*/
	int nt;		/* number of points on input trace		*/
	int ntr;	/* trace counter				*/
	int ps;		/* flag: output is PWS (0) or phase stack (1)	*/
	int verbose;	/* verbose flag					*/

	cwp_Bool pws_and_cdp=cwp_false;	/* are PWS and CDP set?		*/

	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);

	/* Get info from first trace */
	if(!gettr(&intr)) err("can't get first trace");
	nt = intr.ns;

	/* Get parameters */
	if (!getparstring("key", &key))			key="cdp";
	if (!getparfloat("pwr", &pwr))			pwr = 1.0;
	if (!getparfloat("dt", &dt)) dt = ((double) intr.dt)/1000000.0;
	if (!getparfloat("sl", &sl))			sl = 0.0;
	if (!getparint("ps", &ps))			ps = 0;
	if (!getparint("verbose", &verbose))		verbose = 0;

	if (STREQ(key, "cdp") &&  !(ps))
		pws_and_cdp = cwp_true;

	/* convert seconds to samples (necessary only for smoothing) */
	if (!dt) {
		dt = 0.004;
		warn("dt not set, assuming dt=0.004");
	}

	/* integerized smoothing window length */
	isl = NINT(fabs(sl)/dt);
	if (isl>nt)
		err("sl=%g too long for trace", fabs(sl));

	/* diagnostic print */
	if (verbose && isl)
		warn("smoothing window = %d samples", isl);

	/* initialize flag */
	gottrace = 1;

	/* get key type and index */
	type = hdtype(key);
	index = getindex(key);

	/* Get value of key and convert to float */
	prevfval = fval;
	gethval(&intr, index, &val);
	fval = vtof(type,val);

	/* remember previous value of key */
	prevfval = fval;

	/* allocate space for data, hilbert transformed data, */
	/* phase-stacked data and complex trace */
	data = ealloc1float(nt);
	hdata = ealloc1float(nt);
	stdata = ealloc1float(nt);
	psdata = ealloc1float(nt);
	psct = ealloc1complex(nt);
	ct = ealloc1complex(nt);


	/* zero out accumulators */
	memset( (void *) stdata, 0, nt*FSIZE);
	memset( (void *) psct, 0, nt*(sizeof(complex)));


	/* open temporary file for trace header   */
	headerfp = etmpfile();

	/* store trace header in temporary file and read data */
	efwrite(&intr, HDRBYTES, 1, headerfp);

	/* loop over input traces */
	ntr=0;
	while (gottrace|(~gottrace) ) { /* middle exit loop */

		/* if got a trace */
		if (gottrace) {
			/* get value of key */
			gethval(&intr, index, &val);
			fval = vtof(type,val);

			/* get data */
			memcpy((void *) data, (const void *) intr.data,
					nt*FSIZE);
		}

		/* construct quadrature trace with hilbert transform */
		hilbert(nt, data, hdata);

		/* build the complex trace and get rid of amplitude */
		for (i=0; i<nt; i++) {
			ct[i] = cmplx(data[i],hdata[i]);
			a = (rcabs(ct[i])) ? 1.0 / rcabs(ct[i]) : 0.0;
			ct[i] = crmul(ct[i], a);
		}

		/* stacking */
		if (fval==prevfval && gottrace) {
			++ntr;
			for (i=0; i<nt; ++i) {
				stdata[i] += data[i];
				psct[i] = cadd(psct[i],ct[i]);
			}
		}

		/* if key-value has changed or no more input traces */
		if (fval!=prevfval || !gottrace) {

			/* diagnostic print */
			if (verbose)
				warn("%s=%g, fold=%d\n", key, prevfval, ntr);

			/* convert complex phase stack to real weights */
			for (i=0; i<nt; ++i) {
				psdata[i] = rcabs(psct[i]) / (float) ntr;
				psdata[i] = pow(psdata[i], pwr);
			}

			/* smooth phase-stack (weights) */
			if (isl) do_smooth(psdata,nt,isl);

			/* apply weights to "ordinary" stack (do PWS) */
			if (!ps) {
				for (i=0; i<nt; ++i) {
					stdata[i] *= psdata[i] / (float) ntr;
				}
			}

			/* set header and write PS trace or */
			/* PWS trace to stdout */
			erewind(headerfp);
			efread(&outtr, 1, HDRBYTES, headerfp);
			outtr.nhs=ntr;
			if (ps) {
				memcpy((void *) outtr.data,
					(const void *) psdata, nt*FSIZE);
			} else {
				memcpy((void *) outtr.data,
					(const void *) stdata, nt*FSIZE);
			}

			/* zero offset field if a pws and cdp stack */
			if (pws_and_cdp) outtr.offset = 0;

			puttr(&outtr);

			/* if no more input traces, break input trace loop* */
			if (!gottrace) break;


			/* remember previous value of key */
			prevfval = fval;

			/* zero out accumulators */
			ntr=0;
			memset( (void *) stdata, 0, nt*FSIZE);
			memset( (void *) psct, 0, nt*(sizeof(complex)));

			/* stacking */
			if (gottrace) {
				++ntr;
				for (i=0; i<nt; ++i) {
					stdata[i] += data[i];
					psct[i] = cadd(psct[i],ct[i]);
				}
			}

			/* save trace header for output trace */
			erewind(headerfp);
			efwrite(&intr, HDRBYTES, 1, headerfp);
		}

		/* get next trace (if there is one) */
		if (!gettr(&intr)) gottrace = 0;

	} /* end loop over traces */

	return(CWP_Exit());
}
Beispiel #20
0
int
main(int argc, char **argv)
{
	char *key=NULL;		/* header key word from segy.h		*/
	char *type=NULL;	/* ... its type				*/
	int index;		/* ... its index			*/
	Value val;		/* ... its value			*/
	float fval;		/* ... its value cast to float		*/

	float *xshift=NULL;	/* array of key shift curve values	*/
	float *tshift=NULL;	/* ...		shift curve time values */

	int nxshift;		/* number of key shift values		*/
	int ntshift;		/* ...		shift time values 	*/

	int nxtshift;		/* number of shift values 		*/

	int it;			/* sample counter			*/
	int itr;		/* trace counter			*/
	int nt;			/* number of time samples 		*/
	int ntr=0;		/* number of traces			*/
	int *inshift=NULL;	/* array of (integer) time shift values
				   used for positioning shifted trace in
				   data[][]				*/

	float dt;		/* time sampling interval		*/

	cwp_String xfile="";	/* file containing positions by key	*/
	FILE *xfilep=NULL;	/* ... its file pointer			*/
	cwp_String tfile="";	/* file containing times	 	*/
	FILE *tfilep=NULL;	/* ... its file pointer			*/

	int verbose;		/* flag for printing information	*/
	char *tmpdir=NULL;	/* directory path for tmp files		*/
	cwp_Bool istmpdir=cwp_false;/* true for user-given path		*/

	int median;		/* flag for median filter		*/
	int nmed;		/* no. of traces to median filter	*/
	int nmix;		/* number of traces to mix over		*/
	int imix;		/* mixing counter			*/
	float *mix=NULL;	/* array of mix values			*/
	int sign;		/* flag for up/down shift		*/
	int shiftmin=0;		/* minimum time shift (in samples)	*/
	int shiftmax=0;		/* maximum time shift (in samples)	*/
	int ntdshift;		/* nt + shiftmax			*/

	size_t mixbytes;	/* size of mixing array			*/
	size_t databytes;	/* size of data array			*/
	size_t shiftbytes;	/* size of data array			*/
	float *temp=NULL;	/* temporary array			*/
	float *dtemp=NULL;	/* temporary array			*/
	float *stemp=NULL;	/* rwh median sort array		*/
	float **data=NULL;	/* mixing array 			*/
	int subtract;		/* flag for subtracting shifted data	*/

	/* rwh extra pointers for median sort */
	int first;		/* start pointer in ring buffer */
	int middle;		/* middle pointer in ring buffer */
	int last;		/* last pointer in ring buffer */
	int halfwidth;		/* mid point */
	int trcount;		/* pointer to current start trace number */
	float tmp;		/* temp storage for bubble sort */
	int rindex;		/* wrap around index for ring buffer */
	int jmix;		/* internal pointer for bubble sort */
	

	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);

	/* Get parameters */
	if (!(getparstring("xfile",&xfile) && getparstring("tfile",&tfile))) {
		if (!(nxshift = countparval("xshift")))
			err("must give xshift= vector");
		if (!(ntshift = countparval("tshift")))
			err("must give tshift= vector");
		if (nxshift != ntshift)
			err("lengths of xshift, tshift must be the same");
		xshift = ealloc1float(nxshift);	getparfloat("xshift", xshift);
		tshift = ealloc1float(nxshift);	getparfloat("tshift", tshift);
	} else {
		MUSTGETPARINT("nshift",&nxtshift);
		nxshift = nxtshift;
		xshift = ealloc1float(nxtshift);
		tshift = ealloc1float(nxtshift);

		if((xfilep=fopen(xfile,"r"))==NULL)
			err("cannot open xfile=%s\n",xfile);
		if (fread(xshift,sizeof(float),nxtshift,xfilep)!=nxtshift)
			err("error reading xfile=%s\n",xfile);
		fclose(xfilep);

		if((tfilep=fopen(tfile,"r"))==NULL)
			err("cannot open tfile=%s\n",tfile);
		if (fread(tshift,sizeof(float),nxtshift,tfilep)!=nxtshift)
			err("error reading tfile=%s\n",tfile);
		fclose(tfilep);
	}
	if (!getparstring("key", &key))		key = "tracl";

	/* Get key type and index */
	type = hdtype(key);
	index = getindex(key);   

	/* Get mix weighting values values */
	if ((nmix = countparval("mix"))!=0) {
		mix = ealloc1float(nmix);
		getparfloat("mix",mix);
		/* rwh check nmix is odd */
		if (nmix%2==0) {
			err("number of mixing coefficients must be odd");
		}		
	} else {
		nmix = 5;
		mix = ealloc1float(nmix);
		mix[0] = VAL0;
		mix[1] = VAL1;
		mix[2] = VAL2;
		mix[3] = VAL3;
		mix[4] = VAL4;
	}
	
	/* Get remaning parameters */
	if (!getparint("median",&median))	median = 0;
	if (!getparint("nmed",&nmed) && median)	nmed = 5;
	if (!getparint("sign",&sign))		sign = -1;
	if (!getparint("subtract",&subtract))	subtract = 1;
	if (!getparint("verbose", &verbose))	verbose = 0;

	/* rwh check nmed is odd */
	if (median && nmed%2==0) {
		nmed=nmed+1;
		warn("increased nmed by 1 to ensure it is odd");
	}

	/* Look for user-supplied tmpdir */
	if (!getparstring("tmpdir",&tmpdir) &&
	    !(tmpdir = getenv("CWP_TMPDIR"))) tmpdir="";
	if (!STREQ(tmpdir, "") && access(tmpdir, WRITE_OK))
		err("you can't write in %s (or it doesn't exist)", tmpdir);

	/* rwh fix for median filter if median true set nmix=nmed */
	if (!median) {
		/* Divide mixing weights by number of traces to mix */
		for (imix = 0; imix < nmix; ++imix)
			mix[imix]=mix[imix]/((float) nmix);
	} else {
		nmix=nmed;
	}

	/* Get info from first trace */
	if (!gettr(&tr)) err("can't read first trace");
	if (!tr.dt) err("dt header field must be set");
	dt   = ((double) tr.dt)/1000000.0;
	nt = (int) tr.ns;
	databytes = FSIZE*nt;

	/* Tempfiles */
	if (STREQ(tmpdir,"")) {
		tracefp = etmpfile();
		headerfp = etmpfile();
		if (verbose) warn("using tmpfile() call");
	} else { /* user-supplied tmpdir */
		char directory[BUFSIZ];
		strcpy(directory, tmpdir);
		strcpy(tracefile, temporary_filename(directory));
		strcpy(headerfile, temporary_filename(directory));
		/* Trap signals so can remove temp files */
		signal(SIGINT,  (void (*) (int)) closefiles);
		signal(SIGQUIT, (void (*) (int)) closefiles);
		signal(SIGHUP,  (void (*) (int)) closefiles);
		signal(SIGTERM, (void (*) (int)) closefiles);
		tracefp = efopen(tracefile, "w+");
		headerfp = efopen(headerfile, "w+");
      		istmpdir=cwp_true;		
		if (verbose) warn("putting temporary files in %s", directory);
	}

	/* Read headers and data while getting a count */
	do {
		++ntr;
		efwrite(&tr, 1, HDRBYTES, headerfp);
		efwrite(tr.data, 1, databytes, tracefp);   

	} while (gettr(&tr));
	rewind(headerfp);
	rewind(tracefp);
	
	/* Allocate space for inshift vector */
	inshift = ealloc1int(ntr);

	/* Loop over headers */
 	for (itr=0; itr<ntr; ++itr) {
		float tmin=tr.delrt/1000.0;
		float t;

		/* Read header values */
		efread(&tr, 1, HDRBYTES, headerfp);

		/* Get value of key and convert to float */
		gethval(&tr, index, &val);
		fval = vtof(type,val);

		/* Linearly interpolate between (xshift,tshift) values */
		intlin(nxshift,xshift,tshift,tmin,tshift[nxshift-1],1,&fval,&t);
		
		/* allow for fractional shifts -> requires interpolation */ 
		inshift[itr] = NINT((t - tmin)/dt);
		
		/* Find minimum and maximum shifts */
		if (itr==0) {
			 shiftmax=inshift[0];
			 shiftmin=inshift[0];
		} else {
			shiftmax = MAX(inshift[itr],shiftmax);
			shiftmin = MIN(inshift[itr],shiftmin);
		}
	}
	rewind(headerfp);
	rewind(tracefp);

	if (verbose) {
		for (itr=0;itr<ntr;itr++)
			warn("inshift[%d]=%d",itr,inshift[itr]);
	}

	/* Compute databytes per trace and bytes in mixing panel */
	ntdshift = nt + shiftmax;
	shiftbytes = FSIZE*ntdshift;
	mixbytes = shiftbytes*nmix;
	if (verbose) {
		warn("nt=%d  shiftmax=%d  shiftmin=%d",nt,shiftmax,shiftmin);
		warn("ntdshift=%d  shiftbytes=%d  mixbytes=%d",
						ntdshift,shiftbytes,mixbytes);
	}
	
	/* Allocate space and zero  data array */
	data = ealloc2float(ntdshift,nmix);
	temp = ealloc1float(ntdshift);
	dtemp = ealloc1float(nt);
	memset( (void *) data[0], 0, mixbytes);

	/* rwh array for out of place bubble sort (so we do not corrupt order in ring buffer */ 
	stemp = ealloc1float(nmix);

	/* rwh first preload ring buffer symmetrically (now you know why nmix must be odd) */
	trcount=-1;
	halfwidth=(nmix-1)/2+1;
	first = 0;
	last  = nmix-1;
	middle = (nmix-1)/2;

	for (itr=0; itr<halfwidth; itr++) {
		efread(tr.data, 1, databytes, tracefp);
		trcount++;
		for(it=0; it<nt; ++it) {
			/* sign to account for positive or negative shift */
			/* tr.data needs to be interpolated for non-integer shifts */
			data[middle-itr][it + shiftmax + sign*inshift[itr]] = tr.data[it];
			data[middle+itr][it + shiftmax + sign*inshift[itr]] = tr.data[it];
		}
	}
	
	/* Loop over traces performing median filtering  */
 	for (itr=0; itr<ntr; ++itr) {

		/* paste header and data on output trace */
		efread(&tr, 1, HDRBYTES, headerfp);

		/* Zero out temp and dtemp */
		memset((void *) temp, 0, shiftbytes);
		memset((void *) dtemp, 0, databytes);

		/* Loop over time samples */
		for (it=0; it<nt; ++it) {

			/* Weighted moving average (mix) ? */
			if (!median) {
				for(imix=0; imix<nmix; ++imix) {
					temp[it] += data[imix][it] * mix[imix];
				}
			} else {
			
			/* inlcude median stack */
			/* rwh do bubble sort and choose median value */
				for(imix=0; imix<nmix; ++imix) {
					stemp[imix]=data[imix][it];
				}
				for (imix=0; imix<nmix-1; imix++) {
					for (jmix=0; jmix<nmix-1-imix; jmix++) {
						if (stemp[jmix+1] < stemp[jmix]) {
							tmp = stemp[jmix];
							stemp[jmix] = stemp[jmix+1];
							stemp[jmix+1] = tmp;
						}
					}
				}
				temp[it] = stemp[middle];
			}

			/* shift back mixed data and put into dtemp */
			if (subtract) {
				if ((it - shiftmax - sign*inshift[itr])>=0)
					dtemp[it - shiftmax - sign*inshift[itr]] = data[middle][it]-temp[it];
			} else {
				if ((it - shiftmax)>=0)
				dtemp[it - shiftmax - sign*inshift[itr]] = temp[it];
			}
		}
		memcpy((void *) tr.data,(const void *) dtemp,databytes);
			
		/* Bump rows of data[][] over by 1 to free first row for next tr.data */
		for (imix=nmix-1; 0<imix; --imix)
			memcpy((void *) data[imix],(const void *) data[imix-1],shiftbytes);
			/*for (it=0; it<nt; ++it)
				data[imix][it] = data[imix-1][it];*/

		/* Write output trace */
		tr.ns = nt;
		puttr(&tr);

		/* read next trace into buffer */
		if (trcount < ntr) {
			efread(tr.data, 1, databytes, tracefp);
			trcount++;

			/* read tr.data into first row of mixing array */
			/* WMH: changed ntdshift to nt */
			for(it=0; it<nt; ++it) {
				/* sign to account for positive or negative shift */
				/* tr.data needs to be interpolated for non-integer shifts */
				data[0][it + shiftmax + sign*inshift[trcount]] = tr.data[it];
			}
		} else {
			rindex=2*(trcount-ntr);
			memcpy((void *) data[0],(const void *) data[rindex],shiftbytes);
			trcount++;
		}

	}

	if (verbose && subtract)	warn("filtered data subtracted from input");

	/* Clean up */
	efclose(headerfp);
	if (istmpdir) eremove(headerfile);
	efclose(tracefp);
	if (istmpdir) eremove(tracefile);

	return(CWP_Exit());
}
Beispiel #21
0
int
main(int argc, char **argv)
{
	char *key=NULL;		/* header key word from segy.h		*/	
	char *type=NULL;	/* ... its type				*/
	int index;		/* ... its index			*/
	Value val;		/* ... its value			*/
	float fval;		/* ... its value cast to float		*/
	float twfval;		/* ... its value cast to float		*/
	float *xmute=NULL;	/* array of key mute curve values	*/
	float *tmute=NULL;	/* ...		mute curve time values 	*/
	float *twindow=NULL;	/* ...	mute window time values mode=4	*/
	float linvel;		/* linear velocity			*/
	float tm0;		/* time shift of mute=2 or 3 for 'key'=0*/
	float *taper=NULL;	/* ...		taper values		*/
	int nxmute=0;		/* number of key mute values		*/
	int ntmute;	/* ...		mute time values 	*/
	int ntwindow;	/* ...		mute time values 	*/
	int ntaper;	/* ...		taper values		*/

	int below;	/* mute below curve			*/
	int mode;	/* kind of mute (top, bottom, linear)	*/
	int absolute;    /* Take absolute value of key for mode=2 */
	int hmute=0;	/* read mute times from header		*/

	int nxtmute;	/* number of mute values 		*/
	cwp_String xfile="";	/* file containing positions by key	*/
	FILE *xfilep;		/* ... its file pointer			*/
	cwp_String tfile="";	/* file containing times	 	*/
	FILE *tfilep;		/* ... its file pointer			*/

	cwp_String twfile="";	/* file containing mute time windows 	*/
	FILE *twfilep;		/* ... its file pointer			*/

	cwp_Bool seismic;	/* cwp_true if seismic, cwp_false not seismic */

	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);


	/* Get parameters */
	if (!getparint("mode", &mode))		mode = 0;

	if (getparstring("hmute", &key)) { hmute = 1; } else

	if (!(getparstring("xfile",&xfile) && getparstring("tfile",&tfile))) {
		if (!(nxmute = countparval("xmute")))
			err("must give xmute= vector");
		if (!(ntmute = countparval("tmute")))
			err("must give tmute= vector");
		if (nxmute != ntmute)
			err("lengths of xmute, tmute must be the same");
		xmute = ealloc1float(nxmute);	getparfloat("xmute", xmute);
		tmute = ealloc1float(nxmute);	getparfloat("tmute", tmute);
		if (mode==4) {
			if (!(ntwindow = countparval("twindow")))
				err("must give twindow= vector");
			if (nxmute != ntwindow)
				err("lengths of xmute, twindow must be the same");
			twindow = ealloc1float(nxmute);
			getparfloat("twindow", twindow);
		}
	} else {
		MUSTGETPARINT("nmute",&nxtmute);
		nxmute = nxtmute;
		xmute = ealloc1float(nxtmute);
		tmute = ealloc1float(nxtmute);

		if((xfilep=fopen(xfile,"r"))==NULL)
			err("cannot open xfile=%s\n",xfile);
		if (fread(xmute,sizeof(float),nxtmute,xfilep)!=nxtmute)
			err("error reading xfile=%s\n",xfile);
		fclose(xfilep);

		if((tfilep=fopen(tfile,"r"))==NULL)
			err("cannot open tfile=%s\n",tfile);
		if (fread(tmute,sizeof(float),nxtmute,tfilep)!=nxtmute)
			err("error reading tfile=%s\n",tfile);
		fclose(tfilep);

		if (mode==4) {
			if((twfilep=fopen(twfile,"r"))==NULL)
				err("cannot open tfile=%s\n",twfile);
			if (fread(twindow,sizeof(float),nxtmute,twfilep)!=nxtmute)
				err("error reading tfile=%s\n",tfile);
			fclose(twfilep);
		}
	}

	if (!getparint("ntaper", &ntaper))	ntaper = 0;
	if (getparint("below", &below))	{
		mode = below; 
		warn ("use of below parameter is obsolete. mode value set to %d \n", mode);
	}
	if (!getparint("absolute", &absolute))		absolute = 1;
	if (hmute==0) if (!getparstring("key", &key))	key = "offset";
	if (!getparfloat("linvel", &linvel))	linvel = 330;
	if (!getparfloat("tm0", &tm0))		tm0 = 0;
        checkpars();
	if (linvel==0) err ("linear velocity can't be 0");

	/* get key type and index */
	type = hdtype(key);
	index = getindex(key);

	/* Set up taper weights if tapering requested */
	if (ntaper) {
		register int k;
		taper = ealloc1float(ntaper);
		for (k = 0; k < ntaper; ++k) {
			float s = sin((k+1)*PI/(2*ntaper));
			taper[k] = s*s;
		}
	}

						
	/* Get info from first trace */
	if (!gettr(&tr)) err("can't read first trace");

	seismic = ISSEISMIC(tr.trid);

	if (seismic) {
		if (!tr.dt) err("dt header field must be set");
	} else if (tr.trid==TRID_DEPTH) {   /* depth section */
		if (!tr.d1) err("d1 header field must be set");
	} else {
		err ("tr.trid = %d, unsupported trace id",tr.trid);
	}

	/* Loop over traces */
	do {
		int nt     = (int) tr.ns;
		float tmin = tr.delrt/1000.0;
		float dt = ((double) tr.dt)/1000000.0;
		float t;
		float tw;
		int nmute;
		int itaper;
		int topmute;
		int botmute;
		int ntair=0;
		register int i;

		if (!seismic) { 
			tmin = 0.0;
			dt = tr.d1;	
		}

		/* get value of key and convert to float */
		gethval(&tr, index, &val);
		fval = vtof(type,val);
		

		if (hmute==1) {
			t = fval/1000.;
		} else {
		/* linearly interpolate between (xmute,tmute) values */
		intlin(nxmute,xmute,tmute,tmin,tmute[nxmute-1],1,&fval,&t); 
		}

		if (absolute) fval = abs(fval);
		/* do the mute */
		if (mode==0) {	/* mute above */
			nmute = MIN(NINT((t - tmin)/dt),nt);
			if (nmute>0) memset( (void *) tr.data, 0, nmute*FSIZE);
			for (i = 0; i < ntaper; ++i)
				if (i+nmute>0) tr.data[i+nmute] *= taper[i];
			if (seismic) {
				tr.muts = NINT(t*1000);
			} else	{
				tr.muts = NINT(t);
			}
		} else if (mode==1){	/* mute below */
			nmute = MAX(0,NINT((tmin + nt*dt - t)/dt));
			memset( (void *) (tr.data+nt-nmute), 0, nmute*FSIZE);
			for (i = 0; i < ntaper; ++i)
				if (nt>nmute+i && nmute+i>0)
					tr.data[nt-nmute-1-i] *= taper[i];
			if (seismic) {
				tr.mute = NINT(t*1000);
			} else	{
				tr.mute = NINT(t);
			}
		} else if (mode==2){	/* air wave mute */
			nmute = NINT((tmin+t)/dt);
			ntair=NINT(tm0/dt+fval/linvel/dt);
			topmute=MIN(MAX(0,ntair-nmute/2),nt);
			botmute=MIN(nt,ntair+nmute/2);
			memset( (void *) (tr.data+topmute), 0,
					(botmute-topmute)*FSIZE);
			for (i = 0; i < ntaper; ++i){
				itaper=ntair-nmute/2-i;
				if (itaper > 0) tr.data[itaper] *=taper[i];
			}	
			for (i = 0; i < ntaper; ++i){
				itaper=ntair+nmute/2+i;
				if (itaper<nt) tr.data[itaper] *=taper[i];
			}
		} else if (mode==3) {	/* hyperbolic mute */
			nmute = NINT((tmin + t)/dt);
			ntair=NINT(sqrt( SQ((float)(tm0/dt))+SQ((float)(fval/linvel/dt)) ));
			topmute=MIN(MAX(0,ntair-nmute/2),nt);
			botmute=MIN(nt,ntair+nmute/2);
			memset( (void *) (tr.data+topmute), 0,
					(botmute-topmute)*FSIZE);
			for (i = 0; i < ntaper; ++i){
				itaper=ntair-nmute/2-i;
				if (itaper > 0) tr.data[itaper] *=taper[i];
			}	
			for (i = 0; i < ntaper; ++i){
				itaper=ntair+nmute/2+i;
				if (itaper<nt) tr.data[itaper] *=taper[i];
			}
		} else if (mode==4) {	/* polygonal mute */
			tmin=twindow[0];
			intlin(nxmute,xmute,twindow,tmin,twindow[nxmute-1],1,&twfval,&tw); 
			if (absolute) twfval = abs(twfval);

			nmute = NINT(tw/dt);
			ntair = NINT(t/dt);

			topmute=MIN(MAX(0,ntair-nmute/2),nt);
			botmute=MIN(nt,ntair+nmute/2);
			memset( (void *) (tr.data+topmute), 0,
					(botmute-topmute)*FSIZE);
			for (i = 0;i < ntaper; ++i){
				itaper=ntair-nmute/2-i;
				if (itaper > 0) tr.data[itaper] *=taper[i];
			}	
			for (i = 0; i < ntaper; ++i){
				itaper=ntair+nmute/2+i;
				if (itaper<nt) tr.data[itaper] *=taper[i];
			}


		}
		puttr(&tr);
	} while (gettr(&tr));
	
	return(CWP_Exit());
}
Beispiel #22
0
//更新指定工程的记录, 由已知的字段,算出其它字段的值.
bool CImportAutoPD::RefreshData(CString EnginID)
{
	if( EnginID.IsEmpty() )
	{ 
		return false;
	}
	CString strSQL;
	_RecordsetPtr  pRs;

	_RecordsetPtr  pRs_Weather;		//参数表.
	pRs_Weather.CreateInstance(__uuidof(Recordset));
	HRESULT hr;
	double  e_rate, con_temp1, con_temp2, e_hours, e_wind, Pro_thi;
	double	e_wind_in;	//室内风速

	double   dWeatherTemp=0;							//在气象表中的环境温度值
	try
	{
		strSQL = "SELECT * FROM [Ta_Variable] ";
		pRs_Weather->Open(_variant_t(strSQL), theApp.m_pConnectionCODE.GetInterfacePtr(),
						adOpenStatic, adLockOptimistic, adCmdText);
		if (pRs_Weather->GetRecordCount() > 0)
		{
			//环境温度的索引值 为0
			strSQL = "Index=0";
			pRs_Weather->Find(_bstr_t(strSQL), 0, adSearchForward); 
			if (!pRs_Weather->adoEOF)
			{
				//气象参数表中的"室内环境温度"值
				dWeatherTemp = vtof(pRs_Weather->GetCollect(_variant_t("Ta_Variable_VALUE")) );					
			}
		}

		hr = pRs.CreateInstance(__uuidof(Recordset));
		if( FAILED(hr) )
		{
			return false;
		}
		strSQL = "SELECT * FROM [a_config] WHERE EnginID='"+EnginID+"' ";
		if( pRs->State == adStateOpen )
		{
			pRs->Close();
		}
		pRs->PutCursorLocation(adUseClient);
		pRs->Open(_variant_t(strSQL), (IDispatch*)theApp.m_pConnection,
					adOpenStatic, adLockOptimistic, adCmdText);

		if( pRs->GetRecordCount() < 1 )
		{	
			e_rate = con_temp1 = con_temp2 = e_hours = e_wind = 0;
		}
		else
		{
			//取出[a_config]表中的值,
			pRs->MoveFirst();
			e_rate    = vtof( pRs->GetCollect("年费用率") );
			con_temp1 = vtof( pRs->GetCollect("室内温度") );
			con_temp2 = vtof( pRs->GetCollect("室外温度") );
			e_hours   = vtof( pRs->GetCollect("年运行小时") );
			e_wind    = vtof( pRs->GetCollect("室外风速") );
		}
		e_wind_in = e_wind;    //室内风速为室外风速
	}
	catch(_com_error& e)
	{
		AfxMessageBox(e.Description());
		return false;
	}
	//如果气象库中的环境温度没有值时,则使用常量库中的环境温度
	con_temp1 = (dWeatherTemp <=0)? con_temp1:dWeatherTemp;

	strSQL = "SELECT * FROM [pre_calc] WHERE EnginID='"+EnginID+"' ";
	try
	{
		if (pRs->GetState() == adStateOpen)
		{
			pRs->Close();
		}
		
		pRs->Open(_variant_t(strSQL), theApp.m_pConnection.GetInterfacePtr(),
					adOpenStatic, adLockOptimistic, adCmdText);

		if( pRs->GetRecordCount() <= 0 )
		{	//没有记录时
			return true;
		}
		CString tempStr, place, steam;
		pRs->MoveFirst();//
		//循环.对一些字段进行处理.
		//如:
		// 安装地点(c_p_s)字段值为(室外汽管) 将其分为"室外"另存到c_place;
		//											 "汽管"存到c_steam
		while( !pRs->adoEOF )
		{
			//年费用率
			pRs->PutCollect(_variant_t("c_rate"), _variant_t(e_rate));
			//年运行小时
			pRs->PutCollect(_variant_t("c_hour"), _variant_t(e_hours));

			tempStr = vtos( pRs->GetCollect("c_name3") );
			if( !tempStr.IsEmpty() )
			{
				if( tempStr.Find("(") == -1 )
				{
					Pro_thi = 20.0;
				}
				else
				{
					tempStr = tempStr.Mid( tempStr.Find("(")+1 );
					Pro_thi = strtod(tempStr, NULL);
				}
				pRs->PutCollect(_variant_t("c_pro_thi"), _variant_t(Pro_thi) );
			}
			//处理c_place字段
			tempStr = vtos(pRs->GetCollect("c_place"));		// 自动导入PD中的数据时,对安装地点进行处理。 [2005/06/02] 
			tempStr.TrimLeft(); 
			tempStr.TrimRight();
			tempStr.MakeUpper();

			if( !tempStr.IsEmpty() )
			{
				place = tempStr.Left(4);
				tempStr = tempStr.Mid(4);
				steam = tempStr.Right(4);

				//安装地点字段不存储汽管或水管类型
//				pRs->PutCollect(_variant_t("c_place"), _variant_t(place));
//				pRs->PutCollect(_variant_t("c_steam"), _variant_t(steam));

				if( -1 != place.Find("室内") )
				{
					pRs->PutCollect(_variant_t("c_con_temp"), _variant_t(con_temp1));
					//室内风速为0
					pRs->PutCollect(_variant_t("c_wind"), _variant_t(e_wind_in));
				}
				else
				{
					pRs->PutCollect(_variant_t("c_con_temp"), _variant_t(con_temp2));
					//室外风速
					pRs->PutCollect(_variant_t("c_wind"), _variant_t(e_wind));
				}
			}
			pRs->Update();
			pRs->MoveNext();
		}
	}
	catch(_com_error& e)
	{
		AfxMessageBox(e.Description());
		return false;
	}
	return true;
}
Beispiel #23
0
double HDCrude::GetSizeH()
{
	return vtof(m_pRs.GetFieldValue(m_strSizeHField));
}