コード例 #1
0
/*
  Recursive walk through the directory tree. Depth-first order. 
*/
void __rec_rmdir(char *path)
{
    /* In depth traversal of the subdir tree */
    WIN32_FIND_DATA find_file_data;
    HANDLE hnd;
    DWORD fa = ::GetFileAttributes(path);

    int path_len = strlen(path);

    /* current node */
    if (fa == -1) {
//          theLog("Error: Failed to get file attributes for %s (Error %d)!!!\n", 
//                 (LPCTSTR)path, GetLastError());
        return;
    }

    /* if it is a directory, recurse through all sons */
    if ((fa & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
        strcat(path, "/*");
        hnd = FindFirstFile(path, &find_file_data);
        while (hnd != INVALID_HANDLE_VALUE && 
               FindNextFile(hnd, &find_file_data) != FALSE) { 
            if(!strcmp(find_file_data.cFileName, ".")
               || !strcmp(find_file_data.cFileName, "..")) 
                continue;
            path[path_len+1] = '\0';
            strcat(path, find_file_data.cFileName);
            ::__rec_rmdir(path);
        }
        path[path_len] = '\0';
        FindClose(hnd);
    }
    /* execute after for the current node */
    RemovePath(path);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: CaoCaoBeard/pcejin
void ALoad(const char* filename)
{
	pcejin.romLoaded = true;
	pcejin.started = true;
	if(!MDFNI_LoadGame(filename))
	{
		pcejin.started = false;
		pcejin.romLoaded = false;
		GameName = "";
		SetWindowText(g_hWnd, pcejin.versionName.c_str());
	}
	
	if (AutoRWLoad)
	{
		//Open Ram Watch if its auto-load setting is checked
		OpenRWRecentFile(0);
		RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), g_hWnd, (DLGPROC) RamWatchProc);
	}
	RecentROMs.UpdateRecentItems(filename);
	std::string romname = noExtension(RemovePath(filename));
	GameName = romname;
	std::string temp = pcejin.versionName;
	temp.append(" ");
	temp.append(romname);		
	SetWindowText(g_hWnd, temp.c_str());
}
コード例 #3
0
ファイル: main.cpp プロジェクト: MANICX100/vbjin
void UpdateTitleWithFilename(std::string filename)
{
	std::string temp = pcejin.versionName;
	temp.append(" ");
	temp.append(RemovePath(filename));

	SetWindowText(g_hWnd, temp.c_str());
}
コード例 #4
0
//---------------------------------------------------------------------------
__fastcall TFormScoreTests::TFormScoreTests(TComponent* Owner)
        : TForm(Owner)
{
  StringGridStudents->Cells[0][0] = "#";
  StringGridStudents->Cells[1][0] = "Name";
  StringGridStudents->Cells[2][0] = "Score";
  StringGridStudents->Cells[3][0] = "Comment";

  StringGridQuestions->Cells[0][0] = "#";
  StringGridQuestions->Cells[1][0] = "f";
  StringGridQuestions->Cells[2][0] = "Question";

  assert(RemovePath("Test.txt")=="Test.txt");
  assert(RemovePath("C:\\Test.txt")=="Test.txt");
  assert(RemovePath("C:\\Test\\Test.txt")=="Test.txt");
  assert(RemovePath("C:\\Test\\Test\\Test.txt")=="Test.txt");

  assert(RemoveExtension("Test.txt")=="Test");
  assert(RemoveExtension("C:\\Test.txt")=="C:\\Test");
  assert(RemoveExtension("C:\\Test\\Test.txt")=="C:\\Test\\Test");
  assert(RemoveExtension("C:\\Test\\Test\\Test.txt")=="C:\\Test\\Test\\Test");

}
コード例 #5
0
ファイル: main.cpp プロジェクト: CaoCaoBeard/pcejin
void LoadGame(){

	char szChoice[MAX_PATH]={0};
	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = g_hWnd;
	ofn.lpstrFilter = "PC Engine Files (*.pce, *.cue, *.toc, *.sgx *.zip)\0*.pce;*.cue;*.toc;*.sgx;*.zip\0All files(*.*)\0*.*\0\0";
	ofn.lpstrFile = (LPSTR)szChoice;
	ofn.lpstrTitle = "Select a file to open";
	ofn.lpstrDefExt = "pce";
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	if(GetOpenFileName(&ofn)) {
		pcejin.romLoaded = true;
		pcejin.started = true;
		if(strlen(szChoice) > 4 && (!strcasecmp(szChoice + strlen(szChoice) - 4, ".cue") || !strcasecmp(szChoice + strlen(szChoice) - 4, ".toc"))) {
			char ret[MAX_PATH];
			GetPrivateProfileString("Main", "Bios", "pce.cdbios PATH NOT SET", ret, MAX_PATH, IniName);
			if(std::string(ret) == "pce.cdbios PATH NOT SET") {
				pcejin.started = false;
				pcejin.romLoaded = false;
				MDFN_DispMessage("specify your PCE CD bios");
				return;
			}
		}
		if(!MDFNI_LoadGame(szChoice)) {
			pcejin.started = false;
			pcejin.romLoaded = false;
			
		}
		if (AutoRWLoad)
		{
			//Open Ram Watch if its auto-load setting is checked
			OpenRWRecentFile(0);
			RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), g_hWnd, (DLGPROC) RamWatchProc);
		}
		StopMovie();
		ResetFrameCount();
		RecentROMs.UpdateRecentItems(szChoice);

		std::string romname = noExtension(RemovePath(szChoice));
		std::string temp = pcejin.versionName;
		GameName = romname;
		temp.append(" ");
		temp.append(romname);
		SetWindowText(g_hWnd, temp.c_str());
	}
}
コード例 #6
0
bool ModNameCompare( char *tname, char *membname )
/*******************************************************/
// check if a THEADR record name is equal to a library member name
{
    unsigned    lentheadr;
    unsigned    lenmember;
    char        *namestart;

    namestart = RemovePath( tname, &lentheadr );
    lenmember = strlen( membname );
    if( lentheadr == lenmember ) {
        if( memicmp( namestart, membname, lenmember ) == 0 ) {
            return( TRUE );
        }
    }
    return( FALSE );
}
コード例 #7
0
ファイル: path_build.cpp プロジェクト: chasegreenberg/FreeRCT
void PathBuildManager::OnMouseButtonEvent(Viewport *vp, uint8 state)
{
	this->mouse_state = state & MB_CURRENT;

	if ((this->mouse_state & MB_LEFT) != 0) { // Left-click -> select current tile.
		if (this->state == PBS_LONG_BUILD || this->state == PBS_LONG_BUY) {
			this->ConfirmLongPath();
		} else {
			FinderData fdata((CS_GROUND | CS_PATH), FW_TILE);
			if (vp->ComputeCursorPosition(&fdata) != CS_NONE) this->TileClicked(fdata.voxel_pos);
		}
	} else if ((this->mouse_state & MB_RIGHT) != 0 && this->state == PBS_SINGLE) {
		FinderData fdata(CS_PATH, FW_TILE);
		if (vp->ComputeCursorPosition(&fdata) != CS_NONE && RemovePath(fdata.voxel_pos, false)) {
			_additions.Commit();
		}
	}
}
コード例 #8
0
ファイル: main.cpp プロジェクト: MANICX100/vbjin
void LoadGame(){

	char szChoice[MAX_PATH]={0};
	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = g_hWnd;
	ofn.lpstrFilter = "VB Files (*.vb, *.zip)\0*.vb;*.zip\0All files(*.*)\0*.*\0\0";
	ofn.lpstrFile = (LPSTR)szChoice;
	ofn.lpstrTitle = "Select a file to open";
	ofn.lpstrDefExt = "vb";
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	if(GetOpenFileName(&ofn)) {
		pcejin.romLoaded = true;
		pcejin.started = true;
	
		if(!MDFNI_LoadGame(NULL,szChoice)) {
			pcejin.started = false;
			pcejin.romLoaded = false;
			
		}
		if (AutoRWLoad)
		{
			//Open Ram Watch if its auto-load setting is checked
			OpenRWRecentFile(0);
			RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), g_hWnd, (DLGPROC) RamWatchProc);
		}
		FCEUI_StopMovie();
		UpdateRecentRoms(szChoice);
		ResetFrameCount();
		UpdateTitleWithFilename(szChoice);
		std::string romname = noExtension(RemovePath(szChoice));
		std::string temp = pcejin.versionName;
		temp.append(" ");
		temp.append(romname);
		
		SetWindowText(g_hWnd, temp.c_str());
	}
}
コード例 #9
0
ファイル: log.cpp プロジェクト: Thalur/ak
void LogAppend(ELogLevel aLogLevel, const char* aFile, const std::string& aFunc,
               const std::string& aMessage, int aLine, ...)
{
   if (!loggerInitialized && !uninitializedLoggerUseReported) {
      uninitializedLoggerUseReported = true;
      std::cout << "WARNING: Logger used without initialization. Call InitLogFile() first!" << std::endl;
   }

   // Remove the path from the filename
   aFile = RemovePath(aFile);

   // Assemble the user-generated message
   char buffer[510];
   va_list args;
   va_start(args, aLine);
#ifdef AK_SYSTEM_WINDOWS
   vsnprintf_s(buffer, 500, _TRUNCATE, aMessage.c_str(), args);
#else
   vsnprintf(buffer, 500, aMessage.c_str(), args);
#endif
   va_end(args);

   CClock now;
   std::string timestamp(now.GetTimeLong());
   if (loggerInitialized && aLogLevel >= fileLogLevel) {
      WriteLogEntry(*logFile, timestamp, GetLevelString(aLogLevel), aFile, aFunc, aLine, buffer);
   }
   if (aLogLevel >= consoleLogLevel) {
#ifdef AK_SYSTEM_ANDROID
         __android_log_print(ANDROID_LOG_DEBUG + static_cast<int32_t>(aLogLevel), appName.c_str(), buffer);
#else
      if (simplifiedConsoleOutput) {
         std::cout << buffer << std::endl;
      } else {
         WriteLogEntry(std::cout, timestamp, GetLevelString(aLogLevel), aFile, aFunc, aLine, buffer);
      }
#endif
   }
}
コード例 #10
0
void ProcessMolfileDirectory(string Directory,string OutputDirectory) {
	vector<string> DirectoryList = GetDirectoryFileList(Directory);

	Data* NewData = new Data(0);
	for (int i=0; i < int(DirectoryList.size()); i++) {
		cout << DirectoryList[i] << endl;
		Species* NewSpecies = new Species("", NewData, false);
		if (DirectoryList[i].length() > 0) {
			NewSpecies->ReadFromMol(Directory+DirectoryList[i]);
			NewSpecies->LabelAtoms();
			string FileRoot = RemovePath(RemoveExtension(DirectoryList[i]));
			ofstream Output;
			if (OpenOutput(Output,OutputDirectory+FileRoot+".txt")) {
				Output << "Atom index;Group;GroupIndex" << endl;
				for (int j=0; j < NewSpecies->FNumAtoms(); j++) {
					Output << j << ";" << NewSpecies->GetAtom(j)->FGroupString() << ";" << NewSpecies->GetAtom(j)->FGroupIndex() << endl;
				}
				Output.close();
			}
		}
		delete NewSpecies;
	}
}
コード例 #11
0
ファイル: path_build.cpp プロジェクト: chasegreenberg/FreeRCT
/**
 * User selected 'buy' or 'remove'. Perform the action, and update the path build state.
 * @param buying If \c true, user selected 'buy'.
 */
