// OperUrfFile.cpp: implementation of the COperUrfFile class. // ////////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "GeoMative.h" #include "OperUrfFile.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif extern int g_iUILanguage; extern CGeoMativeApp theApp; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// COperUrfFile::COperUrfFile() { m_pFile = NULL; m_fExtParam = 0; } COperUrfFile::~COperUrfFile() { CloseFile(); } bool COperUrfFile::OpenUrfFileForWrite(const char* pFileName) { if (NULL == pFileName) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("文件名不能为空!")); else MessageBoxEx(NULL, _T("pFileName can not be null!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } if (m_pFile) { CloseFile(); } m_pFile = fopen(pFileName, "w+"); if (NULL == m_pFile) { CString strShow = _T(""); if (LANG_ZHCN == g_iUILanguage) { strShow.Format(_T("打开文件%s失败!错误码%d"), pFileName, GetLastError()); AfxMessageBox(strShow); } else { strShow.Format(_T("Open file %s failed!ErrorCode = %d"), pFileName, GetLastError()); MessageBoxEx(NULL, strShow, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } return true; } bool COperUrfFile::WriteUrfHeadInfo() { if (NULL == m_pFile) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请先打开文件")); else MessageBoxEx(NULL, _T("Please open the file firstly"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } CString strText = _T("A 2D sample Universal Resistivity data File (URF)\r\nTop two lines are comments and the third line defines the length unit.\r\nUnit: meters\r\n"); fwrite(strText, 1, strText.GetLength(), m_pFile); fflush(m_pFile); return true; } bool COperUrfFile::Write3DUrfHeadInfo() { if (NULL == m_pFile) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("请先打开文件")); else MessageBoxEx(NULL, _T("Please open the file firstly"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } //CString strText = _T("A 3D sample Universal Resistivity data File (URF)\r\nTop two lines are comments and the third line defines the length unit.\r\nUnit: meters\r\n"); CString strText = _T("This is a 3D sample Universal Resistivity Data File for testing purpose only.\nTop two lines are comments and the third line defines the length unit.\nUnit: meters\n"); fwrite(strText, 1, strText.GetLength(), m_pFile); fflush(m_pFile); return true; } void COperUrfFile::CloseFile() { if (m_pFile) { fflush(m_pFile); fclose(m_pFile); m_pFile = NULL; } } bool COperUrfFile::WriteElecByCrossHoleGeomative(FILE* pFile, WORD wEamount, float fPoleSpace,CString strSCCN, CString strTaskID) { if (strTaskID.IsEmpty() && strSCCN.IsEmpty()) { return false; } _RecordsetPtr pRecConList = NULL; pRecConList.CreateInstance(_uuidof(Recordset)); int iLen = 0; int iElecID = 0; float fX, fY, fZ; CString strSql,strContent,strErr; strSql.Format(_T("select ElectrodeID,X,Y,Z from TTaskBindElecInfo where TaskID='%s'"), strTaskID); pRecConList->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if (pRecConList->GetRecordCount() < 1) { pRecConList->Close(); if (strSCCN.IsEmpty()) { return false; } strSql.Format(_T("select ElectrodeID,X,Y,Z from TCoordinatesInfo where ScriptCN='%s'"), strSCCN); pRecConList->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); } while ((short)0 == pRecConList->adoEOF) { iElecID = pRecConList->GetCollect(_T("ElectrodeID")).lVal; fX = pRecConList->GetCollect(_T("X")).fltVal; fY = pRecConList->GetCollect(_T("Y")).fltVal; fZ = pRecConList->GetCollect(_T("Z")).fltVal; strContent.Empty(); strContent.Format(_T("%d,%.2f,%.2f,%.2f\r\n"), iElecID, fX, fY, fZ); iLen = fwrite(strContent, 1, strContent.GetLength(), pFile); if (iLen != strContent.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strContent.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strContent.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } pRecConList->Close(); return false; } pRecConList->MoveNext(); } pRecConList->Close(); return true; } bool COperUrfFile::WriteElecByCrossHoleGeomativeAM(FILE* pFile, WORD wEamount, float fPoleSpace, CString strSCCN, CString strTaskID) { if (strTaskID.IsEmpty()&& strSCCN.IsEmpty()) { return false; } _RecordsetPtr pRecConList = NULL; pRecConList.CreateInstance(_uuidof(Recordset)); int iLen = 0, iIndex = 1; int iElecID = 0; float fX, fY, fZ,fWellMaxDepth; CString strSql, strContent, strErr; strSql.Format(_T("select WellMaxDepth from scon where Sname=(select Sname from td where TDCN='%s')"), strTaskID); pRecConList->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if (pRecConList->GetRecordCount() < 1) { pRecConList->Close(); strSql.Empty(); strSql.Format(_T("select WellMaxDepth from td where TDCN='%s'"), strTaskID); pRecConList->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if (pRecConList->GetRecordCount() < 1) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("查询任务信息失败")); else MessageBoxEx(NULL, _T("Query task information failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); pRecConList->Close(); return FALSE; } } fWellMaxDepth = pRecConList->GetCollect(_T("WellMaxDepth")).fltVal; pRecConList->Close(); // 如果测线长度(N*d)小于或等于100m,则R = 500; // 如果测线长度大于100m小于等于200m,则R = 1000 // 如果测线长度大于200m,R = 5000 int iR = 0; if (-fWellMaxDepth <= 100) { iR = 500; } else if (-fWellMaxDepth > 100 && -fWellMaxDepth <= 200) { iR = 1000; } else { iR = 5000; } strContent.Format(_T("1,-%d,0,0\r\n"), iR); fwrite(strContent, 1, strContent.GetLength(), pFile); strSql.Empty(); strSql.Format(_T("select ElectrodeID,X,Y,Z from TTaskBindElecInfo where TaskID='%s'"), strTaskID); pRecConList->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if (pRecConList->GetRecordCount() < 1) { pRecConList->Close(); if (strSCCN.IsEmpty()) { return false; } strSql.Format(_T("select ElectrodeID,X,Y,Z from TCoordinatesInfo where ScriptCN='%s'"), strSCCN); pRecConList->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); } while ((short)0 == pRecConList->adoEOF) { iElecID = pRecConList->GetCollect(_T("ElectrodeID")).lVal; fX = pRecConList->GetCollect(_T("X")).fltVal; fY = pRecConList->GetCollect(_T("Y")).fltVal; fZ = pRecConList->GetCollect(_T("Z")).fltVal; strContent.Empty(); strContent.Format(_T("%d,%.2f,%.2f,%.2f\r\n"), iElecID+1, fX, fY, fZ); iLen = fwrite(strContent, 1, strContent.GetLength(), pFile); if (iLen != strContent.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strContent.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strContent.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } pRecConList->Close(); return false; } iIndex++; pRecConList->MoveNext(); } strContent.Format(_T("%d,%d,0,0\r\n"), ++iIndex, iR); fwrite(strContent, 1, strContent.GetLength(), pFile); pRecConList->Close(); return true; } bool COperUrfFile::WriteElecByWenSch(FILE* pFile, WORD wEamount, float fPoleSpace, int iStartElec, int iEndElec) { CString strText, strErr; int iLen = 0; for (int i = 1; i <= wEamount; i++) { strText.Empty(); strText.Format(_T("%d,%.2f,0,0\r\n"), iStartElec+i-1, fPoleSpace*(i - 1)); iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } } return true; } bool COperUrfFile::WriteElecByWenSch_AMN(FILE* pFile, WORD wEamount, float fPoleSpace, int iStartElec, int iEndElec) { CString strText, strErr; int iLen = 0; int iR = 0; iR = wEamount*fPoleSpace; // 如果测线长度(N*d)小于或等于100m,则R = 500; // 如果测线长度大于100m小于等于200m,则R = 1000 // 如果测线长度大于200m,R = 5000 if (iR <= 100) { iR = 500; } else if (iR > 100 && iR <= 200) { iR = 1000; } else { iR = 5000; } for (int i = 1; i <= wEamount + 1; i++) { strText.Empty(); if (i == wEamount + 1) { strText.Format(_T("%d,%d,0,0,\r\n"), iStartElec + i - 1, iR); } else { strText.Format(_T("%d,%.2f,0,0\r\n"), iStartElec + i - 1, fPoleSpace*(i - 1)); } iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } } return true; } bool COperUrfFile::WriteElecByWenSch_MNB(FILE* pFile, WORD wEamount, float fPoleSpace, int iStartElec, int iEndElec) { CString strText, strErr; int iLen = 0; int iR = 0; iR = wEamount*fPoleSpace; // 如果测线长度(N*d)小于或等于100m,则R = 500; // 如果测线长度大于100m小于等于200m,则R = 1000 // 如果测线长度大于200m,R = 5000 if (iR <= 100) { iR = 500; } else if (iR > 100 && iR <= 200) { iR = 1000; } else { iR = 5000; } for (int i = 1; i <= wEamount + 1; i++) { strText.Empty(); if (i == 1) { strText.Format(_T("%d,-%d,0,0,\r\n"), iStartElec + i - 1, iR); } else { strText.Format(_T("%d,%.2f,0,0\r\n"), iStartElec + i - 1, fPoleSpace*(i - 2)); } iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } } return true; } bool COperUrfFile::WriteElecByWenSch_AM(FILE* pFile, WORD wEamount, float fPoleSpace, int iStartElec, int iEndElec) { CString strText, strErr; int iLen = 0; int iR = 0; iR = wEamount*fPoleSpace; // 如果测线长度(N*d)小于或等于100m,则R = 500; // 如果测线长度大于100m小于等于200m,则R = 1000 // 如果测线长度大于200m,R = 5000 if (iR <= 100) { iR = 500; } else if (iR > 100 && iR <= 200) { iR = 1000; } else { iR = 5000; } for (int i = 1; i <= wEamount + 2; i++) { strText.Empty(); if (i == 1) { strText.Format(_T("%d,-%d,0,0,\r\n"), iStartElec + i - 1, iR); } else if (i == wEamount + 2) { strText.Format(_T("%d,%d,0,0,\r\n"), iStartElec + i - 1, iR); } else { strText.Format(_T("%d,%.2f,0,0\r\n"), iStartElec + i - 1, fPoleSpace*(i - 2)); } iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } } return true; } bool COperUrfFile::WriteElecByCrossHole(FILE* pFile, WORD wEamount, float fPoleSpace, float fHoleSpace, int iStartElec, int iEndElec) { CString strText, strErr; int iLen = 0; int iMidIndex = wEamount/2; for (int i = 0; i < 2; i++) { for (int iIndex = 1; iIndex <= iMidIndex; iIndex++) { strText.Empty(); strText.Format(_T("%d,%.2f,0,%.2f\r\n"), i*iMidIndex+iIndex, fHoleSpace*i, -1*(m_fExtParam+(iIndex-1)*fPoleSpace)); iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("当erport urf文件写入孔空间信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write hole spac Information error when erport urf file!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } } } return true; } bool COperUrfFile::WriteElecByAR(FILE* pFile, int iAR, WORD wEAmount, float fPoleSpace, float fParam, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { if (NULL == pFile) { return false; } switch (iAR) { case 40://customer return WriteElecByCrossHole(pFile, wEAmount, fPoleSpace,fParam,iStartElec,iEndElec); //break; case AR_WENNER_SCH_BASIC://wen-sch basic//to be do, louis case 39://wen-sch return WriteElecByWenSch(pFile, wEAmount, fPoleSpace, iStartElec, iEndElec); case 37: return WriteElecByWenSch_AMN(pFile, wEAmount, fPoleSpace, iStartElec, iEndElec); case 38: return WriteElecByWenSch_MNB(pFile, wEAmount, fPoleSpace, iStartElec, iEndElec); case 36: return WriteElecByWenSch_AM(pFile, wEAmount, fPoleSpace, iStartElec, iEndElec); //break; case AR_CROSS_HOLE_GEOMATIVE: return WriteElecByCrossHoleGeomative(pFile, wEAmount, fPoleSpace, strSCCN, strTaskID); case AR_CROSS_HOLE_GEOMATIVE_AM: return WriteElecByCrossHoleGeomativeAM(pFile, wEAmount, fPoleSpace, strSCCN, strTaskID); default: if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("不支持的装置")); else MessageBoxEx(NULL, _T("Unsupprot AR"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } } bool COperUrfFile::WriteElecByPolePole_AM_3D(FILE* pFile, byte byTestLineDirection, int iXElecCount, int iYElecCount, float fXEDistance, float fYEDistance, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { CString strText, strErr; int iLen = 0; int iR = 0; iR = iXElecCount*fXEDistance > iYElecCount*fYEDistance ? iXElecCount*fXEDistance : iYElecCount*fYEDistance; // 如果测线长度(N*d)小于或等于100m,则R = 500; // 如果测线长度大于100m小于等于200m,则R = 1000 // 如果测线长度大于200m,R = 5000 if (iR <= 100) { iR = 500; } else if (iR > 100 && iR <= 200) { iR = 1000; } else { iR = 5000; } int iElecID = 1; //写入第一个无穷电极 strText.Format(_T("%d,-%d,0,0,\r\n"), iElecID, iR); iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } iElecID++; WriteElecBySchlumberger_3D(pFile, byTestLineDirection, iXElecCount, iYElecCount, fXEDistance, fYEDistance, iElecID, iEndElec, strSCCN, strTaskID); //写入最后一个无穷电极 strText.Format(_T("%d,%d,0,0,\r\n"), iXElecCount*iYElecCount+2, iR); iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } return true; } bool COperUrfFile::WriteElecByPoleDipole_AMN_3D(FILE* pFile, byte byTestLineDirection, int iXElecCount, int iYElecCount, float fXEDistance, float fYEDistance, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { CString strText, strErr; int iLen = 0; int iR = 0; iR = iXElecCount*fXEDistance > iYElecCount*fYEDistance ? iXElecCount*fXEDistance : iYElecCount*fYEDistance; // 如果测线长度(N*d)小于或等于100m,则R = 500; // 如果测线长度大于100m小于等于200m,则R = 1000 // 如果测线长度大于200m,R = 5000 if (iR <= 100) { iR = 500; } else if (iR > 100 && iR <= 200) { iR = 1000; } else { iR = 5000; } int iElecID = 1; WriteElecBySchlumberger_3D(pFile, byTestLineDirection, iXElecCount, iYElecCount, fXEDistance, fYEDistance, iElecID, iEndElec, strSCCN, strTaskID); strText.Format(_T("%d,%d,0,0,\r\n"), iXElecCount*iYElecCount+1, iR); iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } return true; } bool COperUrfFile::WriteElecByDipoleDipole_MNB_3D(FILE* pFile, byte byTestLineDirection, int iXElecCount, int iYElecCount, float fXEDistance, float fYEDistance, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { CString strText, strErr; int iLen = 0; int iR = 0; iR = iXElecCount*fXEDistance > iYElecCount*fYEDistance ? iXElecCount*fXEDistance : iYElecCount*fYEDistance; // 如果测线长度(N*d)小于或等于100m,则R = 500; // 如果测线长度大于100m小于等于200m,则R = 1000 // 如果测线长度大于200m,R = 5000 if (iR <= 100) { iR = 500; } else if (iR > 100 && iR <= 200) { iR = 1000; } else { iR = 5000; } //int iElecID = 1; //strText.Format(_T("%d,-%d,0,0,\n"), iElecID, iR); //iLen = fwrite(strText, 1, strText.GetLength(), pFile); //if (iLen != strText.GetLength()) //{ // if (LANG_ZHCN == g_iUILanguage) // { // strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), // strText.GetLength(), iLen, GetLastError()); // AfxMessageBox(strErr); // } // else // { // strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), // strText.GetLength(), iLen, GetLastError()); // MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); // } // return false; //} int iElecID=1; WriteElecBySchlumberger_3D(pFile, byTestLineDirection, iXElecCount, iYElecCount, fXEDistance, fYEDistance, iElecID, iEndElec, strSCCN, strTaskID); return true; } bool COperUrfFile::WriteElecBySchlumberger_3D(FILE* pFile, byte byTestLineDirection, int iXElecCount, int iYElecCount, float fXEDistance, float fYEDistance, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { int iLen = 0; int iXIndex = 0; int iYIndex = 0; int iElecID = iStartElec; CString strText,strErr; //电缆布线方向为X方向 if (0 == byTestLineDirection) { //行数 for (iYIndex = 0; iYIndex < iYElecCount; iYIndex++) { //列数 for (iXIndex = 0; iXIndex < iXElecCount; iXIndex++) { strText.Empty(); //奇数行 if (0 == iYIndex%2) strText.Format(_T("%d,%.2f,%.2f,0\n"), iElecID, iXIndex*fXEDistance, iYIndex*fYEDistance); //偶数行 else strText.Format(_T("%d,%.2f,%.2f,0\n"), iElecID, /*(iYElecCount-iXIndex+1)*fXEDistance*/iXElecCount - iXIndex * fXEDistance - 1, iYIndex*fYEDistance); iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } iElecID++; } } } //电缆布线方向为Y方向 else { //列数 for (iXIndex = 0; iXIndex < iXElecCount; iXIndex++) { //每一列的内容 for (iYIndex = 0; iYIndex < iYElecCount; iYIndex++) { strText.Empty(); //奇数列 if (0 == iXIndex % 2) strText.Format(_T("%d,%.2f,%.2f,0\n"), iElecID, iXIndex*fXEDistance, iYIndex*fYEDistance); //偶数列 else strText.Format(_T("%d,%.2f,%.2f,0\n"), iElecID, iXIndex*fXEDistance, (iYElecCount-iYIndex-1)*fYEDistance); iLen = fwrite(strText, 1, strText.GetLength(), pFile); if (iLen != strText.GetLength()) { strErr.Empty(); if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } iElecID++; } } } return true; } bool COperUrfFile::WriteElecByAR_3D(FILE* pFile, int iAR, byte byTestLineDirection, int iXElecCount, int iYElecCount, float fXEDistance, float fYEDistance, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { if (NULL == pFile) { return false; } switch (iAR) { /* //2D 与3D均是同数据库读取,因此可以共用同一个头文件 case AR_CROSS_HOLE_GEOMATIVE: return WriteElecByCrossHoleGeomative(pFile, 0, 0, strSCCN, strTaskID); case AR_CROSS_HOLE_GEOMATIVE_AM: return WriteElecByCrossHoleGeomativeAM(pFile, 0, 0, strSCCN, strTaskID); */ case AR_POLE_POLE_AM_3D: return WriteElecByPolePole_AM_3D(pFile, byTestLineDirection, iXElecCount, iYElecCount, fXEDistance, fYEDistance, iStartElec, iEndElec, strSCCN, strTaskID); case AR_POLE_DIPOLE_AMN_3D: return WriteElecByPoleDipole_AMN_3D(pFile, byTestLineDirection, iXElecCount, iYElecCount, fXEDistance, fYEDistance, iStartElec, iEndElec, strSCCN, strTaskID); case AR_DIPOLE_DIPOLE_MNB_3D: return WriteElecByDipoleDipole_MNB_3D(pFile, byTestLineDirection, iXElecCount, iYElecCount, fXEDistance, fYEDistance, iStartElec, iEndElec, strSCCN, strTaskID); case AR_SCHLUMBERGER_3D: return WriteElecBySchlumberger_3D(pFile, byTestLineDirection, iXElecCount,iYElecCount, fXEDistance, fYEDistance, 1, iEndElec, strSCCN, strTaskID); default: if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("不支持的装置")); else MessageBoxEx(NULL, _T("Unsupprot AR"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return false; } } bool COperUrfFile::WriteUrfPoleInfo_3D(int iAR, byte byTestLineDirection, int iXElecCount, int iYElecCount, float fXEDistance, float fYEDistance, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { if (NULL == m_pFile) { return false; } CString strErr = _T(""); CString strText = _T("\n:Geometry\n;ID,X,Y,Z\n"); int iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } if (!WriteElecByAR_3D(m_pFile, iAR,byTestLineDirection,iXElecCount,iYElecCount,fXEDistance,fYEDistance,iStartElec, iEndElec, strSCCN, strTaskID)) { return false; } strText = _T("\n:Measurements\n;A, B, M, N, V/I(ohm), I(mA), Error(%), Chargeability(mV/V)\n"); iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写入固定数据错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write fixed data error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } fflush(m_pFile); return true; } bool COperUrfFile::WriteUrfPoleInfo(int iAR, WORD wEamount, float fPoleSpace, float fParamVal, int iStartElec, int iEndElec, CString strSCCN, CString strTaskID) { if (NULL == m_pFile) { return false; } CString strErr = _T(""); CString strText = _T("\n:Geometry\n;ID,X,Y,Z\n"); int iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } if (!WriteElecByAR(m_pFile, iAR, wEamount, fPoleSpace,fParamVal,iStartElec,iEndElec, strSCCN, strTaskID)) { return false; } strText = _T("\n:Measurements\n;A, B, M, N, V/I(ohm), I(mA), Error(%), Chargeability(mV/V)\n"); iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写入固定数据错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write fixed data error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } fflush(m_pFile); return true; } bool COperUrfFile::WriteUrfPoleInfo(WORD wEamount, float fPoleSpace) { if (NULL == m_pFile) { return false; } CString strErr = _T(""); CString strText = _T("\n:Geometry\n;ID,X,Y,Z\n"); int iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } for (int i = 1; i <= wEamount; i++) { strText.Empty(); strText.Format(_T("%d,%.2f,0,0\n"), i, fPoleSpace*(i-1)); iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写电极信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write Pole Information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } } strText = _T("\n:Measurements\n;A, B, M, N, V/I(ohm), I(mA), Error(%), Chargeability(mV/V)\n"); iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写入固定数据错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write fixed data error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } fflush(m_pFile); return true; } bool COperUrfFile::WriteUrfDataInfo(const CString& strTxtContent) { if (NULL == m_pFile) { return false; } CString strErr = _T(""); int iLen = fwrite(strTxtContent, 1, strTxtContent.GetLength(), m_pFile); if (iLen != strTxtContent.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写入数据信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strTxtContent.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write data information error!should write length = %d, writed length = %d, error_code = %d"), strTxtContent.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } return true; } bool COperUrfFile::WriteUrfDataInfo(const CStringArray& strArrTxt) { if (NULL == m_pFile) { return false; } CString strErr = _T(""); CString strText = _T(""); for (int i = 0; i < strArrTxt.GetSize(); i++) { strText = strArrTxt.GetAt(i); int iLen = fwrite(strText, 1, strText.GetLength(), m_pFile); if (iLen != strText.GetLength()) { if (LANG_ZHCN == g_iUILanguage) { strErr.Format(_T("写入数据信息错误!应该写长度= %d,写长度= %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); AfxMessageBox(strErr); } else { strErr.Format(_T("Write data information error!should write length = %d, writed length = %d, error_code = %d"), strText.GetLength(), iLen, GetLastError()); MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return false; } } /* fflush(m_pFile);*/ return true; }