Exemple #1
0
quint8 fileType(QFile &file) {
    file.seek(sizeof(quint32)*5);
    quint8 type;
    QDataStream fStr(&file);
    fStr >> type;
    file.seek(0);
    return type;
}
Exemple #2
0
Json::Value ReadJSONFile(std::string path)
{
#ifdef __APPLE__
    
    /* MAC ONLY */
    /* Get Current Mac Application Directory */
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    if (!mainBundle) printf("Failed To Get Main Application Bundle \n");
    
    char* cBuf = new char[200];
    
    CFURLRef resourceUrl = CFBundleCopyResourceURL(mainBundle, CFStringCreateWithCString(NULL, path.c_str(), kCFStringEncodingASCII), NULL, NULL);
    if (!resourceUrl) printf("Failed To Get Resource Folder Path \n");
    CFURLGetFileSystemRepresentation(resourceUrl, true, (Uint8*)cBuf, 200);
    
    /* Read Tile Map File */
    Json::Value jVal;
    Json::Reader jTxt; //JSON File Parser
    std::ifstream fStr(cBuf, std::ifstream::binary);
    bool loaded = jTxt.parse(fStr, jVal, false);
    if (!loaded) printf("Failed To Load Tiled Map File. Path: %s Reason: %s \n", cBuf, jTxt.getFormatedErrorMessages().c_str());
    
    delete cBuf;
    
    return jVal;
    
#else
    /* Windows Only */
    
    /* Read Tile Map File */
    Json::Value jVal;
    Json::Reader jTxt; //JSON File Parser
    std::ifstream fStr(path, std::ifstream::binary);
    bool loaded = jTxt.parse(fStr, jVal, false);
    if (!loaded) printf("Failed To Load Tiled Map File. Path: %s Reason: %s \n", path.c_str(), jTxt.getFormatedErrorMessages().c_str());
    
    return jVal;
#endif
}
Exemple #3
0
//-*****************************************************************************
void ParseOBJ( Reader &iReadInto,
               const std::string &iFileName )
{
    std::ifstream fStr( iFileName.c_str() );
    
    if ( !fStr )
    {
        ParseReader reader( iReadInto );
        reader.start( iFileName );
        std::stringstream sstr;
        sstr << "ERROR: OBJ stream \"" << iFileName
             << "\": " << std::endl
             << "Couldn't open file: " << iFileName << std::endl;
        reader.error( iFileName, sstr.str(), 0 );
        return;
    }

    ParseOBJ( iReadInto, iFileName, fStr );
}
Exemple #4
0
template<typename aRec> void afile<aRec>::ReadFile(QFile &file)
{
    QDataStream fStr(&file);
    aRec tempR;
    fileInfo.setFile(file);
    fStr.setByteOrder(QDataStream::LittleEndian);
    fStr >> p1;
    fStr >> p2;
    fStr >> p3;
    fStr >> recNum;
    fStr >> dataLen;

    while (!fStr.atEnd())
    {
        fStr >> recType;
        fStr >> recLen;
        fStr >> tempR;
        if (tempR.getRecLen()==recLen && tempR.getRecType()==recType) records.append(tempR);
        tempR = aRec();
    }
}
Exemple #5
0
//__________________________________________________________________________________
int main (int argc, char* argv[])
{
	mainArgCount = argc - 1;
	
	
	#ifdef	__HYPHYMPI__
		  int 		   rank, 
		  			   size;
		  			   			   			 
		  MPI_Init	   (&argc, &argv);
		  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
		  MPI_Comm_size(MPI_COMM_WORLD, &size);
		  
		  setParameter  (mpiNodeID,    (_Parameter)rank);
		  setParameter	(mpiNodeCount, (_Parameter)size);
		  _hy_mpi_node_rank = rank;
		  
		  if (rank == 0)
		  {
			  mpiNodesThatCantSwitch.Populate (size,1,0);		  	
			/* {
				  char hostname[256];
				  gethostname(hostname, sizeof(hostname));
				  printf("PID %d on %s ready for attach\n", getpid(), hostname);
				  fflush(stdout);
				  //getchar ();
			  }	*/	
#endif
	
	
	//for (long k=0; k<NSIG; k++)
	//{
	//	signal(k, &hyphyBreak);
	//}
	
	#ifdef	__HYPHYMPI__
		  }
	#endif
	
	char 	curWd[4096],
		    dirSlash = GetPlatformDirectoryChar ();
	getcwd (curWd,4096);

	_String baseDir (curWd), 
			argFile;
		

	baseDir=baseDir & dirSlash;
	pathNames&& &baseDir;
	
	baseDirectory = baseDir;
	baseArgDir	  = baseDirectory;
	
	_ExecutionList ex;
			
#ifdef _OPENMP
	systemCPUCount = omp_get_max_threads();
#endif
	
#ifdef _MINGW32_MEGA_
	{
		char pid[16];
		snprintf (pid,16,"%u", GetCurrentProcessId());
		
		_String pipeName = _String("\\\\.\\pipe\\MEGAPipe") & pid;
		printf ("Pipe name = %s\n", pipeName.sData);
		if ((_HY_MEGA_Pipe = CreateFile(pipeName.sData, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
		{
			char* lpMsgBuf;
			FormatMessage(
				FORMAT_MESSAGE_ALLOCATE_BUFFER | 
				FORMAT_MESSAGE_FROM_SYSTEM |
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				GetLastError(),
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPTSTR) &lpMsgBuf,
				0, NULL );
			FlagError (_String("Failed to create a pipe named '") & pipeName & "' to send data from HyPhy to MEGA. Error: "&lpMsgBuf);
		}
	}
#endif	
	
	for (long i=1; i<argc;i++)
	{
		_String thisArg (argv[i]);
		if (thisArg.sData[0]=='-')
		{
			ProcessConfigStr (thisArg);
		}
		else
			if (thisArg.beginswith ("BASEPATH="))
			{
				baseArgDir = thisArg.Cut(9,-1);
				if (baseArgDir.sLength)
				{
					if (baseArgDir.sData[baseArgDir.sLength-1]!=dirSlash)
						baseArgDir = baseArgDir&dirSlash;
						
					baseDirectory = baseArgDir;
				}
			}
			else
				if (thisArg.beginswith ("USEPATH="))
				{
					baseDir 			= thisArg.Cut(8,-1);
					errorFileName 		= baseDir & errorFileName;
					messageFileName 	= baseDir & messageFileName;
					pathNames.Delete 	(0);
					pathNames&& 		&baseDir;
				}
				else
					#ifdef __MP__
					if (thisArg.beginswith ("CPU="))
					{
						_String cpus = thisArg.Cut(4,-1);
						systemCPUCount = cpus.toNum();
						if (systemCPUCount<1)
							systemCPUCount = 1;
						pthread_setconcurrency (systemCPUCount+1);
					}
					else
					#endif
				argFile = thisArg;
	}
	
  	GlobalStartup();

	if (calculatorMode)
	{
		printf ("\nHYPHY is running in calculator mode. Type 'exit' when you are finished.\n");
		while (ExpressionCalculator()) ;
		return 0;
	}
	
	if (pipeMode)
	{
		_String bfIn (stdin);
		_ExecutionList exIn (bfIn);
		exIn.Execute();
		GlobalShutdown();
		return 0;
	}
	
	// try to read the preferences
	_String		prefFile (curWd);
	prefFile = prefFile & '/' & prefFileName;
	FILE	 * testPrefFile = fopen (prefFile.sData,"r");
	if (!testPrefFile)
	{
		prefFile = baseArgDir & prefFileName;
		testPrefFile = fopen (prefFile.sData,"r");
	}
	if (testPrefFile)
	{		
		fclose(testPrefFile);
		ReadBatchFile (prefFile,ex);
		ex.Execute();
		ex.Clear();
	}
	//printf ("Node %d before mpiParallelOptimizer\n", rank);
	#ifdef __HYPHYMPI__
		if (rank>0)
		{
			//if (mpiParallelOptimizer || mpiPartitionOptimizer)
			//	mpiOptimizerLoop (rank, size);
			//else
			mpiNormalLoop (rank, size, baseDir);
			/*argFile = "SHUTDOWN_CONFIRM";
			MPISendString (argFile, senderID);*/
		}
		else
		{
	#endif
	if (!argFile.sLength)
	{	
		long selection = -2;
		if (!updateMode)
			selection = DisplayListOfChoices();

		if (selection == -1)
		{			
			dialogPrompt = "Batch file to run:";
			_String fStr (ReturnDialogInput (true));
			if (logInputMode)
			{
				_String tts = loggedFileEntry&fStr;
				loggedUserInputs && & tts;
			}
			
			PushFilePath (fStr);
			ReadBatchFile (fStr,ex);
		}
		else
		{
			_String templ;

			if (selection >= 0)
			    templ = baseArgDir &"TemplateBatchFiles" & dirSlash;
			else
			  	templ = baseArgDir & "TemplateBatchFiles" & dirSlash & "WebUpdate.bf";				
			
			if (selection >= 0)
				templ= templ&*(_String*)(*(_List*)availableTemplateFiles(selection))(2);

			PushFilePath (templ);
			ReadBatchFile (templ,ex);
		}
	}
	else
	{
#ifndef __MINGW32__
		if (argFile.sData[0] != '/')
			argFile		  = baseDirectory & argFile;
#else
		if (argFile.sData[1] != ':') // not an absolute path 
			argFile		  = baseDirectory & argFile;		
#endif
		PushFilePath  (argFile);
		ReadBatchFile (argFile,ex);
	}
	
	ex.Execute();
	
	if (usePostProcessors && (!updateMode))
	{
		ReadInPostFiles();
		printf ("\n\n**********Continue with result processing (y/n)?");
		_String c_str (StringFromConsole());
	
		if (logInputMode)
			loggedUserInputs && & c_str;

		if (c_str.getChar(0) !='n' && c_str.getChar(0)!='N' )
		{
			long choice = DisplayListOfPostChoices();
			while (choice != -1)
			{
				_ExecutionList postEx;
				argFile = *(_String*)(*(_List*)availablePostProcessors(choice-1))(1);
				PushFilePath (argFile);
				ReadBatchFile (argFile, postEx);
				postEx.Execute();	
				PopFilePath ();
				printf ("\n\n**********Continue with result processing (y/n)?");

				c_str = StringFromConsole();
				if (logInputMode)
					loggedUserInputs && & c_str;

				if (c_str.getChar(0)=='n' || c_str.getChar(0)=='N' ) 
					break;
				
				choice = DisplayListOfPostChoices();				
			}
		}
	}
	#ifdef __HYPHYMPI__
	}
	ReportWarning				(_String ("Node ") & (long)rank & " is shutting down\n");
	#endif
	
	
#ifdef _MINGW32_MEGA_
	if (_HY_MEGA_Pipe != INVALID_HANDLE_VALUE)
		CloseHandle (_HY_MEGA_Pipe);
#endif
	
	PurgeAll					(true);
	GlobalShutdown				();
	
	#ifdef __HYPHYMPI__
		if (rank == 0)
			printf ("\n\n");			
	#endif
	
}
Exemple #6
0
//__________________________________________________________________________________
int main (int argc, char* argv[])
{
	mainArgCount = argc - 1;
	
	
	#ifdef	__HYPHYMPI__
		  int 		   rank, 
		  			   size;
		  			   			   			 
		  MPI_Init	   (&argc, &argv);
		  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
		  MPI_Comm_size(MPI_COMM_WORLD, &size);
		  
		  setParameter  (mpiNodeID, (_Parameter)rank);
		  setParameter	(mpiNodeCount, (_Parameter)size);
		  _hy_mpi_node_rank = rank;
		  
		  if (rank == 0)
		  {
		  	
	#endif
	
	
	//for (long k=0; k<NSIG; k++)
	//{
	//	signal(k, &hyphyBreak);
	//}
	
	#ifdef	__HYPHYMPI__
		  }
	#endif
	
	char 	curWd[4096],
		    dirSlash = GetPlatformDirectoryChar ();
	getcwd (curWd,4096);

	_String baseDir (curWd), 
			argFile;
		

	baseDir=baseDir & dirSlash;
	pathNames&& &baseDir;
	
	baseDirectory = baseDir;
	baseArgDir	  = baseDirectory;
	
	_ExecutionList ex;
			
#ifdef _OPENMP
	systemCPUCount = omp_get_max_threads();
#endif

	for (long i=1; i<argc;i++)
	{
		_String thisArg (argv[i]);
		if (thisArg.sData[0]=='-')
		{
			ProcessConfigStr (thisArg);
		}
		else
			if (thisArg.beginswith ("BASEPATH="))
			{
				baseArgDir = thisArg.Cut(9,-1);
				if (baseArgDir.sLength)
				{
					if (baseArgDir.sData[baseArgDir.sLength-1]!=dirSlash)
						baseArgDir = baseArgDir&dirSlash;
						
					baseDirectory = baseArgDir;
				}
			}
			else
				if (thisArg.beginswith ("USEPATH="))
				{
					baseDir 			= thisArg.Cut(8,-1);
					errorFileName 		= baseDir & errorFileName;
					messageFileName 	= baseDir & messageFileName;
					pathNames.Delete 	(0);
					pathNames&& 		&baseDir;
				}
				else
					#ifdef __MP__
					if (thisArg.beginswith ("CPU="))
					{
						_String cpus = thisArg.Cut(4,-1);
						systemCPUCount = cpus.toNum();
						if (systemCPUCount<1)
							systemCPUCount = 1;
						#ifdef __MP2__
							pthread_setconcurrency (systemCPUCount+1);
						#endif
					}
					else
					#endif
					#ifdef __HYPHYMPI__
					if (thisArg == _String("MPIOPTIMIZER"))
					{
						mpiParallelOptimizer = true;
			  		    setParameter	(mpiNodeCount, 0.0);
			  		}
					else
						if (thisArg == _String("MPIPARTITIONS"))
						{
							mpiPartitionOptimizer = true;
				  		    setParameter	(mpiNodeCount, 0.0);
				  		}
				  		else
					#endif				
				argFile = thisArg;
	}
	
  	GlobalStartup();

	if (calculatorMode)
	{
		printf ("\nHYPHY is running in calculator mode. Type 'exit' when you are finished.\n");
		while (ExpressionCalculator()) ;
		return 0;
	}
	
	if (pipeMode)
	{
		_String bfIn (stdin);
		_ExecutionList exIn (bfIn);
		exIn.Execute();
		GlobalShutdown();
		return 0;
	}
	
	// try to read the preferences
	_String		prefFile (curWd);
	prefFile = prefFile & '/' & prefFileName;
	FILE	 * testPrefFile = fopen (prefFile.sData,"r");
	if (!testPrefFile)
	{
		prefFile = baseArgDir & prefFileName;
		testPrefFile = fopen (prefFile.sData,"r");
	}
	if (testPrefFile)
	{		
		fclose(testPrefFile);
		ReadBatchFile (prefFile,ex);
		ex.Execute();
		ex.Clear();
	}
	//printf ("Node %d before mpiParallelOptimizer\n", rank);
	#ifdef __HYPHYMPI__
		if (rank>0)
		{
			if (mpiParallelOptimizer || mpiPartitionOptimizer)
				mpiOptimizerLoop (rank, size);
			else
				mpiNormalLoop (rank, size, baseDir);
			/*argFile = "SHUTDOWN_CONFIRM";
			MPISendString (argFile, senderID);*/
		}
		else
		{
	#endif
	if (!argFile.sLength)
	{	
		long selection = -2;
		if (!updateMode)
			selection = DisplayListOfChoices();

		if (selection == -1)
		{			
			dialogPrompt = "Batch file to run:";
			_String fStr (ReturnDialogInput (true));
			if (logInputMode)
			{
				_String tts = loggedFileEntry&fStr;
				loggedUserInputs && & tts;
			}
			
			PushFilePath (fStr);
			ReadBatchFile (fStr,ex);
		}
		else
		{
			_String templ;

			if (selection >= 0)
			    templ = baseArgDir &"TemplateBatchFiles" & dirSlash;
			else
			  	templ = baseArgDir & "TemplateBatchFiles" & dirSlash & "WebUpdate.bf";				
			
			if (selection >= 0)
				templ= templ&*(_String*)(*(_List*)availableTemplateFiles(selection))(2);

			PushFilePath (templ);
			ReadBatchFile (templ,ex);
		}
	}
	else
	{
#ifndef __MINGW32__
		if (argFile.sData[0] != '/')
			argFile		  = baseDirectory & argFile;
#else
		if (argFile.sData[1] != ':') // not an absolute path 
			argFile		  = baseDirectory & argFile;		
#endif
		PushFilePath  (argFile);
		ReadBatchFile (argFile,ex);
	}
	
	ex.Execute();
	
	if (usePostProcessors && (!updateMode))
	{
		ReadInPostFiles();
		printf ("\n\n**********Continue with result processing (y/n)?");
		_String c_str (StringFromConsole());
	
		if (logInputMode)
			loggedUserInputs && & c_str;

		if (c_str.sData[0]!='n' && c_str.sData[0]!='N' )
		{
			long choice = DisplayListOfPostChoices();
			while (choice != -1)
			{
				_ExecutionList postEx;
				argFile = *(_String*)(*(_List*)availablePostProcessors(choice-1))(1);
				PushFilePath (argFile);
				ReadBatchFile (argFile, postEx);
				postEx.Execute();	
				PopFilePath ();
				printf ("\n\n**********Continue with result processing (y/n)?");

				_String c_str (StringFromConsole());
				if (logInputMode)
					loggedUserInputs && & c_str;

				if (c_str.sData[0]=='n' || c_str.sData[0]=='N' ) break;
				
				choice = DisplayListOfPostChoices();				
			}
		}
	}
	#ifdef __HYPHYMPI__
	}
	argFile = _String ("Node ") & (long)rank & " is shutting down\n"; 
	ReportWarning (argFile);
	#endif
	batchLanguageFunctions.Clear();
	GlobalShutdown();
	
	#ifdef __HYPHYMPI__
		if (rank == 0)
			printf ("\n\n");			
	#endif
	
}