void PathBuildManager::SelectBuyRemove(bool buying)
{
	if (buying) {
		// Buy a long path.
		if (this->state == PBS_LONG_BUY) {
			_additions.Commit();
			this->pos = this->long_pos;
			this->SetState(PBS_WAIT_ARROW);
			return;
		}
		// Buying a path tile.
		if (this->state != PBS_WAIT_BUY) return;
		_additions.Commit();
		this->SelectMovement(true);
	} else {
		// Removing a path tile.
		if (this->state <= PBS_WAIT_VOXEL || this->state > PBS_WAIT_BUY) return;
		TileEdge edge = (TileEdge)((this->selected_arrow + 2) % 4);
		const Voxel *v = _world.GetVoxel(this->pos);
		if (v == nullptr || !HasValidPath(v)) {
			this->MoveCursor(edge, false);
			this->UpdateState();
			return;
		}
		PathSprites ps = GetImplodedPathSlope(v);

		_additions.Clear();
		if (RemovePath(this->pos, false)) {
			_additions.Commit();
		}

		/* Short-cut version of this->SelectMovement(false), as that function fails after removing the path. */
		bool move_up = (ps == _path_down_from_edge[edge]);
		this->MoveCursor(edge, move_up);
		this->UpdateState();
	}
}
コード例 #12
0
ERcExitCode CResourceCompilerHelper::InvokeResourceCompiler(const char* szSrcFilePath, const char* szDstFilePath, const bool bUserDialog) 
{
	const char* szAdjustedFilename = szSrcFilePath;
#if defined(USE_GAMESTREAM)
	char szFullSrcPathBuf[ICryPak::g_nMaxPath];
	if (gEnv && gEnv->pGameStream)
	{
		szAdjustedFilename = gEnv->pCryPak->AdjustFileName(szSrcFilePath, szFullSrcPathBuf, ICryPak::FLAGS_RESOLVE_TO_CACHE);
	}
#endif

	ERcExitCode eRet = eRcExitCode_Pending;

	// make command for execution
	wchar_t szProjectDir[512];
	GetCurrentDirectoryW(sizeof(szProjectDir) / sizeof(szProjectDir[0]), szProjectDir);

	SettingsManagerHelpers::CFixedString<wchar_t, 512> wRemoteCmdLine;
	SettingsManagerHelpers::CFixedString<wchar_t, 512> wDir;
	CSettingsManagerTools smTools = CSettingsManagerTools();

	const char* const szRcParentDir =
		(smTools.Is64bitWindows() && (DirectoryExists(L"Bin64/rc") || !DirectoryExists(L"Bin32/rc")))
		? "Bin64" 
		: "Bin32";

	wchar_t szRegSettingsBuffer[1024];
	smTools.GetEngineSettingsManager()->GetValueByRef("RC_Parameters", SettingsManagerHelpers::CWCharBuffer(szRegSettingsBuffer, sizeof(szRegSettingsBuffer)));

	wRemoteCmdLine.appendAscii(szRcParentDir);
	wRemoteCmdLine.appendAscii("/rc/");
	wRemoteCmdLine.appendAscii(RC_EXECUTABLE);
	wRemoteCmdLine.appendAscii(" \"");
	wRemoteCmdLine.append(szProjectDir);
	wRemoteCmdLine.appendAscii("\\");
	wRemoteCmdLine.appendAscii(szAdjustedFilename);
	wRemoteCmdLine.appendAscii("\" /userdialog=0 ");
	wRemoteCmdLine.append(szRegSettingsBuffer);

	// make it write to a filename of our choice
	char szDstFilename[512];
	char szDstPath[512];

	RemovePath(szDstFilePath, szDstFilename, 512);
	RemoveFilename(szDstFilePath, szDstPath, 512);

	wRemoteCmdLine.appendAscii(" /overwritefilename=\"");
	wRemoteCmdLine.appendAscii(szDstFilename);
	wRemoteCmdLine.appendAscii("\"");
	wRemoteCmdLine.appendAscii(" /targetroot=\"");
	wRemoteCmdLine.append(szProjectDir);
	wRemoteCmdLine.appendAscii("\\");
	wRemoteCmdLine.appendAscii(szDstPath);
	wRemoteCmdLine.appendAscii("\"");

	wDir.append(szProjectDir);
	wDir.appendAscii("\\");
	wDir.appendAscii(szRcParentDir);
	wDir.appendAscii("\\rc");

	STARTUPINFOW si;
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	si.dwX = 100;
	si.dwY = 100;
	si.dwFlags = STARTF_USEPOSITION;

	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof(pi));

