void writeFile(std::string fp, const std::vector<float>& sweep, const std::vector<float>& measured, std::vector<float>& raw_ir) { int len = sweep.size(); int ir_len = raw_ir.size(); log_msg<LOG_INFO>(L"Write File - sweep len %d, Ir len: %d") % len %ir_len; std::ofstream respfile(fp.c_str(), std::fstream::out | std::fstream::trunc); respfile<<sweep.size()<<" "; for(int i = 0; i < len; i++) { respfile<<raw_ir.at(i)<<" "; } respfile.close(); }
void readFile(std::string fp, std::vector<float>& data) { std::ifstream respfile(fp.c_str(), std::fstream::in); int size; int data_size = (int)data.size(); respfile>>size; int num = (data_size<size ? data_size : size); log_msg<LOG_INFO>(L"Read File - len %d") % num; for(int i = 0; i < num; i++) { respfile>>data.at(i); } float max=0; for(int i = 0; i < num; i++) { if(std::abs(data.at(i))>max) max = std::abs(data.at(i)); } for(int i = 0; i < num; i++) { data.at(i) /= max; } }
bool CallBackend( CGT_CDiagMsg* pdm, int nVerbose, const TCHAR* pszExePath, const TCHAR* pszCmdArgs, const TCHAR* pszGenPath, const TCHAR* pszTrgType ) { long nBackendErr; long nBackendWarn; FC_CString respfile(MAX_PATH); FC_CString jot(MAX_PATH); TCHAR* pText; const TCHAR* pCText; long exitCode; respfile.load(pszGenPath)<<_T("\\.")<<pszTrgType<<_T("\\result.txt"); if(!CGT_DeleteFile(pdm, NULL, respfile)) return false; if(nVerbose>1) { jot.load(pszExePath)<<' '<<pszCmdArgs<<'\n'; pdm->userMsg(jot); } if(!FC_System(pszExePath, pszCmdArgs, NULL, &exitCode)) { pdm->sysErr(GetLastError(), NULL, _T("CreateProcess: "), pszExePath); return false; } //exitCode 0 normal termination 0 errors //exitCode 1 normal termination >0 errors //exitCode 2 normal termination after fatal error //exitCode 3 normal termination after too many errors //all other exist codes mean that something crashed... if(exitCode<0 || exitCode>3) { pdm->msg1(CG_E_BACKEND_ERROR, NULL, pszTrgType); return false; } if(exitCode==0 || exitCode==1) { if(!FC_Exist(respfile)) { pdm->msg1(CG_E_FILE_NOT_EXIST, NULL, respfile); pdm->userMsg(" Note: response file of backend '"); pdm->userMsg(pszExePath); pdm->userMsg("' not found.\r\n"); return false; } if(!CGT_LoadTextFileToMem(pdm, NULL, pszGenPath, respfile, &pText, NULL, NULL)) return false; pCText = pText; pCText = jot.clear().appendUpTo(pCText, _T("\r\n")); nBackendErr = atoi(jot); assert(*pText && nBackendErr>=0); if(nBackendErr>0) pdm->incErrors(nBackendErr); pCText= jot.clear().appendUpTo(pCText, _T("\r\n")); nBackendWarn= atoi(jot); assert(nBackendWarn>=0); if(nBackendWarn>0) pdm->incWarnings(nBackendWarn); delete(pText); return nBackendErr==0; } else { pdm->msg1(CG_E_BACKEND_ERROR, NULL, pszTrgType); return false; } return true; }