Beispiel #1
0
//__________________________________________________________________
void		_HYSequencePane::CleanUpSequenceNames (void)
{
	bool	doSomething = false;
	
	_List		namesl;
	_AVLList	names (&namesl);	
	
	for    (long k=0; k<speciesIndex.lLength; k++)
	{
		_String * thisString = (_String*)rowHeaders (speciesIndex.lData[k]);
		if (!thisString->IsValidIdentifier(false))
		{
			BufferToConsole ("Changed ");
			StringToConsole(*thisString);
			thisString->ConvertToAnIdent(false);
			BufferToConsole (" to ");
			StringToConsole(*thisString);
			NLToConsole();
			doSomething = true;
		}
		
		_String * testString = new _String (*thisString);
		
		if (!testString)
			checkPointer (testString);
		
		long	tryThisSuffix = 2;
		
		while (names.Find (testString)>=0)
		{
			*testString = *thisString & '_' & tryThisSuffix;
			tryThisSuffix++;
		}
		
		if (tryThisSuffix>2)
		{
			BufferToConsole ("Changed ");
			StringToConsole(*thisString);
			BufferToConsole (" to ");
			StringToConsole(*testString);
			BufferToConsole (" to avoid duplicate identifiers\n");
			doSomething  = true;
			thisString->CopyDynamicString (testString,true);
		}
		else
			DeleteObject (testString);
		
		names.Insert(thisString);
		thisString->nInstances++;
	}
	
	if (doSomething)
	{
		SetHeaders (nil,true);
		_MarkForUpdate();
	}
}
Beispiel #2
0
//__________________________________________________________________________________
void    SetStatusLineUser   (_String s)
{
    setvbuf(stdout, NULL, _IONBF, 0);
    BufferToConsole("\33[2K\r");
    StringToConsole(s);
    needExtraNL = true;
}
Beispiel #3
0
//__________________________________________________________________________________
void    SetStatusLine               (_String s)
{
#ifdef  _MINGW32_MEGA_
    if (_HY_MEGA_Pipe != INVALID_HANDLE_VALUE) {
        DWORD bytesWritten = 0;
        if (WriteFile (_HY_MEGA_Pipe,(LPCVOID)s.sData,s.sLength,&bytesWritten,NULL) == FALSE || bytesWritten != s.sLength) {
            _String errMsg ("Failed to write the entire status update to a named MEGA pipe");
            StringToConsole (errMsg);
        }
        FlushFileBuffers(_HY_MEGA_Pipe);
    } else {
        StringToConsole (s);
    }
#endif

}
Beispiel #4
0
bool    ExpressionCalculator (void)
{
    _String data (StringFromConsole(false));

#ifndef __UNIX__
    if (terminateExecution) {
        return false;
    }
    BufferToConsole (">");
    StringToConsole (data);
    BufferToConsole ("\n");
#endif

    if (data.sLength == 4) {
        _String checkForExit (data);
        checkForExit.LoCase();
        if (checkForExit == _String ("exit")) {
            return false;
        }
    }

    _Formula  lhs,
              rhs;

    _FormulaParsingContext fpc;
    long retCode = Parse(&lhs, data, fpc, nil);

    if (!terminateExecution) {
        if (retCode == HY_FORMULA_EXPRESSION) {
            _PMathObj formRes = lhs.Compute();
            if (!formRes) {
                BufferToConsole ("NULL\n");
            } else {
                _String * objValue = (_String*)formRes->toStr();
                StringToConsole (*objValue);
                //BufferToConsole ("\n");
                DeleteObject    (objValue);
            }
        } else {
            BufferToConsole ("NO RETURN VALUE");
        }
    }
    NLToConsole();
    terminateExecution = false;
    return true;
}
Beispiel #5
0
_String ReturnDialogInput(bool dispPath)
{
    if (!dispPath) {
        NLToConsole ();
        StringToConsole (dialogPrompt);
        BufferToConsole (":");
    } else {
        NLToConsole ();
        if (pathNames.lLength) {
            StringToConsole(*(_String*)pathNames(pathNames.lLength-1));
        } else {
            StringToConsole (baseDirectory);
        }
        
        StringToConsole (dialogPrompt);
        BufferToConsole (":");
    }
    return StringFromConsole();
}
Beispiel #6
0
bool ExpressionCalculator (_String data)
{
    //Checking for exit
    #ifndef __HYPHYQT__
        if (data.sLength == 4) {
            _String checkForExit (data);
            checkForExit.LoCase();
            if (checkForExit == _String ("exit")) {
                return false;
            }
        }
    #endif

    _Formula   lhs,
               rhs;
              
    _String    errMsg;
    _FormulaParsingContext fpc (&errMsg, nil);
    
    long       retCode = Parse(&lhs, data, fpc, nil);

    if (retCode != HY_FORMULA_FAILED) {
        if (retCode == HY_FORMULA_EXPRESSION) {
            _PMathObj formRes = lhs.Compute(0,nil,nil,&errMsg);
            if (errMsg.sLength) {
                WarnError(errMsg);
            } else {
                _String * objValue = (_String*)formRes->toStr();
                StringToConsole(*objValue);
                DeleteObject(objValue);
            }
        } else {
            BufferToConsole ("NO RETURN VALUE");
        }
    } else {
        WarnError(errMsg);
    }
    return true;
}
Beispiel #7
0
void 	NLToConsole (void)
{
	StringToConsole (newLN);
}
Beispiel #8
0
void 	BufferToConsole (const char* buffer)
{
	_String s (buffer);
	StringToConsole (s);
}
Beispiel #9
0
int main( int   argc, char *argv[] )
{

	#ifdef	__HYPHYMPI__
		  int 		   rank, 
		  			   size;
		  			   			   			 
		  MPI_Init	   (&argc, &argv);
		  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
		  MPI_Comm_size(MPI_COMM_WORLD, &size);
		  
		  _hy_mpi_node_rank = rank;
		  
		  setParameter  (mpiNodeID, (_Parameter)rank);
		  setParameter	(mpiNodeCount, (_Parameter)size);
		  
		  if (rank == 0)
	#endif
   
	gtk_init (&argc, &argv);

	/* set up globals */
	
	char curWd[4096];
	getcwd (curWd,4096);

	_String baseDir (curWd);
	baseDir=baseDir&'/';

	pathNames&& &baseDir;
	baseDirectory = baseDir;
	for (long i=1; i<argc;i++)
	{
		_String thisArg (argv[i]);
		if (thisArg.beginswith ("BASEPATH="))
		{
			baseDirectory = thisArg.Cut(9,-1);
			if (baseDirectory.sLength)
			{
				if (baseDirectory.sData[baseDirectory.sLength-1]!='/')
					baseDirectory = baseDirectory&"/";
			}
		}
		else
			if (thisArg.beginswith ("USEPATH="))
			{
				_String		baseArgDir 			(thisArg,8,-1);
				errorFileName					= baseArgDir & errorFileName;
				messageFileName					= baseArgDir & messageFileName;
				pathNames.Delete				(0);
				pathNames&&						&baseDir;
			}
			else
				if (thisArg.beginswith ("CPU="))
				{
					#ifdef __MP__
					_String cpus = thisArg.Cut(4,-1);
					systemCPUCount = cpus.toNum();
					if (systemCPUCount<1)
						systemCPUCount = 1;
					#ifdef __MP2__
						pthread_setconcurrency (systemCPUCount+1);
					#endif
					#endif
				}
				#ifdef	__HYPHYMPI__
					else
						if (thisArg == _String("MPIOPTIMIZER"))
						{
							mpiParallelOptimizer = true;
							setParameter	(mpiNodeCount, 0.0);
						}
						else
							if (thisArg == _String("MPIPARTITIONS"))
							{
								mpiPartitionOptimizer = true;
								setParameter	(mpiNodeCount, 0.0);
							}
				#endif
	}
	
	#ifdef	__HYPHYMPI__
	if (rank == 0)
	#endif
	{
		baseDir = baseDirectory & "GTKResources";
		_List scanRes;
		ScanDirectoryForFileNames(baseDir,scanRes,false);
		if (scanRes.lLength == 0)
		{
			GtkWidget * noRez = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "HYPHY_GTK was unable to find a required GTKResources directory in %s. Please use BASEPATH= command line option to specify where the installation directory of HyPhy can be found.", baseDirectory.sData);
			gtk_dialog_run (GTK_DIALOG (noRez));
			gtk_widget_destroy (noRez);
			return 1;
		}
		_String rcPath = baseDir & "/theme/theme.rc";
		//printf ("Loading res files from %s\n", rcPath.sData);
		gtk_rc_parse (rcPath.sData);
	}
	
 	GlobalStartup();

	#ifdef	__HYPHYMPI__
	if (rank == 0)
	{
	#endif
	GdkDisplay * defDisplay = gdk_screen_get_display (gdk_screen_get_default());
	hSizeCursor = gdk_cursor_new_for_display (defDisplay,GDK_SB_H_DOUBLE_ARROW);
	pickUpCursor = gdk_cursor_new_for_display (defDisplay,GDK_TARGET);
	dropOffCursor = gdk_cursor_new_for_display (defDisplay,GDK_TCROSS);
	
	screenPContext = gdk_pango_context_get_for_screen (gdk_screen_get_default());
	tablePDMenuIcon = (GdkPixbuf*)ProcureIconResource(4020);
		
	/*{
		GdkScreen * defD = gdk_screen_get_default();
		fontConversionFactor = 72.27 / (gdk_screen_get_height (defD) *25.4 / gdk_screen_get_height_mm(defD)); 
		printf ("Pango conversion factor computed at: %g\n", fontConversionFactor);
	}*/

		
	ReadInTemplateFiles ();
		
	hyphyConsoleWindow = new _HYConsoleWindow ("HYPHY Console");
	ReadPreferences		();
	SetStatusLine ("None","Idle","00:00:00");
	while (gtk_events_pending())
		gtk_main_iteration();

	SetPreferences		();
	ReadGeneticCodes	();	
	ReadModelTemplates	();
	ReadTreeProcessors ();
	MoveConsoleWindow  (consolePositionRectangle);
	StringToConsole (hyphyCiteString);
	hyphyConsoleWindow->BringToFront();

	#ifdef __HYPHYMPI__ 
	{
		char statBuffer[1024];
		sprintf (statBuffer,"MPI version of HyPhy running on %d nodes (a master and %d compute nodes) in %s mode\n",
							 size, 
							 size-1,
							 mpiPartitionOptimizer?"partition":(mpiParallelOptimizer?"rate heterogeneity":"normal"));
		BufferToConsole (statBuffer);
	}
	#endif
		
	g_timeout_add  (100,GlobalQueueTimer,nil);
	g_timeout_add  (1000,progressTimerFunction,nil);
	gtk_main ();

	WritePreferences();
	#ifdef	__HYPHYMPI__
	}
	else // slave node
	{
		if (mpiParallelOptimizer || mpiPartitionOptimizer)
			mpiOptimizerLoop (rank, size);
		else
			mpiNormalLoop (rank, size, baseDir);
	}
	#endif

	GlobalShutdown();
    return 0;
}