#if defined(DEBUG) && !defined(NDEBUG) && defined(_RENDERER)
	extern ILog *iLog;

	char tmp1[512];
	char tmp2[512];
	SettingsManagerHelpers::CCharBuffer dst1(tmp1, 512); SettingsManagerHelpers::ConvertUtf16ToUtf8(wDir.c_str(), dst1);
	SettingsManagerHelpers::CCharBuffer dst2(tmp2, 512); SettingsManagerHelpers::ConvertUtf16ToUtf8(wRemoteCmdLine.c_str(), dst2);

	iLog->Log("Debug: RC: dir \"%s\", cmd \"%s\"\n", tmp1, tmp2);
#endif

	if (!CreateProcessW( 
		NULL,     // No module name (use command line). 
		const_cast<wchar_t*>(wRemoteCmdLine.c_str()), // Command line. 
		NULL,     // Process handle not inheritable. 
		NULL,     // Thread handle not inheritable. 
		FALSE,    // Set handle inheritance to FALSE. 
		BELOW_NORMAL_PRIORITY_CLASS + (bUserDialog ? 0 : CREATE_NO_WINDOW),	// creation flags. 
		NULL,     // Use parent's environment block. 
		wDir.c_str(),  // Set starting directory. 
		&si,      // Pointer to STARTUPINFO structure.
		&pi))     // Pointer to PROCESS_INFORMATION structure.
	{
		eRet = eRcExitCode_FatalError;
	}
	else
	{
		// Wait until child process exits.
		WaitForSingleObject(pi.hProcess, INFINITE);

		DWORD exitCode;
		if (GetExitCodeProcess(pi.hProcess, &exitCode) == 0)
		{
			eRet = eRcExitCode_Error;
		}
		else
		{
			eRet = (ERcExitCode)exitCode;
		}
	}

	// Close process and thread handles. 
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);

	return eRet;
}
コード例 #13
0
ファイル: lzssmain.c プロジェクト: 8l/CompCert
/****************************************************************************
*   Function   : main
*   Description: This is the main function for this program, it validates
*                the command line input and, if valid, it will either
*                encode a file using the LZSS algorithm or decode a
*                file encoded with the LZSS algorithm.
*   Parameters : argc - number of parameters
*                argv - parameter list
*   Effects    : Encodes/Decodes input file
*   Returned   : EXIT_SUCCESS for success, otherwise EXIT_FAILURE.
****************************************************************************/
int main(int argc, char *argv[])
{
    option_t *optList, *thisOpt;
    FILE *fpIn, *fpOut;      /* pointer to open input & output files */
    MODES mode;

    /* initialize data */
    fpIn = NULL;
    fpOut = NULL;
    mode = ENCODE;

    /* parse command line */
    optList = GetOptList(argc, argv, "cdi:o:h?");
    thisOpt = optList;

    while (thisOpt != NULL)
    {
        switch(thisOpt->option)
        {
            case 'c':       /* compression mode */
                mode = ENCODE;
                break;

            case 'd':       /* decompression mode */
                mode = DECODE;
                break;

            case 'i':       /* input file name */
                if (fpIn != NULL)
                {
                    fprintf(stderr, "Multiple input files not allowed.\n");
                    fclose(fpIn);

                    if (fpOut != NULL)
                    {
                        fclose(fpOut);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }

                /* open input file as binary */
                fpIn = fopen(thisOpt->argument, "rb");
                if (fpIn == NULL)
                {
                    perror("Opening input file");

                    if (fpOut != NULL)
                    {
                        fclose(fpOut);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }
                break;

            case 'o':       /* output file name */
                if (fpOut != NULL)
                {
                    fprintf(stderr, "Multiple output files not allowed.\n");
                    fclose(fpOut);

                    if (fpIn != NULL)
                    {
                        fclose(fpIn);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }

                /* open output file as binary */
                fpOut = fopen(thisOpt->argument, "wb");
                if (fpOut == NULL)
                {
                    perror("Opening output file");

                    if (fpIn != NULL)
                    {
                        fclose(fpIn);
                    }

                    FreeOptList(optList);
                    exit(EXIT_FAILURE);
                }
                break;

            case 'h':
            case '?':
                printf("Usage: %s <options>\n\n", RemovePath(argv[0]));
                printf("options:\n");
                printf("  -c : Encode input file to output file.\n");
                printf("  -d : Decode input file to output file.\n");
                printf("  -i <filename> : Name of input file.\n");
                printf("  -o <filename> : Name of output file.\n");
                printf("  -h | ?  : Print out command line options.\n\n");
                printf("Default: %s -c -i stdin -o stdout\n",
                    RemovePath(argv[0]));

                FreeOptList(optList);
                return(EXIT_SUCCESS);
        }

        optList = thisOpt->next;
        free(thisOpt);
        thisOpt = optList;
    }


    /* use stdin/out if no files are provided */
    if (fpIn == NULL)
    {
        fpIn = stdin;
    }


    if (fpOut == NULL)
    {
        fpOut = stdout;
    }

    /* we have valid parameters encode or decode */
    if (mode == ENCODE)
    {
        EncodeLZSSByFile(fpIn, fpOut);
    }
    else
    {
        DecodeLZSSByFile(fpIn, fpOut);
    }

    /* remember to close files */
    fclose(fpIn);
    fclose(fpOut);
    return EXIT_SUCCESS;
}
コード例 #14
0
//---------------------------------------------------------------------------
const std::string TFormQuestion::Get_question_string() const
{
  //Use '-' instead of comma, because of SeperateString in UnitFormScoreTests
  return (RemovePath(m_question->m_filename) + "-" + m_question->m_question);
}
コード例 #15
0
void LoadDatabaseFile(const char* DatabaseFilename) {
	if (GetParameter("Network output location").compare("none") != 0 && GetParameter("Network output location").length() > 0) {
		if (GetParameter("os").compare("windows") == 0) {
			system(("move "+GetDatabaseDirectory(GetParameter("database"),"output directory")+GetParameter("output folder")+" "+GetParameter("Network output location")).data());
		} else {
			system(("cp -r "+GetDatabaseDirectory(GetParameter("database"),"output directory")+GetParameter("output folder")+" "+GetParameter("Network output location")).data());
		}
	}
	
	//Getting filename that all compound and reaction data will be saved into
	string Filename(DatabaseFilename);	
	if (Filename.length() == 0) {
		Filename = AskString("Input filename for database: ");
	}
	
	//Creating datastructure for all program data
	Data* NewData = new Data(0);
	NewData->ClearData("NAME",STRING);
	NewData->AddData("NAME",RemoveExtension(RemovePath(Filename)).data(),STRING);

	//Loading data from file
	if (NewData->LoadSystem(Filename) == FAIL) {
		delete NewData;
		return;
	}
	//Performing a variety of tasks according to the parameters in the parameters files including KEGG lookup, reaction and compound printing etc.
	NewData->PerformAllRequestedTasks();
	// Test for Adjustment of DeltaGs for PH for COMPOUNDS
	bool TestCpds = 0;

	if (TestCpds){

		double IonicS = 0.25;
		FErrorFile() << "Std Transformed Gibbs Energy of Formation vs pH" << endl;
		
		for (int i=0; i < NewData->FNumSpecies(); i++){
			
			string CompoundID = NewData->GetSpecies(i)->GetData("DATABASE",STRING); // gets the cpdID
			string Name = NewData->GetSpecies(i)->GetData("NAME",STRING); // gets the name of the cpd

			Species* Temp = NewData->FindSpecies("DATABASE",CompoundID.data());
			
			//if (CompoundID.compare("cpd00003") == 0 || CompoundID.compare("cpd00004") == 0 || CompoundID.compare("cpd00002") == 0) {
			double AdjDeltaG5 = Temp->AdjustedDeltaG(IonicS,5,298.15);
			double AdjDeltaG5_kJ = 4.184*AdjDeltaG5;

			double AdjDeltaG6 = Temp->AdjustedDeltaG(IonicS,6,298.15);
			double AdjDeltaG6_kJ = 4.184*AdjDeltaG6;

			double AdjDeltaG7 = Temp->AdjustedDeltaG(IonicS,7,298.15);
			double AdjDeltaG7_kJ = 4.184*AdjDeltaG7;

			double AdjDeltaG8 = Temp->AdjustedDeltaG(IonicS,8,298.15);
			double AdjDeltaG8_kJ = 4.184*AdjDeltaG8;

			double AdjDeltaG9 = Temp->AdjustedDeltaG(IonicS,9,298.15);
			double AdjDeltaG9_kJ = 4.184*AdjDeltaG9;

			FErrorFile() << CompoundID << "\t" << AdjDeltaG5_kJ << "\t" << AdjDeltaG6_kJ << "\t" << AdjDeltaG7_kJ << "\t" << AdjDeltaG8_kJ << "\t" << AdjDeltaG9_kJ << endl;
			//}
		}

		FlushErrorFile();
	}
	// Test for Adjustment of DeltaGs for IONIC STRENGTH for COMPOUNDS
	bool TestCpdsIS = 0;

	if (TestCpdsIS){
	
		FErrorFile() << "Std Transformed Gibbs Energy of Formation vs Ionic Strength" << endl;

		for (int i=0; i < NewData->FNumSpecies(); i++){

			string CompoundID = NewData->GetSpecies(i)->GetData("DATABASE",STRING); // gets the cpdID
			string Name = NewData->GetSpecies(i)->GetData("NAME",STRING); // gets the name of the cpd

			Species* Temp = NewData->FindSpecies("DATABASE",CompoundID.data());

			double AdjDeltaG_IS0 = Temp->AdjustedDeltaG(0,7,298.15);
			double AdjDeltaG_IS0_kJ = 4.184*AdjDeltaG_IS0;

			double AdjDeltaG_IS10 = Temp->AdjustedDeltaG(0.1,7,298.15);
			double AdjDeltaG_IS10_kJ = 4.184*AdjDeltaG_IS10;

			double AdjDeltaG_IS25 = Temp->AdjustedDeltaG(0.25,7,298.15);
			double AdjDeltaG_IS25_kJ = 4.184*AdjDeltaG_IS25;

			FErrorFile() << CompoundID << "\t" << AdjDeltaG_IS0_kJ << "\t" << AdjDeltaG_IS10_kJ << "\t" << AdjDeltaG_IS25_kJ << endl;
		
		}

		FlushErrorFile();
	}
	// Test for Adjustment of DeltaGs for pH for REACTIONS
	bool TestRxns = 0;

	if (TestRxns){
		
		double IonicS = 0.25;
		//double pH = 7;
		FErrorFile() << "Std Transformed Gibbs Energy of Reaction (kJmol-1) vs pH" << endl;

		for (int i=0; i < NewData->FNumReactions(); i++){
			Reaction* Rxn = NewData->GetReaction(i);
			string RxnID = Rxn->GetData("DATABASE",STRING);
			string Name = Rxn->GetData("NAME",STRING);
		
			double DG5 = Rxn->FEstDeltaG(5,IonicS)*4.184;
			double DG6 = Rxn->FEstDeltaG(6,IonicS)*4.184;
			double DG7 = Rxn->FEstDeltaG(7,IonicS)*4.184;
			double DG8 = Rxn->FEstDeltaG(8,IonicS)*4.184;
			double DG9 = Rxn->FEstDeltaG(9,IonicS)*4.184;
			
			FErrorFile() << RxnID << "\t" << DG5 << "\t" << DG6 << "\t" << DG7 << "\t" << DG8 << "\t" << DG9 << endl;
		}
		FlushErrorFile();
	}
	// Test for Adjustment of DeltaGs for IONIC STRENGTH for REACTIONS
	bool TestRxnsIS = 0;

	if (TestRxnsIS){
		
		FErrorFile() << "Std Transformed Gibbs Energy of Reaction (kJmol-1) vs Ionic Strength" << endl;
		
		for (int i=0; i < NewData->FNumReactions(); i++){
			Reaction* Rxn = NewData->GetReaction(i);
			string RxnID = Rxn->GetData("DATABASE",STRING);
			string Name = Rxn->GetData("NAME",STRING);
			
			double DG_IS0 = Rxn->FEstDeltaG(7,0.25)*4.184;
			double DG_IS10 = Rxn->FEstDeltaG(7,0.15)*4.184;
			double DG_IS25 = Rxn->FEstDeltaG(7,0.25)*4.184;
			
			FErrorFile() << RxnID << "\t" << DG_IS0 << "\t" << DG_IS10 << "\t" << DG_IS25 << endl;

		}
		// FlushErrorFile();
	}
	delete NewData;
};
コード例 #16
0
//---------------------------------------------------------------------------
void TFormScoreTests::ReadFile(const String& filename)
{
  const int row = StringGridStudents->RowCount - 1;
  const std::string file_stripped = RemoveExtension(RemovePath(filename.c_str()));
  ++StringGridStudents->RowCount;
  StringGridStudents->Cells[0][row] = row;
  StringGridStudents->Cells[1][row] = file_stripped.c_str();
  StringGridStudents->Cells[2][row] = "";
  StringGridStudents->Cells[3][row] = "";

  const int key = EditKey->Text.ToInt();
  const int penalty = EditPenalty->Text.ToInt();
  const Encranger e(key);


  //Load file
  std::vector<std::string> v = FileToVector(filename.c_str());

  const int sz = v.size();
  for (int i=0; i!=sz; ++i)
  {
    //Deencrypt file
    v[i] = e.Deencrypt(v[i]);
    //Remove asterisks
    v[i] = ReplaceAll(v[i],"*","");
  }

  const std::string username = FindUserName(v);

  if (username.empty())
  {
    StringGridStudents->Cells[3][row] = "Username not found";
    StringGridStudents->Cells[2][row] = "1.0 or 1.1";
    return;
  }

  if (username != file_stripped)
  {
    StringGridStudents->Cells[3][row] = "Filename differs from username";
    StringGridStudents->Cells[2][row] = "1.1";
    return;
  }


  int n_correct = 0;
  const int n_questions = CountQuestions(v);
  LabelNquestions->Caption = "#questions: " + IntToStr(n_questions);

  for (int i=0; i!=sz; ++i)
  {
    if (v[i].empty()) continue;

    const std::vector<std::string> line_markup = SeperateString(v[i],",");

    //Replace {comma} by a comma for each std::string in v
    const std::vector<std::string> line = ReplaceAll(line_markup,"{comma}",",");

    OutputDebugString(line.size() >= 1 ? line[0].c_str() : "line[0] = {}");
    OutputDebugString(line.size() >= 2 ? line[1].c_str() : "line[1] = {}");
    OutputDebugString(line.size() >= 3 ? line[2].c_str() : "line[2] = {}");
    OutputDebugString(line.size() >= 4 ? line[3].c_str() : "line[3] = {}");

    //assert(line.size() == 2); WORKAROUND



    if (line[0]=="NAME") continue;
    const bool is_correct = (line[line.size()-1]=="Y"); //WORKAROUND
    assert(line[line.size()-1]=="Y" || line[line.size()-1]=="N"); //WORKAROUND 
    if (is_correct) ++n_correct;
    ScoreQuestion(line[0],is_correct);
  }

  //Calculate student's score
  assert(n_questions - penalty > 0);
  const double fraction
      = static_cast<double>(n_correct - penalty)
      / static_cast<double>(n_questions - penalty);
  const double init_score = 1.0 + (9.0 * fraction);
  const double score_above_one = (init_score < 1.0 ? 1.0 : init_score);
  const double score_below_ten = (score_above_one > 10.0 ? 10.0 : score_above_one);
  const double score = score_below_ten;

  StringGridStudents->Cells[2][row] = score;
}