NPError NP_LOADDS NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved) { plogf("sp: NPP_New() mode=%d ", mode); if (!instance) { plogf("sp: error: NPERR_INVALID_INSTANCE_ERROR"); return NPERR_INVALID_INSTANCE_ERROR; } if (pluginType) plogf("sp: pluginType: %s ", pluginType); if (saved) plogf("sp: SavedData: len=%d", saved->len); instance->pdata = AllocStruct<InstanceData>(); if (!instance->pdata) { plogf("sp: error: NPERR_OUT_OF_MEMORY_ERROR"); return NPERR_OUT_OF_MEMORY_ERROR; } gNPNFuncs.setvalue(instance, NPPVpluginWindowBool, (void *)true); InstanceData *data = (InstanceData *)instance->pdata; bool ok = GetExePath(data->exepath, dimof(data->exepath)); SelectTranslation(ok ? data->exepath : NULL); if (ok) data->message = _TR("Opening document in SumatraPDF..."); else data->message = _TR("Error: SumatraPDF hasn't been found!"); return NPERR_NO_ERROR; }
int32_t NP_LOADDS NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer) { InstanceData *data = (InstanceData *)instance->pdata; DWORD bytesWritten = len; plogf("sp: NPP_Write() off=%d, len=%d", offset, len); if (data->hFile) { // Note: we optimistically assume that data comes in sequentially // (i.e. next offset will be current offset + bytesWritten) BOOL ok = WriteFile(data->hFile, buffer, (DWORD)len, &bytesWritten, NULL); if (!ok) { plogf("sp: NPP_Write() failed to write %d bytes at offset %d", len, offset); return -1; } } data->currSize = offset + bytesWritten; data->progress = stream->end > 0 ? 1.0f * (offset + len) / stream->end : 0; TriggerRepaintOnProgressChange(data); return bytesWritten; }
NPError NP_LOADDS NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype) { InstanceData *data = (InstanceData *)instance->pdata; if (!*data->exepath) { plogf("sp: NPP_NewStream() error: NPERR_FILE_NOT_FOUND"); return NPERR_FILE_NOT_FOUND; } plogf("sp: NPP_NewStream() end=%d", stream->end); // if we can create a temporary file ourselfes, we manage the download // process. The reason for that is that NP_ASFILE (where browser manages // file downloading) is not reliable and has been broken in almost every // browser at some point *stype = NP_ASFILE; data->hFile = CreateTempFile(data->filepath, dimof(data->filepath)); if (data->hFile) { plogf("sp: using temporary file: %S", data->filepath); *stype = NP_NORMAL; } data->totalSize = stream->end; data->currSize = 0; data->progress = stream->end > 0 ? 0.01f : 0; data->prevProgress = -.1f; TriggerRepaintOnProgressChange(data); return NPERR_NO_ERROR; }
void LaunchWithSumatra(InstanceData *data, const char *url_utf8) { if (!file::Exists(data->filepath)) plogf("sp: NPP_StreamAsFile() error: file doesn't exist"); ScopedMem<WCHAR> url(str::conv::FromUtf8(url_utf8)); // escape quotation marks and backslashes for CmdLineParser.cpp's ParseQuoted if (str::FindChar(url, '"')) { WStrVec parts; parts.Split(url, L"\""); url.Set(parts.Join(L"%22")); } if (str::EndsWith(url, L"\\")) { url[str::Len(url) - 1] = '\0'; url.Set(str::Join(url, L"%5c")); } // prevent overlong URLs from making LaunchProcess fail if (str::Len(url) > 4096) url.Set(NULL); ScopedMem<WCHAR> cmdLine(str::Format(L"\"%s\" -plugin \"%s\" %d \"%s\"", data->exepath, url ? url : L"", (HWND)data->npwin->window, data->filepath)); data->hProcess = LaunchProcess(cmdLine); if (!data->hProcess) { plogf("sp: NPP_StreamAsFile() error: couldn't run SumatraPDF!"); data->message = _TR("Error: Couldn't run SumatraPDF!"); } }
void NP_LOADDS NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) { InstanceData *data = (InstanceData *)instance->pdata; if (!fname) { plogf("sp: NPP_StreamAsFile() error: fname is NULL"); data->message = _TR("Error: The document couldn't be downloaded!"); goto Exit; } plogf("sp: NPP_StreamAsFile() fname=%s", fname); if (data->hFile) plogf("sp: NPP_StreamAsFile() error: data->hFile is != NULL (should be NULL)"); data->progress = 1.0f; data->prevProgress = 0.0f; // force update TriggerRepaintOnProgressChange(data); if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, fname, -1, data->filepath, MAX_PATH)) MultiByteToWideChar(CP_ACP, 0, fname, -1, data->filepath, MAX_PATH); LaunchWithSumatra(data, stream->url); Exit: if (data->npwin) { InvalidateRect((HWND)data->npwin->window, NULL, FALSE); UpdateWindow((HWND)data->npwin->window); } }
void NP_LOADDS NPP_Print(NPP instance, NPPrint* platformPrint) { if (!platformPrint) { plogf("sp: NPP_Print(), platformPrint is NULL"); return; } if (NP_FULL != platformPrint->mode) { plogf("sp: NPP_Print(), platformPrint->mode is %d (!= NP_FULL)", platformPrint->mode); } else { InstanceData *data = (InstanceData *)instance->pdata; HWND hWnd = (HWND)data->npwin->window; HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) { PostMessage(hChild, WM_COMMAND, IDM_PRINT, 0); platformPrint->print.fullPrint.pluginPrinted = true; } } }
NPError NP_LOADDS NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved) { InstanceData *data; plogf("sp: NPP_New() mode=%d ", mode); if (!instance) { plogf("error: NPERR_INVALID_INSTANCE_ERROR"); return NPERR_INVALID_INSTANCE_ERROR; } if (pluginType) plogf("sp: pluginType: %s ", ScopedMem<TCHAR>(str::conv::FromAnsi(pluginType))); if (saved) plogf("sp: SavedData: len=%d", saved->len); instance->pdata = calloc(1, sizeof(InstanceData)); if (!instance->pdata) { plogf("error: NPERR_OUT_OF_MEMORY_ERROR"); return NPERR_OUT_OF_MEMORY_ERROR; } data = (InstanceData *)instance->pdata; gNPNFuncs.setvalue(instance, NPPVpluginWindowBool, (void *)true); if (GetExePath(data->exepath, dimof(data->exepath))) data->message = _T("Opening document in SumatraPDF..."); else data->message = _T("Error: SumatraPDF hasn't been found!"); return NPERR_NO_ERROR; }
void VCS_SOLVE::vcs_TCounters_report(int timing_print_lvl) /************************************************************************** * * vcs_TCounters_report: * * Print out the total Its and time counters to standard output ***************************************************************************/ { plogf("\nTCounters: Num_Calls Total_Its Total_Time (seconds)\n"); if (timing_print_lvl > 0) { plogf(" vcs_basopt: %5d %5d %11.5E\n", m_VCount->T_Basis_Opts, m_VCount->T_Basis_Opts, m_VCount->T_Time_basopt); plogf(" vcs_TP: %5d %5d %11.5E\n", m_VCount->T_Calls_vcs_TP, m_VCount->T_Its, m_VCount->T_Time_vcs_TP); plogf(" vcs_inest: %5d %11.5E\n", m_VCount->T_Calls_Inest, m_VCount->T_Time_inest); plogf(" vcs_TotalTime: %11.5E\n", m_VCount->T_Time_vcs); } else { plogf(" vcs_basopt: %5d %5d %11s\n", m_VCount->T_Basis_Opts, m_VCount->T_Basis_Opts," NA "); plogf(" vcs_TP: %5d %5d %11s\n", m_VCount->T_Calls_vcs_TP, m_VCount->T_Its," NA "); plogf(" vcs_inest: %5d %11s\n", m_VCount->T_Calls_Inest, " NA "); plogf(" vcs_TotalTime: %11s\n", " NA "); } }
static void printProgress(const vector<string> &spName, const vector<double> &soln, const vector<double> &ff) { int nsp = soln.size(); double sum = 0.0; plogf(" --- Summary of current progress:\n"); plogf(" --- Name Moles - SSGibbs \n"); plogf(" -------------------------------------------------------------------------------------\n"); for (int k = 0; k < nsp; k++) { plogf(" --- %20s %12.4g - %12.4g\n", spName[k].c_str(), soln[k], ff[k]); sum += soln[k] * ff[k]; } plogf(" --- Total sum to be minimized = %g\n", sum); }
DLLEXPORT NPError WINAPI NP_GetEntryPoints(NPPluginFuncs *pFuncs) { plogf("sp: NP_GetEntryPoints()"); if (!pFuncs || pFuncs->size < sizeof(NPPluginFuncs)) return NPERR_INVALID_FUNCTABLE_ERROR; pFuncs->size = sizeof(NPPluginFuncs); pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; pFuncs->newp = NPP_New; pFuncs->destroy = NPP_Destroy; pFuncs->setwindow = NPP_SetWindow; pFuncs->newstream = NPP_NewStream; pFuncs->destroystream = NPP_DestroyStream; pFuncs->asfile = NPP_StreamAsFile; pFuncs->writeready = NPP_WriteReady; pFuncs->write = NPP_Write; pFuncs->print = NPP_Print; pFuncs->event = NULL; pFuncs->urlnotify = NULL; pFuncs->javaClass = NULL; pFuncs->getvalue = NULL; pFuncs->setvalue = NULL; return NPERR_NO_ERROR; }
BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { plogf("sp: DllMain() reason: %d (%s)", dwReason, DllMainReason(dwReason)); g_hInstance = hInstance; return TRUE; }
/************************************************************************** * * GStar_R_calc(); * * This function calculates the standard state Gibbs free energy * for species, kspec, at the solution temperature TKelvin and * solution pressure, Pres. * * * Input * kglob = species global index. * TKelvin = Temperature in Kelvin * pres = pressure is given in units specified by if__ variable. * * * Output * return value = standard state free energy in units of Kelvin. */ double VCS_SPECIES_THERMO::GStar_R_calc(size_t kglob, double TKelvin, double pres) { char yo[] = "VCS_SPECIES_THERMO::GStar_R_calc "; double fe, T; fe = G0_R_calc(kglob, TKelvin); T = TKelvin; if (UseCanteraCalls) { AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency"); size_t kspec = IndexSpeciesPhase; OwningPhase->setState_TP(TKelvin, pres); fe = OwningPhase->GStar_calc_one(kspec); double R = vcsUtil_gasConstant(m_VCS_UnitsFormat); fe /= R; } else { double pref = SS0_Pref; switch(SSStar_Model) { case VCS_SSSTAR_CONSTANT: break; case VCS_SSSTAR_IDEAL_GAS: fe += T * log( pres/ pref ); break; default: plogf("%sERROR: unknown SSStar model\n", yo); exit(EXIT_FAILURE); } } return fe; }
/************************************************************************** * * eval_ac: * * This function evaluates the activity coefficient * for species, kspec * * Input * kglob -> integer value of the species in the global * species list within VCS_GLOB. Phase and local species id * can be looked up within object. * * Note, T, P and mole fractions are obtained from the * single private instance of VCS_GLOB * * * Output * return value = activity coefficient for species kspec */ double VCS_SPECIES_THERMO::eval_ac(size_t kglob) { #ifdef DEBUG_MODE char yo[] = "VCS_SPECIES_THERMO::eval_ac "; #endif double ac; /* * Activity coefficients are frequently evaluated on a per phase * basis. If they are, then the currPhAC[] boolean may be used * to reduce repeated work. Just set currPhAC[iph], when the * activity coefficients for all species in the phase are reevaluated. */ if (UseCanteraCalls) { size_t kspec = IndexSpeciesPhase; ac = OwningPhase->AC_calc_one(kspec); } else { switch (Activity_Coeff_Model) { case VCS_AC_CONSTANT: ac = 1.0; break; default: #ifdef DEBUG_MODE plogf("%sERROR: unknown model\n", yo); #endif exit(EXIT_FAILURE); } } return ac; }
/************************************************************************** * * VolStar_calc: * * This function calculates the standard state molar volume * for species, kspec, at the temperature TKelvin and pressure, Pres, * * Input * * Output * return value = standard state volume in m**3 per kmol. * (VCS_UNITS_MKS) */ double VCS_SPECIES_THERMO:: VolStar_calc(size_t kglob, double TKelvin, double presPA) { char yo[] = "VCS_SPECIES_THERMO::VStar_calc "; double vol, T; T = TKelvin; if (UseCanteraCalls) { AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency"); size_t kspec = IndexSpeciesPhase; OwningPhase->setState_TP(TKelvin, presPA); vol = OwningPhase->VolStar_calc_one(kspec); } else { switch(SSStar_Vol_Model) { case VCS_SSVOL_CONSTANT: vol = SSStar_Vol0; break; case VCS_SSVOL_IDEALGAS: // R J/kmol/K (2006 CODATA value) vol= 8314.47215 * T / presPA; break; default: plogf("%sERROR: unknown SSVol model\n", yo); exit(EXIT_FAILURE); } } return vol; }
/* * This routines adds entries for the formula matrix for this object * for one species * * This object also fills in the index filed, IndSpecies, within * the volPhase object. * * @param volPhase object containing the species * @param k Species number within the volPhase k * @param kT global Species number within this object * */ size_t VCS_PROB::addOnePhaseSpecies(vcs_VolPhase* volPhase, size_t k, size_t kT) { size_t e, eVP; if (kT > nspecies) { /* * Need to expand the number of species here */ plogf("Shouldn't be here\n"); exit(EXIT_FAILURE); } double const* const* const fm = volPhase->getFormulaMatrix(); for (eVP = 0; eVP < volPhase->nElemConstraints(); eVP++) { e = volPhase->elemGlobalIndex(eVP); #ifdef DEBUG_MODE if (e == npos) { exit(EXIT_FAILURE); } #endif FormulaMatrix[e][kT] = fm[eVP][k]; } /* * Tell the phase object about the current position of the * species within the global species vector */ volPhase->setSpGlobalIndexVCS(k, kT); return kT; }
/* * This is basically equal to RT * * @param mu_units integer representing the dimensional units system * @param TKelvin double Temperature in Kelvin * * @return Returns the value of RT */ double VCS_SOLVE::vcs_nondimMult_TP(int mu_units, double TKelvin) const { double rt; if (TKelvin <= 0.0) TKelvin = 293.15; switch (mu_units) { case VCS_UNITS_KCALMOL: rt = TKelvin * 8.314472E-3 / 4.184; break; case VCS_UNITS_UNITLESS: rt = 1.0; break; case VCS_UNITS_KJMOL: rt = TKelvin * 0.008314472; break; case VCS_UNITS_KELVIN: rt = TKelvin; break; case VCS_UNITS_MKS: rt = TKelvin * 8.314472E3; break; default: plogf("vcs_nondimMult_TP error: unknown units: %d\n", mu_units); plogendl(); exit(EXIT_FAILURE); } return rt; }
DLLEXPORT NPError WINAPI NP_Initialize(NPNetscapeFuncs *pFuncs) { plogf("sp: NP_Initialize()"); if (!pFuncs || pFuncs->size < sizeof(NPNetscapeFuncs)) { plogf("sp: NP_Initialize() error: NPERR_INVALID_FUNCTABLE_ERROR"); return NPERR_INVALID_FUNCTABLE_ERROR; } if (HIBYTE(pFuncs->version) > NP_VERSION_MAJOR) { plogf("sp: NP_Initialize() error: NPERR_INCOMPATIBLE_VERSION_ERROR"); return NPERR_INCOMPATIBLE_VERSION_ERROR; } gNPNFuncs = *pFuncs; return NPERR_NO_ERROR; }
HANDLE CreateTempFile(WCHAR *filePathBufOut, size_t bufSize) { ScopedMem<WCHAR> tmpPath(path::GetTempPath(L"nPV")); if (!tmpPath) { plogf("sp: CreateTempFile(): GetTempPath() failed"); return NULL; } str::BufSet(filePathBufOut, bufSize, tmpPath); HANDLE hFile = CreateFile(filePathBufOut, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hFile) { plogf("sp: CreateTempFile(): CreateFile() failed"); return NULL; } return hFile; }
/* * We check to see if the problem is well posed. If it is not, we return * false and print out error conditions. * * Current there is one condition. If all the element abundances are * zero, the algorithm will fail * * @param vprob VCS_PROB pointer to the definition of the equilibrium * problem * * @return If true, the problem is well-posed. If false, the problem * is not well posed. */ bool VCS_SOLVE::vcs_wellPosed(VCS_PROB *vprob) { double sum = 0.0; for (size_t e = 0; e < vprob->ne; e++) { sum = sum + vprob->gai[e]; } if (sum < 1.0E-20) { plogf("vcs_wellPosed: Element abundance is close to zero\n"); return false; } return true; }
NPError NP_LOADDS NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) { InstanceData *data; plogf("sp: NPP_DestroyStream() reason: %d", reason); if (stream) { if (stream->url) plogf("sp: url: %s", stream->url); plogf("sp: end: %d", stream->end); } if (!instance) { plogf("sp: NPP_DestroyStream() error: NPERR_INVALID_INSTANCE_ERROR"); return NPERR_INVALID_INSTANCE_ERROR; } data = (InstanceData *)instance->pdata; if (!data) { plogf("sp: NPP_DestroyStream() error: instance->pdata is NULL"); return NPERR_NO_ERROR; } if (!data->hFile) goto Exit; CloseHandle(data->hFile); if (stream) LaunchWithSumatra(data, stream->url); Exit: if (data->npwin) { InvalidateRect((HWND)data->npwin->window, NULL, FALSE); UpdateWindow((HWND)data->npwin->window); } return NPERR_NO_ERROR; }
void PageControl::Paint(Graphics *gfx, int offX, int offY) { CrashIf(!IsVisible()); Timer timerAll; CachedStyle *s = cachedStyle; Timer timerFill; Rect r(offX, offY, pos.Width, pos.Height); if (!s->bgColor->IsTransparent()) { Brush *br = BrushFromColorData(s->bgColor, r); gfx->FillRectangle(br, r); } double durFill = timerFill.Stop(); if (!page) return; // during resize the page we currently show might be bigger than // our area. To avoid drawing outside our area we clip Region origClipRegion; gfx->GetClip(&origClipRegion); r.X += s->padding.left; r.Y += s->padding.top; r.Width -= (s->padding.left + s->padding.right); r.Height -= (s->padding.top + s->padding.bottom); r.Inflate(1,0); gfx->SetClip(r, CombineModeReplace); Color textColor; if (gGlobalPrefs->useSysColors) textColor.SetFromCOLORREF(GetSysColor(COLOR_WINDOWTEXT)); else textColor.SetFromCOLORREF(gGlobalPrefs->ebookUI.textColor); ITextRender *textRender = CreateTextRender(GetTextRenderMethod(), gfx); Color bgCol; if (gGlobalPrefs->useSysColors) bgCol.SetFromCOLORREF(GetSysColor(COLOR_WINDOW)); else bgCol.SetFromCOLORREF(gGlobalPrefs->ebookUI.backgroundColor); textRender->SetTextBgColor(bgCol); Timer timerDrawHtml; DrawHtmlPage(gfx, textRender, &page->instructions, (REAL)r.X, (REAL)r.Y, IsDebugPaint(), textColor); double durDraw = timerDrawHtml.Stop(); gfx->SetClip(&origClipRegion, CombineModeReplace); delete textRender; double durAll = timerAll.Stop(); plogf("all: %.2f, fill: %.2f, draw html: %.2f", durAll, durFill, durDraw); }
NPError NP_LOADDS NPP_SetWindow(NPP instance, NPWindow *npwin) { InstanceData *data; if (!instance) { plogf("sp: NPP_SetWindow() errro: NPERR_INVALID_INSTANCE_ERROR"); return NPERR_INVALID_INSTANCE_ERROR; } plogf("sp: NPP_SetWindow()"); data = (InstanceData *)instance->pdata; if (!npwin) { data->npwin = NULL; } else if (data->npwin != npwin) { HWND hWnd = (HWND)npwin->window; data->npwin = npwin; SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data); SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)PluginWndProc); } else { // The plugin's window hasn't changed, just its size HWND hWnd = (HWND)npwin->window; HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL); if (hChild) { ClientRect rcClient(hWnd); MoveWindow(hChild, rcClient.x, rcClient.y, rcClient.dx, rcClient.dy, FALSE); } } return NPERR_NO_ERROR; }
void SelectTranslation(const WCHAR *exePath=NULL) { LANGID langId = GetUserDefaultUILanguage(); int idx = GetLanguageIndex(langId); if (-1 == idx) { // try a neutral language if the specific sublanguage isn't available langId = MAKELANGID(PRIMARYLANGID(langId), SUBLANG_NEUTRAL); idx = GetLanguageIndex(langId); } if (-1 != idx) { gTranslationIdx = idx; plogf("sp: Detected language %s (%d)", gLanguages[idx / gTranslationsCount], idx); } // try to extract the language used by SumatraPDF ScopedMem<WCHAR> path; if (exePath) { path.Set(path::GetDir(exePath)); path.Set(path::Join(path, PREFS_FILE_NAME)); } if (!file::Exists(path)) { path.Set(GetSpecialFolder(CSIDL_APPDATA)); path.Set(path::Join(path, L"SumatraPDF\\" PREFS_FILE_NAME)); } if (!file::Exists(path)) return; plogf("sp: Found preferences at %S", path); ScopedMem<char> prefsData(file::ReadAll(path, NULL)); SquareTree sqt(prefsData); const char *langCode = sqt.root ? sqt.root->GetValue("UiLanguage") : NULL; if (langCode) { plogf("sp: UiLanguage from preferences: %s", langCode); for (int i = 0; gLanguages[i]; i++) { if (str::Eq(gLanguages[i], langCode)) { gTranslationIdx = i * gTranslationsCount; break; } } } }
NPError NP_LOADDS NPP_Destroy(NPP instance, NPSavedData** save) { InstanceData *data; if (!instance) { plogf("sp: NPP_Destroy() error: NPERR_INVALID_INSTANCE_ERROR"); return NPERR_INVALID_INSTANCE_ERROR; } plogf("sp: NPP_Destroy()"); data = (InstanceData *)instance->pdata; if (data->hProcess) { plogf("sp: NPP_Destroy(): waiting for Sumatra to exit"); TerminateProcess(data->hProcess, 99); WaitForSingleObject(data->hProcess, INFINITE); CloseHandle(data->hProcess); } if (data->hFile) { plogf("sp: NPP_Destroy(): deleting internal temporary file %s", data->filepath); DeleteFile(data->filepath); *data->filepath = '\0'; } if (*data->filepath) { TCHAR tempDir[MAX_PATH]; DWORD len = GetTempPath(MAX_PATH, tempDir); if (0 < len && len < MAX_PATH && str::StartsWithI(data->filepath, tempDir)) { plogf("sp: NPP_Destroy(): deleting browser temporary file %s", data->filepath); DeleteFile(data->filepath); } } free(data); return NPERR_NO_ERROR; }
void LogLastError(DWORD err) { // allow to set a breakpoint in release builds if (0 == err) err = GetLastError(); char *msgBuf = NULL; DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; DWORD lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); FormatMessageA(flags, NULL, err, lang, (LPSTR)&msgBuf, 0, NULL); if (!msgBuf) return; plogf("LogLastError: %s", msgBuf); LocalFree(msgBuf); }
void VCS_SOLVE::vcs_printChemPotUnits(int unitsFormat) const { switch (unitsFormat) { case VCS_UNITS_KCALMOL: plogf("kcal/gmol"); break; case VCS_UNITS_UNITLESS: plogf("dimensionless"); break; case VCS_UNITS_KJMOL: plogf("kJ/gmol"); break; case VCS_UNITS_KELVIN: plogf("Kelvin"); break; case VCS_UNITS_MKS: plogf("J/kmol"); break; default: throw CanteraError("VCS_SOLVE::vcs_printChemPotUnits", "unknown units!"); } }
/* * The element name is added. Formula vector entries ang element * abundances for the new element are set to zero. * * Returns the index number of the new element. * * @param elNameNew New name of the element * @param elType Type of the element * @param elactive boolean indicating whether the element is active * * @return returns the index number of the new element */ size_t VCS_PROB::addElement(const char* elNameNew, int elType, int elactive) { if (!elNameNew) { plogf("error: element must have a name\n"); exit(EXIT_FAILURE); } size_t nel = ne + 1; resizeElements(nel, 1); ne = nel; ElName[ne-1] = elNameNew; m_elType[ne-1] = elType; ElActive[ne-1] = elactive; return ne - 1; }
int VCS_SOLVE::vcs_TP(int ipr, int ip1, int maxit, double T_arg, double pres_arg) { /* * Store the temperature and pressure in the private global variables */ m_temperature = T_arg; m_pressurePA = pres_arg; /* * Evaluate the standard state free energies * at the current temperatures and pressures. */ int iconv = vcs_evalSS_TP(ipr, ip1, m_temperature, pres_arg); /* * Prepare the problem data: * ->nondimensionalize the free energies using * the divisor, R * T */ vcs_nondim_TP(); /* * Prep the fe field */ vcs_fePrep_TP(); /* * Decide whether we need an initial estimate of the solution * If so, go get one. If not, then */ if (m_doEstimateEquil) { int retn = vcs_inest_TP(); if (retn != VCS_SUCCESS) { plogf("vcs_inest_TP returned a failure flag\n"); } } /* * Solve the problem at a fixed Temperature and Pressure * (all information concerning Temperature and Pressure has already * been derived. The free energies are now in dimensionless form.) */ iconv = vcs_solve_TP(ipr, ip1, maxit); /* * Redimensionalize the free energies using * the reverse of vcs_nondim to add back units. */ vcs_redim_TP(); /* * Return the convergence success flag. */ return iconv; }
static void BenchMD5Size(void *data, size_t dataSize, char *desc) { unsigned char d1[16], d2[16]; Timer t1(true); CalcMD5Digest((unsigned char*)data, dataSize, d1); double dur1 = t1.GetTimeInMs(); Timer t2(true); CalcMD5DigestWin(data, dataSize, d2); bool same = memeq(d1, d2, 16); CrashAlwaysIf(!same); double dur2 = t2.GetTimeInMs(); double diff = dur1 - dur2; plogf("%s\nCalcMD5Digest : %f ms\nCalcMD5DigestWin: %f ms\ndiff: %f", desc, dur1, dur2, diff); }
static void GenPythonUIntTest(uint64_t val, uint8_t *d, int dLen) { #if GEN_PYTHON_TESTS == 1 str::Str<char> s; s.AppendFmt(" utassert gob_uvarint_encode(%I64u) == ", val); int n; for (int i = 0; i < dLen; i++) { n = (int)d[i]; s.AppendFmt("chr(%d)", n); if (i < dLen - 1) s.Append(" + "); } plogf("%s", s.Get()); #endif }